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

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

Issue 1411853007: Begin adding class for laying out InfoBar controls (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments Created 5 years, 1 month 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
new file mode 100644
index 0000000000000000000000000000000000000000..f90defeee4848c3029136addeaa935ba3b375e91
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/InfoBarControlLayout.java
@@ -0,0 +1,66 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.infobar;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.widget.FrameLayout;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.Switch;
+import android.widget.TextView;
+
+import org.chromium.chrome.R;
+
+/**
+ * Lays out controls for InfoBars that require more than the standard pair of OK/CANCEL buttons.
+ *
+ * This class works with the {@link InfoBarLayout} to define a standard set of controls with
+ * standardized spacings and text styling that gets laid out in grid form: https://crbug.com/543205
+ *
+ * TODO(dfalcantara): Implement the measurement and layout algorithms.
+ */
+public class InfoBarControlLayout extends FrameLayout {
+
+ public InfoBarControlLayout(Context context) {
+ super(context);
+ }
+
+ /**
+ * Adds a toggle switch to the layout.
+ *
+ * -------------------------------------------------
+ * | ICON | MESSAGE | TOGGLE |
+ * -------------------------------------------------
+ * 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.
+ * @param toggleMessage Message to display for the toggle.
+ * @param toggleId ID to use for the toggle.
+ * @param isChecked Whether the toggle should start off checked.
+ */
+ public LinearLayout addSwitch(
+ int iconResourceId, CharSequence toggleMessage, int toggleId, boolean isChecked) {
+ LinearLayout switchLayout = (LinearLayout) LayoutInflater.from(getContext()).inflate(
+ R.layout.infobar_control_toggle, this, false);
+ addView(switchLayout);
+
+ ImageView iconView = (ImageView) switchLayout.findViewById(R.id.control_toggle_icon);
+ if (iconResourceId == 0) {
+ removeView(iconView);
newt (away) 2015/11/05 22:23:14 or switchLayout.removeView()
+ } else {
+ iconView.setImageResource(iconResourceId);
+ }
+
+ TextView messageView = (TextView) switchLayout.findViewById(R.id.control_toggle_message);
+ messageView.setText(toggleMessage);
+
+ Switch switchView = (Switch) switchLayout.findViewById(R.id.control_toggle_switch);
+ switchView.setId(toggleId);
+ switchView.setChecked(isChecked);
+
+ return switchLayout;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698