mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
bug 721032 - Make thumbnails in about:home and tab menu identical r=mfinkle
This commit is contained in:
parent
5cb8361be5
commit
2f607773e4
@ -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) {
|
||||
|
@ -8,15 +8,15 @@
|
||||
android:layout_height="fill_parent">
|
||||
|
||||
<LinearLayout android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="138dip"
|
||||
android:layout_height="80dip"
|
||||
android:background="@drawable/abouthome_topsite_shadow"
|
||||
android:padding="1dip"
|
||||
android:paddingTop="2dip">
|
||||
android:paddingBottom="2dip">
|
||||
|
||||
<ImageView android:id="@+id/thumbnail"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="80dip"
|
||||
android:layout_width="136dip"
|
||||
android:layout_height="77dip"
|
||||
android:scaleType="centerCrop"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -7,8 +7,8 @@
|
||||
android:background="@drawable/tabs_tray_list_selector">
|
||||
|
||||
<ImageView android:id="@+id/thumbnail"
|
||||
android:layout_width="138dip"
|
||||
android:layout_height="78dip"
|
||||
android:layout_width="136dip"
|
||||
android:layout_height="77dip"
|
||||
android:layout_marginLeft="35dip"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
@ -16,7 +16,7 @@
|
||||
android:scaleType="fitCenter"/>
|
||||
|
||||
<ImageView android:id="@+id/shadow"
|
||||
android:layout_width="140dip"
|
||||
android:layout_width="138dip"
|
||||
android:layout_height="80dip"
|
||||
android:layout_marginLeft="34dip"
|
||||
android:layout_alignParentLeft="true"
|
||||
|
Loading…
Reference in New Issue
Block a user