Separate out ShaderLib from AnimationLib.

Bug: 258689851
Test: m, gradle build
Change-Id: I784637fbe09d82215cc99420d5a472ad06b5326a
diff --git a/packages/SystemUI/animation/Android.bp b/packages/SystemUI/animation/Android.bp
index 978ab5d..5b5871f 100644
--- a/packages/SystemUI/animation/Android.bp
+++ b/packages/SystemUI/animation/Android.bp
@@ -29,6 +29,10 @@
         "src/**/*.java",
         "src/**/*.kt",
     ],
+    exclude_srcs: [
+        "src/com/android/systemui/surfaceeffects/**/*.java",
+        "src/com/android/systemui/surfaceeffects/**/*.kt",
+    ],
 
     resource_dirs: [
         "res",
@@ -38,8 +42,30 @@
         "androidx.core_core-animation-nodeps",
         "androidx.core_core-ktx",
         "androidx.annotation_annotation",
+        "SystemUIShaderLib",
+    ],
+
+    manifest: "AndroidManifest.xml",
+    kotlincflags: ["-Xjvm-default=all"],
+}
+
+android_library {
+    name: "SystemUIShaderLib",
+
+    srcs: [
+        "src/com/android/systemui/surfaceeffects/**/*.java",
+        "src/com/android/systemui/surfaceeffects/**/*.kt",
+    ],
+
+    static_libs: [
+        "androidx.core_core-animation-nodeps",
+        "androidx.core_core-ktx",
+        "androidx.annotation_annotation",
     ],
 
     manifest: "AndroidManifest.xml",
     kotlincflags: ["-Xjvm-default=all"],
+
+    // sdk_version must be specified, otherwise it compiles against private APIs.
+    sdk_version: "current",
 }
diff --git a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/MultiRippleView.kt b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/MultiRippleView.kt
index 550d2c6..6c175dd 100644
--- a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/MultiRippleView.kt
+++ b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/MultiRippleView.kt
@@ -20,7 +20,6 @@
 import android.graphics.Canvas
 import android.graphics.Paint
 import android.util.AttributeSet
-import android.util.Log
 import android.view.View
 import androidx.annotation.VisibleForTesting
 
@@ -34,24 +33,15 @@
     @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
     val ripples = ArrayList<RippleAnimation>()
     private val ripplePaint = Paint()
-    private var isWarningLogged = false
 
     companion object {
         private const val TAG = "MultiRippleView"
     }
 
-    override fun onDraw(canvas: Canvas?) {
-        if (canvas == null || !canvas.isHardwareAccelerated) {
-            // Drawing with the ripple shader requires hardware acceleration, so skip
-            // if it's unsupported.
-            if (!isWarningLogged) {
-                // Only log once to not spam.
-                Log.w(
-                    TAG,
-                    "Can't draw ripple shader. $canvas does not support hardware acceleration."
-                )
-                isWarningLogged = true
-            }
+    override fun onDraw(canvas: Canvas) {
+        if (!canvas.isHardwareAccelerated) {
+            // Drawing with the ripple shader requires hardware acceleration, so skip if it's
+            // unsupported.
             return
         }
 
diff --git a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/RippleAnimation.kt b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/RippleAnimation.kt
index bd91c65..d437250 100644
--- a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/RippleAnimation.kt
+++ b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/RippleAnimation.kt
@@ -54,7 +54,7 @@
         }
         animator.addListener(
             object : AnimatorListenerAdapter() {
-                override fun onAnimationEnd(animation: Animator?) {
+                override fun onAnimationEnd(animation: Animator) {
                     onAnimationEnd?.run()
                 }
             }
diff --git a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/RippleShader.kt b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/RippleShader.kt
index 0b842ad..052888b 100644
--- a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/RippleShader.kt
+++ b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/RippleShader.kt
@@ -17,9 +17,9 @@
 
 import android.graphics.RuntimeShader
 import android.util.Log
-import android.util.MathUtils
+import android.view.animation.Interpolator
+import android.view.animation.PathInterpolator
 import androidx.annotation.VisibleForTesting
-import com.android.systemui.animation.Interpolators
 import com.android.systemui.surfaceeffects.shaderutil.SdfShaderLibrary
 import com.android.systemui.surfaceeffects.shaderutil.ShaderUtilLibrary
 
@@ -180,6 +180,13 @@
 
             return Math.min(fadeIn, fadeOut)
         }
+
+        private fun lerp(start: Float, stop: Float, amount: Float): Float {
+            return start + (stop - start) * amount
+        }
+
+        // Copied from [Interpolators#STANDARD]. This is to remove dependency on AnimationLib.
+        private val STANDARD: Interpolator = PathInterpolator(0.2f, 0f, 0f, 1f)
     }
 
     /** Sets the center position of the ripple. */
@@ -207,7 +214,7 @@
     var rawProgress: Float = 0.0f
         set(value) {
             field = value
-            progress = Interpolators.STANDARD.getInterpolation(value)
+            progress = STANDARD.getInterpolation(value)
 
             setFloatUniform("in_fadeSparkle", getFade(sparkleRingFadeParams, value))
             setFloatUniform("in_fadeRing", getFade(baseRingFadeParams, value))
@@ -228,8 +235,7 @@
                 "in_cornerRadius",
                 Math.min(rippleSize.currentWidth, rippleSize.currentHeight)
             )
-
-            setFloatUniform("in_blur", MathUtils.lerp(blurStart, blurEnd, value))
+            setFloatUniform("in_blur", lerp(1.25f, 0.5f, value))
         }
 
     /** Play time since the start of the effect. */
diff --git a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/RippleView.kt b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/RippleView.kt
index 4c7c435..ef5ad43 100644
--- a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/RippleView.kt
+++ b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/RippleView.kt
@@ -196,7 +196,7 @@
         }
         animator.addListener(
             object : AnimatorListenerAdapter() {
-                override fun onAnimationEnd(animation: Animator?) {
+                override fun onAnimationEnd(animation: Animator) {
                     onAnimationEnd?.run()
                 }
             }
@@ -221,10 +221,10 @@
     /** Indicates whether the ripple animation is playing. */
     fun rippleInProgress(): Boolean = animator.isRunning
 
-    override fun onDraw(canvas: Canvas?) {
-        if (canvas == null || !canvas.isHardwareAccelerated) {
-            // Drawing with the ripple shader requires hardware acceleration, so skip
-            // if it's unsupported.
+    override fun onDraw(canvas: Canvas) {
+        if (!canvas.isHardwareAccelerated) {
+            // Drawing with the ripple shader requires hardware acceleration, so skip if it's
+            // unsupported.
             return
         }
         // To reduce overdraw, we mask the effect to a circle or a rectangle that's bigger than the
diff --git a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseView.kt b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseView.kt
index e1e515d..c3e8478 100644
--- a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseView.kt
+++ b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseView.kt
@@ -49,8 +49,8 @@
     @VisibleForTesting var noiseConfig: TurbulenceNoiseAnimationConfig? = null
     @VisibleForTesting var currentAnimator: ValueAnimator? = null
 
-    override fun onDraw(canvas: Canvas?) {
-        if (canvas == null || !canvas.isHardwareAccelerated) {
+    override fun onDraw(canvas: Canvas) {
+        if (!canvas.isHardwareAccelerated) {
             // Drawing with the turbulence noise shader requires hardware acceleration, so skip
             // if it's unsupported.
             return