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