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: I86879c9942d264edc71e5893325a2f582763d12f
main
Tadashi G. Takaoka 2012-02-07 20:42:07 +09:00
parent 69f672a4b3
commit c217dc9237
10 changed files with 78 additions and 53 deletions

View File

@ -104,14 +104,14 @@
<string name="more_keys_for_star">★,\u066d</string> <string name="more_keys_for_star">★,\u066d</string>
<!-- The all letters need to be mirrored are found at <!-- The all letters need to be mirrored are found at
http://www.unicode.org/Public/6.1.0/ucd/BidiMirroring.txt --> http://www.unicode.org/Public/6.1.0/ucd/BidiMirroring.txt -->
<string name="output_text_for_left_parenthesis">)</string> <integer name="keycode_for_left_parenthesis">0x0029</integer>
<string name="output_text_for_right_parenthesis">(</string> <integer name="keycode_for_right_parenthesis">0x0028</integer>
<!-- \ufd3e: ORNATE LEFT PARENTHESIS <!-- \ufd3e: ORNATE LEFT PARENTHESIS
\ufd3f: ORNATE RIGHT PARENTHESIS --> \ufd3f: ORNATE RIGHT PARENTHESIS -->
<string name="more_keys_for_left_parenthesis">[|],{|},&lt;|&gt;,\ufd3e|\ufd3f</string> <string name="more_keys_for_left_parenthesis">[|],{|},&lt;|&gt;,\ufd3e|\ufd3f</string>
<string name="more_keys_for_right_parenthesis">]|[,}|{,&gt;|&lt;,\ufd3f|\ufd3e</string> <string name="more_keys_for_right_parenthesis">]|[,}|{,&gt;|&lt;,\ufd3f|\ufd3e</string>
<string name="output_text_for_less_than">&gt;</string> <integer name="keycode_for_less_than">0x003e</integer>
<string name="output_text_for_greater_than">&lt;</string> <integer name="keycode_for_greater_than">0x003c</integer>
<!-- \u2264: LESS-THAN OR EQUAL TO <!-- \u2264: LESS-THAN OR EQUAL TO
\u2265: GREATER-THAN EQUAL TO \u2265: GREATER-THAN EQUAL TO
\u00ab: LEFT-POINTING DOUBLE ANGLE QUOTATION MARK \u00ab: LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
@ -129,10 +129,10 @@
\u201f: DOUBLE HIGH-REVERSED-9 QUOTATION MARK --> \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_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="more_keys_for_greater_than">\u2265|\u2264,\u00bb|\u00ab,\u203a|\u2039</string>
<string name="output_text_for_left_square_bracket">]</string> <integer name="keycode_for_left_square_bracket">0x005d</integer>
<string name="output_text_for_right_square_bracket">[</string> <integer name="keycode_for_right_square_bracket">0x005b</integer>
<string name="output_text_for_left_curly_bracket">}</string> <integer name="keycode_for_left_curly_bracket">0x007d</integer>
<string name="output_text_for_right_curly_bracket">{</string> <integer name="keycode_for_right_curly_bracket">0x007b</integer>
<!-- Note: Neither DroidSans nor Roboto have a glyph for DOUBLE HIGH-REVERSED-9 QUOTATION MARK. --> <!-- 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> --> <!-- <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". --> <!-- The 4-more keys will be displayed in order of "3,1,2,4". -->

View File

@ -22,12 +22,12 @@
<string name="more_keys_for_plus">±,﬩</string> <string name="more_keys_for_plus">±,﬩</string>
<!-- The all letters need to be mirrored are found at <!-- The all letters need to be mirrored are found at
http://www.unicode.org/Public/6.1.0/ucd/BidiMirroring.txt --> http://www.unicode.org/Public/6.1.0/ucd/BidiMirroring.txt -->
<string name="output_text_for_left_parenthesis">)</string> <integer name="keycode_for_left_parenthesis">0x0029</integer>
<string name="output_text_for_right_parenthesis">(</string> <integer name="keycode_for_right_parenthesis">0x0028</integer>
<string name="more_keys_for_left_parenthesis">[|],{|},&lt;|&gt;</string> <string name="more_keys_for_left_parenthesis">[|],{|},&lt;|&gt;</string>
<string name="more_keys_for_right_parenthesis">]|[,}|{,&gt;|&lt;</string> <string name="more_keys_for_right_parenthesis">]|[,}|{,&gt;|&lt;</string>
<string name="output_text_for_less_than">&gt;</string> <integer name="keycode_for_less_than">0x003e</integer>
<string name="output_text_for_greater_than">&lt;</string> <integer name="keycode_for_greater_than">0x003c</integer>
<!-- \u2264: LESS-THAN OR EQUAL TO <!-- \u2264: LESS-THAN OR EQUAL TO
\u2265: GREATER-THAN EQUAL TO \u2265: GREATER-THAN EQUAL TO
\u00ab: LEFT-POINTING DOUBLE ANGLE QUOTATION MARK \u00ab: LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
@ -45,10 +45,10 @@
\u201f: DOUBLE HIGH-REVERSED-9 QUOTATION MARK --> \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_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="more_keys_for_greater_than">\u2265|\u2264,\u00bb|\u00ab,\u203a|\u2039</string>
<string name="output_text_for_left_square_bracket">]</string> <integer name="keycode_for_left_square_bracket">0x005d</integer>
<string name="output_text_for_right_square_bracket">[</string> <integer name="keycode_for_right_square_bracket">0x005b</integer>
<string name="output_text_for_left_curly_bracket">}</string> <integer name="keycode_for_left_curly_bracket">0x007d</integer>
<string name="output_text_for_right_curly_bracket">{</string> <integer name="keycode_for_right_curly_bracket">0x007b</integer>
<!-- Note: Neither DroidSans nor Roboto have a glyph for DOUBLE HIGH-REVERSED-9 QUOTATION MARK. --> <!-- 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> --> <!-- <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". --> <!-- The 4-more keys will be displayed in order of "3,1,2,4". -->

View File

@ -114,12 +114,12 @@
<string name="more_keys_for_plus">±</string> <string name="more_keys_for_plus">±</string>
<!-- The all letters need to be mirrored are found at <!-- The all letters need to be mirrored are found at
http://www.unicode.org/Public/6.1.0/ucd/BidiMirroring.txt --> http://www.unicode.org/Public/6.1.0/ucd/BidiMirroring.txt -->
<string name="output_text_for_left_parenthesis">(</string> <integer name="keycode_for_left_parenthesis">0x0028</integer>
<string name="output_text_for_right_parenthesis">)</string> <integer name="keycode_for_right_parenthesis">0x0029</integer>
<string name="more_keys_for_left_parenthesis">[,{,&lt;</string> <string name="more_keys_for_left_parenthesis">[,{,&lt;</string>
<string name="more_keys_for_right_parenthesis">],},&gt;</string> <string name="more_keys_for_right_parenthesis">],},&gt;</string>
<string name="output_text_for_less_than">&lt;</string> <integer name="keycode_for_less_than">0x003c</integer>
<string name="output_text_for_greater_than">&gt;</string> <integer name="keycode_for_greater_than">0x003e</integer>
<!-- \u2264: LESS-THAN OR EQUAL TO <!-- \u2264: LESS-THAN OR EQUAL TO
\u2265: GREATER-THAN EQUAL TO \u2265: GREATER-THAN EQUAL TO
\u00ab: LEFT-POINTING DOUBLE ANGLE QUOTATION MARK \u00ab: LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
@ -137,10 +137,10 @@
\u201f: DOUBLE HIGH-REVERSED-9 QUOTATION MARK --> \u201f: DOUBLE HIGH-REVERSED-9 QUOTATION MARK -->
<string name="more_keys_for_less_than">\u2264,\u00ab,\u2039</string> <string name="more_keys_for_less_than">\u2264,\u00ab,\u2039</string>
<string name="more_keys_for_greater_than">\u2265,\u00bb,\u203a</string> <string name="more_keys_for_greater_than">\u2265,\u00bb,\u203a</string>
<string name="output_text_for_left_square_bracket">[</string> <integer name="keycode_for_left_square_bracket">0x005b</integer>
<string name="output_text_for_right_square_bracket">]</string> <integer name="keycode_for_right_square_bracket">0x005d</integer>
<string name="output_text_for_left_curly_bracket">{</string> <integer name="keycode_for_left_curly_bracket">0x007b</integer>
<string name="output_text_for_right_curly_bracket">}</string> <integer name="keycode_for_right_curly_bracket">0x007d</integer>
<!-- The 4-more keys will be displayed in order of "3,1,2,4". --> <!-- 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> <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. --> <!-- Note: Neither DroidSans nor Roboto have a glyph for DOUBLE HIGH-REVERSED-9 QUOTATION MARK. -->

View File

@ -23,8 +23,8 @@
> >
<Key <Key
latin:keyLabel="{" latin:keyLabel="{"
latin:keyOutputText="@string/output_text_for_left_curly_bracket" /> latin:code="@integer/keycode_for_left_curly_bracket" />
<Key <Key
latin:keyLabel="}" latin:keyLabel="}"
latin:keyOutputText="@string/output_text_for_right_curly_bracket" /> latin:code="@integer/keycode_for_right_curly_bracket" />
</merge> </merge>

View File

@ -23,10 +23,10 @@
> >
<Key <Key
latin:keyLabel="&lt;" latin:keyLabel="&lt;"
latin:keyOutputText="@string/output_text_for_less_than" latin:code="@integer/keycode_for_less_than"
latin:moreKeys="@string/more_keys_for_less_than" /> latin:moreKeys="@string/more_keys_for_less_than" />
<Key <Key
latin:keyLabel="&gt;" latin:keyLabel="&gt;"
latin:keyOutputText="@string/output_text_for_greater_than" latin:code="@integer/keycode_for_greater_than"
latin:moreKeys="@string/more_keys_for_greater_than" /> latin:moreKeys="@string/more_keys_for_greater_than" />
</merge> </merge>

View File

@ -23,10 +23,10 @@
> >
<Key <Key
latin:keyLabel="(" 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" /> latin:moreKeys="@string/more_keys_for_left_parenthesis" />
<Key <Key
latin:keyLabel=")" 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" /> latin:moreKeys="@string/more_keys_for_right_parenthesis" />
</merge> </merge>

View File

@ -23,8 +23,8 @@
> >
<Key <Key
latin:keyLabel="[" latin:keyLabel="["
latin:keyOutputText="@string/output_text_for_left_square_bracket" /> latin:code="@integer/keycode_for_left_square_bracket" />
<Key <Key
latin:keyLabel="]" latin:keyLabel="]"
latin:keyOutputText="@string/output_text_for_right_square_bracket" /> latin:code="@integer/keycode_for_right_square_bracket" />
</merge> </merge>

View File

@ -247,14 +247,14 @@ public class Key {
mMaxMoreKeysColumn = style.getInt(keyAttr, mMaxMoreKeysColumn = style.getInt(keyAttr,
R.styleable.Keyboard_Key_maxMoreKeysColumn, params.mMaxMiniKeyboardColumn); R.styleable.Keyboard_Key_maxMoreKeysColumn, params.mMaxMiniKeyboardColumn);
mLabel = adjustCaseOfStringForKeyboardId(style.getString( mLabel = adjustCaseOfStringForKeyboardId(style.getString(keyAttr,
keyAttr, R.styleable.Keyboard_Key_keyLabel), preserveCase, params.mId); R.styleable.Keyboard_Key_keyLabel), preserveCase, params.mId);
mHintLabel = adjustCaseOfStringForKeyboardId(style.getString( mHintLabel = adjustCaseOfStringForKeyboardId(style.getString(keyAttr,
keyAttr, R.styleable.Keyboard_Key_keyHintLabel), preserveCase, params.mId); R.styleable.Keyboard_Key_keyHintLabel), preserveCase, params.mId);
String outputText = adjustCaseOfStringForKeyboardId(style.getString( String outputText = adjustCaseOfStringForKeyboardId(style.getString(keyAttr,
keyAttr, R.styleable.Keyboard_Key_keyOutputText), preserveCase, params.mId); R.styleable.Keyboard_Key_keyOutputText), preserveCase, params.mId);
final int code = style.getInt( final int code = style.getInt(keyAttr,
keyAttr, R.styleable.Keyboard_Key_code, Keyboard.CODE_UNSPECIFIED); R.styleable.Keyboard_Key_code, Keyboard.CODE_UNSPECIFIED);
// Choose the first letter of the label as primary code if not specified. // Choose the first letter of the label as primary code if not specified.
if (code == Keyboard.CODE_UNSPECIFIED && TextUtils.isEmpty(outputText) if (code == Keyboard.CODE_UNSPECIFIED && TextUtils.isEmpty(outputText)
&& !TextUtils.isEmpty(mLabel)) { && !TextUtils.isEmpty(mLabel)) {
@ -274,7 +274,12 @@ public class Key {
mCode = Keyboard.CODE_OUTPUT_TEXT; mCode = Keyboard.CODE_OUTPUT_TEXT;
} }
} else if (code == Keyboard.CODE_UNSPECIFIED && outputText != null) { } 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; mCode = Keyboard.CODE_OUTPUT_TEXT;
}
} else { } else {
mCode = adjustCaseOfCodeForKeyboardId(code, preserveCase, params.mId); mCode = adjustCaseOfCodeForKeyboardId(code, preserveCase, params.mId);
} }

View File

@ -133,18 +133,28 @@ public class KeySpecParser {
return label; 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) { public static String getOutputText(String moreKeySpec) {
if (hasCode(moreKeySpec)) { if (hasCode(moreKeySpec)) {
return null; return null;
} }
final int end = indexOfLabelEnd(moreKeySpec, 0); final String outputText = getOutputTextInternal(moreKeySpec);
if (end > 0) { if (outputText != null) {
if (indexOfLabelEnd(moreKeySpec, end + 1) >= 0) { if (Utils.codePointCount(outputText) == 1) {
throw new KeySpecParserError("Multiple " + LABEL_END + ": " // If output text is one code point, it should be treated as a code.
+ moreKeySpec); // See {@link #getCode(Resources, String)}.
return null;
} }
final String outputText = parseEscape(
moreKeySpec.substring(end + /* LABEL_END */1));
if (!TextUtils.isEmpty(outputText)) { if (!TextUtils.isEmpty(outputText)) {
return outputText; return outputText;
} }
@ -170,7 +180,13 @@ public class KeySpecParser {
final int code = res.getInteger(resId); final int code = res.getInteger(resId);
return code; 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; return Keyboard.CODE_OUTPUT_TEXT;
} }
final String label = getLabel(moreKeySpec); final String label = getLabel(moreKeySpec);

View File

@ -109,6 +109,10 @@ public class KeySpecParserTests extends AndroidTestCase {
"@", null, ICON_UNDEFINED, '@'); "@", null, ICON_UNDEFINED, '@');
assertParser("Single escaped at", "\\@", assertParser("Single escaped at", "\\@",
"@", null, ICON_UNDEFINED, '@'); "@", 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", assertParser("Single letter with outputText", "a|abc",
"a", "abc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); "a", "abc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
assertParser("Single letter with surrogate outputText", "a|" + SURROGATE1, 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); "a", "a@c", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
assertParser("Single letter with escaped at outputText", "a|\\@bc", assertParser("Single letter with escaped at outputText", "a|\\@bc",
"a", "@bc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); "a", "@bc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
assertParser("Single escaped escape with outputText", "\\\\|\\\\", assertParser("Single escaped escape with single outputText", "\\\\|\\\\",
"\\", "\\", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); "\\", null, ICON_UNDEFINED, '\\');
assertParser("Single escaped bar with outputText", "\\||\\|", assertParser("Single escaped bar with single outputText", "\\||\\|",
"|", "|", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); "|", null, ICON_UNDEFINED, '|');
assertParser("Single letter with code", "a|" + CODE_SETTINGS, assertParser("Single letter with code", "a|" + CODE_SETTINGS,
"a", null, ICON_UNDEFINED, mCodeSettings); "a", null, ICON_UNDEFINED, mCodeSettings);
} }