[Android] Video controls: add a way do disable double tap to play/pause

Nicolas Pomepuy git at videolan.org
Thu Nov 18 08:14:35 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Nov 17 08:14:23 2021 +0100| [cccaf5060228b9009f06549bb42a64910c5a89c8] | committer: Nicolas Pomepuy

Video controls: add a way do disable double tap to play/pause

Fixes #1262

> https://code.videolan.org/videolan/vlc-android/commit/cccaf5060228b9009f06549bb42a64910c5a89c8
---

 application/resources/src/main/res/values/strings.xml    |  2 ++
 .../tools/src/main/java/org/videolan/tools/Settings.kt   |  1 +
 .../vlc-android/res/xml/preferences_video_controls.xml   |  6 ++++++
 .../vlc/gui/preferences/PreferencesVideoControls.kt      |  1 +
 .../org/videolan/vlc/gui/video/VideoPlayerActivity.kt    |  5 +++--
 .../src/org/videolan/vlc/gui/video/VideoTouchDelegate.kt | 16 ++++++----------
 6 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 63412fc38..7d7ef96a5 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -332,6 +332,8 @@
     <string name="enable_android_auto_seek_buttons_summary">Show rewind and fast forward in the overflow menu. Try holding steering wheel previous and next buttons before enabling.</string>
     <string name="enable_double_tap_seek_title">Double tap to seek</string>
     <string name="enable_double_tap_seek_summary">Double tap on screen edges to seek by 10 seconds</string>
+    <string name="enable_double_tap_play_title">Double tap to play/pause</string>
+    <string name="enable_double_tap_play_summary">Double tap on screen center to play or pause</string>
     <string name="popup_keepscreen_title">Keep screen ON in Pop-Up mode</string>
     <string name="popup_keepscreen_summary">Always keep screen ON while Pop-Up is displayed, even if video is paused.</string>
     <string name="browser_show_hidden_files_title">Show hidden files</string>
diff --git a/application/tools/src/main/java/org/videolan/tools/Settings.kt b/application/tools/src/main/java/org/videolan/tools/Settings.kt
index c9044b1a1..bd308e816 100644
--- a/application/tools/src/main/java/org/videolan/tools/Settings.kt
+++ b/application/tools/src/main/java/org/videolan/tools/Settings.kt
@@ -118,6 +118,7 @@ const val VIDEO_RESUME_URI = "VideoResumeUri"
 const val AUDIO_BOOST = "audio_boost"
 const val ENABLE_SEEK_BUTTONS = "enable_seek_buttons"
 const val ENABLE_DOUBLE_TAP_SEEK = "enable_double_tap_seek"
+const val ENABLE_DOUBLE_TAP_PLAY = "enable_double_tap_play"
 const val ENABLE_VOLUME_GESTURE = "enable_volume_gesture"
 const val ENABLE_BRIGHTNESS_GESTURE = "enable_brightness_gesture"
 const val SAVE_BRIGHTNESS = "save_brightness"
diff --git a/application/vlc-android/res/xml/preferences_video_controls.xml b/application/vlc-android/res/xml/preferences_video_controls.xml
index 57755a8e5..cafc339af 100644
--- a/application/vlc-android/res/xml/preferences_video_controls.xml
+++ b/application/vlc-android/res/xml/preferences_video_controls.xml
@@ -31,6 +31,12 @@
                 android:summary="@string/enable_double_tap_seek_summary"
                 android:title="@string/enable_double_tap_seek_title"
                 app:singleLineTitle="false" />
+        <CheckBoxPreference
+                android:defaultValue="true"
+                android:key="enable_double_tap_play"
+                android:summary="@string/enable_double_tap_play_summary"
+                android:title="@string/enable_double_tap_play_title"
+                app:singleLineTitle="false" />
         <org.videolan.vlc.gui.view.NumberPickerPreference
                 android:defaultValue="10"
                 android:dependency="enable_double_tap_seek"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideoControls.kt b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideoControls.kt
index 07d5e0ad1..3f4ac0250 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideoControls.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideoControls.kt
@@ -46,6 +46,7 @@ class PreferencesVideoControls : BasePreferenceFragment(), SharedPreferences.OnS
         findPreference<Preference>(POPUP_KEEPSCREEN)?.isVisible = !AndroidUtil.isOOrLater
         findPreference<Preference>(AUDIO_BOOST)?.isVisible = !AndroidDevices.isAndroidTv
         findPreference<Preference>(ENABLE_DOUBLE_TAP_SEEK)?.isVisible = !AndroidDevices.isAndroidTv
+        findPreference<Preference>(ENABLE_DOUBLE_TAP_PLAY)?.isVisible = !AndroidDevices.isAndroidTv
         findPreference<Preference>(ENABLE_VOLUME_GESTURE)?.isVisible = AndroidDevices.hasTsp
         findPreference<Preference>(ENABLE_BRIGHTNESS_GESTURE)?.isVisible = AndroidDevices.hasTsp
         findPreference<Preference>(POPUP_KEEPSCREEN)?.isVisible = !AndroidDevices.isAndroidTv && !AndroidUtil.isOOrLater
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
index 3e4dd94a6..3db6e39be 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -493,7 +493,8 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
         val brightnessTouch = !AndroidDevices.isChromeBook && settings.getBoolean(ENABLE_BRIGHTNESS_GESTURE, true)
         ((if (audioTouch) TOUCH_FLAG_AUDIO_VOLUME else 0)
                 + (if (brightnessTouch) TOUCH_FLAG_BRIGHTNESS else 0)
-                + if (settings.getBoolean(ENABLE_DOUBLE_TAP_SEEK, true)) TOUCH_FLAG_SEEK else 0)
+                + (if (settings.getBoolean(ENABLE_DOUBLE_TAP_SEEK, true)) TOUCH_FLAG_SEEK else 0)
+                + (if (settings.getBoolean(ENABLE_DOUBLE_TAP_PLAY, true)) TOUCH_FLAG_PLAY else 0))
     } else 0
 
     override fun fireDialog(dialog: Dialog) {
@@ -2160,7 +2161,7 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
      */
     fun onChangedControlSetting(key: String) = when(key) {
         AUDIO_BOOST -> isAudioBoostEnabled = settings.getBoolean(AUDIO_BOOST, true)
-        ENABLE_VOLUME_GESTURE, ENABLE_BRIGHTNESS_GESTURE, ENABLE_DOUBLE_TAP_SEEK -> touchDelegate.touchControls = generateTouchFlags()
+        ENABLE_VOLUME_GESTURE, ENABLE_BRIGHTNESS_GESTURE, ENABLE_DOUBLE_TAP_SEEK, ENABLE_DOUBLE_TAP_PLAY -> touchDelegate.touchControls = generateTouchFlags()
         ENABLE_SEEK_BUTTONS -> overlayDelegate.seekButtons = settings.getBoolean(ENABLE_SEEK_BUTTONS, false)
         else -> {}
     }
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoTouchDelegate.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoTouchDelegate.kt
index 58d87e88d..59f129cbd 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoTouchDelegate.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoTouchDelegate.kt
@@ -33,6 +33,7 @@ import kotlin.math.sign
 const val TOUCH_FLAG_AUDIO_VOLUME = 1
 const val TOUCH_FLAG_BRIGHTNESS = 1 shl 1
 const val TOUCH_FLAG_SEEK = 1 shl 2
+const val TOUCH_FLAG_PLAY = 1 shl 3
 //Touch Events
 private const val TOUCH_NONE = 0
 private const val TOUCH_VOLUME = 1
@@ -217,16 +218,11 @@ class VideoTouchDelegate(private val player: VideoPlayerActivity,
 
                         //handle multi taps
                         if (numberOfTaps > 1 && !player.isLocked) {
-                            if (touchControls and TOUCH_FLAG_SEEK == 0) {
-                                player.doPlayPause()
-                            } else {
-                                val range = (if (screenConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) screenConfig.xRange else screenConfig.yRange).toFloat()
-                                if (BuildConfig.DEBUG) Log.d("VideoTouchDelegate", "Landscape: ${screenConfig.orientation == Configuration.ORIENTATION_LANDSCAPE} range: $range eventx: ${event.x}")
-                                when {
-                                    event.x < range / 4f -> seekDelta(-org.videolan.tools.Settings.videoDoubleTapJumpDelay * 1000)
-                                    event.x > range * 0.75 -> seekDelta(org.videolan.tools.Settings.videoDoubleTapJumpDelay * 1000)
-                                    else -> player.doPlayPause()
-                                }
+                            val range = (if (screenConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) screenConfig.xRange else screenConfig.yRange).toFloat()
+                            when {
+                                (touchControls and TOUCH_FLAG_SEEK != 0) && event.x < range / 4f -> seekDelta(-org.videolan.tools.Settings.videoDoubleTapJumpDelay * 1000)
+                                (touchControls and TOUCH_FLAG_SEEK != 0) && event.x > range * 0.75 -> seekDelta(org.videolan.tools.Settings.videoDoubleTapJumpDelay * 1000)
+                                else -> if (touchControls and TOUCH_FLAG_PLAY != 0) player.doPlayPause()
                             }
                         }
 



More information about the Android mailing list