(config.getWidth(), config.getHeight()) {
82 | @Override
83 | public void onResourceReady(Bitmap bitmap, GlideAnimation glideAnimation) {
84 | config.getBitmapListener().onSuccess(bitmap);
85 | }
86 | };
87 |
88 | setShapeModeAndBlur(config, request);
89 |
90 | if (config.getDiskCacheStrategy() != null) {
91 | request.diskCacheStrategy(config.getDiskCacheStrategy());
92 | }
93 |
94 | request.asBitmap().into(target);
95 |
96 | } else {
97 |
98 | if (request == null) {
99 | return;
100 | }
101 |
102 | if (ImageUtil.shouldSetPlaceHolder(config)) {
103 | request.placeholder(config.getPlaceHolderResId());
104 | }
105 |
106 | int scaleMode = config.getScaleMode();
107 |
108 | switch (scaleMode) {
109 | case ScaleMode.CENTER_CROP:
110 | request.centerCrop();
111 | break;
112 | case ScaleMode.FIT_CENTER:
113 | request.fitCenter();
114 | break;
115 | default:
116 | request.fitCenter();
117 | break;
118 | }
119 |
120 | setShapeModeAndBlur(config, request);
121 |
122 | //设置缩略图
123 | if (config.getThumbnail() != 0) {
124 | request.thumbnail(config.getThumbnail());
125 | }
126 |
127 | //设置图片加载的分辨 sp
128 | if (config.getoWidth() != 0 && config.getoHeight() != 0) {
129 | request.override(config.getoWidth(), config.getoHeight());
130 | }
131 |
132 | //是否跳过磁盘存储
133 | if (config.getDiskCacheStrategy() != null) {
134 | request.diskCacheStrategy(config.getDiskCacheStrategy());
135 | }
136 |
137 | //设置图片加载动画
138 | setAnimator(config, request);
139 |
140 | //设置图片加载优先级
141 | setPriority(config, request);
142 |
143 | if (config.getErrorResId() > 0) {
144 | request.error(config.getErrorResId());
145 | }
146 |
147 | if(config.isGif()){
148 | request.asGif();
149 | }
150 |
151 | if (config.getTarget() instanceof ImageView) {
152 | request.into((ImageView) config.getTarget());
153 |
154 | }
155 | }
156 |
157 | }
158 |
159 | /**
160 | * 设置加载优先级
161 | *
162 | * @param config
163 | * @param request
164 | */
165 | private void setPriority(SingleConfig config, DrawableTypeRequest request) {
166 | switch (config.getPriority()) {
167 | case PriorityMode.PRIORITY_LOW:
168 | request.priority(Priority.LOW);
169 | break;
170 | case PriorityMode.PRIORITY_NORMAL:
171 | request.priority(Priority.NORMAL);
172 | break;
173 | case PriorityMode.PRIORITY_HIGH:
174 | request.priority(Priority.HIGH);
175 | break;
176 | case PriorityMode.PRIORITY_IMMEDIATE:
177 | request.priority(Priority.IMMEDIATE);
178 | break;
179 | default:
180 | request.priority(Priority.IMMEDIATE);
181 | break;
182 | }
183 | }
184 |
185 | /**
186 | * 设置加载进入动画
187 | *
188 | * @param config
189 | * @param request
190 | */
191 | private void setAnimator(SingleConfig config, DrawableTypeRequest request) {
192 | if (config.getAnimationType() == AnimationMode.ANIMATIONID) {
193 | request.animate(config.getAnimationId());
194 | } else if (config.getAnimationType() == AnimationMode.ANIMATOR) {
195 | request.animate(config.getAnimator());
196 | } else if (config.getAnimationType() == AnimationMode.ANIMATION) {
197 | request.animate(config.getAnimation());
198 | }
199 | }
200 |
201 | @Nullable
202 | private DrawableTypeRequest getDrawableTypeRequest(SingleConfig config, RequestManager requestManager) {
203 | DrawableTypeRequest request = null;
204 | if (!TextUtils.isEmpty(config.getUrl())) {
205 | request = requestManager.load(ImageUtil.appendUrl(config.getUrl()));
206 | Log.e("TAG","getUrl : "+config.getUrl());
207 | } else if (!TextUtils.isEmpty(config.getFilePath())) {
208 | request = requestManager.load(ImageUtil.appendUrl(config.getFilePath()));
209 | Log.e("TAG","getFilePath : "+config.getFilePath());
210 | } else if (!TextUtils.isEmpty(config.getContentProvider())) {
211 | request = requestManager.loadFromMediaStore(Uri.parse(config.getContentProvider()));
212 | Log.e("TAG","getContentProvider : "+config.getContentProvider());
213 | } else if (config.getResId() > 0) {
214 | request = requestManager.load(config.getResId());
215 | Log.e("TAG","getResId : "+config.getResId());
216 | } else if(config.getFile() != null){
217 | request = requestManager.load(config.getFile());
218 | Log.e("TAG","getFile : "+config.getFile());
219 | } else if(!TextUtils.isEmpty(config.getAssertspath())){
220 | request = requestManager.load(config.getAssertspath());
221 | Log.e("TAG","getAssertspath : "+config.getAssertspath());
222 | } else if(!TextUtils.isEmpty(config.getRawPath())){
223 | request = requestManager.load(config.getRawPath());
224 | Log.e("TAG","getRawPath : "+config.getRawPath());
225 | }
226 | return request;
227 | }
228 |
229 | /**
230 | * 设置图片滤镜和形状
231 | *
232 | * @param config
233 | * @param request
234 | */
235 | private void setShapeModeAndBlur(SingleConfig config, DrawableTypeRequest request) {
236 |
237 | int count = 0;
238 |
239 | Transformation[] transformation = new Transformation[statisticsCount(config)];
240 |
241 | if (config.isNeedBlur()) {
242 | transformation[count] = new BlurTransformation(config.getContext(), config.getBlurRadius());
243 | count++;
244 | }
245 |
246 | if (config.isNeedBrightness()) {
247 | transformation[count] = new BrightnessFilterTransformation(config.getContext(), config.getBrightnessLeve()); //亮度
248 | count++;
249 | }
250 |
251 | if (config.isNeedGrayscale()) {
252 | transformation[count] = new GrayscaleTransformation(config.getContext()); //黑白效果
253 | count++;
254 | }
255 |
256 | if (config.isNeedFilteColor()) {
257 | transformation[count] = new ColorFilterTransformation(config.getContext(), config.getFilteColor());
258 | count++;
259 | }
260 |
261 | if (config.isNeedSwirl()) {
262 | transformation[count] = new SwirlFilterTransformation(config.getContext(), 0.5f, 1.0f, new PointF(0.5f, 0.5f)); //漩涡
263 | count++;
264 | }
265 |
266 | if (config.isNeedToon()) {
267 | transformation[count] = new ToonFilterTransformation(config.getContext()); //油画
268 | count++;
269 | }
270 |
271 | if (config.isNeedSepia()) {
272 | transformation[count] = new SepiaFilterTransformation(config.getContext()); //墨画
273 | count++;
274 | }
275 |
276 | if (config.isNeedContrast()) {
277 | transformation[count] = new ContrastFilterTransformation(config.getContext(), config.getContrastLevel()); //锐化
278 | count++;
279 | }
280 |
281 | if (config.isNeedInvert()) {
282 | transformation[count] = new InvertFilterTransformation(config.getContext()); //胶片
283 | count++;
284 | }
285 |
286 | if (config.isNeedPixelation()) {
287 | transformation[count] =new PixelationFilterTransformation(config.getContext(), config.getPixelationLevel()); //马赛克
288 | count++;
289 | }
290 |
291 | if (config.isNeedSketch()) {
292 | transformation[count] =new SketchFilterTransformation(config.getContext()); //素描
293 | count++;
294 | }
295 |
296 | if (config.isNeedVignette()) {
297 | transformation[count] =new VignetteFilterTransformation(config.getContext(), new PointF(0.5f, 0.5f),
298 | new float[] { 0.0f, 0.0f, 0.0f }, 0f, 0.75f);//晕映
299 | count++;
300 | }
301 |
302 | switch (config.getShapeMode()) {
303 | case ShapeMode.RECT:
304 |
305 | break;
306 | case ShapeMode.RECT_ROUND:
307 | transformation[count] = new RoundedCornersTransformation
308 | (config.getContext(), config.getRectRoundRadius(), 0, RoundedCornersTransformation.CornerType.ALL);
309 | count++;
310 | break;
311 | case ShapeMode.OVAL:
312 | transformation[count] = new CropCircleTransformation(config.getContext());
313 | count++;
314 | break;
315 |
316 | case ShapeMode.SQUARE:
317 | transformation[count] = new CropSquareTransformation(config.getContext());
318 | count++;
319 | break;
320 | }
321 |
322 | if (transformation.length != 0) {
323 | request.bitmapTransform(transformation);
324 |
325 | }
326 |
327 | }
328 |
329 | private int statisticsCount(SingleConfig config) {
330 | int count = 0;
331 |
332 | if (config.getShapeMode() == ShapeMode.OVAL || config.getShapeMode() == ShapeMode.RECT_ROUND || config.getShapeMode() == ShapeMode.SQUARE) {
333 | count++;
334 | }
335 |
336 | if (config.isNeedBlur()) {
337 | count++;
338 | }
339 |
340 | if (config.isNeedFilteColor()) {
341 | count++;
342 | }
343 |
344 | if (config.isNeedBrightness()) {
345 | count++;
346 | }
347 |
348 | if (config.isNeedGrayscale()) {
349 | count++;
350 | }
351 |
352 | if (config.isNeedSwirl()) {
353 | count++;
354 | }
355 |
356 | if (config.isNeedToon()) {
357 | count++;
358 | }
359 |
360 | if (config.isNeedSepia()) {
361 | count++;
362 | }
363 |
364 | if (config.isNeedContrast()) {
365 | count++;
366 | }
367 |
368 | if (config.isNeedInvert()) {
369 | count++;
370 | }
371 |
372 | if (config.isNeedPixelation()) {
373 | count++;
374 | }
375 |
376 | if (config.isNeedSketch()) {
377 | count++;
378 | }
379 |
380 | if (config.isNeedVignette()) {
381 | count++;
382 | }
383 |
384 | return count;
385 | }
386 |
387 | @Override
388 | public void pause() {
389 | Glide.with(GlobalConfig.context).pauseRequestsRecursive();
390 |
391 | }
392 |
393 | @Override
394 | public void resume() {
395 | Glide.with(GlobalConfig.context).resumeRequestsRecursive();
396 | }
397 |
398 | @Override
399 | public void clearDiskCache() {
400 | Glide.get(GlobalConfig.context).clearDiskCache();
401 | }
402 |
403 | @Override
404 | public void clearMomoryCache(View view) {
405 | Glide.clear(view);
406 | }
407 |
408 | @Override
409 | public void clearMomory() {
410 | Glide.get(GlobalConfig.context).clearMemory();
411 | }
412 |
413 | @Override
414 | public boolean isCached(String url) {
415 | return false;
416 | }
417 |
418 | @Override
419 | public void trimMemory(int level) {
420 | Glide.with(GlobalConfig.context).onTrimMemory(level);
421 | }
422 |
423 | @Override
424 | public void clearAllMemoryCaches() {
425 | Glide.with(GlobalConfig.context).onLowMemory();
426 | }
427 |
428 | @Override
429 | public void saveImageIntoGallery(DownLoadImageService downLoadImageService) {
430 | new Thread(downLoadImageService).start();
431 | }
432 |
433 | }
434 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/ImageLoader/src/main/java/imageloader/libin/com/images/loader/ILoader.java:
--------------------------------------------------------------------------------
1 | package imageloader.libin.com.images.loader;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | import com.bumptech.glide.MemoryCategory;
7 |
8 | import imageloader.libin.com.images.config.SingleConfig;
9 | import imageloader.libin.com.images.utils.DownLoadImageService;
10 |
11 | /**
12 | * Created by doudou on 2017/4/10.
13 | */
14 |
15 | public interface ILoader {
16 |
17 | void init(Context context, int cacheSizeInM, MemoryCategory memoryCategory, boolean isInternalCD);
18 |
19 | void request(SingleConfig config);
20 |
21 | void pause();
22 |
23 | void resume();
24 |
25 | void clearDiskCache();
26 |
27 | void clearMomoryCache(View view);
28 |
29 | void clearMomory();
30 |
31 | boolean isCached(String url);
32 |
33 | void trimMemory(int level);
34 |
35 | void clearAllMemoryCaches();
36 |
37 | void saveImageIntoGallery(DownLoadImageService downLoadImageService);
38 | }
39 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/ImageLoader/src/main/java/imageloader/libin/com/images/loader/ImageLoader.java:
--------------------------------------------------------------------------------
1 | package imageloader.libin.com.images.loader;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | import com.bumptech.glide.Glide;
7 | import com.bumptech.glide.MemoryCategory;
8 |
9 | import imageloader.libin.com.images.config.GlobalConfig;
10 | import imageloader.libin.com.images.config.SingleConfig;
11 | import imageloader.libin.com.images.utils.DownLoadImageService;
12 |
13 | /**
14 | * Created by doudou on 2017/4/19.
15 | */
16 |
17 | public class ImageLoader {
18 | public static Context context;
19 | /**
20 | * 默认最大缓存
21 | */
22 | public static int CACHE_IMAGE_SIZE = 250;
23 |
24 | public static void init(final Context context) {
25 | init(context, CACHE_IMAGE_SIZE);
26 | }
27 |
28 | public static void init(final Context context, int cacheSizeInM) {
29 | init(context, cacheSizeInM, MemoryCategory.NORMAL);
30 | }
31 |
32 | public static void init(final Context context, int cacheSizeInM, MemoryCategory memoryCategory) {
33 | init(context, cacheSizeInM, memoryCategory, true);
34 | }
35 |
36 | /**
37 | * @param context 上下文
38 | * @param cacheSizeInM Glide默认磁盘缓存最大容量250MB
39 | * @param memoryCategory 调整内存缓存的大小 LOW(0.5f) / NORMAL(1f) / HIGH(1.5f);
40 | * @param isInternalCD true 磁盘缓存到应用的内部目录 / false 磁盘缓存到外部存
41 | */
42 | public static void init(final Context context, int cacheSizeInM, MemoryCategory memoryCategory, boolean isInternalCD) {
43 | ImageLoader.context = context;
44 | GlobalConfig.init(context, cacheSizeInM, memoryCategory, isInternalCD);
45 | }
46 |
47 | /**
48 | * 获取当前的Loader
49 | * @return
50 | */
51 | public static ILoader getActualLoader() {
52 | return GlobalConfig.getLoader();
53 | }
54 |
55 | /**
56 | * 加载普通图片
57 | *
58 | * @param context
59 | * @return
60 | */
61 | public static SingleConfig.ConfigBuilder with(Context context) {
62 | return new SingleConfig.ConfigBuilder(context);
63 | }
64 |
65 | public static void trimMemory(int level) {
66 | getActualLoader().trimMemory(level);
67 | }
68 |
69 | public static void clearAllMemoryCaches() {
70 | getActualLoader().clearAllMemoryCaches();
71 | }
72 |
73 | public static void pauseRequests() {
74 | getActualLoader().pause();
75 |
76 | }
77 |
78 | public static void resumeRequests() {
79 | getActualLoader().resume();
80 | }
81 |
82 | /**
83 | *Cancel any pending loads Glide may have for the view and free any resources that may have been loaded for the view.
84 | * @param view
85 | */
86 | public static void clearMomoryCache(View view) {
87 | getActualLoader().clearMomoryCache(view);
88 | }
89 |
90 |
91 | /**
92 | * Clears disk cache.
93 | *
94 | *
95 | * This method should always be called on a background thread, since it is a blocking call.
96 | *
97 | */
98 | public static void clearDiskCache() {
99 | getActualLoader().clearDiskCache();
100 | }
101 |
102 | /**
103 | * Clears as much memory as possible.
104 | */
105 | public static void clearMomory() {
106 | getActualLoader().clearMomory();
107 | }
108 |
109 | /**
110 | * 图片保存到相册
111 | *
112 | * @param downLoadImageService
113 | */
114 | public static void saveImageIntoGallery(DownLoadImageService downLoadImageService) {
115 | getActualLoader().saveImageIntoGallery(downLoadImageService);
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/ImageLoader/src/main/java/imageloader/libin/com/images/utils/DownLoadImageService.java:
--------------------------------------------------------------------------------
1 | package imageloader.libin.com.images.utils;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.graphics.Bitmap;
6 | import android.net.Uri;
7 | import android.os.Environment;
8 | import android.provider.MediaStore;
9 |
10 | import com.bumptech.glide.Glide;
11 | import com.bumptech.glide.request.target.Target;
12 |
13 | import java.io.File;
14 | import java.io.FileNotFoundException;
15 | import java.io.FileOutputStream;
16 | import java.io.IOException;
17 |
18 | import imageloader.libin.com.images.imagei.ImageDownLoadCallBack;
19 |
20 | /**
21 | * 图片下载
22 | * Created by doudou on 2017/5/2.
23 | */
24 |
25 |
26 | public class DownLoadImageService implements Runnable {
27 | private String url;
28 | private Context context;
29 | private ImageDownLoadCallBack callBack;
30 | private File currentFile;
31 | private String fileName;
32 |
33 | private boolean isSetMediaStore;
34 |
35 | public DownLoadImageService(Context context, String url,boolean isSetMediaStore , String fileName, ImageDownLoadCallBack callBack) {
36 | this.url = url;
37 | this.callBack = callBack;
38 | this.context = context;
39 | this.isSetMediaStore = isSetMediaStore;
40 | this.fileName = fileName;
41 | }
42 |
43 | @Override
44 | public void run() {
45 |
46 | Bitmap bitmap = null;
47 | try {
48 | bitmap = Glide.with(context)
49 | .load(url)
50 | .asBitmap()
51 | .into(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
52 | .get();
53 | if (bitmap != null){
54 | // 在这里执行图片保存方法
55 | saveImageToGallery(context,bitmap);
56 | }
57 | } catch (Exception e) {
58 | e.printStackTrace();
59 | } finally {
60 | if (bitmap != null && currentFile.exists()) {
61 | callBack.onDownLoadSuccess(bitmap);
62 | } else {
63 | callBack.onDownLoadFailed();
64 | }
65 | }
66 | }
67 |
68 | public void saveImageToGallery(Context context, Bitmap bmp) {
69 | // 首先保存图片
70 | File file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsoluteFile();//注意小米手机必须这样获得public绝对路径
71 |
72 | File appDir = new File(file ,fileName);
73 | if (!appDir.exists()) {
74 | appDir.mkdirs();
75 | }
76 | fileName = System.currentTimeMillis() + ".jpg";
77 | currentFile = new File(appDir, fileName);
78 |
79 | FileOutputStream fos = null;
80 | try {
81 | fos = new FileOutputStream(currentFile);
82 | bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos);
83 | fos.flush();
84 | } catch (FileNotFoundException e) {
85 | e.printStackTrace();
86 | } catch (IOException e) {
87 | e.printStackTrace();
88 | } finally {
89 | try {
90 | if (fos != null) {
91 | fos.close();
92 | }
93 | } catch (IOException e) {
94 | e.printStackTrace();
95 | }
96 | }
97 |
98 | if(isSetMediaStore){
99 | setMediaDtore(fileName);
100 | }
101 |
102 | // 最后通知图库更新
103 | context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
104 | Uri.fromFile(new File(currentFile.getPath()))));
105 | }
106 |
107 | /**
108 | * 加入到系统图库
109 | * @param fileName
110 | */
111 | public void setMediaDtore(String fileName){
112 | try {
113 | MediaStore.Images.Media.insertImage(context.getContentResolver(),
114 | currentFile.getAbsolutePath(), fileName, null);
115 | } catch (FileNotFoundException e) {
116 | e.printStackTrace();
117 | }
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/ImageLoader/src/main/java/imageloader/libin/com/images/utils/ImageUtil.java:
--------------------------------------------------------------------------------
1 | package imageloader.libin.com.images.utils;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Matrix;
6 | import android.net.Uri;
7 | import android.text.TextUtils;
8 | import android.util.Log;
9 |
10 | import java.io.File;
11 | import java.io.FileInputStream;
12 | import java.io.IOException;
13 | import java.lang.reflect.InvocationHandler;
14 | import java.lang.reflect.InvocationTargetException;
15 | import java.lang.reflect.Method;
16 | import java.lang.reflect.Proxy;
17 | import java.security.KeyManagementException;
18 | import java.security.NoSuchAlgorithmException;
19 | import java.security.SecureRandom;
20 | import java.security.cert.X509Certificate;
21 | import java.util.concurrent.TimeUnit;
22 |
23 | import javax.net.ssl.HostnameVerifier;
24 | import javax.net.ssl.SSLContext;
25 | import javax.net.ssl.SSLSession;
26 | import javax.net.ssl.TrustManager;
27 | import javax.net.ssl.X509TrustManager;
28 |
29 | import imageloader.libin.com.images.config.GlobalConfig;
30 | import imageloader.libin.com.images.config.SingleConfig;
31 | import okhttp3.OkHttpClient;
32 |
33 | import static imageloader.libin.com.images.config.Contants.ANDROID_RESOURCE;
34 | import static imageloader.libin.com.images.config.Contants.FOREWARD_SLASH;
35 |
36 | /**
37 | * Created by doudou on 2017/4/10.
38 | */
39 |
40 | public class ImageUtil {
41 |
42 | public static SingleConfig.BitmapListener getBitmapListenerProxy(final SingleConfig.BitmapListener listener) {
43 | return (SingleConfig.BitmapListener) Proxy.newProxyInstance(SingleConfig.class.getClassLoader(),
44 | listener.getClass().getInterfaces(), new InvocationHandler() {
45 | @Override
46 | public Object invoke(Object proxy, final Method method, final Object[] args) throws Throwable {
47 |
48 | runOnUIThread(new Runnable() {
49 | @Override
50 | public void run() {
51 | try {
52 | Object object = method.invoke(listener, args);
53 | } catch (IllegalAccessException e) {
54 | e.printStackTrace();
55 | } catch (InvocationTargetException e) {
56 | e.printStackTrace();
57 | }
58 | }
59 | });
60 | return null;
61 | }
62 | });
63 | }
64 |
65 |
66 | public static void runOnUIThread(Runnable runnable) {
67 | GlobalConfig.getMainHandler().post(runnable);
68 | }
69 |
70 | public static boolean shouldSetPlaceHolder(SingleConfig config) {
71 | if (config.getPlaceHolderResId() <= 0) {
72 | return false;
73 | }
74 |
75 | if (config.getResId() > 0 || !TextUtils.isEmpty(config.getFilePath()) || GlobalConfig.getLoader().isCached(config.getUrl())) {
76 | return false;
77 | } else {//只有在图片源为网络图片,并且图片没有缓存到本地时,才给显示placeholder
78 | return true;
79 | }
80 | }
81 |
82 |
83 | public static int dip2px(float dipValue) {
84 | final float scale = GlobalConfig.context.getResources().getDisplayMetrics().density;
85 | return (int) (dipValue * scale + 0.5f);
86 | }
87 |
88 |
89 | /**
90 | * 等比压缩(宽高等比缩放)
91 | *
92 | * @param bitmap
93 | * @param needRecycle
94 | * @param targetWidth
95 | * @param targeHeight
96 | * @return
97 | */
98 | public static Bitmap compressBitmap(Bitmap bitmap, boolean needRecycle, int targetWidth, int targeHeight) {
99 | float sourceWidth = bitmap.getWidth();
100 | float sourceHeight = bitmap.getHeight();
101 |
102 | float scaleWidth = targetWidth / sourceWidth;
103 | float scaleHeight = targeHeight / sourceHeight;
104 |
105 | Matrix matrix = new Matrix();
106 | matrix.postScale(scaleWidth, scaleHeight); //长和宽放大缩小的比例
107 | Bitmap bm = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
108 | if (needRecycle) {
109 | bitmap.recycle();
110 | }
111 | bitmap = bm;
112 | return bitmap;
113 | }
114 |
115 |
116 | public static String getRealType(File file) {
117 | FileInputStream is = null;
118 | try {
119 | is = new FileInputStream(file);
120 | byte[] b = new byte[4];
121 | try {
122 | is.read(b, 0, b.length);
123 | } catch (IOException e) {
124 | e.printStackTrace();
125 | return "";
126 | }
127 | String type = bytesToHexString(b).toUpperCase();
128 | if (type.contains("FFD8FF")) {
129 | return "jpg";
130 | } else if (type.contains("89504E47")) {
131 | return "png";
132 | } else if (type.contains("47494638")) {
133 | return "gif";
134 | } else if (type.contains("49492A00")) {
135 | return "tif";
136 | } else if (type.contains("424D")) {
137 | return "bmp";
138 | }
139 | return type;
140 | } catch (Exception e) {
141 | e.printStackTrace();
142 | return "";
143 | } finally {
144 | try {
145 | is.close();
146 | } catch (IOException e) {
147 | e.printStackTrace();
148 | }
149 | }
150 |
151 |
152 | }
153 |
154 | public static String bytesToHexString(byte[] src) {
155 | StringBuilder stringBuilder = new StringBuilder();
156 | if (src == null || src.length <= 0) {
157 | return null;
158 | }
159 | for (int i = 0; i < src.length; i++) {
160 | int v = src[i] & 0xFF;
161 | String hv = Integer.toHexString(v);
162 | if (hv.length() < 2) {
163 | stringBuilder.append(0);
164 | }
165 | stringBuilder.append(hv);
166 | }
167 | return stringBuilder.toString();
168 | }
169 |
170 |
171 | /**
172 | * 类型 SCHEME 示例
173 | * 远程图片 http://, https:// HttpURLConnection 或者参考 使用其他网络加载方案
174 | * 本地文件 file:// FileInputStream
175 | * Content provider content:// ContentResolver
176 | * asset目录下的资源 asset:// AssetManager
177 | * res目录下的资源 res:// Resources.openRawResource
178 | * Uri中指定图片数据 data:mime/type;base64, 数据类型必须符合 rfc2397规定 (仅支持 UTF-8)
179 | *
180 | * @param config
181 | * @return
182 | */
183 | public static Uri buildUriByType(SingleConfig config) {
184 |
185 | Log.e("builduri:", "url: " + config.getUrl() + " ---filepath:" + config.getFilePath() + "--content:" + config.getContentProvider());
186 |
187 | if (!TextUtils.isEmpty(config.getUrl())) {
188 | String url = ImageUtil.appendUrl(config.getUrl());
189 | return Uri.parse(url);
190 | }
191 |
192 | if (config.getResId() > 0) {
193 | return Uri.parse("res://imageloader/" + config.getResId());
194 | }
195 |
196 | if (!TextUtils.isEmpty(config.getFilePath())) {
197 |
198 | File file = new File(config.getFilePath());
199 | if (file.exists()) {
200 | return Uri.fromFile(file);
201 | }
202 | }
203 |
204 | if (!TextUtils.isEmpty(config.getContentProvider())) {
205 | String content = config.getContentProvider();
206 | if (!content.startsWith("content")) {
207 | content = "content://" + content;
208 | }
209 | return Uri.parse(content);
210 | }
211 |
212 |
213 | return null;
214 | }
215 |
216 |
217 | public static String appendUrl(String url) {
218 | String newUrl = url;
219 | if (TextUtils.isEmpty(newUrl)) {
220 | return newUrl;
221 | }
222 | boolean hasHost = url.contains("http:") || url.contains("https:");
223 | if (!hasHost) {
224 | if (!TextUtils.isEmpty(GlobalConfig.baseUrl)) {
225 | newUrl = GlobalConfig.baseUrl + url;
226 | }
227 | }
228 |
229 | return newUrl;
230 | }
231 |
232 |
233 | public static OkHttpClient getClient(boolean ignoreCertificateVerify) {
234 | if (ignoreCertificateVerify) {
235 | return getAllPassClient();
236 | } else {
237 | return getNormalClient();
238 | }
239 | }
240 |
241 | /**
242 | * 不校验证书
243 | *
244 | * @return
245 | */
246 | private static OkHttpClient getAllPassClient() {
247 |
248 | X509TrustManager xtm = new X509TrustManager() {
249 | @Override
250 | public void checkClientTrusted(X509Certificate[] chain, String authType) {
251 | }
252 |
253 | @Override
254 | public void checkServerTrusted(X509Certificate[] chain, String authType) {
255 | }
256 |
257 | @Override
258 | public X509Certificate[] getAcceptedIssuers() {
259 | X509Certificate[] x509Certificates = new X509Certificate[]{};
260 | return x509Certificates;
261 | // return null;
262 | }
263 | };
264 |
265 | SSLContext sslContext = null;
266 | try {
267 | sslContext = SSLContext.getInstance("SSL");
268 |
269 | sslContext.init(null, new TrustManager[]{xtm}, new SecureRandom());
270 |
271 | } catch (NoSuchAlgorithmException e) {
272 | e.printStackTrace();
273 | } catch (KeyManagementException e) {
274 | e.printStackTrace();
275 | }
276 |
277 |
278 | HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
279 | @Override
280 | public boolean verify(String hostname, SSLSession session) {
281 | return true;
282 | }
283 | };
284 |
285 | OkHttpClient client = new OkHttpClient.Builder()
286 | .sslSocketFactory(sslContext.getSocketFactory())
287 | .hostnameVerifier(DO_NOT_VERIFY)
288 | .readTimeout(0, TimeUnit.SECONDS)
289 | .connectTimeout(30, TimeUnit.SECONDS).writeTimeout(0, TimeUnit.SECONDS) //设置超时
290 | .build();
291 |
292 | return client;
293 | }
294 |
295 | private static OkHttpClient getNormalClient() {
296 | OkHttpClient client = new OkHttpClient.Builder()
297 | //.sslSocketFactory(sslContext.getSocketFactory())
298 | //.hostnameVerifier(DO_NOT_VERIFY)
299 | .readTimeout(0, TimeUnit.SECONDS)
300 | .connectTimeout(30, TimeUnit.SECONDS).writeTimeout(0, TimeUnit.SECONDS) //设置超时
301 | .build();
302 | return client;
303 | }
304 |
305 | private static Uri resourceIdToUri(Context context, int resourceId) {
306 | return Uri.parse(ANDROID_RESOURCE + context.getPackageName() + FOREWARD_SLASH + resourceId);
307 | }
308 | }
309 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/ImageLoader/src/main/java/imageloader/libin/com/images/utils/MultiView.java:
--------------------------------------------------------------------------------
1 | package imageloader.libin.com.images.utils;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Bitmap;
6 | import android.graphics.BitmapShader;
7 | import android.graphics.Canvas;
8 | import android.graphics.Matrix;
9 | import android.graphics.Paint;
10 | import android.graphics.Path;
11 | import android.graphics.PointF;
12 | import android.graphics.RectF;
13 | import android.graphics.Shader;
14 | import android.graphics.drawable.BitmapDrawable;
15 | import android.graphics.drawable.Drawable;
16 | import android.os.Bundle;
17 | import android.os.Parcelable;
18 | import android.support.annotation.Nullable;
19 | import android.util.AttributeSet;
20 | import android.util.TypedValue;
21 | import android.widget.ImageView;
22 | import java.util.ArrayList;
23 | import java.util.List;
24 |
25 | import imageloader.libin.com.images.R;
26 |
27 | /**
28 | * Created by doudou on 2017/5/3.
29 | */
30 |
31 | public class MultiView extends ImageView {
32 | /**
33 | * 图片的类型,圆形or圆角or多边形
34 | */
35 | private Context mContext;
36 |
37 | /**
38 | * 传输类型
39 | */
40 | private int type;
41 |
42 | /**
43 | * 圆形
44 | */
45 | public static final int TYPE_CIRCLE = 0;
46 |
47 | /**
48 | * 圆角
49 | */
50 | public static final int TYPE_ROUND = 1;
51 |
52 | /**
53 | * 多边形
54 | */
55 | public static final int TYPE_MULTI = 3;
56 |
57 | /**
58 | *默认多边形角的个数
59 | */
60 | public static final int ANGLECOUNT = 5;
61 |
62 | /**
63 | * 默认开始绘制的角度
64 | */
65 | public static final int CURRENTANGLE = 180;
66 |
67 | /**
68 | * 多边形的半径
69 | */
70 | private int startRadius;
71 |
72 | /**
73 | * 多边形角的个数
74 | */
75 | private int angleCount ;
76 |
77 | private int[] angles;
78 |
79 | /**
80 | * 开始绘制的角度
81 | */
82 | private int currentAngle;
83 |
84 | /**
85 | * 存储角位置的集合
86 | */
87 | private List pointFList = new ArrayList<>();
88 |
89 | /**
90 | * 圆角大小的默认值
91 | */
92 | private static final int BODER_RADIUS_DEFAULT = 10;
93 |
94 | /**
95 | * 圆角的大小
96 | */
97 | private int mBorderRadius;
98 |
99 | /**
100 | * 绘图的Paint
101 | */
102 | private Paint mBitmapPaint;
103 |
104 | /**
105 | * 圆角的半径
106 | */
107 | private int mRadius;
108 |
109 | /**
110 | * 3x3 矩阵,主要用于缩小放大
111 | */
112 | private Matrix mMatrix;
113 |
114 | /**
115 | * 渲染图像,使用图像为绘制图形着色
116 | */
117 | private BitmapShader mBitmapShader;
118 |
119 | /**
120 | * view的宽度
121 | */
122 | private int mWidth;
123 | private RectF mRoundRect;
124 |
125 | public MultiView(Context context) {
126 | this(context, null);
127 | }
128 |
129 | public MultiView(Context context, AttributeSet attrs) {
130 |
131 | this(context, attrs, 0);
132 |
133 | }
134 |
135 | public MultiView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
136 | super(context, attrs, defStyleAttr);
137 |
138 | this.mContext = context;
139 |
140 | init(context, attrs);
141 |
142 | }
143 |
144 | public void init(Context context, AttributeSet attrs) {
145 | mMatrix = new Matrix();
146 | mBitmapPaint = new Paint();
147 | mBitmapPaint.setAntiAlias(true);
148 |
149 | TypedArray typedArray = context.obtainStyledAttributes(attrs,
150 | R.styleable.RoundImageView);
151 |
152 | mBorderRadius = typedArray.getDimensionPixelSize(
153 | R.styleable.RoundImageView_borderRadius, (int) TypedValue
154 | .applyDimension(TypedValue.COMPLEX_UNIT_DIP,
155 | BODER_RADIUS_DEFAULT, getResources()
156 | .getDisplayMetrics()));// 默认为10dp
157 | type = typedArray.getInt(R.styleable.RoundImageView_type, TYPE_CIRCLE);// 默认为Circle
158 | angleCount = typedArray.getInt(R.styleable.RoundImageView_angleCount, ANGLECOUNT);
159 | currentAngle = typedArray.getInt(R.styleable.RoundImageView_currentAngle, currentAngle);
160 |
161 | typedArray.recycle(); //回收之后对象可以重用
162 | }
163 |
164 |
165 | @Override
166 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
167 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
168 |
169 | /**
170 | * 如果类型是圆形或多边形,则强制改变view的宽高一致,以小值为准
171 | */
172 | if (type == TYPE_CIRCLE) {
173 | mWidth = Math.min(getMeasuredWidth(), getMeasuredHeight());
174 | mRadius = mWidth / 2;
175 | setMeasuredDimension(mWidth, mWidth);
176 | }
177 |
178 | if (type == TYPE_MULTI) {
179 | mWidth = Math.min(getMeasuredWidth(), getMeasuredHeight());
180 |
181 | setMeasuredDimension(mWidth, mWidth);
182 |
183 | angles = new int[angleCount];
184 |
185 | for (int i = 0; i < angleCount; i++) {
186 | int partOfAngle = 360 / angleCount; //每个顶点的角度
187 | angles[i] = currentAngle + partOfAngle * i;
188 |
189 | startRadius = mWidth / 2;
190 | float x = (float) (Math.sin(Math.toRadians(angles[i])) * startRadius);
191 | float y = (float) (Math.cos(Math.toRadians(angles[i])) * startRadius);
192 | pointFList.add(new PointF(x, y));
193 | }
194 | }
195 |
196 | }
197 |
198 | /**
199 | * 初始化BitmapShader
200 | */
201 | private void setUpShader() {
202 | Drawable drawable = getDrawable();
203 | if (drawable == null) {
204 | return;
205 | }
206 |
207 | Bitmap bmp = drawableToBitamp(drawable);
208 | // 将bmp作为着色器,就是在指定区域内绘制bmp
209 | mBitmapShader = new BitmapShader(bmp, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
210 | float scale = 1.0f;
211 | if (type == TYPE_CIRCLE) {
212 | // 拿到bitmap宽或高的小值
213 | int bSize = Math.min(bmp.getWidth(), bmp.getHeight());
214 | scale = mWidth * 1.0f / bSize;
215 |
216 | } else if (type == TYPE_ROUND) {
217 | if (!(bmp.getWidth() == getWidth() && bmp.getHeight() == getHeight())) {
218 | // 如果图片的宽或者高与view的宽高不匹配,计算出需要缩放的比例;缩放后的图片的宽高,一定要大于我们view的宽高;所以我们这里取大值;
219 | scale = Math.max(getWidth() * 1.0f / bmp.getWidth(), getHeight() * 1.0f / bmp.getHeight());
220 | }
221 |
222 | } else if (type == TYPE_MULTI) {
223 | // 拿到bitmap宽或高的小值
224 | int bSize = Math.min(bmp.getWidth(), bmp.getHeight());
225 | scale = mWidth * 1.0f / bSize;
226 | }
227 | // shader的变换矩阵,我们这里主要用于放大或者缩小
228 | mMatrix.setScale(scale, scale);
229 |
230 | // 设置变换矩阵
231 | mBitmapShader.setLocalMatrix(mMatrix);
232 | // 设置shader
233 | mBitmapPaint.setShader(mBitmapShader);
234 | }
235 |
236 | @Override
237 | protected void onDraw(Canvas canvas) {
238 | if (getDrawable() == null) {
239 | return;
240 | }
241 | setUpShader();
242 |
243 | if (type == TYPE_ROUND) {
244 | canvas.drawRoundRect(mRoundRect, mBorderRadius, mBorderRadius,
245 | mBitmapPaint);
246 | } else if (type == TYPE_MULTI) {
247 | //canvas.translate(startRadius,startRadius);
248 |
249 | Path mPath = drawPath();
250 |
251 | canvas.drawPath(mPath, mBitmapPaint);
252 | } else {
253 | canvas.drawCircle(mRadius, mRadius, mRadius, mBitmapPaint);
254 | }
255 | }
256 |
257 | /**
258 | * @return 多边形路径
259 | */
260 | private Path drawPath() {
261 | Path mPath = new Path();
262 | mPath.moveTo(pointFList.get(0).x, pointFList.get(0).y);
263 | for (int i = 2; i < angleCount; i++) {
264 | if (i % 2 == 0) {// 除以二取余数,余数为0则为偶数,否则奇数
265 | mPath.lineTo(pointFList.get(i).x, pointFList.get(i).y);
266 | }
267 |
268 | }
269 |
270 | if (angleCount % 2 == 0) { //偶数,moveTo
271 | mPath.moveTo(pointFList.get(1).x, pointFList.get(1).y);
272 | } else { //奇数,lineTo
273 | mPath.lineTo(pointFList.get(1).x, pointFList.get(1).y);
274 | }
275 |
276 | for (int i = 3; i < angleCount; i++) {
277 | if (i % 2 != 0) {
278 | mPath.lineTo(pointFList.get(i).x, pointFList.get(i).y);
279 | }
280 | }
281 |
282 | mPath.offset(startRadius, startRadius);
283 | return mPath;
284 | }
285 |
286 | @Override
287 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
288 | super.onSizeChanged(w, h, oldw, oldh);
289 |
290 | // 圆角图片的范围
291 | if (type == TYPE_ROUND)
292 | mRoundRect = new RectF(0, 0, w, h);
293 | }
294 |
295 | /**
296 | * drawable转bitmap
297 | *
298 | * @param drawable
299 | * @return
300 | */
301 | private Bitmap drawableToBitamp(Drawable drawable) {
302 | if (drawable instanceof BitmapDrawable) {
303 | BitmapDrawable bd = (BitmapDrawable) drawable;
304 | return bd.getBitmap();
305 | }
306 | int w = drawable.getIntrinsicWidth();
307 | int h = drawable.getIntrinsicHeight();
308 | Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
309 | Canvas canvas = new Canvas(bitmap);
310 | drawable.setBounds(0, 0, w, h);
311 | drawable.draw(canvas);
312 | return bitmap;
313 | }
314 |
315 | private static final String STATE_INSTANCE = "state_instance";
316 | private static final String STATE_TYPE = "state_type";
317 | private static final String STATE_BORDER_RADIUS = "state_border_radius";
318 |
319 | @Override
320 | protected Parcelable onSaveInstanceState() {
321 | Bundle bundle = new Bundle();
322 | bundle.putParcelable(STATE_INSTANCE, super.onSaveInstanceState());
323 | bundle.putInt(STATE_TYPE, type);
324 | bundle.putInt(STATE_BORDER_RADIUS, mBorderRadius);
325 | return bundle;
326 | }
327 |
328 | @Override
329 | protected void onRestoreInstanceState(Parcelable state) {
330 | if (state instanceof Bundle) {
331 | Bundle bundle = (Bundle) state;
332 | super.onRestoreInstanceState(((Bundle) state)
333 | .getParcelable(STATE_INSTANCE));
334 | this.type = bundle.getInt(STATE_TYPE);
335 | this.mBorderRadius = bundle.getInt(STATE_BORDER_RADIUS);
336 | } else {
337 | super.onRestoreInstanceState(state);
338 | }
339 |
340 | }
341 |
342 | public void setType(int type) {
343 | if (this.type != type) {
344 | this.type = type;
345 | if (this.type != TYPE_ROUND && this.type != TYPE_CIRCLE && this.type != TYPE_MULTI) {
346 | this.type = TYPE_CIRCLE;
347 | }
348 | requestLayout();
349 | }
350 |
351 | }
352 |
353 | }
354 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/ImageLoader/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | images
3 |
4 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/ImageLoader/src/main/res/values/style.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # For more information about using CMake with Android Studio, read the
2 | # documentation: https://d.android.com/studio/projects/add-native-code.html
3 |
4 | # Sets the minimum version of CMake required to build the native library.
5 |
6 | cmake_minimum_required(VERSION 3.4.1)
7 |
8 | # Creates and names a library, sets it as either STATIC
9 | # or SHARED, and provides the relative paths to its source code.
10 | # You can define multiple libraries, and CMake builds them for you.
11 | # Gradle automatically packages shared libraries with your APK.
12 |
13 | add_library( # Sets the name of the library.
14 | native-lib
15 |
16 | # Sets the library as a shared library.
17 | SHARED
18 |
19 | # Provides a relative path to your source file(s).
20 | src/main/cpp/native-lib.cpp )
21 |
22 | # Searches for a specified prebuilt library and stores the path as a
23 | # variable. Because CMake includes system libraries in the search path by
24 | # default, you only need to specify the name of the public NDK library
25 | # you want to add. CMake verifies that the library exists before
26 | # completing its build.
27 |
28 | find_library( # Sets the name of the path variable.
29 | log-lib # 依赖的系统so库
30 |
31 | # Specifies the name of the NDK library that
32 | # you want CMake to locate.
33 | log )
34 |
35 | # Specifies libraries CMake should link to your target library. You
36 | # can link multiple libraries, such as libraries you define in this
37 | # build script, prebuilt third-party libraries, or system libraries.
38 |
39 | target_link_libraries( # Specifies the target library.
40 | native-lib
41 |
42 | # Links the target library to the log library
43 | # included in the NDK.
44 | ${log-lib} )
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "imageloader.libin.com.imageloaderdemo"
8 | minSdkVersion 11
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | multiDexEnabled true
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 | externalNativeBuild {
15 | cmake {
16 | cppFlags ""
17 | }
18 | }
19 |
20 | }
21 | buildTypes {
22 | release {
23 | minifyEnabled false
24 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
25 | }
26 |
27 | debug {
28 | minifyEnabled false
29 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
30 |
31 | }
32 | }
33 |
34 | lintOptions {
35 | abortOnError false
36 | }
37 |
38 | externalNativeBuild {
39 | cmake {
40 | path 'CMakeLists.txt'
41 | }
42 | }
43 | sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/cpp/'] } }
44 | }
45 |
46 | dependencies {
47 | compile fileTree(include: ['*.jar'], dir: 'libs')
48 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
49 | exclude group: 'com.android.support', module: 'support-annotations'
50 | })
51 | compile project(':ImageLoader')
52 | compile 'com.android.support:appcompat-v7:25.3.0'
53 | compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'
54 | compile 'com.orhanobut:logger:1.15'
55 | testCompile 'junit:junit:4.12'
56 | }
57 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Applications/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/androidTest/java/imageloader/libin/com/imageloaderdemo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package imageloader.libin.com.imageloaderdemo;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("imageloader.libin.com.imageloaderdemo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/assets/jpeg_test.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/libin7278/ImageLoader/b868deb9966a547e3026d214b084c59683c775a7/ImageLoaderDemo/app/src/main/assets/jpeg_test.jpeg
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/cpp/native-lib.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | extern "C"
5 | JNIEXPORT jstring JNICALL
6 | Java_pressure_libin_com_pressure_MainActivity_stringFromJNI(
7 | JNIEnv *env,
8 | jobject /* this */) {
9 | std::string hello = "Hello from C++";
10 | return env->NewStringUTF(hello.c_str());
11 | }
12 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/java/imageloader/libin/com/imageloaderdemo/MainApplication.java:
--------------------------------------------------------------------------------
1 | package imageloader.libin.com.imageloaderdemo;
2 |
3 | import android.app.Application;
4 |
5 | import imageloader.libin.com.images.loader.ImageLoader;
6 |
7 | /**
8 | * Created by doudou on 2017/4/10.
9 | */
10 |
11 | public class MainApplication extends Application {
12 |
13 | @Override
14 | public void onCreate() {
15 | super.onCreate();
16 |
17 | ImageLoader.init(getApplicationContext());
18 |
19 | }
20 |
21 | @Override
22 | public void onTrimMemory(int level) {
23 | super.onTrimMemory(level);
24 |
25 | ImageLoader.trimMemory(level);
26 | }
27 |
28 | @Override
29 | public void onLowMemory() {
30 | super.onLowMemory();
31 |
32 | ImageLoader.clearAllMemoryCaches();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/java/imageloader/libin/com/imageloaderdemo/activity/BigImageActivity.java:
--------------------------------------------------------------------------------
1 | package imageloader.libin.com.imageloaderdemo.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 |
6 | import imageloader.libin.com.imageloaderdemo.R;
7 |
8 |
9 | public class BigImageActivity extends AppCompatActivity {
10 |
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_big_image);
16 |
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/java/imageloader/libin/com/imageloaderdemo/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package imageloader.libin.com.imageloaderdemo.activity;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.Button;
8 | import android.widget.Toast;
9 |
10 | import java.io.File;
11 | import java.io.FileOutputStream;
12 | import java.io.IOException;
13 | import java.io.InputStream;
14 |
15 | import imageloader.libin.com.imageloaderdemo.R;
16 |
17 | import static imageloader.libin.com.imageloaderdemo.config.imageconfig.IMG_NAME_C;
18 |
19 | public class MainActivity extends AppCompatActivity {
20 | Button btn_big_img ;
21 | Button btn_viewpager ;
22 | Button btn_round ;
23 |
24 | static {
25 | System.loadLibrary("native-lib");
26 | }
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_main);
32 |
33 | btn_big_img = (Button) findViewById(R.id.btn_big_img);
34 | btn_viewpager = (Button) findViewById(R.id.btn_viewpager);
35 | btn_round = (Button) findViewById(R.id.btn_round);
36 |
37 | copyFile();
38 |
39 | setonClick();
40 | }
41 |
42 | private void setonClick() {
43 | btn_big_img.setOnClickListener(new View.OnClickListener() {
44 | @Override
45 | public void onClick(View v) {
46 | startActivity(new Intent(MainActivity.this, BigImageActivity.class));
47 | }
48 | });
49 |
50 | btn_viewpager.setOnClickListener(new View.OnClickListener() {
51 | @Override
52 | public void onClick(View v) {
53 | startActivity(new Intent(MainActivity.this, ViewpagerActivity.class));
54 | }
55 | });
56 |
57 | btn_round.setOnClickListener(new View.OnClickListener() {
58 | @Override
59 | public void onClick(View v) {
60 | startActivity(new Intent(MainActivity.this, SimpleActivity.class));
61 | }
62 | });
63 |
64 | }
65 |
66 | private void copyFile() {
67 | InputStream is;
68 | try {
69 | is = getAssets().open(IMG_NAME_C);
70 | FileOutputStream fos = new FileOutputStream(new File(getFilesDir(), IMG_NAME_C));
71 | byte[] buffer = new byte[1024];
72 | int byteCount;
73 | while ((byteCount = is.read(buffer)) != -1) {
74 | fos.write(buffer, 0, byteCount);
75 | }
76 | fos.flush();
77 | is.close();
78 | fos.close();
79 | } catch (IOException e) {
80 | Toast.makeText(MainActivity.this,"图片存储失败",Toast.LENGTH_SHORT).show();
81 | }
82 | }
83 |
84 | public native String stringFromJNI();
85 | }
86 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/java/imageloader/libin/com/imageloaderdemo/activity/SimpleActivity.java:
--------------------------------------------------------------------------------
1 | package imageloader.libin.com.imageloaderdemo.activity;
2 |
3 | import android.animation.ObjectAnimator;
4 | import android.database.Cursor;
5 | import android.graphics.Bitmap;
6 | import android.os.Bundle;
7 | import android.os.Environment;
8 | import android.provider.ContactsContract;
9 | import android.provider.MediaStore;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.util.Log;
12 | import android.view.View;
13 | import android.widget.ImageView;
14 |
15 | import com.bumptech.glide.Glide;
16 | import com.bumptech.glide.load.engine.DiskCacheStrategy;
17 | import com.bumptech.glide.request.animation.ViewPropertyAnimation;
18 |
19 | import java.io.File;
20 |
21 | import imageloader.libin.com.imageloaderdemo.R;
22 | import imageloader.libin.com.images.config.PriorityMode;
23 | import imageloader.libin.com.images.config.ScaleMode;
24 | import imageloader.libin.com.images.imagei.ImageDownLoadCallBack;
25 | import imageloader.libin.com.images.loader.ImageLoader;
26 | import imageloader.libin.com.images.utils.DownLoadImageService;
27 |
28 | import static imageloader.libin.com.imageloaderdemo.config.imageconfig.IMG_NAME;
29 | import static imageloader.libin.com.imageloaderdemo.config.imageconfig.IMG_NAME_C;
30 | import static imageloader.libin.com.imageloaderdemo.config.imageconfig.URL1;
31 | import static imageloader.libin.com.imageloaderdemo.config.imageconfig.URL3;
32 | import static imageloader.libin.com.imageloaderdemo.config.imageconfig.URL4;
33 | import static imageloader.libin.com.imageloaderdemo.config.imageconfig.URL5;
34 | import static imageloader.libin.com.images.config.Contants.ANDROID_RESOURCE;
35 | import static imageloader.libin.com.images.config.Contants.ASSERTS_PATH;
36 | import static imageloader.libin.com.images.config.Contants.FOREWARD_SLASH;
37 | import static imageloader.libin.com.images.config.Contants.RAW;
38 |
39 | public class SimpleActivity extends AppCompatActivity {
40 |
41 | private ImageView iv_test1;
42 | private ImageView iv_test2;
43 | private ImageView iv_test3;
44 | private ImageView iv_test4;
45 | private ImageView iv_test5;
46 | private ImageView iv_test6;
47 | private ImageView iv_test7;
48 | private ImageView iv_test8;
49 | private ImageView iv_test9;
50 | private ImageView iv_test10;
51 | private ImageView iv_test11;
52 | private ImageView iv_test12;
53 | private ImageView iv_test13;
54 | private ImageView iv_test14;
55 | private ImageView iv_test15;
56 |
57 | private static final String TAG = SimpleActivity.class.getSimpleName();
58 |
59 | @Override
60 | protected void onCreate(Bundle savedInstanceState) {
61 | super.onCreate(savedInstanceState);
62 | setContentView(R.layout.activity_sample);
63 |
64 | findview();
65 |
66 | load();
67 | }
68 |
69 | private void findview() {
70 | iv_test1 = (ImageView) findViewById(R.id.iv_test1);
71 | iv_test2 = (ImageView) findViewById(R.id.iv_test2);
72 | iv_test3 = (ImageView) findViewById(R.id.iv_test3);
73 | iv_test4 = (ImageView) findViewById(R.id.iv_test4);
74 | iv_test5 = (ImageView) findViewById(R.id.iv_test5);
75 | iv_test6 = (ImageView) findViewById(R.id.iv_test6);
76 | iv_test7 = (ImageView) findViewById(R.id.iv_test7);
77 | iv_test8 = (ImageView) findViewById(R.id.iv_test8);
78 | iv_test9 = (ImageView) findViewById(R.id.iv_test9);
79 | iv_test10 = (ImageView) findViewById(R.id.iv_test10);
80 | iv_test11 = (ImageView) findViewById(R.id.iv_test11);
81 | iv_test12 = (ImageView) findViewById(R.id.iv_test12);
82 | iv_test13 = (ImageView) findViewById(R.id.iv_test13);
83 | iv_test14 = (ImageView) findViewById(R.id.iv_test14);
84 | iv_test15 = (ImageView) findViewById(R.id.iv_test15);
85 | }
86 |
87 | private void load() {
88 | ViewPropertyAnimation.Animator animationObject = new ViewPropertyAnimation.Animator() {
89 | @Override
90 | public void animate(View view) {
91 | view.setAlpha( 0f );
92 |
93 | ObjectAnimator fadeAnim = ObjectAnimator.ofFloat( view, "alpha", 0f, 1f );
94 | fadeAnim.setDuration( 2500 );
95 | fadeAnim.start();
96 | }
97 | };
98 |
99 | ImageLoader.with(this)
100 | .url(URL1)
101 | .animate(animationObject)
102 | .placeHolder(R.mipmap.ic_launcher)
103 | .scale(ScaleMode.CENTER_CROP)
104 | .into(iv_test1);
105 |
106 | ImageLoader.with(this)
107 | .url(URL1)
108 | .placeHolder(R.mipmap.ic_launcher)
109 | .scale(ScaleMode.FIT_CENTER)
110 | .into(iv_test2);
111 |
112 | // ImageLoader.with(this)
113 | // .url(URL2)
114 | // .placeHolder(R.mipmap.ic_launcher)
115 | // .scale(ScaleMode.FIT_CENTER)
116 | // .into(iv_test3);
117 |
118 | Glide.with(this).load(URL4).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE)
119 | .into(iv_test3);
120 |
121 | ImageLoader.with(this)
122 | .url(URL4)
123 | .placeHolder(R.mipmap.ic_launcher)
124 | .diskCacheStrategy(DiskCacheStrategy.SOURCE)
125 | .scale(ScaleMode.FIT_CENTER)
126 | .into(iv_test4);
127 |
128 | ImageLoader.with(this)
129 | .url(URL3)
130 | .placeHolder(R.mipmap.ic_launcher)
131 | .scale(ScaleMode.FIT_CENTER)
132 | .into(iv_test5);
133 |
134 | ImageLoader.with(this)
135 | .url(URL5)
136 | .placeHolder(R.mipmap.ic_launcher)
137 | .scale(ScaleMode.FIT_CENTER)
138 | .into(iv_test6);
139 |
140 | ImageLoader.with(this)
141 | .res(R.drawable.gif_test)
142 | .diskCacheStrategy(DiskCacheStrategy.SOURCE)
143 | .placeHolder(R.mipmap.ic_launcher)
144 | .scale(ScaleMode.FIT_CENTER)
145 | .into(iv_test7);
146 |
147 | ImageLoader.with(this)
148 | .res(R.drawable.jpeg_test)
149 | .placeHolder(R.mipmap.ic_launcher)
150 | .scale(ScaleMode.FIT_CENTER)
151 | .into(iv_test8);
152 |
153 | ImageLoader.with(this)
154 | .res(R.drawable.b000)
155 | .vignetteFilter()
156 | .priority(PriorityMode.PRIORITY_NORMAL)
157 | .placeHolder(R.mipmap.ic_launcher)
158 | .scale(ScaleMode.FIT_CENTER)
159 | // .ignoreCertificateVerify()
160 | .into(iv_test9);
161 |
162 | ImageLoader.with(this)
163 | .res(R.drawable.b000)
164 | .sketchFilter()
165 | .placeHolder(R.mipmap.ic_launcher)
166 | .scale(ScaleMode.FIT_CENTER)
167 | .into(iv_test10);
168 |
169 | // ImageLoader.with(this)
170 | // .content("content://media/external/images/media/"+getContentId())
171 | // .placeHolder(R.mipmap.ic_launcher)
172 | // .scale(ScaleMode.FIT_CENTER)
173 | // .into(iv_test10);
174 |
175 | ImageLoader.with(this)
176 | .file("file://"+ Environment.getExternalStorageDirectory().getPath()+FOREWARD_SLASH+IMG_NAME)
177 | .placeHolder(R.mipmap.ic_launcher)
178 | .scale(ScaleMode.FIT_CENTER)
179 | .into(iv_test11);
180 |
181 |
182 | ImageLoader.with(this)
183 | .file(new File(getFilesDir(), IMG_NAME_C))
184 | .placeHolder(R.mipmap.ic_launcher)
185 | .scale(ScaleMode.FIT_CENTER)
186 | .into(iv_test12);
187 |
188 | ImageLoader.with(this)
189 | .asserts(ASSERTS_PATH+IMG_NAME_C)
190 | .placeHolder(R.mipmap.ic_launcher)
191 | .scale(ScaleMode.FIT_CENTER)
192 | .rectRoundCorner(50)
193 | .into(iv_test13);
194 |
195 | ImageLoader.with(this)
196 | .raw(ANDROID_RESOURCE+getPackageName()+RAW+R.raw.jpeg_test)
197 | .placeHolder(R.mipmap.ic_launcher)
198 | .scale(ScaleMode.FIT_CENTER)
199 | .asCircle()
200 | .into(iv_test14);
201 |
202 | ImageLoader.with(this)
203 | .raw(ANDROID_RESOURCE+getPackageName()+RAW+R.raw.jpeg_test)
204 | .placeHolder(R.mipmap.ic_launcher)
205 | .scale(ScaleMode.FIT_CENTER)
206 | .diskCacheStrategy(DiskCacheStrategy.NONE)
207 | .asSquare()
208 | .into(iv_test15);
209 |
210 | ImageLoader.saveImageIntoGallery(new DownLoadImageService(SimpleActivity.this, URL3, true, "lala", new ImageDownLoadCallBack() {
211 |
212 | @Override
213 | public void onDownLoadSuccess(Bitmap bitmap) {
214 | Log.e(TAG, "下载图片成功 bitmap");
215 | }
216 |
217 | @Override
218 | public void onDownLoadFailed() {
219 | Log.e(TAG, "下载图片失败");
220 | }
221 |
222 | }));
223 | }
224 |
225 | public long getContentId(){
226 | Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null, null, null);
227 | long aLong = 0;
228 | if (cursor != null && cursor.moveToFirst()) {
229 | aLong = cursor.getLong(cursor.getColumnIndex(ContactsContract.Contacts._ID));
230 | }
231 |
232 | return aLong;
233 | }
234 |
235 |
236 | }
237 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/java/imageloader/libin/com/imageloaderdemo/activity/ViewpagerActivity.java:
--------------------------------------------------------------------------------
1 | package imageloader.libin.com.imageloaderdemo.activity;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.support.v4.view.ViewPager;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | import imageloader.libin.com.imageloaderdemo.R;
11 |
12 |
13 | public class ViewpagerActivity extends Activity {
14 | ViewPager viewPager;
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_viewpager);
20 |
21 | viewPager = (ViewPager) findViewById(R.id.viewpager);
22 | List urls = new ArrayList<>();
23 | /* urls.add("/storage/emulated/0/DCIM/家里有用图/IMG_20170222_221249_HHT.jpg");
24 | urls.add("/storage/emulated/0/DCIM/家里有用图/IMG_20161114_231649.jpg");
25 | urls.add("/storage/emulated/0/DCIM/家里有用图/IMG_20161229_221023.jpg");
26 | urls.add("/storage/emulated/0/DCIM/家里有用图/DSC_0051.JPG");*/
27 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490359324536&di=f1c2dfd6b0ebe0043f089d933d5d9e10&imgtype=0&src=http%3A%2F%2Fyouimg1.c-ctrip.com%2Ftarget%2Ffd%2Ftg%2Fg1%2FM02%2FFE%2FB5%2FCghzfFSrqqCATzfcACG0aD33PsY070.jpg");
28 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490359343773&di=9fc5478b63f369090613c1c27d56f237&imgtype=0&src=http%3A%2F%2Fimg4.duitang.com%2Fuploads%2Fitem%2F201510%2F04%2F20151004210446_usmze.jpeg");
29 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490359365740&di=f02eadaa956bef73d64cf9fb86969228&imgtype=0&src=http%3A%2F%2Fupload4.hlgnet.com%2Fbbsupfile%2F2012%2F2012-07-17%2F20120717003503_80.jpg");
30 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490359415501&di=2457a1060f3ccde0bd7f7b5d0891918d&imgtype=0&src=http%3A%2F%2Fdimg09.c-ctrip.com%2Fimages%2Ffd%2Ftg%2Fg2%2FM03%2FCB%2F19%2FCghzf1UualCAdMmaABQVh70n7_g185.jpg");
31 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490359451818&di=b3031652757061d8d9a681e824c8a9e5&imgtype=0&src=http%3A%2F%2Flvyou.panjin.net%2Ffjpic%2F1299485962.jpg");
32 |
33 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490954196&di=9d3311b40886fc2c670a31f7ba1edb68&imgtype=jpg&er=1&src=http%3A%2F%2Fdimg05.c-ctrip.com%2Fimages%2Ffd%2Ftg%2Fg2%2FM0B%2FCB%2F14%2FCghzgFUuapGABMHyACKrkXeB1zo976.jpg");
34 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490359527096&di=ec923d22df64850456fa01de50540ed3&imgtype=0&src=http%3A%2F%2Ffile28.mafengwo.net%2FM00%2F38%2FEB%2FwKgB6lTHUrKAMiRNABF8ZlX_qGY71.jpeg");
35 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490954377&di=c037874ec1de4ad2528708b89123ffb9&imgtype=jpg&er=1&src=http%3A%2F%2Ffile27.mafengwo.net%2FM00%2F44%2FFA%2FwKgB6lTHYfuAGx8tAAyTEuzr7rQ63.jpeg");
36 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490359641404&di=f0e34cfcfd8789ad6fdddf28ad7dc49b&imgtype=0&src=http%3A%2F%2Ffile27.mafengwo.net%2FM00%2F23%2FFC%2FwKgB6lSBlHCAa62UAAt4XAl0sUc50.jpeg");
37 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490359621573&di=fe03f67cb5b06f8961ceb8e21ca07db7&imgtype=0&src=http%3A%2F%2Ffile21.mafengwo.net%2FM00%2F7B%2F55%2FwKgB3FDF162Afrj8ACtU8-OAkZ484.jpeg");
38 |
39 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490971670&di=d810318cdd61531a5d1d3861d00c2d9e&imgtype=jpg&er=1&src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2Fc%2F570cc782c8312.jpg");
40 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490377045881&di=0f13095a141036c21225c377dd7749a9&imgtype=0&src=http%3A%2F%2Ftpic.home.news.cn%2FxhCloudNewsPic%2Fxhpic1501%2FM09%2F3B%2F9F%2FwKhTlFjGSD-EBUVnAAAAADRqVbw103.jpg");
41 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490377064336&di=887d8cb3473ac568fca9e4e7914039f7&imgtype=0&src=http%3A%2F%2Ftpic.home.news.cn%2FxhCloudNewsPic%2Fxhpic1501%2FM02%2F3B%2F36%2FwKhTlFi8xGiESf0ZAAAAAKAbE3k190.JPG");
42 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490377078620&di=e151b087ab39e1a630a4b233d2ae1b3c&imgtype=0&src=http%3A%2F%2Ftpic.home.news.cn%2FxhCloudNewsPic%2Fxhpic1501%2FM0B%2F3A%2FEA%2FwKhTlFi2HTqEQqC7AAAAABGsE-A602.jpg");
43 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490377147917&di=ebd07f2123fd27bfd6ab721ef5bc10be&imgtype=0&src=http%3A%2F%2Ftpic.home.news.cn%2FxhCloudNewsPic%2Fxhpic1501%2FM07%2F3A%2FEA%2FwKhTlFi2HTmEd_tPAAAAAAAmh48401.jpg");
44 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490377163830&di=3b35cedcc3fe72fa6d446de5f658e37a&imgtype=0&src=http%3A%2F%2Ftpic.home.news.cn%2FxhCloudNewsPic%2Fxhpic1501%2FM04%2F24%2FF8%2FwKhTlVfWBNaEfokmAAAAAIa_flU883.JPG");
45 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490377184956&di=358135e6e95914ac85483fb127f2f61c&imgtype=0&src=http%3A%2F%2Fbbs11.djicdn.com%2Fdata%2Fattachment%2Fforum%2F201605%2F11%2F200721bvbrtifzgczc7xqc.jpg");
46 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490971909&di=4e376f64ea228a1360759339b183bb0f&imgtype=jpg&er=1&src=http%3A%2F%2Fwww.wulong9.com%2Fuploads%2Fallimg%2F160901%2F2339441392-8.jpg");
47 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490377224967&di=7916a9c76cfd76540b3ed41f970c8b05&imgtype=0&src=http%3A%2F%2Fbbs11.djicdn.com%2Fdata%2Fattachment%2Fforum%2F201511%2F22%2F200600doo6tz2zqx6jdz5d.jpg");
48 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490377243693&di=5471e90a84737494794986fe81833f9f&imgtype=0&src=http%3A%2F%2Fnews.cpd.com.cn%2Fn203193%2Fc29879991%2Fpart%2F29880124.jpg");
49 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490377264171&di=6e8aa952f387588e9dce20ce6da70b90&imgtype=0&src=http%3A%2F%2Fimg2.xiangshu.com%2FDay_130214%2F102_721302_a48bffc61d51fcf.jpg");
50 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490377296064&di=88b89e2b139e540e321dfeac8b1e45c5&imgtype=0&src=http%3A%2F%2Fwww.liuzhou.gov.cn%2Fxwzx%2Fqxdt%2Frax%2F201607%2FW020160729407716095395.jpg");
51 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490377327685&di=b2630926b28c9eb55845fb070cdd873a&imgtype=0&src=http%3A%2F%2Fimg.meyet.com%2Fforum%2F201509%2F13%2F161505r4lp1l9x93hsrxj9.jpg");
52 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490377349229&di=e756188f5130990ddcf2026b4c0653f2&imgtype=0&src=http%3A%2F%2Fimg.zhongguowangshi.com%2FxwSceneReport%2F201408%2F20140806201621_2568.jpg");
53 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490377365522&di=03b5ca67a2b928a81755c71d3234960b&imgtype=0&src=http%3A%2F%2Fpicture.youth.cn%2Fqtdb%2F201604%2FW020160401504554381405.jpg");
54 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490377388544&di=23710a64289c9e642a0938a208f5c001&imgtype=0&src=http%3A%2F%2Fnews.cpd.com.cn%2Fn203193%2Fc30062120%2Fpart%2F30062148.jpg");
55 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490377446523&di=881526f14e32deac9bf6135b0fcd9607&imgtype=0&src=http%3A%2F%2Fimg.xiangshu.com%2FDay_160923%2F170_626871_adcb95228d97079.jpg");
56 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490972194&di=e447e1da8606c77991bbad5a5e31259f&imgtype=jpg&er=1&src=http%3A%2F%2Fww1.sinaimg.cn%2Flarge%2F005CX4pyjw1erxh54tsawj32531lr4qp.jpg");
57 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490972241&di=eff2b007af75130d6646646f56332bf2&imgtype=jpg&er=1&src=http%3A%2F%2Ftpic.home.news.cn%2FxhCloudNewsPic%2Fxhpic1501%2FM02%2F3B%2F36%2FwKhTlFi8xGiESf0ZAAAAAKAbE3k190.JPG");
58 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490377550943&di=44e2f1358062eb16e7b5922e8abe0823&imgtype=0&src=http%3A%2F%2Fimage97.360doc.com%2FDownloadImg%2F2016%2F06%2F1500%2F73937627_2.jpg");
59 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490377590254&di=a794edea83b41bfc8f116b4568c89194&imgtype=0&src=http%3A%2F%2Fww2.sinaimg.cn%2Flarge%2F6e4b60cegw1f1td78f79aj23341qiu0y.jpg");
60 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490972384&di=3cafec5973c15688726cec59e1d9085e&imgtype=jpg&er=1&src=http%3A%2F%2Fbbs11.djicdn.com%2Fdata%2Fattachment%2Fforum%2F201604%2F01%2F133253wg01kxggh8o215gc.jpg");
61 | urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490972455&di=53778e44f17970656d0dc2e0a9ce4ee9&imgtype=jpg&er=1&src=http%3A%2F%2Fwww.7695556.com%2Fdata%2Fattachment%2Fforum%2F201609%2F28%2F201212dpyqwo0aam49owpa.jpg");
62 |
63 | // PagerAdapterForBigImage adapter = new PagerAdapterForBigImage(urls);
64 | // viewPager.setAdapter(adapter);
65 | //ImageLoader.loadBigImages(viewPager,urls);
66 | }
67 |
68 | @Override
69 | protected void onDestroy() {
70 | super.onDestroy();
71 |
72 | //viewPager.destroyDrawingCache();
73 | // ImageLoader.clearAllMemoryCaches();//调了没用,也不需要调,下次进来自动会刷新内存
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/java/imageloader/libin/com/imageloaderdemo/config/imageconfig.java:
--------------------------------------------------------------------------------
1 | package imageloader.libin.com.imageloaderdemo.config;
2 |
3 | /**
4 | * Created by doudou on 2017/5/3.
5 | */
6 |
7 | public interface imageconfig {
8 | String URL1 = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1490944508&di=671845045c66356487c1a539c4ed0717&imgtype=jpg&er=1&src=http%3A%2F%2Fattach.bbs.letv.com%2Fforum%2F201606%2F27%2F185306g84m4gsxztvzxjt5.jpg";
9 | String URL2 = "http://s1.dwstatic.com/group1/M00/86/4A/81beb00a44bc52b4fdd46285de8f8f00.png";
10 | String URL3 = "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=2796659031,1466769776&fm=80&w=179&h=119&img.JPEG";
11 | String URL4 = "https://isparta.github.io/compare-webp/image/gif_webp/gif/1.gif";
12 | String URL5 = "https://p.upyun.com/docs/cloud/demo.jpg!/format/webp";
13 |
14 | String IMG_NAME = "SHARE_IMG2.PNG";
15 | String IMG_NAME_C = "jpeg_test.jpeg";
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/drawable-hdpi/b000.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/libin7278/ImageLoader/b868deb9966a547e3026d214b084c59683c775a7/ImageLoaderDemo/app/src/main/res/drawable-hdpi/b000.webp
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/drawable-hdpi/gif_test.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/libin7278/ImageLoader/b868deb9966a547e3026d214b084c59683c775a7/ImageLoaderDemo/app/src/main/res/drawable-hdpi/gif_test.gif
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/drawable-hdpi/jpeg_test.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/libin7278/ImageLoader/b868deb9966a547e3026d214b084c59683c775a7/ImageLoaderDemo/app/src/main/res/drawable-hdpi/jpeg_test.jpeg
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/drawable-hdpi/webp_test.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/libin7278/ImageLoader/b868deb9966a547e3026d214b084c59683c775a7/ImageLoaderDemo/app/src/main/res/drawable-hdpi/webp_test.webp
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/drawable/ads.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/libin7278/ImageLoader/b868deb9966a547e3026d214b084c59683c775a7/ImageLoaderDemo/app/src/main/res/drawable/ads.gif
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/layout/activity_big_image.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
18 |
19 |
24 |
25 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/layout/activity_sample.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
17 |
18 |
23 |
24 |
29 |
30 |
35 |
36 |
41 |
42 |
47 |
48 |
53 |
54 |
59 |
60 |
65 |
66 |
71 |
72 |
77 |
78 |
83 |
84 |
89 |
90 |
95 |
96 |
101 |
102 |
103 |
111 |
112 |
121 |
122 |
130 |
131 |
132 |
133 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/layout/activity_viewpager.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/libin7278/ImageLoader/b868deb9966a547e3026d214b084c59683c775a7/ImageLoaderDemo/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/libin7278/ImageLoader/b868deb9966a547e3026d214b084c59683c775a7/ImageLoaderDemo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/libin7278/ImageLoader/b868deb9966a547e3026d214b084c59683c775a7/ImageLoaderDemo/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/libin7278/ImageLoader/b868deb9966a547e3026d214b084c59683c775a7/ImageLoaderDemo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/libin7278/ImageLoader/b868deb9966a547e3026d214b084c59683c775a7/ImageLoaderDemo/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/libin7278/ImageLoader/b868deb9966a547e3026d214b084c59683c775a7/ImageLoaderDemo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/libin7278/ImageLoader/b868deb9966a547e3026d214b084c59683c775a7/ImageLoaderDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/libin7278/ImageLoader/b868deb9966a547e3026d214b084c59683c775a7/ImageLoaderDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/libin7278/ImageLoader/b868deb9966a547e3026d214b084c59683c775a7/ImageLoaderDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/libin7278/ImageLoader/b868deb9966a547e3026d214b084c59683c775a7/ImageLoaderDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/raw/jpeg_test.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/libin7278/ImageLoader/b868deb9966a547e3026d214b084c59683c775a7/ImageLoaderDemo/app/src/main/res/raw/jpeg_test.jpeg
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ImageLoader
3 | 基本功能使用
4 |
5 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/app/src/test/java/imageloader/libin/com/imageloaderdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package imageloader.libin.com.imageloaderdemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/ImageLoaderDemo/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.1'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 |
13 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
14 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | jcenter()
21 | maven {
22 | url "http://dl.bintray.com/piasy/maven"
23 | }
24 | }
25 | }
26 |
27 | task clean(type: Delete) {
28 | delete rootProject.buildDir
29 | }
30 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/codeiris/codeIrisExport.json:
--------------------------------------------------------------------------------
1 | [{"packageName":"imageloader.libin.com.images","superClass":null,"className":"ImageLoader","associations":[],"usages":[],"interfaces":[],"type":"CLASS"},{"packageName":"imageloader.libin.com.images","superClass":null,"className":"BuildConfig","associations":[],"usages":[],"interfaces":[],"type":"CLASS"},{"packageName":"imageloader.libin.com.images.config","superClass":null,"className":"ScaleMode","associations":[],"usages":[],"interfaces":[],"type":"INTERFACE"},{"packageName":"imageloader.libin.com.images","superClass":null,"className":"BuildConfig","associations":[],"usages":[],"interfaces":[],"type":"CLASS"},{"packageName":"imageloader.libin.com.images","superClass":null,"className":"R","associations":[],"usages":[],"interfaces":[],"type":"CLASS"},{"packageName":"imageloader.libin.com.images.config","superClass":null,"className":"ShapeMode","associations":[],"usages":[],"interfaces":[],"type":"INTERFACE"},{"packageName":"imageloader.libin.com.images.config","superClass":null,"className":"ScaleMode","associations":[],"usages":[],"interfaces":[],"type":"INTERFACE"},{"packageName":"imageloader.libin.com.images","superClass":null,"className":"R","associations":[],"usages":[],"interfaces":[],"type":"CLASS"},{"packageName":"imageloader.libin.com.images","superClass":null,"className":"ExampleInstrumentedTest","associations":[],"usages":[],"interfaces":[],"type":"CLASS"},{"packageName":"imageloader.libin.com.images.config","superClass":null,"className":"GlobalConfig","associations":["imageloader.libin.com.images.loader.ILoader"],"usages":[],"interfaces":[],"type":"CLASS"},{"packageName":"imageloader.libin.com.images.glide","superClass":null,"className":"GlideLoader","associations":["imageloader.libin.com.images.config.SingleConfig"],"usages":[],"interfaces":[],"type":"CLASS"},{"packageName":"imageloader.libin.com.images.config","superClass":null,"className":"ShapeMode","associations":[],"usages":[],"interfaces":[],"type":"INTERFACE"},{"packageName":"imageloader.libin.com.images.loader","superClass":null,"className":"ILoader","associations":["imageloader.libin.com.images.config.SingleConfig"],"usages":["imageloader.libin.com.images.config.GlobalConfig","imageloader.libin.com.images.loader.ImageLoader"],"interfaces":[],"type":"INTERFACE"},{"packageName":"imageloader.libin.com.images.config","superClass":null,"className":"SingleConfig","associations":[],"usages":["imageloader.libin.com.images.glide.GlideLoader","imageloader.libin.com.images.loader.GlideLoader","imageloader.libin.com.images.utils.MyUtil","imageloader.libin.com.images.interfaces.ILoader","imageloader.libin.com.images.loader.ILoader"],"interfaces":[],"type":"CLASS"},{"packageName":"imageloader.libin.com.images.loader","superClass":null,"className":"GlideLoader","associations":["imageloader.libin.com.images.config.SingleConfig"],"usages":[],"interfaces":["imageloader.libin.com.images.loader.ILoader"],"type":"CLASS"},{"packageName":"imageloader.libin.com.images.interfaces","superClass":null,"className":"ILoader","associations":["imageloader.libin.com.images.config.SingleConfig"],"usages":[],"interfaces":[],"type":"INTERFACE"},{"packageName":"imageloader.libin.com.images.loader","superClass":null,"className":"ImageLoader","associations":["imageloader.libin.com.images.loader.ILoader"],"usages":[],"interfaces":[],"type":"CLASS"},{"packageName":"imageloader.libin.com.images.utils","superClass":null,"className":"MyUtil","associations":["imageloader.libin.com.images.config.SingleConfig"],"usages":[],"interfaces":[],"type":"CLASS"},{"packageName":"imageloader.libin.com.images.config","superClass":null,"className":"GlobalConfig","associations":["imageloader.libin.com.images.loader.ILoader"],"usages":[],"interfaces":[],"type":"CLASS"},{"packageName":"imageloader.libin.com.images.interfaces","superClass":null,"className":"ILoader","associations":["imageloader.libin.com.images.config.SingleConfig"],"usages":[],"interfaces":[],"type":"INTERFACE"},{"packageName":"imageloader.libin.com.images.test","superClass":null,"className":"R","associations":[],"usages":[],"interfaces":[],"type":"CLASS"},{"packageName":"imageloader.libin.com.images.test","superClass":null,"className":"BuildConfig","associations":[],"usages":[],"interfaces":[],"type":"CLASS"},{"packageName":"imageloader.libin.com.images.loader","superClass":null,"className":"ILoader","associations":["imageloader.libin.com.images.config.SingleConfig"],"usages":["imageloader.libin.com.images.config.GlobalConfig","imageloader.libin.com.images.loader.ImageLoader"],"interfaces":[],"type":"INTERFACE"},{"packageName":"imageloader.libin.com.images.loader","superClass":null,"className":"GlideLoader","associations":["imageloader.libin.com.images.config.SingleConfig"],"usages":[],"interfaces":["imageloader.libin.com.images.loader.ILoader"],"type":"CLASS"},{"packageName":"imageloader.libin.com.images.config","superClass":null,"className":"SingleConfig","associations":[],"usages":["imageloader.libin.com.images.loader.GlideLoader","imageloader.libin.com.images.utils.MyUtil","imageloader.libin.com.images.interfaces.ILoader","imageloader.libin.com.images.loader.ILoader"],"interfaces":[],"type":"CLASS"},{"packageName":"imageloader.libin.com.images.loader","superClass":null,"className":"ImageLoader","associations":["imageloader.libin.com.images.loader.ILoader"],"usages":[],"interfaces":[],"type":"CLASS"},{"packageName":"imageloader.libin.com.images.utils","superClass":null,"className":"MyUtil","associations":["imageloader.libin.com.images.config.SingleConfig"],"usages":[],"interfaces":[],"type":"CLASS"}]
--------------------------------------------------------------------------------
/ImageLoaderDemo/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/libin7278/ImageLoader/b868deb9966a547e3026d214b084c59683c775a7/ImageLoaderDemo/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/ImageLoaderDemo/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Apr 13 17:23:28 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/ImageLoaderDemo/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':ImageLoader'
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 前言
2 | =============
3 | > - 有人可能会问为什么选择Glide进行二次封装?
4 | > - 那你应该去看我的上一篇文章:
5 | > http://blog.csdn.net/github_33304260/article/details/70213300
6 | > - 那么又有人问了Glide直接能使用了,已经很方便了,为啥还要封装?
7 | > - 入口统一,所有图片加载都在这一个地方管理,一目了然,即使有什么改动我也只需要改这一个类就可以了。
8 | > - 虽然现在的第三方库已经非常好用,但是如果我们看到第三方库就拿来用的话,很可能在第三方库无法满足业务需求或者停止维护的时候,发现替换库,工作量可见一斑。这就是不封装在切库时面临的窘境!
9 | > - 外部表现一致,内部灵活处理原则
10 | > - 更多内容参考:[如何正确使用开源项目?](http://mp.weixin.qq.com/s?__biz=MzA4NTQwNDcyMA==&mid=2650661623&idx=1&sn=ab28ac6587e8a5ef1241be7870851355#rd)
11 |
12 | 初识Glide
13 | =============
14 | ##Glide配置
15 | **1、 在build.gradle中添加依赖:**
16 |
17 | ```
18 | dependencies {
19 | compile 'com.github.bumptech.glide:glide:3.7.0'
20 | compile 'com.android.support:support-v4:19.1.0'
21 | }
22 | ```
23 | Or Maven:
24 |
25 | ```
26 |
27 | com.github.bumptech.glide
28 | glide
29 | 3.7.0
30 |
31 |
32 | com.google.android
33 | support-v4
34 | r7
35 |
36 | ```
37 |
38 | **2、混淆**
39 |
40 | ```
41 | -keep public class * implements com.bumptech.glide.module.GlideModule
42 | -keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
43 | **[] $VALUES;
44 | public *;
45 | }
46 |
47 | # for DexGuard only
48 | -keepresourcexmlelements manifest/application/meta-data@value=GlideModule
49 | ```
50 |
51 | **3、权限**
52 | 如果是联网获取图片或者本地存储需要添加以下权限:
53 |
54 | ```
55 |
56 |
57 |
58 | ```
59 |
60 | ##Glide基本使用
61 | Glide使用一个流接口(Fluent Interface)。用Glide完成一个完整的图片加载功能请求,需要向其构造器中至少传入3个参数,分别是:
62 | > - with(Context context)- Context是许多Android API需要调用的, Glide也不例外。这里Glide非常方便,你可以任意传递一个Activity或者Fragment对象,它都可以自动提取出上下文。
63 | > - load(String imageUrl) - 这里传入的是你要加载的图片的URL,大多数情况下这个String类型的变量会链接到一个网络图片。
64 | > - into(ImageView targetImageView) - 将你所希望解析的图片传递给所要显示的ImageView。
65 |
66 | example:
67 |
68 | ```
69 | ImageView targetImageView = (ImageView) findViewById(R.id.imageView);
70 | String internetUrl = "http://i.imgur.com/DvpvklR.png";
71 |
72 | Glide
73 | .with(context)
74 | .load(internetUrl)
75 | .into(targetImageView);
76 | ```
77 | ##Compatibility
78 | > - **Android SDK**: Glide requires a minimum API level of 10.
79 | > - **OkHttp 2.x**: there are optional dependencies available called okhttp-integration, see Integration Libraries wiki page.
80 | > - **OkHttp 3**.x: there are optional dependencies available called okhttp3-integration, see Integration Libraries wiki page.
81 | > - **Volley**: there are optional dependencies available called volley-integration, see Integration Libraries wiki page.
82 | > - **Round Pictures**: CircleImageView/CircularImageView/RoundedImageView are known to have issues with TransitionDrawable (.crossFade() with .thumbnail() or .placeholder()) and animated GIFs, use a BitmapTransformation (.circleCrop() will be available in v4) or .dontAnimate() to fix the issue.
83 | > - **Huge Images** (maps, comic strips): Glide can load huge images by downsampling them, but does not support zooming and panning ImageViews as they require special resource optimizations (such as tiling) to work without OutOfMemoryErrors.
84 |
85 |
86 | ##常用API
87 | > - **thumbnail(float sizeMultiplier)**. 请求给定系数的缩略图。如果缩略图比全尺寸图先加载完,就显示缩略图,否则就不显示。系数sizeMultiplier必须在(0,1)之间,可以递归调用该方法。
88 | > - **sizeMultiplier(float sizeMultiplier).** 在加载资源之前给Target大小设置系数。
89 | > - **diskCacheStrategy(DiskCacheStrategy strategy).**设置缓存策略。> -DiskCacheStrategy.SOURCE:缓存原始数据,DiskCacheStrategy.RESULT:缓存变换(如缩放、裁剪等)后的资源数据,DiskCacheStrategy.NONE:什么都不缓存,DiskCacheStrategy.ALL:缓存SOURC和RESULT。默认采用> -> -DiskCacheStrategy.RESULT策略,对于download only操作要使用> -DiskCacheStrategy.SOURCE。
90 | > - **priority(Priority priority)**. 指定加载的优先级,优先级越高越优先加载,但不保证所有图片都按序加载。枚举Priority.IMMEDIATE,Priority.HIGH,Priority.NORMAL,Priority.LOW。默认为Priority.NORMAL。
91 | > - **dontAnimate()
92 | > .** 移除所有的动画。
93 | > - **animate(int animationId).** 在异步加载资源完成时会执行该动画。
94 | > - **animate(ViewPropertyAnimation.Animator animator).** 在异步加载资源完成时> 会执行该动画。
95 | > - **placeholder(int resourceId)**. 设置资源加载过程中的占位Drawable。
96 | > - **placeholder(Drawable drawable).** 设置资源加载过程中的占位Drawable。
97 | > - **fallback(int resourceId).** 设置model为空时要显示的Drawable。如果没设置fallback,model为空时将显示error的Drawable,如果error的Drawable也没设置,就显示placeholder的Drawable。
98 | > - **fallback(Drawable drawable)**.设置model为空时显示的Drawable。
99 | > - **error(int resourceId).**设置load失败时显示的Drawable。
100 | > - **error(Drawable drawable).**设置load失败时显示的Drawable。
101 | > -**listener(RequestListener《? super ModelType, TranscodeType》> -requestListener).** 监听资源加载的请求状态,可以使用两个回调:onResourceReady(R resource, T model, Target target, boolean isFromMemoryCache, boolean isFirstResource)和onException(Exception e, T model, Target<R> target, boolean isFirstResource),但不要每次请求都使用新的监听器,要避免不必要的内存申请,可以使用单例进行统一的异常监听和处理。
102 | > - **skipMemoryCache(boolean skip).** 设置是否跳过内存缓存,但不保证一定不被缓存(比如请求已经在加载资源且没设置跳过内存缓存,这个资源就会被缓存在内存中)。
103 | > - **override(int width, int height).** 重新设置Target的宽高值(单位为pixel)。
104 | > - **into(Y target)**.设置资源将被加载到的Target。
105 | > - **into(ImageView view).** 设置资源将被加载到的ImageView。取消该ImageView之前所有的加载并释放资源。
106 | > - **into(int width, int height)**. 后台线程加载时要加载资源的宽高值(单位为pixel)。
107 | > - **preload(int width, int height)**. 预加载resource到缓存中(单位为pixel)。
108 | > - **asBitmap().** 无论资源是不是gif动画,都作为Bitmap对待。如果是gif动画会停在第一帧。
109 | > - **asGif().**把资源作为GifDrawable对待。如果资源不是gif动画将会失败,会回调.error()。
110 |
111 | ***更多Glide详细介绍可以看[Glide官网](https://github.com/bumptech/glide)以及[Glide教程系列文章](http://www.jianshu.com/p/7610bdbbad17)***
112 |
113 | 如何封装
114 | =============
115 | 明白了为什么封装以及基本原理,接下来我们就要开工,大干一场。
116 |
117 | 先看一下本人封装后的基本使用样式:
118 |
119 | ```
120 | ImageLoader.with(this)
121 | .url("http://img.yxbao.com/news/image/201703/13/7bda462477.gif")
122 | .placeHolder(R.mipmap.ic_launcher,false)
123 | .rectRoundCorner(30, R.color.colorPrimary)
124 | .blur(40)
125 | .into(iv_round);
126 | ```
127 |
128 | 更多属性我们后再详细讲解使用,主要先来看看具体的封装。
129 |
130 | 先看一下uml:
131 |
132 | 
133 |
134 | 使用者只需要关心ImageLoader就好了,就算里面封装的库更换、更新也没关系,因为对外的接口是不变的。实际操作中是由实现了ILoader的具体类去操作的,这里我们只封装了GlideLoader,其实所有操作都是由ImageLoader下发指令,由GlideLoader具体去实现的。这里如果想封装别的第三方库,只需要实现ILoader自己去完成里面的方法。
135 |
136 | ##初始化
137 |
138 | ```
139 | public static int CACHE_IMAGE_SIZE = 250;
140 |
141 | public static void init(final Context context) {
142 | init(context, CACHE_IMAGE_SIZE);
143 | }
144 |
145 | public static void init(final Context context, int cacheSizeInM) {
146 | init(context, cacheSizeInM, MemoryCategory.NORMAL);
147 | }
148 |
149 | public static void init(final Context context, int cacheSizeInM, MemoryCategory memoryCategory) {
150 | init(context, cacheSizeInM, memoryCategory, true);
151 | }
152 |
153 | /**
154 | * @param context 上下文
155 | * @param cacheSizeInM Glide默认磁盘缓存最大容量250MB
156 | * @param memoryCategory 调整内存缓存的大小 LOW(0.5f) / NORMAL(1f) / HIGH(1.5f);
157 | * @param isInternalCD true 磁盘缓存到应用的内部目录 / false 磁盘缓存到外部存
158 | */
159 | public static void init(final Context context, int cacheSizeInM, MemoryCategory memoryCategory, boolean isInternalCD) {
160 | ImageLoader.context = context;
161 | GlobalConfig.init(context, cacheSizeInM, memoryCategory, isInternalCD);
162 | }
163 | ```
164 |
165 | 从这里可以看出我们提供了四个构造器,这里注释详细说明了所有参数的用法及意义。
166 |
167 | 除了初始化,我们还需要在Application中重写以下方法:
168 |
169 | ```
170 | @Override
171 | public void onTrimMemory(int level) {
172 | super.onTrimMemory(level);
173 | // 程序在内存清理的时候执行
174 | ImageLoader.trimMemory(level);
175 | }
176 |
177 | @Override
178 | public void onLowMemory() {
179 | super.onLowMemory();
180 | // 低内存的时候执行
181 | ImageLoader.clearAllMemoryCaches();
182 | }
183 | ```
184 | 上面这两个方法会在下面ImageLoader中介绍到。
185 |
186 | ##你所关心的类--ImageLoader
187 | ImageLoader是封装好所有的方法供用户使用的,让我们看看都有什么方法:
188 | > - ImageLoader.init(Context context) //初始化
189 | > - ImageLoader.trimMemory(int level);
190 | > - ImageLoader.clearAllMemoryCaches();
191 | > - ImageLoader.getActualLoader(); //获取当前的loader
192 | > - ImageLoader.with(Context context) //加载图片
193 | > - ImageLoader.saveImageIntoGallery(String url) // 保存图片到相册
194 | > - ImageLoader.pauseRequests() //取消请求
195 | > - ImageLoader.resumeRequests() //回复的请求(当列表在滑动的时候,调用pauseRequests()取消请求,滑动停止时,调用resumeRequests()恢复请求 等等)
196 | > - ImageLoader.clearDiskCache()//清除磁盘缓存(必须在后台线程中调用)
197 | > - ImageLoader.clearMomoryCache(View view) //清除指定view的缓存
198 | > - ImageLoader.clearMomory() // 清除内存缓存(必须在UI线程中调用)
199 |
200 |
201 | ##图片的各种设置信息--SingleConfig
202 | 我们所设置图片的所有属性都写在这个类里面。下面我们详细的看一下:
203 |
204 | > - url(String url) //支持filepath、图片链接、contenProvider、资源id四种
205 | > - thumbnail(float thumbnail)//缩略图
206 | > - rectRoundCorner(int rectRoundRadius, int overlayColorWhenGif) //形状为圆角矩形时的圆角半径
207 | > - asSquare() //形状为正方形
208 | > - colorFilter(int color) //颜色滤镜
209 | > - diskCacheStrategy(DiskCacheStrategy diskCacheStrategy) //DiskCacheStrategy.NONE :不缓存图片 /DiskCacheStrategy.SOURCE :缓存图片源文件/DiskCacheStrategy.RESULT:缓存修改过的图片/DiskCacheStrategy.ALL:缓存所有的图片,默认
210 | > - asCircle(int overlayColorWhenGif)//加载圆形图片
211 | > - placeHolder(int placeHolderResId) //占位图
212 | > - override(int oWidth, int oHeight) //加载图片时设置分辨率 a
213 | > - scale(int scaleMode) // CENTER_CROP等比例缩放图片,直到图片的狂高都大于等于ImageView的宽度,然后截取中间的显示 ; FIT_CENTER 等比例缩放图片,宽或者是高等于ImageView的宽或者是高 默认:FIT_CENTER
214 | > - animate(int animationId ) 引入动画
215 | > - animate( Animation animation) 引入动画
216 | > - animate(ViewPropertyAnimation.Animator animato) 引入动画
217 | > - asBitmap(BitmapListener bitmapListener)// 使用bitmap不显示到imageview
218 | > - into(View targetView) //展示到imageview
219 | > - colorFilter(int filteColor) //颜色滤镜
220 | > - blur(int blurRadius) //高斯模糊
221 | > - brightnessFilter(float level) //调节图片亮度
222 | > - grayscaleFilter() //黑白效果
223 | > - swirlFilter() //漩涡效果
224 | > - toonFilter() //油画效果
225 | > - sepiaFilter() //水墨画效果
226 | > - contrastFilter(float constrasrLevel) //锐化效果
227 | > - invertFilter() //胶片效果
228 | > - pixelationFilter(float pixelationLevel) //马赛克效果
229 | > - sketchFilter() // //素描效果
230 | > - vignetteFilter() //晕映效果
231 |
232 | [github项目地址](https://github.com/libin7278/ImageLoader)
233 |
234 | ##中转站--GlideLoader
235 | GlideLoader实现ILoader接口。在使用的时候我们虽然不用关心这个类,但是了解一下主要做了什么功能还是不错的。
236 |
237 | ```
238 | public class GlideLoader implements ILoader {
239 |
240 | /**
241 | * @param context 上下文
242 | * @param cacheSizeInM Glide默认磁盘缓存最大容量250MB
243 | * @param memoryCategory 调整内存缓存的大小 LOW(0.5f) / NORMAL(1f) / HIGH(1.5f);
244 | * @param isInternalCD true 磁盘缓存到应用的内部目录 / false 磁盘缓存到外部存
245 | */
246 | @Override
247 | public void init(Context context, int cacheSizeInM, MemoryCategory memoryCategory, boolean isInternalCD) {
248 | Glide.get(context).setMemoryCategory(memoryCategory); //如果在应用当中想要调整内存缓存的大小,开发者可以通过如下方式:
249 | GlideBuilder builder = new GlideBuilder(context);
250 | if (isInternalCD) {
251 | builder.setDiskCache(new InternalCacheDiskCacheFactory(context, cacheSizeInM * 1024 * 1024));
252 | } else {
253 | builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, cacheSizeInM * 1024 * 1024));
254 | }
255 | }
256 |
257 | @Override
258 | public void request(final SingleConfig config) {
259 | RequestManager requestManager = Glide.with(config.getContext());
260 | DrawableTypeRequest request = getDrawableTypeRequest(config, requestManager);
261 |
262 | if (config.isAsBitmap()) {
263 | SimpleTarget target = new SimpleTarget(config.getWidth(), config.getHeight()) {
264 | @Override
265 | public void onResourceReady(Bitmap bitmap, GlideAnimation glideAnimation) {
266 | config.getBitmapListener().onSuccess(bitmap);
267 | }
268 | };
269 |
270 | setShapeModeAndBlur(config, request);
271 |
272 | if (config.getDiskCacheStrategy() != null) {
273 | request.diskCacheStrategy(config.getDiskCacheStrategy());
274 | Logger.e("config.getDiskCacheStrategy() : " + config.getDiskCacheStrategy());
275 | }
276 |
277 | request.asBitmap().into(target);
278 |
279 | } else {
280 |
281 | if (request == null) {
282 | return;
283 | }
284 |
285 | if (MyUtil.shouldSetPlaceHolder(config)) {
286 | request.placeholder(config.getPlaceHolderResId());
287 | }
288 |
289 | int scaleMode = config.getScaleMode();
290 |
291 | switch (scaleMode) {
292 | case ScaleMode.CENTER_CROP:
293 | request.centerCrop();
294 | break;
295 | case ScaleMode.FIT_CENTER:
296 | request.fitCenter();
297 | break;
298 | default:
299 | request.fitCenter();
300 | break;
301 | }
302 |
303 | // TODO: 2017/4/21 设置图片滤镜(目前只有高斯)
304 | setShapeModeAndBlur(config, request);
305 |
306 | //设置缩略图
307 | if (config.getThumbnail() != 0) {
308 | request.thumbnail(config.getThumbnail());
309 | }
310 |
311 | //设置图片加载的分辨 sp
312 | if (config.getoWidth() != 0 && config.getoHeight() != 0) {
313 | request.override(config.getoWidth(), config.getoHeight());
314 | Logger.e("设置图片加载的分辨 : " + config.getoWidth() + " " + config.getoHeight());
315 | }
316 |
317 | //是否跳过磁盘存储
318 | if (config.getDiskCacheStrategy() != null) {
319 | request.diskCacheStrategy(config.getDiskCacheStrategy());
320 | Logger.e("config.getDiskCacheStrategy() : " + config.getDiskCacheStrategy());
321 | }
322 |
323 | //设置图片加载动画
324 | setAnimator(config, request);
325 |
326 | //设置图片加载优先级
327 | setPriority(config, request);
328 |
329 | if (config.getErrorResId() > 0) {
330 | request.error(config.getErrorResId());
331 | }
332 |
333 | if (config.getTarget() instanceof ImageView) {
334 | request.into((ImageView) config.getTarget());
335 |
336 | Logger.e("config.getTarget()" + config.getTarget().getMeasuredWidth());
337 | }
338 | }
339 |
340 | }
341 |
342 | /**
343 | * 设置加载优先级
344 | *
345 | * @param config
346 | * @param request
347 | */
348 | private void setPriority(SingleConfig config, DrawableTypeRequest request) {
349 | switch (config.getPriority()) {
350 | case PriorityMode.PRIORITY_LOW:
351 | request.priority(Priority.LOW);
352 | break;
353 | case PriorityMode.PRIORITY_NORMAL:
354 | request.priority(Priority.NORMAL);
355 | break;
356 | case PriorityMode.PRIORITY_HIGH:
357 | request.priority(Priority.HIGH);
358 | break;
359 | case PriorityMode.PRIORITY_IMMEDIATE:
360 | request.priority(Priority.IMMEDIATE);
361 | break;
362 | default:
363 | request.priority(Priority.IMMEDIATE);
364 | break;
365 | }
366 | }
367 |
368 | /**
369 | * 设置加载进入动画
370 | *
371 | * @param config
372 | * @param request
373 | */
374 | private void setAnimator(SingleConfig config, DrawableTypeRequest request) {
375 | if (config.getAnimationType() == AnimationMode.ANIMATIONID) {
376 | request.animate(config.getAnimationId());
377 | } else if (config.getAnimationType() == AnimationMode.ANIMATOR) {
378 | request.animate(config.getAnimator());
379 | } else if (config.getAnimationType() == AnimationMode.ANIMATION) {
380 | request.animate(config.getAnimation());
381 | }
382 | }
383 |
384 | @Nullable
385 | private DrawableTypeRequest getDrawableTypeRequest(SingleConfig config, RequestManager requestManager) {
386 | DrawableTypeRequest request = null;
387 | if (!TextUtils.isEmpty(config.getUrl())) {
388 | request = requestManager.load(MyUtil.appendUrl(config.getUrl()));
389 | } else if (!TextUtils.isEmpty(config.getFilePath())) {
390 | request = requestManager.load(MyUtil.appendUrl(config.getFilePath()));
391 | } else if (!TextUtils.isEmpty(config.getContentProvider())) {
392 | request = requestManager.loadFromMediaStore(Uri.parse(config.getContentProvider()));
393 | } else if (config.getResId() > 0) {
394 | request = requestManager.load(config.getResId());
395 | }
396 | return request;
397 | }
398 |
399 | /**
400 | * 设置图片滤镜和形状
401 | *
402 | * @param config
403 | * @param request
404 | */
405 | private void setShapeModeAndBlur(SingleConfig config, DrawableTypeRequest request) {
406 | int shapeMode = config.getShapeMode();
407 | Transformation[] transformation = new Transformation[3];
408 | if (config.isNeedBlur()) {
409 | // transformation[0] = new BlurTransformation(config.getContext(), config.getBlurRadius());
410 | transformation[0] = new BrightnessFilterTransformation(config.getContext(), 0.5f);
411 | //transformation[0] =new GrayscaleTransformation(config.getContext()); 黑白效果
412 | }
413 |
414 | if(config.isNeedFilteColor()){
415 | transformation[2] = new ColorFilterTransformation(config.getContext(), config.getFilteColor());
416 | }
417 |
418 | switch (shapeMode) {
419 | case ShapeMode.RECT:
420 |
421 | break;
422 | case ShapeMode.RECT_ROUND:
423 | transformation[1] = new RoundedCornersTransformation
424 | (config.getContext(), config.getRectRoundRadius(), 0, RoundedCornersTransformation.CornerType.ALL);
425 |
426 | break;
427 | case ShapeMode.OVAL:
428 | transformation[1] = new CropCircleTransformation(config.getContext());
429 | break;
430 |
431 | case ShapeMode.SQUARE:
432 | transformation[1] = new CropSquareTransformation(config.getContext());
433 | break;
434 | }
435 |
436 | if (transformation[0] != null && transformation[1] != null && transformation[2] != null) {
437 | request.bitmapTransform(transformation);
438 | } else if (transformation[0] != null && transformation[1] == null) {
439 | request.bitmapTransform(transformation[0]);
440 | } else if (transformation[0] == null && transformation[1] != null) {
441 | request.bitmapTransform(transformation[1]);
442 | }else if(transformation[0] == null && transformation[1] == null && transformation[2] != null){
443 | request.bitmapTransform(transformation[2]);
444 | }
445 | }
446 |
447 | @Override
448 | public void pause() {
449 | Glide.with(GlobalConfig.context).pauseRequestsRecursive();
450 |
451 | }
452 |
453 | @Override
454 | public void resume() {
455 | Glide.with(GlobalConfig.context).resumeRequestsRecursive();
456 | }
457 |
458 | @Override
459 | public void clearDiskCache() {
460 | Glide.get(GlobalConfig.context).clearDiskCache();
461 | }
462 |
463 | @Override
464 | public void clearMomoryCache(View view) {
465 | Glide.clear(view);
466 | }
467 |
468 | @Override
469 | public void clearMomory() {
470 | Glide.get(GlobalConfig.context).clearMemory();
471 | }
472 |
473 | @Override
474 | public File getFileFromDiskCache(String url) {
475 | return null;
476 | }
477 |
478 | @Override
479 | public boolean isCached(String url) {
480 | return false;
481 | }
482 |
483 | @Override
484 | public void trimMemory(int level) {
485 | Glide.with(GlobalConfig.context).onTrimMemory(level);
486 | }
487 |
488 | @Override
489 | public void clearAllMemoryCaches() {
490 | Glide.with(GlobalConfig.context).onLowMemory();
491 | }
492 | }
493 | ```
494 |
495 | 看一下效果哦:
496 | 
497 |
498 | 到这里我们的封装就结束了,就可以愉快的使用了,欢迎大家提出意见与建议。
499 |
500 | [Glide二次封装库源码](https://github.com/libin7278/ImageLoader)
501 |
502 | 后面会更新到jcenter,并会出一篇具体如何使用本库的文章,还请大家持续关注哦。
503 |
--------------------------------------------------------------------------------