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