Merge pull request #937 from jtrax/bugfixes

Fixed turn on the screen algorithm
This commit is contained in:
vshcherb 2014-10-31 14:41:14 +01:00
commit 9539a10d24

View file

@ -112,10 +112,9 @@ public class MapActivity extends AccessibleActivity implements
private StateChangedListener<ApplicationMode> applicationModeListener; private StateChangedListener<ApplicationMode> applicationModeListener;
private FrameLayout lockView; private FrameLayout lockView;
private GpxImportHelper gpxImportHelper; private GpxImportHelper gpxImportHelper;
private Long lastWakeOnTime = 0l;
private PowerManager.WakeLock wakeLock = null; private PowerManager.WakeLock wakeLock = null;
private KeyguardManager.KeyguardLock keyguardLock = null; private KeyguardManager.KeyguardLock keyguardLock = null;
private ReleaseWakeLocksRunnable releaseWakeLocksRunnable = new ReleaseWakeLocksRunnable();
private Notification getNotification() { private Notification getNotification() {
Intent notificationIndent = new Intent(this, getMyApplication().getAppCustomization().getMapActivity()); Intent notificationIndent = new Intent(this, getMyApplication().getAppCustomization().getMapActivity());
@ -783,7 +782,8 @@ public class MapActivity extends AccessibleActivity implements
@Override @Override
public void onVoiceMessage() { public void onVoiceMessage() {
if (settings.WAKE_ON_VOICE.get()) { if (settings.WAKE_ON_VOICE.get()) {
lastWakeOnTime = System.currentTimeMillis(); uiHandler.removeCallbacks(releaseWakeLocksRunnable);
if (wakeLock == null) { if (wakeLock == null) {
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK wakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK
@ -797,19 +797,11 @@ public class MapActivity extends AccessibleActivity implements
keyguardLock.disableKeyguard(); keyguardLock.disableKeyguard();
} }
uiHandler.postDelayed(new Runnable() { uiHandler.postDelayed(releaseWakeLocksRunnable, WAKE_ON_VOICE_INTERVAL);
@Override
public void run() {
releaseWakeLocks();
}
}, WAKE_ON_VOICE_INTERVAL);
} }
} }
private void releaseWakeLocks() { private void releaseWakeLocks() {
long now = System.currentTimeMillis();
if (now >= lastWakeOnTime) {
if (keyguardLock != null) { if (keyguardLock != null) {
keyguardLock.reenableKeyguard(); keyguardLock.reenableKeyguard();
keyguardLock = null; keyguardLock = null;
@ -819,5 +811,12 @@ public class MapActivity extends AccessibleActivity implements
wakeLock = null; wakeLock = null;
} }
} }
private class ReleaseWakeLocksRunnable implements Runnable {
@Override
public void run() {
releaseWakeLocks();
}
} }
} }