Dynamic creating broadcast receiver for changing gps mode.

This commit is contained in:
Vladimir Byko-Ianko 2016-08-15 15:51:57 +03:00
parent fbd8337481
commit 2e8a2c280b
2 changed files with 24 additions and 8 deletions

View file

@ -390,12 +390,5 @@
</intent-filter>
</receiver>
<receiver android:name="com.mapswithme.maps.location.GPSCheck" >
<intent-filter>
<action android:name="android.location.PROVIDERS_CHANGED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>

View file

@ -3,7 +3,9 @@ package com.mapswithme.maps.location;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.Location;
import android.location.LocationManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
@ -27,6 +29,8 @@ import com.mapswithme.util.concurrency.UiThread;
import com.mapswithme.util.log.DebugLogger;
import com.mapswithme.util.log.Logger;
import static com.mapswithme.maps.background.AppBackgroundTracker.*;
public enum LocationHelper
{
INSTANCE;
@ -59,6 +63,25 @@ public enum LocationHelper
boolean shouldNotifyLocationNotFound();
}
private final GPSCheck mReceiver = new GPSCheck();
private final OnTransitionListener mOnTransition = new OnTransitionListener()
{
@Override
public void onTransit(boolean foreground)
{
if (foreground)
{
final IntentFilter filter = new IntentFilter();
filter.addAction(LocationManager.PROVIDERS_CHANGED_ACTION);
filter.addCategory(Intent.CATEGORY_DEFAULT);
MwmApplication.get().registerReceiver(mReceiver, filter);
return;
}
MwmApplication.get().unregisterReceiver(mReceiver);
}
};
private final LocationListener mLocationListener = new LocationListener()
{
@Override
@ -150,7 +173,6 @@ public enum LocationHelper
private boolean mHighAccuracy;
private CompassData mCompassData;
@SuppressWarnings("FieldCanBeLocal")
private final LocationState.ModeChangeListener mModeChangeListener = new LocationState.ModeChangeListener()
{
@ -219,6 +241,7 @@ public enum LocationHelper
calcParams();
initProvider(false);
MwmApplication.get().backgroundTracker().addListener(mOnTransition);
}
public void initProvider(boolean forceNative)