diff options
Diffstat (limited to 'java/src')
14 files changed, 76 insertions, 67 deletions
diff --git a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java index 11a9d1fe4..ae9bdf3fc 100644 --- a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java @@ -89,8 +89,6 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { } private synchronized void registerObserver(final Context context) { - // Perform a managed query. The Activity will handle closing and requerying the cursor - // when needed. if (mObserver != null) return; ContentResolver cres = context.getContentResolver(); cres.registerContentObserver(Contacts.CONTENT_URI, true, mObserver = diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java index 3b9be4395..230739d6f 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java @@ -62,7 +62,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { private static final boolean DBG_STRESS_TEST = false; private static final int TIMEOUT_FOR_READ_OPS_IN_MILLISECONDS = 100; - private static final int TIMEOUT_FOR_READ_OPS_FOR_TESTS_IN_MILLISECONDS = 1000; + private static final int TIMEOUT_FOR_READ_OPS_FOR_TESTS_IN_MILLISECONDS = 10000; /** * The maximum length of a word in this dictionary. @@ -750,7 +750,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { @UsedForTesting public boolean isInUnderlyingBinaryDictionaryForTests(final String word) { final AsyncResultHolder<Boolean> holder = new AsyncResultHolder<Boolean>(); - getExecutor(mDictName).executePrioritized(new Runnable() { + getExecutor(mDictName).execute(new Runnable() { @Override public void run() { if (mDictType == Dictionary.TYPE_USER_HISTORY) { diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 5d90e10a0..346ba8523 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -541,7 +541,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen shouldKeepUserHistoryDictionaries = true; // TODO: Eliminate this restriction shouldKeepPersonalizationDictionaries = - mSubtypeSwitcher.isSystemLocaleSameAsLocaleOfAllEnabledSubtypes(); + mSubtypeSwitcher.isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes(); } else { shouldKeepUserHistoryDictionaries = false; shouldKeepPersonalizationDictionaries = false; @@ -1183,14 +1183,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void showImportantNoticeContents() { final Context context = this; - final OnShowListener onShowListener = new OnShowListener() { - @Override - public void onShow(final DialogInterface dialog) { - ImportantNoticeUtils.updateLastImportantNoticeVersion(context); - onShowImportantNoticeDialog( - ImportantNoticeUtils.getCurrentImportantNoticeVersion(context)); - } - }; + final AlertDialog.Builder builder = + new AlertDialog.Builder(context, AlertDialog.THEME_HOLO_DARK); + builder.setMessage(ImportantNoticeUtils.getNextImportantNoticeContents(context)); + builder.setPositiveButton(android.R.string.ok, null /* listener */); final OnClickListener onClickListener = new OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int position) { @@ -1199,34 +1195,23 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } } }; - final OnDismissListener onDismissListener = new OnDismissListener() { + builder.setNegativeButton(R.string.go_to_settings, onClickListener); + final AlertDialog importantNoticeDialog = builder.create(); + importantNoticeDialog.setOnShowListener(new OnShowListener() { + @Override + public void onShow(final DialogInterface dialog) { + ImportantNoticeUtils.updateLastImportantNoticeVersion(context); + } + }); + importantNoticeDialog.setOnDismissListener(new OnDismissListener() { @Override - public void onDismiss(DialogInterface dialog) { + public void onDismiss(final DialogInterface dialog) { setNeutralSuggestionStrip(); } - }; - final String importantNoticeContents = ImportantNoticeUtils.getImportantNoticeContents( - context); - final AlertDialog.Builder builder = new AlertDialog.Builder( - context, AlertDialog.THEME_HOLO_DARK); - builder.setMessage(importantNoticeContents) - .setPositiveButton(android.R.string.ok, null /* listener */) - .setNegativeButton(R.string.go_to_settings, onClickListener); - final AlertDialog importantNoticeDialog = builder.create(); - importantNoticeDialog.setOnShowListener(onShowListener); - importantNoticeDialog.setOnDismissListener(onDismissListener); + }); showOptionDialog(importantNoticeDialog); } - private void onShowImportantNoticeDialog(final int importantNoticeVersion) { - if (importantNoticeVersion == - ImportantNoticeUtils.VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS) { - mSettings.writeUsePersonalizationDictionary(true /* enabled */); - loadSettings(); - initSuggest(); - } - } - public void displaySettingsDialog() { if (isShowingOptionDialog()) { return; diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java index ebad9bc0d..cc2db4c93 100644 --- a/java/src/com/android/inputmethod/latin/RichInputConnection.java +++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java @@ -810,11 +810,11 @@ public final class RichInputConnection { if (mExpectedSelStart == newSelStart && mExpectedSelEnd == newSelEnd) return true; // This update is not belated if mExpectedSelStart and mExpectedSelEnd match the old // values, and one of newSelStart or newSelEnd is updated to a different value. In this - // case, there is likely something other than the IME has moved the selection endpoint + // case, it is likely that something other than the IME has moved the selection endpoint // to the new value. if (mExpectedSelStart == oldSelStart && mExpectedSelEnd == oldSelEnd && (oldSelStart != newSelStart || oldSelEnd != newSelEnd)) return false; - // If nether of the above two cases holds, then the system may be having trouble keeping up + // If neither of the above two cases hold, then the system may be having trouble keeping up // with updates. If 1) the selection is a cursor, 2) newSelStart is between oldSelStart // and mExpectedSelStart, and 3) newSelEnd is between oldSelEnd and mExpectedSelEnd, then // assume a belated update. diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index 860575a1f..935dd9667 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -37,9 +37,11 @@ import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.latin.utils.LocaleUtils; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; +import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; public final class SubtypeSwitcher { private static boolean DBG = LatinImeLogger.sDBG; @@ -273,12 +275,26 @@ public final class SubtypeSwitcher { return mNeedsToDisplayLanguage.getValue(); } - public boolean isSystemLocaleSameAsLocaleOfAllEnabledSubtypes() { + public boolean isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes() { final Locale systemLocale = mResources.getConfiguration().locale; - final List<InputMethodSubtype> enabledSubtypesOfThisIme = - mRichImm.getMyEnabledInputMethodSubtypeList(true); - for (final InputMethodSubtype subtype : enabledSubtypesOfThisIme) { - if (!systemLocale.equals(SubtypeLocaleUtils.getSubtypeLocale(subtype))) { + final Set<InputMethodSubtype> enabledSubtypesOfEnabledImes = + new HashSet<InputMethodSubtype>(); + final InputMethodManager inputMethodManager = mRichImm.getInputMethodManager(); + final List<InputMethodInfo> enabledInputMethodInfoList = + inputMethodManager.getEnabledInputMethodList(); + for (final InputMethodInfo info : enabledInputMethodInfoList) { + final List<InputMethodSubtype> enabledSubtypes = + inputMethodManager.getEnabledInputMethodSubtypeList( + info, true /* allowsImplicitlySelectedSubtypes */); + if (enabledSubtypes.isEmpty()) { + // An IME with no subtypes is found. + return false; + } + enabledSubtypesOfEnabledImes.addAll(enabledSubtypes); + } + for (final InputMethodSubtype subtype : enabledSubtypesOfEnabledImes) { + if (!subtype.isAuxiliary() && !subtype.getLocale().isEmpty() + && !systemLocale.equals(SubtypeLocaleUtils.getSubtypeLocale(subtype))) { return false; } } diff --git a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java index 2a195f58b..3e3cbf063 100644 --- a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java @@ -97,8 +97,6 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary { mLocale = localeStr; } mAlsoUseMoreRestrictiveLocales = alsoUseMoreRestrictiveLocales; - // Perform a managed query. The Activity will handle closing and re-querying the cursor - // when needed. ContentResolver cres = context.getContentResolver(); mObserver = new ContentObserver(null) { diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index 3fc2cf8fd..52a6f5f08 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -77,9 +77,10 @@ public final class InputLogic { public int mSpaceState; // Never null public SuggestedWords mSuggestedWords = SuggestedWords.EMPTY; - public Suggest mSuggest; + // TODO: mSuggest should be touched by a single thread. + public volatile Suggest mSuggest; // The event interpreter should never be null. - public EventInterpreter mEventInterpreter; + public final EventInterpreter mEventInterpreter; public LastComposedWord mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD; public final WordComposer mWordComposer; diff --git a/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java index 23aa05d18..88fff38f2 100644 --- a/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java +++ b/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java @@ -53,6 +53,10 @@ public class Ver4DictDecoder extends AbstractDictDecoder { @Override public DictionaryHeader readHeader() throws IOException, UnsupportedFormatException { + final DictionaryHeader header = mBinaryDictionary.getHeader(); + if (header == null) { + throw new IOException("Cannot read the dictionary header."); + } return mBinaryDictionary.getHeader(); } diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java index 6a1503fed..b51c765f0 100644 --- a/java/src/com/android/inputmethod/latin/settings/Settings.java +++ b/java/src/com/android/inputmethod/latin/settings/Settings.java @@ -55,7 +55,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang public static final String PREF_MISC_SETTINGS = "misc_settings"; public static final String PREF_ADVANCED_SETTINGS = "pref_advanced_settings"; public static final String PREF_KEY_USE_CONTACTS_DICT = "pref_key_use_contacts_dict"; - public static final String PREF_USE_PERSONALIZED_DICTS = "pref_use_personalized_dicts"; + public static final String PREF_KEY_USE_PERSONALIZED_DICTS = "pref_key_use_personalized_dicts"; public static final String PREF_KEY_USE_DOUBLE_SPACE_PERIOD = "pref_key_use_double_space_period"; public static final String PREF_BLOCK_POTENTIALLY_OFFENSIVE = @@ -421,10 +421,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang return mPrefs.getStringSet(PREF_CORPUS_HANDLES_FOR_PERSONALIZATION, emptySet); } - public void writeUsePersonalizationDictionary(final boolean enabled) { - mPrefs.edit().putBoolean(PREF_USE_PERSONALIZED_DICTS, enabled).apply(); - } - public static void writeEmojiRecentKeys(final SharedPreferences prefs, String str) { prefs.edit().putString(PREF_EMOJI_RECENT_KEYS, str).apply(); } diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java index 0f3deeaa9..77968f79a 100644 --- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java @@ -128,7 +128,7 @@ public final class SettingsValues { Settings.PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST, false); mShowsLanguageSwitchKey = Settings.readShowsLanguageSwitchKey(prefs); mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true); - mUsePersonalizedDicts = prefs.getBoolean(Settings.PREF_USE_PERSONALIZED_DICTS, false); + mUsePersonalizedDicts = prefs.getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true); mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true); mBlockPotentiallyOffensive = Settings.readBlockPotentiallyOffensive(prefs, res); mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(autoCorrectionThresholdRawValue, res); diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java index 2966a8bba..4ef562d8f 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java @@ -237,7 +237,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick if (width <= 0) { return false; } - final String importantNoticeTitle = ImportantNoticeUtils.getImportantNoticeTitle( + final String importantNoticeTitle = ImportantNoticeUtils.getNextImportantNoticeTitle( getContext()); if (TextUtils.isEmpty(importantNoticeTitle)) { return false; diff --git a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java index 2f41ce9ce..97a924d7b 100644 --- a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java +++ b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java @@ -53,8 +53,7 @@ public class UserDictionaryList extends PreferenceFragment { } public static TreeSet<String> getUserDictionaryLocalesSet(Activity activity) { - @SuppressWarnings("deprecation") - final Cursor cursor = activity.managedQuery(UserDictionary.Words.CONTENT_URI, + final Cursor cursor = activity.getContentResolver().query(UserDictionary.Words.CONTENT_URI, new String[] { UserDictionary.Words.LOCALE }, null, null, null); final TreeSet<String> localeSet = new TreeSet<String>(); diff --git a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettings.java b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettings.java index 220efb5d3..cf2014a1a 100644 --- a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettings.java +++ b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettings.java @@ -141,7 +141,10 @@ public class UserDictionarySettings extends ListFragment { mLocale = locale; // WARNING: The following cursor is never closed! TODO: don't put that in a member, and - // make sure all cursors are correctly closed. + // make sure all cursors are correctly closed. Also, this comes from a call to + // Activity#managedQuery, which has been deprecated for a long time (and which FORBIDS + // closing the cursor, so take care when resolving this TODO). We should either use a + // regular query and close the cursor, or switch to a LoaderManager and a CursorLoader. mCursor = createCursor(locale); TextView emptyView = (TextView) getView().findViewById(android.R.id.empty); emptyView.setText(R.string.user_dict_settings_empty_text); diff --git a/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java b/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java index dd418b8cf..6b0bb86ac 100644 --- a/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java @@ -30,9 +30,9 @@ public final class ImportantNoticeUtils { // {@link SharedPreferences} name to save the last important notice version that has been // displayed to users. - private static final String PREFERENCE_NAME = "important_notice"; + private static final String PREFERENCE_NAME = "important_notice_pref"; private static final String KEY_IMPORTANT_NOTICE_VERSION = "important_notice_version"; - public static final int VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS = 2; + public static final int VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS = 1; // Copy of the hidden {@link Settings.Secure#USER_SETUP_COMPLETE} settings key. // The value is zero until each multiuser completes system setup wizard. @@ -64,9 +64,16 @@ public final class ImportantNoticeUtils { return context.getResources().getInteger(R.integer.config_important_notice_version); } + private static int getLastImportantNoticeVersion(final Context context) { + return getImportantNoticePreferences(context).getInt(KEY_IMPORTANT_NOTICE_VERSION, 0); + } + + private static int getNextImportantNoticeVersion(final Context context) { + return getLastImportantNoticeVersion(context) + 1; + } + private static boolean hasNewImportantNotice(final Context context) { - final SharedPreferences prefs = getImportantNoticePreferences(context); - final int lastVersion = prefs.getInt(KEY_IMPORTANT_NOTICE_VERSION, 0); + final int lastVersion = getLastImportantNoticeVersion(context); return getCurrentImportantNoticeVersion(context) > lastVersion; } @@ -79,14 +86,15 @@ public final class ImportantNoticeUtils { } public static void updateLastImportantNoticeVersion(final Context context) { - final SharedPreferences prefs = getImportantNoticePreferences(context); - prefs.edit() - .putInt(KEY_IMPORTANT_NOTICE_VERSION, getCurrentImportantNoticeVersion(context)) + getImportantNoticePreferences(context) + .edit() + .putInt(KEY_IMPORTANT_NOTICE_VERSION, getNextImportantNoticeVersion(context)) .apply(); } - public static String getImportantNoticeTitle(final Context context) { - switch (getCurrentImportantNoticeVersion(context)) { + // TODO: Make title resource to string array indexed by version. + public static String getNextImportantNoticeTitle(final Context context) { + switch (getNextImportantNoticeVersion(context)) { case VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS: return context.getString(R.string.important_notice_title); default: @@ -94,8 +102,9 @@ public final class ImportantNoticeUtils { } } - public static String getImportantNoticeContents(final Context context) { - switch (getCurrentImportantNoticeVersion(context)) { + // TODO: Make content resource to string array indexed by version. + public static String getNextImportantNoticeContents(final Context context) { + switch (getNextImportantNoticeVersion(context)) { case VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS: return context.getString(R.string.important_notice_contents); default: |