summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRuben Brunk <rubenbrunk@google.com>2012-12-03 12:18:56 -0800
committerRuben Brunk <rubenbrunk@google.com>2012-12-03 12:32:27 -0800
commite05d11454e60ab15e530f2878e3db507b974b113 (patch)
tree4654c33af7e1a6dccff679065379288b73232345
parent8d26578f8db895dadb7e0e1d7a56c00fa18183ec (diff)
downloadandroid_packages_apps_Snap-e05d11454e60ab15e530f2878e3db507b974b113.tar.gz
android_packages_apps_Snap-e05d11454e60ab15e530f2878e3db507b974b113.tar.bz2
android_packages_apps_Snap-e05d11454e60ab15e530f2878e3db507b974b113.zip
Fix call to Toast outside UI thread.
Bug: 7412281 Change-Id: I976ccd28f696a65a1159b6a092b8aa2f2a2d0e08
-rw-r--r--src/com/android/gallery3d/filtershow/FilterShowActivity.java26
-rw-r--r--src/com/android/gallery3d/filtershow/cache/ImageLoader.java138
2 files changed, 93 insertions, 71 deletions
diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
index 9a0c69dcf..56e60ed5e 100644
--- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java
+++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
@@ -156,7 +156,8 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
ImageFilterRS.setRenderScriptContext(this);
ImageShow.setDefaultBackgroundColor(getResources().getColor(R.color.background_screen));
- ImageSmallFilter.setDefaultBackgroundColor(getResources().getColor(R.color.background_main_toolbar));
+ ImageSmallFilter.setDefaultBackgroundColor(getResources().getColor(
+ R.color.background_main_toolbar));
// TODO: get those values from XML.
ImageZoom.setZoomedSize(getPixelsFromDip(256));
FramedTextButton.setTextSize((int) getPixelsFromDip(14));
@@ -414,7 +415,7 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
mLoadBitmapTask.execute(uri);
}
- private class LoadBitmapTask extends AsyncTask<Uri, Void, Boolean> {
+ private class LoadBitmapTask extends AsyncTask<Uri, Boolean, Boolean> {
View mTinyPlanetButton;
int mBitmapSize;
@@ -425,19 +426,25 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
@Override
protected Boolean doInBackground(Uri... params) {
- mImageLoader.loadBitmap(params[0], mBitmapSize);
- publishProgress();
- return mImageLoader.queryLightCycle360();
+ if (!mImageLoader.loadBitmap(params[0], mBitmapSize)) {
+ return false;
+ }
+ publishProgress(mImageLoader.queryLightCycle360());
+ return true;
}
@Override
- protected void onProgressUpdate(Void... values) {
+ protected void onProgressUpdate(Boolean... values) {
super.onProgressUpdate(values);
- if (isCancelled()) return;
+ if (isCancelled())
+ return;
final View filters = findViewById(R.id.filtersPanel);
final View loading = findViewById(R.id.loading);
loading.setVisibility(View.GONE);
filters.setVisibility(View.VISIBLE);
+ if (values[0]) {
+ mTinyPlanetButton.setVisibility(View.VISIBLE);
+ }
}
@Override
@@ -445,9 +452,10 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
if (isCancelled()) {
return;
}
- if (result) {
- mTinyPlanetButton.setVisibility(View.VISIBLE);
+ if (!result) {
+ cannotLoadImage();
}
+
mLoadBitmapTask = null;
super.onPostExecute(result);
}
diff --git a/src/com/android/gallery3d/filtershow/cache/ImageLoader.java b/src/com/android/gallery3d/filtershow/cache/ImageLoader.java
index cd1cc27ef..c5b35e5b4 100644
--- a/src/com/android/gallery3d/filtershow/cache/ImageLoader.java
+++ b/src/com/android/gallery3d/filtershow/cache/ImageLoader.java
@@ -73,13 +73,13 @@ public class ImageLoader {
private FilterShowActivity mActivity = null;
- public static final int ORI_NORMAL = ExifInterface.ORIENTATION_NORMAL;
- public static final int ORI_ROTATE_90 = ExifInterface.ORIENTATION_ROTATE_90;
+ public static final int ORI_NORMAL = ExifInterface.ORIENTATION_NORMAL;
+ public static final int ORI_ROTATE_90 = ExifInterface.ORIENTATION_ROTATE_90;
public static final int ORI_ROTATE_180 = ExifInterface.ORIENTATION_ROTATE_180;
public static final int ORI_ROTATE_270 = ExifInterface.ORIENTATION_ROTATE_270;
- public static final int ORI_FLIP_HOR = ExifInterface.ORIENTATION_FLIP_HORIZONTAL;
- public static final int ORI_FLIP_VERT = ExifInterface.ORIENTATION_FLIP_VERTICAL;
- public static final int ORI_TRANSPOSE = ExifInterface.ORIENTATION_TRANSPOSE;
+ public static final int ORI_FLIP_HOR = ExifInterface.ORIENTATION_FLIP_HORIZONTAL;
+ public static final int ORI_FLIP_VERT = ExifInterface.ORIENTATION_FLIP_VERTICAL;
+ public static final int ORI_TRANSPOSE = ExifInterface.ORIENTATION_TRANSPOSE;
public static final int ORI_TRANSVERSE = ExifInterface.ORIENTATION_TRANSVERSE;
private Context mContext = null;
@@ -105,18 +105,24 @@ public class ImageLoader {
return mActivity;
}
- public void loadBitmap(Uri uri,int size) {
+ public boolean loadBitmap(Uri uri, int size) {
mLoadingLock.lock();
mUri = uri;
mOrientation = getOrientation(mContext, uri);
mOriginalBitmapSmall = loadScaledBitmap(uri, 160);
if (mOriginalBitmapSmall == null) {
// Couldn't read the bitmap, let's exit
- mActivity.cannotLoadImage();
+ mLoadingLock.unlock();
+ return false;
}
mOriginalBitmapLarge = loadScaledBitmap(uri, size);
+ if (mOriginalBitmapLarge == null) {
+ mLoadingLock.unlock();
+ return false;
+ }
updateBitmaps();
mLoadingLock.unlock();
+ return true;
}
public Uri getUri() {
@@ -139,21 +145,25 @@ public class ImageLoader {
MediaStore.Images.ImageColumns.ORIENTATION
},
null, null, null);
- if (cursor.moveToNext()){
- int ori = cursor.getInt(0);
-
- switch (ori){
- case 0: return ORI_NORMAL;
- case 90: return ORI_ROTATE_90;
- case 270: return ORI_ROTATE_270;
- case 180: return ORI_ROTATE_180;
- default:
- return -1;
- }
- } else{
+ if (cursor.moveToNext()) {
+ int ori = cursor.getInt(0);
+
+ switch (ori) {
+ case 0:
+ return ORI_NORMAL;
+ case 90:
+ return ORI_ROTATE_90;
+ case 270:
+ return ORI_ROTATE_270;
+ case 180:
+ return ORI_ROTATE_180;
+ default:
+ return -1;
+ }
+ } else {
return -1;
}
- } catch (SQLiteException e){
+ } catch (SQLiteException e) {
return ExifInterface.ORIENTATION_UNDEFINED;
} finally {
Utils.closeSilently(cursor);
@@ -198,46 +208,46 @@ public class ImageLoader {
warnListeners();
}
- public static Bitmap rotateToPortrait(Bitmap bitmap,int ori) {
- Matrix matrix = new Matrix();
- int w = bitmap.getWidth();
- int h = bitmap.getHeight();
- if (ori == ORI_ROTATE_90 ||
- ori == ORI_ROTATE_270 ||
- ori == ORI_TRANSPOSE||
- ori == ORI_TRANSVERSE) {
- int tmp = w;
- w = h;
- h = tmp;
- }
- switch(ori){
- case ORI_ROTATE_90:
- matrix.setRotate(90,w/2f,h/2f);
- break;
- case ORI_ROTATE_180:
- matrix.setRotate(180,w/2f,h/2f);
- break;
- case ORI_ROTATE_270:
- matrix.setRotate(270,w/2f,h/2f);
- break;
- case ORI_FLIP_HOR:
- matrix.preScale(-1, 1);
- break;
- case ORI_FLIP_VERT:
- matrix.preScale(1, -1);
- break;
- case ORI_TRANSPOSE:
- matrix.setRotate(90,w/2f,h/2f);
- matrix.preScale(1, -1);
- break;
- case ORI_TRANSVERSE:
- matrix.setRotate(270,w/2f,h/2f);
- matrix.preScale(1, -1);
- break;
- case ORI_NORMAL:
- default:
- return bitmap;
- }
+ public static Bitmap rotateToPortrait(Bitmap bitmap, int ori) {
+ Matrix matrix = new Matrix();
+ int w = bitmap.getWidth();
+ int h = bitmap.getHeight();
+ if (ori == ORI_ROTATE_90 ||
+ ori == ORI_ROTATE_270 ||
+ ori == ORI_TRANSPOSE ||
+ ori == ORI_TRANSVERSE) {
+ int tmp = w;
+ w = h;
+ h = tmp;
+ }
+ switch (ori) {
+ case ORI_ROTATE_90:
+ matrix.setRotate(90, w / 2f, h / 2f);
+ break;
+ case ORI_ROTATE_180:
+ matrix.setRotate(180, w / 2f, h / 2f);
+ break;
+ case ORI_ROTATE_270:
+ matrix.setRotate(270, w / 2f, h / 2f);
+ break;
+ case ORI_FLIP_HOR:
+ matrix.preScale(-1, 1);
+ break;
+ case ORI_FLIP_VERT:
+ matrix.preScale(1, -1);
+ break;
+ case ORI_TRANSPOSE:
+ matrix.setRotate(90, w / 2f, h / 2f);
+ matrix.preScale(1, -1);
+ break;
+ case ORI_TRANSVERSE:
+ matrix.setRotate(270, w / 2f, h / 2f);
+ matrix.preScale(1, -1);
+ break;
+ case ORI_NORMAL:
+ default:
+ return bitmap;
+ }
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
bitmap.getHeight(), matrix, true);
@@ -270,6 +280,7 @@ public class ImageLoader {
}
static final int MAX_BITMAP_DIM = 2048;
+
private Bitmap loadScaledBitmap(Uri uri, int size) {
InputStream is = null;
try {
@@ -355,7 +366,8 @@ public class ImageLoader {
}
};
- // TODO: this currently does the loading + filtering on the UI thread -- need to
+ // 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,
boolean force) {
@@ -371,6 +383,7 @@ public class ImageLoader {
bmp2 = imagePreset.apply(bmp2);
imagePreset.setScaleFactor(scaleFactor);
mZoomCache.setImage(imagePreset, bounds, bmp2);
+ mLoadingLock.unlock();
return bmp2;
}
}
@@ -383,9 +396,11 @@ public class ImageLoader {
boolean hiRes) {
mLoadingLock.lock();
if (mOriginalBitmapSmall == null) {
+ mLoadingLock.unlock();
return null;
}
if (mOriginalBitmapLarge == null) {
+ mLoadingLock.unlock();
return null;
}
@@ -451,7 +466,6 @@ public class ImageLoader {
/**
* Determine if this is a light cycle 360 image
- *
* @return true if it is a light Cycle image that is full 360
*/
public boolean queryLightCycle360() {