Bug 808663 - Use large favicons in awesomebar if they're provided. r=bnicholson

This commit is contained in:
Wes Johnston 2012-11-15 19:16:35 -08:00
Родитель b0a473bc33
Коммит 19acca1828
3 изменённых файлов: 25 добавлений и 8 удалений

Просмотреть файл

@ -576,8 +576,13 @@ public class AllPagesTab extends AwesomeBarTab implements GeckoEventListener {
}
private Bitmap getBitmapFromDataURI(String dataURI) {
byte[] raw = Base64.decode(dataURI.substring(22), Base64.DEFAULT);
return BitmapFactory.decodeByteArray(raw, 0, raw.length);
try {
byte[] raw = Base64.decode(dataURI.substring(22), Base64.DEFAULT);
return BitmapFactory.decodeByteArray(raw, 0, raw.length);
} catch(Exception ex) {
Log.i(LOGTAG, "exception while decoding bitmap: " + dataURI, ex);
}
return null;
}
private void showSuggestionsOptIn() {

Просмотреть файл

@ -41,12 +41,16 @@ abstract public class AwesomeBarTab {
// FIXME: This value should probably come from a prefs key
public static final int MAX_RESULTS = 100;
protected Context mContext = null;
private static int sFaviconSize = -1;
private static int sFaviconSmallSize = -1;
private static int sFaviconLargeSize = -1;
public AwesomeBarTab(Context context) {
mContext = context;
if (sFaviconSize < 0) {
sFaviconSize = Math.round(mContext.getResources().getDimension(R.dimen.awesomebar_row_favicon_size));
if (sFaviconSmallSize < 0) {
sFaviconSmallSize = Math.round(mContext.getResources().getDimension(R.dimen.awesomebar_row_favicon_size_small));
}
if (sFaviconLargeSize < 0) {
sFaviconLargeSize = Math.round(mContext.getResources().getDimension(R.dimen.awesomebar_row_favicon_size_large));
}
}
@ -105,9 +109,16 @@ abstract public class AwesomeBarTab {
protected void updateFavicon(ImageView faviconView, Bitmap bitmap) {
if (bitmap == null) {
faviconView.setImageDrawable(null);
} else {
bitmap = Bitmap.createScaledBitmap(bitmap, sFaviconSize, sFaviconSize, false);
} else if (bitmap.getWidth() > 16 || bitmap.getHeight() > 16) {
// If the icon is larger than 16px, scale it to sFaviconLargeSize and hide the background
bitmap = Bitmap.createScaledBitmap(bitmap, sFaviconLargeSize, sFaviconLargeSize, false);
faviconView.setImageBitmap(bitmap);
faviconView.setBackgroundResource(0);
} else {
// If the icon is 16px or smaller, don't scale it up to full size
bitmap = Bitmap.createScaledBitmap(bitmap, sFaviconSmallSize, sFaviconSmallSize, false);
faviconView.setImageBitmap(bitmap);
faviconView.setBackgroundResource(R.drawable.awesomebar_row_favicon_bg);
}
}

Просмотреть файл

@ -15,7 +15,8 @@
<dimen name="autocomplete_row_height">32dp</dimen>
<dimen name="awesomebar_header_row_height">20dp</dimen>
<dimen name="awesomebar_row_height">48dp</dimen>
<dimen name="awesomebar_row_favicon_size">16dp</dimen>
<dimen name="awesomebar_row_favicon_size_small">16dp</dimen>
<dimen name="awesomebar_row_favicon_size_large">32dp</dimen>
<dimen name="awesomebar_row_favicon_bg">32dp</dimen>
<dimen name="awesomebar_row_favicon_bg_radius">1dp</dimen>
<dimen name="awesomebar_tab_transparency_height">38dp</dimen>