4747
4848public class MainActivity extends Activity implements View .OnClickListener , View .OnLongClickListener {
4949 private final int FLAG_LAUNCH_APP = 0 ;
50+ private final int LOCK_SCREEN_TIMEOUT = 5000 ; // 5 seconds
5051 private final List <AppModel > appList = new ArrayList <>();
5152
5253 private Prefs prefs ;
@@ -407,11 +408,12 @@ private void showLockPopup() {
407408 private void setScreenTimeout () {
408409 try {
409410 int screenTimeoutInMillis = Settings .System .getInt (getContentResolver (), Settings .System .SCREEN_OFF_TIMEOUT );
410- if (screenTimeoutInMillis >= 5000 ) prefs .setScreenTimeout (screenTimeoutInMillis );
411+ if (screenTimeoutInMillis >= LOCK_SCREEN_TIMEOUT )
412+ prefs .setScreenTimeout (screenTimeoutInMillis );
411413 } catch (Settings .SettingNotFoundException e ) {
412414 e .printStackTrace ();
413415 }
414- Settings .System .putInt (getContentResolver (), Settings .System .SCREEN_OFF_TIMEOUT , 5000 );
416+ Settings .System .putInt (getContentResolver (), Settings .System .SCREEN_OFF_TIMEOUT , LOCK_SCREEN_TIMEOUT );
415417 }
416418
417419 private void hideNavBar () {
@@ -426,8 +428,17 @@ private void hideNavBar() {
426428 }
427429
428430 private void showNavBarAndResetScreenTimeout () {
429- if (Settings .System .canWrite (this ))
430- Settings .System .putInt (getContentResolver (), Settings .System .SCREEN_OFF_TIMEOUT , prefs .getScreenTimeout ());
431+ try {
432+ if (Settings .System .canWrite (this )) {
433+ int screenTimeoutInMillis = Settings .System .getInt (getContentResolver (), Settings .System .SCREEN_OFF_TIMEOUT );
434+ if (screenTimeoutInMillis <= LOCK_SCREEN_TIMEOUT )
435+ Settings .System .putInt (getContentResolver (), Settings .System .SCREEN_OFF_TIMEOUT , prefs .getScreenTimeout ());
436+ else
437+ Settings .System .putInt (getContentResolver (), Settings .System .SCREEN_OFF_TIMEOUT , screenTimeoutInMillis );
438+ }
439+ } catch (Settings .SettingNotFoundException e ) {
440+ e .printStackTrace ();
441+ }
431442 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
432443 getWindow ().getInsetsController ().show (WindowInsets .Type .navigationBars ());
433444 } else
0 commit comments