/[projects]/android/Side9/src/dk/thoerup/side9/ImageAdapter.java
ViewVC logotype

Diff of /android/Side9/src/dk/thoerup/side9/ImageAdapter.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1221 by torben, Fri Jan 7 07:15:42 2011 UTC revision 1222 by torben, Tue Feb 8 07:32:07 2011 UTC
# Line 25  import android.widget.ImageView; Line 25  import android.widget.ImageView;
25  import android.widget.Toast;  import android.widget.Toast;
26    
27  public class ImageAdapter extends BaseAdapter {  public class ImageAdapter extends BaseAdapter {
28                    final static String DIR_NAME = "/Side9";
29            final static String THUMBDIR_NAME = "/.thumb/";
30    
31                    
32      //int mGalleryItemBackground;      //int mGalleryItemBackground;
# Line 38  public class ImageAdapter extends BaseAd Line 39  public class ImageAdapter extends BaseAd
39            
40            
41      int thumbSize;      int thumbSize;
42        
43        public static Bitmap generateAndLoadThumb(File image) {
44            
45            File thumbDir = new File(Environment.getExternalStorageDirectory().getPath() + DIR_NAME + THUMBDIR_NAME);
46            String fileName = image.getName();
47            File thumb = new File ( thumbDir.getPath() + "/" + fileName );
48            
49            Bitmap thumbBmp = null;
50            
51            if (! thumbDir.exists()) {
52                    thumbDir.mkdirs();
53            }
54            
55            if (! thumb.exists() || thumb.lastModified() < image.lastModified()) {
56                    Bitmap bmp = BitmapFactory.decodeFile( image.getPath() );
57                    thumbBmp =  Bitmap.createScaledBitmap(bmp, bmp.getWidth()/4, bmp.getHeight()/4, true);
58    
59                    try {
60                            FileOutputStream fos = new FileOutputStream(thumb);
61                            thumbBmp.compress(CompressFormat.JPEG, 90, fos);  
62                            fos.close();
63                            
64                    } catch (IOException e) {
65                            Log.e("Side9", "error", e);
66                    }
67                    
68            } else {
69                    thumbBmp = BitmapFactory.decodeFile( thumb.getPath());
70            }      
71            return thumbBmp;
72        }
73    
74      public ImageAdapter(Context c) {      public ImageAdapter(Context c) {
75          mContext = c;          mContext = c;
76                    
77          String path = Environment.getExternalStorageDirectory().getPath() + "/Side9" ;          String path = Environment.getExternalStorageDirectory().getPath() + DIR_NAME ;
78                            
           
79                    
80          File root = new File(path);          File root = new File(path);
81                    
# Line 54  public class ImageAdapter extends BaseAd Line 85  public class ImageAdapter extends BaseAd
85          }          }
86    
87          File files[] = root.listFiles( new ExtensionFilter("jpg") );          File files[] = root.listFiles( new ExtensionFilter("jpg") );
88                    
89                    
90            for (File f : files) {          
         String thumbPath =  path + "/.thumb/";  
           
         File thumbDir = new File(thumbPath);  
         if (! thumbDir.exists()) {  
                 thumbDir.mkdirs();  
         }  
           
           
         for (File f : files) {  
                   
91                  ImageEntry entry = new ImageEntry();                  ImageEntry entry = new ImageEntry();
92                  entry.path = f.getPath();                  entry.path = f.getPath();
93    
94                  String fileName = f.getName();                  entry.thumb = generateAndLoadThumb(f);
95                  File thumb = new File ( thumbPath + fileName );  
                   
                 if (! thumb.exists() || thumb.lastModified() < f.lastModified()) {  
                         Bitmap bmp = BitmapFactory.decodeFile( f.getPath() );  
                         Bitmap scaled =  Bitmap.createScaledBitmap(bmp, bmp.getWidth()/4, bmp.getHeight()/4, true);  
                         entry.thumb = scaled;  
                         try {  
                                 FileOutputStream fos = new FileOutputStream(thumb);  
                                 scaled.compress(CompressFormat.JPEG, 90, fos);    
                                 fos.close();  
                                   
                         } catch (IOException e) {  
                                 Log.e("Side9", "error", e);  
                         }  
                           
                 } else {  
                         Bitmap thumbBmp = BitmapFactory.decodeFile( thumb.getPath());  
                         entry.thumb = thumbBmp;  
                 }  
96                                    
97                  /* load captions */                  /* load captions */
98                  String infoFileName = f.getPath().replace(".jpg", ".txt");                  String infoFileName = f.getPath().replace(".jpg", ".txt");

Legend:
Removed from v.1221  
changed lines
  Added in v.1222

  ViewVC Help
Powered by ViewVC 1.1.20