From 327a071a321f8ce303ecc74155b208dbd4a8d5cf Mon Sep 17 00:00:00 2001 From: FongMi Date: Sun, 8 Jan 2023 18:55:49 +0800 Subject: [PATCH] Optimize Live UX --- .../android/tv/ui/activity/LiveActivity.java | 18 +++-- .../tv/ui/custom/CustomKeyDownLive.java | 67 ++++++++++++++++--- app/src/leanback/res/layout/activity_live.xml | 43 +++++++----- 3 files changed, 99 insertions(+), 29 deletions(-) diff --git a/app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java b/app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java index bbee9c053..9ebde881b 100644 --- a/app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java +++ b/app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java @@ -1,5 +1,6 @@ package com.fongmi.android.tv.ui.activity; +import android.annotation.SuppressLint; import android.app.Activity; import android.content.Intent; import android.view.KeyEvent; @@ -138,6 +139,7 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick } @Override + @SuppressLint("ClickableViewAccessibility") protected void initEvent() { mBinding.group.setListener(this); mBinding.channel.setListener(this); @@ -153,6 +155,7 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick mBinding.control.decode.setOnClickListener(view -> onDecode()); mBinding.control.line.setOnClickListener(view -> nextLine(false)); mBinding.control.speed.setOnLongClickListener(view -> onSpeedLong()); + mBinding.video.setOnTouchListener((view, event) -> mKeyDown.onTouchEvent(event)); mBinding.group.addOnChildViewHolderSelectedListener(new OnChildViewHolderSelectedListener() { @Override public void onChildViewHolderSelected(@NonNull RecyclerView parent, @Nullable RecyclerView.ViewHolder child, int position, int subposition) { @@ -183,10 +186,6 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick mPlayers.setupExo(getExo()); setScale(Prefers.getLiveScale()); getIjk().setRender(Prefers.getRender()); - getExo().setOnClickListener(view -> onToggle()); - getIjk().setOnClickListener(view -> onToggle()); - getExo().setOnLongClickListener(view -> onLongPress()); - getIjk().setOnLongClickListener(view -> onLongPress()); mBinding.control.speed.setText(mPlayers.getSpeedText()); mBinding.control.home.setVisibility(LiveConfig.isOnly() ? View.GONE : View.VISIBLE); mBinding.control.invert.setActivated(Prefers.isInvert()); @@ -607,6 +606,17 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick return true; } + @Override + public void onSingleTap() { + onToggle(); + } + + @Override + public void onDoubleTap() { + if (isVisible(mBinding.control.getRoot())) hideControl(); + else onLongPress(); + } + @Override public void setPass(String pass) { boolean first = true; diff --git a/app/src/leanback/java/com/fongmi/android/tv/ui/custom/CustomKeyDownLive.java b/app/src/leanback/java/com/fongmi/android/tv/ui/custom/CustomKeyDownLive.java index 711251e18..bc465972d 100644 --- a/app/src/leanback/java/com/fongmi/android/tv/ui/custom/CustomKeyDownLive.java +++ b/app/src/leanback/java/com/fongmi/android/tv/ui/custom/CustomKeyDownLive.java @@ -1,15 +1,24 @@ package com.fongmi.android.tv.ui.custom; +import android.content.Context; +import android.view.GestureDetector; import android.view.KeyEvent; +import android.view.MotionEvent; + +import androidx.annotation.NonNull; import com.fongmi.android.tv.App; import com.fongmi.android.tv.utils.Prefers; import com.fongmi.android.tv.utils.Utils; -public class CustomKeyDownLive { +public class CustomKeyDownLive extends GestureDetector.SimpleOnGestureListener { - private final Listener listener; + private static final int DISTANCE = 100; + private static final int VELOCITY = 10; + + private final GestureDetector detector; private final StringBuilder text; + private final Listener listener; private int holdTime; private final Runnable runnable = new Runnable() { @@ -20,13 +29,18 @@ public class CustomKeyDownLive { } }; - public static CustomKeyDownLive create(Listener listener) { - return new CustomKeyDownLive(listener); + public static CustomKeyDownLive create(Context context) { + return new CustomKeyDownLive(context); } - private CustomKeyDownLive(Listener listener) { - this.listener = listener; + private CustomKeyDownLive(Context context) { this.text = new StringBuilder(); + this.listener = (Listener) context; + this.detector = new GestureDetector(context, this); + } + + public boolean onTouchEvent(MotionEvent e) { + return detector.onTouchEvent(e); } public void onKeyDown(int keyCode) { @@ -42,9 +56,11 @@ public class CustomKeyDownLive { } else if (event.getAction() == KeyEvent.ACTION_DOWN && Utils.isRightKey(event)) { listener.onSeeking(addTime()); } else if (event.getAction() == KeyEvent.ACTION_DOWN && Utils.isUpKey(event)) { - if (Prefers.isInvert()) listener.onKeyDown(); else listener.onKeyUp(); + if (Prefers.isInvert()) listener.onKeyDown(); + else listener.onKeyUp(); } else if (event.getAction() == KeyEvent.ACTION_DOWN && Utils.isDownKey(event)) { - if (Prefers.isInvert()) listener.onKeyUp(); else listener.onKeyDown(); + if (Prefers.isInvert()) listener.onKeyUp(); + else listener.onKeyDown(); } else if (event.getAction() == KeyEvent.ACTION_UP && Utils.isLeftKey(event)) { listener.onKeyLeft(holdTime); } else if (event.getAction() == KeyEvent.ACTION_UP && Utils.isRightKey(event)) { @@ -59,6 +75,37 @@ public class CustomKeyDownLive { return true; } + @Override + public boolean onDoubleTap(@NonNull MotionEvent e) { + listener.onDoubleTap(); + return true; + } + + @Override + public boolean onSingleTapConfirmed(@NonNull MotionEvent e) { + listener.onSingleTap(); + return true; + } + + @Override + public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { + if (e1.getX() - e2.getX() > DISTANCE && Math.abs(velocityX) > VELOCITY) { + listener.onKeyLeft(30 * 1000); + return true; + } else if (e2.getX() - e1.getX() > DISTANCE && Math.abs(velocityX) > VELOCITY) { + listener.onKeyRight(30 * 1000); + return true; + } else if (e1.getY() - e2.getY() > DISTANCE && Math.abs(velocityY) > VELOCITY) { + listener.onKeyUp(); + return true; + } else if (e2.getY() - e1.getY() > DISTANCE && Math.abs(velocityY) > VELOCITY) { + listener.onKeyDown(); + return true; + } else { + return false; + } + } + public boolean hasEvent(KeyEvent event) { return Utils.isEnterKey(event) || Utils.isUpKey(event) || Utils.isDownKey(event) || Utils.isLeftKey(event) || Utils.isRightKey(event) || Utils.isDigitKey(event) || event.isLongPress(); } @@ -98,5 +145,9 @@ public class CustomKeyDownLive { void onKeyCenter(); boolean onLongPress(); + + void onSingleTap(); + + void onDoubleTap(); } } diff --git a/app/src/leanback/res/layout/activity_live.xml b/app/src/leanback/res/layout/activity_live.xml index b0b5d42e5..c985a27b9 100644 --- a/app/src/leanback/res/layout/activity_live.xml +++ b/app/src/leanback/res/layout/activity_live.xml @@ -7,27 +7,36 @@ android:background="@color/black" android:keepScreenOn="true"> - + android:clickable="true" + android:focusable="true"> - + - + + + + +