diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
4 files changed, 56 insertions, 100 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 1e7171406..1bc55a583 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -59,7 +59,6 @@ import com.android.inputmethod.compat.SuggestionSpanUtils; import com.android.inputmethod.compat.VibratorCompatWrapper; import com.android.inputmethod.deprecated.LanguageSwitcherProxy; import com.android.inputmethod.deprecated.VoiceProxy; -import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardActionListener; import com.android.inputmethod.keyboard.KeyboardId; @@ -873,13 +872,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // turn this flag on in succession and both onUpdateSelection() calls arrive after // the second one - the first call successfully avoids this test, but the second one // enters. For the moment we rely on candidatesCleared to further reduce the impact. - if (SPACE_STATE_WEAK == mSpaceState) { - // Test for no WEAK_SPACE action because there is a race condition that may end up - // in coming here on a normal key press. We set this to NONE because after - // a cursor move, we don't want the suggestion strip to swap the space with the - // newly inserted punctuation. - mSpaceState = SPACE_STATE_NONE; - } + + // We set this to NONE because after a cursor move, we don't want the space + // state-related special processing to kick in. + mSpaceState = SPACE_STATE_NONE; + if (((mWordComposer.isComposingWord()) || mVoiceProxy.isVoiceInputHighlighted()) && (selectionChanged || candidatesCleared)) { @@ -1296,10 +1293,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar case Keyboard.CODE_SETTINGS: onSettingsKeyPressed(); break; - case Keyboard.CODE_CAPSLOCK: - // Caps lock code is handled in KeyboardSwitcher.onCodeInput() below. - hapticAndAudioFeedback(primaryCode); - break; case Keyboard.CODE_SHORTCUT: mSubtypeSwitcher.switchToShortcutIME(); break; @@ -1901,16 +1894,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // So, LatinImeLogger logs "" as a user's input. LatinImeLogger.logOnManualSuggestion( "", suggestion.toString(), index, suggestions.mWords); + final CharSequence outputText = mSettingsValues.mSuggestPuncOutputTextList + .getWord(index); + final int primaryCode = outputText.charAt(0); // Find out whether the previous character is a space. If it is, as a special case // 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. - final int rawPrimaryCode = suggestion.charAt(0); - // Maybe apply the "bidi mirrored" conversions for parentheses - final Keyboard keyboard = mKeyboardSwitcher.getKeyboard(); - final boolean isRtl = keyboard != null && keyboard.mIsRtlKeyboard; - final int primaryCode = Key.getRtlParenthesisCode(rawPrimaryCode, isRtl); - insertPunctuationFromSuggestionStrip(ic, primaryCode); // TODO: the following endBatchEdit seems useless, check if (ic != null) { @@ -2229,9 +2219,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // be needed, but it's there just in case something went wrong. final CharSequence textBeforeCursor = ic.getTextBeforeCursor(2, 0); if (!". ".equals(textBeforeCursor)) { - // We should not have come here if we aren't just after a ". ". - throw new RuntimeException("Tried to revert double-space combo but we didn't find " + // Theoretically we should not be coming here if there isn't ". " before the + // cursor, but the application may be changing the text while we are typing, so + // anything goes. We should not crash. + Log.d(TAG, "Tried to revert double-space combo but we didn't find " + "\". \" just before the cursor."); + return false; } ic.beginBatchEdit(); ic.deleteSurroundingText(2, 0); @@ -2294,18 +2287,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar loadSettings(); } - private void hapticAndAudioFeedback(int primaryCode) { + public void hapticAndAudioFeedback(int primaryCode) { vibrate(); playKeyClick(primaryCode); } @Override public void onPressKey(int primaryCode) { - final KeyboardSwitcher switcher = mKeyboardSwitcher; - if (switcher.isVibrateAndSoundFeedbackRequired()) { - hapticAndAudioFeedback(primaryCode); - } - switcher.onPressKey(primaryCode); + mKeyboardSwitcher.onPressKey(primaryCode); } @Override @@ -2313,7 +2302,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mKeyboardSwitcher.onReleaseKey(primaryCode, withSliding); } - // receive ringer mode change and network state change. private BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index e6ef3962e..8e2f605c4 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -25,6 +25,7 @@ import android.view.inputmethod.EditorInfo; import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.compat.VibratorCompatWrapper; +import com.android.inputmethod.keyboard.internal.KeySpecParser; import java.util.Arrays; import java.util.Locale; @@ -36,8 +37,9 @@ public class SettingsValues { public final int mDelayUpdateOldSuggestions; public final String mMagicSpaceStrippers; public final String mMagicSpaceSwappers; - public final String mSuggestPuncs; + private final String mSuggestPuncs; public final SuggestedWords mSuggestPuncList; + public final SuggestedWords mSuggestPuncOutputTextList; private final String mSymbolsExcludedFromWordSeparators; public final String mWordSeparators; public final CharSequence mHintToSaveText; @@ -98,9 +100,11 @@ public class SettingsValues { } } } - mSuggestPuncs = res.getString(R.string.suggested_punctuations); - // TODO: it would be nice not to recreate this each time we change the configuration - mSuggestPuncList = createSuggestPuncList(mSuggestPuncs); + final String[] suggestPuncsSpec = KeySpecParser.parseCsvString( + res.getString(R.string.suggested_punctuations), res, R.string.english_ime_name); + mSuggestPuncs = createSuggestPuncs(suggestPuncsSpec); + mSuggestPuncList = createSuggestPuncList(suggestPuncsSpec); + mSuggestPuncOutputTextList = createSuggestPuncOutputTextList(suggestPuncsSpec); mSymbolsExcludedFromWordSeparators = res.getString(R.string.symbols_excluded_from_word_separators); mWordSeparators = createWordSeparators(mMagicSpaceStrippers, mMagicSpaceSwappers, @@ -150,11 +154,36 @@ public class SettingsValues { } // Helper functions to create member values. - private static SuggestedWords createSuggestPuncList(final String puncs) { - SuggestedWords.Builder builder = new SuggestedWords.Builder(); + private static String createSuggestPuncs(final String[] puncs) { + final StringBuilder sb = new StringBuilder(); if (puncs != null) { - for (int i = 0; i < puncs.length(); i++) { - builder.addWord(puncs.subSequence(i, i + 1)); + for (final String puncSpec : puncs) { + sb.append(KeySpecParser.getLabel(puncSpec)); + } + } + return sb.toString(); + } + + private static SuggestedWords createSuggestPuncList(final String[] puncs) { + final SuggestedWords.Builder builder = new SuggestedWords.Builder(); + if (puncs != null) { + for (final String puncSpec : puncs) { + builder.addWord(KeySpecParser.getLabel(puncSpec)); + } + } + return builder.setIsPunctuationSuggestions().build(); + } + + private static SuggestedWords createSuggestPuncOutputTextList(final String[] puncs) { + final SuggestedWords.Builder builder = new SuggestedWords.Builder(); + if (puncs != null) { + for (final String puncSpec : puncs) { + final String outputText = KeySpecParser.getOutputText(puncSpec); + if (outputText != null) { + builder.addWord(outputText); + } else { + builder.addWord(KeySpecParser.getLabel(puncSpec)); + } } } return builder.setIsPunctuationSuggestions().build(); diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index a70808741..3975dddeb 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -62,12 +62,6 @@ public class Utils { private static boolean DBG = LatinImeLogger.sDBG; private static boolean DBG_EDIT_DISTANCE = false; - // Constants for resource name parsing. - public static final char ESCAPE_CHAR = '\\'; - public static final char PREFIX_AT = '@'; - public static final char SUFFIX_SLASH = '/'; - private static final String PREFIX_STRING = PREFIX_AT + "string"; - private Utils() { // Intentional empty constructor for utility class. } @@ -800,61 +794,8 @@ public class Utils { } } - public static int getResourceId(Resources res, String name, int packageNameResId) { - String packageName = res.getResourcePackageName(packageNameResId); - int resId = res.getIdentifier(name, null, packageName); - if (resId == 0) { - throw new RuntimeException("Unknown resource: " + name); - } - return resId; - } - - public static String resolveStringResource(String text, Resources res, int packageNameResId) { - final int size = text.length(); - if (size < PREFIX_STRING.length()) { - return text; - } - - StringBuilder sb = null; - for (int pos = 0; pos < size; pos++) { - final char c = text.charAt(pos); - if (c == PREFIX_AT && text.startsWith(PREFIX_STRING, pos)) { - if (sb == null) { - sb = new StringBuilder(text.substring(0, pos)); - } - final int end = Utils.searchResourceNameEnd(text, pos + PREFIX_STRING.length()); - final String resName = text.substring(pos + 1, end); - final int resId = getResourceId(res, resName, packageNameResId); - sb.append(res.getString(resId)); - pos = end - 1; - } else if (c == ESCAPE_CHAR) { - pos++; - if (sb != null) { - sb.append(c); - if (pos < size) { - sb.append(text.charAt(pos)); - } - } - } else if (sb != null) { - sb.append(c); - } - } - return (sb == null) ? text : sb.toString(); - } - - private static int searchResourceNameEnd(String text, int start) { - final int size = text.length(); - if (start >= size || text.charAt(start) != SUFFIX_SLASH) { - throw new RuntimeException("Resource name not specified"); - } - for (int pos = start + 1; pos < size; pos++) { - final char c = text.charAt(pos); - // String resource name should be consisted of [a-z_0-9]. - if ((c >= 'a' && c <= 'z') || c == '_' || (c >= '0' && c <= '9')) { - continue; - } - return pos; - } - return size; + public static int codePointCount(String text) { + if (TextUtils.isEmpty(text)) return 0; + return text.codePointCount(0, text.length()); } } diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index 230c2916b..bd244b913 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -16,8 +16,6 @@ package com.android.inputmethod.latin; -import android.text.TextUtils; - import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.KeyDetector; import com.android.inputmethod.keyboard.Keyboard; @@ -33,7 +31,7 @@ public class WordComposer { public static final int NOT_A_CODE = KeyDetector.NOT_A_CODE; public static final int NOT_A_COORDINATE = -1; - final int N = BinaryDictionary.MAX_WORD_LENGTH; + final static int N = BinaryDictionary.MAX_WORD_LENGTH; private ArrayList<int[]> mCodes; private int[] mXCoordinates; |