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 | |
Yuncheol Heo | 5d62e75 | 2020-04-08 14:54:24 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW; |
Mady Mellor | c41ed32 | 2019-09-25 11:19:26 -0700 | [diff] [blame] | 20 | import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK; |
| 21 | import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT; |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 22 | import static android.graphics.PixelFormat.TRANSPARENT; |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 23 | import static android.view.Display.INVALID_DISPLAY; |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 24 | import static android.view.InsetsState.ITYPE_IME; |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 25 | import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; |
Jorim Jaggi | 924ef75 | 2020-01-29 17:26:55 +0100 | [diff] [blame] | 26 | import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL; |
| 27 | import static android.view.ViewRootImpl.sNewInsetsMode; |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
| 29 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 30 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
| 31 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 32 | |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 33 | import static com.android.systemui.bubbles.BubbleDebugConfig.DEBUG_BUBBLE_EXPANDED_VIEW; |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 34 | import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_BUBBLES; |
| 35 | import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_WITH_CLASS_NAME; |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 36 | |
Joshua Tsuji | 847b1d42 | 2020-06-01 13:42:19 -0400 | [diff] [blame] | 37 | import android.annotation.SuppressLint; |
Mady Mellor | 60101c9 | 2019-04-11 19:04:00 -0700 | [diff] [blame] | 38 | import android.app.ActivityOptions; |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 39 | import android.app.ActivityTaskManager; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 40 | import android.app.ActivityView; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 41 | import android.app.PendingIntent; |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 42 | import android.content.ComponentName; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 43 | import android.content.Context; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 44 | import android.content.Intent; |
Lyn Han | 26bb198 | 2020-06-08 15:38:01 -0700 | [diff] [blame] | 45 | import android.content.res.Configuration; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 46 | import android.content.res.Resources; |
Mady Mellor | dd49705 | 2019-01-30 17:23:48 -0800 | [diff] [blame] | 47 | import android.content.res.TypedArray; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 48 | import android.graphics.Color; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 49 | import android.graphics.Insets; |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 50 | import android.graphics.Outline; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 51 | import android.graphics.Point; |
Mady Mellor | 47b11e3 | 2019-07-11 19:06:21 -0700 | [diff] [blame] | 52 | import android.graphics.Rect; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 53 | import android.graphics.drawable.ShapeDrawable; |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 54 | import android.hardware.display.VirtualDisplay; |
| 55 | import android.os.Binder; |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 56 | import android.os.RemoteException; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 57 | import android.util.AttributeSet; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 58 | import android.util.Log; |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 59 | import android.view.Gravity; |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 60 | import android.view.SurfaceControl; |
| 61 | import android.view.SurfaceView; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 62 | import android.view.View; |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 63 | import android.view.ViewGroup; |
| 64 | import android.view.ViewOutlineProvider; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 65 | import android.view.WindowInsets; |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 66 | import android.view.WindowManager; |
Lyn Han | 670fa80 | 2020-05-05 12:56:33 -0700 | [diff] [blame] | 67 | import android.view.accessibility.AccessibilityNodeInfo; |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 68 | import android.widget.FrameLayout; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 69 | import android.widget.LinearLayout; |
| 70 | |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 71 | import androidx.annotation.Nullable; |
| 72 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 73 | import com.android.internal.policy.ScreenDecorationsUtils; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 74 | import com.android.systemui.Dependency; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 75 | import com.android.systemui.R; |
| 76 | import com.android.systemui.recents.TriangleShape; |
Lyn Han | 754e77b | 2019-04-30 14:34:49 -0700 | [diff] [blame] | 77 | import com.android.systemui.statusbar.AlphaOptimizedButton; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 78 | |
| 79 | /** |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 80 | * 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] | 81 | */ |
Joshua Tsuji | 6855cab | 2020-04-16 01:05:39 -0400 | [diff] [blame] | 82 | public class BubbleExpandedView extends LinearLayout { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 83 | private static final String TAG = TAG_WITH_CLASS_NAME ? "BubbleExpandedView" : TAG_BUBBLES; |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 84 | private static final String WINDOW_TITLE = "ImeInsetsWindowWithoutContent"; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 85 | |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 86 | private enum ActivityViewStatus { |
| 87 | // ActivityView is being initialized, cannot start an activity yet. |
| 88 | INITIALIZING, |
| 89 | // ActivityView is initialized, and ready to start an activity. |
| 90 | INITIALIZED, |
| 91 | // Activity runs in the ActivityView. |
| 92 | ACTIVITY_STARTED, |
| 93 | // ActivityView is released, so activity launching will no longer be permitted. |
| 94 | RELEASED, |
| 95 | } |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 96 | |
| 97 | // The triangle pointing to the expanded view |
| 98 | private View mPointerView; |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 99 | private int mPointerMargin; |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 100 | @Nullable private int[] mExpandedViewContainerLocation; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 101 | |
Lyn Han | 754e77b | 2019-04-30 14:34:49 -0700 | [diff] [blame] | 102 | private AlphaOptimizedButton mSettingsIcon; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 103 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 104 | // Views for expanded state |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 105 | private ActivityView mActivityView; |
| 106 | |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 107 | private ActivityViewStatus mActivityViewStatus = ActivityViewStatus.INITIALIZING; |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 108 | private int mTaskId = -1; |
| 109 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 110 | private PendingIntent mPendingIntent; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 111 | |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 112 | private boolean mKeyboardVisible; |
| 113 | private boolean mNeedsNewHeight; |
| 114 | |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 115 | private Point mDisplaySize; |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 116 | private int mMinHeight; |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 117 | private int mOverflowHeight; |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 118 | private int mSettingsIconHeight; |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 119 | private int mPointerWidth; |
| 120 | private int mPointerHeight; |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 121 | private ShapeDrawable mPointerDrawable; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 122 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 123 | @Nullable private Bubble mBubble; |
| 124 | |
| 125 | private boolean mIsOverflow; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 126 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 127 | private BubbleController mBubbleController = Dependency.get(BubbleController.class); |
Mady Mellor | 9be3bed | 2019-08-21 17:26:26 -0700 | [diff] [blame] | 128 | private WindowManager mWindowManager; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 129 | |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 130 | private BubbleStackView mStackView; |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 131 | private View mVirtualImeView; |
| 132 | private WindowManager mVirtualDisplayWindowManager; |
| 133 | private boolean mImeShowing = false; |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 134 | private float mCornerRadius = 0f; |
| 135 | |
| 136 | /** |
| 137 | * Container for the ActivityView that has a solid, round-rect background that shows if the |
| 138 | * ActivityView hasn't loaded. |
| 139 | */ |
| 140 | private FrameLayout mActivityViewContainer = new FrameLayout(getContext()); |
| 141 | |
| 142 | /** The SurfaceView that the ActivityView draws to. */ |
| 143 | @Nullable private SurfaceView mActivitySurface; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 144 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 145 | private ActivityView.StateCallback mStateCallback = new ActivityView.StateCallback() { |
| 146 | @Override |
| 147 | public void onActivityViewReady(ActivityView view) { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 148 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 149 | Log.d(TAG, "onActivityViewReady: mActivityViewStatus=" + mActivityViewStatus |
| 150 | + " bubble=" + getBubbleKey()); |
| 151 | } |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 152 | switch (mActivityViewStatus) { |
| 153 | case INITIALIZING: |
| 154 | case INITIALIZED: |
| 155 | // Custom options so there is no activity transition animation |
| 156 | ActivityOptions options = ActivityOptions.makeCustomAnimation(getContext(), |
| 157 | 0 /* enterResId */, 0 /* exitResId */); |
Winson Chung | 0620052 | 2020-03-31 22:47:02 -0700 | [diff] [blame] | 158 | options.setTaskAlwaysOnTop(true); |
Yuncheol Heo | 5d62e75 | 2020-04-08 14:54:24 -0700 | [diff] [blame] | 159 | options.setLaunchWindowingMode(WINDOWING_MODE_MULTI_WINDOW); |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 160 | // Post to keep the lifecycle normal |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 161 | post(() -> { |
| 162 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 163 | Log.d(TAG, "onActivityViewReady: calling startActivity, " |
| 164 | + "bubble=" + getBubbleKey()); |
| 165 | } |
Mady Mellor | 8454ddf | 2019-08-15 11:16:23 -0700 | [diff] [blame] | 166 | try { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 167 | if (!mIsOverflow && mBubble.usingShortcutInfo()) { |
Mady Mellor | 80d5ed1 | 2020-04-10 21:17:30 -0700 | [diff] [blame] | 168 | options.setApplyActivityFlagsForBubbles(true); |
Mady Mellor | b547e5e | 2019-12-02 10:15:56 -0800 | [diff] [blame] | 169 | mActivityView.startShortcutActivity(mBubble.getShortcutInfo(), |
| 170 | options, null /* sourceBounds */); |
| 171 | } else { |
| 172 | Intent fillInIntent = new Intent(); |
| 173 | // Apply flags to make behaviour match documentLaunchMode=always. |
| 174 | fillInIntent.addFlags(FLAG_ACTIVITY_NEW_DOCUMENT); |
| 175 | fillInIntent.addFlags(FLAG_ACTIVITY_MULTIPLE_TASK); |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 176 | mActivityView.startActivity(mPendingIntent, fillInIntent, options); |
Mady Mellor | b547e5e | 2019-12-02 10:15:56 -0800 | [diff] [blame] | 177 | } |
Mady Mellor | 8454ddf | 2019-08-15 11:16:23 -0700 | [diff] [blame] | 178 | } catch (RuntimeException e) { |
| 179 | // If there's a runtime exception here then there's something |
| 180 | // wrong with the intent, we can't really recover / try to populate |
| 181 | // the bubble again so we'll just remove it. |
| 182 | Log.w(TAG, "Exception while displaying bubble: " + getBubbleKey() |
| 183 | + ", " + e.getMessage() + "; removing bubble"); |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 184 | mBubbleController.removeBubble(getBubbleKey(), |
Mady Mellor | 8454ddf | 2019-08-15 11:16:23 -0700 | [diff] [blame] | 185 | BubbleController.DISMISS_INVALID_INTENT); |
| 186 | } |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 187 | }); |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 188 | mActivityViewStatus = ActivityViewStatus.ACTIVITY_STARTED; |
Mady Mellor | 6d00203 | 2019-02-13 13:45:17 -0800 | [diff] [blame] | 189 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | @Override |
| 193 | public void onActivityViewDestroyed(ActivityView view) { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 194 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 195 | Log.d(TAG, "onActivityViewDestroyed: mActivityViewStatus=" + mActivityViewStatus |
| 196 | + " bubble=" + getBubbleKey()); |
| 197 | } |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 198 | mActivityViewStatus = ActivityViewStatus.RELEASED; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 199 | } |
| 200 | |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 201 | @Override |
| 202 | public void onTaskCreated(int taskId, ComponentName componentName) { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 203 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 204 | Log.d(TAG, "onTaskCreated: taskId=" + taskId |
| 205 | + " bubble=" + getBubbleKey()); |
| 206 | } |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 207 | // Since Bubble ActivityView applies singleTaskDisplay this is |
| 208 | // guaranteed to only be called once per ActivityView. The taskId is |
| 209 | // saved to use for removeTask, preventing appearance in recent tasks. |
| 210 | mTaskId = taskId; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /** |
| 214 | * This is only called for tasks on this ActivityView, which is also set to |
| 215 | * single-task mode -- meaning never more than one task on this display. If a task |
| 216 | * is being removed, it's the top Activity finishing and this bubble should |
| 217 | * be removed or collapsed. |
| 218 | */ |
| 219 | @Override |
| 220 | public void onTaskRemovalStarted(int taskId) { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 221 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 222 | Log.d(TAG, "onTaskRemovalStarted: taskId=" + taskId |
| 223 | + " mActivityViewStatus=" + mActivityViewStatus |
| 224 | + " bubble=" + getBubbleKey()); |
| 225 | } |
Mady Mellor | dd6fe61 | 2020-04-15 11:47:55 -0700 | [diff] [blame] | 226 | if (mBubble != null) { |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 227 | // Must post because this is called from a binder thread. |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 228 | post(() -> mBubbleController.removeBubble(mBubble.getKey(), |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 229 | BubbleController.DISMISS_TASK_FINISHED)); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | }; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 233 | |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 234 | public BubbleExpandedView(Context context) { |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 235 | this(context, null); |
| 236 | } |
| 237 | |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 238 | public BubbleExpandedView(Context context, AttributeSet attrs) { |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 239 | this(context, attrs, 0); |
| 240 | } |
| 241 | |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 242 | public BubbleExpandedView(Context context, AttributeSet attrs, int defStyleAttr) { |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 243 | this(context, attrs, defStyleAttr, 0); |
| 244 | } |
| 245 | |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 246 | public BubbleExpandedView(Context context, AttributeSet attrs, int defStyleAttr, |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 247 | int defStyleRes) { |
| 248 | super(context, attrs, defStyleAttr, defStyleRes); |
Lyn Han | bc985c5 | 2020-05-18 17:57:58 -0700 | [diff] [blame] | 249 | updateDimensions(); |
| 250 | } |
| 251 | |
| 252 | void updateDimensions() { |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 253 | mDisplaySize = new Point(); |
Lyn Han | bc985c5 | 2020-05-18 17:57:58 -0700 | [diff] [blame] | 254 | mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 255 | // Get the real size -- this includes screen decorations (notches, statusbar, navbar). |
Mady Mellor | 9be3bed | 2019-08-21 17:26:26 -0700 | [diff] [blame] | 256 | mWindowManager.getDefaultDisplay().getRealSize(mDisplaySize); |
Mady Mellor | 47b11e3 | 2019-07-11 19:06:21 -0700 | [diff] [blame] | 257 | Resources res = getResources(); |
| 258 | mMinHeight = res.getDimensionPixelSize(R.dimen.bubble_expanded_default_height); |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 259 | mOverflowHeight = res.getDimensionPixelSize(R.dimen.bubble_overflow_height); |
Mady Mellor | 47b11e3 | 2019-07-11 19:06:21 -0700 | [diff] [blame] | 260 | mPointerMargin = res.getDimensionPixelSize(R.dimen.bubble_pointer_margin); |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 261 | } |
| 262 | |
Joshua Tsuji | 847b1d42 | 2020-06-01 13:42:19 -0400 | [diff] [blame] | 263 | @SuppressLint("ClickableViewAccessibility") |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 264 | @Override |
| 265 | protected void onFinishInflate() { |
| 266 | super.onFinishInflate(); |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 267 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 268 | Log.d(TAG, "onFinishInflate: bubble=" + getBubbleKey()); |
| 269 | } |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 270 | |
| 271 | Resources res = getResources(); |
| 272 | mPointerView = findViewById(R.id.pointer_view); |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 273 | mPointerWidth = res.getDimensionPixelSize(R.dimen.bubble_pointer_width); |
| 274 | mPointerHeight = res.getDimensionPixelSize(R.dimen.bubble_pointer_height); |
Mady Mellor | dd49705 | 2019-01-30 17:23:48 -0800 | [diff] [blame] | 275 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 276 | mPointerDrawable = new ShapeDrawable(TriangleShape.create( |
Lyn Han | 5aa27e2 | 2019-05-15 10:55:07 -0700 | [diff] [blame] | 277 | mPointerWidth, mPointerHeight, true /* pointUp */)); |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 278 | mPointerView.setVisibility(INVISIBLE); |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 279 | |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 280 | mSettingsIconHeight = getContext().getResources().getDimensionPixelSize( |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 281 | R.dimen.bubble_manage_button_height); |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 282 | mSettingsIcon = findViewById(R.id.settings_button); |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 283 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 284 | mActivityView = new ActivityView(mContext, null /* attrs */, 0 /* defStyle */, |
shawnlin | ba532af | 2020-06-02 17:48:37 +0800 | [diff] [blame] | 285 | true /* singleTaskInstance */, false /* usePublicVirtualDisplay*/, |
| 286 | true /* disableSurfaceViewBackgroundLayer */); |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 287 | |
lumark | dc9b319 | 2019-07-23 21:18:17 +0800 | [diff] [blame] | 288 | // 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] | 289 | setContentVisibility(false); |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 290 | |
| 291 | mActivityViewContainer.setBackgroundColor(Color.WHITE); |
| 292 | mActivityViewContainer.setOutlineProvider(new ViewOutlineProvider() { |
| 293 | @Override |
| 294 | public void getOutline(View view, Outline outline) { |
| 295 | outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), mCornerRadius); |
| 296 | } |
| 297 | }); |
| 298 | mActivityViewContainer.setClipToOutline(true); |
| 299 | mActivityViewContainer.addView(mActivityView); |
| 300 | mActivityViewContainer.setLayoutParams( |
| 301 | new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)); |
| 302 | addView(mActivityViewContainer); |
| 303 | |
| 304 | if (mActivityView != null |
| 305 | && mActivityView.getChildCount() > 0 |
| 306 | && mActivityView.getChildAt(0) instanceof SurfaceView) { |
| 307 | // Retrieve the surface from the ActivityView so we can screenshot it and change its |
| 308 | // z-ordering. This should always be possible, since ActivityView's constructor adds the |
| 309 | // SurfaceView as its first child. |
| 310 | mActivitySurface = (SurfaceView) mActivityView.getChildAt(0); |
| 311 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 312 | |
Lyn Han | 5aa27e2 | 2019-05-15 10:55:07 -0700 | [diff] [blame] | 313 | // Expanded stack layout, top to bottom: |
| 314 | // Expanded view container |
| 315 | // ==> bubble row |
| 316 | // ==> expanded view |
| 317 | // ==> activity view |
| 318 | // ==> manage button |
| 319 | bringChildToFront(mActivityView); |
| 320 | bringChildToFront(mSettingsIcon); |
Mady Mellor | 52b1ac6 | 2019-04-10 16:59:03 -0700 | [diff] [blame] | 321 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 322 | applyThemeAttrs(); |
| 323 | |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 324 | setOnApplyWindowInsetsListener((View view, WindowInsets insets) -> { |
| 325 | // Keep track of IME displaying because we should not make any adjustments that might |
| 326 | // 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] | 327 | final int keyboardHeight = insets.getSystemWindowInsetBottom() |
| 328 | - insets.getStableInsetBottom(); |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 329 | mKeyboardVisible = keyboardHeight != 0; |
| 330 | if (!mKeyboardVisible && mNeedsNewHeight) { |
| 331 | updateHeight(); |
| 332 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 333 | return view.onApplyWindowInsets(insets); |
| 334 | }); |
Joshua Tsuji | 847b1d42 | 2020-06-01 13:42:19 -0400 | [diff] [blame] | 335 | |
| 336 | final int expandedViewPadding = |
| 337 | res.getDimensionPixelSize(R.dimen.bubble_expanded_view_padding); |
| 338 | |
| 339 | setPadding( |
| 340 | expandedViewPadding, expandedViewPadding, expandedViewPadding, expandedViewPadding); |
| 341 | setOnTouchListener((view, motionEvent) -> { |
| 342 | if (!usingActivityView()) { |
| 343 | return false; |
| 344 | } |
| 345 | |
| 346 | final Rect avBounds = new Rect(); |
| 347 | mActivityView.getBoundsOnScreen(avBounds); |
| 348 | |
| 349 | // Consume and ignore events on the expanded view padding that are within the |
| 350 | // ActivityView's vertical bounds. These events are part of a back gesture, and so they |
| 351 | // should not collapse the stack (which all other touches on areas around the AV would |
| 352 | // do). |
| 353 | if (motionEvent.getRawY() >= avBounds.top && motionEvent.getRawY() <= avBounds.bottom) { |
| 354 | return true; |
| 355 | } |
| 356 | |
| 357 | return false; |
| 358 | }); |
Joshua Tsuji | 519d4c1 | 2020-05-29 15:22:31 -0400 | [diff] [blame] | 359 | |
| 360 | // BubbleStackView is forced LTR, but we want to respect the locale for expanded view layout |
| 361 | // so the Manage button appears on the right. |
| 362 | setLayoutDirection(LAYOUT_DIRECTION_LOCALE); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 363 | } |
| 364 | |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 365 | private String getBubbleKey() { |
| 366 | return mBubble != null ? mBubble.getKey() : "null"; |
| 367 | } |
| 368 | |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 369 | /** |
| 370 | * Asks the ActivityView's surface to draw on top of all other views in the window. This is |
| 371 | * useful for ordering surfaces during animations, but should otherwise be set to false so that |
| 372 | * bubbles and menus can draw over the ActivityView. |
| 373 | */ |
| 374 | void setSurfaceZOrderedOnTop(boolean onTop) { |
| 375 | if (mActivitySurface == null) { |
| 376 | return; |
| 377 | } |
| 378 | |
| 379 | mActivitySurface.setZOrderedOnTop(onTop, true); |
| 380 | } |
| 381 | |
| 382 | /** Return a GraphicBuffer with the contents of the ActivityView's underlying surface. */ |
| 383 | @Nullable SurfaceControl.ScreenshotGraphicBuffer snapshotActivitySurface() { |
| 384 | if (mActivitySurface == null) { |
| 385 | return null; |
| 386 | } |
| 387 | |
| 388 | return SurfaceControl.captureLayers( |
| 389 | mActivitySurface.getSurfaceControl(), |
| 390 | new Rect(0, 0, mActivityView.getWidth(), mActivityView.getHeight()), |
| 391 | 1 /* scale */); |
| 392 | } |
| 393 | |
| 394 | int[] getActivityViewLocationOnScreen() { |
| 395 | if (mActivityView != null) { |
| 396 | return mActivityView.getLocationOnScreen(); |
| 397 | } else { |
| 398 | return new int[]{0, 0}; |
| 399 | } |
| 400 | } |
| 401 | |
Joshua Tsuji | 6855cab | 2020-04-16 01:05:39 -0400 | [diff] [blame] | 402 | void setManageClickListener(OnClickListener manageClickListener) { |
| 403 | findViewById(R.id.settings_button).setOnClickListener(manageClickListener); |
| 404 | } |
| 405 | |
| 406 | /** |
| 407 | * Updates the ActivityView's obscured touchable region. This calls onLocationChanged, which |
| 408 | * results in a call to {@link BubbleStackView#subtractObscuredTouchableRegion}. This is useful |
| 409 | * if a view has been added or removed from on top of the ActivityView, such as the manage menu. |
| 410 | */ |
| 411 | void updateObscuredTouchableRegion() { |
Mady Mellor | 64db51a | 2020-05-27 19:00:14 -0700 | [diff] [blame] | 412 | if (mActivityView != null) { |
| 413 | mActivityView.onLocationChanged(); |
| 414 | } |
Joshua Tsuji | 6855cab | 2020-04-16 01:05:39 -0400 | [diff] [blame] | 415 | } |
| 416 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 417 | void applyThemeAttrs() { |
Lyn Han | 61bfdb3 | 2019-12-10 14:34:12 -0800 | [diff] [blame] | 418 | final TypedArray ta = mContext.obtainStyledAttributes( |
Joshua Tsuji | dd082b6 | 2020-05-20 22:26:24 -0400 | [diff] [blame] | 419 | new int[] {android.R.attr.dialogCornerRadius}); |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 420 | mCornerRadius = ta.getDimensionPixelSize(0, 0); |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 421 | ta.recycle(); |
| 422 | |
Lyn Han | edb55e2 | 2020-02-12 18:55:39 -0800 | [diff] [blame] | 423 | if (mActivityView != null && ScreenDecorationsUtils.supportsRoundedCornersOnWindows( |
| 424 | mContext.getResources())) { |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 425 | mActivityView.setCornerRadius(mCornerRadius); |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 426 | } |
Lyn Han | 26bb198 | 2020-06-08 15:38:01 -0700 | [diff] [blame] | 427 | |
| 428 | final int mode = |
| 429 | getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; |
| 430 | switch (mode) { |
| 431 | case Configuration.UI_MODE_NIGHT_NO: |
| 432 | mPointerDrawable.setTint(getResources().getColor(R.color.bubbles_pointer_light)); |
| 433 | break; |
| 434 | case Configuration.UI_MODE_NIGHT_YES: |
| 435 | mPointerDrawable.setTint(getResources().getColor(R.color.bubbles_pointer_dark)); |
| 436 | break; |
| 437 | } |
| 438 | mPointerView.setBackground(mPointerDrawable); |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame] | 439 | } |
| 440 | |
Joshua Tsuji | 847b1d42 | 2020-06-01 13:42:19 -0400 | [diff] [blame] | 441 | /** |
| 442 | * Hides the IME if it's showing. This is currently done by dispatching a back press to the AV. |
| 443 | */ |
| 444 | void hideImeIfVisible() { |
| 445 | if (mKeyboardVisible) { |
| 446 | performBackPressIfNeeded(); |
| 447 | } |
| 448 | } |
| 449 | |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 450 | @Override |
| 451 | protected void onDetachedFromWindow() { |
| 452 | super.onDetachedFromWindow(); |
Joshua Tsuji | 847b1d42 | 2020-06-01 13:42:19 -0400 | [diff] [blame] | 453 | hideImeIfVisible(); |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 454 | mKeyboardVisible = false; |
| 455 | mNeedsNewHeight = false; |
| 456 | if (mActivityView != null) { |
Mady Mellor | af02fa4 | 2020-03-04 14:22:16 -0800 | [diff] [blame] | 457 | if (sNewInsetsMode == NEW_INSETS_MODE_FULL) { |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 458 | setImeWindowToDisplay(0, 0); |
Mady Mellor | af02fa4 | 2020-03-04 14:22:16 -0800 | [diff] [blame] | 459 | } else { |
| 460 | mActivityView.setForwardedInsets(Insets.of(0, 0, 0, 0)); |
| 461 | } |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 462 | } |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 463 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 464 | Log.d(TAG, "onDetachedFromWindow: bubble=" + getBubbleKey()); |
| 465 | } |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | /** |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 469 | * Set visibility of contents in the expanded state. |
| 470 | * |
| 471 | * @param visibility {@code true} if the contents should be visible on the screen. |
| 472 | * |
| 473 | * Note that this contents visibility doesn't affect visibility at {@link android.view.View}, |
| 474 | * and setting {@code false} actually means rendering the contents in transparent. |
| 475 | */ |
| 476 | void setContentVisibility(boolean visibility) { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 477 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 478 | Log.d(TAG, "setContentVisibility: visibility=" + visibility |
| 479 | + " bubble=" + getBubbleKey()); |
| 480 | } |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 481 | final float alpha = visibility ? 1f : 0f; |
| 482 | mPointerView.setAlpha(alpha); |
| 483 | if (mActivityView != null) { |
| 484 | mActivityView.setAlpha(alpha); |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 485 | mActivityView.bringToFront(); |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 486 | } |
| 487 | } |
| 488 | |
| 489 | /** |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 490 | * Called by {@link BubbleStackView} when the insets for the expanded state should be updated. |
| 491 | * This should be done post-move and post-animation. |
| 492 | */ |
| 493 | void updateInsets(WindowInsets insets) { |
| 494 | if (usingActivityView()) { |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 495 | int[] screenLoc = mActivityView.getLocationOnScreen(); |
| 496 | final int activityViewBottom = screenLoc[1] + mActivityView.getHeight(); |
Mady Mellor | 9be3bed | 2019-08-21 17:26:26 -0700 | [diff] [blame] | 497 | final int keyboardTop = mDisplaySize.y - Math.max(insets.getSystemWindowInsetBottom(), |
| 498 | insets.getDisplayCutout() != null |
| 499 | ? insets.getDisplayCutout().getSafeInsetBottom() |
| 500 | : 0); |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 501 | final int insetsBottom = Math.max(activityViewBottom - keyboardTop, 0); |
Jorim Jaggi | 924ef75 | 2020-01-29 17:26:55 +0100 | [diff] [blame] | 502 | |
Jorim Jaggi | 924ef75 | 2020-01-29 17:26:55 +0100 | [diff] [blame] | 503 | if (sNewInsetsMode == NEW_INSETS_MODE_FULL) { |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 504 | setImeWindowToDisplay(getWidth(), insetsBottom); |
Jorim Jaggi | 924ef75 | 2020-01-29 17:26:55 +0100 | [diff] [blame] | 505 | } else { |
| 506 | mActivityView.setForwardedInsets(Insets.of(0, 0, 0, insetsBottom)); |
| 507 | } |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 508 | } |
| 509 | } |
| 510 | |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 511 | private void setImeWindowToDisplay(int w, int h) { |
| 512 | if (getVirtualDisplayId() == INVALID_DISPLAY) { |
| 513 | return; |
| 514 | } |
| 515 | if (h == 0 || w == 0) { |
| 516 | if (mImeShowing) { |
| 517 | mVirtualImeView.setVisibility(GONE); |
| 518 | mImeShowing = false; |
| 519 | } |
| 520 | return; |
| 521 | } |
| 522 | final Context virtualDisplayContext = mContext.createDisplayContext( |
| 523 | getVirtualDisplay().getDisplay()); |
| 524 | |
| 525 | if (mVirtualDisplayWindowManager == null) { |
| 526 | mVirtualDisplayWindowManager = |
| 527 | (WindowManager) virtualDisplayContext.getSystemService(Context.WINDOW_SERVICE); |
| 528 | } |
| 529 | if (mVirtualImeView == null) { |
| 530 | mVirtualImeView = new View(virtualDisplayContext); |
| 531 | mVirtualImeView.setVisibility(VISIBLE); |
| 532 | mVirtualDisplayWindowManager.addView(mVirtualImeView, |
| 533 | getVirtualImeViewAttrs(w, h)); |
| 534 | } else { |
| 535 | mVirtualDisplayWindowManager.updateViewLayout(mVirtualImeView, |
| 536 | getVirtualImeViewAttrs(w, h)); |
| 537 | mVirtualImeView.setVisibility(VISIBLE); |
| 538 | } |
| 539 | |
| 540 | mImeShowing = true; |
| 541 | } |
| 542 | |
| 543 | private WindowManager.LayoutParams getVirtualImeViewAttrs(int w, int h) { |
| 544 | // To use TYPE_NAVIGATION_BAR_PANEL instead of TYPE_IME_BAR to bypass the IME window type |
| 545 | // token check when adding the window. |
| 546 | final WindowManager.LayoutParams attrs = |
| 547 | new WindowManager.LayoutParams(w, h, TYPE_NAVIGATION_BAR_PANEL, |
| 548 | FLAG_LAYOUT_NO_LIMITS | FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCHABLE, |
| 549 | TRANSPARENT); |
| 550 | attrs.gravity = Gravity.BOTTOM; |
| 551 | attrs.setTitle(WINDOW_TITLE); |
| 552 | attrs.token = new Binder(); |
| 553 | attrs.providesInsetsTypes = new int[]{ITYPE_IME}; |
| 554 | attrs.alpha = 0.0f; |
| 555 | return attrs; |
| 556 | } |
| 557 | |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 558 | void setStackView(BubbleStackView stackView) { |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 559 | mStackView = stackView; |
Mady Mellor | 6d00203 | 2019-02-13 13:45:17 -0800 | [diff] [blame] | 560 | } |
| 561 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 562 | public void setOverflow(boolean overflow) { |
| 563 | mIsOverflow = overflow; |
| 564 | |
| 565 | Intent target = new Intent(mContext, BubbleOverflowActivity.class); |
| 566 | mPendingIntent = PendingIntent.getActivity(mContext, /* requestCode */ 0, |
| 567 | target, PendingIntent.FLAG_UPDATE_CURRENT); |
| 568 | mSettingsIcon.setVisibility(GONE); |
| 569 | } |
| 570 | |
Mady Mellor | 6d00203 | 2019-02-13 13:45:17 -0800 | [diff] [blame] | 571 | /** |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 572 | * Sets the bubble used to populate this view. |
Mady Mellor | 6d00203 | 2019-02-13 13:45:17 -0800 | [diff] [blame] | 573 | */ |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 574 | void update(Bubble bubble) { |
| 575 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 576 | Log.d(TAG, "update: bubble=" + (bubble != null ? bubble.getKey() : "null")); |
| 577 | } |
Mady Mellor | 458a626 | 2020-06-07 21:09:19 -0700 | [diff] [blame] | 578 | boolean isNew = mBubble == null || didBackingContentChange(bubble); |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 579 | if (isNew || bubble != null && bubble.getKey().equals(mBubble.getKey())) { |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 580 | mBubble = bubble; |
| 581 | mSettingsIcon.setContentDescription(getResources().getString( |
| 582 | R.string.bubbles_settings_button_description, bubble.getAppName())); |
| 583 | |
Lyn Han | 670fa80 | 2020-05-05 12:56:33 -0700 | [diff] [blame] | 584 | mSettingsIcon.setAccessibilityDelegate( |
| 585 | new AccessibilityDelegate() { |
| 586 | @Override |
| 587 | public void onInitializeAccessibilityNodeInfo(View host, |
| 588 | AccessibilityNodeInfo info) { |
| 589 | super.onInitializeAccessibilityNodeInfo(host, info); |
| 590 | // On focus, have TalkBack say |
| 591 | // "Actions available. Use swipe up then right to view." |
| 592 | // in addition to the default "double tap to activate". |
| 593 | mStackView.setupLocalMenu(info); |
| 594 | } |
| 595 | }); |
| 596 | |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 597 | if (isNew) { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 598 | mPendingIntent = mBubble.getBubbleIntent(); |
| 599 | if (mPendingIntent != null || mBubble.getShortcutInfo() != null) { |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 600 | setContentVisibility(false); |
| 601 | mActivityView.setVisibility(VISIBLE); |
| 602 | } |
| 603 | } |
| 604 | applyThemeAttrs(); |
| 605 | } else { |
| 606 | Log.w(TAG, "Trying to update entry with different key, new bubble: " |
| 607 | + bubble.getKey() + " old bubble: " + bubble.getKey()); |
| 608 | } |
| 609 | } |
| 610 | |
Mady Mellor | 458a626 | 2020-06-07 21:09:19 -0700 | [diff] [blame] | 611 | private boolean didBackingContentChange(Bubble newBubble) { |
| 612 | boolean prevWasIntentBased = mBubble != null && mPendingIntent != null; |
| 613 | boolean newIsIntentBased = newBubble.getBubbleIntent() != null; |
| 614 | return prevWasIntentBased != newIsIntentBased; |
| 615 | } |
| 616 | |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 617 | /** |
| 618 | * Lets activity view know it should be shown / populated with activity content. |
| 619 | */ |
| 620 | void populateExpandedView() { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 621 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 622 | Log.d(TAG, "populateExpandedView: " |
| 623 | + "bubble=" + getBubbleKey()); |
| 624 | } |
| 625 | |
Mady Mellor | 5029fa6 | 2019-03-05 12:16:21 -0800 | [diff] [blame] | 626 | if (usingActivityView()) { |
| 627 | mActivityView.setCallback(mStateCallback); |
| 628 | } else { |
Issei Suzuki | a91f396 | 2019-06-07 11:48:23 +0200 | [diff] [blame] | 629 | Log.e(TAG, "Cannot populate expanded view."); |
Mady Mellor | 5029fa6 | 2019-03-05 12:16:21 -0800 | [diff] [blame] | 630 | } |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 631 | } |
| 632 | |
Mark Renouf | 041d726 | 2019-02-06 12:09:41 -0500 | [diff] [blame] | 633 | boolean performBackPressIfNeeded() { |
Mady Mellor | 323fb0b | 2019-03-25 12:15:22 -0700 | [diff] [blame] | 634 | if (!usingActivityView()) { |
Mark Renouf | 041d726 | 2019-02-06 12:09:41 -0500 | [diff] [blame] | 635 | return false; |
| 636 | } |
| 637 | mActivityView.performBackPress(); |
| 638 | return true; |
| 639 | } |
| 640 | |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 641 | void updateHeight() { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 642 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 643 | Log.d(TAG, "updateHeight: bubble=" + getBubbleKey()); |
| 644 | } |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 645 | |
| 646 | if (mExpandedViewContainerLocation == null) { |
| 647 | return; |
| 648 | } |
| 649 | |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 650 | if (usingActivityView()) { |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 651 | float desiredHeight = mOverflowHeight; |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 652 | if (!mIsOverflow) { |
| 653 | desiredHeight = Math.max(mBubble.getDesiredHeight(mContext), mMinHeight); |
| 654 | } |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 655 | float height = Math.min(desiredHeight, getMaxExpandedHeight()); |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 656 | height = Math.max(height, mIsOverflow? mOverflowHeight : mMinHeight); |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 657 | ViewGroup.LayoutParams lp = mActivityView.getLayoutParams(); |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 658 | mNeedsNewHeight = lp.height != height; |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 659 | if (!mKeyboardVisible) { |
| 660 | // If the keyboard is visible... don't adjust the height because that will cause |
| 661 | // a configuration change and the keyboard will be lost. |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame] | 662 | lp.height = (int) height; |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 663 | mActivityView.setLayoutParams(lp); |
| 664 | mNeedsNewHeight = false; |
| 665 | } |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 666 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 667 | Log.d(TAG, "updateHeight: bubble=" + getBubbleKey() |
| 668 | + " height=" + height |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 669 | + " mNeedsNewHeight=" + mNeedsNewHeight); |
| 670 | } |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 671 | } |
| 672 | } |
| 673 | |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 674 | private int getMaxExpandedHeight() { |
Mady Mellor | 9be3bed | 2019-08-21 17:26:26 -0700 | [diff] [blame] | 675 | mWindowManager.getDefaultDisplay().getRealSize(mDisplaySize); |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 676 | int bottomInset = getRootWindowInsets() != null |
| 677 | ? getRootWindowInsets().getStableInsetBottom() |
| 678 | : 0; |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 679 | |
| 680 | return mDisplaySize.y |
| 681 | - mExpandedViewContainerLocation[1] |
| 682 | - getPaddingTop() |
| 683 | - getPaddingBottom() |
| 684 | - mSettingsIconHeight |
| 685 | - mPointerHeight |
Mady Mellor | 8fe411d | 2019-08-16 11:27:53 -0700 | [diff] [blame] | 686 | - mPointerMargin - bottomInset; |
Mady Mellor | a96c9ed | 2019-06-07 12:55:26 -0700 | [diff] [blame] | 687 | } |
| 688 | |
Mady Mellor | 47b11e3 | 2019-07-11 19:06:21 -0700 | [diff] [blame] | 689 | /** |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 690 | * Update appearance of the expanded view being displayed. |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 691 | * |
| 692 | * @param containerLocationOnScreen The location on-screen of the container the expanded view is |
| 693 | * added to. This allows us to calculate max height without |
| 694 | * waiting for layout. |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 695 | */ |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 696 | public void updateView(int[] containerLocationOnScreen) { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 697 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 698 | Log.d(TAG, "updateView: bubble=" |
| 699 | + getBubbleKey()); |
| 700 | } |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 701 | |
| 702 | mExpandedViewContainerLocation = containerLocationOnScreen; |
| 703 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 704 | if (usingActivityView() |
| 705 | && mActivityView.getVisibility() == VISIBLE |
| 706 | && mActivityView.isAttachedToWindow()) { |
| 707 | mActivityView.onLocationChanged(); |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 708 | updateHeight(); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 709 | } |
| 710 | } |
| 711 | |
| 712 | /** |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 713 | * Set the x position that the tip of the triangle should point to. |
| 714 | */ |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 715 | public void setPointerPosition(float x) { |
Lyn Han | 9a2f5cf | 2019-05-23 11:01:41 -0700 | [diff] [blame] | 716 | float halfPointerWidth = mPointerWidth / 2f; |
| 717 | float pointerLeft = x - halfPointerWidth; |
| 718 | mPointerView.setTranslationX(pointerLeft); |
Lyn Han | f74ba67 | 2019-05-20 16:08:48 -0700 | [diff] [blame] | 719 | mPointerView.setVisibility(VISIBLE); |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | /** |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 723 | * Position of the manage button displayed in the expanded view. Used for placing user |
| 724 | * education about the manage button. |
| 725 | */ |
Joshua Tsuji | 6855cab | 2020-04-16 01:05:39 -0400 | [diff] [blame] | 726 | public void getManageButtonBoundsOnScreen(Rect rect) { |
| 727 | mSettingsIcon.getBoundsOnScreen(rect); |
Mady Mellor | 5a3e94b | 2020-02-07 12:16:21 -0800 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | /** |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 731 | * 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] | 732 | */ |
Mady Mellor | 94d94a7 | 2019-03-05 18:16:59 -0800 | [diff] [blame] | 733 | public void cleanUpExpandedState() { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 734 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 735 | Log.d(TAG, "cleanUpExpandedState: mActivityViewStatus=" + mActivityViewStatus |
| 736 | + ", bubble=" + getBubbleKey()); |
| 737 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 738 | if (mActivityView == null) { |
Mark Renouf | 89b1a4a | 2018-12-04 14:59:45 -0500 | [diff] [blame] | 739 | return; |
| 740 | } |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 741 | switch (mActivityViewStatus) { |
| 742 | case INITIALIZED: |
| 743 | case ACTIVITY_STARTED: |
| 744 | mActivityView.release(); |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 745 | } |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 746 | if (mTaskId != -1) { |
| 747 | try { |
| 748 | ActivityTaskManager.getService().removeTask(mTaskId); |
| 749 | } catch (RemoteException e) { |
| 750 | Log.w(TAG, "Failed to remove taskId " + mTaskId); |
| 751 | } |
| 752 | mTaskId = -1; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 753 | } |
Mark Renouf | 28c250d | 2019-02-25 16:47:34 -0500 | [diff] [blame] | 754 | removeView(mActivityView); |
Mark Renouf | 5c732b3 | 2019-06-12 15:14:54 -0400 | [diff] [blame] | 755 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 756 | mActivityView = null; |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | /** |
| 760 | * Called when the last task is removed from a {@link android.hardware.display.VirtualDisplay} |
| 761 | * which {@link ActivityView} uses. |
| 762 | */ |
| 763 | void notifyDisplayEmpty() { |
Mark Renouf | db861c9 | 2019-07-26 13:58:17 -0400 | [diff] [blame] | 764 | if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 765 | Log.d(TAG, "notifyDisplayEmpty: bubble=" |
| 766 | + getBubbleKey() |
| 767 | + " mActivityViewStatus=" + mActivityViewStatus); |
| 768 | } |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 769 | if (mActivityViewStatus == ActivityViewStatus.ACTIVITY_STARTED) { |
| 770 | mActivityViewStatus = ActivityViewStatus.INITIALIZED; |
| 771 | } |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 772 | } |
| 773 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 774 | private boolean usingActivityView() { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 775 | return (mPendingIntent != null || mBubble.getShortcutInfo() != null) |
Mady Mellor | 2ac2d3a | 2020-01-08 17:18:54 -0800 | [diff] [blame] | 776 | && mActivityView != null; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 777 | } |
| 778 | |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 779 | /** |
| 780 | * @return the display id of the virtual display. |
| 781 | */ |
| 782 | public int getVirtualDisplayId() { |
| 783 | if (usingActivityView()) { |
| 784 | return mActivityView.getVirtualDisplayId(); |
| 785 | } |
| 786 | return INVALID_DISPLAY; |
| 787 | } |
Yunfan Chen | b83940c | 2020-04-06 16:43:09 +0900 | [diff] [blame] | 788 | |
| 789 | private VirtualDisplay getVirtualDisplay() { |
| 790 | if (usingActivityView()) { |
| 791 | return mActivityView.getVirtualDisplay(); |
| 792 | } |
| 793 | return null; |
| 794 | } |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 795 | } |