adding a toggle for preventing the phone from falling asleep

This commit is contained in:
tibbi 2018-02-12 16:07:03 +01:00
parent d70fe4e281
commit 8386dd4286
5 changed files with 44 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import android.os.Bundle
import android.provider.MediaStore
import android.view.Menu
import android.view.MenuItem
import android.view.WindowManager
import android.webkit.MimeTypeMap
import android.widget.SeekBar
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
@ -85,6 +86,9 @@ class MainActivity : SimpleActivity(), CanvasListener {
stroke_width_bar.beVisibleIf(isStrokeWidthBarEnabled)
my_canvas.setIsStrokeWidthBarEnabled(isStrokeWidthBarEnabled)
updateTextColors(main_holder)
if (config.preventPhoneFromSleeping) {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}
override fun onPause() {
@ -92,6 +96,9 @@ class MainActivity : SimpleActivity(), CanvasListener {
config.brushColor = color
config.brushSize = strokeWidth
storeStateVariables()
if (config.preventPhoneFromSleeping) {
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}
override fun onDestroy() {

View File

@ -21,6 +21,7 @@ class SettingsActivity : SimpleActivity() {
setupCustomizeColors()
setupUseEnglish()
setupAvoidWhatsNew()
setupPreventPhoneFromSleeping()
setupBrushSize()
updateTextColors(settings_holder)
}
@ -49,6 +50,14 @@ class SettingsActivity : SimpleActivity() {
}
}
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
}
}
private fun setupBrushSize() {
settings_show_brush_size.isChecked = config.showBrushSize
settings_show_brush_size_holder.setOnClickListener {

View File

@ -28,4 +28,8 @@ class Config(context: Context) : BaseConfig(context) {
var lastSaveFolder: String
get() = prefs.getString(LAST_SAVE_FOLDER, "")
set(lastSaveFolder) = prefs.edit().putString(LAST_SAVE_FOLDER, lastSaveFolder).apply()
var preventPhoneFromSleeping: Boolean
get() = prefs.getBoolean(PREVENT_PHONE_FROM_SLEEPING, true)
set(preventPhoneFromSleeping) = prefs.edit().putBoolean(PREVENT_PHONE_FROM_SLEEPING, preventPhoneFromSleeping).apply()
}

View File

@ -5,6 +5,7 @@ const val CANVAS_BACKGROUND_COLOR = "canvas_background_color"
const val SHOW_BRUSH_SIZE = "show_brush_size"
const val BRUSH_SIZE = "brush_size"
const val LAST_SAVE_FOLDER = "last_save_folder"
const val PREVENT_PHONE_FROM_SLEEPING = "prevent_phone_from_sleeping"
const val PNG = "png"
const val SVG = "svg"

View File

@ -79,6 +79,29 @@
</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>
<RelativeLayout
android:id="@+id/settings_show_brush_size_holder"
android:layout_width="match_parent"