summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/animation/Android.bp26
-rw-r--r--packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/MultiRippleView.kt18
-rw-r--r--packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/RippleAnimation.kt2
-rw-r--r--packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/RippleShader.kt16
-rw-r--r--packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/RippleView.kt10
-rw-r--r--packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/turbulencenoise/TurbulenceNoiseView.kt4
6 files changed, 49 insertions, 27 deletions
diff --git a/packages/SystemUI/animation/Android.bp b/packages/SystemUI/animation/Android.bp
index 978ab5d9ddd8..5b5871f95fb3 100644
--- a/packages/SystemUI/animation/Android.bp
+++ b/packages/SystemUI/animation/Android.bp
@@ -29,6 +29,10 @@ android_library {
"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 @@ android_library {
"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 550d2c6d8732..6c175ddf1ea4 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.content.Context
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 @@ class MultiRippleView(context: Context?, attrs: AttributeSet?) : View(context, a
@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 bd91c65ecc6e..d4372507e2c4 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 @@ class RippleAnimation(private val config: RippleAnimationConfig) {
}
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 0b842ad5331c..052888b61496 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 @@ package com.android.systemui.surfaceeffects.ripple
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 @@ class RippleShader(rippleShape: RippleShape = RippleShape.CIRCLE) :
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 @@ class RippleShader(rippleShape: RippleShape = RippleShape.CIRCLE) :
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 @@ class RippleShader(rippleShape: RippleShape = RippleShape.CIRCLE) :
"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 4c7c43548016..ef5ad436ec38 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 @@ open class RippleView(context: Context?, attrs: AttributeSet?) : View(context, a
}
animator.addListener(
object : AnimatorListenerAdapter() {
- override fun onAnimationEnd(animation: Animator?) {
+ override fun onAnimationEnd(animation: Animator) {
onAnimationEnd?.run()
}
}
@@ -221,10 +221,10 @@ open class RippleView(context: Context?, attrs: AttributeSet?) : View(context, a
/** 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 e1e515d14771..c3e84787d4fb 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 @@ class TurbulenceNoiseView(context: Context?, attrs: AttributeSet?) : View(contex
@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