From 4be4bb631f366d05fa24922c9f4efae1fd724058 Mon Sep 17 00:00:00 2001 From: Koen Date: Thu, 30 Nov 2023 11:40:58 +0100 Subject: [PATCH] Fixed gesture control issues causing wrong area to have gesture controls and disabled full screen gesture when casting. --- .../views/behavior/GestureControlView.kt | 113 +++++++++--------- .../platformplayer/views/casting/CastView.kt | 3 +- .../views/video/FutoVideoPlayer.kt | 2 +- app/src/main/res/layout/view_cast.xml | 10 +- 4 files changed, 67 insertions(+), 61 deletions(-) diff --git a/app/src/main/java/com/futo/platformplayer/views/behavior/GestureControlView.kt b/app/src/main/java/com/futo/platformplayer/views/behavior/GestureControlView.kt index c4990dce..01ec06dc 100644 --- a/app/src/main/java/com/futo/platformplayer/views/behavior/GestureControlView.kt +++ b/app/src/main/java/com/futo/platformplayer/views/behavior/GestureControlView.kt @@ -6,7 +6,6 @@ import android.animation.ObjectAnimator import android.content.Context import android.graphics.drawable.Animatable import android.util.AttributeSet -import android.util.Log import android.view.GestureDetector import android.view.LayoutInflater import android.view.MotionEvent @@ -63,11 +62,15 @@ class GestureControlView : LinearLayout { private var _fullScreenFactorUp = 1.0f; private var _fullScreenFactorDown = 1.0f; + private val _gestureController: GestureDetectorCompat; + val onSeek = Event1(); val onBrightnessAdjusted = Event1(); val onSoundAdjusted = Event1(); val onToggleFullscreen = Event0(); + var fullScreenGestureEnabled = true + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { LayoutInflater.from(context).inflate(R.layout.view_gesture_controls, this, true); @@ -82,14 +85,9 @@ class GestureControlView : LinearLayout { _layoutControlsBrightness = findViewById(R.id.layout_controls_brightness); _progressBrightness = findViewById(R.id.progress_brightness); _layoutControlsFullscreen = findViewById(R.id.layout_controls_fullscreen); - } - fun setupTouchArea(view: View, layoutControls: ViewGroup? = null, background: View? = null) { - _layoutControls = layoutControls; - _background = background; - - val gestureController = GestureDetectorCompat(context, object : GestureDetector.OnGestureListener { - override fun onDown(p0: MotionEvent): Boolean { return false; } + _gestureController = GestureDetectorCompat(context, object : GestureDetector.OnGestureListener { + override fun onDown(p0: MotionEvent): Boolean { Logger.v(TAG, "onDown ${p0.x}, ${p0.y}"); return false; } override fun onShowPress(p0: MotionEvent) = Unit; override fun onSingleTapUp(p0: MotionEvent): Boolean { return false; } override fun onScroll(p0: MotionEvent, p1: MotionEvent, distanceX: Float, distanceY: Float): Boolean { @@ -112,15 +110,15 @@ class GestureControlView : LinearLayout { _fullScreenFactorDown = (_fullScreenFactorDown + adjustAmount).coerceAtLeast(0.0f).coerceAtMost(1.0f); _layoutControlsFullscreen.alpha = _fullScreenFactorDown; } else { - val rx = p0.x / width; - val ry = p0.y / height; - Logger.v(TAG, "rx = $rx, ry = $ry, _isFullScreen = $_isFullScreen") + val rx = (p0.x + p1.x) / (2 * width); + val ry = (p0.y + p1.y) / (2 * height); + Logger.v(TAG, "onScroll p0.x = ${p0.x}, p0.y = ${p0.y}, p1.x = ${p1.x}, p1.y = ${p1.y}, rx = $rx, ry = $ry, width = $width, height = $height, _isFullScreen = $_isFullScreen") if (ry > 0.1 && ry < 0.9) { - if (_isFullScreen && rx < 0.4) { + if (_isFullScreen && rx < 0.2) { startAdjustingBrightness(); - } else if (_isFullScreen && rx > 0.6) { + } else if (_isFullScreen && rx > 0.8) { startAdjustingSound(); - } else if (rx >= 0.4 && rx <= 0.6) { + } else if (fullScreenGestureEnabled && rx in 0.3..0.7) { if (_isFullScreen) { startAdjustingFullscreenDown(); } else { @@ -136,7 +134,7 @@ class GestureControlView : LinearLayout { override fun onFling(p0: MotionEvent, p1: MotionEvent, p2: Float, p3: Float): Boolean { return false; } }); - gestureController.setOnDoubleTapListener(object : GestureDetector.OnDoubleTapListener { + _gestureController.setOnDoubleTapListener(object : GestureDetector.OnDoubleTapListener { override fun onSingleTapConfirmed(ev: MotionEvent): Boolean { if (_skipping) { return false; @@ -166,52 +164,59 @@ class GestureControlView : LinearLayout { } }); - val touchListener = object : OnTouchListener { - override fun onTouch(v: View?, ev: MotionEvent): Boolean { - cancelHideJob(); + isClickable = true + } - if (_skipping) { - if (ev.action == MotionEvent.ACTION_UP) { - startExitFastForward(); - stopAutoFastForward(); - } else if (ev.action == MotionEvent.ACTION_DOWN) { - _jobExitFastForward?.cancel(); - _jobExitFastForward = null; + fun setupTouchArea(layoutControls: ViewGroup? = null, background: View? = null) { + _layoutControls = layoutControls; + _background = background; + } - startAutoFastForward(); - fastForwardTick(); - } - } + override fun onTouchEvent(event: MotionEvent?): Boolean { + val ev = event ?: return super.onTouchEvent(event); + Logger.v(TAG, "onTouch x = $x, y = $y, ev.x = ${ev.x}, ev.y = ${ev.y}"); - if (_adjustingSound && ev.action == MotionEvent.ACTION_UP) { - stopAdjustingSound(); - } + cancelHideJob(); - if (_adjustingBrightness && ev.action == MotionEvent.ACTION_UP) { - stopAdjustingBrightness(); - } + if (_skipping) { + if (ev.action == MotionEvent.ACTION_UP) { + startExitFastForward(); + stopAutoFastForward(); + } else if (ev.action == MotionEvent.ACTION_DOWN) { + _jobExitFastForward?.cancel(); + _jobExitFastForward = null; - if (_adjustingFullscreenUp && ev.action == MotionEvent.ACTION_UP) { - if (_fullScreenFactorUp > 0.5) { - onToggleFullscreen.emit(); - } - stopAdjustingFullscreenUp(); - } - - if (_adjustingFullscreenDown && ev.action == MotionEvent.ACTION_UP) { - if (_fullScreenFactorDown > 0.5) { - onToggleFullscreen.emit(); - } - stopAdjustingFullscreenDown(); - } - - startHideJobIfNecessary(); - return gestureController.onTouchEvent(ev); + startAutoFastForward(); + fastForwardTick(); } - }; + } - view.setOnTouchListener(touchListener); - view.isClickable = true; + if (_adjustingSound && ev.action == MotionEvent.ACTION_UP) { + stopAdjustingSound(); + } + + if (_adjustingBrightness && ev.action == MotionEvent.ACTION_UP) { + stopAdjustingBrightness(); + } + + if (_adjustingFullscreenUp && ev.action == MotionEvent.ACTION_UP) { + if (_fullScreenFactorUp > 0.5) { + onToggleFullscreen.emit(); + } + stopAdjustingFullscreenUp(); + } + + if (_adjustingFullscreenDown && ev.action == MotionEvent.ACTION_UP) { + if (_fullScreenFactorDown > 0.5) { + onToggleFullscreen.emit(); + } + stopAdjustingFullscreenDown(); + } + + startHideJobIfNecessary(); + + _gestureController.onTouchEvent(ev) + return true; } fun cancelHideJob() { diff --git a/app/src/main/java/com/futo/platformplayer/views/casting/CastView.kt b/app/src/main/java/com/futo/platformplayer/views/casting/CastView.kt index 0c0be08b..5045f59d 100644 --- a/app/src/main/java/com/futo/platformplayer/views/casting/CastView.kt +++ b/app/src/main/java/com/futo/platformplayer/views/casting/CastView.kt @@ -58,7 +58,8 @@ class CastView : ConstraintLayout { _timeBar = findViewById(R.id.time_progress); _background = findViewById(R.id.layout_background); _gestureControlView = findViewById(R.id.gesture_control); - _gestureControlView.setupTouchArea(_background); + _gestureControlView.fullScreenGestureEnabled = false + _gestureControlView.setupTouchArea(); _gestureControlView.onSeek.subscribe { val d = StateCasting.instance.activeDevice ?: return@subscribe; StateCasting.instance.videoSeekTo(d.expectedCurrentTime + it / 1000); diff --git a/app/src/main/java/com/futo/platformplayer/views/video/FutoVideoPlayer.kt b/app/src/main/java/com/futo/platformplayer/views/video/FutoVideoPlayer.kt index 01eb189c..3b1c9430 100644 --- a/app/src/main/java/com/futo/platformplayer/views/video/FutoVideoPlayer.kt +++ b/app/src/main/java/com/futo/platformplayer/views/video/FutoVideoPlayer.kt @@ -156,7 +156,7 @@ class FutoVideoPlayer : FutoVideoPlayerBase { _layoutControls = findViewById(R.id.layout_controls); gestureControl = findViewById(R.id.gesture_control); - _videoView?.videoSurfaceView?.let { gestureControl.setupTouchArea(it, _layoutControls, background); }; + gestureControl.setupTouchArea(_layoutControls, background); gestureControl.onSeek.subscribe { seekFromCurrent(it); }; gestureControl.onSoundAdjusted.subscribe { setVolume(it) }; gestureControl.onToggleFullscreen.subscribe { setFullScreen(!isFullScreen) }; diff --git a/app/src/main/res/layout/view_cast.xml b/app/src/main/res/layout/view_cast.xml index 18958a08..9344fa9e 100644 --- a/app/src/main/res/layout/view_cast.xml +++ b/app/src/main/res/layout/view_cast.xml @@ -23,6 +23,11 @@ android:background="#cc000000" android:layout_marginBottom="6dp" /> + + - -