mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-14 05:52:47 +00:00
simplify setting touchPositionCorrectionData
This commit is contained in:
parent
2cb2a5da21
commit
1f0f7f6b7c
2 changed files with 7 additions and 25 deletions
|
@ -53,6 +53,8 @@ open class KeyboardBuilder<KP : KeyboardParams>(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<KP : KeyboardParams>(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<KP : KeyboardParams>(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
|
||||
|
|
|
@ -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<Key> 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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue