Android LruCache - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android LruCache class.

This code example shows how to use the following methods:put
    protected void onPostExecute(Bitmap bitmap) {
 
        if (bitmap != null) {
            view.setVisibility(View.VISIBLE);
            view.setImageBitmap(bitmap);
            lruCache.put(data, bitmap);
 
        } else { 
            view.setImageDrawable(new ColorDrawable(Color.TRANSPARENT));
        } 
 
    } 
 
 
} 
6
CodeRank
This code example shows how to use the following methods:get, put, remove
	} 
 
	public Bitmap getBitmap(long key) {
		Bitmap bm = getFolderBitmap(key);
		if (bm != null) return bm;
		return mContentCache.get(key);
	} 
	 
	public void clearAll() { 
		clearContent(); 
		clearFolder(); 
	} 
	 
	public void clearContent() { 
		mContentCache.evictAll();
	} 
	 
	public void clearFolder() { 
		mFolderCache.evictAll();
	} 

7
CodeRank
This code example shows how to use the following methods:get
     * If only wants values that are not expired, use {@link #get(Object)} instead. 
     * 
     * @param key the key to look up 
     */ 
    public CachedValue<V> getCachedValue(K key) {
        return mCache.get(key);
    } 
 
    /** 
     * Returns the value for the given key, or null if no value exists. 
     * <p> 
     * When using this method, it is not possible to determine whether the value is expired or not. 
     * Use {@link #getCachedValue(Object)} to achieve that instead. However, if using 
     * {@link #getCachedValue(Object)} to determine if an item is expired, one should use the item 
     * within the {@link CachedValue} and not call {@link #getPossiblyExpired(Object)} to get the 
     * value afterwards, since that is not guaranteed to return the same value or that the newly 
     * returned value is in the same state. 
     * 
     * @param key the key to look up 
     */ 
6
CodeRank
This code example shows how to use the following methods:get, put
        mPadding      = context.getResources().getDimensionPixelOffset(R.dimen.marker_padding  );
    } 
 
    public Bitmap get(String color, String route) {
        String key = color+"_"+route;
        Bitmap bitmap = mCache.get(key);
        if (bitmap != null) {
            return bitmap;
        } 
        bitmap = render(Color.parseColor(color), route);
        mCache.put(key, bitmap);
        return bitmap;
    } 
 
    private Bitmap render(int color, String text) {
        TextPaint textPaint = new TextPaint();
        textPaint.setColor(Color.WHITE);
        textPaint.setStyle(Paint.Style.FILL);
        textPaint.setAntiAlias(true);
        textPaint.setTextSize(mTextSize);
5
CodeRank
This code example shows how to use the following methods:get
 
    private static final ThreadLocal<SoftReference<Entry>> cache = new ThreadLocal<SoftReference<Entry>>();
 
    static Entry instance() { 
        SoftReference<Entry> ref = cache.get();
        Entry entry = ref == null ? null : ref.get();
        if (entry == null) {
            HandlesStreamInput handles = new HandlesStreamInput();
            entry = new Entry(handles);
            cache.set(new SoftReference<Entry>(entry));
        } 
        return entry;
    } 
 
    public static void clear() { 
        cache.remove();
    } 
 
    public static StreamInput compressed(Compressor compressor, StreamInput in) throws IOException {
        return compressor.streamInput(in);
9
CodeRank
This code example shows how to use the following methods:
        super(delegate); 
    } 
 
    @Override 
    Reference<V> fold(V value) { 
        return new SoftReference<V>(value); 
    } 
 
} 
8
CodeRank
This code example shows how to use the following methods:
  private static ResourceBundle getBundle() {
    ResourceBundle bundle = null;
    if (ourBundle != null) bundle = ourBundle.get();
    if (bundle == null) {
      bundle = ResourceBundle.getBundle(PATH_TO_BUNDLE);
      ourBundle = new SoftReference<ResourceBundle>(bundle);
    } 
    return bundle;
  } 
} 
8
CodeRank
This code example shows how to use the following methods:
	} 
 
	public V put(K key, V value) {
		lock.lock();
		try { 
			map.put(key, new SoftReference<V>(value, queue));
			return value;
		} finally { 
			lock.unlock();
		} 
	} 
 
	public V get(K key) {
		lock.lock();
		try { 
			queue.poll();
			return map.get(key).get();
		} finally { 
			lock.unlock();
		} 
7
CodeRank
This code example shows how to use the following methods:
  private static ResourceBundle getBundle() {
    ResourceBundle bundle = null;
    if (ourBundle != null) bundle = ourBundle.get();
    if (bundle == null) {
      bundle = ResourceBundle.getBundle(PATH_TO_BUNDLE);
      ourBundle = new SoftReference<ResourceBundle>(bundle);
    } 
    return bundle;
  } 
} 
8
CodeRank
This code example shows how to use the following methods:
      if (reference != null) {
        System.out.println("[DEBUG] ********************* GC'ed SdkEnvironment reused!");
      } 
 
      sdkEnvironment = factory.create();
      sdkToEnvironmentSoft.put(sdkConfig, new SoftReference<SdkEnvironment>(sdkEnvironment));
    } 
 
    return sdkEnvironment;
  } 
} 
7
CodeRank

Related Android LruCache Questions & Answers:

Other Android LruCache Examples

5:	import android.support.v4.util.LruCache;
6:	
7:	public class LruBitmapCache extends LruCache<String, Bitmap> implements
8:			ImageCache {
9:		public static int getDefaultLruCacheSize() {

Read More

See Code Examples for Android LruCache Methods: