• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download

<lambda>null1 package com.android.systemui.navigationbar.gestural
2 
3 import android.content.res.Resources
4 import android.util.TypedValue
5 import androidx.core.animation.PathInterpolator
6 import androidx.dynamicanimation.animation.SpringForce
7 import com.android.systemui.R
8 
9 data class EdgePanelParams(private var resources: Resources) {
10 
11     data class ArrowDimens(
12             val length: Float? = 0f,
13             val height: Float? = 0f,
14             val alpha: Float = 0f,
15             var alphaSpring: SpringForce? = null,
16             val heightSpring: SpringForce? = null,
17             val lengthSpring: SpringForce? = null,
18     )
19 
20     data class BackgroundDimens(
21             val width: Float? = 0f,
22             val height: Float = 0f,
23             val edgeCornerRadius: Float = 0f,
24             val farCornerRadius: Float = 0f,
25             val alpha: Float = 0f,
26             val widthSpring: SpringForce? = null,
27             val heightSpring: SpringForce? = null,
28             val farCornerRadiusSpring: SpringForce? = null,
29             val edgeCornerRadiusSpring: SpringForce? = null,
30             val alphaSpring: SpringForce? = null,
31     )
32 
33     data class BackIndicatorDimens(
34             val horizontalTranslation: Float? = 0f,
35             val scale: Float = 0f,
36             val scalePivotX: Float = 0f,
37             val arrowDimens: ArrowDimens,
38             val backgroundDimens: BackgroundDimens,
39             val verticalTranslationSpring: SpringForce? = null,
40             val horizontalTranslationSpring: SpringForce? = null,
41             val scaleSpring: SpringForce? = null,
42     )
43 
44     lateinit var entryIndicator: BackIndicatorDimens
45         private set
46     lateinit var activeIndicator: BackIndicatorDimens
47         private set
48     lateinit var cancelledIndicator: BackIndicatorDimens
49         private set
50     lateinit var flungIndicator: BackIndicatorDimens
51         private set
52     lateinit var committedIndicator: BackIndicatorDimens
53         private set
54     lateinit var preThresholdIndicator: BackIndicatorDimens
55         private set
56     lateinit var fullyStretchedIndicator: BackIndicatorDimens
57         private set
58 
59     // navigation bar edge constants
60     var arrowPaddingEnd: Int = 0
61         private set
62     var arrowThickness: Float = 0f
63         private set
64     lateinit var arrowStrokeAlphaSpring: Step<SpringForce>
65         private set
66     lateinit var arrowStrokeAlphaInterpolator: Step<Float>
67         private set
68 
69     // The closest to y
70     var minArrowYPosition: Int = 0
71         private set
72     var fingerOffset: Int = 0
73         private set
74     var staticTriggerThreshold: Float = 0f
75         private set
76     var reactivationTriggerThreshold: Float = 0f
77         private set
78     var deactivationSwipeTriggerThreshold: Float = 0f
79         get() = -field
80         private set
81     var swipeProgressThreshold: Float = 0f
82         private set
83 
84     // The minimum delta needed to change direction / stop triggering back
85     var minDeltaForSwitch: Int = 0
86         private set
87 
88     var minDragToStartAnimation: Float = 0f
89         private set
90 
91     lateinit var entryWidthInterpolator: PathInterpolator
92         private set
93     lateinit var entryWidthTowardsEdgeInterpolator: PathInterpolator
94         private set
95     lateinit var activeWidthInterpolator: PathInterpolator
96         private set
97     lateinit var arrowAngleInterpolator: PathInterpolator
98         private set
99     lateinit var translationInterpolator: PathInterpolator
100         private set
101     lateinit var farCornerInterpolator: PathInterpolator
102         private set
103     lateinit var edgeCornerInterpolator: PathInterpolator
104         private set
105     lateinit var heightInterpolator: PathInterpolator
106         private set
107 
108     init {
109         update(resources)
110     }
111 
112     private fun getDimen(id: Int): Float {
113         return resources.getDimension(id)
114     }
115 
116     private fun getDimenFloat(id: Int): Float {
117         return TypedValue().run { resources.getValue(id, this, true); float }
118     }
119 
120     private fun getPx(id: Int): Int {
121         return resources.getDimensionPixelSize(id)
122     }
123 
124     fun update(resources: Resources) {
125         this.resources = resources
126         arrowThickness = getDimen(R.dimen.navigation_edge_arrow_thickness)
127         arrowPaddingEnd = getPx(R.dimen.navigation_edge_panel_padding)
128         minArrowYPosition = getPx(R.dimen.navigation_edge_arrow_min_y)
129         fingerOffset = getPx(R.dimen.navigation_edge_finger_offset)
130         staticTriggerThreshold = getDimen(R.dimen.navigation_edge_action_drag_threshold)
131         reactivationTriggerThreshold =
132                 getDimen(R.dimen.navigation_edge_action_reactivation_drag_threshold)
133         deactivationSwipeTriggerThreshold =
134                 getDimen(R.dimen.navigation_edge_action_deactivation_drag_threshold)
135         swipeProgressThreshold = getDimen(R.dimen.navigation_edge_action_progress_threshold)
136         minDeltaForSwitch = getPx(R.dimen.navigation_edge_minimum_x_delta_for_switch)
137         minDragToStartAnimation =
138                 getDimen(R.dimen.navigation_edge_action_min_distance_to_start_animation)
139 
140         entryWidthInterpolator = PathInterpolator(.19f, 1.27f, .71f, .86f)
141         entryWidthTowardsEdgeInterpolator = PathInterpolator(1f, -3f, 1f, 1.2f)
142         activeWidthInterpolator = PathInterpolator(.32f, 0f, .16f, .94f)
143         arrowAngleInterpolator = entryWidthInterpolator
144         translationInterpolator = PathInterpolator(0.2f, 1.0f, 1.0f, 1.0f)
145         farCornerInterpolator = PathInterpolator(.03f, .19f, .14f, 1.09f)
146         edgeCornerInterpolator = PathInterpolator(0f, 1.11f, .85f, .84f)
147         heightInterpolator = PathInterpolator(1f, .05f, .9f, -0.29f)
148 
149         val showArrowOnProgressValue = .23f
150         val showArrowOnProgressValueFactor = 1.05f
151 
152         val entryActiveHorizontalTranslationSpring = createSpring(800f, 0.8f)
153         val activeCommittedArrowLengthSpring = createSpring(1500f, 0.29f)
154         val activeCommittedArrowHeightSpring = createSpring(1500f, 0.29f)
155         val flungCommittedEdgeCornerSpring = createSpring(10000f, 1f)
156         val flungCommittedFarCornerSpring = createSpring(10000f, 1f)
157         val flungCommittedWidthSpring = createSpring(10000f, 1f)
158         val flungCommittedHeightSpring = createSpring(10000f, 1f)
159 
160         entryIndicator = BackIndicatorDimens(
161                 horizontalTranslation = getDimen(R.dimen.navigation_edge_entry_margin),
162                 scale = getDimenFloat(R.dimen.navigation_edge_entry_scale),
163                 scalePivotX = getDimen(R.dimen.navigation_edge_pre_threshold_background_width),
164                 horizontalTranslationSpring = entryActiveHorizontalTranslationSpring,
165                 verticalTranslationSpring = createSpring(10000f, 0.9f),
166                 scaleSpring = createSpring(120f, 0.8f),
167                 arrowDimens = ArrowDimens(
168                         length = getDimen(R.dimen.navigation_edge_entry_arrow_length),
169                         height = getDimen(R.dimen.navigation_edge_entry_arrow_height),
170                         alpha = 0f,
171                         alphaSpring = createSpring(200f, 1f),
172                         lengthSpring = createSpring(600f, 0.4f),
173                         heightSpring = createSpring(600f, 0.4f),
174                 ),
175                 backgroundDimens = BackgroundDimens(
176                         alpha = 1f,
177                         width = getDimen(R.dimen.navigation_edge_entry_background_width),
178                         height = getDimen(R.dimen.navigation_edge_entry_background_height),
179                         edgeCornerRadius = getDimen(R.dimen.navigation_edge_entry_edge_corners),
180                         farCornerRadius = getDimen(R.dimen.navigation_edge_entry_far_corners),
181                         alphaSpring = createSpring(1100f, 1f),
182                         widthSpring = createSpring(450f, 0.65f),
183                         heightSpring = createSpring(1500f, 0.45f),
184                         farCornerRadiusSpring = createSpring(300f, 0.5f),
185                         edgeCornerRadiusSpring = createSpring(150f, 0.5f),
186                 )
187         )
188 
189         activeIndicator = BackIndicatorDimens(
190                 horizontalTranslation = getDimen(R.dimen.navigation_edge_active_margin),
191                 scale = getDimenFloat(R.dimen.navigation_edge_active_scale),
192                 horizontalTranslationSpring = entryActiveHorizontalTranslationSpring,
193                 scaleSpring = createSpring(450f, 0.415f),
194                 arrowDimens = ArrowDimens(
195                         length = getDimen(R.dimen.navigation_edge_active_arrow_length),
196                         height = getDimen(R.dimen.navigation_edge_active_arrow_height),
197                         alpha = 1f,
198                         lengthSpring = activeCommittedArrowLengthSpring,
199                         heightSpring = activeCommittedArrowHeightSpring,
200                 ),
201                 backgroundDimens = BackgroundDimens(
202                         alpha = 1f,
203                         width = getDimen(R.dimen.navigation_edge_active_background_width),
204                         height = getDimen(R.dimen.navigation_edge_active_background_height),
205                         edgeCornerRadius = getDimen(R.dimen.navigation_edge_active_edge_corners),
206                         farCornerRadius = getDimen(R.dimen.navigation_edge_active_far_corners),
207                         widthSpring = createSpring(375f, 0.675f),
208                         heightSpring = createSpring(10000f, 1f),
209                         edgeCornerRadiusSpring = createSpring(600f, 0.36f),
210                         farCornerRadiusSpring = createSpring(2500f, 0.855f),
211                 )
212         )
213 
214         preThresholdIndicator = BackIndicatorDimens(
215                 horizontalTranslation = getDimen(R.dimen.navigation_edge_pre_threshold_margin),
216                 scale = getDimenFloat(R.dimen.navigation_edge_pre_threshold_scale),
217                 scalePivotX = getDimen(R.dimen.navigation_edge_pre_threshold_background_width),
218                 scaleSpring = createSpring(120f, 0.8f),
219                 horizontalTranslationSpring = createSpring(6000f, 1f),
220                 arrowDimens = ArrowDimens(
221                         length = getDimen(R.dimen.navigation_edge_pre_threshold_arrow_length),
222                         height = getDimen(R.dimen.navigation_edge_pre_threshold_arrow_height),
223                         alpha = 1f,
224                         lengthSpring = createSpring(100f, 0.6f),
225                         heightSpring = createSpring(100f, 0.6f),
226                 ),
227                 backgroundDimens = BackgroundDimens(
228                         alpha = 1f,
229                         width = getDimen(R.dimen.navigation_edge_pre_threshold_background_width),
230                         height = getDimen(R.dimen.navigation_edge_pre_threshold_background_height),
231                         edgeCornerRadius =
232                                 getDimen(R.dimen.navigation_edge_pre_threshold_edge_corners),
233                         farCornerRadius =
234                                 getDimen(R.dimen.navigation_edge_pre_threshold_far_corners),
235                         widthSpring = createSpring(250f, 0.65f),
236                         heightSpring = createSpring(1500f, 0.45f),
237                         farCornerRadiusSpring = createSpring(200f, 1f),
238                         edgeCornerRadiusSpring = createSpring(150f, 0.5f),
239                 )
240         )
241 
242         committedIndicator = activeIndicator.copy(
243                 horizontalTranslation = null,
244                 arrowDimens = activeIndicator.arrowDimens.copy(
245                         lengthSpring = activeCommittedArrowLengthSpring,
246                         heightSpring = activeCommittedArrowHeightSpring,
247                         length = null,
248                         height = null,
249                 ),
250                 backgroundDimens = activeIndicator.backgroundDimens.copy(
251                         alpha = 0f,
252                         // explicitly set to null to preserve previous width upon state change
253                         width = null,
254                         widthSpring = flungCommittedWidthSpring,
255                         heightSpring = flungCommittedHeightSpring,
256                         edgeCornerRadiusSpring = flungCommittedEdgeCornerSpring,
257                         farCornerRadiusSpring = flungCommittedFarCornerSpring,
258                 ),
259                 scale = 0.85f,
260                 scaleSpring = createSpring(1150f, 1f),
261         )
262 
263         flungIndicator = committedIndicator.copy(
264                 arrowDimens = committedIndicator.arrowDimens.copy(
265                         lengthSpring = createSpring(850f, 0.46f),
266                         heightSpring = createSpring(850f, 0.46f),
267                         length = activeIndicator.arrowDimens.length,
268                         height = activeIndicator.arrowDimens.height
269                 ),
270                 backgroundDimens = committedIndicator.backgroundDimens.copy(
271                         widthSpring = flungCommittedWidthSpring,
272                         heightSpring = flungCommittedHeightSpring,
273                         edgeCornerRadiusSpring = flungCommittedEdgeCornerSpring,
274                         farCornerRadiusSpring = flungCommittedFarCornerSpring,
275                 )
276         )
277 
278         cancelledIndicator = entryIndicator.copy(
279                 backgroundDimens = entryIndicator.backgroundDimens.copy(width = 0f)
280         )
281 
282         fullyStretchedIndicator = BackIndicatorDimens(
283                 horizontalTranslation = getDimen(R.dimen.navigation_edge_stretch_margin),
284                 scale = getDimenFloat(R.dimen.navigation_edge_stretch_scale),
285                 horizontalTranslationSpring = null,
286                 verticalTranslationSpring = null,
287                 scaleSpring = null,
288                 arrowDimens = ArrowDimens(
289                         length = getDimen(R.dimen.navigation_edge_stretched_arrow_length),
290                         height = getDimen(R.dimen.navigation_edge_stretched_arrow_height),
291                         alpha = 1f,
292                         alphaSpring = null,
293                         heightSpring = null,
294                         lengthSpring = null,
295                 ),
296                 backgroundDimens = BackgroundDimens(
297                         alpha = 1f,
298                         width = getDimen(R.dimen.navigation_edge_stretch_background_width),
299                         height = getDimen(R.dimen.navigation_edge_stretch_background_height),
300                         edgeCornerRadius = getDimen(R.dimen.navigation_edge_stretch_edge_corners),
301                         farCornerRadius = getDimen(R.dimen.navigation_edge_stretch_far_corners),
302                         alphaSpring = null,
303                         widthSpring = null,
304                         heightSpring = null,
305                         edgeCornerRadiusSpring = null,
306                         farCornerRadiusSpring = null,
307                 )
308         )
309 
310         arrowStrokeAlphaInterpolator = Step(
311                 threshold = showArrowOnProgressValue,
312                 factor = showArrowOnProgressValueFactor,
313                 postThreshold = 1f,
314                 preThreshold = 0f
315         )
316 
317         entryIndicator.arrowDimens.alphaSpring?.let { alphaSpring ->
318             arrowStrokeAlphaSpring = Step(
319                     threshold = showArrowOnProgressValue,
320                     factor = showArrowOnProgressValueFactor,
321                     postThreshold = alphaSpring,
322                     preThreshold = SpringForce().setStiffness(2000f).setDampingRatio(1f)
323             )
324         }
325     }
326 }
327 
createSpringnull328 fun createSpring(stiffness: Float, dampingRatio: Float): SpringForce {
329     return SpringForce().setStiffness(stiffness).setDampingRatio(dampingRatio)
330 }