import com.android.gallery3d.filtershow.ui.FramedTextButton;
import com.android.gallery3d.filtershow.ui.Spline;
import com.android.gallery3d.util.GalleryUtils;
+import com.android.photos.data.GalleryBitmapPool;
import java.io.File;
import java.io.IOException;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ clearGalleryBitmapPoolInBackground();
+
setupMasterImage();
setDefaultValues();
fillEditors();
}
+ void clearGalleryBitmapPoolInBackground() {
+ BitmapTask.Callbacks<Object, Object> cb = new BitmapTask.Callbacks<Object, Object>() {
+ @Override
+ public void onComplete(Object result) {}
+
+ @Override
+ public void onCancel() {}
+
+ @Override
+ public Object onExecute(Object param) {
+ // Free memory held in Gallery's Bitmap pool. May be O(n) for n bitmaps.
+ GalleryBitmapPool.getInstance().clear();
+ return null;
+ }
+ };
+ (new BitmapTask<Object, Object>(cb)).execute(0);
+ }
+
private void fillButtonIcons() {
Bitmap bmap = mImageLoader.getOriginalBitmapSmall();
if (bmap != null && bmap.getWidth() > 0 && bmap.getHeight() > 0) {
void setWallpaperInBackground(final Bitmap bmap) {
Toast.makeText(this, R.string.setting_wallpaper, Toast.LENGTH_LONG).show();
- BitmapTask.Callbacks<FilterShowActivity> cb = new BitmapTask.Callbacks<FilterShowActivity>() {
+ BitmapTask.Callbacks<FilterShowActivity, Bitmap> cb = new BitmapTask.Callbacks<FilterShowActivity, Bitmap>() {
@Override
public void onComplete(Bitmap result) {}
@Override
public Bitmap onExecute(FilterShowActivity param) {
+ if (param == null) {
+ return null;
+ }
try {
WallpaperManager.getInstance(param).setBitmap(bmap);
} catch (IOException e) {
return null;
}
};
- (new BitmapTask<FilterShowActivity>(cb)).execute(this);
+ (new BitmapTask<FilterShowActivity, Bitmap>(cb)).execute(this);
}
public void done() {
preset.setQuality(ImagePreset.QUALITY_FINAL);
preset.setScaleFactor(1.0f);
- BitmapTask.Callbacks<ImagePreset> cb = new BitmapTask.Callbacks<ImagePreset>() {
+ BitmapTask.Callbacks<ImagePreset, Bitmap> cb = new BitmapTask.Callbacks<ImagePreset, Bitmap>() {
@Override
public void onComplete(Bitmap result) {
}
};
- (new BitmapTask<ImagePreset>(cb)).execute(preset);
+ (new BitmapTask<ImagePreset, Bitmap>(cb)).execute(preset);
}
private String getFileExtension(String requestFormat) {
final InterruptableOutputStream ios = new InterruptableOutputStream(out);
- BitmapTask.Callbacks<Bitmap> cb = new BitmapTask.Callbacks<Bitmap>() {
+ BitmapTask.Callbacks<Bitmap, Bitmap> cb = new BitmapTask.Callbacks<Bitmap, Bitmap>() {
@Override
public void onComplete(Bitmap result) {
@Override
public Bitmap onExecute(Bitmap param) {
+ if (param == null) {
+ return null;
+ }
CompressFormat cf = convertExtensionToCompressFormat(getFileExtension(outputFormat));
param.compress(cf, DEFAULT_COMPRESS_QUALITY, ios);
Utils.closeSilently(ios);
}
};
- (new BitmapTask<Bitmap>(cb)).execute(bmap);
+ (new BitmapTask<Bitmap, Bitmap>(cb)).execute(bmap);
}
public void setAdapter(HistoryAdapter adapter) {
package com.android.gallery3d.filtershow.tools;
-import android.graphics.Bitmap;
import android.os.AsyncTask;
/**
- * Asynchronous task filtering or doign I/O with bitmaps.
+ * Asynchronous task wrapper class for doing Bitmap I/O.
*/
-public class BitmapTask <T> extends AsyncTask<T, Void, Bitmap> {
+public class BitmapTask <T, K> extends AsyncTask<T, Void, K> {
- private Callbacks<T> mCallbacks;
+ private Callbacks<T, K> mCallbacks;
private static final String LOGTAG = "BitmapTask";
- public BitmapTask(Callbacks<T> callbacks) {
+ public BitmapTask(Callbacks<T, K> callbacks) {
mCallbacks = callbacks;
}
@Override
- protected Bitmap doInBackground(T... params) {
+ protected K doInBackground(T... params) {
if (params == null || mCallbacks == null) {
return null;
}
}
@Override
- protected void onPostExecute(Bitmap result) {
+ protected void onPostExecute(K result) {
if (mCallbacks == null) {
return;
}
/**
* Callbacks for the asynchronous task.
*/
- public interface Callbacks<P> {
- void onComplete(Bitmap result);
+ public interface Callbacks<P, J> {
+ void onComplete(J result);
void onCancel();
- Bitmap onExecute(P param);
+ J onExecute(P param);
}
}