Optimize Live UX

pull/123/head
FongMi 3 years ago
parent bcc0d95116
commit 327a071a32
  1. 18
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java
  2. 67
      app/src/leanback/java/com/fongmi/android/tv/ui/custom/CustomKeyDownLive.java
  3. 43
      app/src/leanback/res/layout/activity_live.xml

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

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

@ -7,27 +7,36 @@
android:background="@color/black"
android:keepScreenOn="true">
<com.google.android.exoplayer2.ui.StyledPlayerView
android:id="@+id/surface"
style="@style/ExoStyle"
<FrameLayout
android:id="@+id/video"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:surface_type="surface_view" />
android:clickable="true"
android:focusable="true">
<com.google.android.exoplayer2.ui.StyledPlayerView
android:id="@+id/texture"
style="@style/ExoStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:surface_type="texture_view" />
<com.google.android.exoplayer2.ui.StyledPlayerView
android:id="@+id/surface"
style="@style/ExoStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:surface_type="surface_view" />
<tv.danmaku.ijk.media.player.ui.IjkVideoView
android:id="@+id/ijk"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<com.google.android.exoplayer2.ui.StyledPlayerView
android:id="@+id/texture"
style="@style/ExoStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:surface_type="texture_view" />
<tv.danmaku.ijk.media.player.ui.IjkVideoView
android:id="@+id/ijk"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
</FrameLayout>
<include
android:id="@+id/widget"

Loading…
Cancel
Save