Skip to content

Commit

Permalink
make remove redundant popup keys work on base layout only
Browse files Browse the repository at this point in the history
fixes #1052
  • Loading branch information
Helium314 committed Jan 5, 2025
1 parent ca67fc7 commit 3989c13
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
1 change: 0 additions & 1 deletion app/src/main/java/helium314/keyboard/keyboard/Key.java
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,6 @@ private static int getPopupKeysColumnAndFlagsAndSetNullInArray(final KeyboardPar
return popupKeysColumnAndFlags;
}

// only for testing
public String getOutputText() {
return mOptionalAttributes == null ? null : mOptionalAttributes.mOutputText;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public class KeyboardParams {
// should be enabled for all alphabet layouts, except for specific layouts when shifted
public boolean mProximityCharsCorrectionEnabled;

// only for removing redundant popup keys
public List<Key.KeyParams> baseKeys;

@NonNull
public final TouchPositionCorrection mTouchPositionCorrection = new TouchPositionCorrection();

Expand Down Expand Up @@ -145,12 +148,12 @@ public void onAddKey(@NonNull final Key newKey) {
}

public void removeRedundantPopupKeys() {
if (mAllowRedundantPopupKeys) {
if (mAllowRedundantPopupKeys || baseKeys == null) {
return;
}
final PopupKeySpec.LettersOnBaseLayout lettersOnBaseLayout =
new PopupKeySpec.LettersOnBaseLayout();
for (final Key key : mSortedKeys) {
for (final Key.KeyParams key : baseKeys) {
lettersOnBaseLayout.addLetter(key);
}
final ArrayList<Key> allKeys = new ArrayList<>(mSortedKeys);
Expand All @@ -159,6 +162,7 @@ public void removeRedundantPopupKeys() {
final Key filteredKey = Key.removeRedundantPopupKeys(key, lettersOnBaseLayout);
mSortedKeys.add(mUniqueKeysCache.getUniqueKey(filteredKey));
}
baseKeys = null;
}

private int mMaxHeightCount = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public static class LettersOnBaseLayout {
private final SparseIntArray mCodes = new SparseIntArray();
private final HashSet<String> mTexts = new HashSet<>();

public void addLetter(@NonNull final Key key) {
final int code = key.getCode();
public void addLetter(@NonNull final Key.KeyParams key) {
final int code = key.mCode;
if (code > 32) {
mCodes.put(code, 0);
} else if (code == KeyCode.MULTIPLE_CODE_POINTS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co
if (params.mId.isAlphaOrSymbolKeyboard && params.mId.mNumberRowEnabled)
baseKeys.add(0, numberRow
.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)
adjustBottomFunctionalRowAndBaseKeys(allFunctionalKeys, baseKeys)
Expand Down

0 comments on commit 3989c13

Please # to comment.