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