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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetHeaderViewHolder.java

Issue 2120283003: NTP, modify the snippet header display to above the peeking card (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes 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
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetHeaderViewHolder.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetHeaderViewHolder.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetHeaderViewHolder.java
index 919a1d243b767a962b0c94c84f5dcf9ff5385120..28ec164bb7f56cc8b4abbc45f595964659421568 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetHeaderViewHolder.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetHeaderViewHolder.java
@@ -4,9 +4,6 @@
package org.chromium.chrome.browser.ntp.snippets;
-import android.animation.Animator;
-import android.animation.AnimatorListenerAdapter;
-import android.animation.ObjectAnimator;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
@@ -14,90 +11,64 @@ import android.view.ViewGroup;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ntp.cards.NewTabPageListItem;
+import org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView;
import org.chromium.chrome.browser.ntp.cards.NewTabPageViewHolder;
+import org.chromium.chrome.browser.util.MathUtils;
/**
* A class that represents the view for a single card snippet.
*/
public class SnippetHeaderViewHolder extends NewTabPageViewHolder {
- private static final int ANIMATION_DURATION_MS = 300;
+ private static final double SCROLL_HEADER_HEIGHT_PERCENTAGE = 0.7;
private final int mMaxSnippetHeaderHeight;
+ private final int mMaxPeekPadding;
+ private final NewTabPageRecyclerView mRecyclerView;
+
private SnippetHeaderListItem mHeader;
- private Animator mAnimator;
public static View createView(ViewGroup parent) {
return LayoutInflater.from(parent.getContext())
.inflate(R.layout.new_tab_page_snippets_card, parent, false);
}
- public SnippetHeaderViewHolder(final View cardView) {
+ public SnippetHeaderViewHolder(final View cardView, final NewTabPageRecyclerView recyclerView) {
super(cardView);
mMaxSnippetHeaderHeight = cardView.getResources().getDimensionPixelSize(
R.dimen.snippets_article_header_height);
+
+ mMaxPeekPadding = cardView.getResources().getDimensionPixelSize(
+ R.dimen.snippets_padding_and_peeking_card_height);
+
+ mRecyclerView = recyclerView;
}
@Override
public void onBindViewHolder(NewTabPageListItem header) {
mHeader = (SnippetHeaderListItem) header;
- animateFade();
+ updateDisplay();
}
/**
- * Update the view for the scroll-triggered fade in/out animation.
- * @param omniBoxHeight The height of the omnibox displayed over the NTP, we use this to offset
- * the start point of the transition.
+ * Update the view for the fade in/out and heading height.
*/
- public void onScrolled(int omniBoxHeight) {
+ public void updateDisplay() {
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) itemView.getLayoutParams();
int headerHeight = 0;
-
- // Measurement used to multiply the max snippet height to get a range on when to start
- // modifying the display of article header.
- final int numberHeaderHeight = 2;
- // Used to indicate when to start modifying the snippet header.
- int heightToStartChangingHeader = mMaxSnippetHeaderHeight * numberHeaderHeight;
int snippetHeaderTop = itemView.getTop();
-
- // Check if snippet header top is within range to start showing the snippet header.
- if (snippetHeaderTop < omniBoxHeight + heightToStartChangingHeader) {
- // The amount of space the article header has scrolled into the
- // |heightToStartChangingHeader|.
- int amountScrolledIntoHeaderSpace =
- heightToStartChangingHeader - (snippetHeaderTop - omniBoxHeight);
-
- // Remove the |numberHeaderHeight| to get the actual header height we want to
- // display. Never let the height be more than the |maxSnippetHeaderHeight|.
- headerHeight = Math.min(
- amountScrolledIntoHeaderSpace / numberHeaderHeight, mMaxSnippetHeaderHeight);
-
+ int recyclerViewHeight = mRecyclerView.getHeight();
+
+ // Check if snippet header top is within range to start showing. Set the header height, this
+ // is a percentage of how much is scrolled. The balance of the scroll will
+ // be used to display the peeking card.
+ int amountScrolled = (recyclerViewHeight - mMaxPeekPadding) - snippetHeaderTop;
+ if (mHeader.isVisible()) {
+ headerHeight = MathUtils.clamp((int) (amountScrolled * SCROLL_HEADER_HEIGHT_PERCENTAGE),
+ 0, mMaxSnippetHeaderHeight);
}
- if (mHeader.isVisible()) itemView.setAlpha((float) headerHeight / mMaxSnippetHeaderHeight);
+ itemView.setAlpha((float) headerHeight / mMaxSnippetHeaderHeight);
params.height = headerHeight;
- itemView.setLayoutParams(params);
- }
-
- /**
- * Make the header fade in or out depending on the model's state.
- * @see SnippetHeaderListItem#isVisible()
- */
- private void animateFade() {
- if (mAnimator != null) mAnimator.cancel();
-
- float currentAlpha = itemView.getAlpha();
- float targetAlpha = mHeader.isVisible() ? 1f : 0f;
-
- if (currentAlpha == targetAlpha) return;
-
- mAnimator = ObjectAnimator.ofFloat(itemView, View.ALPHA, currentAlpha, targetAlpha);
- mAnimator.setDuration(ANIMATION_DURATION_MS);
- mAnimator.addListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(Animator animator) {
- mAnimator = null;
- }
- });
- mAnimator.start();
+ itemView.requestLayout();
}
}
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698