From 1f0f7f6b7c8dc6b9d10da9410da42a30a929c55f Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sat, 18 May 2024 15:59:47 +0200 Subject: [PATCH] simplify setting touchPositionCorrectionData --- .../keyboard/internal/KeyboardBuilder.kt | 6 ++--- .../keyboard/internal/KeyboardParams.java | 26 +++---------------- 2 files changed, 7 insertions(+), 25 deletions(-) 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 5171199d8..73f6c01b4 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt @@ -53,6 +53,8 @@ open class KeyboardBuilder(protected val mContext: Context, try { setupParams() keysInRows = KeyboardParser(mParams, mContext).parseLayout() + if (keysInRows.size != 4) // that was effectively the default for OpenBoard + mParams.mTouchPositionCorrection.load(mContext.resources.getStringArray(R.array.touch_position_correction_data_default)) determineAbsoluteValues() } catch (e: Exception) { Log.e(TAG, "error parsing layout $id ${id.mElementId}", e) @@ -63,9 +65,6 @@ open class KeyboardBuilder(protected val mContext: Context, } 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 @@ -73,6 +72,7 @@ open class KeyboardBuilder(protected val mContext: Context, mParams.mProximityCharsCorrectionEnabled = mParams.mId.mElementId == KeyboardId.ELEMENT_ALPHABET || (mParams.mId.isAlphabetKeyboard && !mParams.mId.mSubtype.hasExtraValue(Constants.Subtype.ExtraValue.NO_SHIFT_PROXIMITY_CORRECTION)) + val sv = Settings.getInstance().current addLocaleKeyTextsToParams(mContext, mParams, sv.mShowMorePopupKeys) mParams.mPopupKeyTypes.addAll(sv.mPopupKeyTypes) // add label source only if popup key type enabled 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 e3c9fd911..9d39c79d6 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardParams.java +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardParams.java @@ -20,7 +20,6 @@ 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; @@ -98,8 +97,7 @@ public class KeyboardParams { public boolean mProximityCharsCorrectionEnabled; @NonNull - public final TouchPositionCorrection mTouchPositionCorrection = - new TouchPositionCorrection(); + public final TouchPositionCorrection mTouchPositionCorrection = new TouchPositionCorrection(); // Comparator to sort {@link Key}s from top-left to bottom-right order. private static final Comparator ROW_COLUMN_COMPARATOR = (lhs, rhs) -> { @@ -269,29 +267,13 @@ public class KeyboardParams { mThemeId = keyboardAttr.getInt(R.styleable.Keyboard_themeId, 0); mIconsSet.loadIcons(keyboardAttr); - // 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 + // touchPositionResId currently is 0 for popups, and touch_position_correction_data_holo for others final int touchPositionResId = keyboardAttr.getResourceId(R.styleable.Keyboard_touchPositionCorrectionData, 0); if (touchPositionResId != 0) { - final String[] data = context.getResources().getStringArray(touchPositionResId); + final int actualId = mId.isAlphabetKeyboard() ? touchPositionResId : R.array.touch_position_correction_data_default; + final String[] data = context.getResources().getStringArray(actualId); 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();