OLD | NEW |
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.text.SpannableString; | 13 import android.text.SpannableString; |
13 import android.text.method.LinkMovementMethod; | 14 import android.text.method.LinkMovementMethod; |
14 import android.text.style.ClickableSpan; | 15 import android.text.style.ClickableSpan; |
15 import android.text.style.StyleSpan; | 16 import android.text.style.StyleSpan; |
16 import android.view.View; | 17 import android.view.View; |
17 import android.widget.TextView; | 18 import android.widget.TextView; |
18 | 19 |
19 import org.chromium.base.ContextUtils; | 20 import org.chromium.base.ContextUtils; |
20 import org.chromium.base.metrics.RecordHistogram; | 21 import org.chromium.base.metrics.RecordHistogram; |
21 import org.chromium.chrome.R; | 22 import org.chromium.chrome.R; |
(...skipping 16 matching lines...) Expand all Loading... |
38 @Retention(RetentionPolicy.SOURCE) | 39 @Retention(RetentionPolicy.SOURCE) |
39 @IntDef({CHOICE_USE_SOGOU, CHOICE_KEEP_GOOGLE, CHOICE_SETTINGS, CHOICE_BACK_
KEY}) | 40 @IntDef({CHOICE_USE_SOGOU, CHOICE_KEEP_GOOGLE, CHOICE_SETTINGS, CHOICE_BACK_
KEY}) |
40 private @interface UserChoice {} | 41 private @interface UserChoice {} |
41 private static final int CHOICE_USE_SOGOU = 0; | 42 private static final int CHOICE_USE_SOGOU = 0; |
42 private static final int CHOICE_KEEP_GOOGLE = 1; | 43 private static final int CHOICE_KEEP_GOOGLE = 1; |
43 private static final int CHOICE_SETTINGS = 2; | 44 private static final int CHOICE_SETTINGS = 2; |
44 private static final int CHOICE_BACK_KEY = 3; | 45 private static final int CHOICE_BACK_KEY = 3; |
45 | 46 |
46 private static final int CHOICE_ENUM_COUNT = 4; | 47 private static final int CHOICE_ENUM_COUNT = 4; |
47 | 48 |
| 49 /** Run when the dialog is dismissed. */ |
| 50 private final Runnable mOnDismissedRunnable; |
| 51 |
48 private final LocaleManager mLocaleManager; | 52 private final LocaleManager mLocaleManager; |
49 private final ClickableSpan mSpan = new NoUnderlineClickableSpan() { | 53 private final ClickableSpan mSpan = new NoUnderlineClickableSpan() { |
50 @Override | 54 @Override |
51 public void onClick(View widget) { | 55 public void onClick(View widget) { |
52 mChoice = CHOICE_SETTINGS; | 56 mChoice = CHOICE_SETTINGS; |
53 Intent intent = PreferencesLauncher.createIntentForSettingsPage( | 57 Intent intent = PreferencesLauncher.createIntentForSettingsPage( |
54 getContext(), SearchEnginePreference.class.getName()); | 58 getContext(), SearchEnginePreference.class.getName()); |
55 getContext().startActivity(intent); | 59 getContext().startActivity(intent); |
56 dismiss(); | 60 dismiss(); |
57 } | 61 } |
58 }; | 62 }; |
59 | 63 |
60 @UserChoice | 64 @UserChoice |
61 private int mChoice = CHOICE_BACK_KEY; | 65 private int mChoice = CHOICE_BACK_KEY; |
62 | 66 |
63 /** | 67 /** |
64 * Creates an instance of the dialog. | 68 * Creates an instance of the dialog. |
65 */ | 69 */ |
66 public SogouPromoDialog(Context context, LocaleManager localeManager) { | 70 public SogouPromoDialog( |
| 71 Context context, LocaleManager localeManager, @Nullable Runnable onD
ismissed) { |
67 super(context); | 72 super(context); |
68 mLocaleManager = localeManager; | 73 mLocaleManager = localeManager; |
69 setOnDismissListener(this); | 74 setOnDismissListener(this); |
70 setCanceledOnTouchOutside(false); | 75 setCanceledOnTouchOutside(false); |
| 76 mOnDismissedRunnable = onDismissed; |
71 } | 77 } |
72 | 78 |
73 @Override | 79 @Override |
74 protected DialogParams getDialogParams() { | 80 protected DialogParams getDialogParams() { |
75 PromoDialog.DialogParams params = new PromoDialog.DialogParams(); | 81 PromoDialog.DialogParams params = new PromoDialog.DialogParams(); |
76 params.drawableResource = R.drawable.search_sogou; | 82 params.drawableResource = R.drawable.search_sogou; |
77 params.headerStringResource = R.string.search_with_sogou; | 83 params.headerStringResource = R.string.search_with_sogou; |
78 params.subheaderStringResource = R.string.sogou_explanation; | 84 params.subheaderStringResource = R.string.sogou_explanation; |
79 params.primaryButtonStringResource = R.string.ok; | 85 params.primaryButtonStringResource = R.string.ok; |
80 params.secondaryButtonStringResource = R.string.keep_google; | 86 params.secondaryButtonStringResource = R.string.keep_google; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 break; | 142 break; |
137 default: | 143 default: |
138 assert false : "Unexpected choice"; | 144 assert false : "Unexpected choice"; |
139 } | 145 } |
140 ContextUtils.getAppSharedPreferences() | 146 ContextUtils.getAppSharedPreferences() |
141 .edit() | 147 .edit() |
142 .putBoolean(LocaleManager.PREF_PROMO_SHOWN, true) | 148 .putBoolean(LocaleManager.PREF_PROMO_SHOWN, true) |
143 .apply(); | 149 .apply(); |
144 RecordHistogram.recordEnumeratedHistogram( | 150 RecordHistogram.recordEnumeratedHistogram( |
145 "SpecialLocale.PromotionDialog", mChoice, CHOICE_ENUM_COUNT); | 151 "SpecialLocale.PromotionDialog", mChoice, CHOICE_ENUM_COUNT); |
| 152 |
| 153 if (mOnDismissedRunnable != null) mOnDismissedRunnable.run(); |
146 } | 154 } |
147 } | 155 } |
OLD | NEW |