mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-15 06:22:45 +00:00
set random (but fixed) default colors for "all colors", see #903
This commit is contained in:
parent
3b30864b00
commit
4aac81391e
3 changed files with 11 additions and 6 deletions
|
@ -552,7 +552,7 @@ class AllColors(private val colorMap: EnumMap<ColorType, Int>, override val them
|
||||||
private val stateListMap = EnumMap<ColorType, ColorStateList>(ColorType::class.java)
|
private val stateListMap = EnumMap<ColorType, ColorStateList>(ColorType::class.java)
|
||||||
private var backgroundSetupDone = false
|
private var backgroundSetupDone = false
|
||||||
private val colorFilters = hashMapOf<ColorType, ColorFilter>()
|
private val colorFilters = hashMapOf<ColorType, ColorFilter>()
|
||||||
override fun get(color: ColorType): Int = colorMap[color] ?: Color.GRAY
|
override fun get(color: ColorType): Int = colorMap[color] ?: color.default()
|
||||||
|
|
||||||
override fun setColor(drawable: Drawable, color: ColorType) {
|
override fun setColor(drawable: Drawable, color: ColorType) {
|
||||||
val colorStateList = stateListMap.getOrPut(color) { stateList(brightenOrDarken(get(color), true), get(color)) }
|
val colorStateList = stateListMap.getOrPut(color) { stateList(brightenOrDarken(get(color), true), get(color)) }
|
||||||
|
@ -668,3 +668,5 @@ enum class ColorType {
|
||||||
TOOL_BAR_KEY_ENABLED_BACKGROUND,
|
TOOL_BAR_KEY_ENABLED_BACKGROUND,
|
||||||
MAIN_BACKGROUND,
|
MAIN_BACKGROUND,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun ColorType.default() = ColorUtils.setAlphaComponent(name.hashCode() and 0xffffff, 255)
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
package helium314.keyboard.latin.settings
|
package helium314.keyboard.latin.settings
|
||||||
|
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.graphics.Color
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuInflater
|
import android.view.MenuInflater
|
||||||
|
@ -17,12 +16,14 @@ import androidx.core.content.edit
|
||||||
import androidx.core.view.MenuProvider
|
import androidx.core.view.MenuProvider
|
||||||
import androidx.core.view.forEach
|
import androidx.core.view.forEach
|
||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
|
import androidx.core.view.isVisible
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import com.rarepebble.colorpicker.ColorPickerView
|
import com.rarepebble.colorpicker.ColorPickerView
|
||||||
import helium314.keyboard.keyboard.KeyboardSwitcher
|
import helium314.keyboard.keyboard.KeyboardSwitcher
|
||||||
import helium314.keyboard.latin.R
|
import helium314.keyboard.latin.R
|
||||||
import helium314.keyboard.latin.RichInputMethodManager
|
import helium314.keyboard.latin.RichInputMethodManager
|
||||||
import helium314.keyboard.latin.common.ColorType
|
import helium314.keyboard.latin.common.ColorType
|
||||||
|
import helium314.keyboard.latin.common.default
|
||||||
import helium314.keyboard.latin.common.readAllColorsMap
|
import helium314.keyboard.latin.common.readAllColorsMap
|
||||||
import helium314.keyboard.latin.common.writeAllColorsMap
|
import helium314.keyboard.latin.common.writeAllColorsMap
|
||||||
import helium314.keyboard.latin.databinding.ColorSettingBinding
|
import helium314.keyboard.latin.databinding.ColorSettingBinding
|
||||||
|
@ -107,7 +108,6 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings), MenuProvi
|
||||||
reloadKeyboard(false)
|
reloadKeyboard(false)
|
||||||
}
|
}
|
||||||
moreColors = menuItem.itemId
|
moreColors = menuItem.itemId
|
||||||
binding.info.isGone = menuItem.itemId != 2
|
|
||||||
updateColorPrefs()
|
updateColorPrefs()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -128,9 +128,11 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings), MenuProvi
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showAllColors() {
|
private fun showAllColors() {
|
||||||
|
binding.info.isVisible = true
|
||||||
val colors = readAllColorsMap(prefs, isNight)
|
val colors = readAllColorsMap(prefs, isNight)
|
||||||
ColorType.entries.forEach { type ->
|
ColorType.entries.forEach { type ->
|
||||||
val color = colors[type] ?: Color.GRAY
|
val color = colors[type] ?: type.default()
|
||||||
|
|
||||||
val csb = ColorSettingBinding.inflate(layoutInflater, binding.colorSettingsContainer, true)
|
val csb = ColorSettingBinding.inflate(layoutInflater, binding.colorSettingsContainer, true)
|
||||||
csb.root.tag = type
|
csb.root.tag = type
|
||||||
csb.colorSwitch.isGone = true
|
csb.colorSwitch.isGone = true
|
||||||
|
@ -174,6 +176,7 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings), MenuProvi
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showMainColors() {
|
private fun showMainColors() {
|
||||||
|
binding.info.isGone = true
|
||||||
val prefPrefix = if (isNight) Settings.PREF_THEME_USER_COLOR_NIGHT_PREFIX else Settings.PREF_THEME_USER_COLOR_PREFIX
|
val prefPrefix = if (isNight) Settings.PREF_THEME_USER_COLOR_NIGHT_PREFIX else Settings.PREF_THEME_USER_COLOR_PREFIX
|
||||||
colorPrefsAndNames.forEachIndexed { index, (colorPref, colorPrefName) ->
|
colorPrefsAndNames.forEachIndexed { index, (colorPref, colorPrefName) ->
|
||||||
val autoColor = prefs.getBoolean(prefPrefix + colorPref + Settings.PREF_AUTO_USER_COLOR_SUFFIX, true)
|
val autoColor = prefs.getBoolean(prefPrefix + colorPref + Settings.PREF_AUTO_USER_COLOR_SUFFIX, true)
|
||||||
|
@ -276,7 +279,7 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings), MenuProvi
|
||||||
val colorMap = readAllColorsMap(prefs, isNight)
|
val colorMap = readAllColorsMap(prefs, isNight)
|
||||||
binding.colorSettingsContainer.forEach { view ->
|
binding.colorSettingsContainer.forEach { view ->
|
||||||
val type = view.tag as? ColorType ?: return@forEach
|
val type = view.tag as? ColorType ?: return@forEach
|
||||||
val color = colorMap[type] ?: Color.GRAY
|
val color = colorMap[type] ?: type.default()
|
||||||
view.findViewById<ImageView>(R.id.color_preview)?.setColorFilter(color)
|
view.findViewById<ImageView>(R.id.color_preview)?.setColorFilter(color)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -714,7 +714,7 @@ New dictionary:
|
||||||
<!-- Menu item for showing all colors -->
|
<!-- Menu item for showing all colors -->
|
||||||
<string name="all_colors">Show all colors</string>
|
<string name="all_colors">Show all colors</string>
|
||||||
<!-- Warning message displayed when showing all colors -->
|
<!-- Warning message displayed when showing all colors -->
|
||||||
<string name="all_colors_warning">This setting exposes all colors that are used internally. The list of colors may change at any time. There is no default color, and the names will not be translated.</string>
|
<string name="all_colors_warning">This setting exposes all colors that are used internally. The list of colors may change at any time. The default color is random, and the names will not be translated.</string>
|
||||||
<!-- Hint for text field just to show keyboard (in color settings) -->
|
<!-- Hint for text field just to show keyboard (in color settings) -->
|
||||||
<string name="hint_show_keyboard">Click for preview</string>
|
<string name="hint_show_keyboard">Click for preview</string>
|
||||||
<!-- Description for selection of user-defined colors. -->
|
<!-- Description for selection of user-defined colors. -->
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue