make remove redundant popup keys work on base layout only

fixes #1052
This commit is contained in:
Helium314 2025-01-05 22:05:55 +01:00
parent ca67fc71a6
commit 3989c1348a
4 changed files with 10 additions and 5 deletions

View file

@ -1052,7 +1052,6 @@ public class Key implements Comparable<Key> {
return popupKeysColumnAndFlags; return popupKeysColumnAndFlags;
} }
// only for testing
public String getOutputText() { public String getOutputText() {
return mOptionalAttributes == null ? null : mOptionalAttributes.mOutputText; return mOptionalAttributes == null ? null : mOptionalAttributes.mOutputText;
} }

View file

@ -98,6 +98,9 @@ public class KeyboardParams {
// should be enabled for all alphabet layouts, except for specific layouts when shifted // should be enabled for all alphabet layouts, except for specific layouts when shifted
public boolean mProximityCharsCorrectionEnabled; public boolean mProximityCharsCorrectionEnabled;
// only for removing redundant popup keys
public List<Key.KeyParams> baseKeys;
@NonNull @NonNull
public final TouchPositionCorrection mTouchPositionCorrection = new TouchPositionCorrection(); public final TouchPositionCorrection mTouchPositionCorrection = new TouchPositionCorrection();
@ -145,12 +148,12 @@ public class KeyboardParams {
} }
public void removeRedundantPopupKeys() { public void removeRedundantPopupKeys() {
if (mAllowRedundantPopupKeys) { if (mAllowRedundantPopupKeys || baseKeys == null) {
return; return;
} }
final PopupKeySpec.LettersOnBaseLayout lettersOnBaseLayout = final PopupKeySpec.LettersOnBaseLayout lettersOnBaseLayout =
new PopupKeySpec.LettersOnBaseLayout(); new PopupKeySpec.LettersOnBaseLayout();
for (final Key key : mSortedKeys) { for (final Key.KeyParams key : baseKeys) {
lettersOnBaseLayout.addLetter(key); lettersOnBaseLayout.addLetter(key);
} }
final ArrayList<Key> allKeys = new ArrayList<>(mSortedKeys); final ArrayList<Key> allKeys = new ArrayList<>(mSortedKeys);
@ -159,6 +162,7 @@ public class KeyboardParams {
final Key filteredKey = Key.removeRedundantPopupKeys(key, lettersOnBaseLayout); final Key filteredKey = Key.removeRedundantPopupKeys(key, lettersOnBaseLayout);
mSortedKeys.add(mUniqueKeysCache.getUniqueKey(filteredKey)); mSortedKeys.add(mUniqueKeysCache.getUniqueKey(filteredKey));
} }
baseKeys = null;
} }
private int mMaxHeightCount = 0; private int mMaxHeightCount = 0;

View file

@ -118,8 +118,8 @@ public final class PopupKeySpec {
private final SparseIntArray mCodes = new SparseIntArray(); private final SparseIntArray mCodes = new SparseIntArray();
private final HashSet<String> mTexts = new HashSet<>(); private final HashSet<String> mTexts = new HashSet<>();
public void addLetter(@NonNull final Key key) { public void addLetter(@NonNull final Key.KeyParams key) {
final int code = key.getCode(); final int code = key.mCode;
if (code > 32) { if (code > 32) {
mCodes.put(code, 0); mCodes.put(code, 0);
} else if (code == KeyCode.MULTIPLE_CODE_POINTS) { } else if (code == KeyCode.MULTIPLE_CODE_POINTS) {

View file

@ -91,6 +91,8 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co
if (params.mId.isAlphaOrSymbolKeyboard && params.mId.mNumberRowEnabled) if (params.mId.isAlphaOrSymbolKeyboard && params.mId.mNumberRowEnabled)
baseKeys.add(0, numberRow baseKeys.add(0, numberRow
.mapTo(mutableListOf()) { it.copy(newLabelFlags = Key.LABEL_FLAGS_DISABLE_HINT_LABEL or defaultLabelFlags) }) .mapTo(mutableListOf()) { it.copy(newLabelFlags = Key.LABEL_FLAGS_DISABLE_HINT_LABEL or defaultLabelFlags) })
if (!params.mAllowRedundantPopupKeys)
params.baseKeys = baseKeys.flatMap { it.map { it.toKeyParams(params) } }
val allFunctionalKeys = RawKeyboardParser.parseLayout(params, context, true) val allFunctionalKeys = RawKeyboardParser.parseLayout(params, context, true)
adjustBottomFunctionalRowAndBaseKeys(allFunctionalKeys, baseKeys) adjustBottomFunctionalRowAndBaseKeys(allFunctionalKeys, baseKeys)