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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/infobar/InfoBarControlLayout.java

Issue 2838833002: 🔍 Introduce default search engine dialog (Closed)
Patch Set: Redo how the dialog is created 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.infobar; 5 package org.chromium.chrome.browser.infobar;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.res.Resources; 8 import android.content.res.Resources;
9 import android.graphics.Paint; 9 import android.graphics.Paint;
10 import android.support.annotation.Nullable;
10 import android.support.v7.widget.SwitchCompat; 11 import android.support.v7.widget.SwitchCompat;
11 import android.text.method.LinkMovementMethod; 12 import android.text.method.LinkMovementMethod;
12 import android.view.LayoutInflater; 13 import android.view.LayoutInflater;
13 import android.view.View; 14 import android.view.View;
14 import android.view.ViewGroup; 15 import android.view.ViewGroup;
15 import android.widget.ArrayAdapter; 16 import android.widget.ArrayAdapter;
16 import android.widget.ImageView; 17 import android.widget.ImageView;
17 import android.widget.LinearLayout; 18 import android.widget.LinearLayout;
18 import android.widget.RadioButton; 19 import android.widget.RadioButton;
19 import android.widget.RadioGroup; 20 import android.widget.RadioGroup;
(...skipping 17 matching lines...) Expand all
37 * 38 *
38 * Manually specified margins on the children managed by this layout are EXPLICI TLY ignored to 39 * Manually specified margins on the children managed by this layout are EXPLICI TLY ignored to
39 * enforce a uniform margin between controls across all InfoBar types. Do NOT c ircumvent this 40 * enforce a uniform margin between controls across all InfoBar types. Do NOT c ircumvent this
40 * restriction with creative layout definitions. If the layout algorithm doesn' t work for your new 41 * restriction with creative layout definitions. If the layout algorithm doesn' t work for your new
41 * InfoBar, convince Chrome for Android's UX team to amend the master spec and t hen change the 42 * InfoBar, convince Chrome for Android's UX team to amend the master spec and t hen change the
42 * layout algorithm to match. 43 * layout algorithm to match.
43 * 44 *
44 * TODO(dfalcantara): The line spacing multiplier is applied to all lines in JB & KK, even if the 45 * TODO(dfalcantara): The line spacing multiplier is applied to all lines in JB & KK, even if the
45 * TextView has only one line. This throws off vertical alig nment. Find a 46 * TextView has only one line. This throws off vertical alig nment. Find a
46 * solution that hopefully doesn't involve subclassing the Te xtView. 47 * solution that hopefully doesn't involve subclassing the Te xtView.
48 *
49 * TODO(dfalcantara): Move this to a more general location.
47 */ 50 */
48 public final class InfoBarControlLayout extends ViewGroup { 51 public final class InfoBarControlLayout extends ViewGroup {
52 public static final int INVALID_INDEX = -1;
53
49 /** 54 /**
50 * ArrayAdapter that automatically determines what size make its Views to ac commodate all of 55 * ArrayAdapter that automatically determines what size make its Views to ac commodate all of
51 * its potential values. 56 * its potential values.
57 * @param <T> Type of object that the ArrayAdapter stores.
52 */ 58 */
53 public static final class InfoBarArrayAdapter<T> extends ArrayAdapter<T> { 59 public static final class InfoBarArrayAdapter<T> extends ArrayAdapter<T> {
54 private final String mLabel; 60 private final String mLabel;
55 private int mMinWidthRequiredForValues; 61 private int mMinWidthRequiredForValues;
56 62
57 public InfoBarArrayAdapter(Context context, String label) { 63 public InfoBarArrayAdapter(Context context, String label) {
58 super(context, R.layout.infobar_control_spinner_drop_down); 64 super(context, R.layout.infobar_control_spinner_drop_down);
59 mLabel = label; 65 mLabel = label;
60 } 66 }
61 67
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 360
355 /** 361 /**
356 * Creates a set of standard radio buttons and adds it to the layout. 362 * Creates a set of standard radio buttons and adds it to the layout.
357 * 363 *
358 * ------------------------------------------------- 364 * -------------------------------------------------
359 * | O | MESSAGE #1 | 365 * | O | MESSAGE #1 |
360 * | O | MESSAGE #N | 366 * | O | MESSAGE #N |
361 * ------------------------------------------------- 367 * -------------------------------------------------
362 * 368 *
363 * @param messages Messages to display for the options. 369 * @param messages Messages to display for the options.
370 * @param tags Optional list of tags to attach to the buttons.
364 * @param selectedIndex Which index to mark as being selected. 371 * @param selectedIndex Which index to mark as being selected.
365 */ 372 */
366 public RadioGroup addRadioButtons(List<CharSequence> messages, int selectedI ndex) { 373 public RadioGroup addRadioButtons(
374 List<CharSequence> messages, @Nullable List<?> tags, int selectedInd ex) {
367 ControlLayoutParams params = new ControlLayoutParams(); 375 ControlLayoutParams params = new ControlLayoutParams();
368 params.mMustBeFullWidth = true; 376 params.mMustBeFullWidth = true;
369 377
370 RadioGroup radioLayout = new RadioGroup(getContext()); 378 RadioGroup radioLayout = new RadioGroup(getContext());
371 addView(radioLayout, params); 379 addView(radioLayout, params);
372 380
Ted C 2017/04/26 20:21:52 maybe add if (tags != null) assert tags.size() ==
gone 2017/04/26 21:45:15 Done on the forked copy.
373 for (int i = 0; i < messages.size(); i++) { 381 for (int i = 0; i < messages.size(); i++) {
374 RadioButton button = 382 RadioButton button =
375 (RadioButton) LayoutInflater.from(getContext()) 383 (RadioButton) LayoutInflater.from(getContext())
376 .inflate(R.layout.infobar_control_radio, radioLayout , false); 384 .inflate(R.layout.infobar_control_radio, radioLayout , false);
377 button.setText(messages.get(i)); 385 button.setText(messages.get(i));
386 if (tags != null) button.setTag(tags.get(i));
378 button.setChecked(i == selectedIndex); 387 button.setChecked(i == selectedIndex);
379 radioLayout.addView(button); 388 radioLayout.addView(button);
380 389
381 // Add margins between each of the radio buttons. 390 // Add margins between each of the radio buttons.
382 if (i < messages.size() - 1) { 391 if (i < messages.size() - 1) {
383 ((MarginLayoutParams) button.getLayoutParams()).bottomMargin = m MarginBetweenRows; 392 ((MarginLayoutParams) button.getLayoutParams()).bottomMargin = m MarginBetweenRows;
384 } 393 }
385 } 394 }
386 395
387 return radioLayout; 396 return radioLayout;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 460
452 /** 461 /**
453 * @return The {@link ControlLayoutParams} for the given child. 462 * @return The {@link ControlLayoutParams} for the given child.
454 */ 463 */
455 @VisibleForTesting 464 @VisibleForTesting
456 static ControlLayoutParams getControlLayoutParams(View child) { 465 static ControlLayoutParams getControlLayoutParams(View child) {
457 return (ControlLayoutParams) child.getLayoutParams(); 466 return (ControlLayoutParams) child.getLayoutParams();
458 } 467 }
459 468
460 } 469 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698