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