Bug 1083263 - Sort out aspect ratio of thumbnails for new tablet UI and implement new empty tab globes (r=lucasr)

This commit is contained in:
Martyn Haigh 2014-11-03 17:34:48 +00:00
parent 2993a0f8e3
commit 89f0fc63e0
16 changed files with 99 additions and 18 deletions

View File

@ -33,6 +33,9 @@ public final class ThumbnailHelper {
public static final float THUMBNAIL_ASPECT_RATIO = 0.571f; // this is a 4:7 ratio (as per UX decision) public static final float THUMBNAIL_ASPECT_RATIO = 0.571f; // this is a 4:7 ratio (as per UX decision)
// Should actually be more like 0.83 (140/168) but various roundings mean that 0.9 works better
public static final float NEW_TABLET_THUMBNAIL_ASPECT_RATIO = 0.9f;
public static enum CachePolicy { public static enum CachePolicy {
STORE, STORE,
NO_STORE NO_STORE
@ -118,11 +121,15 @@ public final class ThumbnailHelper {
// Apply any pending width updates. // Apply any pending width updates.
mWidth = mPendingWidth.get(); mWidth = mPendingWidth.get();
if(NewTabletUI.isEnabled(GeckoAppShell.getContext())) {
mHeight = Math.round(mWidth * NEW_TABLET_THUMBNAIL_ASPECT_RATIO);
} else {
mHeight = Math.round(mWidth * THUMBNAIL_ASPECT_RATIO); mHeight = Math.round(mWidth * THUMBNAIL_ASPECT_RATIO);
}
int pixelSize = (GeckoAppShell.getScreenDepth() == 24) ? 4 : 2; int pixelSize = (GeckoAppShell.getScreenDepth() == 24) ? 4 : 2;
int capacity = mWidth * mHeight * pixelSize; int capacity = mWidth * mHeight * pixelSize;
Log.d(LOGTAG, "Using new thumbnail size: " + capacity + " (width " + mWidth + ")"); Log.d(LOGTAG, "Using new thumbnail size: " + capacity + " (width " + mWidth + " - height " + mHeight + ")");
if (mBuffer == null || mBuffer.capacity() != capacity) { if (mBuffer == null || mBuffer.capacity() != capacity) {
if (mBuffer != null) { if (mBuffer != null) {
mBuffer = DirectBufferAllocator.free(mBuffer); mBuffer = DirectBufferAllocator.free(mBuffer);

View File

@ -224,7 +224,7 @@ public class TopSitesGridItemView extends RelativeLayout {
ImageLoader.with(getContext()).cancelRequest(mThumbnailView); ImageLoader.with(getContext()).cancelRequest(mThumbnailView);
mThumbnailView.setScaleType(SCALE_TYPE_THUMBNAIL); mThumbnailView.setScaleType(SCALE_TYPE_THUMBNAIL);
mThumbnailView.setImageBitmap(thumbnail); mThumbnailView.setImageBitmap(thumbnail, true);
mThumbnailView.setBackgroundDrawable(null); mThumbnailView.setBackgroundDrawable(null);
} }
@ -279,7 +279,7 @@ public class TopSitesGridItemView extends RelativeLayout {
} }
mThumbnailView.setScaleType(SCALE_TYPE_FAVICON); mThumbnailView.setScaleType(SCALE_TYPE_FAVICON);
mThumbnailView.setImageBitmap(favicon); mThumbnailView.setImageBitmap(favicon, false);
if (mFaviconURL != null) { if (mFaviconURL != null) {
final int bgColor = Favicons.getFaviconColor(mFaviconURL); final int bgColor = Favicons.getFaviconColor(mFaviconURL);

View File

@ -5,14 +5,18 @@
package org.mozilla.gecko.home; package org.mozilla.gecko.home;
import org.mozilla.gecko.NewTabletUI;
import org.mozilla.gecko.R; import org.mozilla.gecko.R;
import org.mozilla.gecko.ThumbnailHelper; import org.mozilla.gecko.ThumbnailHelper;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuff.Mode;
import android.graphics.RectF;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.widget.ImageView; import android.widget.ImageView;
@ -35,11 +39,16 @@ public class TopSitesThumbnailView extends ImageView {
// Paint for drawing the border. // Paint for drawing the border.
private final Paint mBorderPaint; private final Paint mBorderPaint;
private boolean mResize = false;
private int mWidth;
private int mHeight;
public TopSitesThumbnailView(Context context) { public TopSitesThumbnailView(Context context) {
this(context, null); this(context, null);
// A border will be drawn if needed. // A border will be drawn if needed.
setWillNotDraw(false); setWillNotDraw(false);
} }
public TopSitesThumbnailView(Context context, AttributeSet attrs) { public TopSitesThumbnailView(Context context, AttributeSet attrs) {
@ -56,6 +65,35 @@ public class TopSitesThumbnailView extends ImageView {
mBorderPaint.setStyle(Paint.Style.STROKE); mBorderPaint.setStyle(Paint.Style.STROKE);
} }
public void setImageBitmap(Bitmap bm, boolean resize) {
super.setImageBitmap(bm);
mResize = resize;
}
@Override
public void setImageResource(int resId) {
super.setImageResource(resId);
mResize = false;
}
@Override
public void setImageDrawable(Drawable drawable) {
super.setImageDrawable(drawable);
mResize = false;
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if(NewTabletUI.isEnabled(getContext()) && mResize) {
setScaleType(ScaleType.MATRIX);
RectF rect = new RectF(0, 0, mWidth, mHeight);
Matrix matrix = new Matrix();
matrix.setRectToRect(rect, rect, Matrix.ScaleToFit.CENTER);
setImageMatrix(matrix);
}
}
/** /**
* Measure the view to determine the measured width and height. * Measure the view to determine the measured width and height.
* The height is constrained by the measured width. * The height is constrained by the measured width.
@ -69,9 +107,9 @@ public class TopSitesThumbnailView extends ImageView {
super.onMeasure(widthMeasureSpec, heightMeasureSpec); super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// Force the height based on the aspect ratio. // Force the height based on the aspect ratio.
final int width = getMeasuredWidth(); mWidth = getMeasuredWidth();
final int height = (int) (width * ThumbnailHelper.THUMBNAIL_ASPECT_RATIO); mHeight = (int) (mWidth * ThumbnailHelper.THUMBNAIL_ASPECT_RATIO);
setMeasuredDimension(width, height); setMeasuredDimension(mWidth, mHeight);
} }
/** /**

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<solid android:color="@color/background_normal"/>
</shape>
</item>
<item>
<bitmap android:src="@drawable/tab_panel_tab_globe"
android:gravity="center"
/>
</item>
</layer-list>

View File

@ -52,7 +52,7 @@
<org.mozilla.gecko.widget.ThumbnailView android:id="@+id/thumbnail" <org.mozilla.gecko.widget.ThumbnailView android:id="@+id/thumbnail"
android:layout_width="@dimen/new_tablet_tab_thumbnail_width" android:layout_width="@dimen/new_tablet_tab_thumbnail_width"
android:layout_height="@dimen/new_tablet_tab_thumbnail_height" android:layout_height="@dimen/new_tablet_tab_thumbnail_height"
android:src="@drawable/tab_thumbnail_default"/> />
</RelativeLayout> </RelativeLayout>

View File

@ -24,8 +24,7 @@
<org.mozilla.gecko.widget.ThumbnailView android:id="@+id/thumbnail" <org.mozilla.gecko.widget.ThumbnailView android:id="@+id/thumbnail"
android:layout_width="@dimen/tab_thumbnail_width" android:layout_width="@dimen/tab_thumbnail_width"
android:layout_height="@dimen/tab_thumbnail_height" android:layout_height="@dimen/tab_thumbnail_height"/>
android:src="@drawable/tab_thumbnail_default"/>
<LinearLayout android:layout_width="@dimen/tab_thumbnail_width" <LinearLayout android:layout_width="@dimen/tab_thumbnail_width"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -24,8 +24,7 @@
<org.mozilla.gecko.widget.ThumbnailView android:id="@+id/thumbnail" <org.mozilla.gecko.widget.ThumbnailView android:id="@+id/thumbnail"
android:layout_width="@dimen/tab_thumbnail_width" android:layout_width="@dimen/tab_thumbnail_width"
android:layout_height="@dimen/tab_thumbnail_height" android:layout_height="@dimen/tab_thumbnail_height"/>
android:src="@drawable/tab_thumbnail_default"/>
</org.mozilla.gecko.widget.TabThumbnailWrapper> </org.mozilla.gecko.widget.TabThumbnailWrapper>

View File

@ -95,16 +95,14 @@ public class TabsLayoutItemView extends LinearLayout
mTabId = tab.getId(); mTabId = tab.getId();
Drawable thumbnailImage = tab.getThumbnail(); Drawable thumbnailImage = tab.getThumbnail();
if (thumbnailImage != null) { mThumbnail.setImageDrawable(thumbnailImage);
setThumbnail(thumbnailImage);
} else {
mThumbnail.setImageResource(R.drawable.tab_thumbnail_default);
}
if (mThumbnailWrapper != null) { if (mThumbnailWrapper != null) {
mThumbnailWrapper.setRecording(tab.isRecording()); mThumbnailWrapper.setRecording(tab.isRecording());
} }
mTitle.setText(tab.getDisplayTitle()); mTitle.setText(tab.getDisplayTitle());
mCloseButton.setTag(this); mCloseButton.setTag(this);
} }
public int getTabId() { public int getTabId() {

View File

@ -5,6 +5,8 @@
package org.mozilla.gecko.widget; package org.mozilla.gecko.widget;
import org.mozilla.gecko.R;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Matrix; import android.graphics.Matrix;
@ -21,6 +23,7 @@ public class ThumbnailView extends ImageView {
private int mWidthSpec = -1; private int mWidthSpec = -1;
private int mHeightSpec = -1; private int mHeightSpec = -1;
private boolean mLayoutChanged; private boolean mLayoutChanged;
private boolean mScale = false;
public ThumbnailView(Context context, AttributeSet attrs) { public ThumbnailView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
@ -30,6 +33,11 @@ public class ThumbnailView extends ImageView {
@Override @Override
public void onDraw(Canvas canvas) { public void onDraw(Canvas canvas) {
if (!mScale) {
super.onDraw(canvas);
return;
}
Drawable d = getDrawable(); Drawable d = getDrawable();
if (mLayoutChanged) { if (mLayoutChanged) {
int w1 = d.getIntrinsicWidth(); int w1 = d.getIntrinsicWidth();
@ -59,4 +67,19 @@ public class ThumbnailView extends ImageView {
} }
super.onMeasure(widthMeasureSpec, heightMeasureSpec); super.onMeasure(widthMeasureSpec, heightMeasureSpec);
} }
@Override
public void setImageDrawable(Drawable drawable) {
if (drawable == null) {
drawable = getResources().getDrawable(R.drawable.tab_panel_tab_background);
setScaleType(ScaleType.FIT_XY);
mScale = false;
} else {
mScale = true;
setScaleType(ScaleType.FIT_CENTER);
}
super.setImageDrawable(drawable);
}
} }