From d7c395c9bc88b576405acdeffb91cac9a4a20257 Mon Sep 17 00:00:00 2001 From: Dmitry Yunitsky Date: Mon, 24 Aug 2015 16:33:10 +0300 Subject: [PATCH] [android] Check location before building route. --- .../src/com/mapswithme/maps/LocationState.java | 8 ++++++++ .../com/mapswithme/maps/widget/RoutingLayout.java | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/android/src/com/mapswithme/maps/LocationState.java b/android/src/com/mapswithme/maps/LocationState.java index 95ba14e1af..f2563baca8 100644 --- a/android/src/com/mapswithme/maps/LocationState.java +++ b/android/src/com/mapswithme/maps/LocationState.java @@ -34,4 +34,12 @@ public enum LocationState public native void turnOff(); public native void invalidatePosition(); + + /** + * Checks if location state on the map is active (so its not turned off or pending). + */ + public static boolean isTurnedOn() + { + return INSTANCE.getLocationStateMode() > PENDING_POSITION; + } } diff --git a/android/src/com/mapswithme/maps/widget/RoutingLayout.java b/android/src/com/mapswithme/maps/widget/RoutingLayout.java index ef45f44d2f..252602c1f8 100644 --- a/android/src/com/mapswithme/maps/widget/RoutingLayout.java +++ b/android/src/com/mapswithme/maps/widget/RoutingLayout.java @@ -20,12 +20,14 @@ import android.widget.RadioButton; import android.widget.TextView; import com.mapswithme.maps.Framework; +import com.mapswithme.maps.LocationState; import com.mapswithme.maps.MwmApplication; import com.mapswithme.maps.R; import com.mapswithme.maps.bookmarks.data.DistanceAndAzimut; import com.mapswithme.maps.bookmarks.data.MapObject; import com.mapswithme.maps.location.LocationHelper; import com.mapswithme.maps.routing.RoutingInfo; +import com.mapswithme.maps.routing.RoutingResultCodesProcessor; import com.mapswithme.util.UiUtils; import com.mapswithme.util.statistics.AlohaHelper; @@ -342,6 +344,12 @@ public class RoutingLayout extends FrameLayout implements CompoundButton.OnCheck return; } + if (!LocationState.isTurnedOn()) + { + onMissingLocation(); + return; + } + Location location = LocationHelper.INSTANCE.getLastLocation(); Framework.nativeBuildRoute(location.getLatitude(), location.getLongitude(), mEndPoint.getLat(), mEndPoint.getLon()); } @@ -371,6 +379,13 @@ public class RoutingLayout extends FrameLayout implements CompoundButton.OnCheck .show(); } + private void onMissingLocation() + { + Context context = getContext(); + if (context instanceof Framework.RoutingListener) + ((Framework.RoutingListener) context).onRoutingEvent(RoutingResultCodesProcessor.NO_POSITION, null); + } + @Override protected Parcelable onSaveInstanceState() {