Android Open Source - VolleyDemo Bitmap Lru Cache






From Project

Back to project page VolleyDemo.

License

The source code is released under:

MIT License

If you think the Android project VolleyDemo 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 br.gdgsp.volleydemo.domain;
/* ww  w. j  a  v  a2s.co  m*/
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;

import com.android.volley.toolbox.ImageLoader.ImageCache;

/**
 * @author : ubiratanfsoares
 **/

public class BitmapLruCache extends LruCache<String, Bitmap>
        implements ImageCache {

    public static int getDefaultLruCacheSize() {
        final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
        final int cacheSize = maxMemory / 8;
        return cacheSize;
    }

    public BitmapLruCache() {
        this(getDefaultLruCacheSize());
    }

    public BitmapLruCache(int sizeInKiloBytes) {
        super(sizeInKiloBytes);
    }

    @Override
    protected int sizeOf(String key, Bitmap value) {
        return value.getRowBytes() * value.getHeight() / 1024;
    }

    @Override
    public Bitmap getBitmap(String url) {
        return get(url);
    }

    @Override
    public void putBitmap(String url, Bitmap bitmap) {
        put(url, bitmap);
    }

}




Java Source Code List

br.gdgsp.volleydemo.domain.BitmapLruCache.java
br.gdgsp.volleydemo.domain.CityWeatherInfo.java
br.gdgsp.volleydemo.domain.City.java
br.gdgsp.volleydemo.domain.WeatherRequest.java
br.gdgsp.volleydemo.ui.MainActivity.java
br.gdgsp.volleydemo.ui.WeatherInfoAdapter.java