diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 11e8073bfa0..6c28de816c7 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -311,7 +311,6 @@ public void onCreate(Bundle savedInstanceState) { app.getAidlApi().onCreateMapActivity(this); lockHelper.setLockUIAdapter(this); - lockHelper.addLockScreenListener(this); keyEventHelper.setMapActivity(this); mIsDestroyed = false; if (mapViewWithLayers != null) { @@ -559,7 +558,6 @@ protected void onResume() { return; } importHelper.setUiActivity(this); - lockHelper.setMapActivity(this); long time = System.currentTimeMillis(); FragmentManager fragmentManager = getSupportFragmentManager(); @@ -964,7 +962,6 @@ protected void onDestroy() { mapViewWithLayers.onDestroy(); } lockHelper.setLockUIAdapter(null); - lockHelper.removeLockScreenListener(); keyEventHelper.setMapActivity(null); extendedMapActivity.onDestroy(this); diff --git a/OsmAnd/src/net/osmand/plus/helpers/LockHelper.java b/OsmAnd/src/net/osmand/plus/helpers/LockHelper.java index 7dd3f26dd7b..8a8a6c3119b 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/LockHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/LockHelper.java @@ -46,8 +46,6 @@ public class LockHelper implements SensorEventListener, StateChangedListener turnScreenOnTime; private CommonPreference turnScreenOnSensor; private CommonPreference useSystemScreenTimeout; @@ -78,6 +76,7 @@ public LockHelper(OsmandApplication app) { turnScreenOnPowerButton = settings.TURN_SCREEN_ON_POWER_BUTTON; turnScreenOnNavigationInstructions = settings.TURN_SCREEN_ON_NAVIGATION_INSTRUCTIONS; + settings.APPLICATION_MODE.addListener(this); lockRunnable = this::lock; voiceMessageListener = new VoiceMessageListener() { @Override @@ -136,14 +135,6 @@ public void lock() { } } - public void toggleLockScreen(){ - lockScreen = !lockScreen; - } - - public boolean isScreenLocked(){ - return lockScreen; - } - private void timedUnlock(long millis) { uiHandler.removeCallbacks(lockRunnable); if (wakeLock == null) { @@ -227,29 +218,30 @@ public void setLockUIAdapter(@Nullable LockUIAdapter adapter) { * LockScreenAction part */ - public void addLockScreenListener(@Nullable MapActivity mapActivity) { - setMapActivity(mapActivity); - app.getSettings().APPLICATION_MODE.addListener(this); + + public void toggleLockScreen() { + lockScreen = !lockScreen; + } + + public boolean isScreenLocked() { + return lockScreen; } - public void removeLockScreenListener() { - app.getSettings().APPLICATION_MODE.removeListener(this); + public void unlockScreen() { + lockScreen = false; } @Override public void stateChanged(ApplicationMode mode) { - if (mapActivity != null) { - List buttonStates = app.getMapButtonsHelper().getButtonsStates(); - ApplicationMode currentMode = app.getSettings().getApplicationMode(); - LockHelper lockHelper = app.getLockHelper(); - - if (lastApplicationMode != currentMode && lockHelper.isScreenLocked()) { - if (!hasLockScreenAction(buttonStates)) { - lockHelper.toggleLockScreen(); - } + List buttonStates = app.getMapButtonsHelper().getButtonsStates(); + ApplicationMode currentMode = app.getSettings().getApplicationMode(); + + if (isScreenLocked() && lastApplicationMode != currentMode) { + if (!hasLockScreenAction(buttonStates)) { + unlockScreen(); } - lastApplicationMode = currentMode; } + lastApplicationMode = currentMode; } private boolean hasLockScreenAction(@NonNull List mapButtonStates) { @@ -266,10 +258,6 @@ private boolean hasLockScreenAction(@NonNull List mapBut return false; } - public void setMapActivity(@Nullable MapActivity mapActivity) { - this.mapActivity = mapActivity; - } - public GestureDetector getLockGestureDetector(@NonNull MapActivity mapActivity) { if (gestureDetector == null) { gestureDetector = LockGestureDetector.getDetector(mapActivity);