blob: 071e00d08d6727b429e1d6c8f1203476b5e8e4c0 [file] [log] [blame]
Jason Monk62515be2014-05-21 16:06:19 -04001/*
Matthew Ng9c3bce52018-02-01 22:00:31 +00002 * Copyright (C) 2018 The Android Open Source Project
Jason Monk62515be2014-05-21 16:06:19 -04003 *
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
Matthew Ng9c3bce52018-02-01 22:00:31 +000017package com.android.systemui.statusbar.phone;
Jason Monk62515be2014-05-21 16:06:19 -040018
Jason Monk62515be2014-05-21 16:06:19 -040019import android.content.Context;
Koji Fukuid8c16032016-10-06 23:00:00 +090020import android.os.SystemClock;
21import android.util.Slog;
Jason Monka8f569c2014-07-07 12:15:21 -040022import android.widget.Toast;
Jason Monk62515be2014-05-21 16:06:19 -040023
Matthew Ng9c3bce52018-02-01 22:00:31 +000024import com.android.systemui.R;
25import com.android.systemui.SysUIToast;
Jason Monk62515be2014-05-21 16:06:19 -040026
27/**
Charles He49736802017-10-23 11:06:23 +010028 * Helper to manage showing/hiding a image to notify them that they are entering or exiting screen
29 * pinning mode. All exposed methods should be called from a handler thread.
Jason Monk62515be2014-05-21 16:06:19 -040030 */
Matthew Ng9c3bce52018-02-01 22:00:31 +000031public class ScreenPinningNotify {
32 private static final String TAG = "ScreenPinningNotify";
Koji Fukuid8c16032016-10-06 23:00:00 +090033 private static final long SHOW_TOAST_MINIMUM_INTERVAL = 1000;
Jason Monk62515be2014-05-21 16:06:19 -040034
Jason Monk62515be2014-05-21 16:06:19 -040035 private final Context mContext;
Jason Monk07f82b72014-08-19 15:20:01 -040036 private Toast mLastToast;
Koji Fukuid8c16032016-10-06 23:00:00 +090037 private long mLastShowToastTime;
Jason Monk62515be2014-05-21 16:06:19 -040038
Matthew Ng9c3bce52018-02-01 22:00:31 +000039 public ScreenPinningNotify(Context context) {
Jason Monk62515be2014-05-21 16:06:19 -040040 mContext = context;
Jason Monk62515be2014-05-21 16:06:19 -040041 }
42
Charles Hebfe82d12017-10-20 11:59:44 +010043 /** Show "Screen pinned" toast. */
Daichi Hirono926c56f2018-04-13 15:40:37 +090044 public void showPinningStartToast() {
Matthew Ng9c3bce52018-02-01 22:00:31 +000045 makeAllUserToastAndShow(R.string.screen_pinning_start);
Jason Monka8f569c2014-07-07 12:15:21 -040046 }
47
Charles Hebfe82d12017-10-20 11:59:44 +010048 /** Show "Screen unpinned" toast. */
Daichi Hirono926c56f2018-04-13 15:40:37 +090049 public void showPinningExitToast() {
Matthew Ng9c3bce52018-02-01 22:00:31 +000050 makeAllUserToastAndShow(R.string.screen_pinning_exit);
Charles Hebfe82d12017-10-20 11:59:44 +010051 }
52
53 /** Show a toast that describes the gesture the user should use to escape pinned mode. */
Hongwei Wang98d08582019-08-14 14:55:27 -070054 public void showEscapeToast(boolean isGestureNavEnabled, boolean isRecentsButtonVisible) {
Koji Fukuid8c16032016-10-06 23:00:00 +090055 long showToastTime = SystemClock.elapsedRealtime();
56 if ((showToastTime - mLastShowToastTime) < SHOW_TOAST_MINIMUM_INTERVAL) {
57 Slog.i(TAG, "Ignore toast since it is requested in very short interval.");
58 return;
59 }
Jason Monk07f82b72014-08-19 15:20:01 -040060 if (mLastToast != null) {
61 mLastToast.cancel();
62 }
Hongwei Wang98d08582019-08-14 14:55:27 -070063 mLastToast = makeAllUserToastAndShow(isGestureNavEnabled
64 ? R.string.screen_pinning_toast_gesture_nav
65 : isRecentsButtonVisible
66 ? R.string.screen_pinning_toast
67 : R.string.screen_pinning_toast_recents_invisible);
Koji Fukuid8c16032016-10-06 23:00:00 +090068 mLastShowToastTime = showToastTime;
Jason Monka8f569c2014-07-07 12:15:21 -040069 }
70
Charles Hebfe82d12017-10-20 11:59:44 +010071 private Toast makeAllUserToastAndShow(int resId) {
Matthew Ng9c3bce52018-02-01 22:00:31 +000072 Toast toast = SysUIToast.makeText(mContext, resId, Toast.LENGTH_LONG);
Jason Monka5852682014-10-23 11:48:36 -040073 toast.show();
74 return toast;
Jason Monk62515be2014-05-21 16:06:19 -040075 }
Jason Monk62515be2014-05-21 16:06:19 -040076}