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

Commit b8f89eb1 authored by Ibrahim Yilmaz's avatar Ibrahim Yilmaz Committed by Automerger Merge Worker
Browse files

Merge "Use immutable shouldBeAnimated during Unfold Animation" into tm-qpr-dev...

Merge "Use immutable shouldBeAnimated during Unfold Animation" into tm-qpr-dev am: 7339dfcf am: 51920160

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21611507



Change-Id: I5c2a89dfa0bd885921a6ced3460b2e99a4bdab82
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents ed4c5e3e 51920160
Loading
Loading
Loading
Loading
+19 −14
Original line number Diff line number Diff line
@@ -65,35 +65,40 @@ class UnfoldConstantTranslateAnimator(
            } else {
                1
            }
        viewsToTranslate.forEach { (view, direction, shouldBeAnimated) ->
            if (shouldBeAnimated()) {
        viewsToTranslate.forEach { (view, direction) ->
            view.get()?.translationX = xTrans * direction.multiplier * rtlMultiplier
        }
    }
    }

    /** Finds in [parent] all views specified by [ids] and register them for the animation. */
    private fun registerViewsForAnimation(parent: ViewGroup, ids: Set<ViewIdToTranslate>) {
        viewsToTranslate =
            ids.mapNotNull { (id, dir, pred) ->
                parent.findViewById<View>(id)?.let { view ->
                    ViewToTranslate(WeakReference(view), dir, pred)
            ids.asSequence()
                .filter { it.shouldBeAnimated() }
                .mapNotNull {
                    parent.findViewById<View>(it.viewId)?.let { view ->
                        ViewToTranslate(WeakReference(view), it.direction)
                    }
                }
                .toList()
    }

    /** Represents a view to animate. [rootView] should contain a view with [viewId] inside. */
    /**
     * Represents a view to animate. [rootView] should contain a view with [viewId] inside.
     * [shouldBeAnimated] is only evaluated when the viewsToTranslate is registered in
     * [registerViewsForAnimation].
     */
    data class ViewIdToTranslate(
        val viewId: Int,
        val direction: Direction,
        val shouldBeAnimated: () -> Boolean = { true }
    )

    private data class ViewToTranslate(
        val view: WeakReference<View>,
        val direction: Direction,
        val shouldBeAnimated: () -> Boolean
    )
    /**
     * Represents a view whose animation process is in-progress. It should be immutable because the
     * started animation should be completed.
     */
    private data class ViewToTranslate(val view: WeakReference<View>, val direction: Direction)

    /** Direction of the animation. */
    enum class Direction(val multiplier: Float) {
+3 −3
Original line number Diff line number Diff line
@@ -2254,10 +2254,10 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
            pw.println("Current Status Bar state:");
            pw.println("  mExpandedVisible=" + mShadeController.isExpandedVisible());
            pw.println("  mDisplayMetrics=" + mDisplayMetrics);
            pw.println("  mStackScroller: " + CentralSurfaces.viewInfo(mStackScroller));
            pw.println("  mStackScroller: " + CentralSurfaces.viewInfo(mStackScroller)
                    + " scroll " + mStackScroller.getScrollX()
            pw.print("  mStackScroller: " + CentralSurfaces.viewInfo(mStackScroller));
            pw.print(" scroll " + mStackScroller.getScrollX()
                    + "," + mStackScroller.getScrollY());
            pw.println(" translationX " + mStackScroller.getTranslationX());
        }

        pw.print("  mInteractingWindows="); pw.println(mInteractingWindows);
+27 −8
Original line number Diff line number Diff line
@@ -36,21 +36,26 @@ class UnfoldConstantTranslateAnimatorTest : SysuiTestCase() {

    private val progressProvider = TestUnfoldTransitionProvider()

    @Mock private lateinit var parent: ViewGroup
    @Mock
    private lateinit var parent: ViewGroup

    @Mock
    private lateinit var shouldBeAnimated: () -> Boolean

    private lateinit var animator: UnfoldConstantTranslateAnimator

    private val viewsIdToRegister =
    private val viewsIdToRegister
        get() =
            setOf(
            ViewIdToTranslate(START_VIEW_ID, Direction.START),
            ViewIdToTranslate(END_VIEW_ID, Direction.END))
                    ViewIdToTranslate(START_VIEW_ID, Direction.START, shouldBeAnimated),
                    ViewIdToTranslate(END_VIEW_ID, Direction.END, shouldBeAnimated)
            )

    @Before
    fun setup() {
        MockitoAnnotations.initMocks(this)

        animator =
            UnfoldConstantTranslateAnimator(viewsIdToRegister, progressProvider)
        whenever(shouldBeAnimated.invoke()).thenReturn(true)
        animator = UnfoldConstantTranslateAnimator(viewsIdToRegister, progressProvider)

        animator.init(parent, MAX_TRANSLATION)
    }
@@ -96,6 +101,20 @@ class UnfoldConstantTranslateAnimatorTest : SysuiTestCase() {
        moveAndValidate(listOf(leftView to START, rightView to END), View.LAYOUT_DIRECTION_LTR)
    }

    @Test
    fun onTransition_completeStartedTranslation() {
        // GIVEN
        val leftView = View(context)
        whenever(parent.findViewById<View>(START_VIEW_ID)).thenReturn(leftView)
        // To start animation, shouldBeAnimated should return true.
        // There is a possibility for shouldBeAnimated to return false during the animation.
        whenever(shouldBeAnimated.invoke()).thenReturn(true).thenReturn(false)

        // shouldBeAnimated state may change during the animation.
        // However, started animation should be completed.
        moveAndValidate(listOf(leftView to START), View.LAYOUT_DIRECTION_LTR)
    }

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