123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- package com.edufound.mobile.util;
- import android.app.Activity;
- import android.view.DisplayCutout;
- import android.view.View;
- import android.view.Window;
- import android.view.WindowInsets;
- import android.view.WindowManager;
- public class LiuHaiScreenUtil {
- // /**
- // * 判断是否是刘海屏
- // *
- // * @return
- // */
- // public static boolean hasNotchScreen(Activity activity) {
- // if (getInt("ro.miui.notch", activity) == 1 || hasNotchAtHuawei() || hasNotchAtOPPO()
- // || hasNotchAtVivo() || isAndroidP(activity) != null) { //TODO 各种品牌
- // return true;
- // }
- //
- // return false;
- // }
- /**
- * Android P 刘海屏判断
- *
- * @param activity
- * @return
- */
- public static DisplayCutout isAndroidP(Activity activity) {
- View decorView = activity.getWindow().getDecorView();
- if (decorView != null && android.os.Build.VERSION.SDK_INT >= 28) {
- WindowInsets windowInsets = decorView.getRootWindowInsets();
- if (windowInsets != null)
- return windowInsets.getDisplayCutout();
- }
- return null;
- }
- // /**
- // * 小米刘海屏判断.
- // * @return 0 if it is not notch ; return 1 means notch
- // * @throws IllegalArgumentException if the key exceeds 32 characters
- // */
- // public static int getInt(String key,Activity activity) {
- // int result = 0;
- // if (isXiaomi()){
- // try {
- // ClassLoader classLoader = activity.getClassLoader();
- // @SuppressWarnings("rawtypes")
- // Class SystemProperties = classLoader.loadClass("android.os.SystemProperties");
- // //参数类型
- // @SuppressWarnings("rawtypes")
- // Class[] paramTypes = new Class[2];
- // paramTypes[0] = String.class;
- // paramTypes[1] = int.class;
- // Method getInt = SystemProperties.getMethod("getInt", paramTypes);
- // //参数
- // Object[] params = new Object[2];
- // params[0] = new String(key);
- // params[1] = new Integer(0);
- // result = (Integer) getInt.invoke(SystemProperties, params);
- //
- // } catch (ClassNotFoundException e) {
- // e.printStackTrace();
- // } catch (NoSuchMethodException e) {
- // e.printStackTrace();
- // } catch (IllegalAccessException e) {
- // e.printStackTrace();
- // } catch (IllegalArgumentException e) {
- // e.printStackTrace();
- // } catch (InvocationTargetException e) {
- // e.printStackTrace();
- // }
- // }
- // return result;
- // }
- // /**
- // * 华为刘海屏判断
- // * @return
- // */
- // public static boolean hasNotchAtHuawei() {
- // boolean ret = false;
- // try {
- // ClassLoader classLoader = StaticContext.CONTEXT.getClassLoader();
- // Class HwNotchSizeUtil = classLoader.loadClass("com.huawei.android.util.HwNotchSizeUtil");
- // Method get = HwNotchSizeUtil.getMethod("hasNotchInScreen");
- // ret = (boolean) get.invoke(HwNotchSizeUtil);
- // } catch (ClassNotFoundException e) {
- // Logger.e("hasNotchAtHuawei ClassNotFoundException");
- // } catch (NoSuchMethodException e) {
- // Logger.e("hasNotchAtHuawei NoSuchMethodException");
- // } catch (Exception e) {
- // Logger.e( "hasNotchAtHuawei Exception");
- // } finally {
- // return ret;
- // }
- // }
- // public static final int VIVO_NOTCH = 0x00000020;//是否有刘海
- // public static final int VIVO_FILLET = 0x00000008;//是否有圆角
- // /**
- // * VIVO刘海屏判断
- // * @return
- // */
- // public static boolean hasNotchAtVivo() {
- // boolean ret = false;
- // try {
- // ClassLoader classLoader = StaticContext.CONTEXT.getClassLoader();
- // Class FtFeature = classLoader.loadClass("android.util.FtFeature");
- // Method method = FtFeature.getMethod("isFeatureSupport", int.class);
- // ret = (boolean) method.invoke(FtFeature, VIVO_NOTCH);
- // } catch (ClassNotFoundException e) {
- // Logger.e( "hasNotchAtVivo ClassNotFoundException");
- // } catch (NoSuchMethodException e) {
- // Logger.e( "hasNotchAtVivo NoSuchMethodException");
- // } catch (Exception e) {
- // Logger.e( "hasNotchAtVivo Exception");
- // } finally {
- // return ret;
- // }
- // }
- // /**
- // * OPPO刘海屏判断
- // * @return
- // */
- // public static boolean hasNotchAtOPPO() {
- // return StaticContext.CONTEXT.getPackageManager().hasSystemFeature("com.oppo.feature.screen.heteromorphism");
- // }
- public static void openFullScreenModel(Activity activity) {
- // activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
- WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
- lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
- activity.getWindow().setAttributes(lp);
- View decorView = activity.getWindow().getDecorView();
- int systemUiVisibility = decorView.getSystemUiVisibility();
- int flags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
- | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
- | View.SYSTEM_UI_FLAG_FULLSCREEN;
- systemUiVisibility |= flags;
- activity.getWindow().getDecorView().setSystemUiVisibility(systemUiVisibility);
- }
- }
|