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

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

Issue 2088793004: NTP, change the card elevation from setElevation to a 9 patch file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes Created 4 years, 6 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 faa44c8979d9063d6f49fe64eca64bb86e526c1e..c5a2ef4e8e4ba590433cc31f6878ceba029fb3b4 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
@@ -12,7 +12,6 @@ import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.Interpolator;
-import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.util.MathUtils;
@@ -38,6 +37,15 @@ public class CardViewHolder extends NewTabPageViewHolder {
private final int mMaxPeekPadding;
/**
+ * Due to the card background being a 9 patch file - the card border shadow will be part of
+ * the card width and height. This value will be used to adjust values to account for the
+ * borders.
+ */
+ private final int mCards9PatchAdjustment;
+
+ private final NewTabPageRecyclerView mRecyclerView;
+
+ /**
* 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
* the background is visible around the cards. When the padding is maximum
@@ -48,25 +56,26 @@ public class CardViewHolder extends NewTabPageViewHolder {
/**
* @param layoutId resource id of the layout to inflate and to use as card.
- * @param parent ViewGroup that will contain the newly created view.
+ * @param recyclerView ViewGroup that will contain the newly created view.
*/
- public CardViewHolder(int layoutId, final NewTabPageRecyclerView parent) {
- super(inflateView(layoutId, parent));
+ public CardViewHolder(int layoutId, final NewTabPageRecyclerView recyclerView) {
+ super(inflateView(layoutId, recyclerView));
+
+ mCards9PatchAdjustment = recyclerView.getResources().getDimensionPixelSize(
+ R.dimen.snippets_card_9_patch_adjustment);
- mMaxPeekPadding = parent.getResources().getDimensionPixelSize(
+ mMaxPeekPadding = recyclerView.getResources().getDimensionPixelSize(
R.dimen.snippets_padding_and_peeking_card_height);
mPeekPadding = mMaxPeekPadding;
- ApiCompatibilityUtils.setElevation(
- itemView, parent.getContext().getResources().getDimensionPixelSize(
- R.dimen.snippets_card_elevation));
+ mRecyclerView = recyclerView;
itemView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (isPeeking()) {
- parent.showCardsFrom(mPeekPadding);
+ recyclerView.showCardsFrom(mPeekPadding);
} else {
onCardTapped();
}
@@ -89,6 +98,21 @@ public class CardViewHolder extends NewTabPageViewHolder {
itemView.setAlpha(1f);
}
+ @Override
+ public void updateLayoutParams() {
+ RecyclerView.LayoutParams params = getParams();
+
+ // Each card has the full elevation effect so we will remove bottom margin to overlay and
+ // hide the bottom shadow of the previous card to give the effect of a divider instead of a
+ // shadow.
+ if (mRecyclerView.getAdapter().getItemViewType(getAdapterPosition() + 1)
+ == NewTabPageListItem.VIEW_TYPE_SNIPPET) {
+ params.bottomMargin = -mCards9PatchAdjustment;
+ } else {
+ params.bottomMargin = 0;
+ }
+ }
+
/**
* Change the width, padding and child opacity of the card to give a smooth transition as the
* user scrolls.
@@ -122,15 +146,19 @@ public class CardViewHolder extends NewTabPageViewHolder {
protected void onCardTapped() {}
private void setPeekingStateForPadding(int padding) {
+ // TODO(mcwilliams): Change the 'padding' value to a percentage of what the transition
+ // should be which can be used for alpha and bleed.
mPeekPadding = 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);
- RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) itemView.getLayoutParams();
- params.leftMargin = mMaxPeekPadding - mPeekPadding;
- params.rightMargin = mMaxPeekPadding - mPeekPadding;
+ // 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);
// Set the opacity of the card content to be 0 when peeking and 1 when full width.
int itemViewChildCount = ((ViewGroup) itemView).getChildCount();
@@ -143,4 +171,8 @@ public class CardViewHolder extends NewTabPageViewHolder {
private static View inflateView(int resourceId, ViewGroup parent) {
return LayoutInflater.from(parent.getContext()).inflate(resourceId, parent, false);
}
+
+ private RecyclerView.LayoutParams getParams() {
+ return (RecyclerView.LayoutParams) itemView.getLayoutParams();
+ }
}

Powered by Google App Engine
This is Rietveld 408576698