Android Open Source - Android-Fast-ImageLoader Thumbnail Loader






From Project

Back to project page Android-Fast-ImageLoader.

License

The source code is released under:

Apache License

If you think the Android project Android-Fast-ImageLoader 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 com.sunny.cache;
/*from w  w  w  .ja v  a2s  .c  om*/
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Build;
import android.webkit.URLUtil;
import android.widget.ImageView;

import com.sunny.util.MD5Util;

/**
 * 1. Keep Clean away from Download. 2. More timely recycle. 3. Priority of
 * download.
 * 
 * @author Kang, Leo
 */
public class ThumbnailLoader extends CacheWorker {

  /**
   * Memory cache!
   */
  // public static ArrayList<ThumbnailLoader> instances = new
  // ArrayList<ThumbnailLoader>();
  private static ThumbnailLoader instance;
  private String cacheDir = null;

  public synchronized static ThumbnailLoader getInstance(Context context,
      String loaderTag, String cachedir) {
    // ThumbnailLoader result = null;
    // for (ThumbnailLoader loader : instances) {
    // if (loader.tag.equalsIgnoreCase(loaderTag)) {
    // result = loader;
    // }
    // }
    if (instance == null) {
      final String path = getCacheFolder(context, cachedir);

      // judge static cover picture
      instance = new ThumbnailLoader(context, loaderTag, path, true);
      // TODO can enable auto clean cache file.
      instance.cleanCache = false;
      // instances.add(result);
    }
    // result.restartThreadPool();
    return instance;
  }

  @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
  public ThumbnailLoader(Context context, String tag, String cachePath,
      boolean sortASC) {
    super(context, cachePath, sortASC);
    this.tag = tag;
    this.cacheDir = cachePath;
  }

  // public static void hardEvict() {
  // for (ThumbnailLoader self : instances) {
  // self.cleanMemoryCache();
  // self.searchThreadPool.shutdownNow();
  // self.downloadThreadQueue.cancelQueueByCategory(self.tag);
  // self.restartThreadPool();
  // }
  // }

  /**
   * ????????
   * 
   * @return
   */
  public String getCacheDir() {
    return this.cacheDir;
  }

  /**
   * ??????????
   * 
   * @param url
   * @return
   */
  public String getFilePath(String url) {
    return cacheDir + "/" + MD5Util.getStringMD5(url);
  }

  public synchronized void loadRemoteImage(String url, ImageView view,
      Builder cacheParams, OnSetImageListener setImageListener) {
    if (URLUtil.isValidUrl(url)) {
      doLoadRemoteImage(url, view, cacheParams, setImageListener);
    }

  }

  public synchronized void loadLocalImage(String filename, ImageView view,
      Builder cacheParams, Bitmap loadingBitmap,
      OnSetImageListener setImageListener) {
    if (URLUtil.isFileUrl(filename)) {
      doLoadLocalImage(filename, view, cacheParams, loadingBitmap,
          setImageListener);
    }
  }

}




Java Source Code List

com.sunny.cache.BaseLoadListener.java
com.sunny.cache.CacheWorker.java
com.sunny.cache.DiskLruCache.java
com.sunny.cache.FileLastModifSort.java
com.sunny.cache.GIFDecoder.java
com.sunny.cache.IDownloadHandler.java
com.sunny.cache.MemoryCache.java
com.sunny.cache.OnSetImageListener.java
com.sunny.cache.RecyclingBitmapDrawable.java
com.sunny.cache.ThumbnailLoader.java
com.sunny.net.DHttpClient.java
com.sunny.net.ProxyUtil.java
com.sunny.threadpool.AbstractCommand.java
com.sunny.threadpool.CommandFactory.java
com.sunny.threadpool.DThreadPool.java
com.sunny.threadpool.IDThreadPool.java
com.sunny.threadpool.IPriorityTask.java
com.sunny.threadpool.ITaskHandler.java
com.sunny.threadpool.PriorityTask.java
com.sunny.threadpool.PriorityThreadFactory.java
com.sunny.threadpool.TaskPriority.java
com.sunny.util.ImageUtil.java
com.sunny.util.MD5Util.java
com.sunny.util.Utils.java