• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.mechanics.impl
18 
19 import com.android.mechanics.spring.SpringParameters
20 import com.android.mechanics.spring.SpringState
21 
22 /**
23  * Captures the start-state of a spring-animation to smooth over a discontinuity.
24  *
25  * Discontinuities are caused by segment changes, where the new and old segment produce different
26  * output values for the same input.
27  */
28 internal data class DiscontinuityAnimation(
29     val targetValue: Float,
30     val springStartState: SpringState,
31     val springParameters: SpringParameters,
32     val springStartTimeNanos: Long,
33 ) {
34     val isAtRest: Boolean
35         get() = springStartState == SpringState.AtRest
36 
37     companion object {
38         val None =
39             DiscontinuityAnimation(
40                 targetValue = 0f,
41                 springStartState = SpringState.AtRest,
42                 springParameters = SpringParameters.Snap,
43                 springStartTimeNanos = 0L,
44             )
45     }
46 }
47