|
|
@@ -27,6 +27,7 @@ package com.cocos.game;
|
|
|
import android.content.Intent;
|
|
|
import android.content.res.Configuration;
|
|
|
import android.os.Bundle;
|
|
|
+import android.view.KeyEvent;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
import com.cocos.lib.CocosActivity;
|
|
|
@@ -103,6 +104,34 @@ public class AppActivity extends CocosActivity {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public boolean onKeyUp(int keyCode, KeyEvent event) {
|
|
|
+ return super.onKeyUp(keyCode, event);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
|
+ if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
|
|
+ long timeMillis = System.currentTimeMillis();
|
|
|
+ if (timeMillis - lastBackPressedTime < 2000) {
|
|
|
+ launchHomeScreen();
|
|
|
+ } else {
|
|
|
+ lastBackPressedTime = timeMillis;
|
|
|
+ Toast.makeText(this, "再按一次退出游戏", Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return super.onKeyDown(keyCode, event);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void launchHomeScreen() {
|
|
|
+ Intent intent = new Intent(Intent.ACTION_MAIN);
|
|
|
+ intent.addCategory(Intent.CATEGORY_HOME);
|
|
|
+ startActivity(intent);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
SDKWrapper.shared().onConfigurationChanged(newConfig);
|
|
|
super.onConfigurationChanged(newConfig);
|