Separate out ShaderLib from AnimationLib.
Bug: 258689851 Test: m, gradle build Change-Id: I784637fbe09d82215cc99420d5a472ad06b5326a
This commit is contained in:
@@ -29,11 +29,34 @@ android_library {
|
||||
"src/**/*.java",
|
||||
"src/**/*.kt",
|
||||
],
|
||||
exclude_srcs: [
|
||||
"src/com/android/systemui/surfaceeffects/**/*.java",
|
||||
"src/com/android/systemui/surfaceeffects/**/*.kt",
|
||||
],
|
||||
|
||||
resource_dirs: [
|
||||
"res",
|
||||
],
|
||||
|
||||
static_libs: [
|
||||
"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",
|
||||
@@ -42,4 +65,7 @@ android_library {
|
||||
|
||||
manifest: "AndroidManifest.xml",
|
||||
kotlincflags: ["-Xjvm-default=all"],
|
||||
|
||||
// sdk_version must be specified, otherwise it compiles against private APIs.
|
||||
sdk_version: "current",
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user