Merge "Fix color animation" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
e4ba4f837d
@@ -1,7 +1,6 @@
|
|||||||
package com.android.systemui.qs.customize
|
package com.android.systemui.qs.customize
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.drawable.Drawable
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import com.android.systemui.plugins.qs.QSIconView
|
import com.android.systemui.plugins.qs.QSIconView
|
||||||
import com.android.systemui.plugins.qs.QSTile
|
import com.android.systemui.plugins.qs.QSTile
|
||||||
@@ -42,9 +41,4 @@ class CustomizeTileViewHorizontal(
|
|||||||
override fun changeState(state: QSTile.State) {
|
override fun changeState(state: QSTile.State) {
|
||||||
handleStateChanged(state)
|
handleStateChanged(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun newTileBackground(): Drawable? {
|
|
||||||
super.newTileBackground()
|
|
||||||
return paintDrawable
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -21,8 +21,8 @@ import android.content.Context
|
|||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.graphics.drawable.PaintDrawable
|
import android.graphics.drawable.ShapeDrawable
|
||||||
import android.graphics.drawable.RippleDrawable
|
import android.graphics.drawable.shapes.RoundRectShape
|
||||||
import android.service.quicksettings.Tile.STATE_ACTIVE
|
import android.service.quicksettings.Tile.STATE_ACTIVE
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
@@ -34,13 +34,14 @@ import com.android.systemui.qs.tileimpl.QSTileImpl.getColorForState
|
|||||||
|
|
||||||
// Placeholder
|
// Placeholder
|
||||||
private const val CORNER_RADIUS = 40f
|
private const val CORNER_RADIUS = 40f
|
||||||
|
private val RADII = (1..8).map { CORNER_RADIUS }.toFloatArray()
|
||||||
|
|
||||||
open class QSTileViewHorizontal(
|
open class QSTileViewHorizontal(
|
||||||
context: Context,
|
context: Context,
|
||||||
icon: QSIconView
|
icon: QSIconView
|
||||||
) : QSTileView(context, icon, false) {
|
) : QSTileView(context, icon, false) {
|
||||||
|
|
||||||
protected var paintDrawable: PaintDrawable? = null
|
protected var backgroundDrawable: ShapeDrawable? = null
|
||||||
private var paintColor = Color.WHITE
|
private var paintColor = Color.WHITE
|
||||||
private var paintAnimator: ValueAnimator? = null
|
private var paintAnimator: ValueAnimator? = null
|
||||||
|
|
||||||
@@ -74,28 +75,13 @@ open class QSTileViewHorizontal(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun newTileBackground(): Drawable? {
|
override fun newTileBackground(): Drawable? {
|
||||||
val d = super.newTileBackground()
|
backgroundDrawable = ShapeDrawable(RoundRectShape(RADII, null, null))
|
||||||
if (paintDrawable == null) {
|
return backgroundDrawable
|
||||||
paintDrawable = PaintDrawable(paintColor).apply {
|
|
||||||
setCornerRadius(CORNER_RADIUS)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (d is RippleDrawable) {
|
|
||||||
d.addLayer(paintDrawable)
|
|
||||||
return d
|
|
||||||
} else {
|
|
||||||
return paintDrawable
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setClickable(clickable: Boolean) {
|
override fun setClickable(clickable: Boolean) {
|
||||||
super.setClickable(clickable)
|
super.setClickable(clickable)
|
||||||
background = mTileBackground
|
background = mTileBackground
|
||||||
if (clickable && mShowRippleEffect) {
|
|
||||||
mRipple?.setHotspotBounds(left, top, right, bottom)
|
|
||||||
} else {
|
|
||||||
mRipple?.setHotspotBounds(0, 0, 0, 0)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handleStateChanged(state: QSTile.State) {
|
override fun handleStateChanged(state: QSTile.State) {
|
||||||
@@ -110,11 +96,10 @@ open class QSTileViewHorizontal(
|
|||||||
} else {
|
} else {
|
||||||
if (newColor != paintColor) {
|
if (newColor != paintColor) {
|
||||||
clearAnimator()
|
clearAnimator()
|
||||||
paintDrawable?.paint?.color = newColor
|
backgroundDrawable?.setTintList(ColorStateList.valueOf(newColor))
|
||||||
paintDrawable?.invalidateSelf()
|
paintColor = newColor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
paintColor = newColor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun animateToNewState(newColor: Int) {
|
private fun animateToNewState(newColor: Int) {
|
||||||
@@ -123,8 +108,9 @@ open class QSTileViewHorizontal(
|
|||||||
paintAnimator = ValueAnimator.ofArgb(paintColor, newColor)
|
paintAnimator = ValueAnimator.ofArgb(paintColor, newColor)
|
||||||
.setDuration(QSIconViewImpl.QS_ANIM_LENGTH).apply {
|
.setDuration(QSIconViewImpl.QS_ANIM_LENGTH).apply {
|
||||||
addUpdateListener { animation: ValueAnimator ->
|
addUpdateListener { animation: ValueAnimator ->
|
||||||
paintDrawable?.paint?.color = animation.animatedValue as Int
|
val c = animation.animatedValue as Int
|
||||||
paintDrawable?.invalidateSelf()
|
backgroundDrawable?.setTintList(ColorStateList.valueOf(c))
|
||||||
|
paintColor = c
|
||||||
}
|
}
|
||||||
start()
|
start()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user