Turn personalization on when important notice dialog is displayed

This change must be checked in together with Ifde70b1d3b.

Bug: 10587358
Change-Id: I9dc48f9d521e0e6f6269e4f184389ba805f3053f
main
Tadashi G. Takaoka 2014-02-19 13:17:36 +09:00
parent 0a4ac795d6
commit 6abc852255
6 changed files with 77 additions and 24 deletions

View File

@ -52,7 +52,6 @@
android:layout_height="match_parent">
<TextView
android:id="@+id/important_notice_title"
android:text="@string/important_notice_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="6sp"

View File

@ -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;
@ -1163,27 +1166,48 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override
public void showImportantNoticeContents() {
final Context context = this;
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
final OnShowListener onShowListener = new OnShowListener() {
@Override
public void onClick(final DialogInterface di, final int position) {
di.dismiss();
public void onShow(final DialogInterface dialog) {
ImportantNoticeUtils.updateLastImportantNoticeVersion(context);
if (position == DialogInterface.BUTTON_POSITIVE) {
setNeutralSuggestionStrip();
return;
}
onShowImportantNoticeDialog(
ImportantNoticeUtils.getCurrentImportantNoticeVersion(context));
}
};
final OnClickListener onClickListener = new OnClickListener() {
@Override
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 */);
final OnDismissListener onDismissListener = new OnDismissListener() {
@Override
public void onDismiss(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)
.setOnDismissListener(onDismissListener);
final AlertDialog importantNoticeDialog = builder.create();
importantNoticeDialog.setOnShowListener(onShowListener);
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() {
@ -1637,7 +1661,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();
@ -1658,18 +1682,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();

View File

@ -421,6 +421,10 @@ 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();
}

View File

@ -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());

View File

@ -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.getImportantNoticeTitle(
getContext());
if (TextUtils.isEmpty(importantNoticeTitle)) {
return false;
}
mLayoutHelper.layoutImportantNotice(mImportantNoticeStrip, width, importantNoticeTitle);
mStripVisibilityGroup.showImportantNoticeStrip();
mImportantNoticeStrip.setOnClickListener(this);
return true;

View File

@ -32,6 +32,7 @@ public final class ImportantNoticeUtils {
// displayed to users.
private static final String PREFERENCE_NAME = "important_notice";
private static final String KEY_IMPORTANT_NOTICE_VERSION = "important_notice_version";
public static final int VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS = 2;
// Copy of the hidden {@link Settings.Secure#USER_SETUP_COMPLETE} settings key.
// The value is zero until each multiuser completes system setup wizard.
@ -59,7 +60,7 @@ 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);
}
@ -83,4 +84,22 @@ public final class ImportantNoticeUtils {
.putInt(KEY_IMPORTANT_NOTICE_VERSION, getCurrentImportantNoticeVersion(context))
.apply();
}
public static String getImportantNoticeTitle(final Context context) {
switch (getCurrentImportantNoticeVersion(context)) {
case VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS:
return context.getString(R.string.important_notice_title);
default:
return null;
}
}
public static String getImportantNoticeContents(final Context context) {
switch (getCurrentImportantNoticeVersion(context)) {
case VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS:
return context.getString(R.string.important_notice_contents);
default:
return null;
}
}
}