diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt index 855c31d4b..59ded3036 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt @@ -51,14 +51,7 @@ open class KeyboardBuilder(protected val mContext: Context, keysInRows = EmojiParser(mParams, mContext).parse() } else { try { - val sv = Settings.getInstance().current - // previously was false for nordic and serbian_qwertz, true for all others - // todo: add setting? maybe users want it in a custom layout - mParams.mAllowRedundantPopupKeys = mParams.mId.mElementId != KeyboardId.ELEMENT_SYMBOLS - addLocaleKeyTextsToParams(mContext, mParams, sv.mShowMorePopupKeys) - mParams.mPopupKeyTypes.addAll(sv.mPopupKeyTypes) - // add label source only if popup key type enabled - sv.mPopupKeyLabelSources.forEach { if (it in sv.mPopupKeyTypes) mParams.mPopupKeyLabelSources.add(it) } + setupParams() keysInRows = KeyboardParser(mParams, mContext).parseLayout() determineAbsoluteValues() } catch (e: Exception) { @@ -69,6 +62,27 @@ open class KeyboardBuilder(protected val mContext: Context, return this } + private fun setupParams() { + val sv = Settings.getInstance().current + val layoutName = mParams.mId.mSubtype.keyboardLayoutSetName + + // previously was false for nordic and serbian_qwertz, true for all others + // todo: add setting? maybe users want it in a custom layout + mParams.mAllowRedundantPopupKeys = mParams.mId.mElementId != KeyboardId.ELEMENT_SYMBOLS + + // todo: should this be in subtype extra values? + mParams.mProximityCharsCorrectionEnabled = mParams.mId.isAlphabetKeyboard && when (layoutName) { + "bengali_akkhor", "georgian", "hindi", "lao", "nepali_romanized", "nepali_traditional", "sinhala", "thai" -> + mParams.mId.mElementId == KeyboardId.ELEMENT_ALPHABET // not for shifted layouts + else -> true + } + + addLocaleKeyTextsToParams(mContext, mParams, sv.mShowMorePopupKeys) + mParams.mPopupKeyTypes.addAll(sv.mPopupKeyTypes) + // add label source only if popup key type enabled + sv.mPopupKeyLabelSources.forEach { if (it in sv.mPopupKeyTypes) mParams.mPopupKeyLabelSources.add(it) } + } + // todo: remnant of old parser, replace it if reasonably simple protected fun readAttributes(@XmlRes xmlId: Int) { val parser = mResources.getXml(xmlId) diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardParams.java b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardParams.java index 0b9f6e9ae..e3c9fd911 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardParams.java +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardParams.java @@ -20,6 +20,7 @@ import helium314.keyboard.keyboard.internal.keyboard_parser.LocaleKeyboardInfos; import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode; import helium314.keyboard.latin.R; import helium314.keyboard.latin.settings.Settings; +import helium314.keyboard.latin.utils.Log; import helium314.keyboard.latin.utils.ResourceUtils; import java.util.ArrayList; @@ -93,6 +94,7 @@ public class KeyboardParams { public int mMostCommonKeyHeight = 0; public int mMostCommonKeyWidth = 0; + // should be enabled for all alphabet layouts, except for specific layouts when shifted public boolean mProximityCharsCorrectionEnabled; @NonNull @@ -267,11 +269,29 @@ public class KeyboardParams { mThemeId = keyboardAttr.getInt(R.styleable.Keyboard_themeId, 0); mIconsSet.loadIcons(keyboardAttr); - final int resourceId = keyboardAttr.getResourceId(R.styleable.Keyboard_touchPositionCorrectionData, 0); - if (resourceId != 0) { - final String[] data = context.getResources().getStringArray(resourceId); + // todo: this clashes with the other way of doing it... now both moved here, in same order + // need to check OpenBoard how it was done there + // also, popup keys should have an empty array + final int touchPositionResId = keyboardAttr.getResourceId(R.styleable.Keyboard_touchPositionCorrectionData, 0); + if (touchPositionResId != 0) { + final String[] data = context.getResources().getStringArray(touchPositionResId); mTouchPositionCorrection.load(data); } + // so this is the new way: + final int touchPositionResIdNew; + if (mId.isAlphabetKeyboard()) { + touchPositionResIdNew = switch (mId.mSubtype.getKeyboardLayoutSetName()) { + case "armenian_phonetic", "khmer", "lao", "malayalam", "pcqwerty", "thai" -> R.array.touch_position_correction_data_default; + default -> R.array.touch_position_correction_data_holo; + }; + } else touchPositionResIdNew = R.array.touch_position_correction_data_holo; + if (touchPositionResIdNew != touchPositionResId) { + Log.i("KeyboardParams", "overriding touchPositionCorrection "+touchPositionResId+" with "+touchPositionResIdNew); + if (touchPositionResIdNew != 0) { + final String[] data = context.getResources().getStringArray(touchPositionResIdNew); + mTouchPositionCorrection.load(data); + } + } } finally { keyAttr.recycle(); keyboardAttr.recycle(); diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/KeyboardParser.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/KeyboardParser.kt index a98a4beb4..015d33200 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/KeyboardParser.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/KeyboardParser.kt @@ -13,7 +13,6 @@ import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyLabel import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyType import helium314.keyboard.keyboard.internal.keyboard_parser.floris.SimplePopups import helium314.keyboard.keyboard.internal.keyboard_parser.floris.TextKeyData -import helium314.keyboard.latin.R import helium314.keyboard.latin.common.isEmoji import helium314.keyboard.latin.define.DebugFlags import helium314.keyboard.latin.settings.Settings @@ -36,7 +35,6 @@ import helium314.keyboard.latin.utils.sumOf * requirements of certain non-latin languages. */ class KeyboardParser(private val params: KeyboardParams, private val context: Context) { - private val infos = layoutInfos(params) private val defaultLabelFlags = when { params.mId.isAlphabetKeyboard -> params.mLocaleKeyboardInfos.labelFlags // reproduce the no-hints in symbol layouts @@ -47,11 +45,6 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co fun parseLayout(): ArrayList> { params.readAttributes(context, null) - params.mProximityCharsCorrectionEnabled = infos.enableProximityCharsCorrection - if (infos.touchPositionCorrectionData == null) // need to set correctly, as it's not properly done in readAttributes with attr = null - params.mTouchPositionCorrection.load(emptyArray()) - else - params.mTouchPositionCorrection.load(context.resources.getStringArray(infos.touchPositionCorrectionData)) val baseKeys = RawKeyboardParser.parseLayout(params, context) val keysInRows = createRows(baseKeys) @@ -272,7 +265,6 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co private fun KeyData.processFunctionalKeys(): KeyData? = when (label) { // todo: why defaultLabelFlags exactly here? is this for armenian or bengali period labels? try removing also check in holo theme KeyLabel.PERIOD -> copy(newLabelFlags = labelFlags or defaultLabelFlags) - KeyLabel.SHIFT -> if (infos.hasShiftKey) this else null else -> this } @@ -282,7 +274,7 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co val numberRow = params.mLocaleKeyboardInfos.getNumberRow() numberRow.forEachIndexed { index, keyData -> keyData.popup.symbol = baseKeys[0].getOrNull(index)?.label } baseKeys[0] = numberRow.toMutableList() - } else if (!params.mId.mNumberRowEnabled && params.mId.isAlphabetKeyboard && infos.numbersOnTopRow) { + } else if (!params.mId.mNumberRowEnabled && params.mId.isAlphabetKeyboard && hasNumbersOnTopRow()) { if (baseKeys[0].any { it.popup.main != null || !it.popup.relevant.isNullOrEmpty() } // first row of baseKeys has any layout popup key && params.mPopupKeyLabelSources.let { val layout = it.indexOf(POPUP_KEYS_LAYOUT) @@ -312,76 +304,16 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co } } + // some layouts have different number layout, and there we don't want the numbers on the top row + // todo: actually should not be in here, but in subtype extra values + private fun hasNumbersOnTopRow() = params.mId.mSubtype.keyboardLayoutSetName !in listOf("pcqwerty", "lao", "thai", "korean_sebeolsik_390", "korean_sebeolsik_final") + companion object { private const val TAG = "KeyboardParser" - - // todo: - // layoutInfos should be stored in method.xml (imeSubtypeExtraValue) - // or somewhere else... some replacement for keyboard_layout_set xml maybe - // some assets file? - // some extended version of locale_key_texts? that would be good, just need to rename the class and file - // touchPositionCorrectionData is just the resId, needs to be loaded in parser - // currently always holo is applied in readAttributes - private fun layoutInfos(params: KeyboardParams): LayoutInfos { - val layout = params.mId.mSubtype.keyboardLayoutSetName - // only for alphabet, but some exceptions for shift layouts - val enableProximityCharsCorrection = params.mId.isAlphabetKeyboard && when (layout) { - "bengali_akkhor", "georgian", "hindi", "lao", "nepali_romanized", "nepali_traditional", "sinhala", "thai" -> - params.mId.mElementId == KeyboardId.ELEMENT_ALPHABET - else -> true - } - // essentially this is default for 4 row and non-alphabet layouts, maybe this could be determined automatically instead of using a list - // todo: check the difference between default (i.e. none) and holo (test behavior on keyboard) - val touchPositionCorrectionData = if (params.mId.isAlphabetKeyboard && layout in listOf("armenian_phonetic", "khmer", "lao", "malayalam", "pcqwerty", "thai")) - R.array.touch_position_correction_data_default - else R.array.touch_position_correction_data_holo - // custom non-json layout for non-uppercase language should not have shift key - val hasShiftKey = !params.mId.isAlphabetKeyboard - || 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") - return LayoutInfos(enableProximityCharsCorrection, touchPositionCorrectionData, hasShiftKey, numbersOnTopRow) - } } } -// todo: actually this should be in some separate file -data class LayoutInfos( - // disabled by default, but enabled for all alphabet layouts - // currently set in keyboardLayoutSet - val enableProximityCharsCorrection: Boolean = false, - // there is holo, default and null - // null only for popupKeys keyboard - val touchPositionCorrectionData: Int? = null, - // some layouts do not have a shift key - val hasShiftKey: Boolean = true, - // some layouts have different number layout, e.g. thai or korean_sebeolsik - val numbersOnTopRow: Boolean = true, -) - -fun String.rtlLabel(params: KeyboardParams): String { - if (!params.mId.mSubtype.isRtlSubtype || params.mId.isNumberLayout) return this - return when (this) { - "{" -> "{|}" - "}" -> "}|{" - "(" -> "(|)" - ")" -> ")|(" - "[" -> "[|]" - "]" -> "]|[" - "<" -> "<|>" - ">" -> ">|<" - "≤" -> "≤|≥" - "≥" -> "≥|≤" - "«" -> "«|»" - "»" -> "»|«" - "‹" -> "‹|›" - "›" -> "›|‹" - "﴾" -> "﴾|﴿" - "﴿" -> "﴿|﴾" - else -> this - } -} - const val LAYOUT_SYMBOLS = "symbols" const val LAYOUT_SYMBOLS_SHIFTED = "symbols_shifted" const val LAYOUT_SYMBOLS_ARABIC = "symbols_arabic" diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyLabel.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyLabel.kt index b444045d1..01752b662 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyLabel.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyLabel.kt @@ -1,5 +1,7 @@ package helium314.keyboard.keyboard.internal.keyboard_parser.floris +import helium314.keyboard.keyboard.internal.KeyboardParams + /** labels for functional / special keys */ object KeyLabel { const val EMOJI = "emoji" @@ -45,4 +47,27 @@ object KeyLabel { else -> this } + fun String.rtlLabel(params: KeyboardParams): String { + if (!params.mId.mSubtype.isRtlSubtype || params.mId.isNumberLayout) return this + return when (this) { + "{" -> "{|}" + "}" -> "}|{" + "(" -> "(|)" + ")" -> ")|(" + "[" -> "[|]" + "]" -> "]|[" + "<" -> "<|>" + ">" -> ">|<" + "≤" -> "≤|≥" + "≥" -> "≥|≤" + "«" -> "«|»" + "»" -> "»|«" + "‹" -> "‹|›" + "›" -> "›|‹" + "﴾" -> "﴾|﴿" + "﴿" -> "﴿|﴾" + else -> this + } + } + } diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt index 4082a47cd..a0a5c1145 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt @@ -16,7 +16,7 @@ import helium314.keyboard.keyboard.internal.KeyboardIconsSet import helium314.keyboard.keyboard.internal.KeyboardParams import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode.checkAndConvertCode import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyLabel.convertFlorisLabel -import helium314.keyboard.keyboard.internal.keyboard_parser.rtlLabel +import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyLabel.rtlLabel import helium314.keyboard.latin.common.Constants import helium314.keyboard.latin.common.LocaleUtils.constructLocale import helium314.keyboard.latin.common.StringUtils @@ -284,12 +284,15 @@ sealed interface KeyData : AbstractKeyData { private const val POPUP_EYS_NAVIGATE_EMOJI_PREVIOUS_NEXT = "!fixedColumnOrder!4,!needsDividers!,!icon/previous_key|!code/key_action_previous,!icon/clipboard_action_key|!code/key_clipboard,!icon/emoji_action_key|!code/key_emoji,!icon/next_key|!code/key_action_next" } - // make it non-nullable for simplicity, and to reflect current implementations - override fun compute(params: KeyboardParams): KeyData { + override fun compute(params: KeyboardParams): KeyData? { require(groupId <= GROUP_ENTER) { "only groups up to GROUP_ENTER are supported" } require(label.isNotEmpty() || type == KeyType.PLACEHOLDER || code != KeyCode.UNSPECIFIED) { "non-placeholder key has no code and no label" } require(width >= 0f || width == -1f) { "illegal width $width" } val newLabel = label.convertFlorisLabel().resolveStringLabel(params) + if (newLabel == KeyLabel.SHIFT && params.mId.isAlphabetKeyboard + && params.mId.mSubtype.keyboardLayoutSetName in listOf("hindi_compact", "bengali", "arabic", "arabic_pc", "hebrew", "kannada", "kannada_extended","malayalam", "marathi", "farsi", "tamil", "telugu")) { + return null // these layouts have no shift key, todo: should be in subtype extras + } val newCode = code.checkAndConvertCode() val newLabelFlags = if (labelFlags == 0 && params.mId.isNumberLayout) { if (type == KeyType.NUMERIC) { diff --git a/app/src/main/java/helium314/keyboard/latin/utils/PopupKeysUtils.kt b/app/src/main/java/helium314/keyboard/latin/utils/PopupKeysUtils.kt index e08d16995..167aacfa3 100644 --- a/app/src/main/java/helium314/keyboard/latin/utils/PopupKeysUtils.kt +++ b/app/src/main/java/helium314/keyboard/latin/utils/PopupKeysUtils.kt @@ -5,8 +5,8 @@ import android.content.SharedPreferences import helium314.keyboard.keyboard.Key import helium314.keyboard.keyboard.internal.KeySpecParser import helium314.keyboard.keyboard.internal.KeyboardParams +import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyLabel.rtlLabel import helium314.keyboard.keyboard.internal.keyboard_parser.floris.PopupSet -import helium314.keyboard.keyboard.internal.keyboard_parser.rtlLabel const val POPUP_KEYS_NUMBER = "popup_keys_number" private const val POPUP_KEYS_LANGUAGE_PRIORITY = "popup_keys_language_priority"