| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.google.android.example.locktasktests; |
| 18 |
|
| 19 |
import android.app.Activity; |
| 20 |
import android.app.ActivityManager; |
| 21 |
import android.content.Context; |
| 22 |
import android.content.Intent; |
| 23 |
import android.os.Bundle; |
| 24 |
import android.os.Handler; |
| 25 |
import android.os.Looper; |
| 26 |
import android.view.View; |
| 27 |
import android.widget.EditText; |
| 28 |
|
| 29 |
public class LaunchActivity extends Activity { |
| 30 |
|
| 31 |
Runnable mBackgroundPolling; |
| 32 |
boolean mRunning; |
| 33 |
Handler mHandler; |
| 34 |
|
| 35 |
@Override |
| 36 |
protected void onCreate(Bundle savedInstanceState) { |
| 37 |
super.onCreate(savedInstanceState); |
| 38 |
setContentView(R.layout.activity_launch); |
| 39 |
mBackgroundPolling = new Runnable() { |
| 40 |
@Override |
| 41 |
public void run() { |
| 42 |
if (!mRunning) { |
| 43 |
return; |
| 44 |
} |
| 45 |
ActivityManager activityManager = |
| 46 |
(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); |
| 47 |
final int color = activityManager.getLockTaskModeState() != |
| 48 |
ActivityManager.LOCK_TASK_MODE_NONE ? 0xFFFFC0C0 : 0xFFFFFFFF; |
| 49 |
findViewById(R.id.root_launch).setBackgroundColor(color); |
| 50 |
mHandler.postDelayed(this, 1000); |
| 51 |
} |
| 52 |
}; |
| 53 |
mHandler = new Handler(Looper.getMainLooper()); |
| 54 |
} |
| 55 |
|
| 56 |
@Override |
| 57 |
public void onResume() { |
| 58 |
super.onResume(); |
| 59 |
mRunning = true; |
| 60 |
mBackgroundPolling.run(); |
| 61 |
} |
| 62 |
|
| 63 |
@Override |
| 64 |
public void onPause() { |
| 65 |
super.onPause(); |
| 66 |
mRunning = false; |
| 67 |
} |
| 68 |
|
| 69 |
public void onTryLock(View view) { |
| 70 |
startLockTask(); |
| 71 |
} |
| 72 |
|
| 73 |
public void onTryUnlock(View view) { |
| 74 |
stopLockTask(); |
| 75 |
} |
| 76 |
|
| 77 |
public void onLaunchMain(View view) { |
| 78 |
Intent intent = new Intent(this, MainActivity.class); |
| 79 |
startActivity(intent); |
| 80 |
} |
| 81 |
} |