Skip to content

Commit

Permalink
Merge pull request #21565 from osmandapp/reset_lock_timer_on_interact…
Browse files Browse the repository at this point in the history
…ions

Reset lock timer on screen interactions
  • Loading branch information
Chumva authored Dec 17, 2024
2 parents ed1f8ee + c9515fb commit 8836ef2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
4 changes: 4 additions & 0 deletions OsmAnd/src/net/osmand/plus/activities/MapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,10 @@ public boolean dispatchTouchEvent(MotionEvent event) {
return lockHelper.getLockGestureDetector(this).onTouchEvent(event);
}

if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
lockHelper.resetLockTimerIfNeeded();
}

if (settings.DO_NOT_USE_ANIMATIONS.get()) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
Expand Down
50 changes: 32 additions & 18 deletions OsmAnd/src/net/osmand/plus/helpers/LockHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.provider.Settings;
Expand All @@ -18,6 +19,7 @@

import net.osmand.PlatformUtil;
import net.osmand.StateChangedListener;
import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction;
Expand All @@ -36,6 +38,7 @@
public class LockHelper implements SensorEventListener, StateChangedListener<ApplicationMode> {

private static final Log LOG = PlatformUtil.getLog(LockHelper.class);
private static final int LOCK_SCREEN_MESSAGE = OsmAndConstants.UI_HANDLER_MAP_VIEW + 8;

private static final int SENSOR_SENSITIVITY = 4;

Expand Down Expand Up @@ -78,24 +81,20 @@ public LockHelper(OsmandApplication app) {

settings.APPLICATION_MODE.addListener(this);
lockRunnable = this::lock;
voiceMessageListener = new VoiceMessageListener() {
@Override
public void onVoiceMessage(List<String> listCommands, List<String> played) {
if (turnScreenOnNavigationInstructions.get()) {
unlockEvent();
}

voiceMessageListener = (listCommands, played) -> {
if (turnScreenOnNavigationInstructions.get()) {
unlockEvent();
}
};
OsmAndAppCustomizationListener customizationListener = new OsmAndAppCustomizationListener() {
@Override
public void onOsmAndSettingsCustomized() {
OsmandSettings settings = app.getSettings();
turnScreenOnTime = settings.TURN_SCREEN_ON_TIME_INT;
turnScreenOnSensor = settings.TURN_SCREEN_ON_SENSOR;
useSystemScreenTimeout = settings.USE_SYSTEM_SCREEN_TIMEOUT;
turnScreenOnPowerButton = settings.TURN_SCREEN_ON_POWER_BUTTON;
turnScreenOnNavigationInstructions = settings.TURN_SCREEN_ON_NAVIGATION_INSTRUCTIONS;
}

OsmAndAppCustomizationListener customizationListener = () -> {
OsmandSettings osmSettings = app.getSettings();
turnScreenOnTime = osmSettings.TURN_SCREEN_ON_TIME_INT;
turnScreenOnSensor = osmSettings.TURN_SCREEN_ON_SENSOR;
useSystemScreenTimeout = osmSettings.USE_SYSTEM_SCREEN_TIMEOUT;
turnScreenOnPowerButton = osmSettings.TURN_SCREEN_ON_POWER_BUTTON;
turnScreenOnNavigationInstructions = osmSettings.TURN_SCREEN_ON_NAVIGATION_INSTRUCTIONS;
};
app.getAppCustomization().addListener(customizationListener);
app.getRoutingHelper().getVoiceRouter().addVoiceMessageListener(voiceMessageListener);
Expand Down Expand Up @@ -145,7 +144,7 @@ private void timedUnlock(long millis) {
});
}
if (millis > 0) {
uiHandler.postDelayed(lockRunnable, millis);
sendPostDelayedLockMessage(millis);
}
}

Expand All @@ -158,6 +157,22 @@ private void unlockEvent() {
}
}

public void resetLockTimerIfNeeded() {
if (uiHandler.hasMessages(LOCK_SCREEN_MESSAGE)) {
uiHandler.removeCallbacks(lockRunnable);
int unlockTime = getUnlockTime();
if (unlockTime > 0) {
sendPostDelayedLockMessage(unlockTime * 1000L);
}
}
}

private void sendPostDelayedLockMessage(long delayMillis){
Message message = Message.obtain(uiHandler, lockRunnable);
message.what = LOCK_SCREEN_MESSAGE;
uiHandler.sendMessageDelayed(message, delayMillis);
}

private int getUnlockTime() {
int unlockTime = turnScreenOnTime.get();
if (useSystemScreenTimeout.get()) {
Expand Down Expand Up @@ -218,7 +233,6 @@ public void setLockUIAdapter(@Nullable LockUIAdapter adapter) {
* LockScreenAction part
*/


public void toggleLockScreen() {
lockScreen = !lockScreen;
}
Expand Down

0 comments on commit 8836ef2

Please sign in to comment.