Loading packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt +75 −44 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView import androidx.annotation.ColorInt import com.android.internal.graphics.ColorUtils import com.android.systemui.R import com.android.systemui.animation.Interpolators Loading Loading @@ -313,7 +314,8 @@ class ControlViewHolder( @ColorRes bgColor: Int ) { val bg = context.resources.getColor(R.color.control_default_background, context.theme) var (newClipColor, newAlpha) = if (enabled) { val (newClipColor, newAlpha) = if (enabled) { // allow color overrides for the enabled state only val color = cws.control?.getCustomColor()?.let { val state = intArrayOf(android.R.attr.state_enabled) Loading @@ -326,37 +328,54 @@ class ControlViewHolder( ALPHA_DISABLED ) } clipLayer.getDrawable().apply { clipLayer.alpha = ALPHA_DISABLED val newBaseColor = if (behavior is ToggleRangeBehavior) { ColorUtils.blendARGB(bg, newClipColor, toggleBackgroundIntensity) } else { bg } clipLayer.drawable?.apply { clipLayer.alpha = ALPHA_DISABLED stateAnimator?.cancel() if (animated) { val oldColor = if (this is GradientDrawable) { this.color?.defaultColor ?: newClipColor startBackgroundAnimation(this, newAlpha, newClipColor, newBaseColor) } else { applyBackgroundChange( this, newAlpha, newClipColor, newBaseColor, newLayoutAlpha = 1f ) } } } private fun startBackgroundAnimation( clipDrawable: Drawable, newAlpha: Int, @ColorInt newClipColor: Int, @ColorInt newBaseColor: Int ) { val oldClipColor = if (clipDrawable is GradientDrawable) { clipDrawable.color?.defaultColor ?: newClipColor } else { newClipColor } val oldBaseColor = baseLayer.color?.defaultColor ?: newBaseColor val oldAlpha = layout.alpha // Animate both alpha and background colors. Only animate colors for // GradientDrawables and not static images as used for the ThumbnailTemplate. stateAnimator = ValueAnimator.ofInt(clipLayer.alpha, newAlpha).apply { addUpdateListener { alpha = it.animatedValue as Int if (this is GradientDrawable) { this.setColor(ColorUtils.blendARGB(oldColor, newClipColor, it.animatedFraction)) } baseLayer.setColor(ColorUtils.blendARGB(oldBaseColor, newBaseColor, it.animatedFraction)) layout.alpha = MathUtils.lerp(oldAlpha, 1f, it.animatedFraction) val updatedAlpha = it.animatedValue as Int val updatedClipColor = ColorUtils.blendARGB(oldClipColor, newClipColor, it.animatedFraction) val updatedBaseColor = ColorUtils.blendARGB(oldBaseColor, newBaseColor, it.animatedFraction) val updatedLayoutAlpha = MathUtils.lerp(oldAlpha, 1f, it.animatedFraction) applyBackgroundChange( clipDrawable, updatedAlpha, updatedClipColor, updatedBaseColor, updatedLayoutAlpha ) } addListener(object : AnimatorListenerAdapter() { override fun onAnimationEnd(animation: Animator?) { Loading @@ -367,15 +386,27 @@ class ControlViewHolder( interpolator = Interpolators.CONTROL_STATE start() } } else { alpha = newAlpha if (this is GradientDrawable) { this.setColor(newClipColor) } baseLayer.setColor(newBaseColor) layout.alpha = 1f } /** * Applies a change in background. * * Updates both alpha and background colors. Only updates colors for GradientDrawables and not * static images as used for the ThumbnailTemplate. */ private fun applyBackgroundChange( clipDrawable: Drawable, newAlpha: Int, @ColorInt newClipColor: Int, @ColorInt newBaseColor: Int, newLayoutAlpha: Float ) { clipDrawable.alpha = newAlpha if (clipDrawable is GradientDrawable) { clipDrawable.setColor(newClipColor) } baseLayer.setColor(newBaseColor) layout.alpha = newLayoutAlpha } private fun animateStatusChange(animated: Boolean, statusRowUpdater: () -> Unit) { Loading Loading
packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt +75 −44 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView import androidx.annotation.ColorInt import com.android.internal.graphics.ColorUtils import com.android.systemui.R import com.android.systemui.animation.Interpolators Loading Loading @@ -313,7 +314,8 @@ class ControlViewHolder( @ColorRes bgColor: Int ) { val bg = context.resources.getColor(R.color.control_default_background, context.theme) var (newClipColor, newAlpha) = if (enabled) { val (newClipColor, newAlpha) = if (enabled) { // allow color overrides for the enabled state only val color = cws.control?.getCustomColor()?.let { val state = intArrayOf(android.R.attr.state_enabled) Loading @@ -326,37 +328,54 @@ class ControlViewHolder( ALPHA_DISABLED ) } clipLayer.getDrawable().apply { clipLayer.alpha = ALPHA_DISABLED val newBaseColor = if (behavior is ToggleRangeBehavior) { ColorUtils.blendARGB(bg, newClipColor, toggleBackgroundIntensity) } else { bg } clipLayer.drawable?.apply { clipLayer.alpha = ALPHA_DISABLED stateAnimator?.cancel() if (animated) { val oldColor = if (this is GradientDrawable) { this.color?.defaultColor ?: newClipColor startBackgroundAnimation(this, newAlpha, newClipColor, newBaseColor) } else { applyBackgroundChange( this, newAlpha, newClipColor, newBaseColor, newLayoutAlpha = 1f ) } } } private fun startBackgroundAnimation( clipDrawable: Drawable, newAlpha: Int, @ColorInt newClipColor: Int, @ColorInt newBaseColor: Int ) { val oldClipColor = if (clipDrawable is GradientDrawable) { clipDrawable.color?.defaultColor ?: newClipColor } else { newClipColor } val oldBaseColor = baseLayer.color?.defaultColor ?: newBaseColor val oldAlpha = layout.alpha // Animate both alpha and background colors. Only animate colors for // GradientDrawables and not static images as used for the ThumbnailTemplate. stateAnimator = ValueAnimator.ofInt(clipLayer.alpha, newAlpha).apply { addUpdateListener { alpha = it.animatedValue as Int if (this is GradientDrawable) { this.setColor(ColorUtils.blendARGB(oldColor, newClipColor, it.animatedFraction)) } baseLayer.setColor(ColorUtils.blendARGB(oldBaseColor, newBaseColor, it.animatedFraction)) layout.alpha = MathUtils.lerp(oldAlpha, 1f, it.animatedFraction) val updatedAlpha = it.animatedValue as Int val updatedClipColor = ColorUtils.blendARGB(oldClipColor, newClipColor, it.animatedFraction) val updatedBaseColor = ColorUtils.blendARGB(oldBaseColor, newBaseColor, it.animatedFraction) val updatedLayoutAlpha = MathUtils.lerp(oldAlpha, 1f, it.animatedFraction) applyBackgroundChange( clipDrawable, updatedAlpha, updatedClipColor, updatedBaseColor, updatedLayoutAlpha ) } addListener(object : AnimatorListenerAdapter() { override fun onAnimationEnd(animation: Animator?) { Loading @@ -367,15 +386,27 @@ class ControlViewHolder( interpolator = Interpolators.CONTROL_STATE start() } } else { alpha = newAlpha if (this is GradientDrawable) { this.setColor(newClipColor) } baseLayer.setColor(newBaseColor) layout.alpha = 1f } /** * Applies a change in background. * * Updates both alpha and background colors. Only updates colors for GradientDrawables and not * static images as used for the ThumbnailTemplate. */ private fun applyBackgroundChange( clipDrawable: Drawable, newAlpha: Int, @ColorInt newClipColor: Int, @ColorInt newBaseColor: Int, newLayoutAlpha: Float ) { clipDrawable.alpha = newAlpha if (clipDrawable is GradientDrawable) { clipDrawable.setColor(newClipColor) } baseLayer.setColor(newBaseColor) layout.alpha = newLayoutAlpha } private fun animateStatusChange(animated: Boolean, statusRowUpdater: () -> Unit) { Loading