Fixed gesture control issues causing wrong area to have gesture controls and disabled full screen gesture when casting.

This commit is contained in:
Koen 2023-11-30 11:40:58 +01:00
commit 4be4bb631f
4 changed files with 67 additions and 61 deletions

View file

@ -6,7 +6,6 @@ import android.animation.ObjectAnimator
import android.content.Context import android.content.Context
import android.graphics.drawable.Animatable import android.graphics.drawable.Animatable
import android.util.AttributeSet import android.util.AttributeSet
import android.util.Log
import android.view.GestureDetector import android.view.GestureDetector
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.MotionEvent import android.view.MotionEvent
@ -63,11 +62,15 @@ class GestureControlView : LinearLayout {
private var _fullScreenFactorUp = 1.0f; private var _fullScreenFactorUp = 1.0f;
private var _fullScreenFactorDown = 1.0f; private var _fullScreenFactorDown = 1.0f;
private val _gestureController: GestureDetectorCompat;
val onSeek = Event1<Long>(); val onSeek = Event1<Long>();
val onBrightnessAdjusted = Event1<Float>(); val onBrightnessAdjusted = Event1<Float>();
val onSoundAdjusted = Event1<Float>(); val onSoundAdjusted = Event1<Float>();
val onToggleFullscreen = Event0(); val onToggleFullscreen = Event0();
var fullScreenGestureEnabled = true
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
LayoutInflater.from(context).inflate(R.layout.view_gesture_controls, this, true); 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); _layoutControlsBrightness = findViewById(R.id.layout_controls_brightness);
_progressBrightness = findViewById(R.id.progress_brightness); _progressBrightness = findViewById(R.id.progress_brightness);
_layoutControlsFullscreen = findViewById(R.id.layout_controls_fullscreen); _layoutControlsFullscreen = findViewById(R.id.layout_controls_fullscreen);
}
fun setupTouchArea(view: View, layoutControls: ViewGroup? = null, background: View? = null) { _gestureController = GestureDetectorCompat(context, object : GestureDetector.OnGestureListener {
_layoutControls = layoutControls; override fun onDown(p0: MotionEvent): Boolean { Logger.v(TAG, "onDown ${p0.x}, ${p0.y}"); return false; }
_background = background;
val gestureController = GestureDetectorCompat(context, object : GestureDetector.OnGestureListener {
override fun onDown(p0: MotionEvent): Boolean { return false; }
override fun onShowPress(p0: MotionEvent) = Unit; override fun onShowPress(p0: MotionEvent) = Unit;
override fun onSingleTapUp(p0: MotionEvent): Boolean { return false; } override fun onSingleTapUp(p0: MotionEvent): Boolean { return false; }
override fun onScroll(p0: MotionEvent, p1: MotionEvent, distanceX: Float, distanceY: Float): Boolean { 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); _fullScreenFactorDown = (_fullScreenFactorDown + adjustAmount).coerceAtLeast(0.0f).coerceAtMost(1.0f);
_layoutControlsFullscreen.alpha = _fullScreenFactorDown; _layoutControlsFullscreen.alpha = _fullScreenFactorDown;
} else { } else {
val rx = p0.x / width; val rx = (p0.x + p1.x) / (2 * width);
val ry = p0.y / height; val ry = (p0.y + p1.y) / (2 * height);
Logger.v(TAG, "rx = $rx, ry = $ry, _isFullScreen = $_isFullScreen") 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 (ry > 0.1 && ry < 0.9) {
if (_isFullScreen && rx < 0.4) { if (_isFullScreen && rx < 0.2) {
startAdjustingBrightness(); startAdjustingBrightness();
} else if (_isFullScreen && rx > 0.6) { } else if (_isFullScreen && rx > 0.8) {
startAdjustingSound(); startAdjustingSound();
} else if (rx >= 0.4 && rx <= 0.6) { } else if (fullScreenGestureEnabled && rx in 0.3..0.7) {
if (_isFullScreen) { if (_isFullScreen) {
startAdjustingFullscreenDown(); startAdjustingFullscreenDown();
} else { } else {
@ -136,7 +134,7 @@ class GestureControlView : LinearLayout {
override fun onFling(p0: MotionEvent, p1: MotionEvent, p2: Float, p3: Float): Boolean { return false; } 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 { override fun onSingleTapConfirmed(ev: MotionEvent): Boolean {
if (_skipping) { if (_skipping) {
return false; return false;
@ -166,8 +164,18 @@ class GestureControlView : LinearLayout {
} }
}); });
val touchListener = object : OnTouchListener { isClickable = true
override fun onTouch(v: View?, ev: MotionEvent): Boolean { }
fun setupTouchArea(layoutControls: ViewGroup? = null, background: View? = null) {
_layoutControls = layoutControls;
_background = background;
}
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}");
cancelHideJob(); cancelHideJob();
if (_skipping) { if (_skipping) {
@ -206,12 +214,9 @@ class GestureControlView : LinearLayout {
} }
startHideJobIfNecessary(); startHideJobIfNecessary();
return gestureController.onTouchEvent(ev);
}
};
view.setOnTouchListener(touchListener); _gestureController.onTouchEvent(ev)
view.isClickable = true; return true;
} }
fun cancelHideJob() { fun cancelHideJob() {

View file

@ -58,7 +58,8 @@ class CastView : ConstraintLayout {
_timeBar = findViewById(R.id.time_progress); _timeBar = findViewById(R.id.time_progress);
_background = findViewById(R.id.layout_background); _background = findViewById(R.id.layout_background);
_gestureControlView = findViewById(R.id.gesture_control); _gestureControlView = findViewById(R.id.gesture_control);
_gestureControlView.setupTouchArea(_background); _gestureControlView.fullScreenGestureEnabled = false
_gestureControlView.setupTouchArea();
_gestureControlView.onSeek.subscribe { _gestureControlView.onSeek.subscribe {
val d = StateCasting.instance.activeDevice ?: return@subscribe; val d = StateCasting.instance.activeDevice ?: return@subscribe;
StateCasting.instance.videoSeekTo(d.expectedCurrentTime + it / 1000); StateCasting.instance.videoSeekTo(d.expectedCurrentTime + it / 1000);

View file

@ -156,7 +156,7 @@ class FutoVideoPlayer : FutoVideoPlayerBase {
_layoutControls = findViewById(R.id.layout_controls); _layoutControls = findViewById(R.id.layout_controls);
gestureControl = findViewById(R.id.gesture_control); gestureControl = findViewById(R.id.gesture_control);
_videoView?.videoSurfaceView?.let { gestureControl.setupTouchArea(it, _layoutControls, background); }; gestureControl.setupTouchArea(_layoutControls, background);
gestureControl.onSeek.subscribe { seekFromCurrent(it); }; gestureControl.onSeek.subscribe { seekFromCurrent(it); };
gestureControl.onSoundAdjusted.subscribe { setVolume(it) }; gestureControl.onSoundAdjusted.subscribe { setVolume(it) };
gestureControl.onToggleFullscreen.subscribe { setFullScreen(!isFullScreen) }; gestureControl.onToggleFullscreen.subscribe { setFullScreen(!isFullScreen) };

View file

@ -23,6 +23,11 @@
android:background="#cc000000" android:background="#cc000000"
android:layout_marginBottom="6dp" /> android:layout_marginBottom="6dp" />
<com.futo.platformplayer.views.behavior.GestureControlView
android:id="@+id/gesture_control"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageButton <ImageButton
android:id="@+id/button_minimize" android:id="@+id/button_minimize"
android:layout_width="50dp" android:layout_width="50dp"
@ -129,11 +134,6 @@
app:layout_constraintTop_toTopOf="@id/text_position" app:layout_constraintTop_toTopOf="@id/text_position"
app:layout_constraintBottom_toBottomOf="@id/text_position"/> app:layout_constraintBottom_toBottomOf="@id/text_position"/>
<com.futo.platformplayer.views.behavior.GestureControlView
android:id="@+id/gesture_control"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.exoplayer2.ui.DefaultTimeBar <com.google.android.exoplayer2.ui.DefaultTimeBar
android:id="@+id/time_progress" android:id="@+id/time_progress"
android:layout_width="match_parent" android:layout_width="match_parent"