| OLD | NEW |
| 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.view.View; | 11 import android.view.View; |
| 12 import android.widget.Button; | |
| 13 import android.widget.RadioGroup; | 12 import android.widget.RadioGroup; |
| 14 import android.widget.RadioGroup.OnCheckedChangeListener; | 13 import android.widget.RadioGroup.OnCheckedChangeListener; |
| 15 | 14 |
| 16 import org.chromium.base.Callback; | 15 import org.chromium.base.Callback; |
| 17 import org.chromium.base.library_loader.LibraryLoader; | 16 import org.chromium.base.library_loader.LibraryLoader; |
| 18 import org.chromium.chrome.R; | 17 import org.chromium.chrome.R; |
| 18 import org.chromium.chrome.browser.infobar.InfoBarControlLayout; |
| 19 import org.chromium.chrome.browser.locale.LocaleManager.SearchEnginePromoType; | 19 import org.chromium.chrome.browser.locale.LocaleManager.SearchEnginePromoType; |
| 20 import org.chromium.chrome.browser.search_engines.TemplateUrlService; | 20 import org.chromium.chrome.browser.search_engines.TemplateUrlService; |
| 21 import org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrl
; | 21 import org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrl
; |
| 22 import org.chromium.chrome.browser.widget.PromoDialog; | 22 import org.chromium.chrome.browser.widget.PromoDialog; |
| 23 import org.chromium.chrome.browser.widget.RadioButtonLayout; | |
| 24 | 23 |
| 25 import java.util.ArrayList; | 24 import java.util.ArrayList; |
| 26 import java.util.Collections; | 25 import java.util.Collections; |
| 27 import java.util.List; | 26 import java.util.List; |
| 28 | 27 |
| 29 /** A dialog that forces the user to choose a default search engine. */ | 28 /** A dialog that forces the user to choose a default search engine. */ |
| 30 public class DefaultSearchEnginePromoDialog extends PromoDialog implements OnChe
ckedChangeListener { | 29 public class DefaultSearchEnginePromoDialog extends PromoDialog implements OnChe
ckedChangeListener { |
| 31 /** Used to determine the promo dialog contents. */ | 30 /** Used to determine the promo dialog contents. */ |
| 32 @SearchEnginePromoType | 31 @SearchEnginePromoType |
| 33 private final int mDialogType; | 32 private final int mDialogType; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 List<CharSequence> engineNames = new ArrayList<>(); | 101 List<CharSequence> engineNames = new ArrayList<>(); |
| 103 List<String> engineKeywords = new ArrayList<>(); | 102 List<String> engineKeywords = new ArrayList<>(); |
| 104 Collections.shuffle(engines); | 103 Collections.shuffle(engines); |
| 105 for (int i = 0; i < engines.size(); i++) { | 104 for (int i = 0; i < engines.size(); i++) { |
| 106 TemplateUrl engine = engines.get(i); | 105 TemplateUrl engine = engines.get(i); |
| 107 engineNames.add(engine.getShortName()); | 106 engineNames.add(engine.getShortName()); |
| 108 engineKeywords.add(engine.getKeyword()); | 107 engineKeywords.add(engine.getKeyword()); |
| 109 } | 108 } |
| 110 | 109 |
| 111 // Add the search engines to the dialog. | 110 // Add the search engines to the dialog. |
| 112 RadioButtonLayout radioButtons = new RadioButtonLayout(getContext()); | 111 InfoBarControlLayout controls = addControlLayout(); |
| 113 radioButtons.addOptions(engineNames, engineKeywords); | 112 mRadioGroup = controls.addRadioButtons( |
| 114 radioButtons.setOnCheckedChangeListener(this); | 113 engineNames, engineKeywords, InfoBarControlLayout.INVALID_INDEX)
; |
| 115 addControl(radioButtons); | 114 mRadioGroup.setOnCheckedChangeListener(this); |
| 116 | |
| 117 Button button = (Button) findViewById(R.id.button_primary); | |
| 118 button.setOnClickListener(this); | |
| 119 updateButtonState(); | 115 updateButtonState(); |
| 120 } | 116 } |
| 121 | 117 |
| 122 @Override | 118 @Override |
| 123 public void onCheckedChanged(RadioGroup group, int checkedId) { | 119 public void onCheckedChanged(RadioGroup group, int checkedId) { |
| 124 mSelectedKeyword = (String) group.findViewById(checkedId).getTag(); | 120 mSelectedKeyword = (String) group.findViewById(checkedId).getTag(); |
| 125 updateButtonState(); | 121 updateButtonState(); |
| 126 } | 122 } |
| 127 | 123 |
| 128 @Override | 124 @Override |
| (...skipping 23 matching lines...) Expand all Loading... |
| 152 // TODO(dfalcantara): Prevent the dialog from appearing again. | 148 // TODO(dfalcantara): Prevent the dialog from appearing again. |
| 153 } | 149 } |
| 154 | 150 |
| 155 if (mOnDismissed != null) mOnDismissed.onResult(mSelectedKeyword != null
); | 151 if (mOnDismissed != null) mOnDismissed.onResult(mSelectedKeyword != null
); |
| 156 } | 152 } |
| 157 | 153 |
| 158 private void updateButtonState() { | 154 private void updateButtonState() { |
| 159 findViewById(R.id.button_primary).setEnabled(mSelectedKeyword != null); | 155 findViewById(R.id.button_primary).setEnabled(mSelectedKeyword != null); |
| 160 } | 156 } |
| 161 } | 157 } |
| OLD | NEW |