| 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.Configuration; | 9 import android.content.res.Configuration; |
| 10 import android.content.res.Resources; | 10 import android.content.res.Resources; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 import jp.tomorrowkey.android.gifplayer.BaseGifImage; | 69 import jp.tomorrowkey.android.gifplayer.BaseGifImage; |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * The native new tab page, represented by some basic data such as title and url
, and an Android | 72 * The native new tab page, represented by some basic data such as title and url
, and an Android |
| 73 * View that displays the page. | 73 * View that displays the page. |
| 74 */ | 74 */ |
| 75 public class NewTabPageView extends FrameLayout | 75 public class NewTabPageView extends FrameLayout |
| 76 implements MostVisitedURLsObserver, OnLayoutChangeListener { | 76 implements MostVisitedURLsObserver, OnLayoutChangeListener { |
| 77 | 77 |
| 78 private static final int SHADOW_COLOR = 0x11000000; | |
| 79 private static final long SNAP_SCROLL_DELAY_MS = 30; | 78 private static final long SNAP_SCROLL_DELAY_MS = 30; |
| 80 private static final String TAG = "Ntp"; | 79 private static final String TAG = "Ntp"; |
| 81 | 80 |
| 82 /** | |
| 83 * Indicates which UI mode we are using. Should be checked when manipulating
some members, as | |
| 84 * they may be unused or {@code null} depending on the mode. | |
| 85 */ | |
| 86 private boolean mUseCardsUi; | |
| 87 | |
| 88 // Note: Only one of these will be valid at a time, depending on if we are u
sing the old NTP | |
| 89 // (NewTabPageScrollView) or the new NTP with cards (NewTabPageRecyclerView)
. | |
| 90 private NewTabPageScrollView mScrollView; | |
| 91 private NewTabPageRecyclerView mRecyclerView; | 81 private NewTabPageRecyclerView mRecyclerView; |
| 92 | 82 |
| 93 private NewTabPageLayout mNewTabPageLayout; | 83 private NewTabPageLayout mNewTabPageLayout; |
| 94 private LogoView mSearchProviderLogoView; | 84 private LogoView mSearchProviderLogoView; |
| 95 private View mSearchBoxView; | 85 private View mSearchBoxView; |
| 96 private ImageView mVoiceSearchButton; | 86 private ImageView mVoiceSearchButton; |
| 97 private MostVisitedLayout mMostVisitedLayout; | 87 private MostVisitedLayout mMostVisitedLayout; |
| 98 private View mMostVisitedPlaceholder; | 88 private View mMostVisitedPlaceholder; |
| 99 private View mNoSearchLogoSpacer; | 89 private View mNoSearchLogoSpacer; |
| 100 | 90 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 * @param searchProviderHasLogo Whether the search provider has a logo. | 196 * @param searchProviderHasLogo Whether the search provider has a logo. |
| 207 * @param scrollPosition The adapter scroll position to initialize to. | 197 * @param scrollPosition The adapter scroll position to initialize to. |
| 208 */ | 198 */ |
| 209 public void initialize( | 199 public void initialize( |
| 210 NewTabPageManager manager, Tab tab, boolean searchProviderHasLogo, i
nt scrollPosition) { | 200 NewTabPageManager manager, Tab tab, boolean searchProviderHasLogo, i
nt scrollPosition) { |
| 211 mActivity = tab.getActivity(); | 201 mActivity = tab.getActivity(); |
| 212 mManager = manager; | 202 mManager = manager; |
| 213 mUiConfig = new UiConfig(this); | 203 mUiConfig = new UiConfig(this); |
| 214 ViewStub stub = (ViewStub) findViewById(R.id.new_tab_page_layout_stub); | 204 ViewStub stub = (ViewStub) findViewById(R.id.new_tab_page_layout_stub); |
| 215 | 205 |
| 216 mUseCardsUi = manager.getSuggestionsSource() != null; | 206 assert manager.getSuggestionsSource() != null; |
| 217 if (mUseCardsUi) { | |
| 218 stub.setLayoutResource(R.layout.new_tab_page_recycler_view); | |
| 219 mRecyclerView = (NewTabPageRecyclerView) stub.inflate(); | |
| 220 | 207 |
| 221 // Don't attach now, the recyclerView itself will determine when to
do it. | 208 stub.setLayoutResource(R.layout.new_tab_page_recycler_view); |
| 222 mNewTabPageLayout = | 209 mRecyclerView = (NewTabPageRecyclerView) stub.inflate(); |
| 223 (NewTabPageLayout) LayoutInflater.from(getContext()) | |
| 224 .inflate(R.layout.new_tab_page_layout, mRecyclerView
, false); | |
| 225 mNewTabPageLayout.setUseCardsUiEnabled(mUseCardsUi); | |
| 226 mRecyclerView.setAboveTheFoldView(mNewTabPageLayout); | |
| 227 | 210 |
| 228 // Tailor the LayoutParams for the snippets UI, as the configuration
in the XML is | 211 // Don't attach now, the recyclerView itself will determine when to do i
t. |
| 229 // made for the ScrollView UI. | 212 mNewTabPageLayout = |
| 230 ViewGroup.LayoutParams params = mNewTabPageLayout.getLayoutParams(); | 213 (NewTabPageLayout) LayoutInflater.from(getContext()) |
| 231 params.height = ViewGroup.LayoutParams.WRAP_CONTENT; | 214 .inflate(R.layout.new_tab_page_layout, mRecyclerView, fa
lse); |
| 215 mRecyclerView.setAboveTheFoldView(mNewTabPageLayout); |
| 232 | 216 |
| 233 mRecyclerView.setItemAnimator(new DefaultItemAnimator() { | 217 // Tailor the LayoutParams for the snippets UI, as the configuration in
the XML is |
| 234 @Override | 218 // made for the ScrollView UI. |
| 235 public void onAnimationFinished(ViewHolder viewHolder) { | 219 ViewGroup.LayoutParams params = mNewTabPageLayout.getLayoutParams(); |
| 236 super.onAnimationFinished(viewHolder); | 220 params.height = ViewGroup.LayoutParams.WRAP_CONTENT; |
| 237 // When removing sections, because the animations are all tr
anslations, the | 221 |
| 238 // scroll events don't fire and we can get in the situation
where the toolbar | 222 mRecyclerView.setItemAnimator(new DefaultItemAnimator() { |
| 239 // buttons disappear. | 223 @Override |
| 240 updateSearchBoxOnScroll(); | 224 public void onAnimationFinished(ViewHolder viewHolder) { |
| 241 } | 225 super.onAnimationFinished(viewHolder); |
| 242 }); | 226 // When removing sections, because the animations are all transl
ations, the |
| 243 } else { | 227 // scroll events don't fire and we can get in the situation wher
e the toolbar |
| 244 stub.setLayoutResource(R.layout.new_tab_page_scroll_view); | 228 // buttons disappear. |
| 245 mScrollView = (NewTabPageScrollView) stub.inflate(); | 229 updateSearchBoxOnScroll(); |
| 246 mScrollView.setBackgroundColor( | 230 } |
| 247 ApiCompatibilityUtils.getColor(getResources(), R.color.ntp_b
g)); | 231 }); |
| 248 mScrollView.enableBottomShadow(SHADOW_COLOR); | 232 |
| 249 mNewTabPageLayout = (NewTabPageLayout) findViewById(R.id.ntp_content
); | 233 mContextMenuManager = |
| 250 } | 234 new ContextMenuManager(mActivity, mManager.getNavigationDelegate
(), mRecyclerView); |
| 251 mContextMenuManager = new ContextMenuManager(mActivity, mManager.getNavi
gationDelegate(), | |
| 252 mUseCardsUi ? mRecyclerView : mScrollView); | |
| 253 mActivity.getWindowAndroid().addContextMenuCloseListener(mContextMenuMan
ager); | 235 mActivity.getWindowAndroid().addContextMenuCloseListener(mContextMenuMan
ager); |
| 254 manager.addDestructionObserver(new DestructionObserver() { | 236 manager.addDestructionObserver(new DestructionObserver() { |
| 255 @Override | 237 @Override |
| 256 public void onDestroy() { | 238 public void onDestroy() { |
| 257 mActivity.getWindowAndroid().removeContextMenuCloseListener(mCon
textMenuManager); | 239 mActivity.getWindowAndroid().removeContextMenuCloseListener(mCon
textMenuManager); |
| 258 } | 240 } |
| 259 }); | 241 }); |
| 260 | 242 |
| 261 mMostVisitedDesign = new MostVisitedDesign(getContext()); | 243 mMostVisitedDesign = new MostVisitedDesign(getContext()); |
| 262 mMostVisitedLayout = | 244 mMostVisitedLayout = |
| (...skipping 10 matching lines...) Expand all Loading... |
| 273 initializeBottomToolbar(); | 255 initializeBottomToolbar(); |
| 274 | 256 |
| 275 mNewTabPageLayout.addOnLayoutChangeListener(this); | 257 mNewTabPageLayout.addOnLayoutChangeListener(this); |
| 276 setSearchProviderHasLogo(searchProviderHasLogo); | 258 setSearchProviderHasLogo(searchProviderHasLogo); |
| 277 | 259 |
| 278 mPendingLoadTasks++; | 260 mPendingLoadTasks++; |
| 279 mManager.setMostVisitedURLsObserver( | 261 mManager.setMostVisitedURLsObserver( |
| 280 this, mMostVisitedDesign.getNumberOfTiles(searchProviderHasLogo)
); | 262 this, mMostVisitedDesign.getNumberOfTiles(searchProviderHasLogo)
); |
| 281 | 263 |
| 282 // Set up snippets | 264 // Set up snippets |
| 283 if (mUseCardsUi) { | 265 NewTabPageAdapter newTabPageAdapter = new NewTabPageAdapter(mManager, mN
ewTabPageLayout, |
| 284 NewTabPageAdapter newTabPageAdapter = new NewTabPageAdapter(mManager
, mNewTabPageLayout, | 266 mUiConfig, OfflinePageBridge.getForProfile(Profile.getLastUsedPr
ofile()), |
| 285 mUiConfig, OfflinePageBridge.getForProfile(Profile.getLastUs
edProfile()), | 267 mContextMenuManager); |
| 286 mContextMenuManager); | 268 mRecyclerView.setAdapter(newTabPageAdapter); |
| 287 mRecyclerView.setAdapter(newTabPageAdapter); | |
| 288 | 269 |
| 289 int scrollOffset; | 270 int scrollOffset; |
| 290 if (CardsVariationParameters.isScrollBelowTheFoldEnabled()) { | 271 if (CardsVariationParameters.isScrollBelowTheFoldEnabled()) { |
| 291 scrollPosition = newTabPageAdapter.getFirstHeaderPosition(); | 272 scrollPosition = newTabPageAdapter.getFirstHeaderPosition(); |
| 292 scrollOffset = getResources().getDimensionPixelSize(R.dimen.ntp_
search_box_height); | 273 scrollOffset = getResources().getDimensionPixelSize(R.dimen.ntp_sear
ch_box_height); |
| 293 } else { | 274 } else { |
| 294 scrollOffset = 0; | 275 scrollOffset = 0; |
| 276 } |
| 277 mRecyclerView.getLinearLayoutManager().scrollToPositionWithOffset( |
| 278 scrollPosition, scrollOffset); |
| 279 |
| 280 mRecyclerView.setUpSwipeToDismiss(); |
| 281 |
| 282 setupScrollHandling(); |
| 283 |
| 284 // When the NewTabPageAdapter's data changes we need to invalidate any p
revious |
| 285 // screen captures of the NewTabPageView. |
| 286 newTabPageAdapter.registerAdapterDataObserver(new AdapterDataObserver()
{ |
| 287 @Override |
| 288 public void onChanged() { |
| 289 mNewTabPageRecyclerViewChanged = true; |
| 295 } | 290 } |
| 296 mRecyclerView.getLinearLayoutManager().scrollToPositionWithOffset( | |
| 297 scrollPosition, scrollOffset); | |
| 298 | 291 |
| 299 mRecyclerView.setUpSwipeToDismiss(); | 292 @Override |
| 293 public void onItemRangeChanged(int positionStart, int itemCount) { |
| 294 onChanged(); |
| 295 } |
| 300 | 296 |
| 301 initializeSearchBoxRecyclerViewScrollHandling(); | 297 @Override |
| 298 public void onItemRangeInserted(int positionStart, int itemCount) { |
| 299 onChanged(); |
| 300 } |
| 302 | 301 |
| 303 // When the NewTabPageAdapter's data changes we need to invalidate a
ny previous | 302 @Override |
| 304 // screen captures of the NewTabPageView. | 303 public void onItemRangeRemoved(int positionStart, int itemCount) { |
| 305 newTabPageAdapter.registerAdapterDataObserver(new AdapterDataObserve
r() { | 304 onChanged(); |
| 306 @Override | 305 } |
| 307 public void onChanged() { | |
| 308 mNewTabPageRecyclerViewChanged = true; | |
| 309 } | |
| 310 | 306 |
| 311 @Override | 307 @Override |
| 312 public void onItemRangeChanged(int positionStart, int itemCount)
{ | 308 public void onItemRangeMoved(int fromPosition, int toPosition, int i
temCount) { |
| 313 onChanged(); | 309 onChanged(); |
| 314 } | 310 } |
| 311 }); |
| 315 | 312 |
| 316 @Override | |
| 317 public void onItemRangeInserted(int positionStart, int itemCount
) { | |
| 318 onChanged(); | |
| 319 } | |
| 320 | |
| 321 @Override | |
| 322 public void onItemRangeRemoved(int positionStart, int itemCount)
{ | |
| 323 onChanged(); | |
| 324 } | |
| 325 | |
| 326 @Override | |
| 327 public void onItemRangeMoved(int fromPosition, int toPosition, i
nt itemCount) { | |
| 328 onChanged(); | |
| 329 } | |
| 330 }); | |
| 331 } else { | |
| 332 initializeSearchBoxScrollHandling(); | |
| 333 } | |
| 334 } | 313 } |
| 335 | 314 |
| 336 /** | 315 /** |
| 337 * Sets up the hint text and event handlers for the search box text view. | 316 * Sets up the hint text and event handlers for the search box text view. |
| 338 */ | 317 */ |
| 339 private void initializeSearchBoxTextView() { | 318 private void initializeSearchBoxTextView() { |
| 340 final TextView searchBoxTextView = (TextView) mSearchBoxView | 319 final TextView searchBoxTextView = (TextView) mSearchBoxView |
| 341 .findViewById(R.id.search_box_text); | 320 .findViewById(R.id.search_box_text); |
| 342 String hintText = getResources().getString(R.string.search_or_type_url); | 321 String hintText = getResources().getString(R.string.search_or_type_url); |
| 343 | 322 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 * the position of the search box. | 407 * the position of the search box. |
| 429 * | 408 * |
| 430 * @return the transition percentage | 409 * @return the transition percentage |
| 431 */ | 410 */ |
| 432 private float getToolbarTransitionPercentage() { | 411 private float getToolbarTransitionPercentage() { |
| 433 // During startup the view may not be fully initialized, so we only calc
ulate the current | 412 // During startup the view may not be fully initialized, so we only calc
ulate the current |
| 434 // percentage if some basic view properties (height of the containing vi
ew, position of the | 413 // percentage if some basic view properties (height of the containing vi
ew, position of the |
| 435 // search box) are sane. | 414 // search box) are sane. |
| 436 if (getWrapperView().getHeight() == 0) return 0f; | 415 if (getWrapperView().getHeight() == 0) return 0f; |
| 437 | 416 |
| 438 if (mUseCardsUi && !mRecyclerView.isFirstItemVisible()) { | 417 if (!mRecyclerView.isFirstItemVisible()) { |
| 439 // getVerticalScroll is valid only for the RecyclerView if the first
item is visible. | 418 // getVerticalScroll is valid only for the RecyclerView if the first
item is visible. |
| 440 // If the first item is not visible, we must have scrolled quite far
and we know the | 419 // If the first item is not visible, we must have scrolled quite far
and we know the |
| 441 // toolbar transition should be 100%. This might be the initial scro
ll position due to | 420 // toolbar transition should be 100%. This might be the initial scro
ll position due to |
| 442 // the scroll restore feature, so the search box will not have been
laid out yet. | 421 // the scroll restore feature, so the search box will not have been
laid out yet. |
| 443 return 1f; | 422 return 1f; |
| 444 } | 423 } |
| 445 | 424 |
| 446 int searchBoxTop = mSearchBoxView.getTop(); | 425 int searchBoxTop = mSearchBoxView.getTop(); |
| 447 if (searchBoxTop == 0) return 0f; | 426 if (searchBoxTop == 0) return 0f; |
| 448 | 427 |
| 449 // For all other calculations, add the search box padding, because it de
fines where the | 428 // For all other calculations, add the search box padding, because it de
fines where the |
| 450 // visible "border" of the search box is. | 429 // visible "border" of the search box is. |
| 451 searchBoxTop += mSearchBoxView.getPaddingTop(); | 430 searchBoxTop += mSearchBoxView.getPaddingTop(); |
| 452 | 431 |
| 453 if (!mUseCardsUi) { | |
| 454 return MathUtils.clamp(getVerticalScroll() / (float) searchBoxTop, 0
f, 1f); | |
| 455 } | |
| 456 | |
| 457 final int scrollY = getVerticalScroll(); | 432 final int scrollY = getVerticalScroll(); |
| 458 final float transitionLength = | 433 final float transitionLength = |
| 459 getResources().getDimension(R.dimen.ntp_search_box_transition_le
ngth); | 434 getResources().getDimension(R.dimen.ntp_search_box_transition_le
ngth); |
| 460 // Tab strip height is zero on phones, nonzero on tablets. | 435 // Tab strip height is zero on phones, nonzero on tablets. |
| 461 int tabStripHeight = getResources().getDimensionPixelSize(R.dimen.tab_st
rip_height); | 436 int tabStripHeight = getResources().getDimensionPixelSize(R.dimen.tab_st
rip_height); |
| 462 | 437 |
| 463 // |scrollY - searchBoxTop + tabStripHeight| gives the distance the sear
ch bar is from the | 438 // |scrollY - searchBoxTop + tabStripHeight| gives the distance the sear
ch bar is from the |
| 464 // top of the tab. | 439 // top of the tab. |
| 465 return MathUtils.clamp((scrollY - searchBoxTop + transitionLength + tabS
tripHeight) | 440 return MathUtils.clamp((scrollY - searchBoxTop + transitionLength + tabS
tripHeight) |
| 466 / transitionLength, 0f, 1f); | 441 / transitionLength, 0f, 1f); |
| 467 } | 442 } |
| 468 | 443 |
| 469 @VisibleForTesting | 444 @VisibleForTesting |
| 470 public ViewGroup getWrapperView() { | 445 public ViewGroup getWrapperView() { |
| 471 return mUseCardsUi ? mRecyclerView : mScrollView; | 446 return mRecyclerView; |
| 472 } | 447 } |
| 473 | 448 |
| 474 /** | 449 /** |
| 475 * Sets up scrolling when snippets are enabled. It adds scroll listeners and
touch listeners to | 450 * Adds listeners to scrolling to take care of snap scrolling and updating t
he search box on |
| 476 * the RecyclerView. | 451 * scroll. |
| 477 */ | 452 */ |
| 478 private void initializeSearchBoxRecyclerViewScrollHandling() { | 453 private void setupScrollHandling() { |
| 479 final Runnable mSnapScrollRunnable = new Runnable() { | 454 final Runnable mSnapScrollRunnable = new Runnable() { |
| 480 @Override | 455 @Override |
| 481 public void run() { | 456 public void run() { |
| 482 assert mPendingSnapScroll; | 457 assert mPendingSnapScroll; |
| 483 mPendingSnapScroll = false; | 458 mPendingSnapScroll = false; |
| 484 | 459 |
| 485 mRecyclerView.snapScroll(mSearchBoxView, getVerticalScroll(), ge
tHeight()); | 460 mRecyclerView.snapScroll(mSearchBoxView, getVerticalScroll(), ge
tHeight()); |
| 486 } | 461 } |
| 487 }; | 462 }; |
| 488 | 463 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 510 mRecyclerView.postDelayed(mSnapScrollRunnable, SNAP_SCROLL_D
ELAY_MS); | 485 mRecyclerView.postDelayed(mSnapScrollRunnable, SNAP_SCROLL_D
ELAY_MS); |
| 511 } else { | 486 } else { |
| 512 mPendingSnapScroll = false; | 487 mPendingSnapScroll = false; |
| 513 } | 488 } |
| 514 return false; | 489 return false; |
| 515 } | 490 } |
| 516 }); | 491 }); |
| 517 } | 492 } |
| 518 | 493 |
| 519 /** | 494 /** |
| 520 * Sets up scrolling when snippets are disabled. It adds scroll and touch li
steners to the | |
| 521 * scroll view. | |
| 522 */ | |
| 523 private void initializeSearchBoxScrollHandling() { | |
| 524 final Runnable mSnapScrollRunnable = new Runnable() { | |
| 525 @Override | |
| 526 public void run() { | |
| 527 if (!mPendingSnapScroll) return; | |
| 528 int scrollY = mScrollView.getScrollY(); | |
| 529 int dividerTop = mMostVisitedLayout.getTop() - mNewTabPageLayout
.getPaddingTop(); | |
| 530 if (scrollY > 0 && scrollY < dividerTop) { | |
| 531 mScrollView.smoothScrollTo(0, scrollY < (dividerTop / 2) ? 0
: dividerTop); | |
| 532 } | |
| 533 mPendingSnapScroll = false; | |
| 534 } | |
| 535 }; | |
| 536 mScrollView.setOnScrollListener(new NewTabPageScrollView.OnScrollListene
r() { | |
| 537 @Override | |
| 538 public void onScrollChanged(int l, int t, int oldl, int oldt) { | |
| 539 if (mPendingSnapScroll) { | |
| 540 mScrollView.removeCallbacks(mSnapScrollRunnable); | |
| 541 mScrollView.postDelayed(mSnapScrollRunnable, SNAP_SCROLL_DEL
AY_MS); | |
| 542 } | |
| 543 updateSearchBoxOnScroll(); | |
| 544 } | |
| 545 }); | |
| 546 mScrollView.setOnTouchListener(new OnTouchListener() { | |
| 547 @Override | |
| 548 @SuppressLint("ClickableViewAccessibility") | |
| 549 public boolean onTouch(View v, MotionEvent event) { | |
| 550 mScrollView.removeCallbacks(mSnapScrollRunnable); | |
| 551 | |
| 552 if (event.getActionMasked() == MotionEvent.ACTION_CANCEL | |
| 553 || event.getActionMasked() == MotionEvent.ACTION_UP) { | |
| 554 mPendingSnapScroll = true; | |
| 555 mScrollView.postDelayed(mSnapScrollRunnable, SNAP_SCROLL_DEL
AY_MS); | |
| 556 } else { | |
| 557 mPendingSnapScroll = false; | |
| 558 } | |
| 559 return false; | |
| 560 } | |
| 561 }); | |
| 562 } | |
| 563 | |
| 564 /** | |
| 565 * Decrements the count of pending load tasks and notifies the manager when
the page load | 495 * Decrements the count of pending load tasks and notifies the manager when
the page load |
| 566 * is complete. | 496 * is complete. |
| 567 */ | 497 */ |
| 568 private void loadTaskCompleted() { | 498 private void loadTaskCompleted() { |
| 569 assert mPendingLoadTasks > 0; | 499 assert mPendingLoadTasks > 0; |
| 570 mPendingLoadTasks--; | 500 mPendingLoadTasks--; |
| 571 if (mPendingLoadTasks == 0) { | 501 if (mPendingLoadTasks == 0) { |
| 572 if (mLoadHasCompleted) { | 502 if (mLoadHasCompleted) { |
| 573 assert false; | 503 assert false; |
| 574 } else { | 504 } else { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 * @return The percentage that the URL bar is focused during an animation. | 601 * @return The percentage that the URL bar is focused during an animation. |
| 672 */ | 602 */ |
| 673 @VisibleForTesting | 603 @VisibleForTesting |
| 674 float getUrlFocusChangeAnimationPercent() { | 604 float getUrlFocusChangeAnimationPercent() { |
| 675 return mUrlFocusChangePercent; | 605 return mUrlFocusChangePercent; |
| 676 } | 606 } |
| 677 | 607 |
| 678 private void onUrlFocusAnimationChanged() { | 608 private void onUrlFocusAnimationChanged() { |
| 679 if (mDisableUrlFocusChangeAnimations) return; | 609 if (mDisableUrlFocusChangeAnimations) return; |
| 680 | 610 |
| 611 // Translate so that the search box is at the top, but only upwards. |
| 681 float percent = mSearchProviderHasLogo ? mUrlFocusChangePercent : 0; | 612 float percent = mSearchProviderHasLogo ? mUrlFocusChangePercent : 0; |
| 613 int basePosition = getVerticalScroll() + mNewTabPageLayout.getPaddingTop
(); |
| 614 int target = Math.max(basePosition, |
| 615 mSearchBoxView.getBottom() - mSearchBoxView.getPaddingBottom
()); |
| 682 | 616 |
| 683 int basePosition = getVerticalScroll() + mNewTabPageLayout.getPaddingTop
(); | |
| 684 int target; | |
| 685 if (mUseCardsUi) { | |
| 686 // Cards UI: translate so that the search box is at the top, but onl
y upwards. | |
| 687 target = Math.max(basePosition, | |
| 688 mSearchBoxView.getBottom() - mSearchBoxView.getPaddingBottom
()); | |
| 689 } else { | |
| 690 // Otherwise: translate so that Most Visited is right below the omni
box. | |
| 691 target = mMostVisitedLayout.getTop(); | |
| 692 } | |
| 693 mNewTabPageLayout.setTranslationY(percent * (basePosition - target)); | 617 mNewTabPageLayout.setTranslationY(percent * (basePosition - target)); |
| 694 } | 618 } |
| 695 | 619 |
| 696 /** | 620 /** |
| 697 * Updates the opacity of the search box when scrolling. | 621 * Updates the opacity of the search box when scrolling. |
| 698 * | 622 * |
| 699 * @param alpha opacity (alpha) value to use. | 623 * @param alpha opacity (alpha) value to use. |
| 700 */ | 624 */ |
| 701 public void setSearchBoxAlpha(float alpha) { | 625 public void setSearchBoxAlpha(float alpha) { |
| 702 mSearchBoxView.setAlpha(alpha); | 626 mSearchBoxView.setAlpha(alpha); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 int newHeight = bottom - top; | 757 int newHeight = bottom - top; |
| 834 | 758 |
| 835 if (oldHeight == newHeight && !mTileCountChanged) return; | 759 if (oldHeight == newHeight && !mTileCountChanged) return; |
| 836 mTileCountChanged = false; | 760 mTileCountChanged = false; |
| 837 | 761 |
| 838 // Re-apply the url focus change amount after a rotation to ensure the v
iews are correctly | 762 // Re-apply the url focus change amount after a rotation to ensure the v
iews are correctly |
| 839 // placed with their new layout configurations. | 763 // placed with their new layout configurations. |
| 840 onUrlFocusAnimationChanged(); | 764 onUrlFocusAnimationChanged(); |
| 841 updateSearchBoxOnScroll(); | 765 updateSearchBoxOnScroll(); |
| 842 | 766 |
| 843 if (mUseCardsUi) { | 767 mRecyclerView.updatePeekingCardAndHeader(); |
| 844 mRecyclerView.updatePeekingCardAndHeader(); | 768 // The positioning of elements may have been changed (since the elements
expand to fill |
| 845 // The positioning of elements may have been changed (since the elem
ents expand to fill | 769 // the available vertical space), so adjust the scroll. |
| 846 // the available vertical space), so adjust the scroll. | 770 mRecyclerView.snapScroll(mSearchBoxView, getVerticalScroll(), getHeight(
)); |
| 847 mRecyclerView.snapScroll(mSearchBoxView, getVerticalScroll(), getHei
ght()); | |
| 848 } | |
| 849 } | 771 } |
| 850 | 772 |
| 851 // MostVisitedURLsObserver implementation | 773 // MostVisitedURLsObserver implementation |
| 852 | 774 |
| 853 @Override | 775 @Override |
| 854 public void onMostVisitedURLsAvailable(final String[] titles, final String[]
urls, | 776 public void onMostVisitedURLsAvailable(final String[] titles, final String[]
urls, |
| 855 final String[] whitelistIconPaths, final int[] sources) { | 777 final String[] whitelistIconPaths, final int[] sources) { |
| 856 Set<String> urlSet = new HashSet<>(Arrays.asList(urls)); | 778 Set<String> urlSet = new HashSet<>(Arrays.asList(urls)); |
| 857 | 779 |
| 858 // If no Most Visited items have been built yet, this is the initial loa
d. Build the Most | 780 // If no Most Visited items have been built yet, this is the initial loa
d. Build the Most |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 } | 1022 } |
| 1101 } | 1023 } |
| 1102 | 1024 |
| 1103 @Override | 1025 @Override |
| 1104 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | 1026 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 1105 if (mNewTabPageLayout != null) { | 1027 if (mNewTabPageLayout != null) { |
| 1106 mNewTabPageLayout.setParentViewportHeight(MeasureSpec.getSize(height
MeasureSpec)); | 1028 mNewTabPageLayout.setParentViewportHeight(MeasureSpec.getSize(height
MeasureSpec)); |
| 1107 } | 1029 } |
| 1108 super.onMeasure(widthMeasureSpec, heightMeasureSpec); | 1030 super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 1109 | 1031 |
| 1110 if (mUseCardsUi) mRecyclerView.updatePeekingCardAndHeader(); | 1032 mRecyclerView.updatePeekingCardAndHeader(); |
| 1111 } | 1033 } |
| 1112 | 1034 |
| 1113 @Override | 1035 @Override |
| 1114 protected void onConfigurationChanged(Configuration newConfig) { | 1036 protected void onConfigurationChanged(Configuration newConfig) { |
| 1115 super.onConfigurationChanged(newConfig); | 1037 super.onConfigurationChanged(newConfig); |
| 1116 | 1038 |
| 1117 // When the viewport configuration changes, we want to update the displa
y style so that the | 1039 // When the viewport configuration changes, we want to update the displa
y style so that the |
| 1118 // observers are aware of the new available space. Another moment to do
this update could | 1040 // observers are aware of the new available space. Another moment to do
this update could |
| 1119 // be through a OnLayoutChangeListener, but then we get notified of the
change after the | 1041 // be through a OnLayoutChangeListener, but then we get notified of the
change after the |
| 1120 // layout pass, which means that the new style will only be visible afte
r layout happens | 1042 // layout pass, which means that the new style will only be visible afte
r layout happens |
| 1121 // again. We prefer updating here to avoid having to require that additi
onal layout pass. | 1043 // again. We prefer updating here to avoid having to require that additi
onal layout pass. |
| 1122 mUiConfig.updateDisplayStyle(); | 1044 mUiConfig.updateDisplayStyle(); |
| 1123 | 1045 |
| 1124 // Close the Context Menu as it may have moved (https://crbug.com/642688
). | 1046 // Close the Context Menu as it may have moved (https://crbug.com/642688
). |
| 1125 mContextMenuManager.closeContextMenu(); | 1047 mContextMenuManager.closeContextMenu(); |
| 1126 } | 1048 } |
| 1127 | 1049 |
| 1128 private int getVerticalScroll() { | 1050 private int getVerticalScroll() { |
| 1129 if (mUseCardsUi) { | 1051 return mRecyclerView.computeVerticalScrollOffset(); |
| 1130 return mRecyclerView.computeVerticalScrollOffset(); | |
| 1131 } else { | |
| 1132 return mScrollView.getScrollY(); | |
| 1133 } | |
| 1134 } | 1052 } |
| 1135 | 1053 |
| 1136 /** | 1054 /** |
| 1137 * @return The adapter position the user has scrolled to. | 1055 * @return The adapter position the user has scrolled to. |
| 1138 */ | 1056 */ |
| 1139 public int getScrollPosition() { | 1057 public int getScrollPosition() { |
| 1140 if (mUseCardsUi) return mRecyclerView.getScrollPosition(); | 1058 return mRecyclerView.getScrollPosition(); |
| 1141 return RecyclerView.NO_POSITION; | |
| 1142 } | 1059 } |
| 1143 | 1060 |
| 1144 /** @return the context menu manager. */ | 1061 /** @return the context menu manager. */ |
| 1145 public ContextMenuManager getContextMenuManager() { | 1062 public ContextMenuManager getContextMenuManager() { |
| 1146 return mContextMenuManager; | 1063 return mContextMenuManager; |
| 1147 } | 1064 } |
| 1148 } | 1065 } |
| OLD | NEW |