Fix turn screen on/off

This commit is contained in:
max-klaus 2019-08-09 11:45:04 +03:00
parent 5b399f039b
commit aee1ab9f87
2 changed files with 19 additions and 2 deletions

View file

@ -909,6 +909,13 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
} }
} }
public void setKeepScreenOn(boolean keepScreenOn) {
View mainView = findViewById(R.id.MapViewWithLayers);
if (mainView != null) {
mainView.setKeepScreenOn(keepScreenOn);
}
}
private void clearIntent(Intent intent) { private void clearIntent(Intent intent) {
intent.setAction(null); intent.setAction(null);
intent.setData(null); intent.setData(null);
@ -1397,6 +1404,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
} }
public void updateApplicationModeSettings() { public void updateApplicationModeSettings() {
changeKeyguardFlags(true);
updateMapSettings(); updateMapSettings();
mapViewTrackingUtilities.updateSettings(); mapViewTrackingUtilities.updateSettings();
//app.getRoutingHelper().setAppMode(settings.getApplicationMode()); //app.getRoutingHelper().setAppMode(settings.getApplicationMode());
@ -1898,8 +1906,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
if (enable) { if (enable) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED, getWindow().setFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED,
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
setKeepScreenOn(true);
} else { } else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
setKeepScreenOn(false);
} }
} }
@ -1976,12 +1986,14 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
@Override @Override
public void routeWasCancelled() { public void routeWasCancelled() {
changeKeyguardFlags(true);
} }
@Override @Override
public void routeWasFinished() { public void routeWasFinished() {
if (!mIsDestroyed) { if (!mIsDestroyed) {
DestinationReachedMenu.show(this); DestinationReachedMenu.show(this);
changeKeyguardFlags(true);
} }
} }

View file

@ -28,6 +28,7 @@ public class LockHelper implements SensorEventListener {
private Handler uiHandler; private Handler uiHandler;
private OsmandApplication app; private OsmandApplication app;
private CommonPreference<Boolean> turnScreenOn;
private CommonPreference<Integer> turnScreenOnTime; private CommonPreference<Integer> turnScreenOnTime;
private CommonPreference<Boolean> turnScreenOnSensor; private CommonPreference<Boolean> turnScreenOnSensor;
@ -91,11 +92,15 @@ public class LockHelper implements SensorEventListener {
private void lock() { private void lock() {
releaseWakeLocks(); releaseWakeLocks();
if (lockUIAdapter != null) { if (lockUIAdapter != null && isFollowingMode()) {
lockUIAdapter.lock(); lockUIAdapter.lock();
} }
} }
private boolean isFollowingMode() {
return app.getRoutingHelper().isFollowingMode();
}
private void timedUnlock(final long millis) { private void timedUnlock(final long millis) {
uiHandler.removeCallbacks(lockRunnable); uiHandler.removeCallbacks(lockRunnable);
uiHandler.post(new Runnable() { uiHandler.post(new Runnable() {
@ -149,7 +154,7 @@ public class LockHelper implements SensorEventListener {
} }
private boolean isSensorEnabled() { private boolean isSensorEnabled() {
return turnScreenOnSensor.get() && app.getRoutingHelper().isFollowingMode(); return turnScreenOnSensor.get() && isFollowingMode();
} }
public void onStart(@NonNull Activity activity) { public void onStart(@NonNull Activity activity) {