summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/filtershow/category
diff options
context:
space:
mode:
authornicolasroard <nicolasroard@google.com>2013-09-06 17:21:55 -0700
committernicolasroard <nicolasroard@google.com>2013-09-06 17:39:46 -0700
commit32cc4dd751569721aa19218b4d947145577060d0 (patch)
tree5f2a8a96cb1bb08a94e0ca8abbf1c03bffbe242a /src/com/android/gallery3d/filtershow/category
parent98b296ffc50e11b7950acf1d0df850b617913131 (diff)
downloadandroid_packages_apps_Gallery2-32cc4dd751569721aa19218b4d947145577060d0.tar.gz
android_packages_apps_Gallery2-32cc4dd751569721aa19218b4d947145577060d0.tar.bz2
android_packages_apps_Gallery2-32cc4dd751569721aa19218b4d947145577060d0.zip
Fix UI performances / glitches
- load/process thumbnails fully in background - fix reveal slider - fix race condition when loading - better memory usage - fix loading spinner (wasn't shown!) Change-Id: Id78163556d8ee1c3ad04eae16fe1bf06f4312405
Diffstat (limited to 'src/com/android/gallery3d/filtershow/category')
-rw-r--r--src/com/android/gallery3d/filtershow/category/Action.java79
-rw-r--r--src/com/android/gallery3d/filtershow/category/CategoryAdapter.java9
-rw-r--r--src/com/android/gallery3d/filtershow/category/CategorySelected.java14
-rw-r--r--src/com/android/gallery3d/filtershow/category/CategoryView.java5
-rw-r--r--src/com/android/gallery3d/filtershow/category/IconView.java1
5 files changed, 67 insertions, 41 deletions
diff --git a/src/com/android/gallery3d/filtershow/category/Action.java b/src/com/android/gallery3d/filtershow/category/Action.java
index 7bdc8ec90..b3f35dab9 100644
--- a/src/com/android/gallery3d/filtershow/category/Action.java
+++ b/src/com/android/gallery3d/filtershow/category/Action.java
@@ -24,8 +24,12 @@ import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
+import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
+
+import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.FilterShowActivity;
import com.android.gallery3d.filtershow.filters.FilterUserPresetRepresentation;
import com.android.gallery3d.filtershow.pipeline.RenderingRequest;
import com.android.gallery3d.filtershow.pipeline.RenderingRequestCaller;
@@ -48,26 +52,30 @@ public class Action implements RenderingRequestCaller {
private int mType = CROP_VIEW;
private Bitmap mPortraitImage;
private Bitmap mOverlayBitmap;
- private Context mContext;
+ private FilterShowActivity mContext;
private boolean mCanBeRemoved = false;
+ private int mTextSize = 32;
- public Action(Context context, FilterRepresentation representation, int type,
+ public Action(FilterShowActivity context, FilterRepresentation representation, int type,
boolean canBeRemoved) {
this(context, representation, type);
mCanBeRemoved = canBeRemoved;
+ mTextSize = context.getResources().getDimensionPixelSize(
+ R.dimen.category_panel_text_size);
}
- public Action(Context context, FilterRepresentation representation, int type) {
+ public Action(FilterShowActivity context, FilterRepresentation representation, int type) {
this(context, type);
setRepresentation(representation);
}
- public Action(Context context, int type) {
+ public Action(FilterShowActivity context, int type) {
mContext = context;
setType(type);
+ mContext.registerAction(this);
}
- public Action(Context context, FilterRepresentation representation) {
+ public Action(FilterShowActivity context, FilterRepresentation representation) {
this(context, representation, CROP_VIEW);
}
@@ -100,19 +108,19 @@ public class Action implements RenderingRequestCaller {
if (mImageFrame != null && mImageFrame.equals(imageFrame)) {
return;
}
- Bitmap bitmap = MasterImage.getImage().getLargeThumbnailBitmap();
+ if (getType() == Action.ADD_ACTION) {
+ return;
+ }
+ Bitmap temp = MasterImage.getImage().getTemporaryThumbnailBitmap();
+ if (temp != null) {
+ mImage = temp;
+ }
+ Bitmap bitmap = MasterImage.getImage().getThumbnailBitmap();
if (bitmap != null) {
mImageFrame = imageFrame;
int w = mImageFrame.width();
int h = mImageFrame.height();
- if (orientation == CategoryView.VERTICAL
- && mType == CROP_VIEW) {
- w /= 2;
- }
- Bitmap bitmapCrop = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
- drawCenteredImage(bitmap, bitmapCrop, true);
-
- postNewIconRenderRequest(bitmapCrop);
+ postNewIconRenderRequest(w, h);
}
}
@@ -132,40 +140,37 @@ public class Action implements RenderingRequestCaller {
mType = type;
}
- private void postNewIconRenderRequest(Bitmap bitmap) {
- if (bitmap != null && mRepresentation != null) {
+ private void postNewIconRenderRequest(int w, int h) {
+ if (mRepresentation != null) {
ImagePreset preset = new ImagePreset();
preset.addFilter(mRepresentation);
- RenderingRequest.post(mContext, bitmap,
- preset, RenderingRequest.ICON_RENDERING, this);
+ RenderingRequest.postIconRequest(mContext, w, h, preset, this);
}
}
private void drawCenteredImage(Bitmap source, Bitmap destination, boolean scale) {
- RectF image = new RectF(0, 0, source.getWidth(), source.getHeight());
- int border = 0;
- if (!scale) {
- border = destination.getWidth() - destination.getHeight();
- if (border < 0) {
- border = 0;
- }
- }
- RectF frame = new RectF(border, 0,
- destination.getWidth() - border,
- destination.getHeight());
+ int minSide = Math.min(destination.getWidth(), destination.getHeight());
Matrix m = new Matrix();
- m.setRectToRect(frame, image, Matrix.ScaleToFit.CENTER);
- image.set(frame);
- m.mapRect(image);
- m.setRectToRect(image, frame, Matrix.ScaleToFit.FILL);
+ float scaleFactor = minSide / (float) Math.min(source.getWidth(), source.getHeight());
+
+ float dx = (destination.getWidth() - source.getWidth() * scaleFactor) / 2.0f;
+ float dy = (destination.getHeight() - source.getHeight() * scaleFactor) / 2.0f;
+ if (mImageFrame.height() > mImageFrame.width()) {
+ // if portrait
+ dy -= mTextSize;
+ }
+ m.setScale(scaleFactor, scaleFactor);
+ m.postTranslate(dx, dy);
Canvas canvas = new Canvas(destination);
canvas.drawBitmap(source, m, new Paint(Paint.FILTER_BITMAP_FLAG));
}
@Override
public void available(RenderingRequest request) {
+ clearBitmap();
mImage = request.getBitmap();
if (mImage == null) {
+ mImageFrame = null;
return;
}
if (mRepresentation.getOverlayId() != 0 && mOverlayBitmap == null) {
@@ -204,4 +209,12 @@ public class Action implements RenderingRequestCaller {
public void setOverlayBitmap(Bitmap overlayBitmap) {
mOverlayBitmap = overlayBitmap;
}
+
+ public void clearBitmap() {
+ if (mImage != null
+ && mImage != MasterImage.getImage().getTemporaryThumbnailBitmap()) {
+ MasterImage.getImage().getBitmapCache().cache(mImage);
+ }
+ mImage = null;
+ }
}
diff --git a/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java b/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java
index 51ae07fc2..09f02dd37 100644
--- a/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java
+++ b/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java
@@ -49,6 +49,15 @@ public class CategoryAdapter extends ArrayAdapter<Action> {
this(context, 0);
}
+ @Override
+ public void clear() {
+ for (int i = 0; i < getCount(); i++) {
+ Action action = getItem(i);
+ action.clearBitmap();
+ }
+ super.clear();
+ }
+
public void setItemHeight(int height) {
mItemHeight = height;
}
diff --git a/src/com/android/gallery3d/filtershow/category/CategorySelected.java b/src/com/android/gallery3d/filtershow/category/CategorySelected.java
index 1a6135bb8..42058c0db 100644
--- a/src/com/android/gallery3d/filtershow/category/CategorySelected.java
+++ b/src/com/android/gallery3d/filtershow/category/CategorySelected.java
@@ -7,21 +7,25 @@ import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
+import com.android.gallery3d.R;
+
public class CategorySelected extends View {
- Paint mPaint = new Paint();
+ private Paint mPaint = new Paint();
+ private int mMargin = 20;
public CategorySelected(Context context, AttributeSet attrs) {
super(context, attrs);
+ mMargin = getResources().getDimensionPixelSize(R.dimen.touch_circle_size);
}
public void onDraw(Canvas canvas) {
mPaint.reset();
- int margin = 20;
- mPaint.setStrokeWidth(margin);
+ mPaint.setStrokeWidth(mMargin);
mPaint.setAntiAlias(true);
mPaint.setStyle(Paint.Style.STROKE);
- mPaint.setColor(Color.GRAY);
- canvas.drawCircle(getWidth()/2, getHeight()/2, getWidth()/2 - margin, mPaint);
+ mPaint.setColor(Color.argb(128, 128, 128, 128));
+ canvas.drawCircle(getWidth()/2, getHeight()/2,
+ getWidth()/2 - mMargin, mPaint);
}
}
diff --git a/src/com/android/gallery3d/filtershow/category/CategoryView.java b/src/com/android/gallery3d/filtershow/category/CategoryView.java
index c613c2174..22c50fd96 100644
--- a/src/com/android/gallery3d/filtershow/category/CategoryView.java
+++ b/src/com/android/gallery3d/filtershow/category/CategoryView.java
@@ -109,9 +109,8 @@ public class CategoryView extends IconView
drawSpacer(canvas);
return;
}
- if (mAction.getImage() == null) {
- mAction.setImageFrame(new Rect(0, 0, getWidth(), getHeight()), getOrientation());
- } else {
+ mAction.setImageFrame(new Rect(0, 0, getWidth(), getHeight()), getOrientation());
+ if (mAction.getImage() != null) {
setBitmap(mAction.getImage());
}
}
diff --git a/src/com/android/gallery3d/filtershow/category/IconView.java b/src/com/android/gallery3d/filtershow/category/IconView.java
index 0443823c9..cba2d794f 100644
--- a/src/com/android/gallery3d/filtershow/category/IconView.java
+++ b/src/com/android/gallery3d/filtershow/category/IconView.java
@@ -193,6 +193,7 @@ public class IconView extends View {
public void onDraw(Canvas canvas) {
mPaint.reset();
mPaint.setAntiAlias(true);
+ mPaint.setFilterBitmap(true);
canvas.drawColor(mBackgroundColor);
computeBitmapBounds();
computeTextPosition(getText());