forked from organicmaps/organicmaps
[android] Added the checking of the Location service availibility to reflect the position more quickly for user
This commit is contained in:
parent
031779253a
commit
da9d301120
6 changed files with 29 additions and 59 deletions
|
@ -1787,7 +1787,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
//TODO: try to use startActivityForResult to handle settings result back
|
||||
startActivity(intent);
|
||||
}
|
||||
}).show();
|
||||
|
|
|
@ -73,9 +73,4 @@ public class BaseActivityDelegate
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
static boolean onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
return LocationHelper.INSTANCE.onActivityResult(requestCode, resultCode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -172,13 +172,6 @@ public class BaseMwmFragmentActivity extends AppCompatActivity
|
|||
mBaseDelegate.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
if (!BaseActivityDelegate.onActivityResult(requestCode, resultCode, data))
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
protected Toolbar getToolbar()
|
||||
{
|
||||
return (Toolbar) findViewById(R.id.toolbar);
|
||||
|
|
|
@ -109,6 +109,9 @@ class AndroidNativeProvider extends BaseLocationProvider
|
|||
{
|
||||
final List<String> res = locationManager.getProviders(true /* enabledOnly */);
|
||||
res.remove(LocationManager.PASSIVE_PROVIDER);
|
||||
// On Huawei P9 Lite, when all location services are disabled OS returns "local_database" provider,
|
||||
// but it doesn't provide any locations actually, so consider it as unreliable.
|
||||
res.remove("local_database");
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@ package com.mapswithme.maps.location;
|
|||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.location.LocationManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
|
||||
|
@ -12,15 +10,7 @@ public class GPSCheck extends BroadcastReceiver
|
|||
{
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
LocationManager locationManager = (LocationManager) context.getSystemService(context.LOCATION_SERVICE);
|
||||
|
||||
if ((locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
|
||||
|| locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
|
||||
&& MwmApplication.get().isFrameworkInitialized() && MwmApplication.backgroundTracker().isForeground())
|
||||
{
|
||||
LocationHelper.INSTANCE.addLocationListener();
|
||||
LocationHelper.INSTANCE.forceRestart();
|
||||
}
|
||||
if (MwmApplication.get().isFrameworkInitialized() && MwmApplication.backgroundTracker().isForeground())
|
||||
LocationHelper.INSTANCE.checkProvidersAndStartIfNeeded();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.mapswithme.maps.location;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
@ -10,8 +11,6 @@ import android.support.annotation.NonNull;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import com.google.android.gms.common.ConnectionResult;
|
||||
import com.google.android.gms.common.GoogleApiAvailability;
|
||||
import com.mapswithme.maps.Framework;
|
||||
|
@ -29,6 +28,7 @@ import com.mapswithme.util.log.DebugLogger;
|
|||
import com.mapswithme.util.log.Logger;
|
||||
|
||||
import static com.mapswithme.maps.background.AppBackgroundTracker.*;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public enum LocationHelper
|
||||
{
|
||||
|
@ -51,7 +51,6 @@ public enum LocationHelper
|
|||
private static final long INTERVAL_NAVIGATION_PEDESTRIAN_MS = 1000;
|
||||
|
||||
private static final long STOP_DELAY_MS = 5000;
|
||||
static final int REQUEST_RESOLVE_ERROR = 101;
|
||||
|
||||
private boolean mErrorOccurred;
|
||||
|
||||
|
@ -132,13 +131,11 @@ public enum LocationHelper
|
|||
{
|
||||
mErrorOccurred = true;
|
||||
mLogger.d("onLocationError errorCode = " + errorCode);
|
||||
if (mLocationStopped)
|
||||
return;
|
||||
|
||||
nativeOnLocationError(errorCode);
|
||||
mLogger.d("nativeOnLocationError errorCode = " + errorCode +", " +
|
||||
"state machine should stop pending, current state = "
|
||||
+ LocationState.nameOf(LocationState.getMode()));
|
||||
mLogger.d("nativeOnLocationError errorCode = " + errorCode +
|
||||
", current state = " + LocationState.nameOf(LocationState.getMode()));
|
||||
stop();
|
||||
|
||||
if (mUiCallback == null)
|
||||
return;
|
||||
|
@ -455,18 +452,25 @@ public enum LocationHelper
|
|||
removeListener(mLocationListener, false);
|
||||
}
|
||||
|
||||
public boolean onActivityResult(int requestCode, int resultCode)
|
||||
void checkProvidersAndStartIfNeeded()
|
||||
{
|
||||
if (requestCode != REQUEST_RESOLVE_ERROR)
|
||||
return false;
|
||||
Context context = MwmApplication.get();
|
||||
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||
boolean networkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
|
||||
boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
|
||||
mLocationStopped = !networkEnabled && !gpsEnabled;
|
||||
mLogger.d("Providers availability: " + !mLocationStopped +
|
||||
"; network provider = " + networkEnabled + ", gps provider = " + gpsEnabled);
|
||||
|
||||
mLocationStopped = (resultCode != Activity.RESULT_OK);
|
||||
mLogger.d("onActivityResult(): success: " + !mLocationStopped);
|
||||
if (mLocationStopped)
|
||||
{
|
||||
if (LocationState.getMode() == LocationState.PENDING_POSITION)
|
||||
notifyLocationError(ERROR_DENIED);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mLocationStopped)
|
||||
LocationState.nativeSwitchToNextMode();
|
||||
|
||||
return true;
|
||||
initProvider(false);
|
||||
LocationState.nativeSwitchToNextMode();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -635,17 +639,6 @@ public enum LocationHelper
|
|||
}
|
||||
}
|
||||
|
||||
public void forceRestart()
|
||||
{
|
||||
mActive = !mListeners.isEmpty();
|
||||
if (mActive)
|
||||
{
|
||||
calcParams();
|
||||
stopInternal();
|
||||
startInternal();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually starts location polling.
|
||||
*/
|
||||
|
@ -715,11 +708,8 @@ public enum LocationHelper
|
|||
|
||||
if (!mLocationStopped)
|
||||
addListener(mLocationListener, true);
|
||||
}
|
||||
|
||||
public void addLocationListener()
|
||||
{
|
||||
addListener(mLocationListener, true);
|
||||
else
|
||||
checkProvidersAndStartIfNeeded();
|
||||
}
|
||||
|
||||
private void compareWithPreviousCallback()
|
||||
|
|
Loading…
Add table
Reference in a new issue