diff --git a/src/info/guardianproject/iocipher/camera/GalleryActivity.java b/src/info/guardianproject/iocipher/camera/GalleryActivity.java index 4b506ff..733858c 100644 --- a/src/info/guardianproject/iocipher/camera/GalleryActivity.java +++ b/src/info/guardianproject/iocipher/camera/GalleryActivity.java @@ -5,6 +5,7 @@ import info.guardianproject.iocipher.File; import info.guardianproject.iocipher.FileInputStream; import info.guardianproject.iocipher.FileOutputStream; +import info.guardianproject.iocipher.VirtualFileSystem; import info.guardianproject.iocipher.camera.io.IOCipherContentProvider; import info.guardianproject.iocipher.camera.viewer.ImageViewerActivity; import info.guardianproject.iocipher.camera.viewer.MjpegViewerActivity; @@ -27,6 +28,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; +import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.provider.MediaStore; @@ -58,7 +60,7 @@ public class GalleryActivity extends Activity implements ICacheWordSubscriber { private GridView gridview; private HashMap mBitCache = new HashMap(); - private HashMap mBitLoaders = new HashMap(); + private HashMap mBitLoaders = new HashMap(); private CacheWordHandler mCacheWord; @@ -590,9 +592,9 @@ private Bitmap getPreview(File fileImage) throws FileNotFoundException { if (b == null && mBitLoaders.get(fileImage.getAbsolutePath())==null) { - BitmapWorkerThread bwt = new BitmapWorkerThread(fileImage); + BitmapWorkerTask bwt = new BitmapWorkerTask(); mBitLoaders.put(fileImage.getAbsolutePath(),bwt); - bwt.start(); + bwt.execute(fileImage); } } @@ -600,42 +602,7 @@ private Bitmap getPreview(File fileImage) throws FileNotFoundException { return b; } - class BitmapWorkerThread extends Thread - { - private File fileImage; - - public BitmapWorkerThread (File fileImage) - { - this.fileImage = fileImage; - } - - public void run () - { - BitmapFactory.Options bounds = new BitmapFactory.Options(); - bounds.inSampleSize = 8; - Bitmap b; - try { - FileInputStream fis = new FileInputStream(fileImage); - b = BitmapFactory.decodeStream(fis, null, bounds); - fis.close(); - mBitCache.put(fileImage.getAbsolutePath(), b); - mBitLoaders.remove(fileImage.getAbsolutePath()); - - h.post(new Runnable() - { - public void run () - { - ((IconicList)gridview.getAdapter()).notifyDataSetChanged(); - } - }); - - } catch (Exception e) { - Log.e(TAG,"error decoding bitmap preview",e); - } - } - } - /* class BitmapWorkerTask extends AsyncTask { // Decode image in background. @@ -651,22 +618,27 @@ protected Bitmap doInBackground(File... fileImage) { fis.close(); mBitCache.put(fileImage[0].getAbsolutePath(), b); + VirtualFileSystem.get().detachThread(); + return b; } catch (Exception e) { Log.e(TAG,"error decoding bitmap preview",e); } + return null; } // Once complete, see if ImageView is still around and set bitmap. @Override - protected void onPostExecute(Bitmap bitmap) { - ((IconicList)gridview.getAdapter()).notifyDataSetChanged(); + protected void onPostExecute(Bitmap bitmap) { + + if (bitmap != null) + ((IconicList)gridview.getAdapter()).notifyDataSetChanged(); } - }*/ + }