From 5b00c4b6bbe83ffabb6ad4c24a6a8dc432600ecf Mon Sep 17 00:00:00 2001 From: Josia Pietsch Date: Sun, 3 Nov 2024 16:09:48 +0100 Subject: [PATCH] Improved handling of volume buttons When the actions volume up / volume down are bound to the volume up key resp. volume down key, key presses are now completely ignored allowing other apps to bind something to those keys (this is not possible on stock Android, but with some custom ROMs or root). --- .../jrpie/android/launcher/ui/HomeActivity.kt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/de/jrpie/android/launcher/ui/HomeActivity.kt b/app/src/main/java/de/jrpie/android/launcher/ui/HomeActivity.kt index f9cf952..1f2a2c9 100644 --- a/app/src/main/java/de/jrpie/android/launcher/ui/HomeActivity.kt +++ b/app/src/main/java/de/jrpie/android/launcher/ui/HomeActivity.kt @@ -13,6 +13,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.core.view.GestureDetectorCompat import androidx.core.view.isVisible import de.jrpie.android.launcher.R +import de.jrpie.android.launcher.actions.Action import de.jrpie.android.launcher.actions.Gesture import de.jrpie.android.launcher.actions.LauncherAction import de.jrpie.android.launcher.databinding.HomeBinding @@ -186,8 +187,21 @@ class HomeActivity : UIObject, AppCompatActivity(), override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean { when (keyCode) { KeyEvent.KEYCODE_BACK -> LauncherAction.CHOOSE.launch(this) - KeyEvent.KEYCODE_VOLUME_UP -> Gesture.VOLUME_UP(this) - KeyEvent.KEYCODE_VOLUME_DOWN -> Gesture.VOLUME_DOWN(this) + KeyEvent.KEYCODE_VOLUME_UP -> { + if (Action.forGesture(Gesture.VOLUME_UP) == LauncherAction.VOLUME_UP) { + // Let the OS handle the key event. This works better with some custom ROMs + // and apps like Samsung Sound Assistant. + return false + } + Gesture.VOLUME_UP(this) + } + KeyEvent.KEYCODE_VOLUME_DOWN -> { + if (Action.forGesture(Gesture.VOLUME_DOWN) == LauncherAction.VOLUME_DOWN) { + // see above + return false + } + Gesture.VOLUME_DOWN(this) + } } return true }