diff options
Diffstat (limited to 'java/src')
3 files changed, 43 insertions, 20 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index c31bcf23e..6eaa606db 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -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/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 20ec090d2..af791e5cb 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -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); @@ -1326,10 +1326,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // Not a tld: do nothing. return text; } + // We have a TLD (or something that looks like this): make sure we don't add + // a space even if currently in phantom mode. + mSpaceState = SPACE_STATE_NONE; final CharSequence lastOne = ic.getTextBeforeCursor(1, 0); if (lastOne != null && lastOne.length() == 1 && lastOne.charAt(0) == Keyboard.CODE_PERIOD) { - mSpaceState = SPACE_STATE_NONE; return text.subSequence(1, text.length()); } else { return text; @@ -1909,7 +1911,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(); |