Author: tian
Date: Tue Mar  1 21:36:30 2016
New Revision: 2265

URL: http://svn.gna.org/viewcvs/gcstar?rev=2265&view=rev
Log:
Faster image loading (requires GCstar 1.7.1 or above)

Modified:
    viewer/src/com/gcstar/viewer/GCstarCollectionLoader.java
    viewer/src/com/gcstar/viewer/GCstarImageLoader.java

Modified: viewer/src/com/gcstar/viewer/GCstarCollectionLoader.java
URL: 
http://svn.gna.org/viewcvs/gcstar/viewer/src/com/gcstar/viewer/GCstarCollectionLoader.java?rev=2265&r1=2264&r2=2265&view=diff
==============================================================================
--- viewer/src/com/gcstar/viewer/GCstarCollectionLoader.java    (original)
+++ viewer/src/com/gcstar/viewer/GCstarCollectionLoader.java    Tue Mar  1 
21:36:30 2016
@@ -48,6 +48,7 @@
 import android.content.res.Resources;
 import android.graphics.BitmapFactory.Options;
 import android.os.AsyncTask;
+import android.os.Looper;
 import android.util.Xml;
 import android.widget.ImageView;
 
@@ -134,6 +135,7 @@
     {
         protected Integer doInBackground(GCstarCollectionLoader... p)
         {
+               Looper.prepare();       // Alessio Del Trecco (Morg4n): fix 
crash on loading
             _parent = p[0];
             _parent.loadFile(_parent._fileName);
             return 0;
@@ -415,7 +417,7 @@
         }
     }
 
-    public synchronized String convertImagePath(String path)
+    public synchronized String convertImagePath(String path, String miniPath, 
Options options)
     {
         if (_isZip && path.length() > 4)
         {
@@ -423,12 +425,24 @@
             String ext = path.substring(path.length() - 4);
             try
             {
+               ZipEntry entry = null;
+               if (miniPath != null)
+               {
+                       entry = _zip.getEntry(miniPath);
+               }
                 File f = File.createTempFile(ImagesPrefix, ext, _cacheDir);
                 f.deleteOnExit();
                 BufferedOutputStream buf = new BufferedOutputStream(
                         new FileOutputStream(f),
                         2048);
-                ZipEntry entry = _zip.getEntry(path);
+                if (entry == null)
+                {
+                       entry = _zip.getEntry(path);
+                }
+                else
+                {
+                       options.inSampleSize = 1;
+                }
                 if (entry != null)
                 {
                     BufferedInputStream is = new BufferedInputStream(
@@ -446,6 +460,7 @@
                     _tmpImages.put(path, f);
                     return f.getAbsolutePath();
                 }
+                buf.close();
             }
             catch (IOException e)
             {

Modified: viewer/src/com/gcstar/viewer/GCstarImageLoader.java
URL: 
http://svn.gna.org/viewcvs/gcstar/viewer/src/com/gcstar/viewer/GCstarImageLoader.java?rev=2265&r1=2264&r2=2265&view=diff
==============================================================================
--- viewer/src/com/gcstar/viewer/GCstarImageLoader.java (original)
+++ viewer/src/com/gcstar/viewer/GCstarImageLoader.java Tue Mar  1 21:36:30 2016
@@ -44,8 +44,18 @@
             // This ImageView may be used for other images before. So there may
             // be some old tasks in the queue. We need to discard them.
             _imagesQueue.Clean(imageView);
+            
+            String miniPath = null;
+            if (isCover && cache)
+            {
+               StringBuilder b = new StringBuilder(path);
+               int lastSlashIndex = path.lastIndexOf("/");
+               b.replace(lastSlashIndex, lastSlashIndex + 1, "-mini/" );
+               miniPath = b.toString();
+            }
+            
             ImageToLoad p = new ImageToLoad(path, imageView, height, isCover,
-                    cache, options);
+                    cache, options, miniPath);
             synchronized (_imagesQueue._imagesList)
             {
                 _imagesQueue._imagesList.offer(p);
@@ -61,7 +71,7 @@
 
     private void getBitmap(ImageToLoad img)
     {
-        String path = _loader.convertImagePath(img._path);
+        String path = _loader.convertImagePath(img._path, img._miniPath, 
img._options);
         File file = new File(path);
         if (!file.isAbsolute())
         {
@@ -91,7 +101,7 @@
     private class ImageToLoad
     {
         public ImageToLoad(String path, ImageView i, int height,
-                boolean isCover, boolean cache, Options options)
+                boolean isCover, boolean cache, Options options, String 
miniPath)
         {
             _path = path;
             _imageView = i;
@@ -99,6 +109,7 @@
             _isCover = isCover;
             _options = options;
             _cache = cache;
+            _miniPath = miniPath;
         }
 
         public String _path;
@@ -109,6 +120,7 @@
         public Bitmap _bm;
         public String _desc;
         public boolean _cache;
+        public String _miniPath;
     }
 
     public void stopThread()


_______________________________________________
GCstar-commits mailing list
[email protected]
https://mail.gna.org/listinfo/gcstar-commits

Reply via email to