Gamebar: Implement "take screenshot" in gesture quick actions menu
Signed-off-by: kenway214 <kenway214@outlook.com>
This commit is contained in:
@@ -83,11 +83,13 @@
|
||||
<item>Toggle Full/Minimal Format</item>
|
||||
<item>Start/Stop Log Capture</item>
|
||||
<item>Open GameBar Settings</item>
|
||||
<item>Take Screenshot</item>
|
||||
</string-array>
|
||||
<string-array name="gesture_function_values">
|
||||
<item>toggle_format</item>
|
||||
<item>capture_logs</item>
|
||||
<item>open_settings</item>
|
||||
<item>take_screenshot</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Long press timeouts -->
|
||||
|
||||
@@ -202,6 +202,9 @@ class GameBar private constructor(context: Context) {
|
||||
"open_settings" -> {
|
||||
openOverlaySettings()
|
||||
}
|
||||
"take_screenshot" -> {
|
||||
takeScreenshot()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1152,6 +1155,16 @@ class GameBar private constructor(context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun takeScreenshot() {
|
||||
try {
|
||||
// Trigger system screenshot using shell command
|
||||
Runtime.getRuntime().exec("input keyevent KEYCODE_SYSRQ")
|
||||
Toast.makeText(context, "Screenshot taken", Toast.LENGTH_SHORT).show()
|
||||
} catch (e: Exception) {
|
||||
Toast.makeText(context, "Failed to take screenshot", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun openOverlaySettings() {
|
||||
try {
|
||||
val intent = Intent(context, GameBarSettingsActivity::class.java)
|
||||
|
||||
@@ -278,6 +278,15 @@ class GameBarFragment : SettingsBasePreferenceFragment() {
|
||||
true
|
||||
}
|
||||
|
||||
// Single tap function change
|
||||
singleTapFunctionPref?.setOnPreferenceChangeListener { _, _ ->
|
||||
// Reload preferences to apply new function
|
||||
android.os.Handler(android.os.Looper.getMainLooper()).post {
|
||||
gameBar?.applyPreferences()
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
// Double tap enable/disable and visibility
|
||||
doubleTapEnablePref?.setOnPreferenceChangeListener { _, newValue ->
|
||||
val enabled = newValue as Boolean
|
||||
@@ -285,6 +294,15 @@ class GameBarFragment : SettingsBasePreferenceFragment() {
|
||||
true
|
||||
}
|
||||
|
||||
// Double tap function change
|
||||
doubleTapFunctionPref?.setOnPreferenceChangeListener { _, _ ->
|
||||
// Reload preferences to apply new function
|
||||
android.os.Handler(android.os.Looper.getMainLooper()).post {
|
||||
gameBar?.applyPreferences()
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
// Long press enable/disable and visibility
|
||||
longPressEnablePref?.setOnPreferenceChangeListener { _, newValue ->
|
||||
val enabled = newValue as Boolean
|
||||
@@ -293,6 +311,15 @@ class GameBarFragment : SettingsBasePreferenceFragment() {
|
||||
true
|
||||
}
|
||||
|
||||
// Long press function change
|
||||
longPressFunctionPref?.setOnPreferenceChangeListener { _, _ ->
|
||||
// Reload preferences to apply new function
|
||||
android.os.Handler(android.os.Looper.getMainLooper()).post {
|
||||
gameBar?.applyPreferences()
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
// Long press timeout
|
||||
longPressTimeoutPref?.setOnPreferenceChangeListener { _, newValue ->
|
||||
if (newValue is String) {
|
||||
|
||||
Reference in New Issue
Block a user