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

Commit bf0f2b93 authored by Matt Pietal's avatar Matt Pietal Committed by Automerger Merge Worker
Browse files

Merge "Fix unfold transition with RTL" into tm-qpr-dev am: 90c03205 am: 8d4756ba

parents d33ca055 8d4756ba
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.systemui.shared.animation

import android.view.View
import android.view.View.LAYOUT_DIRECTION_RTL
import android.view.ViewGroup
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.ViewIdToTranslate
import com.android.systemui.unfold.UnfoldTransitionProgressProvider
@@ -58,9 +59,15 @@ class UnfoldConstantTranslateAnimator(
        // progress == 0 -> -translationMax
        // progress == 1 -> 0
        val xTrans = (progress - 1f) * translationMax
        val rtlMultiplier =
            if (rootView.getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
                -1
            } else {
                1
            }
        viewsToTranslate.forEach { (view, direction, shouldBeAnimated) ->
            if (shouldBeAnimated()) {
                view.get()?.translationX = xTrans * direction.multiplier
                view.get()?.translationX = xTrans * direction.multiplier * rtlMultiplier
            }
        }
    }
@@ -90,7 +97,7 @@ class UnfoldConstantTranslateAnimator(

    /** Direction of the animation. */
    enum class Direction(val multiplier: Float) {
        LEFT(-1f),
        RIGHT(1f),
        START(-1f),
        END(1f),
    }
}
+9 −8
Original line number Diff line number Diff line
@@ -20,8 +20,8 @@ import android.content.Context
import android.view.ViewGroup
import com.android.systemui.R
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.LEFT
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.RIGHT
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.END
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.START
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.ViewIdToTranslate
import com.android.systemui.unfold.SysUIUnfoldScope
import com.android.systemui.unfold.util.NaturalRotationUnfoldProgressProvider
@@ -49,13 +49,14 @@ constructor(
        UnfoldConstantTranslateAnimator(
            viewsIdToTranslate =
                setOf(
                    ViewIdToTranslate(R.id.keyguard_status_area, LEFT, filterNever),
                    ViewIdToTranslate(R.id.lockscreen_clock_view_large, LEFT, filterSplitShadeOnly),
                    ViewIdToTranslate(R.id.lockscreen_clock_view, LEFT, filterNever),
                    ViewIdToTranslate(R.id.keyguard_status_area, START, filterNever),
                    ViewIdToTranslate(
                        R.id.notification_stack_scroller, RIGHT, filterSplitShadeOnly),
                    ViewIdToTranslate(R.id.start_button, LEFT, filterNever),
                    ViewIdToTranslate(R.id.end_button, RIGHT, filterNever)),
                        R.id.lockscreen_clock_view_large, START, filterSplitShadeOnly),
                    ViewIdToTranslate(R.id.lockscreen_clock_view, START, filterNever),
                    ViewIdToTranslate(
                        R.id.notification_stack_scroller, END, filterSplitShadeOnly),
                    ViewIdToTranslate(R.id.start_button, START, filterNever),
                    ViewIdToTranslate(R.id.end_button, END, filterNever)),
            progressProvider = unfoldProgressProvider)
    }

+7 −7
Original line number Diff line number Diff line
@@ -20,8 +20,8 @@ import android.content.Context
import android.view.ViewGroup
import com.android.systemui.R
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.LEFT
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.RIGHT
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.END
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.START
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.ViewIdToTranslate
import com.android.systemui.unfold.SysUIUnfoldScope
import com.android.systemui.unfold.util.NaturalRotationUnfoldProgressProvider
@@ -36,11 +36,11 @@ constructor(private val context: Context, progressProvider: NaturalRotationUnfol
        UnfoldConstantTranslateAnimator(
            viewsIdToTranslate =
                setOf(
                    ViewIdToTranslate(R.id.quick_settings_panel, LEFT),
                    ViewIdToTranslate(R.id.notification_stack_scroller, RIGHT),
                    ViewIdToTranslate(R.id.rightLayout, RIGHT),
                    ViewIdToTranslate(R.id.clock, LEFT),
                    ViewIdToTranslate(R.id.date, LEFT)),
                    ViewIdToTranslate(R.id.quick_settings_panel, START),
                    ViewIdToTranslate(R.id.notification_stack_scroller, END),
                    ViewIdToTranslate(R.id.rightLayout, END),
                    ViewIdToTranslate(R.id.clock, START),
                    ViewIdToTranslate(R.id.date, START)),
            progressProvider = progressProvider)
    }

+39 −18
Original line number Diff line number Diff line
@@ -27,8 +27,8 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.mockito.Mockito.`when` as whenever
import org.mockito.MockitoAnnotations

@SmallTest
@RunWith(AndroidTestingRunner::class)
@@ -42,8 +42,8 @@ class UnfoldConstantTranslateAnimatorTest : SysuiTestCase() {

    private val viewsIdToRegister =
        setOf(
            ViewIdToTranslate(LEFT_VIEW_ID, Direction.LEFT),
            ViewIdToTranslate(RIGHT_VIEW_ID, Direction.RIGHT))
            ViewIdToTranslate(START_VIEW_ID, Direction.START),
            ViewIdToTranslate(END_VIEW_ID, Direction.END))

    @Before
    fun setup() {
@@ -66,41 +66,62 @@ class UnfoldConstantTranslateAnimatorTest : SysuiTestCase() {
    }

    @Test
    fun onTransition_oneMovesLeft() {
    fun onTransition_oneMovesStartWithLTR() {
        // GIVEN one view with a matching id
        val view = View(context)
        whenever(parent.findViewById<View>(LEFT_VIEW_ID)).thenReturn(view)
        whenever(parent.findViewById<View>(START_VIEW_ID)).thenReturn(view)

        moveAndValidate(listOf(view to LEFT))
        moveAndValidate(listOf(view to START), View.LAYOUT_DIRECTION_LTR)
    }

    @Test
    fun onTransition_oneMovesLeftAndOneMovesRightMultipleTimes() {
    fun onTransition_oneMovesStartWithRTL() {
        // GIVEN one view with a matching id
        val view = View(context)
        whenever(parent.findViewById<View>(START_VIEW_ID)).thenReturn(view)

        whenever(parent.getLayoutDirection()).thenReturn(View.LAYOUT_DIRECTION_RTL)
        moveAndValidate(listOf(view to START), View.LAYOUT_DIRECTION_RTL)
    }

    @Test
    fun onTransition_oneMovesStartAndOneMovesEndMultipleTimes() {
        // GIVEN two views with a matching id
        val leftView = View(context)
        val rightView = View(context)
        whenever(parent.findViewById<View>(LEFT_VIEW_ID)).thenReturn(leftView)
        whenever(parent.findViewById<View>(RIGHT_VIEW_ID)).thenReturn(rightView)
        whenever(parent.findViewById<View>(START_VIEW_ID)).thenReturn(leftView)
        whenever(parent.findViewById<View>(END_VIEW_ID)).thenReturn(rightView)

        moveAndValidate(listOf(leftView to LEFT, rightView to RIGHT))
        moveAndValidate(listOf(leftView to LEFT, rightView to RIGHT))
        moveAndValidate(listOf(leftView to START, rightView to END), View.LAYOUT_DIRECTION_LTR)
        moveAndValidate(listOf(leftView to START, rightView to END), View.LAYOUT_DIRECTION_LTR)
    }

    private fun moveAndValidate(list: List<Pair<View, Int>>) {
    private fun moveAndValidate(list: List<Pair<View, Int>>, layoutDirection: Int) {
        // Compare values as ints because -0f != 0f

        // WHEN the transition starts
        progressProvider.onTransitionStarted()
        progressProvider.onTransitionProgress(0f)

        val rtlMultiplier = if (layoutDirection == View.LAYOUT_DIRECTION_LTR) {
            1
        } else {
            -1
        }
        list.forEach { (view, direction) ->
            assertEquals((-MAX_TRANSLATION * direction).toInt(), view.translationX.toInt())
            assertEquals(
                (-MAX_TRANSLATION * direction * rtlMultiplier).toInt(),
                view.translationX.toInt()
            )
        }

        // WHEN the transition progresses, translation is updated
        progressProvider.onTransitionProgress(.5f)
        list.forEach { (view, direction) ->
            assertEquals((-MAX_TRANSLATION / 2f * direction).toInt(), view.translationX.toInt())
            assertEquals(
                (-MAX_TRANSLATION / 2f * direction * rtlMultiplier).toInt(),
                view.translationX.toInt()
            )
        }

        // WHEN the transition ends, translation is completed
@@ -110,12 +131,12 @@ class UnfoldConstantTranslateAnimatorTest : SysuiTestCase() {
    }

    companion object {
        private val LEFT = Direction.LEFT.multiplier.toInt()
        private val RIGHT = Direction.RIGHT.multiplier.toInt()
        private val START = Direction.START.multiplier.toInt()
        private val END = Direction.END.multiplier.toInt()

        private const val MAX_TRANSLATION = 42f

        private const val LEFT_VIEW_ID = 1
        private const val RIGHT_VIEW_ID = 2
        private const val START_VIEW_ID = 1
        private const val END_VIEW_ID = 2
    }
}