Chromium Code Reviews| 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..d0a0b7f074b825ba808ad1ca9743f2a3f6af156f |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/datareduction/DataReductionPromoView.java |
| @@ -0,0 +1,71 @@ |
| +// 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.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 HORIZONTAL_PADDING_DP = 24; |
| + |
| + private View mDataReductionIllustration; |
|
newt (away)
2015/09/15 23:08:43
suggestion: Since these private variables inside a
megjablon
2015/09/16 19:02:48
Done.
|
| + private LinearLayout mDataReductionPromoContent; |
| + private int mMaxChildHeight; |
| + private int mMaxChildWidth; |
| + private int mMaxChildHeightHorizontal; |
| + private int mMaxChildWidthHorizontal; |
| + private int mPaddingBottom; |
| + private float mScale; |
|
newt (away)
2015/09/15 23:08:43
Save mPaddingSide as a member variable instead of
megjablon
2015/09/16 19:02:48
Done.
|
| + |
| + public DataReductionPromoView(Context context, AttributeSet attrs) { |
| + super(context, attrs); |
| + mDataReductionIllustration = findViewById(R.id.data_reduction_illustration); |
| + mDataReductionPromoContent = (LinearLayout) findViewById(R.id.data_reduction_promo_content); |
| + mMaxChildHeight = (int) getResources() |
| + .getDimension(R.dimen.data_reduction_promo_screen_height); |
|
newt (away)
2015/09/15 23:08:43
use getDimensionPixelSize(), which returns an int
megjablon
2015/09/16 19:02:48
Done.
|
| + mMaxChildWidth = (int) getResources() |
| + .getDimension(R.dimen.data_reduction_promo_screen_width); |
| + mMaxChildHeightHorizontal = (int) getResources() |
| + .getDimension(R.dimen.data_reduction_promo_screen_height_horizontal); |
| + mMaxChildWidthHorizontal = (int) getResources() |
| + .getDimension(R.dimen.data_reduction_promo_screen_width_horizontal); |
| + mPaddingBottom = (int) getResources() |
| + .getDimension(R.dimen.data_reduction_promo_illustration_margin_bottom); |
| + mScale = getResources().getDisplayMetrics().density; |
| + } |
| + |
| + @Override |
| + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| + int width = MeasureSpec.getSize(widthMeasureSpec); |
| + int height = MeasureSpec.getSize(heightMeasureSpec); |
| + |
| + if (width >= 2 * mDataReductionIllustration.getWidth() && width > height) { |
| + mDataReductionPromoContent.setOrientation(LinearLayout.HORIZONTAL); |
| + setMaxChildHeight(mMaxChildHeightHorizontal); |
| + setMaxChildWidth(mMaxChildWidthHorizontal); |
| + int paddingInPixels = (int) (HORIZONTAL_PADDING_DP * mScale + 0.5f); |
|
newt (away)
2015/09/15 23:08:43
Customarily, all dimension variables are in pixels
megjablon
2015/09/16 19:02:48
Done.
|
| + ApiCompatibilityUtils.setPaddingRelative( |
| + mDataReductionIllustration, 0, 0, paddingInPixels, 0); |
| + } else { |
| + mDataReductionPromoContent.setOrientation(LinearLayout.VERTICAL); |
| + setMaxChildHeight(mMaxChildHeight); |
| + setMaxChildWidth(mMaxChildWidth); |
| + mDataReductionIllustration.setPadding(0, 0, 0, mPaddingBottom); |
| + } |
| + super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| + } |
| +} |