Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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.pip.phone; |
| 18 | |
Mady Mellor | 637cd48 | 2017-03-21 10:39:42 -0700 | [diff] [blame] | 19 | import static com.android.systemui.pip.phone.PipMenuActivityController.MENU_STATE_CLOSE; |
| 20 | import static com.android.systemui.pip.phone.PipMenuActivityController.MENU_STATE_FULL; |
Chenjie Yu | ae9fdf04 | 2018-02-15 10:19:32 -0800 | [diff] [blame] | 21 | import static com.android.systemui.pip.phone.PipMenuActivityController.MENU_STATE_NONE; |
Mady Mellor | 637cd48 | 2017-03-21 10:39:42 -0700 | [diff] [blame] | 22 | |
Winson Chung | 87e5d55 | 2017-04-05 11:49:38 -0700 | [diff] [blame] | 23 | import android.animation.Animator; |
| 24 | import android.animation.AnimatorListenerAdapter; |
Mady Mellor | 81d4061 | 2017-03-10 15:14:10 -0800 | [diff] [blame] | 25 | import android.animation.ValueAnimator; |
| 26 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 27 | import android.app.IActivityManager; |
Winson Chung | 9b91941 | 2017-06-19 17:01:51 -0700 | [diff] [blame] | 28 | import android.content.ComponentName; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 29 | import android.content.Context; |
Winson Chung | 136d1ec8 | 2017-07-18 11:16:30 -0700 | [diff] [blame] | 30 | import android.content.res.Resources; |
Mady Mellor | a7f6974 | 2017-02-03 11:00:20 -0800 | [diff] [blame] | 31 | import android.graphics.Point; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 32 | import android.graphics.PointF; |
| 33 | import android.graphics.Rect; |
Mady Mellor | d4e40fb | 2017-01-26 10:43:16 -0800 | [diff] [blame] | 34 | import android.os.Handler; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 35 | import android.os.RemoteException; |
| 36 | import android.util.Log; |
Mady Mellor | a7f6974 | 2017-02-03 11:00:20 -0800 | [diff] [blame] | 37 | import android.util.Size; |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 38 | import android.view.IPinnedStackController; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 39 | import android.view.MotionEvent; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 40 | import android.view.ViewConfiguration; |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 41 | import android.view.accessibility.AccessibilityEvent; |
| 42 | import android.view.accessibility.AccessibilityManager; |
| 43 | import android.view.accessibility.AccessibilityNodeInfo; |
Phil Weaver | 0a8caa1 | 2017-08-09 11:28:41 -0700 | [diff] [blame] | 44 | import android.view.accessibility.AccessibilityWindowInfo; |
Chenjie Yu | ae9fdf04 | 2018-02-15 10:19:32 -0800 | [diff] [blame] | 45 | |
Chenjie Yu | 52cacc6 | 2017-12-08 18:11:45 -0800 | [diff] [blame] | 46 | import com.android.internal.os.logging.MetricsLoggerWrapper; |
Winson Chung | cd1ff64 | 2016-10-26 09:44:43 -0700 | [diff] [blame] | 47 | import com.android.internal.policy.PipSnapAlgorithm; |
Mady Mellor | a7f6974 | 2017-02-03 11:00:20 -0800 | [diff] [blame] | 48 | import com.android.systemui.R; |
Winson Chung | cbb15a9 | 2018-01-25 17:46:16 +0000 | [diff] [blame] | 49 | import com.android.systemui.shared.system.InputConsumerController; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 50 | import com.android.systemui.statusbar.FlingAnimationUtils; |
| 51 | |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 52 | import java.io.PrintWriter; |
| 53 | |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 54 | /** |
| 55 | * Manages all the touch handling for PIP on the Phone, including moving, dismissing and expanding |
| 56 | * the PIP. |
| 57 | */ |
Mady Mellor | 8c7dc42 | 2017-05-10 12:55:06 -0700 | [diff] [blame] | 58 | public class PipTouchHandler { |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 59 | private static final String TAG = "PipTouchHandler"; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 60 | |
Mady Mellor | 8c7dc42 | 2017-05-10 12:55:06 -0700 | [diff] [blame] | 61 | // Allow the PIP to be dragged to the edge of the screen to be minimized. |
| 62 | private static final boolean ENABLE_MINIMIZE = false; |
| 63 | // Allow the PIP to be flung from anywhere on the screen to the bottom to be dismissed. |
| 64 | private static final boolean ENABLE_FLING_DISMISS = false; |
Mady Mellor | 2e13878 | 2017-03-27 11:09:50 -0700 | [diff] [blame] | 65 | |
Mady Mellor | 5d58d25 | 2017-04-18 12:48:04 -0700 | [diff] [blame] | 66 | private static final int SHOW_DISMISS_AFFORDANCE_DELAY = 225; |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 67 | |
Winson Chung | 6e35ee1f | 2017-02-14 12:06:44 -0800 | [diff] [blame] | 68 | // Allow dragging the PIP to a location to close it |
Mady Mellor | 81d4061 | 2017-03-10 15:14:10 -0800 | [diff] [blame] | 69 | private static final boolean ENABLE_DISMISS_DRAG_TO_EDGE = true; |
Winson Chung | 6e35ee1f | 2017-02-14 12:06:44 -0800 | [diff] [blame] | 70 | |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 71 | private final Context mContext; |
| 72 | private final IActivityManager mActivityManager; |
| 73 | private final ViewConfiguration mViewConfig; |
Winson Chung | 15504af | 2016-11-02 18:11:36 -0700 | [diff] [blame] | 74 | private final PipMenuListener mMenuListener = new PipMenuListener(); |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 75 | private IPinnedStackController mPinnedStackController; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 76 | |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 77 | private final PipMenuActivityController mMenuController; |
| 78 | private final PipDismissViewController mDismissViewController; |
Winson Chung | 14fefc2 | 2016-11-02 10:02:29 -0700 | [diff] [blame] | 79 | private final PipSnapAlgorithm mSnapAlgorithm; |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 80 | private final AccessibilityManager mAccessibilityManager; |
Wale Ogunwale | 6455e50 | 2017-04-17 14:16:43 -0700 | [diff] [blame] | 81 | private boolean mShowPipMenuOnAnimationEnd = false; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 82 | |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 83 | // The current movement bounds |
| 84 | private Rect mMovementBounds = new Rect(); |
| 85 | |
Winson Chung | 0a2f34f | 2017-08-11 18:13:24 -0700 | [diff] [blame] | 86 | // The reference inset bounds, used to determine the dismiss fraction |
| 87 | private Rect mInsetBounds = new Rect(); |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 88 | // The reference bounds used to calculate the normal/expanded target bounds |
| 89 | private Rect mNormalBounds = new Rect(); |
| 90 | private Rect mNormalMovementBounds = new Rect(); |
| 91 | private Rect mExpandedBounds = new Rect(); |
| 92 | private Rect mExpandedMovementBounds = new Rect(); |
Mady Mellor | a7f6974 | 2017-02-03 11:00:20 -0800 | [diff] [blame] | 93 | private int mExpandedShortestEdgeSize; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 94 | |
Winson Chung | ef4dc81 | 2017-04-11 13:31:44 -0700 | [diff] [blame] | 95 | // Used to workaround an issue where the WM rotation happens before we are notified, allowing |
| 96 | // us to send stale bounds |
| 97 | private int mDeferResizeToNormalBoundsUntilRotation = -1; |
| 98 | private int mDisplayRotation; |
| 99 | |
Mady Mellor | d4e40fb | 2017-01-26 10:43:16 -0800 | [diff] [blame] | 100 | private Handler mHandler = new Handler(); |
| 101 | private Runnable mShowDismissAffordance = new Runnable() { |
| 102 | @Override |
| 103 | public void run() { |
Mady Mellor | 60421c9 | 2017-03-29 15:27:37 -0700 | [diff] [blame] | 104 | if (ENABLE_DISMISS_DRAG_TO_EDGE) { |
| 105 | mDismissViewController.showDismissTarget(); |
Mady Mellor | d4e40fb | 2017-01-26 10:43:16 -0800 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | }; |
Mady Mellor | 81d4061 | 2017-03-10 15:14:10 -0800 | [diff] [blame] | 109 | private ValueAnimator.AnimatorUpdateListener mUpdateScrimListener = |
| 110 | new AnimatorUpdateListener() { |
| 111 | @Override |
| 112 | public void onAnimationUpdate(ValueAnimator animation) { |
| 113 | updateDismissFraction(); |
| 114 | } |
| 115 | }; |
Mady Mellor | d4e40fb | 2017-01-26 10:43:16 -0800 | [diff] [blame] | 116 | |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 117 | // Behaviour states |
Winson Chung | 9b91941 | 2017-06-19 17:01:51 -0700 | [diff] [blame] | 118 | private int mMenuState = MENU_STATE_NONE; |
Winson Chung | d2d9097 | 2017-02-28 11:40:41 -0800 | [diff] [blame] | 119 | private boolean mIsMinimized; |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 120 | private boolean mIsImeShowing; |
| 121 | private int mImeHeight; |
Winson Chung | 136d1ec8 | 2017-07-18 11:16:30 -0700 | [diff] [blame] | 122 | private int mImeOffset; |
Tracy Zhou | 4351308 | 2018-03-08 21:58:36 -0800 | [diff] [blame] | 123 | private boolean mIsShelfShowing; |
| 124 | private int mShelfHeight; |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 125 | private float mSavedSnapFraction = -1f; |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 126 | private boolean mSendingHoverAccessibilityEvents; |
Mady Mellor | 2fbdd3b | 2017-03-21 17:45:00 -0700 | [diff] [blame] | 127 | private boolean mMovementWithinMinimize; |
| 128 | private boolean mMovementWithinDismiss; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 129 | |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 130 | // Touch state |
| 131 | private final PipTouchState mTouchState; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 132 | private final FlingAnimationUtils mFlingAnimationUtils; |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 133 | private final PipTouchGesture[] mGestures; |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 134 | private final PipMotionHelper mMotionHelper; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 135 | |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 136 | // Temp vars |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 137 | private final Rect mTmpBounds = new Rect(); |
| 138 | |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 139 | /** |
Winson Chung | 15504af | 2016-11-02 18:11:36 -0700 | [diff] [blame] | 140 | * A listener for the PIP menu activity. |
| 141 | */ |
| 142 | private class PipMenuListener implements PipMenuActivityController.Listener { |
| 143 | @Override |
Mady Mellor | 637cd48 | 2017-03-21 10:39:42 -0700 | [diff] [blame] | 144 | public void onPipMenuStateChanged(int menuState, boolean resize) { |
| 145 | setMenuState(menuState, resize); |
Winson Chung | 15504af | 2016-11-02 18:11:36 -0700 | [diff] [blame] | 146 | } |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 147 | |
| 148 | @Override |
| 149 | public void onPipExpand() { |
| 150 | if (!mIsMinimized) { |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 151 | mMotionHelper.expandPip(); |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
| 155 | @Override |
| 156 | public void onPipMinimize() { |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 157 | setMinimizedStateInternal(true); |
Mady Mellor | 81d4061 | 2017-03-10 15:14:10 -0800 | [diff] [blame] | 158 | mMotionHelper.animateToClosestMinimizedState(mMovementBounds, null /* updateListener */); |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | @Override |
| 162 | public void onPipDismiss() { |
Chenjie Yu | ae9fdf04 | 2018-02-15 10:19:32 -0800 | [diff] [blame] | 163 | MetricsLoggerWrapper.logPictureInPictureDismissByTap(mContext, |
| 164 | PipUtils.getTopPinnedActivity(mContext, mActivityManager)); |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 165 | mMotionHelper.dismissPip(); |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 166 | } |
Mady Mellor | 637cd48 | 2017-03-21 10:39:42 -0700 | [diff] [blame] | 167 | |
| 168 | @Override |
| 169 | public void onPipShowMenu() { |
| 170 | mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(), |
Winson Chung | bb78744 | 2017-09-01 11:33:47 -0700 | [diff] [blame] | 171 | mMovementBounds, true /* allowMenuTimeout */, willResizeMenu()); |
Mady Mellor | 637cd48 | 2017-03-21 10:39:42 -0700 | [diff] [blame] | 172 | } |
Winson Chung | 15504af | 2016-11-02 18:11:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Winson Chung | d2d9097 | 2017-02-28 11:40:41 -0800 | [diff] [blame] | 175 | public PipTouchHandler(Context context, IActivityManager activityManager, |
| 176 | PipMenuActivityController menuController, |
| 177 | InputConsumerController inputConsumerController) { |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 178 | |
| 179 | // Initialize the Pip input consumer |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 180 | mContext = context; |
| 181 | mActivityManager = activityManager; |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 182 | mAccessibilityManager = context.getSystemService(AccessibilityManager.class); |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 183 | mViewConfig = ViewConfiguration.get(context); |
Winson Chung | 15504af | 2016-11-02 18:11:36 -0700 | [diff] [blame] | 184 | mMenuController = menuController; |
| 185 | mMenuController.addListener(mMenuListener); |
| 186 | mDismissViewController = new PipDismissViewController(context); |
Winson Chung | 14fefc2 | 2016-11-02 10:02:29 -0700 | [diff] [blame] | 187 | mSnapAlgorithm = new PipSnapAlgorithm(mContext); |
Mady Mellor | 15b29c7 | 2017-06-07 14:53:58 -0700 | [diff] [blame] | 188 | mFlingAnimationUtils = new FlingAnimationUtils(context, 2.5f); |
Winson Chung | a5acf18 | 2017-01-05 16:02:27 -0800 | [diff] [blame] | 189 | mGestures = new PipTouchGesture[] { |
Mady Mellor | d4e40fb | 2017-01-26 10:43:16 -0800 | [diff] [blame] | 190 | mDefaultMovementGesture |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 191 | }; |
Winson Chung | 79f852e | 2017-05-04 15:06:18 -0700 | [diff] [blame] | 192 | mMotionHelper = new PipMotionHelper(mContext, mActivityManager, mMenuController, |
| 193 | mSnapAlgorithm, mFlingAnimationUtils); |
Winson Chung | bca0311 | 2017-08-16 10:38:15 -0700 | [diff] [blame] | 194 | mTouchState = new PipTouchState(mViewConfig, mHandler, |
| 195 | () -> mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(), |
| 196 | mMovementBounds, true /* allowMenuTimeout */, willResizeMenu())); |
Winson Chung | 136d1ec8 | 2017-07-18 11:16:30 -0700 | [diff] [blame] | 197 | |
| 198 | Resources res = context.getResources(); |
| 199 | mExpandedShortestEdgeSize = res.getDimensionPixelSize( |
Mady Mellor | a7f6974 | 2017-02-03 11:00:20 -0800 | [diff] [blame] | 200 | R.dimen.pip_expanded_shortest_edge_size); |
Winson Chung | 136d1ec8 | 2017-07-18 11:16:30 -0700 | [diff] [blame] | 201 | mImeOffset = res.getDimensionPixelSize(R.dimen.pip_ime_offset); |
Winson Chung | d2d9097 | 2017-02-28 11:40:41 -0800 | [diff] [blame] | 202 | |
| 203 | // Register the listener for input consumer touch events |
| 204 | inputConsumerController.setTouchListener(this::handleTouchEvent); |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 205 | inputConsumerController.setRegistrationListener(this::onRegistrationChanged); |
| 206 | onRegistrationChanged(inputConsumerController.isRegistered()); |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 209 | public void setTouchEnabled(boolean enabled) { |
| 210 | mTouchState.setAllowTouches(enabled); |
| 211 | } |
| 212 | |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 213 | public void showPictureInPictureMenu() { |
| 214 | // Only show the menu if the user isn't currently interacting with the PiP |
| 215 | if (!mTouchState.isUserInteracting()) { |
Mady Mellor | 637cd48 | 2017-03-21 10:39:42 -0700 | [diff] [blame] | 216 | mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(), |
Winson Chung | bb78744 | 2017-09-01 11:33:47 -0700 | [diff] [blame] | 217 | mMovementBounds, false /* allowMenuTimeout */, willResizeMenu()); |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | |
Winson Chung | 929d4f7 | 2017-01-13 10:21:33 -0800 | [diff] [blame] | 221 | public void onActivityPinned() { |
Winson Chung | 9b91941 | 2017-06-19 17:01:51 -0700 | [diff] [blame] | 222 | cleanUp(); |
Wale Ogunwale | 6455e50 | 2017-04-17 14:16:43 -0700 | [diff] [blame] | 223 | mShowPipMenuOnAnimationEnd = true; |
Winson Chung | 929d4f7 | 2017-01-13 10:21:33 -0800 | [diff] [blame] | 224 | } |
| 225 | |
Winson Chung | 9b91941 | 2017-06-19 17:01:51 -0700 | [diff] [blame] | 226 | public void onActivityUnpinned(ComponentName topPipActivity) { |
| 227 | if (topPipActivity == null) { |
| 228 | // Clean up state after the last PiP activity is removed |
| 229 | cleanUp(); |
| 230 | } |
| 231 | } |
| 232 | |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 233 | public void onPinnedStackAnimationEnded() { |
| 234 | // Always synchronize the motion helper bounds once PiP animations finish |
| 235 | mMotionHelper.synchronizePinnedStackBounds(); |
Wale Ogunwale | 6455e50 | 2017-04-17 14:16:43 -0700 | [diff] [blame] | 236 | |
| 237 | if (mShowPipMenuOnAnimationEnd) { |
| 238 | mMenuController.showMenu(MENU_STATE_CLOSE, mMotionHelper.getBounds(), |
Winson Chung | bb78744 | 2017-09-01 11:33:47 -0700 | [diff] [blame] | 239 | mMovementBounds, true /* allowMenuTimeout */, false /* willResizeMenu */); |
Wale Ogunwale | 6455e50 | 2017-04-17 14:16:43 -0700 | [diff] [blame] | 240 | mShowPipMenuOnAnimationEnd = false; |
| 241 | } |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Winson Chung | 303c6b7 | 2016-10-24 17:12:49 -0700 | [diff] [blame] | 244 | public void onConfigurationChanged() { |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 245 | mMotionHelper.onConfigurationChanged(); |
| 246 | mMotionHelper.synchronizePinnedStackBounds(); |
Winson Chung | 303c6b7 | 2016-10-24 17:12:49 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 249 | public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) { |
| 250 | mIsImeShowing = imeVisible; |
| 251 | mImeHeight = imeHeight; |
| 252 | } |
| 253 | |
Tracy Zhou | 4351308 | 2018-03-08 21:58:36 -0800 | [diff] [blame] | 254 | public void onShelfVisibilityChanged(boolean shelfVisible, int shelfHeight) { |
| 255 | mIsShelfShowing = shelfVisible; |
| 256 | mShelfHeight = shelfHeight; |
| 257 | } |
| 258 | |
Winson Chung | baa7b72 | 2017-03-03 21:33:44 -0800 | [diff] [blame] | 259 | public void onMovementBoundsChanged(Rect insetBounds, Rect normalBounds, Rect animatingBounds, |
Tracy Zhou | 4351308 | 2018-03-08 21:58:36 -0800 | [diff] [blame] | 260 | boolean fromImeAdjustment, boolean fromShelfAdjustment, int displayRotation) { |
| 261 | final int bottomOffset = mIsImeShowing ? mImeHeight : 0; |
| 262 | |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 263 | // Re-calculate the expanded bounds |
| 264 | mNormalBounds = normalBounds; |
| 265 | Rect normalMovementBounds = new Rect(); |
| 266 | mSnapAlgorithm.getMovementBounds(mNormalBounds, insetBounds, normalMovementBounds, |
Tracy Zhou | 4351308 | 2018-03-08 21:58:36 -0800 | [diff] [blame] | 267 | bottomOffset); |
Mady Mellor | a7f6974 | 2017-02-03 11:00:20 -0800 | [diff] [blame] | 268 | |
| 269 | // Calculate the expanded size |
| 270 | float aspectRatio = (float) normalBounds.width() / normalBounds.height(); |
| 271 | Point displaySize = new Point(); |
| 272 | mContext.getDisplay().getRealSize(displaySize); |
| 273 | Size expandedSize = mSnapAlgorithm.getSizeForAspectRatio(aspectRatio, |
| 274 | mExpandedShortestEdgeSize, displaySize.x, displaySize.y); |
| 275 | mExpandedBounds.set(0, 0, expandedSize.getWidth(), expandedSize.getHeight()); |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 276 | Rect expandedMovementBounds = new Rect(); |
| 277 | mSnapAlgorithm.getMovementBounds(mExpandedBounds, insetBounds, expandedMovementBounds, |
Tracy Zhou | 4351308 | 2018-03-08 21:58:36 -0800 | [diff] [blame] | 278 | bottomOffset); |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 279 | |
Tracy Zhou | 4351308 | 2018-03-08 21:58:36 -0800 | [diff] [blame] | 280 | // If this is from an IME or shelf adjustment, then we should move the PiP so that it is not |
| 281 | // occluded by the IME or shelf. |
| 282 | if (fromImeAdjustment || fromShelfAdjustment) { |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 283 | if (mTouchState.isUserInteracting()) { |
| 284 | // Defer the update of the current movement bounds until after the user finishes |
| 285 | // touching the screen |
| 286 | } else { |
Tracy Zhou | 4be72d2 | 2018-03-22 11:41:00 -0700 | [diff] [blame] | 287 | final int adjustedOffset = Math.max(mIsImeShowing ? mImeHeight + mImeOffset : 0, |
| 288 | mIsShelfShowing ? mShelfHeight : 0); |
| 289 | Rect normalAdjustedBounds = new Rect(); |
| 290 | mSnapAlgorithm.getMovementBounds(mNormalBounds, insetBounds, normalAdjustedBounds, |
| 291 | adjustedOffset); |
| 292 | Rect expandedAdjustedBounds = new Rect(); |
| 293 | mSnapAlgorithm.getMovementBounds(mExpandedBounds, insetBounds, |
| 294 | expandedAdjustedBounds, adjustedOffset); |
| 295 | final Rect toAdjustedBounds = mMenuState == MENU_STATE_FULL |
| 296 | ? expandedAdjustedBounds |
| 297 | : normalAdjustedBounds; |
| 298 | |
| 299 | animateToOffset(animatingBounds, toAdjustedBounds); |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 300 | } |
Winson Chung | 14fbe14 | 2016-12-19 16:18:24 -0800 | [diff] [blame] | 301 | } |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 302 | |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 303 | // Update the movement bounds after doing the calculations based on the old movement bounds |
| 304 | // above |
| 305 | mNormalMovementBounds = normalMovementBounds; |
| 306 | mExpandedMovementBounds = expandedMovementBounds; |
Winson Chung | ef4dc81 | 2017-04-11 13:31:44 -0700 | [diff] [blame] | 307 | mDisplayRotation = displayRotation; |
Winson Chung | 0a2f34f | 2017-08-11 18:13:24 -0700 | [diff] [blame] | 308 | mInsetBounds.set(insetBounds); |
Mady Mellor | 637cd48 | 2017-03-21 10:39:42 -0700 | [diff] [blame] | 309 | updateMovementBounds(mMenuState); |
Winson Chung | ef4dc81 | 2017-04-11 13:31:44 -0700 | [diff] [blame] | 310 | |
| 311 | // If we have a deferred resize, apply it now |
| 312 | if (mDeferResizeToNormalBoundsUntilRotation == displayRotation) { |
| 313 | mMotionHelper.animateToUnexpandedState(normalBounds, mSavedSnapFraction, |
| 314 | mNormalMovementBounds, mMovementBounds, mIsMinimized, |
| 315 | true /* immediate */); |
| 316 | mSavedSnapFraction = -1f; |
| 317 | mDeferResizeToNormalBoundsUntilRotation = -1; |
| 318 | } |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 319 | } |
| 320 | |
Tracy Zhou | 4be72d2 | 2018-03-22 11:41:00 -0700 | [diff] [blame] | 321 | private void animateToOffset(Rect animatingBounds, Rect toAdjustedBounds) { |
Tracy Zhou | 4351308 | 2018-03-08 21:58:36 -0800 | [diff] [blame] | 322 | final Rect bounds = new Rect(animatingBounds); |
Tracy Zhou | 4be72d2 | 2018-03-22 11:41:00 -0700 | [diff] [blame] | 323 | if (toAdjustedBounds.bottom < mMovementBounds.bottom |
| 324 | && bounds.top < toAdjustedBounds.bottom) { |
| 325 | return; |
Tracy Zhou | 4351308 | 2018-03-08 21:58:36 -0800 | [diff] [blame] | 326 | } |
Tracy Zhou | 4be72d2 | 2018-03-22 11:41:00 -0700 | [diff] [blame] | 327 | bounds.offset(0, toAdjustedBounds.bottom - bounds.top); |
Tracy Zhou | 4351308 | 2018-03-08 21:58:36 -0800 | [diff] [blame] | 328 | mMotionHelper.animateToOffset(bounds); |
| 329 | } |
| 330 | |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 331 | private void onRegistrationChanged(boolean isRegistered) { |
| 332 | mAccessibilityManager.setPictureInPictureActionReplacingConnection(isRegistered |
Winson Chung | fe1fa64 | 2017-03-13 10:51:22 -0700 | [diff] [blame] | 333 | ? new PipAccessibilityInteractionConnection(mMotionHelper, |
| 334 | this::onAccessibilityShowMenu, mHandler) : null); |
Winson Chung | b54b65b | 2017-04-26 14:02:13 -0700 | [diff] [blame] | 335 | |
| 336 | if (!isRegistered && mTouchState.isUserInteracting()) { |
| 337 | // If the input consumer is unregistered while the user is interacting, then we may not |
| 338 | // get the final TOUCH_UP event, so clean up the dismiss target as well |
| 339 | cleanUpDismissTarget(); |
| 340 | } |
Winson Chung | fe1fa64 | 2017-03-13 10:51:22 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | private void onAccessibilityShowMenu() { |
Mady Mellor | 637cd48 | 2017-03-21 10:39:42 -0700 | [diff] [blame] | 344 | mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(), |
Winson Chung | bb78744 | 2017-09-01 11:33:47 -0700 | [diff] [blame] | 345 | mMovementBounds, false /* allowMenuTimeout */, willResizeMenu()); |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 346 | } |
| 347 | |
Winson Chung | 15504af | 2016-11-02 18:11:36 -0700 | [diff] [blame] | 348 | private boolean handleTouchEvent(MotionEvent ev) { |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 349 | // Skip touch handling until we are bound to the controller |
| 350 | if (mPinnedStackController == null) { |
Winson Chung | 15504af | 2016-11-02 18:11:36 -0700 | [diff] [blame] | 351 | return true; |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 354 | // Update the touch state |
| 355 | mTouchState.onTouchEvent(ev); |
| 356 | |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 357 | switch (ev.getAction()) { |
| 358 | case MotionEvent.ACTION_DOWN: { |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 359 | mMotionHelper.synchronizePinnedStackBounds(); |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 360 | |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 361 | for (PipTouchGesture gesture : mGestures) { |
| 362 | gesture.onDown(mTouchState); |
| 363 | } |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 364 | break; |
| 365 | } |
| 366 | case MotionEvent.ACTION_MOVE: { |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 367 | for (PipTouchGesture gesture : mGestures) { |
| 368 | if (gesture.onMove(mTouchState)) { |
| 369 | break; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 370 | } |
| 371 | } |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 372 | break; |
| 373 | } |
| 374 | case MotionEvent.ACTION_UP: { |
Winson Chung | 14fefc2 | 2016-11-02 10:02:29 -0700 | [diff] [blame] | 375 | // Update the movement bounds again if the state has changed since the user started |
| 376 | // dragging (ie. when the IME shows) |
Mady Mellor | 637cd48 | 2017-03-21 10:39:42 -0700 | [diff] [blame] | 377 | updateMovementBounds(mMenuState); |
Winson Chung | 14fefc2 | 2016-11-02 10:02:29 -0700 | [diff] [blame] | 378 | |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 379 | for (PipTouchGesture gesture : mGestures) { |
| 380 | if (gesture.onUp(mTouchState)) { |
| 381 | break; |
Winson Chung | 5cd26ff | 2016-10-24 11:50:44 -0700 | [diff] [blame] | 382 | } |
Winson Chung | 5cd26ff | 2016-10-24 11:50:44 -0700 | [diff] [blame] | 383 | } |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 384 | |
| 385 | // Fall through to clean up |
| 386 | } |
| 387 | case MotionEvent.ACTION_CANCEL: { |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 388 | mTouchState.reset(); |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 389 | break; |
| 390 | } |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 391 | case MotionEvent.ACTION_HOVER_ENTER: |
| 392 | case MotionEvent.ACTION_HOVER_MOVE: { |
Eugene Susla | d4128ec | 2017-12-04 19:48:41 +0000 | [diff] [blame] | 393 | if (mAccessibilityManager.isEnabled() && !mSendingHoverAccessibilityEvents) { |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 394 | AccessibilityEvent event = AccessibilityEvent.obtain( |
| 395 | AccessibilityEvent.TYPE_VIEW_HOVER_ENTER); |
Phil Weaver | 0a8caa1 | 2017-08-09 11:28:41 -0700 | [diff] [blame] | 396 | event.setImportantForAccessibility(true); |
Phil Weaver | 651fe9f | 2017-05-24 16:43:46 -0700 | [diff] [blame] | 397 | event.setSourceNodeId(AccessibilityNodeInfo.ROOT_NODE_ID); |
Phil Weaver | 0a8caa1 | 2017-08-09 11:28:41 -0700 | [diff] [blame] | 398 | event.setWindowId( |
| 399 | AccessibilityWindowInfo.PICTURE_IN_PICTURE_ACTION_REPLACER_WINDOW_ID); |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 400 | mAccessibilityManager.sendAccessibilityEvent(event); |
| 401 | mSendingHoverAccessibilityEvents = true; |
| 402 | } |
| 403 | break; |
| 404 | } |
| 405 | case MotionEvent.ACTION_HOVER_EXIT: { |
Eugene Susla | d4128ec | 2017-12-04 19:48:41 +0000 | [diff] [blame] | 406 | if (mAccessibilityManager.isEnabled() && mSendingHoverAccessibilityEvents) { |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 407 | AccessibilityEvent event = AccessibilityEvent.obtain( |
| 408 | AccessibilityEvent.TYPE_VIEW_HOVER_EXIT); |
Phil Weaver | 0a8caa1 | 2017-08-09 11:28:41 -0700 | [diff] [blame] | 409 | event.setImportantForAccessibility(true); |
Phil Weaver | 651fe9f | 2017-05-24 16:43:46 -0700 | [diff] [blame] | 410 | event.setSourceNodeId(AccessibilityNodeInfo.ROOT_NODE_ID); |
Phil Weaver | 0a8caa1 | 2017-08-09 11:28:41 -0700 | [diff] [blame] | 411 | event.setWindowId( |
| 412 | AccessibilityWindowInfo.PICTURE_IN_PICTURE_ACTION_REPLACER_WINDOW_ID); |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 413 | mAccessibilityManager.sendAccessibilityEvent(event); |
| 414 | mSendingHoverAccessibilityEvents = false; |
| 415 | } |
| 416 | break; |
| 417 | } |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 418 | } |
Mady Mellor | 637cd48 | 2017-03-21 10:39:42 -0700 | [diff] [blame] | 419 | return mMenuState == MENU_STATE_NONE; |
Winson Chung | 15504af | 2016-11-02 18:11:36 -0700 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | /** |
Mady Mellor | 81d4061 | 2017-03-10 15:14:10 -0800 | [diff] [blame] | 423 | * Updates the appearance of the menu and scrim on top of the PiP while dismissing. |
| 424 | */ |
Winson Chung | 8ec0e16 | 2017-07-07 14:49:49 -0700 | [diff] [blame] | 425 | private void updateDismissFraction() { |
Winson Chung | 0a2f34f | 2017-08-11 18:13:24 -0700 | [diff] [blame] | 426 | // Skip updating the dismiss fraction when the IME is showing. This is to work around an |
| 427 | // issue where starting the menu activity for the dismiss overlay will steal the window |
| 428 | // focus, which closes the IME. |
| 429 | if (mMenuController != null && !mIsImeShowing) { |
Mady Mellor | 81d4061 | 2017-03-10 15:14:10 -0800 | [diff] [blame] | 430 | Rect bounds = mMotionHelper.getBounds(); |
Winson Chung | 0a2f34f | 2017-08-11 18:13:24 -0700 | [diff] [blame] | 431 | final float target = mInsetBounds.bottom; |
Mady Mellor | 81d4061 | 2017-03-10 15:14:10 -0800 | [diff] [blame] | 432 | float fraction = 0f; |
| 433 | if (bounds.bottom > target) { |
| 434 | final float distance = bounds.bottom - target; |
| 435 | fraction = Math.min(distance / bounds.height(), 1f); |
| 436 | } |
Winson Chung | bca0311 | 2017-08-16 10:38:15 -0700 | [diff] [blame] | 437 | if (Float.compare(fraction, 0f) != 0 || mMenuController.isMenuActivityVisible()) { |
Winson Chung | 87e5d55 | 2017-04-05 11:49:38 -0700 | [diff] [blame] | 438 | // Update if the fraction > 0, or if fraction == 0 and the menu was already visible |
| 439 | mMenuController.setDismissFraction(fraction); |
| 440 | } |
Mady Mellor | 81d4061 | 2017-03-10 15:14:10 -0800 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | |
| 444 | /** |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 445 | * Sets the controller to update the system of changes from user interaction. |
| 446 | */ |
| 447 | void setPinnedStackController(IPinnedStackController controller) { |
| 448 | mPinnedStackController = controller; |
| 449 | } |
| 450 | |
| 451 | /** |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 452 | * Sets the minimized state. |
Winson Chung | dff5c08 | 2016-11-02 17:28:03 -0700 | [diff] [blame] | 453 | */ |
Winson Chung | 8ec0e16 | 2017-07-07 14:49:49 -0700 | [diff] [blame] | 454 | private void setMinimizedStateInternal(boolean isMinimized) { |
Mady Mellor | 8c7dc42 | 2017-05-10 12:55:06 -0700 | [diff] [blame] | 455 | if (!ENABLE_MINIMIZE) { |
Mady Mellor | 2e13878 | 2017-03-27 11:09:50 -0700 | [diff] [blame] | 456 | return; |
| 457 | } |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 458 | setMinimizedState(isMinimized, false /* fromController */); |
Winson Chung | dff5c08 | 2016-11-02 17:28:03 -0700 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | /** |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 462 | * Sets the minimized state. |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 463 | */ |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 464 | void setMinimizedState(boolean isMinimized, boolean fromController) { |
Mady Mellor | 8c7dc42 | 2017-05-10 12:55:06 -0700 | [diff] [blame] | 465 | if (!ENABLE_MINIMIZE) { |
Mady Mellor | 2e13878 | 2017-03-27 11:09:50 -0700 | [diff] [blame] | 466 | return; |
| 467 | } |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 468 | if (mIsMinimized != isMinimized) { |
Chenjie Yu | ae9fdf04 | 2018-02-15 10:19:32 -0800 | [diff] [blame] | 469 | MetricsLoggerWrapper.logPictureInPictureMinimize(mContext, |
| 470 | isMinimized, PipUtils.getTopPinnedActivity(mContext, mActivityManager)); |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 471 | } |
| 472 | mIsMinimized = isMinimized; |
| 473 | mSnapAlgorithm.setMinimized(isMinimized); |
Winson Chung | 54f0c65 | 2016-12-06 14:46:31 -0800 | [diff] [blame] | 474 | |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 475 | if (fromController) { |
| 476 | if (isMinimized) { |
| 477 | // Move the PiP to the new bounds immediately if minimized |
| 478 | mMotionHelper.movePip(mMotionHelper.getClosestMinimizedBounds(mNormalBounds, |
| 479 | mMovementBounds)); |
| 480 | } |
| 481 | } else if (mPinnedStackController != null) { |
Winson Chung | 54f0c65 | 2016-12-06 14:46:31 -0800 | [diff] [blame] | 482 | try { |
| 483 | mPinnedStackController.setIsMinimized(isMinimized); |
| 484 | } catch (RemoteException e) { |
| 485 | Log.e(TAG, "Could not set minimized state", e); |
| 486 | } |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 487 | } |
| 488 | } |
| 489 | |
| 490 | /** |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 491 | * Sets the menu visibility. |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 492 | */ |
Winson Chung | 8ec0e16 | 2017-07-07 14:49:49 -0700 | [diff] [blame] | 493 | private void setMenuState(int menuState, boolean resize) { |
Mady Mellor | 637cd48 | 2017-03-21 10:39:42 -0700 | [diff] [blame] | 494 | if (menuState == MENU_STATE_FULL) { |
Winson Chung | d2d9097 | 2017-02-28 11:40:41 -0800 | [diff] [blame] | 495 | // Save the current snap fraction and if we do not drag or move the PiP, then |
| 496 | // we store back to this snap fraction. Otherwise, we'll reset the snap |
| 497 | // fraction and snap to the closest edge |
| 498 | Rect expandedBounds = new Rect(mExpandedBounds); |
| 499 | if (resize) { |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 500 | mSavedSnapFraction = mMotionHelper.animateToExpandedState(expandedBounds, |
| 501 | mMovementBounds, mExpandedMovementBounds); |
Winson Chung | d2d9097 | 2017-02-28 11:40:41 -0800 | [diff] [blame] | 502 | } |
Mady Mellor | 637cd48 | 2017-03-21 10:39:42 -0700 | [diff] [blame] | 503 | } else if (menuState == MENU_STATE_NONE) { |
Winson Chung | d2d9097 | 2017-02-28 11:40:41 -0800 | [diff] [blame] | 504 | // Try and restore the PiP to the closest edge, using the saved snap fraction |
| 505 | // if possible |
| 506 | if (resize) { |
Winson Chung | ef4dc81 | 2017-04-11 13:31:44 -0700 | [diff] [blame] | 507 | if (mDeferResizeToNormalBoundsUntilRotation == -1) { |
Winson Chung | bb23376 | 2017-05-15 14:20:46 -0700 | [diff] [blame] | 508 | // This is a very special case: when the menu is expanded and visible, |
| 509 | // navigating to another activity can trigger auto-enter PiP, and if the |
| 510 | // revealed activity has a forced rotation set, then the controller will get |
| 511 | // updated with the new rotation of the display. However, at the same time, |
| 512 | // SystemUI will try to hide the menu by creating an animation to the normal |
| 513 | // bounds which are now stale. In such a case we defer the animation to the |
| 514 | // normal bounds until after the next onMovementBoundsChanged() call to get the |
| 515 | // bounds in the new orientation |
Winson Chung | ef4dc81 | 2017-04-11 13:31:44 -0700 | [diff] [blame] | 516 | try { |
| 517 | int displayRotation = mPinnedStackController.getDisplayRotation(); |
| 518 | if (mDisplayRotation != displayRotation) { |
| 519 | mDeferResizeToNormalBoundsUntilRotation = displayRotation; |
| 520 | } |
| 521 | } catch (RemoteException e) { |
| 522 | Log.e(TAG, "Could not get display rotation from controller"); |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | if (mDeferResizeToNormalBoundsUntilRotation == -1) { |
| 527 | Rect normalBounds = new Rect(mNormalBounds); |
| 528 | mMotionHelper.animateToUnexpandedState(normalBounds, mSavedSnapFraction, |
| 529 | mNormalMovementBounds, mMovementBounds, mIsMinimized, |
| 530 | false /* immediate */); |
| 531 | mSavedSnapFraction = -1f; |
| 532 | } |
| 533 | } else { |
Winson Chung | bb23376 | 2017-05-15 14:20:46 -0700 | [diff] [blame] | 534 | // If resizing is not allowed, then the PiP should be frozen until the transition |
| 535 | // ends as well |
| 536 | setTouchEnabled(false); |
Winson Chung | ef4dc81 | 2017-04-11 13:31:44 -0700 | [diff] [blame] | 537 | mSavedSnapFraction = -1f; |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 538 | } |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 539 | } |
Mady Mellor | 637cd48 | 2017-03-21 10:39:42 -0700 | [diff] [blame] | 540 | mMenuState = menuState; |
| 541 | updateMovementBounds(menuState); |
| 542 | if (menuState != MENU_STATE_CLOSE) { |
Chenjie Yu | 52cacc6 | 2017-12-08 18:11:45 -0800 | [diff] [blame] | 543 | MetricsLoggerWrapper.logPictureInPictureMenuVisible(mContext, menuState == MENU_STATE_FULL); |
Mady Mellor | 637cd48 | 2017-03-21 10:39:42 -0700 | [diff] [blame] | 544 | } |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | /** |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 548 | * @return the motion helper. |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 549 | */ |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 550 | public PipMotionHelper getMotionHelper() { |
| 551 | return mMotionHelper; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 552 | } |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 553 | |
| 554 | /** |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 555 | * Gesture controlling normal movement of the PIP. |
| 556 | */ |
| 557 | private PipTouchGesture mDefaultMovementGesture = new PipTouchGesture() { |
Mady Mellor | 2fbdd3b | 2017-03-21 17:45:00 -0700 | [diff] [blame] | 558 | // Whether the PiP was on the left side of the screen at the start of the gesture |
| 559 | private boolean mStartedOnLeft; |
Winson Chung | 8ec0e16 | 2017-07-07 14:49:49 -0700 | [diff] [blame] | 560 | private final Point mStartPosition = new Point(); |
| 561 | private final PointF mDelta = new PointF(); |
Mady Mellor | d4e40fb | 2017-01-26 10:43:16 -0800 | [diff] [blame] | 562 | |
| 563 | @Override |
| 564 | public void onDown(PipTouchState touchState) { |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 565 | if (!touchState.isUserInteracting()) { |
| 566 | return; |
| 567 | } |
| 568 | |
Mady Mellor | 15b29c7 | 2017-06-07 14:53:58 -0700 | [diff] [blame] | 569 | Rect bounds = mMotionHelper.getBounds(); |
Winson Chung | 8ec0e16 | 2017-07-07 14:49:49 -0700 | [diff] [blame] | 570 | mDelta.set(0f, 0f); |
| 571 | mStartPosition.set(bounds.left, bounds.top); |
Mady Mellor | 15b29c7 | 2017-06-07 14:53:58 -0700 | [diff] [blame] | 572 | mStartedOnLeft = bounds.left < mMovementBounds.centerX(); |
Mady Mellor | 2fbdd3b | 2017-03-21 17:45:00 -0700 | [diff] [blame] | 573 | mMovementWithinMinimize = true; |
| 574 | mMovementWithinDismiss = touchState.getDownTouchPosition().y >= mMovementBounds.bottom; |
| 575 | |
Mady Mellor | a7f6974 | 2017-02-03 11:00:20 -0800 | [diff] [blame] | 576 | // If the menu is still visible, and we aren't minimized, then just poke the menu |
| 577 | // so that it will timeout after the user stops touching it |
Mady Mellor | 637cd48 | 2017-03-21 10:39:42 -0700 | [diff] [blame] | 578 | if (mMenuState != MENU_STATE_NONE && !mIsMinimized) { |
Mady Mellor | a7f6974 | 2017-02-03 11:00:20 -0800 | [diff] [blame] | 579 | mMenuController.pokeMenu(); |
| 580 | } |
| 581 | |
Mady Mellor | 60421c9 | 2017-03-29 15:27:37 -0700 | [diff] [blame] | 582 | if (ENABLE_DISMISS_DRAG_TO_EDGE) { |
Mady Mellor | d4e40fb | 2017-01-26 10:43:16 -0800 | [diff] [blame] | 583 | mDismissViewController.createDismissTarget(); |
| 584 | mHandler.postDelayed(mShowDismissAffordance, SHOW_DISMISS_AFFORDANCE_DELAY); |
| 585 | } |
| 586 | } |
| 587 | |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 588 | @Override |
| 589 | boolean onMove(PipTouchState touchState) { |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 590 | if (!touchState.isUserInteracting()) { |
| 591 | return false; |
| 592 | } |
| 593 | |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 594 | if (touchState.startedDragging()) { |
| 595 | mSavedSnapFraction = -1f; |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 596 | |
Winson Chung | b54b65b | 2017-04-26 14:02:13 -0700 | [diff] [blame] | 597 | if (ENABLE_DISMISS_DRAG_TO_EDGE) { |
| 598 | mHandler.removeCallbacks(mShowDismissAffordance); |
| 599 | mDismissViewController.showDismissTarget(); |
| 600 | } |
Mady Mellor | d4e40fb | 2017-01-26 10:43:16 -0800 | [diff] [blame] | 601 | } |
| 602 | |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 603 | if (touchState.isDragging()) { |
| 604 | // Move the pinned stack freely |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 605 | final PointF lastDelta = touchState.getLastTouchDelta(); |
Winson Chung | 8ec0e16 | 2017-07-07 14:49:49 -0700 | [diff] [blame] | 606 | float lastX = mStartPosition.x + mDelta.x; |
| 607 | float lastY = mStartPosition.y + mDelta.y; |
| 608 | float left = lastX + lastDelta.x; |
| 609 | float top = lastY + lastDelta.y; |
Mady Mellor | 8c7dc42 | 2017-05-10 12:55:06 -0700 | [diff] [blame] | 610 | if (!touchState.allowDraggingOffscreen() || !ENABLE_MINIMIZE) { |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 611 | left = Math.max(mMovementBounds.left, Math.min(mMovementBounds.right, left)); |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 612 | } |
Mady Mellor | 57d2255 | 2017-03-09 15:37:13 -0800 | [diff] [blame] | 613 | if (ENABLE_DISMISS_DRAG_TO_EDGE) { |
| 614 | // Allow pip to move past bottom bounds |
| 615 | top = Math.max(mMovementBounds.top, top); |
| 616 | } else { |
| 617 | top = Math.max(mMovementBounds.top, Math.min(mMovementBounds.bottom, top)); |
| 618 | } |
Winson Chung | 8ec0e16 | 2017-07-07 14:49:49 -0700 | [diff] [blame] | 619 | |
| 620 | // Add to the cumulative delta after bounding the position |
| 621 | mDelta.x += left - lastX; |
| 622 | mDelta.y += top - lastY; |
| 623 | |
| 624 | mTmpBounds.set(mMotionHelper.getBounds()); |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 625 | mTmpBounds.offsetTo((int) left, (int) top); |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 626 | mMotionHelper.movePip(mTmpBounds); |
| 627 | |
Mady Mellor | 81d4061 | 2017-03-10 15:14:10 -0800 | [diff] [blame] | 628 | if (ENABLE_DISMISS_DRAG_TO_EDGE) { |
| 629 | updateDismissFraction(); |
| 630 | } |
Mady Mellor | 2fbdd3b | 2017-03-21 17:45:00 -0700 | [diff] [blame] | 631 | |
| 632 | final PointF curPos = touchState.getLastTouchPosition(); |
| 633 | if (mMovementWithinMinimize) { |
| 634 | // Track if movement remains near starting edge to identify swipes to minimize |
| 635 | mMovementWithinMinimize = mStartedOnLeft |
| 636 | ? curPos.x <= mMovementBounds.left + mTmpBounds.width() |
| 637 | : curPos.x >= mMovementBounds.right; |
| 638 | } |
| 639 | if (mMovementWithinDismiss) { |
| 640 | // Track if movement remains near the bottom edge to identify swipe to dismiss |
| 641 | mMovementWithinDismiss = curPos.y >= mMovementBounds.bottom; |
| 642 | } |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 643 | return true; |
| 644 | } |
| 645 | return false; |
| 646 | } |
| 647 | |
| 648 | @Override |
| 649 | public boolean onUp(PipTouchState touchState) { |
Winson Chung | b54b65b | 2017-04-26 14:02:13 -0700 | [diff] [blame] | 650 | if (ENABLE_DISMISS_DRAG_TO_EDGE) { |
| 651 | // Clean up the dismiss target regardless of the touch state in case the touch |
| 652 | // enabled state changes while the user is interacting |
| 653 | cleanUpDismissTarget(); |
| 654 | } |
| 655 | |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 656 | if (!touchState.isUserInteracting()) { |
| 657 | return false; |
| 658 | } |
| 659 | |
Mady Mellor | 60421c9 | 2017-03-29 15:27:37 -0700 | [diff] [blame] | 660 | final PointF vel = touchState.getVelocity(); |
| 661 | final boolean isHorizontal = Math.abs(vel.x) > Math.abs(vel.y); |
| 662 | final float velocity = PointF.length(vel.x, vel.y); |
| 663 | final boolean isFling = velocity > mFlingAnimationUtils.getMinVelocityPxPerSecond(); |
Mady Mellor | 8c7dc42 | 2017-05-10 12:55:06 -0700 | [diff] [blame] | 664 | final boolean isUpWithinDimiss = ENABLE_FLING_DISMISS |
Mady Mellor | 47ba140 | 2017-04-04 17:25:43 -0700 | [diff] [blame] | 665 | && touchState.getLastTouchPosition().y >= mMovementBounds.bottom |
| 666 | && mMotionHelper.isGestureToDismissArea(mMotionHelper.getBounds(), vel.x, |
| 667 | vel.y, isFling); |
| 668 | final boolean isFlingToBot = isFling && vel.y > 0 && !isHorizontal |
| 669 | && (mMovementWithinDismiss || isUpWithinDimiss); |
Mady Mellor | 60421c9 | 2017-03-29 15:27:37 -0700 | [diff] [blame] | 670 | if (ENABLE_DISMISS_DRAG_TO_EDGE) { |
Winson Chung | b54b65b | 2017-04-26 14:02:13 -0700 | [diff] [blame] | 671 | // Check if the user dragged or flung the PiP offscreen to dismiss it |
| 672 | if (mMotionHelper.shouldDismissPip() || isFlingToBot) { |
Chenjie Yu | ae9fdf04 | 2018-02-15 10:19:32 -0800 | [diff] [blame] | 673 | MetricsLoggerWrapper.logPictureInPictureDismissByDrag(mContext, |
| 674 | PipUtils.getTopPinnedActivity(mContext, mActivityManager)); |
Winson Chung | b54b65b | 2017-04-26 14:02:13 -0700 | [diff] [blame] | 675 | mMotionHelper.animateDismiss(mMotionHelper.getBounds(), vel.x, |
| 676 | vel.y, mUpdateScrimListener); |
Winson Chung | b54b65b | 2017-04-26 14:02:13 -0700 | [diff] [blame] | 677 | return true; |
Mady Mellor | d4e40fb | 2017-01-26 10:43:16 -0800 | [diff] [blame] | 678 | } |
Mady Mellor | d4e40fb | 2017-01-26 10:43:16 -0800 | [diff] [blame] | 679 | } |
Winson Chung | d2d9097 | 2017-02-28 11:40:41 -0800 | [diff] [blame] | 680 | |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 681 | if (touchState.isDragging()) { |
Mady Mellor | 84a0f89 | 2017-03-27 14:10:46 -0700 | [diff] [blame] | 682 | final boolean isFlingToEdge = isFling && isHorizontal && mMovementWithinMinimize |
| 683 | && (mStartedOnLeft ? vel.x < 0 : vel.x > 0); |
Mady Mellor | 8c7dc42 | 2017-05-10 12:55:06 -0700 | [diff] [blame] | 684 | if (ENABLE_MINIMIZE && |
Mady Mellor | 2e13878 | 2017-03-27 11:09:50 -0700 | [diff] [blame] | 685 | !mIsMinimized && (mMotionHelper.shouldMinimizePip() || isFlingToEdge)) { |
Mady Mellor | 3b10dcd | 2017-01-23 10:08:35 -0800 | [diff] [blame] | 686 | // Pip should be minimized |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 687 | setMinimizedStateInternal(true); |
Mady Mellor | 637cd48 | 2017-03-21 10:39:42 -0700 | [diff] [blame] | 688 | if (mMenuState == MENU_STATE_FULL) { |
Winson Chung | d2d9097 | 2017-02-28 11:40:41 -0800 | [diff] [blame] | 689 | // If the user dragged the expanded PiP to the edge, then hiding the menu |
| 690 | // will trigger the PiP to be scaled back to the normal size with the |
| 691 | // minimize offset adjusted |
| 692 | mMenuController.hideMenu(); |
| 693 | } else { |
Mady Mellor | 81d4061 | 2017-03-10 15:14:10 -0800 | [diff] [blame] | 694 | mMotionHelper.animateToClosestMinimizedState(mMovementBounds, |
| 695 | mUpdateScrimListener); |
Winson Chung | d2d9097 | 2017-02-28 11:40:41 -0800 | [diff] [blame] | 696 | } |
Mady Mellor | 3b10dcd | 2017-01-23 10:08:35 -0800 | [diff] [blame] | 697 | return true; |
| 698 | } |
| 699 | if (mIsMinimized) { |
Winson Chung | d2d9097 | 2017-02-28 11:40:41 -0800 | [diff] [blame] | 700 | // If we're dragging and it wasn't a minimize gesture then we shouldn't be |
| 701 | // minimized. |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 702 | setMinimizedStateInternal(false); |
Mady Mellor | 3b10dcd | 2017-01-23 10:08:35 -0800 | [diff] [blame] | 703 | } |
| 704 | |
Winson Chung | 87e5d55 | 2017-04-05 11:49:38 -0700 | [diff] [blame] | 705 | AnimatorListenerAdapter postAnimationCallback = null; |
Mady Mellor | 637cd48 | 2017-03-21 10:39:42 -0700 | [diff] [blame] | 706 | if (mMenuState != MENU_STATE_NONE) { |
Winson Chung | 87e5d55 | 2017-04-05 11:49:38 -0700 | [diff] [blame] | 707 | // If the menu is still visible, and we aren't minimized, then just poke the |
| 708 | // menu so that it will timeout after the user stops touching it |
Mady Mellor | 637cd48 | 2017-03-21 10:39:42 -0700 | [diff] [blame] | 709 | mMenuController.showMenu(mMenuState, mMotionHelper.getBounds(), |
Winson Chung | bb78744 | 2017-09-01 11:33:47 -0700 | [diff] [blame] | 710 | mMovementBounds, true /* allowMenuTimeout */, willResizeMenu()); |
Winson Chung | 87e5d55 | 2017-04-05 11:49:38 -0700 | [diff] [blame] | 711 | } else { |
| 712 | // If the menu is not visible, then we can still be showing the activity for the |
| 713 | // dismiss overlay, so just finish it after the animation completes |
| 714 | postAnimationCallback = new AnimatorListenerAdapter() { |
| 715 | @Override |
| 716 | public void onAnimationEnd(Animator animation) { |
| 717 | mMenuController.hideMenu(); |
| 718 | } |
| 719 | }; |
Winson Chung | d2d9097 | 2017-02-28 11:40:41 -0800 | [diff] [blame] | 720 | } |
| 721 | |
Mady Mellor | 2fbdd3b | 2017-03-21 17:45:00 -0700 | [diff] [blame] | 722 | if (isFling) { |
Mady Mellor | 81d4061 | 2017-03-10 15:14:10 -0800 | [diff] [blame] | 723 | mMotionHelper.flingToSnapTarget(velocity, vel.x, vel.y, mMovementBounds, |
Mady Mellor | 15b29c7 | 2017-06-07 14:53:58 -0700 | [diff] [blame] | 724 | mUpdateScrimListener, postAnimationCallback, |
| 725 | mStartPosition); |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 726 | } else { |
Winson Chung | 87e5d55 | 2017-04-05 11:49:38 -0700 | [diff] [blame] | 727 | mMotionHelper.animateToClosestSnapTarget(mMovementBounds, mUpdateScrimListener, |
| 728 | postAnimationCallback); |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 729 | } |
Mady Mellor | 3b10dcd | 2017-01-23 10:08:35 -0800 | [diff] [blame] | 730 | } else if (mIsMinimized) { |
| 731 | // This was a tap, so no longer minimized |
Winson Chung | 87e5d55 | 2017-04-05 11:49:38 -0700 | [diff] [blame] | 732 | mMotionHelper.animateToClosestSnapTarget(mMovementBounds, null /* updateListener */, |
| 733 | null /* animatorListener */); |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 734 | setMinimizedStateInternal(false); |
Mady Mellor | 637cd48 | 2017-03-21 10:39:42 -0700 | [diff] [blame] | 735 | } else if (mMenuState != MENU_STATE_FULL) { |
Winson Chung | bca0311 | 2017-08-16 10:38:15 -0700 | [diff] [blame] | 736 | if (mTouchState.isDoubleTap()) { |
| 737 | // Expand to fullscreen if this is a double tap |
| 738 | mMotionHelper.expandPip(); |
| 739 | } else if (!mTouchState.isWaitingForDoubleTap()) { |
| 740 | // User has stalled long enough for this not to be a drag or a double tap, just |
| 741 | // expand the menu |
| 742 | mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(), |
| 743 | mMovementBounds, true /* allowMenuTimeout */, willResizeMenu()); |
| 744 | } else { |
| 745 | // Next touch event _may_ be the second tap for the double-tap, schedule a |
| 746 | // fallback runnable to trigger the menu if no touch event occurs before the |
| 747 | // next tap |
| 748 | mTouchState.scheduleDoubleTapTimeoutCallback(); |
| 749 | } |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 750 | } else { |
Winson Chung | be4a808 | 2017-04-13 13:52:04 -0700 | [diff] [blame] | 751 | mMenuController.hideMenu(); |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 752 | mMotionHelper.expandPip(); |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 753 | } |
| 754 | return true; |
| 755 | } |
| 756 | }; |
Mady Mellor | 3b10dcd | 2017-01-23 10:08:35 -0800 | [diff] [blame] | 757 | |
| 758 | /** |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 759 | * Updates the current movement bounds based on whether the menu is currently visible. |
| 760 | */ |
Mady Mellor | 637cd48 | 2017-03-21 10:39:42 -0700 | [diff] [blame] | 761 | private void updateMovementBounds(int menuState) { |
Winson Chung | a71febe | 2017-05-22 11:14:22 -0700 | [diff] [blame] | 762 | boolean isMenuExpanded = menuState == MENU_STATE_FULL; |
| 763 | mMovementBounds = isMenuExpanded |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 764 | ? mExpandedMovementBounds |
| 765 | : mNormalMovementBounds; |
Winson Chung | a71febe | 2017-05-22 11:14:22 -0700 | [diff] [blame] | 766 | try { |
| 767 | mPinnedStackController.setMinEdgeSize(isMenuExpanded ? mExpandedShortestEdgeSize : 0); |
| 768 | } catch (RemoteException e) { |
| 769 | Log.e(TAG, "Could not set minimized state", e); |
| 770 | } |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 771 | } |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 772 | |
Winson Chung | b54b65b | 2017-04-26 14:02:13 -0700 | [diff] [blame] | 773 | /** |
| 774 | * Removes the dismiss target and cancels any pending callbacks to show it. |
| 775 | */ |
| 776 | private void cleanUpDismissTarget() { |
| 777 | mHandler.removeCallbacks(mShowDismissAffordance); |
| 778 | mDismissViewController.destroyDismissTarget(); |
| 779 | } |
| 780 | |
Winson Chung | 9b91941 | 2017-06-19 17:01:51 -0700 | [diff] [blame] | 781 | /** |
| 782 | * Resets some states related to the touch handling. |
| 783 | */ |
| 784 | private void cleanUp() { |
| 785 | if (mIsMinimized) { |
| 786 | setMinimizedStateInternal(false); |
| 787 | } |
| 788 | cleanUpDismissTarget(); |
| 789 | } |
| 790 | |
Winson Chung | bb78744 | 2017-09-01 11:33:47 -0700 | [diff] [blame] | 791 | /** |
| 792 | * @return whether the menu will resize as a part of showing the full menu. |
| 793 | */ |
| 794 | private boolean willResizeMenu() { |
| 795 | return mExpandedBounds.width() != mNormalBounds.width() || |
| 796 | mExpandedBounds.height() != mNormalBounds.height(); |
| 797 | } |
| 798 | |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 799 | public void dump(PrintWriter pw, String prefix) { |
| 800 | final String innerPrefix = prefix + " "; |
| 801 | pw.println(prefix + TAG); |
| 802 | pw.println(innerPrefix + "mMovementBounds=" + mMovementBounds); |
| 803 | pw.println(innerPrefix + "mNormalBounds=" + mNormalBounds); |
| 804 | pw.println(innerPrefix + "mNormalMovementBounds=" + mNormalMovementBounds); |
| 805 | pw.println(innerPrefix + "mExpandedBounds=" + mExpandedBounds); |
| 806 | pw.println(innerPrefix + "mExpandedMovementBounds=" + mExpandedMovementBounds); |
Mady Mellor | 637cd48 | 2017-03-21 10:39:42 -0700 | [diff] [blame] | 807 | pw.println(innerPrefix + "mMenuState=" + mMenuState); |
Winson Chung | d2d9097 | 2017-02-28 11:40:41 -0800 | [diff] [blame] | 808 | pw.println(innerPrefix + "mIsMinimized=" + mIsMinimized); |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 809 | pw.println(innerPrefix + "mIsImeShowing=" + mIsImeShowing); |
| 810 | pw.println(innerPrefix + "mImeHeight=" + mImeHeight); |
Tracy Zhou | 4351308 | 2018-03-08 21:58:36 -0800 | [diff] [blame] | 811 | pw.println(innerPrefix + "mIsShelfShowing=" + mIsShelfShowing); |
| 812 | pw.println(innerPrefix + "mShelfHeight=" + mShelfHeight); |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 813 | pw.println(innerPrefix + "mSavedSnapFraction=" + mSavedSnapFraction); |
Mady Mellor | 60421c9 | 2017-03-29 15:27:37 -0700 | [diff] [blame] | 814 | pw.println(innerPrefix + "mEnableDragToEdgeDismiss=" + ENABLE_DISMISS_DRAG_TO_EDGE); |
Mady Mellor | 8c7dc42 | 2017-05-10 12:55:06 -0700 | [diff] [blame] | 815 | pw.println(innerPrefix + "mEnableMinimize=" + ENABLE_MINIMIZE); |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 816 | mSnapAlgorithm.dump(pw, innerPrefix); |
| 817 | mTouchState.dump(pw, innerPrefix); |
| 818 | mMotionHelper.dump(pw, innerPrefix); |
| 819 | } |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 820 | |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 821 | } |