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