1 /* 2 * Copyright (C) 2018 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.android.systemui.statusbar.phone; 18 19 import android.content.Context; 20 import android.os.SystemClock; 21 import android.util.Slog; 22 import android.view.WindowManager; 23 import android.widget.Toast; 24 25 import com.android.systemui.R; 26 import com.android.systemui.SysUIToast; 27 28 /** 29 * Helper to manage showing/hiding a image to notify them that they are entering or exiting screen 30 * pinning mode. All exposed methods should be called from a handler thread. 31 */ 32 public class ScreenPinningNotify { 33 private static final String TAG = "ScreenPinningNotify"; 34 private static final long SHOW_TOAST_MINIMUM_INTERVAL = 1000; 35 36 private final Context mContext; 37 private Toast mLastToast; 38 private long mLastShowToastTime; 39 ScreenPinningNotify(Context context)40 public ScreenPinningNotify(Context context) { 41 mContext = context; 42 } 43 44 /** Show "Screen pinned" toast. */ showPinningStartToast()45 public void showPinningStartToast() { 46 makeAllUserToastAndShow(R.string.screen_pinning_start); 47 } 48 49 /** Show "Screen unpinned" toast. */ showPinningExitToast()50 public void showPinningExitToast() { 51 makeAllUserToastAndShow(R.string.screen_pinning_exit); 52 } 53 54 /** Show a toast that describes the gesture the user should use to escape pinned mode. */ showEscapeToast(boolean isRecentsButtonVisible)55 public void showEscapeToast(boolean isRecentsButtonVisible) { 56 long showToastTime = SystemClock.elapsedRealtime(); 57 if ((showToastTime - mLastShowToastTime) < SHOW_TOAST_MINIMUM_INTERVAL) { 58 Slog.i(TAG, "Ignore toast since it is requested in very short interval."); 59 return; 60 } 61 if (mLastToast != null) { 62 mLastToast.cancel(); 63 } 64 mLastToast = makeAllUserToastAndShow(isRecentsButtonVisible 65 ? R.string.screen_pinning_toast 66 : R.string.screen_pinning_toast_recents_invisible); 67 mLastShowToastTime = showToastTime; 68 } 69 makeAllUserToastAndShow(int resId)70 private Toast makeAllUserToastAndShow(int resId) { 71 Toast toast = SysUIToast.makeText(mContext, resId, Toast.LENGTH_LONG); 72 toast.show(); 73 return toast; 74 } 75 } 76