[android] Fixed location state changes after location settings are modified from dialog.

This commit is contained in:
Dmitry Yunitsky 2016-05-10 18:31:51 +03:00 committed by Vladimir Byko-Ianko
parent ebfab8d0e0
commit 3020074f00
3 changed files with 52 additions and 56 deletions

View file

@ -918,16 +918,22 @@ public class MwmActivity extends BaseMwmFragmentActivity
protected void onResume()
{
super.onResume();
LocationState.INSTANCE.nativeSetListener(this);
refreshLocationState();
mMainMenu.getMyPositionButton().update(LocationState.INSTANCE.nativeGetMode());
resumeLocation();
mSearchController.refreshToolbar();
mMainMenu.onResume();
mOnmapDownloader.onResume();
}
private void resumeLocation()
{
LocationHelper.INSTANCE.addLocationListener(this, true);
// Do not turn off the screen while displaying position
Utils.keepScreenOn(true, getWindow());
mLocationPredictor.resume();
}
@Override
public void recreate()
{
@ -936,39 +942,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
super.recreate();
}
private void initShowcase()
{
NativeAppwallAd.AppwallAdListener listener = new NativeAppwallAd.AppwallAdListener()
{
@Override
public void onLoad(NativeAppwallAd nativeAppwallAd)
{
if (nativeAppwallAd.getBanners().isEmpty())
{
mMainMenu.setVisible(MainMenu.Item.SHOWCASE, false);
return;
}
final NativeAppwallBanner menuBanner = nativeAppwallAd.getBanners().get(0);
mMainMenu.setShowcaseText(menuBanner.getTitle());
mMainMenu.setVisible(MainMenu.Item.SHOWCASE, true);
}
@Override
public void onNoAd(String reason, NativeAppwallAd nativeAppwallAd)
{
mMainMenu.setVisible(MainMenu.Item.SHOWCASE, false);
}
@Override
public void onClick(NativeAppwallBanner nativeAppwallBanner, NativeAppwallAd nativeAppwallAd) {}
@Override
public void onDismissDialog(NativeAppwallAd nativeAppwallAd) {}
};
mMytargetHelper = new MytargetHelper(listener, this);
}
@Override
protected void onResumeFragments()
{
@ -1046,14 +1019,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
super.onPause();
}
private void resumeLocation()
{
LocationHelper.INSTANCE.addLocationListener(this, true);
// Do not turn off the screen while displaying position
Utils.keepScreenOn(true, getWindow());
mLocationPredictor.resume();
}
private void pauseLocation()
{
LocationHelper.INSTANCE.removeLocationListener(this);
@ -1062,15 +1027,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
mLocationPredictor.pause();
}
private void refreshLocationState()
{
int newMode = LocationState.INSTANCE.nativeGetMode();
mMainMenu.getMyPositionButton().update(newMode);
if (LocationState.INSTANCE.isTurnedOn())
resumeLocation();
}
@Override
protected void onStart()
{
@ -1081,6 +1037,39 @@ public class MwmActivity extends BaseMwmFragmentActivity
mRoutingPlanInplaceController.setStartButton();
}
private void initShowcase()
{
NativeAppwallAd.AppwallAdListener listener = new NativeAppwallAd.AppwallAdListener()
{
@Override
public void onLoad(NativeAppwallAd nativeAppwallAd)
{
if (nativeAppwallAd.getBanners().isEmpty())
{
mMainMenu.setVisible(MainMenu.Item.SHOWCASE, false);
return;
}
final NativeAppwallBanner menuBanner = nativeAppwallAd.getBanners().get(0);
mMainMenu.setShowcaseText(menuBanner.getTitle());
mMainMenu.setVisible(MainMenu.Item.SHOWCASE, true);
}
@Override
public void onNoAd(String reason, NativeAppwallAd nativeAppwallAd)
{
mMainMenu.setVisible(MainMenu.Item.SHOWCASE, false);
}
@Override
public void onClick(NativeAppwallBanner nativeAppwallBanner, NativeAppwallAd nativeAppwallAd) {}
@Override
public void onDismissDialog(NativeAppwallAd nativeAppwallAd) {}
};
mMytargetHelper = new MytargetHelper(listener, this);
}
@Override
protected void onStop()
{

View file

@ -43,8 +43,14 @@ class GoogleFusedLocationProvider extends BaseLocationProvider
return;
mLocationRequest = LocationRequest.create();
mLocationRequest.setPriority(LocationHelper.INSTANCE.isHighAccuracy() ? LocationRequest.PRIORITY_HIGH_ACCURACY
: LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
// mLocationRequest.setPriority(LocationHelper.INSTANCE.isHighAccuracy() ? LocationRequest.PRIORITY_HIGH_ACCURACY
// : LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
// TODO @yunikkk
// Currently there are some problems concerning location strategies switching.
// With LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY priority GPS is not used and location icon isn't shown in system navbar,
// hence it confuses user.
// We should reconsider if balanced mode is needed at all after results of tests for battery usage will arrive.
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
long interval = LocationHelper.INSTANCE.getInterval();
mLocationRequest.setInterval(interval);
mLocationRequest.setFastestInterval(interval / 2);

View file

@ -28,6 +28,7 @@ public class MyPositionButton
Statistics.INSTANCE.trackEvent(Statistics.EventName.TOOLBAR_MY_POSITION);
AlohaHelper.logClick(AlohaHelper.TOOLBAR_MY_POSITION);
LocationHelper.INSTANCE.setShouldResolveErrors(true);
LocationHelper.INSTANCE.restart(); // restart to check location settings again.
LocationState.INSTANCE.nativeSwitchToNextMode();
}
});