Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/MarginResizer.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/MarginResizer.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/MarginResizer.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f8c827155d492cd4a2abf1ad70e606adc3d083a8 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/MarginResizer.java |
| @@ -0,0 +1,40 @@ |
| +// Copyright 2016 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.ntp.cards; |
| + |
| +import android.view.View; |
| +import android.view.ViewGroup.MarginLayoutParams; |
| + |
| +import org.chromium.chrome.browser.ntp.DisplayStyleObserver; |
| +import org.chromium.chrome.browser.ntp.UiConfig; |
| + |
| +/** |
| + * Adds lateral margins to the view when the display style is {@link UiConfig#DISPLAY_STYLE_WIDE}. |
| + */ |
| +public class MarginResizer implements DisplayStyleObserver { |
| + private final int mWideMarginSizePixels; |
| + private final View mView; |
| + |
| + public static void createWithViewAdapter(View view, UiConfig config) { |
| + new DisplayStyleObserverAdapter(view, config, new MarginResizer(view)); |
| + } |
| + |
| + public MarginResizer(View view) { |
| + mView = view; |
| + mWideMarginSizePixels = view.getResources().getDimensionPixelSize( |
| + org.chromium.chrome.R.dimen.ntp_wide_card_lateral_margins); |
|
Bernhard Bauer
2016/07/20 08:56:24
You can't import R?
dgn
2016/07/20 11:38:39
Ah I didn't notice it. Still need to get used to s
|
| + } |
| + |
| + @Override |
| + public void onDisplayStyleChanged(@UiConfig.DisplayStyle int newDisplayStyle) { |
| + MarginLayoutParams layoutParams = (MarginLayoutParams) mView.getLayoutParams(); |
| + if (newDisplayStyle == UiConfig.DISPLAY_STYLE_WIDE) { |
| + layoutParams.setMargins(mWideMarginSizePixels, layoutParams.topMargin, |
| + mWideMarginSizePixels, layoutParams.bottomMargin); |
| + } else { |
| + layoutParams.setMargins(0, layoutParams.topMargin, 0, layoutParams.bottomMargin); |
| + } |
| + } |
| +} |