From ce25141e402410b75b6200f4426c14429e04c235 Mon Sep 17 00:00:00 2001 From: Merissa Mitchell Date: Thu, 12 Jan 2023 17:21:04 -0800 Subject: Minor style cleanup for Shell caption classes. Bug: 260276028 Test: atest WMShellUnitTests Change-Id: Id27058530b14dbff6268548d149f5bf33c0fb6ea --- .../windowdecor/CaptionWindowDecorViewModel.java | 14 ++-- .../shell/windowdecor/CaptionWindowDecoration.java | 57 +++++++------ .../DesktopModeWindowDecorViewModel.java | 61 +++++++------- .../windowdecor/DesktopModeWindowDecoration.java | 96 +++++++++++----------- 4 files changed, 112 insertions(+), 116 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModel.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModel.java index 1e72c565157a..129924ad5d05 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModel.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModel.java @@ -136,7 +136,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel { } private void setupCaptionColor(RunningTaskInfo taskInfo, CaptionWindowDecoration decoration) { - int statusBarColor = taskInfo.taskDescription.getStatusBarColor(); + final int statusBarColor = taskInfo.taskDescription.getStatusBarColor(); decoration.setCaptionColor(statusBarColor); } @@ -152,7 +152,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel { SurfaceControl taskSurface, SurfaceControl.Transaction startT, SurfaceControl.Transaction finishT) { - CaptionWindowDecoration oldDecoration = mWindowDecorByTaskId.get(taskInfo.taskId); + final CaptionWindowDecoration oldDecoration = mWindowDecorByTaskId.get(taskInfo.taskId); if (oldDecoration != null) { // close the old decoration if it exists to avoid two window decorations being added oldDecoration.close(); @@ -169,9 +169,9 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel { mSyncQueue); mWindowDecorByTaskId.put(taskInfo.taskId, windowDecoration); - TaskPositioner taskPositioner = + final TaskPositioner taskPositioner = new TaskPositioner(mTaskOrganizer, windowDecoration); - CaptionTouchEventListener touchEventListener = + final CaptionTouchEventListener touchEventListener = new CaptionTouchEventListener(taskInfo, taskPositioner); windowDecoration.setCaptionListeners(touchEventListener, touchEventListener); windowDecoration.setDragResizeCallback(taskPositioner); @@ -221,11 +221,11 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel { if (e.getAction() != MotionEvent.ACTION_DOWN) { return false; } - RunningTaskInfo taskInfo = mTaskOrganizer.getRunningTaskInfo(mTaskId); + final RunningTaskInfo taskInfo = mTaskOrganizer.getRunningTaskInfo(mTaskId); if (taskInfo.isFocused) { return false; } - WindowContainerTransaction wct = new WindowContainerTransaction(); + final WindowContainerTransaction wct = new WindowContainerTransaction(); wct.reorder(mTaskToken, true /* onTop */); mSyncQueue.queue(wct); 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 */ private void handleEventForMove(MotionEvent e) { - RunningTaskInfo taskInfo = mTaskOrganizer.getRunningTaskInfo(mTaskId); + final RunningTaskInfo taskInfo = mTaskOrganizer.getRunningTaskInfo(mTaskId); if (taskInfo.getWindowingMode() == WINDOWING_MODE_FULLSCREEN) { return; } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecoration.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecoration.java index 8609c6b0302a..d26f1fc8ef1b 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecoration.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecoration.java @@ -48,15 +48,13 @@ public class CaptionWindowDecoration extends WindowDecoration mResult = new RelayoutResult<>(); - private DragDetector mDragDetector; - CaptionWindowDecoration( Context context, DisplayController displayController, @@ -104,14 +102,14 @@ public class CaptionWindowDecoration extends WindowDecoration mDesktopModeController; - private Optional mDesktopTasksController; + private final Optional mDesktopModeController; + private final Optional mDesktopTasksController; private boolean mTransitionDragActive; private SparseArray mEventReceiversByDisplay = new SparseArray<>(); @@ -78,7 +77,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { private final SparseArray mWindowDecorByTaskId = new SparseArray<>(); private final DragStartListenerImpl mDragStartListener = new DragStartListenerImpl(); - private InputMonitorFactory mInputMonitorFactory; + private final InputMonitorFactory mInputMonitorFactory; private TaskOperations mTaskOperations; public DesktopModeWindowDecorViewModel( @@ -199,7 +198,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { if (decoration == null) return; decoration.close(); - int displayId = taskInfo.displayId; + final int displayId = taskInfo.displayId; if (mEventReceiversByDisplay.contains(displayId)) { removeTaskFromEventReceiver(displayId); } @@ -227,7 +226,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { @Override public void onClick(View v) { - DesktopModeWindowDecoration decoration = mWindowDecorByTaskId.get(mTaskId); + final DesktopModeWindowDecoration decoration = mWindowDecorByTaskId.get(mTaskId); final int id = v.getId(); if (id == R.id.close_window) { mTaskOperations.closeTask(mTaskToken); @@ -250,7 +249,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { @Override public boolean onTouch(View v, MotionEvent e) { boolean isDrag = false; - int id = v.getId(); + final int id = v.getId(); if (id != R.id.caption_handle && id != R.id.desktop_mode_caption) { return false; } @@ -261,11 +260,11 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { if (e.getAction() != MotionEvent.ACTION_DOWN) { return isDrag; } - RunningTaskInfo taskInfo = mTaskOrganizer.getRunningTaskInfo(mTaskId); + final RunningTaskInfo taskInfo = mTaskOrganizer.getRunningTaskInfo(mTaskId); if (taskInfo.isFocused) { return isDrag; } - WindowContainerTransaction wct = new WindowContainerTransaction(); + final WindowContainerTransaction wct = new WindowContainerTransaction(); wct.reorder(mTaskToken, true /* onTop */); mSyncQueue.queue(wct); 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 */ private void handleEventForMove(MotionEvent e) { - RunningTaskInfo taskInfo = mTaskOrganizer.getRunningTaskInfo(mTaskId); + final RunningTaskInfo taskInfo = mTaskOrganizer.getRunningTaskInfo(mTaskId); if (DesktopModeStatus.isProto2Enabled() && taskInfo.getWindowingMode() == WINDOWING_MODE_FULLSCREEN) { return; @@ -295,16 +294,16 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { break; } case MotionEvent.ACTION_MOVE: { - int dragPointerIdx = e.findPointerIndex(mDragPointerId); + final int dragPointerIdx = e.findPointerIndex(mDragPointerId); mDragResizeCallback.onDragResizeMove( e.getRawX(dragPointerIdx), e.getRawY(dragPointerIdx)); break; } case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: { - int dragPointerIdx = e.findPointerIndex(mDragPointerId); - int statusBarHeight = mDisplayController.getDisplayLayout(taskInfo.displayId) - .stableInsets().top; + final int dragPointerIdx = e.findPointerIndex(mDragPointerId); + final int statusBarHeight = mDisplayController + .getDisplayLayout(taskInfo.displayId).stableInsets().top; mDragResizeCallback.onDragResizeEnd( e.getRawX(dragPointerIdx), e.getRawY(dragPointerIdx)); if (e.getRawY(dragPointerIdx) <= statusBarHeight) { @@ -378,7 +377,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { */ private void incrementEventReceiverTasks(int displayId) { if (mEventReceiversByDisplay.contains(displayId)) { - EventReceiver eventReceiver = mEventReceiversByDisplay.get(displayId); + final EventReceiver eventReceiver = mEventReceiversByDisplay.get(displayId); eventReceiver.incrementTaskNumber(); } else { 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. private void removeTaskFromEventReceiver(int displayId) { if (!mEventReceiversByDisplay.contains(displayId)) return; - EventReceiver eventReceiver = mEventReceiversByDisplay.get(displayId); + final EventReceiver eventReceiver = mEventReceiversByDisplay.get(displayId); if (eventReceiver == null) return; eventReceiver.decrementTaskNumber(); if (eventReceiver.getTasksOnDisplay() == 0) { @@ -403,7 +402,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { */ private void handleReceivedMotionEvent(MotionEvent ev, InputMonitor inputMonitor) { if (DesktopModeStatus.isProto2Enabled()) { - DesktopModeWindowDecoration focusedDecor = getFocusedDecor(); + final DesktopModeWindowDecoration focusedDecor = getFocusedDecor(); if (focusedDecor == null || focusedDecor.mTaskInfo.getWindowingMode() != WINDOWING_MODE_FREEFORM) { 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 private void handleEventOutsideFocusedCaption(MotionEvent ev) { - int action = ev.getActionMasked(); + final int action = ev.getActionMasked(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { - DesktopModeWindowDecoration focusedDecor = getFocusedDecor(); + final DesktopModeWindowDecoration focusedDecor = getFocusedDecor(); if (focusedDecor == null) { return; } @@ -450,7 +449,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: { // Begin drag through status bar if applicable. - DesktopModeWindowDecoration focusedDecor = getFocusedDecor(); + final DesktopModeWindowDecoration focusedDecor = getFocusedDecor(); if (focusedDecor != null) { boolean dragFromStatusBarAllowed = false; if (DesktopModeStatus.isProto2Enabled()) { @@ -469,14 +468,14 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { break; } case MotionEvent.ACTION_UP: { - DesktopModeWindowDecoration focusedDecor = getFocusedDecor(); + final DesktopModeWindowDecoration focusedDecor = getFocusedDecor(); if (focusedDecor == null) { mTransitionDragActive = false; return; } if (mTransitionDragActive) { mTransitionDragActive = false; - int statusBarHeight = mDisplayController + final int statusBarHeight = mDisplayController .getDisplayLayout(focusedDecor.mTaskInfo.displayId).stableInsets().top; if (ev.getY() > statusBarHeight) { if (DesktopModeStatus.isProto2Enabled()) { @@ -500,10 +499,10 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { @Nullable private DesktopModeWindowDecoration getFocusedDecor() { - int size = mWindowDecorByTaskId.size(); + final int size = mWindowDecorByTaskId.size(); DesktopModeWindowDecoration focusedDecor = null; for (int i = 0; i < size; i++) { - DesktopModeWindowDecoration decor = mWindowDecorByTaskId.valueAt(i); + final DesktopModeWindowDecoration decor = mWindowDecorByTaskId.valueAt(i); if (decor != null && decor.isFocused()) { focusedDecor = decor; break; @@ -513,16 +512,16 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { } private void createInputChannel(int displayId) { - InputManager inputManager = InputManager.getInstance(); - InputMonitor inputMonitor = + final InputManager inputManager = InputManager.getInstance(); + final InputMonitor inputMonitor = mInputMonitorFactory.create(inputManager, mContext); - EventReceiver eventReceiver = new EventReceiver(inputMonitor, + final EventReceiver eventReceiver = new EventReceiver(inputMonitor, inputMonitor.getInputChannel(), Looper.myLooper()); mEventReceiversByDisplay.put(displayId, eventReceiver); } private void disposeInputChannel(int displayId) { - EventReceiver eventReceiver = mEventReceiversByDisplay.removeReturnOld(displayId); + final EventReceiver eventReceiver = mEventReceiversByDisplay.removeReturnOld(displayId); if (eventReceiver != null) { eventReceiver.dispose(); } @@ -541,7 +540,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { SurfaceControl taskSurface, SurfaceControl.Transaction startT, SurfaceControl.Transaction finishT) { - DesktopModeWindowDecoration oldDecoration = mWindowDecorByTaskId.get(taskInfo.taskId); + final DesktopModeWindowDecoration oldDecoration = mWindowDecorByTaskId.get(taskInfo.taskId); if (oldDecoration != null) { // close the old decoration if it exists to avoid two window decorations being added oldDecoration.close(); @@ -558,9 +557,9 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { mSyncQueue); mWindowDecorByTaskId.put(taskInfo.taskId, windowDecoration); - TaskPositioner taskPositioner = + final TaskPositioner taskPositioner = new TaskPositioner(mTaskOrganizer, windowDecoration, mDragStartListener); - DesktopModeTouchEventListener touchEventListener = + final DesktopModeTouchEventListener touchEventListener = new DesktopModeTouchEventListener( taskInfo, taskPositioner, windowDecoration.getDragDetector()); windowDecoration.setCaptionListeners(touchEventListener, touchEventListener); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java index 9c2beb9c4b2b..1a38d24a4ab1 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java @@ -56,17 +56,14 @@ public class DesktopModeWindowDecoration extends WindowDecoration mResult = new WindowDecoration.RelayoutResult<>(); private boolean mDesktopActive; - - private DragDetector mDragDetector; - private AdditionalWindow mHandleMenu; DesktopModeWindowDecoration( @@ -121,14 +118,14 @@ public class DesktopModeWindowDecoration extends WindowDecoration