put setting defaults in one place

notable exceptions: color settings
they will be re-done anyway...
This commit is contained in:
Helium314 2025-02-09 19:01:57 +01:00
parent ecf7aabdb1
commit d807e08195
39 changed files with 473 additions and 481 deletions

View file

@ -20,6 +20,7 @@ Some hints for finding what you're looking for:
* Suggestions: `DictionaryFacilitatorImpl`, `Suggest`, `InputLogic`, and `SuggestionStripView` (in order from creation to display) * Suggestions: `DictionaryFacilitatorImpl`, `Suggest`, `InputLogic`, and `SuggestionStripView` (in order from creation to display)
* Forwarding entered text / keys to the app / text field: `RichInputConnection` * Forwarding entered text / keys to the app / text field: `RichInputConnection`
* Receiving events and information from the app / text field: `LatinIME` * Receiving events and information from the app / text field: `LatinIME`
* Settings are in `SettingsValues`, with some functionality in `Settings` and the default values in `Default`
# Guidelines # Guidelines

View file

@ -17,6 +17,7 @@ import helium314.keyboard.latin.common.Colors
import helium314.keyboard.latin.common.DefaultColors import helium314.keyboard.latin.common.DefaultColors
import helium314.keyboard.latin.common.DynamicColors import helium314.keyboard.latin.common.DynamicColors
import helium314.keyboard.latin.common.readAllColorsMap import helium314.keyboard.latin.common.readAllColorsMap
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.prefs import helium314.keyboard.latin.utils.prefs
@ -85,8 +86,8 @@ private constructor(val themeId: Int, @JvmField val mStyleId: Int) {
@JvmStatic @JvmStatic
fun getKeyboardTheme(context: Context): KeyboardTheme { fun getKeyboardTheme(context: Context): KeyboardTheme {
val prefs = context.prefs() val prefs = context.prefs()
val style = prefs.getString(Settings.PREF_THEME_STYLE, STYLE_MATERIAL) val style = prefs.getString(Settings.PREF_THEME_STYLE, Defaults.PREF_THEME_STYLE)
val borders = prefs.getBoolean(Settings.PREF_THEME_KEY_BORDERS, false) val borders = prefs.getBoolean(Settings.PREF_THEME_KEY_BORDERS, Defaults.PREF_THEME_KEY_BORDERS)
val matchingId = when (style) { val matchingId = when (style) {
STYLE_HOLO -> THEME_ID_HOLO_BASE STYLE_HOLO -> THEME_ID_HOLO_BASE
STYLE_ROUNDED -> if (borders) THEME_ID_ROUNDED_BASE_BORDER else THEME_ID_ROUNDED_BASE STYLE_ROUNDED -> if (borders) THEME_ID_ROUNDED_BASE_BORDER else THEME_ID_ROUNDED_BASE
@ -101,7 +102,7 @@ private constructor(val themeId: Int, @JvmField val mStyleId: Int) {
@JvmStatic @JvmStatic
fun getThemeColors(themeColors: String, themeStyle: String, context: Context, prefs: SharedPreferences, isNight: Boolean): Colors { fun getThemeColors(themeColors: String, themeStyle: String, context: Context, prefs: SharedPreferences, isNight: Boolean): Colors {
val hasBorders = prefs.getBoolean(Settings.PREF_THEME_KEY_BORDERS, false) val hasBorders = prefs.getBoolean(Settings.PREF_THEME_KEY_BORDERS, Defaults.PREF_THEME_KEY_BORDERS)
val backgroundImage = Settings.readUserBackgroundImage(context, isNight) val backgroundImage = Settings.readUserBackgroundImage(context, isNight)
return when (themeColors) { return when (themeColors) {
THEME_USER -> if (prefs.getInt(Settings.getColorPref(Settings.PREF_SHOW_MORE_COLORS, isNight), 0) == 2) THEME_USER -> if (prefs.getInt(Settings.getColorPref(Settings.PREF_SHOW_MORE_COLORS, isNight), 0) == 2)

View file

@ -52,6 +52,7 @@ import helium314.keyboard.latin.common.Constants;
import helium314.keyboard.latin.common.CoordinateUtils; import helium314.keyboard.latin.common.CoordinateUtils;
import helium314.keyboard.latin.define.DebugFlags; import helium314.keyboard.latin.define.DebugFlags;
import helium314.keyboard.latin.settings.DebugSettings; import helium314.keyboard.latin.settings.DebugSettings;
import helium314.keyboard.latin.settings.Defaults;
import helium314.keyboard.latin.settings.Settings; import helium314.keyboard.latin.settings.Settings;
import helium314.keyboard.latin.utils.KtxKt; import helium314.keyboard.latin.utils.KtxKt;
import helium314.keyboard.latin.utils.LanguageOnSpacebarUtils; import helium314.keyboard.latin.utils.LanguageOnSpacebarUtils;
@ -153,7 +154,7 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
final SharedPreferences prefs = KtxKt.prefs(context); final SharedPreferences prefs = KtxKt.prefs(context);
final boolean forceNonDistinctMultitouch = prefs.getBoolean( final boolean forceNonDistinctMultitouch = prefs.getBoolean(
DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH, false); DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH, Defaults.PREF_FORCE_NON_DISTINCT_MULTITOUCH);
final boolean hasDistinctMultitouch = context.getPackageManager() final boolean hasDistinctMultitouch = context.getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT) .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT)
&& !forceNonDistinctMultitouch; && !forceNonDistinctMultitouch;

View file

@ -10,6 +10,8 @@ import static helium314.keyboard.keyboard.internal.keyboard_parser.EmojiParserKt
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.text.TextUtils; import android.text.TextUtils;
import helium314.keyboard.latin.settings.Defaults;
import helium314.keyboard.latin.utils.Log; import helium314.keyboard.latin.utils.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -197,7 +199,7 @@ final class DynamicGridKeyboard extends Keyboard {
} }
} }
final String jsonStr = JsonUtils.listToJsonStr(keys); final String jsonStr = JsonUtils.listToJsonStr(keys);
Settings.writeEmojiRecentKeys(mPrefs, jsonStr); mPrefs.edit().putString(Settings.PREF_EMOJI_RECENT_KEYS, jsonStr).apply();
} }
private Key getKeyByCode(final Collection<DynamicGridKeyboard> keyboards, private Key getKeyByCode(final Collection<DynamicGridKeyboard> keyboards,
@ -229,7 +231,7 @@ final class DynamicGridKeyboard extends Keyboard {
} }
public void loadRecentKeys(final Collection<DynamicGridKeyboard> keyboards) { public void loadRecentKeys(final Collection<DynamicGridKeyboard> keyboards) {
final String str = Settings.readEmojiRecentKeys(mPrefs); final String str = mPrefs.getString(Settings.PREF_EMOJI_RECENT_KEYS, Defaults.PREF_EMOJI_RECENT_KEYS);
final List<Object> keys = JsonUtils.jsonStrToList(str); final List<Object> keys = JsonUtils.jsonStrToList(str);
for (final Object o : keys) { for (final Object o : keys) {
final Key key; final Key key;

View file

@ -13,6 +13,8 @@ import android.content.res.TypedArray;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Rect; import android.graphics.Rect;
import helium314.keyboard.latin.common.DefaultColors;
import helium314.keyboard.latin.settings.Defaults;
import helium314.keyboard.latin.utils.KtxKt; import helium314.keyboard.latin.utils.KtxKt;
import helium314.keyboard.latin.utils.Log; import helium314.keyboard.latin.utils.Log;
@ -157,8 +159,8 @@ final class EmojiCategory {
addShownCategoryId(EmojiCategory.ID_EMOTICONS); addShownCategoryId(EmojiCategory.ID_EMOTICONS);
DynamicGridKeyboard recentsKbd = getKeyboard(EmojiCategory.ID_RECENTS, 0); DynamicGridKeyboard recentsKbd = getKeyboard(EmojiCategory.ID_RECENTS, 0);
mCurrentCategoryId = Settings.readLastShownEmojiCategoryId(mPrefs, defaultCategoryId); mCurrentCategoryId = mPrefs.getInt(Settings.PREF_LAST_SHOWN_EMOJI_CATEGORY_ID, defaultCategoryId);
mCurrentCategoryPageId = Settings.readLastShownEmojiCategoryPageId(mPrefs, 0); mCurrentCategoryPageId = mPrefs.getInt(Settings.PREF_LAST_SHOWN_EMOJI_CATEGORY_PAGE_ID, Defaults.PREF_LAST_SHOWN_EMOJI_CATEGORY_PAGE_ID);
if (!isShownCategoryId(mCurrentCategoryId)) { if (!isShownCategoryId(mCurrentCategoryId)) {
mCurrentCategoryId = defaultCategoryId; mCurrentCategoryId = defaultCategoryId;
} else if (mCurrentCategoryId == EmojiCategory.ID_RECENTS && } else if (mCurrentCategoryId == EmojiCategory.ID_RECENTS &&
@ -234,12 +236,12 @@ final class EmojiCategory {
public void setCurrentCategoryId(final int categoryId) { public void setCurrentCategoryId(final int categoryId) {
mCurrentCategoryId = categoryId; mCurrentCategoryId = categoryId;
Settings.writeLastShownEmojiCategoryId(mPrefs, categoryId); mPrefs.edit().putInt(Settings.PREF_LAST_SHOWN_EMOJI_CATEGORY_ID, categoryId).apply();
} }
public void setCurrentCategoryPageId(final int id) { public void setCurrentCategoryPageId(final int id) {
mCurrentCategoryPageId = id; mCurrentCategoryPageId = id;
Settings.writeLastShownEmojiCategoryPageId(mPrefs, id); mPrefs.edit().putInt(Settings.PREF_LAST_SHOWN_EMOJI_CATEGORY_PAGE_ID, id).apply();
} }
public int getCurrentCategoryPageId() { public int getCurrentCategoryPageId() {

View file

@ -7,6 +7,7 @@ import androidx.core.content.ContextCompat
import helium314.keyboard.keyboard.KeyboardTheme import helium314.keyboard.keyboard.KeyboardTheme
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.customIconIds import helium314.keyboard.latin.customIconIds
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.Log import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.ToolbarKey import helium314.keyboard.latin.utils.ToolbarKey
@ -20,7 +21,7 @@ class KeyboardIconsSet private constructor() {
fun loadIcons(context: Context) { fun loadIcons(context: Context) {
val prefs = context.prefs() val prefs = context.prefs()
val iconStyle = prefs.getString(Settings.PREF_ICON_STYLE, KeyboardTheme.STYLE_MATERIAL) val iconStyle = prefs.getString(Settings.PREF_ICON_STYLE, Defaults.PREF_ICON_STYLE)
val defaultIds = when (iconStyle) { val defaultIds = when (iconStyle) {
KeyboardTheme.STYLE_HOLO -> keyboardIconsHolo KeyboardTheme.STYLE_HOLO -> keyboardIconsHolo
KeyboardTheme.STYLE_ROUNDED -> keyboardIconsRounded KeyboardTheme.STYLE_ROUNDED -> keyboardIconsRounded
@ -281,7 +282,7 @@ class KeyboardIconsSet private constructor() {
fun getAllIcons(context: Context): Map<String, List<Int>> { fun getAllIcons(context: Context): Map<String, List<Int>> {
// currently active style first // currently active style first
val iconStyle = context.prefs().getString(Settings.PREF_ICON_STYLE, KeyboardTheme.STYLE_MATERIAL) val iconStyle = context.prefs().getString(Settings.PREF_ICON_STYLE, Defaults.PREF_ICON_STYLE)
return keyboardIconsMaterial.entries.associate { (name, id) -> return keyboardIconsMaterial.entries.associate { (name, id) ->
name to when (iconStyle) { name to when (iconStyle) {
KeyboardTheme.STYLE_HOLO -> listOfNotNull(keyboardIconsHolo[name], keyboardIconsRounded[name], id) KeyboardTheme.STYLE_HOLO -> listOfNotNull(keyboardIconsHolo[name], keyboardIconsRounded[name], id)

View file

@ -4,8 +4,8 @@ package helium314.keyboard.latin
import android.app.Application import android.app.Application
import android.content.Context import android.content.Context
import androidx.core.content.edit import androidx.core.content.edit
import androidx.preference.PreferenceManager
import helium314.keyboard.latin.common.LocaleUtils.constructLocale import helium314.keyboard.latin.common.LocaleUtils.constructLocale
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.settings.USER_DICTIONARY_SUFFIX import helium314.keyboard.latin.settings.USER_DICTIONARY_SUFFIX
import helium314.keyboard.latin.utils.CUSTOM_LAYOUT_PREFIX import helium314.keyboard.latin.utils.CUSTOM_LAYOUT_PREFIX
@ -25,6 +25,7 @@ class App : Application() {
super.onCreate() super.onCreate()
checkVersionUpgrade(this) checkVersionUpgrade(this)
app = this app = this
Defaults.initDynamicDefaults(this)
} }
companion object { companion object {
@ -107,7 +108,7 @@ fun checkVersionUpgrade(context: Context) {
} }
} }
if (oldVersion <= 2201) { if (oldVersion <= 2201) {
val additionalSubtypeString = Settings.readPrefAdditionalSubtypes(prefs, context.resources) val additionalSubtypeString = prefs.getString(Settings.PREF_ADDITIONAL_SUBTYPES, Defaults.PREF_ADDITIONAL_SUBTYPES)!!
if (additionalSubtypeString.contains(".")) { // means there are custom layouts if (additionalSubtypeString.contains(".")) { // means there are custom layouts
val subtypeStrings = additionalSubtypeString.split(";") val subtypeStrings = additionalSubtypeString.split(";")
val newSubtypeStrings = subtypeStrings.mapNotNull { val newSubtypeStrings = subtypeStrings.mapNotNull {
@ -226,7 +227,7 @@ private fun upgradesWhenComingFromOldAppName(context: Context) {
} }
// upgrade additional subtype locale strings // upgrade additional subtype locale strings
val additionalSubtypes = mutableListOf<String>() val additionalSubtypes = mutableListOf<String>()
Settings.readPrefAdditionalSubtypes(prefs, context.resources).split(";").forEach { prefs.getString(Settings.PREF_ADDITIONAL_SUBTYPES, Defaults.PREF_ADDITIONAL_SUBTYPES)!!.split(";").forEach {
val localeString = it.substringBefore(":") val localeString = it.substringBefore(":")
additionalSubtypes.add(it.replace(localeString, localeString.constructLocale().toLanguageTag())) additionalSubtypes.add(it.replace(localeString, localeString.constructLocale().toLanguageTag()))
} }

View file

@ -17,6 +17,7 @@ import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode
import helium314.keyboard.latin.common.ColorType import helium314.keyboard.latin.common.ColorType
import helium314.keyboard.latin.common.isValidNumber import helium314.keyboard.latin.common.isValidNumber
import helium314.keyboard.latin.databinding.ClipboardSuggestionBinding import helium314.keyboard.latin.databinding.ClipboardSuggestionBinding
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.InputTypeUtils import helium314.keyboard.latin.utils.InputTypeUtils
import helium314.keyboard.latin.utils.ToolbarKey import helium314.keyboard.latin.utils.ToolbarKey
@ -36,7 +37,7 @@ class ClipboardHistoryManager(
clipboardManager.addPrimaryClipChangedListener(this) clipboardManager.addPrimaryClipChangedListener(this)
if (historyEntries.isEmpty()) if (historyEntries.isEmpty())
loadPinnedClips() loadPinnedClips()
if (Settings.readClipboardHistoryEnabled(latinIME.prefs())) if (latinIME.prefs().getBoolean(Settings.PREF_ENABLE_CLIPBOARD_HISTORY, Defaults.PREF_ENABLE_CLIPBOARD_HISTORY))
fetchPrimaryClip() fetchPrimaryClip()
} }

View file

@ -3,11 +3,12 @@ package helium314.keyboard.latin
import android.content.Context import android.content.Context
import android.content.SharedPreferences import android.content.SharedPreferences
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
fun customIconNames(prefs: SharedPreferences) = runCatching { fun customIconNames(prefs: SharedPreferences) = runCatching {
Json.decodeFromString<Map<String, String>>(prefs.getString(Settings.PREF_CUSTOM_ICON_NAMES, "")!!) Json.decodeFromString<Map<String, String>>(prefs.getString(Settings.PREF_CUSTOM_ICON_NAMES, Defaults.PREF_CUSTOM_ICON_NAMES)!!)
}.getOrElse { emptyMap() } }.getOrElse { emptyMap() }
fun customIconIds(context: Context, prefs: SharedPreferences) = customIconNames(prefs) fun customIconIds(context: Context, prefs: SharedPreferences) = customIconNames(prefs)

View file

@ -10,6 +10,7 @@ import android.content.Context
import android.os.Build import android.os.Build
import helium314.keyboard.latin.BuildConfig import helium314.keyboard.latin.BuildConfig
import helium314.keyboard.latin.settings.DebugSettings import helium314.keyboard.latin.settings.DebugSettings
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.utils.Log import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.prefs import helium314.keyboard.latin.utils.prefs
import java.io.File import java.io.File
@ -24,7 +25,7 @@ object DebugFlags {
@JvmStatic @JvmStatic
fun init(context: Context) { fun init(context: Context) {
DEBUG_ENABLED = context.prefs().getBoolean(DebugSettings.PREF_DEBUG_MODE, false) DEBUG_ENABLED = context.prefs().getBoolean(DebugSettings.PREF_DEBUG_MODE, Defaults.PREF_DEBUG_MODE)
if (DEBUG_ENABLED || BuildConfig.DEBUG) if (DEBUG_ENABLED || BuildConfig.DEBUG)
CrashReportExceptionHandler(context.applicationContext).install() CrashReportExceptionHandler(context.applicationContext).install()
} }

View file

@ -419,7 +419,7 @@ class AdvancedSettingsFragment : SubScreenFragment() {
} }
checkVersionUpgrade(requireContext()) checkVersionUpgrade(requireContext())
Settings.getInstance().startListener() Settings.getInstance().startListener()
val additionalSubtypes = Settings.readPrefAdditionalSubtypes(sharedPreferences, resources) val additionalSubtypes = sharedPreferences.getString(Settings.PREF_ADDITIONAL_SUBTYPES, Defaults.PREF_ADDITIONAL_SUBTYPES)
updateAdditionalSubtypes(AdditionalSubtypeUtils.createAdditionalSubtypesArray(additionalSubtypes)) updateAdditionalSubtypes(AdditionalSubtypeUtils.createAdditionalSubtypesArray(additionalSubtypes))
reloadEnabledSubtypes(requireContext()) reloadEnabledSubtypes(requireContext())
val newDictBroadcast = Intent(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION) val newDictBroadcast = Intent(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION)
@ -518,9 +518,9 @@ class AdvancedSettingsFragment : SubScreenFragment() {
override fun writeDefaultValue(key: String) = prefs.edit().remove(key).apply() override fun writeDefaultValue(key: String) = prefs.edit().remove(key).apply()
override fun readValue(key: String) = Settings.readKeyLongpressTimeout(prefs, resources) override fun readValue(key: String) = prefs.getInt(Settings.PREF_KEY_LONGPRESS_TIMEOUT, Defaults.PREF_KEY_LONGPRESS_TIMEOUT)
override fun readDefaultValue(key: String) = Settings.readDefaultKeyLongpressTimeout(resources) override fun readDefaultValue(key: String) = 300
override fun getValueText(value: Int) = override fun getValueText(value: Int) =
resources.getString(R.string.abbreviation_unit_milliseconds, value.toString()) resources.getString(R.string.abbreviation_unit_milliseconds, value.toString())
@ -570,9 +570,9 @@ class AdvancedSettingsFragment : SubScreenFragment() {
override fun writeDefaultValue(key: String) = prefs.edit().remove(key).apply() override fun writeDefaultValue(key: String) = prefs.edit().remove(key).apply()
override fun readValue(key: String) = Settings.readLanguageSwipeDistance(prefs, resources) override fun readValue(key: String) = prefs.getInt(Settings.PREF_LANGUAGE_SWIPE_DISTANCE, 5)
override fun readDefaultValue(key: String) = Settings.readDefaultLanguageSwipeDistance(resources) override fun readDefaultValue(key: String) = 5
override fun getValueText(value: Int) = value.toString() override fun getValueText(value: Int) = value.toString()

View file

@ -354,7 +354,7 @@ class AppearanceSettingsFragment : SubScreenFragment() {
} }
private fun onClickLoadImage(landscape: Boolean): Boolean { private fun onClickLoadImage(landscape: Boolean): Boolean {
if (Settings.readDayNightPref(sharedPreferences, resources)) { if (sharedPreferences.getBoolean(Settings.PREF_THEME_DAY_NIGHT, Defaults.PREF_THEME_DAY_NIGHT)) {
AlertDialog.Builder(requireContext()) AlertDialog.Builder(requireContext())
.setTitle(R.string.day_or_night_image) .setTitle(R.string.day_or_night_image)
.setPositiveButton(R.string.day_or_night_day) { _, _ -> customImageDialog(false, landscape) } .setPositiveButton(R.string.day_or_night_day) { _, _ -> customImageDialog(false, landscape) }

View file

@ -75,8 +75,8 @@ public final class CorrectionSettingsFragment extends SubScreenFragment
} }
private void refreshEnabledSettings() { private void refreshEnabledSettings() {
setPreferenceVisible(Settings.PREF_AUTO_CORRECTION_CONFIDENCE, Settings.readAutoCorrectEnabled(getSharedPreferences())); setPreferenceVisible(Settings.PREF_AUTO_CORRECTION_CONFIDENCE, getSharedPreferences().getBoolean(Settings.PREF_AUTO_CORRECTION, Defaults.PREF_AUTO_CORRECTION));
setPreferenceVisible(Settings.PREF_MORE_AUTO_CORRECTION, Settings.readAutoCorrectEnabled(getSharedPreferences())); setPreferenceVisible(Settings.PREF_MORE_AUTO_CORRECTION, getSharedPreferences().getBoolean(Settings.PREF_AUTO_CORRECTION, Defaults.PREF_AUTO_CORRECTION));
setPreferenceVisible(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, getSharedPreferences().getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true)); setPreferenceVisible(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, getSharedPreferences().getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true));
setPreferenceVisible(Settings.PREF_ALWAYS_SHOW_SUGGESTIONS, getSharedPreferences().getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true)); setPreferenceVisible(Settings.PREF_ALWAYS_SHOW_SUGGESTIONS, getSharedPreferences().getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true));
setPreferenceVisible(Settings.PREF_CENTER_SUGGESTION_TEXT_TO_ENTER, getSharedPreferences().getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true)); setPreferenceVisible(Settings.PREF_CENTER_SUGGESTION_TEXT_TO_ENTER, getSharedPreferences().getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true));

View file

@ -0,0 +1,146 @@
package helium314.keyboard.latin.settings
import android.annotation.SuppressLint
import android.content.Context
import android.os.Build
import android.util.TypedValue
import android.view.Gravity
import helium314.keyboard.keyboard.KeyboardTheme
import helium314.keyboard.latin.BuildConfig
import helium314.keyboard.latin.utils.AdditionalSubtypeUtils
import helium314.keyboard.latin.utils.JniUtils
import helium314.keyboard.latin.utils.POPUP_KEYS_LABEL_DEFAULT
import helium314.keyboard.latin.utils.POPUP_KEYS_ORDER_DEFAULT
import helium314.keyboard.latin.utils.defaultClipboardToolbarPref
import helium314.keyboard.latin.utils.defaultPinnedToolbarPref
import helium314.keyboard.latin.utils.defaultToolbarPref
object Defaults {
fun initDynamicDefaults(context: Context) {
PREF_GESTURE_DYNAMIC_PREVIEW_FOLLOW_SYSTEM = android.provider.Settings.System.getFloat(
context.contentResolver,
android.provider.Settings.Global.TRANSITION_ANIMATION_SCALE,
1.0f
) != 0.0f
val dm = context.resources.displayMetrics
val px600 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 600f, dm)
PREF_POPUP_ON = dm.widthPixels >= px600 || dm.heightPixels >= px600
}
const val PREF_THEME_STYLE = KeyboardTheme.STYLE_MATERIAL
const val PREF_ICON_STYLE = KeyboardTheme.STYLE_MATERIAL
const val PREF_THEME_COLORS = KeyboardTheme.THEME_LIGHT
const val PREF_THEME_COLORS_NIGHT = KeyboardTheme.THEME_DARK
const val PREF_THEME_KEY_BORDERS = false
@JvmField
val PREF_THEME_DAY_NIGHT = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
const val PREF_CUSTOM_ICON_NAMES = ""
const val PREF_TOOLBAR_CUSTOM_KEY_CODES = ""
const val PREF_TOOLBAR_CUSTOM_LONGPRESS_CODES = ""
const val PREF_AUTO_CAP = true
const val PREF_VIBRATE_ON = false
const val PREF_VIBRATE_IN_DND_MODE = false
const val PREF_SOUND_ON = false
@JvmField
var PREF_POPUP_ON = true
const val PREF_AUTO_CORRECTION = true
const val PREF_MORE_AUTO_CORRECTION = false
const val PREF_AUTO_CORRECTION_CONFIDENCE = "0"
const val PREF_AUTOCORRECT_SHORTCUTS = false
const val PREF_CENTER_SUGGESTION_TEXT_TO_ENTER = false
const val PREF_SHOW_SUGGESTIONS = true
const val PREF_ALWAYS_SHOW_SUGGESTIONS = false
const val PREF_KEY_USE_PERSONALIZED_DICTS = true
const val PREF_KEY_USE_DOUBLE_SPACE_PERIOD = true
const val PREF_BLOCK_POTENTIALLY_OFFENSIVE = true
const val PREF_SHOW_LANGUAGE_SWITCH_KEY = false
const val PREF_LANGUAGE_SWITCH_KEY = "internal"
const val PREF_SHOW_EMOJI_KEY = false
const val PREF_VARIABLE_TOOLBAR_DIRECTION = true
const val PREF_ADDITIONAL_SUBTYPES = "de:qwerty:AsciiCapable${AdditionalSubtypeUtils.PREF_SUBTYPE_SEPARATOR}" +
"fr:qwertz:AsciiCapable${AdditionalSubtypeUtils.PREF_SUBTYPE_SEPARATOR}hu:qwerty:AsciiCapable"
const val PREF_ENABLE_SPLIT_KEYBOARD = false
const val PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE = false
const val PREF_SPLIT_SPACER_SCALE = SettingsValues.DEFAULT_SIZE_SCALE
const val PREF_SPLIT_SPACER_SCALE_LANDSCAPE = SettingsValues.DEFAULT_SIZE_SCALE
const val PREF_KEYBOARD_HEIGHT_SCALE = SettingsValues.DEFAULT_SIZE_SCALE
const val PREF_BOTTOM_PADDING_SCALE = SettingsValues.DEFAULT_SIZE_SCALE
const val PREF_BOTTOM_PADDING_SCALE_LANDSCAPE = 0f
const val PREF_SIDE_PADDING_SCALE = 0f
const val PREF_SIDE_PADDING_SCALE_LANDSCAPE = 0f
const val PREF_FONT_SCALE = SettingsValues.DEFAULT_SIZE_SCALE
const val PREF_EMOJI_FONT_SCALE = SettingsValues.DEFAULT_SIZE_SCALE
const val PREF_SPACE_HORIZONTAL_SWIPE = "move_cursor"
const val PREF_SPACE_VERTICAL_SWIPE = "none"
const val PREF_DELETE_SWIPE = true
const val PREF_AUTOSPACE_AFTER_PUNCTUATION = false
const val PREF_ALWAYS_INCOGNITO_MODE = false
const val PREF_BIGRAM_PREDICTIONS = true
const val PREF_SUGGEST_CLIPBOARD_CONTENT = true
const val PREF_GESTURE_INPUT = true
const val PREF_VIBRATION_DURATION_SETTINGS = -1
const val PREF_KEYPRESS_SOUND_VOLUME = -0.01f
const val PREF_KEY_LONGPRESS_TIMEOUT = 300
const val PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY = true
const val PREF_GESTURE_PREVIEW_TRAIL = true
const val PREF_GESTURE_FLOATING_PREVIEW_TEXT = true
const val PREF_GESTURE_FLOATING_PREVIEW_DYNAMIC = true
@JvmField
var PREF_GESTURE_DYNAMIC_PREVIEW_FOLLOW_SYSTEM = true
const val PREF_GESTURE_SPACE_AWARE = false
const val PREF_GESTURE_FAST_TYPING_COOLDOWN = 500
const val PREF_GESTURE_TRAIL_FADEOUT_DURATION = 800
const val PREF_SHOW_SETUP_WIZARD_ICON = true
const val PREF_USE_CONTACTS = false
const val PREFS_LONG_PRESS_SYMBOLS_FOR_NUMPAD = false
const val PREF_ONE_HANDED_MODE = false
@SuppressLint("RtlHardcoded")
const val PREF_ONE_HANDED_GRAVITY = Gravity.LEFT
const val PREF_ONE_HANDED_SCALE = 1f
const val PREF_SHOW_NUMBER_ROW = false
const val PREF_LOCALIZED_NUMBER_ROW = true
const val PREF_SHOW_NUMBER_ROW_HINTS = false
const val PREF_CUSTOM_CURRENCY_KEY = ""
const val PREF_SHOW_HINTS = true
const val PREF_POPUP_KEYS_ORDER = POPUP_KEYS_ORDER_DEFAULT
const val PREF_POPUP_KEYS_LABELS_ORDER = POPUP_KEYS_LABEL_DEFAULT
const val PREF_SHOW_POPUP_HINTS = false
const val PREF_MORE_POPUP_KEYS = "main"
const val PREF_SPACE_TO_CHANGE_LANG = true
const val PREF_LANGUAGE_SWIPE_DISTANCE = 5
const val PREF_ENABLE_CLIPBOARD_HISTORY = true
const val PREF_CLIPBOARD_HISTORY_RETENTION_TIME = 10 // minutes
const val PREF_SECONDARY_LOCALES = ""
const val PREF_ADD_TO_PERSONAL_DICTIONARY = false
@JvmField
val PREF_NAVBAR_COLOR = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
const val PREF_NARROW_KEY_GAPS = false
const val PREF_ENABLED_SUBTYPES = ""
const val PREF_SELECTED_SUBTYPE = ""
const val PREF_USE_SYSTEM_LOCALES = true
const val PREF_URL_DETECTION = false
const val PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG = false
const val PREF_QUICK_PIN_TOOLBAR_KEYS = false
val PREF_PINNED_TOOLBAR_KEYS = defaultPinnedToolbarPref
val PREF_TOOLBAR_KEYS = defaultToolbarPref
const val PREF_AUTO_SHOW_TOOLBAR = false
const val PREF_AUTO_HIDE_TOOLBAR = false
val PREF_CLIPBOARD_TOOLBAR_KEYS = defaultClipboardToolbarPref
const val PREF_ABC_AFTER_EMOJI = false
const val PREF_ABC_AFTER_CLIP = false
const val PREF_ABC_AFTER_SYMBOL_SPACE = true
const val PREF_REMOVE_REDUNDANT_POPUPS = false
const val PREF_SPACE_BAR_TEXT = ""
@JvmField
val PREF_EMOJI_MAX_SDK = Build.VERSION.SDK_INT
const val PREF_EMOJI_RECENT_KEYS = ""
const val PREF_LAST_SHOWN_EMOJI_CATEGORY_PAGE_ID = 0
const val PREF_PINNED_CLIPS = ""
@JvmField
val PREF_LIBRARY_CHECKSUM: String = JniUtils.expectedDefaultChecksum()
const val PREF_SHOW_DEBUG_SETTINGS = false
val PREF_DEBUG_MODE = BuildConfig.DEBUG
const val PREF_SHOW_SUGGESTION_INFOS = false
const val PREF_FORCE_NON_DISTINCT_MULTITOUCH = false
const val PREF_SLIDING_KEY_INPUT_PREVIEW = true
}

View file

@ -53,7 +53,7 @@ public final class GestureSettingsFragment extends SubScreenFragment {
private void refreshSettingsEnablement() { private void refreshSettingsEnablement() {
final SharedPreferences prefs = getSharedPreferences(); final SharedPreferences prefs = getSharedPreferences();
final boolean gestureInputEnabled = Settings.readGestureInputEnabled(prefs); final boolean gestureInputEnabled = prefs.getBoolean(Settings.PREF_GESTURE_INPUT, Defaults.PREF_GESTURE_INPUT);
setPreferenceVisible(Settings.PREF_GESTURE_PREVIEW_TRAIL, gestureInputEnabled); setPreferenceVisible(Settings.PREF_GESTURE_PREVIEW_TRAIL, gestureInputEnabled);
setPreferenceVisible(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, gestureInputEnabled); setPreferenceVisible(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, gestureInputEnabled);
final boolean gesturePreviewEnabled = gestureInputEnabled final boolean gesturePreviewEnabled = gestureInputEnabled
@ -71,7 +71,7 @@ public final class GestureSettingsFragment extends SubScreenFragment {
final SwitchPreference pref = findPreference(Settings.PREF_GESTURE_FLOATING_PREVIEW_DYNAMIC); final SwitchPreference pref = findPreference(Settings.PREF_GESTURE_FLOATING_PREVIEW_DYNAMIC);
if (pref == null) return; if (pref == null) return;
final SharedPreferences prefs = getSharedPreferences(); final SharedPreferences prefs = getSharedPreferences();
pref.setChecked(Settings.readGestureDynamicPreviewEnabled(prefs, requireContext())); pref.setChecked(Settings.readGestureDynamicPreviewEnabled(prefs));
pref.setOnPreferenceChangeListener((preference, newValue) -> { pref.setOnPreferenceChangeListener((preference, newValue) -> {
// default value is based on system reduced motion // default value is based on system reduced motion
final boolean defValue = Settings.readGestureDynamicPreviewDefault(requireContext()); final boolean defValue = Settings.readGestureDynamicPreviewDefault(requireContext());
@ -102,7 +102,7 @@ public final class GestureSettingsFragment extends SubScreenFragment {
@Override @Override
public int readValue(final String key) { public int readValue(final String key) {
return Settings.readGestureFastTypingCooldown(prefs, res); return prefs.getInt(Settings.PREF_GESTURE_FAST_TYPING_COOLDOWN, Defaults.PREF_GESTURE_FAST_TYPING_COOLDOWN);
} }
@Override @Override
@ -143,12 +143,12 @@ public final class GestureSettingsFragment extends SubScreenFragment {
@Override @Override
public int readValue(final String key) { public int readValue(final String key) {
return Settings.readGestureTrailFadeoutDuration(prefs, res); return prefs.getInt(Settings.PREF_GESTURE_TRAIL_FADEOUT_DURATION, Defaults.PREF_GESTURE_TRAIL_FADEOUT_DURATION);
} }
@Override @Override
public int readDefaultValue(final String key) { public int readDefaultValue(final String key) {
return Settings.readDefaultGestureTrailFadeoutDuration(res); return 800;
} }
@Override @Override

View file

@ -112,7 +112,7 @@ class LanguageSettingsDialog(
return return
} }
addAdditionalSubtype(prefs, context.resources, newSubtype) addAdditionalSubtype(prefs, newSubtype)
addEnabledSubtype(prefs, newSubtype) addEnabledSubtype(prefs, newSubtype)
addSubtypeToView(newSubtypeInfo) addSubtypeToView(newSubtypeInfo)
KeyboardLayoutSet.onKeyboardThemeChanged() KeyboardLayoutSet.onKeyboardThemeChanged()
@ -205,7 +205,7 @@ class LanguageSettingsDialog(
infos.remove(subtype) infos.remove(subtype)
if (isCustom) if (isCustom)
removeCustomLayoutFile(layoutSetName, context) removeCustomLayoutFile(layoutSetName, context)
removeAdditionalSubtype(prefs, context.resources, subtype.subtype) removeAdditionalSubtype(prefs, subtype.subtype)
removeEnabledSubtype(prefs, subtype.subtype) removeEnabledSubtype(prefs, subtype.subtype)
reloadSetting() reloadSetting()
} }

View file

@ -125,13 +125,13 @@ public final class PreferencesSettingsFragment extends SubScreenFragment {
final SharedPreferences prefs = getSharedPreferences(); final SharedPreferences prefs = getSharedPreferences();
final Resources res = getResources(); final Resources res = getResources();
setPreferenceVisible(Settings.PREF_VIBRATION_DURATION_SETTINGS, setPreferenceVisible(Settings.PREF_VIBRATION_DURATION_SETTINGS,
Settings.readVibrationEnabled(prefs, res)); Settings.readVibrationEnabled(prefs));
setPreferenceVisible(Settings.PREF_VIBRATE_IN_DND_MODE, setPreferenceVisible(Settings.PREF_VIBRATE_IN_DND_MODE,
Settings.readVibrationEnabled(prefs, res)); Settings.readVibrationEnabled(prefs));
setPreferenceVisible(Settings.PREF_KEYPRESS_SOUND_VOLUME, setPreferenceVisible(Settings.PREF_KEYPRESS_SOUND_VOLUME,
Settings.readKeypressSoundEnabled(prefs, res)); prefs.getBoolean(Settings.PREF_SOUND_ON, Defaults.PREF_SOUND_ON));
setPreferenceVisible(Settings.PREF_CLIPBOARD_HISTORY_RETENTION_TIME, setPreferenceVisible(Settings.PREF_CLIPBOARD_HISTORY_RETENTION_TIME,
Settings.readClipboardHistoryEnabled(prefs)); prefs.getBoolean(Settings.PREF_ENABLE_CLIPBOARD_HISTORY, Defaults.PREF_ENABLE_CLIPBOARD_HISTORY));
} }
private void setupKeypressVibrationDurationSettings() { private void setupKeypressVibrationDurationSettings() {
@ -155,7 +155,7 @@ public final class PreferencesSettingsFragment extends SubScreenFragment {
@Override @Override
public int readValue(final String key) { public int readValue(final String key) {
return Settings.readKeypressVibrationDuration(prefs); return prefs.getInt(Settings.PREF_VIBRATION_DURATION_SETTINGS, Defaults.PREF_VIBRATION_DURATION_SETTINGS);
} }
@Override @Override
@ -210,7 +210,7 @@ public final class PreferencesSettingsFragment extends SubScreenFragment {
@Override @Override
public int readValue(final String key) { public int readValue(final String key) {
return getPercentageFromValue(Settings.readKeypressSoundVolume(prefs)); return getPercentageFromValue(prefs.getFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, Defaults.PREF_KEYPRESS_SOUND_VOLUME));
} }
@Override @Override
@ -255,7 +255,7 @@ public final class PreferencesSettingsFragment extends SubScreenFragment {
@Override @Override
public int readValue(final String key) { public int readValue(final String key) {
return Settings.readClipboardHistoryRetentionTime(prefs, res); return prefs.getInt(Settings.PREF_CLIPBOARD_HISTORY_RETENTION_TIME, Defaults.PREF_CLIPBOARD_HISTORY_RETENTION_TIME);
} }
@Override @Override

View file

@ -6,7 +6,6 @@
package helium314.keyboard.latin.settings; package helium314.keyboard.latin.settings;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
@ -20,7 +19,6 @@ import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
import android.view.Gravity;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -38,7 +36,6 @@ import helium314.keyboard.latin.common.LocaleUtils;
import helium314.keyboard.latin.utils.AdditionalSubtypeUtils; import helium314.keyboard.latin.utils.AdditionalSubtypeUtils;
import helium314.keyboard.latin.utils.ColorUtilKt; import helium314.keyboard.latin.utils.ColorUtilKt;
import helium314.keyboard.latin.utils.DeviceProtectedUtils; import helium314.keyboard.latin.utils.DeviceProtectedUtils;
import helium314.keyboard.latin.utils.JniUtils;
import helium314.keyboard.latin.utils.KtxKt; import helium314.keyboard.latin.utils.KtxKt;
import helium314.keyboard.latin.utils.Log; import helium314.keyboard.latin.utils.Log;
import helium314.keyboard.latin.utils.ResourceUtils; import helium314.keyboard.latin.utils.ResourceUtils;
@ -265,7 +262,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
mSettingsValuesLock.unlock(); mSettingsValuesLock.unlock();
} }
if (PREF_ADDITIONAL_SUBTYPES.equals(key)) { if (PREF_ADDITIONAL_SUBTYPES.equals(key)) {
final String additionalSubtypes = readPrefAdditionalSubtypes(prefs, mContext.getResources()); final String additionalSubtypes = prefs.getString(Settings.PREF_ADDITIONAL_SUBTYPES, Defaults.PREF_ADDITIONAL_SUBTYPES);
SubtypeSettingsKt.updateAdditionalSubtypes(AdditionalSubtypeUtils.createAdditionalSubtypesArray(additionalSubtypes)); SubtypeSettingsKt.updateAdditionalSubtypes(AdditionalSubtypeUtils.createAdditionalSubtypesArray(additionalSubtypes));
} }
} }
@ -301,26 +298,14 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
return res.getInteger(R.integer.config_screen_metrics); return res.getInteger(R.integer.config_screen_metrics);
} }
// Accessed from the settings interface, hence public public static boolean readVibrationEnabled(final SharedPreferences prefs) {
public static boolean readKeypressSoundEnabled(final SharedPreferences prefs, final Resources res) { return prefs.getBoolean(PREF_VIBRATE_ON, Defaults.PREF_VIBRATE_ON)
return prefs.getBoolean(PREF_SOUND_ON, res.getBoolean(R.bool.config_default_sound_enabled));
}
public static boolean readVibrationEnabled(final SharedPreferences prefs, final Resources res) {
return prefs.getBoolean(PREF_VIBRATE_ON, res.getBoolean(R.bool.config_default_vibration_enabled))
&& AudioAndHapticFeedbackManager.getInstance().hasVibrator(); && AudioAndHapticFeedbackManager.getInstance().hasVibrator();
} }
public static boolean readAutoCorrectEnabled(final SharedPreferences prefs) {
return prefs.getBoolean(PREF_AUTO_CORRECTION, true);
}
public static boolean readMoreAutoCorrectEnabled(final SharedPreferences prefs) {
return prefs.getBoolean(PREF_MORE_AUTO_CORRECTION, true);
}
public void toggleAutoCorrect() { public void toggleAutoCorrect() {
mPrefs.edit().putBoolean(Settings.PREF_AUTO_CORRECTION, !readAutoCorrectEnabled(mPrefs)).apply(); final boolean oldValue = mPrefs.getBoolean(PREF_AUTO_CORRECTION, Defaults.PREF_AUTO_CORRECTION);
mPrefs.edit().putBoolean(Settings.PREF_AUTO_CORRECTION, !oldValue).apply();
} }
public static String readAutoCorrectConfidence(final SharedPreferences prefs, final Resources res) { public static String readAutoCorrectConfidence(final SharedPreferences prefs, final Resources res) {
@ -328,22 +313,9 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
res.getString(R.string.auto_correction_threshold_mode_index_modest)); res.getString(R.string.auto_correction_threshold_mode_index_modest));
} }
public static boolean readCenterSuggestionTextToEnter(final SharedPreferences prefs, final Resources res) { public static boolean readGestureDynamicPreviewEnabled(final SharedPreferences prefs) {
return prefs.getBoolean(PREF_CENTER_SUGGESTION_TEXT_TO_ENTER, res.getBoolean(R.bool.config_center_suggestion_text_to_enter)); final boolean followSystem = prefs.getBoolean(PREF_GESTURE_DYNAMIC_PREVIEW_FOLLOW_SYSTEM, Defaults.PREF_GESTURE_DYNAMIC_PREVIEW_FOLLOW_SYSTEM);
} final boolean defValue = Defaults.PREF_GESTURE_DYNAMIC_PREVIEW_FOLLOW_SYSTEM;
public static boolean readBlockPotentiallyOffensive(final SharedPreferences prefs, final Resources res) {
return prefs.getBoolean(PREF_BLOCK_POTENTIALLY_OFFENSIVE,
res.getBoolean(R.bool.config_block_potentially_offensive));
}
public static boolean readGestureInputEnabled(final SharedPreferences prefs) {
return JniUtils.sHaveGestureLib && prefs.getBoolean(PREF_GESTURE_INPUT, true);
}
public static boolean readGestureDynamicPreviewEnabled(final SharedPreferences prefs, final Context context) {
final boolean followSystem = prefs.getBoolean(PREF_GESTURE_DYNAMIC_PREVIEW_FOLLOW_SYSTEM, true);
final boolean defValue = readGestureDynamicPreviewDefault(context);
final boolean curValue = prefs.getBoolean(Settings.PREF_GESTURE_FLOATING_PREVIEW_DYNAMIC, defValue); final boolean curValue = prefs.getBoolean(Settings.PREF_GESTURE_FLOATING_PREVIEW_DYNAMIC, defValue);
return followSystem ? defValue : curValue; return followSystem ? defValue : curValue;
} }
@ -357,89 +329,25 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
) != 0.0f; ) != 0.0f;
} }
public static int readGestureFastTypingCooldown(final SharedPreferences prefs, final Resources res) {
final int milliseconds = prefs.getInt(
PREF_GESTURE_FAST_TYPING_COOLDOWN, UNDEFINED_PREFERENCE_VALUE_INT);
return (milliseconds != UNDEFINED_PREFERENCE_VALUE_INT) ? milliseconds
: readDefaultGestureFastTypingCooldown(res);
}
public static int readDefaultGestureFastTypingCooldown(final Resources res) { public static int readDefaultGestureFastTypingCooldown(final Resources res) {
return res.getInteger(R.integer.config_gesture_static_time_threshold_after_fast_typing); return res.getInteger(R.integer.config_gesture_static_time_threshold_after_fast_typing);
} }
public static int readGestureTrailFadeoutDuration(final SharedPreferences prefs, final Resources res) {
final int milliseconds = prefs.getInt(
PREF_GESTURE_TRAIL_FADEOUT_DURATION, UNDEFINED_PREFERENCE_VALUE_INT);
return (milliseconds != UNDEFINED_PREFERENCE_VALUE_INT) ? milliseconds
: readDefaultGestureTrailFadeoutDuration(res);
}
public static int readDefaultGestureTrailFadeoutDuration(final Resources res) {
return res.getInteger(R.integer.config_gesture_trail_fadeout_duration_default);
}
public static boolean readKeyPreviewPopupEnabled(final SharedPreferences prefs, final Resources res) {
final boolean defaultKeyPreviewPopup = res.getBoolean(R.bool.config_default_key_preview_popup);
return prefs.getBoolean(PREF_POPUP_ON, defaultKeyPreviewPopup);
}
public static boolean readAlwaysIncognitoMode(final SharedPreferences prefs) {
return prefs.getBoolean(PREF_ALWAYS_INCOGNITO_MODE, false);
}
public void toggleAlwaysIncognitoMode() { public void toggleAlwaysIncognitoMode() {
mPrefs.edit().putBoolean(Settings.PREF_ALWAYS_INCOGNITO_MODE, !readAlwaysIncognitoMode(mPrefs)).apply(); final boolean oldValue = mPrefs.getBoolean(Settings.PREF_ALWAYS_INCOGNITO_MODE, Defaults.PREF_ALWAYS_INCOGNITO_MODE);
} mPrefs.edit().putBoolean(Settings.PREF_ALWAYS_INCOGNITO_MODE, !oldValue).apply();
public static String readPrefAdditionalSubtypes(final SharedPreferences prefs, final Resources res) {
final String predefinedPrefSubtypes = AdditionalSubtypeUtils.createPrefSubtypes(
res.getStringArray(R.array.predefined_subtypes));
return prefs.getString(PREF_ADDITIONAL_SUBTYPES, predefinedPrefSubtypes);
} }
public static void writePrefAdditionalSubtypes(final SharedPreferences prefs, final String prefSubtypes) { public static void writePrefAdditionalSubtypes(final SharedPreferences prefs, final String prefSubtypes) {
prefs.edit().putString(PREF_ADDITIONAL_SUBTYPES, prefSubtypes).apply(); prefs.edit().putString(PREF_ADDITIONAL_SUBTYPES, prefSubtypes).apply();
} }
public static float readKeypressSoundVolume(final SharedPreferences prefs) {
return prefs.getFloat(PREF_KEYPRESS_SOUND_VOLUME, UNDEFINED_PREFERENCE_VALUE_FLOAT);
}
public static int readKeyLongpressTimeout(final SharedPreferences prefs, final Resources res) {
final int milliseconds = prefs.getInt(
PREF_KEY_LONGPRESS_TIMEOUT, UNDEFINED_PREFERENCE_VALUE_INT);
return (milliseconds != UNDEFINED_PREFERENCE_VALUE_INT) ? milliseconds
: readDefaultKeyLongpressTimeout(res);
}
public static int readDefaultKeyLongpressTimeout(final Resources res) {
return res.getInteger(R.integer.config_default_longpress_key_timeout);
}
public static int readKeypressVibrationDuration(final SharedPreferences prefs) {
return prefs.getInt(PREF_VIBRATION_DURATION_SETTINGS, UNDEFINED_PREFERENCE_VALUE_INT);
}
public static boolean readClipboardHistoryEnabled(final SharedPreferences prefs) {
return prefs.getBoolean(PREF_ENABLE_CLIPBOARD_HISTORY, true);
}
public static int readClipboardHistoryRetentionTime(final SharedPreferences prefs,
final Resources res) {
final int minutes = prefs.getInt(
PREF_CLIPBOARD_HISTORY_RETENTION_TIME, UNDEFINED_PREFERENCE_VALUE_INT);
return (minutes != UNDEFINED_PREFERENCE_VALUE_INT) ? minutes
: readDefaultClipboardHistoryRetentionTime(res);
}
public static int readDefaultClipboardHistoryRetentionTime(final Resources res) { public static int readDefaultClipboardHistoryRetentionTime(final Resources res) {
return res.getInteger(R.integer.config_clipboard_history_retention_time); return res.getInteger(R.integer.config_clipboard_history_retention_time);
} }
public static int readHorizontalSpaceSwipe(final SharedPreferences prefs) { public static int readHorizontalSpaceSwipe(final SharedPreferences prefs) {
return switch (prefs.getString(PREF_SPACE_HORIZONTAL_SWIPE, "none")) { return switch (prefs.getString(PREF_SPACE_HORIZONTAL_SWIPE, Defaults.PREF_SPACE_HORIZONTAL_SWIPE)) {
case "move_cursor" -> KeyboardActionListener.SWIPE_MOVE_CURSOR; case "move_cursor" -> KeyboardActionListener.SWIPE_MOVE_CURSOR;
case "switch_language" -> KeyboardActionListener.SWIPE_SWITCH_LANGUAGE; case "switch_language" -> KeyboardActionListener.SWIPE_SWITCH_LANGUAGE;
case "toggle_numpad" -> KeyboardActionListener.SWIPE_TOGGLE_NUMPAD; case "toggle_numpad" -> KeyboardActionListener.SWIPE_TOGGLE_NUMPAD;
@ -448,7 +356,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
} }
public static int readVerticalSpaceSwipe(final SharedPreferences prefs) { public static int readVerticalSpaceSwipe(final SharedPreferences prefs) {
return switch (prefs.getString(PREF_SPACE_VERTICAL_SWIPE, "none")) { return switch (prefs.getString(PREF_SPACE_VERTICAL_SWIPE, Defaults.PREF_SPACE_VERTICAL_SWIPE)) {
case "move_cursor" -> KeyboardActionListener.SWIPE_MOVE_CURSOR; case "move_cursor" -> KeyboardActionListener.SWIPE_MOVE_CURSOR;
case "switch_language" -> KeyboardActionListener.SWIPE_SWITCH_LANGUAGE; case "switch_language" -> KeyboardActionListener.SWIPE_SWITCH_LANGUAGE;
case "toggle_numpad" -> KeyboardActionListener.SWIPE_TOGGLE_NUMPAD; case "toggle_numpad" -> KeyboardActionListener.SWIPE_TOGGLE_NUMPAD;
@ -456,26 +364,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
}; };
} }
public static int readLanguageSwipeDistance(final SharedPreferences prefs,
final Resources res) {
final int sensitivity = prefs.getInt(
PREF_LANGUAGE_SWIPE_DISTANCE, UNDEFINED_PREFERENCE_VALUE_INT);
return (sensitivity != UNDEFINED_PREFERENCE_VALUE_INT) ? sensitivity
: readDefaultLanguageSwipeDistance(res);
}
public static int readDefaultLanguageSwipeDistance(final Resources res) {
return 5;
}
public static boolean readDeleteSwipeEnabled(final SharedPreferences prefs) {
return prefs.getBoolean(PREF_DELETE_SWIPE, true);
}
public static boolean readAutospaceAfterPunctuationEnabled(final SharedPreferences prefs) {
return prefs.getBoolean(PREF_AUTOSPACE_AFTER_PUNCTUATION, false);
}
public static boolean readFullscreenModeAllowed(final Resources res) { public static boolean readFullscreenModeAllowed(final Resources res) {
return res.getBoolean(R.bool.config_fullscreen_mode_allowed); return res.getBoolean(R.bool.config_fullscreen_mode_allowed);
} }
@ -489,11 +377,11 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
// Default value // Default value
return !isApplicationInSystemImage; return !isApplicationInSystemImage;
} }
return prefs.getBoolean(PREF_SHOW_SETUP_WIZARD_ICON, false); return prefs.getBoolean(PREF_SHOW_SETUP_WIZARD_ICON, Defaults.PREF_SHOW_SETUP_WIZARD_ICON);
} }
public static boolean readOneHandedModeEnabled(final SharedPreferences prefs, final boolean isLandscape) { public static boolean readOneHandedModeEnabled(final SharedPreferences prefs, final boolean isLandscape) {
return prefs.getBoolean(PREF_ONE_HANDED_MODE_PREFIX + !isLandscape, false); return prefs.getBoolean(PREF_ONE_HANDED_MODE_PREFIX + !isLandscape, Defaults.PREF_ONE_HANDED_MODE);
} }
public void writeOneHandedModeEnabled(final boolean enabled) { public void writeOneHandedModeEnabled(final boolean enabled) {
@ -502,7 +390,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
} }
public static float readOneHandedModeScale(final SharedPreferences prefs, final boolean isLandscape) { public static float readOneHandedModeScale(final SharedPreferences prefs, final boolean isLandscape) {
return prefs.getFloat(PREF_ONE_HANDED_SCALE_PREFIX + !isLandscape, 1f); return prefs.getFloat(PREF_ONE_HANDED_SCALE_PREFIX + !isLandscape, Defaults.PREF_ONE_HANDED_SCALE);
} }
public void writeOneHandedModeScale(final Float scale) { public void writeOneHandedModeScale(final Float scale) {
@ -510,9 +398,8 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
(getCurrent().mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT), scale).apply(); (getCurrent().mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT), scale).apply();
} }
@SuppressLint("RtlHardcoded")
public static int readOneHandedModeGravity(final SharedPreferences prefs, final boolean isLandscape) { public static int readOneHandedModeGravity(final SharedPreferences prefs, final boolean isLandscape) {
return prefs.getInt(PREF_ONE_HANDED_GRAVITY_PREFIX + !isLandscape, Gravity.LEFT); return prefs.getInt(PREF_ONE_HANDED_GRAVITY_PREFIX + !isLandscape, Defaults.PREF_ONE_HANDED_GRAVITY);
} }
public void writeOneHandedModeGravity(final int gravity) { public void writeOneHandedModeGravity(final int gravity) {
@ -527,24 +414,24 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static boolean readSplitKeyboardEnabled(final SharedPreferences prefs, final boolean isLandscape) { public static boolean readSplitKeyboardEnabled(final SharedPreferences prefs, final boolean isLandscape) {
final String pref = isLandscape ? PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE : PREF_ENABLE_SPLIT_KEYBOARD; final String pref = isLandscape ? PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE : PREF_ENABLE_SPLIT_KEYBOARD;
return prefs.getBoolean(pref, false); return prefs.getBoolean(pref, isLandscape ? Defaults.PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE : Defaults.PREF_ENABLE_SPLIT_KEYBOARD);
} }
public static float readSplitSpacerScale(final SharedPreferences prefs, final boolean isLandscape) { public static float readSplitSpacerScale(final SharedPreferences prefs, final boolean isLandscape) {
final String pref = isLandscape ? PREF_SPLIT_SPACER_SCALE_LANDSCAPE : PREF_SPLIT_SPACER_SCALE; final String pref = isLandscape ? PREF_SPLIT_SPACER_SCALE_LANDSCAPE : PREF_SPLIT_SPACER_SCALE;
return prefs.getFloat(pref, SettingsValues.DEFAULT_SIZE_SCALE); return prefs.getFloat(pref, isLandscape ? Defaults.PREF_SPLIT_SPACER_SCALE_LANDSCAPE : Defaults.PREF_SPLIT_SPACER_SCALE);
} }
public static float readBottomPaddingScale(final SharedPreferences prefs, final boolean landscape) { public static float readBottomPaddingScale(final SharedPreferences prefs, final boolean landscape) {
if (landscape) if (landscape)
return prefs.getFloat(PREF_BOTTOM_PADDING_SCALE_LANDSCAPE, 0f); return prefs.getFloat(PREF_BOTTOM_PADDING_SCALE_LANDSCAPE, Defaults.PREF_BOTTOM_PADDING_SCALE_LANDSCAPE);
return prefs.getFloat(PREF_BOTTOM_PADDING_SCALE, SettingsValues.DEFAULT_SIZE_SCALE); return prefs.getFloat(PREF_BOTTOM_PADDING_SCALE, Defaults.PREF_BOTTOM_PADDING_SCALE);
} }
public static float readSidePaddingScale(final SharedPreferences prefs, final boolean landscape) { public static float readSidePaddingScale(final SharedPreferences prefs, final boolean landscape) {
if (landscape) if (landscape)
return prefs.getFloat(PREF_SIDE_PADDING_SCALE_LANDSCAPE, 0f); return prefs.getFloat(PREF_SIDE_PADDING_SCALE_LANDSCAPE, Defaults.PREF_SIDE_PADDING_SCALE_LANDSCAPE);
return prefs.getFloat(PREF_SIDE_PADDING_SCALE, 0f); return prefs.getFloat(PREF_SIDE_PADDING_SCALE, Defaults.PREF_SIDE_PADDING_SCALE);
} }
public static boolean readHasHardwareKeyboard(final Configuration conf) { public static boolean readHasHardwareKeyboard(final Configuration conf) {
@ -556,38 +443,10 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
&& conf.hardKeyboardHidden != Configuration.HARDKEYBOARDHIDDEN_YES; && conf.hardKeyboardHidden != Configuration.HARDKEYBOARDHIDDEN_YES;
} }
public static void writeEmojiRecentKeys(final SharedPreferences prefs, String str) {
prefs.edit().putString(PREF_EMOJI_RECENT_KEYS, str).apply();
}
public static String readEmojiRecentKeys(final SharedPreferences prefs) {
return prefs.getString(PREF_EMOJI_RECENT_KEYS, "");
}
public static void writeLastShownEmojiCategoryId(
final SharedPreferences prefs, final int categoryId) {
prefs.edit().putInt(PREF_LAST_SHOWN_EMOJI_CATEGORY_ID, categoryId).apply();
}
public static int readLastShownEmojiCategoryId(
final SharedPreferences prefs, final int defValue) {
return prefs.getInt(PREF_LAST_SHOWN_EMOJI_CATEGORY_ID, defValue);
}
public static void writeLastShownEmojiCategoryPageId(
final SharedPreferences prefs, final int categoryId) {
prefs.edit().putInt(PREF_LAST_SHOWN_EMOJI_CATEGORY_PAGE_ID, categoryId).apply();
}
public static int readLastShownEmojiCategoryPageId(
final SharedPreferences prefs, final int defValue) {
return prefs.getInt(PREF_LAST_SHOWN_EMOJI_CATEGORY_PAGE_ID, defValue);
}
public static String readPinnedClipString(final Context context) { public static String readPinnedClipString(final Context context) {
try { try {
final SharedPreferences prefs = KtxKt.protectedPrefs(context); final SharedPreferences prefs = KtxKt.protectedPrefs(context);
return prefs.getString(PREF_PINNED_CLIPS, ""); return prefs.getString(PREF_PINNED_CLIPS, Defaults.PREF_PINNED_CLIPS);
} catch (final IllegalStateException e) { } catch (final IllegalStateException e) {
// SharedPreferences in credential encrypted storage are not available until after user is unlocked // SharedPreferences in credential encrypted storage are not available until after user is unlocked
return ""; return "";
@ -604,7 +463,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
} }
public static int readMorePopupKeysPref(final SharedPreferences prefs) { public static int readMorePopupKeysPref(final SharedPreferences prefs) {
return switch (prefs.getString(Settings.PREF_MORE_POPUP_KEYS, "main")) { return switch (prefs.getString(Settings.PREF_MORE_POPUP_KEYS, Defaults.PREF_MORE_POPUP_KEYS)) {
case "all" -> LocaleKeyboardInfosKt.POPUP_KEYS_ALL; case "all" -> LocaleKeyboardInfosKt.POPUP_KEYS_ALL;
case "more" -> LocaleKeyboardInfosKt.POPUP_KEYS_MORE; case "more" -> LocaleKeyboardInfosKt.POPUP_KEYS_MORE;
case "normal" -> LocaleKeyboardInfosKt.POPUP_KEYS_NORMAL; case "normal" -> LocaleKeyboardInfosKt.POPUP_KEYS_NORMAL;
@ -633,16 +492,12 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
return new File(DeviceProtectedUtils.getFilesDir(context), "custom_background_image" + (landscape ? "_landscape" : "") + (night ? "_night" : "")); return new File(DeviceProtectedUtils.getFilesDir(context), "custom_background_image" + (landscape ? "_landscape" : "") + (night ? "_night" : ""));
} }
public static boolean readDayNightPref(final SharedPreferences prefs, final Resources res) {
return prefs.getBoolean(PREF_THEME_DAY_NIGHT, res.getBoolean(R.bool.day_night_default));
}
public static void clearCachedBackgroundImages() { public static void clearCachedBackgroundImages() {
Arrays.fill(sCachedBackgroundImages, null); Arrays.fill(sCachedBackgroundImages, null);
} }
public static List<Locale> getSecondaryLocales(final SharedPreferences prefs, final Locale mainLocale) { public static List<Locale> getSecondaryLocales(final SharedPreferences prefs, final Locale mainLocale) {
final String localesString = prefs.getString(PREF_SECONDARY_LOCALES_PREFIX + mainLocale.toLanguageTag(), ""); final String localesString = prefs.getString(PREF_SECONDARY_LOCALES_PREFIX + mainLocale.toLanguageTag(), Defaults.PREF_SECONDARY_LOCALES);
final ArrayList<Locale> locales = new ArrayList<>(); final ArrayList<Locale> locales = new ArrayList<>();
for (String languageTag : localesString.split(";")) { for (String languageTag : localesString.split(";")) {
@ -667,11 +522,11 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static Colors getColorsForCurrentTheme(final Context context, final SharedPreferences prefs) { public static Colors getColorsForCurrentTheme(final Context context, final SharedPreferences prefs) {
boolean isNight = ResourceUtils.isNight(context.getResources()); boolean isNight = ResourceUtils.isNight(context.getResources());
if (ColorsSettingsFragment.Companion.getForceOppositeTheme()) isNight = !isNight; if (ColorsSettingsFragment.Companion.getForceOppositeTheme()) isNight = !isNight;
else isNight = isNight && readDayNightPref(prefs, context.getResources()); else isNight = isNight && prefs.getBoolean(PREF_THEME_DAY_NIGHT, Defaults.PREF_THEME_DAY_NIGHT);
final String themeColors = (isNight) final String themeColors = (isNight)
? prefs.getString(Settings.PREF_THEME_COLORS_NIGHT, KeyboardTheme.THEME_DARK) ? prefs.getString(Settings.PREF_THEME_COLORS_NIGHT, Defaults.PREF_THEME_COLORS_NIGHT)
: prefs.getString(Settings.PREF_THEME_COLORS, KeyboardTheme.THEME_LIGHT); : prefs.getString(Settings.PREF_THEME_COLORS, Defaults.PREF_THEME_COLORS);
final String themeStyle = prefs.getString(Settings.PREF_THEME_STYLE, KeyboardTheme.STYLE_MATERIAL); final String themeStyle = prefs.getString(Settings.PREF_THEME_STYLE, Defaults.PREF_THEME_STYLE);
return KeyboardTheme.getThemeColors(themeColors, themeStyle, context, prefs, isNight); return KeyboardTheme.getThemeColors(themeColors, themeStyle, context, prefs, isNight);
} }
@ -710,7 +565,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
final int background = readUserColor(prefs, context, PREF_COLOR_BACKGROUND_SUFFIX, isNight); final int background = readUserColor(prefs, context, PREF_COLOR_BACKGROUND_SUFFIX, isNight);
if (ColorUtilKt.isBrightColor(background)) { if (ColorUtilKt.isBrightColor(background)) {
// but if key borders are enabled, we still want reasonable contrast // but if key borders are enabled, we still want reasonable contrast
if (!prefs.getBoolean(Settings.PREF_THEME_KEY_BORDERS, false) if (!prefs.getBoolean(Settings.PREF_THEME_KEY_BORDERS, Defaults.PREF_THEME_KEY_BORDERS)
|| ColorUtilKt.isGoodContrast(Color.BLACK, readUserColor(prefs, context, PREF_COLOR_KEYS_SUFFIX, isNight))) || ColorUtilKt.isGoodContrast(Color.BLACK, readUserColor(prefs, context, PREF_COLOR_KEYS_SUFFIX, isNight)))
return Color.BLACK; return Color.BLACK;
else else
@ -766,7 +621,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
} }
public String readCustomCurrencyKey() { public String readCustomCurrencyKey() {
return mPrefs.getString(PREF_CUSTOM_CURRENCY_KEY, ""); return mPrefs.getString(PREF_CUSTOM_CURRENCY_KEY, Defaults.PREF_CUSTOM_CURRENCY_KEY);
} }
public Integer getCustomToolbarKeyCode(ToolbarKey key) { public Integer getCustomToolbarKeyCode(ToolbarKey key) {

View file

@ -11,7 +11,6 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Build;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
@ -28,6 +27,7 @@ import helium314.keyboard.latin.common.Colors;
import helium314.keyboard.latin.permissions.PermissionsUtil; import helium314.keyboard.latin.permissions.PermissionsUtil;
import helium314.keyboard.latin.utils.CustomLayoutUtilsKt; import helium314.keyboard.latin.utils.CustomLayoutUtilsKt;
import helium314.keyboard.latin.utils.InputTypeUtils; import helium314.keyboard.latin.utils.InputTypeUtils;
import helium314.keyboard.latin.utils.JniUtils;
import helium314.keyboard.latin.utils.Log; import helium314.keyboard.latin.utils.Log;
import helium314.keyboard.latin.utils.PopupKeysUtilsKt; import helium314.keyboard.latin.utils.PopupKeysUtilsKt;
import helium314.keyboard.latin.utils.ScriptUtils; import helium314.keyboard.latin.utils.ScriptUtils;
@ -163,45 +163,45 @@ public class SettingsValues {
mInputAttributes = inputAttributes; mInputAttributes = inputAttributes;
// Get the settings preferences // Get the settings preferences
mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true) && ScriptUtils.scriptSupportsUppercase(mLocale); mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, Defaults.PREF_AUTO_CAP) && ScriptUtils.scriptSupportsUppercase(mLocale);
mVibrateOn = Settings.readVibrationEnabled(prefs, res); mVibrateOn = Settings.readVibrationEnabled(prefs);
mVibrateInDndMode = prefs.getBoolean(Settings.PREF_VIBRATE_IN_DND_MODE, false); mVibrateInDndMode = prefs.getBoolean(Settings.PREF_VIBRATE_IN_DND_MODE, Defaults.PREF_VIBRATE_IN_DND_MODE);
mSoundOn = Settings.readKeypressSoundEnabled(prefs, res); mSoundOn = prefs.getBoolean(Settings.PREF_SOUND_ON, Defaults.PREF_SOUND_ON);
mKeyPreviewPopupOn = Settings.readKeyPreviewPopupEnabled(prefs, res); mKeyPreviewPopupOn = prefs.getBoolean(Settings.PREF_POPUP_ON, Defaults.PREF_POPUP_ON);
mSlidingKeyInputPreviewEnabled = prefs.getBoolean( mSlidingKeyInputPreviewEnabled = prefs.getBoolean(
DebugSettings.PREF_SLIDING_KEY_INPUT_PREVIEW, true); DebugSettings.PREF_SLIDING_KEY_INPUT_PREVIEW, Defaults.PREF_SLIDING_KEY_INPUT_PREVIEW);
mShowsVoiceInputKey = mInputAttributes.mShouldShowVoiceInputKey; mShowsVoiceInputKey = mInputAttributes.mShouldShowVoiceInputKey;
final String languagePref = prefs.getString(Settings.PREF_LANGUAGE_SWITCH_KEY, "internal"); final String languagePref = prefs.getString(Settings.PREF_LANGUAGE_SWITCH_KEY, Defaults.PREF_LANGUAGE_SWITCH_KEY);
mLanguageSwitchKeyToOtherImes = languagePref.equals("input_method") || languagePref.equals("both"); mLanguageSwitchKeyToOtherImes = languagePref.equals("input_method") || languagePref.equals("both");
mLanguageSwitchKeyToOtherSubtypes = languagePref.equals("internal") || languagePref.equals("both"); mLanguageSwitchKeyToOtherSubtypes = languagePref.equals("internal") || languagePref.equals("both");
mShowsLanguageSwitchKey = prefs.getBoolean(Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY, false); // only relevant for default functional key layout mShowsLanguageSwitchKey = prefs.getBoolean(Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY, Defaults.PREF_SHOW_LANGUAGE_SWITCH_KEY);
mShowsNumberRow = prefs.getBoolean(Settings.PREF_SHOW_NUMBER_ROW, false); mShowsNumberRow = prefs.getBoolean(Settings.PREF_SHOW_NUMBER_ROW, Defaults.PREF_SHOW_NUMBER_ROW);
mLocalizedNumberRow = prefs.getBoolean(Settings.PREF_LOCALIZED_NUMBER_ROW, true); mLocalizedNumberRow = prefs.getBoolean(Settings.PREF_LOCALIZED_NUMBER_ROW, Defaults.PREF_LOCALIZED_NUMBER_ROW);
mShowNumberRowHints = prefs.getBoolean(Settings.PREF_SHOW_NUMBER_ROW_HINTS, false); mShowNumberRowHints = prefs.getBoolean(Settings.PREF_SHOW_NUMBER_ROW_HINTS, Defaults.PREF_SHOW_NUMBER_ROW_HINTS);
mShowsHints = prefs.getBoolean(Settings.PREF_SHOW_HINTS, true); mShowsHints = prefs.getBoolean(Settings.PREF_SHOW_HINTS, Defaults.PREF_SHOW_HINTS);
mShowsPopupHints = prefs.getBoolean(Settings.PREF_SHOW_POPUP_HINTS, false); mShowsPopupHints = prefs.getBoolean(Settings.PREF_SHOW_POPUP_HINTS, Defaults.PREF_SHOW_POPUP_HINTS);
mSpaceForLangChange = prefs.getBoolean(Settings.PREF_SPACE_TO_CHANGE_LANG, true); mSpaceForLangChange = prefs.getBoolean(Settings.PREF_SPACE_TO_CHANGE_LANG, Defaults.PREF_SPACE_TO_CHANGE_LANG);
mShowsEmojiKey = prefs.getBoolean(Settings.PREF_SHOW_EMOJI_KEY, false); mShowsEmojiKey = prefs.getBoolean(Settings.PREF_SHOW_EMOJI_KEY, Defaults.PREF_SHOW_EMOJI_KEY);
mVarToolbarDirection = prefs.getBoolean(Settings.PREF_VARIABLE_TOOLBAR_DIRECTION, true); mVarToolbarDirection = prefs.getBoolean(Settings.PREF_VARIABLE_TOOLBAR_DIRECTION, Defaults.PREF_VARIABLE_TOOLBAR_DIRECTION);
mUsePersonalizedDicts = prefs.getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true); mUsePersonalizedDicts = prefs.getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, Defaults.PREF_KEY_USE_PERSONALIZED_DICTS);
mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true) mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, Defaults.PREF_KEY_USE_DOUBLE_SPACE_PERIOD)
&& inputAttributes.mIsGeneralTextInput; && inputAttributes.mIsGeneralTextInput;
mBlockPotentiallyOffensive = Settings.readBlockPotentiallyOffensive(prefs, res); mBlockPotentiallyOffensive = prefs.getBoolean(Settings.PREF_BLOCK_POTENTIALLY_OFFENSIVE, Defaults.PREF_BLOCK_POTENTIALLY_OFFENSIVE);
mUrlDetectionEnabled = prefs.getBoolean(Settings.PREF_URL_DETECTION, false); mUrlDetectionEnabled = prefs.getBoolean(Settings.PREF_URL_DETECTION, Defaults.PREF_URL_DETECTION);
mAutoCorrectionEnabledPerUserSettings = Settings.readAutoCorrectEnabled(prefs); mAutoCorrectionEnabledPerUserSettings = prefs.getBoolean(Settings.PREF_AUTO_CORRECTION, Defaults.PREF_AUTO_CORRECTION);
mAutoCorrectEnabled = mAutoCorrectionEnabledPerUserSettings mAutoCorrectEnabled = mAutoCorrectionEnabledPerUserSettings
&& (mInputAttributes.mInputTypeShouldAutoCorrect || Settings.readMoreAutoCorrectEnabled(prefs)) && (mInputAttributes.mInputTypeShouldAutoCorrect || prefs.getBoolean(Settings.PREF_MORE_AUTO_CORRECTION, Defaults.PREF_MORE_AUTO_CORRECTION))
&& (mUrlDetectionEnabled || !InputTypeUtils.isUriOrEmailType(mInputAttributes.mInputType)); && (mUrlDetectionEnabled || !InputTypeUtils.isUriOrEmailType(mInputAttributes.mInputType));
mCenterSuggestionTextToEnter = Settings.readCenterSuggestionTextToEnter(prefs, res); mCenterSuggestionTextToEnter = prefs.getBoolean(Settings.PREF_CENTER_SUGGESTION_TEXT_TO_ENTER, Defaults.PREF_CENTER_SUGGESTION_TEXT_TO_ENTER);
mAutoCorrectionThreshold = mAutoCorrectEnabled mAutoCorrectionThreshold = mAutoCorrectEnabled
? readAutoCorrectionThreshold(res, prefs) ? readAutoCorrectionThreshold(res, prefs)
: AUTO_CORRECTION_DISABLED_THRESHOLD; : AUTO_CORRECTION_DISABLED_THRESHOLD;
mScoreLimitForAutocorrect = (mAutoCorrectionThreshold < 0) ? 600000 // very aggressive mScoreLimitForAutocorrect = (mAutoCorrectionThreshold < 0) ? 600000 // very aggressive
: (mAutoCorrectionThreshold < 0.07 ? 800000 : 950000); // aggressive or modest : (mAutoCorrectionThreshold < 0.07 ? 800000 : 950000); // aggressive or modest
mAutoCorrectShortcuts = prefs.getBoolean(Settings.PREF_AUTOCORRECT_SHORTCUTS, true); mAutoCorrectShortcuts = prefs.getBoolean(Settings.PREF_AUTOCORRECT_SHORTCUTS, Defaults.PREF_AUTOCORRECT_SHORTCUTS);
mBigramPredictionEnabled = readBigramPredictionEnabled(prefs, res); mBigramPredictionEnabled = prefs.getBoolean(Settings.PREF_BIGRAM_PREDICTIONS, Defaults.PREF_BIGRAM_PREDICTIONS);
mSuggestClipboardContent = readSuggestClipboardContent(prefs, res); mSuggestClipboardContent = prefs.getBoolean(Settings.PREF_SUGGEST_CLIPBOARD_CONTENT, Defaults.PREF_SUGGEST_CLIPBOARD_CONTENT);
mDoubleSpacePeriodTimeout = res.getInteger(R.integer.config_double_space_period_timeout); mDoubleSpacePeriodTimeout = 1100; // ms
mHasHardwareKeyboard = Settings.readHasHardwareKeyboard(res.getConfiguration()); mHasHardwareKeyboard = Settings.readHasHardwareKeyboard(res.getConfiguration());
final boolean isLandscape = mDisplayOrientation == Configuration.ORIENTATION_LANDSCAPE; final boolean isLandscape = mDisplayOrientation == Configuration.ORIENTATION_LANDSCAPE;
final float displayWidthDp = TypedValueCompat.pxToDp(res.getDisplayMetrics().widthPixels, res.getDisplayMetrics()); final float displayWidthDp = TypedValueCompat.pxToDp(res.getDisplayMetrics().widthPixels, res.getDisplayMetrics());
@ -210,35 +210,36 @@ public class SettingsValues {
mSplitKeyboardSpacerRelativeWidth = mIsSplitKeyboardEnabled mSplitKeyboardSpacerRelativeWidth = mIsSplitKeyboardEnabled
? Math.min(Math.max((displayWidthDp - 600) / 600f + 0.15f, 0.15f), 0.35f) * Settings.readSplitSpacerScale(prefs, isLandscape) ? Math.min(Math.max((displayWidthDp - 600) / 600f + 0.15f, 0.15f), 0.35f) * Settings.readSplitSpacerScale(prefs, isLandscape)
: 0f; : 0f;
mQuickPinToolbarKeys = prefs.getBoolean(Settings.PREF_QUICK_PIN_TOOLBAR_KEYS, false); mQuickPinToolbarKeys = prefs.getBoolean(Settings.PREF_QUICK_PIN_TOOLBAR_KEYS, Defaults.PREF_QUICK_PIN_TOOLBAR_KEYS);
mScreenMetrics = Settings.readScreenMetrics(res); mScreenMetrics = Settings.readScreenMetrics(res);
// Compute other readable settings // Compute other readable settings
mKeyLongpressTimeout = Settings.readKeyLongpressTimeout(prefs, res); mKeyLongpressTimeout = prefs.getInt(Settings.PREF_KEY_LONGPRESS_TIMEOUT, Defaults.PREF_KEY_LONGPRESS_TIMEOUT);
mKeypressVibrationDuration = Settings.readKeypressVibrationDuration(prefs); mKeypressVibrationDuration = prefs.getInt(Settings.PREF_VIBRATION_DURATION_SETTINGS, Defaults.PREF_VIBRATION_DURATION_SETTINGS);
mKeypressSoundVolume = Settings.readKeypressSoundVolume(prefs); mKeypressSoundVolume = prefs.getFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, Defaults.PREF_KEYPRESS_SOUND_VOLUME);
mEnableEmojiAltPhysicalKey = prefs.getBoolean(Settings.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY, true); mEnableEmojiAltPhysicalKey = prefs.getBoolean(Settings.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY, Defaults.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY);
mGestureInputEnabled = Settings.readGestureInputEnabled(prefs); mGestureInputEnabled = JniUtils.sHaveGestureLib && prefs.getBoolean(Settings.PREF_GESTURE_INPUT, Defaults.PREF_GESTURE_INPUT);
mGestureTrailEnabled = prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, true); mGestureTrailEnabled = prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, Defaults.PREF_GESTURE_PREVIEW_TRAIL);
mGestureFloatingPreviewTextEnabled = !mInputAttributes.mDisableGestureFloatingPreviewText mGestureFloatingPreviewTextEnabled = !mInputAttributes.mDisableGestureFloatingPreviewText
&& prefs.getBoolean(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, true); && prefs.getBoolean(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, Defaults.PREF_GESTURE_FLOATING_PREVIEW_TEXT);
mGestureFloatingPreviewDynamicEnabled = Settings.readGestureDynamicPreviewEnabled(prefs, context); mGestureFloatingPreviewDynamicEnabled = Settings.readGestureDynamicPreviewEnabled(prefs);
mGestureFastTypingCooldown = Settings.readGestureFastTypingCooldown(prefs, res); mGestureFastTypingCooldown = prefs.getInt(Settings.PREF_GESTURE_FAST_TYPING_COOLDOWN, Defaults.PREF_GESTURE_FAST_TYPING_COOLDOWN);
mGestureTrailFadeoutDuration = Settings.readGestureTrailFadeoutDuration(prefs, res); mGestureTrailFadeoutDuration = prefs.getInt(Settings.PREF_GESTURE_TRAIL_FADEOUT_DURATION, Defaults.PREF_GESTURE_TRAIL_FADEOUT_DURATION);
mAccount = null; // remove? or can it be useful somewhere? mAccount = null; // remove? or can it be useful somewhere?
mOverrideShowingSuggestions = mInputAttributes.mMayOverrideShowingSuggestions && readSuggestionsOverrideEnabled(prefs); mOverrideShowingSuggestions = mInputAttributes.mMayOverrideShowingSuggestions && prefs.getBoolean(Settings.PREF_ALWAYS_SHOW_SUGGESTIONS, Defaults.PREF_ALWAYS_SHOW_SUGGESTIONS);
mSuggestionsEnabledPerUserSettings = (mInputAttributes.mShouldShowSuggestions && readSuggestionsEnabled(prefs)) final boolean suggestionsEnabled = prefs.getBoolean(Settings.PREF_SHOW_SUGGESTIONS, Defaults.PREF_SHOW_SUGGESTIONS);
mSuggestionsEnabledPerUserSettings = (mInputAttributes.mShouldShowSuggestions && suggestionsEnabled)
|| mOverrideShowingSuggestions; || mOverrideShowingSuggestions;
mIncognitoModeEnabled = Settings.readAlwaysIncognitoMode(prefs) || mInputAttributes.mNoLearning mIncognitoModeEnabled = prefs.getBoolean(Settings.PREF_ALWAYS_INCOGNITO_MODE, Defaults.PREF_ALWAYS_INCOGNITO_MODE) || mInputAttributes.mNoLearning
|| mInputAttributes.mIsPasswordField; || mInputAttributes.mIsPasswordField;
mKeyboardHeightScale = prefs.getFloat(Settings.PREF_KEYBOARD_HEIGHT_SCALE, DEFAULT_SIZE_SCALE); mKeyboardHeightScale = prefs.getFloat(Settings.PREF_KEYBOARD_HEIGHT_SCALE, Defaults.PREF_KEYBOARD_HEIGHT_SCALE);
mSpaceSwipeHorizontal = Settings.readHorizontalSpaceSwipe(prefs); mSpaceSwipeHorizontal = Settings.readHorizontalSpaceSwipe(prefs);
mSpaceSwipeVertical = Settings.readVerticalSpaceSwipe(prefs); mSpaceSwipeVertical = Settings.readVerticalSpaceSwipe(prefs);
mLanguageSwipeDistance = Settings.readLanguageSwipeDistance(prefs, res); mLanguageSwipeDistance = prefs.getInt(Settings.PREF_LANGUAGE_SWIPE_DISTANCE, Defaults.PREF_LANGUAGE_SWIPE_DISTANCE);
mDeleteSwipeEnabled = Settings.readDeleteSwipeEnabled(prefs); mDeleteSwipeEnabled = prefs.getBoolean(Settings.PREF_DELETE_SWIPE, Defaults.PREF_DELETE_SWIPE);
mAutospaceAfterPunctuationEnabled = Settings.readAutospaceAfterPunctuationEnabled(prefs); mAutospaceAfterPunctuationEnabled = prefs.getBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, Defaults.PREF_AUTOSPACE_AFTER_PUNCTUATION);
mClipboardHistoryEnabled = Settings.readClipboardHistoryEnabled(prefs); mClipboardHistoryEnabled = prefs.getBoolean(Settings.PREF_ENABLE_CLIPBOARD_HISTORY, Defaults.PREF_ENABLE_CLIPBOARD_HISTORY);
mClipboardHistoryRetentionTime = Settings.readClipboardHistoryRetentionTime(prefs, res); mClipboardHistoryRetentionTime = prefs.getInt(Settings.PREF_CLIPBOARD_HISTORY_RETENTION_TIME, Defaults.PREF_CLIPBOARD_HISTORY_RETENTION_TIME);
mOneHandedModeEnabled = Settings.readOneHandedModeEnabled(prefs, isLandscape); mOneHandedModeEnabled = Settings.readOneHandedModeEnabled(prefs, isLandscape);
mOneHandedModeGravity = Settings.readOneHandedModeGravity(prefs, isLandscape); mOneHandedModeGravity = Settings.readOneHandedModeGravity(prefs, isLandscape);
@ -256,34 +257,34 @@ public class SettingsValues {
mColors = Settings.getColorsForCurrentTheme(context, prefs); mColors = Settings.getColorsForCurrentTheme(context, prefs);
// read locale-specific popup key settings, fall back to global settings // read locale-specific popup key settings, fall back to global settings
final String popupKeyTypesDefault = prefs.getString(Settings.PREF_POPUP_KEYS_ORDER, PopupKeysUtilsKt.POPUP_KEYS_ORDER_DEFAULT); final String popupKeyTypesDefault = prefs.getString(Settings.PREF_POPUP_KEYS_ORDER, Defaults.PREF_POPUP_KEYS_ORDER);
mPopupKeyTypes = PopupKeysUtilsKt.getEnabledPopupKeys(prefs, Settings.PREF_POPUP_KEYS_ORDER + "_" + mLocale.toLanguageTag(), popupKeyTypesDefault); mPopupKeyTypes = PopupKeysUtilsKt.getEnabledPopupKeys(prefs, Settings.PREF_POPUP_KEYS_ORDER + "_" + mLocale.toLanguageTag(), popupKeyTypesDefault);
final String popupKeyLabelDefault = prefs.getString(Settings.PREF_POPUP_KEYS_LABELS_ORDER, PopupKeysUtilsKt.POPUP_KEYS_LABEL_DEFAULT); final String popupKeyLabelDefault = prefs.getString(Settings.PREF_POPUP_KEYS_LABELS_ORDER, Defaults.PREF_POPUP_KEYS_LABELS_ORDER);
mPopupKeyLabelSources = PopupKeysUtilsKt.getEnabledPopupKeys(prefs, Settings.PREF_POPUP_KEYS_LABELS_ORDER + "_" + mLocale.toLanguageTag(), popupKeyLabelDefault); mPopupKeyLabelSources = PopupKeysUtilsKt.getEnabledPopupKeys(prefs, Settings.PREF_POPUP_KEYS_LABELS_ORDER + "_" + mLocale.toLanguageTag(), popupKeyLabelDefault);
mAddToPersonalDictionary = prefs.getBoolean(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, false); mAddToPersonalDictionary = prefs.getBoolean(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, Defaults.PREF_ADD_TO_PERSONAL_DICTIONARY);
mUseContactsDictionary = SettingsValues.readUseContactsEnabled(prefs, context); mUseContactsDictionary = SettingsValues.readUseContactsEnabled(prefs, context);
mCustomNavBarColor = prefs.getBoolean(Settings.PREF_NAVBAR_COLOR, true); mCustomNavBarColor = prefs.getBoolean(Settings.PREF_NAVBAR_COLOR, Defaults.PREF_NAVBAR_COLOR);
mNarrowKeyGaps = prefs.getBoolean(Settings.PREF_NARROW_KEY_GAPS, true); mNarrowKeyGaps = prefs.getBoolean(Settings.PREF_NARROW_KEY_GAPS, Defaults.PREF_NARROW_KEY_GAPS);
mSettingsValuesForSuggestion = new SettingsValuesForSuggestion( mSettingsValuesForSuggestion = new SettingsValuesForSuggestion(
mBlockPotentiallyOffensive, mBlockPotentiallyOffensive,
prefs.getBoolean(Settings.PREF_GESTURE_SPACE_AWARE, false) prefs.getBoolean(Settings.PREF_GESTURE_SPACE_AWARE, Defaults.PREF_GESTURE_SPACE_AWARE)
); );
mSpacingAndPunctuations = new SpacingAndPunctuations(res, mUrlDetectionEnabled); mSpacingAndPunctuations = new SpacingAndPunctuations(res, mUrlDetectionEnabled);
mBottomPaddingScale = Settings.readBottomPaddingScale(prefs, isLandscape); mBottomPaddingScale = Settings.readBottomPaddingScale(prefs, isLandscape);
mSidePaddingScale = Settings.readSidePaddingScale(prefs, isLandscape); mSidePaddingScale = Settings.readSidePaddingScale(prefs, isLandscape);
mLongPressSymbolsForNumpad = prefs.getBoolean(Settings.PREFS_LONG_PRESS_SYMBOLS_FOR_NUMPAD, false); mLongPressSymbolsForNumpad = prefs.getBoolean(Settings.PREFS_LONG_PRESS_SYMBOLS_FOR_NUMPAD, Defaults.PREFS_LONG_PRESS_SYMBOLS_FOR_NUMPAD);
mAutoShowToolbar = prefs.getBoolean(Settings.PREF_AUTO_SHOW_TOOLBAR, false); mAutoShowToolbar = prefs.getBoolean(Settings.PREF_AUTO_SHOW_TOOLBAR, Defaults.PREF_AUTO_SHOW_TOOLBAR);
mAutoHideToolbar = readSuggestionsEnabled(prefs) && prefs.getBoolean(Settings.PREF_AUTO_HIDE_TOOLBAR, false); mAutoHideToolbar = suggestionsEnabled && prefs.getBoolean(Settings.PREF_AUTO_HIDE_TOOLBAR, Defaults.PREF_AUTO_HIDE_TOOLBAR);
mHasCustomFunctionalLayout = CustomLayoutUtilsKt.hasCustomFunctionalLayout(selectedSubtype, context); mHasCustomFunctionalLayout = CustomLayoutUtilsKt.hasCustomFunctionalLayout(selectedSubtype, context);
mAlphaAfterEmojiInEmojiView = prefs.getBoolean(Settings.PREF_ABC_AFTER_EMOJI, false); mAlphaAfterEmojiInEmojiView = prefs.getBoolean(Settings.PREF_ABC_AFTER_EMOJI, Defaults.PREF_ABC_AFTER_EMOJI);
mAlphaAfterClipHistoryEntry = prefs.getBoolean(Settings.PREF_ABC_AFTER_CLIP, false); mAlphaAfterClipHistoryEntry = prefs.getBoolean(Settings.PREF_ABC_AFTER_CLIP, Defaults.PREF_ABC_AFTER_CLIP);
mAlphaAfterSymbolAndSpace = prefs.getBoolean(Settings.PREF_ABC_AFTER_SYMBOL_SPACE, true); mAlphaAfterSymbolAndSpace = prefs.getBoolean(Settings.PREF_ABC_AFTER_SYMBOL_SPACE, Defaults.PREF_ABC_AFTER_SYMBOL_SPACE);
mRemoveRedundantPopups = prefs.getBoolean(Settings.PREF_REMOVE_REDUNDANT_POPUPS, false); mRemoveRedundantPopups = prefs.getBoolean(Settings.PREF_REMOVE_REDUNDANT_POPUPS, Defaults.PREF_REMOVE_REDUNDANT_POPUPS);
mSpaceBarText = prefs.getString(Settings.PREF_SPACE_BAR_TEXT, ""); mSpaceBarText = prefs.getString(Settings.PREF_SPACE_BAR_TEXT, Defaults.PREF_SPACE_BAR_TEXT);
mEmojiMaxSdk = prefs.getInt(Settings.PREF_EMOJI_MAX_SDK, Build.VERSION.SDK_INT); mEmojiMaxSdk = prefs.getInt(Settings.PREF_EMOJI_MAX_SDK, Defaults.PREF_EMOJI_MAX_SDK);
mFontSizeMultiplier = prefs.getFloat(Settings.PREF_FONT_SCALE, DEFAULT_SIZE_SCALE); mFontSizeMultiplier = prefs.getFloat(Settings.PREF_FONT_SCALE, Defaults.PREF_FONT_SCALE);
mFontSizeMultiplierEmoji = prefs.getFloat(Settings.PREF_EMOJI_FONT_SCALE, DEFAULT_SIZE_SCALE); mFontSizeMultiplierEmoji = prefs.getFloat(Settings.PREF_EMOJI_FONT_SCALE, Defaults.PREF_EMOJI_FONT_SCALE);
} }
public boolean isApplicationSpecifiedCompletionsOn() { public boolean isApplicationSpecifiedCompletionsOn() {
@ -347,26 +348,7 @@ public class SettingsValues {
return mDisplayOrientation == configuration.orientation; return mDisplayOrientation == configuration.orientation;
} }
private static boolean readSuggestionsEnabled(final SharedPreferences prefs) { // todo: way too complicated
return prefs.getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true);
}
private static boolean readSuggestionsOverrideEnabled(final SharedPreferences prefs) {
return prefs.getBoolean(Settings.PREF_ALWAYS_SHOW_SUGGESTIONS, false);
}
private static boolean readBigramPredictionEnabled(final SharedPreferences prefs,
final Resources res) {
return prefs.getBoolean(Settings.PREF_BIGRAM_PREDICTIONS, res.getBoolean(
R.bool.config_default_next_word_prediction));
}
private static boolean readSuggestClipboardContent (SharedPreferences prefs,
final Resources res) {
return prefs.getBoolean(Settings.PREF_SUGGEST_CLIPBOARD_CONTENT, res.getBoolean(
R.bool.config_default_suggest_clipboard_content));
}
private static float readAutoCorrectionThreshold(final Resources res, private static float readAutoCorrectionThreshold(final Resources res,
final SharedPreferences prefs) { final SharedPreferences prefs) {
final String currentAutoCorrectionSetting = Settings.readAutoCorrectConfidence(prefs, res); final String currentAutoCorrectionSetting = Settings.readAutoCorrectConfidence(prefs, res);
@ -400,7 +382,7 @@ public class SettingsValues {
} }
private static boolean readUseContactsEnabled(final SharedPreferences prefs, final Context context) { private static boolean readUseContactsEnabled(final SharedPreferences prefs, final Context context) {
final boolean setting = prefs.getBoolean(Settings.PREF_USE_CONTACTS, false); final boolean setting = prefs.getBoolean(Settings.PREF_USE_CONTACTS, Defaults.PREF_USE_CONTACTS);
if (!setting) return false; if (!setting) return false;
if (PermissionsUtil.checkAllPermissionsGranted(context, Manifest.permission.READ_CONTACTS)) if (PermissionsUtil.checkAllPermissionsGranted(context, Manifest.permission.READ_CONTACTS))
return true; return true;

View file

@ -106,7 +106,7 @@ public class UserDictionaryListFragment extends SubScreenFragment {
static TreeSet<Locale> getSortedDictionaryLocales(final Context context) { static TreeSet<Locale> getSortedDictionaryLocales(final Context context) {
final SharedPreferences prefs = KtxKt.prefs(context); final SharedPreferences prefs = KtxKt.prefs(context);
final boolean localeSystemOnly = prefs.getBoolean(Settings.PREF_USE_SYSTEM_LOCALES, true); final boolean localeSystemOnly = prefs.getBoolean(Settings.PREF_USE_SYSTEM_LOCALES, Defaults.PREF_USE_SYSTEM_LOCALES);
final TreeSet<Locale> sortedLocales = new TreeSet<>(new LocaleComparator()); final TreeSet<Locale> sortedLocales = new TreeSet<>(new LocaleComparator());
// Add the main language selected in the "Language and Layouts" setting except "No language" // Add the main language selected in the "Language and Layouts" setting except "No language"

View file

@ -27,6 +27,7 @@ import helium314.keyboard.latin.R;
import helium314.keyboard.latin.RichInputMethodSubtype; import helium314.keyboard.latin.RichInputMethodSubtype;
import helium314.keyboard.latin.SuggestedWords; import helium314.keyboard.latin.SuggestedWords;
import helium314.keyboard.latin.common.ComposedData; import helium314.keyboard.latin.common.ComposedData;
import helium314.keyboard.latin.settings.Defaults;
import helium314.keyboard.latin.settings.Settings; import helium314.keyboard.latin.settings.Settings;
import helium314.keyboard.latin.settings.SettingsValuesForSuggestion; import helium314.keyboard.latin.settings.SettingsValuesForSuggestion;
import helium314.keyboard.latin.utils.AdditionalSubtypeUtils; import helium314.keyboard.latin.utils.AdditionalSubtypeUtils;
@ -82,7 +83,7 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
final SharedPreferences prefs = KtxKt.prefs(this); final SharedPreferences prefs = KtxKt.prefs(this);
prefs.registerOnSharedPreferenceChangeListener(this); prefs.registerOnSharedPreferenceChangeListener(this);
onSharedPreferenceChanged(prefs, Settings.PREF_USE_CONTACTS); onSharedPreferenceChanged(prefs, Settings.PREF_USE_CONTACTS);
final boolean blockOffensive = Settings.readBlockPotentiallyOffensive(prefs, getResources()); final boolean blockOffensive = prefs.getBoolean(Settings.PREF_BLOCK_POTENTIALLY_OFFENSIVE, Defaults.PREF_BLOCK_POTENTIALLY_OFFENSIVE);
mSettingsValuesForSuggestion = new SettingsValuesForSuggestion(blockOffensive, false); mSettingsValuesForSuggestion = new SettingsValuesForSuggestion(blockOffensive, false);
SubtypeSettingsKt.init(this); SubtypeSettingsKt.init(this);
} }
@ -94,10 +95,10 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
@Override @Override
public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) { public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
if (Settings.PREF_USE_CONTACTS.equals(key)) { if (Settings.PREF_USE_CONTACTS.equals(key)) {
final boolean useContactsDictionary = prefs.getBoolean(Settings.PREF_USE_CONTACTS, true); final boolean useContactsDictionary = prefs.getBoolean(Settings.PREF_USE_CONTACTS, Defaults.PREF_USE_CONTACTS);
mDictionaryFacilitatorCache.setUseContactsDictionary(useContactsDictionary); mDictionaryFacilitatorCache.setUseContactsDictionary(useContactsDictionary);
} else if (Settings.PREF_BLOCK_POTENTIALLY_OFFENSIVE.equals(key)) { } else if (Settings.PREF_BLOCK_POTENTIALLY_OFFENSIVE.equals(key)) {
final boolean blockOffensive = Settings.readBlockPotentiallyOffensive(prefs, getResources()); final boolean blockOffensive = prefs.getBoolean(Settings.PREF_BLOCK_POTENTIALLY_OFFENSIVE, Defaults.PREF_BLOCK_POTENTIALLY_OFFENSIVE);
mSettingsValuesForSuggestion = new SettingsValuesForSuggestion(blockOffensive, false); mSettingsValuesForSuggestion = new SettingsValuesForSuggestion(blockOffensive, false);
} }
} }

View file

@ -55,6 +55,7 @@ import helium314.keyboard.latin.common.Colors;
import helium314.keyboard.latin.common.Constants; import helium314.keyboard.latin.common.Constants;
import helium314.keyboard.latin.define.DebugFlags; import helium314.keyboard.latin.define.DebugFlags;
import helium314.keyboard.latin.settings.DebugSettings; import helium314.keyboard.latin.settings.DebugSettings;
import helium314.keyboard.latin.settings.Defaults;
import helium314.keyboard.latin.settings.Settings; import helium314.keyboard.latin.settings.Settings;
import helium314.keyboard.latin.settings.SettingsValues; import helium314.keyboard.latin.settings.SettingsValues;
import helium314.keyboard.latin.suggestions.PopupSuggestionsView.MoreSuggestionsListener; import helium314.keyboard.latin.suggestions.PopupSuggestionsView.MoreSuggestionsListener;
@ -144,7 +145,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
super(context, attrs, defStyle); super(context, attrs, defStyle);
final Colors colors = Settings.getInstance().getCurrent().mColors; final Colors colors = Settings.getInstance().getCurrent().mColors;
final SharedPreferences prefs = KtxKt.prefs(context); final SharedPreferences prefs = KtxKt.prefs(context);
DEBUG_SUGGESTIONS = prefs.getBoolean(DebugSettings.PREF_SHOW_SUGGESTION_INFOS, false); DEBUG_SUGGESTIONS = prefs.getBoolean(DebugSettings.PREF_SHOW_SUGGESTION_INFOS, Defaults.PREF_SHOW_SUGGESTION_INFOS);
final LayoutInflater inflater = LayoutInflater.from(context); final LayoutInflater inflater = LayoutInflater.from(context);
inflater.inflate(R.layout.suggestions_strip, this); inflater.inflate(R.layout.suggestions_strip, this);

View file

@ -44,7 +44,7 @@ public final class AdditionalSubtypeUtils {
private static final int INDEX_OF_EXTRA_VALUE = 2; private static final int INDEX_OF_EXTRA_VALUE = 2;
private static final int LENGTH_WITHOUT_EXTRA_VALUE = (INDEX_OF_KEYBOARD_LAYOUT + 1); private static final int LENGTH_WITHOUT_EXTRA_VALUE = (INDEX_OF_KEYBOARD_LAYOUT + 1);
private static final int LENGTH_WITH_EXTRA_VALUE = (INDEX_OF_EXTRA_VALUE + 1); private static final int LENGTH_WITH_EXTRA_VALUE = (INDEX_OF_EXTRA_VALUE + 1);
private static final String PREF_SUBTYPE_SEPARATOR = ";"; public static final String PREF_SUBTYPE_SEPARATOR = ";";
private static InputMethodSubtype createAdditionalSubtypeInternal( private static InputMethodSubtype createAdditionalSubtypeInternal(
final Locale locale, final String keyboardLayoutSetName, final Locale locale, final String keyboardLayoutSetName,

View file

@ -12,6 +12,7 @@ import helium314.keyboard.compat.locale
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.LocaleUtils import helium314.keyboard.latin.common.LocaleUtils
import helium314.keyboard.latin.common.LocaleUtils.constructLocale import helium314.keyboard.latin.common.LocaleUtils.constructLocale
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import java.io.File import java.io.File
import java.util.* import java.util.*
@ -40,7 +41,7 @@ fun getDictionaryLocales(context: Context): MutableSet<Locale> {
fun showMissingDictionaryDialog(context: Context, locale: Locale) { fun showMissingDictionaryDialog(context: Context, locale: Locale) {
val prefs = context.prefs() val prefs = context.prefs()
if (prefs.getBoolean(Settings.PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG, false) || locale.toString() == "zz") if (prefs.getBoolean(Settings.PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG, Defaults.PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG) || locale.toString() == "zz")
return return
val repositoryLink = "<a href='$DICTIONARY_URL'>" + context.getString(R.string.dictionary_link_text) + "</a>" val repositoryLink = "<a href='$DICTIONARY_URL'>" + context.getString(R.string.dictionary_link_text) + "</a>"
val dictionaryLink = "<a href='$DICTIONARY_URL/src/branch/main/dictionaries/main_$locale.dict'>" + context.getString( val dictionaryLink = "<a href='$DICTIONARY_URL/src/branch/main/dictionaries/main_$locale.dict'>" + context.getString(

View file

@ -13,6 +13,7 @@ import android.text.TextUtils;
import helium314.keyboard.latin.App; import helium314.keyboard.latin.App;
import helium314.keyboard.latin.BuildConfig; import helium314.keyboard.latin.BuildConfig;
import helium314.keyboard.latin.settings.Defaults;
import helium314.keyboard.latin.settings.Settings; import helium314.keyboard.latin.settings.Settings;
import java.io.File; import java.io.File;
@ -62,7 +63,7 @@ public final class JniUtils {
// we want the default preferences, because storing the checksum in device protected storage is discouraged // we want the default preferences, because storing the checksum in device protected storage is discouraged
// see https://developer.android.com/reference/android/content/Context#createDeviceProtectedStorageContext() // see https://developer.android.com/reference/android/content/Context#createDeviceProtectedStorageContext()
// if device is locked, this will throw an IllegalStateException // if device is locked, this will throw an IllegalStateException
wantedChecksum = KtxKt.protectedPrefs(app).getString(Settings.PREF_LIBRARY_CHECKSUM, wantedChecksum); wantedChecksum = KtxKt.protectedPrefs(app).getString(Settings.PREF_LIBRARY_CHECKSUM, Defaults.PREF_LIBRARY_CHECKSUM);
} }
final FileInputStream libStream = new FileInputStream(userSuppliedLibrary); final FileInputStream libStream = new FileInputStream(userSuppliedLibrary);
final String checksum = ChecksumCalculator.INSTANCE.checksum(libStream); final String checksum = ChecksumCalculator.INSTANCE.checksum(libStream);

View file

@ -17,6 +17,7 @@ import helium314.keyboard.latin.common.Constants
import helium314.keyboard.latin.common.LocaleUtils import helium314.keyboard.latin.common.LocaleUtils
import helium314.keyboard.latin.common.LocaleUtils.constructLocale import helium314.keyboard.latin.common.LocaleUtils.constructLocale
import helium314.keyboard.latin.define.DebugFlags import helium314.keyboard.latin.define.DebugFlags
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.ScriptUtils.script import helium314.keyboard.latin.utils.ScriptUtils.script
import org.xmlpull.v1.XmlPullParser import org.xmlpull.v1.XmlPullParser
@ -26,7 +27,7 @@ import java.util.*
* subtypes for system locales will be returned, or en-US if none found. */ * subtypes for system locales will be returned, or en-US if none found. */
fun getEnabledSubtypes(prefs: SharedPreferences, fallback: Boolean = false): List<InputMethodSubtype> { fun getEnabledSubtypes(prefs: SharedPreferences, fallback: Boolean = false): List<InputMethodSubtype> {
require(initialized) require(initialized)
if (prefs.getBoolean(Settings.PREF_USE_SYSTEM_LOCALES, true)) if (prefs.getBoolean(Settings.PREF_USE_SYSTEM_LOCALES, Defaults.PREF_USE_SYSTEM_LOCALES))
return getDefaultEnabledSubtypes() return getDefaultEnabledSubtypes()
if (fallback && enabledSubtypes.isEmpty()) if (fallback && enabledSubtypes.isEmpty())
return getDefaultEnabledSubtypes() return getDefaultEnabledSubtypes()
@ -76,16 +77,16 @@ fun removeEnabledSubtype(prefs: SharedPreferences, subtype: InputMethodSubtype)
RichInputMethodManager.getInstance().refreshSubtypeCaches() RichInputMethodManager.getInstance().refreshSubtypeCaches()
} }
fun addAdditionalSubtype(prefs: SharedPreferences, resources: Resources, subtype: InputMethodSubtype) { fun addAdditionalSubtype(prefs: SharedPreferences, subtype: InputMethodSubtype) {
val oldAdditionalSubtypesString = Settings.readPrefAdditionalSubtypes(prefs, resources) val oldAdditionalSubtypesString = prefs.getString(Settings.PREF_ADDITIONAL_SUBTYPES, Defaults.PREF_ADDITIONAL_SUBTYPES)
val additionalSubtypes = AdditionalSubtypeUtils.createAdditionalSubtypesArray(oldAdditionalSubtypesString).toMutableSet() val additionalSubtypes = AdditionalSubtypeUtils.createAdditionalSubtypesArray(oldAdditionalSubtypesString).toMutableSet()
additionalSubtypes.add(subtype) additionalSubtypes.add(subtype)
val newAdditionalSubtypesString = AdditionalSubtypeUtils.createPrefSubtypes(additionalSubtypes.toTypedArray()) val newAdditionalSubtypesString = AdditionalSubtypeUtils.createPrefSubtypes(additionalSubtypes.toTypedArray())
Settings.writePrefAdditionalSubtypes(prefs, newAdditionalSubtypesString) Settings.writePrefAdditionalSubtypes(prefs, newAdditionalSubtypesString)
} }
fun removeAdditionalSubtype(prefs: SharedPreferences, resources: Resources, subtype: InputMethodSubtype) { fun removeAdditionalSubtype(prefs: SharedPreferences, subtype: InputMethodSubtype) {
val oldAdditionalSubtypesString = Settings.readPrefAdditionalSubtypes(prefs, resources) val oldAdditionalSubtypesString = prefs.getString(Settings.PREF_ADDITIONAL_SUBTYPES, Defaults.PREF_ADDITIONAL_SUBTYPES)
val oldAdditionalSubtypes = AdditionalSubtypeUtils.createAdditionalSubtypesArray(oldAdditionalSubtypesString) val oldAdditionalSubtypes = AdditionalSubtypeUtils.createAdditionalSubtypesArray(oldAdditionalSubtypesString)
val newAdditionalSubtypes = oldAdditionalSubtypes.filter { it != subtype } val newAdditionalSubtypes = oldAdditionalSubtypes.filter { it != subtype }
val newAdditionalSubtypesString = AdditionalSubtypeUtils.createPrefSubtypes(newAdditionalSubtypes.toTypedArray()) val newAdditionalSubtypesString = AdditionalSubtypeUtils.createPrefSubtypes(newAdditionalSubtypes.toTypedArray())
@ -94,14 +95,14 @@ fun removeAdditionalSubtype(prefs: SharedPreferences, resources: Resources, subt
fun getSelectedSubtype(prefs: SharedPreferences): InputMethodSubtype { fun getSelectedSubtype(prefs: SharedPreferences): InputMethodSubtype {
require(initialized) require(initialized)
val localeAndLayout = prefs.getString(Settings.PREF_SELECTED_SUBTYPE, "")!!.toLocaleAndLayout() val localeAndLayout = prefs.getString(Settings.PREF_SELECTED_SUBTYPE, Defaults.PREF_SELECTED_SUBTYPE)!!.toLocaleAndLayout()
val subtypes = if (prefs.getBoolean(Settings.PREF_USE_SYSTEM_LOCALES, true)) getDefaultEnabledSubtypes() val subtypes = if (prefs.getBoolean(Settings.PREF_USE_SYSTEM_LOCALES, Defaults.PREF_USE_SYSTEM_LOCALES)) getDefaultEnabledSubtypes()
else enabledSubtypes else enabledSubtypes
val subtype = subtypes.firstOrNull { localeAndLayout.first == it.locale() && localeAndLayout.second == SubtypeLocaleUtils.getKeyboardLayoutSetName(it) } val subtype = subtypes.firstOrNull { localeAndLayout.first == it.locale() && localeAndLayout.second == SubtypeLocaleUtils.getKeyboardLayoutSetName(it) }
if (subtype != null) { if (subtype != null) {
return subtype return subtype
} else { } else {
Log.w(TAG, "selected subtype $localeAndLayout / ${prefs.getString(Settings.PREF_SELECTED_SUBTYPE, "")} not found") Log.w(TAG, "selected subtype $localeAndLayout / ${prefs.getString(Settings.PREF_SELECTED_SUBTYPE, Defaults.PREF_SELECTED_SUBTYPE)} not found")
} }
if (subtypes.isNotEmpty()) if (subtypes.isNotEmpty())
return subtypes.first() return subtypes.first()
@ -113,7 +114,7 @@ fun getSelectedSubtype(prefs: SharedPreferences): InputMethodSubtype {
fun setSelectedSubtype(prefs: SharedPreferences, subtype: InputMethodSubtype) { fun setSelectedSubtype(prefs: SharedPreferences, subtype: InputMethodSubtype) {
val subtypeString = subtype.prefString() val subtypeString = subtype.prefString()
if (subtype.locale().toLanguageTag().isEmpty() || prefs.getString(Settings.PREF_SELECTED_SUBTYPE, "") == subtypeString) if (subtype.locale().toLanguageTag().isEmpty() || prefs.getString(Settings.PREF_SELECTED_SUBTYPE, Defaults.PREF_SELECTED_SUBTYPE) == subtypeString)
return return
prefs.edit { putString(Settings.PREF_SELECTED_SUBTYPE, subtypeString) } prefs.edit { putString(Settings.PREF_SELECTED_SUBTYPE, subtypeString) }
} }
@ -170,7 +171,7 @@ fun init(context: Context) {
loadResourceSubtypes(context.resources) loadResourceSubtypes(context.resources)
removeInvalidCustomSubtypes(context) removeInvalidCustomSubtypes(context)
loadAdditionalSubtypes(context) loadAdditionalSubtypes(context.prefs())
loadEnabledSubtypes(context) loadEnabledSubtypes(context)
initialized = true initialized = true
} }
@ -244,7 +245,7 @@ private fun loadResourceSubtypes(resources: Resources) {
// remove custom subtypes without a layout file // remove custom subtypes without a layout file
private fun removeInvalidCustomSubtypes(context: Context) { private fun removeInvalidCustomSubtypes(context: Context) {
val prefs = context.prefs() val prefs = context.prefs()
val additionalSubtypes = Settings.readPrefAdditionalSubtypes(prefs, context.resources).split(";") val additionalSubtypes = prefs.getString(Settings.PREF_ADDITIONAL_SUBTYPES, Defaults.PREF_ADDITIONAL_SUBTYPES)!!.split(";")
val customSubtypeFiles by lazy { getCustomLayoutFiles(context).map { it.name } } val customSubtypeFiles by lazy { getCustomLayoutFiles(context).map { it.name } }
val subtypesToRemove = mutableListOf<String>() val subtypesToRemove = mutableListOf<String>()
additionalSubtypes.forEach { additionalSubtypes.forEach {
@ -258,8 +259,8 @@ private fun removeInvalidCustomSubtypes(context: Context) {
Settings.writePrefAdditionalSubtypes(prefs, additionalSubtypes.filterNot { it in subtypesToRemove }.joinToString(";")) Settings.writePrefAdditionalSubtypes(prefs, additionalSubtypes.filterNot { it in subtypesToRemove }.joinToString(";"))
} }
private fun loadAdditionalSubtypes(context: Context) { private fun loadAdditionalSubtypes(prefs: SharedPreferences) {
val additionalSubtypeString = Settings.readPrefAdditionalSubtypes(context.prefs(), context.resources) val additionalSubtypeString = prefs.getString(Settings.PREF_ADDITIONAL_SUBTYPES, Defaults.PREF_ADDITIONAL_SUBTYPES)
val subtypes = AdditionalSubtypeUtils.createAdditionalSubtypesArray(additionalSubtypeString) val subtypes = AdditionalSubtypeUtils.createAdditionalSubtypesArray(additionalSubtypeString)
additionalSubtypes.addAll(subtypes) additionalSubtypes.addAll(subtypes)
} }
@ -267,7 +268,7 @@ private fun loadAdditionalSubtypes(context: Context) {
// requires loadResourceSubtypes to be called before // requires loadResourceSubtypes to be called before
private fun loadEnabledSubtypes(context: Context) { private fun loadEnabledSubtypes(context: Context) {
val prefs = context.prefs() val prefs = context.prefs()
val subtypeStrings = prefs.getString(Settings.PREF_ENABLED_SUBTYPES, "")!! val subtypeStrings = prefs.getString(Settings.PREF_ENABLED_SUBTYPES, Defaults.PREF_ENABLED_SUBTYPES)!!
.split(SUBTYPE_SEPARATOR).filter { it.isNotEmpty() }.map { it.toLocaleAndLayout() } .split(SUBTYPE_SEPARATOR).filter { it.isNotEmpty() }.map { it.toLocaleAndLayout() }
for (localeAndLayout in subtypeStrings) { for (localeAndLayout in subtypeStrings) {
@ -299,12 +300,12 @@ private fun loadEnabledSubtypes(context: Context) {
} }
private fun removeEnabledSubtype(prefs: SharedPreferences, subtypeString: String) { private fun removeEnabledSubtype(prefs: SharedPreferences, subtypeString: String) {
val oldSubtypeString = prefs.getString(Settings.PREF_ENABLED_SUBTYPES, "")!! val oldSubtypeString = prefs.getString(Settings.PREF_ENABLED_SUBTYPES, Defaults.PREF_ENABLED_SUBTYPES)!!
val newString = (oldSubtypeString.split(SUBTYPE_SEPARATOR) - subtypeString).joinToString(SUBTYPE_SEPARATOR) val newString = (oldSubtypeString.split(SUBTYPE_SEPARATOR) - subtypeString).joinToString(SUBTYPE_SEPARATOR)
if (newString == oldSubtypeString) if (newString == oldSubtypeString)
return // already removed return // already removed
prefs.edit { putString(Settings.PREF_ENABLED_SUBTYPES, newString) } prefs.edit { putString(Settings.PREF_ENABLED_SUBTYPES, newString) }
if (subtypeString == prefs.getString(Settings.PREF_SELECTED_SUBTYPE, "")) { if (subtypeString == prefs.getString(Settings.PREF_SELECTED_SUBTYPE, Defaults.PREF_SELECTED_SUBTYPE)) {
// switch subtype if the currently used one has been disabled // switch subtype if the currently used one has been disabled
try { try {
val nextSubtype = RichInputMethodManager.getInstance().getNextSubtypeInThisIme(true) val nextSubtype = RichInputMethodManager.getInstance().getNextSubtypeInThisIme(true)

View file

@ -26,6 +26,7 @@ import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode
import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode.checkAndConvertCode import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode.checkAndConvertCode
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.databinding.ReorderDialogItemBinding import helium314.keyboard.latin.databinding.ReorderDialogItemBinding
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.ToolbarKey.* import helium314.keyboard.latin.utils.ToolbarKey.*
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
@ -62,7 +63,7 @@ fun setToolbarButtonsActivatedStateOnPrefChange(buttonsGroup: ViewGroup, key: St
private fun setToolbarButtonActivatedState(button: ImageButton) { private fun setToolbarButtonActivatedState(button: ImageButton) {
button.isActivated = when (button.tag) { button.isActivated = when (button.tag) {
INCOGNITO -> Settings.readAlwaysIncognitoMode(button.context.prefs()) INCOGNITO -> button.context.prefs().getBoolean(Settings.PREF_ALWAYS_INCOGNITO_MODE, Defaults.PREF_ALWAYS_INCOGNITO_MODE)
ONE_HANDED -> Settings.getInstance().current.mOneHandedModeEnabled ONE_HANDED -> Settings.getInstance().current.mOneHandedModeEnabled
SPLIT -> Settings.getInstance().current.mIsSplitKeyboardEnabled SPLIT -> Settings.getInstance().current.mIsSplitKeyboardEnabled
AUTOCORRECT -> Settings.getInstance().current.mAutoCorrectionEnabledPerUserSettings AUTOCORRECT -> Settings.getInstance().current.mAutoCorrectionEnabledPerUserSettings
@ -310,17 +311,19 @@ private fun toolbarKeyCustomizer(context: Context, key: ToolbarKey) {
dialog.show() dialog.show()
} }
fun readCustomKeyCodes(prefs: SharedPreferences) = prefs.getString(Settings.PREF_TOOLBAR_CUSTOM_KEY_CODES, "")!! fun readCustomKeyCodes(prefs: SharedPreferences) =
prefs.getString(Settings.PREF_TOOLBAR_CUSTOM_KEY_CODES, Defaults.PREF_TOOLBAR_CUSTOM_KEY_CODES)!!
.split(";").filter { it.isNotEmpty()}.associate { .split(";").filter { it.isNotEmpty()}.associate {
val code = runCatching { it.substringAfter(",").toIntOrNull()?.checkAndConvertCode() }.getOrNull() val code = runCatching { it.substringAfter(",").toIntOrNull()?.checkAndConvertCode() }.getOrNull()
it.substringBefore(",") to code it.substringBefore(",") to code
} }
fun readCustomLongpressCodes(prefs: SharedPreferences) = prefs.getString(Settings.PREF_TOOLBAR_CUSTOM_LONGPRESS_CODES, "")!! fun readCustomLongpressCodes(prefs: SharedPreferences) =
.split(";").filter { it.isNotEmpty()}.associate { prefs.getString(Settings.PREF_TOOLBAR_CUSTOM_LONGPRESS_CODES, Defaults.PREF_TOOLBAR_CUSTOM_LONGPRESS_CODES)!!
val code = runCatching { it.substringAfter(",").toIntOrNull()?.checkAndConvertCode() }.getOrNull() .split(";").filter { it.isNotEmpty()}.associate {
it.substringBefore(",") to code val code = runCatching { it.substringAfter(",").toIntOrNull()?.checkAndConvertCode() }.getOrNull()
} it.substringBefore(",") to code
}
fun writeCustomKeyCodes(prefs: SharedPreferences, codes: Map<String, Int?>) { fun writeCustomKeyCodes(prefs: SharedPreferences, codes: Map<String, Int?>) {
val string = codes.mapNotNull { entry -> entry.value?.let { "${entry.key},$it" } }.joinToString(";") val string = codes.mapNotNull { entry -> entry.value?.let { "${entry.key},$it" } }.joinToString(";")

View file

@ -5,6 +5,7 @@ import android.content.Context
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable import androidx.compose.runtime.Immutable
import helium314.keyboard.latin.utils.JniUtils
import helium314.keyboard.settings.screens.createAboutSettings import helium314.keyboard.settings.screens.createAboutSettings
import helium314.keyboard.settings.screens.createAdvancedSettings import helium314.keyboard.settings.screens.createAdvancedSettings
import helium314.keyboard.settings.screens.createAppearanceSettings import helium314.keyboard.settings.screens.createAppearanceSettings
@ -60,9 +61,9 @@ class Setting(
} }
// intentionally not putting individual debug settings in here so user knows the context // intentionally not putting individual debug settings in here so user knows the context
private fun createSettings(context: Context) = createAboutSettings(context) + private fun createSettings(context: Context) = createAboutSettings(context) + createAppearanceSettings(context) +
createCorrectionSettings(context) + createPreferencesSettings(context) + createToolbarSettings(context) + createCorrectionSettings(context) + createPreferencesSettings(context) + createToolbarSettings(context) +
createGestureTypingSettings(context) + createAdvancedSettings(context) + createAppearanceSettings(context) createAdvancedSettings(context) + if (JniUtils.sHaveGestureLib) createGestureTypingSettings(context) else emptyList()
object SettingsWithoutKey { object SettingsWithoutKey {
const val EDIT_PERSONAL_DICTIONARY = "edit_personal_dictionary" const val EDIT_PERSONAL_DICTIONARY = "edit_personal_dictionary"

View file

@ -21,6 +21,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.FileUtils import helium314.keyboard.latin.common.FileUtils
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.Log import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.getActivity import helium314.keyboard.latin.utils.getActivity
@ -44,7 +45,7 @@ fun BackgroundImagePref(setting: Setting, isLandscape: Boolean) {
val b = (ctx.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState() val b = (ctx.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState()
if ((b?.value ?: 0) < 0) // necessary to reload dayNightPref if ((b?.value ?: 0) < 0) // necessary to reload dayNightPref
Log.v("irrelevant", "stupid way to trigger recomposition on preference change") Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
val dayNightPref = Settings.readDayNightPref(ctx.prefs(), ctx.resources) val dayNightPref = ctx.prefs().getBoolean(Settings.PREF_THEME_DAY_NIGHT, Defaults.PREF_THEME_DAY_NIGHT)
if (!dayNightPref) if (!dayNightPref)
isNight = false isNight = false
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()

View file

@ -27,6 +27,7 @@ import helium314.keyboard.latin.R
import helium314.keyboard.latin.checkVersionUpgrade import helium314.keyboard.latin.checkVersionUpgrade
import helium314.keyboard.latin.common.FileUtils import helium314.keyboard.latin.common.FileUtils
import helium314.keyboard.latin.common.LocaleUtils.constructLocale import helium314.keyboard.latin.common.LocaleUtils.constructLocale
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.settings.USER_DICTIONARY_SUFFIX import helium314.keyboard.latin.settings.USER_DICTIONARY_SUFFIX
import helium314.keyboard.latin.utils.AdditionalSubtypeUtils import helium314.keyboard.latin.utils.AdditionalSubtypeUtils
@ -175,7 +176,7 @@ fun BackupRestorePreference(setting: Setting) {
wait.await() wait.await()
checkVersionUpgrade(ctx) checkVersionUpgrade(ctx)
Settings.getInstance().startListener() Settings.getInstance().startListener()
val additionalSubtypes = Settings.readPrefAdditionalSubtypes(prefs, ctx.resources) val additionalSubtypes = prefs.getString(Settings.PREF_ADDITIONAL_SUBTYPES, Defaults.PREF_ADDITIONAL_SUBTYPES)
updateAdditionalSubtypes(AdditionalSubtypeUtils.createAdditionalSubtypesArray(additionalSubtypes)) updateAdditionalSubtypes(AdditionalSubtypeUtils.createAdditionalSubtypesArray(additionalSubtypes))
reloadEnabledSubtypes(ctx) reloadEnabledSubtypes(ctx)
val newDictBroadcast = Intent(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION) val newDictBroadcast = Intent(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION)

View file

@ -25,6 +25,7 @@ import androidx.core.net.toUri
import helium314.keyboard.latin.BuildConfig import helium314.keyboard.latin.BuildConfig
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.settings.DebugSettings import helium314.keyboard.latin.settings.DebugSettings
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.utils.Log import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.SpannableStringUtils import helium314.keyboard.latin.utils.SpannableStringUtils
import helium314.keyboard.latin.utils.getActivity import helium314.keyboard.latin.utils.getActivity
@ -75,7 +76,7 @@ fun createAboutSettings(context: Context) = listOf(
name = it.title, name = it.title,
description = stringResource(R.string.version_text, BuildConfig.VERSION_NAME), description = stringResource(R.string.version_text, BuildConfig.VERSION_NAME),
onClick = { onClick = {
if (prefs.getBoolean(DebugSettings.PREF_SHOW_DEBUG_SETTINGS, false) || BuildConfig.DEBUG) if (prefs.getBoolean(DebugSettings.PREF_SHOW_DEBUG_SETTINGS, Defaults.PREF_SHOW_DEBUG_SETTINGS) || BuildConfig.DEBUG)
return@Preference return@Preference
count++ count++
if (count < 5) return@Preference if (count < 5) return@Preference

View file

@ -26,6 +26,7 @@ import helium314.keyboard.latin.R
import helium314.keyboard.latin.SystemBroadcastReceiver import helium314.keyboard.latin.SystemBroadcastReceiver
import helium314.keyboard.latin.common.splitOnWhitespace import helium314.keyboard.latin.common.splitOnWhitespace
import helium314.keyboard.latin.settings.DebugSettings import helium314.keyboard.latin.settings.DebugSettings
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.CUSTOM_FUNCTIONAL_LAYOUT_NORMAL import helium314.keyboard.latin.utils.CUSTOM_FUNCTIONAL_LAYOUT_NORMAL
import helium314.keyboard.latin.utils.CUSTOM_FUNCTIONAL_LAYOUT_SYMBOLS import helium314.keyboard.latin.utils.CUSTOM_FUNCTIONAL_LAYOUT_SYMBOLS
@ -76,7 +77,8 @@ fun AdvancedSettingsScreen(
SettingsWithoutKey.CUSTOM_SYMBOLS_NUMBER_LAYOUTS, SettingsWithoutKey.CUSTOM_SYMBOLS_NUMBER_LAYOUTS,
SettingsWithoutKey.CUSTOM_FUNCTIONAL_LAYOUTS, SettingsWithoutKey.CUSTOM_FUNCTIONAL_LAYOUTS,
SettingsWithoutKey.BACKUP_RESTORE, SettingsWithoutKey.BACKUP_RESTORE,
if (BuildConfig.DEBUG || prefs.getBoolean(DebugSettings.PREF_SHOW_DEBUG_SETTINGS, false)) SettingsWithoutKey.DEBUG_SETTINGS else null, if (BuildConfig.DEBUG || prefs.getBoolean(DebugSettings.PREF_SHOW_DEBUG_SETTINGS, Defaults.PREF_SHOW_DEBUG_SETTINGS))
SettingsWithoutKey.DEBUG_SETTINGS else null,
R.string.settings_category_experimental, R.string.settings_category_experimental,
Settings.PREF_EMOJI_MAX_SDK, Settings.PREF_EMOJI_MAX_SDK,
Settings.PREF_URL_DETECTION, Settings.PREF_URL_DETECTION,
@ -94,13 +96,13 @@ fun createAdvancedSettings(context: Context) = listOf(
Setting(context, Settings.PREF_ALWAYS_INCOGNITO_MODE, Setting(context, Settings.PREF_ALWAYS_INCOGNITO_MODE,
R.string.incognito, R.string.prefs_force_incognito_mode_summary) R.string.incognito, R.string.prefs_force_incognito_mode_summary)
{ {
SwitchPreference(it, false) SwitchPreference(it, Defaults.PREF_ALWAYS_INCOGNITO_MODE)
}, },
Setting(context, Settings.PREF_KEY_LONGPRESS_TIMEOUT, R.string.prefs_key_longpress_timeout_settings) { setting -> Setting(context, Settings.PREF_KEY_LONGPRESS_TIMEOUT, R.string.prefs_key_longpress_timeout_settings) { setting ->
SliderPreference( SliderPreference(
name = setting.title, name = setting.title,
key = setting.key, key = setting.key,
default = 300, default = Defaults.PREF_KEY_LONGPRESS_TIMEOUT,
range = 100f..700f, range = 100f..700f,
description = { stringResource(R.string.abbreviation_unit_milliseconds, it.toString()) } description = { stringResource(R.string.abbreviation_unit_milliseconds, it.toString()) }
) )
@ -112,7 +114,7 @@ fun createAdvancedSettings(context: Context) = listOf(
stringResource(R.string.space_swipe_toggle_numpad_entry) to "toggle_numpad", stringResource(R.string.space_swipe_toggle_numpad_entry) to "toggle_numpad",
stringResource(R.string.action_none) to "none", stringResource(R.string.action_none) to "none",
) )
ListPreference(it, items, "move_cursor") ListPreference(it, items, Defaults.PREF_SPACE_HORIZONTAL_SWIPE)
}, },
Setting(context, Settings.PREF_SPACE_VERTICAL_SWIPE, R.string.show_vertical_space_swipe) { Setting(context, Settings.PREF_SPACE_VERTICAL_SWIPE, R.string.show_vertical_space_swipe) {
val items = listOf( val items = listOf(
@ -121,48 +123,48 @@ fun createAdvancedSettings(context: Context) = listOf(
stringResource(R.string.space_swipe_toggle_numpad_entry) to "toggle_numpad", stringResource(R.string.space_swipe_toggle_numpad_entry) to "toggle_numpad",
stringResource(R.string.action_none) to "none", stringResource(R.string.action_none) to "none",
) )
ListPreference(it, items, "none") ListPreference(it, items, Defaults.PREF_SPACE_VERTICAL_SWIPE)
}, },
Setting(context, Settings.PREF_LANGUAGE_SWIPE_DISTANCE, R.string.prefs_language_swipe_distance) { setting -> Setting(context, Settings.PREF_LANGUAGE_SWIPE_DISTANCE, R.string.prefs_language_swipe_distance) { setting ->
SliderPreference( SliderPreference(
name = setting.title, name = setting.title,
key = setting.key, key = setting.key,
default = 5, default = Defaults.PREF_LANGUAGE_SWIPE_DISTANCE,
range = 2f..18f, range = 2f..18f,
description = { it.toString() } description = { it.toString() }
) )
}, },
Setting(context, Settings.PREF_DELETE_SWIPE, R.string.delete_swipe, R.string.delete_swipe_summary) { Setting(context, Settings.PREF_DELETE_SWIPE, R.string.delete_swipe, R.string.delete_swipe_summary) {
SwitchPreference(it, true) SwitchPreference(it, Defaults.PREF_DELETE_SWIPE)
}, },
Setting(context, Settings.PREF_SPACE_TO_CHANGE_LANG, Setting(context, Settings.PREF_SPACE_TO_CHANGE_LANG,
R.string.prefs_long_press_keyboard_to_change_lang, R.string.prefs_long_press_keyboard_to_change_lang,
R.string.prefs_long_press_keyboard_to_change_lang_summary) R.string.prefs_long_press_keyboard_to_change_lang_summary)
{ {
SwitchPreference(it, true) SwitchPreference(it, Defaults.PREF_SPACE_TO_CHANGE_LANG)
}, },
Setting(context, Settings.PREFS_LONG_PRESS_SYMBOLS_FOR_NUMPAD, R.string.prefs_long_press_symbol_for_numpad) { Setting(context, Settings.PREFS_LONG_PRESS_SYMBOLS_FOR_NUMPAD, R.string.prefs_long_press_symbol_for_numpad) {
SwitchPreference(it, false) SwitchPreference(it, Defaults.PREFS_LONG_PRESS_SYMBOLS_FOR_NUMPAD)
}, },
Setting(context, Settings.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY, R.string.prefs_enable_emoji_alt_physical_key, Setting(context, Settings.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY, R.string.prefs_enable_emoji_alt_physical_key,
R.string.prefs_enable_emoji_alt_physical_key_summary) R.string.prefs_enable_emoji_alt_physical_key_summary)
{ {
SwitchPreference(it, true) SwitchPreference(it, Defaults.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY)
}, },
Setting(context, Settings.PREF_SHOW_SETUP_WIZARD_ICON, R.string.prefs_enable_emoji_alt_physical_key_summary) { Setting(context, Settings.PREF_SHOW_SETUP_WIZARD_ICON, R.string.prefs_enable_emoji_alt_physical_key_summary) {
val ctx = LocalContext.current val ctx = LocalContext.current
SwitchPreference(it, true) { SystemBroadcastReceiver.toggleAppIcon(ctx) } SwitchPreference(it, Defaults.PREF_SHOW_SETUP_WIZARD_ICON) { SystemBroadcastReceiver.toggleAppIcon(ctx) }
}, },
Setting(context, Settings.PREF_ABC_AFTER_SYMBOL_SPACE, Setting(context, Settings.PREF_ABC_AFTER_SYMBOL_SPACE,
R.string.switch_keyboard_after, R.string.after_symbol_and_space) R.string.switch_keyboard_after, R.string.after_symbol_and_space)
{ {
SwitchPreference(it, true) SwitchPreference(it, Defaults.PREF_ABC_AFTER_SYMBOL_SPACE)
}, },
Setting(context, Settings.PREF_ABC_AFTER_EMOJI, R.string.switch_keyboard_after, R.string.after_emoji) { Setting(context, Settings.PREF_ABC_AFTER_EMOJI, R.string.switch_keyboard_after, R.string.after_emoji) {
SwitchPreference(it, false) SwitchPreference(it, Defaults.PREF_ABC_AFTER_EMOJI)
}, },
Setting(context, Settings.PREF_ABC_AFTER_CLIP, R.string.switch_keyboard_after, R.string.after_clip) { Setting(context, Settings.PREF_ABC_AFTER_CLIP, R.string.switch_keyboard_after, R.string.after_clip) {
SwitchPreference(it, false) SwitchPreference(it, Defaults.PREF_ABC_AFTER_EMOJI)
}, },
Setting(context, Settings.PREF_CUSTOM_CURRENCY_KEY, R.string.customize_currencies) { setting -> Setting(context, Settings.PREF_CUSTOM_CURRENCY_KEY, R.string.customize_currencies) { setting ->
var showDialog by remember { mutableStateOf(false) } // todo: textInputDialog... var showDialog by remember { mutableStateOf(false) } // todo: textInputDialog...
@ -175,7 +177,7 @@ fun createAdvancedSettings(context: Context) = listOf(
TextInputDialog( TextInputDialog(
onDismissRequest = { showDialog = false }, onDismissRequest = { showDialog = false },
textInputLabel = { Text(stringResource(R.string.customize_currencies_detail)) }, textInputLabel = { Text(stringResource(R.string.customize_currencies_detail)) },
initialText = prefs.getString(setting.key, "")!!, initialText = prefs.getString(setting.key, Defaults.PREF_CUSTOM_CURRENCY_KEY)!!,
onConfirmed = { prefs.edit().putString(setting.key, it).apply(); KeyboardLayoutSet.onSystemLocaleChanged() }, onConfirmed = { prefs.edit().putString(setting.key, it).apply(); KeyboardLayoutSet.onSystemLocaleChanged() },
title = { Text(stringResource(R.string.customize_currencies)) }, title = { Text(stringResource(R.string.customize_currencies)) },
neutralButtonText = if (prefs.contains(setting.key)) stringResource(R.string.button_default) else null, neutralButtonText = if (prefs.contains(setting.key)) stringResource(R.string.button_default) else null,
@ -191,7 +193,7 @@ fun createAdvancedSettings(context: Context) = listOf(
stringResource(R.string.show_popup_keys_more) to "more", stringResource(R.string.show_popup_keys_more) to "more",
stringResource(R.string.show_popup_keys_all) to "all", stringResource(R.string.show_popup_keys_all) to "all",
) )
ListPreference(it, items, "main") { KeyboardLayoutSet.onSystemLocaleChanged() } ListPreference(it, items, Defaults.PREF_MORE_POPUP_KEYS) { KeyboardLayoutSet.onSystemLocaleChanged() }
}, },
Setting(context, SettingsWithoutKey.CUSTOM_SYMBOLS_NUMBER_LAYOUTS, R.string.customize_symbols_number_layouts) { setting -> Setting(context, SettingsWithoutKey.CUSTOM_SYMBOLS_NUMBER_LAYOUTS, R.string.customize_symbols_number_layouts) { setting ->
LayoutEditPreference( LayoutEditPreference(
@ -229,7 +231,7 @@ fun createAdvancedSettings(context: Context) = listOf(
SliderPreference( SliderPreference(
name = setting.title, name = setting.title,
key = setting.key, key = setting.key,
default = Build.VERSION.SDK_INT, default = Defaults.PREF_EMOJI_MAX_SDK,
range = 21f..35f, range = 21f..35f,
description = { description = {
"Android " + when(it) { "Android " + when(it) {
@ -255,7 +257,7 @@ fun createAdvancedSettings(context: Context) = listOf(
) )
}, },
Setting(context, Settings.PREF_URL_DETECTION, R.string.url_detection_title, R.string.url_detection_summary) { Setting(context, Settings.PREF_URL_DETECTION, R.string.url_detection_title, R.string.url_detection_summary) {
SwitchPreference(it, false) SwitchPreference(it, Defaults.PREF_URL_DETECTION)
}, },
Setting(context, SettingsWithoutKey.LOAD_GESTURE_LIB, R.string.load_gesture_library, R.string.load_gesture_library_summary) { Setting(context, SettingsWithoutKey.LOAD_GESTURE_LIB, R.string.load_gesture_library, R.string.load_gesture_library_summary) {
LoadGestureLibPreference(it) LoadGestureLibPreference(it)

View file

@ -14,14 +14,13 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import helium314.keyboard.keyboard.KeyboardLayoutSet
import helium314.keyboard.keyboard.KeyboardSwitcher import helium314.keyboard.keyboard.KeyboardSwitcher
import helium314.keyboard.keyboard.KeyboardTheme import helium314.keyboard.keyboard.KeyboardTheme
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.settings.ColorsNightSettingsFragment import helium314.keyboard.latin.settings.ColorsNightSettingsFragment
import helium314.keyboard.latin.settings.ColorsSettingsFragment import helium314.keyboard.latin.settings.ColorsSettingsFragment
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.settings.SettingsValues
import helium314.keyboard.latin.utils.Log import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.getActivity import helium314.keyboard.latin.utils.getActivity
import helium314.keyboard.latin.utils.getStringResourceOrName import helium314.keyboard.latin.utils.getStringResourceOrName
@ -52,30 +51,30 @@ fun AppearanceScreen(
val b = (LocalContext.current.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState() val b = (LocalContext.current.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState()
if ((b?.value ?: 0) < 0) if ((b?.value ?: 0) < 0)
Log.v("irrelevant", "stupid way to trigger recomposition on preference change") Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
val dayNightMode = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && Settings.readDayNightPref(prefs, ctx.resources) val dayNightMode = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && prefs.getBoolean(Settings.PREF_THEME_DAY_NIGHT, Defaults.PREF_THEME_DAY_NIGHT)
val items = listOf( val items = listOf(
R.string.settings_screen_theme, R.string.settings_screen_theme,
Settings.PREF_THEME_STYLE, Settings.PREF_THEME_STYLE,
Settings.PREF_ICON_STYLE, Settings.PREF_ICON_STYLE,
Settings.PREF_CUSTOM_ICON_NAMES, Settings.PREF_CUSTOM_ICON_NAMES,
Settings.PREF_THEME_COLORS, Settings.PREF_THEME_COLORS,
if (prefs.getString(Settings.PREF_THEME_COLORS, KeyboardTheme.THEME_LIGHT) == KeyboardTheme.THEME_USER) if (prefs.getString(Settings.PREF_THEME_COLORS, Defaults.PREF_THEME_COLORS) == KeyboardTheme.THEME_USER)
SettingsWithoutKey.ADJUST_COLORS else null, SettingsWithoutKey.ADJUST_COLORS else null,
Settings.PREF_THEME_KEY_BORDERS, Settings.PREF_THEME_KEY_BORDERS,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
Settings.PREF_THEME_DAY_NIGHT else null, Settings.PREF_THEME_DAY_NIGHT else null,
if (dayNightMode) Settings.PREF_THEME_COLORS_NIGHT else null, if (dayNightMode) Settings.PREF_THEME_COLORS_NIGHT else null,
if (dayNightMode && prefs.getString(Settings.PREF_THEME_COLORS_NIGHT, KeyboardTheme.THEME_DARK) == KeyboardTheme.THEME_USER_NIGHT) if (dayNightMode && prefs.getString(Settings.PREF_THEME_COLORS_NIGHT, Defaults.PREF_THEME_COLORS_NIGHT) == KeyboardTheme.THEME_USER_NIGHT)
SettingsWithoutKey.ADJUST_COLORS_NIGHT else null, SettingsWithoutKey.ADJUST_COLORS_NIGHT else null,
Settings.PREF_NAVBAR_COLOR, Settings.PREF_NAVBAR_COLOR,
SettingsWithoutKey.BACKGROUND_IMAGE, SettingsWithoutKey.BACKGROUND_IMAGE,
SettingsWithoutKey.BACKGROUND_IMAGE_LANDSCAPE, SettingsWithoutKey.BACKGROUND_IMAGE_LANDSCAPE,
R.string.settings_category_miscellaneous, R.string.settings_category_miscellaneous,
Settings.PREF_ENABLE_SPLIT_KEYBOARD, Settings.PREF_ENABLE_SPLIT_KEYBOARD,
if (prefs.getBoolean(Settings.PREF_ENABLE_SPLIT_KEYBOARD, false)) if (prefs.getBoolean(Settings.PREF_ENABLE_SPLIT_KEYBOARD, Defaults.PREF_ENABLE_SPLIT_KEYBOARD))
Settings.PREF_SPLIT_SPACER_SCALE else null, Settings.PREF_SPLIT_SPACER_SCALE else null,
Settings.PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE, Settings.PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE,
if (prefs.getBoolean(Settings.PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE, false)) if (prefs.getBoolean(Settings.PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE, Defaults.PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE))
Settings.PREF_SPLIT_SPACER_SCALE_LANDSCAPE else null, Settings.PREF_SPLIT_SPACER_SCALE_LANDSCAPE else null,
Settings.PREF_NARROW_KEY_GAPS, Settings.PREF_NARROW_KEY_GAPS,
Settings.PREF_KEYBOARD_HEIGHT_SCALE, Settings.PREF_KEYBOARD_HEIGHT_SCALE,
@ -105,14 +104,13 @@ fun createAppearanceSettings(context: Context) = listOf(
ListPreference( ListPreference(
setting, setting,
items, items,
KeyboardTheme.STYLE_MATERIAL Defaults.PREF_ICON_STYLE
) { ) {
if (it != KeyboardTheme.STYLE_HOLO) { if (it != KeyboardTheme.STYLE_HOLO) {
// todo (later): use defaults once they exist if (prefs.getString(Settings.PREF_THEME_COLORS, Defaults.PREF_THEME_COLORS) == KeyboardTheme.THEME_HOLO_WHITE)
if (prefs.getString(Settings.PREF_THEME_COLORS, "") == KeyboardTheme.THEME_HOLO_WHITE) prefs.edit().remove(Settings.PREF_THEME_COLORS).apply()
prefs.edit().putString(Settings.PREF_THEME_COLORS, KeyboardTheme.THEME_LIGHT).apply() if (prefs.getString(Settings.PREF_THEME_COLORS_NIGHT, Defaults.PREF_THEME_COLORS_NIGHT) == KeyboardTheme.THEME_HOLO_WHITE)
if (prefs.getString(Settings.PREF_THEME_COLORS_NIGHT, "") == KeyboardTheme.THEME_HOLO_WHITE) prefs.edit().remove(Settings.PREF_THEME_COLORS_NIGHT).apply()
prefs.edit().putString(Settings.PREF_THEME_COLORS_NIGHT, KeyboardTheme.THEME_DARK).apply()
} }
} }
}, },
@ -122,7 +120,7 @@ fun createAppearanceSettings(context: Context) = listOf(
ListPreference( ListPreference(
setting, setting,
items, items,
KeyboardTheme.STYLE_MATERIAL Defaults.PREF_ICON_STYLE
) { keyboardNeedsReload = true } ) { keyboardNeedsReload = true }
}, },
Setting(context, Settings.PREF_CUSTOM_ICON_NAMES, R.string.customize_icons) { setting -> Setting(context, Settings.PREF_CUSTOM_ICON_NAMES, R.string.customize_icons) { setting ->
@ -144,7 +142,7 @@ fun createAppearanceSettings(context: Context) = listOf(
val b = (ctx.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState() val b = (ctx.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState()
if ((b?.value ?: 0) < 0) if ((b?.value ?: 0) < 0)
Log.v("irrelevant", "stupid way to trigger recomposition on preference change") Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
val currentStyle = ctx.prefs().getString(Settings.PREF_THEME_STYLE, KeyboardTheme.STYLE_MATERIAL) val currentStyle = ctx.prefs().getString(Settings.PREF_THEME_STYLE, Defaults.PREF_THEME_STYLE)
val items = KeyboardTheme.COLORS.mapNotNull { val items = KeyboardTheme.COLORS.mapNotNull {
if (it == KeyboardTheme.THEME_HOLO_WHITE && currentStyle != KeyboardTheme.STYLE_HOLO) if (it == KeyboardTheme.THEME_HOLO_WHITE && currentStyle != KeyboardTheme.STYLE_HOLO)
return@mapNotNull null return@mapNotNull null
@ -153,7 +151,7 @@ fun createAppearanceSettings(context: Context) = listOf(
ListPreference( ListPreference(
setting, setting,
items, items,
KeyboardTheme.THEME_LIGHT Defaults.PREF_THEME_COLORS
) { keyboardNeedsReload = true } ) { keyboardNeedsReload = true }
}, },
Setting(context, Settings.PREF_THEME_COLORS_NIGHT, R.string.theme_colors_night) { setting -> Setting(context, Settings.PREF_THEME_COLORS_NIGHT, R.string.theme_colors_night) { setting ->
@ -161,7 +159,7 @@ fun createAppearanceSettings(context: Context) = listOf(
val b = (ctx.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState() val b = (ctx.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState()
if ((b?.value ?: 0) < 0) if ((b?.value ?: 0) < 0)
Log.v("irrelevant", "stupid way to trigger recomposition on preference change") Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
val currentStyle = ctx.prefs().getString(Settings.PREF_THEME_STYLE, KeyboardTheme.STYLE_MATERIAL) val currentStyle = ctx.prefs().getString(Settings.PREF_THEME_STYLE, Defaults.PREF_THEME_STYLE)
val items = KeyboardTheme.COLORS_DARK.mapNotNull { val items = KeyboardTheme.COLORS_DARK.mapNotNull {
if (it == KeyboardTheme.THEME_HOLO_WHITE && currentStyle == KeyboardTheme.STYLE_HOLO) if (it == KeyboardTheme.THEME_HOLO_WHITE && currentStyle == KeyboardTheme.STYLE_HOLO)
return@mapNotNull null return@mapNotNull null
@ -170,7 +168,7 @@ fun createAppearanceSettings(context: Context) = listOf(
ListPreference( ListPreference(
setting, setting,
items, items,
KeyboardTheme.THEME_DARK Defaults.PREF_THEME_COLORS_NIGHT
) { keyboardNeedsReload = true } ) { keyboardNeedsReload = true }
}, },
Setting(context, SettingsWithoutKey.ADJUST_COLORS, R.string.select_user_colors, R.string.select_user_colors_summary) { Setting(context, SettingsWithoutKey.ADJUST_COLORS, R.string.select_user_colors, R.string.select_user_colors_summary) {
@ -196,13 +194,13 @@ fun createAppearanceSettings(context: Context) = listOf(
) )
}, },
Setting(context, Settings.PREF_THEME_KEY_BORDERS, R.string.key_borders) { Setting(context, Settings.PREF_THEME_KEY_BORDERS, R.string.key_borders) {
SwitchPreference(it, false) SwitchPreference(it, Defaults.PREF_THEME_KEY_BORDERS)
}, },
Setting(context, Settings.PREF_THEME_DAY_NIGHT, R.string.day_night_mode, R.string.day_night_mode_summary) { Setting(context, Settings.PREF_THEME_DAY_NIGHT, R.string.day_night_mode, R.string.day_night_mode_summary) {
SwitchPreference(it, Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { keyboardNeedsReload = true } SwitchPreference(it, Defaults.PREF_THEME_DAY_NIGHT) { keyboardNeedsReload = true }
}, },
Setting(context, Settings.PREF_NAVBAR_COLOR, R.string.theme_navbar, R.string.day_night_mode_summary) { Setting(context, Settings.PREF_NAVBAR_COLOR, R.string.theme_navbar, R.string.day_night_mode_summary) {
SwitchPreference(it, Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) SwitchPreference(it, Defaults.PREF_NAVBAR_COLOR)
}, },
Setting(context, SettingsWithoutKey.BACKGROUND_IMAGE, R.string.customize_background_image) { Setting(context, SettingsWithoutKey.BACKGROUND_IMAGE, R.string.customize_background_image) {
BackgroundImagePref(it, false) BackgroundImagePref(it, false)
@ -213,37 +211,37 @@ fun createAppearanceSettings(context: Context) = listOf(
BackgroundImagePref(it, true) BackgroundImagePref(it, true)
}, },
Setting(context, Settings.PREF_ENABLE_SPLIT_KEYBOARD, R.string.enable_split_keyboard) { Setting(context, Settings.PREF_ENABLE_SPLIT_KEYBOARD, R.string.enable_split_keyboard) {
SwitchPreference(it, false) { KeyboardSwitcher.getInstance().reloadKeyboard() } SwitchPreference(it, Defaults.PREF_ENABLE_SPLIT_KEYBOARD) { KeyboardSwitcher.getInstance().reloadKeyboard() }
}, },
Setting(context, Settings.PREF_SPLIT_SPACER_SCALE, R.string.split_spacer_scale) { setting -> Setting(context, Settings.PREF_SPLIT_SPACER_SCALE, R.string.split_spacer_scale) { setting ->
SliderPreference( SliderPreference(
name = setting.title, name = setting.title,
key = setting.key, key = setting.key,
default = SettingsValues.DEFAULT_SIZE_SCALE, default = Defaults.PREF_SPLIT_SPACER_SCALE,
range = 0.5f..2f, range = 0.5f..2f,
description = { "${(100 * it).toInt()}%" } description = { "${(100 * it).toInt()}%" }
) { keyboardNeedsReload = true } ) { keyboardNeedsReload = true }
}, },
Setting(context, Settings.PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE, R.string.enable_split_keyboard_landscape) { Setting(context, Settings.PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE, R.string.enable_split_keyboard_landscape) {
SwitchPreference(it, false) { KeyboardSwitcher.getInstance().reloadKeyboard() } SwitchPreference(it, Defaults.PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE) { KeyboardSwitcher.getInstance().reloadKeyboard() }
}, },
Setting(context, Settings.PREF_SPLIT_SPACER_SCALE_LANDSCAPE, R.string.split_spacer_scale_landscape) { setting -> Setting(context, Settings.PREF_SPLIT_SPACER_SCALE_LANDSCAPE, R.string.split_spacer_scale_landscape) { setting ->
SliderPreference( SliderPreference(
name = setting.title, name = setting.title,
key = setting.key, key = setting.key,
default = SettingsValues.DEFAULT_SIZE_SCALE, default = Defaults.PREF_SPLIT_SPACER_SCALE_LANDSCAPE,
range = 0.5f..2f, range = 0.5f..2f,
description = { "${(100 * it).toInt()}%" } description = { "${(100 * it).toInt()}%" }
) { keyboardNeedsReload = true } ) { keyboardNeedsReload = true }
}, },
Setting(context, Settings.PREF_NARROW_KEY_GAPS, R.string.prefs_narrow_key_gaps) { Setting(context, Settings.PREF_NARROW_KEY_GAPS, R.string.prefs_narrow_key_gaps) {
SwitchPreference(it, false) { keyboardNeedsReload = true } SwitchPreference(it, Defaults.PREF_NARROW_KEY_GAPS) { keyboardNeedsReload = true }
}, },
Setting(context, Settings.PREF_KEYBOARD_HEIGHT_SCALE, R.string.prefs_keyboard_height_scale) { setting -> Setting(context, Settings.PREF_KEYBOARD_HEIGHT_SCALE, R.string.prefs_keyboard_height_scale) { setting ->
SliderPreference( SliderPreference(
name = setting.title, name = setting.title,
key = setting.key, key = setting.key,
default = SettingsValues.DEFAULT_SIZE_SCALE, default = Defaults.PREF_KEYBOARD_HEIGHT_SCALE,
range = 0.5f..1.5f, range = 0.5f..1.5f,
description = { "${(100 * it).toInt()}%" } description = { "${(100 * it).toInt()}%" }
) { keyboardNeedsReload = true } ) { keyboardNeedsReload = true }
@ -252,7 +250,7 @@ fun createAppearanceSettings(context: Context) = listOf(
SliderPreference( SliderPreference(
name = setting.title, name = setting.title,
key = setting.key, key = setting.key,
default = SettingsValues.DEFAULT_SIZE_SCALE, default = Defaults.PREF_BOTTOM_PADDING_SCALE,
range = 0f..5f, range = 0f..5f,
description = { "${(100 * it).toInt()}%" } description = { "${(100 * it).toInt()}%" }
) { keyboardNeedsReload = true } ) { keyboardNeedsReload = true }
@ -261,7 +259,7 @@ fun createAppearanceSettings(context: Context) = listOf(
SliderPreference( SliderPreference(
name = setting.title, name = setting.title,
key = setting.key, key = setting.key,
default = 0f, default = Defaults.PREF_BOTTOM_PADDING_SCALE_LANDSCAPE,
range = 0f..5f, range = 0f..5f,
description = { "${(100 * it).toInt()}%" } description = { "${(100 * it).toInt()}%" }
) { keyboardNeedsReload = true } ) { keyboardNeedsReload = true }
@ -270,7 +268,7 @@ fun createAppearanceSettings(context: Context) = listOf(
SliderPreference( SliderPreference(
name = setting.title, name = setting.title,
key = setting.key, key = setting.key,
default = 0f, default = Defaults.PREF_SIDE_PADDING_SCALE,
range = 0f..3f, range = 0f..3f,
description = { "${(100 * it).toInt()}%" } description = { "${(100 * it).toInt()}%" }
) { keyboardNeedsReload = true } ) { keyboardNeedsReload = true }
@ -279,7 +277,7 @@ fun createAppearanceSettings(context: Context) = listOf(
SliderPreference( SliderPreference(
name = setting.title, name = setting.title,
key = setting.key, key = setting.key,
default = 0f, default = Defaults.PREF_SIDE_PADDING_SCALE_LANDSCAPE,
range = 0f..3f, range = 0f..3f,
description = { "${(100 * it).toInt()}%" } description = { "${(100 * it).toInt()}%" }
) { keyboardNeedsReload = true } ) { keyboardNeedsReload = true }
@ -290,7 +288,7 @@ fun createAppearanceSettings(context: Context) = listOf(
Preference( Preference(
name = setting.title, name = setting.title,
onClick = { showDialog = true }, onClick = { showDialog = true },
description = prefs.getString(setting.key, "") description = prefs.getString(setting.key, Defaults.PREF_SPACE_BAR_TEXT)
) )
if (showDialog) { if (showDialog) {
TextInputDialog( TextInputDialog(
@ -299,7 +297,7 @@ fun createAppearanceSettings(context: Context) = listOf(
prefs.edit().putString(setting.key, it).apply() prefs.edit().putString(setting.key, it).apply()
keyboardNeedsReload = true keyboardNeedsReload = true
}, },
initialText = prefs.getString(setting.key, "") ?: "", initialText = prefs.getString(setting.key, Defaults.PREF_SPACE_BAR_TEXT) ?: "",
title = { Text(setting.title) }, title = { Text(setting.title) },
checkTextValid = { true } checkTextValid = { true }
) )
@ -312,7 +310,7 @@ fun createAppearanceSettings(context: Context) = listOf(
SliderPreference( SliderPreference(
name = def.title, name = def.title,
key = def.key, key = def.key,
default = 1f, default = Defaults.PREF_FONT_SCALE,
range = 0.5f..1.5f, range = 0.5f..1.5f,
description = { "${(100 * it).toInt()}%" } description = { "${(100 * it).toInt()}%" }
) { keyboardNeedsReload = true } ) { keyboardNeedsReload = true }
@ -321,7 +319,7 @@ fun createAppearanceSettings(context: Context) = listOf(
SliderPreference( SliderPreference(
name = setting.title, name = setting.title,
key = setting.key, key = setting.key,
default = 1f, default = Defaults.PREF_EMOJI_FONT_SCALE,
range = 0.5f..1.5f, range = 0.5f..1.5f,
description = { "${(100 * it).toInt()}%" } description = { "${(100 * it).toInt()}%" }
) { keyboardNeedsReload = true } ) { keyboardNeedsReload = true }

View file

@ -16,6 +16,7 @@ import helium314.keyboard.latin.DictionaryFacilitator
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.settings.DebugSettings import helium314.keyboard.latin.settings.DebugSettings
import helium314.keyboard.latin.settings.DebugSettingsFragment import helium314.keyboard.latin.settings.DebugSettingsFragment
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.utils.prefs import helium314.keyboard.latin.utils.prefs
import helium314.keyboard.settings.SettingsContainer import helium314.keyboard.settings.SettingsContainer
import helium314.keyboard.settings.Setting import helium314.keyboard.settings.Setting
@ -78,20 +79,20 @@ private fun createDebugSettings(context: Context) = listOf(
name = setting.title, name = setting.title,
key = setting.key, key = setting.key,
description = stringResource(R.string.version_text, BuildConfig.VERSION_NAME), description = stringResource(R.string.version_text, BuildConfig.VERSION_NAME),
default = false, default = Defaults.PREF_DEBUG_MODE,
) { ) {
if (!it) prefs.edit().putBoolean(DebugSettings.PREF_SHOW_SUGGESTION_INFOS, false).apply() if (!it) prefs.edit().putBoolean(DebugSettings.PREF_SHOW_SUGGESTION_INFOS, false).apply()
needsRestart = true needsRestart = true
} }
}, },
Setting(context, DebugSettings.PREF_SHOW_SUGGESTION_INFOS, R.string.prefs_show_suggestion_infos) { Setting(context, DebugSettings.PREF_SHOW_SUGGESTION_INFOS, R.string.prefs_show_suggestion_infos) {
SwitchPreference(it, false) { keyboardNeedsReload = true } SwitchPreference(it, Defaults.PREF_SHOW_SUGGESTION_INFOS) { keyboardNeedsReload = true }
}, },
Setting(context, DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH, R.string.prefs_force_non_distinct_multitouch) { Setting(context, DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH, R.string.prefs_force_non_distinct_multitouch) {
SwitchPreference(it, false) { needsRestart = true } SwitchPreference(it, Defaults.PREF_FORCE_NON_DISTINCT_MULTITOUCH) { needsRestart = true }
}, },
Setting(context, DebugSettings.PREF_SLIDING_KEY_INPUT_PREVIEW, R.string.sliding_key_input_preview, R.string.sliding_key_input_preview_summary) { def -> Setting(context, DebugSettings.PREF_SLIDING_KEY_INPUT_PREVIEW, R.string.sliding_key_input_preview, R.string.sliding_key_input_preview_summary) { def ->
SwitchPreference(def, false) SwitchPreference(def, Defaults.PREF_SLIDING_KEY_INPUT_PREVIEW)
}, },
) + DictionaryFacilitator.DYNAMIC_DICTIONARY_TYPES.map { type -> ) + DictionaryFacilitator.DYNAMIC_DICTIONARY_TYPES.map { type ->
Setting(context, DebugSettingsFragment.PREF_KEY_DUMP_DICT_PREFIX + type, R.string.button_default) { Setting(context, DebugSettingsFragment.PREF_KEY_DUMP_DICT_PREFIX + type, R.string.button_default) {

View file

@ -9,6 +9,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.Log import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.getActivity import helium314.keyboard.latin.utils.getActivity
@ -30,8 +31,8 @@ fun GestureTypingScreen(
val b = (LocalContext.current.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState() val b = (LocalContext.current.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState()
if ((b?.value ?: 0) < 0) if ((b?.value ?: 0) < 0)
Log.v("irrelevant", "stupid way to trigger recomposition on preference change") Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
val gestureFloatingPreviewEnabled = prefs.getBoolean(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, true) val gestureFloatingPreviewEnabled = prefs.getBoolean(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, Defaults.PREF_GESTURE_FLOATING_PREVIEW_TEXT)
val gestureEnabled = prefs.getBoolean(Settings.PREF_GESTURE_INPUT, true) val gestureEnabled = prefs.getBoolean(Settings.PREF_GESTURE_INPUT, Defaults.PREF_GESTURE_INPUT)
val items = listOf( val items = listOf(
Settings.PREF_GESTURE_INPUT, Settings.PREF_GESTURE_INPUT,
if (gestureEnabled) if (gestureEnabled)
@ -44,7 +45,8 @@ fun GestureTypingScreen(
Settings.PREF_GESTURE_SPACE_AWARE else null, Settings.PREF_GESTURE_SPACE_AWARE else null,
if (gestureEnabled) if (gestureEnabled)
Settings.PREF_GESTURE_FAST_TYPING_COOLDOWN else null, Settings.PREF_GESTURE_FAST_TYPING_COOLDOWN else null,
if (gestureEnabled && (prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, true) || gestureFloatingPreviewEnabled)) if (gestureEnabled &&
(prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, Defaults.PREF_GESTURE_PREVIEW_TRAIL) || gestureFloatingPreviewEnabled))
Settings.PREF_GESTURE_TRAIL_FADEOUT_DURATION else null Settings.PREF_GESTURE_TRAIL_FADEOUT_DURATION else null
) )
SearchSettingsScreen( SearchSettingsScreen(
@ -56,21 +58,21 @@ fun GestureTypingScreen(
fun createGestureTypingSettings(context: Context) = listOf( fun createGestureTypingSettings(context: Context) = listOf(
Setting(context, Settings.PREF_GESTURE_INPUT, R.string.gesture_input, R.string.gesture_input_summary) { Setting(context, Settings.PREF_GESTURE_INPUT, R.string.gesture_input, R.string.gesture_input_summary) {
SwitchPreference(it, true) SwitchPreference(it, Defaults.PREF_GESTURE_INPUT)
}, },
Setting(context, Settings.PREF_GESTURE_PREVIEW_TRAIL, R.string.gesture_preview_trail) { Setting(context, Settings.PREF_GESTURE_PREVIEW_TRAIL, R.string.gesture_preview_trail) {
SwitchPreference(it, true) SwitchPreference(it, Defaults.PREF_GESTURE_PREVIEW_TRAIL)
}, },
Setting(context, Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, Setting(context, Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT,
R.string.gesture_floating_preview_static, R.string.gesture_floating_preview_static_summary) R.string.gesture_floating_preview_static, R.string.gesture_floating_preview_static_summary)
{ {
SwitchPreference(it, true) SwitchPreference(it, Defaults.PREF_GESTURE_FLOATING_PREVIEW_TEXT)
}, },
Setting(context, Settings.PREF_GESTURE_FLOATING_PREVIEW_DYNAMIC, Setting(context, Settings.PREF_GESTURE_FLOATING_PREVIEW_DYNAMIC,
R.string.gesture_floating_preview_text, R.string.gesture_floating_preview_dynamic_summary) R.string.gesture_floating_preview_text, R.string.gesture_floating_preview_dynamic_summary)
{ def -> { def ->
val ctx = LocalContext.current val ctx = LocalContext.current
SwitchPreference(def, true) { SwitchPreference(def, Defaults.PREF_GESTURE_FLOATING_PREVIEW_DYNAMIC) {
// is this complexity and 2 pref keys for one setting really needed? // is this complexity and 2 pref keys for one setting really needed?
// default value is based on system reduced motion // default value is based on system reduced motion
val default = Settings.readGestureDynamicPreviewDefault(ctx) val default = Settings.readGestureDynamicPreviewDefault(ctx)
@ -81,13 +83,13 @@ fun createGestureTypingSettings(context: Context) = listOf(
} }
}, },
Setting(context, Settings.PREF_GESTURE_SPACE_AWARE, R.string.gesture_space_aware, R.string.gesture_space_aware_summary) { Setting(context, Settings.PREF_GESTURE_SPACE_AWARE, R.string.gesture_space_aware, R.string.gesture_space_aware_summary) {
SwitchPreference(it, false) SwitchPreference(it, Defaults.PREF_GESTURE_SPACE_AWARE)
}, },
Setting(context, Settings.PREF_GESTURE_FAST_TYPING_COOLDOWN, R.string.gesture_fast_typing_cooldown) { def -> Setting(context, Settings.PREF_GESTURE_FAST_TYPING_COOLDOWN, R.string.gesture_fast_typing_cooldown) { def ->
SliderPreference( SliderPreference(
name = def.title, name = def.title,
key = def.key, key = def.key,
default = 500, default = Defaults.PREF_GESTURE_FAST_TYPING_COOLDOWN,
range = 0f..500f, range = 0f..500f,
description = { description = {
if (it <= 0) stringResource(R.string.gesture_fast_typing_cooldown_instant) if (it <= 0) stringResource(R.string.gesture_fast_typing_cooldown_instant)
@ -99,7 +101,7 @@ fun createGestureTypingSettings(context: Context) = listOf(
SliderPreference( SliderPreference(
name = def.title, name = def.title,
key = def.key, key = def.key,
default = 800, default = Defaults.PREF_GESTURE_TRAIL_FADEOUT_DURATION,
range = 100f..1900f, range = 100f..1900f,
description = { stringResource(R.string.abbreviation_unit_milliseconds, (it + 100).toString()) }, description = { stringResource(R.string.abbreviation_unit_milliseconds, (it + 100).toString()) },
stepSize = 10, stepSize = 10,

View file

@ -7,17 +7,14 @@ import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import helium314.keyboard.keyboard.KeyboardLayoutSet import helium314.keyboard.keyboard.KeyboardLayoutSet
import helium314.keyboard.latin.AudioAndHapticFeedbackManager import helium314.keyboard.latin.AudioAndHapticFeedbackManager
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.Log import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.POPUP_KEYS_LABEL_DEFAULT
import helium314.keyboard.latin.utils.POPUP_KEYS_ORDER_DEFAULT
import helium314.keyboard.latin.utils.getActivity import helium314.keyboard.latin.utils.getActivity
import helium314.keyboard.latin.utils.getEnabledSubtypes import helium314.keyboard.latin.utils.getEnabledSubtypes
import helium314.keyboard.latin.utils.locale import helium314.keyboard.latin.utils.locale
@ -44,24 +41,26 @@ fun PreferencesScreen(
val items = listOf( val items = listOf(
R.string.settings_category_input, R.string.settings_category_input,
Settings.PREF_SHOW_HINTS, Settings.PREF_SHOW_HINTS,
if (prefs.getBoolean(Settings.PREF_SHOW_HINTS, true)) if (prefs.getBoolean(Settings.PREF_SHOW_HINTS, Defaults.PREF_SHOW_HINTS))
Settings.PREF_POPUP_KEYS_LABELS_ORDER else null, Settings.PREF_POPUP_KEYS_LABELS_ORDER else null,
Settings.PREF_POPUP_KEYS_ORDER, Settings.PREF_POPUP_KEYS_ORDER,
Settings.PREF_SHOW_POPUP_HINTS, Settings.PREF_SHOW_POPUP_HINTS,
Settings.PREF_POPUP_ON, Settings.PREF_POPUP_ON,
Settings.PREF_VIBRATE_ON, if (AudioAndHapticFeedbackManager.getInstance().hasVibrator())
if (prefs.getBoolean(Settings.PREF_VIBRATE_ON, true)) Settings.PREF_VIBRATE_ON else null,
if (prefs.getBoolean(Settings.PREF_VIBRATE_ON, Defaults.PREF_VIBRATE_ON))
Settings.PREF_VIBRATION_DURATION_SETTINGS else null, Settings.PREF_VIBRATION_DURATION_SETTINGS else null,
if (prefs.getBoolean(Settings.PREF_VIBRATE_ON, true)) if (prefs.getBoolean(Settings.PREF_VIBRATE_ON, Defaults.PREF_VIBRATE_ON))
Settings.PREF_VIBRATE_IN_DND_MODE else null, Settings.PREF_VIBRATE_IN_DND_MODE else null,
Settings.PREF_SOUND_ON, Settings.PREF_SOUND_ON,
if (prefs.getBoolean(Settings.PREF_SOUND_ON, true)) if (prefs.getBoolean(Settings.PREF_SOUND_ON, Defaults.PREF_SOUND_ON))
Settings.PREF_KEYPRESS_SOUND_VOLUME else null, Settings.PREF_KEYPRESS_SOUND_VOLUME else null,
R.string.settings_category_additional_keys, R.string.settings_category_additional_keys,
Settings.PREF_SHOW_NUMBER_ROW, Settings.PREF_SHOW_NUMBER_ROW,
if (getEnabledSubtypes(prefs, true).any { it.locale().language in localesWithLocalizedNumberRow }) if (getEnabledSubtypes(prefs, true).any { it.locale().language in localesWithLocalizedNumberRow })
Settings.PREF_LOCALIZED_NUMBER_ROW else null, Settings.PREF_LOCALIZED_NUMBER_ROW else null,
if (prefs.getBoolean(Settings.PREF_SHOW_HINTS, true) && prefs.getBoolean(Settings.PREF_SHOW_NUMBER_ROW, false)) if (prefs.getBoolean(Settings.PREF_SHOW_HINTS, Defaults.PREF_SHOW_HINTS)
&& prefs.getBoolean(Settings.PREF_SHOW_NUMBER_ROW, Defaults.PREF_SHOW_NUMBER_ROW))
Settings.PREF_SHOW_NUMBER_ROW_HINTS else null, Settings.PREF_SHOW_NUMBER_ROW_HINTS else null,
Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY, Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY,
Settings.PREF_LANGUAGE_SWITCH_KEY, Settings.PREF_LANGUAGE_SWITCH_KEY,
@ -69,7 +68,7 @@ fun PreferencesScreen(
Settings.PREF_REMOVE_REDUNDANT_POPUPS, Settings.PREF_REMOVE_REDUNDANT_POPUPS,
R.string.settings_category_clipboard_history, R.string.settings_category_clipboard_history,
Settings.PREF_ENABLE_CLIPBOARD_HISTORY, Settings.PREF_ENABLE_CLIPBOARD_HISTORY,
if (prefs.getBoolean(Settings.PREF_ENABLE_CLIPBOARD_HISTORY, true)) if (prefs.getBoolean(Settings.PREF_ENABLE_CLIPBOARD_HISTORY, Defaults.PREF_ENABLE_CLIPBOARD_HISTORY))
Settings.PREF_CLIPBOARD_HISTORY_RETENTION_TIME else null Settings.PREF_CLIPBOARD_HISTORY_RETENTION_TIME else null
) )
SearchSettingsScreen( SearchSettingsScreen(
@ -81,47 +80,45 @@ fun PreferencesScreen(
fun createPreferencesSettings(context: Context) = listOf( fun createPreferencesSettings(context: Context) = listOf(
Setting(context, Settings.PREF_SHOW_HINTS, R.string.show_hints, R.string.show_hints_summary) { Setting(context, Settings.PREF_SHOW_HINTS, R.string.show_hints, R.string.show_hints_summary) {
SwitchPreference(it, true) SwitchPreference(it, Defaults.PREF_SHOW_HINTS)
}, },
Setting(context, Settings.PREF_POPUP_KEYS_LABELS_ORDER, R.string.hint_source) { Setting(context, Settings.PREF_POPUP_KEYS_LABELS_ORDER, R.string.hint_source) {
ReorderSwitchPreference(it, POPUP_KEYS_LABEL_DEFAULT) ReorderSwitchPreference(it, Defaults.PREF_POPUP_KEYS_LABELS_ORDER)
}, },
Setting(context, Settings.PREF_POPUP_KEYS_ORDER, R.string.popup_order) { Setting(context, Settings.PREF_POPUP_KEYS_ORDER, R.string.popup_order) {
ReorderSwitchPreference(it, POPUP_KEYS_ORDER_DEFAULT) ReorderSwitchPreference(it, Defaults.PREF_POPUP_KEYS_ORDER)
}, },
Setting(context, Settings.PREF_SHOW_POPUP_HINTS, R.string.show_popup_hints, R.string.show_popup_hints_summary) { Setting(context, Settings.PREF_SHOW_POPUP_HINTS, R.string.show_popup_hints, R.string.show_popup_hints_summary) {
SwitchPreference(it, false) { keyboardNeedsReload = true } SwitchPreference(it, Defaults.PREF_SHOW_POPUP_HINTS) { keyboardNeedsReload = true }
}, },
Setting(context, Settings.PREF_POPUP_ON, R.string.popup_on_keypress) { Setting(context, Settings.PREF_POPUP_ON, R.string.popup_on_keypress) {
val dm = LocalContext.current.resources.displayMetrics SwitchPreference(it, Defaults.PREF_POPUP_ON)
val px600 = with(LocalDensity.current) { 600.dp.toPx() }
SwitchPreference(it, dm.widthPixels >= px600 || dm.heightPixels >= px600)
}, },
Setting(context, Settings.PREF_VIBRATE_ON, R.string.vibrate_on_keypress) { Setting(context, Settings.PREF_VIBRATE_ON, R.string.vibrate_on_keypress) {
SwitchPreference(it, false) SwitchPreference(it, Defaults.PREF_VIBRATE_ON)
}, },
Setting(context, Settings.PREF_VIBRATE_IN_DND_MODE, R.string.vibrate_in_dnd_mode) { Setting(context, Settings.PREF_VIBRATE_IN_DND_MODE, R.string.vibrate_in_dnd_mode) {
SwitchPreference(it, false) SwitchPreference(it, Defaults.PREF_VIBRATE_IN_DND_MODE)
}, },
Setting(context, Settings.PREF_SOUND_ON, R.string.sound_on_keypress) { Setting(context, Settings.PREF_SOUND_ON, R.string.sound_on_keypress) {
SwitchPreference(it, false) SwitchPreference(it, Defaults.PREF_SOUND_ON)
}, },
Setting(context, Settings.PREF_ENABLE_CLIPBOARD_HISTORY, Setting(context, Settings.PREF_ENABLE_CLIPBOARD_HISTORY,
R.string.enable_clipboard_history, R.string.enable_clipboard_history_summary) R.string.enable_clipboard_history, R.string.enable_clipboard_history_summary)
{ {
SwitchPreference(it, true) SwitchPreference(it, Defaults.PREF_ENABLE_CLIPBOARD_HISTORY)
}, },
Setting(context, Settings.PREF_SHOW_NUMBER_ROW, R.string.number_row, R.string.number_row_summary) { Setting(context, Settings.PREF_SHOW_NUMBER_ROW, R.string.number_row, R.string.number_row_summary) {
SwitchPreference(it, false) { keyboardNeedsReload = true } SwitchPreference(it, Defaults.PREF_SHOW_NUMBER_ROW) { keyboardNeedsReload = true }
}, },
Setting(context, Settings.PREF_LOCALIZED_NUMBER_ROW, R.string.localized_number_row, R.string.localized_number_row_summary) { Setting(context, Settings.PREF_LOCALIZED_NUMBER_ROW, R.string.localized_number_row, R.string.localized_number_row_summary) {
SwitchPreference(it, true) { KeyboardLayoutSet.onSystemLocaleChanged() } SwitchPreference(it, Defaults.PREF_LOCALIZED_NUMBER_ROW) { KeyboardLayoutSet.onSystemLocaleChanged() }
}, },
Setting(context, Settings.PREF_SHOW_NUMBER_ROW_HINTS, R.string.number_row_hints) { Setting(context, Settings.PREF_SHOW_NUMBER_ROW_HINTS, R.string.number_row_hints) {
SwitchPreference(it, false) { keyboardNeedsReload = true } SwitchPreference(it, Defaults.PREF_SHOW_NUMBER_ROW_HINTS) { keyboardNeedsReload = true }
}, },
Setting(context, Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY, R.string.show_language_switch_key) { Setting(context, Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY, R.string.show_language_switch_key) {
SwitchPreference(it, false) { keyboardNeedsReload = true } SwitchPreference(it, Defaults.PREF_SHOW_LANGUAGE_SWITCH_KEY) { keyboardNeedsReload = true }
}, },
Setting(context, Settings.PREF_LANGUAGE_SWITCH_KEY, R.string.language_switch_key_behavior) { Setting(context, Settings.PREF_LANGUAGE_SWITCH_KEY, R.string.language_switch_key_behavior) {
ListPreference( ListPreference(
@ -131,22 +128,22 @@ fun createPreferencesSettings(context: Context) = listOf(
"input_method" to stringResource(R.string.language_switch_key_switch_input_method), "input_method" to stringResource(R.string.language_switch_key_switch_input_method),
"both" to stringResource(R.string.language_switch_key_switch_both) "both" to stringResource(R.string.language_switch_key_switch_both)
), ),
"internal" Defaults.PREF_LANGUAGE_SWITCH_KEY
) { keyboardNeedsReload = true } ) { keyboardNeedsReload = true }
}, },
Setting(context, Settings.PREF_SHOW_EMOJI_KEY, R.string.show_emoji_key) { Setting(context, Settings.PREF_SHOW_EMOJI_KEY, R.string.show_emoji_key) {
SwitchPreference(it, false) SwitchPreference(it, Defaults.PREF_SHOW_EMOJI_KEY)
}, },
Setting(context, Settings.PREF_REMOVE_REDUNDANT_POPUPS, Setting(context, Settings.PREF_REMOVE_REDUNDANT_POPUPS,
R.string.remove_redundant_popups, R.string.remove_redundant_popups_summary) R.string.remove_redundant_popups, R.string.remove_redundant_popups_summary)
{ {
SwitchPreference(it, false) { keyboardNeedsReload = true } SwitchPreference(it, Defaults.PREF_REMOVE_REDUNDANT_POPUPS) { keyboardNeedsReload = true }
}, },
Setting(context, Settings.PREF_CLIPBOARD_HISTORY_RETENTION_TIME, R.string.clipboard_history_retention_time) { setting -> Setting(context, Settings.PREF_CLIPBOARD_HISTORY_RETENTION_TIME, R.string.clipboard_history_retention_time) { setting ->
SliderPreference( SliderPreference(
name = setting.title, name = setting.title,
key = setting.key, key = setting.key,
default = 10, default = Defaults.PREF_CLIPBOARD_HISTORY_RETENTION_TIME,
description = { description = {
if (it < 0) stringResource(R.string.settings_no_limit) if (it < 0) stringResource(R.string.settings_no_limit)
else stringResource(R.string.abbreviation_unit_minutes, it.toString()) else stringResource(R.string.abbreviation_unit_minutes, it.toString())
@ -158,7 +155,7 @@ fun createPreferencesSettings(context: Context) = listOf(
SliderPreference( SliderPreference(
name = setting.title, name = setting.title,
key = setting.key, key = setting.key,
default = -1, default = Defaults.PREF_VIBRATION_DURATION_SETTINGS,
description = { description = {
if (it < 0) stringResource(R.string.settings_system_default) if (it < 0) stringResource(R.string.settings_system_default)
else stringResource(R.string.abbreviation_unit_milliseconds, it.toString()) else stringResource(R.string.abbreviation_unit_milliseconds, it.toString())
@ -172,7 +169,7 @@ fun createPreferencesSettings(context: Context) = listOf(
SliderPreference( SliderPreference(
name = setting.title, name = setting.title,
key = setting.key, key = setting.key,
default = -0.01f, default = Defaults.PREF_KEYPRESS_SOUND_VOLUME,
description = { description = {
if (it < 0) stringResource(R.string.settings_system_default) if (it < 0) stringResource(R.string.settings_system_default)
else (it * 100).toInt().toString() else (it * 100).toInt().toString()

View file

@ -23,6 +23,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.permissions.PermissionsUtil import helium314.keyboard.latin.permissions.PermissionsUtil
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.settings.UserDictionaryListFragment import helium314.keyboard.latin.settings.UserDictionaryListFragment
import helium314.keyboard.latin.utils.Log import helium314.keyboard.latin.utils.Log
@ -49,8 +50,8 @@ fun TextCorrectionScreen(
val b = (LocalContext.current.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState() val b = (LocalContext.current.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState()
if ((b?.value ?: 0) < 0) if ((b?.value ?: 0) < 0)
Log.v("irrelevant", "stupid way to trigger recomposition on preference change") Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
val autocorrectEnabled = prefs.getBoolean(Settings.PREF_AUTO_CORRECTION, true) val autocorrectEnabled = prefs.getBoolean(Settings.PREF_AUTO_CORRECTION, Defaults.PREF_AUTO_CORRECTION)
val suggestionsEnabled = prefs.getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true) val suggestionsEnabled = prefs.getBoolean(Settings.PREF_SHOW_SUGGESTIONS, Defaults.PREF_SHOW_SUGGESTIONS)
val items = listOf( val items = listOf(
SettingsWithoutKey.EDIT_PERSONAL_DICTIONARY, SettingsWithoutKey.EDIT_PERSONAL_DICTIONARY,
R.string.settings_category_correction, R.string.settings_category_correction,
@ -70,7 +71,7 @@ fun TextCorrectionScreen(
Settings.PREF_BIGRAM_PREDICTIONS, Settings.PREF_BIGRAM_PREDICTIONS,
Settings.PREF_SUGGEST_CLIPBOARD_CONTENT, Settings.PREF_SUGGEST_CLIPBOARD_CONTENT,
Settings.PREF_USE_CONTACTS, Settings.PREF_USE_CONTACTS,
if (prefs.getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true)) if (prefs.getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, Defaults.PREF_KEY_USE_PERSONALIZED_DICTS))
Settings.PREF_ADD_TO_PERSONAL_DICTIONARY else null Settings.PREF_ADD_TO_PERSONAL_DICTIONARY else null
) )
SearchSettingsScreen( SearchSettingsScreen(
@ -97,22 +98,22 @@ fun createCorrectionSettings(context: Context) = listOf(
Setting(context, Settings.PREF_BLOCK_POTENTIALLY_OFFENSIVE, Setting(context, Settings.PREF_BLOCK_POTENTIALLY_OFFENSIVE,
R.string.prefs_block_potentially_offensive_title, R.string.prefs_block_potentially_offensive_summary R.string.prefs_block_potentially_offensive_title, R.string.prefs_block_potentially_offensive_summary
) { ) {
SwitchPreference(it, true) SwitchPreference(it, Defaults.PREF_BLOCK_POTENTIALLY_OFFENSIVE)
}, },
Setting(context, Settings.PREF_AUTO_CORRECTION, Setting(context, Settings.PREF_AUTO_CORRECTION,
R.string.autocorrect, R.string.auto_correction_summary R.string.autocorrect, R.string.auto_correction_summary
) { ) {
SwitchPreference(it, true) SwitchPreference(it, Defaults.PREF_AUTO_CORRECTION)
}, },
Setting(context, Settings.PREF_MORE_AUTO_CORRECTION, Setting(context, Settings.PREF_MORE_AUTO_CORRECTION,
R.string.more_autocorrect, R.string.more_autocorrect_summary R.string.more_autocorrect, R.string.more_autocorrect_summary
) { ) {
SwitchPreference(it, true) // todo (later): shouldn't it better be false? SwitchPreference(it, Defaults.PREF_MORE_AUTO_CORRECTION)
}, },
Setting(context, Settings.PREF_AUTOCORRECT_SHORTCUTS, Setting(context, Settings.PREF_AUTOCORRECT_SHORTCUTS,
R.string.auto_correct_shortcuts, R.string.auto_correct_shortcuts_summary R.string.auto_correct_shortcuts, R.string.auto_correct_shortcuts_summary
) { ) {
SwitchPreference(it, true) SwitchPreference(it, Defaults.PREF_AUTOCORRECT_SHORTCUTS)
}, },
Setting(context, Settings.PREF_AUTO_CORRECTION_CONFIDENCE, R.string.auto_correction_confidence) { Setting(context, Settings.PREF_AUTO_CORRECTION_CONFIDENCE, R.string.auto_correction_confidence) {
val items = listOf( val items = listOf(
@ -120,38 +121,38 @@ fun createCorrectionSettings(context: Context) = listOf(
stringResource(R.string.auto_correction_threshold_mode_aggressive) to "1", stringResource(R.string.auto_correction_threshold_mode_aggressive) to "1",
stringResource(R.string.auto_correction_threshold_mode_very_aggressive) to "2", stringResource(R.string.auto_correction_threshold_mode_very_aggressive) to "2",
) )
ListPreference(it, items, "0") ListPreference(it, items, Defaults.PREF_AUTO_CORRECTION_CONFIDENCE)
}, },
Setting(context, Settings.PREF_AUTO_CAP, Setting(context, Settings.PREF_AUTO_CAP,
R.string.auto_cap, R.string.auto_cap_summary R.string.auto_cap, R.string.auto_cap_summary
) { ) {
SwitchPreference(it, true) SwitchPreference(it, Defaults.PREF_AUTO_CAP)
}, },
Setting(context, Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, Setting(context, Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD,
R.string.use_double_space_period, R.string.use_double_space_period_summary R.string.use_double_space_period, R.string.use_double_space_period_summary
) { ) {
SwitchPreference(it, true) SwitchPreference(it, Defaults.PREF_KEY_USE_DOUBLE_SPACE_PERIOD)
}, },
Setting(context, Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, Setting(context, Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION,
R.string.autospace_after_punctuation, R.string.autospace_after_punctuation_summary R.string.autospace_after_punctuation, R.string.autospace_after_punctuation_summary
) { ) {
SwitchPreference(it, false) SwitchPreference(it, Defaults.PREF_AUTOSPACE_AFTER_PUNCTUATION)
}, },
Setting(context, Settings.PREF_SHOW_SUGGESTIONS, Setting(context, Settings.PREF_SHOW_SUGGESTIONS,
R.string.prefs_show_suggestions, R.string.prefs_show_suggestions_summary R.string.prefs_show_suggestions, R.string.prefs_show_suggestions_summary
) { ) {
SwitchPreference(it, true) SwitchPreference(it, Defaults.PREF_SHOW_SUGGESTIONS)
}, },
Setting(context, Settings.PREF_ALWAYS_SHOW_SUGGESTIONS, Setting(context, Settings.PREF_ALWAYS_SHOW_SUGGESTIONS,
R.string.prefs_always_show_suggestions, R.string.prefs_always_show_suggestions_summary R.string.prefs_always_show_suggestions, R.string.prefs_always_show_suggestions_summary
) { ) {
SwitchPreference(it, false) SwitchPreference(it, Defaults.PREF_ALWAYS_SHOW_SUGGESTIONS)
}, },
Setting(context, Settings.PREF_KEY_USE_PERSONALIZED_DICTS, Setting(context, Settings.PREF_KEY_USE_PERSONALIZED_DICTS,
R.string.use_personalized_dicts, R.string.use_personalized_dicts_summary R.string.use_personalized_dicts, R.string.use_personalized_dicts_summary
) { setting -> ) { setting ->
var showConfirmDialog by rememberSaveable { mutableStateOf(false) } var showConfirmDialog by rememberSaveable { mutableStateOf(false) }
SwitchPreference(setting, true, SwitchPreference(setting, Defaults.PREF_KEY_USE_PERSONALIZED_DICTS,
allowCheckedChange = { allowCheckedChange = {
showConfirmDialog = !it showConfirmDialog = !it
it it
@ -172,17 +173,17 @@ fun createCorrectionSettings(context: Context) = listOf(
Setting(context, Settings.PREF_BIGRAM_PREDICTIONS, Setting(context, Settings.PREF_BIGRAM_PREDICTIONS,
R.string.bigram_prediction, R.string.bigram_prediction_summary R.string.bigram_prediction, R.string.bigram_prediction_summary
) { ) {
SwitchPreference(it, true) { keyboardNeedsReload = true } SwitchPreference(it, Defaults.PREF_BIGRAM_PREDICTIONS) { keyboardNeedsReload = true }
}, },
Setting(context, Settings.PREF_CENTER_SUGGESTION_TEXT_TO_ENTER, Setting(context, Settings.PREF_CENTER_SUGGESTION_TEXT_TO_ENTER,
R.string.center_suggestion_text_to_enter, R.string.center_suggestion_text_to_enter_summary R.string.center_suggestion_text_to_enter, R.string.center_suggestion_text_to_enter_summary
) { ) {
SwitchPreference(it, false) SwitchPreference(it, Defaults.PREF_CENTER_SUGGESTION_TEXT_TO_ENTER)
}, },
Setting(context, Settings.PREF_SUGGEST_CLIPBOARD_CONTENT, Setting(context, Settings.PREF_SUGGEST_CLIPBOARD_CONTENT,
R.string.suggest_clipboard_content, R.string.suggest_clipboard_content_summary R.string.suggest_clipboard_content, R.string.suggest_clipboard_content_summary
) { ) {
SwitchPreference(it, true) SwitchPreference(it, Defaults.PREF_SUGGEST_CLIPBOARD_CONTENT)
}, },
Setting(context, Settings.PREF_USE_CONTACTS, Setting(context, Settings.PREF_USE_CONTACTS,
R.string.use_contacts_dict, R.string.use_contacts_dict_summary R.string.use_contacts_dict, R.string.use_contacts_dict_summary
@ -194,7 +195,7 @@ fun createCorrectionSettings(context: Context) = listOf(
if (granted) if (granted)
activity.prefs().edit().putBoolean(setting.key, true).apply() activity.prefs().edit().putBoolean(setting.key, true).apply()
} }
SwitchPreference(setting, false, SwitchPreference(setting, Defaults.PREF_USE_CONTACTS,
allowCheckedChange = { allowCheckedChange = {
if (it && !granted) { if (it && !granted) {
launcher.launch(Manifest.permission.READ_CONTACTS) launcher.launch(Manifest.permission.READ_CONTACTS)
@ -206,7 +207,7 @@ fun createCorrectionSettings(context: Context) = listOf(
Setting(context, Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, Setting(context, Settings.PREF_ADD_TO_PERSONAL_DICTIONARY,
R.string.add_to_personal_dictionary, R.string.add_to_personal_dictionary_summary R.string.add_to_personal_dictionary, R.string.add_to_personal_dictionary_summary
) { ) {
SwitchPreference(it, false) SwitchPreference(it, Defaults.PREF_ADD_TO_PERSONAL_DICTIONARY)
}, },
) )

View file

@ -25,10 +25,8 @@ import androidx.core.graphics.drawable.toBitmap
import androidx.core.util.TypedValueCompat import androidx.core.util.TypedValueCompat
import helium314.keyboard.keyboard.internal.KeyboardIconsSet import helium314.keyboard.keyboard.internal.KeyboardIconsSet
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.defaultClipboardToolbarPref
import helium314.keyboard.latin.utils.defaultPinnedToolbarPref
import helium314.keyboard.latin.utils.defaultToolbarPref
import helium314.keyboard.settings.SettingsContainer import helium314.keyboard.settings.SettingsContainer
import helium314.keyboard.settings.SettingsWithoutKey import helium314.keyboard.settings.SettingsWithoutKey
import helium314.keyboard.settings.Setting import helium314.keyboard.settings.Setting
@ -64,13 +62,13 @@ fun ToolbarScreen(
fun createToolbarSettings(context: Context) = listOf( fun createToolbarSettings(context: Context) = listOf(
Setting(context, Settings.PREF_TOOLBAR_KEYS, R.string.toolbar_keys) { Setting(context, Settings.PREF_TOOLBAR_KEYS, R.string.toolbar_keys) {
ReorderSwitchPreference(it, defaultToolbarPref) ReorderSwitchPreference(it, Defaults.PREF_TOOLBAR_KEYS)
}, },
Setting(context, Settings.PREF_PINNED_TOOLBAR_KEYS, R.string.pinned_toolbar_keys) { Setting(context, Settings.PREF_PINNED_TOOLBAR_KEYS, R.string.pinned_toolbar_keys) {
ReorderSwitchPreference(it, defaultPinnedToolbarPref) ReorderSwitchPreference(it, Defaults.PREF_PINNED_TOOLBAR_KEYS)
}, },
Setting(context, Settings.PREF_CLIPBOARD_TOOLBAR_KEYS, R.string.clipboard_toolbar_keys) { Setting(context, Settings.PREF_CLIPBOARD_TOOLBAR_KEYS, R.string.clipboard_toolbar_keys) {
ReorderSwitchPreference(it, defaultClipboardToolbarPref) ReorderSwitchPreference(it, Defaults.PREF_CLIPBOARD_TOOLBAR_KEYS)
}, },
Setting(context, SettingsWithoutKey.CUSTOM_KEY_CODES, R.string.customize_toolbar_key_codes) { Setting(context, SettingsWithoutKey.CUSTOM_KEY_CODES, R.string.customize_toolbar_key_codes) {
var showDialog by rememberSaveable { mutableStateOf(false) } var showDialog by rememberSaveable { mutableStateOf(false) }
@ -87,20 +85,20 @@ fun createToolbarSettings(context: Context) = listOf(
Setting(context, Settings.PREF_QUICK_PIN_TOOLBAR_KEYS, Setting(context, Settings.PREF_QUICK_PIN_TOOLBAR_KEYS,
R.string.quick_pin_toolbar_keys, R.string.quick_pin_toolbar_keys_summary) R.string.quick_pin_toolbar_keys, R.string.quick_pin_toolbar_keys_summary)
{ {
SwitchPreference(it, false,) { keyboardNeedsReload = true } SwitchPreference(it, Defaults.PREF_QUICK_PIN_TOOLBAR_KEYS) { keyboardNeedsReload = true }
}, },
Setting(context, Settings.PREF_AUTO_SHOW_TOOLBAR, R.string.auto_show_toolbar, R.string.auto_show_toolbar_summary) Setting(context, Settings.PREF_AUTO_SHOW_TOOLBAR, R.string.auto_show_toolbar, R.string.auto_show_toolbar_summary)
{ {
SwitchPreference(it, false,) SwitchPreference(it, Defaults.PREF_AUTO_SHOW_TOOLBAR)
}, },
Setting(context, Settings.PREF_AUTO_HIDE_TOOLBAR, R.string.auto_hide_toolbar, R.string.auto_hide_toolbar_summary) Setting(context, Settings.PREF_AUTO_HIDE_TOOLBAR, R.string.auto_hide_toolbar, R.string.auto_hide_toolbar_summary)
{ {
SwitchPreference(it, false,) SwitchPreference(it, Defaults.PREF_AUTO_HIDE_TOOLBAR)
}, },
Setting(context, Settings.PREF_VARIABLE_TOOLBAR_DIRECTION, Setting(context, Settings.PREF_VARIABLE_TOOLBAR_DIRECTION,
R.string.var_toolbar_direction, R.string.var_toolbar_direction_summary) R.string.var_toolbar_direction, R.string.var_toolbar_direction_summary)
{ {
SwitchPreference(it, true,) SwitchPreference(it, Defaults.PREF_VARIABLE_TOOLBAR_DIRECTION)
} }
) )

View file

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2012 The Android Open Source Project
modified
SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Predefined subtypes (language:layout[:extraValue]) -->
<string-array name="predefined_subtypes" translatable="false">
<item>de:qwerty:AsciiCapable</item>
<item>fr:qwertz:AsciiCapable</item>
<item>hu:qwerty:AsciiCapable</item>
</string-array>
</resources>