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

Unified Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/widget/BoundedLinearLayout.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java_staging/src/org/chromium/chrome/browser/widget/BoundedLinearLayout.java
diff --git a/chrome/android/java_staging/src/org/chromium/chrome/browser/widget/BoundedLinearLayout.java b/chrome/android/java_staging/src/org/chromium/chrome/browser/widget/BoundedLinearLayout.java
new file mode 100644
index 0000000000000000000000000000000000000000..004f304a17420cdd0dc0c4682ffa394b05466498
--- /dev/null
+++ b/chrome/android/java_staging/src/org/chromium/chrome/browser/widget/BoundedLinearLayout.java
@@ -0,0 +1,53 @@
+// 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.widget;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.util.AttributeSet;
+import android.widget.LinearLayout;
+
+import com.google.android.apps.chrome.R;
+
+/**
+ * A LinearLayout that can be constrained to a maximum width.
+ *
+ * Example:
+ * <org.chromium.chrome.browser.widget.BoundedLinearLayout
+ * xmlns:android="http://schemas.android.com/apk/res/android"
+ * xmlns:chrome="http://schemas.android.com/apk/res-auto"
+ * android:layout_width="match_parent"
+ * android:layout_height="match_parent"
+ * chrome:maxWidth="692dp" >
+ * ...
+ */
+public class BoundedLinearLayout extends LinearLayout {
+
+ private static final int NO_MAX_WIDTH = -1;
+
+ private final int mMaxWidth;
+
+ /**
+ * Constructor for inflating from XML.
+ */
+ public BoundedLinearLayout(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BoundedView);
+ mMaxWidth = a.getDimensionPixelSize(R.styleable.BoundedView_maxWidth, NO_MAX_WIDTH);
+ a.recycle();
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ // Limit width to mMaxWidth.
+ int widthSize = MeasureSpec.getSize(widthMeasureSpec);
+ if (mMaxWidth != NO_MAX_WIDTH && widthSize > mMaxWidth) {
+ int widthMode = MeasureSpec.getMode(widthMeasureSpec);
+ if (widthMode == MeasureSpec.UNSPECIFIED) widthMode = MeasureSpec.AT_MOST;
+ widthMeasureSpec = MeasureSpec.makeMeasureSpec(mMaxWidth, widthMode);
+ }
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698