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; |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 21 | import static android.app.ActivityManager.FREEFORM_WORKSPACE_STACK_ID; |
Chong Zhang | 87b2172 | 2015-09-21 15:39:51 -0700 | [diff] [blame] | 22 | import static android.app.ActivityManager.RESIZE_MODE_FORCED; |
| 23 | import static android.app.ActivityManager.RESIZE_MODE_USER; |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 24 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 25 | import static com.android.server.wm.WindowManagerService.DEBUG_TASK_POSITIONING; |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 26 | import static com.android.server.wm.WindowManagerService.SHOW_TRANSACTIONS; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 27 | import static com.android.server.wm.WindowState.MINIMUM_VISIBLE_HEIGHT_IN_DP; |
| 28 | import static com.android.server.wm.WindowState.MINIMUM_VISIBLE_WIDTH_IN_DP; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 29 | |
| 30 | import android.annotation.IntDef; |
| 31 | import android.graphics.Point; |
| 32 | import android.graphics.Rect; |
| 33 | import android.os.Looper; |
| 34 | import android.os.Process; |
| 35 | import android.os.RemoteException; |
| 36 | import android.util.DisplayMetrics; |
| 37 | import android.util.Slog; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 38 | import android.view.Display; |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 39 | import android.view.DisplayInfo; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 40 | import android.view.InputChannel; |
| 41 | import android.view.InputDevice; |
| 42 | import android.view.InputEvent; |
| 43 | import android.view.InputEventReceiver; |
| 44 | import android.view.MotionEvent; |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 45 | import android.view.SurfaceControl; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 46 | import android.view.WindowManager; |
| 47 | |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 48 | import com.android.server.input.InputApplicationHandle; |
| 49 | import com.android.server.input.InputWindowHandle; |
| 50 | import com.android.server.wm.WindowManagerService.H; |
| 51 | |
| 52 | import java.lang.annotation.Retention; |
| 53 | import java.lang.annotation.RetentionPolicy; |
| 54 | |
| 55 | class TaskPositioner implements DimLayer.DimLayerUser { |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 56 | private static final String TAG = "TaskPositioner"; |
| 57 | |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 58 | // The margin the pointer position has to be within the side of the screen to be |
| 59 | // considered at the side of the screen. |
Wale Ogunwale | f5a67f5 | 2015-09-15 09:54:33 -0700 | [diff] [blame] | 60 | private static final int SIDE_MARGIN_DIP = 100; |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 61 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 62 | @IntDef(flag = true, |
| 63 | value = { |
| 64 | CTRL_NONE, |
| 65 | CTRL_LEFT, |
| 66 | CTRL_RIGHT, |
| 67 | CTRL_TOP, |
| 68 | CTRL_BOTTOM |
| 69 | }) |
| 70 | @Retention(RetentionPolicy.SOURCE) |
| 71 | @interface CtrlType {} |
| 72 | |
| 73 | private static final int CTRL_NONE = 0x0; |
| 74 | private static final int CTRL_LEFT = 0x1; |
| 75 | private static final int CTRL_RIGHT = 0x2; |
| 76 | private static final int CTRL_TOP = 0x4; |
| 77 | private static final int CTRL_BOTTOM = 0x8; |
| 78 | |
| 79 | private final WindowManagerService mService; |
| 80 | private WindowPositionerEventReceiver mInputEventReceiver; |
| 81 | private Display mDisplay; |
| 82 | private final DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 83 | private DimLayer mDimLayer; |
| 84 | @CtrlType |
| 85 | private int mCurrentDimSide; |
| 86 | private Rect mTmpRect = new Rect(); |
| 87 | private int mSideMargin; |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 88 | private int mMinVisibleWidth; |
| 89 | private int mMinVisibleHeight; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 90 | |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 91 | private Task mTask; |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 92 | private boolean mResizing; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 93 | private final Rect mWindowOriginalBounds = new Rect(); |
| 94 | private final Rect mWindowDragBounds = new Rect(); |
| 95 | private float mStartDragX; |
| 96 | private float mStartDragY; |
| 97 | @CtrlType |
| 98 | private int mCtrlType = CTRL_NONE; |
| 99 | |
| 100 | InputChannel mServerChannel; |
| 101 | InputChannel mClientChannel; |
| 102 | InputApplicationHandle mDragApplicationHandle; |
| 103 | InputWindowHandle mDragWindowHandle; |
| 104 | |
| 105 | private final class WindowPositionerEventReceiver extends InputEventReceiver { |
| 106 | public WindowPositionerEventReceiver(InputChannel inputChannel, Looper looper) { |
| 107 | super(inputChannel, looper); |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public void onInputEvent(InputEvent event) { |
| 112 | if (!(event instanceof MotionEvent) |
| 113 | || (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 114 | return; |
| 115 | } |
| 116 | final MotionEvent motionEvent = (MotionEvent) event; |
| 117 | boolean handled = false; |
| 118 | |
| 119 | try { |
| 120 | boolean endDrag = false; |
| 121 | final float newX = motionEvent.getRawX(); |
| 122 | final float newY = motionEvent.getRawY(); |
| 123 | |
| 124 | switch (motionEvent.getAction()) { |
| 125 | case MotionEvent.ACTION_DOWN: { |
| 126 | if (DEBUG_TASK_POSITIONING) { |
| 127 | Slog.w(TAG, "ACTION_DOWN @ {" + newX + ", " + newY + "}"); |
| 128 | } |
| 129 | } break; |
| 130 | |
| 131 | case MotionEvent.ACTION_MOVE: { |
| 132 | if (DEBUG_TASK_POSITIONING){ |
| 133 | Slog.w(TAG, "ACTION_MOVE @ {" + newX + ", " + newY + "}"); |
| 134 | } |
| 135 | synchronized (mService.mWindowMap) { |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 136 | endDrag = notifyMoveLocked(newX, newY); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 137 | } |
| 138 | try { |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 139 | mService.mActivityManager.resizeTask( |
Chong Zhang | 87b2172 | 2015-09-21 15:39:51 -0700 | [diff] [blame] | 140 | mTask.mTaskId, mWindowDragBounds, RESIZE_MODE_USER); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 141 | } catch(RemoteException e) {} |
| 142 | } break; |
| 143 | |
| 144 | case MotionEvent.ACTION_UP: { |
| 145 | if (DEBUG_TASK_POSITIONING) { |
| 146 | Slog.w(TAG, "ACTION_UP @ {" + newX + ", " + newY + "}"); |
| 147 | } |
| 148 | endDrag = true; |
| 149 | } break; |
| 150 | |
| 151 | case MotionEvent.ACTION_CANCEL: { |
| 152 | if (DEBUG_TASK_POSITIONING) { |
| 153 | Slog.w(TAG, "ACTION_CANCEL @ {" + newX + ", " + newY + "}"); |
| 154 | } |
| 155 | endDrag = true; |
| 156 | } break; |
| 157 | } |
| 158 | |
| 159 | if (endDrag) { |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 160 | synchronized (mService.mWindowMap) { |
| 161 | endDragLocked(); |
| 162 | } |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 163 | try { |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 164 | if (mResizing) { |
| 165 | // We were using fullscreen surface during resizing. Request |
| 166 | // resizeTask() one last time to restore surface to window size. |
| 167 | mService.mActivityManager.resizeTask( |
Chong Zhang | 87b2172 | 2015-09-21 15:39:51 -0700 | [diff] [blame] | 168 | mTask.mTaskId, mWindowDragBounds, RESIZE_MODE_FORCED); |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | if (mCurrentDimSide != CTRL_NONE) { |
| 172 | final int createMode = mCurrentDimSide == CTRL_LEFT |
| 173 | ? DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT |
| 174 | : DOCKED_STACK_CREATE_MODE_BOTTOM_OR_RIGHT; |
| 175 | mService.mActivityManager.moveTaskToDockedStack( |
| 176 | mTask.mTaskId, createMode, true /*toTop*/); |
| 177 | } |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 178 | } catch(RemoteException e) {} |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 179 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 180 | // Post back to WM to handle clean-ups. We still need the input |
| 181 | // event handler for the last finishInputEvent()! |
| 182 | mService.mH.sendEmptyMessage(H.FINISH_TASK_POSITIONING); |
| 183 | } |
| 184 | handled = true; |
| 185 | } catch (Exception e) { |
| 186 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 187 | } finally { |
| 188 | finishInputEvent(event, handled); |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | TaskPositioner(WindowManagerService service) { |
| 194 | mService = service; |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * @param display The Display that the window being dragged is on. |
| 199 | */ |
| 200 | void register(Display display) { |
| 201 | if (DEBUG_TASK_POSITIONING) { |
| 202 | Slog.d(TAG, "Registering task positioner"); |
| 203 | } |
| 204 | |
| 205 | if (mClientChannel != null) { |
| 206 | Slog.e(TAG, "Task positioner already registered"); |
| 207 | return; |
| 208 | } |
| 209 | |
| 210 | mDisplay = display; |
| 211 | mDisplay.getMetrics(mDisplayMetrics); |
| 212 | final InputChannel[] channels = InputChannel.openInputChannelPair(TAG); |
| 213 | mServerChannel = channels[0]; |
| 214 | mClientChannel = channels[1]; |
| 215 | mService.mInputManager.registerInputChannel(mServerChannel, null); |
| 216 | |
| 217 | mInputEventReceiver = new WindowPositionerEventReceiver(mClientChannel, |
| 218 | mService.mH.getLooper()); |
| 219 | |
| 220 | mDragApplicationHandle = new InputApplicationHandle(null); |
| 221 | mDragApplicationHandle.name = TAG; |
| 222 | mDragApplicationHandle.dispatchingTimeoutNanos = |
| 223 | WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 224 | |
| 225 | mDragWindowHandle = new InputWindowHandle(mDragApplicationHandle, null, |
| 226 | mDisplay.getDisplayId()); |
| 227 | mDragWindowHandle.name = TAG; |
| 228 | mDragWindowHandle.inputChannel = mServerChannel; |
| 229 | mDragWindowHandle.layer = getDragLayerLocked(); |
| 230 | mDragWindowHandle.layoutParamsFlags = 0; |
| 231 | mDragWindowHandle.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG; |
| 232 | mDragWindowHandle.dispatchingTimeoutNanos = |
| 233 | WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 234 | mDragWindowHandle.visible = true; |
| 235 | mDragWindowHandle.canReceiveKeys = false; |
| 236 | mDragWindowHandle.hasFocus = true; |
| 237 | mDragWindowHandle.hasWallpaper = false; |
| 238 | mDragWindowHandle.paused = false; |
| 239 | mDragWindowHandle.ownerPid = Process.myPid(); |
| 240 | mDragWindowHandle.ownerUid = Process.myUid(); |
| 241 | mDragWindowHandle.inputFeatures = 0; |
| 242 | mDragWindowHandle.scaleFactor = 1.0f; |
| 243 | |
| 244 | // The drag window cannot receive new touches. |
| 245 | mDragWindowHandle.touchableRegion.setEmpty(); |
| 246 | |
| 247 | // The drag window covers the entire display |
| 248 | mDragWindowHandle.frameLeft = 0; |
| 249 | mDragWindowHandle.frameTop = 0; |
| 250 | final Point p = new Point(); |
| 251 | mDisplay.getRealSize(p); |
| 252 | mDragWindowHandle.frameRight = p.x; |
| 253 | mDragWindowHandle.frameBottom = p.y; |
| 254 | |
| 255 | // Pause rotations before a drag. |
| 256 | if (WindowManagerService.DEBUG_ORIENTATION) { |
| 257 | Slog.d(TAG, "Pausing rotation during re-position"); |
| 258 | } |
| 259 | mService.pauseRotationLocked(); |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 260 | |
| 261 | mDimLayer = new DimLayer(mService, this, mDisplay.getDisplayId()); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 262 | mSideMargin = mService.dipToPixel(SIDE_MARGIN_DIP, mDisplayMetrics); |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 263 | mMinVisibleWidth = mService.dipToPixel(MINIMUM_VISIBLE_WIDTH_IN_DP, mDisplayMetrics); |
| 264 | mMinVisibleHeight = mService.dipToPixel(MINIMUM_VISIBLE_HEIGHT_IN_DP, mDisplayMetrics); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | void unregister() { |
| 268 | if (DEBUG_TASK_POSITIONING) { |
| 269 | Slog.d(TAG, "Unregistering task positioner"); |
| 270 | } |
| 271 | |
| 272 | if (mClientChannel == null) { |
| 273 | Slog.e(TAG, "Task positioner not registered"); |
| 274 | return; |
| 275 | } |
| 276 | |
| 277 | mService.mInputManager.unregisterInputChannel(mServerChannel); |
| 278 | |
| 279 | mInputEventReceiver.dispose(); |
| 280 | mInputEventReceiver = null; |
| 281 | mClientChannel.dispose(); |
| 282 | mServerChannel.dispose(); |
| 283 | mClientChannel = null; |
| 284 | mServerChannel = null; |
| 285 | |
| 286 | mDragWindowHandle = null; |
| 287 | mDragApplicationHandle = null; |
| 288 | mDisplay = null; |
| 289 | |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 290 | if (mDimLayer != null) { |
| 291 | mDimLayer.destroySurface(); |
| 292 | mDimLayer = null; |
| 293 | } |
| 294 | mCurrentDimSide = CTRL_NONE; |
| 295 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 296 | // Resume rotations after a drag. |
| 297 | if (WindowManagerService.DEBUG_ORIENTATION) { |
| 298 | Slog.d(TAG, "Resuming rotation after re-position"); |
| 299 | } |
| 300 | mService.resumeRotationLocked(); |
| 301 | } |
| 302 | |
| 303 | void startDragLocked(WindowState win, boolean resize, float startX, float startY) { |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 304 | if (DEBUG_TASK_POSITIONING) { |
| 305 | Slog.d(TAG, "startDragLocked: win=" + win + ", resize=" + resize |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 306 | + ", {" + startX + ", " + startY + "}"); |
| 307 | } |
| 308 | mCtrlType = CTRL_NONE; |
| 309 | if (resize) { |
| 310 | final Rect visibleFrame = win.mVisibleFrame; |
| 311 | if (startX < visibleFrame.left) { |
| 312 | mCtrlType |= CTRL_LEFT; |
| 313 | } |
| 314 | if (startX > visibleFrame.right) { |
| 315 | mCtrlType |= CTRL_RIGHT; |
| 316 | } |
| 317 | if (startY < visibleFrame.top) { |
| 318 | mCtrlType |= CTRL_TOP; |
| 319 | } |
| 320 | if (startY > visibleFrame.bottom) { |
| 321 | mCtrlType |= CTRL_BOTTOM; |
| 322 | } |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 323 | mResizing = true; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 326 | mTask = win.getTask(); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 327 | mStartDragX = startX; |
| 328 | mStartDragY = startY; |
| 329 | |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 330 | mService.getTaskBounds(mTask.mTaskId, mWindowOriginalBounds); |
| 331 | } |
| 332 | |
| 333 | private void endDragLocked() { |
| 334 | mResizing = false; |
| 335 | mTask.setDragResizing(false); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 338 | /** Returns true if the move operation should be ended. */ |
| 339 | private boolean notifyMoveLocked(float x, float y) { |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 340 | if (DEBUG_TASK_POSITIONING) { |
| 341 | Slog.d(TAG, "notifyMoveLw: {" + x + "," + y + "}"); |
| 342 | } |
| 343 | |
| 344 | if (mCtrlType != CTRL_NONE) { |
| 345 | // This is a resizing operation. |
| 346 | final int deltaX = Math.round(x - mStartDragX); |
| 347 | final int deltaY = Math.round(y - mStartDragY); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 348 | int left = mWindowOriginalBounds.left; |
| 349 | int top = mWindowOriginalBounds.top; |
| 350 | int right = mWindowOriginalBounds.right; |
| 351 | int bottom = mWindowOriginalBounds.bottom; |
| 352 | if ((mCtrlType & CTRL_LEFT) != 0) { |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 353 | left = Math.min(left + deltaX, right - mMinVisibleWidth); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 354 | } |
| 355 | if ((mCtrlType & CTRL_TOP) != 0) { |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 356 | top = Math.min(top + deltaY, bottom - mMinVisibleHeight); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 357 | } |
| 358 | if ((mCtrlType & CTRL_RIGHT) != 0) { |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 359 | right = Math.max(left + mMinVisibleWidth, right + deltaX); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 360 | } |
| 361 | if ((mCtrlType & CTRL_BOTTOM) != 0) { |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 362 | bottom = Math.max(top + mMinVisibleHeight, bottom + deltaY); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 363 | } |
| 364 | mWindowDragBounds.set(left, top, right, bottom); |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 365 | mTask.setDragResizing(true); |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 366 | return false; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 367 | } |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 368 | |
| 369 | // This is a moving operation. |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 370 | mTask.mStack.getBounds(mTmpRect); |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 371 | mTmpRect.inset(mMinVisibleWidth, mMinVisibleHeight); |
| 372 | if (!mTmpRect.contains((int) x, (int) y)) { |
| 373 | // We end the moving operation if position is outside the stack bounds. |
| 374 | return true; |
| 375 | } |
| 376 | mWindowDragBounds.set(mWindowOriginalBounds); |
| 377 | mWindowDragBounds.offset(Math.round(x - mStartDragX), Math.round(y - mStartDragY)); |
| 378 | updateDimLayerVisibility((int) x); |
| 379 | return false; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 382 | private void updateDimLayerVisibility(int x) { |
| 383 | @CtrlType |
| 384 | int dimSide = getDimSide(x); |
| 385 | if (dimSide == mCurrentDimSide) { |
| 386 | return; |
| 387 | } |
| 388 | |
| 389 | mCurrentDimSide = dimSide; |
| 390 | |
| 391 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION updateDimLayerVisibility"); |
| 392 | SurfaceControl.openTransaction(); |
| 393 | if (mCurrentDimSide == CTRL_NONE) { |
| 394 | mDimLayer.hide(); |
| 395 | } else { |
| 396 | showDimLayer(); |
| 397 | } |
| 398 | SurfaceControl.closeTransaction(); |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * Returns the side of the screen the dim layer should be shown. |
| 403 | * @param x horizontal coordinate used to determine if the dim layer should be shown |
| 404 | * @return Returns {@link #CTRL_LEFT} if the dim layer should be shown on the left half of the |
| 405 | * screen, {@link #CTRL_RIGHT} if on the right side, or {@link #CTRL_NONE} if the dim layer |
| 406 | * shouldn't be shown. |
| 407 | */ |
| 408 | private int getDimSide(int x) { |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 409 | if (mTask.mStack.mStackId != FREEFORM_WORKSPACE_STACK_ID |
| 410 | || !mTask.mStack.isFullscreen() |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 411 | || mService.mCurConfiguration.orientation != ORIENTATION_LANDSCAPE) { |
| 412 | return CTRL_NONE; |
| 413 | } |
| 414 | |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 415 | mTask.mStack.getBounds(mTmpRect); |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 416 | if (x - mSideMargin <= mTmpRect.left) { |
| 417 | return CTRL_LEFT; |
| 418 | } |
| 419 | if (x + mSideMargin >= mTmpRect.right) { |
| 420 | return CTRL_RIGHT; |
| 421 | } |
| 422 | |
| 423 | return CTRL_NONE; |
| 424 | } |
| 425 | |
| 426 | private void showDimLayer() { |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 427 | mTask.mStack.getBounds(mTmpRect); |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 428 | if (mCurrentDimSide == CTRL_LEFT) { |
| 429 | mTmpRect.right = mTmpRect.centerX(); |
| 430 | } else if (mCurrentDimSide == CTRL_RIGHT) { |
| 431 | mTmpRect.left = mTmpRect.centerX(); |
| 432 | } |
| 433 | |
| 434 | mDimLayer.setBounds(mTmpRect); |
| 435 | mDimLayer.show(getDragLayerLocked(), 0.5f, 0); |
| 436 | } |
| 437 | |
| 438 | @Override /** {@link DimLayer.DimLayerUser} */ |
| 439 | public boolean isFullscreen() { |
| 440 | return false; |
| 441 | } |
| 442 | |
| 443 | @Override /** {@link DimLayer.DimLayerUser} */ |
| 444 | public DisplayInfo getDisplayInfo() { |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 445 | return mTask.mStack.getDisplayInfo(); |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 448 | private int getDragLayerLocked() { |
| 449 | return mService.mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG) |
| 450 | * WindowManagerService.TYPE_LAYER_MULTIPLIER |
| 451 | + WindowManagerService.TYPE_LAYER_OFFSET; |
| 452 | } |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 453 | } |