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