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

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

Issue 1543913002: Add support for images with descriptions to infobars (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased, ready to review Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/infobar/InfoBarControlLayout.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/InfoBarControlLayout.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/InfoBarControlLayout.java
index 7bb2d2dec166408d794b1769090e5bc8a1cae03c..266fadbf125bc6bb6edb5d198e07587d9bee1efb 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/infobar/InfoBarControlLayout.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/InfoBarControlLayout.java
@@ -36,6 +36,9 @@ import org.chromium.chrome.R;
* layout algorithm to match.
*
* TODO(dfalcantara): Standardize all the possible control types.
+ * TODO(dfalcantara): The line spacing multiplier is applied to all lines in JB & KK, even if the
+ * TextView has only one line. This throws off vertical alignment. Find a
+ * solution that hopefully doesn't involve subclassing the TextView.
*/
public final class InfoBarControlLayout extends ViewGroup {
@@ -185,6 +188,47 @@ public final class InfoBarControlLayout extends ViewGroup {
}
/**
+ * Adds an icon with a descriptive message to the layout.
+ *
+ * -----------------------------------------------------
+ * | ICON | PRIMARY MESSAGE SECONDARY MESSAGE |
+ * -----------------------------------------------------
+ * If an icon is not provided, the ImageView that would normally show it is hidden.
+ *
+ * @param iconResourceId ID of the drawable to use for the icon, or 0 to hide the ImageView.
newt (away) 2016/01/05 21:20:53 Do we need to allow 0 here? I'd prefer not to, unl
gone 2016/01/05 21:43:54 Nope, carryover from a rebase. Nuked it.
+ * @param primaryMessage Message to display for the toggle.
+ * @param secondaryMessage Additional descriptive text for the toggle. May be null.
+ */
+ public View addIcon(
+ int iconResourceId, CharSequence primaryMessage, CharSequence secondaryMessage) {
+ LinearLayout layout = (LinearLayout) LayoutInflater.from(getContext()).inflate(
+ R.layout.infobar_control_icon_with_description, this, false);
+ addView(layout, new ControlLayoutParams());
+
+ ImageView iconView = (ImageView) layout.findViewById(R.id.control_icon);
+ if (iconResourceId == 0) {
+ layout.removeView(iconView);
+ } else {
+ iconView.setImageResource(iconResourceId);
+ }
+
+ // The primary message text is always displayed.
+ TextView primaryView = (TextView) layout.findViewById(R.id.control_message);
+ primaryView.setText(primaryMessage);
+
+ // The secondary message text is optional.
+ TextView secondaryView =
+ (TextView) layout.findViewById(R.id.control_secondary_message);
+ if (secondaryMessage == null) {
+ layout.removeView(secondaryView);
+ } else {
+ secondaryView.setText(secondaryMessage);
+ }
+
+ return layout;
+ }
+
+ /**
* Creates a standard toggle switch and adds it to the layout.
*
* -------------------------------------------------
@@ -203,14 +247,14 @@ public final class InfoBarControlLayout extends ViewGroup {
R.layout.infobar_control_toggle, this, false);
addView(switchLayout, new ControlLayoutParams());
- ImageView iconView = (ImageView) switchLayout.findViewById(R.id.control_toggle_icon);
+ ImageView iconView = (ImageView) switchLayout.findViewById(R.id.control_icon);
if (iconResourceId == 0) {
switchLayout.removeView(iconView);
} else {
iconView.setImageResource(iconResourceId);
}
- TextView messageView = (TextView) switchLayout.findViewById(R.id.control_toggle_message);
+ TextView messageView = (TextView) switchLayout.findViewById(R.id.control_message);
messageView.setText(toggleMessage);
SwitchCompat switchView =

Powered by Google App Engine
This is Rietveld 408576698