diff options
Diffstat (limited to 'java/src')
12 files changed, 111 insertions, 52 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/DictionaryFacilitatorForSuggest.java b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java index 259c1372e..138a626a0 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java @@ -512,7 +512,6 @@ public class DictionaryFacilitatorForSuggest { } } - @UsedForTesting public void clearUserHistoryDictionary() { if (mUserHistoryDictionary == null) { return; diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 459f6d8e1..94e3e7418 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -25,6 +25,9 @@ import android.app.AlertDialog; import android.content.BroadcastReceiver; import android.content.Context; import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; +import android.content.DialogInterface.OnDismissListener; +import android.content.DialogInterface.OnShowListener; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; @@ -531,18 +534,33 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } private void refreshPersonalizationDictionarySession() { + final Suggest suggest = mInputLogic.mSuggest; + final boolean shouldKeepUserHistoryDictionaries; + final boolean shouldKeepPersonalizationDictionaries; if (mSettings.getCurrent().mUsePersonalizedDicts) { - if (mSubtypeSwitcher.isSystemLocaleSameAsLocaleOfAllEnabledSubtypes()) { - final DictionaryFacilitatorForSuggest dictionaryFacilitator = - (mInputLogic.mSuggest == null) ? - null : mInputLogic.mSuggest.mDictionaryFacilitator; - PersonalizationDictionarySessionRegistrar.init(this, dictionaryFacilitator); - } else { - PersonalizationDictionarySessionRegistrar.close(this); - } + shouldKeepUserHistoryDictionaries = true; + // TODO: Eliminate this restriction + shouldKeepPersonalizationDictionaries = + mSubtypeSwitcher.isSystemLocaleSameAsLocaleOfAllEnabledSubtypes(); } else { - PersonalizationHelper.removeAllPersonalizedDictionaries(this); + shouldKeepUserHistoryDictionaries = false; + shouldKeepPersonalizationDictionaries = false; + } + if (!shouldKeepUserHistoryDictionaries) { + // Remove user history dictionaries. + PersonalizationHelper.removeAllUserHistoryDictionaries(this); + if (suggest != null) { + suggest.mDictionaryFacilitator.clearUserHistoryDictionary(); + } + } + if (!shouldKeepPersonalizationDictionaries) { + // Remove personalization dictionaries. + PersonalizationHelper.removeAllPersonalizationDictionaries(this); PersonalizationDictionarySessionRegistrar.resetAll(this); + } else { + final DictionaryFacilitatorForSuggest dictionaryFacilitator = + (suggest == null) ? null : suggest.mDictionaryFacilitator; + PersonalizationDictionarySessionRegistrar.init(this, dictionaryFacilitator); } } @@ -1165,27 +1183,33 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void showImportantNoticeContents() { final Context context = this; - final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { + 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 di, final int position) { - di.dismiss(); - ImportantNoticeUtils.updateLastImportantNoticeVersion(context); - if (position == DialogInterface.BUTTON_POSITIVE) { - setNeutralSuggestionStrip(); - return; - } + public void onClick(final DialogInterface dialog, final int position) { if (position == DialogInterface.BUTTON_NEGATIVE) { launchSettings(); - return; } } }; - final AlertDialog.Builder builder = - new AlertDialog.Builder(context, AlertDialog.THEME_HOLO_DARK); - builder.setMessage(R.string.important_notice_contents) - .setPositiveButton(android.R.string.ok, listener) - .setNegativeButton(R.string.go_to_settings, listener); - showOptionDialog(builder.create(), true /* cancelable */); + 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(final DialogInterface dialog) { + setNeutralSuggestionStrip(); + } + }); + showOptionDialog(importantNoticeDialog); } public void displaySettingsDialog() { @@ -1639,7 +1663,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen getString(R.string.language_selection_title), getString(ApplicationUtils.getActivityTitleResId(this, SettingsActivity.class)), }; - final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { + final OnClickListener listener = new OnClickListener() { @Override public void onClick(DialogInterface di, int position) { di.dismiss(); @@ -1660,18 +1684,18 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen }; final AlertDialog.Builder builder = new AlertDialog.Builder(this).setItems(items, listener).setTitle(title); - showOptionDialog(builder.create(), true /*cancelable */); + showOptionDialog(builder.create()); } // TODO: Move this method out of {@link LatinIME}. - private void showOptionDialog(final AlertDialog dialog, final boolean cancelable) { + private void showOptionDialog(final AlertDialog dialog) { final IBinder windowToken = mKeyboardSwitcher.getMainKeyboardView().getWindowToken(); if (windowToken == null) { return; } - dialog.setCancelable(cancelable); - dialog.setCanceledOnTouchOutside(cancelable); + dialog.setCancelable(true /* cancelable */); + dialog.setCanceledOnTouchOutside(true /* cancelable */); final Window window = dialog.getWindow(); final WindowManager.LayoutParams lp = window.getAttributes(); 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/personalization/PersonalizationHelper.java b/java/src/com/android/inputmethod/latin/personalization/PersonalizationHelper.java index df64bcec1..5ae2fb6f8 100644 --- a/java/src/com/android/inputmethod/latin/personalization/PersonalizationHelper.java +++ b/java/src/com/android/inputmethod/latin/personalization/PersonalizationHelper.java @@ -93,13 +93,16 @@ public class PersonalizationHelper { } } - public static void removeAllPersonalizedDictionaries(final Context context) { - removeAllDictionaries(context, sLangUserHistoryDictCache, - UserHistoryDictionary.NAME); + public static void removeAllPersonalizationDictionaries(final Context context) { removeAllDictionaries(context, sLangPersonalizationDictCache, PersonalizationDictionary.NAME); } + public static void removeAllUserHistoryDictionaries(final Context context) { + removeAllDictionaries(context, sLangUserHistoryDictCache, + UserHistoryDictionary.NAME); + } + private static <T extends DecayingExpandableBinaryDictionaryBase> void removeAllDictionaries( final Context context, final ConcurrentHashMap<String, SoftReference<T>> dictionaryMap, final String dictNamePrefix) { diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java index 501979645..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 = 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/SuggestionStripLayoutHelper.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java index e77c55069..8ea712835 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java @@ -504,12 +504,13 @@ final class SuggestionStripLayoutHelper { hintView, 1.0f - mCenterSuggestionWeight, ViewGroup.LayoutParams.MATCH_PARENT); } - public void layoutImportantNotice(final View importantNoticeStrip, final int stripWidth) { + public void layoutImportantNotice(final View importantNoticeStrip, final int stripWidth, + final String importantNoticeTitle) { final TextView titleView = (TextView)importantNoticeStrip.findViewById( R.id.important_notice_title); final int width = stripWidth - titleView.getPaddingLeft() - titleView.getPaddingRight(); titleView.setTextColor(mColorAutoCorrect); - final CharSequence importantNoticeTitle = titleView.getText(); + titleView.setText(importantNoticeTitle); titleView.setTextScaleX(1.0f); // Reset textScaleX. final float titleScaleX = getTextScaleX( importantNoticeTitle, width, titleView.getPaint()); diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java index 1f80c4cca..4ef562d8f 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java @@ -20,6 +20,7 @@ import android.content.Context; import android.content.res.Resources; import android.graphics.Color; import android.support.v4.view.ViewCompat; +import android.text.TextUtils; import android.util.AttributeSet; import android.util.TypedValue; import android.view.GestureDetector; @@ -236,7 +237,12 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick if (width <= 0) { return false; } - mLayoutHelper.layoutImportantNotice(mImportantNoticeStrip, width); + final String importantNoticeTitle = ImportantNoticeUtils.getNextImportantNoticeTitle( + getContext()); + if (TextUtils.isEmpty(importantNoticeTitle)) { + return false; + } + mLayoutHelper.layoutImportantNotice(mImportantNoticeStrip, width, importantNoticeTitle); mStripVisibilityGroup.showImportantNoticeStrip(); mImportantNoticeStrip.setOnClickListener(this); return true; 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 50a942382..6b0bb86ac 100644 --- a/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java @@ -30,8 +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 = 1; // Copy of the hidden {@link Settings.Secure#USER_SETUP_COMPLETE} settings key. // The value is zero until each multiuser completes system setup wizard. @@ -59,13 +60,20 @@ public final class ImportantNoticeUtils { return context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE); } - private static int getCurrentImportantNoticeVersion(final Context context) { + public static int getCurrentImportantNoticeVersion(final Context context) { 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; } @@ -78,9 +86,29 @@ 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(); } + + // 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: + return null; + } + } + + // 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: + return null; + } + } } |