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