LockTaskNotify.java revision 7779bf1ce8243d9f856c05db3cc5a37a8227a970
1/* 2 * Copyright (C) 2013 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.android.server.am; 18 19import android.content.Context; 20import android.os.Handler; 21import android.os.Message; 22import android.widget.Toast; 23 24import com.android.internal.R; 25 26/** 27 * Helper to manage showing/hiding a image to notify them that they are entering 28 * or exiting lock-to-app mode. 29 */ 30public class LockTaskNotify { 31 private static final String TAG = "LockTaskNotify"; 32 33 private final Context mContext; 34 private final H mHandler; 35 36 public LockTaskNotify(Context context) { 37 mContext = context; 38 mHandler = new H(); 39 } 40 41 public void showToast(boolean isLocked) { 42 mHandler.obtainMessage(H.SHOW_TOAST, isLocked ? 1 : 0, 0 /* Not used */).sendToTarget(); 43 } 44 45 public void handleShowToast(boolean isLocked) { 46 String text = mContext.getString(isLocked 47 ? R.string.lock_to_app_toast_locked : R.string.lock_to_app_toast); 48 Toast.makeText(mContext, text, Toast.LENGTH_LONG).show(); 49 } 50 51 public void show(boolean starting) { 52 int showString = R.string.lock_to_app_exit; 53 if (starting) { 54 showString = R.string.lock_to_app_start; 55 } 56 Toast.makeText(mContext, mContext.getString(showString), Toast.LENGTH_LONG).show(); 57 } 58 59 private final class H extends Handler { 60 private static final int SHOW_TOAST = 3; 61 62 @Override 63 public void handleMessage(Message msg) { 64 switch(msg.what) { 65 case SHOW_TOAST: 66 handleShowToast(msg.arg1 != 0); 67 break; 68 } 69 } 70 } 71} 72