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