Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 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.bubbles; |
| 18 | |
Yuncheol Heo | 5d62e75 | 2020-04-08 14:54:24 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW; |
Mady Mellor | c41ed32 | 2019-09-25 11:19:26 -0700 | [diff] [blame] | 20 | import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK; |
| 21 | import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT; |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 22 | import static android.graphics.PixelFormat.TRANSPARENT; |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 23 | import static android.view.Display.INVALID_DISPLAY; |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 24 | import static android.view.InsetsState.ITYPE_IME; |
Jorim Jaggi | 924ef75 | 2020-01-29 17:26:55 +0100 | [diff] [blame] | 25 | import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL; |
| 26 | import static android.view.ViewRootImpl.sNewInsetsMode; |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
| 28 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 29 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
| 30 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 31 | |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 32 | import static com.android.systemui.bubbles.BubbleDebugConfig.DEBUG_BUBBLE_EXPANDED_VIEW; |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 33 | import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_BUBBLES; |
| 34 | import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_WITH_CLASS_NAME; |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 35 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 36 | import android.annotation.Nullable; |
Joshua Tsuji | 847b1d42 | 2020-06-01 13:42:19 -0400 | [diff] [blame] | 37 | import android.annotation.SuppressLint; |
Mady Mellor | 60101c9 | 2019-04-11 19:04:00 -0700 | [diff] [blame] | 38 | import android.app.ActivityOptions; |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 39 | import android.app.ActivityTaskManager; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 40 | import android.app.ActivityView; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 41 | import android.app.PendingIntent; |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 42 | import android.content.ComponentName; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 43 | import android.content.Context; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 44 | import android.content.Intent; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 45 | import android.content.res.Resources; |
Mady Mellor | dd49705 | 2019-01-30 17:23:48 -0800 | [diff] [blame] | 46 | import android.content.res.TypedArray; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 47 | import android.graphics.Color; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 48 | import android.graphics.Insets; |
| 49 | import android.graphics.Point; |
Mady Mellor | 47b11e3 | 2019-07-11 19:06:21 -0700 | [diff] [blame] | 50 | import android.graphics.Rect; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 51 | import android.graphics.drawable.ShapeDrawable; |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 52 | import android.hardware.display.VirtualDisplay; |
| 53 | import android.os.Binder; |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 54 | import android.os.RemoteException; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 55 | import android.util.AttributeSet; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 56 | import android.util.Log; |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 57 | import android.view.Gravity; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 58 | import android.view.View; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 59 | import android.view.WindowInsets; |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 60 | import android.view.WindowManager; |
Lyn Han | 670fa80 | 2020-05-05 12:56:33 -0700 | [diff] [blame] | 61 | import android.view.accessibility.AccessibilityNodeInfo; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 62 | import android.widget.LinearLayout; |
| 63 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 64 | import com.android.internal.policy.ScreenDecorationsUtils; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 65 | import com.android.systemui.Dependency; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 66 | import com.android.systemui.R; |
| 67 | import com.android.systemui.recents.TriangleShape; |
Lyn Han | 754e77b | 2019-04-30 14:34:49 -0700 | [diff] [blame] | 68 | import com.android.systemui.statusbar.AlphaOptimizedButton; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 69 | |
| 70 | /** |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 71 | * Container for the expanded bubble view, handles rendering the caret and settings icon. |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 72 | */ |
Joshua Tsuji | 6855cab | 2020-04-16 01:05:39 -0400 | [diff] [blame] | 73 | public class BubbleExpandedView extends LinearLayout { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 74 | private static final String TAG = TAG_WITH_CLASS_NAME ? "BubbleExpandedView" : TAG_BUBBLES; |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 75 | private static final String WINDOW_TITLE = "ImeInsetsWindowWithoutContent"; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 76 | |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 77 | private enum ActivityViewStatus { |
| 78 | // ActivityView is being initialized, cannot start an activity yet. |
| 79 | INITIALIZING, |
| 80 | // ActivityView is initialized, and ready to start an activity. |
| 81 | INITIALIZED, |
| 82 | // Activity runs in the ActivityView. |
| 83 | ACTIVITY_STARTED, |
| 84 | // ActivityView is released, so activity launching will no longer be permitted. |
| 85 | RELEASED, |
| 86 | } |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 87 | |
| 88 | // The triangle pointing to the expanded view |
| 89 | private View mPointerView; |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 90 | private int mPointerMargin; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 91 | |
Lyn Han | 754e77b | 2019-04-30 14:34:49 -0700 | [diff] [blame] | 92 | private AlphaOptimizedButton mSettingsIcon; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 93 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 94 | // Views for expanded state |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 95 | private ActivityView mActivityView; |
| 96 | |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 97 | private ActivityViewStatus mActivityViewStatus = ActivityViewStatus.INITIALIZING; |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 98 | private int mTaskId = -1; |
| 99 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 100 | private PendingIntent mPendingIntent; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 101 | |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 102 | private boolean mKeyboardVisible; |
| 103 | private boolean mNeedsNewHeight; |
| 104 | |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 105 | private Point mDisplaySize; |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 106 | private int mMinHeight; |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 107 | private int mOverflowHeight; |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 108 | private int mSettingsIconHeight; |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 109 | private int mPointerWidth; |
| 110 | private int mPointerHeight; |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 111 | private ShapeDrawable mPointerDrawable; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 112 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 113 | @Nullable private Bubble mBubble; |
| 114 | |
| 115 | private boolean mIsOverflow; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 116 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 117 | private BubbleController mBubbleController = Dependency.get(BubbleController.class); |
Mady Mellor | 9be3bed | 2019-08-21 17:26:26 -0700 | [diff] [blame] | 118 | private WindowManager mWindowManager; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 119 | |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 120 | private BubbleStackView mStackView; |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 121 | private View mVirtualImeView; |
| 122 | private WindowManager mVirtualDisplayWindowManager; |
| 123 | private boolean mImeShowing = false; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 124 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 125 | private ActivityView.StateCallback mStateCallback = new ActivityView.StateCallback() { |
| 126 | @Override |
| 127 | public void onActivityViewReady(ActivityView view) { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 128 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 129 | Log.d(TAG, "onActivityViewReady: mActivityViewStatus=" + mActivityViewStatus |
| 130 | + " bubble=" + getBubbleKey()); |
| 131 | } |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 132 | switch (mActivityViewStatus) { |
| 133 | case INITIALIZING: |
| 134 | case INITIALIZED: |
| 135 | // Custom options so there is no activity transition animation |
| 136 | ActivityOptions options = ActivityOptions.makeCustomAnimation(getContext(), |
| 137 | 0 /* enterResId */, 0 /* exitResId */); |
Winson Chung | 0620052 | 2020-03-31 22:47:02 -0700 | [diff] [blame] | 138 | options.setTaskAlwaysOnTop(true); |
Yuncheol Heo | 5d62e75 | 2020-04-08 14:54:24 -0700 | [diff] [blame] | 139 | options.setLaunchWindowingMode(WINDOWING_MODE_MULTI_WINDOW); |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 140 | // Post to keep the lifecycle normal |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 141 | post(() -> { |
| 142 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 143 | Log.d(TAG, "onActivityViewReady: calling startActivity, " |
| 144 | + "bubble=" + getBubbleKey()); |
| 145 | } |
Mady Mellor | 8454ddf | 2019-08-15 11:16:23 -0700 | [diff] [blame] | 146 | try { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 147 | if (!mIsOverflow && mBubble.usingShortcutInfo()) { |
Mady Mellor | 80d5ed1 | 2020-04-10 21:17:30 -0700 | [diff] [blame] | 148 | options.setApplyActivityFlagsForBubbles(true); |
Mady Mellor | b547e5e | 2019-12-02 10:15:56 -0800 | [diff] [blame] | 149 | mActivityView.startShortcutActivity(mBubble.getShortcutInfo(), |
| 150 | options, null /* sourceBounds */); |
| 151 | } else { |
| 152 | Intent fillInIntent = new Intent(); |
| 153 | // Apply flags to make behaviour match documentLaunchMode=always. |
| 154 | fillInIntent.addFlags(FLAG_ACTIVITY_NEW_DOCUMENT); |
| 155 | fillInIntent.addFlags(FLAG_ACTIVITY_MULTIPLE_TASK); |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 156 | mActivityView.startActivity(mPendingIntent, fillInIntent, options); |
Mady Mellor | b547e5e | 2019-12-02 10:15:56 -0800 | [diff] [blame] | 157 | } |
Mady Mellor | 8454ddf | 2019-08-15 11:16:23 -0700 | [diff] [blame] | 158 | } catch (RuntimeException e) { |
| 159 | // If there's a runtime exception here then there's something |
| 160 | // wrong with the intent, we can't really recover / try to populate |
| 161 | // the bubble again so we'll just remove it. |
| 162 | Log.w(TAG, "Exception while displaying bubble: " + getBubbleKey() |
| 163 | + ", " + e.getMessage() + "; removing bubble"); |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 164 | mBubbleController.removeBubble(getBubbleKey(), |
Mady Mellor | 8454ddf | 2019-08-15 11:16:23 -0700 | [diff] [blame] | 165 | BubbleController.DISMISS_INVALID_INTENT); |
| 166 | } |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 167 | }); |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 168 | mActivityViewStatus = ActivityViewStatus.ACTIVITY_STARTED; |
Mady Mellor | 6d00203 | 2019-02-13 13:45:17 -0800 | [diff] [blame] | 169 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public void onActivityViewDestroyed(ActivityView view) { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 174 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 175 | Log.d(TAG, "onActivityViewDestroyed: mActivityViewStatus=" + mActivityViewStatus |
| 176 | + " bubble=" + getBubbleKey()); |
| 177 | } |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 178 | mActivityViewStatus = ActivityViewStatus.RELEASED; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 179 | } |
| 180 | |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 181 | @Override |
| 182 | public void onTaskCreated(int taskId, ComponentName componentName) { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 183 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 184 | Log.d(TAG, "onTaskCreated: taskId=" + taskId |
| 185 | + " bubble=" + getBubbleKey()); |
| 186 | } |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 187 | // Since Bubble ActivityView applies singleTaskDisplay this is |
| 188 | // guaranteed to only be called once per ActivityView. The taskId is |
| 189 | // saved to use for removeTask, preventing appearance in recent tasks. |
| 190 | mTaskId = taskId; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | /** |
| 194 | * This is only called for tasks on this ActivityView, which is also set to |
| 195 | * single-task mode -- meaning never more than one task on this display. If a task |
| 196 | * is being removed, it's the top Activity finishing and this bubble should |
| 197 | * be removed or collapsed. |
| 198 | */ |
| 199 | @Override |
| 200 | public void onTaskRemovalStarted(int taskId) { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 201 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 202 | Log.d(TAG, "onTaskRemovalStarted: taskId=" + taskId |
| 203 | + " mActivityViewStatus=" + mActivityViewStatus |
| 204 | + " bubble=" + getBubbleKey()); |
| 205 | } |
Mady Mellor | dd6fe61 | 2020-04-15 11:47:55 -0700 | [diff] [blame] | 206 | if (mBubble != null) { |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 207 | // Must post because this is called from a binder thread. |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 208 | post(() -> mBubbleController.removeBubble(mBubble.getKey(), |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 209 | BubbleController.DISMISS_TASK_FINISHED)); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | }; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 213 | |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 214 | public BubbleExpandedView(Context context) { |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 215 | this(context, null); |
| 216 | } |
| 217 | |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 218 | public BubbleExpandedView(Context context, AttributeSet attrs) { |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 219 | this(context, attrs, 0); |
| 220 | } |
| 221 | |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 222 | public BubbleExpandedView(Context context, AttributeSet attrs, int defStyleAttr) { |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 223 | this(context, attrs, defStyleAttr, 0); |
| 224 | } |
| 225 | |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 226 | public BubbleExpandedView(Context context, AttributeSet attrs, int defStyleAttr, |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 227 | int defStyleRes) { |
| 228 | super(context, attrs, defStyleAttr, defStyleRes); |
Lyn Han | bc985c5 | 2020-05-18 17:57:58 -0700 | [diff] [blame] | 229 | updateDimensions(); |
| 230 | } |
| 231 | |
| 232 | void updateDimensions() { |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 233 | mDisplaySize = new Point(); |
Lyn Han | bc985c5 | 2020-05-18 17:57:58 -0700 | [diff] [blame] | 234 | mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 235 | // Get the real size -- this includes screen decorations (notches, statusbar, navbar). |
Mady Mellor | 9be3bed | 2019-08-21 17:26:26 -0700 | [diff] [blame] | 236 | mWindowManager.getDefaultDisplay().getRealSize(mDisplaySize); |
Mady Mellor | 47b11e3 | 2019-07-11 19:06:21 -0700 | [diff] [blame] | 237 | Resources res = getResources(); |
| 238 | mMinHeight = res.getDimensionPixelSize(R.dimen.bubble_expanded_default_height); |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 239 | mOverflowHeight = res.getDimensionPixelSize(R.dimen.bubble_overflow_height); |
Mady Mellor | 47b11e3 | 2019-07-11 19:06:21 -0700 | [diff] [blame] | 240 | mPointerMargin = res.getDimensionPixelSize(R.dimen.bubble_pointer_margin); |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 241 | } |
| 242 | |
Joshua Tsuji | 847b1d42 | 2020-06-01 13:42:19 -0400 | [diff] [blame] | 243 | @SuppressLint("ClickableViewAccessibility") |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 244 | @Override |
| 245 | protected void onFinishInflate() { |
| 246 | super.onFinishInflate(); |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 247 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 248 | Log.d(TAG, "onFinishInflate: bubble=" + getBubbleKey()); |
| 249 | } |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 250 | |
| 251 | Resources res = getResources(); |
| 252 | mPointerView = findViewById(R.id.pointer_view); |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 253 | mPointerWidth = res.getDimensionPixelSize(R.dimen.bubble_pointer_width); |
| 254 | mPointerHeight = res.getDimensionPixelSize(R.dimen.bubble_pointer_height); |
Mady Mellor | dd49705 | 2019-01-30 17:23:48 -0800 | [diff] [blame] | 255 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 256 | mPointerDrawable = new ShapeDrawable(TriangleShape.create( |
Lyn Han | 5aa27e2 | 2019-05-15 10:55:07 -0700 | [diff] [blame] | 257 | mPointerWidth, mPointerHeight, true /* pointUp */)); |
Joshua Tsuji | dd082b6 | 2020-05-20 22:26:24 -0400 | [diff] [blame] | 258 | mPointerDrawable.setTint(Color.WHITE); |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 259 | mPointerView.setBackground(mPointerDrawable); |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 260 | mPointerView.setVisibility(INVISIBLE); |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 261 | |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 262 | mSettingsIconHeight = getContext().getResources().getDimensionPixelSize( |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 263 | R.dimen.bubble_manage_button_height); |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 264 | mSettingsIcon = findViewById(R.id.settings_button); |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 265 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 266 | mActivityView = new ActivityView(mContext, null /* attrs */, 0 /* defStyle */, |
shawnlin | ba532af | 2020-06-02 17:48:37 +0800 | [diff] [blame] | 267 | true /* singleTaskInstance */, false /* usePublicVirtualDisplay*/, |
| 268 | true /* disableSurfaceViewBackgroundLayer */); |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 269 | |
lumark | dc9b319 | 2019-07-23 21:18:17 +0800 | [diff] [blame] | 270 | // Set ActivityView's alpha value as zero, since there is no view content to be shown. |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 271 | setContentVisibility(false); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 272 | addView(mActivityView); |
| 273 | |
Lyn Han | 5aa27e2 | 2019-05-15 10:55:07 -0700 | [diff] [blame] | 274 | // Expanded stack layout, top to bottom: |
| 275 | // Expanded view container |
| 276 | // ==> bubble row |
| 277 | // ==> expanded view |
| 278 | // ==> activity view |
| 279 | // ==> manage button |
| 280 | bringChildToFront(mActivityView); |
| 281 | bringChildToFront(mSettingsIcon); |
Mady Mellor | 52b1ac6 | 2019-04-10 16:59:03 -0700 | [diff] [blame] | 282 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 283 | applyThemeAttrs(); |
| 284 | |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 285 | setOnApplyWindowInsetsListener((View view, WindowInsets insets) -> { |
| 286 | // Keep track of IME displaying because we should not make any adjustments that might |
| 287 | // cause a config change while the IME is displayed otherwise it'll loose focus. |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 288 | final int keyboardHeight = insets.getSystemWindowInsetBottom() |
| 289 | - insets.getStableInsetBottom(); |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 290 | mKeyboardVisible = keyboardHeight != 0; |
| 291 | if (!mKeyboardVisible && mNeedsNewHeight) { |
| 292 | updateHeight(); |
| 293 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 294 | return view.onApplyWindowInsets(insets); |
| 295 | }); |
Joshua Tsuji | 847b1d42 | 2020-06-01 13:42:19 -0400 | [diff] [blame] | 296 | |
| 297 | final int expandedViewPadding = |
| 298 | res.getDimensionPixelSize(R.dimen.bubble_expanded_view_padding); |
| 299 | |
| 300 | setPadding( |
| 301 | expandedViewPadding, expandedViewPadding, expandedViewPadding, expandedViewPadding); |
| 302 | setOnTouchListener((view, motionEvent) -> { |
| 303 | if (!usingActivityView()) { |
| 304 | return false; |
| 305 | } |
| 306 | |
| 307 | final Rect avBounds = new Rect(); |
| 308 | mActivityView.getBoundsOnScreen(avBounds); |
| 309 | |
| 310 | // Consume and ignore events on the expanded view padding that are within the |
| 311 | // ActivityView's vertical bounds. These events are part of a back gesture, and so they |
| 312 | // should not collapse the stack (which all other touches on areas around the AV would |
| 313 | // do). |
| 314 | if (motionEvent.getRawY() >= avBounds.top && motionEvent.getRawY() <= avBounds.bottom) { |
| 315 | return true; |
| 316 | } |
| 317 | |
| 318 | return false; |
| 319 | }); |
Joshua Tsuji | 519d4c1 | 2020-05-29 15:22:31 -0400 | [diff] [blame] | 320 | |
| 321 | // BubbleStackView is forced LTR, but we want to respect the locale for expanded view layout |
| 322 | // so the Manage button appears on the right. |
| 323 | setLayoutDirection(LAYOUT_DIRECTION_LOCALE); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 324 | } |
| 325 | |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 326 | private String getBubbleKey() { |
| 327 | return mBubble != null ? mBubble.getKey() : "null"; |
| 328 | } |
| 329 | |
Joshua Tsuji | 6855cab | 2020-04-16 01:05:39 -0400 | [diff] [blame] | 330 | void setManageClickListener(OnClickListener manageClickListener) { |
| 331 | findViewById(R.id.settings_button).setOnClickListener(manageClickListener); |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * Updates the ActivityView's obscured touchable region. This calls onLocationChanged, which |
| 336 | * results in a call to {@link BubbleStackView#subtractObscuredTouchableRegion}. This is useful |
| 337 | * if a view has been added or removed from on top of the ActivityView, such as the manage menu. |
| 338 | */ |
| 339 | void updateObscuredTouchableRegion() { |
Mady Mellor | 64db51a | 2020-05-27 19:00:14 -0700 | [diff] [blame] | 340 | if (mActivityView != null) { |
| 341 | mActivityView.onLocationChanged(); |
| 342 | } |
Joshua Tsuji | 6855cab | 2020-04-16 01:05:39 -0400 | [diff] [blame] | 343 | } |
| 344 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 345 | void applyThemeAttrs() { |
Lyn Han | 61bfdb3 | 2019-12-10 14:34:12 -0800 | [diff] [blame] | 346 | final TypedArray ta = mContext.obtainStyledAttributes( |
Joshua Tsuji | dd082b6 | 2020-05-20 22:26:24 -0400 | [diff] [blame] | 347 | new int[] {android.R.attr.dialogCornerRadius}); |
| 348 | float cornerRadius = ta.getDimensionPixelSize(0, 0); |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 349 | ta.recycle(); |
| 350 | |
Lyn Han | edb55e2 | 2020-02-12 18:55:39 -0800 | [diff] [blame] | 351 | if (mActivityView != null && ScreenDecorationsUtils.supportsRoundedCornersOnWindows( |
| 352 | mContext.getResources())) { |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 353 | mActivityView.setCornerRadius(cornerRadius); |
| 354 | } |
| 355 | } |
| 356 | |
Joshua Tsuji | 847b1d42 | 2020-06-01 13:42:19 -0400 | [diff] [blame] | 357 | /** |
| 358 | * Hides the IME if it's showing. This is currently done by dispatching a back press to the AV. |
| 359 | */ |
| 360 | void hideImeIfVisible() { |
| 361 | if (mKeyboardVisible) { |
| 362 | performBackPressIfNeeded(); |
| 363 | } |
| 364 | } |
| 365 | |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 366 | @Override |
| 367 | protected void onDetachedFromWindow() { |
| 368 | super.onDetachedFromWindow(); |
Joshua Tsuji | 847b1d42 | 2020-06-01 13:42:19 -0400 | [diff] [blame] | 369 | hideImeIfVisible(); |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 370 | mKeyboardVisible = false; |
| 371 | mNeedsNewHeight = false; |
| 372 | if (mActivityView != null) { |
Mady Mellor | af02fa4 | 2020-03-04 14:22:16 -0800 | [diff] [blame] | 373 | if (sNewInsetsMode == NEW_INSETS_MODE_FULL) { |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 374 | setImeWindowToDisplay(0, 0); |
Mady Mellor | af02fa4 | 2020-03-04 14:22:16 -0800 | [diff] [blame] | 375 | } else { |
| 376 | mActivityView.setForwardedInsets(Insets.of(0, 0, 0, 0)); |
| 377 | } |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 378 | } |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 379 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 380 | Log.d(TAG, "onDetachedFromWindow: bubble=" + getBubbleKey()); |
| 381 | } |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | /** |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 385 | * Set visibility of contents in the expanded state. |
| 386 | * |
| 387 | * @param visibility {@code true} if the contents should be visible on the screen. |
| 388 | * |
| 389 | * Note that this contents visibility doesn't affect visibility at {@link android.view.View}, |
| 390 | * and setting {@code false} actually means rendering the contents in transparent. |
| 391 | */ |
| 392 | void setContentVisibility(boolean visibility) { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 393 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 394 | Log.d(TAG, "setContentVisibility: visibility=" + visibility |
| 395 | + " bubble=" + getBubbleKey()); |
| 396 | } |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 397 | final float alpha = visibility ? 1f : 0f; |
| 398 | mPointerView.setAlpha(alpha); |
| 399 | if (mActivityView != null) { |
| 400 | mActivityView.setAlpha(alpha); |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | /** |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 405 | * Called by {@link BubbleStackView} when the insets for the expanded state should be updated. |
| 406 | * This should be done post-move and post-animation. |
| 407 | */ |
| 408 | void updateInsets(WindowInsets insets) { |
| 409 | if (usingActivityView()) { |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 410 | int[] screenLoc = mActivityView.getLocationOnScreen(); |
| 411 | final int activityViewBottom = screenLoc[1] + mActivityView.getHeight(); |
Mady Mellor | 9be3bed | 2019-08-21 17:26:26 -0700 | [diff] [blame] | 412 | final int keyboardTop = mDisplaySize.y - Math.max(insets.getSystemWindowInsetBottom(), |
| 413 | insets.getDisplayCutout() != null |
| 414 | ? insets.getDisplayCutout().getSafeInsetBottom() |
| 415 | : 0); |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 416 | final int insetsBottom = Math.max(activityViewBottom - keyboardTop, 0); |
Jorim Jaggi | 924ef75 | 2020-01-29 17:26:55 +0100 | [diff] [blame] | 417 | |
Jorim Jaggi | 924ef75 | 2020-01-29 17:26:55 +0100 | [diff] [blame] | 418 | if (sNewInsetsMode == NEW_INSETS_MODE_FULL) { |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 419 | setImeWindowToDisplay(getWidth(), insetsBottom); |
Jorim Jaggi | 924ef75 | 2020-01-29 17:26:55 +0100 | [diff] [blame] | 420 | } else { |
| 421 | mActivityView.setForwardedInsets(Insets.of(0, 0, 0, insetsBottom)); |
| 422 | } |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 426 | private void setImeWindowToDisplay(int w, int h) { |
| 427 | if (getVirtualDisplayId() == INVALID_DISPLAY) { |
| 428 | return; |
| 429 | } |
| 430 | if (h == 0 || w == 0) { |
| 431 | if (mImeShowing) { |
| 432 | mVirtualImeView.setVisibility(GONE); |
| 433 | mImeShowing = false; |
| 434 | } |
| 435 | return; |
| 436 | } |
| 437 | final Context virtualDisplayContext = mContext.createDisplayContext( |
| 438 | getVirtualDisplay().getDisplay()); |
| 439 | |
| 440 | if (mVirtualDisplayWindowManager == null) { |
| 441 | mVirtualDisplayWindowManager = |
| 442 | (WindowManager) virtualDisplayContext.getSystemService(Context.WINDOW_SERVICE); |
| 443 | } |
| 444 | if (mVirtualImeView == null) { |
| 445 | mVirtualImeView = new View(virtualDisplayContext); |
| 446 | mVirtualImeView.setVisibility(VISIBLE); |
| 447 | mVirtualDisplayWindowManager.addView(mVirtualImeView, |
| 448 | getVirtualImeViewAttrs(w, h)); |
| 449 | } else { |
| 450 | mVirtualDisplayWindowManager.updateViewLayout(mVirtualImeView, |
| 451 | getVirtualImeViewAttrs(w, h)); |
| 452 | mVirtualImeView.setVisibility(VISIBLE); |
| 453 | } |
| 454 | |
| 455 | mImeShowing = true; |
| 456 | } |
| 457 | |
| 458 | private WindowManager.LayoutParams getVirtualImeViewAttrs(int w, int h) { |
| 459 | // To use TYPE_NAVIGATION_BAR_PANEL instead of TYPE_IME_BAR to bypass the IME window type |
| 460 | // token check when adding the window. |
| 461 | final WindowManager.LayoutParams attrs = |
| 462 | new WindowManager.LayoutParams(w, h, TYPE_NAVIGATION_BAR_PANEL, |
| 463 | FLAG_LAYOUT_NO_LIMITS | FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCHABLE, |
| 464 | TRANSPARENT); |
| 465 | attrs.gravity = Gravity.BOTTOM; |
| 466 | attrs.setTitle(WINDOW_TITLE); |
| 467 | attrs.token = new Binder(); |
| 468 | attrs.providesInsetsTypes = new int[]{ITYPE_IME}; |
| 469 | attrs.alpha = 0.0f; |
| 470 | return attrs; |
| 471 | } |
| 472 | |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 473 | void setStackView(BubbleStackView stackView) { |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 474 | mStackView = stackView; |
Mady Mellor | 6d00203 | 2019-02-13 13:45:17 -0800 | [diff] [blame] | 475 | } |
| 476 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 477 | public void setOverflow(boolean overflow) { |
| 478 | mIsOverflow = overflow; |
| 479 | |
| 480 | Intent target = new Intent(mContext, BubbleOverflowActivity.class); |
| 481 | mPendingIntent = PendingIntent.getActivity(mContext, /* requestCode */ 0, |
| 482 | target, PendingIntent.FLAG_UPDATE_CURRENT); |
| 483 | mSettingsIcon.setVisibility(GONE); |
| 484 | } |
| 485 | |
Mady Mellor | 6d00203 | 2019-02-13 13:45:17 -0800 | [diff] [blame] | 486 | /** |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 487 | * Sets the bubble used to populate this view. |
Mady Mellor | 6d00203 | 2019-02-13 13:45:17 -0800 | [diff] [blame] | 488 | */ |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 489 | void update(Bubble bubble) { |
| 490 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 491 | Log.d(TAG, "update: bubble=" + (bubble != null ? bubble.getKey() : "null")); |
| 492 | } |
| 493 | boolean isNew = mBubble == null; |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 494 | if (isNew || bubble != null && bubble.getKey().equals(mBubble.getKey())) { |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 495 | mBubble = bubble; |
| 496 | mSettingsIcon.setContentDescription(getResources().getString( |
| 497 | R.string.bubbles_settings_button_description, bubble.getAppName())); |
| 498 | |
Lyn Han | 670fa80 | 2020-05-05 12:56:33 -0700 | [diff] [blame] | 499 | mSettingsIcon.setAccessibilityDelegate( |
| 500 | new AccessibilityDelegate() { |
| 501 | @Override |
| 502 | public void onInitializeAccessibilityNodeInfo(View host, |
| 503 | AccessibilityNodeInfo info) { |
| 504 | super.onInitializeAccessibilityNodeInfo(host, info); |
| 505 | // On focus, have TalkBack say |
| 506 | // "Actions available. Use swipe up then right to view." |
| 507 | // in addition to the default "double tap to activate". |
| 508 | mStackView.setupLocalMenu(info); |
| 509 | } |
| 510 | }); |
| 511 | |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 512 | if (isNew) { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 513 | mPendingIntent = mBubble.getBubbleIntent(); |
| 514 | if (mPendingIntent != null || mBubble.getShortcutInfo() != null) { |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 515 | setContentVisibility(false); |
| 516 | mActivityView.setVisibility(VISIBLE); |
| 517 | } |
| 518 | } |
| 519 | applyThemeAttrs(); |
| 520 | } else { |
| 521 | Log.w(TAG, "Trying to update entry with different key, new bubble: " |
| 522 | + bubble.getKey() + " old bubble: " + bubble.getKey()); |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | /** |
| 527 | * Lets activity view know it should be shown / populated with activity content. |
| 528 | */ |
| 529 | void populateExpandedView() { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 530 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 531 | Log.d(TAG, "populateExpandedView: " |
| 532 | + "bubble=" + getBubbleKey()); |
| 533 | } |
| 534 | |
Mady Mellor | 5029fa6 | 2019-03-05 12:16:21 -0800 | [diff] [blame] | 535 | if (usingActivityView()) { |
| 536 | mActivityView.setCallback(mStateCallback); |
| 537 | } else { |
Issei Suzuki | a91f396 | 2019-06-07 11:48:23 +0200 | [diff] [blame] | 538 | Log.e(TAG, "Cannot populate expanded view."); |
Mady Mellor | 5029fa6 | 2019-03-05 12:16:21 -0800 | [diff] [blame] | 539 | } |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 540 | } |
| 541 | |
Mark Renouf | 041d726 | 2019-02-06 12:09:41 -0500 | [diff] [blame] | 542 | boolean performBackPressIfNeeded() { |
Mady Mellor | 323fb0b | 2019-03-25 12:15:22 -0700 | [diff] [blame] | 543 | if (!usingActivityView()) { |
Mark Renouf | 041d726 | 2019-02-06 12:09:41 -0500 | [diff] [blame] | 544 | return false; |
| 545 | } |
| 546 | mActivityView.performBackPress(); |
| 547 | return true; |
| 548 | } |
| 549 | |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 550 | void updateHeight() { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 551 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 552 | Log.d(TAG, "updateHeight: bubble=" + getBubbleKey()); |
| 553 | } |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 554 | if (usingActivityView()) { |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 555 | float desiredHeight = mOverflowHeight; |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 556 | if (!mIsOverflow) { |
| 557 | desiredHeight = Math.max(mBubble.getDesiredHeight(mContext), mMinHeight); |
| 558 | } |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 559 | float height = Math.min(desiredHeight, getMaxExpandedHeight()); |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 560 | height = Math.max(height, mIsOverflow? mOverflowHeight : mMinHeight); |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 561 | LayoutParams lp = (LayoutParams) mActivityView.getLayoutParams(); |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 562 | mNeedsNewHeight = lp.height != height; |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 563 | if (!mKeyboardVisible) { |
| 564 | // If the keyboard is visible... don't adjust the height because that will cause |
| 565 | // a configuration change and the keyboard will be lost. |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame] | 566 | lp.height = (int) height; |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 567 | mActivityView.setLayoutParams(lp); |
| 568 | mNeedsNewHeight = false; |
| 569 | } |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 570 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 571 | Log.d(TAG, "updateHeight: bubble=" + getBubbleKey() + " height=" + height |
| 572 | + " mNeedsNewHeight=" + mNeedsNewHeight); |
| 573 | } |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 574 | } |
| 575 | } |
| 576 | |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 577 | private int getMaxExpandedHeight() { |
Mady Mellor | 9be3bed | 2019-08-21 17:26:26 -0700 | [diff] [blame] | 578 | mWindowManager.getDefaultDisplay().getRealSize(mDisplaySize); |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 579 | int[] windowLocation = mActivityView.getLocationOnScreen(); |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 580 | int bottomInset = getRootWindowInsets() != null |
| 581 | ? getRootWindowInsets().getStableInsetBottom() |
| 582 | : 0; |
Lyn Han | 0b955ed | 2020-01-31 09:47:35 -0800 | [diff] [blame] | 583 | return mDisplaySize.y - windowLocation[1] - mSettingsIconHeight - mPointerHeight |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 584 | - mPointerMargin - bottomInset; |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Mady Mellor | 47b11e3 | 2019-07-11 19:06:21 -0700 | [diff] [blame] | 587 | /** |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 588 | * Update appearance of the expanded view being displayed. |
| 589 | */ |
| 590 | public void updateView() { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 591 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 592 | Log.d(TAG, "updateView: bubble=" |
| 593 | + getBubbleKey()); |
| 594 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 595 | if (usingActivityView() |
| 596 | && mActivityView.getVisibility() == VISIBLE |
| 597 | && mActivityView.isAttachedToWindow()) { |
| 598 | mActivityView.onLocationChanged(); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 599 | } |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 600 | updateHeight(); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | /** |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 604 | * Set the x position that the tip of the triangle should point to. |
| 605 | */ |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 606 | public void setPointerPosition(float x) { |
Lyn Han | 9a2f5cf | 2019-05-23 11:01:41 -0700 | [diff] [blame] | 607 | float halfPointerWidth = mPointerWidth / 2f; |
| 608 | float pointerLeft = x - halfPointerWidth; |
| 609 | mPointerView.setTranslationX(pointerLeft); |
Lyn Han | f74ba67 | 2019-05-20 16:08:48 -0700 | [diff] [blame] | 610 | mPointerView.setVisibility(VISIBLE); |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | /** |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 614 | * Position of the manage button displayed in the expanded view. Used for placing user |
| 615 | * education about the manage button. |
| 616 | */ |
Joshua Tsuji | 6855cab | 2020-04-16 01:05:39 -0400 | [diff] [blame] | 617 | public void getManageButtonBoundsOnScreen(Rect rect) { |
| 618 | mSettingsIcon.getBoundsOnScreen(rect); |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | /** |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 622 | * Removes and releases an ActivityView if one was previously created for this bubble. |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 623 | */ |
Mady Mellor | 94d94a7 | 2019-03-05 18:16:59 -0800 | [diff] [blame] | 624 | public void cleanUpExpandedState() { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 625 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 626 | Log.d(TAG, "cleanUpExpandedState: mActivityViewStatus=" + mActivityViewStatus |
| 627 | + ", bubble=" + getBubbleKey()); |
| 628 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 629 | if (mActivityView == null) { |
Mark Renouf | 89b1a4a | 2018-12-04 14:59:45 -0500 | [diff] [blame] | 630 | return; |
| 631 | } |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 632 | switch (mActivityViewStatus) { |
| 633 | case INITIALIZED: |
| 634 | case ACTIVITY_STARTED: |
| 635 | mActivityView.release(); |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 636 | } |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 637 | if (mTaskId != -1) { |
| 638 | try { |
| 639 | ActivityTaskManager.getService().removeTask(mTaskId); |
| 640 | } catch (RemoteException e) { |
| 641 | Log.w(TAG, "Failed to remove taskId " + mTaskId); |
| 642 | } |
| 643 | mTaskId = -1; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 644 | } |
Mark Renouf | 28c250d | 2019-02-25 16:47:34 -0500 | [diff] [blame] | 645 | removeView(mActivityView); |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 646 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 647 | mActivityView = null; |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | /** |
| 651 | * Called when the last task is removed from a {@link android.hardware.display.VirtualDisplay} |
| 652 | * which {@link ActivityView} uses. |
| 653 | */ |
| 654 | void notifyDisplayEmpty() { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 655 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 656 | Log.d(TAG, "notifyDisplayEmpty: bubble=" |
| 657 | + getBubbleKey() |
| 658 | + " mActivityViewStatus=" + mActivityViewStatus); |
| 659 | } |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 660 | if (mActivityViewStatus == ActivityViewStatus.ACTIVITY_STARTED) { |
| 661 | mActivityViewStatus = ActivityViewStatus.INITIALIZED; |
| 662 | } |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 663 | } |
| 664 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 665 | private boolean usingActivityView() { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 666 | return (mPendingIntent != null || mBubble.getShortcutInfo() != null) |
Mady Mellor | 2ac2d3a | 2020-01-08 17:18:54 -0800 | [diff] [blame] | 667 | && mActivityView != null; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 668 | } |
| 669 | |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 670 | /** |
| 671 | * @return the display id of the virtual display. |
| 672 | */ |
| 673 | public int getVirtualDisplayId() { |
| 674 | if (usingActivityView()) { |
| 675 | return mActivityView.getVirtualDisplayId(); |
| 676 | } |
| 677 | return INVALID_DISPLAY; |
| 678 | } |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 679 | |
| 680 | private VirtualDisplay getVirtualDisplay() { |
| 681 | if (usingActivityView()) { |
| 682 | return mActivityView.getVirtualDisplay(); |
| 683 | } |
| 684 | return null; |
| 685 | } |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 686 | } |