|  |  |  | 
|---|
|  |  |  | import android.support.v4.content.PermissionChecker; | 
|---|
|  |  |  | import android.view.View; | 
|---|
|  |  |  | import android.widget.FrameLayout; | 
|---|
|  |  |  | import android.widget.RelativeLayout; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.unity3d.player.UnityPlayerActivity; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public class MainActivity extends UnityPlayerActivity | 
|---|
|  |  |  | { | 
|---|
|  |  |  | private static final String TAG = "MainActivity"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static boolean isForeground = false; | 
|---|
|  |  |  | // 启用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) | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  | _frameLayout.addView(unityView); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | H2EngineSDK.onCreate(savedInstanceState); | 
|---|
|  |  |  | H2EngineSDK.onCreate(this, savedInstanceState); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onWindowFocusChanged(boolean b) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | super.onWindowFocusChanged(b); | 
|---|
|  |  |  | H2EngineSDK.onWindowFocusChanged(b); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected void onNewIntent(Intent intent) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | H2EngineSDK.onNewIntent(intent); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | super.onNewIntent(intent); | 
|---|
|  |  |  | LogUtil.i(TAG, "onNewIntent"); | 
|---|
|  |  |  | H2EngineSDK.onNewIntent(this, intent); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected void onActivityResult(int requestCode, int resultCode, Intent data) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | H2EngineSDK.onActivityResult(requestCode, resultCode, data, this); | 
|---|
|  |  |  | super.onActivityResult(requestCode, resultCode, data); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onConfigurationChanged(Configuration newConfig) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | NotchPhoneUtil.onConfigurationChanged(this, isNotch, mType, m_MainContainer); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | H2EngineSDK.onConfigurationChanged(newConfig); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | super.onConfigurationChanged(newConfig); | 
|---|
|  |  |  | LogUtil.i(TAG, "onConfigurationChanged"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected void onStart() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | H2EngineSDK.onStart(); | 
|---|
|  |  |  | H2EngineSDK.onStart(this); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | super.onStart(); | 
|---|
|  |  |  | LogUtil.i(TAG, "onStart"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected void onStop() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | H2EngineSDK.onStop(); | 
|---|
|  |  |  | isForeground = false; | 
|---|
|  |  |  | H2EngineSDK.onStop(this); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | super.onStop(); | 
|---|
|  |  |  | LogUtil.i(TAG, "onStop"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected void onResume() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | H2EngineSDK.onResume(); | 
|---|
|  |  |  | isForeground = true; | 
|---|
|  |  |  | H2EngineSDK.onResume(this); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | super.onResume(); | 
|---|
|  |  |  | LogUtil.i(TAG, "onResume"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 检测本地存储权限是否有, 没有的话要提示用户 | 
|---|
|  |  |  | if (PermissionChecker.checkPermission(this, | 
|---|
|  |  |  | Manifest.permission.WRITE_EXTERNAL_STORAGE, | 
|---|
|  |  |  | Process.myPid(), Process.myUid(), | 
|---|
|  |  |  | getPackageName()) != PackageManager.PERMISSION_GRANTED | 
|---|
|  |  |  | || PermissionChecker.checkPermission(this, | 
|---|
|  |  |  | Manifest.permission.READ_EXTERNAL_STORAGE, | 
|---|
|  |  |  | Process.myPid(), Process.myUid(), | 
|---|
|  |  |  | getPackageName()) != PackageManager.PERMISSION_GRANTED) | 
|---|
|  |  |  | || PermissionChecker.checkPermission(this, | 
|---|
|  |  |  | Manifest.permission.READ_EXTERNAL_STORAGE, | 
|---|
|  |  |  | Process.myPid(), Process.myUid(), | 
|---|
|  |  |  | getPackageName()) != PackageManager.PERMISSION_GRANTED) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | new AlertDialog.Builder(this) | 
|---|
|  |  |  | .setMessage("应用没有存储读取权限,点击确定至设置中开启,否则无法继续游戏.") | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected void onPause() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | H2EngineSDK.onPause(); | 
|---|
|  |  |  | H2EngineSDK.onPause(this); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | super.onPause(); | 
|---|
|  |  |  | LogUtil.i(TAG, "onPause"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected void onDestroy() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | H2EngineSDK.onDestroy(); | 
|---|
|  |  |  | H2EngineSDK.onDestroy(this); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | super.onDestroy(); | 
|---|
|  |  |  | LogUtil.i(TAG, "onDestroy"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected void onRestart() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | H2EngineSDK.onRestart(); | 
|---|
|  |  |  | H2EngineSDK.onRestart(this); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | super.onRestart(); | 
|---|
|  |  |  | LogUtil.i(TAG, "onRestart"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|