am ed616083: Merge "Turn personalization on when important notice dialog is displayed"
* commit 'ed616083dda090775c6d17ca073ccb80aaa1c4bd': Turn personalization on when important notice dialog is displayedmain
commit
433651a228
|
@ -52,7 +52,6 @@
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/important_notice_title"
|
android:id="@+id/important_notice_title"
|
||||||
android:text="@string/important_notice_title"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:padding="6sp"
|
android:padding="6sp"
|
||||||
|
|
|
@ -25,6 +25,9 @@ import android.app.AlertDialog;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
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.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
@ -1165,27 +1168,48 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
@Override
|
@Override
|
||||||
public void showImportantNoticeContents() {
|
public void showImportantNoticeContents() {
|
||||||
final Context context = this;
|
final Context context = this;
|
||||||
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
final OnShowListener onShowListener = new OnShowListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(final DialogInterface di, final int position) {
|
public void onShow(final DialogInterface dialog) {
|
||||||
di.dismiss();
|
|
||||||
ImportantNoticeUtils.updateLastImportantNoticeVersion(context);
|
ImportantNoticeUtils.updateLastImportantNoticeVersion(context);
|
||||||
if (position == DialogInterface.BUTTON_POSITIVE) {
|
onShowImportantNoticeDialog(
|
||||||
setNeutralSuggestionStrip();
|
ImportantNoticeUtils.getCurrentImportantNoticeVersion(context));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
final OnClickListener onClickListener = new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(final DialogInterface dialog, final int position) {
|
||||||
if (position == DialogInterface.BUTTON_NEGATIVE) {
|
if (position == DialogInterface.BUTTON_NEGATIVE) {
|
||||||
launchSettings();
|
launchSettings();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
final AlertDialog.Builder builder =
|
final OnDismissListener onDismissListener = new OnDismissListener() {
|
||||||
new AlertDialog.Builder(context, AlertDialog.THEME_HOLO_DARK);
|
@Override
|
||||||
builder.setMessage(R.string.important_notice_contents)
|
public void onDismiss(DialogInterface dialog) {
|
||||||
.setPositiveButton(android.R.string.ok, listener)
|
setNeutralSuggestionStrip();
|
||||||
.setNegativeButton(R.string.go_to_settings, listener);
|
}
|
||||||
showOptionDialog(builder.create(), true /* cancelable */);
|
};
|
||||||
|
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() {
|
public void displaySettingsDialog() {
|
||||||
|
@ -1639,7 +1663,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
getString(R.string.language_selection_title),
|
getString(R.string.language_selection_title),
|
||||||
getString(ApplicationUtils.getActivityTitleResId(this, SettingsActivity.class)),
|
getString(ApplicationUtils.getActivityTitleResId(this, SettingsActivity.class)),
|
||||||
};
|
};
|
||||||
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
final OnClickListener listener = new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface di, int position) {
|
public void onClick(DialogInterface di, int position) {
|
||||||
di.dismiss();
|
di.dismiss();
|
||||||
|
@ -1660,18 +1684,18 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
};
|
};
|
||||||
final AlertDialog.Builder builder =
|
final AlertDialog.Builder builder =
|
||||||
new AlertDialog.Builder(this).setItems(items, listener).setTitle(title);
|
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}.
|
// 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();
|
final IBinder windowToken = mKeyboardSwitcher.getMainKeyboardView().getWindowToken();
|
||||||
if (windowToken == null) {
|
if (windowToken == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog.setCancelable(cancelable);
|
dialog.setCancelable(true /* cancelable */);
|
||||||
dialog.setCanceledOnTouchOutside(cancelable);
|
dialog.setCanceledOnTouchOutside(true /* cancelable */);
|
||||||
|
|
||||||
final Window window = dialog.getWindow();
|
final Window window = dialog.getWindow();
|
||||||
final WindowManager.LayoutParams lp = window.getAttributes();
|
final WindowManager.LayoutParams lp = window.getAttributes();
|
||||||
|
|
|
@ -421,6 +421,10 @@ 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_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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -504,12 +504,13 @@ final class SuggestionStripLayoutHelper {
|
||||||
hintView, 1.0f - mCenterSuggestionWeight, ViewGroup.LayoutParams.MATCH_PARENT);
|
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(
|
final TextView titleView = (TextView)importantNoticeStrip.findViewById(
|
||||||
R.id.important_notice_title);
|
R.id.important_notice_title);
|
||||||
final int width = stripWidth - titleView.getPaddingLeft() - titleView.getPaddingRight();
|
final int width = stripWidth - titleView.getPaddingLeft() - titleView.getPaddingRight();
|
||||||
titleView.setTextColor(mColorAutoCorrect);
|
titleView.setTextColor(mColorAutoCorrect);
|
||||||
final CharSequence importantNoticeTitle = titleView.getText();
|
titleView.setText(importantNoticeTitle);
|
||||||
titleView.setTextScaleX(1.0f); // Reset textScaleX.
|
titleView.setTextScaleX(1.0f); // Reset textScaleX.
|
||||||
final float titleScaleX = getTextScaleX(
|
final float titleScaleX = getTextScaleX(
|
||||||
importantNoticeTitle, width, titleView.getPaint());
|
importantNoticeTitle, width, titleView.getPaint());
|
||||||
|
|
|
@ -20,6 +20,7 @@ import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.support.v4.view.ViewCompat;
|
import android.support.v4.view.ViewCompat;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.GestureDetector;
|
import android.view.GestureDetector;
|
||||||
|
@ -236,7 +237,12 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
||||||
if (width <= 0) {
|
if (width <= 0) {
|
||||||
return false;
|
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();
|
mStripVisibilityGroup.showImportantNoticeStrip();
|
||||||
mImportantNoticeStrip.setOnClickListener(this);
|
mImportantNoticeStrip.setOnClickListener(this);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -32,6 +32,7 @@ public final class ImportantNoticeUtils {
|
||||||
// displayed to users.
|
// displayed to users.
|
||||||
private static final String PREFERENCE_NAME = "important_notice";
|
private static final String PREFERENCE_NAME = "important_notice";
|
||||||
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;
|
||||||
|
|
||||||
// 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.
|
||||||
|
@ -59,7 +60,7 @@ public final class ImportantNoticeUtils {
|
||||||
return context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
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);
|
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))
|
.putInt(KEY_IMPORTANT_NOTICE_VERSION, getCurrentImportantNoticeVersion(context))
|
||||||
.apply();
|
.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue