mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-27 04:07:10 +00:00
allow storing AllColors in prefs (still not used)
This commit is contained in:
parent
aa94c84d52
commit
0f250d72bb
1 changed files with 22 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
|||
package helium314.keyboard.latin.common
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.content.res.ColorStateList
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.TypedArray
|
||||
|
@ -18,6 +19,7 @@ import android.widget.ImageView
|
|||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.edit
|
||||
import androidx.core.graphics.BlendModeColorFilterCompat
|
||||
import androidx.core.graphics.BlendModeCompat
|
||||
import androidx.core.graphics.ColorUtils
|
||||
|
@ -540,7 +542,7 @@ 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
|
||||
// settings read and write untested
|
||||
// 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
|
||||
|
@ -581,6 +583,25 @@ class AllColors(private val colorMap: EnumMap<ColorType, Int>, override val them
|
|||
}
|
||||
}
|
||||
|
||||
fun readAllColorsMap(prefs: SharedPreferences): EnumMap<ColorType, Int> {
|
||||
val s = prefs.getString("all_colors", "") ?: ""
|
||||
val c = EnumMap<ColorType, Int>(ColorType::class.java)
|
||||
s.split(";").forEach {
|
||||
val ct = try {
|
||||
ColorType.valueOf(it.substringBefore(",").uppercase())
|
||||
} catch (_: Exception) { // todo: which one?
|
||||
return@forEach
|
||||
}
|
||||
val i = it.substringAfter(",").toIntOrNull() ?: return@forEach
|
||||
c[ct] = i
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
fun writeAllColorsMap(c: EnumMap<ColorType, Int>, prefs: SharedPreferences) {
|
||||
prefs.edit { putString("all_colors", c.map { "${it.key},${it.value}" }.joinToString(";")) }
|
||||
}
|
||||
|
||||
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
Add a link
Reference in a new issue