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

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

Issue 1772363002: Start using the whitelist icon on the NTP. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing newt's comments 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java
index 2cca3fb1a2b7b646c8b8d4206c1151b78f16b7a5..2da52ad55f00077278da2a0814bfbd660425c415 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java
@@ -8,6 +8,7 @@ import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
@@ -34,6 +35,7 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
+import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction;
@@ -68,6 +70,7 @@ public class NewTabPageView extends FrameLayout
private static final int SHADOW_COLOR = 0x11000000;
private static final long SNAP_SCROLL_DELAY_MS = 30;
+ private static final String TAG = "NewTabPageView";
private ViewGroup mContentView;
private NewTabScrollView mScrollView;
@@ -767,7 +770,8 @@ public class NewTabPageView extends FrameLayout
// MostVisitedURLsObserver implementation
@Override
- public void onMostVisitedURLsAvailable(String[] titles, String[] urls) {
+ public void onMostVisitedURLsAvailable(
+ String[] titles, String[] urls, String[] whitelistIconPaths) {
mMostVisitedLayout.removeAllViews();
MostVisitedItem[] oldItems = mMostVisitedItems;
@@ -781,6 +785,7 @@ public class NewTabPageView extends FrameLayout
for (int i = 0; i < titles.length; i++) {
final String url = urls[i];
final String title = titles[i];
+ final String whitelistIconPath = whitelistIconPaths[i];
boolean offlineAvailable = mManager.isOfflineAvailable(url);
// Look for an existing item to reuse.
@@ -789,7 +794,8 @@ public class NewTabPageView extends FrameLayout
MostVisitedItem oldItem = oldItems[j];
if (oldItem != null && TextUtils.equals(url, oldItem.getUrl())
&& TextUtils.equals(title, oldItem.getTitle())
- && offlineAvailable == oldItem.isOfflineAvailable()) {
+ && offlineAvailable == oldItem.isOfflineAvailable()
+ && whitelistIconPath.equals(oldItem.getWhitelistIconPath())) {
item = oldItem;
item.setIndex(i);
oldItems[j] = null;
@@ -799,7 +805,8 @@ public class NewTabPageView extends FrameLayout
// If nothing can be reused, create a new item.
if (item == null) {
- item = new MostVisitedItem(mManager, title, url, offlineAvailable, i);
+ item = new MostVisitedItem(
+ mManager, title, url, whitelistIconPath, offlineAvailable, i);
View view =
mMostVisitedDesign.createMostVisitedItemView(inflater, item, isInitialLoad);
item.initView(view);
@@ -971,11 +978,39 @@ public class NewTabPageView extends FrameLayout
LargeIconCallback iconCallback = new LargeIconCallbackImpl(item, isInitialLoad);
if (isInitialLoad) mPendingLoadTasks++;
- mManager.getLargeIconForUrl(item.getUrl(), mMinIconSize, iconCallback);
+ if (!setWhitelistIcon(item, view, isInitialLoad)) {
newt (away) 2016/03/16 18:06:33 For simplicity and to minimize differences in code
atanasova 2016/03/16 18:43:07 Done.
+ mManager.getLargeIconForUrl(item.getUrl(), mMinIconSize, iconCallback);
+ }
return view;
}
+ public boolean setWhitelistIcon(
newt (away) 2016/03/16 18:06:33 should be private
atanasova 2016/03/16 18:43:07 Done.
+ MostVisitedItem item, MostVisitedItemView view, boolean isInitialLoad) {
+ if (!item.getWhitelistIconPath().isEmpty()) {
Bernhard Bauer 2016/03/16 12:14:18 Invert these conditions to remove some levels of i
atanasova 2016/03/16 17:58:17 Done.
+ Bitmap bitmap = BitmapFactory.decodeFile(item.getWhitelistIconPath());
+ if (bitmap != null) {
+ RoundedBitmapDrawable roundedIcon =
+ RoundedBitmapDrawableFactory.create(getResources(), bitmap);
+ int cornerRadius = Math.round(ICON_CORNER_RADIUS_DP
+ * getResources().getDisplayMetrics().density * bitmap.getWidth()
+ / mDesiredIconSize);
+ roundedIcon.setCornerRadius(cornerRadius);
+ roundedIcon.setAntiAlias(true);
+ roundedIcon.setFilterBitmap(true);
+ view.setIcon(roundedIcon);
+ item.setTileType(MostVisitedTileType.ICON_REAL);
+
+ mSnapshotMostVisitedChanged = true;
+ if (isInitialLoad) loadTaskCompleted();
+ return true;
+ } else {
+ Log.d(TAG, "Image decoding failed: %s", item.getWhitelistIconPath());
+ }
+ }
+ return false;
+ }
+
public void onIconUpdated(final String url) {
if (mMostVisitedItems == null) return;
// Find a matching most visited item.

Powered by Google App Engine
This is Rietveld 408576698