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

This commit is contained in:
Ibrahim Yilmaz
2023-02-28 16:18:34 +00:00
committed by Android (Google) Code Review
3 changed files with 49 additions and 25 deletions

View File

@@ -65,35 +65,40 @@ class UnfoldConstantTranslateAnimator(
} else { } else {
1 1
} }
viewsToTranslate.forEach { (view, direction, shouldBeAnimated) -> viewsToTranslate.forEach { (view, direction) ->
if (shouldBeAnimated()) { view.get()?.translationX = xTrans * direction.multiplier * rtlMultiplier
view.get()?.translationX = xTrans * direction.multiplier * rtlMultiplier
}
} }
} }
/** Finds in [parent] all views specified by [ids] and register them for the animation. */ /** Finds in [parent] all views specified by [ids] and register them for the animation. */
private fun registerViewsForAnimation(parent: ViewGroup, ids: Set<ViewIdToTranslate>) { private fun registerViewsForAnimation(parent: ViewGroup, ids: Set<ViewIdToTranslate>) {
viewsToTranslate = viewsToTranslate =
ids.mapNotNull { (id, dir, pred) -> ids.asSequence()
parent.findViewById<View>(id)?.let { view -> .filter { it.shouldBeAnimated() }
ViewToTranslate(WeakReference(view), dir, pred) .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( data class ViewIdToTranslate(
val viewId: Int, val viewId: Int,
val direction: Direction, val direction: Direction,
val shouldBeAnimated: () -> Boolean = { true } val shouldBeAnimated: () -> Boolean = { true }
) )
private data class ViewToTranslate( /**
val view: WeakReference<View>, * Represents a view whose animation process is in-progress. It should be immutable because the
val direction: Direction, * started animation should be completed.
val shouldBeAnimated: () -> Boolean */
) private data class ViewToTranslate(val view: WeakReference<View>, val direction: Direction)
/** Direction of the animation. */ /** Direction of the animation. */
enum class Direction(val multiplier: Float) { enum class Direction(val multiplier: Float) {

View File

@@ -2211,10 +2211,10 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
pw.println("Current Status Bar state:"); pw.println("Current Status Bar state:");
pw.println(" mExpandedVisible=" + mShadeController.isExpandedVisible()); pw.println(" mExpandedVisible=" + mShadeController.isExpandedVisible());
pw.println(" mDisplayMetrics=" + mDisplayMetrics); pw.println(" mDisplayMetrics=" + mDisplayMetrics);
pw.println(" mStackScroller: " + CentralSurfaces.viewInfo(mStackScroller)); pw.print(" mStackScroller: " + CentralSurfaces.viewInfo(mStackScroller));
pw.println(" mStackScroller: " + CentralSurfaces.viewInfo(mStackScroller) pw.print(" scroll " + mStackScroller.getScrollX()
+ " scroll " + mStackScroller.getScrollX()
+ "," + mStackScroller.getScrollY()); + "," + mStackScroller.getScrollY());
pw.println(" translationX " + mStackScroller.getTranslationX());
} }
pw.print(" mInteractingWindows="); pw.println(mInteractingWindows); pw.print(" mInteractingWindows="); pw.println(mInteractingWindows);

View File

@@ -36,21 +36,26 @@ class UnfoldConstantTranslateAnimatorTest : SysuiTestCase() {
private val progressProvider = TestUnfoldTransitionProvider() 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 lateinit var animator: UnfoldConstantTranslateAnimator
private val viewsIdToRegister = private val viewsIdToRegister
setOf( get() =
ViewIdToTranslate(START_VIEW_ID, Direction.START), setOf(
ViewIdToTranslate(END_VIEW_ID, Direction.END)) ViewIdToTranslate(START_VIEW_ID, Direction.START, shouldBeAnimated),
ViewIdToTranslate(END_VIEW_ID, Direction.END, shouldBeAnimated)
)
@Before @Before
fun setup() { fun setup() {
MockitoAnnotations.initMocks(this) MockitoAnnotations.initMocks(this)
whenever(shouldBeAnimated.invoke()).thenReturn(true)
animator = animator = UnfoldConstantTranslateAnimator(viewsIdToRegister, progressProvider)
UnfoldConstantTranslateAnimator(viewsIdToRegister, progressProvider)
animator.init(parent, MAX_TRANSLATION) animator.init(parent, MAX_TRANSLATION)
} }
@@ -96,6 +101,20 @@ class UnfoldConstantTranslateAnimatorTest : SysuiTestCase() {
moveAndValidate(listOf(leftView to START, rightView to END), View.LAYOUT_DIRECTION_LTR) 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) { private fun moveAndValidate(list: List<Pair<View, Int>>, layoutDirection: Int) {
// Compare values as ints because -0f != 0f // Compare values as ints because -0f != 0f