From e15d8a672992b1c586d5b67b4e69bbff1b46ab8b Mon Sep 17 00:00:00 2001 From: jhengazuki Date: Sun, 17 Aug 2025 17:24:23 +0800 Subject: [PATCH] Clean --- .../android/tv/ui/activity/LiveActivity.java | 27 +- .../android/tv/ui/activity/VideoActivity.java | 9 +- ...stomKeyDownVod.java => CustomKeyDown.java} | 10 +- .../tv/ui/custom/CustomKeyDownLive.java | 249 ------------------ 4 files changed, 15 insertions(+), 280 deletions(-) rename app/src/mobile/java/com/fongmi/android/tv/ui/custom/{CustomKeyDownVod.java => CustomKeyDown.java} (95%) delete mode 100644 app/src/mobile/java/com/fongmi/android/tv/ui/custom/CustomKeyDownLive.java diff --git a/app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java b/app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java index cf20c3b3a..2c47027a6 100644 --- a/app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java +++ b/app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java @@ -51,7 +51,7 @@ import com.fongmi.android.tv.ui.adapter.ChannelAdapter; import com.fongmi.android.tv.ui.adapter.EpgDataAdapter; import com.fongmi.android.tv.ui.adapter.GroupAdapter; import com.fongmi.android.tv.ui.base.BaseActivity; -import com.fongmi.android.tv.ui.custom.CustomKeyDownLive; +import com.fongmi.android.tv.ui.custom.CustomKeyDown; import com.fongmi.android.tv.ui.dialog.CastDialog; import com.fongmi.android.tv.ui.dialog.InfoDialog; import com.fongmi.android.tv.ui.dialog.LiveDialog; @@ -74,16 +74,16 @@ import java.util.Iterator; import java.util.List; import java.util.UUID; -public class LiveActivity extends BaseActivity implements CustomKeyDownLive.Listener, TrackDialog.Listener, Biometric.Callback, PassCallback, LiveCallback, GroupAdapter.OnClickListener, ChannelAdapter.OnClickListener, EpgDataAdapter.OnClickListener, CastDialog.Listener, InfoDialog.Listener { +public class LiveActivity extends BaseActivity implements CustomKeyDown.Listener, TrackDialog.Listener, Biometric.Callback, PassCallback, LiveCallback, GroupAdapter.OnClickListener, ChannelAdapter.OnClickListener, EpgDataAdapter.OnClickListener, CastDialog.Listener, InfoDialog.Listener { private ActivityLiveBinding mBinding; private ChannelAdapter mChannelAdapter; private EpgDataAdapter mEpgDataAdapter; private Observer mObserveUrl; - private CustomKeyDownLive mKeyDown; private GroupAdapter mGroupAdapter; private Observer mObserveEpg; private LiveViewModel mViewModel; + private CustomKeyDown mKeyDown; private List mHides; private Players mPlayers; private Channel mChannel; @@ -137,7 +137,7 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List @Override protected void initView(Bundle savedInstanceState) { - mKeyDown = CustomKeyDownLive.create(this, mBinding.exo); + mKeyDown = CustomKeyDown.create(this, mBinding.exo); setPadding(mBinding.control.getRoot()); setPadding(mBinding.recycler, true); mPlayers = Players.create(this); @@ -863,13 +863,6 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List else fetch(); } - private void prevLine() { - if (mChannel == null || mChannel.isOnly()) return; - mChannel.prevLine(); - showInfo(); - fetch(); - } - private void nextLine(boolean show) { if (mChannel == null || mChannel.isOnly()) return; mChannel.nextLine(); @@ -986,16 +979,6 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List else nextChannel(); } - @Override - public void onFlingLeft() { - if (mPlayers.isLive()) prevLine(); - } - - @Override - public void onFlingRight() { - if (mPlayers.isLive()) nextLine(true); - } - @Override public void onSeek(long time) { if (mPlayers.isLive()) return; @@ -1022,7 +1005,7 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List @Override public void onDoubleTap() { if (isVisible(mBinding.recycler)) hideUI(); - else if (isVisible(mBinding.control.getRoot())) hideControl(); + if (isVisible(mBinding.control.getRoot())) hideControl(); else showControl(); } 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 c1aa5f2c4..96c49bb3c 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 @@ -71,7 +71,7 @@ import com.fongmi.android.tv.ui.adapter.QualityAdapter; import com.fongmi.android.tv.ui.adapter.QuickAdapter; import com.fongmi.android.tv.ui.base.BaseActivity; import com.fongmi.android.tv.ui.base.ViewType; -import com.fongmi.android.tv.ui.custom.CustomKeyDownVod; +import com.fongmi.android.tv.ui.custom.CustomKeyDown; import com.fongmi.android.tv.ui.custom.CustomMovement; import com.fongmi.android.tv.ui.custom.SpaceItemDecoration; import com.fongmi.android.tv.ui.dialog.CastDialog; @@ -113,7 +113,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.regex.Matcher; -public class VideoActivity extends BaseActivity implements Clock.Callback, CustomKeyDownVod.Listener, TrackDialog.Listener, ControlDialog.Listener, FlagAdapter.OnClickListener, EpisodeAdapter.OnClickListener, QualityAdapter.OnClickListener, QuickAdapter.OnClickListener, ParseAdapter.OnClickListener, CastDialog.Listener, InfoDialog.Listener { +public class VideoActivity extends BaseActivity implements Clock.Callback, CustomKeyDown.Listener, TrackDialog.Listener, ControlDialog.Listener, FlagAdapter.OnClickListener, EpisodeAdapter.OnClickListener, QualityAdapter.OnClickListener, QuickAdapter.OnClickListener, ParseAdapter.OnClickListener, CastDialog.Listener, InfoDialog.Listener { private ActivityVideoBinding mBinding; private ViewGroup.LayoutParams mFrameParams; @@ -125,10 +125,10 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo private ControlDialog mControlDialog; private QuickAdapter mQuickAdapter; private ParseAdapter mParseAdapter; - private CustomKeyDownVod mKeyDown; private ExecutorService mExecutor; private SiteViewModel mViewModel; private FlagAdapter mFlagAdapter; + private CustomKeyDown mKeyDown; private List mDialogs; private List mBroken; private History mHistory; @@ -279,7 +279,7 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo @Override protected void initView(Bundle savedInstanceState) { - mKeyDown = CustomKeyDownVod.create(this, mBinding.exo); + mKeyDown = CustomKeyDown.create(this, mBinding.exo); mFrameParams = mBinding.video.getLayoutParams(); mBinding.progressLayout.showProgress(); mBinding.swipeLayout.setEnabled(false); @@ -1500,6 +1500,7 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo @Override public void onDoubleTap() { + if (isLock()) return; if (!isFullscreen()) { App.post(this::enterFullscreen, 250); } else if (mPlayers.isPlaying()) { 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/CustomKeyDown.java similarity index 95% rename from app/src/mobile/java/com/fongmi/android/tv/ui/custom/CustomKeyDownVod.java rename to app/src/mobile/java/com/fongmi/android/tv/ui/custom/CustomKeyDown.java index ce371d730..b6e5582d0 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/CustomKeyDown.java @@ -15,7 +15,7 @@ import com.fongmi.android.tv.App; import com.fongmi.android.tv.utils.ResUtil; import com.fongmi.android.tv.utils.Util; -public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener implements ScaleGestureDetector.OnScaleGestureListener { +public class CustomKeyDown extends GestureDetector.SimpleOnGestureListener implements ScaleGestureDetector.OnScaleGestureListener { private static final int DISTANCE = 250; private static final int VELOCITY = 10; @@ -40,11 +40,11 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener im private float scale; private long time; - public static CustomKeyDownVod create(Activity activity, View videoView) { - return new CustomKeyDownVod(activity, videoView); + public static CustomKeyDown create(Activity activity, View videoView) { + return new CustomKeyDown(activity, videoView); } - private CustomKeyDownVod(Activity activity, View videoView) { + private CustomKeyDown(Activity activity, View videoView) { this.manager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE); this.scaleDetector = new ScaleGestureDetector(activity, this); this.detector = new GestureDetector(activity, this); @@ -119,7 +119,7 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener im @Override public boolean onDoubleTap(@NonNull MotionEvent e) { if (isEdge(e) || changeScale || e.getPointerCount() > 1) return true; - if (!lock) listener.onDoubleTap(); + listener.onDoubleTap(); return true; } 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 deleted file mode 100644 index ea9e9606b..000000000 --- a/app/src/mobile/java/com/fongmi/android/tv/ui/custom/CustomKeyDownLive.java +++ /dev/null @@ -1,249 +0,0 @@ -package com.fongmi.android.tv.ui.custom; - -import android.app.Activity; -import android.content.Context; -import android.media.AudioManager; -import android.view.GestureDetector; -import android.view.MotionEvent; -import android.view.ScaleGestureDetector; -import android.view.View; -import android.view.WindowManager; - -import androidx.annotation.NonNull; - -import com.fongmi.android.tv.App; -import com.fongmi.android.tv.utils.ResUtil; -import com.fongmi.android.tv.utils.Util; - -public class CustomKeyDownLive extends GestureDetector.SimpleOnGestureListener implements ScaleGestureDetector.OnScaleGestureListener { - - private static final int DISTANCE = 250; - private static final int VELOCITY = 10; - - private final ScaleGestureDetector scaleDetector; - private final GestureDetector detector; - private final AudioManager manager; - private final Listener listener; - private final Activity activity; - private final View videoView; - private boolean changeBright; - private boolean changeVolume; - private boolean changeSpeed; - private boolean changeScale; - private boolean changeTime; - private boolean animating; - private boolean center; - private boolean touch; - private boolean lock; - private float bright; - private float volume; - private float scale; - private long time; - - public static CustomKeyDownLive create(Activity activity, View videoView) { - return new CustomKeyDownLive(activity, videoView); - } - - private CustomKeyDownLive(Activity activity, View videoView) { - this.manager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE); - this.scaleDetector = new ScaleGestureDetector(activity, this); - this.detector = new GestureDetector(activity, this); - this.listener = (Listener) activity; - this.videoView = videoView; - this.activity = activity; - this.scale = 1.0f; - } - - public boolean onTouchEvent(MotionEvent e) { - if (changeTime && e.getAction() == MotionEvent.ACTION_UP) onSeekEnd(); - if (changeSpeed && e.getAction() == MotionEvent.ACTION_UP) listener.onSpeedEnd(); - if (changeBright && e.getAction() == MotionEvent.ACTION_UP) listener.onBrightEnd(); - if (changeVolume && e.getAction() == MotionEvent.ACTION_UP) listener.onVolumeEnd(); - return e.getPointerCount() == 2 ? scaleDetector.onTouchEvent(e) : detector.onTouchEvent(e); - } - - public void resetScale() { - if (scale == 1.0f) return; - videoView.animate().scaleX(1.0f).scaleY(1.0f).translationX(0f).translationY(0f).setDuration(250).withEndAction(() -> { - videoView.setPivotY(videoView.getHeight() / 2f); - videoView.setPivotX(videoView.getWidth() / 2f); - scale = 1.0f; - }).start(); - } - - public void setLock(boolean lock) { - this.lock = lock; - } - - public float getScale() { - return scale; - } - - private boolean isEdge(MotionEvent e) { - return ResUtil.isEdge(activity, e, ResUtil.dp2px(24)); - } - - @Override - public boolean onDown(@NonNull MotionEvent e) { - if (isEdge(e) || changeScale || lock || e.getPointerCount() > 1) return true; - volume = manager.getStreamVolume(AudioManager.STREAM_MUSIC); - bright = Util.getBrightness(activity); - changeBright = false; - changeVolume = false; - changeSpeed = false; - changeTime = false; - center = false; - touch = true; - return true; - } - - @Override - public void onLongPress(@NonNull MotionEvent e) { - if (isEdge(e) || changeScale || lock || e.getPointerCount() > 1) return; - changeSpeed = true; - listener.onSpeedUp(); - } - - @Override - public boolean onScroll(MotionEvent e1, @NonNull MotionEvent e2, float distanceX, float distanceY) { - if (isEdge(e1) || changeScale || 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 (changeBright) setBright(deltaY); - if (changeVolume) setVolume(deltaY); - return true; - } - - @Override - public boolean onDoubleTap(@NonNull MotionEvent e) { - if (isEdge(e) || changeScale || e.getPointerCount() > 1) return true; - listener.onDoubleTap(); - return true; - } - - @Override - public boolean onSingleTapConfirmed(@NonNull MotionEvent e) { - if (isEdge(e) || changeScale || e.getPointerCount() > 1) return true; - int half = ResUtil.getScreenWidth(activity) / 2; - if (e.getX() > half || lock) listener.onDoubleTap(); - else listener.onSingleTap(); - return true; - } - - @Override - public boolean onFling(MotionEvent e1, @NonNull MotionEvent e2, float velocityX, float velocityY) { - if (isEdge(e1) || changeScale || !center || animating || e1.getPointerCount() > 1) return true; - checkFunc(e1, e2, velocityX, velocityY); - return true; - } - - private void onSeekEnd() { - listener.onSeekEnd(time); - changeTime = false; - time = 0; - } - - private void checkFunc(float distanceX, float distanceY, MotionEvent 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 velocityX, float velocityY) { - if (e1.getX() - e2.getX() > DISTANCE && Math.abs(velocityX) > VELOCITY) { - listener.onFlingLeft(); - } else if (e2.getX() - e1.getX() > DISTANCE && Math.abs(velocityX) > VELOCITY) { - listener.onFlingRight(); - } else if (e1.getY() - e2.getY() > DISTANCE && Math.abs(velocityY) > VELOCITY) { - videoView.animate().translationYBy(-ResUtil.dp2px(24)).setDuration(150).withStartAction(() -> animating = true).withEndAction(() -> videoView.animate().translationY(0).setDuration(100).withStartAction(listener::onFlingUp).withEndAction(() -> animating = false).start()).start(); - } else if (e2.getY() - e1.getY() > DISTANCE && Math.abs(velocityY) > VELOCITY) { - videoView.animate().translationYBy(ResUtil.dp2px(24)).setDuration(150).withStartAction(() -> animating = true).withEndAction(() -> videoView.animate().translationY(0).setDuration(100).withStartAction(listener::onFlingDown).withEndAction(() -> animating = false).start()).start(); - } - } - - private void checkSide(MotionEvent e2) { - int half = ResUtil.getScreenWidth(activity) / 2; - if (e2.getX() > half) changeVolume = true; - else changeBright = true; - } - - 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; - if (brightness > 1.0f) brightness = 1.0f; - WindowManager.LayoutParams attributes = activity.getWindow().getAttributes(); - attributes.screenBrightness = brightness; - activity.getWindow().setAttributes(attributes); - listener.onBright((int) (brightness * 100)); - } - - private void setVolume(float deltaY) { - int height = videoView.getMeasuredHeight(); - int maxVolume = manager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); - float deltaV = deltaY * 2 / height * maxVolume; - float index = volume + deltaV; - if (index > maxVolume) index = maxVolume; - if (index < 0) index = 0; - manager.setStreamVolume(AudioManager.STREAM_MUSIC, (int) index, 0); - listener.onVolume((int) (index / maxVolume * 100)); - } - - @Override - public boolean onScaleBegin(@NonNull ScaleGestureDetector detector) { - if (changeBright || changeVolume || changeSpeed || changeTime || lock) return changeScale = false; - return changeScale = true; - } - - @Override - public void onScaleEnd(@NonNull ScaleGestureDetector detector) { - App.post(() -> changeScale = false, 500); - } - - @Override - public boolean onScale(@NonNull ScaleGestureDetector detector) { - scale *= detector.getScaleFactor(); - scale = Math.max(1.0f, Math.min(scale, 5.0f)); - videoView.setPivotX(detector.getFocusX()); - videoView.setPivotY(detector.getFocusY()); - videoView.setScaleX(scale); - videoView.setScaleY(scale); - return true; - } - - public interface Listener { - - void onSpeedUp(); - - void onSpeedEnd(); - - void onBright(int progress); - - void onBrightEnd(); - - void onVolume(int progress); - - void onVolumeEnd(); - - void onFlingUp(); - - void onFlingDown(); - - void onFlingLeft(); - - void onFlingRight(); - - void onSeek(long time); - - void onSeekEnd(long time); - - void onSingleTap(); - - void onDoubleTap(); - } -}