Skip to content

Commit

Permalink
Add options to keep screen awake
Browse files Browse the repository at this point in the history
  • Loading branch information
cyb3rko committed Dec 18, 2021
1 parent 60270de commit f5b9df8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/com/cyb3rko/logviewerforopenhab/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ internal const val PORT_CHECK = "port_check"
internal const val PORT_INT = "port_int"
internal const val REVIEW_COUNTER = "review_counter"
internal const val REVIEW_REVISION = "review_revision"
internal const val STAY_AWAKE = "stay_awake"
internal const val TEXTSIZE_AUTO = "textsize_auto"
internal const val TEXTSIZE_LANDSCAPE = "textsize_landscape"
internal const val TEXTSIZE_PORTRAIT = "textsize_PORTRAIT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class PreferenceFragment : PreferenceFragmentCompat() {
private lateinit var nightModeList: ListPreference
private lateinit var orientationList: ListPreference
private lateinit var openhabVersionList: ListPreference
private lateinit var stayAwakeSwitch: SwitchPreferenceCompat

override fun onAttach(context: Context) {
super.onAttach(context)
Expand All @@ -45,6 +46,7 @@ class PreferenceFragment : PreferenceFragmentCompat() {
openhabVersionList = findPreference(OPENHAB_VERSION)!!
hideTopbarSwitch = findPreference(HIDE_TOPBAR)!!
orientationList = findPreference(ORIENTATION)!!
stayAwakeSwitch = findPreference(STAY_AWAKE)!!
connectionOverviewSwitch = findPreference(CONNECTION_OVERVIEW_ENABLED)!!
nightModeList = findPreference(NIGHTMODE)!!
analyticsCollectionSwitch = findPreference(ANALYTICS_COLLECTION)!!
Expand All @@ -54,6 +56,7 @@ class PreferenceFragment : PreferenceFragmentCompat() {
hideTopbarSwitch.isChecked = mySPR.getBoolean(HIDE_TOPBAR, false)
orientationList.value = mySPR.getString(ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED.toString())
connectionOverviewSwitch.isChecked = mySPR.getBoolean(CONNECTION_OVERVIEW_ENABLED, true)
stayAwakeSwitch.isChecked = mySPR.getBoolean(STAY_AWAKE, true)
nightModeList.value = mySPR.getString(NIGHTMODE, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM.toString())
analyticsCollectionSwitch.isChecked = mySPR.getBoolean(ANALYTICS_COLLECTION, true)
crashlyticsCollectionSwitch.isChecked = mySPR.getBoolean(CRASHLYTICS_COLLECTION, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import android.content.pm.ActivityInfo
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.*
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
Expand Down Expand Up @@ -92,11 +89,15 @@ class WebViewFragment : Fragment() {
override fun onResume() {
super.onResume()
requireActivity().window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LOW_PROFILE
if (mySPR.getBoolean(STAY_AWAKE, true)) {
requireActivity().window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}

override fun onPause() {
super.onPause()
requireActivity().window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
requireActivity().window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}

private fun setUpWebview() {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<string name="settings_data_collection">Data Collection</string>
<string name="settings_orientation_title">Orientation</string>
<string name="settings_orientation_summary">Toggle the orientation of the app</string>
<string name="settings_stay_awake_title">Stay Awake</string>
<string name="settings_stay_awake_summary">Keep the device awake while on the log</string>
<string name="settings_connection_overview_title">Connection Overview</string>
<string name="settings_connection_overview_summary">En-/Disable the overview of recent connections in the Navigation Drawer</string>
<string name="settings_manage_connections_title">Manage Connections</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<string name="settings_data_collection">Data Collection</string>
<string name="settings_orientation_title">Orientation</string>
<string name="settings_orientation_summary">Toggle the orientation of the app</string>
<string name="settings_stay_awake_title">Stay Awake</string>
<string name="settings_stay_awake_summary">Keep the device awake while on the log</string>
<string name="settings_connection_overview_title">Connection Overview</string>
<string name="settings_connection_overview_summary">En-/Disable the overview of recent connections in the Navigation Drawer</string>
<string name="settings_manage_connections_title">Manage Connections</string>
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@
android:defaultValue=""
android:entries="@array/orientations"
android:entryValues="@array/orientations_values"
android:key="orientation"/>
android:key="orientation" />

<SwitchPreferenceCompat
android:title="@string/settings_stay_awake_title"
android:summary="@string/settings_stay_awake_summary"
app:iconSpaceReserved="false"
android:defaultValue="true"
android:key="stay_awake" />

<SwitchPreferenceCompat
android:title="@string/settings_connection_overview_title"
Expand Down

0 comments on commit f5b9df8

Please sign in to comment.