blob: ab60d4851ab612f5e4d4b0d544b3b3de9382cd21 [file] [log] [blame]
Craig Mautner2ad0bb42015-04-08 15:43:26 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package com.google.android.example.locktasktests;
18
19import android.app.Activity;
20import android.app.ActivityManager;
21import android.content.Context;
22import android.content.Intent;
23import android.os.Bundle;
Craig Mautnerc21ae9e2015-04-15 09:45:42 -070024import android.os.Handler;
25import android.os.Looper;
Craig Mautner2ad0bb42015-04-08 15:43:26 -070026import android.view.View;
27import android.widget.EditText;
28
29public class LaunchActivity extends Activity {
30
Craig Mautnerc21ae9e2015-04-15 09:45:42 -070031 Runnable mBackgroundPolling;
32 boolean mRunning;
33 Handler mHandler;
Craig Mautner2ad0bb42015-04-08 15:43:26 -070034
35 @Override
36 protected void onCreate(Bundle savedInstanceState) {
37 super.onCreate(savedInstanceState);
38 setContentView(R.layout.activity_launch);
Craig Mautnerc21ae9e2015-04-15 09:45:42 -070039 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());
Craig Mautner2ad0bb42015-04-08 15:43:26 -070054 }
55
56 @Override
57 public void onResume() {
58 super.onResume();
Craig Mautnerc21ae9e2015-04-15 09:45:42 -070059 mRunning = true;
60 mBackgroundPolling.run();
61 }
62
63 @Override
64 public void onPause() {
65 super.onPause();
66 mRunning = false;
Craig Mautner2ad0bb42015-04-08 15:43:26 -070067 }
68
69 public void onTryLock(View view) {
70 startLockTask();
Craig Mautner2ad0bb42015-04-08 15:43:26 -070071 }
72
73 public void onTryUnlock(View view) {
74 stopLockTask();
Craig Mautner2ad0bb42015-04-08 15:43:26 -070075 }
76
77 public void onLaunchMain(View view) {
78 Intent intent = new Intent(this, MainActivity.class);
79 startActivity(intent);
80 }
Craig Mautner2ad0bb42015-04-08 15:43:26 -070081}