Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 139a2cb6 authored by Mike Schneider's avatar Mike Schneider
Browse files

[MotionValue] implementation #MotionMechanics

The [MotionValue] implementation, transforming an input value to an (animated) output value, acording to the [MotionSpec].

Background on design and motivation in go/motionvalue-design

Flag: NONE Initial commits for new library, currently unused.
Test: atest mechanics_tests
Bug: 379248269
Change-Id: I959517ff863c060b655c40950b95f7ae0cea2e3d
parent fd9fc8e7
Loading
Loading
Loading
Loading
+807 −0

File added.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ import kotlin.math.pow
 * @see SpringParameters function to create this value.
 */
@JvmInline
value class SpringParameters(private val packedValue: Long) {
value class SpringParameters(val packedValue: Long) {
    val stiffness: Float
        get() = unpackFloat1(packedValue)

+5 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ import kotlin.math.sqrt
 * @see SpringState function to create this value.
 */
@JvmInline
value class SpringState(private val packedValue: Long) {
value class SpringState(val packedValue: Long) {
    val displacement: Float
        get() = unpackFloat1(packedValue)

@@ -51,6 +51,10 @@ value class SpringState(private val packedValue: Long) {
        return currentEnergy <= maxStableEnergy
    }

    fun addDisplacement(displacementDelta: Float): SpringState {
        return SpringState(displacement + displacementDelta, velocity)
    }

    override fun toString(): String {
        return "MechanicsSpringState(displacement=$displacement, velocity=$velocity)"
    }
+3 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ package {
android_test {
    name: "mechanics_tests",
    manifest: "AndroidManifest.xml",
    defaults: ["MotionTestDefaults"],
    test_suites: ["device-tests"],

    srcs: [
@@ -37,8 +38,9 @@ android_test {
        // ":mechanics_tests" dependencies
        "androidx.compose.animation_animation-core",
        "platform-test-annotations",
        "PlatformMotionTesting",
        "PlatformMotionTestingCompose",
        "androidx.compose.ui_ui-test-junit4",
        "androidx.compose.ui_ui-test-manifest",
        "androidx.test.runner",
        "androidx.test.ext.junit",
        "kotlin-test",
+0 −4
Original line number Diff line number Diff line
@@ -17,10 +17,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.mechanics.tests">

    <application>
        <uses-library android:name="android.test.runner" />
    </application>

    <instrumentation
        android:name="androidx.test.runner.AndroidJUnitRunner"
        android:label="Tests for Motion Mechanics"
Loading