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

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

Issue 2144413003: NTP, peeking card and heading hiding constraints (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 28ec164bb7f56cc8b4abbc45f595964659421568..d9a0b0237819075112fb9b9dac949d0bcea1bf0c 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
@@ -50,22 +50,40 @@ public class SnippetHeaderViewHolder extends NewTabPageViewHolder {
}
/**
+ * Is the header in a state where the height can vary from show to hidden.
+ * @return Whether the header can transition.
+ */
+ private boolean canTransition() {
+ // Only allow the header to transition if the user has not scrolled on the page beyond the
+ // |mMaxPeekPadding + mMaxSnippetHeaderHeight|.
+ return mRecyclerView.computeVerticalScrollOffset()
+ <= mMaxSnippetHeaderHeight + mMaxPeekPadding;
+ }
+
+ /**
+ * @return The header height we want to set.
+ */
+ private int getHeaderHeight() {
+ if (!mHeader.isVisible()) return 0;
+
+ // If the header cannot transition but is visible - set the height to the maximum so
+ // it always displays
+ if (!canTransition()) return mMaxSnippetHeaderHeight;
+
+ // 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 = (mRecyclerView.getHeight() - mMaxPeekPadding) - itemView.getTop();
+ return MathUtils.clamp((int) (amountScrolled * SCROLL_HEADER_HEIGHT_PERCENTAGE),
+ 0, mMaxSnippetHeaderHeight);
+ }
+
+ /**
* Update the view for the fade in/out and heading height.
*/
public void updateDisplay() {
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) itemView.getLayoutParams();
- int headerHeight = 0;
- int snippetHeaderTop = itemView.getTop();
- 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);
- }
+ int headerHeight = getHeaderHeight();
itemView.setAlpha((float) headerHeight / mMaxSnippetHeaderHeight);
params.height = headerHeight;
« 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