1 package com.android.systemui.animation.back
2
3 import android.util.DisplayMetrics
4 import android.window.BackEvent
5 import androidx.test.filters.SmallTest
6 import com.android.systemui.SysuiTestCase
7 import com.google.common.truth.Truth.assertThat
8 import org.junit.Test
9 import org.junit.runner.RunWith
10 import org.junit.runners.JUnit4
11
12 private data class BackInput(val progressX: Float, val progressY: Float, val edge: Int)
13
14 @SmallTest
15 @RunWith(JUnit4::class)
16 class BackAnimationSpecTest : SysuiTestCase() {
17 private var displayMetrics =
<lambda>null18 DisplayMetrics().apply {
19 widthPixels = 100
20 heightPixels = 200
21 density = 3f
22 }
23
24 @Test
sysUi_floatingSystemSurfaces_animationValuesnull25 fun sysUi_floatingSystemSurfaces_animationValues() {
26 val maxX = 14.0f
27 val maxY = 4.0f
28 val minScale = 0.8f
29
30 val backAnimationSpec = BackAnimationSpec.floatingSystemSurfacesForSysUi(displayMetrics)
31
32 assertBackTransformation(
33 backAnimationSpec = backAnimationSpec,
34 backInput = BackInput(progressX = 0f, progressY = 0f, edge = BackEvent.EDGE_LEFT),
35 expected = BackTransformation(translateX = 0f, translateY = 0f, scale = 1f),
36 )
37 assertBackTransformation(
38 backAnimationSpec = backAnimationSpec,
39 backInput = BackInput(progressX = 1f, progressY = 0f, edge = BackEvent.EDGE_LEFT),
40 expected = BackTransformation(translateX = -maxX, translateY = 0f, scale = minScale),
41 )
42 assertBackTransformation(
43 backAnimationSpec = backAnimationSpec,
44 backInput = BackInput(progressX = 1f, progressY = 0f, edge = BackEvent.EDGE_RIGHT),
45 expected = BackTransformation(translateX = maxX, translateY = 0f, scale = minScale),
46 )
47 assertBackTransformation(
48 backAnimationSpec = backAnimationSpec,
49 backInput = BackInput(progressX = 1f, progressY = 1f, edge = BackEvent.EDGE_LEFT),
50 expected = BackTransformation(translateX = -maxX, translateY = -maxY, scale = minScale),
51 )
52 assertBackTransformation(
53 backAnimationSpec = backAnimationSpec,
54 backInput = BackInput(progressX = 0f, progressY = 1f, edge = BackEvent.EDGE_LEFT),
55 expected = BackTransformation(translateX = 0f, translateY = -maxY, scale = 1f),
56 )
57 assertBackTransformation(
58 backAnimationSpec = backAnimationSpec,
59 backInput = BackInput(progressX = 0f, progressY = -1f, edge = BackEvent.EDGE_LEFT),
60 expected = BackTransformation(translateX = 0f, translateY = maxY, scale = 1f),
61 )
62 }
63 }
64
assertBackTransformationnull65 private fun assertBackTransformation(
66 backAnimationSpec: BackAnimationSpec,
67 backInput: BackInput,
68 expected: BackTransformation,
69 ) {
70 val actual = BackTransformation()
71 backAnimationSpec.getBackTransformation(
72 backEvent =
73 BackEvent(
74 /* touchX = */ 0f,
75 /* touchY = */ 0f,
76 /* progress = */ backInput.progressX,
77 /* swipeEdge = */ backInput.edge,
78 ),
79 progressY = backInput.progressY,
80 result = actual
81 )
82
83 val tolerance = 0f
84 assertThat(actual.translateX).isWithin(tolerance).of(expected.translateX)
85 assertThat(actual.translateY).isWithin(tolerance).of(expected.translateY)
86 assertThat(actual.scale).isWithin(tolerance).of(expected.scale)
87 }
88