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; |
Mady Mellor | 60101c9 | 2019-04-11 19:04:00 -0700 | [diff] [blame] | 37 | import android.app.ActivityOptions; |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 38 | import android.app.ActivityTaskManager; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 39 | import android.app.ActivityView; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 40 | import android.app.PendingIntent; |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 41 | import android.content.ComponentName; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 42 | import android.content.Context; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 43 | import android.content.Intent; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 44 | import android.content.res.Resources; |
Mady Mellor | dd49705 | 2019-01-30 17:23:48 -0800 | [diff] [blame] | 45 | import android.content.res.TypedArray; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 46 | import android.graphics.Color; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 47 | import android.graphics.Insets; |
| 48 | import android.graphics.Point; |
Mady Mellor | 47b11e3 | 2019-07-11 19:06:21 -0700 | [diff] [blame] | 49 | import android.graphics.Rect; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 50 | import android.graphics.drawable.ShapeDrawable; |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 51 | import android.hardware.display.VirtualDisplay; |
| 52 | import android.os.Binder; |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 53 | import android.os.RemoteException; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 54 | import android.util.AttributeSet; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 55 | import android.util.Log; |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 56 | import android.view.Gravity; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 57 | import android.view.View; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 58 | import android.view.WindowInsets; |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 59 | import android.view.WindowManager; |
Lyn Han | 670fa80 | 2020-05-05 12:56:33 -0700 | [diff] [blame] | 60 | import android.view.accessibility.AccessibilityNodeInfo; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 61 | import android.widget.LinearLayout; |
| 62 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 63 | import com.android.internal.policy.ScreenDecorationsUtils; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 64 | import com.android.systemui.Dependency; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 65 | import com.android.systemui.R; |
| 66 | import com.android.systemui.recents.TriangleShape; |
Lyn Han | 754e77b | 2019-04-30 14:34:49 -0700 | [diff] [blame] | 67 | import com.android.systemui.statusbar.AlphaOptimizedButton; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 68 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
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"); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 164 | mBubbleController.removeBubble(getBubbleEntry(), |
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. |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 208 | post(() -> mBubbleController.removeBubble(mBubble.getEntry(), |
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); |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 229 | mDisplaySize = new Point(); |
Mady Mellor | 9be3bed | 2019-08-21 17:26:26 -0700 | [diff] [blame] | 230 | mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 231 | // Get the real size -- this includes screen decorations (notches, statusbar, navbar). |
Mady Mellor | 9be3bed | 2019-08-21 17:26:26 -0700 | [diff] [blame] | 232 | mWindowManager.getDefaultDisplay().getRealSize(mDisplaySize); |
Mady Mellor | 47b11e3 | 2019-07-11 19:06:21 -0700 | [diff] [blame] | 233 | Resources res = getResources(); |
| 234 | mMinHeight = res.getDimensionPixelSize(R.dimen.bubble_expanded_default_height); |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 235 | mOverflowHeight = res.getDimensionPixelSize(R.dimen.bubble_overflow_height); |
Mady Mellor | 47b11e3 | 2019-07-11 19:06:21 -0700 | [diff] [blame] | 236 | mPointerMargin = res.getDimensionPixelSize(R.dimen.bubble_pointer_margin); |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | @Override |
| 240 | protected void onFinishInflate() { |
| 241 | super.onFinishInflate(); |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 242 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 243 | Log.d(TAG, "onFinishInflate: bubble=" + getBubbleKey()); |
| 244 | } |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 245 | |
| 246 | Resources res = getResources(); |
| 247 | mPointerView = findViewById(R.id.pointer_view); |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 248 | mPointerWidth = res.getDimensionPixelSize(R.dimen.bubble_pointer_width); |
| 249 | mPointerHeight = res.getDimensionPixelSize(R.dimen.bubble_pointer_height); |
Mady Mellor | dd49705 | 2019-01-30 17:23:48 -0800 | [diff] [blame] | 250 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 251 | mPointerDrawable = new ShapeDrawable(TriangleShape.create( |
Lyn Han | 5aa27e2 | 2019-05-15 10:55:07 -0700 | [diff] [blame] | 252 | mPointerWidth, mPointerHeight, true /* pointUp */)); |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 253 | mPointerView.setBackground(mPointerDrawable); |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 254 | mPointerView.setVisibility(INVISIBLE); |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 255 | |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 256 | mSettingsIconHeight = getContext().getResources().getDimensionPixelSize( |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 257 | R.dimen.bubble_manage_button_height); |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 258 | mSettingsIcon = findViewById(R.id.settings_button); |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 259 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 260 | mActivityView = new ActivityView(mContext, null /* attrs */, 0 /* defStyle */, |
| 261 | true /* singleTaskInstance */); |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 262 | |
lumark | dc9b319 | 2019-07-23 21:18:17 +0800 | [diff] [blame] | 263 | // 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] | 264 | setContentVisibility(false); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 265 | addView(mActivityView); |
| 266 | |
Lyn Han | 5aa27e2 | 2019-05-15 10:55:07 -0700 | [diff] [blame] | 267 | // Expanded stack layout, top to bottom: |
| 268 | // Expanded view container |
| 269 | // ==> bubble row |
| 270 | // ==> expanded view |
| 271 | // ==> activity view |
| 272 | // ==> manage button |
| 273 | bringChildToFront(mActivityView); |
| 274 | bringChildToFront(mSettingsIcon); |
Mady Mellor | 52b1ac6 | 2019-04-10 16:59:03 -0700 | [diff] [blame] | 275 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 276 | applyThemeAttrs(); |
| 277 | |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 278 | setOnApplyWindowInsetsListener((View view, WindowInsets insets) -> { |
| 279 | // Keep track of IME displaying because we should not make any adjustments that might |
| 280 | // 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] | 281 | final int keyboardHeight = insets.getSystemWindowInsetBottom() |
| 282 | - insets.getStableInsetBottom(); |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 283 | mKeyboardVisible = keyboardHeight != 0; |
| 284 | if (!mKeyboardVisible && mNeedsNewHeight) { |
| 285 | updateHeight(); |
| 286 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 287 | return view.onApplyWindowInsets(insets); |
| 288 | }); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 289 | } |
| 290 | |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 291 | private String getBubbleKey() { |
| 292 | return mBubble != null ? mBubble.getKey() : "null"; |
| 293 | } |
| 294 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 295 | private NotificationEntry getBubbleEntry() { |
| 296 | return mBubble != null ? mBubble.getEntry() : null; |
| 297 | } |
| 298 | |
Joshua Tsuji | 6855cab | 2020-04-16 01:05:39 -0400 | [diff] [blame] | 299 | void setManageClickListener(OnClickListener manageClickListener) { |
| 300 | findViewById(R.id.settings_button).setOnClickListener(manageClickListener); |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Updates the ActivityView's obscured touchable region. This calls onLocationChanged, which |
| 305 | * results in a call to {@link BubbleStackView#subtractObscuredTouchableRegion}. This is useful |
| 306 | * if a view has been added or removed from on top of the ActivityView, such as the manage menu. |
| 307 | */ |
| 308 | void updateObscuredTouchableRegion() { |
| 309 | mActivityView.onLocationChanged(); |
| 310 | } |
| 311 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 312 | void applyThemeAttrs() { |
Lyn Han | 61bfdb3 | 2019-12-10 14:34:12 -0800 | [diff] [blame] | 313 | final TypedArray ta = mContext.obtainStyledAttributes( |
| 314 | new int[] { |
| 315 | android.R.attr.colorBackgroundFloating, |
| 316 | android.R.attr.dialogCornerRadius}); |
| 317 | int bgColor = ta.getColor(0, Color.WHITE); |
| 318 | float cornerRadius = ta.getDimensionPixelSize(1, 0); |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 319 | ta.recycle(); |
| 320 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 321 | mPointerDrawable.setTint(bgColor); |
Lyn Han | edb55e2 | 2020-02-12 18:55:39 -0800 | [diff] [blame] | 322 | if (mActivityView != null && ScreenDecorationsUtils.supportsRoundedCornersOnWindows( |
| 323 | mContext.getResources())) { |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 324 | mActivityView.setCornerRadius(cornerRadius); |
| 325 | } |
| 326 | } |
| 327 | |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 328 | @Override |
| 329 | protected void onDetachedFromWindow() { |
| 330 | super.onDetachedFromWindow(); |
| 331 | mKeyboardVisible = false; |
| 332 | mNeedsNewHeight = false; |
| 333 | if (mActivityView != null) { |
Mady Mellor | af02fa4 | 2020-03-04 14:22:16 -0800 | [diff] [blame] | 334 | if (sNewInsetsMode == NEW_INSETS_MODE_FULL) { |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 335 | setImeWindowToDisplay(0, 0); |
Mady Mellor | af02fa4 | 2020-03-04 14:22:16 -0800 | [diff] [blame] | 336 | } else { |
| 337 | mActivityView.setForwardedInsets(Insets.of(0, 0, 0, 0)); |
| 338 | } |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 339 | } |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 340 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 341 | Log.d(TAG, "onDetachedFromWindow: bubble=" + getBubbleKey()); |
| 342 | } |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | /** |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 346 | * Set visibility of contents in the expanded state. |
| 347 | * |
| 348 | * @param visibility {@code true} if the contents should be visible on the screen. |
| 349 | * |
| 350 | * Note that this contents visibility doesn't affect visibility at {@link android.view.View}, |
| 351 | * and setting {@code false} actually means rendering the contents in transparent. |
| 352 | */ |
| 353 | void setContentVisibility(boolean visibility) { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 354 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 355 | Log.d(TAG, "setContentVisibility: visibility=" + visibility |
| 356 | + " bubble=" + getBubbleKey()); |
| 357 | } |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 358 | final float alpha = visibility ? 1f : 0f; |
| 359 | mPointerView.setAlpha(alpha); |
| 360 | if (mActivityView != null) { |
| 361 | mActivityView.setAlpha(alpha); |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | /** |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 366 | * Called by {@link BubbleStackView} when the insets for the expanded state should be updated. |
| 367 | * This should be done post-move and post-animation. |
| 368 | */ |
| 369 | void updateInsets(WindowInsets insets) { |
| 370 | if (usingActivityView()) { |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 371 | int[] screenLoc = mActivityView.getLocationOnScreen(); |
| 372 | final int activityViewBottom = screenLoc[1] + mActivityView.getHeight(); |
Mady Mellor | 9be3bed | 2019-08-21 17:26:26 -0700 | [diff] [blame] | 373 | final int keyboardTop = mDisplaySize.y - Math.max(insets.getSystemWindowInsetBottom(), |
| 374 | insets.getDisplayCutout() != null |
| 375 | ? insets.getDisplayCutout().getSafeInsetBottom() |
| 376 | : 0); |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 377 | final int insetsBottom = Math.max(activityViewBottom - keyboardTop, 0); |
Jorim Jaggi | 924ef75 | 2020-01-29 17:26:55 +0100 | [diff] [blame] | 378 | |
Jorim Jaggi | 924ef75 | 2020-01-29 17:26:55 +0100 | [diff] [blame] | 379 | if (sNewInsetsMode == NEW_INSETS_MODE_FULL) { |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 380 | setImeWindowToDisplay(getWidth(), insetsBottom); |
Jorim Jaggi | 924ef75 | 2020-01-29 17:26:55 +0100 | [diff] [blame] | 381 | } else { |
| 382 | mActivityView.setForwardedInsets(Insets.of(0, 0, 0, insetsBottom)); |
| 383 | } |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 387 | private void setImeWindowToDisplay(int w, int h) { |
| 388 | if (getVirtualDisplayId() == INVALID_DISPLAY) { |
| 389 | return; |
| 390 | } |
| 391 | if (h == 0 || w == 0) { |
| 392 | if (mImeShowing) { |
| 393 | mVirtualImeView.setVisibility(GONE); |
| 394 | mImeShowing = false; |
| 395 | } |
| 396 | return; |
| 397 | } |
| 398 | final Context virtualDisplayContext = mContext.createDisplayContext( |
| 399 | getVirtualDisplay().getDisplay()); |
| 400 | |
| 401 | if (mVirtualDisplayWindowManager == null) { |
| 402 | mVirtualDisplayWindowManager = |
| 403 | (WindowManager) virtualDisplayContext.getSystemService(Context.WINDOW_SERVICE); |
| 404 | } |
| 405 | if (mVirtualImeView == null) { |
| 406 | mVirtualImeView = new View(virtualDisplayContext); |
| 407 | mVirtualImeView.setVisibility(VISIBLE); |
| 408 | mVirtualDisplayWindowManager.addView(mVirtualImeView, |
| 409 | getVirtualImeViewAttrs(w, h)); |
| 410 | } else { |
| 411 | mVirtualDisplayWindowManager.updateViewLayout(mVirtualImeView, |
| 412 | getVirtualImeViewAttrs(w, h)); |
| 413 | mVirtualImeView.setVisibility(VISIBLE); |
| 414 | } |
| 415 | |
| 416 | mImeShowing = true; |
| 417 | } |
| 418 | |
| 419 | private WindowManager.LayoutParams getVirtualImeViewAttrs(int w, int h) { |
| 420 | // To use TYPE_NAVIGATION_BAR_PANEL instead of TYPE_IME_BAR to bypass the IME window type |
| 421 | // token check when adding the window. |
| 422 | final WindowManager.LayoutParams attrs = |
| 423 | new WindowManager.LayoutParams(w, h, TYPE_NAVIGATION_BAR_PANEL, |
| 424 | FLAG_LAYOUT_NO_LIMITS | FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCHABLE, |
| 425 | TRANSPARENT); |
| 426 | attrs.gravity = Gravity.BOTTOM; |
| 427 | attrs.setTitle(WINDOW_TITLE); |
| 428 | attrs.token = new Binder(); |
| 429 | attrs.providesInsetsTypes = new int[]{ITYPE_IME}; |
| 430 | attrs.alpha = 0.0f; |
| 431 | return attrs; |
| 432 | } |
| 433 | |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 434 | void setStackView(BubbleStackView stackView) { |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 435 | mStackView = stackView; |
Mady Mellor | 6d00203 | 2019-02-13 13:45:17 -0800 | [diff] [blame] | 436 | } |
| 437 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 438 | public void setOverflow(boolean overflow) { |
| 439 | mIsOverflow = overflow; |
| 440 | |
| 441 | Intent target = new Intent(mContext, BubbleOverflowActivity.class); |
| 442 | mPendingIntent = PendingIntent.getActivity(mContext, /* requestCode */ 0, |
| 443 | target, PendingIntent.FLAG_UPDATE_CURRENT); |
| 444 | mSettingsIcon.setVisibility(GONE); |
| 445 | } |
| 446 | |
Mady Mellor | 6d00203 | 2019-02-13 13:45:17 -0800 | [diff] [blame] | 447 | /** |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 448 | * Sets the bubble used to populate this view. |
Mady Mellor | 6d00203 | 2019-02-13 13:45:17 -0800 | [diff] [blame] | 449 | */ |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 450 | void update(Bubble bubble) { |
| 451 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 452 | Log.d(TAG, "update: bubble=" + (bubble != null ? bubble.getKey() : "null")); |
| 453 | } |
| 454 | boolean isNew = mBubble == null; |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 455 | if (isNew || bubble != null && bubble.getKey().equals(mBubble.getKey())) { |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 456 | mBubble = bubble; |
| 457 | mSettingsIcon.setContentDescription(getResources().getString( |
| 458 | R.string.bubbles_settings_button_description, bubble.getAppName())); |
| 459 | |
Lyn Han | 670fa80 | 2020-05-05 12:56:33 -0700 | [diff] [blame] | 460 | mSettingsIcon.setAccessibilityDelegate( |
| 461 | new AccessibilityDelegate() { |
| 462 | @Override |
| 463 | public void onInitializeAccessibilityNodeInfo(View host, |
| 464 | AccessibilityNodeInfo info) { |
| 465 | super.onInitializeAccessibilityNodeInfo(host, info); |
| 466 | // On focus, have TalkBack say |
| 467 | // "Actions available. Use swipe up then right to view." |
| 468 | // in addition to the default "double tap to activate". |
| 469 | mStackView.setupLocalMenu(info); |
| 470 | } |
| 471 | }); |
| 472 | |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 473 | if (isNew) { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 474 | mPendingIntent = mBubble.getBubbleIntent(); |
| 475 | if (mPendingIntent != null || mBubble.getShortcutInfo() != null) { |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 476 | setContentVisibility(false); |
| 477 | mActivityView.setVisibility(VISIBLE); |
| 478 | } |
| 479 | } |
| 480 | applyThemeAttrs(); |
| 481 | } else { |
| 482 | Log.w(TAG, "Trying to update entry with different key, new bubble: " |
| 483 | + bubble.getKey() + " old bubble: " + bubble.getKey()); |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | /** |
| 488 | * Lets activity view know it should be shown / populated with activity content. |
| 489 | */ |
| 490 | void populateExpandedView() { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 491 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 492 | Log.d(TAG, "populateExpandedView: " |
| 493 | + "bubble=" + getBubbleKey()); |
| 494 | } |
| 495 | |
Mady Mellor | 5029fa6 | 2019-03-05 12:16:21 -0800 | [diff] [blame] | 496 | if (usingActivityView()) { |
| 497 | mActivityView.setCallback(mStateCallback); |
| 498 | } else { |
Issei Suzuki | a91f396 | 2019-06-07 11:48:23 +0200 | [diff] [blame] | 499 | Log.e(TAG, "Cannot populate expanded view."); |
Mady Mellor | 5029fa6 | 2019-03-05 12:16:21 -0800 | [diff] [blame] | 500 | } |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 501 | } |
| 502 | |
Mark Renouf | 041d726 | 2019-02-06 12:09:41 -0500 | [diff] [blame] | 503 | boolean performBackPressIfNeeded() { |
Mady Mellor | 323fb0b | 2019-03-25 12:15:22 -0700 | [diff] [blame] | 504 | if (!usingActivityView()) { |
Mark Renouf | 041d726 | 2019-02-06 12:09:41 -0500 | [diff] [blame] | 505 | return false; |
| 506 | } |
| 507 | mActivityView.performBackPress(); |
| 508 | return true; |
| 509 | } |
| 510 | |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 511 | void updateHeight() { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 512 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 513 | Log.d(TAG, "updateHeight: bubble=" + getBubbleKey()); |
| 514 | } |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 515 | if (usingActivityView()) { |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 516 | float desiredHeight = mOverflowHeight; |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 517 | if (!mIsOverflow) { |
| 518 | desiredHeight = Math.max(mBubble.getDesiredHeight(mContext), mMinHeight); |
| 519 | } |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 520 | float height = Math.min(desiredHeight, getMaxExpandedHeight()); |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 521 | height = Math.max(height, mIsOverflow? mOverflowHeight : mMinHeight); |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 522 | LayoutParams lp = (LayoutParams) mActivityView.getLayoutParams(); |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 523 | mNeedsNewHeight = lp.height != height; |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 524 | if (!mKeyboardVisible) { |
| 525 | // If the keyboard is visible... don't adjust the height because that will cause |
| 526 | // a configuration change and the keyboard will be lost. |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame] | 527 | lp.height = (int) height; |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 528 | mActivityView.setLayoutParams(lp); |
| 529 | mNeedsNewHeight = false; |
| 530 | } |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 531 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 532 | Log.d(TAG, "updateHeight: bubble=" + getBubbleKey() + " height=" + height |
| 533 | + " mNeedsNewHeight=" + mNeedsNewHeight); |
| 534 | } |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 535 | } |
| 536 | } |
| 537 | |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 538 | private int getMaxExpandedHeight() { |
Mady Mellor | 9be3bed | 2019-08-21 17:26:26 -0700 | [diff] [blame] | 539 | mWindowManager.getDefaultDisplay().getRealSize(mDisplaySize); |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 540 | int[] windowLocation = mActivityView.getLocationOnScreen(); |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 541 | int bottomInset = getRootWindowInsets() != null |
| 542 | ? getRootWindowInsets().getStableInsetBottom() |
| 543 | : 0; |
Lyn Han | 0b955ed | 2020-01-31 09:47:35 -0800 | [diff] [blame] | 544 | return mDisplaySize.y - windowLocation[1] - mSettingsIconHeight - mPointerHeight |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 545 | - mPointerMargin - bottomInset; |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 546 | } |
| 547 | |
Mady Mellor | 47b11e3 | 2019-07-11 19:06:21 -0700 | [diff] [blame] | 548 | /** |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 549 | * Update appearance of the expanded view being displayed. |
| 550 | */ |
| 551 | public void updateView() { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 552 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 553 | Log.d(TAG, "updateView: bubble=" |
| 554 | + getBubbleKey()); |
| 555 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 556 | if (usingActivityView() |
| 557 | && mActivityView.getVisibility() == VISIBLE |
| 558 | && mActivityView.isAttachedToWindow()) { |
| 559 | mActivityView.onLocationChanged(); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 560 | } |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 561 | updateHeight(); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | /** |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 565 | * Set the x position that the tip of the triangle should point to. |
| 566 | */ |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 567 | public void setPointerPosition(float x) { |
Lyn Han | 9a2f5cf | 2019-05-23 11:01:41 -0700 | [diff] [blame] | 568 | float halfPointerWidth = mPointerWidth / 2f; |
| 569 | float pointerLeft = x - halfPointerWidth; |
| 570 | mPointerView.setTranslationX(pointerLeft); |
Lyn Han | f74ba67 | 2019-05-20 16:08:48 -0700 | [diff] [blame] | 571 | mPointerView.setVisibility(VISIBLE); |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | /** |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 575 | * Position of the manage button displayed in the expanded view. Used for placing user |
| 576 | * education about the manage button. |
| 577 | */ |
Joshua Tsuji | 6855cab | 2020-04-16 01:05:39 -0400 | [diff] [blame] | 578 | public void getManageButtonBoundsOnScreen(Rect rect) { |
| 579 | mSettingsIcon.getBoundsOnScreen(rect); |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | /** |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 583 | * 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] | 584 | */ |
Mady Mellor | 94d94a7 | 2019-03-05 18:16:59 -0800 | [diff] [blame] | 585 | public void cleanUpExpandedState() { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 586 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 587 | Log.d(TAG, "cleanUpExpandedState: mActivityViewStatus=" + mActivityViewStatus |
| 588 | + ", bubble=" + getBubbleKey()); |
| 589 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 590 | if (mActivityView == null) { |
Mark Renouf | 89b1a4a | 2018-12-04 14:59:45 -0500 | [diff] [blame] | 591 | return; |
| 592 | } |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 593 | switch (mActivityViewStatus) { |
| 594 | case INITIALIZED: |
| 595 | case ACTIVITY_STARTED: |
| 596 | mActivityView.release(); |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 597 | } |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 598 | if (mTaskId != -1) { |
| 599 | try { |
| 600 | ActivityTaskManager.getService().removeTask(mTaskId); |
| 601 | } catch (RemoteException e) { |
| 602 | Log.w(TAG, "Failed to remove taskId " + mTaskId); |
| 603 | } |
| 604 | mTaskId = -1; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 605 | } |
Mark Renouf | 28c250d | 2019-02-25 16:47:34 -0500 | [diff] [blame] | 606 | removeView(mActivityView); |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 607 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 608 | mActivityView = null; |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | /** |
| 612 | * Called when the last task is removed from a {@link android.hardware.display.VirtualDisplay} |
| 613 | * which {@link ActivityView} uses. |
| 614 | */ |
| 615 | void notifyDisplayEmpty() { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 616 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 617 | Log.d(TAG, "notifyDisplayEmpty: bubble=" |
| 618 | + getBubbleKey() |
| 619 | + " mActivityViewStatus=" + mActivityViewStatus); |
| 620 | } |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 621 | if (mActivityViewStatus == ActivityViewStatus.ACTIVITY_STARTED) { |
| 622 | mActivityViewStatus = ActivityViewStatus.INITIALIZED; |
| 623 | } |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 624 | } |
| 625 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 626 | private boolean usingActivityView() { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 627 | return (mPendingIntent != null || mBubble.getShortcutInfo() != null) |
Mady Mellor | 2ac2d3a | 2020-01-08 17:18:54 -0800 | [diff] [blame] | 628 | && mActivityView != null; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 629 | } |
| 630 | |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 631 | /** |
| 632 | * @return the display id of the virtual display. |
| 633 | */ |
| 634 | public int getVirtualDisplayId() { |
| 635 | if (usingActivityView()) { |
| 636 | return mActivityView.getVirtualDisplayId(); |
| 637 | } |
| 638 | return INVALID_DISPLAY; |
| 639 | } |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 640 | |
| 641 | private VirtualDisplay getVirtualDisplay() { |
| 642 | if (usingActivityView()) { |
| 643 | return mActivityView.getVirtualDisplay(); |
| 644 | } |
| 645 | return null; |
| 646 | } |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 647 | } |