From def45677c9afc999969406f9590d93ce2c3782e3 Mon Sep 17 00:00:00 2001 From: Fabian Kozynski Date: Wed, 3 Mar 2021 16:18:47 -0500 Subject: [PATCH] Fix color animation The animation was broken for some tiles. Remove the ripple as it was causing issues and was not actually visible. May need to be added later. Test: manual Fixes: 181683146 Change-Id: I778330c88951c7568bd81d06b60dcebd6d28219c --- .../customize/CustomizeTileViewHorizontal.kt | 6 ---- .../qs/tileimpl/QSTileViewHorizontal.kt | 36 ++++++------------- 2 files changed, 11 insertions(+), 31 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/qs/customize/CustomizeTileViewHorizontal.kt b/packages/SystemUI/src/com/android/systemui/qs/customize/CustomizeTileViewHorizontal.kt index 4ffcd8cdd9ce6..f8c0dd4239d9a 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/customize/CustomizeTileViewHorizontal.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/customize/CustomizeTileViewHorizontal.kt @@ -1,7 +1,6 @@ package com.android.systemui.qs.customize import android.content.Context -import android.graphics.drawable.Drawable import android.view.View import com.android.systemui.plugins.qs.QSIconView import com.android.systemui.plugins.qs.QSTile @@ -42,9 +41,4 @@ class CustomizeTileViewHorizontal( override fun changeState(state: QSTile.State) { handleStateChanged(state) } - - override fun newTileBackground(): Drawable? { - super.newTileBackground() - return paintDrawable - } } \ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewHorizontal.kt b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewHorizontal.kt index 231037fdd158e..328c2c353a29b 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewHorizontal.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewHorizontal.kt @@ -21,8 +21,8 @@ import android.content.Context import android.content.res.ColorStateList import android.graphics.Color import android.graphics.drawable.Drawable -import android.graphics.drawable.PaintDrawable -import android.graphics.drawable.RippleDrawable +import android.graphics.drawable.ShapeDrawable +import android.graphics.drawable.shapes.RoundRectShape import android.service.quicksettings.Tile.STATE_ACTIVE import android.view.Gravity import android.widget.LinearLayout @@ -34,13 +34,14 @@ import com.android.systemui.qs.tileimpl.QSTileImpl.getColorForState // Placeholder private const val CORNER_RADIUS = 40f +private val RADII = (1..8).map { CORNER_RADIUS }.toFloatArray() open class QSTileViewHorizontal( context: Context, icon: QSIconView ) : QSTileView(context, icon, false) { - protected var paintDrawable: PaintDrawable? = null + protected var backgroundDrawable: ShapeDrawable? = null private var paintColor = Color.WHITE private var paintAnimator: ValueAnimator? = null @@ -74,28 +75,13 @@ open class QSTileViewHorizontal( } override fun newTileBackground(): Drawable? { - val d = super.newTileBackground() - if (paintDrawable == null) { - paintDrawable = PaintDrawable(paintColor).apply { - setCornerRadius(CORNER_RADIUS) - } - } - if (d is RippleDrawable) { - d.addLayer(paintDrawable) - return d - } else { - return paintDrawable - } + backgroundDrawable = ShapeDrawable(RoundRectShape(RADII, null, null)) + return backgroundDrawable } override fun setClickable(clickable: Boolean) { super.setClickable(clickable) background = mTileBackground - if (clickable && mShowRippleEffect) { - mRipple?.setHotspotBounds(left, top, right, bottom) - } else { - mRipple?.setHotspotBounds(0, 0, 0, 0) - } } override fun handleStateChanged(state: QSTile.State) { @@ -110,11 +96,10 @@ open class QSTileViewHorizontal( } else { if (newColor != paintColor) { clearAnimator() - paintDrawable?.paint?.color = newColor - paintDrawable?.invalidateSelf() + backgroundDrawable?.setTintList(ColorStateList.valueOf(newColor)) + paintColor = newColor } } - paintColor = newColor } private fun animateToNewState(newColor: Int) { @@ -123,8 +108,9 @@ open class QSTileViewHorizontal( paintAnimator = ValueAnimator.ofArgb(paintColor, newColor) .setDuration(QSIconViewImpl.QS_ANIM_LENGTH).apply { addUpdateListener { animation: ValueAnimator -> - paintDrawable?.paint?.color = animation.animatedValue as Int - paintDrawable?.invalidateSelf() + val c = animation.animatedValue as Int + backgroundDrawable?.setTintList(ColorStateList.valueOf(c)) + paintColor = c } start() }