/** * 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); } }
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; } }