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

Commit 873d9af4 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 12710726 from 25602792 to 25Q1-release

Change-Id: I4ae0bdc094968428cac53aeaf7e52485457e7dcf
parents 0f42cbcc 25602792
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -76,3 +76,10 @@ flag {
    description: "Enables ambient wallpaper and AOD enhancements"
    bug: "372655702"
}

flag {
    name: "enable_launcher_icon_shapes"
    namespace: "systemui"
    description: "Enables launcher icon shapes customization"
    bug: "348708061"
}

mechanics/Android.bp

0 → 100644
+40 −0
Original line number Diff line number Diff line
// Copyright (C) 2024 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package {
    default_team: "trendy_team_motion",
    default_applicable_licenses: ["Android-Apache-2.0"],
}

filegroup {
    name: "mechanics-srcs",
    srcs: [
        "src/**/*.kt",
    ],
}

android_library {
    name: "mechanics",
    manifest: "AndroidManifest.xml",
    sdk_version: "system_current",
    min_sdk_version: "current",
    static_libs: [
        "androidx.compose.runtime_runtime",
        "androidx.compose.ui_ui-util",
    ],
    srcs: [
        ":mechanics-srcs",
    ],
    kotlincflags: ["-Xjvm-default=all"],
}
+19 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!--
     Copyright (C) 2024 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.mechanics">
</manifest>

mechanics/TEST_MAPPING

0 → 100644
+7 −0
Original line number Diff line number Diff line
{
  "postsubmit": [
    {
      "name": "mechanics_tests"
    }
  ]
}
+78 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.mechanics.spring

import androidx.compose.ui.util.lerp
import androidx.compose.ui.util.packFloats
import androidx.compose.ui.util.unpackFloat1
import androidx.compose.ui.util.unpackFloat2
import kotlin.math.pow

/**
 * Describes the parameters of a spring.
 *
 * Note: This is conceptually compatible with the Compose [SpringSpec]. In contrast to the compose
 * implementation, these [SpringParameters] are intended to be continuously updated.
 *
 * @see SpringParameters function to create this value.
 */
@JvmInline
value class SpringParameters(private val packedValue: Long) {
    val stiffness: Float
        get() = unpackFloat1(packedValue)

    val dampingRatio: Float
        get() = unpackFloat2(packedValue)

    /** Whether the spring is expected to immediately end movement. */
    val isSnapSpring: Boolean
        get() = stiffness >= snapStiffness && dampingRatio == snapDamping

    override fun toString(): String {
        return "MechanicsSpringSpec(stiffness=$stiffness, dampingRatio=$dampingRatio)"
    }

    companion object {
        private val snapStiffness = 100_000f
        private val snapDamping = 1f

        /** A spring so stiff it completes the motion almost immediately. */
        val Snap = SpringParameters(snapStiffness, snapDamping)
    }
}

/** Creates a [SpringParameters] with the given [stiffness] and [dampingRatio]. */
fun SpringParameters(stiffness: Float, dampingRatio: Float): SpringParameters {
    require(stiffness > 0) { "Spring stiffness constant must be positive." }
    require(dampingRatio >= 0) { "Spring damping constant must be positive." }
    return SpringParameters(packFloats(stiffness, dampingRatio))
}

/**
 * Return interpolated [SpringParameters], based on the [fraction] between [start] and [stop].
 *
 * The [SpringParameters.dampingRatio] is interpolated linearly, the [SpringParameters.stiffness] is
 * interpolated logarithmically.
 *
 * The [fraction] is clamped to a `0..1` range.
 */
fun lerp(start: SpringParameters, stop: SpringParameters, fraction: Float): SpringParameters {
    val f = fraction.coerceIn(0f, 1f)
    val stiffness = start.stiffness.pow(1 - f) * stop.stiffness.pow(f)
    val dampingRatio = lerp(start.dampingRatio, stop.dampingRatio, f)
    return SpringParameters(packFloats(stiffness, dampingRatio))
}
Loading