mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Remove duplicate moreKeys
This commit is contained in:
parent
b182a9cc4e
commit
b3d12fc7a1
@ -465,11 +465,18 @@ public class Key implements Comparable<Key> {
|
||||
|
||||
@Nonnull
|
||||
public static Key removeRedundantMoreKeys(@Nonnull final Key key,
|
||||
@Nonnull final MoreKeySpec.LettersOnBaseLayout lettersOnBaseLayout) {
|
||||
@Nonnull final MoreKeySpec.LettersOnBaseLayout lettersOnBaseLayout, boolean onlyDuplicateKeys) {
|
||||
final MoreKeySpec[] moreKeys = key.getMoreKeys();
|
||||
final MoreKeySpec[] filteredMoreKeys = MoreKeySpec.removeRedundantMoreKeys(
|
||||
moreKeys, lettersOnBaseLayout);
|
||||
return (filteredMoreKeys == moreKeys) ? key : new Key(key, filteredMoreKeys);
|
||||
|
||||
MoreKeySpec[] clearedMoreKeys = moreKeys;
|
||||
|
||||
clearedMoreKeys = MoreKeySpec.removeDuplicateMoreKeys(moreKeys);
|
||||
|
||||
if(!onlyDuplicateKeys) {
|
||||
clearedMoreKeys = MoreKeySpec.removeRedundantMoreKeys(
|
||||
moreKeys, lettersOnBaseLayout);
|
||||
}
|
||||
return (clearedMoreKeys == moreKeys) ? key : new Key(key, clearedMoreKeys);
|
||||
}
|
||||
|
||||
private static boolean needsToUpcase(final int labelFlags, final int keyboardElementId) {
|
||||
|
@ -139,9 +139,6 @@ public class KeyboardParams {
|
||||
}
|
||||
|
||||
public void removeRedundantMoreKeys() {
|
||||
if (mAllowRedundantMoreKeys) {
|
||||
return;
|
||||
}
|
||||
final MoreKeySpec.LettersOnBaseLayout lettersOnBaseLayout =
|
||||
new MoreKeySpec.LettersOnBaseLayout();
|
||||
for (final Key key : mSortedKeys) {
|
||||
@ -150,7 +147,7 @@ public class KeyboardParams {
|
||||
final ArrayList<Key> allKeys = new ArrayList<>(mSortedKeys);
|
||||
mSortedKeys.clear();
|
||||
for (final Key key : allKeys) {
|
||||
final Key filteredKey = Key.removeRedundantMoreKeys(key, lettersOnBaseLayout);
|
||||
final Key filteredKey = Key.removeRedundantMoreKeys(key, lettersOnBaseLayout, mAllowRedundantMoreKeys);
|
||||
mSortedKeys.add(mUniqueKeysCache.getUniqueKey(filteredKey));
|
||||
}
|
||||
}
|
||||
|
@ -169,6 +169,29 @@ public final class MoreKeySpec {
|
||||
return filteredMoreKeys.toArray(new MoreKeySpec[size]);
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public static MoreKeySpec[] removeDuplicateMoreKeys(@Nullable final MoreKeySpec[] moreKeys) {
|
||||
if (moreKeys == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final ArrayList<MoreKeySpec> filteredMoreKeys = new ArrayList<>();
|
||||
for (final MoreKeySpec moreKey : moreKeys) {
|
||||
if (!filteredMoreKeys.contains(moreKey)) {
|
||||
filteredMoreKeys.add(moreKey);
|
||||
}
|
||||
}
|
||||
|
||||
final int size = filteredMoreKeys.size();
|
||||
if (size == moreKeys.length) {
|
||||
return moreKeys;
|
||||
}
|
||||
|
||||
return filteredMoreKeys.toArray(new MoreKeySpec[size]);
|
||||
}
|
||||
|
||||
|
||||
// Constants for parsing.
|
||||
private static final char COMMA = Constants.CODE_COMMA;
|
||||
private static final char BACKSLASH = Constants.CODE_BACKSLASH;
|
||||
|
Loading…
Reference in New Issue
Block a user