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