allow customizing number row

so users can do #558 themselves
This commit is contained in:
Helium314 2024-08-26 23:11:59 +02:00
parent 44eb296d38
commit 3306ffb849
3 changed files with 13 additions and 3 deletions

View file

@ -17,10 +17,12 @@ import helium314.keyboard.keyboard.internal.keyboard_parser.floris.TextKeyData
import helium314.keyboard.latin.common.isEmoji
import helium314.keyboard.latin.define.DebugFlags
import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.CUSTOM_LAYOUT_PREFIX
import helium314.keyboard.latin.utils.POPUP_KEYS_LAYOUT
import helium314.keyboard.latin.utils.POPUP_KEYS_NUMBER
import helium314.keyboard.latin.utils.ScriptUtils
import helium314.keyboard.latin.utils.ScriptUtils.script
import helium314.keyboard.latin.utils.getCustomLayoutFiles
import helium314.keyboard.latin.utils.replaceFirst
import helium314.keyboard.latin.utils.splitAt
import helium314.keyboard.latin.utils.sumOf
@ -269,7 +271,7 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co
}
private fun getNumberRow(): MutableList<KeyData> {
val row = RawKeyboardParser.parseLayout("number_row.txt", params, context).first()
val row = RawKeyboardParser.parseLayout(LAYOUT_NUMBER_ROW, params, context).first()
val localizedNumbers = params.mLocaleKeyboardInfos.localizedNumberKeys
if (localizedNumbers?.size != 10) return row
if (Settings.getInstance().current.mLocalizedNumberRow) {
@ -314,3 +316,4 @@ const val LAYOUT_NUMPAD_LANDSCAPE = "numpad_landscape"
const val LAYOUT_NUMBER = "number"
const val LAYOUT_PHONE = "phone"
const val LAYOUT_PHONE_SYMBOLS = "phone_symbols"
const val LAYOUT_NUMBER_ROW = "number_row"

View file

@ -37,7 +37,7 @@ object RawKeyboardParser {
private val rawLayoutCache = hashMapOf<String, (KeyboardParams) -> MutableList<MutableList<KeyData>>>()
val symbolAndNumberLayouts = listOf(LAYOUT_SYMBOLS, LAYOUT_SYMBOLS_SHIFTED, LAYOUT_SYMBOLS_ARABIC,
LAYOUT_NUMBER, LAYOUT_NUMPAD, LAYOUT_NUMPAD_LANDSCAPE, LAYOUT_PHONE, LAYOUT_PHONE_SYMBOLS)
LAYOUT_NUMBER, LAYOUT_NUMPAD, LAYOUT_NUMPAD_LANDSCAPE, LAYOUT_PHONE, LAYOUT_PHONE_SYMBOLS, LAYOUT_NUMBER_ROW)
fun clearCache() = rawLayoutCache.clear()
@ -91,7 +91,12 @@ object RawKeyboardParser {
try {
getCustomLayoutFile(layoutFileName, context).readText()
} catch (e: Exception) { // fall back to defaults if for some reason file is broken
val name = if (layoutName.contains("functional")) "functional_keys.json" else "qwerty.txt"
val name = when {
layoutName.contains("functional") -> "functional_keys.json"
layoutName.contains("number_row") -> "number_row.txt"
layoutName.contains("symbols") -> "symbols.txt"
else -> "qwerty.txt"
}
Log.e(TAG, "cannot open layout $layoutName, falling back to $name", e)
context.assets.open("layouts${File.separator}$name").reader().use { it.readText() }
}