diff options
2 files changed, 30 insertions, 10 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/TilingDividerView.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/TilingDividerView.kt index 065a5d77ccd3..f8113c219bd1 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/TilingDividerView.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/TilingDividerView.kt @@ -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 - dividerBounds.left = dividerBounds.left + lastAcceptedPos - startPos - if (moving) { + if (moving && resized) { + dividerBounds.left = dividerBounds.left + lastAcceptedPos - startPos callback.onDividerMovedEnd(dividerBounds.left) - moving = false - canResize = false } - + moving = false + canResize = false + resized = false releaseTouching() } } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/TilingDividerViewTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/TilingDividerViewTest.kt index fd5eb8855d32..c96ce955f217 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/TilingDividerViewTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/TilingDividerViewTest.kt @@ -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 |