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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/preferences/datareduction/DataReductionPromoView.java

Issue 1343433002: Add landscape specs for Data Reduction Proxy promo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase and add dynamic maxHeight Created 5 years, 3 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/preferences/datareduction/DataReductionPromoView.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/datareduction/DataReductionPromoView.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/datareduction/DataReductionPromoView.java
new file mode 100644
index 0000000000000000000000000000000000000000..093d455337a6f16615c5da3337a7b5006391d7b2
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/datareduction/DataReductionPromoView.java
@@ -0,0 +1,74 @@
+// 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.preferences.datareduction;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.View.MeasureSpec;
+import android.widget.LinearLayout;
+
+import org.chromium.base.ApiCompatibilityUtils;
+import org.chromium.chrome.R;
+import org.chromium.chrome.browser.widget.PaddedFrameLayout;
+
+/**
+ * View that handles orientation changes for the Data Reduction Proxy promo. When the width is
+ * greater than the height, switches the promo content view from vertical to horizontal and moves
+ * the illustration from the top of the text to the side of the text.
+ */
+public class DataReductionPromoView extends PaddedFrameLayout {
+
+ private static final int ILLUSTRATION_HORIZONTAL_PADDING_DP = 24;
+ private static final int FRAME_HEIGHT_MARGIN_DP = 30;
+
+ private View mIllustration;
+ private LinearLayout mPromoContent;
+ private int mMaxChildWidth;
+ private int mMaxChildWidthHorizontal;
+ private int mIllustrationPaddingBottom;
+ private int mIllustrationPaddingSide;
+ private int mFrameHeightMargin;
+
+ public DataReductionPromoView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mMaxChildWidth = getResources()
+ .getDimensionPixelSize(R.dimen.data_reduction_promo_screen_width);
+ mMaxChildWidthHorizontal = getResources()
+ .getDimensionPixelSize(R.dimen.data_reduction_promo_screen_width_horizontal);
+ mIllustrationPaddingBottom = getResources()
+ .getDimensionPixelSize(R.dimen.data_reduction_promo_illustration_margin_bottom);
+ float density = getResources().getDisplayMetrics().density;
+ mIllustrationPaddingSide = (int) (ILLUSTRATION_HORIZONTAL_PADDING_DP * density + 0.5f);
+ mFrameHeightMargin = (int) (FRAME_HEIGHT_MARGIN_DP * density + 0.5f);
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ super.onFinishInflate();
+ mIllustration = findViewById(R.id.data_reduction_illustration);
+ mPromoContent = (LinearLayout) findViewById(R.id.data_reduction_promo_content);
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ int width = MeasureSpec.getSize(widthMeasureSpec);
+ int height = MeasureSpec.getSize(heightMeasureSpec);
+
+ if (width >= 2 * mIllustration.getWidth() && width > height) {
+ mPromoContent.setOrientation(LinearLayout.HORIZONTAL);
+ setMaxChildWidth(mMaxChildWidthHorizontal);
+ ApiCompatibilityUtils.setPaddingRelative(
+ mIllustration, 0, 0, mIllustrationPaddingSide, 0);
+ } else {
+ mPromoContent.setOrientation(LinearLayout.VERTICAL);
+ setMaxChildWidth(mMaxChildWidth);
+ mIllustration.setPadding(0, 0, 0, mIllustrationPaddingBottom);
+ }
+
+ setMaxChildHeight(height - mFrameHeightMargin);
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698