diff --git a/java/res/values-ar/donottranslate-more-keys.xml b/java/res/values-ar/donottranslate-more-keys.xml
index 9a7a0267a..a5f35bb88 100644
--- a/java/res/values-ar/donottranslate-more-keys.xml
+++ b/java/res/values-ar/donottranslate-more-keys.xml
@@ -104,14 +104,14 @@
★,\u066d
- )
- (
+ 0x0029
+ 0x0028
[|],{|},<|>,\ufd3e|\ufd3f
]|[,}|{,>|<,\ufd3f|\ufd3e
- >
- <
+ 0x003e
+ 0x003c
\u2264|\u2265,\u00ab|\u00bb,\u2039|\u203a
\u2265|\u2264,\u00bb|\u00ab,\u203a|\u2039
- ]
- [
- }
- {
+ 0x005d
+ 0x005b
+ 0x007d
+ 0x007b
diff --git a/java/res/values-iw/donottranslate-more-keys.xml b/java/res/values-iw/donottranslate-more-keys.xml
index 6fc336002..f44ff2123 100644
--- a/java/res/values-iw/donottranslate-more-keys.xml
+++ b/java/res/values-iw/donottranslate-more-keys.xml
@@ -22,12 +22,12 @@
±,﬩
- )
- (
+ 0x0029
+ 0x0028
[|],{|},<|>
]|[,}|{,>|<
- >
- <
+ 0x003e
+ 0x003c
\u2264|\u2265,\u00ab|\u00bb,\u2039|\u203a
\u2265|\u2264,\u00bb|\u00ab,\u203a|\u2039
- ]
- [
- }
- {
+ 0x005d
+ 0x005b
+ 0x007d
+ 0x007b
diff --git a/java/res/values/donottranslate-more-keys.xml b/java/res/values/donottranslate-more-keys.xml
index d7b1ff5e7..d78e41fb1 100644
--- a/java/res/values/donottranslate-more-keys.xml
+++ b/java/res/values/donottranslate-more-keys.xml
@@ -114,12 +114,12 @@
±
- (
- )
+ 0x0028
+ 0x0029
[,{,<
],},>
- <
- >
+ 0x003c
+ 0x003e
\u2264,\u00ab,\u2039
\u2265,\u00bb,\u203a
- [
- ]
- {
- }
+ 0x005b
+ 0x005d
+ 0x007b
+ 0x007d
\u2019,\u201a,\u2018,\u201b
diff --git a/java/res/xml/keys_curly_brackets.xml b/java/res/xml/keys_curly_brackets.xml
index b43fbb1fe..d21a09281 100644
--- a/java/res/xml/keys_curly_brackets.xml
+++ b/java/res/xml/keys_curly_brackets.xml
@@ -23,8 +23,8 @@
>
+ latin:code="@integer/keycode_for_left_curly_bracket" />
+ latin:code="@integer/keycode_for_right_curly_bracket" />
diff --git a/java/res/xml/keys_less_greater.xml b/java/res/xml/keys_less_greater.xml
index 8e90199fe..8961d9ce6 100644
--- a/java/res/xml/keys_less_greater.xml
+++ b/java/res/xml/keys_less_greater.xml
@@ -23,10 +23,10 @@
>
diff --git a/java/res/xml/keys_parentheses.xml b/java/res/xml/keys_parentheses.xml
index bacb26d2f..6853bf167 100644
--- a/java/res/xml/keys_parentheses.xml
+++ b/java/res/xml/keys_parentheses.xml
@@ -23,10 +23,10 @@
>
diff --git a/java/res/xml/keys_square_brackets.xml b/java/res/xml/keys_square_brackets.xml
index 3525f4d5a..44387c3bf 100644
--- a/java/res/xml/keys_square_brackets.xml
+++ b/java/res/xml/keys_square_brackets.xml
@@ -23,8 +23,8 @@
>
+ latin:code="@integer/keycode_for_left_square_bracket" />
+ latin:code="@integer/keycode_for_right_square_bracket" />
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index c31bcf23e..6eaa606db 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -247,14 +247,14 @@ public class Key {
mMaxMoreKeysColumn = style.getInt(keyAttr,
R.styleable.Keyboard_Key_maxMoreKeysColumn, params.mMaxMiniKeyboardColumn);
- mLabel = adjustCaseOfStringForKeyboardId(style.getString(
- keyAttr, R.styleable.Keyboard_Key_keyLabel), preserveCase, params.mId);
- mHintLabel = adjustCaseOfStringForKeyboardId(style.getString(
- keyAttr, R.styleable.Keyboard_Key_keyHintLabel), preserveCase, params.mId);
- String outputText = adjustCaseOfStringForKeyboardId(style.getString(
- keyAttr, R.styleable.Keyboard_Key_keyOutputText), preserveCase, params.mId);
- final int code = style.getInt(
- keyAttr, R.styleable.Keyboard_Key_code, Keyboard.CODE_UNSPECIFIED);
+ mLabel = adjustCaseOfStringForKeyboardId(style.getString(keyAttr,
+ R.styleable.Keyboard_Key_keyLabel), preserveCase, params.mId);
+ mHintLabel = adjustCaseOfStringForKeyboardId(style.getString(keyAttr,
+ R.styleable.Keyboard_Key_keyHintLabel), preserveCase, params.mId);
+ String outputText = adjustCaseOfStringForKeyboardId(style.getString(keyAttr,
+ R.styleable.Keyboard_Key_keyOutputText), preserveCase, params.mId);
+ final int code = style.getInt(keyAttr,
+ R.styleable.Keyboard_Key_code, Keyboard.CODE_UNSPECIFIED);
// Choose the first letter of the label as primary code if not specified.
if (code == Keyboard.CODE_UNSPECIFIED && TextUtils.isEmpty(outputText)
&& !TextUtils.isEmpty(mLabel)) {
@@ -274,7 +274,12 @@ public class Key {
mCode = Keyboard.CODE_OUTPUT_TEXT;
}
} else if (code == Keyboard.CODE_UNSPECIFIED && outputText != null) {
- mCode = Keyboard.CODE_OUTPUT_TEXT;
+ if (Utils.codePointCount(outputText) == 1) {
+ mCode = outputText.codePointAt(0);
+ outputText = null;
+ } else {
+ mCode = Keyboard.CODE_OUTPUT_TEXT;
+ }
} else {
mCode = adjustCaseOfCodeForKeyboardId(code, preserveCase, params.mId);
}
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java
index e3c5da456..1626a140b 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java
@@ -133,18 +133,28 @@ public class KeySpecParser {
return label;
}
+ private static String getOutputTextInternal(String moreKeySpec) {
+ final int end = indexOfLabelEnd(moreKeySpec, 0);
+ if (end <= 0) {
+ return null;
+ }
+ if (indexOfLabelEnd(moreKeySpec, end + 1) >= 0) {
+ throw new KeySpecParserError("Multiple " + LABEL_END + ": " + moreKeySpec);
+ }
+ return parseEscape(moreKeySpec.substring(end + /* LABEL_END */1));
+ }
+
public static String getOutputText(String moreKeySpec) {
if (hasCode(moreKeySpec)) {
return null;
}
- final int end = indexOfLabelEnd(moreKeySpec, 0);
- if (end > 0) {
- if (indexOfLabelEnd(moreKeySpec, end + 1) >= 0) {
- throw new KeySpecParserError("Multiple " + LABEL_END + ": "
- + moreKeySpec);
+ final String outputText = getOutputTextInternal(moreKeySpec);
+ if (outputText != null) {
+ if (Utils.codePointCount(outputText) == 1) {
+ // If output text is one code point, it should be treated as a code.
+ // See {@link #getCode(Resources, String)}.
+ return null;
}
- final String outputText = parseEscape(
- moreKeySpec.substring(end + /* LABEL_END */1));
if (!TextUtils.isEmpty(outputText)) {
return outputText;
}
@@ -170,7 +180,13 @@ public class KeySpecParser {
final int code = res.getInteger(resId);
return code;
}
- if (indexOfLabelEnd(moreKeySpec, 0) > 0) {
+ final String outputText = getOutputTextInternal(moreKeySpec);
+ if (outputText != null) {
+ // If output text is one code point, it should be treated as a code.
+ // See {@link #getOutputText(String)}.
+ if (Utils.codePointCount(outputText) == 1) {
+ return outputText.codePointAt(0);
+ }
return Keyboard.CODE_OUTPUT_TEXT;
}
final String label = getLabel(moreKeySpec);
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java
index 429e16d5f..07f5848b2 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java
@@ -109,6 +109,10 @@ public class KeySpecParserTests extends AndroidTestCase {
"@", null, ICON_UNDEFINED, '@');
assertParser("Single escaped at", "\\@",
"@", null, ICON_UNDEFINED, '@');
+ assertParser("Single output text letter", "a|a",
+ "a", null, ICON_UNDEFINED, 'a');
+ assertParser("Single surrogate pair outputText", "G Clef|" + PAIR1,
+ "G Clef", null, ICON_UNDEFINED, CODE1);
assertParser("Single letter with outputText", "a|abc",
"a", "abc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
assertParser("Single letter with surrogate outputText", "a|" + SURROGATE1,
@@ -132,10 +136,10 @@ public class KeySpecParserTests extends AndroidTestCase {
"a", "a@c", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
assertParser("Single letter with escaped at outputText", "a|\\@bc",
"a", "@bc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
- assertParser("Single escaped escape with outputText", "\\\\|\\\\",
- "\\", "\\", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
- assertParser("Single escaped bar with outputText", "\\||\\|",
- "|", "|", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
+ assertParser("Single escaped escape with single outputText", "\\\\|\\\\",
+ "\\", null, ICON_UNDEFINED, '\\');
+ assertParser("Single escaped bar with single outputText", "\\||\\|",
+ "|", null, ICON_UNDEFINED, '|');
assertParser("Single letter with code", "a|" + CODE_SETTINGS,
"a", null, ICON_UNDEFINED, mCodeSettings);
}