PageRenderTime 24ms CodeModel.GetById 17ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/UniversalImageLoader/src/com/nostra13/universalimageloader/core/DisplayImageOptions.java

https://github.com/rashedulkabir/Android-Universal-Image-Loader
Java | 178 lines | 91 code | 24 blank | 63 comment | 2 complexity | 9dcee24c77fef99ea704627eef5c19ae MD5 | raw file
  1package com.nostra13.universalimageloader.core;
  2
  3import android.graphics.Matrix;
  4
  5import com.nostra13.universalimageloader.core.assist.ImageScaleType;
  6
  7/**
  8 * Contains options for image display. Defines:
  9 * <ul>
 10 * <li>whether stub image will be displayed in {@link android.widget.ImageView ImageView} during image loading</li>
 11 * <li>whether stub image will be displayed in {@link android.widget.ImageView ImageView} if empty URI is passed</li>
 12 * <li>whether {@link android.widget.ImageView ImageView} should be reset before image loading start</li>
 13 * <li>whether loaded image will be cached in memory</li>
 14 * <li>whether loaded image will be cached on disc</li>
 15 * <li>image scale type</li>
 16 * <li>transformation matrix</li>
 17 * </ul>
 18 * 
 19 * You can create instance:
 20 * <ul>
 21 * <li>with {@link Builder}:<br />
 22 * <b>i.e.</b> :
 23 * <code>new {@link DisplayImageOptions}.{@link Builder#Builder() Builder()}.{@link Builder#cacheInMemory() cacheInMemory()}.
 24 * {@link Builder#showStubImage(int) showStubImage()}.{@link Builder#build() build()}</code><br />
 25 * </li>
 26 * <li>or by static method: {@link #createSimple()}</li> <br />
 27 * 
 28 * @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
 29 */
 30public final class DisplayImageOptions {
 31
 32	private final Integer stubImage;
 33	private final Integer imageForEmptyUri;
 34	private final boolean resetViewBeforeLoading;
 35	private final boolean cacheInMemory;
 36	private final boolean cacheOnDisc;
 37	private final ImageScaleType imageScaleType;
 38	private final Matrix transformationMatrix;
 39
 40	private DisplayImageOptions(Builder builder) {
 41		stubImage = builder.stubImage;
 42		imageForEmptyUri = builder.imageForEmptyUri;
 43		resetViewBeforeLoading = builder.resetViewBeforeLoading;
 44		cacheInMemory = builder.cacheInMemory;
 45		cacheOnDisc = builder.cacheOnDisc;
 46		imageScaleType = builder.imageScaleType;
 47		transformationMatrix = builder.transformationMatrix;
 48	}
 49
 50	boolean isShowStubImage() {
 51		return stubImage != null;
 52	}
 53
 54	boolean isShowImageForEmptyUri() {
 55		return imageForEmptyUri != null;
 56	}
 57
 58	Integer getStubImage() {
 59		return stubImage;
 60	}
 61
 62	Integer getImageForEmptyUri() {
 63		return imageForEmptyUri;
 64	}
 65
 66	boolean isResetViewBeforeLoading() {
 67		return resetViewBeforeLoading;
 68	}
 69
 70	boolean isCacheInMemory() {
 71		return cacheInMemory;
 72	}
 73
 74	boolean isCacheOnDisc() {
 75		return cacheOnDisc;
 76	}
 77
 78	ImageScaleType getImageScaleType() {
 79		return imageScaleType;
 80	}
 81
 82	Matrix getTransformationMatrix() {
 83		return transformationMatrix;
 84	}
 85
 86	/**
 87	 * Builder for {@link DisplayImageOptions}
 88	 * 
 89	 * @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
 90	 */
 91	public static class Builder {
 92		private Integer stubImage = null;
 93		private Integer imageForEmptyUri = null;
 94		private boolean resetViewBeforeLoading = false;
 95		private boolean cacheInMemory = false;
 96		private boolean cacheOnDisc = false;
 97		private ImageScaleType imageScaleType = ImageScaleType.POWER_OF_2;
 98		private Matrix transformationMatrix = null;
 99
100		/**
101		 * Stub image will be displayed in {@link android.widget.ImageView ImageView} during image loading
102		 * 
103		 * @param stubImageRes
104		 *            Stub image resource
105		 */
106		public Builder showStubImage(int stubImageRes) {
107			stubImage = stubImageRes;
108			return this;
109		}
110
111		/**
112		 * Image will be displayed in {@link android.widget.ImageView ImageView} if empty URI (null or empty string)
113		 * will be passed to <b>ImageLoader.displayImage(...)</b> method.
114		 * 
115		 * @param imageRes
116		 *            Image resource
117		 */
118		public Builder showImageForEmptyUri(int imageRes) {
119			imageForEmptyUri = imageRes;
120			return this;
121		}
122
123		/** {@link android.widget.ImageView ImageView} will be reset (set <b>null</b>) before image loading start */
124		public Builder resetViewBeforeLoading() {
125			resetViewBeforeLoading = true;
126			return this;
127		}
128
129		/** Loaded image will be cached in memory */
130		public Builder cacheInMemory() {
131			cacheInMemory = true;
132			return this;
133		}
134
135		/** Loaded image will be cached on disc */
136		public Builder cacheOnDisc() {
137			cacheOnDisc = true;
138			return this;
139		}
140
141		/**
142		 * Sets {@link ImageScaleType decoding type} for image loading task. Default value -
143		 * {@link ImageScaleType#POWER_OF_2}
144		 */
145		public Builder imageScaleType(ImageScaleType imageScaleType) {
146			this.imageScaleType = imageScaleType;
147			return this;
148		}
149
150		/**
151		 * Sets transformation {@link android.graphics.Matrix} which will be applied to the decoded image before display
152		 */
153		public Builder transform(Matrix transformationMatrix) {
154			this.transformationMatrix = transformationMatrix;
155			return this;
156		}
157
158		/** Builds configured {@link DisplayImageOptions} object */
159		public DisplayImageOptions build() {
160			return new DisplayImageOptions(this);
161		}
162	}
163
164	/**
165	 * Creates options appropriate for single displaying:
166	 * <ul>
167	 * <li>Stub image will <b>not</b> be displayed in {@link android.widget.ImageView ImageView} during image loading</li>
168	 * <li>Loaded image will <b>not</b> be cached in memory</li>
169	 * <li>Loaded image will <b>not</b> be cached on disc (application cache directory or on SD card)</li>
170	 * <li>{@link ImageScaleType#POWER_OF_2 FAST} decoding type will be used</li>
171	 * </ul>
172	 * 
173	 * These option are appropriate for simple single-use image (from drawables or from internet) displaying.
174	 */
175	public static DisplayImageOptions createSimple() {
176		return new Builder().build();
177	}
178}