Commit 6b493b59 authored by fallenstardust's avatar fallenstardust

没写完

parent 6105b329
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
<meta-data <meta-data
android:name="android.app.lib_name" android:name="android.app.lib_name"
android:value="YGOMobile"/> android:value="YGOMobile"/>
<meta-data
android:name="android.notch_support"
android:value="true"/>
</activity> </activity>
<receiver android:name="cn.garymb.ygomobile.GameReceiver" <receiver android:name="cn.garymb.ygomobile.GameReceiver"
android:process=":game" > android:process=":game" >
......
...@@ -15,6 +15,7 @@ import org.json.JSONArray; ...@@ -15,6 +15,7 @@ import org.json.JSONArray;
import java.io.File; import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
...@@ -65,17 +66,52 @@ public class AppsSettings { ...@@ -65,17 +66,52 @@ public class AppsSettings {
update(context); update(context);
} }
public static int getRealHeight(Context context) { //检测是否存在刘海屏
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); public static boolean hasNotchInScreen(Context context) {
Display display = windowManager.getDefaultDisplay(); boolean ret = false;
DisplayMetrics dm = new DisplayMetrics(); try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { ClassLoader cl = context.getClassLoader();
display.getRealMetrics(dm); Class HwNotchSizeUtil = cl.loadClass("com.huawei.android.util.HwNotchSizeUtil");
} else { Method get = HwNotchSizeUtil.getMethod("hasNotchInScreen");
display.getMetrics(dm); 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;
} }
int realHeight = dm.widthPixels; }
return realHeight;
//获取刘海屏的参数
public static int[] getNotchSize(Context context) {
int[] notchSize = new int[]{0, 0};
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 int getStatusBarHeight(Context context) {
int StatusBarHeight = 0;
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
StatusBarHeight = context.getResources().getDimensionPixelSize(resourceId);
}
return StatusBarHeight;
} }
public void update(Context context) { public void update(Context context) {
...@@ -87,14 +123,16 @@ public class AppsSettings { ...@@ -87,14 +123,16 @@ public class AppsSettings {
if (dm != null) { if (dm != null) {
int height = Math.max(dm.widthPixels, dm.heightPixels); int height = Math.max(dm.widthPixels, dm.heightPixels);
if (mScreenHeight == Math.max(mScreenHeight, mScreenWidth)) { if (mScreenHeight == Math.max(mScreenHeight, mScreenWidth)) {
mScreenHeight = getRealHeight(context); mScreenHeight = height;
} else { } else {
mScreenWidth = getRealHeight(context); mScreenWidth = height;
} }
} }
}
if (!hasNotchInScreen(context)) {
} }
Log.i("屏幕不算虚拟键", "" + mScreenHeight); Log.i("屏幕不算虚拟键", "" + mScreenHeight);
Log.i("屏幕总宽", "" + getRealHeight(context));
} }
public int getAppVersion() { public int getAppVersion() {
......
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