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