Merge "Migrate to RippleShader#FadeParams to deprecate rippleFill." into tm-qpr-dev am: 75ae9ea269

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21164324

Change-Id: I65b51b9b9bc96e39b1f42fcb29adb5e1743e1dce
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Yein Jo
2023-02-02 21:06:27 +00:00
committed by Automerger Merge Worker
3 changed files with 29 additions and 12 deletions

View File

@@ -87,7 +87,7 @@ class RippleShader(rippleShape: RippleShape = RippleShape.CIRCLE) :
* (1.-sparkleRing) * in_fadeSparkle; * (1.-sparkleRing) * in_fadeSparkle;
float rippleInsideAlpha = (1.-inside) * in_fadeFill; float rippleInsideAlpha = (1.-inside) * in_fadeFill;
float rippleRingAlpha = (1.-sparkleRing) * in_fadeRing * in_sparkle_strength; float rippleRingAlpha = (1.-sparkleRing) * in_fadeRing;
float rippleAlpha = max(rippleInsideAlpha, rippleRingAlpha) * in_color.a; float rippleAlpha = max(rippleInsideAlpha, rippleRingAlpha) * in_color.a;
vec4 ripple = vec4(in_color.rgb, 1.0) * rippleAlpha; vec4 ripple = vec4(in_color.rgb, 1.0) * rippleAlpha;
return mix(ripple, vec4(sparkle), sparkle * in_sparkle_strength); return mix(ripple, vec4(sparkle), sparkle * in_sparkle_strength);

View File

@@ -117,15 +117,6 @@ open class RippleView(context: Context?, attrs: AttributeSet?) : View(context, a
rippleShader.color = ColorUtils.setAlphaComponent(color, alpha) rippleShader.color = ColorUtils.setAlphaComponent(color, alpha)
} }
/**
* Set whether the ripple should remain filled as the ripple expands.
*
* See [RippleShader.rippleFill].
*/
fun setRippleFill(rippleFill: Boolean) {
rippleShader.rippleFill = rippleFill
}
/** Set the intensity of the sparkles. */ /** Set the intensity of the sparkles. */
fun setSparkleStrength(strength: Float) { fun setSparkleStrength(strength: Float) {
rippleShader.sparkleStrength = strength rippleShader.sparkleStrength = strength

View File

@@ -34,7 +34,7 @@ class ReceiverChipRippleView(context: Context?, attrs: AttributeSet?) : RippleVi
init { init {
setupShader(RippleShader.RippleShape.CIRCLE) setupShader(RippleShader.RippleShape.CIRCLE)
setRippleFill(true) setupRippleFadeParams()
setSparkleStrength(0f) setSparkleStrength(0f)
isStarted = false isStarted = false
} }
@@ -72,7 +72,7 @@ class ReceiverChipRippleView(context: Context?, attrs: AttributeSet?) : RippleVi
animator.removeAllUpdateListeners() animator.removeAllUpdateListeners()
// Only show the outline as ripple expands and disappears when animation ends. // Only show the outline as ripple expands and disappears when animation ends.
setRippleFill(false) removeRippleFill()
val startingPercentage = calculateStartingPercentage(newHeight) val startingPercentage = calculateStartingPercentage(newHeight)
animator.duration = EXPAND_TO_FULL_DURATION animator.duration = EXPAND_TO_FULL_DURATION
@@ -103,6 +103,32 @@ class ReceiverChipRippleView(context: Context?, attrs: AttributeSet?) : RippleVi
return 1 - remainingPercentage return 1 - remainingPercentage
} }
private fun setupRippleFadeParams() {
with(rippleShader) {
// No fade out for the base ring.
baseRingFadeParams.fadeOutStart = 1f
baseRingFadeParams.fadeOutEnd = 1f
// No fade in and outs for the center fill, as we always draw it.
centerFillFadeParams.fadeInStart = 0f
centerFillFadeParams.fadeInEnd = 0f
centerFillFadeParams.fadeOutStart = 1f
centerFillFadeParams.fadeOutEnd = 1f
}
}
private fun removeRippleFill() {
with(rippleShader) {
baseRingFadeParams.fadeOutStart = RippleShader.DEFAULT_BASE_RING_FADE_OUT_START
baseRingFadeParams.fadeOutEnd = RippleShader.DEFAULT_FADE_OUT_END
centerFillFadeParams.fadeInStart = RippleShader.DEFAULT_FADE_IN_START
centerFillFadeParams.fadeInEnd = RippleShader.DEFAULT_CENTER_FILL_FADE_IN_END
centerFillFadeParams.fadeOutStart = RippleShader.DEFAULT_CENTER_FILL_FADE_OUT_START
centerFillFadeParams.fadeOutEnd = RippleShader.DEFAULT_CENTER_FILL_FADE_OUT_END
}
}
companion object { companion object {
const val DEFAULT_DURATION = 333L const val DEFAULT_DURATION = 333L
const val EXPAND_TO_FULL_DURATION = 1000L const val EXPAND_TO_FULL_DURATION = 1000L