From 5d3f153141c3744df125f9a05e15d75dbc6fa0ac Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Mon, 22 Aug 2016 16:02:37 +0300 Subject: [PATCH 1/3] Android. Switching on or off using location sevices immediately on changing check state. --- .../mapswithme/maps/settings/MiscPrefsFragment.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/android/src/com/mapswithme/maps/settings/MiscPrefsFragment.java b/android/src/com/mapswithme/maps/settings/MiscPrefsFragment.java index dfeb89246b..4725b285ff 100644 --- a/android/src/com/mapswithme/maps/settings/MiscPrefsFragment.java +++ b/android/src/com/mapswithme/maps/settings/MiscPrefsFragment.java @@ -8,6 +8,7 @@ import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GoogleApiAvailability; import com.mapswithme.maps.MwmApplication; import com.mapswithme.maps.R; +import com.mapswithme.maps.location.LocationHelper; import com.mapswithme.util.Config; import com.mapswithme.util.statistics.MytargetHelper; import com.mapswithme.util.statistics.Statistics; @@ -49,8 +50,13 @@ public class MiscPrefsFragment extends BaseXmlSettingsFragment @Override public boolean onPreferenceChange(Preference preference, Object newValue) { - Config.setUseGoogleService((Boolean) newValue); - // TODO (trashkalmar): Reinitialize location provider + boolean oldVal = Config.useGoogleServices(); + boolean newVal = ((Boolean) newValue).booleanValue(); + if (oldVal == newVal) + return true; + + Config.setUseGoogleService(newVal); + LocationHelper.INSTANCE.initProvider(false); return true; } }); From 8c60dd29f2e9ebd435b2c1f2cfc5cf330b3da0a4 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Tue, 23 Aug 2016 09:42:58 +0300 Subject: [PATCH 2/3] Review fixes. --- .../com/mapswithme/maps/location/LocationHelper.java | 4 ++++ .../mapswithme/maps/settings/MiscPrefsFragment.java | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/android/src/com/mapswithme/maps/location/LocationHelper.java b/android/src/com/mapswithme/maps/location/LocationHelper.java index 6f2f7ba2a1..808bead84e 100644 --- a/android/src/com/mapswithme/maps/location/LocationHelper.java +++ b/android/src/com/mapswithme/maps/location/LocationHelper.java @@ -255,6 +255,10 @@ public enum LocationHelper public void initProvider(boolean forceNative) { + mActive = !mListeners.isEmpty(); + if (mActive) + stopInternal(); + final MwmApplication application = MwmApplication.get(); final boolean containsGoogleServices = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(application) == ConnectionResult.SUCCESS; final boolean googleServicesTurnedInSettings = Config.useGoogleServices(); diff --git a/android/src/com/mapswithme/maps/settings/MiscPrefsFragment.java b/android/src/com/mapswithme/maps/settings/MiscPrefsFragment.java index 4725b285ff..89b199ca33 100644 --- a/android/src/com/mapswithme/maps/settings/MiscPrefsFragment.java +++ b/android/src/com/mapswithme/maps/settings/MiscPrefsFragment.java @@ -52,11 +52,11 @@ public class MiscPrefsFragment extends BaseXmlSettingsFragment { boolean oldVal = Config.useGoogleServices(); boolean newVal = ((Boolean) newValue).booleanValue(); - if (oldVal == newVal) - return true; - - Config.setUseGoogleService(newVal); - LocationHelper.INSTANCE.initProvider(false); + if (oldVal != newVal) + { + Config.setUseGoogleService(newVal); + LocationHelper.INSTANCE.initProvider(false /* forceNative */); + } return true; } }); From ad32f933271666d6c182da03cac866be09d94f30 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Tue, 23 Aug 2016 18:57:29 +0300 Subject: [PATCH 3/3] Using native GPS provider in case of any issues with fuse GPS provider. --- .../maps/location/GoogleFusedLocationProvider.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/android/src/com/mapswithme/maps/location/GoogleFusedLocationProvider.java b/android/src/com/mapswithme/maps/location/GoogleFusedLocationProvider.java index df8a627186..730ebbc472 100644 --- a/android/src/com/mapswithme/maps/location/GoogleFusedLocationProvider.java +++ b/android/src/com/mapswithme/maps/location/GoogleFusedLocationProvider.java @@ -112,7 +112,7 @@ class GoogleFusedLocationProvider extends BaseLocationProvider break; case LocationSettingsStatusCodes.RESOLUTION_REQUIRED: - // Location settings are not satisfied, but this can be fixed by showing the user a dialog. + // Location settings are not satisfied. AndroidNativeProvider should be used. resolveError(status); return; @@ -131,15 +131,7 @@ class GoogleFusedLocationProvider extends BaseLocationProvider if (LocationHelper.INSTANCE.isLocationStopped()) return; - LocationHelper.INSTANCE.stop(); - Activity activity = MwmApplication.backgroundTracker().getTopActivity(); - if (activity != null) - { - try - { - status.startResolutionForResult(activity, LocationHelper.REQUEST_RESOLVE_ERROR); - } catch (IntentSender.SendIntentException ignored) {} - } + LocationHelper.INSTANCE.initProvider(true /* forceNative */); } private void requestLocationUpdates()