Add menu entry to keep screen on
This commit is contained in:
@@ -6,6 +6,7 @@ import android.os.Bundle
|
||||
import android.text.InputType
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.WindowManager
|
||||
import android.widget.ScrollView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
@@ -31,6 +32,12 @@ class MainActivity : AppCompatActivity() {
|
||||
inputTeamA.requestFocus()
|
||||
disableSubmitButton()
|
||||
updateTheme(this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getInt("Theme", 2))
|
||||
keepScreenOn(
|
||||
this.getSharedPreferences("Settings", Context.MODE_PRIVATE)
|
||||
.getBoolean("Screen_On", false)
|
||||
)
|
||||
|
||||
|
||||
|
||||
history = savedInstanceState?.getParcelable("history") ?: History()
|
||||
updateView()
|
||||
@@ -265,9 +272,14 @@ class MainActivity : AppCompatActivity() {
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
menuInflater.inflate(R.menu.menu_main, menu)
|
||||
|
||||
menu.findItem(R.id.action_screenOn).isChecked =
|
||||
this.getSharedPreferences("Settings", Context.MODE_PRIVATE)
|
||||
.getBoolean("Screen_On", false)
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.action_clear -> {
|
||||
@@ -282,6 +294,11 @@ class MainActivity : AppCompatActivity() {
|
||||
chooseThemeDialog()
|
||||
true
|
||||
}
|
||||
R.id.action_screenOn -> {
|
||||
item.isChecked = !item.isChecked
|
||||
keepScreenOn(item.isChecked)
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
@@ -381,4 +398,16 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
delegate.applyDayNight()
|
||||
}
|
||||
|
||||
private fun keepScreenOn(keepOn: Boolean) {
|
||||
if (keepOn) {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
} else {
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
|
||||
val prefs = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).edit()
|
||||
prefs.putBoolean("Screen_On", keepOn)
|
||||
prefs.apply()
|
||||
}
|
||||
}
|
||||
@@ -17,4 +17,9 @@
|
||||
android:id="@+id/action_theme"
|
||||
android:orderInCategory="15"
|
||||
android:title="@string/choose_theme_text" />
|
||||
<item
|
||||
android:id="@+id/action_screenOn"
|
||||
android:checkable="true"
|
||||
android:orderInCategory="20"
|
||||
android:title="@string/keep_screen_on" />
|
||||
</menu>
|
||||
@@ -3,4 +3,5 @@
|
||||
<string name="clear">Neues Spiel Starten</string>
|
||||
<string name="undo">Letzte Runde Löschen</string>
|
||||
<string name="choose_theme_text">Theme auswählen</string>
|
||||
<string name="keep_screen_on">Bildschirm eingeschaltet lassen</string>
|
||||
</resources>
|
||||
@@ -3,4 +3,5 @@
|
||||
<string name="clear">Neus Spil Starte</string>
|
||||
<string name="undo">Letschti Rundi Lösche</string>
|
||||
<string name="choose_theme_text">Usgsehe ändere</string>
|
||||
<string name="keep_screen_on">Bildschirm igschalted la</string>
|
||||
</resources>
|
||||
@@ -7,4 +7,5 @@
|
||||
<string name="clear">Start New Game</string>
|
||||
<string name="undo">Undo Last Round</string>
|
||||
<string name="choose_theme_text">Choose theme</string>
|
||||
<string name="keep_screen_on">Keep screen on</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user