[android] Check location before building route.

This commit is contained in:
Dmitry Yunitsky 2015-08-24 16:33:10 +03:00 committed by Alex Zolotarev
parent 2c48d826ee
commit d7c395c9bc
2 changed files with 23 additions and 0 deletions

View file

@ -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;
}
}

View file

@ -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()
{