Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/locale/SogouPromoDialog.java

Issue 2838833002: 🔍 Introduce default search engine dialog (Closed)
Patch Set: COmments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.locale; 5 package org.chromium.chrome.browser.locale;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.DialogInterface; 8 import android.content.DialogInterface;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.os.Bundle; 10 import android.os.Bundle;
11 import android.support.annotation.IntDef; 11 import android.support.annotation.IntDef;
12 import android.support.annotation.Nullable; 12 import android.support.annotation.Nullable;
13 import android.text.SpannableString; 13 import android.text.SpannableString;
14 import android.text.method.LinkMovementMethod; 14 import android.text.method.LinkMovementMethod;
15 import android.text.style.ClickableSpan; 15 import android.text.style.ClickableSpan;
16 import android.text.style.StyleSpan; 16 import android.text.style.StyleSpan;
17 import android.view.View; 17 import android.view.View;
18 import android.widget.TextView; 18 import android.widget.TextView;
19 19
20 import org.chromium.base.Callback;
20 import org.chromium.base.ContextUtils; 21 import org.chromium.base.ContextUtils;
21 import org.chromium.base.metrics.RecordHistogram; 22 import org.chromium.base.metrics.RecordHistogram;
22 import org.chromium.chrome.R; 23 import org.chromium.chrome.R;
23 import org.chromium.chrome.browser.preferences.PreferencesLauncher; 24 import org.chromium.chrome.browser.preferences.PreferencesLauncher;
24 import org.chromium.chrome.browser.preferences.SearchEnginePreference; 25 import org.chromium.chrome.browser.preferences.SearchEnginePreference;
25 import org.chromium.chrome.browser.widget.PromoDialog; 26 import org.chromium.chrome.browser.widget.PromoDialog;
26 import org.chromium.ui.text.NoUnderlineClickableSpan; 27 import org.chromium.ui.text.NoUnderlineClickableSpan;
27 import org.chromium.ui.text.SpanApplier; 28 import org.chromium.ui.text.SpanApplier;
28 import org.chromium.ui.text.SpanApplier.SpanInfo; 29 import org.chromium.ui.text.SpanApplier.SpanInfo;
29 30
(...skipping 10 matching lines...) Expand all
40 @IntDef({CHOICE_USE_SOGOU, CHOICE_KEEP_GOOGLE, CHOICE_SETTINGS, CHOICE_BACK_ KEY}) 41 @IntDef({CHOICE_USE_SOGOU, CHOICE_KEEP_GOOGLE, CHOICE_SETTINGS, CHOICE_BACK_ KEY})
41 private @interface UserChoice {} 42 private @interface UserChoice {}
42 private static final int CHOICE_USE_SOGOU = 0; 43 private static final int CHOICE_USE_SOGOU = 0;
43 private static final int CHOICE_KEEP_GOOGLE = 1; 44 private static final int CHOICE_KEEP_GOOGLE = 1;
44 private static final int CHOICE_SETTINGS = 2; 45 private static final int CHOICE_SETTINGS = 2;
45 private static final int CHOICE_BACK_KEY = 3; 46 private static final int CHOICE_BACK_KEY = 3;
46 47
47 private static final int CHOICE_ENUM_COUNT = 4; 48 private static final int CHOICE_ENUM_COUNT = 4;
48 49
49 /** Run when the dialog is dismissed. */ 50 /** Run when the dialog is dismissed. */
50 private final Runnable mOnDismissedRunnable; 51 private final Callback<Boolean> mOnDismissedCallback;
51 52
52 private final LocaleManager mLocaleManager; 53 private final LocaleManager mLocaleManager;
53 private final ClickableSpan mSpan = new NoUnderlineClickableSpan() { 54 private final ClickableSpan mSpan = new NoUnderlineClickableSpan() {
54 @Override 55 @Override
55 public void onClick(View widget) { 56 public void onClick(View widget) {
56 mChoice = CHOICE_SETTINGS; 57 mChoice = CHOICE_SETTINGS;
57 Intent intent = PreferencesLauncher.createIntentForSettingsPage( 58 Intent intent = PreferencesLauncher.createIntentForSettingsPage(
58 getContext(), SearchEnginePreference.class.getName()); 59 getContext(), SearchEnginePreference.class.getName());
59 getContext().startActivity(intent); 60 getContext().startActivity(intent);
60 dismiss(); 61 dismiss();
61 } 62 }
62 }; 63 };
63 64
64 @UserChoice 65 @UserChoice
65 private int mChoice = CHOICE_BACK_KEY; 66 private int mChoice = CHOICE_BACK_KEY;
66 67
67 /** 68 /**
68 * Creates an instance of the dialog. 69 * Creates an instance of the dialog.
69 */ 70 */
70 public SogouPromoDialog( 71 public SogouPromoDialog(
71 Context context, LocaleManager localeManager, @Nullable Runnable onD ismissed) { 72 Context context, LocaleManager localeManager, @Nullable Callback<Boo lean> onDismissed) {
72 super(context); 73 super(context);
73 mLocaleManager = localeManager; 74 mLocaleManager = localeManager;
74 setOnDismissListener(this); 75 setOnDismissListener(this);
75 setCanceledOnTouchOutside(false); 76 setCanceledOnTouchOutside(false);
76 mOnDismissedRunnable = onDismissed; 77 mOnDismissedCallback = onDismissed;
77 } 78 }
78 79
79 @Override 80 @Override
80 protected DialogParams getDialogParams() { 81 protected DialogParams getDialogParams() {
81 PromoDialog.DialogParams params = new PromoDialog.DialogParams(); 82 PromoDialog.DialogParams params = new PromoDialog.DialogParams();
82 params.drawableResource = R.drawable.search_sogou; 83 params.drawableResource = R.drawable.search_sogou;
83 params.headerStringResource = R.string.search_with_sogou; 84 params.headerStringResource = R.string.search_with_sogou;
84 params.subheaderStringResource = R.string.sogou_explanation; 85 params.subheaderStringResource = R.string.sogou_explanation;
85 params.primaryButtonStringResource = R.string.ok; 86 params.primaryButtonStringResource = R.string.ok;
86 params.secondaryButtonStringResource = R.string.keep_google; 87 params.secondaryButtonStringResource = R.string.keep_google;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 default: 144 default:
144 assert false : "Unexpected choice"; 145 assert false : "Unexpected choice";
145 } 146 }
146 ContextUtils.getAppSharedPreferences() 147 ContextUtils.getAppSharedPreferences()
147 .edit() 148 .edit()
148 .putBoolean(LocaleManager.PREF_PROMO_SHOWN, true) 149 .putBoolean(LocaleManager.PREF_PROMO_SHOWN, true)
149 .apply(); 150 .apply();
150 RecordHistogram.recordEnumeratedHistogram( 151 RecordHistogram.recordEnumeratedHistogram(
151 "SpecialLocale.PromotionDialog", mChoice, CHOICE_ENUM_COUNT); 152 "SpecialLocale.PromotionDialog", mChoice, CHOICE_ENUM_COUNT);
152 153
153 if (mOnDismissedRunnable != null) mOnDismissedRunnable.run(); 154 if (mOnDismissedCallback != null) mOnDismissedCallback.onResult(true);
154 } 155 }
155 } 156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698