From 171d9f931fabde7b54c212f0c41138adfbb47294 Mon Sep 17 00:00:00 2001 From: Fabian Kozynski Date: Tue, 9 Mar 2021 17:24:27 -0500 Subject: [PATCH] Bring back ripple in tiles Also, animate the labels color. Test: manual Fixes: 172063461 Change-Id: I6d002cd1ffe954cc296347a6adf43df3eee71992 --- .../res/drawable/qs_tile_background.xml | 23 ++++++ .../res/drawable/qs_tile_background_shape.xml | 21 +++++ .../customize/CustomizeTileViewHorizontal.kt | 1 + .../systemui/qs/tileimpl/QSTileView.java | 6 +- .../qs/tileimpl/QSTileViewHorizontal.kt | 76 ++++++++++++------- 5 files changed, 100 insertions(+), 27 deletions(-) create mode 100644 packages/SystemUI/res/drawable/qs_tile_background.xml create mode 100644 packages/SystemUI/res/drawable/qs_tile_background_shape.xml diff --git a/packages/SystemUI/res/drawable/qs_tile_background.xml b/packages/SystemUI/res/drawable/qs_tile_background.xml new file mode 100644 index 0000000000000..265f575fc99c1 --- /dev/null +++ b/packages/SystemUI/res/drawable/qs_tile_background.xml @@ -0,0 +1,23 @@ + + + + + + \ No newline at end of file diff --git a/packages/SystemUI/res/drawable/qs_tile_background_shape.xml b/packages/SystemUI/res/drawable/qs_tile_background_shape.xml new file mode 100644 index 0000000000000..f6b68347124ea --- /dev/null +++ b/packages/SystemUI/res/drawable/qs_tile_background_shape.xml @@ -0,0 +1,21 @@ + + + + + + + \ No newline at end of file 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 dd0f1f2392dd9..7977b4904a7da 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/customize/CustomizeTileViewHorizontal.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/customize/CustomizeTileViewHorizontal.kt @@ -27,6 +27,7 @@ class CustomizeTileViewHorizontal( override fun handleStateChanged(state: QSTile.State) { super.handleStateChanged(state) + mShowRippleEffect = false mSecondLine.visibility = if (showAppLabel) View.VISIBLE else View.GONE } diff --git a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileView.java b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileView.java index e65d3a3a56a63..c7ed89ba49b14 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileView.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileView.java @@ -141,7 +141,7 @@ public class QSTileView extends QSTileBaseView { } else { labelColor = mColorLabelUnavailable; } - mLabel.setTextColor(labelColor); + changeLabelColor(labelColor); mState = state.state; mLabel.setText(state.label); } @@ -163,6 +163,10 @@ public class QSTileView extends QSTileBaseView { mPadLock.setVisibility(state.disabledByPolicy ? View.VISIBLE : View.GONE); } + protected void changeLabelColor(ColorStateList color) { + mLabel.setTextColor(color); + } + protected void handleExpand(boolean dualTarget) { mExpandIndicator.setVisibility(dualTarget ? View.VISIBLE : View.GONE); mExpandSpace.setVisibility(dualTarget ? View.VISIBLE : View.GONE); 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 7b0686b752f4f..32285cf797e45 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,7 @@ import android.content.Context import android.content.res.ColorStateList import android.graphics.Color import android.graphics.drawable.Drawable -import android.graphics.drawable.ShapeDrawable -import android.graphics.drawable.shapes.RoundRectShape +import android.graphics.drawable.RippleDrawable import android.service.quicksettings.Tile.STATE_ACTIVE import android.view.Gravity import android.widget.LinearLayout @@ -38,9 +37,10 @@ open class QSTileViewHorizontal( collapsed: Boolean ) : QSTileView(context, icon, collapsed) { - protected var backgroundDrawable: ShapeDrawable? = null + protected var colorBackgroundDrawable: Drawable? = null private var paintColor = Color.WHITE private var paintAnimator: ValueAnimator? = null + private var labelAnimator: ValueAnimator? = null init { orientation = HORIZONTAL @@ -90,38 +90,32 @@ open class QSTileViewHorizontal( } override fun newTileBackground(): Drawable? { - val cornerRadius = context.resources - .getDimensionPixelSize(R.dimen.qs_corner_radius).toFloat() - backgroundDrawable = ShapeDrawable(createShape(cornerRadius)) - return backgroundDrawable - } - - private fun createShape(cornerRadius: Float): RoundRectShape { - val radii = FloatArray(8) - radii.indices.forEach { radii[it] = cornerRadius } - return RoundRectShape(radii, null, null) + val ripple = mContext.getDrawable(R.drawable.qs_tile_background) as RippleDrawable + colorBackgroundDrawable = ripple.findDrawableByLayerId(R.id.background) + return ripple } override fun setClickable(clickable: Boolean) { super.setClickable(clickable) - background = mTileBackground + background = if (clickable && mShowRippleEffect) { + mTileBackground + } else { + colorBackgroundDrawable + } } override fun handleStateChanged(state: QSTile.State) { super.handleStateChanged(state) - if (!mCollapsedView) { - mSecondLine.setTextColor(mLabel.textColors) - } mLabelContainer.background = null val allowAnimations = animationsEnabled() && paintColor != Color.WHITE val newColor = getCircleColor(state.state) if (allowAnimations) { - animateToNewState(newColor) + animateBackground(newColor) } else { if (newColor != paintColor) { - clearAnimator() - backgroundDrawable?.setTintList(ColorStateList.valueOf(newColor))?.also { + clearBackgroundAnimator() + colorBackgroundDrawable?.setTintList(ColorStateList.valueOf(newColor))?.also { paintColor = newColor } paintColor = newColor @@ -129,14 +123,14 @@ open class QSTileViewHorizontal( } } - private fun animateToNewState(newColor: Int) { - if (newColor != paintColor) { - clearAnimator() - paintAnimator = ValueAnimator.ofArgb(paintColor, newColor) + private fun animateBackground(newBackgroundColor: Int) { + if (newBackgroundColor != paintColor) { + clearBackgroundAnimator() + paintAnimator = ValueAnimator.ofArgb(paintColor, newBackgroundColor) .setDuration(QSIconViewImpl.QS_ANIM_LENGTH).apply { addUpdateListener { animation: ValueAnimator -> val c = animation.animatedValue as Int - backgroundDrawable?.setTintList(ColorStateList.valueOf(c))?.also { + colorBackgroundDrawable?.setTintList(ColorStateList.valueOf(c))?.also { paintColor = c } } @@ -145,9 +139,39 @@ open class QSTileViewHorizontal( } } - private fun clearAnimator() { + override fun changeLabelColor(color: ColorStateList) { + val allowAnimations = animationsEnabled() + val currentColor = mLabel.textColors.defaultColor + if (currentColor != color.defaultColor) { + clearLabelAnimator() + if (allowAnimations) { + labelAnimator = ValueAnimator.ofArgb(currentColor, color.defaultColor) + .setDuration(QSIconViewImpl.QS_ANIM_LENGTH).apply { + addUpdateListener { + setLabelsColor(ColorStateList.valueOf(it.animatedValue as Int)) + } + start() + } + } else { + setLabelsColor(color) + } + } + } + + private fun setLabelsColor(color: ColorStateList) { + mLabel.setTextColor(color) + if (!mCollapsedView) { + mSecondLine.setTextColor(color) + } + } + + private fun clearBackgroundAnimator() { paintAnimator?.cancel()?.also { paintAnimator = null } } + private fun clearLabelAnimator() { + labelAnimator?.cancel()?.also { labelAnimator = null } + } + override fun handleExpand(dualTarget: Boolean) {} } \ No newline at end of file