Android Open Source - BitmapHandler File Cache






From Project

Back to project page BitmapHandler.

License

The source code is released under:

MIT License

If you think the Android project BitmapHandler listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.utils;
// w  ww .  j  a  v a2  s  .co  m
import java.io.File;
import java.util.ArrayList;
 
public class FileCache {
 
    private File cacheDir;
//    private File latest_photos;
//    private File graphicsDir;
//    private File root;
 
    public FileCache(File file){
        //Find the dir to save cached images
        cacheDir=file;
    }
 
    public File getFile(String url){
      String filename = "";
      if(!isHashCode(url))
        filename = String.valueOf(url.hashCode());
      else
        filename = url;
      //Log.e("file name for downloaded images", filename);
        File f = new File(cacheDir, filename);
        return f;
 
    }
    
    private boolean isHashCode(String url) {
    // TODO Auto-generated method stub
      try {
      Integer.parseInt(url);
    } catch (NumberFormatException e) {
      // TODO Auto-generated catch block
      //Log.e("NumberFormatException", e.toString());
      return false;
    }
    return true;
  }

  public ArrayList<String> getFiles(){
       File[] files=cacheDir.listFiles();
       ArrayList<String> arrayFiles = new ArrayList<String>();
         if(files==null)
             return null;
         for(File file : files){
           //Log.e("file name", file.getName());
             arrayFiles.add(file.getName());
         }
         return arrayFiles;
    }
 
    public boolean deleteFile(String filename){
        File f = new File(cacheDir, filename);
        try {
      if(f.exists()){
        f.delete();
        return true;
      }else{
        return false;
      }
    } catch (Exception e) {
      // TODO Auto-generated catch block
      return false;
    }
    }
}




Java Source Code List

com.bitmaphandler.AsyncLoader.java
com.bitmaphandler.AsyncTask.java
com.bitmaphandler.ImageWorker.java
com.displayer.CircleImageView.java
com.displayer.RecyclingBitmapDrawable.java
com.displayer.RecyclingImageView.java
com.displayer.RoundedBitmapDisplayer.java
com.utils.DiskLruCache.java
com.utils.FileCache.java
com.utils.ImageCache.java
com.utils.ImageFetcher.java
com.utils.ImageResizer.java
com.utils.StorageUtils.java
com.utils.Utils.java