diff options
Diffstat (limited to 'java/src')
13 files changed, 67 insertions, 62 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index 45ed34ed2..91e81f347 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -42,6 +42,7 @@ import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.util.Arrays; +import java.util.Locale; /** * Class for describing the position and characteristics of a single key in the keyboard. @@ -240,7 +241,8 @@ public class Key { mLabelFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelFlags) | row.getDefaultKeyLabelFlags(); - final boolean preserveCase = (mLabelFlags & LABEL_FLAGS_PRESERVE_CASE) != 0; + final boolean needsToUpperCase = needsToUpperCase(mLabelFlags, params.mId.mElementId); + final Locale locale = params.mId.mLocale; int actionFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyActionFlags); String[] moreKeys = style.getStringArray(keyAttr, R.styleable.Keyboard_Key_moreKeys); @@ -276,8 +278,8 @@ public class Key { actionFlags |= ACTION_FLAGS_ENABLE_LONG_PRESS; mMoreKeys = new MoreKeySpec[moreKeys.length]; for (int i = 0; i < moreKeys.length; i++) { - mMoreKeys[i] = new MoreKeySpec(adjustCaseOfStringForKeyboardId( - moreKeys[i], preserveCase, params.mId), params.mCodesSet); + mMoreKeys[i] = new MoreKeySpec( + moreKeys[i], needsToUpperCase, locale, params.mCodesSet); } } else { mMoreKeys = null; @@ -287,17 +289,17 @@ public class Key { if ((mLabelFlags & LABEL_FLAGS_FROM_CUSTOM_ACTION_LABEL) != 0) { mLabel = params.mId.mCustomActionLabel; } else { - mLabel = adjustCaseOfStringForKeyboardId(style.getString(keyAttr, - R.styleable.Keyboard_Key_keyLabel), preserveCase, params.mId); + mLabel = KeySpecParser.toUpperCaseOfStringForLocale(style.getString(keyAttr, + R.styleable.Keyboard_Key_keyLabel), needsToUpperCase, locale); } if ((mLabelFlags & LABEL_FLAGS_DISABLE_HINT_LABEL) != 0) { mHintLabel = null; } else { - mHintLabel = adjustCaseOfStringForKeyboardId(style.getString(keyAttr, - R.styleable.Keyboard_Key_keyHintLabel), preserveCase, params.mId); + mHintLabel = KeySpecParser.toUpperCaseOfStringForLocale(style.getString(keyAttr, + R.styleable.Keyboard_Key_keyHintLabel), needsToUpperCase, locale); } - String outputText = adjustCaseOfStringForKeyboardId(style.getString(keyAttr, - R.styleable.Keyboard_Key_keyOutputText), preserveCase, params.mId); + String outputText = KeySpecParser.toUpperCaseOfStringForLocale(style.getString(keyAttr, + R.styleable.Keyboard_Key_keyOutputText), needsToUpperCase, locale); final int code = KeySpecParser.parseCode(style.getString(keyAttr, R.styleable.Keyboard_Key_code), params.mCodesSet, CODE_UNSPECIFIED); // Choose the first letter of the label as primary code if not specified. @@ -326,12 +328,13 @@ public class Key { mCode = CODE_OUTPUT_TEXT; } } else { - mCode = adjustCaseOfCodeForKeyboardId(code, preserveCase, params.mId); + mCode = KeySpecParser.toUpperCaseOfCodeForLocale(code, needsToUpperCase, locale); } mOutputText = outputText; - mAltCode = adjustCaseOfCodeForKeyboardId(KeySpecParser.parseCode(style.getString(keyAttr, + mAltCode = KeySpecParser.toUpperCaseOfCodeForLocale( + KeySpecParser.parseCode(style.getString(keyAttr, R.styleable.Keyboard_Key_altCode), params.mCodesSet, CODE_UNSPECIFIED), - preserveCase, params.mId); + needsToUpperCase, locale); mHashCode = computeHashCode(this); keyAttr.recycle(); @@ -341,26 +344,16 @@ public class Key { } } - private static int adjustCaseOfCodeForKeyboardId(int code, boolean preserveCase, - KeyboardId id) { - if (!Keyboard.isLetterCode(code) || preserveCase) return code; - final String text = new String(new int[] { code } , 0, 1); - final String casedText = adjustCaseOfStringForKeyboardId(text, preserveCase, id); - return StringUtils.codePointCount(casedText) == 1 - ? casedText.codePointAt(0) : CODE_UNSPECIFIED; - } - - private static String adjustCaseOfStringForKeyboardId(String text, boolean preserveCase, - KeyboardId id) { - if (text == null || preserveCase) return text; - switch (id.mElementId) { + private static boolean needsToUpperCase(int labelFlags, int keyboardElementId) { + if ((labelFlags & LABEL_FLAGS_PRESERVE_CASE) != 0) return false; + switch (keyboardElementId) { case KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED: case KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED: case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED: case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED: - return text.toUpperCase(id.mLocale); + return true; default: - return text; + return false; } } diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 6ad854d1b..59f53fc21 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -452,12 +452,6 @@ public class PointerTracker { return newKey; } - private Key onUpKey(int x, int y, long eventTime) { - mUpTime = eventTime; - mCurrentKey = null; - return onMoveKeyInternal(x, y); - } - public void processMotionEvent(int action, int x, int y, long eventTime, KeyEventHandler handler) { switch (action) { diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java index a44ddf182..b95bddc81 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java @@ -16,6 +16,8 @@ package com.android.inputmethod.keyboard.internal; +import static com.android.inputmethod.keyboard.Keyboard.CODE_UNSPECIFIED; + import android.text.TextUtils; import com.android.inputmethod.keyboard.Keyboard; @@ -24,6 +26,7 @@ import com.android.inputmethod.latin.StringUtils; import java.util.ArrayList; import java.util.Arrays; +import java.util.Locale; /** * The string parser of more keys specification. @@ -63,10 +66,14 @@ public class KeySpecParser { public final String mOutputText; public final int mIconId; - public MoreKeySpec(final String moreKeySpec, final KeyboardCodesSet codesSet) { - mCode = getCode(moreKeySpec, codesSet); - mLabel = getLabel(moreKeySpec); - mOutputText = getOutputText(moreKeySpec); + public MoreKeySpec(final String moreKeySpec, boolean needsToUpperCase, Locale locale, + final KeyboardCodesSet codesSet) { + mCode = toUpperCaseOfCodeForLocale(getCode(moreKeySpec, codesSet), + needsToUpperCase, locale); + mLabel = toUpperCaseOfStringForLocale(getLabel(moreKeySpec), + needsToUpperCase, locale); + mOutputText = toUpperCaseOfStringForLocale(getOutputText(moreKeySpec), + needsToUpperCase, locale); mIconId = getIconId(moreKeySpec); } } @@ -256,9 +263,8 @@ public class KeySpecParser { } if (out == null) { return array; - } else { - return out.toArray(new String[out.size()]); } + return out.toArray(new String[out.size()]); } public static String[] insertAdditionalMoreKeys(String[] moreKeySpecs, @@ -427,12 +433,11 @@ public class KeySpecParser { final String remain = (size - start > 0) ? text.substring(start) : null; if (list == null) { return remain != null ? new String[] { remain } : null; - } else { - if (remain != null) { - list.add(remain); - } - return list.toArray(new String[list.size()]); } + if (remain != null) { + list.add(remain); + } + return list.toArray(new String[list.size()]); } public static int getIntValue(String[] moreKeys, String key, int defaultValue) { @@ -476,4 +481,20 @@ public class KeySpecParser { } return value; } + + public static int toUpperCaseOfCodeForLocale(int code, boolean needsToUpperCase, + Locale locale) { + if (!Keyboard.isLetterCode(code) || !needsToUpperCase) return code; + final String text = new String(new int[] { code } , 0, 1); + final String casedText = KeySpecParser.toUpperCaseOfStringForLocale( + text, needsToUpperCase, locale); + return StringUtils.codePointCount(casedText) == 1 + ? casedText.codePointAt(0) : CODE_UNSPECIFIED; + } + + public static String toUpperCaseOfStringForLocale(String text, boolean needsToUpperCase, + Locale locale) { + if (text == null || !needsToUpperCase) return text; + return text.toUpperCase(locale); + } } diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java index c10a394c1..67cb74f4d 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java @@ -34,9 +34,6 @@ public class KeyboardCodesSet { public int getCode(final String name) { Integer id = sNameToIdMap.get(name); - if (id == null) { - id = sNameToIdMap.get(name.toLowerCase()); - } if (id == null) throw new RuntimeException("Unknown key code: " + name); return mCodes[id]; } diff --git a/java/src/com/android/inputmethod/latin/ContactsDictionary.java b/java/src/com/android/inputmethod/latin/ContactsDictionary.java index 2f3395245..c9b8d6eb1 100644 --- a/java/src/com/android/inputmethod/latin/ContactsDictionary.java +++ b/java/src/com/android/inputmethod/latin/ContactsDictionary.java @@ -34,6 +34,7 @@ import com.android.inputmethod.keyboard.Keyboard; * * @deprecated Use {@link ContactsBinaryDictionary}. */ +@Deprecated public class ContactsDictionary extends ExpandableDictionary { private static final String[] PROJECTION = { diff --git a/java/src/com/android/inputmethod/latin/Dictionary.java b/java/src/com/android/inputmethod/latin/Dictionary.java index 1ec678f7f..231e9ab81 100644 --- a/java/src/com/android/inputmethod/latin/Dictionary.java +++ b/java/src/com/android/inputmethod/latin/Dictionary.java @@ -33,7 +33,7 @@ public abstract class Dictionary { /** * Interface to be implemented by classes requesting words to be fetched from the dictionary. - * @see #getWords(WordComposer, WordCallback, ProximityInfo) + * @see #getWords(WordComposer, CharSequence, WordCallback, ProximityInfo) */ public interface WordCallback { /** diff --git a/java/src/com/android/inputmethod/latin/DictionaryFactory.java b/java/src/com/android/inputmethod/latin/DictionaryFactory.java index 4cd1b3883..a22d73af7 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFactory.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFactory.java @@ -89,7 +89,6 @@ public class DictionaryFactory { /** * Initializes a dictionary from a raw resource file * @param context application context for reading resources - * @param resId the resource containing the raw binary dictionary * @param locale the locale to use for the resource * @return an initialized instance of BinaryDictionary */ diff --git a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java index dd9c57e0c..6c457afd2 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java @@ -309,7 +309,8 @@ public class ExpandableDictionary extends Dictionary { * @param word the word to insert, as an array of code points * @param depth the depth of the node in the tree * @param finalFreq the frequency for this word - * @return whether there is still space for more words. {@see Dictionary.WordCallback#addWord}. + * @return whether there is still space for more words. + * @see Dictionary.WordCallback#addWord(char[], int, int, int, int, int) */ private boolean addWordAndShortcutsFromNode(final Node node, final char[] word, final int depth, final int finalFreq, final WordCallback callback) { diff --git a/java/src/com/android/inputmethod/latin/ResearchLogger.java b/java/src/com/android/inputmethod/latin/ResearchLogger.java index aa979a66f..66d6d58b1 100644 --- a/java/src/com/android/inputmethod/latin/ResearchLogger.java +++ b/java/src/com/android/inputmethod/latin/ResearchLogger.java @@ -54,7 +54,7 @@ import java.util.Map; * This class logs operations on the IME keyboard, including what the user has typed. * Data is stored locally in a file in app-specific storage. * - * This functionality is off by default. See {@link ProductionFlag.IS_EXPERIMENTAL}. + * This functionality is off by default. See {@link ProductionFlag#IS_EXPERIMENTAL}. */ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChangeListener { private static final String TAG = ResearchLogger.class.getSimpleName(); diff --git a/java/src/com/android/inputmethod/latin/UserDictionary.java b/java/src/com/android/inputmethod/latin/UserDictionary.java index 81e2fdce4..c1efadd44 100644 --- a/java/src/com/android/inputmethod/latin/UserDictionary.java +++ b/java/src/com/android/inputmethod/latin/UserDictionary.java @@ -35,6 +35,7 @@ import java.util.Arrays; * * @deprecated Use {@link UserBinaryDictionary}. */ +@Deprecated public class UserDictionary extends ExpandableDictionary { // TODO: use Words.SHORTCUT when it's public in the SDK diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java index 563f8a99b..89c59f809 100644 --- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java +++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java @@ -882,9 +882,9 @@ public class BinaryDictInputOutput { final int indexOfShortcutByteSize = index; index += GROUP_SHORTCUT_LIST_SIZE_SIZE; groupAddress += GROUP_SHORTCUT_LIST_SIZE_SIZE; - final Iterator shortcutIterator = group.mShortcutTargets.iterator(); + final Iterator<WeightedString> shortcutIterator = group.mShortcutTargets.iterator(); while (shortcutIterator.hasNext()) { - final WeightedString target = (WeightedString)shortcutIterator.next(); + final WeightedString target = shortcutIterator.next(); ++groupAddress; int shortcutFlags = makeShortcutFlags(shortcutIterator.hasNext(), target.mFrequency); @@ -902,9 +902,9 @@ public class BinaryDictInputOutput { } // Write bigrams if (null != group.mBigrams) { - final Iterator bigramIterator = group.mBigrams.iterator(); + final Iterator<WeightedString> bigramIterator = group.mBigrams.iterator(); while (bigramIterator.hasNext()) { - final WeightedString bigram = (WeightedString)bigramIterator.next(); + final WeightedString bigram = bigramIterator.next(); final CharGroup target = FusionDictionary.findWordInTree(dict.mRoot, bigram.mWord); final int addressOfBigram = target.mCachedAddress; diff --git a/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java b/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java index c467ef7d4..8b53c9427 100644 --- a/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java +++ b/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java @@ -296,7 +296,6 @@ public class FusionDictionary implements Iterable<Word> { * @param word the word to add. * @param frequency the frequency of the word, in the range [0..255]. * @param shortcutTargets a list of shortcut targets for this word, or null. - * @param bigrams a list of bigrams, or null. */ public void add(final String word, final int frequency, final ArrayList<WeightedString> shortcutTargets) { @@ -435,6 +434,8 @@ public class FusionDictionary implements Iterable<Word> { } } + private static int ARRAYS_ARE_EQUAL = 0; + /** * Custom comparison of two int arrays taken to contain character codes. * @@ -450,7 +451,6 @@ public class FusionDictionary implements Iterable<Word> { * @param dstOffset the offset in the right-hand side string. * @return the index at which the strings differ, or ARRAYS_ARE_EQUAL = 0 if they don't. */ - private static int ARRAYS_ARE_EQUAL = 0; private static int compareArrays(final int[] src, final int[] dst, int dstOffset) { // We do NOT test the first char, because we come from a method that already // tested it. @@ -469,6 +469,7 @@ public class FusionDictionary implements Iterable<Word> { * This comparator imposes orderings that are inconsistent with equals. */ static private class CharGroupComparator implements java.util.Comparator<CharGroup> { + @Override public int compare(CharGroup c1, CharGroup c2) { if (c1.mChars[0] == c2.mChars[0]) return 0; return c1.mChars[0] < c2.mChars[0] ? -1 : 1; @@ -487,6 +488,8 @@ public class FusionDictionary implements Iterable<Word> { return result >= 0 ? result : -result - 1; } + private static int CHARACTER_NOT_FOUND = -1; + /** * Find the index of a char in a node, if it exists. * @@ -494,7 +497,6 @@ public class FusionDictionary implements Iterable<Word> { * @param character the character to search for. * @return the position of the character if it's there, or CHARACTER_NOT_FOUND = -1 else. */ - private static int CHARACTER_NOT_FOUND = -1; private static int findIndexOfChar(final Node node, int character) { final int insertionIndex = findInsertionIndex(node, character); if (node.mData.size() <= insertionIndex) return CHARACTER_NOT_FOUND; diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java index aa3250185..0e3bf8011 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java @@ -499,10 +499,6 @@ public class AndroidSpellCheckerService extends SpellCheckerService } mUnigramSuggestionsInfoCache.put(query, new SuggestionsParams(suggestions, flags)); } - - public void remove(String key) { - mUnigramSuggestionsInfoCache.remove(key); - } } AndroidSpellCheckerSession(final AndroidSpellCheckerService service) { |