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

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

Issue 1411853007: Begin adding class for laying out InfoBar controls (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/InfoBarSubLayout.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/InfoBarSubLayout.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/InfoBarSubLayout.java
new file mode 100644
index 0000000000000000000000000000000000000000..1b4e3dc29f1961ad72f49ecbc6d633a011e24c7f
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/InfoBarSubLayout.java
@@ -0,0 +1,64 @@
+// 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.view.View;
+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 InfoBarSubLayout extends FrameLayout {
+
+ public InfoBarSubLayout(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 -1 to hide the ImageView.
+ * @param toggleMessage Message to display for the toggle.
+ * @param isChecked Whether the toggle should start off checked.
+ */
+ public LinearLayout addSwitch(
+ int iconResourceId, CharSequence toggleMessage, boolean isChecked) {
+ LinearLayout switchLayout = (LinearLayout) LayoutInflater.from(getContext()).inflate(
+ R.layout.infobar_subcontrol_toggle, this, false);
+ addView(switchLayout);
+
+ ImageView iconView = (ImageView) switchLayout.findViewById(R.id.subcontrol_toggle_icon);
+ if (iconResourceId != -1) {
newt (away) 2015/11/05 05:52:16 Android uses 0 and null to signify "no resource".
gone 2015/11/05 20:42:03 Done.
+ iconView.setVisibility(View.VISIBLE);
+ iconView.setImageResource(iconResourceId);
+ }
+
+ TextView messageView = (TextView) switchLayout.findViewById(R.id.subcontrol_toggle_message);
+ messageView.setText(toggleMessage);
+
+ Switch switchView = (Switch) switchLayout.findViewById(R.id.subcontrol_toggle_switch);
+ switchView.setChecked(isChecked);
+
+ return switchLayout;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698