Loading libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/TilingDividerView.kt +9 −10 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -209,7 +208,6 @@ class TilingDividerView : FrameLayout, View.OnTouchListener, DragDetector.Motion if (!isWithinHandleRegion(yTouchPosInDivider)) return true callback.onDividerMoveStart(touchPos) setTouching() startPos = touchPos canResize = true } Loading @@ -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() } } Loading libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/TilingDividerViewTest.kt +21 −0 Original line number Diff line number Diff line Loading @@ -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) Loading Loading @@ -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) Loading @@ -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 Loading Loading
libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/TilingDividerView.kt +9 −10 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -209,7 +208,6 @@ class TilingDividerView : FrameLayout, View.OnTouchListener, DragDetector.Motion if (!isWithinHandleRegion(yTouchPosInDivider)) return true callback.onDividerMoveStart(touchPos) setTouching() startPos = touchPos canResize = true } Loading @@ -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() } } Loading
libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/TilingDividerViewTest.kt +21 −0 Original line number Diff line number Diff line Loading @@ -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) Loading Loading @@ -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) Loading @@ -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 Loading