四色键及进程退出处理
Showing
6 changed files
with
133 additions
and
6 deletions
| ... | @@ -29,6 +29,8 @@ | ... | @@ -29,6 +29,8 @@ |
| 29 | <uses-permission android:name="com.hiveview.cloudscreen.user.READPROVIDER" /> | 29 | <uses-permission android:name="com.hiveview.cloudscreen.user.READPROVIDER" /> |
| 30 | <uses-permission android:name="com.hiveview.cloudscreen.user.WRITE_USERINFO_DB" /> | 30 | <uses-permission android:name="com.hiveview.cloudscreen.user.WRITE_USERINFO_DB" /> |
| 31 | 31 | ||
| 32 | <uses-permission android:name="android.permission.GET_TASKS"/> | ||
| 33 | |||
| 32 | <application | 34 | <application |
| 33 | android:name="org.cocos2dx.javascript.common.MelodyApplication" | 35 | android:name="org.cocos2dx.javascript.common.MelodyApplication" |
| 34 | android:allowBackup="false" | 36 | android:allowBackup="false" | ... | ... |
| ... | @@ -103,6 +103,11 @@ android { | ... | @@ -103,6 +103,11 @@ android { |
| 103 | signingConfig signingConfigs.config | 103 | signingConfig signingConfigs.config |
| 104 | } | 104 | } |
| 105 | } | 105 | } |
| 106 | |||
| 107 | compileOptions { | ||
| 108 | sourceCompatibility = 1.8 | ||
| 109 | targetCompatibility = 1.8 | ||
| 110 | } | ||
| 106 | } | 111 | } |
| 107 | 112 | ||
| 108 | android.applicationVariants.all { variant -> | 113 | android.applicationVariants.all { variant -> | ... | ... |
build/jsb-link/frameworks/runtime-src/proj.android-studio/app/src/cn/topdraw/forfun/util/Timer.java
0 → 100644
| 1 | package cn.topdraw.forfun.util; | ||
| 2 | |||
| 3 | import android.os.Handler; | ||
| 4 | import android.os.Looper; | ||
| 5 | |||
| 6 | |||
| 7 | /** | ||
| 8 | * | ||
| 9 | */ | ||
| 10 | public class Timer { | ||
| 11 | private Handler mainHandler = new Handler(Looper.getMainLooper()); | ||
| 12 | private Runnable queuedTask = null; | ||
| 13 | private Long periodStartTime = 0L; | ||
| 14 | private Runnable periodDriver = null; | ||
| 15 | private boolean canceled = true; | ||
| 16 | private int periodCount = 0; | ||
| 17 | |||
| 18 | public void start(Long delayedMs, Long periodMs, Runnable task) { | ||
| 19 | if (delayedMs < 0 || periodMs < 0) { | ||
| 20 | return; | ||
| 21 | } | ||
| 22 | cancel(); | ||
| 23 | canceled = false; | ||
| 24 | queuedTask = task; | ||
| 25 | mainHandler.postDelayed(() -> { | ||
| 26 | if (queuedTask != null) { | ||
| 27 | queuedTask.run(); | ||
| 28 | } | ||
| 29 | |||
| 30 | if (periodMs != 0L) { | ||
| 31 | periodCount = 0; | ||
| 32 | periodDriver = () -> { | ||
| 33 | if (!canceled) { | ||
| 34 | periodCount++; | ||
| 35 | Long currentTime = System.currentTimeMillis(); | ||
| 36 | Long timeCompensation = | ||
| 37 | (currentTime - periodStartTime) - periodMs * periodCount; | ||
| 38 | if (queuedTask != null) { | ||
| 39 | queuedTask.run(); | ||
| 40 | } | ||
| 41 | Long compensatedPeriod = periodMs - timeCompensation; | ||
| 42 | mainHandler.postDelayed( | ||
| 43 | periodDriver, | ||
| 44 | compensatedPeriod < 0 ? 0 : compensatedPeriod); | ||
| 45 | } | ||
| 46 | }; | ||
| 47 | if (!canceled) { | ||
| 48 | periodStartTime = System.currentTimeMillis(); | ||
| 49 | mainHandler.postDelayed(periodDriver, periodMs); | ||
| 50 | } | ||
| 51 | } | ||
| 52 | }, delayedMs); | ||
| 53 | } | ||
| 54 | |||
| 55 | public void cancel() { | ||
| 56 | mainHandler.removeCallbacksAndMessages(null); | ||
| 57 | queuedTask = null; | ||
| 58 | canceled = true; | ||
| 59 | } | ||
| 60 | } |
| ... | @@ -31,10 +31,9 @@ import org.cocos2dx.javascript.component.NewTVSDK; | ... | @@ -31,10 +31,9 @@ import org.cocos2dx.javascript.component.NewTVSDK; |
| 31 | import org.cocos2dx.lib.Cocos2dxActivity; | 31 | import org.cocos2dx.lib.Cocos2dxActivity; |
| 32 | import org.cocos2dx.lib.Cocos2dxGLSurfaceView; | 32 | import org.cocos2dx.lib.Cocos2dxGLSurfaceView; |
| 33 | 33 | ||
| 34 | import android.app.AlertDialog; | 34 | import android.app.ActivityManager; |
| 35 | import android.content.BroadcastReceiver; | 35 | import android.content.BroadcastReceiver; |
| 36 | import android.content.Context; | 36 | import android.content.Context; |
| 37 | import android.content.DialogInterface; | ||
| 38 | import android.content.IntentFilter; | 37 | import android.content.IntentFilter; |
| 39 | import android.content.pm.ApplicationInfo; | 38 | import android.content.pm.ApplicationInfo; |
| 40 | import android.content.pm.PackageManager; | 39 | import android.content.pm.PackageManager; |
| ... | @@ -43,8 +42,8 @@ import android.os.Bundle; | ... | @@ -43,8 +42,8 @@ import android.os.Bundle; |
| 43 | import android.content.Intent; | 42 | import android.content.Intent; |
| 44 | import android.content.res.Configuration; | 43 | import android.content.res.Configuration; |
| 45 | import android.os.Handler; | 44 | import android.os.Handler; |
| 46 | import android.provider.Settings; | ||
| 47 | import android.util.Log; | 45 | import android.util.Log; |
| 46 | import android.view.KeyEvent; | ||
| 48 | import android.view.LayoutInflater; | 47 | import android.view.LayoutInflater; |
| 49 | import android.view.View; | 48 | import android.view.View; |
| 50 | import android.view.WindowManager; | 49 | import android.view.WindowManager; |
| ... | @@ -52,7 +51,6 @@ import android.webkit.CookieManager; | ... | @@ -52,7 +51,6 @@ import android.webkit.CookieManager; |
| 52 | import android.webkit.JavascriptInterface; | 51 | import android.webkit.JavascriptInterface; |
| 53 | import android.widget.ImageView; | 52 | import android.widget.ImageView; |
| 54 | import android.widget.RelativeLayout; | 53 | import android.widget.RelativeLayout; |
| 55 | import android.widget.TextView; | ||
| 56 | 54 | ||
| 57 | import com.knowyou_jni.single.SDKUtil; | 55 | import com.knowyou_jni.single.SDKUtil; |
| 58 | import com.topdraw.forfun_FJYD.R; | 56 | import com.topdraw.forfun_FJYD.R; |
| ... | @@ -69,6 +67,9 @@ import org.cocos2dx.javascript.common.MelodyApplication; | ... | @@ -69,6 +67,9 @@ import org.cocos2dx.javascript.common.MelodyApplication; |
| 69 | import org.cocos2dx.javascript.common.TopdrawSDKWrapper; | 67 | import org.cocos2dx.javascript.common.TopdrawSDKWrapper; |
| 70 | import org.cocos2dx.lib.Cocos2dxJavascriptJavaBridge; | 68 | import org.cocos2dx.lib.Cocos2dxJavascriptJavaBridge; |
| 71 | 69 | ||
| 70 | import cn.topdraw.forfun.constant.ControlKey; | ||
| 71 | import cn.topdraw.forfun.util.Timer; | ||
| 72 | |||
| 72 | public class AppActivity extends Cocos2dxActivity { | 73 | public class AppActivity extends Cocos2dxActivity { |
| 73 | private static String TAG = "AppActivity"; | 74 | private static String TAG = "AppActivity"; |
| 74 | private static ImageView img = null; | 75 | private static ImageView img = null; |
| ... | @@ -100,10 +101,15 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -100,10 +101,15 @@ public class AppActivity extends Cocos2dxActivity { |
| 100 | 101 | ||
| 101 | private final Handler mHandler = new Handler(); | 102 | private final Handler mHandler = new Handler(); |
| 102 | 103 | ||
| 104 | private boolean mExitAppOnStop = true; | ||
| 105 | private Timer mAppCheckTimer = new Timer(); | ||
| 106 | private ActivityManager mActivityManager; | ||
| 107 | |||
| 103 | @Override | 108 | @Override |
| 104 | protected void onCreate(Bundle savedInstanceState) { | 109 | protected void onCreate(Bundle savedInstanceState) { |
| 105 | super.onCreate(savedInstanceState); | 110 | super.onCreate(savedInstanceState); |
| 106 | CommonUtils.checkNetwork(this); //检查网络 | 111 | CommonUtils.checkNetwork(this); //检查网络 |
| 112 | mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); | ||
| 107 | 113 | ||
| 108 | initSdkData(); | 114 | initSdkData(); |
| 109 | 115 | ||
| ... | @@ -285,6 +291,21 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -285,6 +291,21 @@ public class AppActivity extends Cocos2dxActivity { |
| 285 | }); | 291 | }); |
| 286 | } | 292 | } |
| 287 | 293 | ||
| 294 | @Override | ||
| 295 | public boolean dispatchKeyEvent(KeyEvent event) { | ||
| 296 | int keyCode = event.getKeyCode(); | ||
| 297 | if (event.getAction() == KeyEvent.ACTION_DOWN) { | ||
| 298 | if (keyCode == ControlKey.KEYCODE_CMCC_RED | ||
| 299 | || keyCode == ControlKey.KEYCODE_CMCC_GREEN | ||
| 300 | || keyCode == ControlKey.KEYCODE_CMCC_YELLOW | ||
| 301 | || keyCode == ControlKey.KEYCODE_CMCC_BLUE) { | ||
| 302 | finish(); | ||
| 303 | return true; | ||
| 304 | } | ||
| 305 | } | ||
| 306 | return super.dispatchKeyEvent(event); | ||
| 307 | } | ||
| 308 | |||
| 288 | public View getProgressBarView() { | 309 | public View getProgressBarView() { |
| 289 | return view; | 310 | return view; |
| 290 | } | 311 | } |
| ... | @@ -407,12 +428,27 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -407,12 +428,27 @@ public class AppActivity extends Cocos2dxActivity { |
| 407 | SDKWrapper.getInstance().onPause(); | 428 | SDKWrapper.getInstance().onPause(); |
| 408 | } | 429 | } |
| 409 | 430 | ||
| 431 | private static final String INSTALLER_HOME_ACTIVITY_NAME = "com.android.packageinstaller.PackageInstallerActivity"; | ||
| 432 | private static final String INSTALLER_PROGRESS_ACTIVITY_NAME = "com.android.packageinstaller.InstallAppProgress"; | ||
| 433 | |||
| 410 | @Override | 434 | @Override |
| 411 | protected void onStop() { | 435 | protected void onStop() { |
| 412 | Log.d("AppActivity", "onStop()...."); | 436 | Log.d("AppActivity", "onStop()...."); |
| 413 | super.onStop(); | 437 | super.onStop(); |
| 414 | SDKWrapper.getInstance().onStop(); | 438 | SDKWrapper.getInstance().onStop(); |
| 415 | onDestroy(); | 439 | if (mExitAppOnStop) { |
| 440 | System.exit(0); | ||
| 441 | } else { | ||
| 442 | mAppCheckTimer.start(1000L, 1000L, () -> { | ||
| 443 | String activity_name = mActivityManager.getRunningTasks(1).get(0).topActivity.getClassName(); | ||
| 444 | if (!activity_name.equals(mOrbbecActivity) | ||
| 445 | && !activity_name.equals(INSTALLER_HOME_ACTIVITY_NAME) | ||
| 446 | && !activity_name.equals(INSTALLER_PROGRESS_ACTIVITY_NAME)) { | ||
| 447 | Log.d("AppActivity", "top activity: " + activity_name); | ||
| 448 | System.exit(0); | ||
| 449 | } | ||
| 450 | }); | ||
| 451 | } | ||
| 416 | } | 452 | } |
| 417 | 453 | ||
| 418 | @Override | 454 | @Override |
| ... | @@ -429,6 +465,8 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -429,6 +465,8 @@ public class AppActivity extends Cocos2dxActivity { |
| 429 | protected void onResume() { | 465 | protected void onResume() { |
| 430 | // Log.d("AppActivity", "onResume()...."); | 466 | // Log.d("AppActivity", "onResume()...."); |
| 431 | super.onResume(); | 467 | super.onResume(); |
| 468 | mExitAppOnStop = true; | ||
| 469 | mAppCheckTimer.cancel(); | ||
| 432 | SDKWrapper.getInstance().onResume(); | 470 | SDKWrapper.getInstance().onResume(); |
| 433 | mRLSingleColor.setVisibility(View.GONE); | 471 | mRLSingleColor.setVisibility(View.GONE); |
| 434 | mOBiLayout.setVisibility(View.GONE); | 472 | mOBiLayout.setVisibility(View.GONE); |
| ... | @@ -461,6 +499,16 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -461,6 +499,16 @@ public class AppActivity extends Cocos2dxActivity { |
| 461 | } | 499 | } |
| 462 | } | 500 | } |
| 463 | 501 | ||
| 502 | public void setExitAppOnStop(boolean finish) { | ||
| 503 | mExitAppOnStop = finish; | ||
| 504 | } | ||
| 505 | |||
| 506 | private String mOrbbecActivity = ""; | ||
| 507 | |||
| 508 | public void setOrbbecActivity(String activityName) { | ||
| 509 | mOrbbecActivity = activityName; | ||
| 510 | } | ||
| 511 | |||
| 464 | /** | 512 | /** |
| 465 | * 福建移动埋点SDK、启动游戏 | 513 | * 福建移动埋点SDK、启动游戏 |
| 466 | * | 514 | * | ... | ... |
| ... | @@ -9,7 +9,6 @@ import android.net.Uri; | ... | @@ -9,7 +9,6 @@ import android.net.Uri; |
| 9 | import android.text.TextUtils; | 9 | import android.text.TextUtils; |
| 10 | import android.util.Log; | 10 | import android.util.Log; |
| 11 | import android.view.View; | 11 | import android.view.View; |
| 12 | import android.widget.ProgressBar; | ||
| 13 | import android.widget.RelativeLayout; | 12 | import android.widget.RelativeLayout; |
| 14 | import android.widget.Toast; | 13 | import android.widget.Toast; |
| 15 | 14 | ||
| ... | @@ -252,6 +251,8 @@ public class TopdrawSDKWrapper { | ... | @@ -252,6 +251,8 @@ public class TopdrawSDKWrapper { |
| 252 | final View obiView = _activity.getObiView(); | 251 | final View obiView = _activity.getObiView(); |
| 253 | final String packageName = apkName; | 252 | final String packageName = apkName; |
| 254 | final String className = "com.orbbec.u3d.baminsdk.FujianActivity";//福建移动奥比启动类名已修改为固定值 | 253 | final String className = "com.orbbec.u3d.baminsdk.FujianActivity";//福建移动奥比启动类名已修改为固定值 |
| 254 | _activity.setExitAppOnStop(false); | ||
| 255 | _activity.setOrbbecActivity(className); | ||
| 255 | OBiPluginLoader.getInstance().start(downloadUrl, packageName, new OBiPluginLoader.OnResultListener() { | 256 | OBiPluginLoader.getInstance().start(downloadUrl, packageName, new OBiPluginLoader.OnResultListener() { |
| 256 | @Override | 257 | @Override |
| 257 | public void onResult(int i, final String msg) { | 258 | public void onResult(int i, final String msg) { | ... | ... |
-
Please register or sign in to post a comment