diff options
-rw-r--r-- | java/res/values-ar/donottranslate-more-keys.xml | 16 | ||||
-rw-r--r-- | java/res/values-iw/donottranslate-more-keys.xml | 16 | ||||
-rw-r--r-- | java/res/values/donottranslate-more-keys.xml | 16 | ||||
-rw-r--r-- | java/res/xml/keys_curly_brackets.xml | 4 | ||||
-rw-r--r-- | java/res/xml/keys_less_greater.xml | 4 | ||||
-rw-r--r-- | java/res/xml/keys_parentheses.xml | 4 | ||||
-rw-r--r-- | java/res/xml/keys_square_brackets.xml | 4 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/Key.java | 27 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java | 32 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java | 107 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 7 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java | 12 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/latin/InputLogicTests.java | 14 |
13 files changed, 156 insertions, 107 deletions
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 @@ <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". --> 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 @@ <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". --> 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 @@ <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. --> 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 @@ > <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> 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 @@ > <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> 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 @@ > <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> 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 @@ > <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> diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index 686392da8..6eaa606db 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -228,9 +228,9 @@ public class Key { mDisabledIconId = style.getInt(keyAttr, R.styleable.Keyboard_Key_keyIconDisabled, KeyboardIconsSet.ICON_UNDEFINED); - mLabelFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelFlags, 0); + mLabelFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelFlags); final boolean preserveCase = (mLabelFlags & LABEL_FLAGS_PRESERVE_CASE) != 0; - int actionFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyActionFlags, 0); + int actionFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyActionFlags); final String[] additionalMoreKeys = style.getStringArray( keyAttr, R.styleable.Keyboard_Key_additionalMoreKeys); final String[] moreKeys = KeySpecParser.insertAddtionalMoreKeys(style.getStringArray( @@ -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/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java index 6ec56ca9f..12a9c51f2 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java @@ -40,17 +40,13 @@ public class KeyStyles { public String[] getStringArray(TypedArray a, int index); public String getString(TypedArray a, int index); public int getInt(TypedArray a, int index, int defaultValue); - public int getFlag(TypedArray a, int index, int defaultValue); + public int getFlag(TypedArray a, int index); } - private static class EmptyKeyStyle implements KeyStyle { - EmptyKeyStyle() { - // Nothing to do. - } - + static class EmptyKeyStyle implements KeyStyle { @Override public String[] getStringArray(TypedArray a, int index) { - return parseStringArray(a, index); + return KeyStyles.parseStringArray(a, index); } @Override @@ -64,50 +60,47 @@ public class KeyStyles { } @Override - public int getFlag(TypedArray a, int index, int defaultValue) { - return a.getInt(index, defaultValue); - } - - protected static String[] parseStringArray(TypedArray a, int index) { - if (!a.hasValue(index)) - return null; - return KeySpecParser.parseCsvString( - a.getString(index), a.getResources(), R.string.english_ime_name); + public int getFlag(TypedArray a, int index) { + return a.getInt(index, 0); } } - private static class DeclaredKeyStyle extends EmptyKeyStyle { - private final HashMap<Integer, Object> mAttributes = new HashMap<Integer, Object>(); + static class DeclaredKeyStyle implements KeyStyle { + private final HashMap<Integer, Object> mStyleAttributes = new HashMap<Integer, Object>(); @Override public String[] getStringArray(TypedArray a, int index) { - return a.hasValue(index) - ? super.getStringArray(a, index) : (String[])mAttributes.get(index); + if (a.hasValue(index)) { + return parseStringArray(a, index); + } + return (String[])mStyleAttributes.get(index); } @Override public String getString(TypedArray a, int index) { - return a.hasValue(index) - ? super.getString(a, index) : (String)mAttributes.get(index); + if (a.hasValue(index)) { + return a.getString(index); + } + return (String)mStyleAttributes.get(index); } @Override public int getInt(TypedArray a, int index, int defaultValue) { - final Integer value = (Integer)mAttributes.get(index); - return super.getInt(a, index, (value != null) ? value : defaultValue); + if (a.hasValue(index)) { + return a.getInt(index, defaultValue); + } + final Integer styleValue = (Integer)mStyleAttributes.get(index); + return styleValue != null ? styleValue : defaultValue; } @Override - public int getFlag(TypedArray a, int index, int defaultValue) { - final Integer value = (Integer)mAttributes.get(index); - return super.getFlag(a, index, defaultValue) | (value != null ? value : 0); - } - - DeclaredKeyStyle() { - super(); + public int getFlag(TypedArray a, int index) { + final int value = a.getInt(index, 0); + final Integer styleValue = (Integer)mStyleAttributes.get(index); + return (styleValue != null ? styleValue : 0) | value; } - void parseKeyStyleAttributes(TypedArray keyAttr) { + void readKeyAttributes(TypedArray keyAttr) { // TODO: Currently not all Key attributes can be declared as style. readInt(keyAttr, R.styleable.Keyboard_Key_code); readInt(keyAttr, R.styleable.Keyboard_Key_altCode); @@ -126,52 +119,68 @@ public class KeyStyles { } private void readString(TypedArray a, int index) { - if (a.hasValue(index)) - mAttributes.put(index, a.getString(index)); + if (a.hasValue(index)) { + mStyleAttributes.put(index, a.getString(index)); + } } private void readInt(TypedArray a, int index) { - if (a.hasValue(index)) - mAttributes.put(index, a.getInt(index, 0)); + if (a.hasValue(index)) { + mStyleAttributes.put(index, a.getInt(index, 0)); + } } private void readFlag(TypedArray a, int index) { - final Integer value = (Integer)mAttributes.get(index); - if (a.hasValue(index)) - mAttributes.put(index, a.getInt(index, 0) | (value != null ? value : 0)); + final Integer value = (Integer)mStyleAttributes.get(index); + if (a.hasValue(index)) { + mStyleAttributes.put(index, a.getInt(index, 0) | (value != null ? value : 0)); + } } private void readStringArray(TypedArray a, int index) { final String[] value = parseStringArray(a, index); - if (value != null) - mAttributes.put(index, value); + if (value != null) { + mStyleAttributes.put(index, value); + } + } + + void addParentStyleAttributes(DeclaredKeyStyle parentStyle) { + mStyleAttributes.putAll(parentStyle.mStyleAttributes); } + } - void addParent(DeclaredKeyStyle parentStyle) { - mAttributes.putAll(parentStyle.mAttributes); + static String[] parseStringArray(TypedArray a, int index) { + if (a.hasValue(index)) { + return KeySpecParser.parseCsvString( + a.getString(index), a.getResources(), R.string.english_ime_name); } + return null; } public void parseKeyStyleAttributes(TypedArray keyStyleAttr, TypedArray keyAttrs, XmlPullParser parser) throws XmlPullParserException { final String styleName = keyStyleAttr.getString(R.styleable.Keyboard_KeyStyle_styleName); - if (DEBUG) Log.d(TAG, String.format("<%s styleName=%s />", - Keyboard.Builder.TAG_KEY_STYLE, styleName)); - if (mStyles.containsKey(styleName)) + if (DEBUG) { + Log.d(TAG, String.format("<%s styleName=%s />", + Keyboard.Builder.TAG_KEY_STYLE, styleName)); + } + if (mStyles.containsKey(styleName)) { throw new XmlParseUtils.ParseException( "duplicate key style declared: " + styleName, parser); + } final DeclaredKeyStyle style = new DeclaredKeyStyle(); if (keyStyleAttr.hasValue(R.styleable.Keyboard_KeyStyle_parentStyle)) { final String parentStyle = keyStyleAttr.getString( R.styleable.Keyboard_KeyStyle_parentStyle); final DeclaredKeyStyle parent = mStyles.get(parentStyle); - if (parent == null) + if (parent == null) { throw new XmlParseUtils.ParseException( "Unknown parentStyle " + parentStyle, parser); - style.addParent(parent); + } + style.addParentStyleAttributes(parent); } - style.parseKeyStyleAttributes(keyAttrs); + style.readKeyAttributes(keyAttrs); mStyles.put(styleName, style); } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index e4339318b..9a66e00f2 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -186,7 +186,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private View mKeyPreviewBackingView; private View mSuggestionsContainer; private SuggestionsView mSuggestionsView; - private Suggest mSuggest; + /* package for tests */ Suggest mSuggest; private CompletionInfo[] mApplicationSpecifiedCompletions; private InputMethodManagerCompatWrapper mImm; @@ -1224,7 +1224,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar return mOptionsDialog != null && mOptionsDialog.isShowing(); } - private void insertPunctuationFromSuggestionStrip(final InputConnection ic, final int code) { + private void insertPunctuationFromSuggestionStrip(final int code) { onCodeInput(code, new int[] { code }, KeyboardActionListener.SUGGESTION_STRIP_COORDINATE, KeyboardActionListener.SUGGESTION_STRIP_COORDINATE); @@ -1909,7 +1909,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // for punctuation entered through the suggestion strip, it should be swapped // if it was a magic or a weak space. This is meant to help in case the user // pressed space on purpose of displaying the suggestion strip punctuation. - insertPunctuationFromSuggestionStrip(ic, primaryCode); + insertPunctuationFromSuggestionStrip(primaryCode); // TODO: the following endBatchEdit seems useless, check if (ic != null) { ic.endBatchEdit(); @@ -2211,6 +2211,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } } ic.deleteSurroundingText(restartLength, 0); + mComposingStateManager.onStartComposingText(); ic.setComposingText(mWordComposer.getTypedWord(), 1); mHandler.cancelUpdateBigramPredictions(); mHandler.postUpdateSuggestions(); 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); } diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java index 693352c85..fef704a0e 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java @@ -111,6 +111,20 @@ public class InputLogicTests extends ServiceTestCase<LatinIME> { mLatinIME.onStartInputView(ei, false); mLatinIME.onCreateInputMethodInterface().startInput(ic, ei); mInputConnection = ic; + // Wait for the main dictionary to be loaded (we need it for auto-correction tests) + int remainingAttempts = 10; + while (remainingAttempts > 0 && !mLatinIME.mSuggest.hasMainDictionary()) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + // Don't do much + } finally { + --remainingAttempts; + } + } + if (!mLatinIME.mSuggest.hasMainDictionary()) { + throw new RuntimeException("Can't initialize the main dictionary"); + } } // type(int) and type(String): helper methods to send a code point resp. a string to LatinIME. |