mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-23 07:39:11 +00:00
prepare for adding AllColors
This commit is contained in:
parent
777737db72
commit
b30ac99b09
1 changed files with 44 additions and 0 deletions
|
@ -33,6 +33,7 @@ import helium314.keyboard.latin.utils.brightenOrDarken
|
|||
import helium314.keyboard.latin.utils.darken
|
||||
import helium314.keyboard.latin.utils.isBrightColor
|
||||
import helium314.keyboard.latin.utils.isDarkColor
|
||||
import java.util.EnumMap
|
||||
|
||||
interface Colors {
|
||||
// these theme parameters should no be in here, but are still used
|
||||
|
@ -537,6 +538,49 @@ class DefaultColors (
|
|||
}
|
||||
}
|
||||
|
||||
// todo: allow users to use this class
|
||||
// the colorMap should be stored in settings
|
||||
// reading should consider that colors might be added and removed, i.e. no "simple" serialization
|
||||
// color settings should add another menu option for "all colors"
|
||||
// just show all ColorTypes with current value read from the map (default to black, same as in get)
|
||||
// no string name, as it is not stable
|
||||
class AllColors(private val colorMap: EnumMap<ColorType, Int>, override val themeStyle: String, override val hasKeyBorders: Boolean) : Colors {
|
||||
private var keyboardBackground: Drawable? = null
|
||||
private val stateListMap = EnumMap<ColorType, ColorStateList>(ColorType::class.java)
|
||||
private var backgroundSetupDone = false
|
||||
override fun get(color: ColorType): Int = colorMap[color] ?: Color.BLACK
|
||||
|
||||
override fun setColor(drawable: Drawable, color: ColorType) {
|
||||
val colorStateList = stateListMap.getOrPut(color) { stateList(brightenOrDarken(get(color), true), get(color)) }
|
||||
DrawableCompat.setTintMode(drawable, PorterDuff.Mode.MULTIPLY)
|
||||
DrawableCompat.setTintList(drawable, colorStateList)
|
||||
}
|
||||
|
||||
override fun setColor(view: ImageView, color: ColorType) {
|
||||
setColor(view.drawable, color)
|
||||
}
|
||||
|
||||
override fun setBackground(view: View, color: ColorType) {
|
||||
if (view.background == null)
|
||||
view.setBackgroundColor(Color.WHITE) // set white to make the color filters work
|
||||
when (color) {
|
||||
ONE_HANDED_MODE_BUTTON -> setColor(view.background, BACKGROUND) // button has no separate background color
|
||||
MAIN_BACKGROUND -> {
|
||||
if (keyboardBackground != null) {
|
||||
if (!backgroundSetupDone) {
|
||||
keyboardBackground = BitmapDrawable(view.context.resources, keyboardBackground!!.toBitmap(view.width, view.height))
|
||||
backgroundSetupDone = true
|
||||
}
|
||||
view.background = keyboardBackground
|
||||
} else {
|
||||
setColor(view.background, color)
|
||||
}
|
||||
}
|
||||
else -> setColor(view.background, color)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun colorFilter(color: Int, mode: BlendModeCompat = BlendModeCompat.MODULATE): ColorFilter {
|
||||
// using !! for the color filter because null is only returned for unsupported blend modes, which are not used
|
||||
return BlendModeColorFilterCompat.createBlendModeColorFilterCompat(color, mode)!!
|
||||
|
|
Loading…
Add table
Reference in a new issue