diff options
Diffstat (limited to 'java/src/com/android')
4 files changed, 102 insertions, 71 deletions
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(); |