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

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

Issue 2860313002: 🔍 More SearchActivity tests (Closed)
Patch Set: 🔍 More SearchActivity tests 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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.os.Bundle; 9 import android.os.Bundle;
10 import android.support.annotation.Nullable; 10 import android.support.annotation.Nullable;
11 import android.widget.Button; 11 import android.widget.Button;
12 12
13 import org.chromium.base.Callback; 13 import org.chromium.base.Callback;
14 import org.chromium.base.VisibleForTesting;
14 import org.chromium.base.library_loader.LibraryLoader; 15 import org.chromium.base.library_loader.LibraryLoader;
15 import org.chromium.chrome.R; 16 import org.chromium.chrome.R;
16 import org.chromium.chrome.browser.locale.LocaleManager.SearchEnginePromoType; 17 import org.chromium.chrome.browser.locale.LocaleManager.SearchEnginePromoType;
17 import org.chromium.chrome.browser.search_engines.TemplateUrlService; 18 import org.chromium.chrome.browser.search_engines.TemplateUrlService;
18 import org.chromium.chrome.browser.widget.PromoDialog; 19 import org.chromium.chrome.browser.widget.PromoDialog;
19 import org.chromium.chrome.browser.widget.RadioButtonLayout; 20 import org.chromium.chrome.browser.widget.RadioButtonLayout;
20 21
21 /** A dialog that forces the user to choose a default search engine. */ 22 /** A dialog that forces the user to choose a default search engine. */
22 public class DefaultSearchEnginePromoDialog extends PromoDialog { 23 public class DefaultSearchEnginePromoDialog extends PromoDialog {
24 /** Notified about events happening to the dialog. */
25 public static interface DefaultSearchEnginePromoDialogObserver {
26 void onDialogShown(DefaultSearchEnginePromoDialog shownDialog);
27 }
28 private static DefaultSearchEnginePromoDialogObserver sObserver;
29
23 /** Used to determine the promo dialog contents. */ 30 /** Used to determine the promo dialog contents. */
24 @SearchEnginePromoType 31 @SearchEnginePromoType
25 private final int mDialogType; 32 private final int mDialogType;
26 33
27 /** Called when the dialog is dismissed after the user has chosen a search e ngine. */ 34 /** Called when the dialog is dismissed after the user has chosen a search e ngine. */
28 private final Callback<Boolean> mOnDismissed; 35 private final Callback<Boolean> mOnDismissed;
29 36
30 /** Encapsulates most of the logic for filling the dialog and handling click s. */ 37 /** Encapsulates most of the logic for filling the dialog and handling click s. */
31 private DefaultSearchEngineDialogHelper mHelper; 38 private DefaultSearchEngineDialogHelper mHelper;
32 39
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 } 83 }
77 84
78 @Override 85 @Override
79 protected void onCreate(Bundle savedInstanceState) { 86 protected void onCreate(Bundle savedInstanceState) {
80 super.onCreate(savedInstanceState); 87 super.onCreate(savedInstanceState);
81 88
82 Button okButton = (Button) findViewById(R.id.button_primary); 89 Button okButton = (Button) findViewById(R.id.button_primary);
83 okButton.setEnabled(false); 90 okButton.setEnabled(false);
84 91
85 RadioButtonLayout radioButtons = new RadioButtonLayout(getContext()); 92 RadioButtonLayout radioButtons = new RadioButtonLayout(getContext());
93 radioButtons.setId(R.id.default_search_engine_dialog_options);
86 addControl(radioButtons); 94 addControl(radioButtons);
87 95
88 Runnable dismissRunnable = new Runnable() { 96 Runnable dismissRunnable = new Runnable() {
89 @Override 97 @Override
90 public void run() { 98 public void run() {
91 dismiss(); 99 dismiss();
92 } 100 }
93 }; 101 };
94 mHelper = new DefaultSearchEngineDialogHelper( 102 mHelper = new DefaultSearchEngineDialogHelper(
95 mDialogType, radioButtons, okButton, dismissRunnable); 103 mDialogType, radioButtons, okButton, dismissRunnable);
96 } 104 }
97 105
98 @Override 106 @Override
107 public void show() {
108 super.show();
109 if (sObserver != null) sObserver.onDialogShown(this);
110 }
111
112 @Override
99 public void onDismiss(DialogInterface dialog) { 113 public void onDismiss(DialogInterface dialog) {
100 if (mHelper.getCurrentlySelectedKeyword() == null) { 114 if (mHelper.getCurrentlySelectedKeyword() == null) {
101 // This shouldn't happen, but in case it does, finish the Activity s o that the user has 115 // This shouldn't happen, but in case it does, finish the Activity s o that the user has
102 // to respond to the dialog next time. 116 // to respond to the dialog next time.
103 if (getOwnerActivity() != null) getOwnerActivity().finish(); 117 if (getOwnerActivity() != null) getOwnerActivity().finish();
104 } 118 }
105 119
106 if (mOnDismissed != null) { 120 if (mOnDismissed != null) {
107 mOnDismissed.onResult(mHelper.getCurrentlySelectedKeyword() != null) ; 121 mOnDismissed.onResult(mHelper.getCurrentlySelectedKeyword() != null) ;
108 } 122 }
109 } 123 }
124
125 /** See {@link #sObserver}. */
126 @VisibleForTesting
127 @Nullable
128 public static void setObserverForTests(DefaultSearchEnginePromoDialogObserve r observer) {
129 sObserver = observer;
130 }
110 } 131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698