Skip to content

Commit

Permalink
set random (but fixed) default colors for "all colors", see #903
Browse files Browse the repository at this point in the history
  • Loading branch information
Helium314 committed Jun 25, 2024
1 parent 3b30864 commit 4aac813
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion app/src/main/java/helium314/keyboard/latin/common/Colors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 var backgroundSetupDone = false
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) {
val colorStateList = stateListMap.getOrPut(color) { stateList(brightenOrDarken(get(color), true), get(color)) }
Expand Down Expand Up @@ -668,3 +668,5 @@ enum class ColorType {
TOOL_BAR_KEY_ENABLED_BACKGROUND,
MAIN_BACKGROUND,
}

fun ColorType.default() = ColorUtils.setAlphaComponent(name.hashCode() and 0xffffff, 255)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package helium314.keyboard.latin.settings

import android.content.res.Configuration
import android.graphics.Color
import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
Expand All @@ -17,12 +16,14 @@ import androidx.core.content.edit
import androidx.core.view.MenuProvider
import androidx.core.view.forEach
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import com.rarepebble.colorpicker.ColorPickerView
import helium314.keyboard.keyboard.KeyboardSwitcher
import helium314.keyboard.latin.R
import helium314.keyboard.latin.RichInputMethodManager
import helium314.keyboard.latin.common.ColorType
import helium314.keyboard.latin.common.default
import helium314.keyboard.latin.common.readAllColorsMap
import helium314.keyboard.latin.common.writeAllColorsMap
import helium314.keyboard.latin.databinding.ColorSettingBinding
Expand Down Expand Up @@ -107,7 +108,6 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings), MenuProvi
reloadKeyboard(false)
}
moreColors = menuItem.itemId
binding.info.isGone = menuItem.itemId != 2
updateColorPrefs()
return true
}
Expand All @@ -128,9 +128,11 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings), MenuProvi
}

private fun showAllColors() {
binding.info.isVisible = true
val colors = readAllColorsMap(prefs, isNight)
ColorType.entries.forEach { type ->
val color = colors[type] ?: Color.GRAY
val color = colors[type] ?: type.default()

val csb = ColorSettingBinding.inflate(layoutInflater, binding.colorSettingsContainer, true)
csb.root.tag = type
csb.colorSwitch.isGone = true
Expand Down Expand Up @@ -174,6 +176,7 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings), MenuProvi
}

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
colorPrefsAndNames.forEachIndexed { index, (colorPref, colorPrefName) ->
val autoColor = prefs.getBoolean(prefPrefix + colorPref + Settings.PREF_AUTO_USER_COLOR_SUFFIX, true)
Expand Down Expand Up @@ -276,7 +279,7 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings), MenuProvi
val colorMap = readAllColorsMap(prefs, isNight)
binding.colorSettingsContainer.forEach { view ->
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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ New dictionary:
<!-- Menu item for showing all colors -->
<string name="all_colors">Show all colors</string>
<!-- 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) -->
<string name="hint_show_keyboard">Click for preview</string>
<!-- Description for selection of user-defined colors. -->
Expand Down

0 comments on commit 4aac813

Please sign in to comment.