Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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.server.wm; |
| 18 | |
Wale Ogunwale | 59a73ca | 2015-09-14 12:54:50 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.DOCKED_STACK_CREATE_MODE_BOTTOM_OR_RIGHT; |
| 20 | import static android.app.ActivityManager.DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT; |
Chong Zhang | 87b2172 | 2015-09-21 15:39:51 -0700 | [diff] [blame] | 21 | import static android.app.ActivityManager.RESIZE_MODE_USER; |
Chong Zhang | 6de2ae8 | 2015-09-30 18:25:21 -0700 | [diff] [blame] | 22 | import static android.app.ActivityManager.RESIZE_MODE_USER_FORCED; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame^] | 23 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 24 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 25 | import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; |
Filip Gruszczynski | 57b6cce | 2015-10-06 09:50:51 -0700 | [diff] [blame] | 26 | import static com.android.server.wm.DimLayer.RESIZING_HINT_ALPHA; |
| 27 | import static com.android.server.wm.DimLayer.RESIZING_HINT_DURATION_MS; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame^] | 28 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
| 29 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING; |
| 30 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS; |
| 31 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 32 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Filip Gruszczynski | 57b6cce | 2015-10-06 09:50:51 -0700 | [diff] [blame] | 33 | import static com.android.server.wm.WindowManagerService.dipToPixel; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 34 | import static com.android.server.wm.WindowState.MINIMUM_VISIBLE_HEIGHT_IN_DP; |
| 35 | import static com.android.server.wm.WindowState.MINIMUM_VISIBLE_WIDTH_IN_DP; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 36 | |
| 37 | import android.annotation.IntDef; |
| 38 | import android.graphics.Point; |
| 39 | import android.graphics.Rect; |
| 40 | import android.os.Looper; |
| 41 | import android.os.Process; |
| 42 | import android.os.RemoteException; |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 43 | import android.os.Trace; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 44 | import android.util.DisplayMetrics; |
| 45 | import android.util.Slog; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame^] | 46 | import android.view.BatchedInputEventReceiver; |
Wale Ogunwale | 4f52bc6 | 2015-09-24 13:47:31 -0700 | [diff] [blame] | 47 | import android.view.Choreographer; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 48 | import android.view.Display; |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 49 | import android.view.DisplayInfo; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 50 | import android.view.InputChannel; |
| 51 | import android.view.InputDevice; |
| 52 | import android.view.InputEvent; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 53 | import android.view.MotionEvent; |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 54 | import android.view.SurfaceControl; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 55 | import android.view.WindowManager; |
| 56 | |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 57 | import com.android.server.input.InputApplicationHandle; |
| 58 | import com.android.server.input.InputWindowHandle; |
| 59 | import com.android.server.wm.WindowManagerService.H; |
| 60 | |
| 61 | import java.lang.annotation.Retention; |
| 62 | import java.lang.annotation.RetentionPolicy; |
| 63 | |
| 64 | class TaskPositioner implements DimLayer.DimLayerUser { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame^] | 65 | private static final String TAG = TAG_WITH_CLASS_NAME ? "TaskPositioner" : TAG_WM; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 66 | |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 67 | // The margin the pointer position has to be within the side of the screen to be |
| 68 | // considered at the side of the screen. |
Filip Gruszczynski | 57b6cce | 2015-10-06 09:50:51 -0700 | [diff] [blame] | 69 | static final int SIDE_MARGIN_DIP = 100; |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 70 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 71 | @IntDef(flag = true, |
| 72 | value = { |
| 73 | CTRL_NONE, |
| 74 | CTRL_LEFT, |
| 75 | CTRL_RIGHT, |
| 76 | CTRL_TOP, |
| 77 | CTRL_BOTTOM |
| 78 | }) |
| 79 | @Retention(RetentionPolicy.SOURCE) |
| 80 | @interface CtrlType {} |
| 81 | |
| 82 | private static final int CTRL_NONE = 0x0; |
| 83 | private static final int CTRL_LEFT = 0x1; |
| 84 | private static final int CTRL_RIGHT = 0x2; |
| 85 | private static final int CTRL_TOP = 0x4; |
| 86 | private static final int CTRL_BOTTOM = 0x8; |
| 87 | |
| 88 | private final WindowManagerService mService; |
| 89 | private WindowPositionerEventReceiver mInputEventReceiver; |
| 90 | private Display mDisplay; |
| 91 | private final DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 92 | private DimLayer mDimLayer; |
| 93 | @CtrlType |
| 94 | private int mCurrentDimSide; |
| 95 | private Rect mTmpRect = new Rect(); |
| 96 | private int mSideMargin; |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 97 | private int mMinVisibleWidth; |
| 98 | private int mMinVisibleHeight; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 99 | |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 100 | private Task mTask; |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 101 | private boolean mResizing; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 102 | private final Rect mWindowOriginalBounds = new Rect(); |
| 103 | private final Rect mWindowDragBounds = new Rect(); |
| 104 | private float mStartDragX; |
| 105 | private float mStartDragY; |
| 106 | @CtrlType |
| 107 | private int mCtrlType = CTRL_NONE; |
Wale Ogunwale | 6a804b8 | 2015-09-23 21:04:21 -0700 | [diff] [blame] | 108 | private boolean mDragEnded = false; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 109 | |
| 110 | InputChannel mServerChannel; |
| 111 | InputChannel mClientChannel; |
| 112 | InputApplicationHandle mDragApplicationHandle; |
| 113 | InputWindowHandle mDragWindowHandle; |
| 114 | |
Wale Ogunwale | 4f52bc6 | 2015-09-24 13:47:31 -0700 | [diff] [blame] | 115 | private final class WindowPositionerEventReceiver extends BatchedInputEventReceiver { |
| 116 | public WindowPositionerEventReceiver( |
| 117 | InputChannel inputChannel, Looper looper, Choreographer choreographer) { |
| 118 | super(inputChannel, looper, choreographer); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public void onInputEvent(InputEvent event) { |
| 123 | if (!(event instanceof MotionEvent) |
| 124 | || (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 125 | return; |
| 126 | } |
| 127 | final MotionEvent motionEvent = (MotionEvent) event; |
| 128 | boolean handled = false; |
| 129 | |
| 130 | try { |
Wale Ogunwale | 6a804b8 | 2015-09-23 21:04:21 -0700 | [diff] [blame] | 131 | if (mDragEnded) { |
| 132 | // The drag has ended but the clean-up message has not been processed by |
| 133 | // window manager. Drop events that occur after this until window manager |
| 134 | // has a chance to clean-up the input handle. |
| 135 | handled = true; |
| 136 | return; |
| 137 | } |
| 138 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 139 | final float newX = motionEvent.getRawX(); |
| 140 | final float newY = motionEvent.getRawY(); |
| 141 | |
| 142 | switch (motionEvent.getAction()) { |
| 143 | case MotionEvent.ACTION_DOWN: { |
| 144 | if (DEBUG_TASK_POSITIONING) { |
| 145 | Slog.w(TAG, "ACTION_DOWN @ {" + newX + ", " + newY + "}"); |
| 146 | } |
| 147 | } break; |
| 148 | |
| 149 | case MotionEvent.ACTION_MOVE: { |
| 150 | if (DEBUG_TASK_POSITIONING){ |
| 151 | Slog.w(TAG, "ACTION_MOVE @ {" + newX + ", " + newY + "}"); |
| 152 | } |
| 153 | synchronized (mService.mWindowMap) { |
Wale Ogunwale | 6a804b8 | 2015-09-23 21:04:21 -0700 | [diff] [blame] | 154 | mDragEnded = notifyMoveLocked(newX, newY); |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 155 | mTask.getDimBounds(mTmpRect); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 156 | } |
Wale Ogunwale | 04ad7b1 | 2015-10-02 12:43:27 -0700 | [diff] [blame] | 157 | if (!mTmpRect.equals(mWindowDragBounds)) { |
| 158 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, |
| 159 | "wm.TaskPositioner.resizeTask"); |
| 160 | try { |
| 161 | mService.mActivityManager.resizeTask( |
| 162 | mTask.mTaskId, mWindowDragBounds, RESIZE_MODE_USER); |
| 163 | } catch (RemoteException e) { |
| 164 | } |
| 165 | Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); |
| 166 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 167 | } break; |
| 168 | |
| 169 | case MotionEvent.ACTION_UP: { |
| 170 | if (DEBUG_TASK_POSITIONING) { |
| 171 | Slog.w(TAG, "ACTION_UP @ {" + newX + ", " + newY + "}"); |
| 172 | } |
Wale Ogunwale | 6a804b8 | 2015-09-23 21:04:21 -0700 | [diff] [blame] | 173 | mDragEnded = true; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 174 | } break; |
| 175 | |
| 176 | case MotionEvent.ACTION_CANCEL: { |
| 177 | if (DEBUG_TASK_POSITIONING) { |
| 178 | Slog.w(TAG, "ACTION_CANCEL @ {" + newX + ", " + newY + "}"); |
| 179 | } |
Wale Ogunwale | 6a804b8 | 2015-09-23 21:04:21 -0700 | [diff] [blame] | 180 | mDragEnded = true; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 181 | } break; |
| 182 | } |
| 183 | |
Wale Ogunwale | 6a804b8 | 2015-09-23 21:04:21 -0700 | [diff] [blame] | 184 | if (mDragEnded) { |
Wale Ogunwale | 04ad7b1 | 2015-10-02 12:43:27 -0700 | [diff] [blame] | 185 | final boolean wasResizing = mResizing; |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 186 | synchronized (mService.mWindowMap) { |
| 187 | endDragLocked(); |
| 188 | } |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 189 | try { |
Wale Ogunwale | 04ad7b1 | 2015-10-02 12:43:27 -0700 | [diff] [blame] | 190 | if (wasResizing) { |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 191 | // We were using fullscreen surface during resizing. Request |
| 192 | // resizeTask() one last time to restore surface to window size. |
| 193 | mService.mActivityManager.resizeTask( |
Chong Zhang | 6de2ae8 | 2015-09-30 18:25:21 -0700 | [diff] [blame] | 194 | mTask.mTaskId, mWindowDragBounds, RESIZE_MODE_USER_FORCED); |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | if (mCurrentDimSide != CTRL_NONE) { |
| 198 | final int createMode = mCurrentDimSide == CTRL_LEFT |
| 199 | ? DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT |
| 200 | : DOCKED_STACK_CREATE_MODE_BOTTOM_OR_RIGHT; |
| 201 | mService.mActivityManager.moveTaskToDockedStack( |
Jorim Jaggi | 9ea2f7b | 2015-11-23 18:08:28 -0800 | [diff] [blame] | 202 | mTask.mTaskId, createMode, true /*toTop*/, true /* animate */, |
| 203 | null /* initialBounds */); |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 204 | } |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 205 | } catch(RemoteException e) {} |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 206 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 207 | // Post back to WM to handle clean-ups. We still need the input |
| 208 | // event handler for the last finishInputEvent()! |
| 209 | mService.mH.sendEmptyMessage(H.FINISH_TASK_POSITIONING); |
| 210 | } |
| 211 | handled = true; |
| 212 | } catch (Exception e) { |
| 213 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 214 | } finally { |
| 215 | finishInputEvent(event, handled); |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | TaskPositioner(WindowManagerService service) { |
| 221 | mService = service; |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * @param display The Display that the window being dragged is on. |
| 226 | */ |
| 227 | void register(Display display) { |
| 228 | if (DEBUG_TASK_POSITIONING) { |
| 229 | Slog.d(TAG, "Registering task positioner"); |
| 230 | } |
| 231 | |
| 232 | if (mClientChannel != null) { |
| 233 | Slog.e(TAG, "Task positioner already registered"); |
| 234 | return; |
| 235 | } |
| 236 | |
| 237 | mDisplay = display; |
| 238 | mDisplay.getMetrics(mDisplayMetrics); |
| 239 | final InputChannel[] channels = InputChannel.openInputChannelPair(TAG); |
| 240 | mServerChannel = channels[0]; |
| 241 | mClientChannel = channels[1]; |
| 242 | mService.mInputManager.registerInputChannel(mServerChannel, null); |
| 243 | |
Wale Ogunwale | 4f52bc6 | 2015-09-24 13:47:31 -0700 | [diff] [blame] | 244 | mInputEventReceiver = new WindowPositionerEventReceiver( |
| 245 | mClientChannel, mService.mH.getLooper(), mService.mChoreographer); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 246 | |
| 247 | mDragApplicationHandle = new InputApplicationHandle(null); |
| 248 | mDragApplicationHandle.name = TAG; |
| 249 | mDragApplicationHandle.dispatchingTimeoutNanos = |
| 250 | WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 251 | |
| 252 | mDragWindowHandle = new InputWindowHandle(mDragApplicationHandle, null, |
| 253 | mDisplay.getDisplayId()); |
| 254 | mDragWindowHandle.name = TAG; |
| 255 | mDragWindowHandle.inputChannel = mServerChannel; |
Filip Gruszczynski | 57b6cce | 2015-10-06 09:50:51 -0700 | [diff] [blame] | 256 | mDragWindowHandle.layer = mService.getDragLayerLocked(); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 257 | mDragWindowHandle.layoutParamsFlags = 0; |
| 258 | mDragWindowHandle.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG; |
| 259 | mDragWindowHandle.dispatchingTimeoutNanos = |
| 260 | WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 261 | mDragWindowHandle.visible = true; |
| 262 | mDragWindowHandle.canReceiveKeys = false; |
| 263 | mDragWindowHandle.hasFocus = true; |
| 264 | mDragWindowHandle.hasWallpaper = false; |
| 265 | mDragWindowHandle.paused = false; |
| 266 | mDragWindowHandle.ownerPid = Process.myPid(); |
| 267 | mDragWindowHandle.ownerUid = Process.myUid(); |
| 268 | mDragWindowHandle.inputFeatures = 0; |
| 269 | mDragWindowHandle.scaleFactor = 1.0f; |
| 270 | |
| 271 | // The drag window cannot receive new touches. |
| 272 | mDragWindowHandle.touchableRegion.setEmpty(); |
| 273 | |
| 274 | // The drag window covers the entire display |
| 275 | mDragWindowHandle.frameLeft = 0; |
| 276 | mDragWindowHandle.frameTop = 0; |
| 277 | final Point p = new Point(); |
| 278 | mDisplay.getRealSize(p); |
| 279 | mDragWindowHandle.frameRight = p.x; |
| 280 | mDragWindowHandle.frameBottom = p.y; |
| 281 | |
| 282 | // Pause rotations before a drag. |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame^] | 283 | if (DEBUG_ORIENTATION) { |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 284 | Slog.d(TAG, "Pausing rotation during re-position"); |
| 285 | } |
| 286 | mService.pauseRotationLocked(); |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 287 | |
| 288 | mDimLayer = new DimLayer(mService, this, mDisplay.getDisplayId()); |
Filip Gruszczynski | 57b6cce | 2015-10-06 09:50:51 -0700 | [diff] [blame] | 289 | mSideMargin = dipToPixel(SIDE_MARGIN_DIP, mDisplayMetrics); |
| 290 | mMinVisibleWidth = dipToPixel(MINIMUM_VISIBLE_WIDTH_IN_DP, mDisplayMetrics); |
| 291 | mMinVisibleHeight = dipToPixel(MINIMUM_VISIBLE_HEIGHT_IN_DP, mDisplayMetrics); |
Wale Ogunwale | 6a804b8 | 2015-09-23 21:04:21 -0700 | [diff] [blame] | 292 | |
| 293 | mDragEnded = false; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | void unregister() { |
| 297 | if (DEBUG_TASK_POSITIONING) { |
| 298 | Slog.d(TAG, "Unregistering task positioner"); |
| 299 | } |
| 300 | |
| 301 | if (mClientChannel == null) { |
| 302 | Slog.e(TAG, "Task positioner not registered"); |
| 303 | return; |
| 304 | } |
| 305 | |
| 306 | mService.mInputManager.unregisterInputChannel(mServerChannel); |
| 307 | |
| 308 | mInputEventReceiver.dispose(); |
| 309 | mInputEventReceiver = null; |
| 310 | mClientChannel.dispose(); |
| 311 | mServerChannel.dispose(); |
| 312 | mClientChannel = null; |
| 313 | mServerChannel = null; |
| 314 | |
| 315 | mDragWindowHandle = null; |
| 316 | mDragApplicationHandle = null; |
| 317 | mDisplay = null; |
| 318 | |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 319 | if (mDimLayer != null) { |
| 320 | mDimLayer.destroySurface(); |
| 321 | mDimLayer = null; |
| 322 | } |
| 323 | mCurrentDimSide = CTRL_NONE; |
Wale Ogunwale | 6a804b8 | 2015-09-23 21:04:21 -0700 | [diff] [blame] | 324 | mDragEnded = true; |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 325 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 326 | // Resume rotations after a drag. |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame^] | 327 | if (DEBUG_ORIENTATION) { |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 328 | Slog.d(TAG, "Resuming rotation after re-position"); |
| 329 | } |
| 330 | mService.resumeRotationLocked(); |
| 331 | } |
| 332 | |
| 333 | void startDragLocked(WindowState win, boolean resize, float startX, float startY) { |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 334 | if (DEBUG_TASK_POSITIONING) { |
| 335 | Slog.d(TAG, "startDragLocked: win=" + win + ", resize=" + resize |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 336 | + ", {" + startX + ", " + startY + "}"); |
| 337 | } |
| 338 | mCtrlType = CTRL_NONE; |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 339 | mTask = win.getTask(); |
| 340 | mStartDragX = startX; |
| 341 | mStartDragY = startY; |
| 342 | |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 343 | if (mTask.isDockedInEffect()) { |
| 344 | // If this is a docked task or if task size is affected by docked stack changing size, |
| 345 | // we can only be here if the task is not resizeable and we're handling a two-finger |
| 346 | // scrolling. Use the original task bounds to position the task, the dim bounds |
| 347 | // is cropped and doesn't move. |
| 348 | mTask.getBounds(mTmpRect); |
| 349 | } else { |
| 350 | // Use the dim bounds, not the original task bounds. The cursor |
| 351 | // movement should be calculated relative to the visible bounds. |
| 352 | // Also, use the dim bounds of the task which accounts for |
| 353 | // multiple app windows. Don't use any bounds from win itself as it |
| 354 | // may not be the same size as the task. |
| 355 | mTask.getDimBounds(mTmpRect); |
| 356 | } |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 357 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 358 | if (resize) { |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 359 | if (startX < mTmpRect.left) { |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 360 | mCtrlType |= CTRL_LEFT; |
| 361 | } |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 362 | if (startX > mTmpRect.right) { |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 363 | mCtrlType |= CTRL_RIGHT; |
| 364 | } |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 365 | if (startY < mTmpRect.top) { |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 366 | mCtrlType |= CTRL_TOP; |
| 367 | } |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 368 | if (startY > mTmpRect.bottom) { |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 369 | mCtrlType |= CTRL_BOTTOM; |
| 370 | } |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 371 | mResizing = true; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 374 | mWindowOriginalBounds.set(mTmpRect); |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | private void endDragLocked() { |
| 378 | mResizing = false; |
| 379 | mTask.setDragResizing(false); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 382 | /** Returns true if the move operation should be ended. */ |
| 383 | private boolean notifyMoveLocked(float x, float y) { |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 384 | if (DEBUG_TASK_POSITIONING) { |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 385 | Slog.d(TAG, "notifyMoveLocked: {" + x + "," + y + "}"); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | if (mCtrlType != CTRL_NONE) { |
| 389 | // This is a resizing operation. |
| 390 | final int deltaX = Math.round(x - mStartDragX); |
| 391 | final int deltaY = Math.round(y - mStartDragY); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 392 | int left = mWindowOriginalBounds.left; |
| 393 | int top = mWindowOriginalBounds.top; |
| 394 | int right = mWindowOriginalBounds.right; |
| 395 | int bottom = mWindowOriginalBounds.bottom; |
| 396 | if ((mCtrlType & CTRL_LEFT) != 0) { |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 397 | left = Math.min(left + deltaX, right - mMinVisibleWidth); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 398 | } |
| 399 | if ((mCtrlType & CTRL_TOP) != 0) { |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 400 | top = Math.min(top + deltaY, bottom - mMinVisibleHeight); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 401 | } |
| 402 | if ((mCtrlType & CTRL_RIGHT) != 0) { |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 403 | right = Math.max(left + mMinVisibleWidth, right + deltaX); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 404 | } |
| 405 | if ((mCtrlType & CTRL_BOTTOM) != 0) { |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 406 | bottom = Math.max(top + mMinVisibleHeight, bottom + deltaY); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 407 | } |
| 408 | mWindowDragBounds.set(left, top, right, bottom); |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 409 | mTask.setDragResizing(true); |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 410 | return false; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 411 | } |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 412 | |
| 413 | // This is a moving operation. |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 414 | mTask.mStack.getDimBounds(mTmpRect); |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 415 | |
| 416 | // If this is a non-resizeable task put into side-by-side mode, we are |
| 417 | // handling a two-finger scrolling action. No need to shrink the bounds. |
| 418 | if (!mTask.isDockedInEffect()) { |
| 419 | mTmpRect.inset(mMinVisibleWidth, mMinVisibleHeight); |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 420 | } |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 421 | |
| 422 | boolean dragEnded = false; |
| 423 | final int nX = (int) x; |
| 424 | final int nY = (int) y; |
| 425 | if (!mTmpRect.contains(nX, nY)) { |
| 426 | // We end the moving operation if position is outside the stack bounds. |
| 427 | // In this case we need to clamp the position to stack bounds and calculate |
| 428 | // the final window drag bounds. |
| 429 | x = Math.min(Math.max(x, mTmpRect.left), mTmpRect.right); |
| 430 | y = Math.min(Math.max(y, mTmpRect.top), mTmpRect.bottom); |
| 431 | dragEnded = true; |
| 432 | } |
| 433 | |
| 434 | updateWindowDragBounds(nX, nY); |
| 435 | updateDimLayerVisibility(nX); |
| 436 | return dragEnded; |
| 437 | } |
| 438 | |
| 439 | private void updateWindowDragBounds(int x, int y) { |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 440 | mWindowDragBounds.set(mWindowOriginalBounds); |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 441 | if (mTask.isDockedInEffect()) { |
| 442 | // Offset the bounds without clamp, the bounds will be shifted later |
| 443 | // by window manager before applying the scrolling. |
| 444 | if (mService.mCurConfiguration.orientation == ORIENTATION_LANDSCAPE) { |
| 445 | mWindowDragBounds.offset(Math.round(x - mStartDragX), 0); |
| 446 | } else { |
| 447 | mWindowDragBounds.offset(0, Math.round(y - mStartDragY)); |
| 448 | } |
| 449 | } else { |
| 450 | mWindowDragBounds.offset(Math.round(x - mStartDragX), Math.round(y - mStartDragY)); |
| 451 | } |
| 452 | if (DEBUG_TASK_POSITIONING) Slog.d(TAG, |
| 453 | "updateWindowDragBounds: " + mWindowDragBounds); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 456 | private void updateDimLayerVisibility(int x) { |
| 457 | @CtrlType |
| 458 | int dimSide = getDimSide(x); |
| 459 | if (dimSide == mCurrentDimSide) { |
| 460 | return; |
| 461 | } |
| 462 | |
| 463 | mCurrentDimSide = dimSide; |
| 464 | |
| 465 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION updateDimLayerVisibility"); |
| 466 | SurfaceControl.openTransaction(); |
| 467 | if (mCurrentDimSide == CTRL_NONE) { |
| 468 | mDimLayer.hide(); |
| 469 | } else { |
| 470 | showDimLayer(); |
| 471 | } |
| 472 | SurfaceControl.closeTransaction(); |
| 473 | } |
| 474 | |
| 475 | /** |
| 476 | * Returns the side of the screen the dim layer should be shown. |
| 477 | * @param x horizontal coordinate used to determine if the dim layer should be shown |
| 478 | * @return Returns {@link #CTRL_LEFT} if the dim layer should be shown on the left half of the |
| 479 | * screen, {@link #CTRL_RIGHT} if on the right side, or {@link #CTRL_NONE} if the dim layer |
| 480 | * shouldn't be shown. |
| 481 | */ |
| 482 | private int getDimSide(int x) { |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 483 | if (mTask.mStack.mStackId != FREEFORM_WORKSPACE_STACK_ID |
| 484 | || !mTask.mStack.isFullscreen() |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 485 | || mService.mCurConfiguration.orientation != ORIENTATION_LANDSCAPE) { |
| 486 | return CTRL_NONE; |
| 487 | } |
| 488 | |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 489 | mTask.mStack.getDimBounds(mTmpRect); |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 490 | if (x - mSideMargin <= mTmpRect.left) { |
| 491 | return CTRL_LEFT; |
| 492 | } |
| 493 | if (x + mSideMargin >= mTmpRect.right) { |
| 494 | return CTRL_RIGHT; |
| 495 | } |
| 496 | |
| 497 | return CTRL_NONE; |
| 498 | } |
| 499 | |
| 500 | private void showDimLayer() { |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 501 | mTask.mStack.getDimBounds(mTmpRect); |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 502 | if (mCurrentDimSide == CTRL_LEFT) { |
| 503 | mTmpRect.right = mTmpRect.centerX(); |
| 504 | } else if (mCurrentDimSide == CTRL_RIGHT) { |
| 505 | mTmpRect.left = mTmpRect.centerX(); |
| 506 | } |
| 507 | |
| 508 | mDimLayer.setBounds(mTmpRect); |
Filip Gruszczynski | 57b6cce | 2015-10-06 09:50:51 -0700 | [diff] [blame] | 509 | mDimLayer.show(mService.getDragLayerLocked(), RESIZING_HINT_ALPHA, |
| 510 | RESIZING_HINT_DURATION_MS); |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | @Override /** {@link DimLayer.DimLayerUser} */ |
| 514 | public boolean isFullscreen() { |
| 515 | return false; |
| 516 | } |
| 517 | |
| 518 | @Override /** {@link DimLayer.DimLayerUser} */ |
| 519 | public DisplayInfo getDisplayInfo() { |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 520 | return mTask.mStack.getDisplayInfo(); |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 523 | @Override |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 524 | public void getDimBounds(Rect out) { |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 525 | // This dim layer user doesn't need this. |
| 526 | } |
| 527 | |
| 528 | @Override |
| 529 | public String toShortString() { |
| 530 | return TAG; |
| 531 | } |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 532 | } |