| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 public void startObserving(int maxResults) { | 186 public void startObserving(int maxResults) { |
| 187 mTileGroupDelegate.setMostVisitedSitesObserver(this, maxResults); | 187 mTileGroupDelegate.setMostVisitedSitesObserver(this, maxResults); |
| 188 } | 188 } |
| 189 | 189 |
| 190 /** | 190 /** |
| 191 * Renders tile views in the given {@link TileGridLayout}, reusing existing
tile views where | 191 * Renders tile views in the given {@link TileGridLayout}, reusing existing
tile views where |
| 192 * possible because view inflation and icon loading are slow. | 192 * possible because view inflation and icon loading are slow. |
| 193 * @param tileGridLayout The layout to render the tile views into. | 193 * @param tileGridLayout The layout to render the tile views into. |
| 194 * @param trackLoadTasks Whether to track load tasks. | 194 * @param trackLoadTasks Whether to track load tasks. |
| 195 * @param titleLines The number of text lines to use for each tile title. | 195 * @param titleLines The number of text lines to use for each tile title. |
| 196 * @param condensed Whether to use a condensed layout. |
| 196 */ | 197 */ |
| 197 public void renderTileViews( | 198 public void renderTileViews(TileGridLayout tileGridLayout, boolean trackLoad
Tasks, |
| 198 TileGridLayout tileGridLayout, boolean trackLoadTasks, int titleLine
s) { | 199 int titleLines, boolean condensed) { |
| 199 // Map the old tile views by url so they can be reused later. | 200 // Map the old tile views by url so they can be reused later. |
| 200 Map<String, TileView> oldTileViews = new HashMap<>(); | 201 Map<String, TileView> oldTileViews = new HashMap<>(); |
| 201 int childCount = tileGridLayout.getChildCount(); | 202 int childCount = tileGridLayout.getChildCount(); |
| 202 for (int i = 0; i < childCount; i++) { | 203 for (int i = 0; i < childCount; i++) { |
| 203 TileView tileView = (TileView) tileGridLayout.getChildAt(i); | 204 TileView tileView = (TileView) tileGridLayout.getChildAt(i); |
| 204 oldTileViews.put(tileView.getTile().getUrl(), tileView); | 205 oldTileViews.put(tileView.getTile().getUrl(), tileView); |
| 205 } | 206 } |
| 206 | 207 |
| 207 // Remove all views from the layout because even if they are reused late
r they'll have to be | 208 // Remove all views from the layout because even if they are reused late
r they'll have to be |
| 208 // added back in the correct order. | 209 // added back in the correct order. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 222 | 223 |
| 223 tileGridLayout.addView(oldTileView); | 224 tileGridLayout.addView(oldTileView); |
| 224 | 225 |
| 225 // Re-render the icon because it may not have been painted w
hen re-added. | 226 // Re-render the icon because it may not have been painted w
hen re-added. |
| 226 oldTileView.renderIcon(); | 227 oldTileView.renderIcon(); |
| 227 continue; | 228 continue; |
| 228 } | 229 } |
| 229 } | 230 } |
| 230 | 231 |
| 231 // No view was reused, create a new one. | 232 // No view was reused, create a new one. |
| 232 TileView tileView = buildTileView(tile, tileGridLayout, trackLoadTas
ks, titleLines); | 233 TileView tileView = |
| 234 buildTileView(tile, tileGridLayout, trackLoadTasks, titleLin
es, condensed); |
| 233 | 235 |
| 234 tileView.setOnClickListener(new OnClickListener() { | 236 tileView.setOnClickListener(new OnClickListener() { |
| 235 @Override | 237 @Override |
| 236 public void onClick(View view) { | 238 public void onClick(View view) { |
| 237 mTileGroupDelegate.openMostVisitedItem(WindowOpenDisposition
.CURRENT_TAB, tile); | 239 mTileGroupDelegate.openMostVisitedItem(WindowOpenDisposition
.CURRENT_TAB, tile); |
| 238 } | 240 } |
| 239 }); | 241 }); |
| 240 | 242 |
| 241 tileView.setOnCreateContextMenuListener(new OnCreateContextMenuListe
ner() { | 243 tileView.setOnCreateContextMenuListener(new OnCreateContextMenuListe
ner() { |
| 242 @Override | 244 @Override |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 if (isInitialLoad) mObserver.onLoadTaskCompleted(); | 301 if (isInitialLoad) mObserver.onLoadTaskCompleted(); |
| 300 mObserver.onTileDataChanged(); | 302 mObserver.onTileDataChanged(); |
| 301 } | 303 } |
| 302 | 304 |
| 303 /** | 305 /** |
| 304 * Inflates a new tile view, initializes it, and loads an icon for it. | 306 * Inflates a new tile view, initializes it, and loads an icon for it. |
| 305 * @param tile The tile that holds the data to populate the new tile view. | 307 * @param tile The tile that holds the data to populate the new tile view. |
| 306 * @param parentView The parent of the new tile view. | 308 * @param parentView The parent of the new tile view. |
| 307 * @param trackLoadTask Whether to track a load task. | 309 * @param trackLoadTask Whether to track a load task. |
| 308 * @param titleLines The number of text lines to use for each tile title. | 310 * @param titleLines The number of text lines to use for each tile title. |
| 311 * @param condensed Whether to use a condensed layout. |
| 309 * @return The new tile view. | 312 * @return The new tile view. |
| 310 */ | 313 */ |
| 311 private TileView buildTileView( | 314 private TileView buildTileView(Tile tile, ViewGroup parentView, boolean trac
kLoadTask, |
| 312 Tile tile, ViewGroup parentView, boolean trackLoadTask, int titleLin
es) { | 315 int titleLines, boolean condensed) { |
| 313 TileView tileView = (TileView) LayoutInflater.from(parentView.getContext
()) | 316 TileView tileView = (TileView) LayoutInflater.from(parentView.getContext
()) |
| 314 .inflate(R.layout.tile_view, parentView, fal
se); | 317 .inflate(R.layout.tile_view, parentView, fal
se); |
| 315 tileView.initialize(tile, titleLines); | 318 tileView.initialize(tile, titleLines, condensed); |
| 316 | 319 |
| 317 LargeIconCallback iconCallback = new LargeIconCallbackImpl(tile, trackLo
adTask); | 320 LargeIconCallback iconCallback = new LargeIconCallbackImpl(tile, trackLo
adTask); |
| 318 if (trackLoadTask) mObserver.onLoadTaskAdded(); | 321 if (trackLoadTask) mObserver.onLoadTaskAdded(); |
| 319 if (!loadWhitelistIcon(tile, iconCallback)) { | 322 if (!loadWhitelistIcon(tile, iconCallback)) { |
| 320 mUiDelegate.getLargeIconForUrl(tile.getUrl(), mMinIconSize, iconCall
back); | 323 mUiDelegate.getLargeIconForUrl(tile.getUrl(), mMinIconSize, iconCall
back); |
| 321 } | 324 } |
| 322 | 325 |
| 323 return tileView; | 326 return tileView; |
| 324 } | 327 } |
| 325 | 328 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 roundedIcon.setAntiAlias(true); | 367 roundedIcon.setAntiAlias(true); |
| 365 roundedIcon.setFilterBitmap(true); | 368 roundedIcon.setFilterBitmap(true); |
| 366 mTile.setIcon(roundedIcon); | 369 mTile.setIcon(roundedIcon); |
| 367 mTile.setType(MostVisitedTileType.ICON_REAL); | 370 mTile.setType(MostVisitedTileType.ICON_REAL); |
| 368 } | 371 } |
| 369 mObserver.onTileIconChanged(mTile); | 372 mObserver.onTileIconChanged(mTile); |
| 370 if (mTrackLoadTask) mObserver.onLoadTaskCompleted(); | 373 if (mTrackLoadTask) mObserver.onLoadTaskCompleted(); |
| 371 } | 374 } |
| 372 } | 375 } |
| 373 } | 376 } |
| OLD | NEW |