Convert one letter Key.outputText to Key.code
This change also uses Key.code instead of Key.outputText for the variety of parentheses keys taht introduced by I85998f17. Bug: 5975484 Change-Id: I86879c9942d264edc71e5893325a2f582763d12fmain
parent
69f672a4b3
commit
c217dc9237
|
@ -104,14 +104,14 @@
|
|||
<string name="more_keys_for_star">★,\u066d</string>
|
||||
<!-- The all letters need to be mirrored are found at
|
||||
http://www.unicode.org/Public/6.1.0/ucd/BidiMirroring.txt -->
|
||||
<string name="output_text_for_left_parenthesis">)</string>
|
||||
<string name="output_text_for_right_parenthesis">(</string>
|
||||
<integer name="keycode_for_left_parenthesis">0x0029</integer>
|
||||
<integer name="keycode_for_right_parenthesis">0x0028</integer>
|
||||
<!-- \ufd3e: ORNATE LEFT PARENTHESIS
|
||||
\ufd3f: ORNATE RIGHT PARENTHESIS -->
|
||||
<string name="more_keys_for_left_parenthesis">[|],{|},<|>,\ufd3e|\ufd3f</string>
|
||||
<string name="more_keys_for_right_parenthesis">]|[,}|{,>|<,\ufd3f|\ufd3e</string>
|
||||
<string name="output_text_for_less_than">></string>
|
||||
<string name="output_text_for_greater_than"><</string>
|
||||
<integer name="keycode_for_less_than">0x003e</integer>
|
||||
<integer name="keycode_for_greater_than">0x003c</integer>
|
||||
<!-- \u2264: LESS-THAN OR EQUAL TO
|
||||
\u2265: GREATER-THAN EQUAL TO
|
||||
\u00ab: LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
|
@ -129,10 +129,10 @@
|
|||
\u201f: DOUBLE HIGH-REVERSED-9 QUOTATION MARK -->
|
||||
<string name="more_keys_for_less_than">\u2264|\u2265,\u00ab|\u00bb,\u2039|\u203a</string>
|
||||
<string name="more_keys_for_greater_than">\u2265|\u2264,\u00bb|\u00ab,\u203a|\u2039</string>
|
||||
<string name="output_text_for_left_square_bracket">]</string>
|
||||
<string name="output_text_for_right_square_bracket">[</string>
|
||||
<string name="output_text_for_left_curly_bracket">}</string>
|
||||
<string name="output_text_for_right_curly_bracket">{</string>
|
||||
<integer name="keycode_for_left_square_bracket">0x005d</integer>
|
||||
<integer name="keycode_for_right_square_bracket">0x005b</integer>
|
||||
<integer name="keycode_for_left_curly_bracket">0x007d</integer>
|
||||
<integer name="keycode_for_right_curly_bracket">0x007b</integer>
|
||||
<!-- Note: Neither DroidSans nor Roboto have a glyph for DOUBLE HIGH-REVERSED-9 QUOTATION MARK. -->
|
||||
<!-- <string name="more_keys_for_double_quote">\u201c,\u201d,\u201e,\u201f,\u00ab,\u00bb</string> -->
|
||||
<!-- The 4-more keys will be displayed in order of "3,1,2,4". -->
|
||||
|
|
|
@ -22,12 +22,12 @@
|
|||
<string name="more_keys_for_plus">±,﬩</string>
|
||||
<!-- The all letters need to be mirrored are found at
|
||||
http://www.unicode.org/Public/6.1.0/ucd/BidiMirroring.txt -->
|
||||
<string name="output_text_for_left_parenthesis">)</string>
|
||||
<string name="output_text_for_right_parenthesis">(</string>
|
||||
<integer name="keycode_for_left_parenthesis">0x0029</integer>
|
||||
<integer name="keycode_for_right_parenthesis">0x0028</integer>
|
||||
<string name="more_keys_for_left_parenthesis">[|],{|},<|></string>
|
||||
<string name="more_keys_for_right_parenthesis">]|[,}|{,>|<</string>
|
||||
<string name="output_text_for_less_than">></string>
|
||||
<string name="output_text_for_greater_than"><</string>
|
||||
<integer name="keycode_for_less_than">0x003e</integer>
|
||||
<integer name="keycode_for_greater_than">0x003c</integer>
|
||||
<!-- \u2264: LESS-THAN OR EQUAL TO
|
||||
\u2265: GREATER-THAN EQUAL TO
|
||||
\u00ab: LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
|
@ -45,10 +45,10 @@
|
|||
\u201f: DOUBLE HIGH-REVERSED-9 QUOTATION MARK -->
|
||||
<string name="more_keys_for_less_than">\u2264|\u2265,\u00ab|\u00bb,\u2039|\u203a</string>
|
||||
<string name="more_keys_for_greater_than">\u2265|\u2264,\u00bb|\u00ab,\u203a|\u2039</string>
|
||||
<string name="output_text_for_left_square_bracket">]</string>
|
||||
<string name="output_text_for_right_square_bracket">[</string>
|
||||
<string name="output_text_for_left_curly_bracket">}</string>
|
||||
<string name="output_text_for_right_curly_bracket">{</string>
|
||||
<integer name="keycode_for_left_square_bracket">0x005d</integer>
|
||||
<integer name="keycode_for_right_square_bracket">0x005b</integer>
|
||||
<integer name="keycode_for_left_curly_bracket">0x007d</integer>
|
||||
<integer name="keycode_for_right_curly_bracket">0x007b</integer>
|
||||
<!-- Note: Neither DroidSans nor Roboto have a glyph for DOUBLE HIGH-REVERSED-9 QUOTATION MARK. -->
|
||||
<!-- <string name="more_keys_for_double_quote">\u201c,\u201d,\u201e,\u201f,\u00ab,\u00bb</string> -->
|
||||
<!-- The 4-more keys will be displayed in order of "3,1,2,4". -->
|
||||
|
|
|
@ -114,12 +114,12 @@
|
|||
<string name="more_keys_for_plus">±</string>
|
||||
<!-- The all letters need to be mirrored are found at
|
||||
http://www.unicode.org/Public/6.1.0/ucd/BidiMirroring.txt -->
|
||||
<string name="output_text_for_left_parenthesis">(</string>
|
||||
<string name="output_text_for_right_parenthesis">)</string>
|
||||
<integer name="keycode_for_left_parenthesis">0x0028</integer>
|
||||
<integer name="keycode_for_right_parenthesis">0x0029</integer>
|
||||
<string name="more_keys_for_left_parenthesis">[,{,<</string>
|
||||
<string name="more_keys_for_right_parenthesis">],},></string>
|
||||
<string name="output_text_for_less_than"><</string>
|
||||
<string name="output_text_for_greater_than">></string>
|
||||
<integer name="keycode_for_less_than">0x003c</integer>
|
||||
<integer name="keycode_for_greater_than">0x003e</integer>
|
||||
<!-- \u2264: LESS-THAN OR EQUAL TO
|
||||
\u2265: GREATER-THAN EQUAL TO
|
||||
\u00ab: LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
|
@ -137,10 +137,10 @@
|
|||
\u201f: DOUBLE HIGH-REVERSED-9 QUOTATION MARK -->
|
||||
<string name="more_keys_for_less_than">\u2264,\u00ab,\u2039</string>
|
||||
<string name="more_keys_for_greater_than">\u2265,\u00bb,\u203a</string>
|
||||
<string name="output_text_for_left_square_bracket">[</string>
|
||||
<string name="output_text_for_right_square_bracket">]</string>
|
||||
<string name="output_text_for_left_curly_bracket">{</string>
|
||||
<string name="output_text_for_right_curly_bracket">}</string>
|
||||
<integer name="keycode_for_left_square_bracket">0x005b</integer>
|
||||
<integer name="keycode_for_right_square_bracket">0x005d</integer>
|
||||
<integer name="keycode_for_left_curly_bracket">0x007b</integer>
|
||||
<integer name="keycode_for_right_curly_bracket">0x007d</integer>
|
||||
<!-- The 4-more keys will be displayed in order of "3,1,2,4". -->
|
||||
<string name="more_keys_for_single_quote">\u2019,\u201a,\u2018,\u201b</string>
|
||||
<!-- Note: Neither DroidSans nor Roboto have a glyph for DOUBLE HIGH-REVERSED-9 QUOTATION MARK. -->
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
>
|
||||
<Key
|
||||
latin:keyLabel="{"
|
||||
latin:keyOutputText="@string/output_text_for_left_curly_bracket" />
|
||||
latin:code="@integer/keycode_for_left_curly_bracket" />
|
||||
<Key
|
||||
latin:keyLabel="}"
|
||||
latin:keyOutputText="@string/output_text_for_right_curly_bracket" />
|
||||
latin:code="@integer/keycode_for_right_curly_bracket" />
|
||||
</merge>
|
||||
|
|
|
@ -23,10 +23,10 @@
|
|||
>
|
||||
<Key
|
||||
latin:keyLabel="<"
|
||||
latin:keyOutputText="@string/output_text_for_less_than"
|
||||
latin:code="@integer/keycode_for_less_than"
|
||||
latin:moreKeys="@string/more_keys_for_less_than" />
|
||||
<Key
|
||||
latin:keyLabel=">"
|
||||
latin:keyOutputText="@string/output_text_for_greater_than"
|
||||
latin:code="@integer/keycode_for_greater_than"
|
||||
latin:moreKeys="@string/more_keys_for_greater_than" />
|
||||
</merge>
|
||||
|
|
|
@ -23,10 +23,10 @@
|
|||
>
|
||||
<Key
|
||||
latin:keyLabel="("
|
||||
latin:keyOutputText="@string/output_text_for_left_parenthesis"
|
||||
latin:code="@integer/keycode_for_left_parenthesis"
|
||||
latin:moreKeys="@string/more_keys_for_left_parenthesis" />
|
||||
<Key
|
||||
latin:keyLabel=")"
|
||||
latin:keyOutputText="@string/output_text_for_right_parenthesis"
|
||||
latin:code="@integer/keycode_for_right_parenthesis"
|
||||
latin:moreKeys="@string/more_keys_for_right_parenthesis" />
|
||||
</merge>
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
>
|
||||
<Key
|
||||
latin:keyLabel="["
|
||||
latin:keyOutputText="@string/output_text_for_left_square_bracket" />
|
||||
latin:code="@integer/keycode_for_left_square_bracket" />
|
||||
<Key
|
||||
latin:keyLabel="]"
|
||||
latin:keyOutputText="@string/output_text_for_right_square_bracket" />
|
||||
latin:code="@integer/keycode_for_right_square_bracket" />
|
||||
</merge>
|
||||
|
|
|
@ -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) {
|
||||
if (Utils.codePointCount(outputText) == 1) {
|
||||
mCode = outputText.codePointAt(0);
|
||||
outputText = null;
|
||||
} else {
|
||||
mCode = Keyboard.CODE_OUTPUT_TEXT;
|
||||
}
|
||||
} else {
|
||||
mCode = adjustCaseOfCodeForKeyboardId(code, preserveCase, params.mId);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue