Merge "Fix unfold transition with RTL" into tm-qpr-dev am: 90c03205a6
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20129370 Change-Id: I648df063fa8b506bb878150301989b5f72b01e0c Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
package com.android.systemui.shared.animation
|
package com.android.systemui.shared.animation
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.View.LAYOUT_DIRECTION_RTL
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.ViewIdToTranslate
|
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.ViewIdToTranslate
|
||||||
import com.android.systemui.unfold.UnfoldTransitionProgressProvider
|
import com.android.systemui.unfold.UnfoldTransitionProgressProvider
|
||||||
@@ -58,9 +59,15 @@ class UnfoldConstantTranslateAnimator(
|
|||||||
// progress == 0 -> -translationMax
|
// progress == 0 -> -translationMax
|
||||||
// progress == 1 -> 0
|
// progress == 1 -> 0
|
||||||
val xTrans = (progress - 1f) * translationMax
|
val xTrans = (progress - 1f) * translationMax
|
||||||
|
val rtlMultiplier =
|
||||||
|
if (rootView.getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
|
||||||
|
-1
|
||||||
|
} else {
|
||||||
|
1
|
||||||
|
}
|
||||||
viewsToTranslate.forEach { (view, direction, shouldBeAnimated) ->
|
viewsToTranslate.forEach { (view, direction, shouldBeAnimated) ->
|
||||||
if (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. */
|
/** Direction of the animation. */
|
||||||
enum class Direction(val multiplier: Float) {
|
enum class Direction(val multiplier: Float) {
|
||||||
LEFT(-1f),
|
START(-1f),
|
||||||
RIGHT(1f),
|
END(1f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ import android.content.Context
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import com.android.systemui.R
|
import com.android.systemui.R
|
||||||
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator
|
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator
|
||||||
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.LEFT
|
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.END
|
||||||
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.RIGHT
|
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.START
|
||||||
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.ViewIdToTranslate
|
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.ViewIdToTranslate
|
||||||
import com.android.systemui.unfold.SysUIUnfoldScope
|
import com.android.systemui.unfold.SysUIUnfoldScope
|
||||||
import com.android.systemui.unfold.util.NaturalRotationUnfoldProgressProvider
|
import com.android.systemui.unfold.util.NaturalRotationUnfoldProgressProvider
|
||||||
@@ -49,13 +49,14 @@ constructor(
|
|||||||
UnfoldConstantTranslateAnimator(
|
UnfoldConstantTranslateAnimator(
|
||||||
viewsIdToTranslate =
|
viewsIdToTranslate =
|
||||||
setOf(
|
setOf(
|
||||||
ViewIdToTranslate(R.id.keyguard_status_area, LEFT, filterNever),
|
ViewIdToTranslate(R.id.keyguard_status_area, START, filterNever),
|
||||||
ViewIdToTranslate(R.id.lockscreen_clock_view_large, LEFT, filterSplitShadeOnly),
|
|
||||||
ViewIdToTranslate(R.id.lockscreen_clock_view, LEFT, filterNever),
|
|
||||||
ViewIdToTranslate(
|
ViewIdToTranslate(
|
||||||
R.id.notification_stack_scroller, RIGHT, filterSplitShadeOnly),
|
R.id.lockscreen_clock_view_large, START, filterSplitShadeOnly),
|
||||||
ViewIdToTranslate(R.id.start_button, LEFT, filterNever),
|
ViewIdToTranslate(R.id.lockscreen_clock_view, START, filterNever),
|
||||||
ViewIdToTranslate(R.id.end_button, RIGHT, 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)
|
progressProvider = unfoldProgressProvider)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ import android.content.Context
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import com.android.systemui.R
|
import com.android.systemui.R
|
||||||
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator
|
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator
|
||||||
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.LEFT
|
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.END
|
||||||
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.RIGHT
|
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.START
|
||||||
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.ViewIdToTranslate
|
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.ViewIdToTranslate
|
||||||
import com.android.systemui.unfold.SysUIUnfoldScope
|
import com.android.systemui.unfold.SysUIUnfoldScope
|
||||||
import com.android.systemui.unfold.util.NaturalRotationUnfoldProgressProvider
|
import com.android.systemui.unfold.util.NaturalRotationUnfoldProgressProvider
|
||||||
@@ -36,11 +36,11 @@ constructor(private val context: Context, progressProvider: NaturalRotationUnfol
|
|||||||
UnfoldConstantTranslateAnimator(
|
UnfoldConstantTranslateAnimator(
|
||||||
viewsIdToTranslate =
|
viewsIdToTranslate =
|
||||||
setOf(
|
setOf(
|
||||||
ViewIdToTranslate(R.id.quick_settings_panel, LEFT),
|
ViewIdToTranslate(R.id.quick_settings_panel, START),
|
||||||
ViewIdToTranslate(R.id.notification_stack_scroller, RIGHT),
|
ViewIdToTranslate(R.id.notification_stack_scroller, END),
|
||||||
ViewIdToTranslate(R.id.rightLayout, RIGHT),
|
ViewIdToTranslate(R.id.rightLayout, END),
|
||||||
ViewIdToTranslate(R.id.clock, LEFT),
|
ViewIdToTranslate(R.id.clock, START),
|
||||||
ViewIdToTranslate(R.id.date, LEFT)),
|
ViewIdToTranslate(R.id.date, START)),
|
||||||
progressProvider = progressProvider)
|
progressProvider = progressProvider)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ import org.junit.Before
|
|||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.mockito.MockitoAnnotations
|
|
||||||
import org.mockito.Mockito.`when` as whenever
|
import org.mockito.Mockito.`when` as whenever
|
||||||
|
import org.mockito.MockitoAnnotations
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
@RunWith(AndroidTestingRunner::class)
|
@RunWith(AndroidTestingRunner::class)
|
||||||
@@ -42,8 +42,8 @@ class UnfoldConstantTranslateAnimatorTest : SysuiTestCase() {
|
|||||||
|
|
||||||
private val viewsIdToRegister =
|
private val viewsIdToRegister =
|
||||||
setOf(
|
setOf(
|
||||||
ViewIdToTranslate(LEFT_VIEW_ID, Direction.LEFT),
|
ViewIdToTranslate(START_VIEW_ID, Direction.START),
|
||||||
ViewIdToTranslate(RIGHT_VIEW_ID, Direction.RIGHT))
|
ViewIdToTranslate(END_VIEW_ID, Direction.END))
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setup() {
|
fun setup() {
|
||||||
@@ -66,41 +66,62 @@ class UnfoldConstantTranslateAnimatorTest : SysuiTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun onTransition_oneMovesLeft() {
|
fun onTransition_oneMovesStartWithLTR() {
|
||||||
// GIVEN one view with a matching id
|
// GIVEN one view with a matching id
|
||||||
val view = View(context)
|
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
|
@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
|
// GIVEN two views with a matching id
|
||||||
val leftView = View(context)
|
val leftView = View(context)
|
||||||
val rightView = View(context)
|
val rightView = View(context)
|
||||||
whenever(parent.findViewById<View>(LEFT_VIEW_ID)).thenReturn(leftView)
|
whenever(parent.findViewById<View>(START_VIEW_ID)).thenReturn(leftView)
|
||||||
whenever(parent.findViewById<View>(RIGHT_VIEW_ID)).thenReturn(rightView)
|
whenever(parent.findViewById<View>(END_VIEW_ID)).thenReturn(rightView)
|
||||||
|
|
||||||
moveAndValidate(listOf(leftView to LEFT, rightView to RIGHT))
|
moveAndValidate(listOf(leftView to START, rightView to END), View.LAYOUT_DIRECTION_LTR)
|
||||||
moveAndValidate(listOf(leftView to LEFT, rightView to RIGHT))
|
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
|
// Compare values as ints because -0f != 0f
|
||||||
|
|
||||||
// WHEN the transition starts
|
// WHEN the transition starts
|
||||||
progressProvider.onTransitionStarted()
|
progressProvider.onTransitionStarted()
|
||||||
progressProvider.onTransitionProgress(0f)
|
progressProvider.onTransitionProgress(0f)
|
||||||
|
|
||||||
|
val rtlMultiplier = if (layoutDirection == View.LAYOUT_DIRECTION_LTR) {
|
||||||
|
1
|
||||||
|
} else {
|
||||||
|
-1
|
||||||
|
}
|
||||||
list.forEach { (view, direction) ->
|
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
|
// WHEN the transition progresses, translation is updated
|
||||||
progressProvider.onTransitionProgress(.5f)
|
progressProvider.onTransitionProgress(.5f)
|
||||||
list.forEach { (view, direction) ->
|
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
|
// WHEN the transition ends, translation is completed
|
||||||
@@ -110,12 +131,12 @@ class UnfoldConstantTranslateAnimatorTest : SysuiTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val LEFT = Direction.LEFT.multiplier.toInt()
|
private val START = Direction.START.multiplier.toInt()
|
||||||
private val RIGHT = Direction.RIGHT.multiplier.toInt()
|
private val END = Direction.END.multiplier.toInt()
|
||||||
|
|
||||||
private const val MAX_TRANSLATION = 42f
|
private const val MAX_TRANSLATION = 42f
|
||||||
|
|
||||||
private const val LEFT_VIEW_ID = 1
|
private const val START_VIEW_ID = 1
|
||||||
private const val RIGHT_VIEW_ID = 2
|
private const val END_VIEW_ID = 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user