Bug 1307621 - Use the original size if the downloaded favicon is not big enough. r=sebastian
MozReview-Commit-ID: 53U8bjNDMOI
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -1948,30 +1948,55 @@ public abstract class GeckoApp
// draw the overlay
Bitmap overlay = BitmapUtils.decodeResource(this, R.drawable.home_bg);
canvas.drawBitmap(overlay, null, new Rect(0, 0, size, size), null);
// draw the favicon
if (aSource == null)
aSource = BitmapUtils.decodeResource(this, R.drawable.home_star);
- // by default, we scale the icon to this size
+
+ // use the original size if the downloaded favicon is not big enough. (bug 1307621)
+ if (aSource.getWidth() < insetSize || aSource.getHeight() < insetSize) {
+ drawCenter(aSource, size, canvas);
+
+ } else {
+
+ // by default, we scale the icon to this size
+ drawScaleToFill(aSource, size, insetSize, canvas);
+ }
+ return bitmap;
+ }
+
+ private void drawScaleToFill(Bitmap aSource, int size, int insetSize, Canvas canvas) {
+
int sWidth = insetSize / 2;
int sHeight = sWidth;
-
int halfSize = size / 2;
+
canvas.drawBitmap(aSource,
null,
new Rect(halfSize - sWidth,
halfSize - sHeight,
halfSize + sWidth,
halfSize + sHeight),
null);
-
- return bitmap;
+ }
+
+ private void drawCenter(Bitmap aSource, int size, Canvas canvas) {
+
+ int left = size / 2 - aSource.getWidth() / 2;
+ int top = size / 2 - aSource.getHeight() / 2;
+ int right = left + aSource.getWidth();
+ int bottom = top + aSource.getHeight();
+
+ canvas.drawBitmap(aSource,
+ null,
+ new Rect(left, top, right, bottom),
+ null);
}
@Override
protected void onNewIntent(Intent externalIntent) {
final SafeIntent intent = new SafeIntent(externalIntent);
final boolean isFirstTab = !mWasFirstTabShownAfterActivityUnhidden;
mWasFirstTabShownAfterActivityUnhidden = true; // Reset since we'll be loading a tab.