OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.suggestions; | 5 package org.chromium.chrome.browser.suggestions; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.res.Resources; | 8 import android.content.res.Resources; |
9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
10 import android.graphics.BitmapFactory; | 10 import android.graphics.BitmapFactory; |
11 import android.graphics.Color; | 11 import android.graphics.Color; |
12 import android.graphics.drawable.BitmapDrawable; | 12 import android.graphics.drawable.BitmapDrawable; |
13 import android.support.annotation.Nullable; | 13 import android.support.annotation.Nullable; |
14 import android.support.v4.graphics.drawable.RoundedBitmapDrawable; | 14 import android.support.v4.graphics.drawable.RoundedBitmapDrawable; |
15 import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory; | 15 import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory; |
16 import android.view.ContextMenu; | 16 import android.view.ContextMenu; |
17 import android.view.ContextMenu.ContextMenuInfo; | 17 import android.view.ContextMenu.ContextMenuInfo; |
18 import android.view.LayoutInflater; | 18 import android.view.LayoutInflater; |
19 import android.view.View; | 19 import android.view.View; |
20 import android.view.View.OnClickListener; | 20 import android.view.View.OnClickListener; |
21 import android.view.View.OnCreateContextMenuListener; | 21 import android.view.View.OnCreateContextMenuListener; |
22 import android.view.ViewGroup; | 22 import android.view.ViewGroup; |
23 | 23 |
24 import org.chromium.base.ApiCompatibilityUtils; | 24 import org.chromium.base.ApiCompatibilityUtils; |
25 import org.chromium.base.Log; | 25 import org.chromium.base.Log; |
| 26 import org.chromium.base.VisibleForTesting; |
26 import org.chromium.chrome.R; | 27 import org.chromium.chrome.R; |
27 import org.chromium.chrome.browser.ChromeFeatureList; | 28 import org.chromium.chrome.browser.ChromeFeatureList; |
28 import org.chromium.chrome.browser.favicon.LargeIconBridge.LargeIconCallback; | 29 import org.chromium.chrome.browser.favicon.LargeIconBridge.LargeIconCallback; |
29 import org.chromium.chrome.browser.ntp.ContextMenuManager; | 30 import org.chromium.chrome.browser.ntp.ContextMenuManager; |
30 import org.chromium.chrome.browser.ntp.ContextMenuManager.ContextMenuItemId; | 31 import org.chromium.chrome.browser.ntp.ContextMenuManager.ContextMenuItemId; |
31 import org.chromium.chrome.browser.ntp.MostVisitedTileType; | 32 import org.chromium.chrome.browser.ntp.MostVisitedTileType; |
32 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; | 33 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; |
33 import org.chromium.chrome.browser.widget.RoundedIconGenerator; | 34 import org.chromium.chrome.browser.widget.RoundedIconGenerator; |
34 import org.chromium.ui.mojom.WindowOpenDisposition; | 35 import org.chromium.ui.mojom.WindowOpenDisposition; |
35 | 36 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 oldTileViews.put(tileView.getUrl(), tileView); | 255 oldTileViews.put(tileView.getUrl(), tileView); |
255 } | 256 } |
256 | 257 |
257 // Remove all views from the layout because even if they are reused late
r they'll have to be | 258 // Remove all views from the layout because even if they are reused late
r they'll have to be |
258 // added back in the correct order. | 259 // added back in the correct order. |
259 tileGridLayout.removeAllViews(); | 260 tileGridLayout.removeAllViews(); |
260 | 261 |
261 for (Tile tile : mTiles) { | 262 for (Tile tile : mTiles) { |
262 TileView tileView = oldTileViews.get(tile.getUrl()); | 263 TileView tileView = oldTileViews.get(tile.getUrl()); |
263 if (tileView == null) { | 264 if (tileView == null) { |
264 tileView = buildTileView( | 265 tileView = buildTileView(tile, tileGridLayout, trackLoadTasks, c
ondensed); |
265 tile, tileGridLayout, trackLoadTasks, mTitleLinesCount,
condensed); | |
266 } else { | 266 } else { |
267 tileView.updateIfDataChanged(tile); | 267 tileView.updateIfDataChanged(tile); |
268 } | 268 } |
269 | 269 |
270 tileGridLayout.addView(tileView); | 270 tileGridLayout.addView(tileView); |
271 } | 271 } |
272 } | 272 } |
273 | 273 |
274 public Tile[] getTiles() { | 274 public Tile[] getTiles() { |
275 return Arrays.copyOf(mTiles, mTiles.length); | 275 return Arrays.copyOf(mTiles, mTiles.length); |
276 } | 276 } |
277 | 277 |
278 public boolean hasReceivedData() { | 278 public boolean hasReceivedData() { |
279 return mHasReceivedData; | 279 return mHasReceivedData; |
280 } | 280 } |
281 | 281 |
282 /** | 282 /** |
283 * Inflates a new tile view, initializes it, and loads an icon for it. | 283 * Inflates a new tile view, initializes it, and loads an icon for it. |
284 * @param tile The tile that holds the data to populate the new tile view. | 284 * @param tile The tile that holds the data to populate the new tile view. |
285 * @param parentView The parent of the new tile view. | 285 * @param parentView The parent of the new tile view. |
286 * @param trackLoadTask Whether to track a load task. | 286 * @param trackLoadTask Whether to track a load task. |
287 * @param titleLines The number of text lines to use for each tile title. | |
288 * @param condensed Whether to use a condensed layout. | 287 * @param condensed Whether to use a condensed layout. |
289 * @return The new tile view. | 288 * @return The new tile view. |
290 */ | 289 */ |
291 private TileView buildTileView(Tile tile, ViewGroup parentView, boolean trac
kLoadTask, | 290 @VisibleForTesting |
292 int titleLines, boolean condensed) { | 291 TileView buildTileView( |
| 292 Tile tile, ViewGroup parentView, boolean trackLoadTask, boolean cond
ensed) { |
293 TileView tileView = (TileView) LayoutInflater.from(parentView.getContext
()) | 293 TileView tileView = (TileView) LayoutInflater.from(parentView.getContext
()) |
294 .inflate(R.layout.tile_view, parentView, fal
se); | 294 .inflate(R.layout.tile_view, parentView, fal
se); |
295 tileView.initialize(tile, titleLines, condensed); | 295 tileView.initialize(tile, mTitleLinesCount, condensed); |
296 | 296 |
297 // Note: It is important that the callbacks below don't keep a reference
to the tile or | 297 // Note: It is important that the callbacks below don't keep a reference
to the tile or |
298 // modify them as there is no guarantee that the same tile would be used
to update the view. | 298 // modify them as there is no guarantee that the same tile would be used
to update the view. |
299 LargeIconCallback iconCallback = new LargeIconCallbackImpl(tile.getUrl()
, trackLoadTask); | 299 LargeIconCallback iconCallback = new LargeIconCallbackImpl(tile.getUrl()
, trackLoadTask); |
300 if (trackLoadTask) mObserver.onLoadTaskAdded(); | 300 if (trackLoadTask) mObserver.onLoadTaskAdded(); |
301 if (!loadWhitelistIcon(tile, iconCallback)) { | 301 if (!loadWhitelistIcon(tile, iconCallback)) { |
302 mUiDelegate.getLargeIconForUrl(tile.getUrl(), mMinIconSize, iconCall
back); | 302 mUiDelegate.getLargeIconForUrl(tile.getUrl(), mMinIconSize, iconCall
back); |
303 } | 303 } |
304 | 304 |
305 TileInteractionDelegate delegate = new TileInteractionDelegate(tile.getU
rl()); | 305 TileInteractionDelegate delegate = new TileInteractionDelegate(tile.getU
rl()); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 if (oldOfflineAvailable == tile.isOfflineAvailable()) return; | 442 if (oldOfflineAvailable == tile.isOfflineAvailable()) return; |
443 mObserver.onTileOfflineBadgeVisibilityChanged(tile); | 443 mObserver.onTileOfflineBadgeVisibilityChanged(tile); |
444 } | 444 } |
445 | 445 |
446 @Override | 446 @Override |
447 public Iterable<Tile> getOfflinableSuggestions() { | 447 public Iterable<Tile> getOfflinableSuggestions() { |
448 return Arrays.asList(mTiles); | 448 return Arrays.asList(mTiles); |
449 } | 449 } |
450 } | 450 } |
451 } | 451 } |
OLD | NEW |