From 8e221da29835848e3ce7d9cdc1082fe7012ef1b2 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 27 Feb 2018 20:43:15 +0100 Subject: [PATCH] add a toggle for preventing the phone from sleeping --- app/build.gradle | 2 +- .../calculator/activities/MainActivity.kt | 9 ++++++++ .../calculator/activities/SettingsActivity.kt | 9 ++++++++ app/src/main/res/layout/activity_settings.xml | 23 +++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 51eacb87..5822d1d0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -43,7 +43,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:3.13.15' + implementation 'com.simplemobiletools:commons:3.13.16' implementation 'me.grantland:autofittextview:0.2.1' testImplementation 'junit:junit:4.12' diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/MainActivity.kt index 00863ecc..c5f168e5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/MainActivity.kt @@ -6,6 +6,7 @@ import android.os.Bundle import android.view.Menu import android.view.MenuItem import android.view.View +import android.view.WindowManager import com.simplemobiletools.calculator.BuildConfig import com.simplemobiletools.calculator.R import com.simplemobiletools.calculator.extensions.config @@ -69,12 +70,20 @@ class MainActivity : SimpleActivity(), Calculator { if (storedTextColor != config.textColor) { updateViewColors(calculator_holder, config.textColor) } + + if (config.preventPhoneFromSleeping) { + window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + } + vibrateOnButtonPress = config.vibrateOnButtonPress } override fun onPause() { super.onPause() storeStateVariables() + if (config.preventPhoneFromSleeping) { + window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + } } override fun onCreateOptionsMenu(menu: Menu): Boolean { diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/SettingsActivity.kt index 33aa3cfc..2440a30a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/SettingsActivity.kt @@ -23,6 +23,7 @@ class SettingsActivity : SimpleActivity() { setupUseEnglish() setupAvoidWhatsNew() setupVibrate() + setupPreventPhoneFromSleeping() updateTextColors(settings_scrollview) } @@ -57,4 +58,12 @@ class SettingsActivity : SimpleActivity() { config.vibrateOnButtonPress = settings_vibrate.isChecked } } + + private fun setupPreventPhoneFromSleeping() { + settings_prevent_phone_from_sleeping.isChecked = config.preventPhoneFromSleeping + settings_prevent_phone_from_sleeping_holder.setOnClickListener { + settings_prevent_phone_from_sleeping.toggle() + config.preventPhoneFromSleeping = settings_prevent_phone_from_sleeping.isChecked + } + } } diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 3d260a7e..a8a6d147 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -92,5 +92,28 @@ android:text="@string/vibrate_on_button_press"/> + + + + + +