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; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 public void startObserving(int maxResults) { | 235 public void startObserving(int maxResults) { |
236 mObserver.onLoadTaskAdded(); | 236 mObserver.onLoadTaskAdded(); |
237 mTileGroupDelegate.setMostVisitedSitesObserver(this, maxResults); | 237 mTileGroupDelegate.setMostVisitedSitesObserver(this, maxResults); |
238 } | 238 } |
239 | 239 |
240 /** | 240 /** |
241 * Renders tile views in the given {@link TileGridLayout}, reusing existing
tile views where | 241 * Renders tile views in the given {@link TileGridLayout}, reusing existing
tile views where |
242 * possible because view inflation and icon loading are slow. | 242 * possible because view inflation and icon loading are slow. |
243 * @param tileGridLayout The layout to render the tile views into. | 243 * @param tileGridLayout The layout to render the tile views into. |
244 * @param trackLoadTasks Whether to track load tasks. | 244 * @param trackLoadTasks Whether to track load tasks. |
| 245 * @param condensed Whether to use a condensed layout. |
245 */ | 246 */ |
246 public void renderTileViews(TileGridLayout tileGridLayout, boolean trackLoad
Tasks) { | 247 public void renderTileViews( |
| 248 TileGridLayout tileGridLayout, boolean trackLoadTasks, boolean conde
nsed) { |
247 // Map the old tile views by url so they can be reused later. | 249 // Map the old tile views by url so they can be reused later. |
248 Map<String, TileView> oldTileViews = new HashMap<>(); | 250 Map<String, TileView> oldTileViews = new HashMap<>(); |
249 int childCount = tileGridLayout.getChildCount(); | 251 int childCount = tileGridLayout.getChildCount(); |
250 for (int i = 0; i < childCount; i++) { | 252 for (int i = 0; i < childCount; i++) { |
251 TileView tileView = (TileView) tileGridLayout.getChildAt(i); | 253 TileView tileView = (TileView) tileGridLayout.getChildAt(i); |
252 oldTileViews.put(tileView.getUrl(), tileView); | 254 oldTileViews.put(tileView.getUrl(), tileView); |
253 } | 255 } |
254 | 256 |
255 // Remove all views from the layout because even if they are reused late
r they'll have to be | 257 // Remove all views from the layout because even if they are reused late
r they'll have to be |
256 // added back in the correct order. | 258 // added back in the correct order. |
257 tileGridLayout.removeAllViews(); | 259 tileGridLayout.removeAllViews(); |
258 | 260 |
259 for (Tile tile : mTiles) { | 261 for (Tile tile : mTiles) { |
260 TileView tileView = oldTileViews.get(tile.getUrl()); | 262 TileView tileView = oldTileViews.get(tile.getUrl()); |
261 if (tileView == null) { | 263 if (tileView == null) { |
262 tileView = buildTileView(tile, tileGridLayout, trackLoadTasks, m
TitleLinesCount); | 264 tileView = buildTileView( |
| 265 tile, tileGridLayout, trackLoadTasks, mTitleLinesCount,
condensed); |
263 } else { | 266 } else { |
264 tileView.updateIfDataChanged(tile); | 267 tileView.updateIfDataChanged(tile); |
265 } | 268 } |
266 | 269 |
267 tileGridLayout.addView(tileView); | 270 tileGridLayout.addView(tileView); |
268 } | 271 } |
269 } | 272 } |
270 | 273 |
271 public Tile[] getTiles() { | 274 public Tile[] getTiles() { |
272 return Arrays.copyOf(mTiles, mTiles.length); | 275 return Arrays.copyOf(mTiles, mTiles.length); |
273 } | 276 } |
274 | 277 |
275 public boolean hasReceivedData() { | 278 public boolean hasReceivedData() { |
276 return mHasReceivedData; | 279 return mHasReceivedData; |
277 } | 280 } |
278 | 281 |
279 /** | 282 /** |
280 * 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. |
281 * @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. |
282 * @param parentView The parent of the new tile view. | 285 * @param parentView The parent of the new tile view. |
283 * @param trackLoadTask Whether to track a load task. | 286 * @param trackLoadTask Whether to track a load task. |
284 * @param titleLines The number of text lines to use for each tile title. | 287 * @param titleLines The number of text lines to use for each tile title. |
| 288 * @param condensed Whether to use a condensed layout. |
285 * @return The new tile view. | 289 * @return The new tile view. |
286 */ | 290 */ |
287 private TileView buildTileView( | 291 private TileView buildTileView(Tile tile, ViewGroup parentView, boolean trac
kLoadTask, |
288 Tile tile, ViewGroup parentView, boolean trackLoadTask, int titleLin
es) { | 292 int titleLines, boolean condensed) { |
289 TileView tileView = (TileView) LayoutInflater.from(parentView.getContext
()) | 293 TileView tileView = (TileView) LayoutInflater.from(parentView.getContext
()) |
290 .inflate(R.layout.tile_view, parentView, fal
se); | 294 .inflate(R.layout.tile_view, parentView, fal
se); |
291 tileView.initialize(tile, titleLines); | 295 tileView.initialize(tile, titleLines, condensed); |
292 | 296 |
293 // 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 |
294 // 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. |
295 LargeIconCallback iconCallback = new LargeIconCallbackImpl(tile.getUrl()
, trackLoadTask); | 299 LargeIconCallback iconCallback = new LargeIconCallbackImpl(tile.getUrl()
, trackLoadTask); |
296 if (trackLoadTask) mObserver.onLoadTaskAdded(); | 300 if (trackLoadTask) mObserver.onLoadTaskAdded(); |
297 if (!loadWhitelistIcon(tile, iconCallback)) { | 301 if (!loadWhitelistIcon(tile, iconCallback)) { |
298 mUiDelegate.getLargeIconForUrl(tile.getUrl(), mMinIconSize, iconCall
back); | 302 mUiDelegate.getLargeIconForUrl(tile.getUrl(), mMinIconSize, iconCall
back); |
299 } | 303 } |
300 | 304 |
301 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... |
438 if (oldOfflineAvailable == tile.isOfflineAvailable()) return; | 442 if (oldOfflineAvailable == tile.isOfflineAvailable()) return; |
439 mObserver.onTileOfflineBadgeVisibilityChanged(tile); | 443 mObserver.onTileOfflineBadgeVisibilityChanged(tile); |
440 } | 444 } |
441 | 445 |
442 @Override | 446 @Override |
443 public Iterable<Tile> getOfflinableSuggestions() { | 447 public Iterable<Tile> getOfflinableSuggestions() { |
444 return Arrays.asList(mTiles); | 448 return Arrays.asList(mTiles); |
445 } | 449 } |
446 } | 450 } |
447 } | 451 } |
OLD | NEW |