Skip to content

yeyintlwin/picasso-cache-recycler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Android Picasso-Library Cache Recycler

Reuse the image data (bitmap) from picasso cache. Usage: getBitmap(context, url)

public static Bitmap getBitmap(Context context, String url) {
        final String CACHE_PATH = context.getCacheDir().getAbsolutePath() + "/picasso-cache/";
        File[] files = new File(CACHE_PATH).listFiles();
        for (File file : files) {
            String fname = file.getName();
            if (fname.contains(".") && fname.substring(fname.lastIndexOf(".")).equals(".0")) {
                try {
                    BufferedReader br = new BufferedReader(new FileReader(file));
                    if (br.readLine().equals(url)) {
                        String image_path = CACHE_PATH + fname.replace(".0", ".1");
                        if (new File(image_path).exists()) {
                            return BitmapFactory.decodeFile(image_path);
                        }
                    }
                } catch (FileNotFoundException | IOException e) {
                }
            }
        }
        return null;
    }

About

Recycle the image from picasso cache.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published