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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 private View mMostVisitedPlaceholder; | 80 private View mMostVisitedPlaceholder; |
81 private View mOptOutView; | 81 private View mOptOutView; |
82 private View mNoSearchLogoSpacer; | 82 private View mNoSearchLogoSpacer; |
83 private RecyclerView mSnippetsView; | 83 private RecyclerView mSnippetsView; |
84 | 84 |
85 private OnSearchBoxScrollListener mSearchBoxScrollListener; | 85 private OnSearchBoxScrollListener mSearchBoxScrollListener; |
86 | 86 |
87 private NewTabPageManager mManager; | 87 private NewTabPageManager mManager; |
88 private MostVisitedDesign mMostVisitedDesign; | 88 private MostVisitedDesign mMostVisitedDesign; |
89 private MostVisitedItem[] mMostVisitedItems; | 89 private MostVisitedItem[] mMostVisitedItems; |
90 private SnippetsManager mSnippetsManager; | |
91 private boolean mFirstShow = true; | 90 private boolean mFirstShow = true; |
92 private boolean mSearchProviderHasLogo = true; | 91 private boolean mSearchProviderHasLogo = true; |
93 private boolean mHasReceivedMostVisitedSites; | 92 private boolean mHasReceivedMostVisitedSites; |
94 private boolean mPendingSnapScroll; | 93 private boolean mPendingSnapScroll; |
95 | 94 |
96 /** | 95 /** |
97 * The number of asynchronous tasks that need to complete before the page is
done loading. | 96 * The number of asynchronous tasks that need to complete before the page is
done loading. |
98 * This starts at one to track when the view is finished attaching to the wi
ndow. | 97 * This starts at one to track when the view is finished attaching to the wi
ndow. |
99 */ | 98 */ |
100 private int mPendingLoadTasks = 1; | 99 private int mPendingLoadTasks = 1; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 /** | 242 /** |
244 * Initializes the NTP. This must be called immediately after inflation, bef
ore this object is | 243 * Initializes the NTP. This must be called immediately after inflation, bef
ore this object is |
245 * used in any other way. | 244 * used in any other way. |
246 * | 245 * |
247 * @param manager NewTabPageManager used to perform various actions when the
user interacts | 246 * @param manager NewTabPageManager used to perform various actions when the
user interacts |
248 * with the page. | 247 * with the page. |
249 * @param isSingleUrlBarMode Whether the NTP is in single URL bar mode. | 248 * @param isSingleUrlBarMode Whether the NTP is in single URL bar mode. |
250 * @param searchProviderHasLogo Whether the search provider has a logo. | 249 * @param searchProviderHasLogo Whether the search provider has a logo. |
251 */ | 250 */ |
252 public void initialize(NewTabPageManager manager, boolean isSingleUrlBarMode
, | 251 public void initialize(NewTabPageManager manager, boolean isSingleUrlBarMode
, |
253 boolean searchProviderHasLogo) { | 252 boolean searchProviderHasLogo, SnippetsManager snippetsManager) { |
254 mManager = manager; | 253 mManager = manager; |
255 | 254 |
256 mScrollView = (NewTabScrollView) findViewById(R.id.ntp_scrollview); | 255 mScrollView = (NewTabScrollView) findViewById(R.id.ntp_scrollview); |
257 mScrollView.enableBottomShadow(SHADOW_COLOR); | 256 mScrollView.enableBottomShadow(SHADOW_COLOR); |
258 mContentView = (ViewGroup) findViewById(R.id.ntp_content); | 257 mContentView = (ViewGroup) findViewById(R.id.ntp_content); |
259 | 258 |
260 mMostVisitedDesign = new MostVisitedDesign(getContext()); | 259 mMostVisitedDesign = new MostVisitedDesign(getContext()); |
261 mMostVisitedLayout = (MostVisitedLayout) findViewById(R.id.most_visited_
layout); | 260 mMostVisitedLayout = (MostVisitedLayout) findViewById(R.id.most_visited_
layout); |
262 mMostVisitedDesign.initMostVisitedLayout(mMostVisitedLayout, searchProvi
derHasLogo); | 261 mMostVisitedDesign.initMostVisitedLayout(mMostVisitedLayout, searchProvi
derHasLogo); |
263 | 262 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 | 332 |
334 if (mManager.shouldShowOptOutPromo()) showOptOutPromo(); | 333 if (mManager.shouldShowOptOutPromo()) showOptOutPromo(); |
335 | 334 |
336 // Set up snippets | 335 // Set up snippets |
337 if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_NTP_SNIPPE
TS)) { | 336 if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_NTP_SNIPPE
TS)) { |
338 mSnippetsView = (RecyclerView) findViewById(R.id.snippets_card_list)
; | 337 mSnippetsView = (RecyclerView) findViewById(R.id.snippets_card_list)
; |
339 mSnippetsView.setVisibility(View.VISIBLE); | 338 mSnippetsView.setVisibility(View.VISIBLE); |
340 RecordHistogram.recordEnumeratedHistogram(SnippetsManager.SNIPPETS_S
TATE_HISTOGRAM, | 339 RecordHistogram.recordEnumeratedHistogram(SnippetsManager.SNIPPETS_S
TATE_HISTOGRAM, |
341 SnippetsManager.SNIPPETS_SHOWN, SnippetsManager.NUM_SNIPPETS
_ACTIONS); | 340 SnippetsManager.SNIPPETS_SHOWN, SnippetsManager.NUM_SNIPPETS
_ACTIONS); |
342 mSnippetsView.setLayoutManager(new LinearLayoutManager(getContext())
); | 341 mSnippetsView.setLayoutManager(new LinearLayoutManager(getContext())
); |
343 mSnippetsManager = new SnippetsManager(mManager, mSnippetsView); | |
344 mSnippetsView.addOnScrollListener(new RecyclerView.OnScrollListener(
) { | 342 mSnippetsView.addOnScrollListener(new RecyclerView.OnScrollListener(
) { |
345 private boolean mScrolledOnce = false; | 343 private boolean mScrolledOnce = false; |
346 @Override | 344 @Override |
347 public void onScrollStateChanged(RecyclerView recyclerView, int
newState) { | 345 public void onScrollStateChanged(RecyclerView recyclerView, int
newState) { |
348 if (newState != RecyclerView.SCROLL_STATE_DRAGGING) return; | 346 if (newState != RecyclerView.SCROLL_STATE_DRAGGING) return; |
349 RecordUserAction.record("MobileNTP.Snippets.Scrolled"); | 347 RecordUserAction.record("MobileNTP.Snippets.Scrolled"); |
350 if (mScrolledOnce) return; | 348 if (mScrolledOnce) return; |
351 mScrolledOnce = true; | 349 mScrolledOnce = true; |
352 RecordHistogram.recordEnumeratedHistogram( | 350 RecordHistogram.recordEnumeratedHistogram( |
353 SnippetsManager.SNIPPETS_STATE_HISTOGRAM, | 351 SnippetsManager.SNIPPETS_STATE_HISTOGRAM, |
354 SnippetsManager.SNIPPETS_SCROLLED, | 352 SnippetsManager.SNIPPETS_SCROLLED, |
355 SnippetsManager.NUM_SNIPPETS_ACTIONS); | 353 SnippetsManager.NUM_SNIPPETS_ACTIONS); |
356 } | 354 } |
357 }); | 355 }); |
| 356 snippetsManager.setSnippetsView(mSnippetsView); |
358 } | 357 } |
359 | 358 |
360 // Set up interests | 359 // Set up interests |
361 if (manager.isInterestsEnabled()) { | 360 if (manager.isInterestsEnabled()) { |
362 toolbar.getInterestsButton().setVisibility(View.VISIBLE); | 361 toolbar.getInterestsButton().setVisibility(View.VISIBLE); |
363 } | 362 } |
364 } | 363 } |
365 | 364 |
366 private int getTabsMovedIllustration() { | 365 private int getTabsMovedIllustration() { |
367 switch (Build.MANUFACTURER.toLowerCase(Locale.US)) { | 366 switch (Build.MANUFACTURER.toLowerCase(Locale.US)) { |
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
984 for (MostVisitedItem item : mMostVisitedItems) { | 983 for (MostVisitedItem item : mMostVisitedItems) { |
985 if (item.getUrl().equals(url)) { | 984 if (item.getUrl().equals(url)) { |
986 LargeIconCallback iconCallback = new LargeIconCallbackImpl(i
tem, false); | 985 LargeIconCallback iconCallback = new LargeIconCallbackImpl(i
tem, false); |
987 mManager.getLargeIconForUrl(url, mMinIconSize, iconCallback)
; | 986 mManager.getLargeIconForUrl(url, mMinIconSize, iconCallback)
; |
988 break; | 987 break; |
989 } | 988 } |
990 } | 989 } |
991 } | 990 } |
992 } | 991 } |
993 } | 992 } |
OLD | NEW |