diff --git a/java/res/values/strings-config-important-notice.xml b/java/res/values/strings-config-important-notice.xml index 6a9fe28f72792a5823c6853fec731fd162522ea2..3be95d333572cbb3fddfefd97825ff5dd575d503 100644 --- a/java/res/values/strings-config-important-notice.xml +++ b/java/res/values/strings-config-important-notice.xml @@ -20,7 +20,8 @@ <resources> <integer name="config_important_notice_version">0</integer> - <!-- The title of the important notice displayed on the suggestion strip. --> + <!-- TODO: Make title and contents resource to string array indexed by version. --> + <!-- The text of the important notice displayed on the suggestion strip. --> <string name="important_notice_title"></string> <!-- The contents of the important notice. --> <string name="important_notice_contents"></string> diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 5d90e10a00b98c77ee0d53c438fdb544e20ef3a8..94e3e74187a37871f11aa71c6c19e78cd85c4026 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -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/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java index a0c8ec04572aa7a98fb3d6ce45a7f5db2be04f08..b51c765f02241364ef30b5da37a23cc444bd344c 100644 --- a/java/src/com/android/inputmethod/latin/settings/Settings.java +++ b/java/src/com/android/inputmethod/latin/settings/Settings.java @@ -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_KEY_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/suggestions/SuggestionStripView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java index 2966a8bba005482cc9eb952307ad7267bef5d333..4ef562d8fecbf6a690e70923936a373606eb1220 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/utils/ImportantNoticeUtils.java b/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java index dd418b8cf7a0274911540a988c9dbc723bbf0fae..6b0bb86ac3ee80815bafb93dabe3a500b7de412c 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: