Commit 5c906bdd authored by Bartek Fabiszewski's avatar Bartek Fabiszewski
Browse files

Add waypoint button to main screen, use switch for tracking toggle

parent a877a734
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -47,6 +47,6 @@ dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.preference:preference:1.1.0'
    implementation 'androidx.exifinterface:exifinterface:1.0.0'
    implementation 'androidx.exifinterface:exifinterface:1.1.0'
    testImplementation 'junit:junit:4.12'
}
+0 −20
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.text.HtmlCompat;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.preference.PreferenceManager;

import static net.fabiszewski.ulogger.Alert.showAlert;
@@ -140,9 +139,6 @@ public class MainActivity extends AppCompatActivity
            case R.id.menu_export:
                startExport();
                return true;
            case R.id.menu_waypoint:
                addWaypoint();
                return true;
            case android.R.id.home:
                onBackPressed();
                return true;
@@ -163,22 +159,6 @@ public class MainActivity extends AppCompatActivity
        preferenceLiveSync = prefs.getBoolean(SettingsActivity.KEY_LIVE_SYNC, false);
    }

    /**
     * Start waypoint activity
     */
    private void addWaypoint() {
        if (DbAccess.getTrackName(this) != null) {
            WaypointFragment fragment = WaypointFragment.newInstance();
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            transaction.replace(R.id.fragment_placeholder, fragment);
            transaction.addToBackStack(null);
            transaction.commit();
        } else {
            showNoTrackWarning();
        }
    }


    /**
     * Display warning if track name is not set
     */
+38 −19
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

@@ -37,6 +38,8 @@ import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.widget.TextViewCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import java.text.NumberFormat;
import java.text.SimpleDateFormat;
@@ -53,9 +56,6 @@ public class MainFragment extends Fragment {

    private final String TAG = MainFragment.class.getSimpleName();

    private static String TXT_START;
    private static String TXT_STOP;

    private final static int LED_GREEN = 1;
    private final static int LED_RED = 2;
    private final static int LED_YELLOW = 3;
@@ -73,7 +73,7 @@ public class MainFragment extends Fragment {
    private TextView syncLed;
    private TextView locLabel;
    private TextView locLed;
    private Button buttonLogger;
    private SwipeSwitch switchLogger;

    private PorterDuffColorFilter redFilter;
    private PorterDuffColorFilter greenFilter;
@@ -96,14 +96,12 @@ public class MainFragment extends Fragment {
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.fragment_main, container, false);
        TXT_START = getString(R.string.button_start);
        TXT_STOP = getString(R.string.button_stop);
        ScrollView layout = (ScrollView) inflater.inflate(R.layout.fragment_main, container, false);

        buttonLogger = layout.findViewById(R.id.buttonLogger);
        switchLogger = layout.findViewById(R.id.switchLogger);
        Button buttonWaypoint = layout.findViewById(R.id.buttonWaypoint);
        Button buttonUpload = layout.findViewById(R.id.buttonUpload);
        Button buttonNewTrack = layout.findViewById(R.id.buttonNewTrack);
        buttonLogger = layout.findViewById(R.id.buttonLogger);
        syncErrorLabel = layout.findViewById(R.id.sync_error);
        syncLabel = layout.findViewById(R.id.sync_status);
        syncLed = layout.findViewById(R.id.sync_led);
@@ -111,7 +109,8 @@ public class MainFragment extends Fragment {
        locLed = layout.findViewById(R.id.loc_led);
        LinearLayout layoutSummary = layout.findViewById(R.id.layoutSummary);

        buttonLogger.setOnClickListener(this::toggleLogging);
        switchLogger.setOnCheckedChangeListener(this::toggleLogging);
        buttonWaypoint.setOnClickListener(this::addWaypoint);
        buttonUpload.setOnClickListener(this::uploadData);
        buttonNewTrack.setOnClickListener(this::newTrack);
        layoutSummary.setOnClickListener(this::trackSummary);
@@ -156,10 +155,10 @@ public class MainFragment extends Fragment {
            }

            if (LoggerService.isRunning()) {
                buttonLogger.setText(TXT_STOP);
                switchLogger.setChecked(true);
                setLocLed(LED_GREEN);
            } else {
                buttonLogger.setText(TXT_START);
                switchLogger.setChecked(false);
                setLocLed(LED_RED);
            }
            registerBroadcastReceiver();
@@ -181,14 +180,14 @@ public class MainFragment extends Fragment {
    }

    /**
     * Called when the user clicks the Start/Stop button
     * Called when the user swipes tracking switch
     * @param view View
     */
    private void toggleLogging(View view) {
        if (LoggerService.isRunning()) {
            stopLogger(view.getContext());
        } else {
    private void toggleLogging(View view, boolean isChecked) {
        if (isChecked && !LoggerService.isRunning()) {
            startLogger(view.getContext());
        } else if (!isChecked && LoggerService.isRunning()) {
            stopLogger(view.getContext());
        }
    }

@@ -216,6 +215,26 @@ public class MainFragment extends Fragment {
        context.stopService(intent);
    }

    /**
     * Start waypoint activity
     */
    private void addWaypoint(View view) {
        if (DbAccess.getTrackName(view.getContext()) != null) {
            WaypointFragment fragment = WaypointFragment.newInstance();
            FragmentManager manager = getFragmentManager();
            if (manager != null) {
                FragmentTransaction transaction = manager.beginTransaction();
                transaction.replace(R.id.fragment_placeholder, fragment);
                transaction.addToBackStack(null);
                transaction.commit();
            }
        } else {
            if (mListener != null) {
                mListener.showNoTrackWarning();
            }
        }
    }

    /**
     * Called when the user clicks the New track button
     * @param view View
@@ -614,12 +633,12 @@ public class MainFragment extends Fragment {
                    break;
                }
                case LoggerService.BROADCAST_LOCATION_STARTED:
                    buttonLogger.setText(TXT_STOP);
                    switchLogger.setChecked(true);
                    showToast(getString(R.string.tracking_started));
                    setLocLed(LED_YELLOW);
                    break;
                case LoggerService.BROADCAST_LOCATION_STOPPED:
                    buttonLogger.setText(TXT_START);
                    switchLogger.setChecked(false);
                    showToast(getString(R.string.tracking_stopped));
                    setLocLed(LED_RED);
                    break;
+43 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2020 Bartek Fabiszewski
 * http://www.fabiszewski.net
 *
 * This file is part of μlogger-android.
 * Licensed under GPL, either version 3, or any later.
 * See <http://www.gnu.org/licenses/>
 */

package net.fabiszewski.ulogger;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.Switch;

import androidx.annotation.RequiresApi;

public class SwipeSwitch extends Switch {
    public SwipeSwitch(Context context) {
        super(context);
    }

    public SwipeSwitch(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SwipeSwitch(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public SwipeSwitch(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @SuppressLint("ClickableViewAccessibility")
    @Override
    public boolean performClick() {
        return super.isChecked();
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -220,7 +220,9 @@ public class WaypointFragment extends Fragment implements LoggerTask.LoggerTaskC
     */
    private void saveWaypoint(View view) {
        if (hasLocation()) {
            if (photoUri != null) {
                photoUri = ImageHelper.moveCachedToAppStorage(view.getContext(), photoUri);
            }
            String comment = commentEditText.getText().toString();
            String uri = (photoUri == null) ? null : photoUri.toString();
            DbAccess.writeLocation(view.getContext(), location, comment, uri);
Loading