LiuHaiScreenUtil.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package com.edufound.mobile.xxt.util;
  2. import android.app.Activity;
  3. import android.view.DisplayCutout;
  4. import android.view.View;
  5. import android.view.WindowInsets;
  6. import android.view.WindowManager;
  7. public class LiuHaiScreenUtil {
  8. // /**
  9. // * 判断是否是刘海屏
  10. // *
  11. // * @return
  12. // */
  13. // public static boolean hasNotchScreen(Activity activity) {
  14. // if (getInt("ro.miui.notch", activity) == 1 || hasNotchAtHuawei() || hasNotchAtOPPO()
  15. // || hasNotchAtVivo() || isAndroidP(activity) != null) { //TODO 各种品牌
  16. // return true;
  17. // }
  18. //
  19. // return false;
  20. // }
  21. /**
  22. * Android P 刘海屏判断
  23. *
  24. * @param activity
  25. * @return
  26. */
  27. public static DisplayCutout isAndroidP(Activity activity) {
  28. View decorView = activity.getWindow().getDecorView();
  29. if (decorView != null && android.os.Build.VERSION.SDK_INT >= 28) {
  30. WindowInsets windowInsets = decorView.getRootWindowInsets();
  31. if (windowInsets != null)
  32. return windowInsets.getDisplayCutout();
  33. }
  34. return null;
  35. }
  36. // /**
  37. // * 小米刘海屏判断.
  38. // * @return 0 if it is not notch ; return 1 means notch
  39. // * @throws IllegalArgumentException if the key exceeds 32 characters
  40. // */
  41. // public static int getInt(String key,Activity activity) {
  42. // int result = 0;
  43. // if (isXiaomi()){
  44. // try {
  45. // ClassLoader classLoader = activity.getClassLoader();
  46. // @SuppressWarnings("rawtypes")
  47. // Class SystemProperties = classLoader.loadClass("android.os.SystemProperties");
  48. // //参数类型
  49. // @SuppressWarnings("rawtypes")
  50. // Class[] paramTypes = new Class[2];
  51. // paramTypes[0] = String.class;
  52. // paramTypes[1] = int.class;
  53. // Method getInt = SystemProperties.getMethod("getInt", paramTypes);
  54. // //参数
  55. // Object[] params = new Object[2];
  56. // params[0] = new String(key);
  57. // params[1] = new Integer(0);
  58. // result = (Integer) getInt.invoke(SystemProperties, params);
  59. //
  60. // } catch (ClassNotFoundException e) {
  61. // e.printStackTrace();
  62. // } catch (NoSuchMethodException e) {
  63. // e.printStackTrace();
  64. // } catch (IllegalAccessException e) {
  65. // e.printStackTrace();
  66. // } catch (IllegalArgumentException e) {
  67. // e.printStackTrace();
  68. // } catch (InvocationTargetException e) {
  69. // e.printStackTrace();
  70. // }
  71. // }
  72. // return result;
  73. // }
  74. // /**
  75. // * 华为刘海屏判断
  76. // * @return
  77. // */
  78. // public static boolean hasNotchAtHuawei() {
  79. // boolean ret = false;
  80. // try {
  81. // ClassLoader classLoader = StaticContext.CONTEXT.getClassLoader();
  82. // Class HwNotchSizeUtil = classLoader.loadClass("com.huawei.android.util.HwNotchSizeUtil");
  83. // Method get = HwNotchSizeUtil.getMethod("hasNotchInScreen");
  84. // ret = (boolean) get.invoke(HwNotchSizeUtil);
  85. // } catch (ClassNotFoundException e) {
  86. // Logger.e("hasNotchAtHuawei ClassNotFoundException");
  87. // } catch (NoSuchMethodException e) {
  88. // Logger.e("hasNotchAtHuawei NoSuchMethodException");
  89. // } catch (Exception e) {
  90. // Logger.e( "hasNotchAtHuawei Exception");
  91. // } finally {
  92. // return ret;
  93. // }
  94. // }
  95. // public static final int VIVO_NOTCH = 0x00000020;//是否有刘海
  96. // public static final int VIVO_FILLET = 0x00000008;//是否有圆角
  97. // /**
  98. // * VIVO刘海屏判断
  99. // * @return
  100. // */
  101. // public static boolean hasNotchAtVivo() {
  102. // boolean ret = false;
  103. // try {
  104. // ClassLoader classLoader = StaticContext.CONTEXT.getClassLoader();
  105. // Class FtFeature = classLoader.loadClass("android.util.FtFeature");
  106. // Method method = FtFeature.getMethod("isFeatureSupport", int.class);
  107. // ret = (boolean) method.invoke(FtFeature, VIVO_NOTCH);
  108. // } catch (ClassNotFoundException e) {
  109. // Logger.e( "hasNotchAtVivo ClassNotFoundException");
  110. // } catch (NoSuchMethodException e) {
  111. // Logger.e( "hasNotchAtVivo NoSuchMethodException");
  112. // } catch (Exception e) {
  113. // Logger.e( "hasNotchAtVivo Exception");
  114. // } finally {
  115. // return ret;
  116. // }
  117. // }
  118. // /**
  119. // * OPPO刘海屏判断
  120. // * @return
  121. // */
  122. // public static boolean hasNotchAtOPPO() {
  123. // return StaticContext.CONTEXT.getPackageManager().hasSystemFeature("com.oppo.feature.screen.heteromorphism");
  124. // }
  125. public static void openFullScreenModel(Activity activity) {
  126. // activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
  127. WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
  128. lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
  129. activity.getWindow().setAttributes(lp);
  130. View decorView = activity.getWindow().getDecorView();
  131. int systemUiVisibility = decorView.getSystemUiVisibility();
  132. int flags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
  133. | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
  134. | View.SYSTEM_UI_FLAG_FULLSCREEN;
  135. systemUiVisibility |= flags;
  136. activity.getWindow().getDecorView().setSystemUiVisibility(systemUiVisibility);
  137. }
  138. }