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