am c217dc92: Convert one letter Key.outputText to Key.code

* commit 'c217dc9237e5d1e1e721b9007139d771dcb41145':
  Convert one letter Key.outputText to Key.code
This commit is contained in:
Tadashi G. Takaoka 2012-02-07 05:46:05 -08:00 committed by Android Git Automerger
commit 29742cfc83
10 changed files with 78 additions and 53 deletions

View file

@ -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">[|],{|},&lt;|&gt;,\ufd3e|\ufd3f</string>
<string name="more_keys_for_right_parenthesis">]|[,}|{,&gt;|&lt;,\ufd3f|\ufd3e</string>
<string name="output_text_for_less_than">&gt;</string>
<string name="output_text_for_greater_than">&lt;</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". -->

View file

@ -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">[|],{|},&lt;|&gt;</string>
<string name="more_keys_for_right_parenthesis">]|[,}|{,&gt;|&lt;</string>
<string name="output_text_for_less_than">&gt;</string>
<string name="output_text_for_greater_than">&lt;</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". -->

View file

@ -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">[,{,&lt;</string>
<string name="more_keys_for_right_parenthesis">],},&gt;</string>
<string name="output_text_for_less_than">&lt;</string>
<string name="output_text_for_greater_than">&gt;</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. -->

View file

@ -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>

View file

@ -23,10 +23,10 @@
>
<Key
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" />
<Key
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" />
</merge>

View file

@ -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>

View file

@ -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>

View file

@ -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);
}

View file

@ -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);

View file

@ -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);
}