mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-10 00:27:45 +00:00
rename LocaleKeyTexts, move some parts from LayoutInfos there
This commit is contained in:
parent
be9b438cca
commit
b4a223ae67
10 changed files with 63 additions and 58 deletions
|
@ -16,8 +16,8 @@ import android.view.inputmethod.EditorInfo;
|
||||||
import helium314.keyboard.keyboard.internal.KeyboardBuilder;
|
import helium314.keyboard.keyboard.internal.KeyboardBuilder;
|
||||||
import helium314.keyboard.keyboard.internal.KeyboardParams;
|
import helium314.keyboard.keyboard.internal.KeyboardParams;
|
||||||
import helium314.keyboard.keyboard.internal.UniqueKeysCache;
|
import helium314.keyboard.keyboard.internal.UniqueKeysCache;
|
||||||
import helium314.keyboard.keyboard.internal.keyboard_parser.LocaleKeyTexts;
|
import helium314.keyboard.keyboard.internal.keyboard_parser.LocaleKeyboardInfos;
|
||||||
import helium314.keyboard.keyboard.internal.keyboard_parser.LocaleKeyTextsKt;
|
import helium314.keyboard.keyboard.internal.keyboard_parser.LocaleKeyboardInfosKt;
|
||||||
import helium314.keyboard.latin.RichInputMethodSubtype;
|
import helium314.keyboard.latin.RichInputMethodSubtype;
|
||||||
import helium314.keyboard.latin.utils.InputTypeUtils;
|
import helium314.keyboard.latin.utils.InputTypeUtils;
|
||||||
import helium314.keyboard.latin.utils.Log;
|
import helium314.keyboard.latin.utils.Log;
|
||||||
|
@ -45,7 +45,7 @@ public final class KeyboardLayoutSet {
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Params mParams;
|
private final Params mParams;
|
||||||
public final LocaleKeyTexts mLocaleKeyTexts;
|
public final LocaleKeyboardInfos mLocaleKeyboardInfos;
|
||||||
|
|
||||||
// How many layouts we forcibly keep in cache. This only includes ALPHABET (default) and
|
// How many layouts we forcibly keep in cache. This only includes ALPHABET (default) and
|
||||||
// ALPHABET_AUTOMATIC_SHIFTED layouts - other layouts may stay in memory in the map of
|
// ALPHABET_AUTOMATIC_SHIFTED layouts - other layouts may stay in memory in the map of
|
||||||
|
@ -94,7 +94,7 @@ public final class KeyboardLayoutSet {
|
||||||
|
|
||||||
public static void onSystemLocaleChanged() {
|
public static void onSystemLocaleChanged() {
|
||||||
clearKeyboardCache();
|
clearKeyboardCache();
|
||||||
LocaleKeyTextsKt.clearCache();
|
LocaleKeyboardInfosKt.clearCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onKeyboardThemeChanged() {
|
public static void onKeyboardThemeChanged() {
|
||||||
|
@ -109,7 +109,7 @@ public final class KeyboardLayoutSet {
|
||||||
KeyboardLayoutSet(final Context context, @NonNull final Params params) {
|
KeyboardLayoutSet(final Context context, @NonNull final Params params) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mParams = params;
|
mParams = params;
|
||||||
mLocaleKeyTexts = LocaleKeyTextsKt.getOrCreate(context, params.mSubtype.getLocale());
|
mLocaleKeyboardInfos = LocaleKeyboardInfosKt.getOrCreate(context, params.mSubtype.getLocale());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|
|
@ -303,7 +303,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
mEmojiTabStripView.setVisibility(View.VISIBLE);
|
mEmojiTabStripView.setVisibility(View.VISIBLE);
|
||||||
mClipboardHistoryView.setVisibility(View.GONE);
|
mClipboardHistoryView.setVisibility(View.GONE);
|
||||||
mEmojiPalettesView.startEmojiPalettes(
|
mEmojiPalettesView.startEmojiPalettes(
|
||||||
mKeyboardLayoutSet.mLocaleKeyTexts.getLabelAlphabet(),
|
mKeyboardLayoutSet.mLocaleKeyboardInfos.getLabelAlphabet(),
|
||||||
mKeyboardView.getKeyVisualAttribute(), keyboard.mIconsSet);
|
mKeyboardView.getKeyVisualAttribute(), keyboard.mIconsSet);
|
||||||
mEmojiPalettesView.setVisibility(View.VISIBLE);
|
mEmojiPalettesView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
@ -326,7 +326,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
mEmojiPalettesView.setVisibility(View.GONE);
|
mEmojiPalettesView.setVisibility(View.GONE);
|
||||||
mClipboardHistoryView.startClipboardHistory(
|
mClipboardHistoryView.startClipboardHistory(
|
||||||
mLatinIME.getClipboardHistoryManager(),
|
mLatinIME.getClipboardHistoryManager(),
|
||||||
mKeyboardLayoutSet.mLocaleKeyTexts.getLabelAlphabet(),
|
mKeyboardLayoutSet.mLocaleKeyboardInfos.getLabelAlphabet(),
|
||||||
mKeyboardView.getKeyVisualAttribute(), keyboard.mIconsSet);
|
mKeyboardView.getKeyVisualAttribute(), keyboard.mIconsSet);
|
||||||
mClipboardHistoryView.setVisibility(View.VISIBLE);
|
mClipboardHistoryView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import helium314.keyboard.keyboard.Key;
|
import helium314.keyboard.keyboard.Key;
|
||||||
import helium314.keyboard.keyboard.KeyboardId;
|
import helium314.keyboard.keyboard.KeyboardId;
|
||||||
import helium314.keyboard.keyboard.internal.keyboard_parser.LocaleKeyTexts;
|
import helium314.keyboard.keyboard.internal.keyboard_parser.LocaleKeyboardInfos;
|
||||||
import helium314.keyboard.latin.R;
|
import helium314.keyboard.latin.R;
|
||||||
import helium314.keyboard.latin.common.Constants;
|
import helium314.keyboard.latin.common.Constants;
|
||||||
import helium314.keyboard.latin.settings.Settings;
|
import helium314.keyboard.latin.settings.Settings;
|
||||||
|
@ -88,7 +88,7 @@ public class KeyboardParams {
|
||||||
private final UniqueKeysCache mUniqueKeysCache;
|
private final UniqueKeysCache mUniqueKeysCache;
|
||||||
public boolean mAllowRedundantPopupKeys;
|
public boolean mAllowRedundantPopupKeys;
|
||||||
@NonNull
|
@NonNull
|
||||||
public LocaleKeyTexts mLocaleKeyTexts;
|
public LocaleKeyboardInfos mLocaleKeyboardInfos;
|
||||||
|
|
||||||
public int mMostCommonKeyHeight = 0;
|
public int mMostCommonKeyHeight = 0;
|
||||||
public int mMostCommonKeyWidth = 0;
|
public int mMostCommonKeyWidth = 0;
|
||||||
|
|
|
@ -43,9 +43,11 @@ import java.io.File
|
||||||
*/
|
*/
|
||||||
abstract class KeyboardParser(private val params: KeyboardParams, private val context: Context) {
|
abstract class KeyboardParser(private val params: KeyboardParams, private val context: Context) {
|
||||||
private val infos = layoutInfos(params)
|
private val infos = layoutInfos(params)
|
||||||
private val defaultLabelFlags = infos.defaultLabelFlags or if (params.mId.mElementId == KeyboardId.ELEMENT_SYMBOLS || params.mId.mElementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED)
|
private val defaultLabelFlags = if (params.mId.isAlphabetKeyboard) {
|
||||||
|
params.mLocaleKeyboardInfos.labelFlags
|
||||||
|
} else if (params.mId.mElementId == KeyboardId.ELEMENT_SYMBOLS || params.mId.mElementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED) {
|
||||||
Key.LABEL_FLAGS_DISABLE_HINT_LABEL // reproduce the no-hints in symbol layouts, todo: add setting
|
Key.LABEL_FLAGS_DISABLE_HINT_LABEL // reproduce the no-hints in symbol layouts, todo: add setting
|
||||||
else 0
|
} else 0
|
||||||
|
|
||||||
abstract fun parseCoreLayout(layoutContent: String): MutableList<List<KeyData>>
|
abstract fun parseCoreLayout(layoutContent: String): MutableList<List<KeyData>>
|
||||||
|
|
||||||
|
@ -91,7 +93,7 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
|
||||||
baseKeys.forEachIndexed { i, it ->
|
baseKeys.forEachIndexed { i, it ->
|
||||||
val row: List<KeyData> = if (i == baseKeys.lastIndex && isTablet()) {
|
val row: List<KeyData> = if (i == baseKeys.lastIndex && isTablet()) {
|
||||||
// add bottom row extra keys
|
// add bottom row extra keys
|
||||||
val tabletExtraKeys = params.mLocaleKeyTexts.getTabletExtraKeys(params.mId.mElementId)
|
val tabletExtraKeys = params.mLocaleKeyboardInfos.getTabletExtraKeys(params.mId.mElementId)
|
||||||
tabletExtraKeys.first + it + tabletExtraKeys.second
|
tabletExtraKeys.first + it + tabletExtraKeys.second
|
||||||
} else {
|
} else {
|
||||||
it
|
it
|
||||||
|
@ -160,7 +162,7 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
|
||||||
private fun addNumberRowOrPopupKeys(baseKeys: MutableList<List<KeyData>>) {
|
private fun addNumberRowOrPopupKeys(baseKeys: MutableList<List<KeyData>>) {
|
||||||
if (!params.mId.mNumberRowEnabled && params.mId.mElementId == KeyboardId.ELEMENT_SYMBOLS) {
|
if (!params.mId.mNumberRowEnabled && params.mId.mElementId == KeyboardId.ELEMENT_SYMBOLS) {
|
||||||
// replace first symbols row with number row, but use the labels as popupKeys
|
// replace first symbols row with number row, but use the labels as popupKeys
|
||||||
val numberRow = params.mLocaleKeyTexts.getNumberRow()
|
val numberRow = params.mLocaleKeyboardInfos.getNumberRow()
|
||||||
numberRow.forEachIndexed { index, keyData -> keyData.popup.symbol = baseKeys[0].getOrNull(index)?.label }
|
numberRow.forEachIndexed { index, keyData -> keyData.popup.symbol = baseKeys[0].getOrNull(index)?.label }
|
||||||
baseKeys[0] = numberRow
|
baseKeys[0] = numberRow
|
||||||
} else if (!params.mId.mNumberRowEnabled && params.mId.isAlphabetKeyboard && infos.numbersOnTopRow) {
|
} else if (!params.mId.mNumberRowEnabled && params.mId.isAlphabetKeyboard && infos.numbersOnTopRow) {
|
||||||
|
@ -379,7 +381,7 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
|
||||||
if (params.mId.mEmojiKeyEnabled)
|
if (params.mId.mEmojiKeyEnabled)
|
||||||
bottomRow.add(getFunctionalKeyParams(FunctionalKey.EMOJI))
|
bottomRow.add(getFunctionalKeyParams(FunctionalKey.EMOJI))
|
||||||
bottomRow.add(keyParams)
|
bottomRow.add(keyParams)
|
||||||
if (infos.hasZwnjKey)
|
if (params.mLocaleKeyboardInfos.hasZwnjKey)
|
||||||
bottomRow.add(getFunctionalKeyParams(FunctionalKey.ZWNJ))
|
bottomRow.add(getFunctionalKeyParams(FunctionalKey.ZWNJ))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -393,7 +395,7 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getNumberRow(): ArrayList<KeyParams> =
|
private fun getNumberRow(): ArrayList<KeyParams> =
|
||||||
params.mLocaleKeyTexts.getNumberRow().mapTo(ArrayList()) {
|
params.mLocaleKeyboardInfos.getNumberRow().mapTo(ArrayList()) {
|
||||||
it.toKeyParams(params, additionalLabelFlags = Key.LABEL_FLAGS_DISABLE_HINT_LABEL or defaultLabelFlags)
|
it.toKeyParams(params, additionalLabelFlags = Key.LABEL_FLAGS_DISABLE_HINT_LABEL or defaultLabelFlags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,7 +421,7 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
FunctionalKey.ALPHA -> KeyParams(
|
FunctionalKey.ALPHA -> KeyParams(
|
||||||
params.mLocaleKeyTexts.labelAlphabet,
|
params.mLocaleKeyboardInfos.labelAlphabet,
|
||||||
getToAlphaCode(),
|
getToAlphaCode(),
|
||||||
params,
|
params,
|
||||||
width,
|
width,
|
||||||
|
@ -653,8 +655,8 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
|
||||||
|
|
||||||
private fun getToSymbolLabel() =
|
private fun getToSymbolLabel() =
|
||||||
if (params.mId.mElementId == KeyboardId.ELEMENT_SYMBOLS || params.mId.mElementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED)
|
if (params.mId.mElementId == KeyboardId.ELEMENT_SYMBOLS || params.mId.mElementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED)
|
||||||
params.mLocaleKeyTexts.labelAlphabet
|
params.mLocaleKeyboardInfos.labelAlphabet
|
||||||
else params.mLocaleKeyTexts.labelSymbol
|
else params.mLocaleKeyboardInfos.labelSymbol
|
||||||
|
|
||||||
private fun getToSymbolCode() =
|
private fun getToSymbolCode() =
|
||||||
if (params.mId.mElementId == KeyboardId.ELEMENT_NUMPAD)
|
if (params.mId.mElementId == KeyboardId.ELEMENT_NUMPAD)
|
||||||
|
@ -669,9 +671,9 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
|
||||||
private fun getShiftLabel(): String {
|
private fun getShiftLabel(): String {
|
||||||
val elementId = params.mId.mElementId
|
val elementId = params.mId.mElementId
|
||||||
if (elementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED)
|
if (elementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED)
|
||||||
return params.mLocaleKeyTexts.labelSymbol
|
return params.mLocaleKeyboardInfos.labelSymbol
|
||||||
if (elementId == KeyboardId.ELEMENT_SYMBOLS)
|
if (elementId == KeyboardId.ELEMENT_SYMBOLS)
|
||||||
return params.mLocaleKeyTexts.getShiftSymbolLabel(isTablet())
|
return params.mLocaleKeyboardInfos.getShiftSymbolLabel(isTablet())
|
||||||
if (elementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED || elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED
|
if (elementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED || elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED
|
||||||
|| elementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED || elementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED)
|
|| elementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED || elementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED)
|
||||||
return "!icon/shift_key_shifted"
|
return "!icon/shift_key_shifted"
|
||||||
|
@ -681,7 +683,7 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
|
||||||
private fun getPeriodLabel(): String {
|
private fun getPeriodLabel(): String {
|
||||||
if (params.mId.isNumberLayout) return "."
|
if (params.mId.isNumberLayout) return "."
|
||||||
if (params.mId.isAlphabetKeyboard || params.mId.locale.language in listOf("ar", "fa")) // todo: this exception is not so great...
|
if (params.mId.isAlphabetKeyboard || params.mId.locale.language in listOf("ar", "fa")) // todo: this exception is not so great...
|
||||||
return params.mLocaleKeyTexts.labelPeriod
|
return params.mLocaleKeyboardInfos.labelPeriod
|
||||||
return "."
|
return "."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -692,7 +694,7 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
|
||||||
return "\\@"
|
return "\\@"
|
||||||
if (params.mId.isNumberLayout)
|
if (params.mId.isNumberLayout)
|
||||||
return ","
|
return ","
|
||||||
return params.mLocaleKeyTexts.labelComma
|
return params.mLocaleKeyboardInfos.labelComma
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCommaPopupKeys(): List<String> {
|
private fun getCommaPopupKeys(): List<String> {
|
||||||
|
@ -715,7 +717,7 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
|
||||||
return listOf("…")
|
return listOf("…")
|
||||||
if (params.mId.isNumberLayout)
|
if (params.mId.isNumberLayout)
|
||||||
return listOf(":", "…", ";", "∞", "π", "√", "°", "^")
|
return listOf(":", "…", ";", "∞", "π", "√", "°", "^")
|
||||||
val popupKeys = params.mLocaleKeyTexts.getPopupKeys("punctuation")!!.toMutableList()
|
val popupKeys = params.mLocaleKeyboardInfos.getPopupKeys("punctuation")!!.toMutableList()
|
||||||
if (params.mId.mSubtype.isRtlSubtype) {
|
if (params.mId.mSubtype.isRtlSubtype) {
|
||||||
for (i in popupKeys.indices)
|
for (i in popupKeys.indices)
|
||||||
popupKeys[i] = popupKeys[i].rtlLabel(params) // for parentheses
|
popupKeys[i] = popupKeys[i].rtlLabel(params) // for parentheses
|
||||||
|
@ -787,11 +789,6 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
|
||||||
private fun layoutInfos(params: KeyboardParams): LayoutInfos {
|
private fun layoutInfos(params: KeyboardParams): LayoutInfos {
|
||||||
val layout = params.mId.mSubtype.keyboardLayoutSetName
|
val layout = params.mId.mSubtype.keyboardLayoutSetName
|
||||||
val language = params.mId.locale.language
|
val language = params.mId.locale.language
|
||||||
val labelFlags = if (!params.mId.isAlphabetKeyboard) 0 else when (language) {
|
|
||||||
"hy", "ar", "be", "fa", "hi", "lo", "mr", "ne", "th", "ur" -> Key.LABEL_FLAGS_FONT_NORMAL
|
|
||||||
"kn", "km", "ml", "si", "ta", "te" -> Key.LABEL_FLAGS_FONT_NORMAL or Key.LABEL_FLAGS_AUTO_X_SCALE
|
|
||||||
else -> 0
|
|
||||||
}
|
|
||||||
// only for alphabet, but some exceptions for shift layouts
|
// only for alphabet, but some exceptions for shift layouts
|
||||||
val enableProximityCharsCorrection = params.mId.isAlphabetKeyboard && when (layout) {
|
val enableProximityCharsCorrection = params.mId.isAlphabetKeyboard && when (layout) {
|
||||||
"bengali_akkhor", "georgian", "hindi", "lao", "nepali_romanized", "nepali_traditional", "sinhala", "thai" ->
|
"bengali_akkhor", "georgian", "hindi", "lao", "nepali_romanized", "nepali_traditional", "sinhala", "thai" ->
|
||||||
|
@ -804,12 +801,11 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
|
||||||
val touchPositionCorrectionData = if (params.mId.isAlphabetKeyboard && layout in listOf("armenian_phonetic", "khmer", "lao", "malayalam", "pcqwerty", "thai"))
|
val touchPositionCorrectionData = if (params.mId.isAlphabetKeyboard && layout in listOf("armenian_phonetic", "khmer", "lao", "malayalam", "pcqwerty", "thai"))
|
||||||
R.array.touch_position_correction_data_default
|
R.array.touch_position_correction_data_default
|
||||||
else R.array.touch_position_correction_data_holo
|
else R.array.touch_position_correction_data_holo
|
||||||
val hasZwnjKey = params.mId.locale.language in listOf("fa", "ne", "kn", "te") // determine from language, user might have custom layout
|
|
||||||
// custom non-json layout for non-uppercase language should not have shift key
|
// custom non-json layout for non-uppercase language should not have shift key
|
||||||
val hasShiftKey = !params.mId.isAlphabetKeyboard
|
val hasShiftKey = !params.mId.isAlphabetKeyboard
|
||||||
|| layout !in listOf("hindi_compact", "bengali", "arabic", "arabic_pc", "hebrew", "kannada", "kannada_extended","malayalam", "marathi", "farsi", "tamil", "telugu")
|
|| layout !in listOf("hindi_compact", "bengali", "arabic", "arabic_pc", "hebrew", "kannada", "kannada_extended","malayalam", "marathi", "farsi", "tamil", "telugu")
|
||||||
val numbersOnTopRow = layout !in listOf("pcqwerty", "lao", "thai", "korean_sebeolsik_390", "korean_sebeolsik_final")
|
val numbersOnTopRow = layout !in listOf("pcqwerty", "lao", "thai", "korean_sebeolsik_390", "korean_sebeolsik_final")
|
||||||
return LayoutInfos(labelFlags, enableProximityCharsCorrection, allowRedundantPopupKeys, touchPositionCorrectionData, hasZwnjKey, hasShiftKey, numbersOnTopRow)
|
return LayoutInfos(enableProximityCharsCorrection, allowRedundantPopupKeys, touchPositionCorrectionData, hasShiftKey, numbersOnTopRow)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -819,9 +815,8 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: actually this should be in some separate file, or maybe part of an (extended) key texts
|
// todo: actually this should be in some separate file
|
||||||
data class LayoutInfos(
|
data class LayoutInfos(
|
||||||
val defaultLabelFlags: Int = 0,
|
|
||||||
// disabled by default, but enabled for all alphabet layouts
|
// disabled by default, but enabled for all alphabet layouts
|
||||||
// currently set in keyboardLayoutSet
|
// currently set in keyboardLayoutSet
|
||||||
val enableProximityCharsCorrection: Boolean = false,
|
val enableProximityCharsCorrection: Boolean = false,
|
||||||
|
@ -830,8 +825,9 @@ data class LayoutInfos(
|
||||||
// there is holo, default and null
|
// there is holo, default and null
|
||||||
// null only for popupKeys keyboard
|
// null only for popupKeys keyboard
|
||||||
val touchPositionCorrectionData: Int? = null,
|
val touchPositionCorrectionData: Int? = null,
|
||||||
val hasZwnjKey: Boolean = false,
|
// some layouts do not have a shift key
|
||||||
val hasShiftKey: Boolean = true,
|
val hasShiftKey: Boolean = true,
|
||||||
|
// some layouts have different number layout, e.g. thai or korean_sebeolsik
|
||||||
val numbersOnTopRow: Boolean = true,
|
val numbersOnTopRow: Boolean = true,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ import java.io.InputStream
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import kotlin.math.round
|
import kotlin.math.round
|
||||||
|
|
||||||
class LocaleKeyTexts(dataStream: InputStream?, locale: Locale) {
|
class LocaleKeyboardInfos(dataStream: InputStream?, locale: Locale) {
|
||||||
private val popupKeys = hashMapOf<String, List<String>>()
|
private val popupKeys = hashMapOf<String, List<String>>()
|
||||||
private val priorityPopupKeys = hashMapOf<String, List<String>>()
|
private val priorityPopupKeys = hashMapOf<String, List<String>>()
|
||||||
private val extraKeys = Array<MutableList<KeyData>?>(5) { null }
|
private val extraKeys = Array<MutableList<KeyData>?>(5) { null }
|
||||||
|
@ -44,6 +44,15 @@ class LocaleKeyTexts(dataStream: InputStream?, locale: Locale) {
|
||||||
mutableListOf(),
|
mutableListOf(),
|
||||||
mutableListOf("ⁿ", "∅"),
|
mutableListOf("ⁿ", "∅"),
|
||||||
)
|
)
|
||||||
|
val hasZwnjKey = when (locale.language) { // todo: move to the info file
|
||||||
|
"fa", "ne", "kn", "te" -> true
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
val labelFlags = when (locale.language) { // todo: move to the info file
|
||||||
|
"hy", "ar", "be", "fa", "hi", "lo", "mr", "ne", "th", "ur" -> Key.LABEL_FLAGS_FONT_NORMAL
|
||||||
|
"kn", "km", "ml", "si", "ta", "te" -> Key.LABEL_FLAGS_FONT_NORMAL or Key.LABEL_FLAGS_AUTO_X_SCALE
|
||||||
|
else -> 0
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
readStream(dataStream, false)
|
readStream(dataStream, false)
|
||||||
|
@ -213,20 +222,20 @@ private fun addFixedColumnOrder(popupKeys: List<String>): List<String> {
|
||||||
return listOf("${Key.POPUP_KEYS_FIXED_COLUMN_ORDER}${newPopupKeys.size}") + newPopupKeys
|
return listOf("${Key.POPUP_KEYS_FIXED_COLUMN_ORDER}${newPopupKeys.size}") + newPopupKeys
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getOrCreate(context: Context, locale: Locale): LocaleKeyTexts =
|
fun getOrCreate(context: Context, locale: Locale): LocaleKeyboardInfos =
|
||||||
localeKeyTextsCache.getOrPut(locale.toString()) {
|
localeKeyboardInfosCache.getOrPut(locale.toString()) {
|
||||||
LocaleKeyTexts(getStreamForLocale(locale, context), locale)
|
LocaleKeyboardInfos(getStreamForLocale(locale, context), locale)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addLocaleKeyTextsToParams(context: Context, params: KeyboardParams, popupKeysSetting: Int) {
|
fun addLocaleKeyTextsToParams(context: Context, params: KeyboardParams, popupKeysSetting: Int) {
|
||||||
val locales = params.mSecondaryLocales + params.mId.locale
|
val locales = params.mSecondaryLocales + params.mId.locale
|
||||||
params.mLocaleKeyTexts = localeKeyTextsCache.getOrPut(locales.joinToString { it.toString() }) {
|
params.mLocaleKeyboardInfos = localeKeyboardInfosCache.getOrPut(locales.joinToString { it.toString() }) {
|
||||||
createLocaleKeyTexts(context, params, popupKeysSetting)
|
createLocaleKeyTexts(context, params, popupKeysSetting)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createLocaleKeyTexts(context: Context, params: KeyboardParams, popupKeysSetting: Int): LocaleKeyTexts {
|
private fun createLocaleKeyTexts(context: Context, params: KeyboardParams, popupKeysSetting: Int): LocaleKeyboardInfos {
|
||||||
val lkt = LocaleKeyTexts(getStreamForLocale(params.mId.locale, context), params.mId.locale)
|
val lkt = LocaleKeyboardInfos(getStreamForLocale(params.mId.locale, context), params.mId.locale)
|
||||||
if (popupKeysSetting == POPUP_KEYS_MORE)
|
if (popupKeysSetting == POPUP_KEYS_MORE)
|
||||||
lkt.addFile(context.assets.open("$LANGUAGE_TEXTS_FOLDER/all_popup_keys.txt"))
|
lkt.addFile(context.assets.open("$LANGUAGE_TEXTS_FOLDER/all_popup_keys.txt"))
|
||||||
else if (popupKeysSetting == POPUP_KEYS_ALL)
|
else if (popupKeysSetting == POPUP_KEYS_ALL)
|
||||||
|
@ -250,10 +259,10 @@ private fun getStreamForLocale(locale: Locale, context: Context) =
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clearCache() = localeKeyTextsCache.clear()
|
fun clearCache() = localeKeyboardInfosCache.clear()
|
||||||
|
|
||||||
// cache the texts, so they don't need to be read over and over
|
// cache the texts, so they don't need to be read over and over
|
||||||
private val localeKeyTextsCache = hashMapOf<String, LocaleKeyTexts>()
|
private val localeKeyboardInfosCache = hashMapOf<String, LocaleKeyboardInfos>()
|
||||||
|
|
||||||
private const val READER_MODE_NONE = 0
|
private const val READER_MODE_NONE = 0
|
||||||
private const val READER_MODE_POPUP_KEYS = 1
|
private const val READER_MODE_POPUP_KEYS = 1
|
|
@ -35,7 +35,7 @@ class SimpleKeyboardParser(
|
||||||
else parseKey(it)
|
else parseKey(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getExtraKeys(rowIndex: Int) = params.mLocaleKeyTexts.getExtraKeys(rowIndex + 1)
|
private fun getExtraKeys(rowIndex: Int) = params.mLocaleKeyboardInfos.getExtraKeys(rowIndex + 1)
|
||||||
|
|
||||||
private fun parseKey(key: String): KeyData {
|
private fun parseKey(key: String): KeyData {
|
||||||
val split = key.splitOnWhitespace()
|
val split = key.splitOnWhitespace()
|
||||||
|
|
|
@ -44,11 +44,11 @@ class TextKeyData(
|
||||||
// }
|
// }
|
||||||
if (label.startsWith("$$$")) { // currency key
|
if (label.startsWith("$$$")) { // currency key
|
||||||
if (label == "$$$")
|
if (label == "$$$")
|
||||||
return params.mLocaleKeyTexts.currencyKey
|
return params.mLocaleKeyboardInfos.currencyKey
|
||||||
.let { it.first.toTextKey(it.second.toList(), labelFlags = Key.LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO) } // the flag is to match old parser, but why for main currency key, but not for others?
|
.let { it.first.toTextKey(it.second.toList(), labelFlags = Key.LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO) } // the flag is to match old parser, but why for main currency key, but not for others?
|
||||||
val n = label.substringAfter("$$$").toIntOrNull()
|
val n = label.substringAfter("$$$").toIntOrNull()
|
||||||
if (n != null && n <= 4 && n > 0)
|
if (n != null && n <= 4 && n > 0)
|
||||||
return params.mLocaleKeyTexts.currencyKey.second[n - 1].toTextKey()
|
return params.mLocaleKeyboardInfos.currencyKey.second[n - 1].toTextKey()
|
||||||
}
|
}
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ import androidx.core.content.ContextCompat;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
import helium314.keyboard.keyboard.KeyboardTheme;
|
import helium314.keyboard.keyboard.KeyboardTheme;
|
||||||
import helium314.keyboard.keyboard.internal.keyboard_parser.LocaleKeyTextsKt;
|
import helium314.keyboard.keyboard.internal.keyboard_parser.LocaleKeyboardInfosKt;
|
||||||
import helium314.keyboard.latin.AudioAndHapticFeedbackManager;
|
import helium314.keyboard.latin.AudioAndHapticFeedbackManager;
|
||||||
import helium314.keyboard.latin.InputAttributes;
|
import helium314.keyboard.latin.InputAttributes;
|
||||||
import helium314.keyboard.latin.R;
|
import helium314.keyboard.latin.R;
|
||||||
|
@ -522,9 +522,9 @@ 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, "normal")) {
|
return switch (prefs.getString(Settings.PREF_MORE_POPUP_KEYS, "normal")) {
|
||||||
case "all" -> LocaleKeyTextsKt.POPUP_KEYS_ALL;
|
case "all" -> LocaleKeyboardInfosKt.POPUP_KEYS_ALL;
|
||||||
case "more" -> LocaleKeyTextsKt.POPUP_KEYS_MORE;
|
case "more" -> LocaleKeyboardInfosKt.POPUP_KEYS_MORE;
|
||||||
default -> LocaleKeyTextsKt.POPUP_KEYS_NORMAL;
|
default -> LocaleKeyboardInfosKt.POPUP_KEYS_NORMAL;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import helium314.keyboard.compat.ConfigurationCompatKt;
|
import helium314.keyboard.compat.ConfigurationCompatKt;
|
||||||
import helium314.keyboard.keyboard.internal.keyboard_parser.LocaleKeyTextsKt;
|
import helium314.keyboard.keyboard.internal.keyboard_parser.LocaleKeyboardInfosKt;
|
||||||
import helium314.keyboard.latin.InputAttributes;
|
import helium314.keyboard.latin.InputAttributes;
|
||||||
import helium314.keyboard.latin.R;
|
import helium314.keyboard.latin.R;
|
||||||
import helium314.keyboard.latin.RichInputMethodManager;
|
import helium314.keyboard.latin.RichInputMethodManager;
|
||||||
|
@ -210,7 +210,7 @@ public class SettingsValues {
|
||||||
mSecondaryLocales = Settings.getSecondaryLocales(prefs, mLocale);
|
mSecondaryLocales = Settings.getSecondaryLocales(prefs, mLocale);
|
||||||
mShowMorePopupKeys = selectedSubtype.isAsciiCapable()
|
mShowMorePopupKeys = selectedSubtype.isAsciiCapable()
|
||||||
? Settings.readMorePopupKeysPref(prefs)
|
? Settings.readMorePopupKeysPref(prefs)
|
||||||
: LocaleKeyTextsKt.POPUP_KEYS_NORMAL;
|
: LocaleKeyboardInfosKt.POPUP_KEYS_NORMAL;
|
||||||
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
|
||||||
|
|
|
@ -40,11 +40,11 @@ fun createPopupKeysArray(popupSet: PopupSet<*>?, params: KeyboardParams, label:
|
||||||
val types = if (params.mId.isAlphabetKeyboard) params.mPopupKeyTypes else allPopupKeyTypes
|
val types = if (params.mId.isAlphabetKeyboard) params.mPopupKeyTypes else allPopupKeyTypes
|
||||||
types.forEach { type ->
|
types.forEach { type ->
|
||||||
when (type) {
|
when (type) {
|
||||||
POPUP_KEYS_NUMBER -> params.mLocaleKeyTexts.getNumberLabel(popupSet?.numberIndex)?.let { popupKeys.add(it) }
|
POPUP_KEYS_NUMBER -> params.mLocaleKeyboardInfos.getNumberLabel(popupSet?.numberIndex)?.let { popupKeys.add(it) }
|
||||||
POPUP_KEYS_LAYOUT -> popupSet?.getPopupKeyLabels(params)?.let { popupKeys.addAll(it) }
|
POPUP_KEYS_LAYOUT -> popupSet?.getPopupKeyLabels(params)?.let { popupKeys.addAll(it) }
|
||||||
POPUP_KEYS_SYMBOLS -> popupSet?.symbol?.let { popupKeys.add(it) }
|
POPUP_KEYS_SYMBOLS -> popupSet?.symbol?.let { popupKeys.add(it) }
|
||||||
POPUP_KEYS_LANGUAGE -> params.mLocaleKeyTexts.getPopupKeys(label)?.let { popupKeys.addAll(it) }
|
POPUP_KEYS_LANGUAGE -> params.mLocaleKeyboardInfos.getPopupKeys(label)?.let { popupKeys.addAll(it) }
|
||||||
POPUP_KEYS_LANGUAGE_PRIORITY -> params.mLocaleKeyTexts.getPriorityPopupKeys(label)?.let { popupKeys.addAll(it) }
|
POPUP_KEYS_LANGUAGE_PRIORITY -> params.mLocaleKeyboardInfos.getPriorityPopupKeys(label)?.let { popupKeys.addAll(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!popupKeysDelegate.isInitialized() || popupKeys.isEmpty())
|
if (!popupKeysDelegate.isInitialized() || popupKeys.isEmpty())
|
||||||
|
@ -75,11 +75,11 @@ fun getHintLabel(popupSet: PopupSet<*>?, params: KeyboardParams, label: String):
|
||||||
var hintLabel: String? = null
|
var hintLabel: String? = null
|
||||||
for (type in params.mPopupKeyLabelSources) {
|
for (type in params.mPopupKeyLabelSources) {
|
||||||
when (type) {
|
when (type) {
|
||||||
POPUP_KEYS_NUMBER -> params.mLocaleKeyTexts.getNumberLabel(popupSet?.numberIndex)?.let { hintLabel = it }
|
POPUP_KEYS_NUMBER -> params.mLocaleKeyboardInfos.getNumberLabel(popupSet?.numberIndex)?.let { hintLabel = it }
|
||||||
POPUP_KEYS_LAYOUT -> popupSet?.getPopupKeyLabels(params)?.let { hintLabel = it.firstOrNull() }
|
POPUP_KEYS_LAYOUT -> popupSet?.getPopupKeyLabels(params)?.let { hintLabel = it.firstOrNull() }
|
||||||
POPUP_KEYS_SYMBOLS -> popupSet?.symbol?.let { hintLabel = it }
|
POPUP_KEYS_SYMBOLS -> popupSet?.symbol?.let { hintLabel = it }
|
||||||
POPUP_KEYS_LANGUAGE -> params.mLocaleKeyTexts.getPopupKeys(label)?.let { hintLabel = it.firstOrNull() }
|
POPUP_KEYS_LANGUAGE -> params.mLocaleKeyboardInfos.getPopupKeys(label)?.let { hintLabel = it.firstOrNull() }
|
||||||
POPUP_KEYS_LANGUAGE_PRIORITY -> params.mLocaleKeyTexts.getPriorityPopupKeys(label)?.let { hintLabel = it.firstOrNull() }
|
POPUP_KEYS_LANGUAGE_PRIORITY -> params.mLocaleKeyboardInfos.getPriorityPopupKeys(label)?.let { hintLabel = it.firstOrNull() }
|
||||||
}
|
}
|
||||||
if (hintLabel != null) break
|
if (hintLabel != null) break
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ fun getHintLabel(popupSet: PopupSet<*>?, params: KeyboardParams, label: String):
|
||||||
private fun transformLabel(label: String, params: KeyboardParams): String =
|
private fun transformLabel(label: String, params: KeyboardParams): String =
|
||||||
if (label == "$$$") { // currency key
|
if (label == "$$$") { // currency key
|
||||||
if (params.mId.passwordInput()) "$"
|
if (params.mId.passwordInput()) "$"
|
||||||
else params.mLocaleKeyTexts.currencyKey.first
|
else params.mLocaleKeyboardInfos.currencyKey.first
|
||||||
} else if (params.mId.mSubtype.isRtlSubtype) {
|
} else if (params.mId.mSubtype.isRtlSubtype) {
|
||||||
label.rtlLabel(params)
|
label.rtlLabel(params)
|
||||||
} else label
|
} else label
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue