diff --git a/app/build.gradle b/app/build.gradle index 51eacb8..5822d1d 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 00863ec..c5f168e 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 33aa3cf..2440a30 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 3d260a7..a8a6d14 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"/> + + + + + +