Skip to content

Commit

Permalink
Prevent screensaver while route navigation is active
Browse files Browse the repository at this point in the history
  • Loading branch information
shinovon committed Jun 23, 2023
1 parent a6f691b commit 7982234
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/mahomaps/DeviceControlInvoker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package mahomaps;

import com.nokia.mid.ui.DeviceControl;

public class DeviceControlInvoker {

public static boolean supported;

static {
try {
if (System.getProperty("com.nokia.mid.ui.version") != null &&
System.getProperty("com.nokia.mid.ui.screensaverprevention") != null) {
Class.forName("com.nokia.mid.ui.DeviceControl");
supported = true;
}
} catch (Exception e) {
}
}

public static void resetUserInactivityTime() {
if (!supported) return;
try {
DeviceControl.resetUserInactivityTime();
} catch (Throwable e) {
}
}

}
7 changes: 7 additions & 0 deletions src/mahomaps/screens/MapCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.TextBox;

import mahomaps.DeviceControlInvoker;
import mahomaps.FpsLimiter;
import mahomaps.MahoMapsApp;
import mahomaps.Settings;
Expand Down Expand Up @@ -59,6 +60,8 @@ public class MapCanvas extends MultitouchCanvas implements CommandListener {
public final FpsLimiter repaintGate = new FpsLimiter();
private Graphics cachedGraphics;

private long lastResetTime;

public MapCanvas(TilesProvider tiles) {
this.tiles = tiles;
setFullScreenMode(true);
Expand Down Expand Up @@ -325,6 +328,10 @@ public void run() throws InterruptedException {
repaint(g);
flushGraphics();
repaintGate.End(rt != null ? 33 : 2000);
if (rt != null && System.currentTimeMillis() - lastResetTime > 15000L) {
DeviceControlInvoker.resetUserInactivityTime();
lastResetTime = System.currentTimeMillis();
}
}
}
}
Expand Down

0 comments on commit 7982234

Please sign in to comment.