From ab4ef13cfb5ca48b6499547d2a46f6d5e1ab4da3 Mon Sep 17 00:00:00 2001 From: FongMi Date: Fri, 6 Jun 2025 14:52:55 +0800 Subject: [PATCH] Add flip for vod --- .../android/tv/ui/activity/VideoActivity.java | 10 ++++++ .../tv/ui/custom/CustomKeyDownLive.java | 6 ++-- .../tv/ui/custom/CustomKeyDownVod.java | 35 ++++++++++++++++--- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/app/src/mobile/java/com/fongmi/android/tv/ui/activity/VideoActivity.java b/app/src/mobile/java/com/fongmi/android/tv/ui/activity/VideoActivity.java index f00b0b2ea..14d3f4b18 100644 --- a/app/src/mobile/java/com/fongmi/android/tv/ui/activity/VideoActivity.java +++ b/app/src/mobile/java/com/fongmi/android/tv/ui/activity/VideoActivity.java @@ -1467,6 +1467,16 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo mBinding.widget.volume.setVisibility(View.GONE); } + @Override + public void onFlingUp() { + checkNext(); + } + + @Override + public void onFlingDown() { + checkPrev(); + } + @Override public void onSeek(long time) { mBinding.widget.action.setImageResource(time > 0 ? R.drawable.ic_widget_forward : R.drawable.ic_widget_rewind); diff --git a/app/src/mobile/java/com/fongmi/android/tv/ui/custom/CustomKeyDownLive.java b/app/src/mobile/java/com/fongmi/android/tv/ui/custom/CustomKeyDownLive.java index bc8e8df38..e33706a53 100644 --- a/app/src/mobile/java/com/fongmi/android/tv/ui/custom/CustomKeyDownLive.java +++ b/app/src/mobile/java/com/fongmi/android/tv/ui/custom/CustomKeyDownLive.java @@ -85,7 +85,7 @@ public class CustomKeyDownLive extends GestureDetector.SimpleOnGestureListener { } @Override - public boolean onScroll(@NonNull MotionEvent e1, @NonNull MotionEvent e2, float distanceX, float distanceY) { + public boolean onScroll(MotionEvent e1, @NonNull MotionEvent e2, float distanceX, float distanceY) { if (isEdge(e1) || lock || e1.getPointerCount() > 1) return true; float deltaX = e2.getX() - e1.getX(); float deltaY = e1.getY() - e2.getY(); @@ -111,7 +111,7 @@ public class CustomKeyDownLive extends GestureDetector.SimpleOnGestureListener { } @Override - public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { + public boolean onFling(MotionEvent e1, @NonNull MotionEvent e2, float velocityX, float velocityY) { if (isEdge(e1) || !center) return true; checkFunc(e1, e2, velocityX, velocityY); return true; @@ -152,8 +152,8 @@ public class CustomKeyDownLive extends GestureDetector.SimpleOnGestureListener { } private void setBright(float deltaY) { - int height = videoView.getMeasuredHeight(); if (bright == -1.0f) bright = 0.5f; + int height = videoView.getMeasuredHeight(); float brightness = deltaY * 2 / height + bright; if (brightness < 0) brightness = 0f; if (brightness > 1.0f) brightness = 1.0f; diff --git a/app/src/mobile/java/com/fongmi/android/tv/ui/custom/CustomKeyDownVod.java b/app/src/mobile/java/com/fongmi/android/tv/ui/custom/CustomKeyDownVod.java index 55ac21373..3a9e44fab 100644 --- a/app/src/mobile/java/com/fongmi/android/tv/ui/custom/CustomKeyDownVod.java +++ b/app/src/mobile/java/com/fongmi/android/tv/ui/custom/CustomKeyDownVod.java @@ -15,6 +15,9 @@ import com.fongmi.android.tv.utils.Util; public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener { + private static final int DISTANCE = 100; + private static final int VELOCITY = 10; + private final GestureDetector detector; private final AudioManager manager; private final Listener listener; @@ -24,6 +27,7 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener { private boolean changeVolume; private boolean changeSpeed; private boolean changeTime; + private boolean center; private boolean touch; private boolean lock; private float bright; @@ -67,6 +71,7 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener { changeVolume = false; changeSpeed = false; changeTime = false; + center = false; touch = true; return true; } @@ -79,12 +84,12 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener { } @Override - public boolean onScroll(@NonNull MotionEvent e1, @NonNull MotionEvent e2, float distanceX, float distanceY) { + public boolean onScroll(MotionEvent e1, @NonNull MotionEvent e2, float distanceX, float distanceY) { if (isEdge(e1) || lock || e1.getPointerCount() > 1) return true; float deltaX = e2.getX() - e1.getX(); float deltaY = e1.getY() - e2.getY(); if (touch) checkFunc(distanceX, distanceY, e2); - if (changeTime) listener.onSeek(time = (long) deltaX * 50); + if (changeTime) listener.onSeek(time = (long) (deltaX * 50)); if (changeBright) setBright(deltaY); if (changeVolume) setVolume(deltaY); return true; @@ -102,6 +107,13 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener { return true; } + @Override + public boolean onFling(MotionEvent e1, @NonNull MotionEvent e2, float velocityX, float velocityY) { + if (isEdge(e1) || !center) return true; + checkFunc(e1, e2, velocityY); + return true; + } + private void onSeekEnd() { listener.onSeekEnd(time); changeTime = false; @@ -109,11 +121,21 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener { } private void checkFunc(float distanceX, float distanceY, MotionEvent e2) { - changeTime = Math.abs(distanceX) >= Math.abs(distanceY); - if (!changeTime) checkSide(e2); + int four = ResUtil.getScreenWidth(activity) / 4; + if (e2.getX() > four && e2.getX() < four * 3) center = true; + else if (Math.abs(distanceX) < Math.abs(distanceY)) checkSide(e2); + if (Math.abs(distanceX) >= Math.abs(distanceY)) changeTime = true; touch = false; } + private void checkFunc(MotionEvent e1, MotionEvent e2, float velocityY) { + if (e1.getY() - e2.getY() > DISTANCE && Math.abs(velocityY) > VELOCITY) { + listener.onFlingUp(); + } else if (e2.getY() - e1.getY() > DISTANCE && Math.abs(velocityY) > VELOCITY) { + listener.onFlingDown(); + } + } + private void checkSide(MotionEvent e2) { int half = ResUtil.getScreenWidth(activity) / 2; if (e2.getX() > half) changeVolume = true; @@ -121,6 +143,7 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener { } private void setBright(float deltaY) { + if (bright == -1.0f) bright = 0.5f; int height = videoView.getMeasuredHeight(); float brightness = deltaY * 2 / height + bright; if (brightness < 0) brightness = 0f; @@ -156,6 +179,10 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener { void onVolumeEnd(); + void onFlingUp(); + + void onFlingDown(); + void onSeek(long time); void onSeekEnd(long time);