Fix drawables state
This commit is contained in:
@@ -33,7 +33,7 @@ class AnimatedFaviconDrawable(
|
||||
|
||||
init {
|
||||
timeAnimator.setTimeListener(this)
|
||||
updateColor()
|
||||
onStateChange(state)
|
||||
}
|
||||
|
||||
override fun draw(canvas: Canvas) {
|
||||
@@ -44,11 +44,11 @@ class AnimatedFaviconDrawable(
|
||||
super.draw(canvas)
|
||||
}
|
||||
|
||||
override fun setAlpha(alpha: Int) = Unit
|
||||
|
||||
override fun getAlpha(): Int = 255
|
||||
|
||||
override fun isOpaque(): Boolean = false
|
||||
// override fun setAlpha(alpha: Int) = Unit
|
||||
//
|
||||
// override fun getAlpha(): Int = 255
|
||||
//
|
||||
// override fun isOpaque(): Boolean = false
|
||||
|
||||
override fun onTimeUpdate(animation: TimeAnimator?, totalTime: Long, deltaTime: Long) {
|
||||
callback?.also {
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.graphics.ColorFilter
|
||||
import android.graphics.PixelFormat
|
||||
import android.graphics.drawable.Animatable
|
||||
import android.graphics.drawable.Drawable
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
|
||||
import com.google.android.material.animation.ArgbEvaluatorCompat
|
||||
import org.koitharu.kotatsu.R
|
||||
@@ -23,6 +24,7 @@ class AnimatedPlaceholderDrawable(context: Context) : Drawable(), Animatable, Ti
|
||||
private val interpolator = FastOutSlowInInterpolator()
|
||||
private val period = context.getAnimationDuration(R.integer.config_longAnimTime) * 2
|
||||
private val timeAnimator = TimeAnimator()
|
||||
private var currentAlpha: Int = 255
|
||||
|
||||
init {
|
||||
timeAnimator.setTimeListener(this)
|
||||
@@ -38,14 +40,15 @@ class AnimatedPlaceholderDrawable(context: Context) : Drawable(), Animatable, Ti
|
||||
}
|
||||
|
||||
override fun setAlpha(alpha: Int) {
|
||||
// this.alpha = alpha FIXME coil's crossfade
|
||||
currentAlpha = alpha
|
||||
updateColor()
|
||||
}
|
||||
|
||||
@Suppress("DeprecatedCallableAddReplaceWith")
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun getOpacity(): Int = PixelFormat.TRANSLUCENT
|
||||
|
||||
override fun getAlpha(): Int = 255
|
||||
override fun getAlpha(): Int = currentAlpha
|
||||
|
||||
override fun setColorFilter(colorFilter: ColorFilter?) = Unit
|
||||
|
||||
@@ -72,7 +75,10 @@ class AnimatedPlaceholderDrawable(context: Context) : Drawable(), Animatable, Ti
|
||||
}
|
||||
val ph = period / 2
|
||||
val fraction = abs((System.currentTimeMillis() % period) - ph) / ph.toFloat()
|
||||
currentColor = ArgbEvaluatorCompat.getInstance()
|
||||
.evaluate(interpolator.getInterpolation(fraction), colorLow, colorHigh)
|
||||
currentColor = ColorUtils.setAlphaComponent(
|
||||
ArgbEvaluatorCompat.getInstance()
|
||||
.evaluate(interpolator.getInterpolation(fraction), colorLow, colorHigh),
|
||||
currentAlpha
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ open class FaviconDrawable(
|
||||
paint.isFakeBoldText = true
|
||||
colorForeground = KotatsuColors.random(name)
|
||||
currentForegroundColor = MaterialColors.harmonize(colorForeground, colorBackground.defaultColor)
|
||||
onStateChange(state)
|
||||
}
|
||||
|
||||
override fun draw(canvas: Canvas) {
|
||||
|
||||
@@ -34,6 +34,7 @@ class TextDrawable(
|
||||
}
|
||||
|
||||
init {
|
||||
onStateChange(state)
|
||||
measureTextBounds()
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ class DotsIndicator @JvmOverloads constructor(
|
||||
dotsColor = getColorStateList(R.styleable.DotsIndicator_dotColor)
|
||||
?: context.getThemeColorStateList(materialR.attr.colorOnBackground)
|
||||
?: dotsColor
|
||||
paint.color = dotsColor.defaultColor
|
||||
paint.color = dotsColor.getColorForState(drawableState, dotsColor.defaultColor)
|
||||
indicatorSize = getDimension(R.styleable.DotsIndicator_dotSize, indicatorSize)
|
||||
dotSpacing = getDimension(R.styleable.DotsIndicator_dotSpacing, dotSpacing)
|
||||
smallDotScale = getFloat(R.styleable.DotsIndicator_dotScale, smallDotScale).coerceIn(0f, 1f)
|
||||
|
||||
@@ -76,6 +76,7 @@ class ReadingProgressDrawable(
|
||||
paint.strokeWidth = ta.getDimension(R.styleable.ProgressDrawable_strokeWidth, 1f)
|
||||
ta.recycle()
|
||||
checkDrawable?.setTintList(textColor)
|
||||
onStateChange(state)
|
||||
}
|
||||
|
||||
override fun onBoundsChange(bounds: Rect) {
|
||||
|
||||
Reference in New Issue
Block a user