Fix screen width and height bug

pull/589/head
FongMi 9 months ago
parent 7e86b3659d
commit fa12b77a40
  1. 32
      app/src/main/java/com/fongmi/android/tv/utils/ResUtil.java
  2. 10
      app/src/mobile/java/com/fongmi/android/tv/Product.java
  3. 2
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/CollectActivity.java
  4. 8
      app/src/mobile/java/com/fongmi/android/tv/ui/custom/CustomKeyDownLive.java
  5. 4
      app/src/mobile/java/com/fongmi/android/tv/ui/custom/CustomKeyDownVod.java

@ -1,15 +1,17 @@
package com.fongmi.android.tv.utils;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Display;
import android.view.MotionEvent;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
@ -25,27 +27,31 @@ import com.fongmi.android.tv.App;
public class ResUtil {
public static DisplayMetrics getDisplayMetrics() {
return App.get().getResources().getDisplayMetrics();
return Resources.getSystem().getDisplayMetrics();
}
public static int getScreenWidth() {
return getDisplayMetrics().widthPixels;
public static WindowManager getWindowManager() {
return (WindowManager) App.get().getSystemService(Context.WINDOW_SERVICE);
}
public static int getScreenWidth(Context context) {
return context.getResources().getDisplayMetrics().widthPixels;
public static int getScreenWidth() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
return getWindowManager().getCurrentWindowMetrics().getBounds().width();
} else {
return getDisplayMetrics().widthPixels;
}
}
public static int getScreenHeight() {
return getDisplayMetrics().heightPixels;
}
public static int getScreenHeight(Context context) {
return context.getResources().getDisplayMetrics().heightPixels;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
return getWindowManager().getCurrentWindowMetrics().getBounds().height();
} else {
return getDisplayMetrics().heightPixels;
}
}
public static boolean isEdge(Activity activity, MotionEvent e, int edge) {
return e.getRawX() < edge || e.getRawX() > getScreenWidth(activity) - edge || e.getRawY() < edge || e.getRawY() > getScreenHeight(activity) - edge;
public static boolean isEdge(MotionEvent e, int edge) {
return e.getRawX() < edge || e.getRawX() > getScreenWidth() - edge || e.getRawY() < edge || e.getRawY() > getScreenHeight() - edge;
}
public static boolean isLand(Context context) {

@ -29,15 +29,15 @@ public class Product {
int column = getColumn(context, style);
int space = ResUtil.dp2px(32) + ResUtil.dp2px(16 * (column - 1));
if (style.isOval()) space += ResUtil.dp2px(column * 16);
return getSpec(context, space, column, style);
return getSpec(space, column, style);
}
public static int[] getSpec(Context context, int space, int column) {
return getSpec(context, space, column, Style.rect());
public static int[] getSpec(int space, int column) {
return getSpec(space, column, Style.rect());
}
private static int[] getSpec(Context context, int space, int column, Style style) {
int base = ResUtil.getScreenWidth(context) - space;
private static int[] getSpec(int space, int column, Style style) {
int base = ResUtil.getScreenWidth() - space;
int width = base / column;
int height = (int) (width / style.getRatio());
return new int[]{width, height};

@ -141,7 +141,7 @@ public class CollectActivity extends BaseActivity implements CustomScroller.Call
private void setViewType(int viewType) {
int count = Product.getColumn(this) - 1;
mSearchAdapter.setViewType(viewType, count);
mSearchAdapter.setSize(Product.getSpec(this, ResUtil.dp2px(128 + (count) * 16), count));
mSearchAdapter.setSize(Product.getSpec(ResUtil.dp2px(128 + (count) * 16), count));
((GridLayoutManager) mBinding.recycler.getLayoutManager()).setSpanCount(mSearchAdapter.isGrid() ? count : 1);
mBinding.view.setImageResource(mSearchAdapter.isGrid() ? R.drawable.ic_action_list : R.drawable.ic_action_grid);
}

@ -60,7 +60,7 @@ public class CustomKeyDownLive extends GestureDetector.SimpleOnGestureListener {
}
private boolean isEdge(MotionEvent e) {
return ResUtil.isEdge(activity, e, ResUtil.dp2px(40));
return ResUtil.isEdge(e, ResUtil.dp2px(24));
}
@Override
@ -104,7 +104,7 @@ public class CustomKeyDownLive extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onSingleTapConfirmed(@NonNull MotionEvent e) {
int half = ResUtil.getScreenWidth(activity) / 2;
int half = ResUtil.getScreenWidth() / 2;
if (e.getX() > half || lock) listener.onDoubleTap();
else listener.onSingleTap();
return true;
@ -124,7 +124,7 @@ public class CustomKeyDownLive extends GestureDetector.SimpleOnGestureListener {
}
private void checkFunc(float distanceX, float distanceY, MotionEvent e2) {
int four = ResUtil.getScreenWidth(activity) / 4;
int four = ResUtil.getScreenWidth() / 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;
@ -146,7 +146,7 @@ public class CustomKeyDownLive extends GestureDetector.SimpleOnGestureListener {
}
private void checkSide(MotionEvent e2) {
int half = ResUtil.getScreenWidth(activity) / 2;
int half = ResUtil.getScreenWidth() / 2;
if (e2.getX() > half) changeVolume = true;
else changeBright = true;
}

@ -55,7 +55,7 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener {
}
private boolean isEdge(MotionEvent e) {
return ResUtil.isEdge(activity, e, ResUtil.dp2px(40));
return ResUtil.isEdge(e, ResUtil.dp2px(24));
}
@Override
@ -115,7 +115,7 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener {
}
private void checkSide(MotionEvent e2) {
int half = ResUtil.getScreenWidth(activity) / 2;
int half = ResUtil.getScreenWidth() / 2;
if (e2.getX() > half) changeVolume = true;
else changeBright = true;
}

Loading…
Cancel
Save