Skip to content

Commit

Permalink
allow customizing number row
Browse files Browse the repository at this point in the history
so users can do #558 themselves
  • Loading branch information
Helium314 committed Aug 26, 2024
1 parent 44eb296 commit 3306ffb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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() }
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@ disposition rather than other common dispositions for Latin languages. [CHAR LIM
<string name="layout_numpad" tools:keep="@string/layout_numpad">Numpad</string>
<!-- Name for numpad layout in landscape mode -->
<string name="layout_numpad_landscape" tools:keep="@string/layout_numpad_landscape">Numpad (landscape)</string>
<!-- Name for number row layout -->
<string name="layout_number_row" tools:keep="@string/layout_number_row">Number row</string>
<!-- Title for customizing background image -->
<string name="customize_background_image">Set background image</string>
<!-- Title for customizing currencies -->
Expand Down

0 comments on commit 3306ffb

Please # to comment.