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