Commit f9f9ba08 authored by feihuaduo's avatar feihuaduo

修复ygo界面Android p刘海检测不到的问题

parent e5779772
...@@ -201,6 +201,7 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -201,6 +201,7 @@ public class YGOMobileActivity extends NativeActivity implements
} }
private void fullscreen() { private void fullscreen() {
//如果是沉浸模式 //如果是沉浸模式
if (app().isImmerSiveMode()) { if (app().isImmerSiveMode()) {
mFullScreenUtils.fullscreen(); mFullScreenUtils.fullscreen();
......
...@@ -44,11 +44,14 @@ public class AppsSettings { ...@@ -44,11 +44,14 @@ public class AppsSettings {
private Context context; private Context context;
private PreferenceFragmentPlus.SharedPreferencesPlus mSharedPreferences; private PreferenceFragmentPlus.SharedPreferencesPlus mSharedPreferences;
private float mScreenHeight, mScreenWidth, mDensity; private float mScreenHeight, mScreenWidth, mDensity;
public static int notchHeight;
private AppsSettings(Context context) { private AppsSettings(Context context) {
this.context = context; this.context = context;
mSharedPreferences = PreferenceFragmentPlus.SharedPreferencesPlus.create(context, context.getPackageName() + ".settings"); mSharedPreferences = PreferenceFragmentPlus.SharedPreferencesPlus.create(context, context.getPackageName() + ".settings");
mSharedPreferences.setAutoSave(true); mSharedPreferences.setAutoSave(true);
Log.e("YGOMobile", "初始化AppsSettings");
update(context); update(context);
} }
...@@ -62,52 +65,21 @@ public class AppsSettings { ...@@ -62,52 +65,21 @@ public class AppsSettings {
return sAppsSettings; return sAppsSettings;
} }
//获取刘海屏的参数 //获取刘海高度
public static int[] getNotchSize(Context context) { public int getNotchHeight() {
int[] notchSize = new int[]{0, 0}; return notchHeight;
try {
ClassLoader cl = context.getClassLoader();
Class HwNotchSizeUtil = cl.loadClass("com.huawei.android.util.HwNotchSizeUtil");
Method get = HwNotchSizeUtil.getMethod("getNotchSize");
notchSize = (int[]) get.invoke(HwNotchSizeUtil);
} catch (ClassNotFoundException e) {
Log.e("test", "getNotchSize ClassNotFoundException");
} catch (NoSuchMethodException e) {
Log.e("test", "getNotchSize NoSuchMethodException");
} catch (Exception e) {
Log.e("test", "getNotchSize Exception");
} finally {
return notchSize;
}
} }
//检测是否存在刘海屏 //设置刘海高度
public static boolean hasNotchInScreen(Context context) { public void setNotchHeight(int notchHeight) {
boolean ret = false;
try {
ClassLoader cl = context.getClassLoader();
Class HwNotchSizeUtil = cl.loadClass("com.huawei.android.util.HwNotchSizeUtil");
Method get = HwNotchSizeUtil.getMethod("hasNotchInScreen");
ret = (boolean) get.invoke(HwNotchSizeUtil);
} catch (ClassNotFoundException e) {
Log.e("test", "hasNotchInScreen ClassNotFoundException");
} catch (NoSuchMethodException e) {
Log.e("test", "hasNotchInScreen NoSuchMethodException");
} catch (Exception e) {
Log.e("test", "hasNotchInScreen Exception");
} finally {
return ret;
}
}
//获取系统状态栏高度 this.notchHeight = notchHeight;
public static int getStatusBarHeight(Context context) { try {
int StatusBarHeight = 0; FileLogUtil.writeAndTime("设置刘海高度"+notchHeight);
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); FileLogUtil.writeAndTime("当前文件设置刘海高度"+this.notchHeight);
if (resourceId > 0) { } catch (IOException e) {
StatusBarHeight = context.getResources().getDimensionPixelSize(resourceId); e.printStackTrace();
} }
return StatusBarHeight;
} }
public File getSystemConfig() { public File getSystemConfig() {
...@@ -119,65 +91,47 @@ public class AppsSettings { ...@@ -119,65 +91,47 @@ public class AppsSettings {
mScreenHeight = context.getResources().getDisplayMetrics().heightPixels; mScreenHeight = context.getResources().getDisplayMetrics().heightPixels;
mScreenWidth = context.getResources().getDisplayMetrics().widthPixels; mScreenWidth = context.getResources().getDisplayMetrics().widthPixels;
if (context instanceof Activity) { if (isImmerSiveMode() && context instanceof Activity) {
DisplayMetrics dm = SystemUtils.getHasVirtualDisplayMetrics((Activity) context); DisplayMetrics dm = SystemUtils.getHasVirtualDisplayMetrics((Activity) context);
if (dm != null) { if (dm != null) {
int height = Math.max(dm.widthPixels, dm.heightPixels); int height = Math.max(dm.widthPixels, dm.heightPixels);
try { try {
FileLogUtil.writeAndTime("原始长"+mScreenHeight); FileLogUtil.writeAndTime("是否沉浸: " + isImmerSiveMode());
FileLogUtil.writeAndTime("原始宽"+mScreenWidth); FileLogUtil.writeAndTime("原始长: " + mScreenHeight);
FileLogUtil.writeAndTime("界面长"+dm.heightPixels); FileLogUtil.writeAndTime("原始宽: " + mScreenWidth);
FileLogUtil.writeAndTime("界面宽"+dm.widthPixels); FileLogUtil.writeAndTime("界面长: " + dm.heightPixels);
FileLogUtil.writeAndTime("界面宽: " + dm.widthPixels);
FileLogUtil.writeAndTime("刘海长: "+notchHeight);
FileLogUtil.writeAndTime("get刘海长: "+getNotchHeight());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
if(isImmerSiveMode()) height -= notchHeight;
return;
ScreenUtil.findNotchInformation(((Activity) context), new ScreenUtil.FindNotchInformation() {
@Override
public void onNotchInformation(boolean isNotch, int notchHeight, int phoneType) {
int height = Math.max(dm.widthPixels, dm.heightPixels);
try {
FileLogUtil.writeAndTime("是否有刘海: "+isNotch);
FileLogUtil.writeAndTime("刘海高"+notchHeight);
FileLogUtil.writeAndTime("height值: "+height);
} catch (IOException e) {
e.printStackTrace();
}
if (isNotch) {
height-=notchHeight;
}
try {
FileLogUtil.writeAndTime("处理后height值: "+height);
} catch (IOException e) {
e.printStackTrace();
}
if (mScreenHeight> mScreenWidth) {
mScreenHeight = height;
} else {
mScreenWidth = height;
}
try {
FileLogUtil.writeAndTime("转换后长"+mScreenHeight);
FileLogUtil.writeAndTime("转换后宽"+mScreenWidth);
} catch (IOException e) {
e.printStackTrace();
}
} try {
}); FileLogUtil.writeAndTime("处理后height值: " + height);
} catch (IOException e) {
e.printStackTrace();
}
if (mScreenHeight > mScreenWidth) {
mScreenHeight = height;
} else {
mScreenWidth = height;
}
try {
FileLogUtil.writeAndTime("转换后长: " + mScreenHeight);
FileLogUtil.writeAndTime("转换后宽: " + mScreenWidth);
} catch (IOException e) {
e.printStackTrace();
}
} }
} }
Log.i("机屏幕高度", "" + mScreenHeight);
Log.i("机屏幕宽度", "" + mScreenWidth);
for (int i : getNotchSize(context))
Log.i("机刘海高度", "刘海高度" + i);
Log.i("机状态栏高度", "" + getStatusBarHeight(context));
Log.i("机是否存在刘海", "" + hasNotchInScreen(context));
} }
public int getAppVersion() { public int getAppVersion() {
......
package cn.garymb.ygomobile.ui.activities;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import cn.garymb.ygomobile.lite.R;
public class DebugActivity extends BaseActivity {
private RecyclerView rv_list;
private Toolbar toolbar;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.debug_activity);
initView();
}
private void initView() {
rv_list=$(R.id.rv_list);
toolbar=$(R.id.toolbar);
setSupportActionBar(toolbar);
enableBackHome();
}
}
package cn.garymb.ygomobile.ui.adapters;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
public class DebugListRecyclerAdapter extends RecyclerView.Adapter<DebugListRecyclerAdapter.ViewHolder> {
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return null;
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
}
@Override
public int getItemCount() {
return 0;
}
class ViewHolder extends RecyclerView.ViewHolder{
public ViewHolder(View itemView) {
super(itemView);
}
}
}
package cn.garymb.ygomobile.ui.home; package cn.garymb.ygomobile.ui.home;
import android.app.Activity;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
...@@ -47,6 +48,7 @@ import org.greenrobot.eventbus.EventBus; ...@@ -47,6 +48,7 @@ import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode; import org.greenrobot.eventbus.ThreadMode;
import java.io.IOException;
import java.util.List; import java.util.List;
import cn.garymb.ygodata.YGOGameOptions; import cn.garymb.ygodata.YGOGameOptions;
...@@ -70,6 +72,8 @@ import cn.garymb.ygomobile.ui.plus.DialogPlus; ...@@ -70,6 +72,8 @@ import cn.garymb.ygomobile.ui.plus.DialogPlus;
import cn.garymb.ygomobile.ui.plus.ServiceDuelAssistant; import cn.garymb.ygomobile.ui.plus.ServiceDuelAssistant;
import cn.garymb.ygomobile.ui.preference.SettingsActivity; import cn.garymb.ygomobile.ui.preference.SettingsActivity;
import cn.garymb.ygomobile.utils.AlipayPayUtils; import cn.garymb.ygomobile.utils.AlipayPayUtils;
import cn.garymb.ygomobile.utils.FileLogUtil;
import cn.garymb.ygomobile.utils.ScreenUtil;
public abstract class HomeActivity extends BaseActivity implements NavigationView.OnNavigationItemSelectedListener { public abstract class HomeActivity extends BaseActivity implements NavigationView.OnNavigationItemSelectedListener {
protected SwipeMenuRecyclerView mServerList; protected SwipeMenuRecyclerView mServerList;
...@@ -130,6 +134,24 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie ...@@ -130,6 +134,24 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
//萌卡 //萌卡
StartMycard(); StartMycard();
checkNotch();
}
//检查是否有刘海
private void checkNotch() {
ScreenUtil.findNotchInformation(HomeActivity.this, new ScreenUtil.FindNotchInformation() {
@Override
public void onNotchInformation(boolean isNotch, int notchHeight, int phoneType) {
try {
FileLogUtil.writeAndTime("检查刘海"+isNotch+" "+notchHeight);
} catch (IOException e) {
e.printStackTrace();
}
// AppsSettings.get().setNotchHeight(notchHeight);
AppsSettings.notchHeight=notchHeight;
}
});
} }
@Override @Override
......
...@@ -9,6 +9,7 @@ import android.util.Log; ...@@ -9,6 +9,7 @@ import android.util.Log;
import android.view.DisplayCutout; import android.view.DisplayCutout;
import android.view.View; import android.view.View;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.List; import java.util.List;
...@@ -64,12 +65,28 @@ public class ScreenUtil { ...@@ -64,12 +65,28 @@ public class ScreenUtil {
public void run() { public void run() {
DisplayCutout cutout = decorView.getRootWindowInsets().getDisplayCutout(); DisplayCutout cutout = decorView.getRootWindowInsets().getDisplayCutout();
if (cutout == null) { if (cutout == null) {
try {
FileLogUtil.writeAndTime("Android P刘海: cotout为空");
} catch (IOException e) {
e.printStackTrace();
}
findNotchPInformation.onNotchInformation(false, 0, NOTCH_TYPE_PHONE_ANDROID_P); findNotchPInformation.onNotchInformation(false, 0, NOTCH_TYPE_PHONE_ANDROID_P);
} else { } else {
List<Rect> rects = cutout.getBoundingRects(); List<Rect> rects = cutout.getBoundingRects();
if (rects == null || rects.size() == 0) { if (rects == null || rects.size() == 0) {
try {
FileLogUtil.writeAndTime("Android P刘海: rects:"+(rects==null));
} catch (IOException e) {
e.printStackTrace();
}
findNotchPInformation.onNotchInformation(false, 0, NOTCH_TYPE_PHONE_ANDROID_P); findNotchPInformation.onNotchInformation(false, 0, NOTCH_TYPE_PHONE_ANDROID_P);
} else { } else {
try {
FileLogUtil.writeAndTime("Android P刘海: 刘海存在,个数为"+rects.size());
} catch (IOException e) {
e.printStackTrace();
}
findNotchPInformation.onNotchInformation(true, cutout.getSafeInsetTop(), NOTCH_TYPE_PHONE_ANDROID_P); findNotchPInformation.onNotchInformation(true, cutout.getSafeInsetTop(), NOTCH_TYPE_PHONE_ANDROID_P);
//刘海的数量可以是多个 //刘海的数量可以是多个
// for (Rect rect : rects) { // for (Rect rect : rects) {
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="@layout/content_toolbar"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment