Merge "Minor style cleanup for Shell caption classes." into tm-qpr-dev

This commit is contained in:
Merissa Mitchell
2023-01-13 22:40:18 +00:00
committed by Android (Google) Code Review
4 changed files with 112 additions and 116 deletions

View File

@@ -136,7 +136,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
} }
private void setupCaptionColor(RunningTaskInfo taskInfo, CaptionWindowDecoration decoration) { private void setupCaptionColor(RunningTaskInfo taskInfo, CaptionWindowDecoration decoration) {
int statusBarColor = taskInfo.taskDescription.getStatusBarColor(); final int statusBarColor = taskInfo.taskDescription.getStatusBarColor();
decoration.setCaptionColor(statusBarColor); decoration.setCaptionColor(statusBarColor);
} }
@@ -152,7 +152,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
SurfaceControl taskSurface, SurfaceControl taskSurface,
SurfaceControl.Transaction startT, SurfaceControl.Transaction startT,
SurfaceControl.Transaction finishT) { SurfaceControl.Transaction finishT) {
CaptionWindowDecoration oldDecoration = mWindowDecorByTaskId.get(taskInfo.taskId); final CaptionWindowDecoration oldDecoration = mWindowDecorByTaskId.get(taskInfo.taskId);
if (oldDecoration != null) { if (oldDecoration != null) {
// close the old decoration if it exists to avoid two window decorations being added // close the old decoration if it exists to avoid two window decorations being added
oldDecoration.close(); oldDecoration.close();
@@ -169,9 +169,9 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
mSyncQueue); mSyncQueue);
mWindowDecorByTaskId.put(taskInfo.taskId, windowDecoration); mWindowDecorByTaskId.put(taskInfo.taskId, windowDecoration);
TaskPositioner taskPositioner = final TaskPositioner taskPositioner =
new TaskPositioner(mTaskOrganizer, windowDecoration); new TaskPositioner(mTaskOrganizer, windowDecoration);
CaptionTouchEventListener touchEventListener = final CaptionTouchEventListener touchEventListener =
new CaptionTouchEventListener(taskInfo, taskPositioner); new CaptionTouchEventListener(taskInfo, taskPositioner);
windowDecoration.setCaptionListeners(touchEventListener, touchEventListener); windowDecoration.setCaptionListeners(touchEventListener, touchEventListener);
windowDecoration.setDragResizeCallback(taskPositioner); windowDecoration.setDragResizeCallback(taskPositioner);
@@ -221,11 +221,11 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
if (e.getAction() != MotionEvent.ACTION_DOWN) { if (e.getAction() != MotionEvent.ACTION_DOWN) {
return false; return false;
} }
RunningTaskInfo taskInfo = mTaskOrganizer.getRunningTaskInfo(mTaskId); final RunningTaskInfo taskInfo = mTaskOrganizer.getRunningTaskInfo(mTaskId);
if (taskInfo.isFocused) { if (taskInfo.isFocused) {
return false; return false;
} }
WindowContainerTransaction wct = new WindowContainerTransaction(); final WindowContainerTransaction wct = new WindowContainerTransaction();
wct.reorder(mTaskToken, true /* onTop */); wct.reorder(mTaskToken, true /* onTop */);
mSyncQueue.queue(wct); mSyncQueue.queue(wct);
return true; return true;
@@ -236,7 +236,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
* @return {@code true} if a drag is happening; or {@code false} if it is not * @return {@code true} if a drag is happening; or {@code false} if it is not
*/ */
private void handleEventForMove(MotionEvent e) { private void handleEventForMove(MotionEvent e) {
RunningTaskInfo taskInfo = mTaskOrganizer.getRunningTaskInfo(mTaskId); final RunningTaskInfo taskInfo = mTaskOrganizer.getRunningTaskInfo(mTaskId);
if (taskInfo.getWindowingMode() == WINDOWING_MODE_FULLSCREEN) { if (taskInfo.getWindowingMode() == WINDOWING_MODE_FULLSCREEN) {
return; return;
} }

View File

@@ -48,15 +48,13 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
private View.OnClickListener mOnCaptionButtonClickListener; private View.OnClickListener mOnCaptionButtonClickListener;
private View.OnTouchListener mOnCaptionTouchListener; private View.OnTouchListener mOnCaptionTouchListener;
private DragResizeCallback mDragResizeCallback; private DragResizeCallback mDragResizeCallback;
private DragResizeInputListener mDragResizeListener; private DragResizeInputListener mDragResizeListener;
private final DragDetector mDragDetector;
private RelayoutParams mRelayoutParams = new RelayoutParams(); private RelayoutParams mRelayoutParams = new RelayoutParams();
private final RelayoutResult<WindowDecorLinearLayout> mResult = private final RelayoutResult<WindowDecorLinearLayout> mResult =
new RelayoutResult<>(); new RelayoutResult<>();
private DragDetector mDragDetector;
CaptionWindowDecoration( CaptionWindowDecoration(
Context context, Context context,
DisplayController displayController, DisplayController displayController,
@@ -104,14 +102,14 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
taskInfo.getWindowingMode() == WindowConfiguration.WINDOWING_MODE_FREEFORM; taskInfo.getWindowingMode() == WindowConfiguration.WINDOWING_MODE_FREEFORM;
final boolean isDragResizeable = isFreeform && taskInfo.isResizeable; final boolean isDragResizeable = isFreeform && taskInfo.isResizeable;
WindowDecorLinearLayout oldRootView = mResult.mRootView; final WindowDecorLinearLayout oldRootView = mResult.mRootView;
final SurfaceControl oldDecorationSurface = mDecorationContainerSurface; final SurfaceControl oldDecorationSurface = mDecorationContainerSurface;
final WindowContainerTransaction wct = new WindowContainerTransaction(); final WindowContainerTransaction wct = new WindowContainerTransaction();
int outsetLeftId = R.dimen.freeform_resize_handle; final int outsetLeftId = R.dimen.freeform_resize_handle;
int outsetTopId = R.dimen.freeform_resize_handle; final int outsetTopId = R.dimen.freeform_resize_handle;
int outsetRightId = R.dimen.freeform_resize_handle; final int outsetRightId = R.dimen.freeform_resize_handle;
int outsetBottomId = R.dimen.freeform_resize_handle; final int outsetBottomId = R.dimen.freeform_resize_handle;
mRelayoutParams.reset(); mRelayoutParams.reset();
mRelayoutParams.mRunningTaskInfo = taskInfo; mRelayoutParams.mRunningTaskInfo = taskInfo;
@@ -123,7 +121,7 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
} }
relayout(mRelayoutParams, startT, finishT, wct, oldRootView, mResult); relayout(mRelayoutParams, startT, finishT, wct, oldRootView, mResult);
taskInfo = null; // Clear it just in case we use it accidentally // After this line, mTaskInfo is up-to-date and should be used instead of taskInfo
mTaskOrganizer.applyTransaction(wct); mTaskOrganizer.applyTransaction(wct);
@@ -152,12 +150,13 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
mDragResizeCallback); mDragResizeCallback);
} }
int touchSlop = ViewConfiguration.get(mResult.mRootView.getContext()).getScaledTouchSlop(); final int touchSlop = ViewConfiguration.get(mResult.mRootView.getContext())
.getScaledTouchSlop();
mDragDetector.setTouchSlop(touchSlop); mDragDetector.setTouchSlop(touchSlop);
int resize_handle = mResult.mRootView.getResources() final int resize_handle = mResult.mRootView.getResources()
.getDimensionPixelSize(R.dimen.freeform_resize_handle); .getDimensionPixelSize(R.dimen.freeform_resize_handle);
int resize_corner = mResult.mRootView.getResources() final int resize_corner = mResult.mRootView.getResources()
.getDimensionPixelSize(R.dimen.freeform_resize_corner); .getDimensionPixelSize(R.dimen.freeform_resize_corner);
mDragResizeListener.setGeometry( mDragResizeListener.setGeometry(
mResult.mWidth, mResult.mHeight, resize_handle, resize_corner, touchSlop); mResult.mWidth, mResult.mHeight, resize_handle, resize_corner, touchSlop);
@@ -167,15 +166,15 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
* Sets up listeners when a new root view is created. * Sets up listeners when a new root view is created.
*/ */
private void setupRootView() { private void setupRootView() {
View caption = mResult.mRootView.findViewById(R.id.caption); final View caption = mResult.mRootView.findViewById(R.id.caption);
caption.setOnTouchListener(mOnCaptionTouchListener); caption.setOnTouchListener(mOnCaptionTouchListener);
View close = caption.findViewById(R.id.close_window); final View close = caption.findViewById(R.id.close_window);
close.setOnClickListener(mOnCaptionButtonClickListener); close.setOnClickListener(mOnCaptionButtonClickListener);
View back = caption.findViewById(R.id.back_button); final View back = caption.findViewById(R.id.back_button);
back.setOnClickListener(mOnCaptionButtonClickListener); back.setOnClickListener(mOnCaptionButtonClickListener);
View minimize = caption.findViewById(R.id.minimize_window); final View minimize = caption.findViewById(R.id.minimize_window);
minimize.setOnClickListener(mOnCaptionButtonClickListener); minimize.setOnClickListener(mOnCaptionButtonClickListener);
View maximize = caption.findViewById(R.id.maximize_window); final View maximize = caption.findViewById(R.id.maximize_window);
maximize.setOnClickListener(mOnCaptionButtonClickListener); maximize.setOnClickListener(mOnCaptionButtonClickListener);
} }
@@ -184,31 +183,31 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
return; return;
} }
View caption = mResult.mRootView.findViewById(R.id.caption); final View caption = mResult.mRootView.findViewById(R.id.caption);
GradientDrawable captionDrawable = (GradientDrawable) caption.getBackground(); final GradientDrawable captionDrawable = (GradientDrawable) caption.getBackground();
captionDrawable.setColor(captionColor); captionDrawable.setColor(captionColor);
int buttonTintColorRes = final int buttonTintColorRes =
Color.valueOf(captionColor).luminance() < 0.5 Color.valueOf(captionColor).luminance() < 0.5
? R.color.decor_button_light_color ? R.color.decor_button_light_color
: R.color.decor_button_dark_color; : R.color.decor_button_dark_color;
ColorStateList buttonTintColor = final ColorStateList buttonTintColor =
caption.getResources().getColorStateList(buttonTintColorRes, null /* theme */); caption.getResources().getColorStateList(buttonTintColorRes, null /* theme */);
View back = caption.findViewById(R.id.back_button); final View back = caption.findViewById(R.id.back_button);
VectorDrawable backBackground = (VectorDrawable) back.getBackground(); final VectorDrawable backBackground = (VectorDrawable) back.getBackground();
backBackground.setTintList(buttonTintColor); backBackground.setTintList(buttonTintColor);
View minimize = caption.findViewById(R.id.minimize_window); final View minimize = caption.findViewById(R.id.minimize_window);
VectorDrawable minimizeBackground = (VectorDrawable) minimize.getBackground(); final VectorDrawable minimizeBackground = (VectorDrawable) minimize.getBackground();
minimizeBackground.setTintList(buttonTintColor); minimizeBackground.setTintList(buttonTintColor);
View maximize = caption.findViewById(R.id.maximize_window); final View maximize = caption.findViewById(R.id.maximize_window);
VectorDrawable maximizeBackground = (VectorDrawable) maximize.getBackground(); final VectorDrawable maximizeBackground = (VectorDrawable) maximize.getBackground();
maximizeBackground.setTintList(buttonTintColor); maximizeBackground.setTintList(buttonTintColor);
View close = caption.findViewById(R.id.close_window); final View close = caption.findViewById(R.id.close_window);
VectorDrawable closeBackground = (VectorDrawable) close.getBackground(); final VectorDrawable closeBackground = (VectorDrawable) close.getBackground();
closeBackground.setTintList(buttonTintColor); closeBackground.setTintList(buttonTintColor);
} }

View File

@@ -68,9 +68,8 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
private final Choreographer mMainChoreographer; private final Choreographer mMainChoreographer;
private final DisplayController mDisplayController; private final DisplayController mDisplayController;
private final SyncTransactionQueue mSyncQueue; private final SyncTransactionQueue mSyncQueue;
private FreeformTaskTransitionStarter mTransitionStarter; private final Optional<DesktopModeController> mDesktopModeController;
private Optional<DesktopModeController> mDesktopModeController; private final Optional<DesktopTasksController> mDesktopTasksController;
private Optional<DesktopTasksController> mDesktopTasksController;
private boolean mTransitionDragActive; private boolean mTransitionDragActive;
private SparseArray<EventReceiver> mEventReceiversByDisplay = new SparseArray<>(); private SparseArray<EventReceiver> mEventReceiversByDisplay = new SparseArray<>();
@@ -78,7 +77,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
private final SparseArray<DesktopModeWindowDecoration> mWindowDecorByTaskId = private final SparseArray<DesktopModeWindowDecoration> mWindowDecorByTaskId =
new SparseArray<>(); new SparseArray<>();
private final DragStartListenerImpl mDragStartListener = new DragStartListenerImpl(); private final DragStartListenerImpl mDragStartListener = new DragStartListenerImpl();
private InputMonitorFactory mInputMonitorFactory; private final InputMonitorFactory mInputMonitorFactory;
private TaskOperations mTaskOperations; private TaskOperations mTaskOperations;
public DesktopModeWindowDecorViewModel( public DesktopModeWindowDecorViewModel(
@@ -199,7 +198,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
if (decoration == null) return; if (decoration == null) return;
decoration.close(); decoration.close();
int displayId = taskInfo.displayId; final int displayId = taskInfo.displayId;
if (mEventReceiversByDisplay.contains(displayId)) { if (mEventReceiversByDisplay.contains(displayId)) {
removeTaskFromEventReceiver(displayId); removeTaskFromEventReceiver(displayId);
} }
@@ -227,7 +226,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
DesktopModeWindowDecoration decoration = mWindowDecorByTaskId.get(mTaskId); final DesktopModeWindowDecoration decoration = mWindowDecorByTaskId.get(mTaskId);
final int id = v.getId(); final int id = v.getId();
if (id == R.id.close_window) { if (id == R.id.close_window) {
mTaskOperations.closeTask(mTaskToken); mTaskOperations.closeTask(mTaskToken);
@@ -250,7 +249,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
@Override @Override
public boolean onTouch(View v, MotionEvent e) { public boolean onTouch(View v, MotionEvent e) {
boolean isDrag = false; boolean isDrag = false;
int id = v.getId(); final int id = v.getId();
if (id != R.id.caption_handle && id != R.id.desktop_mode_caption) { if (id != R.id.caption_handle && id != R.id.desktop_mode_caption) {
return false; return false;
} }
@@ -261,11 +260,11 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
if (e.getAction() != MotionEvent.ACTION_DOWN) { if (e.getAction() != MotionEvent.ACTION_DOWN) {
return isDrag; return isDrag;
} }
RunningTaskInfo taskInfo = mTaskOrganizer.getRunningTaskInfo(mTaskId); final RunningTaskInfo taskInfo = mTaskOrganizer.getRunningTaskInfo(mTaskId);
if (taskInfo.isFocused) { if (taskInfo.isFocused) {
return isDrag; return isDrag;
} }
WindowContainerTransaction wct = new WindowContainerTransaction(); final WindowContainerTransaction wct = new WindowContainerTransaction();
wct.reorder(mTaskToken, true /* onTop */); wct.reorder(mTaskToken, true /* onTop */);
mSyncQueue.queue(wct); mSyncQueue.queue(wct);
return true; return true;
@@ -276,7 +275,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
* @return {@code true} if a drag is happening; or {@code false} if it is not * @return {@code true} if a drag is happening; or {@code false} if it is not
*/ */
private void handleEventForMove(MotionEvent e) { private void handleEventForMove(MotionEvent e) {
RunningTaskInfo taskInfo = mTaskOrganizer.getRunningTaskInfo(mTaskId); final RunningTaskInfo taskInfo = mTaskOrganizer.getRunningTaskInfo(mTaskId);
if (DesktopModeStatus.isProto2Enabled() if (DesktopModeStatus.isProto2Enabled()
&& taskInfo.getWindowingMode() == WINDOWING_MODE_FULLSCREEN) { && taskInfo.getWindowingMode() == WINDOWING_MODE_FULLSCREEN) {
return; return;
@@ -295,16 +294,16 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
break; break;
} }
case MotionEvent.ACTION_MOVE: { case MotionEvent.ACTION_MOVE: {
int dragPointerIdx = e.findPointerIndex(mDragPointerId); final int dragPointerIdx = e.findPointerIndex(mDragPointerId);
mDragResizeCallback.onDragResizeMove( mDragResizeCallback.onDragResizeMove(
e.getRawX(dragPointerIdx), e.getRawY(dragPointerIdx)); e.getRawX(dragPointerIdx), e.getRawY(dragPointerIdx));
break; break;
} }
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL: { case MotionEvent.ACTION_CANCEL: {
int dragPointerIdx = e.findPointerIndex(mDragPointerId); final int dragPointerIdx = e.findPointerIndex(mDragPointerId);
int statusBarHeight = mDisplayController.getDisplayLayout(taskInfo.displayId) final int statusBarHeight = mDisplayController
.stableInsets().top; .getDisplayLayout(taskInfo.displayId).stableInsets().top;
mDragResizeCallback.onDragResizeEnd( mDragResizeCallback.onDragResizeEnd(
e.getRawX(dragPointerIdx), e.getRawY(dragPointerIdx)); e.getRawX(dragPointerIdx), e.getRawY(dragPointerIdx));
if (e.getRawY(dragPointerIdx) <= statusBarHeight) { if (e.getRawY(dragPointerIdx) <= statusBarHeight) {
@@ -378,7 +377,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
*/ */
private void incrementEventReceiverTasks(int displayId) { private void incrementEventReceiverTasks(int displayId) {
if (mEventReceiversByDisplay.contains(displayId)) { if (mEventReceiversByDisplay.contains(displayId)) {
EventReceiver eventReceiver = mEventReceiversByDisplay.get(displayId); final EventReceiver eventReceiver = mEventReceiversByDisplay.get(displayId);
eventReceiver.incrementTaskNumber(); eventReceiver.incrementTaskNumber();
} else { } else {
createInputChannel(displayId); createInputChannel(displayId);
@@ -388,7 +387,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
// If all tasks on this display are gone, we don't need to monitor its input. // If all tasks on this display are gone, we don't need to monitor its input.
private void removeTaskFromEventReceiver(int displayId) { private void removeTaskFromEventReceiver(int displayId) {
if (!mEventReceiversByDisplay.contains(displayId)) return; if (!mEventReceiversByDisplay.contains(displayId)) return;
EventReceiver eventReceiver = mEventReceiversByDisplay.get(displayId); final EventReceiver eventReceiver = mEventReceiversByDisplay.get(displayId);
if (eventReceiver == null) return; if (eventReceiver == null) return;
eventReceiver.decrementTaskNumber(); eventReceiver.decrementTaskNumber();
if (eventReceiver.getTasksOnDisplay() == 0) { if (eventReceiver.getTasksOnDisplay() == 0) {
@@ -403,7 +402,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
*/ */
private void handleReceivedMotionEvent(MotionEvent ev, InputMonitor inputMonitor) { private void handleReceivedMotionEvent(MotionEvent ev, InputMonitor inputMonitor) {
if (DesktopModeStatus.isProto2Enabled()) { if (DesktopModeStatus.isProto2Enabled()) {
DesktopModeWindowDecoration focusedDecor = getFocusedDecor(); final DesktopModeWindowDecoration focusedDecor = getFocusedDecor();
if (focusedDecor == null if (focusedDecor == null
|| focusedDecor.mTaskInfo.getWindowingMode() != WINDOWING_MODE_FREEFORM) { || focusedDecor.mTaskInfo.getWindowingMode() != WINDOWING_MODE_FREEFORM) {
handleCaptionThroughStatusBar(ev); handleCaptionThroughStatusBar(ev);
@@ -428,9 +427,9 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
// If an UP/CANCEL action is received outside of caption bounds, turn off handle menu // If an UP/CANCEL action is received outside of caption bounds, turn off handle menu
private void handleEventOutsideFocusedCaption(MotionEvent ev) { private void handleEventOutsideFocusedCaption(MotionEvent ev) {
int action = ev.getActionMasked(); final int action = ev.getActionMasked();
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
DesktopModeWindowDecoration focusedDecor = getFocusedDecor(); final DesktopModeWindowDecoration focusedDecor = getFocusedDecor();
if (focusedDecor == null) { if (focusedDecor == null) {
return; return;
} }
@@ -450,7 +449,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
switch (ev.getActionMasked()) { switch (ev.getActionMasked()) {
case MotionEvent.ACTION_DOWN: { case MotionEvent.ACTION_DOWN: {
// Begin drag through status bar if applicable. // Begin drag through status bar if applicable.
DesktopModeWindowDecoration focusedDecor = getFocusedDecor(); final DesktopModeWindowDecoration focusedDecor = getFocusedDecor();
if (focusedDecor != null) { if (focusedDecor != null) {
boolean dragFromStatusBarAllowed = false; boolean dragFromStatusBarAllowed = false;
if (DesktopModeStatus.isProto2Enabled()) { if (DesktopModeStatus.isProto2Enabled()) {
@@ -469,14 +468,14 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
break; break;
} }
case MotionEvent.ACTION_UP: { case MotionEvent.ACTION_UP: {
DesktopModeWindowDecoration focusedDecor = getFocusedDecor(); final DesktopModeWindowDecoration focusedDecor = getFocusedDecor();
if (focusedDecor == null) { if (focusedDecor == null) {
mTransitionDragActive = false; mTransitionDragActive = false;
return; return;
} }
if (mTransitionDragActive) { if (mTransitionDragActive) {
mTransitionDragActive = false; mTransitionDragActive = false;
int statusBarHeight = mDisplayController final int statusBarHeight = mDisplayController
.getDisplayLayout(focusedDecor.mTaskInfo.displayId).stableInsets().top; .getDisplayLayout(focusedDecor.mTaskInfo.displayId).stableInsets().top;
if (ev.getY() > statusBarHeight) { if (ev.getY() > statusBarHeight) {
if (DesktopModeStatus.isProto2Enabled()) { if (DesktopModeStatus.isProto2Enabled()) {
@@ -500,10 +499,10 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
@Nullable @Nullable
private DesktopModeWindowDecoration getFocusedDecor() { private DesktopModeWindowDecoration getFocusedDecor() {
int size = mWindowDecorByTaskId.size(); final int size = mWindowDecorByTaskId.size();
DesktopModeWindowDecoration focusedDecor = null; DesktopModeWindowDecoration focusedDecor = null;
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
DesktopModeWindowDecoration decor = mWindowDecorByTaskId.valueAt(i); final DesktopModeWindowDecoration decor = mWindowDecorByTaskId.valueAt(i);
if (decor != null && decor.isFocused()) { if (decor != null && decor.isFocused()) {
focusedDecor = decor; focusedDecor = decor;
break; break;
@@ -513,16 +512,16 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
} }
private void createInputChannel(int displayId) { private void createInputChannel(int displayId) {
InputManager inputManager = InputManager.getInstance(); final InputManager inputManager = InputManager.getInstance();
InputMonitor inputMonitor = final InputMonitor inputMonitor =
mInputMonitorFactory.create(inputManager, mContext); mInputMonitorFactory.create(inputManager, mContext);
EventReceiver eventReceiver = new EventReceiver(inputMonitor, final EventReceiver eventReceiver = new EventReceiver(inputMonitor,
inputMonitor.getInputChannel(), Looper.myLooper()); inputMonitor.getInputChannel(), Looper.myLooper());
mEventReceiversByDisplay.put(displayId, eventReceiver); mEventReceiversByDisplay.put(displayId, eventReceiver);
} }
private void disposeInputChannel(int displayId) { private void disposeInputChannel(int displayId) {
EventReceiver eventReceiver = mEventReceiversByDisplay.removeReturnOld(displayId); final EventReceiver eventReceiver = mEventReceiversByDisplay.removeReturnOld(displayId);
if (eventReceiver != null) { if (eventReceiver != null) {
eventReceiver.dispose(); eventReceiver.dispose();
} }
@@ -541,7 +540,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
SurfaceControl taskSurface, SurfaceControl taskSurface,
SurfaceControl.Transaction startT, SurfaceControl.Transaction startT,
SurfaceControl.Transaction finishT) { SurfaceControl.Transaction finishT) {
DesktopModeWindowDecoration oldDecoration = mWindowDecorByTaskId.get(taskInfo.taskId); final DesktopModeWindowDecoration oldDecoration = mWindowDecorByTaskId.get(taskInfo.taskId);
if (oldDecoration != null) { if (oldDecoration != null) {
// close the old decoration if it exists to avoid two window decorations being added // close the old decoration if it exists to avoid two window decorations being added
oldDecoration.close(); oldDecoration.close();
@@ -558,9 +557,9 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
mSyncQueue); mSyncQueue);
mWindowDecorByTaskId.put(taskInfo.taskId, windowDecoration); mWindowDecorByTaskId.put(taskInfo.taskId, windowDecoration);
TaskPositioner taskPositioner = final TaskPositioner taskPositioner =
new TaskPositioner(mTaskOrganizer, windowDecoration, mDragStartListener); new TaskPositioner(mTaskOrganizer, windowDecoration, mDragStartListener);
DesktopModeTouchEventListener touchEventListener = final DesktopModeTouchEventListener touchEventListener =
new DesktopModeTouchEventListener( new DesktopModeTouchEventListener(
taskInfo, taskPositioner, windowDecoration.getDragDetector()); taskInfo, taskPositioner, windowDecoration.getDragDetector());
windowDecoration.setCaptionListeners(touchEventListener, touchEventListener); windowDecoration.setCaptionListeners(touchEventListener, touchEventListener);

View File

@@ -56,17 +56,14 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
private View.OnClickListener mOnCaptionButtonClickListener; private View.OnClickListener mOnCaptionButtonClickListener;
private View.OnTouchListener mOnCaptionTouchListener; private View.OnTouchListener mOnCaptionTouchListener;
private DragResizeCallback mDragResizeCallback; private DragResizeCallback mDragResizeCallback;
private DragResizeInputListener mDragResizeListener; private DragResizeInputListener mDragResizeListener;
private final DragDetector mDragDetector;
private RelayoutParams mRelayoutParams = new RelayoutParams(); private RelayoutParams mRelayoutParams = new RelayoutParams();
private final WindowDecoration.RelayoutResult<WindowDecorLinearLayout> mResult = private final WindowDecoration.RelayoutResult<WindowDecorLinearLayout> mResult =
new WindowDecoration.RelayoutResult<>(); new WindowDecoration.RelayoutResult<>();
private boolean mDesktopActive; private boolean mDesktopActive;
private DragDetector mDragDetector;
private AdditionalWindow mHandleMenu; private AdditionalWindow mHandleMenu;
DesktopModeWindowDecoration( DesktopModeWindowDecoration(
@@ -121,14 +118,14 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
taskInfo.getWindowingMode() == WINDOWING_MODE_FREEFORM; taskInfo.getWindowingMode() == WINDOWING_MODE_FREEFORM;
final boolean isDragResizeable = isFreeform && taskInfo.isResizeable; final boolean isDragResizeable = isFreeform && taskInfo.isResizeable;
WindowDecorLinearLayout oldRootView = mResult.mRootView; final WindowDecorLinearLayout oldRootView = mResult.mRootView;
final SurfaceControl oldDecorationSurface = mDecorationContainerSurface; final SurfaceControl oldDecorationSurface = mDecorationContainerSurface;
final WindowContainerTransaction wct = new WindowContainerTransaction(); final WindowContainerTransaction wct = new WindowContainerTransaction();
int outsetLeftId = R.dimen.freeform_resize_handle; final int outsetLeftId = R.dimen.freeform_resize_handle;
int outsetTopId = R.dimen.freeform_resize_handle; final int outsetTopId = R.dimen.freeform_resize_handle;
int outsetRightId = R.dimen.freeform_resize_handle; final int outsetRightId = R.dimen.freeform_resize_handle;
int outsetBottomId = R.dimen.freeform_resize_handle; final int outsetBottomId = R.dimen.freeform_resize_handle;
mRelayoutParams.reset(); mRelayoutParams.reset();
mRelayoutParams.mRunningTaskInfo = taskInfo; mRelayoutParams.mRunningTaskInfo = taskInfo;
@@ -152,7 +149,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
mRelayoutParams.setCaptionPosition(captionLeft, captionTop); mRelayoutParams.setCaptionPosition(captionLeft, captionTop);
relayout(mRelayoutParams, startT, finishT, wct, oldRootView, mResult); relayout(mRelayoutParams, startT, finishT, wct, oldRootView, mResult);
taskInfo = null; // Clear it just in case we use it accidentally // After this line, mTaskInfo is up-to-date and should be used instead of taskInfo
mTaskOrganizer.applyTransaction(wct); mTaskOrganizer.applyTransaction(wct);
@@ -197,12 +194,13 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
mDragResizeCallback); mDragResizeCallback);
} }
int touchSlop = ViewConfiguration.get(mResult.mRootView.getContext()).getScaledTouchSlop(); final int touchSlop = ViewConfiguration.get(mResult.mRootView.getContext())
.getScaledTouchSlop();
mDragDetector.setTouchSlop(touchSlop); mDragDetector.setTouchSlop(touchSlop);
int resize_handle = mResult.mRootView.getResources() final int resize_handle = mResult.mRootView.getResources()
.getDimensionPixelSize(R.dimen.freeform_resize_handle); .getDimensionPixelSize(R.dimen.freeform_resize_handle);
int resize_corner = mResult.mRootView.getResources() final int resize_corner = mResult.mRootView.getResources()
.getDimensionPixelSize(R.dimen.freeform_resize_corner); .getDimensionPixelSize(R.dimen.freeform_resize_corner);
mDragResizeListener.setGeometry( mDragResizeListener.setGeometry(
mResult.mWidth, mResult.mHeight, resize_handle, resize_corner, touchSlop); mResult.mWidth, mResult.mHeight, resize_handle, resize_corner, touchSlop);
@@ -212,27 +210,27 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
* Sets up listeners when a new root view is created. * Sets up listeners when a new root view is created.
*/ */
private void setupRootView() { private void setupRootView() {
View caption = mResult.mRootView.findViewById(R.id.desktop_mode_caption); final View caption = mResult.mRootView.findViewById(R.id.desktop_mode_caption);
caption.setOnTouchListener(mOnCaptionTouchListener); caption.setOnTouchListener(mOnCaptionTouchListener);
View close = caption.findViewById(R.id.close_window); final View close = caption.findViewById(R.id.close_window);
close.setOnClickListener(mOnCaptionButtonClickListener); close.setOnClickListener(mOnCaptionButtonClickListener);
View back = caption.findViewById(R.id.back_button); final View back = caption.findViewById(R.id.back_button);
back.setOnClickListener(mOnCaptionButtonClickListener); back.setOnClickListener(mOnCaptionButtonClickListener);
View handle = caption.findViewById(R.id.caption_handle); final View handle = caption.findViewById(R.id.caption_handle);
handle.setOnTouchListener(mOnCaptionTouchListener); handle.setOnTouchListener(mOnCaptionTouchListener);
handle.setOnClickListener(mOnCaptionButtonClickListener); handle.setOnClickListener(mOnCaptionButtonClickListener);
updateButtonVisibility(); updateButtonVisibility();
} }
private void setupHandleMenu() { private void setupHandleMenu() {
View menu = mHandleMenu.mWindowViewHost.getView(); final View menu = mHandleMenu.mWindowViewHost.getView();
View fullscreen = menu.findViewById(R.id.fullscreen_button); final View fullscreen = menu.findViewById(R.id.fullscreen_button);
fullscreen.setOnClickListener(mOnCaptionButtonClickListener); fullscreen.setOnClickListener(mOnCaptionButtonClickListener);
View desktop = menu.findViewById(R.id.desktop_button); final View desktop = menu.findViewById(R.id.desktop_button);
desktop.setOnClickListener(mOnCaptionButtonClickListener); desktop.setOnClickListener(mOnCaptionButtonClickListener);
View split = menu.findViewById(R.id.split_screen_button); final View split = menu.findViewById(R.id.split_screen_button);
split.setOnClickListener(mOnCaptionButtonClickListener); split.setOnClickListener(mOnCaptionButtonClickListener);
View more = menu.findViewById(R.id.more_button); final View more = menu.findViewById(R.id.more_button);
more.setOnClickListener(mOnCaptionButtonClickListener); more.setOnClickListener(mOnCaptionButtonClickListener);
} }
@@ -242,8 +240,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
* @param visible whether or not the caption should be visible * @param visible whether or not the caption should be visible
*/ */
private void setCaptionVisibility(boolean visible) { private void setCaptionVisibility(boolean visible) {
int v = visible ? View.VISIBLE : View.GONE; final int v = visible ? View.VISIBLE : View.GONE;
View captionView = mResult.mRootView.findViewById(R.id.desktop_mode_caption); final View captionView = mResult.mRootView.findViewById(R.id.desktop_mode_caption);
captionView.setVisibility(v); captionView.setVisibility(v);
if (!visible) closeHandleMenu(); if (!visible) closeHandleMenu();
} }
@@ -264,19 +262,19 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
* Show or hide buttons * Show or hide buttons
*/ */
void setButtonVisibility(boolean visible) { void setButtonVisibility(boolean visible) {
int visibility = visible ? View.VISIBLE : View.GONE; final int visibility = visible ? View.VISIBLE : View.GONE;
View caption = mResult.mRootView.findViewById(R.id.desktop_mode_caption); final View caption = mResult.mRootView.findViewById(R.id.desktop_mode_caption);
View back = caption.findViewById(R.id.back_button); final View back = caption.findViewById(R.id.back_button);
View close = caption.findViewById(R.id.close_window); final View close = caption.findViewById(R.id.close_window);
back.setVisibility(visibility); back.setVisibility(visibility);
close.setVisibility(visibility); close.setVisibility(visibility);
int buttonTintColorRes = final int buttonTintColorRes =
mDesktopActive ? R.color.decor_button_dark_color mDesktopActive ? R.color.decor_button_dark_color
: R.color.decor_button_light_color; : R.color.decor_button_light_color;
ColorStateList buttonTintColor = final ColorStateList buttonTintColor =
caption.getResources().getColorStateList(buttonTintColorRes, null /* theme */); caption.getResources().getColorStateList(buttonTintColorRes, null /* theme */);
View handle = caption.findViewById(R.id.caption_handle); final View handle = caption.findViewById(R.id.caption_handle);
VectorDrawable handleBackground = (VectorDrawable) handle.getBackground(); final VectorDrawable handleBackground = (VectorDrawable) handle.getBackground();
handleBackground.setTintList(buttonTintColor); handleBackground.setTintList(buttonTintColor);
caption.getBackground().setTint(visible ? Color.WHITE : Color.TRANSPARENT); caption.getBackground().setTint(visible ? Color.WHITE : Color.TRANSPARENT);
} }
@@ -297,12 +295,12 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
* Create and display handle menu window * Create and display handle menu window
*/ */
void createHandleMenu() { void createHandleMenu() {
SurfaceControl.Transaction t = new SurfaceControl.Transaction(); final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
final Resources resources = mDecorWindowContext.getResources(); final Resources resources = mDecorWindowContext.getResources();
int x = mRelayoutParams.mCaptionX; final int x = mRelayoutParams.mCaptionX;
int y = mRelayoutParams.mCaptionY; final int y = mRelayoutParams.mCaptionY;
int width = loadDimensionPixelSize(resources, mRelayoutParams.mCaptionWidthId); final int width = loadDimensionPixelSize(resources, mRelayoutParams.mCaptionWidthId);
int height = loadDimensionPixelSize(resources, mRelayoutParams.mCaptionHeightId); final int height = loadDimensionPixelSize(resources, mRelayoutParams.mCaptionHeightId);
String namePrefix = "Caption Menu"; String namePrefix = "Caption Menu";
mHandleMenu = addWindow(R.layout.desktop_mode_decor_handle_menu, namePrefix, t, mHandleMenu = addWindow(R.layout.desktop_mode_decor_handle_menu, namePrefix, t,
x - mResult.mDecorContainerOffsetX, y - mResult.mDecorContainerOffsetY, x - mResult.mDecorContainerOffsetX, y - mResult.mDecorContainerOffsetY,
@@ -353,8 +351,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
* @return the point of the input in local space * @return the point of the input in local space
*/ */
private PointF offsetCaptionLocation(MotionEvent ev) { private PointF offsetCaptionLocation(MotionEvent ev) {
PointF result = new PointF(ev.getX(), ev.getY()); final PointF result = new PointF(ev.getX(), ev.getY());
Point positionInParent = mTaskOrganizer.getRunningTaskInfo(mTaskInfo.taskId) final Point positionInParent = mTaskOrganizer.getRunningTaskInfo(mTaskInfo.taskId)
.positionInParent; .positionInParent;
result.offset(-mRelayoutParams.mCaptionX, -mRelayoutParams.mCaptionY); result.offset(-mRelayoutParams.mCaptionX, -mRelayoutParams.mCaptionY);
result.offset(-positionInParent.x, -positionInParent.y); result.offset(-positionInParent.x, -positionInParent.y);
@@ -370,8 +368,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
*/ */
private boolean checkEventInCaptionView(MotionEvent ev, int layoutId) { private boolean checkEventInCaptionView(MotionEvent ev, int layoutId) {
if (mResult.mRootView == null) return false; if (mResult.mRootView == null) return false;
PointF inputPoint = offsetCaptionLocation(ev); final PointF inputPoint = offsetCaptionLocation(ev);
View view = mResult.mRootView.findViewById(layoutId); final View view = mResult.mRootView.findViewById(layoutId);
return view != null && view.pointInView(inputPoint.x, inputPoint.y, 0); return view != null && view.pointInView(inputPoint.x, inputPoint.y, 0);
} }
@@ -389,20 +387,20 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
*/ */
void checkClickEvent(MotionEvent ev) { void checkClickEvent(MotionEvent ev) {
if (mResult.mRootView == null) return; if (mResult.mRootView == null) return;
View caption = mResult.mRootView.findViewById(R.id.desktop_mode_caption); final View caption = mResult.mRootView.findViewById(R.id.desktop_mode_caption);
PointF inputPoint = offsetCaptionLocation(ev); final PointF inputPoint = offsetCaptionLocation(ev);
if (!isHandleMenuActive()) { if (!isHandleMenuActive()) {
View handle = caption.findViewById(R.id.caption_handle); final View handle = caption.findViewById(R.id.caption_handle);
clickIfPointInView(inputPoint, handle); clickIfPointInView(inputPoint, handle);
} else { } else {
View menu = mHandleMenu.mWindowViewHost.getView(); final View menu = mHandleMenu.mWindowViewHost.getView();
View fullscreen = menu.findViewById(R.id.fullscreen_button); final View fullscreen = menu.findViewById(R.id.fullscreen_button);
if (clickIfPointInView(inputPoint, fullscreen)) return; if (clickIfPointInView(inputPoint, fullscreen)) return;
View desktop = menu.findViewById(R.id.desktop_button); final View desktop = menu.findViewById(R.id.desktop_button);
if (clickIfPointInView(inputPoint, desktop)) return; if (clickIfPointInView(inputPoint, desktop)) return;
View split = menu.findViewById(R.id.split_screen_button); final View split = menu.findViewById(R.id.split_screen_button);
if (clickIfPointInView(inputPoint, split)) return; if (clickIfPointInView(inputPoint, split)) return;
View more = menu.findViewById(R.id.more_button); final View more = menu.findViewById(R.id.more_button);
clickIfPointInView(inputPoint, more); clickIfPointInView(inputPoint, more);
} }
} }