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