LiuHaiScreenUtil.java 5.5 KB

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