|
|
@ -23,6 +23,7 @@ import io.legado.app.utils.ColorUtils |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author afollestad, plusCubed |
|
|
|
* @author afollestad, plusCubed |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Suppress("MemberVisibilityCanBePrivate") |
|
|
|
object TintHelper { |
|
|
|
object TintHelper { |
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("PrivateResource") |
|
|
|
@SuppressLint("PrivateResource") |
|
|
@ -37,7 +38,10 @@ object TintHelper { |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun getDisabledColorStateList(@ColorInt normal: Int, @ColorInt disabled: Int): ColorStateList { |
|
|
|
private fun getDisabledColorStateList( |
|
|
|
|
|
|
|
@ColorInt normal: Int, |
|
|
|
|
|
|
|
@ColorInt disabled: Int |
|
|
|
|
|
|
|
): ColorStateList { |
|
|
|
return ColorStateList( |
|
|
|
return ColorStateList( |
|
|
|
arrayOf( |
|
|
|
arrayOf( |
|
|
|
intArrayOf(-android.R.attr.state_enabled), |
|
|
|
intArrayOf(-android.R.attr.state_enabled), |
|
|
@ -61,7 +65,8 @@ object TintHelper { |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
val sl: ColorStateList |
|
|
|
val sl: ColorStateList |
|
|
|
if (view is Button) { |
|
|
|
when (view) { |
|
|
|
|
|
|
|
is Button -> { |
|
|
|
sl = getDisabledColorStateList(color, disabled) |
|
|
|
sl = getDisabledColorStateList(color, disabled) |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && view.getBackground() is RippleDrawable) { |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && view.getBackground() is RippleDrawable) { |
|
|
|
val rd = view.getBackground() as RippleDrawable |
|
|
|
val rd = view.getBackground() as RippleDrawable |
|
|
@ -78,7 +83,8 @@ object TintHelper { |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
} else if (view is FloatingActionButton) { |
|
|
|
} |
|
|
|
|
|
|
|
is FloatingActionButton -> { |
|
|
|
// FloatingActionButton doesn't support disabled state? |
|
|
|
// FloatingActionButton doesn't support disabled state? |
|
|
|
sl = ColorStateList( |
|
|
|
sl = ColorStateList( |
|
|
|
arrayOf( |
|
|
|
arrayOf( |
|
|
@ -92,7 +98,8 @@ object TintHelper { |
|
|
|
if (view.drawable != null) |
|
|
|
if (view.drawable != null) |
|
|
|
view.setImageDrawable(createTintedDrawable(view.drawable, textColor)) |
|
|
|
view.setImageDrawable(createTintedDrawable(view.drawable, textColor)) |
|
|
|
return |
|
|
|
return |
|
|
|
} else { |
|
|
|
} |
|
|
|
|
|
|
|
else -> { |
|
|
|
sl = ColorStateList( |
|
|
|
sl = ColorStateList( |
|
|
|
arrayOf( |
|
|
|
arrayOf( |
|
|
|
intArrayOf(-android.R.attr.state_enabled), |
|
|
|
intArrayOf(-android.R.attr.state_enabled), |
|
|
@ -104,6 +111,7 @@ object TintHelper { |
|
|
|
intArrayOf(disabled, color, pressed, activated, activated) |
|
|
|
intArrayOf(disabled, color, pressed, activated, activated) |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var drawable: Drawable? = view.background |
|
|
|
var drawable: Drawable? = view.background |
|
|
|
if (drawable != null) { |
|
|
|
if (drawable != null) { |
|
|
@ -386,7 +394,11 @@ object TintHelper { |
|
|
|
return createTintedDrawable(from, sl) |
|
|
|
return createTintedDrawable(from, sl) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun setTint(switchView: Switch, @ColorInt color: Int, useDarker: Boolean) { |
|
|
|
fun setTint( |
|
|
|
|
|
|
|
@SuppressLint("UseSwitchCompatOrMaterialCode") switchView: Switch, |
|
|
|
|
|
|
|
@ColorInt color: Int, |
|
|
|
|
|
|
|
useDarker: Boolean |
|
|
|
|
|
|
|
) { |
|
|
|
if (switchView.trackDrawable != null) { |
|
|
|
if (switchView.trackDrawable != null) { |
|
|
|
switchView.trackDrawable = modifySwitchDrawable( |
|
|
|
switchView.trackDrawable = modifySwitchDrawable( |
|
|
|
switchView.context, |
|
|
|
switchView.context, |
|
|
|