Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 502f65bd authored by Qijing Yao's avatar Qijing Yao
Browse files

Apply ktfmt formatting to MultiDisplay- files

Command run:
$ANDROID_BUILD_TOP/external/ktfmt/ktfmt.sh --kotlinlang-style

Bug: None
Test: atest
Flag: EXEMPT - only running linter, no functional change
Change-Id: I7524dbf36c38031557fda51a0272a020d40d5e59
parent 51216ebd
Loading
Loading
Loading
Loading
+29 −26
Original line number Diff line number Diff line
@@ -36,11 +36,11 @@ class MultiDisplayDragMoveIndicatorController(
        mutableMapOf<Int, MutableMap<Int, MultiDisplayDragMoveIndicatorSurface>>()

    /**
     * Called during drag move, which started at [startDisplayId] and currently
     * at [currentDisplayid]. Updates the position and visibility of the drag move indicators
     * for the [taskInfo] based on [boundsDp] on the destination displays ([displayIds])
     * as the dragged window moves. [transactionSupplier] provides a [SurfaceControl.Transaction]
     * for applying changes to the indicator surfaces.
     * Called during drag move, which started at [startDisplayId] and currently at
     * [currentDisplayid]. Updates the position and visibility of the drag move indicators for the
     * [taskInfo] based on [boundsDp] on the destination displays ([displayIds]) as the dragged
     * window moves. [transactionSupplier] provides a [SurfaceControl.Transaction] for applying
     * changes to the indicator surfaces.
     *
     * It is executed on the [desktopExecutor] to prevent blocking the main thread and avoid jank,
     * as creating and manipulating surfaces can be expensive.
@@ -94,7 +94,8 @@ class MultiDisplayDragMoveIndicatorController(
                    val transaction = transactionSupplier()
                    existingIndicator.relayout(boundsPx, transaction, visibility)
                    transaction.apply()
                } ?: run {
                }
                    ?: run {
                        val newIndicator =
                            indicatorSurfaceFactory.create(
                                taskInfo,
@@ -125,11 +126,13 @@ class MultiDisplayDragMoveIndicatorController(
     */
    fun onDragEnd(taskId: Int, transactionSupplier: () -> SurfaceControl.Transaction) {
        desktopExecutor.execute {
            dragIndicators.remove(taskId)?.values?.takeIf { it.isNotEmpty() }?.let { indicators ->
            dragIndicators
                .remove(taskId)
                ?.values
                ?.takeIf { it.isNotEmpty() }
                ?.let { indicators ->
                    val transaction = transactionSupplier()
                indicators.forEach { indicator ->
                    indicator.dispose(transaction)
                }
                    indicators.forEach { indicator -> indicator.dispose(transaction) }
                    transaction.apply()
                }
        }
+1 −0
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ class MultiDisplayDragMoveIndicatorSurface(
        TRANSLUCENT,
        VISIBLE,
    }

    private var visibility = Visibility.INVISIBLE

    // A container surface to host the veil background
+11 −7
Original line number Diff line number Diff line
@@ -216,7 +216,8 @@ class MultiDisplayVeiledResizeTaskPositioner(
                    repositionTaskBounds.top.toFloat(),
                )
                // Make the window translucent in the case when the cursor moves to another display.
                val alpha = if (startDisplayId == displayId) {
                val alpha =
                    if (startDisplayId == displayId) {
                        ALPHA_FOR_WINDOW_ON_DISPLAY_WITH_CURSOR
                    } else {
                        ALPHA_FOR_WINDOW_ON_NON_CURSOR_DISPLAY
@@ -257,8 +258,11 @@ class MultiDisplayVeiledResizeTaskPositioner(
            val startDisplayLayout = displayController.getDisplayLayout(startDisplayId)
            val currentDisplayLayout = displayController.getDisplayLayout(displayId)

            if (startDisplayId == displayId
                || startDisplayLayout == null || currentDisplayLayout == null) {
            if (
                startDisplayId == displayId ||
                    startDisplayLayout == null ||
                    currentDisplayLayout == null
            ) {
                // Fall back to single-display drag behavior if:
                // 1. The drag destination display is the same as the start display. This prevents
                // unnecessary animations caused by minor width/height changes due to DPI scaling.
+30 −10
Original line number Diff line number Diff line
@@ -88,8 +88,10 @@ class MultiDisplayDragMoveIndicatorControllerTest : ShellTestCase() {
        whenever(displayController.getDisplayContext(any())).thenReturn(mContext)
        whenever(displayController.getDisplay(0)).thenReturn(display0)
        whenever(displayController.getDisplay(1)).thenReturn(display1)
        whenever(indicatorSurfaceFactory.create(eq(taskInfo), eq(display0), any())).thenReturn(indicatorSurface0)
        whenever(indicatorSurfaceFactory.create(eq(taskInfo), eq(display1), any())).thenReturn(indicatorSurface1)
        whenever(indicatorSurfaceFactory.create(eq(taskInfo), eq(display0), any()))
            .thenReturn(indicatorSurface0)
        whenever(indicatorSurfaceFactory.create(eq(taskInfo), eq(display1), any()))
            .thenReturn(indicatorSurface1)
        whenever(transactionSupplier.get()).thenReturn(transaction)
    }

@@ -101,7 +103,9 @@ class MultiDisplayDragMoveIndicatorControllerTest : ShellTestCase() {
            startDisplayId = 0,
            taskInfo,
            displayIds = setOf(0, 1),
        ) { transaction }
        ) {
            transaction
        }
        executor.flushAll()

        verify(indicatorSurfaceFactory, never()).create(any(), any(), any())
@@ -115,7 +119,9 @@ class MultiDisplayDragMoveIndicatorControllerTest : ShellTestCase() {
            startDisplayId = 0,
            taskInfo,
            displayIds = setOf(0, 1),
        ) { transaction }
        ) {
            transaction
        }
        executor.flushAll()

        verify(indicatorSurfaceFactory, never()).create(any(), any(), any())
@@ -129,27 +135,41 @@ class MultiDisplayDragMoveIndicatorControllerTest : ShellTestCase() {
            startDisplayId = 0,
            taskInfo,
            displayIds = setOf(0, 1),
        ) { transaction }
        ) {
            transaction
        }
        executor.flushAll()

        verify(indicatorSurfaceFactory, times(1)).create(eq(taskInfo), eq(display1), any())
        verify(indicatorSurface1, times(1))
            .show(transaction, taskInfo, rootTaskDisplayAreaOrganizer, 1, Rect(0, 1800, 200, 2400),
                  MultiDisplayDragMoveIndicatorSurface.Visibility.VISIBLE)
            .show(
                transaction,
                taskInfo,
                rootTaskDisplayAreaOrganizer,
                1,
                Rect(0, 1800, 200, 2400),
                MultiDisplayDragMoveIndicatorSurface.Visibility.VISIBLE,
            )

        controller.onDragMove(
            RectF(2000f, 2000f, 2100f, 2200f), // not intersect with display 1
            currentDisplayId = 0,
            startDisplayId = 0,
            taskInfo,
            displayIds = setOf(0, 1)
        ) { transaction }
            displayIds = setOf(0, 1),
        ) {
            transaction
        }
        while (executor.callbacks.isNotEmpty()) {
            executor.flushAll()
        }

        verify(indicatorSurface1, times(1))
            .relayout(any(), eq(transaction), eq(MultiDisplayDragMoveIndicatorSurface.Visibility.INVISIBLE))
            .relayout(
                any(),
                eq(transaction),
                eq(MultiDisplayDragMoveIndicatorSurface.Visibility.INVISIBLE),
            )

        controller.onDragEnd(TASK_ID, { transaction })
        while (executor.callbacks.isNotEmpty()) {
+34 −16
Original line number Diff line number Diff line
@@ -218,12 +218,15 @@ class MultiDisplayDragMoveIndicatorSurfaceTest : ShellTestCase() {
            mockRootTaskDisplayAreaOrganizer,
            DEFAULT_DISPLAY,
            BOUNDS,
            MultiDisplayDragMoveIndicatorSurface.Visibility.VISIBLE
            MultiDisplayDragMoveIndicatorSurface.Visibility.VISIBLE,
        )
        clearInvocations(mockTransaction)

        dragIndicatorSurface.relayout(NEW_BOUNDS, mockTransaction,
                                      MultiDisplayDragMoveIndicatorSurface.Visibility.VISIBLE)
        dragIndicatorSurface.relayout(
            NEW_BOUNDS,
            mockTransaction,
            MultiDisplayDragMoveIndicatorSurface.Visibility.VISIBLE,
        )

        verify(mockTransaction).setCrop(eq(mockVeilSurface), eq(NEW_BOUNDS))
        verify(mockTransaction).setPosition(eq(mockIconSurface), eq(expectedX), eq(expectedY))
@@ -240,11 +243,14 @@ class MultiDisplayDragMoveIndicatorSurfaceTest : ShellTestCase() {
            mockRootTaskDisplayAreaOrganizer,
            DEFAULT_DISPLAY,
            BOUNDS,
            MultiDisplayDragMoveIndicatorSurface.Visibility.VISIBLE
            MultiDisplayDragMoveIndicatorSurface.Visibility.VISIBLE,
        )
        clearInvocations(mockTransaction)
        dragIndicatorSurface.relayout(NEW_BOUNDS, mockTransaction,
                                      MultiDisplayDragMoveIndicatorSurface.Visibility.INVISIBLE)
        dragIndicatorSurface.relayout(
            NEW_BOUNDS,
            mockTransaction,
            MultiDisplayDragMoveIndicatorSurface.Visibility.INVISIBLE,
        )

        verify(mockTransaction).setCrop(eq(mockVeilSurface), eq(NEW_BOUNDS))
        verify(mockTransaction).setPosition(eq(mockIconSurface), eq(expectedX), eq(expectedY))
@@ -255,8 +261,11 @@ class MultiDisplayDragMoveIndicatorSurfaceTest : ShellTestCase() {
        val expectedX = NEW_BOUNDS.left + NEW_BOUNDS.width().toFloat() / 2 - ICON_SIZE.toFloat() / 2
        val expectedY = NEW_BOUNDS.top + NEW_BOUNDS.height().toFloat() / 2 - ICON_SIZE.toFloat() / 2

        dragIndicatorSurface.relayout(NEW_BOUNDS, mockTransaction,
                                      MultiDisplayDragMoveIndicatorSurface.Visibility.VISIBLE)
        dragIndicatorSurface.relayout(
            NEW_BOUNDS,
            mockTransaction,
            MultiDisplayDragMoveIndicatorSurface.Visibility.VISIBLE,
        )

        verify(mockTransaction).setCrop(eq(mockVeilSurface), eq(NEW_BOUNDS))
        verify(mockTransaction).setPosition(eq(mockIconSurface), eq(expectedX), eq(expectedY))
@@ -264,8 +273,11 @@ class MultiDisplayDragMoveIndicatorSurfaceTest : ShellTestCase() {

    @Test
    fun relayout_whenInvisibleAndShouldBeInvisible_doesNotSetCropOrPosition() {
        dragIndicatorSurface.relayout(NEW_BOUNDS, mockTransaction,
                                      MultiDisplayDragMoveIndicatorSurface.Visibility.INVISIBLE)
        dragIndicatorSurface.relayout(
            NEW_BOUNDS,
            mockTransaction,
            MultiDisplayDragMoveIndicatorSurface.Visibility.INVISIBLE,
        )

        verify(mockTransaction, never()).setCrop(any(), any())
        verify(mockTransaction, never()).setPosition(any(), any(), any())
@@ -279,11 +291,14 @@ class MultiDisplayDragMoveIndicatorSurfaceTest : ShellTestCase() {
            mockRootTaskDisplayAreaOrganizer,
            DEFAULT_DISPLAY,
            BOUNDS,
            MultiDisplayDragMoveIndicatorSurface.Visibility.VISIBLE
            MultiDisplayDragMoveIndicatorSurface.Visibility.VISIBLE,
        )
        clearInvocations(mockTransaction)
        dragIndicatorSurface.relayout(NEW_BOUNDS, mockTransaction,
                                      MultiDisplayDragMoveIndicatorSurface.Visibility.TRANSLUCENT)
        dragIndicatorSurface.relayout(
            NEW_BOUNDS,
            mockTransaction,
            MultiDisplayDragMoveIndicatorSurface.Visibility.TRANSLUCENT,
        )

        verify(mockTransaction).setAlpha(eq(mockVeilSurface), eq(ALPHA_FOR_TRANSLUCENT))
        verify(mockTransaction).setAlpha(eq(mockIconSurface), eq(ALPHA_FOR_TRANSLUCENT))
@@ -297,11 +312,14 @@ class MultiDisplayDragMoveIndicatorSurfaceTest : ShellTestCase() {
            mockRootTaskDisplayAreaOrganizer,
            DEFAULT_DISPLAY,
            BOUNDS,
            MultiDisplayDragMoveIndicatorSurface.Visibility.TRANSLUCENT
            MultiDisplayDragMoveIndicatorSurface.Visibility.TRANSLUCENT,
        )
        clearInvocations(mockTransaction)
        dragIndicatorSurface.relayout(NEW_BOUNDS, mockTransaction,
                                      MultiDisplayDragMoveIndicatorSurface.Visibility.VISIBLE)
        dragIndicatorSurface.relayout(
            NEW_BOUNDS,
            mockTransaction,
            MultiDisplayDragMoveIndicatorSurface.Visibility.VISIBLE,
        )

        verify(mockTransaction).setAlpha(eq(mockVeilSurface), eq(ALPHA_FOR_VISIBLE))
        verify(mockTransaction).setAlpha(eq(mockIconSurface), eq(ALPHA_FOR_VISIBLE))
Loading