Fix Android 5 progress drawable color
This commit is contained in:
parent
b66184787d
commit
29e9008980
2 changed files with 89 additions and 81 deletions
|
@ -14,30 +14,22 @@
|
||||||
|
|
||||||
package code.name.monkey.retromusic.util
|
package code.name.monkey.retromusic.util
|
||||||
|
|
||||||
import android.animation.Animator
|
import android.animation.*
|
||||||
import android.animation.ArgbEvaluator
|
|
||||||
import android.animation.ObjectAnimator
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.res.ColorStateList
|
import android.content.res.*
|
||||||
import android.content.res.Resources
|
import android.graphics.*
|
||||||
import android.graphics.Color
|
|
||||||
import android.graphics.PorterDuff
|
|
||||||
import android.graphics.drawable.LayerDrawable
|
import android.graphics.drawable.LayerDrawable
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.animation.PathInterpolator
|
import android.view.animation.PathInterpolator
|
||||||
import android.widget.ProgressBar
|
import android.widget.*
|
||||||
import android.widget.SeekBar
|
|
||||||
import androidx.annotation.ColorInt
|
import androidx.annotation.ColorInt
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import code.name.monkey.appthemehelper.ThemeStore
|
import code.name.monkey.appthemehelper.ThemeStore
|
||||||
import code.name.monkey.appthemehelper.util.ATHUtil
|
import code.name.monkey.appthemehelper.util.*
|
||||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
|
||||||
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
|
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
|
||||||
|
|
||||||
|
|
||||||
object ViewUtil {
|
object ViewUtil {
|
||||||
|
|
||||||
const val RETRO_MUSIC_ANIM_TIME = 1000
|
const val RETRO_MUSIC_ANIM_TIME = 1000
|
||||||
|
@ -47,8 +39,14 @@ object ViewUtil {
|
||||||
if (thumbTint) {
|
if (thumbTint) {
|
||||||
progressSlider.thumbTintList = ColorStateList.valueOf(newColor)
|
progressSlider.thumbTintList = ColorStateList.valueOf(newColor)
|
||||||
}
|
}
|
||||||
|
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||||
|
val layerDrawable = progressSlider.progressDrawable as LayerDrawable
|
||||||
|
val progressDrawable = layerDrawable.findDrawableByLayerId(android.R.id.progress)
|
||||||
|
progressDrawable.setColorFilter(newColor, PorterDuff.Mode.SRC_IN)
|
||||||
|
} else {
|
||||||
progressSlider.progressTintList = ColorStateList.valueOf(newColor)
|
progressSlider.progressTintList = ColorStateList.valueOf(newColor)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun setProgressDrawable(progressSlider: ProgressBar, newColor: Int) {
|
fun setProgressDrawable(progressSlider: ProgressBar, newColor: Int) {
|
||||||
|
|
||||||
|
@ -59,13 +57,23 @@ object ViewUtil {
|
||||||
|
|
||||||
val background = ld.findDrawableByLayerId(android.R.id.background)
|
val background = ld.findDrawableByLayerId(android.R.id.background)
|
||||||
val primaryColor = ATHUtil.resolveColor(progressSlider.context, R.attr.colorPrimary)
|
val primaryColor = ATHUtil.resolveColor(progressSlider.context, R.attr.colorPrimary)
|
||||||
background.setColorFilter(MaterialValueHelper.getPrimaryDisabledTextColor(progressSlider.context, ColorUtil.isColorLight(primaryColor)), PorterDuff.Mode.SRC_IN)
|
background.setColorFilter(
|
||||||
|
MaterialValueHelper.getPrimaryDisabledTextColor(
|
||||||
|
progressSlider.context, ColorUtil.isColorLight(
|
||||||
|
primaryColor
|
||||||
|
)
|
||||||
|
), PorterDuff.Mode.SRC_IN
|
||||||
|
)
|
||||||
|
|
||||||
val secondaryProgress = ld.findDrawableByLayerId(android.R.id.secondaryProgress)
|
val secondaryProgress = ld.findDrawableByLayerId(android.R.id.secondaryProgress)
|
||||||
secondaryProgress?.setColorFilter(ColorUtil.withAlpha(newColor, 0.65f), PorterDuff.Mode.SRC_IN)
|
secondaryProgress?.setColorFilter(
|
||||||
|
ColorUtil.withAlpha(newColor, 0.65f), PorterDuff.Mode.SRC_IN
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createColorAnimator(target: Any, propertyName: String, @ColorInt startColor: Int, @ColorInt endColor: Int): Animator {
|
private fun createColorAnimator(
|
||||||
|
target: Any, propertyName: String, @ColorInt startColor: Int, @ColorInt endColor: Int
|
||||||
|
): Animator {
|
||||||
val animator: ObjectAnimator
|
val animator: ObjectAnimator
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
animator = ObjectAnimator.ofArgb(target, propertyName, startColor, endColor)
|
animator = ObjectAnimator.ofArgb(target, propertyName, startColor, endColor)
|
||||||
|
@ -92,13 +100,28 @@ object ViewUtil {
|
||||||
return x in left..right && y >= top && y <= bottom
|
return x in left..right && y >= top && y <= bottom
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setUpFastScrollRecyclerViewColor(context: Context,
|
fun setUpFastScrollRecyclerViewColor(
|
||||||
recyclerView: FastScrollRecyclerView, accentColor: Int = ThemeStore.accentColor(context)) {
|
context: Context,
|
||||||
|
recyclerView: FastScrollRecyclerView,
|
||||||
|
accentColor: Int = ThemeStore.accentColor(context)
|
||||||
|
) {
|
||||||
recyclerView.setPopupBgColor(accentColor)
|
recyclerView.setPopupBgColor(accentColor)
|
||||||
recyclerView.setPopupTextColor(MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(accentColor)))
|
recyclerView.setPopupTextColor(
|
||||||
|
MaterialValueHelper.getPrimaryTextColor(
|
||||||
|
context, ColorUtil.isColorLight(
|
||||||
|
accentColor
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
recyclerView.setThumbColor(accentColor)
|
recyclerView.setThumbColor(accentColor)
|
||||||
recyclerView.setTrackColor(Color.TRANSPARENT)
|
recyclerView.setTrackColor(Color.TRANSPARENT)
|
||||||
recyclerView.setTrackColor(ColorUtil.withAlpha(ATHUtil.resolveColor(context, R.attr.colorControlNormal), 0.12f))
|
recyclerView.setTrackColor(
|
||||||
|
ColorUtil.withAlpha(
|
||||||
|
ATHUtil.resolveColor(
|
||||||
|
context, R.attr.colorControlNormal
|
||||||
|
), 0.12f
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,19 +40,4 @@
|
||||||
</clip>
|
</clip>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
</layer-list><!--<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
</layer-list>
|
||||||
<item android:id="@android:id/background">
|
|
||||||
<shape>
|
|
||||||
<corners android:radius="8dp" />
|
|
||||||
<solid android:color="?android:colorButtonNormal" />
|
|
||||||
</shape>
|
|
||||||
</item>
|
|
||||||
<item android:id="@android:id/progress">
|
|
||||||
<clip>
|
|
||||||
<shape>
|
|
||||||
<corners android:radius="8dp" />
|
|
||||||
<solid android:color="@color/md_black_1000" />
|
|
||||||
</shape>
|
|
||||||
</clip>
|
|
||||||
</item>
|
|
||||||
</layer-list>-->
|
|
Loading…
Reference in a new issue