Change important notice version preference file

This CL also reset the notice version to 1.
This CL must be checked in together with Iea8d9ff038.

Change-Id: I838f7b5b295388d64d6aba90f50b06654eba16e5
main
Tadashi G. Takaoka 2014-02-20 15:47:54 +09:00
parent 78db739cdb
commit 1672ccbbb6
5 changed files with 38 additions and 47 deletions

View File

@ -20,7 +20,8 @@
<resources> <resources>
<integer name="config_important_notice_version">0</integer> <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> <string name="important_notice_title"></string>
<!-- The contents of the important notice. --> <!-- The contents of the important notice. -->
<string name="important_notice_contents"></string> <string name="important_notice_contents"></string>

View File

@ -1183,14 +1183,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override @Override
public void showImportantNoticeContents() { public void showImportantNoticeContents() {
final Context context = this; final Context context = this;
final OnShowListener onShowListener = new OnShowListener() { final AlertDialog.Builder builder =
@Override new AlertDialog.Builder(context, AlertDialog.THEME_HOLO_DARK);
public void onShow(final DialogInterface dialog) { builder.setMessage(ImportantNoticeUtils.getNextImportantNoticeContents(context));
ImportantNoticeUtils.updateLastImportantNoticeVersion(context); builder.setPositiveButton(android.R.string.ok, null /* listener */);
onShowImportantNoticeDialog(
ImportantNoticeUtils.getCurrentImportantNoticeVersion(context));
}
};
final OnClickListener onClickListener = new OnClickListener() { final OnClickListener onClickListener = new OnClickListener() {
@Override @Override
public void onClick(final DialogInterface dialog, final int position) { 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 @Override
public void onDismiss(DialogInterface dialog) { public void onShow(final DialogInterface dialog) {
ImportantNoticeUtils.updateLastImportantNoticeVersion(context);
}
});
importantNoticeDialog.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(final DialogInterface dialog) {
setNeutralSuggestionStrip(); 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); 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() { public void displaySettingsDialog() {
if (isShowingOptionDialog()) { if (isShowingOptionDialog()) {
return; return;

View File

@ -421,10 +421,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
return mPrefs.getStringSet(PREF_CORPUS_HANDLES_FOR_PERSONALIZATION, emptySet); 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) { public static void writeEmojiRecentKeys(final SharedPreferences prefs, String str) {
prefs.edit().putString(PREF_EMOJI_RECENT_KEYS, str).apply(); prefs.edit().putString(PREF_EMOJI_RECENT_KEYS, str).apply();
} }

View File

@ -237,7 +237,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
if (width <= 0) { if (width <= 0) {
return false; return false;
} }
final String importantNoticeTitle = ImportantNoticeUtils.getImportantNoticeTitle( final String importantNoticeTitle = ImportantNoticeUtils.getNextImportantNoticeTitle(
getContext()); getContext());
if (TextUtils.isEmpty(importantNoticeTitle)) { if (TextUtils.isEmpty(importantNoticeTitle)) {
return false; return false;

View File

@ -30,9 +30,9 @@ public final class ImportantNoticeUtils {
// {@link SharedPreferences} name to save the last important notice version that has been // {@link SharedPreferences} name to save the last important notice version that has been
// displayed to users. // 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"; 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. // Copy of the hidden {@link Settings.Secure#USER_SETUP_COMPLETE} settings key.
// The value is zero until each multiuser completes system setup wizard. // 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); 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) { private static boolean hasNewImportantNotice(final Context context) {
final SharedPreferences prefs = getImportantNoticePreferences(context); final int lastVersion = getLastImportantNoticeVersion(context);
final int lastVersion = prefs.getInt(KEY_IMPORTANT_NOTICE_VERSION, 0);
return getCurrentImportantNoticeVersion(context) > lastVersion; return getCurrentImportantNoticeVersion(context) > lastVersion;
} }
@ -79,14 +86,15 @@ public final class ImportantNoticeUtils {
} }
public static void updateLastImportantNoticeVersion(final Context context) { public static void updateLastImportantNoticeVersion(final Context context) {
final SharedPreferences prefs = getImportantNoticePreferences(context); getImportantNoticePreferences(context)
prefs.edit() .edit()
.putInt(KEY_IMPORTANT_NOTICE_VERSION, getCurrentImportantNoticeVersion(context)) .putInt(KEY_IMPORTANT_NOTICE_VERSION, getNextImportantNoticeVersion(context))
.apply(); .apply();
} }
public static String getImportantNoticeTitle(final Context context) { // TODO: Make title resource to string array indexed by version.
switch (getCurrentImportantNoticeVersion(context)) { public static String getNextImportantNoticeTitle(final Context context) {
switch (getNextImportantNoticeVersion(context)) {
case VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS: case VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS:
return context.getString(R.string.important_notice_title); return context.getString(R.string.important_notice_title);
default: default:
@ -94,8 +102,9 @@ public final class ImportantNoticeUtils {
} }
} }
public static String getImportantNoticeContents(final Context context) { // TODO: Make content resource to string array indexed by version.
switch (getCurrentImportantNoticeVersion(context)) { public static String getNextImportantNoticeContents(final Context context) {
switch (getNextImportantNoticeVersion(context)) {
case VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS: case VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS:
return context.getString(R.string.important_notice_contents); return context.getString(R.string.important_notice_contents);
default: default: