|
|
@ -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,48 +65,52 @@ object TintHelper { |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
val sl: ColorStateList |
|
|
|
val sl: ColorStateList |
|
|
|
if (view is Button) { |
|
|
|
when (view) { |
|
|
|
sl = getDisabledColorStateList(color, disabled) |
|
|
|
is Button -> { |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && view.getBackground() is RippleDrawable) { |
|
|
|
sl = getDisabledColorStateList(color, disabled) |
|
|
|
val rd = view.getBackground() as RippleDrawable |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && view.getBackground() is RippleDrawable) { |
|
|
|
rd.setColor(ColorStateList.valueOf(rippleColor)) |
|
|
|
val rd = view.getBackground() as RippleDrawable |
|
|
|
} |
|
|
|
rd.setColor(ColorStateList.valueOf(rippleColor)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Disabled text color state for buttons, may get overridden later by ATE tags |
|
|
|
// Disabled text color state for buttons, may get overridden later by ATE tags |
|
|
|
view.setTextColor( |
|
|
|
view.setTextColor( |
|
|
|
getDisabledColorStateList( |
|
|
|
getDisabledColorStateList( |
|
|
|
textColor, |
|
|
|
textColor, |
|
|
|
ContextCompat.getColor( |
|
|
|
ContextCompat.getColor( |
|
|
|
view.getContext(), |
|
|
|
view.getContext(), |
|
|
|
if (useDarkTheme) R.color.ate_button_text_disabled_dark else R.color.ate_button_text_disabled_light |
|
|
|
if (useDarkTheme) R.color.ate_button_text_disabled_dark else R.color.ate_button_text_disabled_light |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} 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( |
|
|
|
intArrayOf(-android.R.attr.state_pressed), |
|
|
|
intArrayOf(-android.R.attr.state_pressed), |
|
|
|
intArrayOf(android.R.attr.state_pressed) |
|
|
|
intArrayOf(android.R.attr.state_pressed) |
|
|
|
), intArrayOf(color, pressed) |
|
|
|
), intArrayOf(color, pressed) |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
view.rippleColor = rippleColor |
|
|
|
view.rippleColor = rippleColor |
|
|
|
view.backgroundTintList = sl |
|
|
|
view.backgroundTintList = sl |
|
|
|
if (view.drawable != null) |
|
|
|
if (view.drawable != null) |
|
|
|
view.setImageDrawable(createTintedDrawable(view.drawable, textColor)) |
|
|
|
view.setImageDrawable(createTintedDrawable(view.drawable, textColor)) |
|
|
|
return |
|
|
|
return |
|
|
|
} else { |
|
|
|
} |
|
|
|
sl = ColorStateList( |
|
|
|
else -> { |
|
|
|
arrayOf( |
|
|
|
sl = ColorStateList( |
|
|
|
intArrayOf(-android.R.attr.state_enabled), |
|
|
|
arrayOf( |
|
|
|
intArrayOf(android.R.attr.state_enabled), |
|
|
|
intArrayOf(-android.R.attr.state_enabled), |
|
|
|
intArrayOf(android.R.attr.state_enabled, android.R.attr.state_pressed), |
|
|
|
intArrayOf(android.R.attr.state_enabled), |
|
|
|
intArrayOf(android.R.attr.state_enabled, android.R.attr.state_activated), |
|
|
|
intArrayOf(android.R.attr.state_enabled, android.R.attr.state_pressed), |
|
|
|
intArrayOf(android.R.attr.state_enabled, android.R.attr.state_checked) |
|
|
|
intArrayOf(android.R.attr.state_enabled, android.R.attr.state_activated), |
|
|
|
), |
|
|
|
intArrayOf(android.R.attr.state_enabled, android.R.attr.state_checked) |
|
|
|
intArrayOf(disabled, color, pressed, activated, activated) |
|
|
|
), |
|
|
|
) |
|
|
|
intArrayOf(disabled, color, pressed, activated, activated) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var drawable: Drawable? = view.background |
|
|
|
var drawable: Drawable? = view.background |
|
|
@ -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, |
|
|
|