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