Commit 0aa98699 authored by Bartek Fabiszewski's avatar Bartek Fabiszewski
Browse files

Improve services status reporting, permissions handling, updating preferences

Fixes #3, fixes #4, fixes #5
parent 286c01ae
Loading
Loading
Loading
Loading
+147 −53
Original line number Diff line number Diff line
@@ -45,11 +45,19 @@ import static android.location.LocationProvider.TEMPORARILY_UNAVAILABLE;
public class LoggerService extends Service {

    private static final String TAG = LoggerService.class.getSimpleName();
    public static final String BROADCAST_LOCATION_STARTED = "net.fabiszewski.ulogger.broadcast.location_started";
    public static final String BROADCAST_LOCATION_STOPPED = "net.fabiszewski.ulogger.broadcast.location_stopped";
    public static final String BROADCAST_LOCATION_UPDATED = "net.fabiszewski.ulogger.broadcast.location_updated";
    public static final String BROADCAST_LOCATION_PERMISSION_DENIED = "net.fabiszewski.ulogger.broadcast.location_permission_denied";
    public static final String BROADCAST_LOCATION_NETWORK_DISABLED = "net.fabiszewski.ulogger.broadcast.network_disabled";
    public static final String BROADCAST_LOCATION_GPS_DISABLED = "net.fabiszewski.ulogger.broadcast.gps_disabled";
    public static final String BROADCAST_LOCATION_NETWORK_ENABLED = "net.fabiszewski.ulogger.broadcast.network_enabled";
    public static final String BROADCAST_LOCATION_GPS_ENABLED = "net.fabiszewski.ulogger.broadcast.gps_enabled";
    public static final String BROADCAST_LOCATION_DISABLED = "net.fabiszewski.ulogger.broadcast.location_disabled";
    private boolean liveSync = false;
    private Intent syncIntent;

    private static boolean isRunning = false;
    private static volatile boolean isRunning = false;
    private LoggerThread thread;
    private Looper looper;
    private LocationManager locManager;
@@ -63,12 +71,12 @@ public class LoggerService extends Service {
    final private long maxTimeMillis = minTimeMillis + minTimeTolerance;

    private static Location lastLocation = null;
    private static long lastUpdateRealtime = 0;
    private static volatile long lastUpdateRealtime = 0;

    private final int NOTIFICATION_ID = (int) (System.currentTimeMillis() / 1000L);
    private NotificationManager mNotificationManager;


    private boolean useGps;
    private boolean useNet;

    /**
     * Basic initializations.
@@ -76,44 +84,37 @@ public class LoggerService extends Service {
    @Override
    public void onCreate() {
        if (Logger.DEBUG) { Log.d(TAG, "[onCreate]"); }
        thread = new LoggerThread();
        syncIntent = new Intent(getApplicationContext(), WebSyncService.class);

        mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.cancelAll();

        locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locListener = new mLocationListener();

        // read user preferences
        updatePreferences();

        boolean hasLocationUpdates = requestLocationUpdates();

        if (hasLocationUpdates) {
            isRunning = true;
            sendBroadcast(BROADCAST_LOCATION_STARTED);

            syncIntent = new Intent(getApplicationContext(), WebSyncService.class);

            thread = new LoggerThread();
            thread.start();
            looper = thread.getLooper();

            db = DbAccess.getInstance();
            db.open(this);
        locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locListener = new mLocationListener();
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        minTimeMillis = Long.parseLong(prefs.getString("prefMinTime", getString(R.string.pref_mintime_default))) * 1000;
        minDistance = Float.parseFloat(prefs.getString("prefMinDistance", getString(R.string.pref_mindistance_default)));
        maxAccuracy = Integer.parseInt(prefs.getString("prefMinAccuracy", getString(R.string.pref_minaccuracy_default)));

        boolean useGps = prefs.getBoolean("prefUseGps", true);
        boolean useNet = prefs.getBoolean("prefUseNet", true);

        if (canAccessLocation()) {
            if (useNet && providerExists(LocationManager.NETWORK_PROVIDER)) {
                //noinspection MissingPermission
                locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, minTimeMillis, minDistance, locListener, looper);
            }
            if (useGps && providerExists(LocationManager.GPS_PROVIDER)) {
                //noinspection MissingPermission
                locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTimeMillis, minDistance, locListener, looper);
            }
        }

        mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            // start websync service if needed
        liveSync = prefs.getBoolean("prefLiveSync", false);
            if (liveSync && db.needsSync()) {
                startService(syncIntent);
            }
        }
    }

    /**
     * Start main thread, request location updates, start synchronization.
@@ -126,11 +127,33 @@ public class LoggerService extends Service {
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (Logger.DEBUG) { Log.d(TAG, "[onStartCommand]"); }

        final boolean prefsUpdated = (intent != null) && intent.getBooleanExtra(MainActivity.UPDATED_PREFS, false);
        if (prefsUpdated) {
            handlePrefsUpdated();
        } else if (isRunning) {
            // first start
            showNotification(mNotificationManager, NOTIFICATION_ID);
        } else {
            // onCreate failed to start updates
            stopSelf();
        }

        return START_STICKY;
    }

    /**
     * When user updated preferences, restart location updates, stop service on failure
     */
    private void handlePrefsUpdated() {
        // restart updates
        updatePreferences();
        if (isRunning && !restartUpdates()) {
            // no valid providers after preferences update
            stopSelf();
        }
    }

    /**
     * Check if user granted permission to access location.
     *
@@ -140,10 +163,77 @@ public class LoggerService extends Service {
        return (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED);
    }

    /**
     * Check if given provider exists on device
     * @param provider Provider
     * @return True if exists, false otherwise
     */
    private boolean providerExists(String provider) {
        return locManager.getAllProviders().contains(provider);
    }

    /**
     * Reread preferences
     */
    private void updatePreferences() {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        minTimeMillis = Long.parseLong(prefs.getString("prefMinTime", getString(R.string.pref_mintime_default))) * 1000;
        minDistance = Float.parseFloat(prefs.getString("prefMinDistance", getString(R.string.pref_mindistance_default)));
        maxAccuracy = Integer.parseInt(prefs.getString("prefMinAccuracy", getString(R.string.pref_minaccuracy_default)));
        useGps = prefs.getBoolean("prefUseGps", providerExists(LocationManager.GPS_PROVIDER));
        useNet = prefs.getBoolean("prefUseNet", providerExists(LocationManager.NETWORK_PROVIDER));
        liveSync = prefs.getBoolean("prefLiveSync", false);
    }

    /**
     * Restart request for location updates
     *
     * @return True if succeeded, false otherwise (eg. disabled all providers)
     */
    private boolean restartUpdates() {
        if (Logger.DEBUG) { Log.d(TAG, "[location updates restart]"); }

        locManager.removeUpdates(locListener);
        return requestLocationUpdates();
    }

    /**
     * Request location updates
     * @return True if succeeded from at least one provider
     */
    private boolean requestLocationUpdates() {
        boolean hasLocationUpdates = false;
        if (canAccessLocation()) {
            if (useNet) {
                //noinspection MissingPermission
                locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, minTimeMillis, minDistance, locListener, looper);
                if (locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
                    hasLocationUpdates = true;
                    if (Logger.DEBUG) { Log.d(TAG, "[Using net provider]"); }
                }
            }
            if (useGps) {
                //noinspection MissingPermission
                locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTimeMillis, minDistance, locListener, looper);
                if (locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                    hasLocationUpdates = true;
                    if (Logger.DEBUG) { Log.d(TAG, "[Using gps provider]"); }
                }
            }
            if (!hasLocationUpdates) {
                // no location provider available
                sendBroadcast(BROADCAST_LOCATION_DISABLED);
                if (Logger.DEBUG) { Log.d(TAG, "[No available location updates]"); }
            }
        } else {
            // can't access location
            sendBroadcast(BROADCAST_LOCATION_PERMISSION_DENIED);
            if (Logger.DEBUG) { Log.d(TAG, "[Location permission denied]"); }
        }

        return hasLocationUpdates;
    }

    /**
     * Service cleanup
     */
@@ -162,11 +252,13 @@ public class LoggerService extends Service {
        isRunning = false;

        mNotificationManager.cancel(NOTIFICATION_ID);
        sendBroadcast(BROADCAST_LOCATION_STOPPED);

        if (thread != null) {
            thread.interrupt();
        }
        thread = null;

    }

    @Override
@@ -251,6 +343,15 @@ public class LoggerService extends Service {
        mNotificationManager.notify(mId, mBuilder.build());
    }

    /**
     * Send broadcast message
     * @param broadcast Broadcast message
     */
    private void sendBroadcast(String broadcast) {
        Intent intent = new Intent(broadcast);
        sendBroadcast(intent);
    }

    /**
     * Location listener class
     */
@@ -270,8 +371,7 @@ public class LoggerService extends Service {
                    lastUpdateRealtime = loc.getElapsedRealtimeNanos() / 1000000;
                }
                db.writeLocation(loc);
                Intent intent = new Intent(BROADCAST_LOCATION_UPDATED);
                sendBroadcast(intent);
                sendBroadcast(BROADCAST_LOCATION_UPDATED);
                if (liveSync) {
                    startService(syncIntent);
                }
@@ -289,7 +389,7 @@ public class LoggerService extends Service {
                if (Logger.DEBUG) { Log.d(TAG, "[location accuracy above limit: " + loc.getAccuracy() + " > " + maxAccuracy + "]"); }
                // reset gps provider to get better accuracy even if time and distance criteria don't change
                if (loc.getProvider().equals(LocationManager.GPS_PROVIDER)) {
                    restartUpdates(LocationManager.GPS_PROVIDER);
                    restartUpdates();
                }
                return true;
            }
@@ -306,22 +406,6 @@ public class LoggerService extends Service {
            return false;
        }

        /**
         * Restart request for location updates for given provider
         * @param provider Location provider
         */
        private void restartUpdates(String provider) {
            if (Logger.DEBUG) { Log.d(TAG, "[location restart provider " + provider + "]"); }

            if (providerExists(provider) && canAccessLocation()) {
                //noinspection MissingPermission
                locManager.removeUpdates(locListener);
                //noinspection MissingPermission
                locManager.requestLocationUpdates(provider, minTimeMillis, minDistance, locListener, looper);
            }

        }

        /**
         * Callback on provider disabled
         * @param provider Provider
@@ -329,6 +413,11 @@ public class LoggerService extends Service {
        @Override
        public void onProviderDisabled(String provider) {
            if (Logger.DEBUG) { Log.d(TAG, "[location provider " + provider + " disabled]"); }
            if (provider.equals(LocationManager.GPS_PROVIDER)) {
                sendBroadcast(BROADCAST_LOCATION_GPS_DISABLED);
            } else if (provider.equals(LocationManager.NETWORK_PROVIDER)) {
                sendBroadcast(BROADCAST_LOCATION_NETWORK_DISABLED);
            }
        }

        /**
@@ -338,6 +427,11 @@ public class LoggerService extends Service {
        @Override
        public void onProviderEnabled(String provider) {
            if (Logger.DEBUG) { Log.d(TAG, "[location provider " + provider + " enabled]"); }
            if (provider.equals(LocationManager.GPS_PROVIDER)) {
                sendBroadcast(BROADCAST_LOCATION_GPS_ENABLED);
            } else if (provider.equals(LocationManager.NETWORK_PROVIDER)) {
                sendBroadcast(BROADCAST_LOCATION_NETWORK_ENABLED);
            }
        }

        /**
+146 −35
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@

package net.fabiszewski.ulogger;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
@@ -18,11 +19,14 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
@@ -51,12 +55,21 @@ import java.util.TimeZone;

public class MainActivity extends AppCompatActivity {

    public static final String UPDATED_PREFS = "extra_updated_prefs";

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

    private final static int LED_GREEN = 1;
    private final static int LED_RED = 2;
    private final static int LED_YELLOW = 3;

    private final static int PERMISSION_LOCATION = 1;
    private final static int RESULT_PREFS_UPDATED = 1;

    private String pref_units;
    private long pref_minTimeMillis;
    private boolean pref_liveSync;

    private final static double KM_MILE = 0.621371;

    private static boolean syncError = false;
@@ -79,6 +92,7 @@ public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        updatePreferences();
        TXT_START = getString(R.string.button_start);
        TXT_STOP = getString(R.string.button_stop);
        setContentView(R.layout.activity_main);
@@ -90,7 +104,6 @@ public class MainActivity extends AppCompatActivity {
        syncLed = (TextView) findViewById(R.id.sync_led);
        locLabel = (TextView) findViewById(R.id.location_status);
        locLed = (TextView) findViewById(R.id.loc_led);

    }

    /**
@@ -164,7 +177,7 @@ public class MainActivity extends AppCompatActivity {

            case R.id.menu_settings:
                Intent i = new Intent(MainActivity.this, SettingsActivity.class);
                startActivity(i);
                startActivityForResult(i, RESULT_PREFS_UPDATED);
                return true;
            case R.id.menu_about:
                showAbout();
@@ -176,29 +189,94 @@ public class MainActivity extends AppCompatActivity {
        }
    }

    /**
     * Callback on permission request result
     * Called after user granted/rejected location permission
     *
     * @param requestCode Permission code
     * @param permissions Permissions
     * @param grantResults Result
     */
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
        switch (requestCode) {
            case PERMISSION_LOCATION:
                if ((grantResults.length > 0) && (grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
                    // onPause closed db
                    db.open(this);
                    startLogger();
                    db.close();
                }
                break;
        }
    }

    /**
     * Callback on activity result.
     * Called after user updated preferences
     *
     * @param requestCode Activity code
     * @param resultCode Result
     * @param data Data
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
            case RESULT_PREFS_UPDATED:
                // Preferences updated
                updatePreferences();
                if (LoggerService.isRunning()) {
                    // restart logging
                    Intent intent = new Intent(MainActivity.this, LoggerService.class);
                    intent.putExtra(UPDATED_PREFS, true);
                    startService(intent);
                }
                break;
        }
    }

    /**
     * Reread user preferences
     */
    private void updatePreferences() {
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        pref_units = prefs.getString("prefUnits", getString(R.string.pref_units_default));
        pref_minTimeMillis = Long.parseLong(prefs.getString("prefMinTime", getString(R.string.pref_mintime_default))) * 1000;
        pref_liveSync = prefs.getBoolean("prefLiveSync", false);
    }

    /**
     * Called when the user clicks the Start/Stop button
     * @param view View
     */
    public void toggleLogging(@SuppressWarnings("UnusedParameters") View view) {
        Intent intent = new Intent(MainActivity.this, LoggerService.class);
        if (LoggerService.isRunning()) {
            // stop tracking
            stopService(intent);
            toggleButton.setText(TXT_START);
            setLocLed(LED_RED);
            showToast(getString(R.string.tracking_stopped));
            stopLogger();
        } else {
            startLogger();
        }
    }

    /**
     * Start logger service
     */
    private void startLogger() {
        // start tracking
        if (db.getTrackName() != null) {
            Intent intent = new Intent(MainActivity.this, LoggerService.class);
            startService(intent);
                toggleButton.setText(TXT_STOP);
                setLocLed(LED_YELLOW);
                showToast(getString(R.string.tracking_started));
        } else {
            showEmptyTrackNameWarning();
        }
    }

    /**
     * Stop logger service
     */
    private void stopLogger() {
        // stop tracking
        Intent intent = new Intent(MainActivity.this, LoggerService.class);
        stopService(intent);
    }

    /**
@@ -260,11 +338,9 @@ public class MainActivity extends AppCompatActivity {
        final TextView summaryDistance = (TextView) alertDialog.findViewById(R.id.summary_distance);
        final TextView summaryDuration = (TextView) alertDialog.findViewById(R.id.summary_duration);
        final TextView summaryPositions = (TextView) alertDialog.findViewById(R.id.summary_positions);
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        final String unit = prefs.getString("prefUnits", getString(R.string.pref_units_default));
        double distance = (double) summary.getDistance() / 1000;
        String unitName = getString(R.string.unit_kilometer);
        if (unit.equals(getString(R.string.pref_units_imperial))) {
        if (pref_units.equals(getString(R.string.pref_units_imperial))) {
            distance *= KM_MILE;
            unitName = getString(R.string.unit_mile);
        }
@@ -462,18 +538,16 @@ public class MainActivity extends AppCompatActivity {
        }
        locLabel.setText(timeString);
        // Change led if more than 2 update periods elapsed since last location update
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        final long minTimeMillis = Long.parseLong(prefs.getString("prefMinTime", getString(R.string.pref_mintime_default))) * 1000;
        if (LoggerService.isRunning() && (timestamp == 0 || elapsed > minTimeMillis * 2)) {
        if (LoggerService.isRunning() && (timestamp == 0 || elapsed > pref_minTimeMillis * 2)) {
            setLocLed(LED_YELLOW);
        }
    }

    /**
     * Update synchronization status label
     * Update synchronization status label and led
     * @param unsynced Count of not synchronized positions
     */
    private void updateSyncLabel(int unsynced) {
    private void updateSyncStatus(int unsynced) {
        String text;
        if (unsynced > 0) {
            text = getResources().getQuantityString(R.plurals.label_positions_behind, unsynced, unsynced);
@@ -497,15 +571,16 @@ public class MainActivity extends AppCompatActivity {
        updateLocationLabel(LoggerService.lastUpdateRealtime());
        // get sync status
        int count = db.countUnsynced();
        if (count > 0) {
        String error = db.getError();
            if (Logger.DEBUG) { Log.d(TAG, "[sync error: " + error + "]"); }
        if (error != null) {
            if (Logger.DEBUG) { Log.d(TAG, "[sync error: " + error + "]"); }
            syncError = true;
            syncErrorLabel.setText(error);
        } else if (syncError) {
            syncError = false;
            syncErrorLabel.setText(null);
        }
        }
        updateSyncLabel(count);
        updateSyncStatus(count);
    }

    /**
@@ -566,7 +641,15 @@ public class MainActivity extends AppCompatActivity {
     */
    private void registerBroadcastReceiver() {
        IntentFilter filter = new IntentFilter();
        filter.addAction(LoggerService.BROADCAST_LOCATION_STARTED);
        filter.addAction(LoggerService.BROADCAST_LOCATION_STOPPED);
        filter.addAction(LoggerService.BROADCAST_LOCATION_UPDATED);
        filter.addAction(LoggerService.BROADCAST_LOCATION_DISABLED);
        filter.addAction(LoggerService.BROADCAST_LOCATION_GPS_DISABLED);
        filter.addAction(LoggerService.BROADCAST_LOCATION_NETWORK_DISABLED);
        filter.addAction(LoggerService.BROADCAST_LOCATION_GPS_ENABLED);
        filter.addAction(LoggerService.BROADCAST_LOCATION_NETWORK_ENABLED);
        filter.addAction(LoggerService.BROADCAST_LOCATION_PERMISSION_DENIED);
        filter.addAction(WebSyncService.BROADCAST_SYNC_DONE);
        filter.addAction(WebSyncService.BROADCAST_SYNC_FAILED);
        registerReceiver(mBroadcastReceiver, filter);
@@ -578,13 +661,18 @@ public class MainActivity extends AppCompatActivity {
    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (Logger.DEBUG) {
                Log.d(TAG, "[broadcast received " + intent + "]");
            }
            if (intent.getAction().equals(LoggerService.BROADCAST_LOCATION_UPDATED)) {
                if (Logger.DEBUG) { Log.d(TAG, "[broadcast received " + intent + "]"); }
                updateLocationLabel(LoggerService.lastUpdateRealtime());
                setLocLed(LED_GREEN);
                if (!pref_liveSync) {
                    updateSyncStatus(db.countUnsynced());
                }
            } else if (intent.getAction().equals(WebSyncService.BROADCAST_SYNC_DONE)) {
                final int unsyncedCount = db.countUnsynced();
                updateSyncLabel(unsyncedCount);
                updateSyncStatus(unsyncedCount);
                setSyncLed(LED_GREEN);
                // reset error flag and label
                if (syncError) {
@@ -597,7 +685,7 @@ public class MainActivity extends AppCompatActivity {
                    isUploading = false;
                }
            } else if (intent.getAction().equals((WebSyncService.BROADCAST_SYNC_FAILED))) {
                updateSyncLabel(db.countUnsynced());
                updateSyncStatus(db.countUnsynced());
                setSyncLed(LED_RED);
                // set error flag and label
                String message = intent.getStringExtra("message");
@@ -608,6 +696,29 @@ public class MainActivity extends AppCompatActivity {
                    showToast(getString(R.string.uploading_failed) + "\n" + message, Toast.LENGTH_LONG);
                    isUploading = false;
                }
            } else if (intent.getAction().equals(LoggerService.BROADCAST_LOCATION_STARTED)) {
                toggleButton.setText(TXT_STOP);
                showToast(getString(R.string.tracking_started));
                setLocLed(LED_YELLOW);
            } else if (intent.getAction().equals(LoggerService.BROADCAST_LOCATION_STOPPED)) {
                toggleButton.setText(TXT_START);
                showToast(getString(R.string.tracking_stopped));
                setLocLed(LED_RED);
            } else if (intent.getAction().equals(LoggerService.BROADCAST_LOCATION_GPS_DISABLED)) {
                showToast(getString(R.string.gps_disabled_warning), Toast.LENGTH_LONG);
            } else if (intent.getAction().equals(LoggerService.BROADCAST_LOCATION_NETWORK_DISABLED)) {
                showToast(getString(R.string.net_disabled_warning), Toast.LENGTH_LONG);
            } else if (intent.getAction().equals(LoggerService.BROADCAST_LOCATION_DISABLED)) {
                showToast(getString(R.string.location_disabled), Toast.LENGTH_LONG);
                setLocLed(LED_RED);
            } else if (intent.getAction().equals(LoggerService.BROADCAST_LOCATION_NETWORK_ENABLED)) {
                showToast(getString(R.string.using_network), Toast.LENGTH_LONG);
            } else if (intent.getAction().equals(LoggerService.BROADCAST_LOCATION_GPS_ENABLED)) {
                showToast(getString(R.string.using_gps), Toast.LENGTH_LONG);
            } else if (intent.getAction().equals(LoggerService.BROADCAST_LOCATION_PERMISSION_DENIED)) {
                showToast(getString(R.string.location_permission_denied), Toast.LENGTH_LONG);
                setLocLed(LED_RED);
                ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSION_LOCATION);
            }
        }
    };
+126 −13

File changed.

Preview size limit exceeded, changes collapsed.

+6 −1

File changed.

Preview size limit exceeded, changes collapsed.

+1 −2
Original line number Diff line number Diff line
@@ -61,8 +61,7 @@
        android:title="@string/pref_provider_title"
        android:summary="@string/pref_provider_summary"
        android:entries="@array/providersEntries"
        android:entryValues="@array/providersValues"
        android:defaultValue="@string/pref_provider_default" />
        android:entryValues="@array/providersValues" />
    <ListPreference
        android:key="prefUnits"
        android:title="@string/pref_units_title"