From e1c795ca03c682950a12a994f2ccb94d1ec107ac Mon Sep 17 00:00:00 2001
From: client_Hale <339726288@qq.com>
Date: 星期二, 11 九月 2018 15:10:56 +0800
Subject: [PATCH] Fixed 猫耳刘海屏支持

---
 ChannelDiff/mrgame/AndroidManifest.xml                                    |   24 +++
 ChannelDiff/mrgame/libs/app-game_mrgame-release.aar                       |    0 
 Project/app/src/main/java/com/secondworld/univeralsdk/MainActivity.java   |   33 ++++
 Project/app/src/main/java/com/secondworld/univeralsdk/NotchPhoneUtil.java |  347 +++++++++++++++++++++++++++++++++++++++++++
 Project/app/src/main/res/layout/activity_main.xml                         |    1 
 Project/app/src/main/AndroidManifest.xml                                  |   34 ++++
 6 files changed, 439 insertions(+), 0 deletions(-)

diff --git a/ChannelDiff/mrgame/AndroidManifest.xml b/ChannelDiff/mrgame/AndroidManifest.xml
index 23faa79..daf38a3 100644
--- a/ChannelDiff/mrgame/AndroidManifest.xml
+++ b/ChannelDiff/mrgame/AndroidManifest.xml
@@ -62,6 +62,15 @@
             <meta-data
                 android:name="unityplayer.SkipPermissionsDialog"
                 android:value="true" />
+            <meta-data
+                android:name="android.vendor.home_indicator"
+                android:value="hide" />
+            <meta-data
+                android:name="android.max_aspect"
+                android:value="1075419520.000000" />
+            <meta-data
+                android:name="com.samsung.android.keepalive.density"
+                android:value="true" />
         </activity>
 
         <!-- 閽堝7.0浠ヤ笂鐨刟pi寮�鏀剧殑鏂囦欢鏉冮檺 -->
@@ -224,6 +233,21 @@
         <meta-data
             android:name="JPUSH_APPKEY"
             android:value="803d5cb73efe51a59968bf52" />
+        <meta-data
+            android:name="android.max_aspect"
+            android:value="1075838976.000000" />
+        <meta-data
+            android:name="com.samsung.android.keepalive.density"
+            android:value="true" />
+        <meta-data
+            android:name="android.notch_support"
+            android:value="true" />
+        <meta-data
+            android:name="notch.config"
+            android:value="portrait|landscape" />
+        <meta-data
+            android:name="android.vendor.full_screen"
+            android:value="true" />
     </application>
 
 </manifest>
\ No newline at end of file
diff --git a/ChannelDiff/mrgame/libs/app-game_mrgame-release.aar b/ChannelDiff/mrgame/libs/app-game_mrgame-release.aar
index 0f5bde6..b170730 100644
--- a/ChannelDiff/mrgame/libs/app-game_mrgame-release.aar
+++ b/ChannelDiff/mrgame/libs/app-game_mrgame-release.aar
Binary files differ
diff --git a/Project/app/src/main/AndroidManifest.xml b/Project/app/src/main/AndroidManifest.xml
index c76f564..31bf914 100644
--- a/Project/app/src/main/AndroidManifest.xml
+++ b/Project/app/src/main/AndroidManifest.xml
@@ -34,6 +34,27 @@
         android:isGame="true"
         android:label="@string/app_name"
         android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen">
+
+        <meta-data
+            android:name="android.max_aspect"
+            android:value="1075838976.000000" />
+
+        <meta-data
+            android:name="com.samsung.android.keepalive.density"
+            android:value="true" />
+
+        <meta-data
+            android:name="android.notch_support"
+            android:value="true" />
+
+        <meta-data
+            android:name="notch.config"
+            android:value="portrait|landscape" />
+
+        <meta-data
+            android:name="android.vendor.full_screen"
+            android:value="true" />
+
         <activity
             android:name="com.secondworld.univeralsdk.MainActivity"
             android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection"
@@ -53,6 +74,19 @@
             <meta-data
                 android:name="unityplayer.SkipPermissionsDialog"
                 android:value="true" />
+
+            <meta-data
+                android:name="android.vendor.home_indicator"
+                android:value="hide" />
+
+            <meta-data
+                android:name="android.max_aspect"
+                android:value="1075419520.000000" />
+
+            <meta-data
+                android:name="com.samsung.android.keepalive.density"
+                android:value="true" />
+
         </activity>
 
         <!-- 閽堝7.0浠ヤ笂鐨刟pi寮�鏀剧殑鏂囦欢鏉冮檺 -->
diff --git a/Project/app/src/main/java/com/secondworld/univeralsdk/MainActivity.java b/Project/app/src/main/java/com/secondworld/univeralsdk/MainActivity.java
index 4a19082..1e0d5fc 100644
--- a/Project/app/src/main/java/com/secondworld/univeralsdk/MainActivity.java
+++ b/Project/app/src/main/java/com/secondworld/univeralsdk/MainActivity.java
@@ -13,6 +13,7 @@
 import android.support.v4.content.PermissionChecker;
 import android.view.View;
 import android.widget.FrameLayout;
+import android.widget.RelativeLayout;
 
 import com.unity3d.player.UnityPlayerActivity;
 
@@ -23,6 +24,10 @@
     // 鍚敤6.0浠ヤ笂鏉冮檺鍥炶皟code
     // private static final int CODE_REQUEST_PERMISSION = 1000;
 
+    private RelativeLayout m_MainContainer;
+    private int mType;
+    private boolean isNotch = false;
+
     @Override
     protected void onCreate(Bundle savedInstanceState)
     {
@@ -32,6 +37,32 @@
         LogUtil.init(this, true);
 
         setContentView(R.layout.activity_main);
+
+        m_MainContainer = (RelativeLayout) findViewById(R.id.main_container);
+
+        String _brand = NotchPhoneUtil.getDeviceBrand();
+        if (_brand.indexOf("vivo") > 0)
+        {
+            isNotch = NotchPhoneUtil.HasNotchVivo(MainActivity.this);
+            mType = 1;
+        }
+        else if (_brand.indexOf("HUAWEI") > 0)
+        {
+            isNotch = NotchPhoneUtil.HasNotchVivo(MainActivity.this);
+            mType = 2;
+        }
+        else if (_brand.indexOf("OPPO") > 0)
+        {
+            isNotch = NotchPhoneUtil.HasNotchVivo(MainActivity.this);
+            mType = 3;
+        }
+        else if (_brand.indexOf("Xiaomi") > 0)
+        {
+            isNotch = NotchPhoneUtil.HasNotchVivo(MainActivity.this);
+            mType = 4;
+        }
+
+        NotchPhoneUtil.onConfigurationChanged(this, isNotch, mType, m_MainContainer);
 
         FrameLayout _frameLayout = (FrameLayout) findViewById(R.id.unity_view);
         View unityView = mUnityPlayer.getView();
@@ -64,6 +95,8 @@
     @Override
     public void onConfigurationChanged(Configuration newConfig)
     {
+        NotchPhoneUtil.onConfigurationChanged(this, isNotch, mType, m_MainContainer);
+
         H2EngineSDK.onConfigurationChanged(newConfig);
 
         super.onConfigurationChanged(newConfig);
diff --git a/Project/app/src/main/java/com/secondworld/univeralsdk/NotchPhoneUtil.java b/Project/app/src/main/java/com/secondworld/univeralsdk/NotchPhoneUtil.java
new file mode 100644
index 0000000..51a355c
--- /dev/null
+++ b/Project/app/src/main/java/com/secondworld/univeralsdk/NotchPhoneUtil.java
@@ -0,0 +1,347 @@
+package com.secondworld.univeralsdk;
+
+import android.app.Activity;
+import android.content.Context;
+import android.view.Surface;
+import android.view.ViewGroup;
+import android.widget.FrameLayout;
+
+import java.lang.reflect.Method;
+
+/**
+ * Created by Administrator on 2018/9/11 0011.
+ */
+
+public class NotchPhoneUtil
+{
+    private final static String TAG = "Notch";
+    /**
+     * 鍗庝负鎵嬫満鍒ゆ柇鏄笉鏄垬娴锋墜鏈�
+     *
+     * @param context
+     * @return
+     */
+    public static boolean hasNotchAtHuawei(Context context)
+    {
+        boolean ret = false;
+        try
+        {
+            ClassLoader classLoader = context.getClassLoader();
+            Class HwNotchSizeUtil = classLoader.loadClass(
+                    "com.huawei.android.util.HwNotchSizeUtil");
+            Method get = HwNotchSizeUtil.getMethod("hasNotchInScreen");
+            ret = (boolean) get.invoke(HwNotchSizeUtil);
+        } catch (ClassNotFoundException e)
+        {
+            LogUtil.e(TAG, "hasNotchAtHuawei ClassNotFoundException");
+        } catch (NoSuchMethodException e)
+        {
+            LogUtil.e(TAG, "hasNotchAtHuawei NoSuchMethodException");
+        } catch (Exception e)
+        {
+            LogUtil.e(TAG, "hasNotchAtHuawei Exception");
+        } finally
+        {
+            return ret;
+        }
+    }
+
+
+    /**
+     * 鍗庝负鎵嬫満鑾峰彇鍒樻捣鐨勫楂�
+     * int[0]鍊间负鍒樻捣瀹藉害 int[1]鍊间负鍒樻捣楂樺害
+     */
+    public static int[] getNotchSizeAtHuawei(Context context)
+    {
+        int[] ret = new int[]{0, 0};
+        try
+        {
+            ClassLoader cl = context.getClassLoader();
+            Class HwNotchSizeUtil = cl.loadClass("com.huawei.android.util.HwNotchSizeUtil");
+            Method get = HwNotchSizeUtil.getMethod("getNotchSize");
+            ret = (int[]) get.invoke(HwNotchSizeUtil);
+        } catch (ClassNotFoundException e)
+        {
+            LogUtil.e(TAG, "getNotchSizeAtHuawei ClassNotFoundException");
+        } catch (NoSuchMethodException e)
+        {
+            LogUtil.e(TAG, "getNotchSizeAtHuawei NoSuchMethodException");
+        } catch (Exception e)
+        {
+            LogUtil.e(TAG, "getNotchSizeAtHuawei Exception");
+        } finally
+        {
+            return ret;
+        }
+    }
+
+
+    /**
+     * OPPO鍒ゆ柇鏄笉鏄垬娴锋墜鏈�,
+     * OPPO涓嶆彁渚涙帴鍙h幏鍙栧垬娴峰昂瀵革紝鐩墠鍏舵湁鍒樻捣灞忕殑鏈哄瀷灏哄瑙勬牸閮芥槸缁熶竴鐨勩�備笉鎺掗櫎浠ュ悗鏈哄瀷浼氭湁鍙樺寲銆�
+     * 鍒樻捣鍖哄煙鍒欓兘鏄搴︿负324px, 楂樺害涓�80px銆�
+     *
+     * @param context
+     * @return
+     */
+    public static boolean HasNotchOPPO(Context context)
+    {
+        return context.getPackageManager().hasSystemFeature(
+                "com.oppo.feature.screen.heteromorphism");
+    }
+
+
+    public static final int VIVO_NOTCH = 0x00000020;//鏄惁鏈夊垬娴�
+
+    /**
+     * vivo鍒ゆ柇鏄笉鏄垬娴锋墜鏈�
+     */
+    public static boolean HasNotchVivo(Context context)
+    {
+        boolean ret = false;
+        try
+        {
+            ClassLoader classLoader = 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)
+        {
+            LogUtil.e(TAG, "hasNotchAtVivo ClassNotFoundException");
+        } catch (NoSuchMethodException e)
+        {
+            LogUtil.e(TAG, "hasNotchAtVivo NoSuchMethodException");
+        } catch (Exception e)
+        {
+            LogUtil.e(TAG, "hasNotchAtVivo Exception");
+        } finally
+        {
+            return ret;
+        }
+
+    }
+
+    /**
+     * 灏忕背鎵嬫満鍒ゆ柇鏄笉鏄垬娴锋墜鏈�
+     *
+     * @return
+     */
+    public static boolean HasNotchXiaoMi()
+    {
+        Boolean _hasNotchXiaoMi = getPropertyInt("ro.miui.notch", 0) == 1 ? true : false;
+        LogUtil.i(TAG,"鏄惁鏄皬绫冲垬娴锋墜鏈�: " + _hasNotchXiaoMi);
+        return _hasNotchXiaoMi;
+    }
+
+    private static int getPropertyInt(String key,int defaultValue)
+    {
+        int value = defaultValue;
+        try
+        {
+            Class<?> c = Class.forName("android.os.SystemProperties");
+            Method get = c.getMethod("get", String.class, String.class);
+            value = (int) (get.invoke(c, key, "unknown"));
+        } catch (Exception e)
+        {
+            e.printStackTrace();
+        } finally
+        {
+            return value;
+        }
+    }
+
+    /**
+     * 灏忕背鎵嬫満鑾峰彇鍒樻捣鐨勯珮搴�
+     */
+    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;
+    }
+
+    /**
+     * 灞忓箷鏃嬭浆姹囨�荤殑鏂规硶
+     *
+     * @param activity
+     * @param isNotch
+     * @param type
+     * @param viewGroup
+     */
+    public static void onConfigurationChanged(Activity activity, Boolean isNotch, int type,
+                                              ViewGroup viewGroup)
+    {
+        if (getDisplayRotation(activity) == 0)
+        {
+            if (isNotch)
+            {
+                switch (type)
+                {
+                    case 1:   //vivo
+                        FrameLayout.LayoutParams lpvivo = (FrameLayout.LayoutParams) viewGroup.getLayoutParams();
+                        lpvivo.topMargin = dp2px(activity, 32);
+                        lpvivo.leftMargin = 0;
+                        lpvivo.rightMargin = 0;
+                        viewGroup.setLayoutParams(lpvivo);
+                        break;
+                    case 2: //HUAWEI
+
+                        int[] sizeAtHuawei = NotchPhoneUtil.getNotchSizeAtHuawei(activity);
+                        FrameLayout.LayoutParams lphuawei = (FrameLayout.LayoutParams) viewGroup.getLayoutParams();
+                        lphuawei.topMargin = sizeAtHuawei[1];
+                        lphuawei.leftMargin = 0;
+                        lphuawei.rightMargin = 0;
+                        viewGroup.setLayoutParams(lphuawei);
+
+                        break;
+                    case 3:  //OPPO  鐩墠閮戒负 80px
+                        FrameLayout.LayoutParams lpOppo = (FrameLayout.LayoutParams) viewGroup.getLayoutParams();
+                        lpOppo.topMargin = 80;
+                        lpOppo.leftMargin = 0;
+                        lpOppo.rightMargin = 0;
+                        viewGroup.setLayoutParams(lpOppo);
+
+
+                        break;
+                    case 4:  //Xiaomi
+                        int sizeAtXiaomi = NotchPhoneUtil.getStatusBarHeight(activity);
+                        FrameLayout.LayoutParams lpXiaomi = (FrameLayout.LayoutParams) viewGroup.getLayoutParams();
+                        lpXiaomi.topMargin = sizeAtXiaomi;
+                        lpXiaomi.leftMargin = 0;
+                        lpXiaomi.rightMargin = 0;
+                        viewGroup.setLayoutParams(lpXiaomi);
+
+                        break;
+                }
+
+            }
+
+        }
+        else if (getDisplayRotation(activity) == 90)
+        {
+            leftAndRightChange(activity, isNotch, type, viewGroup);
+        }
+        else if (getDisplayRotation(activity) == 180)
+        {
+        }
+        else if (getDisplayRotation(activity) == 270)
+        {
+            leftAndRightChange(activity, isNotch, type, viewGroup);
+        }
+
+
+    }
+
+    /**
+     * 宸﹀彸妯睆閮芥槸璁� leftMargin  鍜宺ightMargin 绌哄嚭涓�涓垬娴风殑璺濈
+     *
+     * @param activity
+     * @param isNotch
+     * @param type
+     * @param viewGroup
+     */
+    private static void leftAndRightChange(Activity activity, Boolean isNotch, int type,
+                                           ViewGroup viewGroup)
+    {
+        if (isNotch)
+        {
+            switch (type)
+            {
+                case 1:   //vivo
+                    FrameLayout.LayoutParams lpvivo = (FrameLayout.LayoutParams) viewGroup.getLayoutParams();
+                    lpvivo.leftMargin = dp2px(activity, 32);
+                    lpvivo.rightMargin = dp2px(activity, 32);
+                    lpvivo.topMargin = 0;
+                    lpvivo.bottomMargin = 0;
+                    viewGroup.setLayoutParams(lpvivo);
+                    break;
+                case 2: //HUAWEI
+
+                    int[] sizeAtHuawei = NotchPhoneUtil.getNotchSizeAtHuawei(activity);
+                    FrameLayout.LayoutParams lphuawei = (FrameLayout.LayoutParams) viewGroup.getLayoutParams();
+                    lphuawei.leftMargin = sizeAtHuawei[1];
+                    lphuawei.rightMargin = sizeAtHuawei[1];
+                    lphuawei.topMargin = 0;
+                    lphuawei.bottomMargin = 0;
+                    viewGroup.setLayoutParams(lphuawei);
+
+                    break;
+                case 3:  //OPPO  鐩墠閮戒负 80px
+                    FrameLayout.LayoutParams lpOppo = (FrameLayout.LayoutParams) viewGroup.getLayoutParams();
+                    lpOppo.leftMargin = 80;
+                    lpOppo.rightMargin = 80;
+                    lpOppo.topMargin = 0;
+                    lpOppo.bottomMargin = 0;
+                    viewGroup.setLayoutParams(lpOppo);
+
+                    break;
+                case 4:  //Xiaomi
+                    int sizeAtXiaomi = NotchPhoneUtil.getStatusBarHeight(activity);
+                    FrameLayout.LayoutParams lpXiaomi = (FrameLayout.LayoutParams) viewGroup.getLayoutParams();
+                    lpXiaomi.leftMargin = sizeAtXiaomi;
+                    lpXiaomi.rightMargin = sizeAtXiaomi;
+                    lpXiaomi.topMargin = 0;
+                    lpXiaomi.bottomMargin = 0;
+                    viewGroup.setLayoutParams(lpXiaomi);
+                    break;
+            }
+
+        }
+    }
+
+    /**
+     * 鑾峰彇褰撳墠灞忓箷鏃嬭浆瑙掑害
+     *
+     * @param activity
+     * @return 0琛ㄧず鏄珫灞�; 90琛ㄧず鏄乏妯睆; 180琛ㄧず鏄弽鍚戠珫灞�; 270琛ㄧず鏄彸妯睆
+     */
+    public static int getDisplayRotation(Activity activity)
+    {
+        if (activity == null)
+        {
+            return 0;
+        }
+
+        int rotation = activity.getWindowManager().getDefaultDisplay()
+                .getRotation();
+        switch (rotation)
+        {
+            case Surface.ROTATION_0:
+                return 0;
+            case Surface.ROTATION_90:
+                return 90;
+            case Surface.ROTATION_180:
+                return 180;
+            case Surface.ROTATION_270:
+                return 270;
+        }
+        return 0;
+    }
+
+    /**
+     * px杞琩p
+     *
+     * @param context
+     * @param dipValue
+     */
+    public static int dp2px(Context context, float dipValue)
+    {
+        final float scale = context.getResources().getDisplayMetrics().density;
+        return (int) (dipValue * scale + 0.5f);
+    }
+
+    /**
+     * 鑾峰彇鎵嬫満鍘傚晢
+     *
+     * @return 鎵嬫満鍘傚晢   Xiaomi   HUAWEI   vivo
+     */
+    public static String getDeviceBrand()
+    {
+        return android.os.Build.BRAND;
+    }
+}
diff --git a/Project/app/src/main/res/layout/activity_main.xml b/Project/app/src/main/res/layout/activity_main.xml
index 56fb5de..4bf1374 100644
--- a/Project/app/src/main/res/layout/activity_main.xml
+++ b/Project/app/src/main/res/layout/activity_main.xml
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/main_container"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
 

--
Gitblit v1.8.0