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

Commit 94b14f7b authored by Omar Elmekkawy's avatar Omar Elmekkawy Committed by Android (Google) Code Review
Browse files

Merge "[10/n] Fix a divider handle moving bug that causes it to freeze." into main

parents 44d69e21 1e500ba5
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -49,11 +49,10 @@ class TilingDividerView : FrameLayout, View.OnTouchListener, DragDetector.Motion
    var handleRegionWidth: Int = 0
    private var handleRegionHeight = 0
    private var lastAcceptedPos = 0
    @VisibleForTesting
    var handleStartY = 0
    @VisibleForTesting
    var handleEndY = 0
    @VisibleForTesting var handleStartY = 0
    @VisibleForTesting var handleEndY = 0
    private var canResize = false
    private var resized = false
    /**
     * Tracks divider bar visible bounds in screen-based coordination. Used to calculate with
     * insets.
@@ -209,7 +208,6 @@ class TilingDividerView : FrameLayout, View.OnTouchListener, DragDetector.Motion
                if (!isWithinHandleRegion(yTouchPosInDivider)) return true
                callback.onDividerMoveStart(touchPos)
                setTouching()
                startPos = touchPos
                canResize = true
            }

@@ -223,19 +221,20 @@ class TilingDividerView : FrameLayout, View.OnTouchListener, DragDetector.Motion
                val pos = dividerBounds.left + touchPos - startPos
                if (callback.onDividerMove(pos)) {
                    lastAcceptedPos = touchPos
                    resized = true
                }
            }

            MotionEvent.ACTION_CANCEL,
            MotionEvent.ACTION_UP -> {
                if (!canResize) return true
                if (moving && resized) {
                    dividerBounds.left = dividerBounds.left + lastAcceptedPos - startPos
                if (moving) {
                    callback.onDividerMovedEnd(dividerBounds.left)
                }
                moving = false
                canResize = false
                }

                resized = false
                releaseTouching()
            }
        }
+21 −0
Original line number Diff line number Diff line
@@ -32,8 +32,10 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.any
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
import org.mockito.kotlin.times
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever

@SmallTest
@RunWith(AndroidTestingRunner::class)
@@ -68,6 +70,7 @@ class TilingDividerViewTest : ShellTestCase() {
        tilingDividerView.handleMotionEvent(viewMock, downMotionEvent)
        verify(dividerMoveCallbackMock, times(1)).onDividerMoveStart(any())

        whenever(dividerMoveCallbackMock.onDividerMove(any())).thenReturn(true)
        val motionEvent =
            getMotionEvent(downTime, MotionEvent.ACTION_MOVE, x.toFloat(), y.toFloat())
        tilingDividerView.handleMotionEvent(viewMock, motionEvent)
@@ -79,6 +82,24 @@ class TilingDividerViewTest : ShellTestCase() {
        verify(dividerMoveCallbackMock, times(1)).onDividerMovedEnd(any())
    }

    @Test
    @UiThreadTest
    fun testCallbackOnTouch_doesNotHappen_whenNoTouchMove() {
        val x = 5
        val y = 5
        val downTime: Long = SystemClock.uptimeMillis()

        val downMotionEvent =
            getMotionEvent(downTime, MotionEvent.ACTION_DOWN, x.toFloat(), y.toFloat())
        tilingDividerView.handleMotionEvent(viewMock, downMotionEvent)
        verify(dividerMoveCallbackMock, times(1)).onDividerMoveStart(any())

        val upMotionEvent =
            getMotionEvent(downTime, MotionEvent.ACTION_UP, x.toFloat(), y.toFloat())
        tilingDividerView.handleMotionEvent(viewMock, upMotionEvent)
        verify(dividerMoveCallbackMock, never()).onDividerMovedEnd(any())
    }

    private fun getMotionEvent(eventTime: Long, action: Int, x: Float, y: Float): MotionEvent {
        val properties = MotionEvent.PointerProperties()
        properties.id = 0