release
jhengazuki 8 months ago
parent ea45e95681
commit 6087a60f99
  1. 1
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/HomeActivity.java
  2. 5
      app/src/leanback/java/com/fongmi/android/tv/ui/custom/CustomHorizontalGridView.java
  3. 16
      app/src/leanback/java/com/fongmi/android/tv/ui/custom/CustomKeyDownLive.java
  4. 12
      app/src/leanback/java/com/fongmi/android/tv/ui/custom/CustomKeyDownVod.java
  5. 2
      app/src/leanback/java/com/fongmi/android/tv/ui/custom/CustomLeftRightLayout.java
  6. 4
      app/src/leanback/java/com/fongmi/android/tv/ui/custom/CustomTitleView.java
  7. 2
      app/src/leanback/java/com/fongmi/android/tv/ui/custom/CustomTypeView.java
  8. 2
      app/src/leanback/java/com/fongmi/android/tv/ui/custom/CustomUpDownView.java
  9. 5
      app/src/leanback/java/com/fongmi/android/tv/ui/custom/CustomViewPager.java
  10. 8
      app/src/leanback/java/com/fongmi/android/tv/utils/KeyUtil.java
  11. 58
      app/src/leanback/res/layout/activity_home.xml
  12. 4
      app/src/main/java/com/fongmi/android/tv/ui/custom/CustomMovement.java

@ -446,6 +446,7 @@ public class HomeActivity extends BaseActivity implements CustomTitleView.Listen
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (KeyUtil.isMenuKey(event)) showDialog();
if (KeyUtil.isActionDown(event) & KeyUtil.isDownKey(event) && getCurrentFocus() == mBinding.site) return mBinding.recycler.getChildAt(0).requestFocus();
return super.dispatchKeyEvent(event);
}

@ -14,6 +14,7 @@ import androidx.annotation.Nullable;
import androidx.leanback.widget.HorizontalGridView;
import com.fongmi.android.tv.R;
import com.fongmi.android.tv.utils.KeyUtil;
import com.fongmi.android.tv.utils.ResUtil;
public class CustomHorizontalGridView extends HorizontalGridView {
@ -59,8 +60,8 @@ public class CustomHorizontalGridView extends HorizontalGridView {
}
public boolean executeKeyEvent(@NonNull KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) return arrowScroll(FOCUS_LEFT);
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT) return arrowScroll(FOCUS_RIGHT);
if (KeyUtil.isActionDown(event) && KeyUtil.isLeftKey(event)) return arrowScroll(FOCUS_LEFT);
if (KeyUtil.isActionDown(event) && KeyUtil.isRightKey(event)) return arrowScroll(FOCUS_RIGHT);
return false;
}

@ -50,21 +50,21 @@ public class CustomKeyDownLive extends GestureDetector.SimpleOnGestureListener {
}
private void check(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN && KeyUtil.isLeftKey(event)) {
if (KeyUtil.isActionDown(event) && KeyUtil.isLeftKey(event)) {
listener.onSeeking(subTime());
} else if (event.getAction() == KeyEvent.ACTION_DOWN && KeyUtil.isRightKey(event)) {
} else if (KeyUtil.isActionDown(event) && KeyUtil.isRightKey(event)) {
listener.onSeeking(addTime());
} else if (event.getAction() == KeyEvent.ACTION_DOWN && KeyUtil.isUpKey(event)) {
} else if (KeyUtil.isActionDown(event) && KeyUtil.isUpKey(event)) {
listener.onKeyUp();
} else if (event.getAction() == KeyEvent.ACTION_DOWN && KeyUtil.isDownKey(event)) {
} else if (KeyUtil.isActionDown(event) && KeyUtil.isDownKey(event)) {
listener.onKeyDown();
} else if (event.getAction() == KeyEvent.ACTION_UP && KeyUtil.isLeftKey(event)) {
} else if (KeyUtil.isActionUp(event) && KeyUtil.isLeftKey(event)) {
listener.onKeyLeft(holdTime);
} else if (event.getAction() == KeyEvent.ACTION_UP && KeyUtil.isRightKey(event)) {
} else if (KeyUtil.isActionUp(event) && KeyUtil.isRightKey(event)) {
listener.onKeyRight(holdTime);
} else if (event.getAction() == KeyEvent.ACTION_UP && KeyUtil.isDigitKey(event)) {
} else if (KeyUtil.isActionUp(event) && KeyUtil.isDigitKey(event)) {
onKeyDown(event.getKeyCode());
} else if (event.getAction() == KeyEvent.ACTION_UP && KeyUtil.isEnterKey(event)) {
} else if (KeyUtil.isActionUp(event) && KeyUtil.isEnterKey(event)) {
listener.onKeyCenter();
} else if (KeyUtil.isMenuKey(event) || event.isLongPress() && KeyUtil.isEnterKey(event)) {
listener.onMenu();

@ -47,19 +47,19 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener {
}
private void check(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN && KeyUtil.isLeftKey(event)) {
if (KeyUtil.isActionDown(event) && KeyUtil.isLeftKey(event)) {
listener.onSeeking(subTime());
} else if (event.getAction() == KeyEvent.ACTION_DOWN && KeyUtil.isRightKey(event)) {
} else if (KeyUtil.isActionDown(event) && KeyUtil.isRightKey(event)) {
listener.onSeeking(addTime());
} else if (event.getAction() == KeyEvent.ACTION_UP && (KeyUtil.isLeftKey(event) || KeyUtil.isRightKey(event))) {
} else if (KeyUtil.isActionUp(event) && (KeyUtil.isLeftKey(event) || KeyUtil.isRightKey(event))) {
App.post(() -> listener.onSeekTo(holdTime), 250);
} else if (event.getAction() == KeyEvent.ACTION_UP && KeyUtil.isUpKey(event)) {
} else if (KeyUtil.isActionUp(event) && KeyUtil.isUpKey(event)) {
if (changeSpeed) listener.onSpeedEnd();
else listener.onKeyUp();
changeSpeed = false;
} else if (event.getAction() == KeyEvent.ACTION_UP && KeyUtil.isDownKey(event)) {
} else if (KeyUtil.isActionUp(event) && KeyUtil.isDownKey(event)) {
listener.onKeyDown();
} else if (event.getAction() == KeyEvent.ACTION_UP && KeyUtil.isEnterKey(event)) {
} else if (KeyUtil.isActionUp(event) && KeyUtil.isEnterKey(event)) {
listener.onKeyCenter();
} else if (event.isLongPress() && KeyUtil.isUpKey(event)) {
listener.onSpeedUp();

@ -32,7 +32,7 @@ public class CustomLeftRightLayout extends LinearLayout {
}
private boolean hasEvent(KeyEvent event) {
return event.getAction() == KeyEvent.ACTION_DOWN && ((leftListener != null && KeyUtil.isLeftKey(event)) || (rightListener != null && KeyUtil.isRightKey(event)));
return KeyUtil.isActionDown(event) && ((leftListener != null && KeyUtil.isLeftKey(event)) || (rightListener != null && KeyUtil.isRightKey(event)));
}
@Override

@ -60,8 +60,8 @@ public class CustomTitleView extends AppCompatTextView {
}
private void onKeyDown(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_UP && KeyUtil.isEnterKey(event)) listener.showDialog();
else if (event.getAction() == KeyEvent.ACTION_DOWN && KeyUtil.isUpKey(event)) onKeyUp();
if (KeyUtil.isActionUp(event) && KeyUtil.isEnterKey(event)) listener.showDialog();
else if (KeyUtil.isActionDown(event) && KeyUtil.isUpKey(event)) onKeyUp();
}
private void onKeyUp() {

@ -30,7 +30,7 @@ public class CustomTypeView extends AppCompatTextView {
}
private boolean hasEvent(KeyEvent event) {
return !coolDown && event.getAction() == KeyEvent.ACTION_DOWN && KeyUtil.isUpKey(event);
return !coolDown && KeyUtil.isActionDown(event) && KeyUtil.isUpKey(event);
}
@Override

@ -32,7 +32,7 @@ public class CustomUpDownView extends AppCompatTextView {
}
private boolean hasEvent(KeyEvent event) {
return event.getAction() == KeyEvent.ACTION_DOWN && ((upListener != null && KeyUtil.isUpKey(event)) || (downListener != null && KeyUtil.isDownKey(event)));
return KeyUtil.isActionDown(event) && ((upListener != null && KeyUtil.isUpKey(event)) || (downListener != null && KeyUtil.isDownKey(event)));
}
@Override

@ -17,6 +17,7 @@ import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;
import com.fongmi.android.tv.R;
import com.fongmi.android.tv.utils.KeyUtil;
import com.fongmi.android.tv.utils.ResUtil;
public class CustomViewPager extends ViewPager {
@ -46,8 +47,8 @@ public class CustomViewPager extends ViewPager {
@Override
public boolean executeKeyEvent(@NonNull KeyEvent event) {
if (findFocus() instanceof TextView) return false;
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) return arrowScroll(FOCUS_LEFT);
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT) return arrowScroll(FOCUS_RIGHT);
if (KeyUtil.isActionDown(event) && KeyUtil.isLeftKey(event)) return arrowScroll(FOCUS_LEFT);
if (KeyUtil.isActionDown(event) && KeyUtil.isRightKey(event)) return arrowScroll(FOCUS_RIGHT);
return false;
}

@ -35,4 +35,12 @@ public class KeyUtil {
public static boolean isMenuKey(KeyEvent event) {
return event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_MENU;
}
public static boolean isActionDown(KeyEvent event) {
return event.getAction() == KeyEvent.ACTION_DOWN;
}
public static boolean isActionUp(KeyEvent event) {
return event.getAction() == KeyEvent.ACTION_UP;
}
}

@ -6,56 +6,50 @@
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
<LinearLayout
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingStart="24dp"
android:paddingTop="24dp"
android:paddingEnd="24dp"
android:paddingBottom="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/logo"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginEnd="12dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:visibility="gone"
tools:src="@drawable/ic_logo"
tools:visibility="visible" />
<ImageView
android:id="@+id/logo"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginEnd="12dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:visibility="gone"
tools:src="@drawable/ic_logo"
tools:visibility="visible" />
<com.fongmi.android.tv.ui.custom.CustomTitleView
android:id="@+id/site"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|start"
android:ellipsize="marquee"
android:focusable="false"
android:singleLine="true"
android:text="@string/app_name"
android:textColor="@color/white"
android:textSize="24sp" />
</LinearLayout>
<com.fongmi.android.tv.ui.custom.CustomTitleView
android:id="@+id/site"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="12dp"
android:layout_weight="1"
android:ellipsize="marquee"
android:focusable="false"
android:singleLine="true"
android:text="@string/app_name"
android:textColor="@color/white"
android:textSize="24sp" />
<TextView
android:id="@+id/clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:textColor="@color/white"
android:textSize="24sp"
tools:text="07/25 09:20:00" />
</FrameLayout>
</LinearLayout>
<com.fongmi.android.tv.ui.custom.ProgressLayout
android:id="@+id/progressLayout"

@ -13,6 +13,8 @@ import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import com.fongmi.android.tv.utils.KeyUtil;
public class CustomMovement extends ScrollingMovementMethod {
private static final int CLICK = 1;
@ -43,7 +45,7 @@ public class CustomMovement extends ScrollingMovementMethod {
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0 && action(CLICK, widget, buffer)) {
if (KeyUtil.isActionDown(event) && event.getRepeatCount() == 0 && action(CLICK, widget, buffer)) {
return true;
}
}

Loading…
Cancel
Save