blob: f5e4e3be34779695776d1cf21b47d867303b4f5d [file] [log] [blame]
Chong Zhang8e89b312015-09-09 15:09:30 -07001/*
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
17package com.android.server.wm;
18
Wale Ogunwale59a73ca2015-09-14 12:54:50 -070019import static android.app.ActivityManager.DOCKED_STACK_CREATE_MODE_BOTTOM_OR_RIGHT;
20import static android.app.ActivityManager.DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT;
Wale Ogunwale3797c222015-10-27 14:21:58 -070021import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
Chong Zhang87b21722015-09-21 15:39:51 -070022import static android.app.ActivityManager.RESIZE_MODE_USER;
Chong Zhang6de2ae82015-09-30 18:25:21 -070023import static android.app.ActivityManager.RESIZE_MODE_USER_FORCED;
Wale Ogunwale228d4042015-09-13 10:17:34 -070024import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
Wale Ogunwalecad05a02015-09-25 10:41:44 -070025import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Filip Gruszczynski57b6cce2015-10-06 09:50:51 -070026import static com.android.server.wm.DimLayer.RESIZING_HINT_ALPHA;
27import static com.android.server.wm.DimLayer.RESIZING_HINT_DURATION_MS;
Chong Zhang8e89b312015-09-09 15:09:30 -070028import static com.android.server.wm.WindowManagerService.DEBUG_TASK_POSITIONING;
Wale Ogunwale228d4042015-09-13 10:17:34 -070029import static com.android.server.wm.WindowManagerService.SHOW_TRANSACTIONS;
Filip Gruszczynski57b6cce2015-10-06 09:50:51 -070030import static com.android.server.wm.WindowManagerService.dipToPixel;
Wale Ogunwale231b06e2015-09-16 12:03:09 -070031import static com.android.server.wm.WindowState.MINIMUM_VISIBLE_HEIGHT_IN_DP;
32import static com.android.server.wm.WindowState.MINIMUM_VISIBLE_WIDTH_IN_DP;
Chong Zhang8e89b312015-09-09 15:09:30 -070033
34import android.annotation.IntDef;
35import android.graphics.Point;
36import android.graphics.Rect;
37import android.os.Looper;
38import android.os.Process;
39import android.os.RemoteException;
Wale Ogunwalecad05a02015-09-25 10:41:44 -070040import android.os.Trace;
Chong Zhang8e89b312015-09-09 15:09:30 -070041import android.util.DisplayMetrics;
42import android.util.Slog;
Wale Ogunwale4f52bc62015-09-24 13:47:31 -070043import android.view.Choreographer;
Chong Zhang8e89b312015-09-09 15:09:30 -070044import android.view.Display;
Wale Ogunwale228d4042015-09-13 10:17:34 -070045import android.view.DisplayInfo;
Chong Zhang8e89b312015-09-09 15:09:30 -070046import android.view.InputChannel;
47import android.view.InputDevice;
48import android.view.InputEvent;
Wale Ogunwale4f52bc62015-09-24 13:47:31 -070049import android.view.BatchedInputEventReceiver;
Chong Zhang8e89b312015-09-09 15:09:30 -070050import android.view.MotionEvent;
Wale Ogunwale228d4042015-09-13 10:17:34 -070051import android.view.SurfaceControl;
Chong Zhang8e89b312015-09-09 15:09:30 -070052import android.view.WindowManager;
53
Wale Ogunwale228d4042015-09-13 10:17:34 -070054import com.android.server.input.InputApplicationHandle;
55import com.android.server.input.InputWindowHandle;
56import com.android.server.wm.WindowManagerService.H;
57
58import java.lang.annotation.Retention;
59import java.lang.annotation.RetentionPolicy;
60
61class TaskPositioner implements DimLayer.DimLayerUser {
Chong Zhang8e89b312015-09-09 15:09:30 -070062 private static final String TAG = "TaskPositioner";
63
Wale Ogunwale228d4042015-09-13 10:17:34 -070064 // The margin the pointer position has to be within the side of the screen to be
65 // considered at the side of the screen.
Filip Gruszczynski57b6cce2015-10-06 09:50:51 -070066 static final int SIDE_MARGIN_DIP = 100;
Wale Ogunwale228d4042015-09-13 10:17:34 -070067
Chong Zhang8e89b312015-09-09 15:09:30 -070068 @IntDef(flag = true,
69 value = {
70 CTRL_NONE,
71 CTRL_LEFT,
72 CTRL_RIGHT,
73 CTRL_TOP,
74 CTRL_BOTTOM
75 })
76 @Retention(RetentionPolicy.SOURCE)
77 @interface CtrlType {}
78
79 private static final int CTRL_NONE = 0x0;
80 private static final int CTRL_LEFT = 0x1;
81 private static final int CTRL_RIGHT = 0x2;
82 private static final int CTRL_TOP = 0x4;
83 private static final int CTRL_BOTTOM = 0x8;
84
85 private final WindowManagerService mService;
86 private WindowPositionerEventReceiver mInputEventReceiver;
87 private Display mDisplay;
88 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Wale Ogunwale228d4042015-09-13 10:17:34 -070089 private DimLayer mDimLayer;
90 @CtrlType
91 private int mCurrentDimSide;
92 private Rect mTmpRect = new Rect();
93 private int mSideMargin;
Wale Ogunwaleb8051b82015-09-17 15:41:52 -070094 private int mMinVisibleWidth;
95 private int mMinVisibleHeight;
Chong Zhang8e89b312015-09-09 15:09:30 -070096
Chong Zhang3005e752015-09-18 18:46:28 -070097 private Task mTask;
Chong Zhang09b21ef2015-09-14 10:20:21 -070098 private boolean mResizing;
Chong Zhang8e89b312015-09-09 15:09:30 -070099 private final Rect mWindowOriginalBounds = new Rect();
100 private final Rect mWindowDragBounds = new Rect();
101 private float mStartDragX;
102 private float mStartDragY;
103 @CtrlType
104 private int mCtrlType = CTRL_NONE;
Wale Ogunwale6a804b82015-09-23 21:04:21 -0700105 private boolean mDragEnded = false;
Chong Zhang8e89b312015-09-09 15:09:30 -0700106
107 InputChannel mServerChannel;
108 InputChannel mClientChannel;
109 InputApplicationHandle mDragApplicationHandle;
110 InputWindowHandle mDragWindowHandle;
111
Wale Ogunwale4f52bc62015-09-24 13:47:31 -0700112 private final class WindowPositionerEventReceiver extends BatchedInputEventReceiver {
113 public WindowPositionerEventReceiver(
114 InputChannel inputChannel, Looper looper, Choreographer choreographer) {
115 super(inputChannel, looper, choreographer);
Chong Zhang8e89b312015-09-09 15:09:30 -0700116 }
117
118 @Override
119 public void onInputEvent(InputEvent event) {
120 if (!(event instanceof MotionEvent)
121 || (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
122 return;
123 }
124 final MotionEvent motionEvent = (MotionEvent) event;
125 boolean handled = false;
126
127 try {
Wale Ogunwale6a804b82015-09-23 21:04:21 -0700128 if (mDragEnded) {
129 // The drag has ended but the clean-up message has not been processed by
130 // window manager. Drop events that occur after this until window manager
131 // has a chance to clean-up the input handle.
132 handled = true;
133 return;
134 }
135
Chong Zhang8e89b312015-09-09 15:09:30 -0700136 final float newX = motionEvent.getRawX();
137 final float newY = motionEvent.getRawY();
138
139 switch (motionEvent.getAction()) {
140 case MotionEvent.ACTION_DOWN: {
141 if (DEBUG_TASK_POSITIONING) {
142 Slog.w(TAG, "ACTION_DOWN @ {" + newX + ", " + newY + "}");
143 }
144 } break;
145
146 case MotionEvent.ACTION_MOVE: {
147 if (DEBUG_TASK_POSITIONING){
148 Slog.w(TAG, "ACTION_MOVE @ {" + newX + ", " + newY + "}");
149 }
150 synchronized (mService.mWindowMap) {
Wale Ogunwale6a804b82015-09-23 21:04:21 -0700151 mDragEnded = notifyMoveLocked(newX, newY);
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800152 mTask.getDimBounds(mTmpRect);
Chong Zhang8e89b312015-09-09 15:09:30 -0700153 }
Wale Ogunwale04ad7b12015-10-02 12:43:27 -0700154 if (!mTmpRect.equals(mWindowDragBounds)) {
155 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER,
156 "wm.TaskPositioner.resizeTask");
157 try {
158 mService.mActivityManager.resizeTask(
159 mTask.mTaskId, mWindowDragBounds, RESIZE_MODE_USER);
160 } catch (RemoteException e) {
161 }
162 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
163 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700164 } break;
165
166 case MotionEvent.ACTION_UP: {
167 if (DEBUG_TASK_POSITIONING) {
168 Slog.w(TAG, "ACTION_UP @ {" + newX + ", " + newY + "}");
169 }
Wale Ogunwale6a804b82015-09-23 21:04:21 -0700170 mDragEnded = true;
Chong Zhang8e89b312015-09-09 15:09:30 -0700171 } break;
172
173 case MotionEvent.ACTION_CANCEL: {
174 if (DEBUG_TASK_POSITIONING) {
175 Slog.w(TAG, "ACTION_CANCEL @ {" + newX + ", " + newY + "}");
176 }
Wale Ogunwale6a804b82015-09-23 21:04:21 -0700177 mDragEnded = true;
Chong Zhang8e89b312015-09-09 15:09:30 -0700178 } break;
179 }
180
Wale Ogunwale6a804b82015-09-23 21:04:21 -0700181 if (mDragEnded) {
Wale Ogunwale04ad7b12015-10-02 12:43:27 -0700182 final boolean wasResizing = mResizing;
Chong Zhang3005e752015-09-18 18:46:28 -0700183 synchronized (mService.mWindowMap) {
184 endDragLocked();
185 }
Chong Zhang09b21ef2015-09-14 10:20:21 -0700186 try {
Wale Ogunwale04ad7b12015-10-02 12:43:27 -0700187 if (wasResizing) {
Chong Zhang3005e752015-09-18 18:46:28 -0700188 // We were using fullscreen surface during resizing. Request
189 // resizeTask() one last time to restore surface to window size.
190 mService.mActivityManager.resizeTask(
Chong Zhang6de2ae82015-09-30 18:25:21 -0700191 mTask.mTaskId, mWindowDragBounds, RESIZE_MODE_USER_FORCED);
Chong Zhang3005e752015-09-18 18:46:28 -0700192 }
193
194 if (mCurrentDimSide != CTRL_NONE) {
195 final int createMode = mCurrentDimSide == CTRL_LEFT
196 ? DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT
197 : DOCKED_STACK_CREATE_MODE_BOTTOM_OR_RIGHT;
198 mService.mActivityManager.moveTaskToDockedStack(
199 mTask.mTaskId, createMode, true /*toTop*/);
200 }
Chong Zhang09b21ef2015-09-14 10:20:21 -0700201 } catch(RemoteException e) {}
Chong Zhang3005e752015-09-18 18:46:28 -0700202
Chong Zhang8e89b312015-09-09 15:09:30 -0700203 // Post back to WM to handle clean-ups. We still need the input
204 // event handler for the last finishInputEvent()!
205 mService.mH.sendEmptyMessage(H.FINISH_TASK_POSITIONING);
206 }
207 handled = true;
208 } catch (Exception e) {
209 Slog.e(TAG, "Exception caught by drag handleMotion", e);
210 } finally {
211 finishInputEvent(event, handled);
212 }
213 }
214 }
215
216 TaskPositioner(WindowManagerService service) {
217 mService = service;
218 }
219
220 /**
221 * @param display The Display that the window being dragged is on.
222 */
223 void register(Display display) {
224 if (DEBUG_TASK_POSITIONING) {
225 Slog.d(TAG, "Registering task positioner");
226 }
227
228 if (mClientChannel != null) {
229 Slog.e(TAG, "Task positioner already registered");
230 return;
231 }
232
233 mDisplay = display;
234 mDisplay.getMetrics(mDisplayMetrics);
235 final InputChannel[] channels = InputChannel.openInputChannelPair(TAG);
236 mServerChannel = channels[0];
237 mClientChannel = channels[1];
238 mService.mInputManager.registerInputChannel(mServerChannel, null);
239
Wale Ogunwale4f52bc62015-09-24 13:47:31 -0700240 mInputEventReceiver = new WindowPositionerEventReceiver(
241 mClientChannel, mService.mH.getLooper(), mService.mChoreographer);
Chong Zhang8e89b312015-09-09 15:09:30 -0700242
243 mDragApplicationHandle = new InputApplicationHandle(null);
244 mDragApplicationHandle.name = TAG;
245 mDragApplicationHandle.dispatchingTimeoutNanos =
246 WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
247
248 mDragWindowHandle = new InputWindowHandle(mDragApplicationHandle, null,
249 mDisplay.getDisplayId());
250 mDragWindowHandle.name = TAG;
251 mDragWindowHandle.inputChannel = mServerChannel;
Filip Gruszczynski57b6cce2015-10-06 09:50:51 -0700252 mDragWindowHandle.layer = mService.getDragLayerLocked();
Chong Zhang8e89b312015-09-09 15:09:30 -0700253 mDragWindowHandle.layoutParamsFlags = 0;
254 mDragWindowHandle.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
255 mDragWindowHandle.dispatchingTimeoutNanos =
256 WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
257 mDragWindowHandle.visible = true;
258 mDragWindowHandle.canReceiveKeys = false;
259 mDragWindowHandle.hasFocus = true;
260 mDragWindowHandle.hasWallpaper = false;
261 mDragWindowHandle.paused = false;
262 mDragWindowHandle.ownerPid = Process.myPid();
263 mDragWindowHandle.ownerUid = Process.myUid();
264 mDragWindowHandle.inputFeatures = 0;
265 mDragWindowHandle.scaleFactor = 1.0f;
266
267 // The drag window cannot receive new touches.
268 mDragWindowHandle.touchableRegion.setEmpty();
269
270 // The drag window covers the entire display
271 mDragWindowHandle.frameLeft = 0;
272 mDragWindowHandle.frameTop = 0;
273 final Point p = new Point();
274 mDisplay.getRealSize(p);
275 mDragWindowHandle.frameRight = p.x;
276 mDragWindowHandle.frameBottom = p.y;
277
278 // Pause rotations before a drag.
279 if (WindowManagerService.DEBUG_ORIENTATION) {
280 Slog.d(TAG, "Pausing rotation during re-position");
281 }
282 mService.pauseRotationLocked();
Wale Ogunwale228d4042015-09-13 10:17:34 -0700283
284 mDimLayer = new DimLayer(mService, this, mDisplay.getDisplayId());
Filip Gruszczynski57b6cce2015-10-06 09:50:51 -0700285 mSideMargin = dipToPixel(SIDE_MARGIN_DIP, mDisplayMetrics);
286 mMinVisibleWidth = dipToPixel(MINIMUM_VISIBLE_WIDTH_IN_DP, mDisplayMetrics);
287 mMinVisibleHeight = dipToPixel(MINIMUM_VISIBLE_HEIGHT_IN_DP, mDisplayMetrics);
Wale Ogunwale6a804b82015-09-23 21:04:21 -0700288
289 mDragEnded = false;
Chong Zhang8e89b312015-09-09 15:09:30 -0700290 }
291
292 void unregister() {
293 if (DEBUG_TASK_POSITIONING) {
294 Slog.d(TAG, "Unregistering task positioner");
295 }
296
297 if (mClientChannel == null) {
298 Slog.e(TAG, "Task positioner not registered");
299 return;
300 }
301
302 mService.mInputManager.unregisterInputChannel(mServerChannel);
303
304 mInputEventReceiver.dispose();
305 mInputEventReceiver = null;
306 mClientChannel.dispose();
307 mServerChannel.dispose();
308 mClientChannel = null;
309 mServerChannel = null;
310
311 mDragWindowHandle = null;
312 mDragApplicationHandle = null;
313 mDisplay = null;
314
Wale Ogunwale228d4042015-09-13 10:17:34 -0700315 if (mDimLayer != null) {
316 mDimLayer.destroySurface();
317 mDimLayer = null;
318 }
319 mCurrentDimSide = CTRL_NONE;
Wale Ogunwale6a804b82015-09-23 21:04:21 -0700320 mDragEnded = true;
Wale Ogunwale228d4042015-09-13 10:17:34 -0700321
Chong Zhang8e89b312015-09-09 15:09:30 -0700322 // Resume rotations after a drag.
323 if (WindowManagerService.DEBUG_ORIENTATION) {
324 Slog.d(TAG, "Resuming rotation after re-position");
325 }
326 mService.resumeRotationLocked();
327 }
328
329 void startDragLocked(WindowState win, boolean resize, float startX, float startY) {
Wale Ogunwale228d4042015-09-13 10:17:34 -0700330 if (DEBUG_TASK_POSITIONING) {
331 Slog.d(TAG, "startDragLocked: win=" + win + ", resize=" + resize
Chong Zhang8e89b312015-09-09 15:09:30 -0700332 + ", {" + startX + ", " + startY + "}");
333 }
334 mCtrlType = CTRL_NONE;
Chong Zhangd8ceb852015-11-11 14:53:41 -0800335 mTask = win.getTask();
336 mStartDragX = startX;
337 mStartDragY = startY;
338
339 // Use the dim bounds, not the original task bounds. The cursor
340 // movement should be calculated relative to the visible bounds.
341 // Also, use the dim bounds of the task which accounts for
342 // multiple app windows. Don't use any bounds from win itself as it
343 // may not be the same size as the task.
344 mTask.getDimBounds(mTmpRect);
345
Chong Zhang8e89b312015-09-09 15:09:30 -0700346 if (resize) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800347 if (startX < mTmpRect.left) {
Chong Zhang8e89b312015-09-09 15:09:30 -0700348 mCtrlType |= CTRL_LEFT;
349 }
Chong Zhangd8ceb852015-11-11 14:53:41 -0800350 if (startX > mTmpRect.right) {
Chong Zhang8e89b312015-09-09 15:09:30 -0700351 mCtrlType |= CTRL_RIGHT;
352 }
Chong Zhangd8ceb852015-11-11 14:53:41 -0800353 if (startY < mTmpRect.top) {
Chong Zhang8e89b312015-09-09 15:09:30 -0700354 mCtrlType |= CTRL_TOP;
355 }
Chong Zhangd8ceb852015-11-11 14:53:41 -0800356 if (startY > mTmpRect.bottom) {
Chong Zhang8e89b312015-09-09 15:09:30 -0700357 mCtrlType |= CTRL_BOTTOM;
358 }
Chong Zhang09b21ef2015-09-14 10:20:21 -0700359 mResizing = true;
Chong Zhang8e89b312015-09-09 15:09:30 -0700360 }
361
Chong Zhangd8ceb852015-11-11 14:53:41 -0800362 mWindowOriginalBounds.set(mTmpRect);
Chong Zhang3005e752015-09-18 18:46:28 -0700363 }
364
365 private void endDragLocked() {
366 mResizing = false;
367 mTask.setDragResizing(false);
Chong Zhang8e89b312015-09-09 15:09:30 -0700368 }
369
Wale Ogunwaleb8051b82015-09-17 15:41:52 -0700370 /** Returns true if the move operation should be ended. */
371 private boolean notifyMoveLocked(float x, float y) {
Chong Zhang8e89b312015-09-09 15:09:30 -0700372 if (DEBUG_TASK_POSITIONING) {
373 Slog.d(TAG, "notifyMoveLw: {" + x + "," + y + "}");
374 }
375
376 if (mCtrlType != CTRL_NONE) {
377 // This is a resizing operation.
378 final int deltaX = Math.round(x - mStartDragX);
379 final int deltaY = Math.round(y - mStartDragY);
Chong Zhang8e89b312015-09-09 15:09:30 -0700380 int left = mWindowOriginalBounds.left;
381 int top = mWindowOriginalBounds.top;
382 int right = mWindowOriginalBounds.right;
383 int bottom = mWindowOriginalBounds.bottom;
384 if ((mCtrlType & CTRL_LEFT) != 0) {
Wale Ogunwaleb8051b82015-09-17 15:41:52 -0700385 left = Math.min(left + deltaX, right - mMinVisibleWidth);
Chong Zhang8e89b312015-09-09 15:09:30 -0700386 }
387 if ((mCtrlType & CTRL_TOP) != 0) {
Wale Ogunwaleb8051b82015-09-17 15:41:52 -0700388 top = Math.min(top + deltaY, bottom - mMinVisibleHeight);
Chong Zhang8e89b312015-09-09 15:09:30 -0700389 }
390 if ((mCtrlType & CTRL_RIGHT) != 0) {
Wale Ogunwaleb8051b82015-09-17 15:41:52 -0700391 right = Math.max(left + mMinVisibleWidth, right + deltaX);
Chong Zhang8e89b312015-09-09 15:09:30 -0700392 }
393 if ((mCtrlType & CTRL_BOTTOM) != 0) {
Wale Ogunwaleb8051b82015-09-17 15:41:52 -0700394 bottom = Math.max(top + mMinVisibleHeight, bottom + deltaY);
Chong Zhang8e89b312015-09-09 15:09:30 -0700395 }
396 mWindowDragBounds.set(left, top, right, bottom);
Chong Zhang3005e752015-09-18 18:46:28 -0700397 mTask.setDragResizing(true);
Wale Ogunwaleb8051b82015-09-17 15:41:52 -0700398 return false;
Chong Zhang8e89b312015-09-09 15:09:30 -0700399 }
Wale Ogunwaleb8051b82015-09-17 15:41:52 -0700400
401 // This is a moving operation.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800402 mTask.mStack.getDimBounds(mTmpRect);
Wale Ogunwaleb8051b82015-09-17 15:41:52 -0700403 mTmpRect.inset(mMinVisibleWidth, mMinVisibleHeight);
404 if (!mTmpRect.contains((int) x, (int) y)) {
405 // We end the moving operation if position is outside the stack bounds.
406 return true;
407 }
408 mWindowDragBounds.set(mWindowOriginalBounds);
409 mWindowDragBounds.offset(Math.round(x - mStartDragX), Math.round(y - mStartDragY));
410 updateDimLayerVisibility((int) x);
411 return false;
Chong Zhang8e89b312015-09-09 15:09:30 -0700412 }
413
Wale Ogunwale228d4042015-09-13 10:17:34 -0700414 private void updateDimLayerVisibility(int x) {
415 @CtrlType
416 int dimSide = getDimSide(x);
417 if (dimSide == mCurrentDimSide) {
418 return;
419 }
420
421 mCurrentDimSide = dimSide;
422
423 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION updateDimLayerVisibility");
424 SurfaceControl.openTransaction();
425 if (mCurrentDimSide == CTRL_NONE) {
426 mDimLayer.hide();
427 } else {
428 showDimLayer();
429 }
430 SurfaceControl.closeTransaction();
431 }
432
433 /**
434 * Returns the side of the screen the dim layer should be shown.
435 * @param x horizontal coordinate used to determine if the dim layer should be shown
436 * @return Returns {@link #CTRL_LEFT} if the dim layer should be shown on the left half of the
437 * screen, {@link #CTRL_RIGHT} if on the right side, or {@link #CTRL_NONE} if the dim layer
438 * shouldn't be shown.
439 */
440 private int getDimSide(int x) {
Chong Zhang3005e752015-09-18 18:46:28 -0700441 if (mTask.mStack.mStackId != FREEFORM_WORKSPACE_STACK_ID
442 || !mTask.mStack.isFullscreen()
Wale Ogunwale228d4042015-09-13 10:17:34 -0700443 || mService.mCurConfiguration.orientation != ORIENTATION_LANDSCAPE) {
444 return CTRL_NONE;
445 }
446
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800447 mTask.mStack.getDimBounds(mTmpRect);
Wale Ogunwale228d4042015-09-13 10:17:34 -0700448 if (x - mSideMargin <= mTmpRect.left) {
449 return CTRL_LEFT;
450 }
451 if (x + mSideMargin >= mTmpRect.right) {
452 return CTRL_RIGHT;
453 }
454
455 return CTRL_NONE;
456 }
457
458 private void showDimLayer() {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800459 mTask.mStack.getDimBounds(mTmpRect);
Wale Ogunwale228d4042015-09-13 10:17:34 -0700460 if (mCurrentDimSide == CTRL_LEFT) {
461 mTmpRect.right = mTmpRect.centerX();
462 } else if (mCurrentDimSide == CTRL_RIGHT) {
463 mTmpRect.left = mTmpRect.centerX();
464 }
465
466 mDimLayer.setBounds(mTmpRect);
Filip Gruszczynski57b6cce2015-10-06 09:50:51 -0700467 mDimLayer.show(mService.getDragLayerLocked(), RESIZING_HINT_ALPHA,
468 RESIZING_HINT_DURATION_MS);
Wale Ogunwale228d4042015-09-13 10:17:34 -0700469 }
470
471 @Override /** {@link DimLayer.DimLayerUser} */
472 public boolean isFullscreen() {
473 return false;
474 }
475
476 @Override /** {@link DimLayer.DimLayerUser} */
477 public DisplayInfo getDisplayInfo() {
Chong Zhang3005e752015-09-18 18:46:28 -0700478 return mTask.mStack.getDisplayInfo();
Wale Ogunwale228d4042015-09-13 10:17:34 -0700479 }
480
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700481 @Override
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800482 public void getDimBounds(Rect out) {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700483 // This dim layer user doesn't need this.
484 }
485
486 @Override
487 public String toShortString() {
488 return TAG;
489 }
Wale Ogunwale228d4042015-09-13 10:17:34 -0700490}