Loading packages/SystemUI/animation/Android.bp +26 −0 Original line number Original line Diff line number Diff line Loading @@ -29,6 +29,10 @@ android_library { "src/**/*.java", "src/**/*.java", "src/**/*.kt", "src/**/*.kt", ], ], exclude_srcs: [ "src/com/android/systemui/surfaceeffects/**/*.java", "src/com/android/systemui/surfaceeffects/**/*.kt", ], resource_dirs: [ resource_dirs: [ "res", "res", Loading @@ -38,8 +42,30 @@ android_library { "androidx.core_core-animation-nodeps", "androidx.core_core-animation-nodeps", "androidx.core_core-ktx", "androidx.core_core-ktx", "androidx.annotation_annotation", "androidx.annotation_annotation", "SystemUIShaderLib", ], ], manifest: "AndroidManifest.xml", manifest: "AndroidManifest.xml", kotlincflags: ["-Xjvm-default=all"], 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", } packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/MultiRippleView.kt +4 −14 Original line number Original line Diff line number Diff line Loading @@ -20,7 +20,6 @@ import android.content.Context import android.graphics.Canvas import android.graphics.Canvas import android.graphics.Paint import android.graphics.Paint import android.util.AttributeSet import android.util.AttributeSet import android.util.Log import android.view.View import android.view.View import androidx.annotation.VisibleForTesting import androidx.annotation.VisibleForTesting Loading @@ -34,24 +33,15 @@ class MultiRippleView(context: Context?, attrs: AttributeSet?) : View(context, a @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE) @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE) val ripples = ArrayList<RippleAnimation>() val ripples = ArrayList<RippleAnimation>() private val ripplePaint = Paint() private val ripplePaint = Paint() private var isWarningLogged = false companion object { companion object { private const val TAG = "MultiRippleView" private const val TAG = "MultiRippleView" } } override fun onDraw(canvas: Canvas?) { override fun onDraw(canvas: Canvas) { if (canvas == null || !canvas.isHardwareAccelerated) { if (!canvas.isHardwareAccelerated) { // Drawing with the ripple shader requires hardware acceleration, so skip // Drawing with the ripple shader requires hardware acceleration, so skip if it's // if it's unsupported. // 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 } return return } } Loading packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/RippleAnimation.kt +1 −1 Original line number Original line Diff line number Diff line Loading @@ -54,7 +54,7 @@ class RippleAnimation(private val config: RippleAnimationConfig) { } } animator.addListener( animator.addListener( object : AnimatorListenerAdapter() { object : AnimatorListenerAdapter() { override fun onAnimationEnd(animation: Animator?) { override fun onAnimationEnd(animation: Animator) { onAnimationEnd?.run() onAnimationEnd?.run() } } } } Loading packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/RippleShader.kt +11 −5 Original line number Original line Diff line number Diff line Loading @@ -17,9 +17,9 @@ package com.android.systemui.surfaceeffects.ripple import android.graphics.RuntimeShader import android.graphics.RuntimeShader import android.util.Log import android.util.Log import android.util.MathUtils import android.view.animation.Interpolator import android.view.animation.PathInterpolator import androidx.annotation.VisibleForTesting import androidx.annotation.VisibleForTesting import com.android.systemui.animation.Interpolators import com.android.systemui.surfaceeffects.shaderutil.SdfShaderLibrary import com.android.systemui.surfaceeffects.shaderutil.SdfShaderLibrary import com.android.systemui.surfaceeffects.shaderutil.ShaderUtilLibrary import com.android.systemui.surfaceeffects.shaderutil.ShaderUtilLibrary Loading Loading @@ -180,6 +180,13 @@ class RippleShader(rippleShape: RippleShape = RippleShape.CIRCLE) : return Math.min(fadeIn, fadeOut) 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. */ /** Sets the center position of the ripple. */ Loading Loading @@ -207,7 +214,7 @@ class RippleShader(rippleShape: RippleShape = RippleShape.CIRCLE) : var rawProgress: Float = 0.0f var rawProgress: Float = 0.0f set(value) { set(value) { field = value field = value progress = Interpolators.STANDARD.getInterpolation(value) progress = STANDARD.getInterpolation(value) setFloatUniform("in_fadeSparkle", getFade(sparkleRingFadeParams, value)) setFloatUniform("in_fadeSparkle", getFade(sparkleRingFadeParams, value)) setFloatUniform("in_fadeRing", getFade(baseRingFadeParams, value)) setFloatUniform("in_fadeRing", getFade(baseRingFadeParams, value)) Loading @@ -228,8 +235,7 @@ class RippleShader(rippleShape: RippleShape = RippleShape.CIRCLE) : "in_cornerRadius", "in_cornerRadius", Math.min(rippleSize.currentWidth, rippleSize.currentHeight) Math.min(rippleSize.currentWidth, rippleSize.currentHeight) ) ) setFloatUniform("in_blur", lerp(1.25f, 0.5f, value)) setFloatUniform("in_blur", MathUtils.lerp(blurStart, blurEnd, value)) } } /** Play time since the start of the effect. */ /** Play time since the start of the effect. */ Loading packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/RippleView.kt +5 −5 Original line number Original line Diff line number Diff line Loading @@ -196,7 +196,7 @@ open class RippleView(context: Context?, attrs: AttributeSet?) : View(context, a } } animator.addListener( animator.addListener( object : AnimatorListenerAdapter() { object : AnimatorListenerAdapter() { override fun onAnimationEnd(animation: Animator?) { override fun onAnimationEnd(animation: Animator) { onAnimationEnd?.run() onAnimationEnd?.run() } } } } Loading @@ -221,10 +221,10 @@ open class RippleView(context: Context?, attrs: AttributeSet?) : View(context, a /** Indicates whether the ripple animation is playing. */ /** Indicates whether the ripple animation is playing. */ fun rippleInProgress(): Boolean = animator.isRunning fun rippleInProgress(): Boolean = animator.isRunning override fun onDraw(canvas: Canvas?) { override fun onDraw(canvas: Canvas) { if (canvas == null || !canvas.isHardwareAccelerated) { if (!canvas.isHardwareAccelerated) { // Drawing with the ripple shader requires hardware acceleration, so skip // Drawing with the ripple shader requires hardware acceleration, so skip if it's // if it's unsupported. // unsupported. return return } } // To reduce overdraw, we mask the effect to a circle or a rectangle that's bigger than the // To reduce overdraw, we mask the effect to a circle or a rectangle that's bigger than the Loading Loading
packages/SystemUI/animation/Android.bp +26 −0 Original line number Original line Diff line number Diff line Loading @@ -29,6 +29,10 @@ android_library { "src/**/*.java", "src/**/*.java", "src/**/*.kt", "src/**/*.kt", ], ], exclude_srcs: [ "src/com/android/systemui/surfaceeffects/**/*.java", "src/com/android/systemui/surfaceeffects/**/*.kt", ], resource_dirs: [ resource_dirs: [ "res", "res", Loading @@ -38,8 +42,30 @@ android_library { "androidx.core_core-animation-nodeps", "androidx.core_core-animation-nodeps", "androidx.core_core-ktx", "androidx.core_core-ktx", "androidx.annotation_annotation", "androidx.annotation_annotation", "SystemUIShaderLib", ], ], manifest: "AndroidManifest.xml", manifest: "AndroidManifest.xml", kotlincflags: ["-Xjvm-default=all"], 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", }
packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/MultiRippleView.kt +4 −14 Original line number Original line Diff line number Diff line Loading @@ -20,7 +20,6 @@ import android.content.Context import android.graphics.Canvas import android.graphics.Canvas import android.graphics.Paint import android.graphics.Paint import android.util.AttributeSet import android.util.AttributeSet import android.util.Log import android.view.View import android.view.View import androidx.annotation.VisibleForTesting import androidx.annotation.VisibleForTesting Loading @@ -34,24 +33,15 @@ class MultiRippleView(context: Context?, attrs: AttributeSet?) : View(context, a @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE) @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE) val ripples = ArrayList<RippleAnimation>() val ripples = ArrayList<RippleAnimation>() private val ripplePaint = Paint() private val ripplePaint = Paint() private var isWarningLogged = false companion object { companion object { private const val TAG = "MultiRippleView" private const val TAG = "MultiRippleView" } } override fun onDraw(canvas: Canvas?) { override fun onDraw(canvas: Canvas) { if (canvas == null || !canvas.isHardwareAccelerated) { if (!canvas.isHardwareAccelerated) { // Drawing with the ripple shader requires hardware acceleration, so skip // Drawing with the ripple shader requires hardware acceleration, so skip if it's // if it's unsupported. // 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 } return return } } Loading
packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/RippleAnimation.kt +1 −1 Original line number Original line Diff line number Diff line Loading @@ -54,7 +54,7 @@ class RippleAnimation(private val config: RippleAnimationConfig) { } } animator.addListener( animator.addListener( object : AnimatorListenerAdapter() { object : AnimatorListenerAdapter() { override fun onAnimationEnd(animation: Animator?) { override fun onAnimationEnd(animation: Animator) { onAnimationEnd?.run() onAnimationEnd?.run() } } } } Loading
packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/RippleShader.kt +11 −5 Original line number Original line Diff line number Diff line Loading @@ -17,9 +17,9 @@ package com.android.systemui.surfaceeffects.ripple import android.graphics.RuntimeShader import android.graphics.RuntimeShader import android.util.Log import android.util.Log import android.util.MathUtils import android.view.animation.Interpolator import android.view.animation.PathInterpolator import androidx.annotation.VisibleForTesting import androidx.annotation.VisibleForTesting import com.android.systemui.animation.Interpolators import com.android.systemui.surfaceeffects.shaderutil.SdfShaderLibrary import com.android.systemui.surfaceeffects.shaderutil.SdfShaderLibrary import com.android.systemui.surfaceeffects.shaderutil.ShaderUtilLibrary import com.android.systemui.surfaceeffects.shaderutil.ShaderUtilLibrary Loading Loading @@ -180,6 +180,13 @@ class RippleShader(rippleShape: RippleShape = RippleShape.CIRCLE) : return Math.min(fadeIn, fadeOut) 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. */ /** Sets the center position of the ripple. */ Loading Loading @@ -207,7 +214,7 @@ class RippleShader(rippleShape: RippleShape = RippleShape.CIRCLE) : var rawProgress: Float = 0.0f var rawProgress: Float = 0.0f set(value) { set(value) { field = value field = value progress = Interpolators.STANDARD.getInterpolation(value) progress = STANDARD.getInterpolation(value) setFloatUniform("in_fadeSparkle", getFade(sparkleRingFadeParams, value)) setFloatUniform("in_fadeSparkle", getFade(sparkleRingFadeParams, value)) setFloatUniform("in_fadeRing", getFade(baseRingFadeParams, value)) setFloatUniform("in_fadeRing", getFade(baseRingFadeParams, value)) Loading @@ -228,8 +235,7 @@ class RippleShader(rippleShape: RippleShape = RippleShape.CIRCLE) : "in_cornerRadius", "in_cornerRadius", Math.min(rippleSize.currentWidth, rippleSize.currentHeight) Math.min(rippleSize.currentWidth, rippleSize.currentHeight) ) ) setFloatUniform("in_blur", lerp(1.25f, 0.5f, value)) setFloatUniform("in_blur", MathUtils.lerp(blurStart, blurEnd, value)) } } /** Play time since the start of the effect. */ /** Play time since the start of the effect. */ Loading
packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/RippleView.kt +5 −5 Original line number Original line Diff line number Diff line Loading @@ -196,7 +196,7 @@ open class RippleView(context: Context?, attrs: AttributeSet?) : View(context, a } } animator.addListener( animator.addListener( object : AnimatorListenerAdapter() { object : AnimatorListenerAdapter() { override fun onAnimationEnd(animation: Animator?) { override fun onAnimationEnd(animation: Animator) { onAnimationEnd?.run() onAnimationEnd?.run() } } } } Loading @@ -221,10 +221,10 @@ open class RippleView(context: Context?, attrs: AttributeSet?) : View(context, a /** Indicates whether the ripple animation is playing. */ /** Indicates whether the ripple animation is playing. */ fun rippleInProgress(): Boolean = animator.isRunning fun rippleInProgress(): Boolean = animator.isRunning override fun onDraw(canvas: Canvas?) { override fun onDraw(canvas: Canvas) { if (canvas == null || !canvas.isHardwareAccelerated) { if (!canvas.isHardwareAccelerated) { // Drawing with the ripple shader requires hardware acceleration, so skip // Drawing with the ripple shader requires hardware acceleration, so skip if it's // if it's unsupported. // unsupported. return return } } // To reduce overdraw, we mask the effect to a circle or a rectangle that's bigger than the // To reduce overdraw, we mask the effect to a circle or a rectangle that's bigger than the Loading