mirror of
https://github.com/SimpleMobileTools/Simple-Calculator.git
synced 2024-12-27 15:42:34 +01:00
add a toggle for preventing the phone from sleeping
This commit is contained in:
parent
389aaac3ee
commit
8e221da298
@ -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'
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -92,5 +92,28 @@
|
||||
android:text="@string/vibrate_on_button_press"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_prevent_phone_from_sleeping_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/medium_margin"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingLeft="@dimen/normal_margin"
|
||||
android:paddingRight="@dimen/normal_margin"
|
||||
android:paddingTop="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MySwitchCompat
|
||||
android:id="@+id/settings_prevent_phone_from_sleeping"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:paddingLeft="@dimen/medium_margin"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/prevent_phone_from_sleeping"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
Loading…
Reference in New Issue
Block a user