diff options
Diffstat (limited to 'java/src')
9 files changed, 99 insertions, 126 deletions
diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java index 322127a12..15f79f3de 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java @@ -136,12 +136,19 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp return; } // Announce the language name only when the language is changed. - if (lastKeyboard == null || !lastKeyboard.mId.mSubtype.equals(keyboard.mId.mSubtype)) { + if (lastKeyboard == null || !keyboard.mId.mSubtype.equals(lastKeyboard.mId.mSubtype)) { announceKeyboardLanguage(keyboard); + return; } // Announce the mode only when the mode is changed. - if (lastKeyboardMode != keyboard.mId.mMode) { + if (keyboard.mId.mMode != lastKeyboardMode) { announceKeyboardMode(keyboard); + return; + } + // Announce the keyboard type only when the type is changed. + if (keyboard.mId.mElementId != lastKeyboard.mId.mElementId) { + announceKeyboardType(keyboard, lastKeyboard); + return; } } @@ -174,9 +181,8 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp * @param keyboard The new keyboard. */ private void announceKeyboardMode(final Keyboard keyboard) { - final int mode = keyboard.mId.mMode; final Context context = mView.getContext(); - final int modeTextResId = KEYBOARD_MODE_RES_IDS.get(mode); + final int modeTextResId = KEYBOARD_MODE_RES_IDS.get(keyboard.mId.mMode); if (modeTextResId == 0) { return; } @@ -186,6 +192,50 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp } /** + * Announces which type of keyboard is being displayed. + * + * @param keyboard The new keyboard. + * @param lastKeyboard The last keyboard. + */ + private void announceKeyboardType(final Keyboard keyboard, final Keyboard lastKeyboard) { + final int lastElementId = lastKeyboard.mId.mElementId; + final int resId; + switch (keyboard.mId.mElementId) { + case KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED: + case KeyboardId.ELEMENT_ALPHABET: + if (lastElementId == KeyboardId.ELEMENT_ALPHABET + || lastElementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) { + return; + } + resId = R.string.spoken_description_mode_alpha; + break; + case KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED: + resId = R.string.spoken_description_shiftmode_on; + break; + case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED: + case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED: + resId = R.string.spoken_description_shiftmode_locked; + break; + case KeyboardId.ELEMENT_SYMBOLS: + resId = R.string.spoken_description_mode_symbol; + break; + case KeyboardId.ELEMENT_SYMBOLS_SHIFTED: + resId = R.string.spoken_description_mode_symbol_shift; + break; + case KeyboardId.ELEMENT_PHONE: + resId = R.string.spoken_description_mode_phone; + break; + case KeyboardId.ELEMENT_PHONE_SYMBOLS: + resId = R.string.spoken_description_mode_phone_shift; + break; + default: + return; + } + final String text = mView.getContext().getString(resId); + sendWindowStateChanged(text); + } + + /** * Announces that the keyboard has been hidden. */ private void announceKeyboardHidden() { @@ -301,7 +351,7 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp } /** - * Simulates a key press by injecting touch event into the keyboard view. + * Simulates a key press by injecting touch an event into the keyboard view. * This avoids the complexity of trackers and listeners within the keyboard. * * @param key The key to press. @@ -318,7 +368,7 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp } /** - * Simulates a key release by injecting touch event into the keyboard view. + * Simulates a key release by injecting touch an event into the keyboard view. * This avoids the complexity of trackers and listeners within the keyboard. * * @param key The key to release. @@ -383,72 +433,4 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp } return true; } - - /** - * Notifies the user of changes in the keyboard shift state. - */ - public void notifyShiftState() { - if (mView == null || mKeyboard == null) { - return; - } - - final KeyboardId keyboardId = mKeyboard.mId; - final int elementId = keyboardId.mElementId; - final Context context = mView.getContext(); - final CharSequence text; - - switch (elementId) { - case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED: - case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED: - text = context.getText(R.string.spoken_description_shiftmode_locked); - break; - case KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED: - case KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED: - case KeyboardId.ELEMENT_SYMBOLS_SHIFTED: - text = context.getText(R.string.spoken_description_shiftmode_on); - break; - default: - text = context.getText(R.string.spoken_description_shiftmode_off); - } - AccessibilityUtils.getInstance().announceForAccessibility(mView, text); - } - - /** - * Notifies the user of changes in the keyboard symbols state. - */ - public void notifySymbolsState() { - if (mView == null || mKeyboard == null) { - return; - } - - final KeyboardId keyboardId = mKeyboard.mId; - final int elementId = keyboardId.mElementId; - final Context context = mView.getContext(); - final int resId; - - switch (elementId) { - case KeyboardId.ELEMENT_ALPHABET: - case KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED: - case KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED: - case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED: - case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED: - resId = R.string.spoken_description_mode_alpha; - break; - case KeyboardId.ELEMENT_SYMBOLS: - case KeyboardId.ELEMENT_SYMBOLS_SHIFTED: - resId = R.string.spoken_description_mode_symbol; - break; - case KeyboardId.ELEMENT_PHONE: - resId = R.string.spoken_description_mode_phone; - break; - case KeyboardId.ELEMENT_PHONE_SYMBOLS: - resId = R.string.spoken_description_mode_phone_shift; - break; - default: - return; - } - - final String text = context.getString(resId); - AccessibilityUtils.getInstance().announceForAccessibility(mView, text); - } } diff --git a/java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java b/java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java index a0d76415c..6e32e74ab 100644 --- a/java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java +++ b/java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java @@ -29,8 +29,8 @@ public final class UserDictionaryCompatUtils { Context.class, String.class, Integer.TYPE, String.class, Locale.class); @SuppressWarnings("deprecation") - public static void addWord(final Context context, final String word, final int freq, - final String shortcut, final Locale locale) { + public static void addWord(final Context context, final String word, + final int freq, final String shortcut, final Locale locale) { if (hasNewerAddWord()) { CompatUtils.invoke(Words.class, null, METHOD_addWord, context, word, freq, shortcut, locale); diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 0235fde38..0e667bc1c 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -123,7 +123,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { builder.setOptions( mSubtypeSwitcher.isShortcutImeEnabled(), settingsValues.mShowsVoiceInputKey, - mLatinIME.shouldSwitchToOtherInputMethods()); + mLatinIME.shouldShowLanguageSwitchKey()); mKeyboardLayoutSet = builder.build(); mCurrentSettingsValues = settingsValues; try { diff --git a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java index 5238395a4..b6fcbd1d6 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java @@ -49,6 +49,7 @@ public class DictionaryFacilitatorForSuggest { private static final int CAPITALIZED_FORM_MAX_PROBABILITY_FOR_INSERT = 140; private Dictionaries mDictionaries = new Dictionaries(); + private boolean mIsUserDictEnabled = false; private volatile CountDownLatch mLatchForWaitingLoadingMainDictionary = new CountDownLatch(0); // To synchronize assigning mDictionaries to ensure closing dictionaries. private Object mLock = new Object(); @@ -71,24 +72,21 @@ public class DictionaryFacilitatorForSuggest { CollectionUtils.newConcurrentHashMap(); public final ConcurrentHashMap<String, ExpandableBinaryDictionary> mSubDictMap = CollectionUtils.newConcurrentHashMap(); - // TODO: Remove sub dictionary members and use mSubDictMap. - public final UserBinaryDictionary mUserDictionary; public Dictionaries() { mLocale = null; - mUserDictionary = null; } public Dictionaries(final Locale locale, final Dictionary mainDict, - final ExpandableBinaryDictionary contactsDict, final UserBinaryDictionary userDict, + final ExpandableBinaryDictionary contactsDict, + final ExpandableBinaryDictionary userDict, final ExpandableBinaryDictionary userHistoryDict, final ExpandableBinaryDictionary personalizationDict) { mLocale = locale; // Main dictionary can be asynchronously loaded. setMainDict(mainDict); setSubDict(Dictionary.TYPE_CONTACTS, contactsDict); - mUserDictionary = userDict; - setSubDict(Dictionary.TYPE_USER, mUserDictionary); + setSubDict(Dictionary.TYPE_USER, userDict); setSubDict(Dictionary.TYPE_USER_HISTORY, userHistoryDict); setSubDict(Dictionary.TYPE_PERSONALIZATION, personalizationDict); } @@ -176,11 +174,12 @@ public class DictionaryFacilitatorForSuggest { } // Open or move user dictionary. - final UserBinaryDictionary newUserDictionary; + final ExpandableBinaryDictionary newUserDictionary; if (!closeUserDictionary && mDictionaries.hasDict(Dictionary.TYPE_USER)) { - newUserDictionary = mDictionaries.mUserDictionary; + newUserDictionary = mDictionaries.getSubDict(Dictionary.TYPE_USER); } else { newUserDictionary = new UserBinaryDictionary(context, newLocale); + mIsUserDictEnabled = UserBinaryDictionary.isEnabled(context); } // Open or move user history dictionary. @@ -364,19 +363,15 @@ public class DictionaryFacilitatorForSuggest { } public boolean isUserDictionaryEnabled() { - final UserBinaryDictionary userDictionary = mDictionaries.mUserDictionary; - if (userDictionary == null) { - return false; - } - return userDictionary.mEnabled; + return mIsUserDictEnabled; } - public void addWordToUserDictionary(String word) { - final UserBinaryDictionary userDictionary = mDictionaries.mUserDictionary; - if (userDictionary == null) { + public void addWordToUserDictionary(final Context context, final String word) { + final Locale locale = getLocale(); + if (locale == null) { return; } - userDictionary.addWordToUserDictionary(word); + UserBinaryDictionary.addWordToUserDictionary(context, locale, word); } public void addToUserHistory(final String suggestion, final boolean wasAutoCapitalized, diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java index 08f3c63a3..550db4a6c 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java @@ -511,12 +511,12 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { */ private final void asyncReloadDictionary() { if (mIsReloading.compareAndSet(false, true)) { - mNeedsToReload = false; asyncExecuteTaskWithWriteLock(new Runnable() { @Override public void run() { try { - if (!mDictFile.exists() || haveContentsChanged()) { + // TODO: Quit checking contents in ExpandableBinaryDictionary. + if (!mDictFile.exists() || (mNeedsToReload && haveContentsChanged())) { // If the dictionary file does not exist or contents have been updated, // generate a new one. createNewDictionaryLocked(); @@ -524,6 +524,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { // Otherwise, load the existing dictionary. loadBinaryDictionaryLocked(); } + mNeedsToReload = false; if (mBinaryDictionary != null && !(isValidDictionaryLocked() // TODO: remove the check below && matchesExpectedBinaryDictFormatVersionForThisType( diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index f1b1b8db2..e5dcb12ae 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1179,7 +1179,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } else { wordToEdit = word; } - mInputLogic.mSuggest.mDictionaryFacilitator.addWordToUserDictionary(wordToEdit); + mInputLogic.mSuggest.mDictionaryFacilitator.addWordToUserDictionary( + this /* context */, wordToEdit); } // Callback for the {@link SuggestionStripView}, to call when the important notice strip is @@ -1596,18 +1597,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen public void onReleaseKey(final int primaryCode, final boolean withSliding) { mKeyboardSwitcher.onReleaseKey(primaryCode, withSliding, getCurrentAutoCapsState(), getCurrentRecapitalizeState()); - - // If accessibility is on, ensure the user receives keyboard state updates. - if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) { - switch (primaryCode) { - case Constants.CODE_SHIFT: - AccessibleKeyboardViewProxy.getInstance().notifyShiftState(); - break; - case Constants.CODE_SWITCH_ALPHA_SYMBOL: - AccessibleKeyboardViewProxy.getInstance().notifySymbolsState(); - break; - } - } } private HardwareEventDecoder getHardwareKeyEventDecoder(final int deviceId) { diff --git a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java index 2b0be545e..64cc562c8 100644 --- a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java +++ b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java @@ -410,12 +410,21 @@ public final class RichInputMethodManager { public boolean shouldOfferSwitchingToNextInputMethod(final IBinder binder, boolean defaultValue) { - // Use the default value instead on Jelly Bean MR2 and previous where - // {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} isn't yet available - // and on KitKat where the API is still just a stub to return true always. - if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { + // Use the default value instead on Jelly Bean MR2 and previous, where + // {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} isn't yet available. + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2) { return defaultValue; } + // Use the default value instead on KitKat as well, where + // {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} is still just a stub to + // return true always. + if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { + // Make sure this is actually KitKat. + // TODO: Consider to remove this check once the *next* version becomes available. + if (Build.VERSION.CODENAME.equals("REL")) { + return defaultValue; + } + } return mImmWrapper.shouldOfferSwitchingToNextInputMethod(binder); } } diff --git a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java index 9d9ce0138..b21f30087 100644 --- a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java @@ -29,7 +29,6 @@ import android.text.TextUtils; import android.util.Log; import com.android.inputmethod.compat.UserDictionaryCompatUtils; -import com.android.inputmethod.latin.utils.LocaleUtils; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; import java.io.File; @@ -74,7 +73,6 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary { private ContentObserver mObserver; final private String mLocale; final private boolean mAlsoUseMoreRestrictiveLocales; - final public boolean mEnabled; public UserBinaryDictionary(final Context context, final Locale locale) { this(context, locale, false /* alsoUseMoreRestrictiveLocales */, null /* dictFile */); @@ -120,7 +118,6 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary { } }; cres.registerContentObserver(Words.CONTENT_URI, true, mObserver); - mEnabled = readIsEnabled(); reloadDictionaryIfRequired(); } @@ -198,8 +195,8 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary { } } - private boolean readIsEnabled() { - final ContentResolver cr = mContext.getContentResolver(); + public static boolean isEnabled(final Context context) { + final ContentResolver cr = context.getContentResolver(); final ContentProviderClient client = cr.acquireContentProviderClient(Words.CONTENT_URI); if (client != null) { client.release(); @@ -212,18 +209,15 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary { /** * Adds a word to the user dictionary and makes it persistent. * + * @param context the context + * @param locale the locale * @param word the word to add. If the word is capitalized, then the dictionary will * recognize it as a capitalized word when searched. */ - public synchronized void addWordToUserDictionary(final String word) { + public static void addWordToUserDictionary(final Context context, final Locale locale, + final String word) { // Update the user dictionary provider - final Locale locale; - if (USER_DICTIONARY_ALL_LANGUAGES == mLocale) { - locale = null; - } else { - locale = LocaleUtils.constructLocaleFromString(mLocale); - } - UserDictionaryCompatUtils.addWord(mContext, word, + UserDictionaryCompatUtils.addWord(context, word, HISTORICAL_DEFAULT_USER_DICTIONARY_FREQUENCY, null, locale); } diff --git a/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java b/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java index a23b3ac79..bf38abc95 100644 --- a/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java +++ b/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java @@ -16,6 +16,8 @@ package com.android.inputmethod.latin.utils; +import com.android.inputmethod.annotations.UsedForTesting; + import java.util.Queue; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ConcurrentLinkedQueue; @@ -74,6 +76,7 @@ public class PrioritizedSerialExecutor { * Enqueues the given task into the prioritized task queue. * @param r the enqueued task */ + @UsedForTesting public void executePrioritized(final Runnable r) { synchronized(mLock) { if (!mIsShutdown) { |