diff --git a/mobile/android/base/Tab.java b/mobile/android/base/Tab.java index 97d7db68c2a..fd580d27beb 100644 --- a/mobile/android/base/Tab.java +++ b/mobile/android/base/Tab.java @@ -55,11 +55,13 @@ import java.util.List; public final class Tab { private static final String LOGTAG = "GeckoTab"; - private static final int kThumbnailWidth = 120; - private static final int kThumbnailHeight = 80; + private static final int kThumbnailWidth = 136; + private static final int kThumbnailHeight = 77; - private static int sMinDim = 0; + private static float sMinDim = 0; private static float sDensity = 1; + private static int sMinScreenshotWidth = 0; + private static int sMinScreenshotHeight = 0; private int mId; private String mUrl; private String mTitle; @@ -145,24 +147,73 @@ public final class Tab { return mThumbnail; } + void initMetrics() { + DisplayMetrics metrics = new DisplayMetrics(); + GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics); + sMinDim = Math.min(metrics.widthPixels / kThumbnailWidth, metrics.heightPixels / kThumbnailHeight); + sDensity = metrics.density; + } + + float getMinDim() { + if (sMinDim == 0) + initMetrics(); + return sMinDim; + } + + float getDensity() { + if (sDensity == 0.0f) + initMetrics(); + return sDensity; + } + + int getMinScreenshotWidth() { + if (sMinScreenshotWidth != 0) + return sMinScreenshotWidth; + return sMinScreenshotWidth = (int)(getMinDim() * kThumbnailWidth); + } + + int getMinScreenshotHeight() { + if (sMinScreenshotHeight != 0) + return sMinScreenshotHeight; + return sMinScreenshotHeight = (int)(getMinDim() * kThumbnailHeight); + } + + int getThumbnailWidth() { + return (int)(kThumbnailWidth * getDensity()); + } + + int getThumbnailHeight() { + return (int)(kThumbnailHeight * getDensity()); + } + public void updateThumbnail(final Bitmap b) { final Tab tab = this; GeckoAppShell.getHandler().post(new Runnable() { public void run() { - if (sMinDim == 0) { - DisplayMetrics metrics = new DisplayMetrics(); - GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics); - sMinDim = Math.min(metrics.widthPixels / 3, metrics.heightPixels / 2); - sDensity = metrics.density; - } if (b != null) { try { - Bitmap cropped = Bitmap.createBitmap(b, 0, 0, sMinDim * 3, sMinDim * 2); - Bitmap bitmap = Bitmap.createScaledBitmap(cropped, (int) (kThumbnailWidth * sDensity), (int) (kThumbnailHeight * sDensity), false); - saveThumbnailToDB(new BitmapDrawable(bitmap)); - b.recycle(); + Bitmap cropped = null; + /* Crop to screen width if the bitmap is larger than the screen width or height. If smaller and the + * the aspect ratio is correct, just use the bitmap as is. Otherwise, fit the smaller + * smaller dimension, then crop the larger dimention. + */ + if (getMinScreenshotWidth() < b.getWidth() && getMinScreenshotHeight() < b.getHeight()) + cropped = Bitmap.createBitmap(b, 0, 0, getMinScreenshotWidth(), getMinScreenshotHeight()); + else if (b.getWidth() * getMinScreenshotHeight() == b.getHeight() * getMinScreenshotWidth()) + cropped = b; + else if (b.getWidth() * getMinScreenshotHeight() < b.getHeight() * getMinScreenshotWidth()) + cropped = Bitmap.createBitmap(b, 0, 0, b.getWidth(), + b.getWidth() * getMinScreenshotHeight() / getMinScreenshotWidth()); + else + cropped = Bitmap.createBitmap(b, 0, 0, + b.getHeight() * getMinScreenshotWidth() / getMinScreenshotHeight(), + b.getHeight()); - bitmap = Bitmap.createBitmap(cropped, 0, 0, (int) (138 * sDensity), (int) (78 * sDensity)); + Bitmap bitmap = Bitmap.createScaledBitmap(cropped, getThumbnailWidth(), getThumbnailHeight(), false); + saveThumbnailToDB(new BitmapDrawable(bitmap)); + + if (!cropped.equals(b)) + b.recycle(); mThumbnail = new BitmapDrawable(bitmap); cropped.recycle(); } catch (OutOfMemoryError oom) { diff --git a/mobile/android/base/resources/layout/abouthome_topsite_item.xml b/mobile/android/base/resources/layout/abouthome_topsite_item.xml index 714fa3b70b8..3e598e232cb 100644 --- a/mobile/android/base/resources/layout/abouthome_topsite_item.xml +++ b/mobile/android/base/resources/layout/abouthome_topsite_item.xml @@ -8,15 +8,15 @@ android:layout_height="fill_parent"> + android:paddingBottom="2dip"> diff --git a/mobile/android/base/resources/layout/tabs_row.xml b/mobile/android/base/resources/layout/tabs_row.xml index b5bc55370ef..b32076c171e 100644 --- a/mobile/android/base/resources/layout/tabs_row.xml +++ b/mobile/android/base/resources/layout/tabs_row.xml @@ -7,8 +7,8 @@ android:background="@drawable/tabs_tray_list_selector">