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 | |
Arthur Hung | d52d119 | 2019-08-30 16:06:59 +0800 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
| 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 21 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 22 | import android.app.ActivityManager; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 23 | import android.app.ActivityTaskManager; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 24 | import android.app.IActivityManager; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 25 | import android.app.IActivityTaskManager; |
Winson Chung | 3535df2 | 2017-01-17 18:43:39 -0800 | [diff] [blame] | 26 | import android.content.ComponentName; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 27 | import android.content.Context; |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 28 | import android.content.pm.ParceledListSlice; |
Winson Chung | 0c5a592 | 2017-05-22 17:41:06 -0700 | [diff] [blame] | 29 | import android.content.res.Configuration; |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 30 | import android.graphics.Rect; |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 31 | import android.os.Handler; |
| 32 | import android.os.RemoteException; |
| 33 | import android.util.Log; |
Winson Chung | 85d3c8a | 2017-09-15 15:41:00 -0700 | [diff] [blame] | 34 | import android.util.Pair; |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 35 | import android.view.DisplayInfo; |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 36 | import android.view.IPinnedStackController; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 37 | |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 38 | import com.android.systemui.Dependency; |
| 39 | import com.android.systemui.UiOffloadThread; |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 40 | import com.android.systemui.broadcast.BroadcastDispatcher; |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 41 | import com.android.systemui.pip.BasePipManager; |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 42 | import com.android.systemui.pip.PipBoundsHandler; |
Winson Chung | aa35745 | 2017-10-31 11:35:30 -0700 | [diff] [blame] | 43 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Winson Chung | cbb15a9 | 2018-01-25 17:46:16 +0000 | [diff] [blame] | 44 | import com.android.systemui.shared.system.InputConsumerController; |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 45 | import com.android.systemui.shared.system.PinnedStackListenerForwarder.PinnedStackListener; |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 46 | import com.android.systemui.shared.system.TaskStackChangeListener; |
| 47 | import com.android.systemui.shared.system.WindowManagerWrapper; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 48 | |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 49 | import java.io.PrintWriter; |
| 50 | |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 51 | /** |
| 52 | * Manages the picture-in-picture (PIP) UI and states for Phones. |
| 53 | */ |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 54 | public class PipManager implements BasePipManager { |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 55 | private static final String TAG = "PipManager"; |
| 56 | |
| 57 | private static PipManager sPipController; |
| 58 | |
| 59 | private Context mContext; |
| 60 | private IActivityManager mActivityManager; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 61 | private IActivityTaskManager mActivityTaskManager; |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 62 | private Handler mHandler = new Handler(); |
| 63 | |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 64 | private final PinnedStackListener mPinnedStackListener = new PipManagerPinnedStackListener(); |
| 65 | private final DisplayInfo mTmpDisplayInfo = new DisplayInfo(); |
| 66 | private final Rect mTmpInsetBounds = new Rect(); |
| 67 | private final Rect mTmpNormalBounds = new Rect(); |
jorgegil@google.com | 62f735e | 2019-10-30 14:37:19 -0700 | [diff] [blame^] | 68 | private final Rect mReentryBounds = new Rect(); |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 69 | |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 70 | private PipBoundsHandler mPipBoundsHandler; |
Winson Chung | d2d9097 | 2017-02-28 11:40:41 -0800 | [diff] [blame] | 71 | private InputConsumerController mInputConsumerController; |
Winson Chung | 15504af | 2016-11-02 18:11:36 -0700 | [diff] [blame] | 72 | private PipMenuActivityController mMenuController; |
Winson Chung | 97a60d9 | 2017-01-18 16:01:53 -0800 | [diff] [blame] | 73 | private PipMediaController mMediaController; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 74 | private PipTouchHandler mTouchHandler; |
Winson Chung | 95bccdc | 2018-01-03 11:45:47 -0800 | [diff] [blame] | 75 | private PipAppOpsListener mAppOpsListener; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 76 | |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 77 | /** |
Winson Chung | 929d4f7 | 2017-01-13 10:21:33 -0800 | [diff] [blame] | 78 | * Handler for system task stack changes. |
| 79 | */ |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 80 | TaskStackChangeListener mTaskStackListener = new TaskStackChangeListener() { |
Winson Chung | 929d4f7 | 2017-01-13 10:21:33 -0800 | [diff] [blame] | 81 | @Override |
Wale Ogunwale | 89be576 | 2017-10-04 13:27:49 -0700 | [diff] [blame] | 82 | public void onActivityPinned(String packageName, int userId, int taskId, int stackId) { |
Winson Chung | 929d4f7 | 2017-01-13 10:21:33 -0800 | [diff] [blame] | 83 | mTouchHandler.onActivityPinned(); |
Winson Chung | 97a60d9 | 2017-01-18 16:01:53 -0800 | [diff] [blame] | 84 | mMediaController.onActivityPinned(); |
Winson Chung | d2d9097 | 2017-02-28 11:40:41 -0800 | [diff] [blame] | 85 | mMenuController.onActivityPinned(); |
Winson Chung | 95bccdc | 2018-01-03 11:45:47 -0800 | [diff] [blame] | 86 | mAppOpsListener.onActivityPinned(packageName); |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 87 | |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 88 | Dependency.get(UiOffloadThread.class).submit(() -> { |
| 89 | WindowManagerWrapper.getInstance().setPipVisibility(true); |
| 90 | }); |
Winson Chung | c81c0ce | 2017-03-17 12:27:30 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public void onActivityUnpinned() { |
Winson Chung | 85d3c8a | 2017-09-15 15:41:00 -0700 | [diff] [blame] | 95 | final Pair<ComponentName, Integer> topPipActivityInfo = PipUtils.getTopPinnedActivity( |
| 96 | mContext, mActivityManager); |
| 97 | final ComponentName topActivity = topPipActivityInfo.first; |
Winson Chung | 85d3c8a | 2017-09-15 15:41:00 -0700 | [diff] [blame] | 98 | mMenuController.onActivityUnpinned(); |
| 99 | mTouchHandler.onActivityUnpinned(topActivity); |
Winson Chung | 95bccdc | 2018-01-03 11:45:47 -0800 | [diff] [blame] | 100 | mAppOpsListener.onActivityUnpinned(); |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 101 | |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 102 | Dependency.get(UiOffloadThread.class).submit(() -> { |
| 103 | WindowManagerWrapper.getInstance().setPipVisibility(topActivity != null); |
| 104 | }); |
Winson Chung | 929d4f7 | 2017-01-13 10:21:33 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | @Override |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 108 | public void onPinnedStackAnimationStarted() { |
| 109 | // Disable touches while the animation is running |
| 110 | mTouchHandler.setTouchEnabled(false); |
| 111 | } |
| 112 | |
| 113 | @Override |
Winson Chung | 929d4f7 | 2017-01-13 10:21:33 -0800 | [diff] [blame] | 114 | public void onPinnedStackAnimationEnded() { |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 115 | // Re-enable touches after the animation completes |
| 116 | mTouchHandler.setTouchEnabled(true); |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 117 | mTouchHandler.onPinnedStackAnimationEnded(); |
Winson Chung | 3448824 | 2017-04-26 15:53:51 -0700 | [diff] [blame] | 118 | mMenuController.onPinnedStackAnimationEnded(); |
Winson Chung | 929d4f7 | 2017-01-13 10:21:33 -0800 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | @Override |
Winson Chung | e6385a2 | 2017-05-02 18:15:16 -0700 | [diff] [blame] | 122 | public void onPinnedActivityRestartAttempt(boolean clearedTask) { |
Winson Chung | e6385a2 | 2017-05-02 18:15:16 -0700 | [diff] [blame] | 123 | mTouchHandler.getMotionHelper().expandPip(clearedTask /* skipAnimation */); |
Winson Chung | 929d4f7 | 2017-01-13 10:21:33 -0800 | [diff] [blame] | 124 | } |
| 125 | }; |
| 126 | |
| 127 | /** |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 128 | * Handler for messages from the PIP controller. |
| 129 | */ |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 130 | private class PipManagerPinnedStackListener extends PinnedStackListener { |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 131 | @Override |
| 132 | public void onListenerRegistered(IPinnedStackController controller) { |
| 133 | mHandler.post(() -> { |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 134 | mPipBoundsHandler.setPinnedStackController(controller); |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 135 | mTouchHandler.setPinnedStackController(controller); |
| 136 | }); |
| 137 | } |
| 138 | |
| 139 | @Override |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 140 | public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) { |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 141 | mHandler.post(() -> { |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 142 | mPipBoundsHandler.onImeVisibilityChanged(imeVisible, imeHeight); |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 143 | mTouchHandler.onImeVisibilityChanged(imeVisible, imeHeight); |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 144 | }); |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public void onMinimizedStateChanged(boolean isMinimized) { |
| 149 | mHandler.post(() -> { |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 150 | mPipBoundsHandler.onMinimizedStateChanged(isMinimized); |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 151 | mTouchHandler.setMinimizedState(isMinimized, true /* fromController */); |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 152 | }); |
| 153 | } |
| 154 | |
| 155 | @Override |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 156 | public void onMovementBoundsChanged(Rect animatingBounds, boolean fromImeAdjustment, |
| 157 | boolean fromShelfAdjustment) { |
Hongwei Wang | 9b75180 | 2019-09-11 12:13:21 -0700 | [diff] [blame] | 158 | mHandler.post(() -> updateMovementBounds(animatingBounds, fromImeAdjustment, |
| 159 | fromShelfAdjustment)); |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public void onActionsChanged(ParceledListSlice actions) { |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 164 | mHandler.post(() -> mMenuController.setAppActions(actions)); |
| 165 | } |
| 166 | |
| 167 | @Override |
jorgegil@google.com | 62f735e | 2019-10-30 14:37:19 -0700 | [diff] [blame^] | 168 | public void onSaveReentryBounds(ComponentName componentName, Rect bounds) { |
| 169 | mHandler.post(() -> { |
| 170 | // On phones, the expansion animation that happens on pip tap before restoring |
| 171 | // to fullscreen makes it so that the bounds received here are the expanded |
| 172 | // bounds. We want to restore to the unexpanded bounds when re-entering pip, |
| 173 | // so we save the bounds before expansion (normal) instead of the current |
| 174 | // bounds. |
| 175 | mReentryBounds.set(mTouchHandler.getNormalBounds()); |
| 176 | // Apply the snap fraction of the current bounds to the normal bounds. |
| 177 | float snapFraction = mPipBoundsHandler.getSnapFraction(bounds); |
| 178 | mPipBoundsHandler.applySnapFraction(mReentryBounds, snapFraction); |
| 179 | // Save reentry bounds (normal non-expand bounds with current position applied). |
| 180 | mPipBoundsHandler.onSaveReentryBounds(componentName, mReentryBounds); |
| 181 | }); |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | @Override |
jorgegil@google.com | 62f735e | 2019-10-30 14:37:19 -0700 | [diff] [blame^] | 185 | public void onResetReentryBounds(ComponentName componentName) { |
| 186 | mHandler.post(() -> mPipBoundsHandler.onResetReentryBounds(componentName)); |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public void onDisplayInfoChanged(DisplayInfo displayInfo) { |
| 191 | mHandler.post(() -> mPipBoundsHandler.onDisplayInfoChanged(displayInfo)); |
| 192 | } |
| 193 | |
| 194 | @Override |
| 195 | public void onConfigurationChanged() { |
| 196 | mHandler.post(() -> mPipBoundsHandler.onConfigurationChanged()); |
| 197 | } |
| 198 | |
| 199 | @Override |
| 200 | public void onAspectRatioChanged(float aspectRatio) { |
| 201 | mHandler.post(() -> mPipBoundsHandler.onAspectRatioChanged(aspectRatio)); |
| 202 | } |
| 203 | |
| 204 | @Override |
| 205 | public void onPrepareAnimation(Rect sourceRectHint, float aspectRatio, Rect bounds) { |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 206 | mHandler.post(() -> { |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 207 | mPipBoundsHandler.onPrepareAnimation(sourceRectHint, aspectRatio, bounds); |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 208 | }); |
| 209 | } |
| 210 | } |
| 211 | |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 212 | private PipManager() {} |
| 213 | |
| 214 | /** |
| 215 | * Initializes {@link PipManager}. |
| 216 | */ |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 217 | public void initialize(Context context, BroadcastDispatcher broadcastDispatcher) { |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 218 | mContext = context; |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 219 | mActivityManager = ActivityManager.getService(); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 220 | mActivityTaskManager = ActivityTaskManager.getService(); |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 221 | |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 222 | try { |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 223 | WindowManagerWrapper.getInstance().addPinnedStackListener(mPinnedStackListener); |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 224 | } catch (RemoteException e) { |
| 225 | Log.e(TAG, "Failed to register pinned stack listener", e); |
| 226 | } |
Winson Chung | 2cf6ad8 | 2017-11-09 17:36:59 -0800 | [diff] [blame] | 227 | ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener); |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 228 | |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 229 | mPipBoundsHandler = new PipBoundsHandler(context); |
Winson Chung | cbb15a9 | 2018-01-25 17:46:16 +0000 | [diff] [blame] | 230 | mInputConsumerController = InputConsumerController.getPipInputConsumer(); |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 231 | mMediaController = new PipMediaController(context, mActivityManager, broadcastDispatcher); |
Winson Chung | d2d9097 | 2017-02-28 11:40:41 -0800 | [diff] [blame] | 232 | mMenuController = new PipMenuActivityController(context, mActivityManager, mMediaController, |
| 233 | mInputConsumerController); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 234 | mTouchHandler = new PipTouchHandler(context, mActivityManager, mActivityTaskManager, |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 235 | mMenuController, mInputConsumerController, mPipBoundsHandler); |
Winson Chung | 95bccdc | 2018-01-03 11:45:47 -0800 | [diff] [blame] | 236 | mAppOpsListener = new PipAppOpsListener(context, mActivityManager, |
| 237 | mTouchHandler.getMotionHelper()); |
Arthur Hung | d52d119 | 2019-08-30 16:06:59 +0800 | [diff] [blame] | 238 | |
| 239 | // If SystemUI restart, and it already existed a pinned stack, |
| 240 | // register the pip input consumer to ensure touch can send to it. |
| 241 | try { |
| 242 | ActivityManager.StackInfo stackInfo = mActivityTaskManager.getStackInfo( |
| 243 | WINDOWING_MODE_PINNED, ACTIVITY_TYPE_UNDEFINED); |
| 244 | if (stackInfo != null) { |
| 245 | mInputConsumerController.registerInputConsumer(); |
| 246 | } |
| 247 | } catch (RemoteException e) { |
| 248 | e.printStackTrace(); |
| 249 | } |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | /** |
| 253 | * Updates the PIP per configuration changed. |
| 254 | */ |
Winson Chung | 0c5a592 | 2017-05-22 17:41:06 -0700 | [diff] [blame] | 255 | public void onConfigurationChanged(Configuration newConfig) { |
Winson Chung | 303c6b7 | 2016-10-24 17:12:49 -0700 | [diff] [blame] | 256 | mTouchHandler.onConfigurationChanged(); |
| 257 | } |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 258 | |
| 259 | /** |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 260 | * Expands the PIP. |
| 261 | */ |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 262 | @Override |
| 263 | public void expandPip() { |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 264 | mTouchHandler.getMotionHelper().expandPip(false /* skipAnimation */); |
| 265 | } |
| 266 | |
| 267 | /** |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 268 | * Hides the PIP menu. |
| 269 | */ |
| 270 | @Override |
| 271 | public void hidePipMenu(Runnable onStartCallback, Runnable onEndCallback) { |
| 272 | mMenuController.hideMenu(onStartCallback, onEndCallback); |
| 273 | } |
| 274 | |
| 275 | /** |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 276 | * Sent from KEYCODE_WINDOW handler in PhoneWindowManager, to request the menu to be shown. |
| 277 | */ |
| 278 | public void showPictureInPictureMenu() { |
| 279 | mTouchHandler.showPictureInPictureMenu(); |
| 280 | } |
| 281 | |
| 282 | /** |
Hongwei Wang | 9b75180 | 2019-09-11 12:13:21 -0700 | [diff] [blame] | 283 | * Sets both shelf visibility and its height. |
| 284 | */ |
| 285 | @Override |
| 286 | public void setShelfHeight(boolean visible, int height) { |
| 287 | mHandler.post(() -> { |
| 288 | final boolean changed = mPipBoundsHandler.setShelfHeight(visible, height); |
| 289 | if (changed) { |
| 290 | mTouchHandler.onShelfVisibilityChanged(visible, height); |
| 291 | updateMovementBounds(mPipBoundsHandler.getLastDestinationBounds(), |
| 292 | false /* fromImeAdjustment */, true /* fromShelfAdjustment */); |
| 293 | } |
| 294 | }); |
| 295 | } |
| 296 | |
| 297 | private void updateMovementBounds(Rect animatingBounds, boolean fromImeAdjustment, |
| 298 | boolean fromShelfAdjustment) { |
| 299 | // Populate inset / normal bounds and DisplayInfo from mPipBoundsHandler first. |
| 300 | mPipBoundsHandler.onMovementBoundsChanged(mTmpInsetBounds, mTmpNormalBounds, |
| 301 | animatingBounds, mTmpDisplayInfo); |
| 302 | mTouchHandler.onMovementBoundsChanged(mTmpInsetBounds, mTmpNormalBounds, |
| 303 | animatingBounds, fromImeAdjustment, fromShelfAdjustment, |
| 304 | mTmpDisplayInfo.rotation); |
| 305 | } |
| 306 | |
| 307 | /** |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 308 | * Gets an instance of {@link PipManager}. |
| 309 | */ |
| 310 | public static PipManager getInstance() { |
| 311 | if (sPipController == null) { |
| 312 | sPipController = new PipManager(); |
| 313 | } |
| 314 | return sPipController; |
| 315 | } |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 316 | |
| 317 | public void dump(PrintWriter pw) { |
| 318 | final String innerPrefix = " "; |
| 319 | pw.println(TAG); |
Winson Chung | d2d9097 | 2017-02-28 11:40:41 -0800 | [diff] [blame] | 320 | mInputConsumerController.dump(pw, innerPrefix); |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 321 | mMenuController.dump(pw, innerPrefix); |
| 322 | mTouchHandler.dump(pw, innerPrefix); |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 323 | mPipBoundsHandler.dump(pw, innerPrefix); |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 324 | } |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 325 | } |