|
|
@@ -0,0 +1,88 @@
|
|
|
+package com.mgtech.base_library.util;
|
|
|
+
|
|
|
+import android.annotation.TargetApi;
|
|
|
+import android.content.res.Resources;
|
|
|
+import android.os.Build;
|
|
|
+import android.util.DisplayMetrics;
|
|
|
+import android.view.ViewConfiguration;
|
|
|
+
|
|
|
+import com.mgtech.base_library.contextUtil.ContextUtils;
|
|
|
+
|
|
|
+import java.lang.reflect.Method;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @ProjectName: BaseLibrary
|
|
|
+ * @Package: com.mgtech.base_library.util
|
|
|
+ * @ClassName: NavigationBarInfoUtil
|
|
|
+ * @Description: java类作用描述
|
|
|
+ * @Author: niusongtao
|
|
|
+ * @CreateDate: 2020/12/10 9:43
|
|
|
+ * @UpdateUser: 更新者:niusongtao
|
|
|
+ * @UpdateDate: 2020/12/10 9:43
|
|
|
+ * @UpdateRemark: 更新说明:
|
|
|
+ * @Version: 1.0
|
|
|
+ */
|
|
|
+public class NavigationBarInfoUtil {
|
|
|
+
|
|
|
+
|
|
|
+ private static final String TAG = "NavigationBarInfo";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取虚拟按键的高度
|
|
|
+ */
|
|
|
+ public static int getNavigationBarHeight() {
|
|
|
+ int result = 0;
|
|
|
+ if (hasNavBar()) {
|
|
|
+ Resources res = ContextUtils.getContext().getResources();
|
|
|
+ int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android");
|
|
|
+ if (resourceId > 0) {
|
|
|
+ result = res.getDimensionPixelSize(resourceId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ LogUtil.e(TAG,hasNavBar() + "NavigationBarHeight = "+result);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查是否存在虚拟按键栏
|
|
|
+ */
|
|
|
+ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
|
|
+ private static boolean hasNavBar() {
|
|
|
+ Resources res = ContextUtils.getContext().getResources();
|
|
|
+ int resourceId = res.getIdentifier("config_showNavigationBar", "bool", "android");
|
|
|
+ if (resourceId != 0) {
|
|
|
+ boolean hasNav = res.getBoolean(resourceId);
|
|
|
+ String sNavBarOverride = getNavBarOverride();
|
|
|
+ if ("1".equals(sNavBarOverride)) {
|
|
|
+ hasNav = false;
|
|
|
+ } else if ("0".equals(sNavBarOverride)) {
|
|
|
+ hasNav = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return hasNav;
|
|
|
+ } else {
|
|
|
+ return !ViewConfiguration.get(ContextUtils.getContext()).hasPermanentMenuKey();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断虚拟按键栏是否重写
|
|
|
+ */
|
|
|
+ private static String getNavBarOverride() {
|
|
|
+ String sNavBarOverride = null;
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
|
|
+ try {
|
|
|
+ Class c = Class.forName("android.os.SystemProperties");
|
|
|
+ Method m = c.getDeclaredMethod("get", String.class);
|
|
|
+ m.setAccessible(true);
|
|
|
+ sNavBarOverride = (String) m.invoke(null, "qemu.hw.mainkeys");
|
|
|
+ } catch (Exception e) {
|
|
|
+ LogUtil.e(TAG,e.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sNavBarOverride;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|