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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java

Issue 1812293002: Add new NTP layout with snippet cards and hide it behind a flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + CR comments + added background color to new NTP Created 4 years, 9 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 unified diff | Download patch
OLDNEW
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;
11 import android.graphics.BitmapFactory; 11 import android.graphics.BitmapFactory;
12 import android.graphics.Canvas; 12 import android.graphics.Canvas;
13 import android.graphics.Color; 13 import android.graphics.Color;
14 import android.graphics.Rect; 14 import android.graphics.Rect;
15 import android.graphics.drawable.BitmapDrawable; 15 import android.graphics.drawable.BitmapDrawable;
16 import android.net.Uri; 16 import android.net.Uri;
17 import android.os.Build; 17 import android.os.Build;
18 import android.support.v4.graphics.drawable.RoundedBitmapDrawable; 18 import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
19 import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory; 19 import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
20 import android.support.v7.widget.LinearLayoutManager;
21 import android.support.v7.widget.RecyclerView; 20 import android.support.v7.widget.RecyclerView;
22 import android.text.Editable; 21 import android.text.Editable;
23 import android.text.TextUtils; 22 import android.text.TextUtils;
24 import android.text.TextWatcher; 23 import android.text.TextWatcher;
25 import android.text.method.LinkMovementMethod; 24 import android.text.method.LinkMovementMethod;
26 import android.text.style.ClickableSpan; 25 import android.text.style.ClickableSpan;
27 import android.util.AttributeSet; 26 import android.util.AttributeSet;
28 import android.view.LayoutInflater; 27 import android.view.LayoutInflater;
29 import android.view.MotionEvent; 28 import android.view.MotionEvent;
30 import android.view.View; 29 import android.view.View;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 * The native new tab page, represented by some basic data such as title and url , and an Android 65 * The native new tab page, represented by some basic data such as title and url , and an Android
67 * View that displays the page. 66 * View that displays the page.
68 */ 67 */
69 public class NewTabPageView extends FrameLayout 68 public class NewTabPageView extends FrameLayout
70 implements MostVisitedURLsObserver, OnLayoutChangeListener { 69 implements MostVisitedURLsObserver, OnLayoutChangeListener {
71 70
72 private static final int SHADOW_COLOR = 0x11000000; 71 private static final int SHADOW_COLOR = 0x11000000;
73 private static final long SNAP_SCROLL_DELAY_MS = 30; 72 private static final long SNAP_SCROLL_DELAY_MS = 30;
74 private static final String TAG = "NewTabPageView"; 73 private static final String TAG = "NewTabPageView";
75 74
76 private ViewGroup mContentView; 75 // Note: Only one of these will be valid at a time, depending on if we are u sing the old NTP
76 // (NewTabScrollView) or the new NTP with cards (NewTabRecyclerView).
77 private NewTabScrollView mScrollView; 77 private NewTabScrollView mScrollView;
dgn 2016/03/25 16:29:20 Would it make sense to use composition or inherita
78 private NewTabRecyclerView mRecyclerView;
79
80 private NewTabPageLayout mContentView;
78 private LogoView mSearchProviderLogoView; 81 private LogoView mSearchProviderLogoView;
79 private View mSearchBoxView; 82 private View mSearchBoxView;
80 private TextView mSearchBoxTextView; 83 private TextView mSearchBoxTextView;
81 private ImageView mVoiceSearchButton; 84 private ImageView mVoiceSearchButton;
82 private MostVisitedLayout mMostVisitedLayout; 85 private MostVisitedLayout mMostVisitedLayout;
83 private View mMostVisitedPlaceholder; 86 private View mMostVisitedPlaceholder;
84 private View mOptOutView; 87 private View mOptOutView;
85 private View mNoSearchLogoSpacer; 88 private View mNoSearchLogoSpacer;
86 private RecyclerView mSnippetsView; 89 private NewTabPageCardsManager mCardsManager;
87 90
88 private OnSearchBoxScrollListener mSearchBoxScrollListener; 91 private OnSearchBoxScrollListener mSearchBoxScrollListener;
89 92
90 private NewTabPageManager mManager; 93 private NewTabPageManager mManager;
91 private MostVisitedDesign mMostVisitedDesign; 94 private MostVisitedDesign mMostVisitedDesign;
92 private MostVisitedItem[] mMostVisitedItems; 95 private MostVisitedItem[] mMostVisitedItems;
93 private boolean mFirstShow = true; 96 private boolean mFirstShow = true;
94 private boolean mSearchProviderHasLogo = true; 97 private boolean mSearchProviderHasLogo = true;
95 private boolean mHasReceivedMostVisitedSites; 98 private boolean mHasReceivedMostVisitedSites;
96 private boolean mPendingSnapScroll; 99 private boolean mPendingSnapScroll;
100 private boolean mAreSnippetsEnabled;
97 101
98 /** 102 /**
99 * The number of asynchronous tasks that need to complete before the page is done loading. 103 * The number of asynchronous tasks that need to complete before the page is done loading.
100 * This starts at one to track when the view is finished attaching to the wi ndow. 104 * This starts at one to track when the view is finished attaching to the wi ndow.
101 */ 105 */
102 private int mPendingLoadTasks = 1; 106 private int mPendingLoadTasks = 1;
103 private boolean mLoadHasCompleted; 107 private boolean mLoadHasCompleted;
104 108
105 private float mUrlFocusChangePercent; 109 private float mUrlFocusChangePercent;
106 private boolean mDisableUrlFocusChangeAnimations; 110 private boolean mDisableUrlFocusChangeAnimations;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 * used in any other way. 254 * used in any other way.
251 * 255 *
252 * @param manager NewTabPageManager used to perform various actions when the user interacts 256 * @param manager NewTabPageManager used to perform various actions when the user interacts
253 * with the page. 257 * with the page.
254 * @param isSingleUrlBarMode Whether the NTP is in single URL bar mode. 258 * @param isSingleUrlBarMode Whether the NTP is in single URL bar mode.
255 * @param searchProviderHasLogo Whether the search provider has a logo. 259 * @param searchProviderHasLogo Whether the search provider has a logo.
256 */ 260 */
257 public void initialize(NewTabPageManager manager, boolean isSingleUrlBarMode , 261 public void initialize(NewTabPageManager manager, boolean isSingleUrlBarMode ,
258 boolean searchProviderHasLogo, SnippetsManager snippetsManager) { 262 boolean searchProviderHasLogo, SnippetsManager snippetsManager) {
259 mManager = manager; 263 mManager = manager;
264 ViewStub stub = (ViewStub) findViewById(R.id.new_tab_page_layout_stub);
260 265
261 mScrollView = (NewTabScrollView) findViewById(R.id.ntp_scrollview); 266 mAreSnippetsEnabled = ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_ SNIPPETS);
262 mScrollView.enableBottomShadow(SHADOW_COLOR); 267
263 mContentView = (ViewGroup) findViewById(R.id.ntp_content); 268 if (mAreSnippetsEnabled) {
269 stub.setLayoutResource(R.layout.new_tab_page_recyclerview);
270 mRecyclerView = (NewTabRecyclerView) stub.inflate();
271 mContentView = (NewTabPageLayout) LayoutInflater.from(getContext())
272 .inflate(R.layout.new_tab_page_layout, null);
273 } else {
274 stub.setLayoutResource(R.layout.new_tab_page_scrollview);
275 mScrollView = (NewTabScrollView) stub.inflate();
276 mScrollView.enableBottomShadow(SHADOW_COLOR);
277 mContentView = (NewTabPageLayout) findViewById(R.id.ntp_content);
278 }
264 279
265 mMostVisitedDesign = new MostVisitedDesign(getContext()); 280 mMostVisitedDesign = new MostVisitedDesign(getContext());
266 mMostVisitedLayout = (MostVisitedLayout) findViewById(R.id.most_visited_ layout); 281 mMostVisitedLayout =
282 (MostVisitedLayout) mContentView.findViewById(R.id.most_visited_ layout);
267 mMostVisitedDesign.initMostVisitedLayout(mMostVisitedLayout, searchProvi derHasLogo); 283 mMostVisitedDesign.initMostVisitedLayout(mMostVisitedLayout, searchProvi derHasLogo);
268 284
269 mSearchProviderLogoView = (LogoView) findViewById(R.id.search_provider_l ogo); 285 mSearchProviderLogoView = (LogoView) mContentView.findViewById(R.id.sear ch_provider_logo);
270 mSearchBoxView = findViewById(R.id.search_box); 286 mSearchBoxView = mContentView.findViewById(R.id.search_box);
271 mNoSearchLogoSpacer = findViewById(R.id.no_search_logo_spacer); 287 mNoSearchLogoSpacer = mContentView.findViewById(R.id.no_search_logo_spac er);
272 288
273 mSearchBoxTextView = (TextView) mSearchBoxView.findViewById(R.id.search_ box_text); 289 mSearchBoxTextView = (TextView) mSearchBoxView.findViewById(R.id.search_ box_text);
274 String hintText = getResources().getString(R.string.search_or_type_url); 290 String hintText = getResources().getString(R.string.search_or_type_url);
275 if (isSingleUrlBarMode) { 291 if (isSingleUrlBarMode) {
276 mSearchBoxTextView.setHint(hintText); 292 mSearchBoxTextView.setHint(hintText);
277 } else { 293 } else {
278 mSearchBoxTextView.setContentDescription(hintText); 294 mSearchBoxTextView.setContentDescription(hintText);
279 } 295 }
280 mSearchBoxTextView.setOnClickListener(new View.OnClickListener() { 296 mSearchBoxTextView.setOnClickListener(new View.OnClickListener() {
281 @Override 297 @Override
(...skipping 11 matching lines...) Expand all
293 } 309 }
294 310
295 @Override 311 @Override
296 public void afterTextChanged(Editable s) { 312 public void afterTextChanged(Editable s) {
297 if (s.length() == 0) return; 313 if (s.length() == 0) return;
298 mManager.focusSearchBox(false, s.toString()); 314 mManager.focusSearchBox(false, s.toString());
299 mSearchBoxTextView.setText(""); 315 mSearchBoxTextView.setText("");
300 } 316 }
301 }); 317 });
302 318
303 mVoiceSearchButton = (ImageView) findViewById(R.id.voice_search_button); 319 mVoiceSearchButton = (ImageView) mContentView.findViewById(R.id.voice_se arch_button);
304 mVoiceSearchButton.setOnClickListener(new View.OnClickListener() { 320 mVoiceSearchButton.setOnClickListener(new View.OnClickListener() {
305 @Override 321 @Override
306 public void onClick(View v) { 322 public void onClick(View v) {
307 mManager.focusSearchBox(true, null); 323 mManager.focusSearchBox(true, null);
308 } 324 }
309 }); 325 });
310 326
311 // Set up the toolbar 327 // Set up the toolbar
312 NewTabPageToolbar toolbar = (NewTabPageToolbar) findViewById(R.id.ntp_to olbar); 328 NewTabPageToolbar toolbar = (NewTabPageToolbar) findViewById(R.id.ntp_to olbar);
313 if (manager.isToolbarEnabled()) { 329 if (manager.isToolbarEnabled()) {
(...skipping 15 matching lines...) Expand all
329 mManager.navigateToInterests(); 345 mManager.navigateToInterests();
330 } 346 }
331 }); 347 });
332 348
333 // Set up interests 349 // Set up interests
334 if (manager.isInterestsEnabled()) { 350 if (manager.isInterestsEnabled()) {
335 toolbar.getInterestsButton().setVisibility(View.VISIBLE); 351 toolbar.getInterestsButton().setVisibility(View.VISIBLE);
336 } 352 }
337 } else { 353 } else {
338 ((ViewGroup) toolbar.getParent()).removeView(toolbar); 354 ((ViewGroup) toolbar.getParent()).removeView(toolbar);
339 FrameLayout.LayoutParams params = 355 if (!ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_SNIPPETS)) {
newt (away) 2016/03/24 19:47:39 better: if (mScrollView != null)
dgn 2016/03/28 21:33:02 We have mAreSnippetsEnabled for that, right? Isn't
340 (FrameLayout.LayoutParams) mScrollView.getLayoutParams(); 356 // Only remove if we're using the old NTP view, the new one does not use a
341 params.bottomMargin = 0; 357 // ScrollView
342 mScrollView.setLayoutParams(params); 358 FrameLayout.LayoutParams params =
359 (FrameLayout.LayoutParams) mScrollView.getLayoutParams() ;
360 params.bottomMargin = 0;
361 mScrollView.setLayoutParams(params);
362 }
343 } 363 }
344 364
345 initializeSearchBoxScrollHandling();
346 addOnLayoutChangeListener(this); 365 addOnLayoutChangeListener(this);
347 setSearchProviderHasLogo(searchProviderHasLogo); 366 setSearchProviderHasLogo(searchProviderHasLogo);
348 367
349 mPendingLoadTasks++; 368 mPendingLoadTasks++;
350 mManager.setMostVisitedURLsObserver(this, 369 mManager.setMostVisitedURLsObserver(this,
351 mMostVisitedDesign.getNumberOfTiles(searchProviderHasLogo)); 370 mMostVisitedDesign.getNumberOfTiles(searchProviderHasLogo));
352 371
353 if (mManager.shouldShowOptOutPromo()) showOptOutPromo(); 372 if (mManager.shouldShowOptOutPromo()) showOptOutPromo();
354 373
355 // Set up snippets 374 // Set up snippets
356 if (ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_SNIPPETS)) { 375 if (mAreSnippetsEnabled) {
357 mSnippetsView = (RecyclerView) findViewById(R.id.snippets_card_list) ; 376 mCardsManager = new NewTabPageCardsManager(snippetsManager, mContent View);
358 mSnippetsView.setVisibility(View.VISIBLE); 377 mRecyclerView.setAdapter(mCardsManager);
378
359 RecordHistogram.recordEnumeratedHistogram(SnippetsManager.SNIPPETS_S TATE_HISTOGRAM, 379 RecordHistogram.recordEnumeratedHistogram(SnippetsManager.SNIPPETS_S TATE_HISTOGRAM,
360 SnippetsManager.SNIPPETS_SHOWN, SnippetsManager.NUM_SNIPPETS _ACTIONS); 380 SnippetsManager.SNIPPETS_SHOWN, SnippetsManager.NUM_SNIPPETS _ACTIONS);
361 mSnippetsView.setLayoutManager(new LinearLayoutManager(getContext()) ); 381 mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener( ) {
362 mSnippetsView.addOnScrollListener(new RecyclerView.OnScrollListener( ) {
363 private boolean mScrolledOnce = false; 382 private boolean mScrolledOnce = false;
364 @Override 383 @Override
365 public void onScrollStateChanged(RecyclerView recyclerView, int newState) { 384 public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
366 if (newState != RecyclerView.SCROLL_STATE_DRAGGING) return; 385 if (newState != RecyclerView.SCROLL_STATE_DRAGGING) return;
367 RecordUserAction.record("MobileNTP.Snippets.Scrolled"); 386 RecordUserAction.record("MobileNTP.Snippets.Scrolled");
368 if (mScrolledOnce) return; 387 if (mScrolledOnce) return;
369 mScrolledOnce = true; 388 mScrolledOnce = true;
370 RecordHistogram.recordEnumeratedHistogram( 389 RecordHistogram.recordEnumeratedHistogram(
371 SnippetsManager.SNIPPETS_STATE_HISTOGRAM, 390 SnippetsManager.SNIPPETS_STATE_HISTOGRAM,
372 SnippetsManager.SNIPPETS_SCROLLED, 391 SnippetsManager.SNIPPETS_SCROLLED,
373 SnippetsManager.NUM_SNIPPETS_ACTIONS); 392 SnippetsManager.NUM_SNIPPETS_ACTIONS);
374 } 393 }
375 }); 394 });
376 snippetsManager.setSnippetsView(mSnippetsView); 395 initializeSearchBoxRecyclerViewScrollHandling();
396 } else {
397 initializeSearchBoxScrollHandling();
377 } 398 }
378 } 399 }
379 400
380 private int getTabsMovedIllustration() { 401 private int getTabsMovedIllustration() {
381 switch (Build.MANUFACTURER.toLowerCase(Locale.US)) { 402 switch (Build.MANUFACTURER.toLowerCase(Locale.US)) {
382 case "samsung": 403 case "samsung":
383 if (DocumentModeManager.isDeviceTabbedModeByDefault()) return 0; 404 if (DocumentModeManager.isDeviceTabbedModeByDefault()) return 0;
384 return R.drawable.tabs_moved_samsung; 405 return R.drawable.tabs_moved_samsung;
385 case "htc": 406 case "htc":
386 return R.drawable.tabs_moved_htc; 407 return R.drawable.tabs_moved_htc;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 }); 458 });
438 mManager.optOutPromoShown(); 459 mManager.optOutPromoShown();
439 } 460 }
440 461
441 private void updateSearchBoxOnScroll() { 462 private void updateSearchBoxOnScroll() {
442 if (mDisableUrlFocusChangeAnimations) return; 463 if (mDisableUrlFocusChangeAnimations) return;
443 464
444 float percentage = 0; 465 float percentage = 0;
445 // During startup the view may not be fully initialized, so we only calc ulate the current 466 // During startup the view may not be fully initialized, so we only calc ulate the current
446 // percentage if some basic view properties are sane. 467 // percentage if some basic view properties are sane.
447 if (mScrollView.getHeight() != 0 && mSearchBoxView.getTop() != 0) { 468 if (mAreSnippetsEnabled) {
newt (away) 2016/03/24 19:47:39 lines 468-478 need more de-duplication. The only d
dgn 2016/03/28 21:33:02 Done.
448 int scrollY = mScrollView.getScrollY(); 469 if (mRecyclerView.getHeight() != 0 && mSearchBoxView.getTop() != 0) {
449 percentage = Math.max( 470 int scrollY = getVerticalScroll();
450 0f, Math.min(1f, scrollY / (float) mSearchBoxView.getTop())) ; 471 percentage = Math.max(0f, Math.min(1f, scrollY / (float) mSearch BoxView.getTop()));
472 }
473 } else {
474 if (mScrollView.getHeight() != 0 && mSearchBoxView.getTop() != 0) {
475 int scrollY = getVerticalScroll();
476 percentage = Math.max(0f, Math.min(1f, scrollY / (float) mSearch BoxView.getTop()));
477 }
451 } 478 }
452 479
453 updateVisualsForToolbarTransition(percentage); 480 updateVisualsForToolbarTransition(percentage);
454 481
455 if (mSearchBoxScrollListener != null) { 482 if (mSearchBoxScrollListener != null) {
456 mSearchBoxScrollListener.onNtpScrollChanged(percentage); 483 mSearchBoxScrollListener.onNtpScrollChanged(percentage);
457 } 484 }
458 } 485 }
459 486
487 private void initializeSearchBoxRecyclerViewScrollHandling() {
488 mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
489 @Override
490 public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
491 updateSearchBoxOnScroll();
492 }
493 });
494 }
495
460 private void initializeSearchBoxScrollHandling() { 496 private void initializeSearchBoxScrollHandling() {
461 final Runnable mSnapScrollRunnable = new Runnable() { 497 final Runnable mSnapScrollRunnable = new Runnable() {
462 @Override 498 @Override
463 public void run() { 499 public void run() {
464 if (!mPendingSnapScroll) return; 500 if (!mPendingSnapScroll) return;
465 int scrollY = mScrollView.getScrollY(); 501 int scrollY = mScrollView.getScrollY();
466 int dividerTop = mMostVisitedLayout.getTop() - mContentView.getP addingTop(); 502 int dividerTop = mMostVisitedLayout.getTop() - mContentView.getP addingTop();
467 if (scrollY > 0 && scrollY < dividerTop) { 503 if (scrollY > 0 && scrollY < dividerTop) {
468 mScrollView.smoothScrollTo(0, scrollY < (dividerTop / 2) ? 0 : dividerTop); 504 mScrollView.smoothScrollTo(0, scrollY < (dividerTop / 2) ? 0 : dividerTop);
469 } 505 }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 float getUrlFocusChangeAnimationPercent() { 658 float getUrlFocusChangeAnimationPercent() {
623 return mUrlFocusChangePercent; 659 return mUrlFocusChangePercent;
624 } 660 }
625 661
626 /** 662 /**
627 * Unconditionally sets the percentage the URL is focused during an animatio n, without updating 663 * Unconditionally sets the percentage the URL is focused during an animatio n, without updating
628 * mUrlFocusChangePercent. 664 * mUrlFocusChangePercent.
629 * @see #setUrlFocusChangeAnimationPercent 665 * @see #setUrlFocusChangeAnimationPercent
630 */ 666 */
631 private void setUrlFocusChangeAnimationPercentInternal(float percent) { 667 private void setUrlFocusChangeAnimationPercentInternal(float percent) {
632 mContentView.setTranslationY(percent * (-mMostVisitedLayout.getTop() 668 int scrollOffset = mAreSnippetsEnabled ? mRecyclerView.computeVerticalSc rollOffset()
633 + mScrollView.getScrollY() + mContentView.getPaddingTop())); 669 : mScrollView.getScrollY();
670 mContentView.setTranslationY(percent
671 * (-mMostVisitedLayout.getTop() + scrollOffset + mContentView.ge tPaddingTop()));
634 updateVisualsForToolbarTransition(percent); 672 updateVisualsForToolbarTransition(percent);
635 } 673 }
636 674
637 private void updateVisualsForToolbarTransition(float transitionPercentage) { 675 private void updateVisualsForToolbarTransition(float transitionPercentage) {
638 // Complete the full alpha transition in the first 40% of the animation. 676 // Complete the full alpha transition in the first 40% of the animation.
639 float searchUiAlpha = 677 float searchUiAlpha =
640 transitionPercentage >= 0.4f ? 0f : (0.4f - transitionPercentage ) * 2.5f; 678 transitionPercentage >= 0.4f ? 0f : (0.4f - transitionPercentage ) * 2.5f;
641 // Ensure there are no rounding issues when the animation percent is 0. 679 // Ensure there are no rounding issues when the animation percent is 0.
642 if (transitionPercentage == 0f) searchUiAlpha = 1f; 680 if (transitionPercentage == 0f) searchUiAlpha = 1f;
643 681
(...skipping 15 matching lines...) Expand all
659 void getSearchBoxBounds(Rect originalBounds, Rect transformedBounds) { 697 void getSearchBoxBounds(Rect originalBounds, Rect transformedBounds) {
660 int searchBoxX = (int) mSearchBoxView.getX(); 698 int searchBoxX = (int) mSearchBoxView.getX();
661 int searchBoxY = (int) mSearchBoxView.getY(); 699 int searchBoxY = (int) mSearchBoxView.getY();
662 originalBounds.set( 700 originalBounds.set(
663 searchBoxX + mSearchBoxView.getPaddingLeft(), 701 searchBoxX + mSearchBoxView.getPaddingLeft(),
664 searchBoxY + mSearchBoxView.getPaddingTop(), 702 searchBoxY + mSearchBoxView.getPaddingTop(),
665 searchBoxX + mSearchBoxView.getWidth() - mSearchBoxView.getPaddi ngRight(), 703 searchBoxX + mSearchBoxView.getWidth() - mSearchBoxView.getPaddi ngRight(),
666 searchBoxY + mSearchBoxView.getHeight() - mSearchBoxView.getPadd ingBottom()); 704 searchBoxY + mSearchBoxView.getHeight() - mSearchBoxView.getPadd ingBottom());
667 705
668 transformedBounds.set(originalBounds); 706 transformedBounds.set(originalBounds);
707
669 View view = (View) mSearchBoxView.getParent(); 708 View view = (View) mSearchBoxView.getParent();
670 while (view != null) { 709 while (view != null) {
671 transformedBounds.offset(-view.getScrollX(), -view.getScrollY()); 710 if (view instanceof RecyclerView) {
711 transformedBounds.offset(-((RecyclerView) view).computeHorizonta lScrollOffset(),
712 -((RecyclerView) view).computeVerticalScrollOffset());
713 } else {
714 transformedBounds.offset(-view.getScrollX(), -view.getScrollY()) ;
715 }
672 if (view == this) break; 716 if (view == this) break;
673 transformedBounds.offset((int) view.getX(), (int) view.getY()); 717 transformedBounds.offset((int) view.getX(), (int) view.getY());
674 view = (View) view.getParent(); 718 view = (View) view.getParent();
675 } 719 }
676 } 720 }
677 721
678 /** 722 /**
679 * Sets the listener for search box scroll changes. 723 * Sets the listener for search box scroll changes.
680 * @param listener The listener to be notified on changes. 724 * @param listener The listener to be notified on changes.
681 */ 725 */
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 @Override 760 @Override
717 protected void onWindowVisibilityChanged(int visibility) { 761 protected void onWindowVisibilityChanged(int visibility) {
718 super.onWindowVisibilityChanged(visibility); 762 super.onWindowVisibilityChanged(visibility);
719 763
720 if (visibility == VISIBLE) { 764 if (visibility == VISIBLE) {
721 updateVoiceSearchButtonVisibility(); 765 updateVoiceSearchButtonVisibility();
722 } 766 }
723 } 767 }
724 768
725 @Override 769 @Override
726 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 770 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
newt (away) 2016/03/24 19:47:39 This method should be deleted and the remainder of
dgn 2016/03/28 21:33:02 Done. I'm not familiar with the layout mechanisms
727 super.onMeasure(widthMeasureSpec, heightMeasureSpec); 771 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
728 772
729 // Make the search box and logo the same width as the most visited tiles . 773 // Make the search box and logo the same width as the most visited tiles .
730 if (mMostVisitedLayout.getVisibility() != GONE) { 774 if (mMostVisitedLayout.getVisibility() != GONE) {
731 int mostVisitedWidth = MeasureSpec.makeMeasureSpec(mMostVisitedLayou t.getMeasuredWidth() 775 mContentView.setMostVisitedWidth(mMostVisitedLayout.getMeasuredWidth ()
732 - mMostVisitedDesign.getMostVisitedLayoutBleed(), MeasureSpe c.EXACTLY); 776 - mMostVisitedDesign.getMostVisitedLayoutBleed());
733 int searchBoxHeight = MeasureSpec.makeMeasureSpec(
734 mSearchBoxView.getMeasuredHeight(), MeasureSpec.EXACTLY);
735 int logoHeight = MeasureSpec.makeMeasureSpec(
736 mSearchProviderLogoView.getMeasuredHeight(), MeasureSpec.EXA CTLY);
737 mSearchBoxView.measure(mostVisitedWidth, searchBoxHeight);
738 mSearchProviderLogoView.measure(mostVisitedWidth, logoHeight);
739 } 777 }
May 2016/03/24 07:21:20 To whoever takes over this CL: This needs an else
dgn 2016/03/25 16:29:20 Done.
740 } 778 }
741 779
742 /** 780 /**
743 * @see org.chromium.chrome.browser.compositor.layouts.content. 781 * @see org.chromium.chrome.browser.compositor.layouts.content.
744 * InvalidationAwareThumbnailProvider#shouldCaptureThumbnail() 782 * InvalidationAwareThumbnailProvider#shouldCaptureThumbnail()
745 */ 783 */
746 boolean shouldCaptureThumbnail() { 784 boolean shouldCaptureThumbnail() {
747 if (getWidth() == 0 || getHeight() == 0) return false; 785 if (getWidth() == 0 || getHeight() == 0) return false;
748 786
749 return mSnapshotMostVisitedChanged 787 return mSnapshotMostVisitedChanged || getWidth() != mSnapshotWidth
750 || getWidth() != mSnapshotWidth 788 || getHeight() != mSnapshotHeight || getVerticalScroll() != mSna pshotScrollY;
751 || getHeight() != mSnapshotHeight
752 || mScrollView.getScrollY() != mSnapshotScrollY;
753 } 789 }
754 790
755 /** 791 /**
756 * @see org.chromium.chrome.browser.compositor.layouts.content. 792 * @see org.chromium.chrome.browser.compositor.layouts.content.
757 * InvalidationAwareThumbnailProvider#captureThumbnail(Canvas) 793 * InvalidationAwareThumbnailProvider#captureThumbnail(Canvas)
758 */ 794 */
759 void captureThumbnail(Canvas canvas) { 795 void captureThumbnail(Canvas canvas) {
760 mSearchProviderLogoView.endFadeAnimation(); 796 mSearchProviderLogoView.endFadeAnimation();
761 ViewUtils.captureBitmap(this, canvas); 797 ViewUtils.captureBitmap(this, canvas);
762 mSnapshotWidth = getWidth(); 798 mSnapshotWidth = getWidth();
763 mSnapshotHeight = getHeight(); 799 mSnapshotHeight = getHeight();
764 mSnapshotScrollY = mScrollView.getScrollY(); 800 mSnapshotScrollY = getVerticalScroll();
765 mSnapshotMostVisitedChanged = false; 801 mSnapshotMostVisitedChanged = false;
766 } 802 }
767 803
768 // OnLayoutChangeListener overrides 804 // OnLayoutChangeListener overrides
769 805
770 @Override 806 @Override
771 public void onLayoutChange(View v, int left, int top, int right, int bottom, 807 public void onLayoutChange(View v, int left, int top, int right, int bottom,
772 int oldLeft, int oldTop, int oldRight, int oldBottom) { 808 int oldLeft, int oldTop, int oldRight, int oldBottom) {
773 int oldWidth = oldRight - oldLeft; 809 int oldWidth = oldRight - oldLeft;
774 int newWidth = right - left; 810 int newWidth = right - left;
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 for (MostVisitedItem item : mMostVisitedItems) { 1054 for (MostVisitedItem item : mMostVisitedItems) {
1019 if (item.getUrl().equals(url)) { 1055 if (item.getUrl().equals(url)) {
1020 LargeIconCallback iconCallback = new LargeIconCallbackImpl( 1056 LargeIconCallback iconCallback = new LargeIconCallbackImpl(
1021 item, (MostVisitedItemView) item.getView(), false); 1057 item, (MostVisitedItemView) item.getView(), false);
1022 mManager.getLargeIconForUrl(url, mMinIconSize, iconCallback) ; 1058 mManager.getLargeIconForUrl(url, mMinIconSize, iconCallback) ;
1023 break; 1059 break;
1024 } 1060 }
1025 } 1061 }
1026 } 1062 }
1027 } 1063 }
1064
1065 private int getVerticalScroll() {
1066 if (mAreSnippetsEnabled) {
1067 return mRecyclerView.computeVerticalScrollOffset();
1068 } else {
1069 return mScrollView.getScrollY();
1070 }
1071 }
1028 } 1072 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698