Home | History | Annotate | Download | only in locktasktests
      1 /*
      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 
     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 }
     82