Skip to content

Commit

Permalink
Fixed: screen timeout resetting to 30 seconds if double tap lock is e…
Browse files Browse the repository at this point in the history
…nabled
  • Loading branch information
tanujnotes committed Dec 28, 2020
1 parent 0dbd928 commit 2d80cc0
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions app/src/main/java/app/olauncher/light/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

public class MainActivity extends Activity implements View.OnClickListener, View.OnLongClickListener {
private final int FLAG_LAUNCH_APP = 0;
private final int LOCK_SCREEN_TIMEOUT = 5000; // 5 seconds
private final List<AppModel> appList = new ArrayList<>();

private Prefs prefs;
Expand Down Expand Up @@ -407,11 +408,12 @@ private void showLockPopup() {
private void setScreenTimeout() {
try {
int screenTimeoutInMillis = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT);
if (screenTimeoutInMillis >= 5000) prefs.setScreenTimeout(screenTimeoutInMillis);
if (screenTimeoutInMillis >= LOCK_SCREEN_TIMEOUT)
prefs.setScreenTimeout(screenTimeoutInMillis);
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 5000);
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, LOCK_SCREEN_TIMEOUT);
}

private void hideNavBar() {
Expand All @@ -426,8 +428,17 @@ private void hideNavBar() {
}

private void showNavBarAndResetScreenTimeout() {
if (Settings.System.canWrite(this))
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, prefs.getScreenTimeout());
try {
if (Settings.System.canWrite(this)) {
int screenTimeoutInMillis = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT);
if (screenTimeoutInMillis <= LOCK_SCREEN_TIMEOUT)
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, prefs.getScreenTimeout());
else
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, screenTimeoutInMillis);
}
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
getWindow().getInsetsController().show(WindowInsets.Type.navigationBars());
} else
Expand Down

0 comments on commit 2d80cc0

Please sign in to comment.