summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2012-10-24 12:56:31 -0700
committerJohn Reck <jreck@google.com>2012-10-24 14:08:24 -0700
commit80a35b17989ee57b706cd18cfe8c5d928f08eeda (patch)
tree34b2318b822ea3d924594e86bccabef26aecd71c /src
parent474cf37aca1a88f909cc272ab5f7936726c011ab (diff)
downloadandroid_packages_apps_Snap-80a35b17989ee57b706cd18cfe8c5d928f08eeda.tar.gz
android_packages_apps_Snap-80a35b17989ee57b706cd18cfe8c5d928f08eeda.tar.bz2
android_packages_apps_Snap-80a35b17989ee57b706cd18cfe8c5d928f08eeda.zip
Move loadBitmap to async task
Bug: 7406705 Change-Id: I4e540e08d239d2e57f0ae6be5d70c8777cdbab2a
Diffstat (limited to 'src')
-rw-r--r--src/com/android/gallery3d/filtershow/FilterShowActivity.java41
-rw-r--r--src/com/android/gallery3d/filtershow/cache/ImageLoader.java19
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java66
3 files changed, 71 insertions, 55 deletions
diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
index 0d197afee..c3bc0873a 100644
--- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java
+++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
@@ -141,7 +141,7 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
private WeakReference<ProgressDialog> mSavingProgressDialog;
private static final int SEEK_BAR_MAX = 600;
- private LightCycleChecker mCheckFor360;
+ private LoadBitmapTask mLoadBitmapTask;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -367,17 +367,8 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
- String data = intent.getDataString();
- if (data != null) {
- Uri uri = Uri.parse(data);
- mImageLoader.loadBitmap(uri, getScreenImageSize());
-
- View tinyPlanetView = listColors.findViewById(R.id.tinyplanetButton);
- if (tinyPlanetView != null) {
- tinyPlanetView.setVisibility(View.GONE);
- mCheckFor360 = new LightCycleChecker(tinyPlanetView);
- mCheckFor360.execute();
- }
+ if (intent.getData() != null) {
+ startLoadBitmap(intent.getData());
} else {
pickImage();
}
@@ -390,15 +381,27 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
}
}
- private class LightCycleChecker extends AsyncTask<Void, Void, Boolean> {
+ private void startLoadBitmap(Uri uri) {
+ View tinyPlanetView = findViewById(R.id.tinyplanetButton);
+ if (tinyPlanetView != null) {
+ tinyPlanetView.setVisibility(View.GONE);
+ }
+ mLoadBitmapTask = new LoadBitmapTask(tinyPlanetView);
+ mLoadBitmapTask.execute(uri);
+ }
+
+ private class LoadBitmapTask extends AsyncTask<Uri, Void, Boolean> {
View mTinyPlanetButton;
+ int mBitmapSize;
- public LightCycleChecker(View button) {
+ public LoadBitmapTask(View button) {
mTinyPlanetButton = button;
+ mBitmapSize = getScreenImageSize();
}
@Override
- protected Boolean doInBackground(Void... params) {
+ protected Boolean doInBackground(Uri... params) {
+ mImageLoader.loadBitmap(params[0], mBitmapSize);
return mImageLoader.queryLightCycle360();
}
@@ -410,7 +413,7 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
if (result) {
mTinyPlanetButton.setVisibility(View.VISIBLE);
}
- mCheckFor360 = null;
+ mLoadBitmapTask = null;
super.onPostExecute(result);
}
@@ -418,8 +421,8 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
@Override
protected void onDestroy() {
- if (mCheckFor360 != null) {
- mCheckFor360.cancel(false);
+ if (mLoadBitmapTask != null) {
+ mLoadBitmapTask.cancel(false);
}
super.onDestroy();
}
@@ -923,7 +926,7 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
- mImageLoader.loadBitmap(selectedImageUri, getScreenImageSize());
+ startLoadBitmap(selectedImageUri);
}
}
}
diff --git a/src/com/android/gallery3d/filtershow/cache/ImageLoader.java b/src/com/android/gallery3d/filtershow/cache/ImageLoader.java
index c25226548..0ab45e29b 100644
--- a/src/com/android/gallery3d/filtershow/cache/ImageLoader.java
+++ b/src/com/android/gallery3d/filtershow/cache/ImageLoader.java
@@ -302,13 +302,22 @@ public class ImageLoader {
}
}
- public void warnListeners() {
- for (int i = 0; i < mListeners.size(); i++) {
- ImageShow imageShow = mListeners.elementAt(i);
- imageShow.updateImage();
- }
+ private void warnListeners() {
+ mActivity.runOnUiThread(mWarnListenersRunnable);
}
+ private Runnable mWarnListenersRunnable = new Runnable() {
+
+ @Override
+ public void run() {
+ for (int i = 0; i < mListeners.size(); i++) {
+ ImageShow imageShow = mListeners.elementAt(i);
+ imageShow.updateImage();
+ imageShow.invalidate();
+ }
+ }
+ };
+
// TODO: this currently does the loading + filtering on the UI thread -- need to
// move this to a background thread.
public Bitmap getScaleOneImageForPreset(ImageShow caller, ImagePreset imagePreset, Rect bounds,
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java
index c996e9c03..003d036e0 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java
@@ -66,37 +66,8 @@ public class ImageFilterTinyPlanet extends ImageFilter {
int outputSize = Math.min(w, h);
ImagePreset preset = getImagePreset();
- if (preset != null) {
- if (preset.isPanoramaSafe()) {
- try {
- XMPMeta xmp = preset.getImageLoader().getXmpObject();
- int croppedAreaWidth =
- getInt(xmp, CROPPED_AREA_IMAGE_WIDTH_PIXELS);
- int croppedAreaHeight =
- getInt(xmp, CROPPED_AREA_IMAGE_HEIGHT_PIXELS);
- int fullPanoWidth =
- getInt(xmp, CROPPED_AREA_FULL_PANO_WIDTH_PIXELS);
- int fullPanoHeight =
- getInt(xmp, CROPPED_AREA_FULL_PANO_HEIGHT_PIXELS);
- int left = getInt(xmp, CROPPED_AREA_LEFT);
- int top = getInt(xmp, CROPPED_AREA_TOP);
-
- Bitmap paddedBitmap = Bitmap.createBitmap(
- fullPanoWidth, fullPanoHeight, Bitmap.Config.ARGB_8888);
- Canvas paddedCanvas = new Canvas(paddedBitmap);
-
- int right = left + croppedAreaWidth;
- int bottom = top + croppedAreaHeight;
- Rect destRect = new Rect(left, top, right, bottom);
- paddedCanvas.drawBitmap(bitmapIn, null, destRect, null);
- bitmapIn = paddedBitmap;
- } catch (XMPException ex) {
- // Do nothing, just use bitmapIn as is.
- }
- } else {
- // Do nothing, just use bitmapIn as is, there is nothing else we
- // can do.
- }
+ if (preset != null && preset.isPanoramaSafe()) {
+ bitmapIn = applyXmp(bitmapIn, preset);
}
Bitmap mBitmapOut = Bitmap.createBitmap(
@@ -106,6 +77,39 @@ public class ImageFilterTinyPlanet extends ImageFilter {
return mBitmapOut;
}
+ private Bitmap applyXmp(Bitmap bitmapIn, ImagePreset preset) {
+ try {
+ XMPMeta xmp = preset.getImageLoader().getXmpObject();
+ if (xmp == null) {
+ // Do nothing, just use bitmapIn as is.
+ return bitmapIn;
+ }
+ int croppedAreaWidth =
+ getInt(xmp, CROPPED_AREA_IMAGE_WIDTH_PIXELS);
+ int croppedAreaHeight =
+ getInt(xmp, CROPPED_AREA_IMAGE_HEIGHT_PIXELS);
+ int fullPanoWidth =
+ getInt(xmp, CROPPED_AREA_FULL_PANO_WIDTH_PIXELS);
+ int fullPanoHeight =
+ getInt(xmp, CROPPED_AREA_FULL_PANO_HEIGHT_PIXELS);
+ int left = getInt(xmp, CROPPED_AREA_LEFT);
+ int top = getInt(xmp, CROPPED_AREA_TOP);
+
+ Bitmap paddedBitmap = Bitmap.createBitmap(
+ fullPanoWidth, fullPanoHeight, Bitmap.Config.ARGB_8888);
+ Canvas paddedCanvas = new Canvas(paddedBitmap);
+
+ int right = left + croppedAreaWidth;
+ int bottom = top + croppedAreaHeight;
+ Rect destRect = new Rect(left, top, right, bottom);
+ paddedCanvas.drawBitmap(bitmapIn, null, destRect, null);
+ bitmapIn = paddedBitmap;
+ } catch (XMPException ex) {
+ // Do nothing, just use bitmapIn as is.
+ }
+ return bitmapIn;
+ }
+
private static int getInt(XMPMeta xmp, String key) throws XMPException {
if (xmp.doesPropertyExist(GOOGLE_PANO_NAMESPACE, key)) {
return xmp.getPropertyInteger(GOOGLE_PANO_NAMESPACE, key);