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: I838f7b5b295388d64d6aba90f50b06654eba16e5main
parent
78db739cdb
commit
1672ccbbb6
|
@ -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>
|
||||
|
|
|
@ -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 onDismiss(DialogInterface dialog) {
|
||||
public void onShow(final DialogInterface dialog) {
|
||||
ImportantNoticeUtils.updateLastImportantNoticeVersion(context);
|
||||
}
|
||||
});
|
||||
importantNoticeDialog.setOnDismissListener(new OnDismissListener() {
|
||||
@Override
|
||||
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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue