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; |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 22 | import static android.view.Display.INVALID_DISPLAY; |
Jorim Jaggi | 924ef75 | 2020-01-29 17:26:55 +0100 | [diff] [blame] | 23 | import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL; |
| 24 | import static android.view.ViewRootImpl.sNewInsetsMode; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 25 | |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 26 | import static com.android.systemui.bubbles.BubbleDebugConfig.DEBUG_BUBBLE_EXPANDED_VIEW; |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 27 | import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_BUBBLES; |
| 28 | import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_WITH_CLASS_NAME; |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 29 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 30 | import android.annotation.Nullable; |
Mady Mellor | 60101c9 | 2019-04-11 19:04:00 -0700 | [diff] [blame] | 31 | import android.app.ActivityOptions; |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 32 | import android.app.ActivityTaskManager; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 33 | import android.app.ActivityView; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 34 | import android.app.PendingIntent; |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 35 | import android.content.ComponentName; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 36 | import android.content.Context; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 37 | import android.content.Intent; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 38 | import android.content.res.Resources; |
Mady Mellor | dd49705 | 2019-01-30 17:23:48 -0800 | [diff] [blame] | 39 | import android.content.res.TypedArray; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 40 | import android.graphics.Color; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 41 | import android.graphics.Insets; |
| 42 | import android.graphics.Point; |
Mady Mellor | 47b11e3 | 2019-07-11 19:06:21 -0700 | [diff] [blame] | 43 | import android.graphics.Rect; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 44 | import android.graphics.drawable.ShapeDrawable; |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 45 | import android.os.RemoteException; |
Steven Wu | b00225b | 2019-02-08 14:27:42 -0500 | [diff] [blame] | 46 | import android.service.notification.StatusBarNotification; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 47 | import android.util.AttributeSet; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 48 | import android.util.Log; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 49 | import android.view.View; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 50 | import android.view.WindowInsets; |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 51 | import android.view.WindowManager; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 52 | import android.widget.LinearLayout; |
| 53 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 54 | import com.android.internal.policy.ScreenDecorationsUtils; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 55 | import com.android.systemui.Dependency; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 56 | import com.android.systemui.R; |
| 57 | import com.android.systemui.recents.TriangleShape; |
Muhammad Qureshi | 9bced7d | 2020-01-16 15:22:12 -0800 | [diff] [blame] | 58 | import com.android.systemui.shared.system.SysUiStatsLog; |
Lyn Han | 754e77b | 2019-04-30 14:34:49 -0700 | [diff] [blame] | 59 | import com.android.systemui.statusbar.AlphaOptimizedButton; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 60 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 61 | |
| 62 | /** |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 63 | * 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] | 64 | */ |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 65 | public class BubbleExpandedView extends LinearLayout implements View.OnClickListener { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 66 | private static final String TAG = TAG_WITH_CLASS_NAME ? "BubbleExpandedView" : TAG_BUBBLES; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 67 | |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 68 | private enum ActivityViewStatus { |
| 69 | // ActivityView is being initialized, cannot start an activity yet. |
| 70 | INITIALIZING, |
| 71 | // ActivityView is initialized, and ready to start an activity. |
| 72 | INITIALIZED, |
| 73 | // Activity runs in the ActivityView. |
| 74 | ACTIVITY_STARTED, |
| 75 | // ActivityView is released, so activity launching will no longer be permitted. |
| 76 | RELEASED, |
| 77 | } |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 78 | |
| 79 | // The triangle pointing to the expanded view |
| 80 | private View mPointerView; |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 81 | private int mPointerMargin; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 82 | |
Lyn Han | 754e77b | 2019-04-30 14:34:49 -0700 | [diff] [blame] | 83 | private AlphaOptimizedButton mSettingsIcon; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 84 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 85 | // Views for expanded state |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 86 | private ActivityView mActivityView; |
| 87 | |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 88 | private ActivityViewStatus mActivityViewStatus = ActivityViewStatus.INITIALIZING; |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 89 | private int mTaskId = -1; |
| 90 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 91 | private PendingIntent mPendingIntent; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 92 | |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 93 | private boolean mKeyboardVisible; |
| 94 | private boolean mNeedsNewHeight; |
| 95 | |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 96 | private Point mDisplaySize; |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 97 | private int mMinHeight; |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 98 | private int mOverflowHeight; |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 99 | private int mSettingsIconHeight; |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 100 | private int mPointerWidth; |
| 101 | private int mPointerHeight; |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 102 | private ShapeDrawable mPointerDrawable; |
Mady Mellor | 47b11e3 | 2019-07-11 19:06:21 -0700 | [diff] [blame] | 103 | private Rect mTempRect = new Rect(); |
| 104 | private int[] mTempLoc = new int[2]; |
| 105 | private int mExpandedViewTouchSlop; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 106 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 107 | @Nullable private Bubble mBubble; |
| 108 | |
| 109 | private boolean mIsOverflow; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 110 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 111 | private BubbleController mBubbleController = Dependency.get(BubbleController.class); |
Mady Mellor | 9be3bed | 2019-08-21 17:26:26 -0700 | [diff] [blame] | 112 | private WindowManager mWindowManager; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 113 | |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 114 | private BubbleStackView mStackView; |
| 115 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 116 | private ActivityView.StateCallback mStateCallback = new ActivityView.StateCallback() { |
| 117 | @Override |
| 118 | public void onActivityViewReady(ActivityView view) { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 119 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 120 | Log.d(TAG, "onActivityViewReady: mActivityViewStatus=" + mActivityViewStatus |
| 121 | + " bubble=" + getBubbleKey()); |
| 122 | } |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 123 | switch (mActivityViewStatus) { |
| 124 | case INITIALIZING: |
| 125 | case INITIALIZED: |
| 126 | // Custom options so there is no activity transition animation |
| 127 | ActivityOptions options = ActivityOptions.makeCustomAnimation(getContext(), |
| 128 | 0 /* enterResId */, 0 /* exitResId */); |
Winson Chung | 0620052 | 2020-03-31 22:47:02 -0700 | [diff] [blame] | 129 | options.setTaskAlwaysOnTop(true); |
Yuncheol Heo | 5d62e75 | 2020-04-08 14:54:24 -0700 | [diff] [blame] | 130 | options.setLaunchWindowingMode(WINDOWING_MODE_MULTI_WINDOW); |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 131 | // Post to keep the lifecycle normal |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 132 | post(() -> { |
| 133 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 134 | Log.d(TAG, "onActivityViewReady: calling startActivity, " |
| 135 | + "bubble=" + getBubbleKey()); |
| 136 | } |
Mady Mellor | 8454ddf | 2019-08-15 11:16:23 -0700 | [diff] [blame] | 137 | try { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 138 | if (!mIsOverflow && mBubble.usingShortcutInfo()) { |
Mady Mellor | b547e5e | 2019-12-02 10:15:56 -0800 | [diff] [blame] | 139 | mActivityView.startShortcutActivity(mBubble.getShortcutInfo(), |
| 140 | options, null /* sourceBounds */); |
| 141 | } else { |
| 142 | Intent fillInIntent = new Intent(); |
| 143 | // Apply flags to make behaviour match documentLaunchMode=always. |
| 144 | fillInIntent.addFlags(FLAG_ACTIVITY_NEW_DOCUMENT); |
| 145 | fillInIntent.addFlags(FLAG_ACTIVITY_MULTIPLE_TASK); |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 146 | mActivityView.startActivity(mPendingIntent, fillInIntent, options); |
Mady Mellor | b547e5e | 2019-12-02 10:15:56 -0800 | [diff] [blame] | 147 | } |
Mady Mellor | 8454ddf | 2019-08-15 11:16:23 -0700 | [diff] [blame] | 148 | } catch (RuntimeException e) { |
| 149 | // If there's a runtime exception here then there's something |
| 150 | // wrong with the intent, we can't really recover / try to populate |
| 151 | // the bubble again so we'll just remove it. |
| 152 | Log.w(TAG, "Exception while displaying bubble: " + getBubbleKey() |
| 153 | + ", " + e.getMessage() + "; removing bubble"); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 154 | mBubbleController.removeBubble(getBubbleEntry(), |
Mady Mellor | 8454ddf | 2019-08-15 11:16:23 -0700 | [diff] [blame] | 155 | BubbleController.DISMISS_INVALID_INTENT); |
| 156 | } |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 157 | }); |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 158 | mActivityViewStatus = ActivityViewStatus.ACTIVITY_STARTED; |
Mady Mellor | 6d00203 | 2019-02-13 13:45:17 -0800 | [diff] [blame] | 159 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public void onActivityViewDestroyed(ActivityView view) { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 164 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 165 | Log.d(TAG, "onActivityViewDestroyed: mActivityViewStatus=" + mActivityViewStatus |
| 166 | + " bubble=" + getBubbleKey()); |
| 167 | } |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 168 | mActivityViewStatus = ActivityViewStatus.RELEASED; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 169 | } |
| 170 | |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 171 | @Override |
| 172 | public void onTaskCreated(int taskId, ComponentName componentName) { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 173 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 174 | Log.d(TAG, "onTaskCreated: taskId=" + taskId |
| 175 | + " bubble=" + getBubbleKey()); |
| 176 | } |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 177 | // Since Bubble ActivityView applies singleTaskDisplay this is |
| 178 | // guaranteed to only be called once per ActivityView. The taskId is |
| 179 | // saved to use for removeTask, preventing appearance in recent tasks. |
| 180 | mTaskId = taskId; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | /** |
| 184 | * This is only called for tasks on this ActivityView, which is also set to |
| 185 | * single-task mode -- meaning never more than one task on this display. If a task |
| 186 | * is being removed, it's the top Activity finishing and this bubble should |
| 187 | * be removed or collapsed. |
| 188 | */ |
| 189 | @Override |
| 190 | public void onTaskRemovalStarted(int taskId) { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 191 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 192 | Log.d(TAG, "onTaskRemovalStarted: taskId=" + taskId |
| 193 | + " mActivityViewStatus=" + mActivityViewStatus |
| 194 | + " bubble=" + getBubbleKey()); |
| 195 | } |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 196 | if (mBubble != null && !mBubbleController.isUserCreatedBubble(mBubble.getKey())) { |
| 197 | // Must post because this is called from a binder thread. |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 198 | post(() -> mBubbleController.removeBubble(mBubble.getEntry(), |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 199 | BubbleController.DISMISS_TASK_FINISHED)); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | }; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 203 | |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 204 | public BubbleExpandedView(Context context) { |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 205 | this(context, null); |
| 206 | } |
| 207 | |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 208 | public BubbleExpandedView(Context context, AttributeSet attrs) { |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 209 | this(context, attrs, 0); |
| 210 | } |
| 211 | |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 212 | public BubbleExpandedView(Context context, AttributeSet attrs, int defStyleAttr) { |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 213 | this(context, attrs, defStyleAttr, 0); |
| 214 | } |
| 215 | |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 216 | public BubbleExpandedView(Context context, AttributeSet attrs, int defStyleAttr, |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 217 | int defStyleRes) { |
| 218 | super(context, attrs, defStyleAttr, defStyleRes); |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 219 | mDisplaySize = new Point(); |
Mady Mellor | 9be3bed | 2019-08-21 17:26:26 -0700 | [diff] [blame] | 220 | mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 221 | // Get the real size -- this includes screen decorations (notches, statusbar, navbar). |
Mady Mellor | 9be3bed | 2019-08-21 17:26:26 -0700 | [diff] [blame] | 222 | mWindowManager.getDefaultDisplay().getRealSize(mDisplaySize); |
Mady Mellor | 47b11e3 | 2019-07-11 19:06:21 -0700 | [diff] [blame] | 223 | Resources res = getResources(); |
| 224 | mMinHeight = res.getDimensionPixelSize(R.dimen.bubble_expanded_default_height); |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 225 | mOverflowHeight = res.getDimensionPixelSize(R.dimen.bubble_overflow_height); |
Mady Mellor | 47b11e3 | 2019-07-11 19:06:21 -0700 | [diff] [blame] | 226 | mPointerMargin = res.getDimensionPixelSize(R.dimen.bubble_pointer_margin); |
| 227 | mExpandedViewTouchSlop = res.getDimensionPixelSize(R.dimen.bubble_expanded_view_slop); |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | @Override |
| 231 | protected void onFinishInflate() { |
| 232 | super.onFinishInflate(); |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 233 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 234 | Log.d(TAG, "onFinishInflate: bubble=" + getBubbleKey()); |
| 235 | } |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 236 | |
| 237 | Resources res = getResources(); |
| 238 | mPointerView = findViewById(R.id.pointer_view); |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 239 | mPointerWidth = res.getDimensionPixelSize(R.dimen.bubble_pointer_width); |
| 240 | mPointerHeight = res.getDimensionPixelSize(R.dimen.bubble_pointer_height); |
Mady Mellor | dd49705 | 2019-01-30 17:23:48 -0800 | [diff] [blame] | 241 | |
Mady Mellor | dd49705 | 2019-01-30 17:23:48 -0800 | [diff] [blame] | 242 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 243 | mPointerDrawable = new ShapeDrawable(TriangleShape.create( |
Lyn Han | 5aa27e2 | 2019-05-15 10:55:07 -0700 | [diff] [blame] | 244 | mPointerWidth, mPointerHeight, true /* pointUp */)); |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 245 | mPointerView.setBackground(mPointerDrawable); |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 246 | mPointerView.setVisibility(INVISIBLE); |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 247 | |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 248 | mSettingsIconHeight = getContext().getResources().getDimensionPixelSize( |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 249 | R.dimen.bubble_manage_button_height); |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 250 | mSettingsIcon = findViewById(R.id.settings_button); |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 251 | mSettingsIcon.setOnClickListener(this); |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 252 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 253 | mActivityView = new ActivityView(mContext, null /* attrs */, 0 /* defStyle */, |
| 254 | true /* singleTaskInstance */); |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 255 | |
lumark | dc9b319 | 2019-07-23 21:18:17 +0800 | [diff] [blame] | 256 | // 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] | 257 | setContentVisibility(false); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 258 | addView(mActivityView); |
| 259 | |
Lyn Han | 5aa27e2 | 2019-05-15 10:55:07 -0700 | [diff] [blame] | 260 | // Expanded stack layout, top to bottom: |
| 261 | // Expanded view container |
| 262 | // ==> bubble row |
| 263 | // ==> expanded view |
| 264 | // ==> activity view |
| 265 | // ==> manage button |
| 266 | bringChildToFront(mActivityView); |
| 267 | bringChildToFront(mSettingsIcon); |
Mady Mellor | 52b1ac6 | 2019-04-10 16:59:03 -0700 | [diff] [blame] | 268 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 269 | applyThemeAttrs(); |
| 270 | |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 271 | setOnApplyWindowInsetsListener((View view, WindowInsets insets) -> { |
| 272 | // Keep track of IME displaying because we should not make any adjustments that might |
| 273 | // 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] | 274 | final int keyboardHeight = insets.getSystemWindowInsetBottom() |
| 275 | - insets.getStableInsetBottom(); |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 276 | mKeyboardVisible = keyboardHeight != 0; |
| 277 | if (!mKeyboardVisible && mNeedsNewHeight) { |
| 278 | updateHeight(); |
| 279 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 280 | return view.onApplyWindowInsets(insets); |
| 281 | }); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 282 | } |
| 283 | |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 284 | private String getBubbleKey() { |
| 285 | return mBubble != null ? mBubble.getKey() : "null"; |
| 286 | } |
| 287 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 288 | private NotificationEntry getBubbleEntry() { |
| 289 | return mBubble != null ? mBubble.getEntry() : null; |
| 290 | } |
| 291 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 292 | void applyThemeAttrs() { |
Lyn Han | 61bfdb3 | 2019-12-10 14:34:12 -0800 | [diff] [blame] | 293 | final TypedArray ta = mContext.obtainStyledAttributes( |
| 294 | new int[] { |
| 295 | android.R.attr.colorBackgroundFloating, |
| 296 | android.R.attr.dialogCornerRadius}); |
| 297 | int bgColor = ta.getColor(0, Color.WHITE); |
| 298 | float cornerRadius = ta.getDimensionPixelSize(1, 0); |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 299 | ta.recycle(); |
| 300 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 301 | mPointerDrawable.setTint(bgColor); |
Lyn Han | edb55e2 | 2020-02-12 18:55:39 -0800 | [diff] [blame] | 302 | if (mActivityView != null && ScreenDecorationsUtils.supportsRoundedCornersOnWindows( |
| 303 | mContext.getResources())) { |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 304 | mActivityView.setCornerRadius(cornerRadius); |
| 305 | } |
| 306 | } |
| 307 | |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 308 | @Override |
| 309 | protected void onDetachedFromWindow() { |
| 310 | super.onDetachedFromWindow(); |
| 311 | mKeyboardVisible = false; |
| 312 | mNeedsNewHeight = false; |
| 313 | if (mActivityView != null) { |
Mady Mellor | af02fa4 | 2020-03-04 14:22:16 -0800 | [diff] [blame] | 314 | // TODO: Temporary hack to offset the view until we can properly inset Bubbles again. |
| 315 | if (sNewInsetsMode == NEW_INSETS_MODE_FULL) { |
| 316 | mStackView.animate() |
| 317 | .setDuration(100) |
| 318 | .translationY(0); |
| 319 | } else { |
| 320 | mActivityView.setForwardedInsets(Insets.of(0, 0, 0, 0)); |
| 321 | } |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 322 | } |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 323 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 324 | Log.d(TAG, "onDetachedFromWindow: bubble=" + getBubbleKey()); |
| 325 | } |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | /** |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 329 | * Set visibility of contents in the expanded state. |
| 330 | * |
| 331 | * @param visibility {@code true} if the contents should be visible on the screen. |
| 332 | * |
| 333 | * Note that this contents visibility doesn't affect visibility at {@link android.view.View}, |
| 334 | * and setting {@code false} actually means rendering the contents in transparent. |
| 335 | */ |
| 336 | void setContentVisibility(boolean visibility) { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 337 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 338 | Log.d(TAG, "setContentVisibility: visibility=" + visibility |
| 339 | + " bubble=" + getBubbleKey()); |
| 340 | } |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 341 | final float alpha = visibility ? 1f : 0f; |
| 342 | mPointerView.setAlpha(alpha); |
| 343 | if (mActivityView != null) { |
| 344 | mActivityView.setAlpha(alpha); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | /** |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 349 | * Called by {@link BubbleStackView} when the insets for the expanded state should be updated. |
| 350 | * This should be done post-move and post-animation. |
| 351 | */ |
| 352 | void updateInsets(WindowInsets insets) { |
| 353 | if (usingActivityView()) { |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 354 | int[] screenLoc = mActivityView.getLocationOnScreen(); |
| 355 | final int activityViewBottom = screenLoc[1] + mActivityView.getHeight(); |
Mady Mellor | 9be3bed | 2019-08-21 17:26:26 -0700 | [diff] [blame] | 356 | final int keyboardTop = mDisplaySize.y - Math.max(insets.getSystemWindowInsetBottom(), |
| 357 | insets.getDisplayCutout() != null |
| 358 | ? insets.getDisplayCutout().getSafeInsetBottom() |
| 359 | : 0); |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 360 | final int insetsBottom = Math.max(activityViewBottom - keyboardTop, 0); |
Jorim Jaggi | 924ef75 | 2020-01-29 17:26:55 +0100 | [diff] [blame] | 361 | |
| 362 | // TODO: Temporary hack to offset the view until we can properly inset Bubbles again. |
| 363 | if (sNewInsetsMode == NEW_INSETS_MODE_FULL) { |
Mady Mellor | af02fa4 | 2020-03-04 14:22:16 -0800 | [diff] [blame] | 364 | mStackView.animate() |
| 365 | .setDuration(100) |
| 366 | .translationY(-insetsBottom) |
| 367 | .withEndAction(() -> mActivityView.onLocationChanged()); |
Jorim Jaggi | 924ef75 | 2020-01-29 17:26:55 +0100 | [diff] [blame] | 368 | } else { |
| 369 | mActivityView.setForwardedInsets(Insets.of(0, 0, 0, insetsBottom)); |
| 370 | } |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 374 | void setStackView(BubbleStackView stackView) { |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 375 | mStackView = stackView; |
Mady Mellor | 6d00203 | 2019-02-13 13:45:17 -0800 | [diff] [blame] | 376 | } |
| 377 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 378 | public void setOverflow(boolean overflow) { |
| 379 | mIsOverflow = overflow; |
| 380 | |
| 381 | Intent target = new Intent(mContext, BubbleOverflowActivity.class); |
| 382 | mPendingIntent = PendingIntent.getActivity(mContext, /* requestCode */ 0, |
| 383 | target, PendingIntent.FLAG_UPDATE_CURRENT); |
| 384 | mSettingsIcon.setVisibility(GONE); |
| 385 | } |
| 386 | |
Mady Mellor | 6d00203 | 2019-02-13 13:45:17 -0800 | [diff] [blame] | 387 | /** |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 388 | * Sets the bubble used to populate this view. |
Mady Mellor | 6d00203 | 2019-02-13 13:45:17 -0800 | [diff] [blame] | 389 | */ |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 390 | void update(Bubble bubble) { |
| 391 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 392 | Log.d(TAG, "update: bubble=" + (bubble != null ? bubble.getKey() : "null")); |
| 393 | } |
| 394 | boolean isNew = mBubble == null; |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 395 | if (isNew || bubble != null && bubble.getKey().equals(mBubble.getKey())) { |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 396 | mBubble = bubble; |
| 397 | mSettingsIcon.setContentDescription(getResources().getString( |
| 398 | R.string.bubbles_settings_button_description, bubble.getAppName())); |
| 399 | |
| 400 | if (isNew) { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 401 | mPendingIntent = mBubble.getBubbleIntent(); |
| 402 | if (mPendingIntent != null || mBubble.getShortcutInfo() != null) { |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 403 | setContentVisibility(false); |
| 404 | mActivityView.setVisibility(VISIBLE); |
| 405 | } |
| 406 | } |
| 407 | applyThemeAttrs(); |
| 408 | } else { |
| 409 | Log.w(TAG, "Trying to update entry with different key, new bubble: " |
| 410 | + bubble.getKey() + " old bubble: " + bubble.getKey()); |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * Lets activity view know it should be shown / populated with activity content. |
| 416 | */ |
| 417 | void populateExpandedView() { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 418 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 419 | Log.d(TAG, "populateExpandedView: " |
| 420 | + "bubble=" + getBubbleKey()); |
| 421 | } |
| 422 | |
Mady Mellor | 5029fa6 | 2019-03-05 12:16:21 -0800 | [diff] [blame] | 423 | if (usingActivityView()) { |
| 424 | mActivityView.setCallback(mStateCallback); |
| 425 | } else { |
Issei Suzuki | a91f396 | 2019-06-07 11:48:23 +0200 | [diff] [blame] | 426 | Log.e(TAG, "Cannot populate expanded view."); |
Mady Mellor | 5029fa6 | 2019-03-05 12:16:21 -0800 | [diff] [blame] | 427 | } |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 428 | } |
| 429 | |
Mark Renouf | 041d726 | 2019-02-06 12:09:41 -0500 | [diff] [blame] | 430 | boolean performBackPressIfNeeded() { |
Mady Mellor | 323fb0b | 2019-03-25 12:15:22 -0700 | [diff] [blame] | 431 | if (!usingActivityView()) { |
Mark Renouf | 041d726 | 2019-02-06 12:09:41 -0500 | [diff] [blame] | 432 | return false; |
| 433 | } |
| 434 | mActivityView.performBackPress(); |
| 435 | return true; |
| 436 | } |
| 437 | |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 438 | void updateHeight() { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 439 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 440 | Log.d(TAG, "updateHeight: bubble=" + getBubbleKey()); |
| 441 | } |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 442 | if (usingActivityView()) { |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 443 | float desiredHeight = mOverflowHeight; |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 444 | if (!mIsOverflow) { |
| 445 | desiredHeight = Math.max(mBubble.getDesiredHeight(mContext), mMinHeight); |
| 446 | } |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 447 | float height = Math.min(desiredHeight, getMaxExpandedHeight()); |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 448 | height = Math.max(height, mIsOverflow? mOverflowHeight : mMinHeight); |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 449 | LayoutParams lp = (LayoutParams) mActivityView.getLayoutParams(); |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 450 | mNeedsNewHeight = lp.height != height; |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 451 | if (!mKeyboardVisible) { |
| 452 | // If the keyboard is visible... don't adjust the height because that will cause |
| 453 | // a configuration change and the keyboard will be lost. |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame] | 454 | lp.height = (int) height; |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 455 | mActivityView.setLayoutParams(lp); |
| 456 | mNeedsNewHeight = false; |
| 457 | } |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 458 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 459 | Log.d(TAG, "updateHeight: bubble=" + getBubbleKey() + " height=" + height |
| 460 | + " mNeedsNewHeight=" + mNeedsNewHeight); |
| 461 | } |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 465 | private int getMaxExpandedHeight() { |
Mady Mellor | 9be3bed | 2019-08-21 17:26:26 -0700 | [diff] [blame] | 466 | mWindowManager.getDefaultDisplay().getRealSize(mDisplaySize); |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 467 | int[] windowLocation = mActivityView.getLocationOnScreen(); |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 468 | int bottomInset = getRootWindowInsets() != null |
| 469 | ? getRootWindowInsets().getStableInsetBottom() |
| 470 | : 0; |
Lyn Han | 0b955ed | 2020-01-31 09:47:35 -0800 | [diff] [blame] | 471 | return mDisplaySize.y - windowLocation[1] - mSettingsIconHeight - mPointerHeight |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 472 | - mPointerMargin - bottomInset; |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Mady Mellor | 47b11e3 | 2019-07-11 19:06:21 -0700 | [diff] [blame] | 475 | /** |
| 476 | * Whether the provided x, y values (in raw coordinates) are in a touchable area of the |
| 477 | * expanded view. |
| 478 | * |
| 479 | * The touchable areas are the ActivityView (plus some slop around it) and the manage button. |
| 480 | */ |
| 481 | boolean intersectingTouchableContent(int rawX, int rawY) { |
| 482 | mTempRect.setEmpty(); |
| 483 | if (mActivityView != null) { |
| 484 | mTempLoc = mActivityView.getLocationOnScreen(); |
| 485 | mTempRect.set(mTempLoc[0] - mExpandedViewTouchSlop, |
| 486 | mTempLoc[1] - mExpandedViewTouchSlop, |
| 487 | mTempLoc[0] + mActivityView.getWidth() + mExpandedViewTouchSlop, |
| 488 | mTempLoc[1] + mActivityView.getHeight() + mExpandedViewTouchSlop); |
| 489 | } |
| 490 | if (mTempRect.contains(rawX, rawY)) { |
| 491 | return true; |
| 492 | } |
| 493 | mTempLoc = mSettingsIcon.getLocationOnScreen(); |
| 494 | mTempRect.set(mTempLoc[0], |
| 495 | mTempLoc[1], |
| 496 | mTempLoc[0] + mSettingsIcon.getWidth(), |
| 497 | mTempLoc[1] + mSettingsIcon.getHeight()); |
| 498 | if (mTempRect.contains(rawX, rawY)) { |
| 499 | return true; |
| 500 | } |
| 501 | return false; |
| 502 | } |
| 503 | |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 504 | @Override |
| 505 | public void onClick(View view) { |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 506 | if (mBubble == null) { |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 507 | return; |
| 508 | } |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 509 | int id = view.getId(); |
Lyn Han | c26ff12 | 2019-03-29 16:46:07 -0700 | [diff] [blame] | 510 | if (id == R.id.settings_button) { |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 511 | Intent intent = mBubble.getSettingsIntent(); |
Steven Wu | b00225b | 2019-02-08 14:27:42 -0500 | [diff] [blame] | 512 | mStackView.collapseStack(() -> { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 513 | mContext.startActivityAsUser(intent, mBubble.getEntry().getSbn().getUser()); |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 514 | logBubbleClickEvent(mBubble, |
Muhammad Qureshi | 9bced7d | 2020-01-16 15:22:12 -0800 | [diff] [blame] | 515 | SysUiStatsLog.BUBBLE_UICHANGED__ACTION__HEADER_GO_TO_SETTINGS); |
Steven Wu | b00225b | 2019-02-08 14:27:42 -0500 | [diff] [blame] | 516 | }); |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 517 | } |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | /** |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 521 | * Update appearance of the expanded view being displayed. |
| 522 | */ |
| 523 | public void updateView() { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 524 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 525 | Log.d(TAG, "updateView: bubble=" |
| 526 | + getBubbleKey()); |
| 527 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 528 | if (usingActivityView() |
| 529 | && mActivityView.getVisibility() == VISIBLE |
| 530 | && mActivityView.isAttachedToWindow()) { |
| 531 | mActivityView.onLocationChanged(); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 532 | } |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 533 | updateHeight(); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | /** |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 537 | * Set the x position that the tip of the triangle should point to. |
| 538 | */ |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 539 | public void setPointerPosition(float x) { |
Lyn Han | 9a2f5cf | 2019-05-23 11:01:41 -0700 | [diff] [blame] | 540 | float halfPointerWidth = mPointerWidth / 2f; |
| 541 | float pointerLeft = x - halfPointerWidth; |
| 542 | mPointerView.setTranslationX(pointerLeft); |
Lyn Han | f74ba67 | 2019-05-20 16:08:48 -0700 | [diff] [blame] | 543 | mPointerView.setVisibility(VISIBLE); |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | /** |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 547 | * Position of the manage button displayed in the expanded view. Used for placing user |
| 548 | * education about the manage button. |
| 549 | */ |
| 550 | public Rect getManageButtonLocationOnScreen() { |
| 551 | mTempLoc = mSettingsIcon.getLocationOnScreen(); |
| 552 | return new Rect(mTempLoc[0], mTempLoc[1], mTempLoc[0] + mSettingsIcon.getWidth(), |
| 553 | mTempLoc[1] + mSettingsIcon.getHeight()); |
| 554 | } |
| 555 | |
| 556 | /** |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 557 | * 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] | 558 | */ |
Mady Mellor | 94d94a7 | 2019-03-05 18:16:59 -0800 | [diff] [blame] | 559 | public void cleanUpExpandedState() { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 560 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 561 | Log.d(TAG, "cleanUpExpandedState: mActivityViewStatus=" + mActivityViewStatus |
| 562 | + ", bubble=" + getBubbleKey()); |
| 563 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 564 | if (mActivityView == null) { |
Mark Renouf | 89b1a4a | 2018-12-04 14:59:45 -0500 | [diff] [blame] | 565 | return; |
| 566 | } |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 567 | switch (mActivityViewStatus) { |
| 568 | case INITIALIZED: |
| 569 | case ACTIVITY_STARTED: |
| 570 | mActivityView.release(); |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 571 | } |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 572 | if (mTaskId != -1) { |
| 573 | try { |
| 574 | ActivityTaskManager.getService().removeTask(mTaskId); |
| 575 | } catch (RemoteException e) { |
| 576 | Log.w(TAG, "Failed to remove taskId " + mTaskId); |
| 577 | } |
| 578 | mTaskId = -1; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 579 | } |
Mark Renouf | 28c250d | 2019-02-25 16:47:34 -0500 | [diff] [blame] | 580 | removeView(mActivityView); |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 581 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 582 | mActivityView = null; |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | /** |
| 586 | * Called when the last task is removed from a {@link android.hardware.display.VirtualDisplay} |
| 587 | * which {@link ActivityView} uses. |
| 588 | */ |
| 589 | void notifyDisplayEmpty() { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 590 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 591 | Log.d(TAG, "notifyDisplayEmpty: bubble=" |
| 592 | + getBubbleKey() |
| 593 | + " mActivityViewStatus=" + mActivityViewStatus); |
| 594 | } |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 595 | if (mActivityViewStatus == ActivityViewStatus.ACTIVITY_STARTED) { |
| 596 | mActivityViewStatus = ActivityViewStatus.INITIALIZED; |
| 597 | } |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 598 | } |
| 599 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 600 | private boolean usingActivityView() { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 601 | return (mPendingIntent != null || mBubble.getShortcutInfo() != null) |
Mady Mellor | 2ac2d3a | 2020-01-08 17:18:54 -0800 | [diff] [blame] | 602 | && mActivityView != null; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 603 | } |
| 604 | |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 605 | /** |
| 606 | * @return the display id of the virtual display. |
| 607 | */ |
| 608 | public int getVirtualDisplayId() { |
| 609 | if (usingActivityView()) { |
| 610 | return mActivityView.getVirtualDisplayId(); |
| 611 | } |
| 612 | return INVALID_DISPLAY; |
| 613 | } |
| 614 | |
Steven Wu | b00225b | 2019-02-08 14:27:42 -0500 | [diff] [blame] | 615 | /** |
| 616 | * Logs bubble UI click event. |
| 617 | * |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 618 | * @param bubble the bubble notification entry that user is interacting with. |
Steven Wu | b00225b | 2019-02-08 14:27:42 -0500 | [diff] [blame] | 619 | * @param action the user interaction enum. |
| 620 | */ |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 621 | private void logBubbleClickEvent(Bubble bubble, int action) { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 622 | StatusBarNotification notification = bubble.getEntry().getSbn(); |
Muhammad Qureshi | 9bced7d | 2020-01-16 15:22:12 -0800 | [diff] [blame] | 623 | SysUiStatsLog.write(SysUiStatsLog.BUBBLE_UI_CHANGED, |
Steven Wu | b00225b | 2019-02-08 14:27:42 -0500 | [diff] [blame] | 624 | notification.getPackageName(), |
| 625 | notification.getNotification().getChannelId(), |
| 626 | notification.getId(), |
| 627 | mStackView.getBubbleIndex(mStackView.getExpandedBubble()), |
| 628 | mStackView.getBubbleCount(), |
| 629 | action, |
| 630 | mStackView.getNormalizedXPosition(), |
Steven Wu | 45e38ae | 2019-03-25 16:16:59 -0400 | [diff] [blame] | 631 | mStackView.getNormalizedYPosition(), |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 632 | bubble.showInShade(), |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 633 | bubble.isOngoing(), |
Mady Mellor | 6cec350 | 2019-06-17 19:20:49 -0700 | [diff] [blame] | 634 | false /* isAppForeground (unused) */); |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame] | 635 | } |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 636 | } |