mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-14 14:02:44 +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 {
|
try {
|
||||||
setupParams()
|
setupParams()
|
||||||
keysInRows = KeyboardParser(mParams, mContext).parseLayout()
|
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()
|
determineAbsoluteValues()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "error parsing layout $id ${id.mElementId}", e)
|
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() {
|
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
|
// previously was false for nordic and serbian_qwertz, true for all others
|
||||||
// todo: add setting? maybe users want it in a custom layout
|
// todo: add setting? maybe users want it in a custom layout
|
||||||
mParams.mAllowRedundantPopupKeys = mParams.mId.mElementId != KeyboardId.ELEMENT_SYMBOLS
|
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.mProximityCharsCorrectionEnabled = mParams.mId.mElementId == KeyboardId.ELEMENT_ALPHABET
|
||||||
|| (mParams.mId.isAlphabetKeyboard && !mParams.mId.mSubtype.hasExtraValue(Constants.Subtype.ExtraValue.NO_SHIFT_PROXIMITY_CORRECTION))
|
|| (mParams.mId.isAlphabetKeyboard && !mParams.mId.mSubtype.hasExtraValue(Constants.Subtype.ExtraValue.NO_SHIFT_PROXIMITY_CORRECTION))
|
||||||
|
|
||||||
|
val sv = Settings.getInstance().current
|
||||||
addLocaleKeyTextsToParams(mContext, mParams, sv.mShowMorePopupKeys)
|
addLocaleKeyTextsToParams(mContext, mParams, sv.mShowMorePopupKeys)
|
||||||
mParams.mPopupKeyTypes.addAll(sv.mPopupKeyTypes)
|
mParams.mPopupKeyTypes.addAll(sv.mPopupKeyTypes)
|
||||||
// add label source only if popup key type enabled
|
// 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.keyboard.internal.keyboard_parser.floris.KeyCode;
|
||||||
import helium314.keyboard.latin.R;
|
import helium314.keyboard.latin.R;
|
||||||
import helium314.keyboard.latin.settings.Settings;
|
import helium314.keyboard.latin.settings.Settings;
|
||||||
import helium314.keyboard.latin.utils.Log;
|
|
||||||
import helium314.keyboard.latin.utils.ResourceUtils;
|
import helium314.keyboard.latin.utils.ResourceUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -98,8 +97,7 @@ public class KeyboardParams {
|
||||||
public boolean mProximityCharsCorrectionEnabled;
|
public boolean mProximityCharsCorrectionEnabled;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public final TouchPositionCorrection mTouchPositionCorrection =
|
public final TouchPositionCorrection mTouchPositionCorrection = new TouchPositionCorrection();
|
||||||
new TouchPositionCorrection();
|
|
||||||
|
|
||||||
// Comparator to sort {@link Key}s from top-left to bottom-right order.
|
// Comparator to sort {@link Key}s from top-left to bottom-right order.
|
||||||
private static final Comparator<Key> ROW_COLUMN_COMPARATOR = (lhs, rhs) -> {
|
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);
|
mThemeId = keyboardAttr.getInt(R.styleable.Keyboard_themeId, 0);
|
||||||
mIconsSet.loadIcons(keyboardAttr);
|
mIconsSet.loadIcons(keyboardAttr);
|
||||||
|
|
||||||
// todo: this clashes with the other way of doing it... now both moved here, in same order
|
// touchPositionResId currently is 0 for popups, and touch_position_correction_data_holo for others
|
||||||
// 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);
|
final int touchPositionResId = keyboardAttr.getResourceId(R.styleable.Keyboard_touchPositionCorrectionData, 0);
|
||||||
if (touchPositionResId != 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);
|
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 {
|
} finally {
|
||||||
keyAttr.recycle();
|
keyAttr.recycle();
|
||||||
keyboardAttr.recycle();
|
keyboardAttr.recycle();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue