|
|
@ -6,7 +6,6 @@ import android.content.res.ColorStateList |
|
|
|
import android.graphics.PorterDuff |
|
|
|
import android.graphics.PorterDuff |
|
|
|
import android.graphics.drawable.Drawable |
|
|
|
import android.graphics.drawable.Drawable |
|
|
|
import android.graphics.drawable.RippleDrawable |
|
|
|
import android.graphics.drawable.RippleDrawable |
|
|
|
import android.os.Build |
|
|
|
|
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
import android.widget.* |
|
|
|
import android.widget.* |
|
|
|
import androidx.annotation.CheckResult |
|
|
|
import androidx.annotation.CheckResult |
|
|
@ -68,10 +67,8 @@ object TintHelper { |
|
|
|
when (view) { |
|
|
|
when (view) { |
|
|
|
is Button -> { |
|
|
|
is Button -> { |
|
|
|
sl = getDisabledColorStateList(color, disabled) |
|
|
|
sl = getDisabledColorStateList(color, disabled) |
|
|
|
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 |
|
|
|
rd.setColor(ColorStateList.valueOf(rippleColor)) |
|
|
|
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( |
|
|
@ -133,8 +130,10 @@ object TintHelper { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun setTintAuto( |
|
|
|
fun setTintAuto( |
|
|
|
view: View, @ColorInt color: Int, |
|
|
|
view: View, |
|
|
|
isBackground: Boolean, isDark: Boolean |
|
|
|
@ColorInt color: Int, |
|
|
|
|
|
|
|
isBackground: Boolean, |
|
|
|
|
|
|
|
isDark: Boolean |
|
|
|
) { |
|
|
|
) { |
|
|
|
var isBg = isBackground |
|
|
|
var isBg = isBackground |
|
|
|
if (!isBg) { |
|
|
|
if (!isBg) { |
|
|
@ -166,9 +165,6 @@ object TintHelper { |
|
|
|
else -> isBg = true |
|
|
|
else -> isBg = true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && |
|
|
|
|
|
|
|
!isBg && view.background is RippleDrawable |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
// Ripples for the above views (e.g. when you tap and hold a switch or checkbox) |
|
|
|
// Ripples for the above views (e.g. when you tap and hold a switch or checkbox) |
|
|
|
val rd = view.background as RippleDrawable |
|
|
|
val rd = view.background as RippleDrawable |
|
|
|
@SuppressLint("PrivateResource") val unchecked = ContextCompat.getColor( |
|
|
|
@SuppressLint("PrivateResource") val unchecked = ContextCompat.getColor( |
|
|
@ -186,7 +182,6 @@ object TintHelper { |
|
|
|
) |
|
|
|
) |
|
|
|
rd.setColor(sl) |
|
|
|
rd.setColor(sl) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (isBg) { |
|
|
|
if (isBg) { |
|
|
|
// Need to tint the isBackground of a view |
|
|
|
// Need to tint the isBackground of a view |
|
|
|
if (view is FloatingActionButton || view is Button) { |
|
|
|
if (view is FloatingActionButton || view is Button) { |
|
|
@ -223,14 +218,7 @@ object TintHelper { |
|
|
|
color |
|
|
|
color |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
|
|
|
|
|
|
|
radioButton.buttonTintList = sl |
|
|
|
radioButton.buttonTintList = sl |
|
|
|
} else { |
|
|
|
|
|
|
|
radioButton.buttonDrawable = createTintedDrawable( |
|
|
|
|
|
|
|
ContextCompat.getDrawable(radioButton.context, R.drawable.abc_btn_radio_material), |
|
|
|
|
|
|
|
sl |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun setTint(seekBar: SeekBar, @ColorInt color: Int, useDarker: Boolean) { |
|
|
|
fun setTint(seekBar: SeekBar, @ColorInt color: Int, useDarker: Boolean) { |
|
|
@ -241,15 +229,8 @@ object TintHelper { |
|
|
|
if (useDarker) R.color.ate_control_disabled_dark else R.color.ate_control_disabled_light |
|
|
|
if (useDarker) R.color.ate_control_disabled_dark else R.color.ate_control_disabled_light |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
|
|
|
|
|
|
|
seekBar.thumbTintList = s1 |
|
|
|
seekBar.thumbTintList = s1 |
|
|
|
seekBar.progressTintList = s1 |
|
|
|
seekBar.progressTintList = s1 |
|
|
|
} else { |
|
|
|
|
|
|
|
val progressDrawable = createTintedDrawable(seekBar.progressDrawable, s1) |
|
|
|
|
|
|
|
seekBar.progressDrawable = progressDrawable |
|
|
|
|
|
|
|
val thumbDrawable = createTintedDrawable(seekBar.thumb, s1) |
|
|
|
|
|
|
|
seekBar.thumb = thumbDrawable |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@JvmOverloads |
|
|
|
@JvmOverloads |
|
|
@ -258,17 +239,10 @@ object TintHelper { |
|
|
|
skipIndeterminate: Boolean = false |
|
|
|
skipIndeterminate: Boolean = false |
|
|
|
) { |
|
|
|
) { |
|
|
|
val sl = ColorStateList.valueOf(color) |
|
|
|
val sl = ColorStateList.valueOf(color) |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
|
|
|
|
|
|
|
progressBar.progressTintList = sl |
|
|
|
progressBar.progressTintList = sl |
|
|
|
progressBar.secondaryProgressTintList = sl |
|
|
|
progressBar.secondaryProgressTintList = sl |
|
|
|
if (!skipIndeterminate) |
|
|
|
if (!skipIndeterminate) |
|
|
|
progressBar.indeterminateTintList = sl |
|
|
|
progressBar.indeterminateTintList = sl |
|
|
|
} else { |
|
|
|
|
|
|
|
if (!skipIndeterminate && progressBar.indeterminateDrawable != null) |
|
|
|
|
|
|
|
progressBar.indeterminateDrawable.setTint(color) |
|
|
|
|
|
|
|
if (progressBar.progressDrawable != null) |
|
|
|
|
|
|
|
progressBar.progressDrawable.setTint(color) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -320,18 +294,7 @@ object TintHelper { |
|
|
|
color |
|
|
|
color |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
|
|
|
|
|
|
|
box.buttonTintList = sl |
|
|
|
box.buttonTintList = sl |
|
|
|
} else { |
|
|
|
|
|
|
|
val drawable = |
|
|
|
|
|
|
|
createTintedDrawable( |
|
|
|
|
|
|
|
ContextCompat.getDrawable( |
|
|
|
|
|
|
|
box.context, |
|
|
|
|
|
|
|
R.drawable.abc_btn_check_material |
|
|
|
|
|
|
|
), sl |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
box.buttonDrawable = drawable |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun setTint(image: ImageView, @ColorInt color: Int) { |
|
|
|
fun setTint(image: ImageView, @ColorInt color: Int) { |
|
|
@ -463,6 +426,7 @@ object TintHelper { |
|
|
|
return drawable1 |
|
|
|
return drawable1 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("DiscouragedPrivateApi", "SoonBlockedPrivateApi") |
|
|
|
fun setCursorTint(editText: EditText, @ColorInt color: Int) { |
|
|
|
fun setCursorTint(editText: EditText, @ColorInt color: Int) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
val fCursorDrawableRes = TextView::class.java.getDeclaredField("mCursorDrawableRes") |
|
|
|
val fCursorDrawableRes = TextView::class.java.getDeclaredField("mCursorDrawableRes") |
|
|
|