import java.io.IOException;
import java.io.InputStream;
import java.util.Vector;
+import java.util.concurrent.locks.ReentrantLock;
public class ImageLoader {
private Rect mOriginalBounds = null;
private static int mZoomOrientation = ORI_NORMAL;
+ private ReentrantLock mLoadingLock = new ReentrantLock();
+
public ImageLoader(FilterShowActivity activity, Context context) {
mActivity = activity;
mContext = context;
}
public void loadBitmap(Uri uri,int size) {
+ mLoadingLock.lock();
mUri = uri;
mOrientation = getOrientation(mContext, uri);
mOriginalBitmapSmall = loadScaledBitmap(uri, 160);
}
mOriginalBitmapLarge = loadScaledBitmap(uri, size);
updateBitmaps();
+ mLoadingLock.unlock();
}
public Uri getUri() {
}
public void addListener(ImageShow imageShow) {
+ mLoadingLock.lock();
if (!mListeners.contains(imageShow)) {
mListeners.add(imageShow);
}
mHiresCache.addObserver(imageShow);
+ mLoadingLock.unlock();
}
private void warnListeners() {
// move this to a background thread.
public Bitmap getScaleOneImageForPreset(ImageShow caller, ImagePreset imagePreset, Rect bounds,
boolean force) {
+ mLoadingLock.lock();
Bitmap bmp = mZoomCache.getImage(imagePreset, bounds);
if (force || bmp == null) {
bmp = loadRegionBitmap(mUri, bounds);
return bmp2;
}
}
+ mLoadingLock.unlock();
return bmp;
}
// Caching method
public Bitmap getImageForPreset(ImageShow caller, ImagePreset imagePreset,
boolean hiRes) {
+ mLoadingLock.lock();
if (mOriginalBitmapSmall == null) {
return null;
}
mCache.addObserver(caller);
}
}
+ mLoadingLock.unlock();
return filteredImage;
}
public void resetImageForPreset(ImagePreset imagePreset, ImageShow caller) {
+ mLoadingLock.lock();
mHiresCache.reset(imagePreset);
mCache.reset(imagePreset);
mZoomCache.reset(imagePreset);
+ mLoadingLock.unlock();
}
public void saveImage(ImagePreset preset, final FilterShowActivity filterShowActivity,