Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/CardViewHolder.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/CardViewHolder.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/CardViewHolder.java |
index f45eb14d1c7139e11ee8df8297b226937886bb35..a7cb3d7f9754c638cedae15624b37c4a8799af1d 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/CardViewHolder.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/CardViewHolder.java |
@@ -13,6 +13,7 @@ |
import android.view.animation.Interpolator; |
import org.chromium.chrome.R; |
+import org.chromium.chrome.browser.ntp.UiConfig; |
import org.chromium.chrome.browser.util.MathUtils; |
/** |
@@ -27,6 +28,9 @@ |
* {@link NewTabPageRecyclerView#showCardsFrom(int)}). Tap events in non-peeking state will be |
* routed through {@link #onCardTapped()} for subclasses to override. |
* |
+ * - Cards will get some lateral margins when the viewport is sufficiently wide. |
+ * (see {@link UiConfig#DISPLAY_STYLE_WIDE}) |
+ * |
* Note: If a subclass overrides {@link #onBindViewHolder(NewTabPageListItem)}, it should call the |
* parent implementation to reset the private state when a card is recycled. |
*/ |
@@ -45,6 +49,10 @@ |
private final NewTabPageRecyclerView mRecyclerView; |
+ private final UiConfig mUiConfig; |
+ private final int mWideMarginSizePixels; |
+ private final DisplayStyleObserverAdapter mDisplayStyleObserverAdapter; |
+ |
/** |
* Current padding value. The padding and the margins are manipulated together to create the |
* shrunk/peeking appearance of the cards. When the padding is low, the margins are high and |
@@ -57,9 +65,13 @@ |
/** |
* @param layoutId resource id of the layout to inflate and to use as card. |
* @param recyclerView ViewGroup that will contain the newly created view. |
+ * @param uiConfig The NTP UI configuration object used to adjust the card UI. |
*/ |
- public CardViewHolder(int layoutId, final NewTabPageRecyclerView recyclerView) { |
+ public CardViewHolder( |
+ int layoutId, final NewTabPageRecyclerView recyclerView, UiConfig uiConfig) { |
super(inflateView(layoutId, recyclerView)); |
+ mWideMarginSizePixels = itemView.getResources().getDimensionPixelSize( |
+ R.dimen.ntp_wide_card_lateral_margins); |
mCards9PatchAdjustment = recyclerView.getResources().getDimensionPixelSize( |
R.dimen.snippets_card_9_patch_adjustment); |
@@ -81,6 +93,9 @@ public void onClick(View v) { |
} |
} |
}); |
+ |
+ mUiConfig = uiConfig; |
+ mDisplayStyleObserverAdapter = MarginResizer.createWithViewAdapter(itemView, mUiConfig); |
} |
/** |
@@ -164,13 +179,23 @@ private void setPeekingStateForPadding(int padding) { |
// Modify the padding so as the margin increases, the padding decreases, keeping the card's |
// contents in the same position. The top and bottom remain the same. |
- itemView.setPadding(mPeekPadding, mMaxPeekPadding, mPeekPadding, mMaxPeekPadding); |
+ int lateralPadding; |
+ int lateralMargin; |
+ if (mDisplayStyleObserverAdapter.getDisplayStyle() != UiConfig.DISPLAY_STYLE_WIDE) { |
+ lateralPadding = mPeekPadding; |
+ lateralMargin = mMaxPeekPadding - (mPeekPadding + mCards9PatchAdjustment); |
+ } else { |
+ lateralPadding = mMaxPeekPadding; |
+ lateralMargin = mWideMarginSizePixels; |
+ } |
+ |
+ itemView.setPadding(lateralPadding, mMaxPeekPadding, lateralPadding, mMaxPeekPadding); |
// This mCards9PatchAdjustment value will be used to adjust the padding so the card width |
// is the actual width not including the elevation shadow so we can have full bleed. |
RecyclerView.LayoutParams params = getParams(); |
- params.leftMargin = mMaxPeekPadding - (mPeekPadding + mCards9PatchAdjustment); |
- params.rightMargin = mMaxPeekPadding - (mPeekPadding + mCards9PatchAdjustment); |
+ params.leftMargin = lateralMargin; |
+ params.rightMargin = lateralMargin; |
// Set the opacity of the card content to be 0 when peeking and 1 when full width. |
int itemViewChildCount = ((ViewGroup) itemView).getChildCount(); |