summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRuben Brunk <rubenbrunk@google.com>2013-03-14 13:47:51 -0700
committerRuben Brunk <rubenbrunk@google.com>2013-03-14 14:04:32 -0700
commit7a09fa86ed2b9bd00c8fbf9ec2dc861641b54a6f (patch)
treef978af1130620394248b1a74dd2a46d4d616ab50 /src
parent1398c04d264d340f136100f0d2af3e675358fb9d (diff)
downloadandroid_packages_apps_Snap-7a09fa86ed2b9bd00c8fbf9ec2dc861641b54a6f.tar.gz
android_packages_apps_Snap-7a09fa86ed2b9bd00c8fbf9ec2dc861641b54a6f.tar.bz2
android_packages_apps_Snap-7a09fa86ed2b9bd00c8fbf9ec2dc861641b54a6f.zip
Fix image icons on Razr M.
Change-Id: I9f47dd043055fb5dc25dda643a3e9c81356bd0d5
Diffstat (limited to 'src')
-rw-r--r--src/com/android/gallery3d/filtershow/ui/FilterIconButton.java73
-rw-r--r--src/com/android/gallery3d/filtershow/ui/IconButton.java45
2 files changed, 65 insertions, 53 deletions
diff --git a/src/com/android/gallery3d/filtershow/ui/FilterIconButton.java b/src/com/android/gallery3d/filtershow/ui/FilterIconButton.java
index 9d50d5ac0..59c18e0f4 100644
--- a/src/com/android/gallery3d/filtershow/ui/FilterIconButton.java
+++ b/src/com/android/gallery3d/filtershow/ui/FilterIconButton.java
@@ -19,13 +19,13 @@ package com.android.gallery3d.filtershow.ui;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import com.android.gallery3d.filtershow.PanelController;
-import com.android.gallery3d.filtershow.cache.ImageLoader;
import com.android.gallery3d.filtershow.cache.RenderingRequest;
import com.android.gallery3d.filtershow.cache.RenderingRequestCaller;
import com.android.gallery3d.filtershow.filters.FilterRepresentation;
@@ -33,6 +33,7 @@ import com.android.gallery3d.filtershow.imageshow.GeometryListener;
import com.android.gallery3d.filtershow.imageshow.MasterImage;
import com.android.gallery3d.filtershow.presets.ImagePreset;
+// TODO: merge back IconButton and FilterIconButton?
public class FilterIconButton extends IconButton implements View.OnClickListener,
RenderingRequestCaller, GeometryListener {
private static final String LOGTAG = "FilterIconButton";
@@ -43,9 +44,6 @@ public class FilterIconButton extends IconButton implements View.OnClickListener
private LinearLayout mParentContainer = null;
private View.OnClickListener mListener = null;
private Bitmap mIconBitmap = null;
- private ImagePreset mPreset = null;
- private Rect mDestination = null;
-
public FilterIconButton(Context context) {
super(context);
}
@@ -68,27 +66,6 @@ public class FilterIconButton extends IconButton implements View.OnClickListener
}
@Override
- protected Bitmap drawImage(Bitmap dst, Bitmap image, Rect destination) {
- if (mOverlayOnly) {
- // TODO: merge back IconButton and FilterIconButton
- return super.drawImage(dst, image, destination);
- }
- if (mIconBitmap == null && mPreset == null) {
- dst = MasterImage.getImage().getThumbnailBitmap();
- if (dst != null) {
- ImagePreset mPreset = new ImagePreset();
- mPreset.addFilter(mFilterRepresentation);
- mPreset.setDoApplyGeometry(false);
- mDestination = destination;
- RenderingRequest.post(dst.copy(Bitmap.Config.ARGB_8888, true), mPreset, RenderingRequest.ICON_RENDERING, this);
- }
- return dst;
- } else {
- return mIconBitmap;
- }
- }
-
- @Override
public void setOnClickListener(View.OnClickListener listener) {
mListener = listener;
}
@@ -117,31 +94,55 @@ public class FilterIconButton extends IconButton implements View.OnClickListener
}
mOverlayOnly = mFilterRepresentation.getOverlayOnly();
if (mOverlayOnly) {
+ assert(mOverlayBitmap != null);
setIcon(mOverlayBitmap);
}
- stale_icon = true;
invalidate();
}
@Override
+ protected void onDraw(Canvas canvas) {
+ if (mIconBitmap == null && !mOverlayOnly) {
+ postNewIconRenderRequest();
+ }
+ super.onDraw(canvas);
+ }
+
+ @Override
public void available(RenderingRequest request) {
- if (request.getBitmap() == null) {
+ Bitmap bmap = request.getBitmap();
+ if (bmap == null) {
return;
}
- mIconBitmap = request.getBitmap();
- if (mOverlayBitmap != null) {
- mIconBitmap = super.drawImage(mIconBitmap, mOverlayBitmap, mDestination);
+ if (mOverlayOnly) {
+ setIcon(mOverlayBitmap);
+ } else {
+ mIconBitmap = bmap;
+ if (mOverlayBitmap != null) {
+ Rect destination = new Rect(0, 0, mIconBitmap.getWidth(), mIconBitmap.getHeight());
+ drawImage(mIconBitmap, mOverlayBitmap, destination);
+ }
+ setIcon(mIconBitmap);
}
- stale_icon = true;
- invalidate();
}
@Override
public void geometryChanged() {
- stale_icon = true;
-
+ if (mOverlayOnly) {
+ return;
+ }
mIconBitmap = null;
- mPreset = null;
- invalidate();
+ postNewIconRenderRequest();
+ }
+
+ private void postNewIconRenderRequest() {
+ Bitmap dst = MasterImage.getImage().getThumbnailBitmap();
+ if (dst != null) {
+ ImagePreset mPreset = new ImagePreset();
+ mPreset.addFilter(mFilterRepresentation);
+ mPreset.setDoApplyGeometry(false);
+ RenderingRequest.post(dst.copy(Bitmap.Config.ARGB_8888, true),
+ mPreset, RenderingRequest.ICON_RENDERING, this);
+ }
}
}
diff --git a/src/com/android/gallery3d/filtershow/ui/IconButton.java b/src/com/android/gallery3d/filtershow/ui/IconButton.java
index ed10be301..2484d5feb 100644
--- a/src/com/android/gallery3d/filtershow/ui/IconButton.java
+++ b/src/com/android/gallery3d/filtershow/ui/IconButton.java
@@ -30,10 +30,10 @@ import android.widget.Button;
*/
public class IconButton extends Button {
- protected Bitmap mImageMirror = null;
- protected Bitmap mIcon = null;
+ private Bitmap mImageMirror = null;
+ private Bitmap mIcon = null;
- protected boolean stale_icon = true;
+ private boolean stale_icon = true;
public IconButton(Context context) {
this(context, null);
@@ -53,7 +53,9 @@ public class IconButton extends Button {
}
/**
- * Set the image that the button icon will use.
+ * Set the image that the button icon will use. The image bitmap will be scaled
+ * and cropped into the largest square bitmap that will fit cleanly within the
+ * IconButton's layout.
*
* @param image image that icon will be set to before next draw.
*/
@@ -68,7 +70,7 @@ public class IconButton extends Button {
*
* @param image bitmap to use as icon
*/
- protected boolean makeAndSetIcon(Bitmap image) {
+ private boolean makeAndSetIcon(Bitmap image) {
int size = getGoodIconSideSize();
if (size > 0) {
return setImageIcon(makeImageIcon(image, size, size));
@@ -81,7 +83,7 @@ public class IconButton extends Button {
*
* @param image bitmap to set the icon to.
*/
- protected boolean setImageIcon(Bitmap image) {
+ private boolean setImageIcon(Bitmap image) {
if (image == null) {
return false;
}
@@ -99,11 +101,11 @@ public class IconButton extends Button {
* @param height icon height
* @return the scaled/cropped icon bitmap
*/
- protected Bitmap makeImageIcon(Bitmap image, int width, int height) {
+ private Bitmap makeImageIcon(Bitmap image, int width, int height) {
Rect destination = new Rect(0, 0, width, height);
Bitmap bmap = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
- bmap = drawImage(bmap, image, destination);
+ drawImage(bmap, image, destination);
return bmap;
}
@@ -113,7 +115,7 @@ public class IconButton extends Button {
*
* @return icon side length
*/
- protected int getGoodIconSideSize() {
+ private int getGoodIconSideSize() {
Paint p = getPaint();
Rect bounds = new Rect();
String s = getText().toString();
@@ -128,7 +130,9 @@ public class IconButton extends Button {
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
- stale_icon = true;
+ if (w != oldw || h != oldh) {
+ stale_icon = true;
+ }
}
@Override
@@ -140,12 +144,20 @@ public class IconButton extends Button {
super.onDraw(canvas);
}
- // Override this for custom icon generation
- protected Bitmap drawImage(Bitmap dst, Bitmap image, Rect destination) {
- if (image != null) {
+ /**
+ * Draws the src image into the destination rectangle within the dst bitmap.
+ * If src is a non-square image, clips to be a square before drawing into dst.
+ *
+ * @param dst bitmap being drawn on.
+ * @param src bitmap to draw into dst.
+ * @param destination square in dst in which to draw src.
+ */
+ protected static void drawImage(Bitmap dst, Bitmap src, Rect destination) {
+ if (src != null && dst != null && src.getWidth() > 0 && dst.getWidth() > 0
+ && src.getHeight() > 0 && dst.getHeight() > 0) {
Canvas canvas = new Canvas(dst);
- int iw = image.getWidth();
- int ih = image.getHeight();
+ int iw = src.getWidth();
+ int ih = src.getHeight();
int x = 0;
int y = 0;
int size = 0;
@@ -160,9 +172,8 @@ public class IconButton extends Button {
y = (int) ((ih - size) / 2.0f);
}
source = new Rect(x, y, x + size, y + size);
- canvas.drawBitmap(image, source, destination, new Paint());
+ canvas.drawBitmap(src, source, destination, new Paint());
}
- return dst;
}
}