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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/CardViewHolder.java

Issue 2149333003: 📰 Adjust the card display depending on the screen width. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ZineTabletUI
Patch Set: address comments Created 4 years, 5 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/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 c5a2ef4e8e4ba590433cc31f6878ceba029fb3b4..10d4c946716506abec66c402f4e3396ea8dcc10f 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,9 @@
private final NewTabPageRecyclerView mRecyclerView;
+ private final UiConfig mConfig;
+ private final int mWideMarginSizePixels;
+
/**
* 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 +64,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 config 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 config) {
super(inflateView(layoutId, recyclerView));
+ mWideMarginSizePixels = itemView.getResources().getDimensionPixelSize(
dgn 2016/07/19 23:33:56 I could also pull the value from MarginResizer ins
+ R.dimen.ntp_wide_card_lateral_margins);
mCards9PatchAdjustment = recyclerView.getResources().getDimensionPixelSize(
R.dimen.snippets_card_9_patch_adjustment);
@@ -81,6 +92,9 @@ public void onClick(View v) {
}
}
});
+
+ mConfig = config;
+ MarginResizer.createWithViewAdapter(itemView, mConfig);
}
/**
@@ -152,13 +166,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 (mConfig.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();

Powered by Google App Engine
This is Rietveld 408576698