adjust constant run option slightly to prevent annoying artifact

This commit is contained in:
wesaphzt 2019-09-09 20:21:24 +01:00
parent 10db550988
commit 063beba464
2 changed files with 22 additions and 29 deletions

View file

@ -3,6 +3,8 @@ package com.wesaphzt.privatelock.receivers;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import static com.wesaphzt.privatelock.service.LockService.disabled; import static com.wesaphzt.privatelock.service.LockService.disabled;
import static com.wesaphzt.privatelock.service.LockService.mInitialized; import static com.wesaphzt.privatelock.service.LockService.mInitialized;
@ -11,6 +13,8 @@ public class PresenceReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) { if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
//prevent lock animation artifacts //prevent lock animation artifacts
mInitialized = false; mInitialized = false;
@ -18,7 +22,9 @@ public class PresenceReceiver extends BroadcastReceiver {
disabled = false; disabled = false;
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
if(! prefs.getBoolean("RUN_CONSTANT", false)) {
disabled = true; disabled = true;
} }
} }
}
} }

View file

@ -87,13 +87,11 @@ public class LockService extends JobIntentService {
switch (action) { switch (action) {
case ACTION_START_FOREGROUND_SERVICE: case ACTION_START_FOREGROUND_SERVICE:
if(! prefs.getBoolean("RUN_CONSTANT", false)) {
presenceReceiver = new PresenceReceiver(); presenceReceiver = new PresenceReceiver();
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_USER_PRESENT); IntentFilter intentFilter = new IntentFilter(Intent.ACTION_USER_PRESENT);
intentFilter.addAction(Intent.ACTION_SCREEN_OFF); intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
registerReceiver(presenceReceiver, intentFilter); registerReceiver(presenceReceiver, intentFilter);
}
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------
try { try {
SENSITIVITY = prefs.getInt(MainActivity.PREFS_THRESHOLD, DEFAULT_SENSITIVITY); SENSITIVITY = prefs.getInt(MainActivity.PREFS_THRESHOLD, DEFAULT_SENSITIVITY);
@ -134,22 +132,13 @@ public class LockService extends JobIntentService {
case ACTION_STOP_FOREGROUND_SERVICE: case ACTION_STOP_FOREGROUND_SERVICE:
try { try {
if(! prefs.getBoolean("RUN_CONSTANT", false)) {
unregisterReceiver(presenceReceiver);
}
mSensorManager.unregisterListener(activeListener); mSensorManager.unregisterListener(activeListener);
disabled = true;
mInitialized = false;
if (PauseReceiver.isRunning) {
PauseReceiver.mCountdown.cancel();
PauseReceiver.isRunning = false;
}
} catch (Exception e) { } catch (Exception e) {
if(! prefs.getBoolean("RUN_CONSTANT", false)) { e.printStackTrace();
unregisterReceiver(presenceReceiver);
} }
unregisterReceiver(presenceReceiver);
disabled = true; disabled = true;
mInitialized = false; mInitialized = false;
@ -157,7 +146,6 @@ public class LockService extends JobIntentService {
PauseReceiver.mCountdown.cancel(); PauseReceiver.mCountdown.cancel();
PauseReceiver.isRunning = false; PauseReceiver.isRunning = false;
} }
}
try { try {
NotificationManager notificationManager = NotificationManager notificationManager =
@ -169,8 +157,7 @@ public class LockService extends JobIntentService {
notificationManager.cancel(LockService.NOTIFICATION_ID); notificationManager.cancel(LockService.NOTIFICATION_ID);
} }
} catch (Exception e) { } catch (Exception e) {
lockWidgetProvider.setWidgetStop(context); e.printStackTrace();
stopService(intent);
} }
lockWidgetProvider.setWidgetStop(context); lockWidgetProvider.setWidgetStop(context);