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

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: Comments 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
« no previous file with comments | « chrome/android/java/res/layout/infobar_control_toggle.xml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..03e8d45caacc7d8fa90af3be081689f89ffe155c 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,43 @@ 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.
+ * @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);
+ 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 +243,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 =
« no previous file with comments | « chrome/android/java/res/layout/infobar_control_toggle.xml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698