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
parent 948f5a2a6d
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.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<Long>();
val onBrightnessAdjusted = Event1<Float>();
val onSoundAdjusted = Event1<Float>();
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() {

View file

@ -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);

View file

@ -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) };

View file

@ -23,6 +23,11 @@
android:background="#cc000000"
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
android:id="@+id/button_minimize"
android:layout_width="50dp"
@ -129,11 +134,6 @@
app:layout_constraintTop_toTopOf="@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
android:id="@+id/time_progress"
android:layout_width="match_parent"