aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2012-01-30 11:14:45 +0900
committerTadashi G. Takaoka <takaoka@google.com>2012-01-30 17:04:25 +0900
commit15c99e9f1a7776b95325d36cf9e38b6d674e483b (patch)
tree93a47af1ca7c59fdb17549ac24eee348e0bc4587 /java/src
parent38a3ad3e3ca1b4e594bcd189277454d12619b868 (diff)
downloadlatinime-15c99e9f1a7776b95325d36cf9e38b6d674e483b.tar.gz
latinime-15c99e9f1a7776b95325d36cf9e38b6d674e483b.tar.xz
latinime-15c99e9f1a7776b95325d36cf9e38b6d674e483b.zip
Support addtionalMoreKeys
This change also removes * Unused more_keys_for_q, w, and p. Change-Id: Idb99e5f6d8c2ad2d28437f42b35b21c282cd181f
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java15
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java1
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParser.java111
3 files changed, 78 insertions, 49 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index bb90653c1..a2d379643 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -285,22 +285,17 @@ public class Key {
mLabelFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelFlags, 0);
final boolean preserveCase = (mLabelFlags & LABEL_FLAGS_PRESERVE_CASE) != 0;
- final String[] moreKeys = style.getStringArray(keyAttr, R.styleable.Keyboard_Key_moreKeys);
+ final String[] additionalMoreKeys = style.getStringArray(
+ keyAttr, R.styleable.Keyboard_Key_additionalMoreKeys);
+ final String[] moreKeys = MoreKeySpecParser.insertAddtionalMoreKeys(style.getStringArray(
+ keyAttr, R.styleable.Keyboard_Key_moreKeys), additionalMoreKeys);
if (moreKeys != null) {
for (int i = 0; i < moreKeys.length; i++) {
moreKeys[i] = adjustCaseOfStringForKeyboardId(
moreKeys[i], preserveCase, params.mId);
}
}
- // TODO: Add new key label flag to control this.
- // In Arabic symbol layouts, we'd like to keep digits in more keys regardless of
- // config_digit_more_keys_enabled.
- if (params.mId.isAlphabetKeyboard()
- && !res.getBoolean(R.bool.config_digit_more_keys_enabled)) {
- mMoreKeys = MoreKeySpecParser.filterOut(res, moreKeys, MoreKeySpecParser.DIGIT_FILTER);
- } else {
- mMoreKeys = moreKeys;
- }
+ mMoreKeys = moreKeys;
mMaxMoreKeysColumn = style.getInt(keyAttr,
R.styleable.Keyboard_Key_maxMoreKeysColumn, params.mMaxMiniKeyboardColumn);
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
index b7215ec1b..1450192b2 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
@@ -173,6 +173,7 @@ public class KeyStyles {
readString(keyAttr, R.styleable.Keyboard_Key_keyOutputText);
readString(keyAttr, R.styleable.Keyboard_Key_keyHintLabel);
readStringArray(keyAttr, R.styleable.Keyboard_Key_moreKeys);
+ readStringArray(keyAttr, R.styleable.Keyboard_Key_additionalMoreKeys);
readFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelFlags);
readInt(keyAttr, R.styleable.Keyboard_Key_keyIcon);
readInt(keyAttr, R.styleable.Keyboard_Key_keyIconDisabled);
diff --git a/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParser.java b/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParser.java
index 16777733e..abebfec01 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParser.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParser.java
@@ -20,10 +20,12 @@ import android.content.res.Resources;
import android.text.TextUtils;
import com.android.inputmethod.keyboard.Keyboard;
+import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.Utils;
import java.util.ArrayList;
+import java.util.Arrays;
/**
* String parser of moreKeys attribute of Key.
@@ -38,9 +40,11 @@ import java.util.ArrayList;
* See {@link KeyboardIconsSet} about icon_number.
*/
public class MoreKeySpecParser {
+ private static final boolean DEBUG = LatinImeLogger.sDBG;
private static final char LABEL_END = '|';
private static final String PREFIX_ICON = Utils.PREFIX_AT + "icon" + Utils.SUFFIX_SLASH;
private static final String PREFIX_CODE = Utils.PREFIX_AT + "integer" + Utils.SUFFIX_SLASH;
+ private static final String ADDITIONAL_MORE_KEY_MARKER = "%";
private MoreKeySpecParser() {
// Intentional empty constructor for utility class.
@@ -173,51 +177,80 @@ public class MoreKeySpecParser {
return KeyboardIconsSet.ICON_UNDEFINED;
}
- @SuppressWarnings("serial")
- public static class MoreKeySpecParserError extends RuntimeException {
- public MoreKeySpecParserError(String message) {
- super(message);
- }
- }
-
- public interface CodeFilter {
- public boolean shouldFilterOut(int code);
- }
-
- public static final CodeFilter DIGIT_FILTER = new CodeFilter() {
- @Override
- public boolean shouldFilterOut(int code) {
- return Character.isDigit(code);
- }
- };
-
- public static String[] filterOut(Resources res, String[] moreKeys, CodeFilter filter) {
- if (moreKeys == null || moreKeys.length < 1) {
- return null;
- }
- if (moreKeys.length == 1 && filter.shouldFilterOut(getCode(res, moreKeys[0]))) {
- return null;
- }
- ArrayList<String> filtered = null;
- for (int i = 0; i < moreKeys.length; i++) {
- final String moreKeySpec = moreKeys[i];
- if (filter.shouldFilterOut(getCode(res, moreKeySpec))) {
- if (filtered == null) {
- filtered = new ArrayList<String>();
- for (int j = 0; j < i; j++) {
- filtered.add(moreKeys[j]);
+ public static String[] insertAddtionalMoreKeys(String[] moreKeys, String[] additionalMoreKeys) {
+ final int moreKeysCount = (moreKeys != null) ? moreKeys.length : 0;
+ final int additionalCount = (additionalMoreKeys != null) ? additionalMoreKeys.length : 0;
+ ArrayList<String> out = null;
+ int additionalIndex = 0;
+ for (int moreKeyIndex = 0; moreKeyIndex < moreKeysCount; moreKeyIndex++) {
+ final String moreKeySpec = moreKeys[moreKeyIndex];
+ if (moreKeySpec.equals(ADDITIONAL_MORE_KEY_MARKER)) {
+ if (additionalIndex < additionalCount) {
+ // Replace '%' marker with additional more key specification.
+ final String additionalMoreKey = additionalMoreKeys[additionalIndex];
+ if (out != null) {
+ out.add(additionalMoreKey);
+ } else {
+ moreKeys[moreKeyIndex] = additionalMoreKey;
+ }
+ additionalIndex++;
+ } else {
+ // Filter out excessive '%' marker.
+ if (out == null) {
+ out = new ArrayList<String>(moreKeyIndex);
+ for (int i = 0; i < moreKeyIndex; i++) {
+ out.add(moreKeys[i]);
+ }
}
}
- } else if (filtered != null) {
- filtered.add(moreKeySpec);
+ } else {
+ if (out != null) {
+ out.add(moreKeySpec);
+ }
+ }
+ }
+ if (additionalCount > 0 && additionalIndex == 0) {
+ // No '%' marker is found in more keys.
+ // Insert all additional more keys to the head of more keys.
+ if (DEBUG && out != null) {
+ throw new RuntimeException("Internal logic error:"
+ + " moreKeys=" + Arrays.toString(moreKeys)
+ + " additionalMoreKeys=" + Arrays.toString(additionalMoreKeys));
+ }
+ out = new ArrayList<String>(additionalCount + moreKeysCount);
+ for (int i = additionalIndex; i < additionalCount; i++) {
+ out.add(additionalMoreKeys[i]);
+ }
+ for (int i = 0; i < moreKeysCount; i++) {
+ out.add(moreKeys[i]);
+ }
+ } else if (additionalIndex < additionalCount) {
+ // The number of '%' markers are less than additional more keys.
+ // Append remained additional more keys to the tail of more keys.
+ if (DEBUG && out != null) {
+ throw new RuntimeException("Internal logic error:"
+ + " moreKeys=" + Arrays.toString(moreKeys)
+ + " additionalMoreKeys=" + Arrays.toString(additionalMoreKeys));
+ }
+ out = new ArrayList<String>(moreKeysCount);
+ for (int i = 0; i < moreKeysCount; i++) {
+ out.add(moreKeys[i]);
+ }
+ for (int i = additionalIndex; i < additionalCount; i++) {
+ out.add(additionalMoreKeys[additionalIndex]);
}
}
- if (filtered == null) {
+ if (out != null) {
+ return out.size() > 0 ? out.toArray(new String[out.size()]) : null;
+ } else {
return moreKeys;
}
- if (filtered.size() == 0) {
- return null;
+ }
+
+ @SuppressWarnings("serial")
+ public static class MoreKeySpecParserError extends RuntimeException {
+ public MoreKeySpecParserError(String message) {
+ super(message);
}
- return filtered.toArray(new String[filtered.size()]);
}
}