Ejemplo n.º 1
0
  ImageLoaderEngine(ImageLoaderConfiguration configuration) {
    this.configuration = configuration;

    taskExecutor = configuration.taskExecutor;
    taskExecutorForCachedImages = configuration.taskExecutorForCachedImages;

    taskDistributor = DefaultConfigurationFactory.createTaskDistributor();
  }
 private void initEmptyFiledsWithDefaultValues() {
   if (discCache == null) {
     if (discCacheFileNameGenerator == null) {
       discCacheFileNameGenerator = DefaultConfigurationFactory.createFileNameGenerator();
     }
     discCache =
         DefaultConfigurationFactory.createDiscCache(
             context, discCacheFileNameGenerator, discCacheSize, discCacheFileCount);
   }
   if (memoryCache == null) {
     memoryCache =
         DefaultConfigurationFactory.createMemoryCache(
             memoryCacheSize, denyCacheImageMultipleSizesInMemory);
   }
   if (downloader == null) {
     downloader = DefaultConfigurationFactory.createImageDownloader(context);
   }
   if (defaultDisplayImageOptions == null) {
     defaultDisplayImageOptions = DisplayImageOptions.createSimple();
   }
 }
 private void initEmptyFieldsWithDefaultValues()
 {
     if (taskExecutor == null)
     {
         taskExecutor = DefaultConfigurationFactory.createExecutor(threadPoolSize, threadPriority, tasksProcessingType);
     } else
     {
         customExecutor = true;
     }
     if (taskExecutorForCachedImages == null)
     {
         taskExecutorForCachedImages = DefaultConfigurationFactory.createExecutor(threadPoolSize, threadPriority, tasksProcessingType);
     } else
     {
         customExecutorForCachedImages = true;
     }
     if (diskCache == null)
     {
         if (diskCacheFileNameGenerator == null)
         {
             diskCacheFileNameGenerator = DefaultConfigurationFactory.createFileNameGenerator();
         }
         diskCache = DefaultConfigurationFactory.createDiskCache(context, diskCacheFileNameGenerator, diskCacheSize, diskCacheFileCount);
     }
     if (memoryCache == null)
     {
         memoryCache = DefaultConfigurationFactory.createMemoryCache(memoryCacheSize);
     }
     if (denyCacheImageMultipleSizesInMemory)
     {
         memoryCache = new FuzzyKeyMemoryCache(memoryCache, MemoryCacheUtils.createFuzzyKeyComparator());
     }
     if (downloader == null)
     {
         downloader = DefaultConfigurationFactory.createImageDownloader(context);
     }
     if (decoder == null)
     {
         decoder = DefaultConfigurationFactory.createImageDecoder(writeLogs);
     }
     if (defaultDisplayImageOptions == null)
     {
         defaultDisplayImageOptions = DisplayImageOptions.createSimple();
     }
 }
Ejemplo n.º 4
0
 @Override
 public void onCreate() {
   super.onCreate();
   application = this;
   WindowManager wm = (WindowManager) this.getSystemService(WINDOW_SERVICE);
   screenHeight = wm.getDefaultDisplay().getHeight();
   screenWidth = wm.getDefaultDisplay().getWidth();
   ImageLoaderConfiguration configuration =
       new ImageLoaderConfiguration.Builder(this)
           .memoryCacheExtraOptions(screenWidth, screenHeight) // 设置解析图片的大小,一般以手机屏幕大小为准
           .diskCacheExtraOptions(screenWidth, screenHeight, null) // 保存到磁盘使用的大小以及压缩方法,默认原图保存
           .threadPoolSize(3) // 线程池大小,不能太大,会出现OOM
           .threadPriority(Thread.NORM_PRIORITY - 1) // 设置线程的优先程度 5-1
           .tasksProcessingOrder(
               QueueProcessingType.FIFO) // 设置图片加载和显示队列处理的类型 默认为QueueProcessingType.
           //  FIFO注:如果设置了taskExecutor或者taskExecutorForCachedImages 此设置无效
           .memoryCache(new LruMemoryCache(2 * 1024 * 1024)) // 设置内存缓存 默认为一个当前应用可用内存的1/8大小的
           .memoryCacheSize(2 * 1024 * 1014) // 设置内存缓存的最大大小 默认为一个当前应用可用内存的1/8
           .memoryCacheSizePercentage(13) // 设置内存缓存最大大小占当前应用可用内存的百分比 默认为一个当前应用可用内存的1/8
           .diskCache(
               new UnlimitedDiskCache(
                   StorageUtils.getCacheDirectory(
                       getApplicationContext()))) // 默认为StorageUtils.getCacheDirectory(getApplicationContext()),即/mnt/sdcard/android/data/包名/cache/
           .diskCacheSize(50 * 1024 * 1024) // 设置硬盘缓存的最大大小
           .diskCacheFileCount(100) // 设置硬盘缓存的文件的最多个数
           .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // 设置硬盘缓存文件名生成规范
           .imageDownloader(new BaseImageDownloader(this)) // 设置图片下载器
           .imageDecoder(DefaultConfigurationFactory.createImageDecoder(false)) // 设置图片的解析器
           .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // 设置默认的图片显示选项
           .denyCacheImageMultipleSizesInMemory() // 不缓存图片的多种尺寸在内存中
           .writeDebugLogs() // 打印调试Log,注意上线之前要去掉这句话
           .imageDownloader(
               new BaseImageDownloader(this, 5 * 1000, 30 * 1000)) // 图片下载器的设置  超时时间   读取时间
           .build();
   ImageLoader.getInstance().init(configuration); // 使用基本配置信息初始化ImageLoader
 }
  /**
   * Builder for {@link com.nostra13.universalimageloader.core.DisplayImageOptions}
   *
   * @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
   */
  public static class Builder {
    private int imageResOnLoading = 0;
    private int imageResForEmptyUri = 0;
    private int imageResOnFail = 0;
    private Drawable imageOnLoading = null;
    private Drawable imageForEmptyUri = null;
    private Drawable imageOnFail = null;
    private boolean resetViewBeforeLoading = false;
    private boolean cacheInMemory = false;
    private boolean cacheOnDisk = false;
    private ImageScaleType imageScaleType = ImageScaleType.IN_SAMPLE_POWER_OF_2;
    private Options decodingOptions = new Options();
    private int delayBeforeLoading = 0;
    private boolean considerExifParams = false;
    private Object extraForDownloader = null;
    private BitmapProcessor preProcessor = null;
    private BitmapProcessor postProcessor = null;
    private BitmapDisplayer displayer = DefaultConfigurationFactory.createBitmapDisplayer();
    private Handler handler = null;
    private boolean isSyncLoading = false;

    public Builder() {
      decodingOptions.inPurgeable = true;
      decodingOptions.inInputShareable = true;
    }

    /**
     * Stub image will be displayed in {@link
     * com.nostra13.universalimageloader.core.imageaware.ImageAware image aware view} during image
     * loading
     *
     * @param imageRes Stub image resource
     * @deprecated Use {@link #showImageOnLoading(int)} instead
     */
    @Deprecated
    public Builder showStubImage(int imageRes) {
      imageResOnLoading = imageRes;
      return this;
    }

    /**
     * Incoming image will be displayed in {@link
     * com.nostra13.universalimageloader.core.imageaware.ImageAware image aware view} during image
     * loading
     *
     * @param imageRes Image resource
     */
    public Builder showImageOnLoading(int imageRes) {
      imageResOnLoading = imageRes;
      return this;
    }

    /**
     * Incoming drawable will be displayed in {@link
     * com.nostra13.universalimageloader.core.imageaware.ImageAware image aware view} during image
     * loading. This option will be ignored if {@link
     * com.nostra13.universalimageloader.core.DisplayImageOptions.Builder#showImageOnLoading(int)}
     * is set.
     */
    public Builder showImageOnLoading(Drawable drawable) {
      imageOnLoading = drawable;
      return this;
    }

    /**
     * Incoming image will be displayed in {@link
     * com.nostra13.universalimageloader.core.imageaware.ImageAware image aware view} if empty URI
     * (null or empty string) will be passed to <b>ImageLoader.displayImage(...)</b> method.
     *
     * @param imageRes Image resource
     */
    public Builder showImageForEmptyUri(int imageRes) {
      imageResForEmptyUri = imageRes;
      return this;
    }

    /**
     * Incoming drawable will be displayed in {@link
     * com.nostra13.universalimageloader.core.imageaware.ImageAware image aware view} if empty URI
     * (null or empty string) will be passed to <b>ImageLoader.displayImage(...)</b> method. This
     * option will be ignored if {@link
     * com.nostra13.universalimageloader.core.DisplayImageOptions.Builder#showImageForEmptyUri(int)}
     * is set.
     */
    public Builder showImageForEmptyUri(Drawable drawable) {
      imageForEmptyUri = drawable;
      return this;
    }

    /**
     * Incoming image will be displayed in {@link
     * com.nostra13.universalimageloader.core.imageaware.ImageAware image aware view} if some error
     * occurs during requested image loading/decoding.
     *
     * @param imageRes Image resource
     */
    public Builder showImageOnFail(int imageRes) {
      imageResOnFail = imageRes;
      return this;
    }

    /**
     * Incoming drawable will be displayed in {@link
     * com.nostra13.universalimageloader.core.imageaware.ImageAware image aware view} if some error
     * occurs during requested image loading/decoding. This option will be ignored if {@link
     * com.nostra13.universalimageloader.core.DisplayImageOptions.Builder#showImageOnFail(int)} is
     * set.
     */
    public Builder showImageOnFail(Drawable drawable) {
      imageOnFail = drawable;
      return this;
    }

    /**
     * {@link com.nostra13.universalimageloader.core.imageaware.ImageAware image aware view} will be
     * reset (set <b>null</b>) before image loading start
     *
     * @deprecated Use {@link #resetViewBeforeLoading(boolean) resetViewBeforeLoading(true)} instead
     */
    public Builder resetViewBeforeLoading() {
      resetViewBeforeLoading = true;
      return this;
    }

    /**
     * Sets whether {@link com.nostra13.universalimageloader.core.imageaware.ImageAware image aware
     * view} will be reset (set <b>null</b>) before image loading start
     */
    public Builder resetViewBeforeLoading(boolean resetViewBeforeLoading) {
      this.resetViewBeforeLoading = resetViewBeforeLoading;
      return this;
    }

    /**
     * Loaded image will be cached in memory
     *
     * @deprecated Use {@link #cacheInMemory(boolean) cacheInMemory(true)} instead
     */
    @Deprecated
    public Builder cacheInMemory() {
      cacheInMemory = true;
      return this;
    }

    /** Sets whether loaded image will be cached in memory */
    public Builder cacheInMemory(boolean cacheInMemory) {
      this.cacheInMemory = cacheInMemory;
      return this;
    }

    /**
     * Loaded image will be cached on disk
     *
     * @deprecated Use {@link #cacheOnDisk(boolean) cacheOnDisk(true)} instead
     */
    @Deprecated
    public Builder cacheOnDisc() {
      return cacheOnDisk(true);
    }

    /**
     * Sets whether loaded image will be cached on disk
     *
     * @deprecated Use {@link #cacheOnDisk(boolean)} instead
     */
    @Deprecated
    public Builder cacheOnDisc(boolean cacheOnDisk) {
      return cacheOnDisk(cacheOnDisk);
    }

    /** Sets whether loaded image will be cached on disk */
    public Builder cacheOnDisk(boolean cacheOnDisk) {
      this.cacheOnDisk = cacheOnDisk;
      return this;
    }

    /**
     * Sets {@linkplain com.nostra13.universalimageloader.core.assist.ImageScaleType scale type} for
     * decoding image. This parameter is used while define scale size for decoding image to Bitmap.
     * Default value - {@link
     * com.nostra13.universalimageloader.core.assist.ImageScaleType#IN_SAMPLE_POWER_OF_2}
     */
    public Builder imageScaleType(ImageScaleType imageScaleType) {
      this.imageScaleType = imageScaleType;
      return this;
    }

    /**
     * Sets {@link android.graphics.Bitmap.Config bitmap config} for image decoding. Default value -
     * {@link android.graphics.Bitmap.Config#ARGB_8888}
     */
    public Builder bitmapConfig(Bitmap.Config bitmapConfig) {
      if (bitmapConfig == null) throw new IllegalArgumentException("bitmapConfig can't be null");
      decodingOptions.inPreferredConfig = bitmapConfig;
      return this;
    }

    /**
     * Sets options for image decoding.<br>
     * <b>NOTE:</b> {@link android.graphics.BitmapFactory.Options#inSampleSize} of incoming options
     * will <b>NOT</b> be considered. Library calculate the most appropriate sample size itself
     * according yo {@link
     * #imageScaleType(com.nostra13.universalimageloader.core.assist.ImageScaleType)} options.<br>
     * <b>NOTE:</b> This option overlaps {@link #bitmapConfig(android.graphics.Bitmap.Config)
     * bitmapConfig()} option.
     */
    public Builder decodingOptions(Options decodingOptions) {
      if (decodingOptions == null)
        throw new IllegalArgumentException("decodingOptions can't be null");
      this.decodingOptions = decodingOptions;
      return this;
    }

    /** Sets delay time before starting loading task. Default - no delay. */
    public Builder delayBeforeLoading(int delayInMillis) {
      this.delayBeforeLoading = delayInMillis;
      return this;
    }

    /**
     * Sets auxiliary object which will be passed to {@link
     * com.nostra13.universalimageloader.core.download.ImageDownloader#getStream(String, Object)}
     */
    public Builder extraForDownloader(Object extra) {
      this.extraForDownloader = extra;
      return this;
    }

    /** Sets whether ImageLoader will consider EXIF parameters of JPEG image (rotate, flip) */
    public Builder considerExifParams(boolean considerExifParams) {
      this.considerExifParams = considerExifParams;
      return this;
    }

    /**
     * Sets bitmap processor which will be process bitmaps before they will be cached in memory. So
     * memory cache will contain bitmap processed by incoming preProcessor.<br>
     * Image will be pre-processed even if caching in memory is disabled.
     */
    public Builder preProcessor(BitmapProcessor preProcessor) {
      this.preProcessor = preProcessor;
      return this;
    }

    /**
     * Sets bitmap processor which will be process bitmaps before they will be displayed in {@link
     * com.nostra13.universalimageloader.core.imageaware.ImageAware image aware view} but after
     * they'll have been saved in memory cache.
     */
    public Builder postProcessor(BitmapProcessor postProcessor) {
      this.postProcessor = postProcessor;
      return this;
    }

    /**
     * Sets custom {@link com.nostra13.universalimageloader.core.display.BitmapDisplayer displayer}
     * for image loading task. Default value - {@link
     * DefaultConfigurationFactory#createBitmapDisplayer()}
     */
    public Builder displayer(BitmapDisplayer displayer) {
      if (displayer == null) throw new IllegalArgumentException("displayer can't be null");
      this.displayer = displayer;
      return this;
    }

    Builder syncLoading(boolean isSyncLoading) {
      this.isSyncLoading = isSyncLoading;
      return this;
    }

    /**
     * Sets custom {@linkplain android.os.Handler handler} for displaying images and firing
     * {@linkplain com.nostra13.universalimageloader.core.listener.ImageLoadingListener listener}
     * events.
     */
    public Builder handler(Handler handler) {
      this.handler = handler;
      return this;
    }

    /** Sets all options equal to incoming options */
    public Builder cloneFrom(DisplayImageOptions options) {
      imageResOnLoading = options.imageResOnLoading;
      imageResForEmptyUri = options.imageResForEmptyUri;
      imageResOnFail = options.imageResOnFail;
      imageOnLoading = options.imageOnLoading;
      imageForEmptyUri = options.imageForEmptyUri;
      imageOnFail = options.imageOnFail;
      resetViewBeforeLoading = options.resetViewBeforeLoading;
      cacheInMemory = options.cacheInMemory;
      cacheOnDisk = options.cacheOnDisk;
      imageScaleType = options.imageScaleType;
      decodingOptions = options.decodingOptions;
      delayBeforeLoading = options.delayBeforeLoading;
      considerExifParams = options.considerExifParams;
      extraForDownloader = options.extraForDownloader;
      preProcessor = options.preProcessor;
      postProcessor = options.postProcessor;
      displayer = options.displayer;
      handler = options.handler;
      isSyncLoading = options.isSyncLoading;
      return this;
    }

    /**
     * Builds configured {@link com.nostra13.universalimageloader.core.DisplayImageOptions} object
     */
    public DisplayImageOptions build() {
      return new DisplayImageOptions(this);
    }
  }
Ejemplo n.º 6
0
 private Executor createTaskExecutor() {
   return DefaultConfigurationFactory.createExecutor(
       configuration.threadPoolSize,
       configuration.threadPriority,
       configuration.tasksProcessingType);
 }
Ejemplo n.º 7
0
public class DisplayImageOptions$Builder {
  private int a = 0;
  private int b = 0;
  private int c = 0;
  private Drawable d = null;
  private Drawable e = null;
  private Drawable f = null;
  private boolean g = false;
  private boolean h = false;
  private boolean i = false;
  private ImageScaleType j = ImageScaleType.IN_SAMPLE_POWER_OF_2;
  private BitmapFactory.Options k = new BitmapFactory.Options();
  private int l = 0;
  private boolean m = false;
  private Object n = null;
  private BitmapProcessor o = null;
  private BitmapProcessor p = null;
  private BitmapDisplayer q = DefaultConfigurationFactory.createBitmapDisplayer();
  private Handler r = null;
  private boolean s = false;

  public DisplayImageOptions$Builder() {
    this.k.inPurgeable = true;
    this.k.inInputShareable = true;
  }

  final Builder a(boolean paramBoolean) {
    this.s = true;
    return this;
  }

  public Builder bitmapConfig(Bitmap.Config paramConfig) {
    if (paramConfig == null) throw new IllegalArgumentException("bitmapConfig can't be null");
    this.k.inPreferredConfig = paramConfig;
    return this;
  }

  public DisplayImageOptions build() {
    return new DisplayImageOptions(this, (byte) 0);
  }

  public Builder cacheInMemory() {
    this.h = true;
    return this;
  }

  public Builder cacheInMemory(boolean paramBoolean) {
    this.h = paramBoolean;
    return this;
  }

  public Builder cacheOnDisc() {
    return cacheOnDisk(true);
  }

  public Builder cacheOnDisc(boolean paramBoolean) {
    return cacheOnDisk(paramBoolean);
  }

  public Builder cacheOnDisk(boolean paramBoolean) {
    this.i = paramBoolean;
    return this;
  }

  public Builder cloneFrom(DisplayImageOptions paramDisplayImageOptions) {
    this.a = DisplayImageOptions.a(paramDisplayImageOptions);
    this.b = DisplayImageOptions.b(paramDisplayImageOptions);
    this.c = DisplayImageOptions.c(paramDisplayImageOptions);
    this.d = DisplayImageOptions.d(paramDisplayImageOptions);
    this.e = DisplayImageOptions.e(paramDisplayImageOptions);
    this.f = DisplayImageOptions.f(paramDisplayImageOptions);
    this.g = DisplayImageOptions.g(paramDisplayImageOptions);
    this.h = DisplayImageOptions.h(paramDisplayImageOptions);
    this.i = DisplayImageOptions.i(paramDisplayImageOptions);
    this.j = DisplayImageOptions.j(paramDisplayImageOptions);
    this.k = DisplayImageOptions.k(paramDisplayImageOptions);
    this.l = DisplayImageOptions.l(paramDisplayImageOptions);
    this.m = DisplayImageOptions.m(paramDisplayImageOptions);
    this.n = DisplayImageOptions.n(paramDisplayImageOptions);
    this.o = DisplayImageOptions.o(paramDisplayImageOptions);
    this.p = DisplayImageOptions.p(paramDisplayImageOptions);
    this.q = DisplayImageOptions.q(paramDisplayImageOptions);
    this.r = DisplayImageOptions.r(paramDisplayImageOptions);
    this.s = DisplayImageOptions.s(paramDisplayImageOptions);
    return this;
  }

  public Builder considerExifParams(boolean paramBoolean) {
    this.m = paramBoolean;
    return this;
  }

  public Builder decodingOptions(BitmapFactory.Options paramOptions) {
    if (paramOptions == null) throw new IllegalArgumentException("decodingOptions can't be null");
    this.k = paramOptions;
    return this;
  }

  public Builder delayBeforeLoading(int paramInt) {
    this.l = paramInt;
    return this;
  }

  public Builder displayer(BitmapDisplayer paramBitmapDisplayer) {
    if (paramBitmapDisplayer == null) throw new IllegalArgumentException("displayer can't be null");
    this.q = paramBitmapDisplayer;
    return this;
  }

  public Builder extraForDownloader(Object paramObject) {
    this.n = paramObject;
    return this;
  }

  public Builder handler(Handler paramHandler) {
    this.r = paramHandler;
    return this;
  }

  public Builder imageScaleType(ImageScaleType paramImageScaleType) {
    this.j = paramImageScaleType;
    return this;
  }

  public Builder postProcessor(BitmapProcessor paramBitmapProcessor) {
    this.p = paramBitmapProcessor;
    return this;
  }

  public Builder preProcessor(BitmapProcessor paramBitmapProcessor) {
    this.o = paramBitmapProcessor;
    return this;
  }

  public Builder resetViewBeforeLoading() {
    this.g = true;
    return this;
  }

  public Builder resetViewBeforeLoading(boolean paramBoolean) {
    this.g = paramBoolean;
    return this;
  }

  public Builder showImageForEmptyUri(int paramInt) {
    this.b = paramInt;
    return this;
  }

  public Builder showImageForEmptyUri(Drawable paramDrawable) {
    this.e = paramDrawable;
    return this;
  }

  public Builder showImageOnFail(int paramInt) {
    this.c = paramInt;
    return this;
  }

  public Builder showImageOnFail(Drawable paramDrawable) {
    this.f = paramDrawable;
    return this;
  }

  public Builder showImageOnLoading(int paramInt) {
    this.a = paramInt;
    return this;
  }

  public Builder showImageOnLoading(Drawable paramDrawable) {
    this.d = paramDrawable;
    return this;
  }

  public Builder showStubImage(int paramInt) {
    this.a = paramInt;
    return this;
  }
}
Ejemplo n.º 8
0
 /**
  * @param cacheDir Directory for file caching. <b>Important:</b> Specify separate folder for
  *     cached files. It's needed for right cache limit work.
  * @param sizeLimit Cache limit value. If cache exceeds this limit then file with the most oldest
  *     last usage date will be deleted.
  */
 public LimitedDiscCache(File cacheDir, int sizeLimit) {
   this(cacheDir, DefaultConfigurationFactory.createFileNameGenerator(), sizeLimit);
 }
 /**
  * @param cacheDir Directory for file caching. <b>Important:</b> Specify separate folder for
  *     cached files. It's needed for right cache limit work.
  * @param maxCacheSize Maximum cache directory size (in bytes). If cache size exceeds this limit
  *     then file with the most oldest last usage date will be deleted.
  */
 public TotalSizeLimitedDiscCache(File cacheDir, int maxCacheSize) {
   this(cacheDir, DefaultConfigurationFactory.createFileNameGenerator(), maxCacheSize);
 }