|  |  |  | 
|---|
|  |  |  | import android.content.res.Configuration; | 
|---|
|  |  |  | import android.net.Uri; | 
|---|
|  |  |  | import android.os.Bundle; | 
|---|
|  |  |  | import android.os.Handler; | 
|---|
|  |  |  | import android.os.Message; | 
|---|
|  |  |  | import android.os.Process; | 
|---|
|  |  |  | import android.provider.Settings; | 
|---|
|  |  |  | import android.support.v4.content.PermissionChecker; | 
|---|
|  |  |  | import android.util.Log; | 
|---|
|  |  |  | import android.view.KeyEvent; | 
|---|
|  |  |  | import android.view.View; | 
|---|
|  |  |  | import android.widget.Button; | 
|---|
|  |  |  | import android.widget.FrameLayout; | 
|---|
|  |  |  | import android.widget.GridLayout; | 
|---|
|  |  |  | import android.widget.RelativeLayout; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.snowfish.cn.ganga.helper.SFOnlineExitListener; | 
|---|
|  |  |  | import com.snowfish.cn.ganga.helper.SFOnlineHelper; | 
|---|
|  |  |  | import com.unity3d.player.UnityPlayerActivity; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public class MainActivity extends UnityPlayerActivity | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | // 启用6.0以上权限回调code | 
|---|
|  |  |  | // private static final int CODE_REQUEST_PERMISSION = 1000; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static final int SHOW_TENCENT_LOGIN = 0; | 
|---|
|  |  |  | public static final int HIDE_TENCENT_LOGIN = 1; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private RelativeLayout m_MainContainer; | 
|---|
|  |  |  | private int mType; | 
|---|
|  |  |  | private boolean isNotch = false; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected void onCreate(Bundle savedInstanceState) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //        sInstance = this; | 
|---|
|  |  |  | super.onCreate(savedInstanceState); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LogUtil.i(TAG, "onCreate"); | 
|---|
|  |  |  | // LogUtil.i(TAG, "onCreate"); | 
|---|
|  |  |  | LogUtil.init(this, true); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | setContentView(R.layout.activity_main); | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onWindowFocusChanged(boolean b) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //LogUtil.i(TAG, "onWindowFocusChanged: " + b); | 
|---|
|  |  |  | super.onWindowFocusChanged(b); | 
|---|
|  |  |  | H2EngineSDK.onWindowFocusChanged(b); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected void onNewIntent(Intent intent) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //LogUtil.i(TAG, "onNewIntent"); | 
|---|
|  |  |  | super.onNewIntent(intent); | 
|---|
|  |  |  | H2EngineSDK.onNewIntent(this, intent); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected void onActivityResult(int requestCode, int resultCode, Intent data) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //LogUtil.i(TAG, "onActivityResult"); | 
|---|
|  |  |  | H2EngineSDK.onActivityResult(requestCode, resultCode, data, this); | 
|---|
|  |  |  | super.onActivityResult(requestCode, resultCode, data); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onConfigurationChanged(Configuration newConfig) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //LogUtil.i(TAG, "onConfigurationChanged"); | 
|---|
|  |  |  | NotchPhoneUtil.onConfigurationChanged(this, isNotch, mType, m_MainContainer); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | H2EngineSDK.onConfigurationChanged(newConfig); | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected void onStart() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | LogUtil.i(TAG, "onStart"); | 
|---|
|  |  |  | H2EngineSDK.onStart(this); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | super.onStart(); | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected void onStop() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //LogUtil.i(TAG, "onStop"); | 
|---|
|  |  |  | isForeground = false; | 
|---|
|  |  |  | H2EngineSDK.onStop(this); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected void onResume() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //LogUtil.i(TAG, "onResume"); | 
|---|
|  |  |  | isForeground = true; | 
|---|
|  |  |  | H2EngineSDK.onResume(this); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected void onPause() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //LogUtil.i(TAG, "onPause"); | 
|---|
|  |  |  | H2EngineSDK.onPause(this); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | super.onPause(); | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected void onDestroy() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //LogUtil.i(TAG, "onDestroy"); | 
|---|
|  |  |  | H2EngineSDK.onDestroy(this); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | super.onDestroy(); | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected void onRestart() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //LogUtil.i(TAG, "onRestart"); | 
|---|
|  |  |  | H2EngineSDK.onRestart(this); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | super.onRestart(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public boolean onKeyDown(int i, KeyEvent keyEvent) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (i == KeyEvent.KEYCODE_BACK) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | SFOnlineHelper.exit(this, new SFOnlineExitListener() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | /*  onSDKExit | 
|---|
|  |  |  | *  @description 当SDK有退出方法及界面,回调该函数 | 
|---|
|  |  |  | *  @param bool   是否退出标志位 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onSDKExit(boolean bool) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (bool) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //apk退出函数,demo中也有使用System.exit()方法;但请注意360SDK的退出使用exit()会导致游戏退出异常 | 
|---|
|  |  |  | finish(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /*  onNoExiterProvide | 
|---|
|  |  |  | *  @description SDK没有退出方法及界面,回调该函数,可在此使用游戏退出界面 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onNoExiterProvide() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | LogUtil.i(TAG, "SDK不支持, 主动调用游戏中..."); | 
|---|
|  |  |  | HashMap<String, Object> m_Message = new HashMap<>(); | 
|---|
|  |  |  | m_Message.put("code", CodeA2U.ExitGame); | 
|---|
|  |  |  | UniversalUtil.sendMessageToUnity(m_Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return super.onKeyDown(i, keyEvent); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|