[android] Added nullifying saved location if location error is encountered

This commit is contained in:
Александр Зацепин 2019-12-11 16:25:56 +03:00 committed by Arsentiy Milchakov
parent adc619332b
commit 6b76d36ef5
3 changed files with 11 additions and 10 deletions

View file

@ -2,10 +2,10 @@ package com.mapswithme.maps.location;
import android.app.Activity;
import android.location.Location;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.mapswithme.maps.Framework;
@ -89,7 +89,7 @@ public enum LocationHelper
public void onLocationError(int errorCode)
{
mLogger.d(TAG, "onLocationError errorCode = " + errorCode, new Throwable());
mSavedLocation = null;
nativeOnLocationError(errorCode);
mLogger.d(TAG, "nativeOnLocationError errorCode = " + errorCode +
", current state = " + LocationState.nameOf(getMyPositionMode()));
@ -111,6 +111,7 @@ public enum LocationHelper
private final Logger mLogger = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.LOCATION);
@NonNull
private final Listeners<LocationListener> mListeners = new Listeners<>();
@Nullable
private Location mSavedLocation;
private MapObject mMyPosition;
private long mSavedLocationTime;

View file

@ -5,9 +5,9 @@ import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.mapswithme.maps.MwmApplication;
class SensorHelper implements SensorEventListener
@ -56,7 +56,7 @@ class SensorHelper implements SensorEventListener
void start()
{
if (mRotation != null)
if (mRotation != null && mSensorManager != null)
mSensorManager.registerListener(this, mRotation, SensorManager.SENSOR_DELAY_UI);
}

View file

@ -8,8 +8,6 @@ import android.location.Location;
import android.media.MediaPlayer;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.text.TextUtils;
import android.util.Pair;
import android.view.View;
@ -17,6 +15,8 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.MwmActivity;
import com.mapswithme.maps.R;
@ -219,10 +219,9 @@ public class NavigationController implements TrafficManager.TrafficCallback, Vie
info.nextCarDirection.setNextTurnDrawable(mNextNextTurnImage);
}
private void updatePedestrian(RoutingInfo info)
private void updatePedestrian(RoutingInfo info, @NonNull Location location)
{
Location next = info.pedestrianNextDirection;
Location location = LocationHelper.INSTANCE.getSavedLocation();
DistanceAndAzimut da = Framework.nativeGetDistanceAndAzimuthFromLatLon(next.getLatitude(), next.getLongitude(),
location.getLatitude(), location.getLongitude(),
mNorth);
@ -250,8 +249,9 @@ public class NavigationController implements TrafficManager.TrafficCallback, Vie
if (info == null)
return;
if (Framework.nativeGetRouter() == Framework.ROUTER_TYPE_PEDESTRIAN)
updatePedestrian(info);
Location location = LocationHelper.INSTANCE.getSavedLocation();
if (Framework.nativeGetRouter() == Framework.ROUTER_TYPE_PEDESTRIAN && location != null)
updatePedestrian(info, location);
else
updateVehicle(info);