Example usage for android.support.v4.util LruCache LruCache

List of usage examples for android.support.v4.util LruCache LruCache

Introduction

In this page you can find the example usage for android.support.v4.util LruCache LruCache.

Prototype

public LruCache(int maxSize) 

Source Link

Usage

From source file:com.example.lzhang.stockchartt.media.AlbumArtCache.java

private AlbumArtCache() {
    // Holds no more than MAX_ALBUM_ART_CACHE_SIZE bytes, bounded by maxmemory/4 and
    // Integer.MAX_VALUE:
    int maxSize = Math.min(MAX_ALBUM_ART_CACHE_SIZE,
            (int) (Math.min(Integer.MAX_VALUE, Runtime.getRuntime().maxMemory() / 4)));
    mCache = new LruCache<String, Bitmap[]>(maxSize) {
        @Override//from   w w w. j  ava2  s. c  o  m
        protected int sizeOf(String key, Bitmap[] value) {
            return value[BIG_BITMAP_INDEX].getByteCount() + value[ICON_BITMAP_INDEX].getByteCount();
        }
    };
}

From source file:com.app.soccerveteranv.GlobalApplication.java

/**
 * ? ?, ? ?,  ?? ./*w  ww .  j  av a  2  s  .co m*/
 */
@Override
public void onCreate() {
    super.onCreate();
    instance = this;

    KakaoSDK.init(new KakaoSDKAdapter());

    final RequestQueue requestQueue = Volley.newRequestQueue(this);

    ImageLoader.ImageCache imageCache = new ImageLoader.ImageCache() {
        final LruCache<String, Bitmap> imageCache = new LruCache<String, Bitmap>(3);

        @Override
        public void putBitmap(String key, Bitmap value) {
            imageCache.put(key, value);
        }

        @Override
        public Bitmap getBitmap(String key) {
            return imageCache.get(key);
        }
    };

    imageLoader = new ImageLoader(requestQueue, imageCache);
}

From source file:com.wuman.twolevellrucache.TwoLevelLruCache.java

/**
 * Constructor for TwoLevelLruCache. Use this constructor if only the first
 * level memory cache is needed./*from   w w w.ja v  a  2  s.com*/
 * 
 * @param maxSizeMem
 */
public TwoLevelLruCache(int maxSizeMem) {
    super();

    mDiskCache = null;
    mConverter = null;
    mMemCache = new LruCache<String, V>(maxSizeMem) {

        @Override
        protected void entryRemoved(boolean evicted, String key, V oldValue, V newValue) {
            wrapEntryRemoved(evicted, key, oldValue, newValue);
        }

        @Override
        protected V create(String key) {
            return wrapCreate(key);
        }

        @Override
        protected int sizeOf(String key, V value) {
            return wrapSizeOf(key, value);
        }

    };
}

From source file:org.videolan.vlc.util.BitmapCache.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private BitmapCache() {

    // Get memory class of this device, exceeding this amount will throw an
    // OutOfMemory exception.
    final ActivityManager am = ((ActivityManager) VLCApplication.getAppContext()
            .getSystemService(Context.ACTIVITY_SERVICE));
    final int memClass = AndroidUtil.isHoneycombOrLater() ? am.getLargeMemoryClass() : am.getMemoryClass();

    // Use 1/5th of the available memory for this memory cache.
    final int cacheSize = 1024 * 1024 * memClass / 5;

    Log.d(TAG, "LRUCache size sets to " + cacheSize);

    mMemCache = new LruCache<String, Bitmap>(cacheSize) {

        @Override/*  w  w w  .  j a va 2 s.co  m*/
        protected int sizeOf(String key, Bitmap value) {
            return value.getRowBytes() * value.getHeight();
        }

    };
}

From source file:com.zhongyun.viewer.utils.ImageDownloader.java

public ImageDownloader() {
    options.inJustDecodeBounds = false;//  w  w  w .j av a 2s  .  com
    cacheDir = FileUtils.createFile(Constants.LOCAL_CID_ICON_PATH);

    int MAXMEMONRY = (int) (Runtime.getRuntime().maxMemory() / 1024);
    if (null == mMemoryCache) {
        mMemoryCache = new LruCache<String, Bitmap>(MAXMEMONRY / 8) {
            @Override
            protected int sizeOf(String key, Bitmap bitmap) {
                return bitmap.getRowBytes() * bitmap.getHeight() / 1024;
            }

            @Override
            protected void entryRemoved(boolean evicted, String key, Bitmap oldValue, Bitmap newValue) {
                if (oldValue != null && !oldValue.isRecycled()) {
                    oldValue.recycle();
                    oldValue = null;
                }

            }
        };
    }

    if (null == mMemoryCache_sd) {
        mMemoryCache_sd = new LruCache<String, Bitmap>(MAXMEMONRY / 8) {
            @Override
            protected int sizeOf(String key, Bitmap bitmap) {
                return bitmap.getRowBytes() * bitmap.getHeight() / 1024;
            }

            @Override
            protected void entryRemoved(boolean evicted, String key, Bitmap oldValue, Bitmap newValue) {
                if (oldValue != null && !oldValue.isRecycled()) {
                    oldValue.recycle();
                    oldValue = null;
                }

            }
        };
    }
}

From source file:com.social.solution.activity.UserProfile.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_parallaxtoolbarlistviewa);

    //setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    activityReference = this;

    mRequestQueue = Volley.newRequestQueue(this);
    imageLoader = new com.mopub.volley.toolbox.ImageLoader(mRequestQueue,
            new com.mopub.volley.toolbox.ImageLoader.ImageCache() {
                private final LruCache<String, Bitmap> mCache = new LruCache<String, Bitmap>(10);

                public void putBitmap(String url, Bitmap bitmap) {
                    mCache.put(url, bitmap);
                }//from   w w  w.j  a va  2  s.  com

                public Bitmap getBitmap(String url) {
                    return mCache.get(url);
                }
            });

    picture = (SquareImageView) findViewById(R.id.userimage);
    new LoadProfileImage().execute("0", "1");

    myTextView = findViewById(R.id.myflexibleview);
    //        mToolbarView = findViewById(R.id.toolbar);
    //        mToolbarView.setBackgroundColor(ScrollUtils.getColorWithAlpha(0, getResources().getColor(R.color.primary)));

    mParallaxImageHeight = getResources().getDimensionPixelSize(R.dimen.parallax_image_height);

    mListView = (ObservableListView) findViewById(R.id.list);
    mListView.setScrollViewCallbacks(this);
    // Set padding view for ListView. This is the flexible space.
    View paddingView = new View(this);
    AbsListView.LayoutParams lp = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT,
            mParallaxImageHeight);
    paddingView.setLayoutParams(lp);

    // This is required to disable header's list selector effect
    paddingView.setClickable(true);

    mListView.addHeaderView(paddingView);
    setDummyData(mListView);

    // mListBackgroundView makes ListView's background except header view.
    mListBackgroundView = findViewById(R.id.list_background);
}

From source file:com.trellmor.berrymotes.EmoteGetter.java

/**
 * Create new EmoteGetter instance/*from  w  ww.  j a  v  a  2  s  . c  o m*/
 * 
 * @param context
 *            Android context
 */
public EmoteGetter(Context context, EmoteLoader loader) {
    mResolver = context.getContentResolver();
    mCache = new LruCache<String, Drawable>(20);
    mAnimationCache = new LruCache<String, AnimationEmode>(5);
    mBlacklist = new HashSet<String>();
    mLoader = loader;
}

From source file:com.a37do.ssumnow.kakao.GlobalApplication.java

/**
 * ? ?, ? ?,  ?? .// w ww. j  a v a  2  s. c  om
 */
@Override
public void onCreate() {
    super.onCreate();
    instance = this;

    KakaoSDK.init(new KakaoSDKAdapter());

    final RequestQueue requestQueue = Volley.newRequestQueue(this);

    ImageLoader.ImageCache imageCache = new ImageLoader.ImageCache() {
        final LruCache<String, Bitmap> imageCache = new LruCache<String, Bitmap>(30);

        @Override
        public void putBitmap(String key, Bitmap value) {
            imageCache.put(key, value);
        }

        @Override
        public Bitmap getBitmap(String key) {
            return imageCache.get(key);
        }
    };

    imageLoader = new ImageLoader(requestQueue, imageCache);
}

From source file:com.kakao.game.sample.common.GlobalApplication.java

/**
 * ? ?, ? ?,  ?? .//from ww  w .  j  a va  2 s . c  o  m
 */
@Override
public void onCreate() {
    super.onCreate();
    instance = this;
    Log.d("bk", "init sdk");
    KakaoSDK.init(new KakaoSDKAdapter());

    final RequestQueue requestQueue = Volley.newRequestQueue(this);

    ImageLoader.ImageCache imageCache = new ImageLoader.ImageCache() {
        final LruCache<String, Bitmap> imageCache = new LruCache<String, Bitmap>(3);

        @Override
        public void putBitmap(String key, Bitmap value) {
            imageCache.put(key, value);
        }

        @Override
        public Bitmap getBitmap(String key) {
            return imageCache.get(key);
        }
    };

    imageLoader = new ImageLoader(requestQueue, imageCache);
}

From source file:at.wada811.android.library.demos.loader.LoaderListFragment.java

public void init() {
    mKeyword = null;/*from   w  w w . j av  a2s  .  c  o m*/
    if (sImageCache != null) {
        sImageCache.evictAll();
        sImageCache = null;
    }
    sImageCache = new LruCache<String, Bitmap>(10);
    if (mLoaderListAdapter != null) {
        mLoaderListAdapter.clear();
        mLoaderListAdapter.destroyAllLoaders();
    }
    setListShown(false);
}