Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 1 | /* |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 2 | * Copyright (C) 2018 The Android Open Source Project |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 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 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 17 | package com.android.systemui.statusbar.phone; |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 18 | |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 19 | import android.content.Context; |
Koji Fukui | d8c1603 | 2016-10-06 23:00:00 +0900 | [diff] [blame] | 20 | import android.os.SystemClock; |
| 21 | import android.util.Slog; |
Jason Monk | a8f569c | 2014-07-07 12:15:21 -0400 | [diff] [blame] | 22 | import android.widget.Toast; |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 23 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 24 | import com.android.systemui.R; |
| 25 | import com.android.systemui.SysUIToast; |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 26 | |
| 27 | /** |
Charles He | 4973680 | 2017-10-23 11:06:23 +0100 | [diff] [blame] | 28 | * 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 Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 30 | */ |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 31 | public class ScreenPinningNotify { |
| 32 | private static final String TAG = "ScreenPinningNotify"; |
Koji Fukui | d8c1603 | 2016-10-06 23:00:00 +0900 | [diff] [blame] | 33 | private static final long SHOW_TOAST_MINIMUM_INTERVAL = 1000; |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 34 | |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 35 | private final Context mContext; |
Jason Monk | 07f82b7 | 2014-08-19 15:20:01 -0400 | [diff] [blame] | 36 | private Toast mLastToast; |
Koji Fukui | d8c1603 | 2016-10-06 23:00:00 +0900 | [diff] [blame] | 37 | private long mLastShowToastTime; |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 38 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 39 | public ScreenPinningNotify(Context context) { |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 40 | mContext = context; |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 41 | } |
| 42 | |
Charles He | bfe82d1 | 2017-10-20 11:59:44 +0100 | [diff] [blame] | 43 | /** Show "Screen pinned" toast. */ |
Daichi Hirono | 926c56f | 2018-04-13 15:40:37 +0900 | [diff] [blame] | 44 | public void showPinningStartToast() { |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 45 | makeAllUserToastAndShow(R.string.screen_pinning_start); |
Jason Monk | a8f569c | 2014-07-07 12:15:21 -0400 | [diff] [blame] | 46 | } |
| 47 | |
Charles He | bfe82d1 | 2017-10-20 11:59:44 +0100 | [diff] [blame] | 48 | /** Show "Screen unpinned" toast. */ |
Daichi Hirono | 926c56f | 2018-04-13 15:40:37 +0900 | [diff] [blame] | 49 | public void showPinningExitToast() { |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 50 | makeAllUserToastAndShow(R.string.screen_pinning_exit); |
Charles He | bfe82d1 | 2017-10-20 11:59:44 +0100 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /** Show a toast that describes the gesture the user should use to escape pinned mode. */ |
Hongwei Wang | 98d0858 | 2019-08-14 14:55:27 -0700 | [diff] [blame] | 54 | public void showEscapeToast(boolean isGestureNavEnabled, boolean isRecentsButtonVisible) { |
Koji Fukui | d8c1603 | 2016-10-06 23:00:00 +0900 | [diff] [blame] | 55 | 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 Monk | 07f82b7 | 2014-08-19 15:20:01 -0400 | [diff] [blame] | 60 | if (mLastToast != null) { |
| 61 | mLastToast.cancel(); |
| 62 | } |
Hongwei Wang | 98d0858 | 2019-08-14 14:55:27 -0700 | [diff] [blame] | 63 | 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 Fukui | d8c1603 | 2016-10-06 23:00:00 +0900 | [diff] [blame] | 68 | mLastShowToastTime = showToastTime; |
Jason Monk | a8f569c | 2014-07-07 12:15:21 -0400 | [diff] [blame] | 69 | } |
| 70 | |
Charles He | bfe82d1 | 2017-10-20 11:59:44 +0100 | [diff] [blame] | 71 | private Toast makeAllUserToastAndShow(int resId) { |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 72 | Toast toast = SysUIToast.makeText(mContext, resId, Toast.LENGTH_LONG); |
Jason Monk | a585268 | 2014-10-23 11:48:36 -0400 | [diff] [blame] | 73 | toast.show(); |
| 74 | return toast; |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 75 | } |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 76 | } |