Android Open Source - fileEx Image Cache






From Project

Back to project page fileEx.

License

The source code is released under:

Apache License

If you think the Android project fileEx 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 android.howard.exp.adapter;
/*  w w w  .j a  va  2  s .c o m*/
import android.app.ActivityManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.LruCache;

/**
 * @author howard image cache >>>lruCache provider
 * 
 */
public final class ImageCache {

  private LruCache<String, Bitmap> mLruCache;
  private static ImageCache sInstance;

  public ImageCache(final Context context) {
    init(context);
  }

  public final static ImageCache getInstance(final Context context) {
    if (sInstance == null) {
      sInstance = new ImageCache(context.getApplicationContext());
    }
    return sInstance;
  }

  public void init(final Context context) {
    final ActivityManager activityManager = (ActivityManager) context
        .getSystemService(Context.ACTIVITY_SERVICE);
    final int lruCacheSize = Math.round(0.25f * activityManager
        .getMemoryClass() * 1024 * 1024);
    mLruCache = new LruCache<String, Bitmap>(lruCacheSize) {
      @Override
      protected int sizeOf(final String paramString,
          final Bitmap paramBitmap) {
        return paramBitmap.getByteCount();
      }

    };
  }

  public void add(final String data, final Bitmap bitmap) {
    if (data == null || bitmap == null) {
      return;
    }
    if (get(data) == null) {
      mLruCache.put(data, bitmap);
    }
  }

  public final Bitmap get(final String data) {
    if (data == null) {
      return null;
    }
    if (mLruCache != null) {
      final Bitmap mBitmap = mLruCache.get(data);
      if (mBitmap != null) {
        return mBitmap;
      }
    }
    return null;
  }

  public void remove(final String key) {
    if (mLruCache != null) {
      mLruCache.remove(key);
    }
  }

  public void clearMemCache() {
    if (mLruCache != null) {
      mLruCache.evictAll();
    }
    System.gc();
  }

}




Java Source Code List

android.howard.exp.adapter.ImageCache.java
android.howard.exp.adapter.ImageReaderTask.java
android.howard.exp.adapter.NaviAdapter.java
android.howard.exp.adapter.ViedioReaderTask.java
android.howard.exp.bean.RootItemBean.java
android.howard.exp.fragment.BaseFragment.java
android.howard.exp.fragment.MenuDrawer.java
android.howard.exp.fragment.RootPage.java
android.howard.exp.fragment.TextReader.java
android.howard.exp.utils.TextFileReader.java
android.howard.exp.views.FlectImageView.java
android.howard.exp.views.ListViewCompat.java
android.howard.exp.views.SlideView.java
com.bpok.fileex.FileExApp.java