| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.ntp; | 5 package org.chromium.chrome.browser.ntp; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.res.Resources; | 9 import android.content.res.Resources; |
| 10 import android.graphics.Bitmap; | 10 import android.graphics.Bitmap; |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 @Override | 390 @Override |
| 391 public void onScrollStateChanged(RecyclerView recyclerView, int
newState) { | 391 public void onScrollStateChanged(RecyclerView recyclerView, int
newState) { |
| 392 if (newState != RecyclerView.SCROLL_STATE_DRAGGING) return; | 392 if (newState != RecyclerView.SCROLL_STATE_DRAGGING) return; |
| 393 RecordUserAction.record("MobileNTP.Snippets.Scrolled"); | 393 RecordUserAction.record("MobileNTP.Snippets.Scrolled"); |
| 394 if (mScrolledOnce) return; | 394 if (mScrolledOnce) return; |
| 395 mScrolledOnce = true; | 395 mScrolledOnce = true; |
| 396 NewTabPageUma.recordSnippetAction(NewTabPageUma.SNIPPETS_ACT
ION_SCROLLED); | 396 NewTabPageUma.recordSnippetAction(NewTabPageUma.SNIPPETS_ACT
ION_SCROLLED); |
| 397 } | 397 } |
| 398 }); | 398 }); |
| 399 initializeSearchBoxRecyclerViewScrollHandling(); | 399 initializeSearchBoxRecyclerViewScrollHandling(); |
| 400 mRecyclerView.updateSnippetsHeaderDisplay(mNewTabPageLayout.getPaddi
ngTop()); | |
| 401 } else { | 400 } else { |
| 402 initializeSearchBoxScrollHandling(); | 401 initializeSearchBoxScrollHandling(); |
| 403 } | 402 } |
| 404 } | 403 } |
| 405 | 404 |
| 406 private void updateSearchBoxOnScroll() { | 405 private void updateSearchBoxOnScroll() { |
| 407 if (mDisableUrlFocusChangeAnimations) return; | 406 if (mDisableUrlFocusChangeAnimations) return; |
| 408 | 407 |
| 409 float toolbarTransitionPercentage; | 408 float toolbarTransitionPercentage; |
| 410 // During startup the view may not be fully initialized, so we only calc
ulate the current | 409 // During startup the view may not be fully initialized, so we only calc
ulate the current |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 | 475 |
| 477 mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { | 476 mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { |
| 478 @Override | 477 @Override |
| 479 public void onScrolled(RecyclerView recyclerView, int dx, int dy) { | 478 public void onScrolled(RecyclerView recyclerView, int dx, int dy) { |
| 480 if (mPendingSnapScroll) { | 479 if (mPendingSnapScroll) { |
| 481 mRecyclerView.removeCallbacks(mSnapScrollRunnable); | 480 mRecyclerView.removeCallbacks(mSnapScrollRunnable); |
| 482 mRecyclerView.postDelayed(mSnapScrollRunnable, SNAP_SCROLL_D
ELAY_MS); | 481 mRecyclerView.postDelayed(mSnapScrollRunnable, SNAP_SCROLL_D
ELAY_MS); |
| 483 } | 482 } |
| 484 updateSearchBoxOnScroll(); | 483 updateSearchBoxOnScroll(); |
| 485 mRecyclerView.updatePeekingCard(); | 484 mRecyclerView.updatePeekingCard(); |
| 486 mRecyclerView.updateSnippetsHeaderDisplay(mNewTabPageLayout.getP
addingTop()); | 485 mRecyclerView.updateSnippetsHeaderDisplay(); |
| 487 } | 486 } |
| 488 }); | 487 }); |
| 489 | 488 |
| 490 mRecyclerView.setOnTouchListener(new OnTouchListener() { | 489 mRecyclerView.setOnTouchListener(new OnTouchListener() { |
| 491 @Override | 490 @Override |
| 492 @SuppressLint("ClickableViewAccessibility") | 491 @SuppressLint("ClickableViewAccessibility") |
| 493 public boolean onTouch(View v, MotionEvent event) { | 492 public boolean onTouch(View v, MotionEvent event) { |
| 494 mRecyclerView.removeCallbacks(mSnapScrollRunnable); | 493 mRecyclerView.removeCallbacks(mSnapScrollRunnable); |
| 495 | 494 |
| 496 if (event.getActionMasked() == MotionEvent.ACTION_CANCEL | 495 if (event.getActionMasked() == MotionEvent.ACTION_CANCEL |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 int newWidth = right - left; | 811 int newWidth = right - left; |
| 813 if (oldWidth == newWidth) return; | 812 if (oldWidth == newWidth) return; |
| 814 | 813 |
| 815 // Re-apply the url focus change amount after a rotation to ensure the v
iews are correctly | 814 // Re-apply the url focus change amount after a rotation to ensure the v
iews are correctly |
| 816 // placed with their new layout configurations. | 815 // placed with their new layout configurations. |
| 817 onUrlFocusAnimationChanged(); | 816 onUrlFocusAnimationChanged(); |
| 818 updateSearchBoxOnScroll(); | 817 updateSearchBoxOnScroll(); |
| 819 | 818 |
| 820 if (mUseCardsUi) { | 819 if (mUseCardsUi) { |
| 821 mRecyclerView.updatePeekingCard(); | 820 mRecyclerView.updatePeekingCard(); |
| 821 mRecyclerView.updateSnippetsHeaderDisplay(); |
| 822 // The positioning of elements may have been changed (since the elem
ents expand to fill | 822 // The positioning of elements may have been changed (since the elem
ents expand to fill |
| 823 // the available vertical space), so adjust the scroll. | 823 // the available vertical space), so adjust the scroll. |
| 824 mRecyclerView.snapScroll(mSearchBoxView, getVerticalScroll(), getHei
ght()); | 824 mRecyclerView.snapScroll(mSearchBoxView, getVerticalScroll(), getHei
ght()); |
| 825 } | 825 } |
| 826 } | 826 } |
| 827 | 827 |
| 828 // MostVisitedURLsObserver implementation | 828 // MostVisitedURLsObserver implementation |
| 829 | 829 |
| 830 @Override | 830 @Override |
| 831 public void onMostVisitedURLsAvailable( | 831 public void onMostVisitedURLsAvailable( |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 | 1080 |
| 1081 @Override | 1081 @Override |
| 1082 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | 1082 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 1083 if (mNewTabPageLayout != null) { | 1083 if (mNewTabPageLayout != null) { |
| 1084 mNewTabPageLayout.setParentViewportHeight(MeasureSpec.getSize(height
MeasureSpec)); | 1084 mNewTabPageLayout.setParentViewportHeight(MeasureSpec.getSize(height
MeasureSpec)); |
| 1085 } | 1085 } |
| 1086 super.onMeasure(widthMeasureSpec, heightMeasureSpec); | 1086 super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 1087 | 1087 |
| 1088 if (mUseCardsUi) { | 1088 if (mUseCardsUi) { |
| 1089 mRecyclerView.updatePeekingCard(); | 1089 mRecyclerView.updatePeekingCard(); |
| 1090 mRecyclerView.updateSnippetsHeaderDisplay(); |
| 1090 } | 1091 } |
| 1091 } | 1092 } |
| 1092 | 1093 |
| 1093 private int getVerticalScroll() { | 1094 private int getVerticalScroll() { |
| 1094 if (mUseCardsUi) { | 1095 if (mUseCardsUi) { |
| 1095 return mRecyclerView.computeVerticalScrollOffset(); | 1096 return mRecyclerView.computeVerticalScrollOffset(); |
| 1096 } else { | 1097 } else { |
| 1097 return mScrollView.getScrollY(); | 1098 return mScrollView.getScrollY(); |
| 1098 } | 1099 } |
| 1099 } | 1100 } |
| 1100 } | 1101 } |
| OLD | NEW |