├── .gitignore
├── .idea
├── gradle.xml
├── misc.xml
├── modules.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── jni
│ ├── Android.mk
│ ├── Application.mk
│ ├── ShimingImageBlur.c
│ ├── com_shiming_imageloader_jnitest_JniUtils.cpp
│ └── com_shiming_imageloader_jnitest_JniUtils.h
├── libs
│ ├── armeabi-v7a
│ │ └── libShimingImageBlur.so
│ ├── armeabi
│ │ └── libShimingImageBlur.so
│ └── x86
│ │ └── libShimingImageBlur.so
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── shiming
│ │ └── imageloader
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── shiming
│ │ │ └── imageloader
│ │ │ ├── GlideV4DemoActivity.java
│ │ │ ├── ImageLoaderByNetActivity.java
│ │ │ ├── JniImageByNetAndJniActivity.java
│ │ │ ├── JniImageByNetNoJniActivity.java
│ │ │ ├── JniImageBySDAndJniActivity.java
│ │ │ ├── JniImageBySDNoJniActivity.java
│ │ │ ├── MainActivity.java
│ │ │ ├── MyApp.java
│ │ │ └── jnitest
│ │ │ └── JniUtils.java
│ └── res
│ │ ├── drawable
│ │ └── blur_bg_mask_gradient_shape.xml
│ │ ├── layout
│ │ ├── activity_glide_v4_demo.xml
│ │ ├── activity_image_loader.xml
│ │ ├── activity_jni_image.xml
│ │ ├── activity_jni_image_by_net_no_jni.xml
│ │ ├── activity_jni_image_by_sd.xml
│ │ ├── activity_jni_image_by_sd_no_jni.xml
│ │ └── activity_main.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_round.png
│ │ ├── icon.jpg
│ │ └── test.jpg
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── shiming
│ └── imageloader
│ └── ExampleUnitTest.java
├── build.gradle
├── build.gradle.bak
├── compresspic
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── shiming
│ │ └── compresspic
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── shiming
│ │ │ └── compresspic
│ │ │ ├── BitmapUtil.java
│ │ │ ├── CompressCore.java
│ │ │ └── ImageCompress.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── shiming
│ └── compresspic
│ └── ExampleUnitTest.java
├── glide4.7.1demo
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── code
│ │ └── shiming
│ │ └── com
│ │ └── glide471demo
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── code
│ │ │ └── shiming
│ │ │ └── com
│ │ │ └── glide471demo
│ │ │ ├── DemoActivity.java
│ │ │ ├── ImageProgressActivity.java
│ │ │ ├── MainActivity.java
│ │ │ └── TransitionOptionsActivity.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── activity_demo.xml
│ │ ├── activity_image_progress.xml
│ │ ├── activity_main.xml
│ │ └── activity_transition_options.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_round.png
│ │ ├── icon.jpg
│ │ └── test.jpg
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── code
│ └── shiming
│ └── com
│ └── glide471demo
│ └── ExampleUnitTest.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ ├── gradle-wrapper.properties
│ └── gradle-wrapper.properties.bak
├── gradlew
├── gradlew.bat
├── imageloader4.7.1
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── code
│ │ └── shiming
│ │ └── com
│ │ └── imageloader471
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── code
│ │ │ └── shiming
│ │ │ └── com
│ │ │ └── imageloader471
│ │ │ ├── AppGlideModuleProgress.java
│ │ │ ├── ExternalDiskCacheFactory.java
│ │ │ ├── GlideImageLoaderClient.java
│ │ │ ├── IImageLoaderClient.java
│ │ │ ├── ImageLoaderV4.java
│ │ │ ├── listener
│ │ │ ├── IGetBitmapListener.java
│ │ │ ├── IGetDrawableListener.java
│ │ │ ├── IImageLoaderListener.java
│ │ │ └── ImageSize.java
│ │ │ ├── okhttp
│ │ │ ├── OnGlideImageViewListener.java
│ │ │ ├── OnProgressListener.java
│ │ │ ├── ProgressManager.java
│ │ │ └── ProgressResponseBody.java
│ │ │ └── tranform
│ │ │ ├── BlurBitmapTranformation.java
│ │ │ ├── GlideCircleTransformation.java
│ │ │ └── RoundBitmapTranformation.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── code
│ └── shiming
│ └── com
│ └── imageloader471
│ └── ExampleUnitTest.java
├── imageloaderlibrary
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── imageloader
│ │ └── shiming
│ │ └── com
│ │ └── imageloaderlibrary
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── iamgeloader
│ │ │ └── client
│ │ │ ├── GlideImageLoaderClient.java
│ │ │ ├── IImageLoaderClient.java
│ │ │ ├── ImageLoader.java
│ │ │ ├── listener
│ │ │ ├── IGetBitmapListenerByCall.java
│ │ │ ├── IGetDrawableListenerByCall.java
│ │ │ ├── IImageLoaderListenerByCall.java
│ │ │ └── ImageSizeTwo.java
│ │ │ └── tranform
│ │ │ ├── BlurBitmapTransformationDD.java
│ │ │ ├── CircleBitmapTransformationDD.java
│ │ │ ├── GlideTransformD.java
│ │ │ ├── IBitmapTransformationD.java
│ │ │ └── RoundBitmapTransformationD.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── imageloader
│ └── shiming
│ └── com
│ └── imageloaderlibrary
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | 1.8
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "com.shiming.imageloader"
8 | minSdkVersion 15
9 | targetSdkVersion 27
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | //ndk编译生成.so文件
14 | // 只要是第一次生成了so库的文件,那么以后就不用生成这个文件,记住一定要记住,如果需要生成so文件
15 | //需要把外面的目录的jni移动到和mian目录下和Java同级的目录下
16 | // ndk {
17 | // moduleName "ShimingImageBlur" //生成的so名字
18 | // abiFilters "armeabi", "armeabi-v7a", "x86" //输出指定三种abi体系结构下的so库。
19 | // }
20 | }
21 | sourceSets.main {
22 | jniLibs.srcDirs = ['libs']
23 | }
24 | sourceSets {
25 | main {
26 | aidl.srcDirs = ['src/main/java']
27 | assets.srcDirs = ['assets']
28 | jniLibs.srcDirs = ['libs']
29 | }
30 | }
31 | buildTypes {
32 | release {
33 | minifyEnabled false
34 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
35 | }
36 | }
37 |
38 | }
39 |
40 | dependencies {
41 | compile fileTree(dir: 'libs', include: ['*.jar'])
42 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
43 | exclude group: 'com.android.support', module: 'support-annotations'
44 | })
45 | compile project(':imageloaderlibrary')
46 |
47 | //noinspection GradleCompatible
48 | compile 'com.android.support:appcompat-v7:27.0.0'
49 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
50 | testCompile 'junit:junit:4.12'
51 | //依赖图片压缩的 jni
52 | // compile project(':compresspic')
53 | }
54 |
--------------------------------------------------------------------------------
/app/jni/Android.mk:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2009 The Android Open Source Project
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | #
15 | LOCAL_PATH := $(call my-dir)
16 |
17 | include $(CLEAR_VARS)
18 | #编译生成的文件的类库叫什么名字
19 | LOCAL_MODULE := ShimingImageBlur
20 | #要编译的c文件
21 | LOCAL_SRC_FILES := com_shiming_imageloader_jnitest_JniUtils.cpp
22 |
23 | include $(BUILD_SHARED_LIBRARY)
24 |
--------------------------------------------------------------------------------
/app/jni/Application.mk:
--------------------------------------------------------------------------------
1 | #jni打包的C语言类库默认仅支持 arm架构,需要在jni目录下创建 Android.mk 文件添加如下代码可以支持x86架构
2 | #或者是 :=all
3 | APP_ABI :=armeabi armeabi-v7a x86
--------------------------------------------------------------------------------
/app/jni/ShimingImageBlur.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #define ABS(a) ((a)<(0)?(-a):(a))
4 | #define MAX(a,b) ((a)>(b)?(a):(b))
5 | #define MIN(a,b) ((a)<(b)?(a):(b))
6 |
7 |
8 | static int* StackBlur(int* pix, int w, int h, int radius) {
9 | int wm = w - 1;
10 | int hm = h - 1;
11 | int wh = w * h;
12 | int div = radius + radius + 1;
13 | // 指针
14 | int *r = (int *)malloc(wh * sizeof(int));
15 | int *g = (int *)malloc(wh * sizeof(int));
16 | int *b = (int *)malloc(wh * sizeof(int));
17 | int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
18 |
19 | int *vmin = (int *)malloc(MAX(w,h) * sizeof(int));
20 |
21 | int divsum = (div + 1) >> 1;
22 | divsum *= divsum;
23 | int *dv = (int *)malloc(256 * divsum * sizeof(int));
24 | for (i = 0; i < 256 * divsum; i++) {
25 | dv[i] = (i / divsum);
26 | }
27 |
28 | yw = yi = 0;
29 |
30 | int(*stack)[3] = (int(*)[3])malloc(div * 3 * sizeof(int));
31 | int stackpointer;
32 | int stackstart;
33 | int *sir;
34 | int rbs;
35 | int r1 = radius + 1;
36 | int routsum, goutsum, boutsum;
37 | int rinsum, ginsum, binsum;
38 |
39 | for (y = 0; y < h; y++) {
40 | rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
41 | for (i = -radius; i <= radius; i++) {
42 | p = pix[yi + (MIN(wm, MAX(i, 0)))];
43 | sir = stack[i + radius];
44 | sir[0] = (p & 0xff0000) >> 16;
45 | sir[1] = (p & 0x00ff00) >> 8;
46 | sir[2] = (p & 0x0000ff);
47 |
48 | rbs = r1 - ABS(i);
49 | rsum += sir[0] * rbs;
50 | gsum += sir[1] * rbs;
51 | bsum += sir[2] * rbs;
52 | if (i > 0) {
53 | rinsum += sir[0];
54 | ginsum += sir[1];
55 | binsum += sir[2];
56 | }
57 | else {
58 | routsum += sir[0];
59 | goutsum += sir[1];
60 | boutsum += sir[2];
61 | }
62 | }
63 | stackpointer = radius;
64 |
65 | for (x = 0; x < w; x++) {
66 |
67 | r[yi] = dv[rsum];
68 | g[yi] = dv[gsum];
69 | b[yi] = dv[bsum];
70 |
71 | rsum -= routsum;
72 | gsum -= goutsum;
73 | bsum -= boutsum;
74 |
75 | stackstart = stackpointer - radius + div;
76 | sir = stack[stackstart % div];
77 |
78 | routsum -= sir[0];
79 | goutsum -= sir[1];
80 | boutsum -= sir[2];
81 |
82 | if (y == 0) {
83 | vmin[x] = MIN(x + radius + 1, wm);
84 | }
85 | p = pix[yw + vmin[x]];
86 |
87 | sir[0] = (p & 0xff0000) >> 16;
88 | sir[1] = (p & 0x00ff00) >> 8;
89 | sir[2] = (p & 0x0000ff);
90 |
91 | rinsum += sir[0];
92 | ginsum += sir[1];
93 | binsum += sir[2];
94 |
95 | rsum += rinsum;
96 | gsum += ginsum;
97 | bsum += binsum;
98 |
99 | stackpointer = (stackpointer + 1) % div;
100 | sir = stack[(stackpointer) % div];
101 |
102 | routsum += sir[0];
103 | goutsum += sir[1];
104 | boutsum += sir[2];
105 |
106 | rinsum -= sir[0];
107 | ginsum -= sir[1];
108 | binsum -= sir[2];
109 |
110 | yi++;
111 | }
112 | yw += w;
113 | }
114 | for (x = 0; x < w; x++) {
115 | rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
116 | yp = -radius * w;
117 | for (i = -radius; i <= radius; i++) {
118 | yi = MAX(0, yp) + x;
119 |
120 | sir = stack[i + radius];
121 |
122 | sir[0] = r[yi];
123 | sir[1] = g[yi];
124 | sir[2] = b[yi];
125 |
126 | rbs = r1 - ABS(i);
127 |
128 | rsum += r[yi] * rbs;
129 | gsum += g[yi] * rbs;
130 | bsum += b[yi] * rbs;
131 |
132 | if (i > 0) {
133 | rinsum += sir[0];
134 | ginsum += sir[1];
135 | binsum += sir[2];
136 | }
137 | else {
138 | routsum += sir[0];
139 | goutsum += sir[1];
140 | boutsum += sir[2];
141 | }
142 |
143 | if (i < hm) {
144 | yp += w;
145 | }
146 | }
147 | yi = x;
148 | stackpointer = radius;
149 | for (y = 0; y < h; y++) {
150 | // Preserve alpha channel: ( 0xff000000 & pix[yi] )
151 | pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];
152 |
153 | rsum -= routsum;
154 | gsum -= goutsum;
155 | bsum -= boutsum;
156 |
157 | stackstart = stackpointer - radius + div;
158 | sir = stack[stackstart % div];
159 |
160 | routsum -= sir[0];
161 | goutsum -= sir[1];
162 | boutsum -= sir[2];
163 |
164 | if (x == 0) {
165 | vmin[y] = MIN(y + r1, hm) * w;
166 | }
167 | p = x + vmin[y];
168 |
169 | sir[0] = r[p];
170 | sir[1] = g[p];
171 | sir[2] = b[p];
172 |
173 | rinsum += sir[0];
174 | ginsum += sir[1];
175 | binsum += sir[2];
176 |
177 | rsum += rinsum;
178 | gsum += ginsum;
179 | bsum += binsum;
180 |
181 | stackpointer = (stackpointer + 1) % div;
182 | sir = stack[stackpointer];
183 |
184 | routsum += sir[0];
185 | goutsum += sir[1];
186 | boutsum += sir[2];
187 |
188 | rinsum -= sir[0];
189 | ginsum -= sir[1];
190 | binsum -= sir[2];
191 |
192 | yi += w;
193 | }
194 | }
195 | //记得要释放掉
196 | free(r);
197 | free(g);
198 | free(b);
199 | free(vmin);
200 | free(dv);
201 | free(stack);
202 | return(pix);
203 | }
204 |
--------------------------------------------------------------------------------
/app/jni/com_shiming_imageloader_jnitest_JniUtils.cpp:
--------------------------------------------------------------------------------
1 | #include "com_shiming_imageloader_jnitest_JniUtils.h"
2 | #include "ShimingImageBlur.c"
3 | #include
4 |
5 | //用c++实现的,方法名必须为本地方法的全类名改为下划线
6 | //第一个参数为java虚拟机的内存地址的二级指正,用于本地方法与java虚拟机在内存中的交互
7 | //第二个参数为一个java对象,即是那个对象调用了这个c的方法 ,
8 | //后面的参数就是我们java的方法参数
9 | JNIEXPORT void JNICALL Java_com_shiming_imageloader_jnitest_JniUtils_blurIntArray
10 | (JNIEnv *env, jclass obj, jintArray arrIn, jint w, jint h, jint r)
11 | {
12 | jint *pix;
13 | pix = env->GetIntArrayElements(arrIn, 0);
14 | if (pix == NULL)
15 | return;
16 | //Start
17 | pix = StackBlur(pix, w, h, r);
18 | //End
19 | //int size = w * h;
20 | //jintArray result = env->NewIntArray(size);
21 | //env->SetIntArrayRegion(result, 0, size, pix);
22 | env->ReleaseIntArrayElements(arrIn, pix, 0);
23 | //return result;
24 | }
25 |
--------------------------------------------------------------------------------
/app/jni/com_shiming_imageloader_jnitest_JniUtils.h:
--------------------------------------------------------------------------------
1 | /* DO NOT EDIT THIS FILE - it is machine generated */
2 | #include
3 | /* Header for class com_shiming_imageloader_jni_JniUtils */
4 |
5 | #ifndef _Included_com_shiming_imageloader_jnitest_JniUtils
6 | #define _Included_com_shiming_imageloader_jnitest_JniUtils
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 | /*
11 | * Class: Java_com_shiming_imageloader_jnitest_JniUtils
12 | * Method: blurIntArray
13 | * Signature: ([IIII)V
14 | * 可千万要加上 Java_的前缀 ,要不然找不到啊
15 | */
16 |
17 | JNIEXPORT void JNICALL Java_com_shiming_imageloader_jnitest_JniUtils_blurIntArray
18 | (JNIEnv *, jclass, jintArray, jint, jint, jint);
19 |
20 | #ifdef __cplusplus
21 | }
22 | #endif
23 | #endif
24 |
--------------------------------------------------------------------------------
/app/libs/armeabi-v7a/libShimingImageBlur.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/app/libs/armeabi-v7a/libShimingImageBlur.so
--------------------------------------------------------------------------------
/app/libs/armeabi/libShimingImageBlur.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/app/libs/armeabi/libShimingImageBlur.so
--------------------------------------------------------------------------------
/app/libs/x86/libShimingImageBlur.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/app/libs/x86/libShimingImageBlur.so
--------------------------------------------------------------------------------
/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 E:\android-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 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/shiming/imageloader/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.shiming.imageloader;
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("com.shiming.imageloader", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/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 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/shiming/imageloader/GlideV4DemoActivity.java:
--------------------------------------------------------------------------------
1 | package com.shiming.imageloader;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.widget.ImageView;
6 |
7 | public class GlideV4DemoActivity extends AppCompatActivity {
8 | private ImageView mImageView_1;
9 | private ImageView mImageView_2;
10 | private ImageView mImageView_3;
11 | private ImageView mImageView_4;
12 | private ImageView mImageView_5;
13 | private ImageView mImageView_6;
14 | private ImageView mImageView_7;
15 | private ImageView mImageView_8;
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_glide_v4_demo);
20 | findView();
21 | // // //圆形图片
22 | // ImageLoaderV4.getInstance().displayCircleImage(this, "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg", mImageView_1, R.mipmap.ic_launcher_round);
23 | // //圆角图片
24 | // ImageLoaderV4.getInstance().displayRoundImage(this, "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg", mImageView_2, R.mipmap.ic_launcher_round, 40);
25 | // //模糊图片
26 | // ImageLoaderV4.getInstance().displayBlurImage(this, "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg", mImageView_3, R.mipmap.ic_launcher_round, 10);
27 | //
28 | // //本地图片 不做处理
29 | // ImageLoaderV4.getInstance().displayImageInResource(this, R.mipmap.test, mImageView_4);
30 | // //本地图片,模糊处理
31 | // ImageLoaderV4.getInstance().displayImageInResource(this, R.mipmap.test, mImageView_5, new BlurBitmapTranformation( 200));
32 | // //本地图片,裁圆角处理
33 | // ImageLoaderV4.getInstance().displayImageInResource(this, R.mipmap.test, mImageView_6, new GlideCircleTransformation());
34 | // //四周倒角处理
35 | // ImageLoaderV4.getInstance().displayImageInResource(this, R.mipmap.test, mImageView_7, new RoundBitmapTranformation( 40));
36 | }
37 |
38 | private void findView() {
39 | mImageView_1 = (ImageView) findViewById(R.id.image_view_1);
40 | mImageView_2 = (ImageView) findViewById(R.id.image_view_2);
41 | mImageView_3 = (ImageView) findViewById(R.id.image_view_3);
42 | mImageView_4 = (ImageView) findViewById(R.id.image_view_4);
43 | mImageView_5 = (ImageView) findViewById(R.id.image_view_5);
44 | mImageView_6 = (ImageView) findViewById(R.id.image_view_6);
45 | mImageView_7 = (ImageView) findViewById(R.id.image_view_7);
46 |
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/com/shiming/imageloader/ImageLoaderByNetActivity.java:
--------------------------------------------------------------------------------
1 | package com.shiming.imageloader;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.graphics.BitmapShader;
6 | import android.graphics.Canvas;
7 | import android.graphics.Matrix;
8 | import android.graphics.Paint;
9 | import android.os.Bundle;
10 | import android.support.annotation.Nullable;
11 | import android.support.v4.app.FragmentActivity;
12 | import android.widget.ImageView;
13 |
14 | import iamgeloader.client.ImageLoader;
15 | import iamgeloader.client.tranform.BlurBitmapTransformationDD;
16 | import iamgeloader.client.tranform.CircleBitmapTransformationDD;
17 | import iamgeloader.client.tranform.RoundBitmapTransformationD;
18 |
19 |
20 | /**
21 | * @author shiming
22 | * @version v1.0 create at 2017/9/26
23 | * @des 通过imageloader 处理图片
24 | */
25 | public class ImageLoaderByNetActivity extends FragmentActivity {
26 |
27 |
28 | private ImageView mImageView_1;
29 | private ImageView mImageView_2;
30 | private ImageView mImageView_3;
31 | private ImageView mImageView_4;
32 | private ImageView mImageView_5;
33 | private ImageView mImageView_6;
34 | private ImageView mImageView_7;
35 | private ImageView mImageView_8;
36 |
37 | @Override
38 | protected void onCreate(@Nullable Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.activity_image_loader);
41 | findView();
42 | loadData();
43 | }
44 |
45 | private void loadData() {
46 | //圆形图片
47 | ImageLoader.getInstance().displayCircleImage(this, "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg", mImageView_1, R.mipmap.ic_launcher_round);
48 | //圆角图片
49 | ImageLoader.getInstance().displayRoundImage(this, "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg", mImageView_2, R.mipmap.ic_launcher_round, 40);
50 | //模糊图片
51 | ImageLoader.getInstance().displayBlurImage(this, "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg", mImageView_3, R.mipmap.ic_launcher_round, 100);
52 |
53 | //本地图片 不做处理
54 | ImageLoader.getInstance().displayImageInResource(this, R.mipmap.test, mImageView_4);
55 | //本地图片,模糊处理
56 | ImageLoader.getInstance().displayImageInResource(this, R.mipmap.test, mImageView_5, new BlurBitmapTransformationDD(this, 200));
57 | //本地图片,裁圆角处理
58 | ImageLoader.getInstance().displayImageInResource(this, R.mipmap.test, mImageView_6, new CircleBitmapTransformationDD(this));
59 | //四周倒角处理
60 | ImageLoader.getInstance().displayImageInResource(this, R.mipmap.test, mImageView_7, new RoundBitmapTransformationD(this, 40));
61 | //通过代码实现裁剪为圆形图片
62 | drawCicriBitmap();
63 |
64 | }
65 |
66 | private void drawCicriBitmap() {
67 | Bitmap source = BitmapFactory.decodeResource(getResources(), R.mipmap.icon);
68 | int size = Math.min(source.getWidth(), source.getHeight());
69 | int width = (source.getWidth() - size) / 2;
70 | int height = (source.getHeight() - size) / 2;
71 | Bitmap target = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_4444);
72 | Canvas canvas = new Canvas(target);
73 | Paint paint = new Paint();
74 | // Call this to create a new shader that will draw with a bitmap.
75 | BitmapShader shader = new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
76 | if (width != 0 || height != 0) {
77 | Matrix matrix = new Matrix();
78 | matrix.setTranslate(-width, -height);
79 | shader.setLocalMatrix(matrix);
80 | }
81 | paint.setShader(shader);
82 | paint.setAntiAlias(true);
83 | float r = size / 2f;
84 | canvas.drawCircle(r, r, r, paint);
85 | mImageView_8.setImageBitmap(target);
86 | }
87 |
88 | private void findView() {
89 | mImageView_1 = (ImageView) findViewById(R.id.image_view_1);
90 | mImageView_2 = (ImageView) findViewById(R.id.image_view_2);
91 | mImageView_3 = (ImageView) findViewById(R.id.image_view_3);
92 | mImageView_4 = (ImageView) findViewById(R.id.image_view_4);
93 | mImageView_5 = (ImageView) findViewById(R.id.image_view_5);
94 | mImageView_6 = (ImageView) findViewById(R.id.image_view_6);
95 | mImageView_7 = (ImageView) findViewById(R.id.image_view_7);
96 | mImageView_8 = (ImageView) findViewById(R.id.image_view_8);
97 | }
98 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/shiming/imageloader/JniImageByNetAndJniActivity.java:
--------------------------------------------------------------------------------
1 | package com.shiming.imageloader;
2 |
3 | import android.graphics.Bitmap;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.widget.ImageView;
7 |
8 |
9 | import com.shiming.imageloader.jnitest.JniUtils;
10 |
11 | import iamgeloader.client.ImageLoader;
12 | import iamgeloader.client.listener.IGetBitmapListenerByCall;
13 |
14 |
15 | /**
16 | * @author shiming
17 | * @version v1.0 create at 2017/9/26
18 | * @des 通过jni实现的高斯模糊图片
19 | */
20 | public class JniImageByNetAndJniActivity extends AppCompatActivity {
21 |
22 | private ImageView mImageView_1;
23 | private ImageView mImageView_2;
24 | private String mUrl;
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_jni_image);
30 | findView();
31 | mUrl = "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg";
32 | initData();
33 | JniUtils.test();
34 | }
35 |
36 | private void initData() {
37 | JniUtils.loadBlurImg(this,mUrl,mImageView_2,true);
38 | ImageLoader.getInstance().getBitmapFromCache(this, mUrl, new IGetBitmapListenerByCall() {
39 | @Override
40 | public void onBitmap(Bitmap bitmap) {
41 | mImageView_1.setImageBitmap(bitmap);
42 | }
43 | });
44 | }
45 |
46 | private void findView() {
47 | mImageView_1 = (ImageView) findViewById(R.id.image_view_1);
48 | mImageView_2 = (ImageView) findViewById(R.id.image_view_2);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/shiming/imageloader/JniImageByNetNoJniActivity.java:
--------------------------------------------------------------------------------
1 | package com.shiming.imageloader;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.FragmentActivity;
6 | import android.widget.ImageView;
7 |
8 | import com.shiming.imageloader.jnitest.JniUtils;
9 |
10 | import iamgeloader.client.ImageLoader;
11 |
12 |
13 | /**
14 | * @author shiming
15 | * @version v1.0 create at 2017/9/27
16 | * @des 通过网络获取图片没有使用到jni里面的算法
17 | */
18 | public class JniImageByNetNoJniActivity extends FragmentActivity{
19 |
20 | private ImageView mImageView_1;
21 | private ImageView mImageView_2;
22 | private String mUrl;
23 |
24 | @Override
25 | protected void onCreate(@Nullable Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_jni_image_by_net_no_jni);
28 | findView();
29 | mUrl = "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg";
30 | initData();
31 | JniUtils.test();
32 | }
33 |
34 | private void initData() {
35 | JniUtils.loadBlurImg(this,mUrl,mImageView_1,false);
36 | ImageLoader.getInstance().displayImage(this,mUrl,mImageView_2);
37 | }
38 |
39 | private void findView() {
40 | mImageView_1 = (ImageView) findViewById(R.id.image_view_1);
41 | mImageView_2 = (ImageView) findViewById(R.id.image_view_2);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/shiming/imageloader/JniImageBySDAndJniActivity.java:
--------------------------------------------------------------------------------
1 | package com.shiming.imageloader;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.FragmentActivity;
6 | import android.widget.ImageView;
7 |
8 | import com.shiming.imageloader.jnitest.JniUtils;
9 |
10 | import iamgeloader.client.ImageLoader;
11 |
12 |
13 | /**
14 | * @author shiming
15 | * @version v1.0 create at 2017/9/26
16 | * @des 获取本地了图片,使用了jni里面的算法
17 | */
18 | public class JniImageBySDAndJniActivity extends FragmentActivity {
19 |
20 | private ImageView mImageView;
21 | private ImageView mImageView2;
22 |
23 | @Override
24 | protected void onCreate(@Nullable Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_jni_image_by_sd);
27 | mImageView = (ImageView) findViewById(R.id.image_view_1);
28 | mImageView2 = (ImageView) findViewById(R.id.image_view_2);
29 | mImageView.setImageResource(R.mipmap.icon);
30 | JniUtils.applyBlur(mImageView,true);
31 | ImageLoader.getInstance().displayImage(this,R.mipmap.icon,mImageView2);
32 |
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/shiming/imageloader/JniImageBySDNoJniActivity.java:
--------------------------------------------------------------------------------
1 | package com.shiming.imageloader;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.FragmentActivity;
6 | import android.widget.ImageView;
7 |
8 | import com.shiming.imageloader.jnitest.JniUtils;
9 |
10 | import iamgeloader.client.ImageLoader;
11 |
12 |
13 | /**
14 | * @author shiming
15 | * @version v1.0 create at 2017/9/27
16 | * @des 我是没有使用jni里面算法实现的高斯模糊,通过本地获取的图片"
17 |
18 | */
19 | public class JniImageBySDNoJniActivity extends FragmentActivity {
20 |
21 | private ImageView mImageView;
22 | private ImageView mImageView2;
23 | @Override
24 | protected void onCreate(@Nullable Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_jni_image_by_sd_no_jni);
27 | mImageView = (ImageView) findViewById(R.id.image_view_1);
28 | mImageView2 = (ImageView) findViewById(R.id.image_view_2);
29 | mImageView.setImageResource(R.mipmap.icon);
30 | JniUtils.applyBlur(mImageView,false);
31 | ImageLoader.getInstance().displayImage(this,R.mipmap.icon,mImageView2);
32 |
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/shiming/imageloader/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.shiming.imageloader;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | public class MainActivity extends AppCompatActivity {
9 |
10 |
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_main);
16 | findViewById(R.id.btn1).setOnClickListener(new View.OnClickListener() {
17 | @Override
18 | public void onClick(View v) {
19 | startActivity(new Intent(MainActivity.this,JniImageByNetAndJniActivity.class));
20 | }
21 | });
22 |
23 | findViewById(R.id.btn2).setOnClickListener(new View.OnClickListener() {
24 | @Override
25 | public void onClick(View v) {
26 | startActivity(new Intent(MainActivity.this,ImageLoaderByNetActivity.class));
27 | }
28 | });
29 | findViewById(R.id.btn3).setOnClickListener(new View.OnClickListener() {
30 | @Override
31 | public void onClick(View v) {
32 | startActivity(new Intent(MainActivity.this,JniImageBySDAndJniActivity.class));
33 | }
34 | });
35 | findViewById(R.id.btn4).setOnClickListener(new View.OnClickListener() {
36 | @Override
37 | public void onClick(View v) {
38 | startActivity(new Intent(MainActivity.this,JniImageByNetNoJniActivity.class));
39 | }
40 | });
41 | findViewById(R.id.btn5).setOnClickListener(new View.OnClickListener() {
42 | @Override
43 | public void onClick(View v) {
44 | startActivity(new Intent(MainActivity.this,JniImageBySDNoJniActivity.class));
45 | }
46 | });
47 |
48 | findViewById(R.id.btn6).setOnClickListener(new View.OnClickListener() {
49 | @Override
50 | public void onClick(View v) {
51 | startActivity(new Intent(MainActivity.this,GlideV4DemoActivity.class));
52 | }
53 | });
54 |
55 |
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/app/src/main/java/com/shiming/imageloader/MyApp.java:
--------------------------------------------------------------------------------
1 | package com.shiming.imageloader;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 |
6 |
7 |
8 | /**
9 | * @author shiming
10 | * @version v1.0 create at 2017/9/26
11 | * @des
12 | */
13 | public class MyApp extends Application {
14 |
15 | private static Context mInstance;
16 |
17 | public static Context getInstance() {
18 | return mInstance;
19 | }
20 |
21 | @Override
22 | public void onCreate() {
23 | super.onCreate();
24 | mInstance=this;
25 | //方法失效了 这个还没有成功尝试
26 | // CompressCore compressCore = new CompressCore();
27 |
28 |
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/shiming/imageloader/jnitest/JniUtils.java:
--------------------------------------------------------------------------------
1 | package com.shiming.imageloader.jnitest;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.graphics.drawable.BitmapDrawable;
8 | import android.view.View;
9 | import android.view.ViewTreeObserver;
10 | import android.widget.ImageView;
11 |
12 | import com.shiming.imageloader.MyApp;
13 |
14 | import java.util.ArrayList;
15 |
16 | import iamgeloader.client.ImageLoader;
17 | import iamgeloader.client.listener.IGetBitmapListenerByCall;
18 |
19 |
20 | /**
21 | * @author shiming
22 | * @version v1.0 create at 2017/9/26
23 | * @des
24 | */
25 | public class JniUtils {
26 |
27 | private final static float DEFAULT_BLUR_FACTOR = 7f; //模糊因子 越大越模糊
28 |
29 | private final static float DEFAULT_BLUR_RADIUS = 2f; //模糊半径
30 | //此处命名要和com_shiming_imageloader_jnitest_JniUtils.cpp 中的一样才可以 出错一步没得商量,要不断的检查
31 | public static native void blurIntArray(int[] pImg, int w, int h, int r);
32 |
33 | /**
34 | * 参照:MediaPlayer的写法
35 | static {
36 | System.loadLibrary("media_jni");
37 | native_init();
38 | }
39 | */
40 | static {
41 | /**
42 | * #编译生成的文件的类库叫什么名字
43 | LOCAL_MODULE := ShimingImageBlur
44 | 必须和Android.mk中的一样,生成的so库虽然会加上libShimingImageBlur.so 但是调用得到
45 | */
46 | System.loadLibrary("ShimingImageBlur");
47 |
48 | }
49 |
50 | /**
51 | * 已设置图片的view模糊 可设置其他view的background
52 | *
53 | * @param view
54 | */
55 | public static void applyBlur(final View view, final boolean flag) {
56 | // Register a callback to be invoked when the view tree is about to be drawn
57 | //翻译注册一个回调,view将要drawn,意思还没有drawn上去
58 | view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
59 | /**
60 | * 再绘图前加上
61 | * @return
62 | */
63 | @Override
64 | public boolean onPreDraw() {
65 | view.getViewTreeObserver().removeOnPreDrawListener(this);
66 | //buildDrawingCache(false);
67 | //如果绘制无效,则强制构建绘图缓存,
68 | view.buildDrawingCache();
69 |
70 | Bitmap bmp = view.getDrawingCache();
71 | blur(bmp, view,flag);
72 | //通常cache会占用一定量的内存,所以必须销毁
73 | view.destroyDrawingCache();
74 | //返回 true 继续绘制,返回false取消。 如果返回为false的,页面就不会绘制了
75 | return true;
76 | }
77 | });
78 | }
79 |
80 | /**
81 | * 模糊图片
82 | * @param blurFactor 模糊因子
83 | * @param blurRadius 模糊半径
84 | * @param bitmap 图片
85 | * @param view view
86 | * @param flag 是否需要jni里面的算法
87 | */
88 | public static void blur(float blurFactor, float blurRadius, Bitmap bitmap, final View view, boolean flag) {
89 |
90 | Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth() / blurFactor),
91 | (int) (view.getMeasuredHeight() / blurFactor), Bitmap.Config.ARGB_8888);
92 | overlay.getHeight();
93 | overlay.getWidth();
94 | Canvas canvas = new Canvas(overlay);
95 | //如果我们需要放大1倍,即 scale(2, 2);缩放的中心点默认也是canvas的左上角,所以先要进行坐标平移,才能去缩放
96 | //平移,将画布的坐标原点向左右方向移动x,向上下方向移动y.canvas的默认位置是在(0,0)
97 | canvas.translate(-view.getLeft() / blurFactor, -view.getTop() / blurFactor);
98 | canvas.scale(1 / blurFactor, 1 / blurFactor);
99 | Paint paint = new Paint();
100 | //抗锯齿
101 | paint.setFlags(Paint.FILTER_BITMAP_FLAG);
102 | canvas.drawBitmap(bitmap, 0, 0, paint);
103 | //这里的overlay已经包含了信息
104 | //是否需要jni的计算
105 | if (flag) {
106 | overlay = doBlurJniArray(overlay, (int) blurRadius, true);
107 | }
108 | //可以简单地理解为 Bitmap 储存的是 像素信息,Drawable 储存的是 对 Canvas 的一系列操作。
109 | //而 BitmapDrawable 储存的是「把 Bitmap 渲染到 Canvas 上」这个操作。
110 | BitmapDrawable blurDrawable = new BitmapDrawable(MyApp.getInstance().getApplicationContext()
111 | .getResources(), overlay);
112 | if (view instanceof ImageView) {
113 | ((ImageView)view).setImageDrawable(blurDrawable);
114 | System.out.println("shiming blurDrawable" +blurDrawable);
115 | } else {
116 | view.setBackgroundDrawable(blurDrawable);
117 | }
118 | }
119 |
120 | /**
121 | * 模糊图片
122 | * @param bitmap
123 | * @param view
124 | * @param flag 是否需要jni来模糊
125 | */
126 | public static void blur(Bitmap bitmap, View view,boolean flag) {
127 | blur(DEFAULT_BLUR_FACTOR, DEFAULT_BLUR_RADIUS, bitmap, view,flag);
128 | }
129 |
130 |
131 | /**
132 | * 模糊网络图片
133 | *
134 | * @param context
135 | * @param url
136 | * @param imageView
137 | */
138 | public static void loadBlurImg(Context context, String url, final ImageView imageView, final boolean flag) {
139 | ImageLoader.getInstance().getBitmapFromCache(context, url, new IGetBitmapListenerByCall() {
140 | @Override
141 | public void onBitmap(Bitmap bitmap) {
142 | imageView.setImageBitmap(bitmap);
143 | applyBlur(imageView,flag);
144 | }
145 | });
146 | }
147 |
148 | /**
149 | *
150 | * @param sentBitmap
151 | * @param radius
152 | * @param canReuseInBitmap
153 | * @return
154 | *
155 | 参数 :http://ranlic.iteye.com/blog/1313735
156 | pixels 接收位图颜色值的数组
157 | offset 写入到pixels[]中的第一个像素索引值
158 | stride pixels[]中的行间距个数值(必须大于等于位图宽度)。可以为负数
159 | x 从位图中读取的第一个像素的x坐标值。
160 | y 从位图中读取的第一个像素的y坐标值
161 | width 从每一行中读取的像素宽度
162 | height 读取的行数
163 | 异常
164 | IilegalArgumentExcepiton 如果x,y,width,height越界或stride的绝对值小于位图宽度时将被抛出。
165 | ArrayIndexOutOfBoundsException 如果像素数组太小而无法接收指定书目的像素值时将被抛出。
166 | */
167 | private static Bitmap doBlurJniArray(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) {
168 | Bitmap bitmap;
169 | if (canReuseInBitmap) {
170 | bitmap = sentBitmap;
171 | } else {
172 | bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
173 | }
174 |
175 | if (radius < 1) {
176 | return (null);
177 | }
178 | int w = bitmap.getWidth();
179 | int h = bitmap.getHeight();
180 | int[] pix = new int[w * h];
181 | bitmap.getPixels(pix, 0, w, 0, 0, w, h);
182 | //pix数组,所有的关键的逻辑都是这个pix的操作,这里我们去交给了so.库去处理了,所以这里才是关键
183 | JniUtils.blurIntArray(pix, w, h, radius);
184 | bitmap.setPixels(pix, 0, w, 0, 0, w, h);
185 | return (bitmap);
186 | }
187 |
188 | /**
189 | * Copy on write array. This array is not thread safe, and only one loop can
190 | * iterate over this array at any given time. This class avoids allocations
191 | * until a concurrent modification happens.
192 | *
193 | * 复制一个集合,线程不安全。只能有一个线程能够loop便利,但是这类能够避免并发修改的发生,如果出现了
194 | * 并发修改的了,马上抛出异常
195 | */
196 | public static void test(){
197 | final CopyOnWriteArray listeners =
198 | new CopyOnWriteArray<>();
199 | listeners.add("1");
200 | listeners.add("2");
201 | listeners.add("3");
202 | listeners.add("4");
203 | listeners.add("5");
204 | if (listeners != null && listeners.size() > 0) {
205 | CopyOnWriteArray.Access access = listeners.start();
206 | try {
207 | int count = access.size();
208 | for (int i = 0; i < count; i++) {
209 | String s = access.get(i);
210 | System.out.println("shiming==="+s);
211 | }
212 | } finally {
213 | listeners.end();
214 | }
215 | }
216 | }
217 |
218 | static class CopyOnWriteArray {
219 | private ArrayList mData = new ArrayList();
220 | private ArrayList mDataCopy;
221 |
222 | private final Access mAccess = new Access();
223 |
224 | private boolean mStart;
225 |
226 | static class Access {
227 | private ArrayList mData;
228 | private int mSize;
229 |
230 | T get(int index) {
231 | return mData.get(index);
232 | }
233 |
234 | int size() {
235 | return mSize;
236 | }
237 | }
238 |
239 | CopyOnWriteArray() {
240 | }
241 |
242 | private ArrayList getArray() {
243 | if (mStart) {
244 | if (mDataCopy == null) mDataCopy = new ArrayList(mData);
245 | return mDataCopy;
246 | }
247 | return mData;
248 | }
249 |
250 | Access start() {
251 | if (mStart) throw new IllegalStateException("Iteration already started");
252 | mStart = true;
253 | mDataCopy = null;
254 | mAccess.mData = mData;
255 | mAccess.mSize = mData.size();
256 | return mAccess;
257 | }
258 |
259 | void end() {
260 | if (!mStart) throw new IllegalStateException("Iteration not started");
261 | mStart = false;
262 | if (mDataCopy != null) {
263 | mData = mDataCopy;
264 | mAccess.mData.clear();
265 | mAccess.mSize = 0;
266 | }
267 | mDataCopy = null;
268 | }
269 |
270 | int size() {
271 | return getArray().size();
272 | }
273 |
274 | void add(T item) {
275 | getArray().add(item);
276 | }
277 |
278 | void addAll(CopyOnWriteArray array) {
279 | getArray().addAll(array.mData);
280 | }
281 |
282 | void remove(T item) {
283 | getArray().remove(item);
284 | }
285 |
286 | void clear() {
287 | getArray().clear();
288 | }
289 | }
290 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/blur_bg_mask_gradient_shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_glide_v4_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
11 |
12 |
17 |
18 |
23 |
24 |
29 |
30 |
36 |
37 |
43 |
44 |
50 |
51 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_image_loader.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
11 |
12 |
17 |
18 |
23 |
24 |
29 |
30 |
35 |
36 |
41 |
42 |
47 |
48 |
53 |
54 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_jni_image.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
16 |
20 |
28 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_jni_image_by_net_no_jni.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
16 |
20 |
28 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_jni_image_by_sd.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
16 |
20 |
28 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_jni_image_by_sd_no_jni.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
16 |
20 |
28 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
22 |
28 |
34 |
35 |
41 |
42 |
48 |
49 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/icon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/app/src/main/res/mipmap-xxxhdpi/icon.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/test.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/app/src/main/res/mipmap-xxxhdpi/test.jpg
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ImageLoader
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/shiming/imageloader/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.shiming.imageloader;
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 | }
--------------------------------------------------------------------------------
/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 | maven {
7 | url 'https://maven.google.com/'
8 | name 'Google'
9 | }
10 | }
11 | dependencies {
12 | classpath 'com.android.tools.build:gradle:2.3.3'
13 |
14 | // NOTE: Do not place your application dependencies here; they belong
15 | // in the individual module build.gradle files
16 | }
17 | }
18 |
19 | allprojects {
20 | repositories {
21 | jcenter()
22 | maven {
23 | url 'https://maven.google.com/'
24 | name 'Google'
25 | }
26 | }
27 | }
28 |
29 | task clean(type: Delete) {
30 | delete rootProject.buildDir
31 | }
32 |
--------------------------------------------------------------------------------
/build.gradle.bak:
--------------------------------------------------------------------------------
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.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/compresspic/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/compresspic/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 15
10 | targetSdkVersion 25
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | ndk {
17 | moduleName "bitherjni"
18 | abiFilters "armeabi", "armeabi-v7a", "x86"
19 | }
20 |
21 | }
22 |
23 | buildTypes {
24 | release {
25 | minifyEnabled false
26 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
27 | }
28 | }
29 |
30 | }
31 |
32 | dependencies {
33 | compile fileTree(dir: 'libs', include: ['*.jar'])
34 | compile 'com.android.support:appcompat-v7:25.1.0'
35 | testCompile 'junit:junit:4.12'
36 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
37 | exclude group: 'com.android.support', module: 'support-annotations'
38 | })
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/compresspic/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/compresspic/src/androidTest/java/com/shiming/compresspic/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.shiming.compresspic;
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 | * Instrumented 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("com.shiming.compresspic.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/compresspic/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/compresspic/src/main/java/com/shiming/compresspic/BitmapUtil.java:
--------------------------------------------------------------------------------
1 | package com.shiming.compresspic;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.graphics.Canvas;
6 | import android.graphics.Matrix;
7 | import android.graphics.Rect;
8 | import android.media.ExifInterface;
9 |
10 | import java.io.ByteArrayOutputStream;
11 | import java.io.File;
12 | import java.io.FileInputStream;
13 | import java.io.FileNotFoundException;
14 | import java.io.IOException;
15 |
16 | /**
17 | * 图片处理工具类
18 | * Created by DDY-03 on 2017/11/17.
19 | * @version V1.0.0
20 | */
21 |
22 | public class BitmapUtil {
23 | //默认压缩率
24 | private final static int DEFAULT_QUALITY = 95;
25 |
26 | /**
27 | * JNI基本压缩
28 | * @param bit bitmap对象
29 | * @param fileName 指定保存目录名
30 | * @param optimize 是否采用哈弗曼表数据计算 品质相差5-10倍
31 | * @author XiaoSai
32 | * @since 2016年3月23日 下午6:32:49
33 | */
34 | public static String compressBitmap(Bitmap bit, String fileName, boolean optimize) {
35 | return CompressCore.saveBitmap(bit, DEFAULT_QUALITY, fileName, optimize);
36 | }
37 |
38 | /**
39 | * 通过JNI图片压缩把Bitmap保存到指定目录
40 | * @param image bitmap对象
41 | * @param filePath 要保存的指定目录
42 | * @param maxSize 最大图片大小 150KB
43 | * @author XiaoSai
44 | * @since 2016年3月23日 下午6:28:15
45 | */
46 | public static String compressBitmap(Bitmap image, String filePath, int maxSize) {
47 | // 获取尺寸压缩倍数
48 | int ratio = getRatioSize(image.getWidth(),image.getHeight());
49 | // 压缩Bitmap到对应尺寸
50 | Bitmap result = Bitmap.createBitmap(image.getWidth() / ratio,image.getHeight() / ratio, Bitmap.Config.ARGB_8888);
51 | Canvas canvas = new Canvas(result);
52 | Rect rect = new Rect(0, 0, image.getWidth() / ratio, image.getHeight() / ratio);
53 | canvas.drawBitmap(image,null,rect,null);
54 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
55 | // 质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中
56 | int options = 100;
57 | result.compress(Bitmap.CompressFormat.JPEG, options, baos);
58 | // 循环判断如果压缩后图片是否大于100kb,大于继续压缩
59 | while (baos.toByteArray().length / 1024 > maxSize) {
60 | // 重置baos即清空baos
61 | baos.reset();
62 | // 每次都减少10
63 | options -= 10;
64 | // 这里压缩options%,把压缩后的数据存放到baos中
65 | result.compress(Bitmap.CompressFormat.JPEG, options, baos);
66 | }
67 | // JNI保存图片到SD卡 这个关键
68 | String resultStr = CompressCore.saveBitmap(result, options, filePath, true);
69 | // 释放Bitmap
70 | if (!result.isRecycled()) {
71 | result.recycle();
72 | }
73 | return resultStr;
74 | }
75 |
76 | /**
77 | * 通过JNI图片压缩把Bitmap保存到指定目录
78 | * @param curFilePath 当前图片文件地址
79 | * @param targetFilePath 要保存的图片文件地址
80 | * @param maxSize 最大图片大小
81 | * @author XiaoSai
82 | * @since 2016年9月28日 下午17:43:15
83 | */
84 | public static String compressBitmap(String curFilePath, String targetFilePath, int maxSize) {
85 | //根据地址获取bitmap
86 | Bitmap result = getBitmapFromFile(curFilePath);
87 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
88 | // 质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中
89 | int quality = 100;
90 | result.compress(Bitmap.CompressFormat.JPEG, quality, baos);
91 | // 循环判断如果压缩后图片是否大于100kb,大于继续压缩
92 | while (baos.toByteArray().length / 1024 > maxSize) {
93 | // 重置baos即清空baos
94 | baos.reset();
95 | // 每次都减少10
96 | quality -= 10;
97 | // 这里压缩quality,把压缩后的数据存放到baos中
98 | result.compress(Bitmap.CompressFormat.JPEG, quality, baos);
99 | }
100 | // JNI保存图片到SD卡 这个关键
101 | String resultStr = CompressCore.saveBitmap(result, quality, targetFilePath, true);
102 | // 释放Bitmap
103 | if (!result.isRecycled()) {
104 | result.recycle();
105 | }
106 | return resultStr;
107 | }
108 |
109 | /**
110 | * 计算缩放比
111 | * @param bitWidth 当前图片宽度
112 | * @param bitHeight 当前图片高度
113 | * @return int 缩放比
114 | * @author XiaoSai
115 | * @since 2016年3月21日 下午3:03:38
116 | */
117 | private static int getRatioSize(int bitWidth, int bitHeight) {
118 | // 图片最大分辨率
119 | int imageHeight = 1280;
120 | int imageWidth = 960;
121 | // 缩放比
122 | int ratio = 1;
123 | // 缩放比,由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可
124 | if (bitWidth > bitHeight && bitWidth > imageWidth) {
125 | // 如果图片宽度比高度大,以宽度为基准
126 | ratio = bitWidth / imageWidth;
127 | } else if (bitWidth < bitHeight && bitHeight > imageHeight) {
128 | // 如果图片高度比宽度大,以高度为基准
129 | ratio = bitHeight / imageHeight;
130 | }
131 | // 最小比率为1
132 | if (ratio <= 0)
133 | ratio = 1;
134 | return ratio;
135 | }
136 |
137 | /**
138 | * 通过文件路径读获取Bitmap防止OOM以及解决图片旋转问题
139 | * @param filePath 路径
140 | * @return bitmap
141 | */
142 | private static Bitmap getBitmapFromFile(String filePath){
143 | BitmapFactory.Options newOpts = new BitmapFactory.Options();
144 | newOpts.inJustDecodeBounds = true;//只读边,不读内容
145 | BitmapFactory.decodeFile(filePath, newOpts);
146 | int w = newOpts.outWidth;
147 | int h = newOpts.outHeight;
148 | // 获取尺寸压缩倍数
149 | newOpts.inSampleSize = getRatioSize(w,h);
150 | newOpts.inJustDecodeBounds = false;//读取所有内容
151 | newOpts.inDither = false;
152 | newOpts.inPurgeable=true;
153 | newOpts.inInputShareable=true;
154 | newOpts.inTempStorage = new byte[32 * 1024];
155 | Bitmap bitmap = null;
156 | File file = new File(filePath);
157 | FileInputStream fs = null;
158 | try {
159 | fs = new FileInputStream(file);
160 | } catch (FileNotFoundException e) {
161 | e.printStackTrace();
162 | }
163 | try {
164 | if(fs!=null){
165 | bitmap = BitmapFactory.decodeFileDescriptor(fs.getFD(),null,newOpts);
166 | //旋转图片
167 | int photoDegree = readPictureDegree(filePath);
168 | if(photoDegree != 0){
169 | Matrix matrix = new Matrix();
170 | matrix.postRotate(photoDegree);
171 | // 创建新的图片
172 | bitmap = Bitmap.createBitmap(bitmap, 0, 0,
173 | bitmap.getWidth(), bitmap.getHeight(), matrix, true);
174 | }
175 | }
176 | } catch (IOException e) {
177 | e.printStackTrace();
178 | } finally{
179 | if(fs!=null) {
180 | try {
181 | fs.close();
182 | } catch (IOException e) {
183 | e.printStackTrace();
184 | }
185 | }
186 | }
187 | return bitmap;
188 | }
189 |
190 | /**
191 | * 读取图片属性:旋转的角度
192 | * @param path 图片绝对路径
193 | * @return degree旋转的角度
194 | */
195 |
196 | private static int readPictureDegree(String path) {
197 | int degree = 0;
198 | try {
199 | ExifInterface exifInterface = new ExifInterface(path);
200 | int orientation = exifInterface.getAttributeInt(
201 | ExifInterface.TAG_ORIENTATION,
202 | ExifInterface.ORIENTATION_NORMAL);
203 | switch (orientation) {
204 | case ExifInterface.ORIENTATION_ROTATE_90:
205 | degree = 90;
206 | break;
207 | case ExifInterface.ORIENTATION_ROTATE_180:
208 | degree = 180;
209 | break;
210 | case ExifInterface.ORIENTATION_ROTATE_270:
211 | degree = 270;
212 | break;
213 | }
214 | } catch (IOException e) {
215 | e.printStackTrace();
216 | }
217 | return degree;
218 | }
219 | }
220 |
--------------------------------------------------------------------------------
/compresspic/src/main/java/com/shiming/compresspic/CompressCore.java:
--------------------------------------------------------------------------------
1 | package com.shiming.compresspic;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | /**
6 | * 图片压缩
7 | * Created by DDY-03 on 2017/11/17.
8 | * @version V1.0.0
9 | */
10 |
11 | public class CompressCore {
12 |
13 | /**
14 | * 调用native方法
15 | * @param bit bitmap
16 | * @param quality 压缩率
17 | * @param fileName 文件名
18 | * @param optimize 是否启用哈希曼算法
19 | * @return result 1表示成功 其它表示失败
20 | * @author XiaoSai
21 | * @since 2016年3月23日 下午6:36:46
22 | */
23 | public static String saveBitmap(Bitmap bit, int quality, String fileName, boolean optimize) {
24 | return compressBitmap(bit, bit.getWidth(), bit.getHeight(), quality, fileName.getBytes(), optimize);
25 | }
26 |
27 | /**
28 | * 调用底层 bitherlibjni.c中的方法
29 | * @param bit bitmap
30 | * @param w 宽
31 | * @param h 高
32 | * @param quality 压缩率
33 | * @param fileNameBytes 文件名大小
34 | * @param optimize 是否启用哈希曼算法压缩
35 | * @return result 1表示成功 其它表示失败
36 | * @author XiaoSai
37 | * @since 2016年3月23日 下午6:35:53
38 | */
39 | private static native String compressBitmap(Bitmap bit, int w, int h, int quality, byte[] fileNameBytes,
40 | boolean optimize);
41 | //加载lib下两个so文件
42 | static {
43 | try {
44 | System.loadLibrary("jpegbither");
45 | System.loadLibrary("bitherjni");
46 | }catch (Exception e){
47 | e.printStackTrace();
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/compresspic/src/main/java/com/shiming/compresspic/ImageCompress.java:
--------------------------------------------------------------------------------
1 | package com.shiming.compresspic;
2 |
3 | import android.content.Context;
4 | import android.os.Handler;
5 | import android.os.Looper;
6 | import android.os.Message;
7 | import android.text.TextUtils;
8 |
9 | /**
10 | * 图片压缩
11 | *
12 | * @author XiaoSai
13 | * @version V1.0.0
14 | */
15 | public class ImageCompress implements Handler.Callback{
16 | private Builder mBuilder;
17 | private final int DEFAULT_SIZE = 150;
18 | private Handler mHandler;
19 | private static final int MSG_COMPRESS_SUCCESS = 0;
20 | private static final int MSG_COMPRESS_START = 1;
21 | private static final int MSG_COMPRESS_ERROR = 2;
22 |
23 | private ImageCompress(Builder builder) {
24 | this.mBuilder = builder;
25 | mHandler = new Handler(Looper.getMainLooper(), this);
26 | }
27 |
28 | public static Builder with(Context context){
29 | return new Builder(context);
30 | }
31 |
32 | private void launch(){
33 | if (TextUtils.isEmpty(mBuilder.filePath) && mBuilder.listener != null) {
34 | mHandler.sendMessage(mHandler.obtainMessage(MSG_COMPRESS_ERROR, new NullPointerException("image file cannot be null")));
35 | return;
36 | }
37 | if (TextUtils.isEmpty(mBuilder.targetDir) && mBuilder.listener != null) {
38 | mHandler.sendMessage(mHandler.obtainMessage(MSG_COMPRESS_ERROR, new NullPointerException("targetDir cannot be null")));
39 | return;
40 | }
41 | mHandler.sendMessage(mHandler.obtainMessage(MSG_COMPRESS_START));
42 | new Thread(new Runnable() {
43 | @Override
44 | public void run() {
45 | try {
46 | int ignoreSize = mBuilder.ignoreSize == 0?DEFAULT_SIZE:mBuilder.ignoreSize;
47 | String targetCompressPath = getImageCacheFile(checkSuffix(mBuilder.filePath));
48 | String resultStr = BitmapUtil.compressBitmap(mBuilder.filePath, targetCompressPath, ignoreSize);
49 | if("1".equals(resultStr)){
50 | mHandler.sendMessage(mHandler.obtainMessage(MSG_COMPRESS_SUCCESS, targetCompressPath));
51 | }else{
52 | // mHandler.sendMessage(mHandler.obtainMessage(MSG_COMPRESS_ERROR, new RuntimeException(resultStr)));
53 | }
54 | }catch (final Exception e){
55 | mHandler.sendMessage(mHandler.obtainMessage(MSG_COMPRESS_ERROR, e));
56 | }
57 | }
58 | }).start();
59 | }
60 |
61 | public boolean handleMessage(Message msg) {
62 | if (mBuilder.listener == null) return false;
63 | switch (msg.what) {
64 | case MSG_COMPRESS_START:
65 | mBuilder.listener.onStart();
66 | break;
67 | case MSG_COMPRESS_SUCCESS:
68 | mBuilder.listener.onSuccess(msg.obj+"");
69 | break;
70 | case MSG_COMPRESS_ERROR:
71 | mBuilder.listener.onError((Throwable) msg.obj);
72 | break;
73 | }
74 | return false;
75 | }
76 |
77 | private String checkSuffix(String path) {
78 | if (TextUtils.isEmpty(path)||!path.contains(".")) {
79 | return ".jpg";
80 | }
81 | return path.substring(path.lastIndexOf("."), path.length());
82 | }
83 |
84 | private String getImageCacheFile(String suffix) {
85 | return mBuilder.targetDir + "/" +
86 | System.currentTimeMillis() +
87 | (int) (Math.random() * 1000) +
88 | (TextUtils.isEmpty(suffix) ? ".jpg" : suffix);
89 | }
90 |
91 | public static class Builder{
92 | private Context context;
93 | private String filePath;
94 | private int ignoreSize;
95 | private String targetDir;
96 | private OnCompressListener listener;
97 |
98 | private Builder(Context context){
99 | this.context = context;
100 | }
101 |
102 | private ImageCompress build(){
103 | return new ImageCompress(this);
104 | }
105 |
106 | public Builder load(String localPath) {
107 | this.filePath = localPath;
108 | return this;
109 | }
110 |
111 | public Builder ignoreBy(int size) {
112 | this.ignoreSize = size;
113 | return this;
114 | }
115 |
116 | public Builder setTargetDir(String targetDir) {
117 | this.targetDir = targetDir;
118 | return this;
119 | }
120 |
121 | public Builder setOnCompressListener(OnCompressListener listener) {
122 | this.listener = listener;
123 | return this;
124 | }
125 |
126 | public void launch(){
127 | build().launch();
128 | }
129 | }
130 |
131 | public interface OnCompressListener{
132 | void onStart();
133 | void onSuccess(String filePath);
134 | void onError(Throwable e);
135 | }
136 | }
--------------------------------------------------------------------------------
/compresspic/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | compressPic
3 |
4 |
--------------------------------------------------------------------------------
/compresspic/src/test/java/com/shiming/compresspic/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.shiming.compresspic;
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 | }
--------------------------------------------------------------------------------
/glide4.7.1demo/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/glide4.7.1demo/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "27.0.3"
6 |
7 |
8 | defaultConfig {
9 | applicationId "code.shiming.com.glide471demo"
10 | minSdkVersion 15
11 | targetSdkVersion 26
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | }
27 |
28 | dependencies {
29 | compile fileTree(dir: 'libs', include: ['*.jar'])
30 | //noinspection GradleCompatible
31 | compile 'com.android.support:appcompat-v7:26.1.0'
32 | compile 'com.android.support.constraint:constraint-layout:1.1.0'
33 | testCompile 'junit:junit:4.12'
34 | androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.1', {
35 | exclude group: 'com.android.support', module: 'support-annotations'
36 | })
37 | compile project(':imageloader4.7.1')
38 |
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/glide4.7.1demo/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/glide4.7.1demo/src/androidTest/java/code/shiming/com/glide471demo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package code.shiming.com.glide471demo;
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 | * Instrumented 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("code.shiming.com.glide471demo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/java/code/shiming/com/glide471demo/DemoActivity.java:
--------------------------------------------------------------------------------
1 | package code.shiming.com.glide471demo;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.widget.ImageView;
6 |
7 | import com.bumptech.glide.load.resource.bitmap.CenterInside;
8 | import com.bumptech.glide.load.resource.bitmap.CircleCrop;
9 | import com.bumptech.glide.load.resource.bitmap.FitCenter;
10 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
11 |
12 | import code.shiming.com.imageloader471.GlideApp;
13 | import code.shiming.com.imageloader471.ImageLoaderV4;
14 | import code.shiming.com.imageloader471.tranform.BlurBitmapTranformation;
15 | import code.shiming.com.imageloader471.tranform.GlideCircleTransformation;
16 | import code.shiming.com.imageloader471.tranform.RoundBitmapTranformation;
17 |
18 | import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;
19 |
20 | public class DemoActivity extends AppCompatActivity {
21 |
22 | private ImageView mImageView_1;
23 | private ImageView mImageView_2;
24 | private ImageView mImageView_3;
25 | private ImageView mImageView_4;
26 | private ImageView mImageView_5;
27 | private ImageView mImageView_6;
28 | private ImageView mImageView_7;
29 | private ImageView mImageView_8;
30 |
31 | private ImageView mImageView_9;
32 | private ImageView mImageView_10;
33 | private ImageView mImageView_11;
34 | private ImageView mImageView_12;
35 | private ImageView mImageView_13;
36 | private ImageView mImageView_14;
37 | private ImageView mImageView_15;
38 | private ImageView mImageView_16;
39 | private ImageView mImageView_17;
40 | private ImageView mImageView_18;
41 | private ImageView mImageView_19;
42 | private ImageView mImageView_20;
43 |
44 | @Override
45 | protected void onCreate(Bundle savedInstanceState) {
46 | super.onCreate(savedInstanceState);
47 | setContentView(R.layout.activity_demo);
48 | findView();
49 | String url="https://upload-images.jianshu.io/upload_images/5363507-476c8bb17b124d22.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240";
50 | // //圆形图片
51 | ImageLoaderV4.getInstance().displayCircleImage(this, "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg", mImageView_1, R.mipmap.ic_launcher_round);
52 | //圆角图片
53 | ImageLoaderV4.getInstance().displayRoundImage(this, "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg", mImageView_2, R.mipmap.ic_launcher_round, 40);
54 | //模糊图片
55 | ImageLoaderV4.getInstance().displayBlurImage(this, "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg", mImageView_3, R.mipmap.ic_launcher_round, 10);
56 |
57 | //本地图片 不做处理
58 | ImageLoaderV4.getInstance().displayImageInResource(this, R.mipmap.test, mImageView_4);
59 | // TODO: 2018/4/20 以下的三种不介意使用,需要解决一些问题 start
60 | //本地图片,模糊处理
61 | ImageLoaderV4.getInstance().displayImageInResource(this, R.mipmap.test, mImageView_5, new BlurBitmapTranformation( 200));
62 | //本地图片,裁圆角处理
63 | ImageLoaderV4.getInstance().displayImageInResource(this, R.mipmap.test, mImageView_6, new GlideCircleTransformation());
64 | //四周倒角处理
65 | ImageLoaderV4.getInstance().displayImageInResource(this, R.mipmap.test, mImageView_7, new RoundBitmapTranformation( 40));
66 | // TODO: 2018/4/20 以上的三种不介意使用,需要解决一些问题 start
67 |
68 |
69 | //使用的是另外一种方法,指定传入的那种的方法 ,还可以不断的扩展,不断的扩展,这是Gilded提供的一些操作,牛逼 ,牛逼 这是对本地图片的操作
70 | ImageLoaderV4.getInstance().displayImageInResourceTransform(this, R.mipmap.test, mImageView_8, new CenterInside(), R.mipmap.test);
71 | ImageLoaderV4.getInstance().displayImageInResourceTransform(this, R.mipmap.test, mImageView_9, new CircleCrop(), R.mipmap.test);
72 | ImageLoaderV4.getInstance().displayImageInResourceTransform(this, R.mipmap.test, mImageView_10, new FitCenter(), R.mipmap.test);
73 | ImageLoaderV4.getInstance().displayImageInResourceTransform(this, R.mipmap.test, mImageView_11, new RoundedCorners(10), R.mipmap.test);
74 |
75 | //对网络图片的操作
76 | ImageLoaderV4.getInstance().displayImageByNet(this,url,mImageView_12, R.mipmap.test,new CenterInside());
77 | ImageLoaderV4.getInstance().displayImageByNet(this,url,mImageView_13, R.mipmap.test,new CircleCrop());
78 | ImageLoaderV4.getInstance().displayImageByNet(this,url,mImageView_14, R.mipmap.test,new FitCenter());
79 | ImageLoaderV4.getInstance().displayImageByNet(this,url,mImageView_15, R.mipmap.test,new RoundedCorners(10));
80 |
81 |
82 | }
83 |
84 | private void findView() {
85 | mImageView_1 = (ImageView) findViewById(R.id.image_view_1);
86 | mImageView_2 = (ImageView) findViewById(R.id.image_view_2);
87 | mImageView_3 = (ImageView) findViewById(R.id.image_view_3);
88 | mImageView_4 = (ImageView) findViewById(R.id.image_view_4);
89 | mImageView_5 = (ImageView) findViewById(R.id.image_view_5);
90 | mImageView_6 = (ImageView) findViewById(R.id.image_view_6);
91 | mImageView_7 = (ImageView) findViewById(R.id.image_view_7);
92 | mImageView_8 = (ImageView) findViewById(R.id.image_view_8);
93 | mImageView_9 = (ImageView) findViewById(R.id.image_view_9);
94 | mImageView_10 = (ImageView) findViewById(R.id.image_view_10);
95 | mImageView_11 = (ImageView) findViewById(R.id.image_view_11);
96 | mImageView_12 = (ImageView) findViewById(R.id.image_view_12);
97 | mImageView_13 = (ImageView) findViewById(R.id.image_view_13);
98 | mImageView_14 = (ImageView) findViewById(R.id.image_view_14);
99 | mImageView_15 = (ImageView) findViewById(R.id.image_view_15);
100 | mImageView_16 = (ImageView) findViewById(R.id.image_view_16);
101 | mImageView_17 = (ImageView) findViewById(R.id.image_view_17);
102 | mImageView_18 = (ImageView) findViewById(R.id.image_view_18);
103 | mImageView_19 = (ImageView) findViewById(R.id.image_view_19);
104 | mImageView_20 = (ImageView) findViewById(R.id.image_view_20);
105 |
106 |
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/java/code/shiming/com/glide471demo/ImageProgressActivity.java:
--------------------------------------------------------------------------------
1 | package code.shiming.com.glide471demo;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.widget.ImageView;
6 | import android.widget.TextView;
7 |
8 | import com.bumptech.glide.load.engine.GlideException;
9 |
10 | import code.shiming.com.imageloader471.ImageLoaderV4;
11 | import code.shiming.com.imageloader471.okhttp.OnGlideImageViewListener;
12 | import code.shiming.com.imageloader471.okhttp.OnProgressListener;
13 |
14 | public class ImageProgressActivity extends AppCompatActivity {
15 | private ImageView mImageView_8;
16 | private TextView mProgress;
17 |
18 | private ImageView mImageView_7;
19 | private TextView mProgress7;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_image_progress);
25 |
26 | mImageView_8 = (ImageView) findViewById(R.id.image_view_8);
27 |
28 | mProgress = findViewById(R.id.tv_progress);
29 | mImageView_7 = (ImageView) findViewById(R.id.image_view_7);
30 | mProgress7 = findViewById(R.id.tv_progress_7);
31 |
32 |
33 | ImageLoaderV4.getInstance().disPlayImageProgress(this, "http://img.zcool.cn/community/0142135541fe180000019ae9b8cf86.jpg@1280w_1l_2o_100sh.png", mImageView_8, R.mipmap.test, R.mipmap.test, new OnGlideImageViewListener() {
34 | @Override
35 | public void onProgress(int percent, boolean isDone, GlideException exception) {
36 | System.out.println("shiming percent="+percent);
37 | System.out.println("shiming isDone="+isDone);
38 | mProgress.setText("我在主线程,进度是多少=="+percent+"%");
39 |
40 | if (isDone){
41 | mProgress.setText("我在主线程,进度是多少==100%");
42 | }
43 | }
44 | });
45 |
46 |
47 | ImageLoaderV4.getInstance().disPlayImageProgressByOnProgressListener(this, "http://img.zcool.cn/community/0142135541fe180000019ae9b8cf86.jpg@1280w_1l_2o_100sh.png", mImageView_7, R.mipmap.test, R.mipmap.test, new OnProgressListener() {
48 | @Override
49 | public void onProgress(String imageUrl, long bytesRead, long totalBytes, boolean isDone, GlideException exception) {
50 | System.out.println("shiming bytesRead="+bytesRead);
51 | System.out.println("shiming totalBytes="+totalBytes);
52 | mProgress7.setText("我在主线程,进度是多少==+bytesRead"+bytesRead+"totalBytes="+totalBytes);
53 |
54 | if (isDone){
55 | mProgress7.setText("我在主线程,进度是多少==100%");
56 | }
57 | }
58 | });
59 | }
60 |
61 | @Override
62 | public void onBackPressed() {
63 |
64 | // ImageLoaderV4.getInstance().glidePauseRequests(this);
65 | super.onBackPressed();
66 | }
67 |
68 | @Override
69 | protected void onPause() {
70 | ImageLoaderV4.getInstance().clear(this,mImageView_7);
71 | ImageLoaderV4.getInstance().clear(this,mImageView_8);
72 | ImageLoaderV4.getInstance().glidePauseRequests(this);
73 | super.onPause();
74 | }
75 |
76 | @Override
77 | protected void onResume() {
78 | // ImageLoaderV4.getInstance().clear(this,mImageView_7);
79 | // ImageLoaderV4.getInstance().clear(this,mImageView_8);
80 | // ImageLoaderV4.getInstance().glideResumeRequests(this);
81 | super.onResume();
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/java/code/shiming/com/glide471demo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package code.shiming.com.glide471demo;
2 |
3 | import android.content.Intent;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.ImageView;
8 |
9 | import code.shiming.com.imageloader471.GlideApp;
10 |
11 | import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;
12 |
13 | public class MainActivity extends AppCompatActivity {
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_main);
19 | findViewById(R.id.btn_click_me).setOnClickListener(new View.OnClickListener() {
20 | @Override
21 | public void onClick(View v) {
22 | startActivity(new Intent(MainActivity.this,DemoActivity.class));
23 | }
24 | });
25 | findViewById(R.id.btn_click_me_2).setOnClickListener(new View.OnClickListener() {
26 | @Override
27 | public void onClick(View v) {
28 | startActivity(new Intent(MainActivity.this,TransitionOptionsActivity.class));
29 | }
30 | });
31 | findViewById(R.id.btn_click_me_3).setOnClickListener(new View.OnClickListener() {
32 | @Override
33 | public void onClick(View v) {
34 | startActivity(new Intent(MainActivity.this,ImageProgressActivity.class));
35 | }
36 | });
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/java/code/shiming/com/glide471demo/TransitionOptionsActivity.java:
--------------------------------------------------------------------------------
1 | package code.shiming.com.glide471demo;
2 |
3 | import android.graphics.Bitmap;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.widget.ImageView;
7 | import android.widget.TextView;
8 |
9 | import com.bumptech.glide.GenericTransitionOptions;
10 | import com.bumptech.glide.Glide;
11 | import com.bumptech.glide.load.engine.DiskCacheStrategy;
12 | import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions;
13 | import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
14 |
15 | import code.shiming.com.imageloader471.GlideApp;
16 | import code.shiming.com.imageloader471.ImageLoaderV4;
17 | import code.shiming.com.imageloader471.tranform.BlurBitmapTranformation;
18 |
19 | import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;
20 |
21 | public class TransitionOptionsActivity extends AppCompatActivity {
22 | private ImageView mImageView_1;
23 | private ImageView mImageView_2;
24 | private ImageView mImageView_3;
25 | private ImageView mImageView_4;
26 | private ImageView mImageView_5;
27 | private ImageView mImageView_6;
28 | private ImageView mImageView_7;
29 | private ImageView mImageView_8;
30 |
31 | private ImageView mImageView_9;
32 | private ImageView mImageView_10;
33 | private TextView mProgress;
34 |
35 | @Override
36 | protected void onCreate(Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 | setContentView(R.layout.activity_transition_options);
39 | findView();
40 |
41 | String url="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1243170106,2389135470&fm=27&gp=0.jpg";
42 | String ur11="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1524215494107&di=d7649711ff443126d049915204cc2415&imgtype=0&src=http%3A%2F%2Fhimg2.huanqiu.com%2Fattachment2010%2F2017%2F0303%2F20170303101721677.jpg";
43 |
44 |
45 | GlideApp.with(this)
46 | .load(ur11)
47 | .transition(withCrossFade())
48 | .into(mImageView_1);
49 |
50 | GlideApp.with(this)
51 | .load(ur11)
52 | .transition(DrawableTransitionOptions.withCrossFade())
53 | .into(mImageView_6);
54 | /**
55 | * 过渡选项
56 | TransitionOptions 用于决定你的加载完成时会发生什么。
57 | 使用 TransitionOption 可以应用以下变换:
58 | View淡入
59 | 与占位符交叉淡入
60 | 或者什么都不发生
61 | 从白色 慢慢变透明 5s的间隔
62 | */
63 | GlideApp.with(this)
64 | .load(ur11)
65 | .transition(withCrossFade(5000))
66 | .into(mImageView_7);
67 | /**
68 | * 加载缩略图 (Thumbnail) 请求
69 | * 只要你的 thumbnailUrl 指向的图片比你的主 url 的分辨率更低,它将会很好地工作
70 | */
71 | GlideApp.with(this)
72 | .load(url)
73 | .thumbnail(Glide.with(this)
74 | .load(ur11))
75 | .into(mImageView_3);
76 |
77 | //如果你仅仅想加载一个本地图像,或者你只有一个单独的远程 URL, 你仍然可以从缩略图 API 受益。
78 | // API 对本地和远程图片都适用,尤其是当低分辨率缩略图存在于 Glide 的磁盘缓存时,它们将很快被加载出来
79 | //
80 | String urlnoData="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1524215871555&di=fcd8f0e14b57279d697ab7078ac36a88&imgtype=0&src=http%3A%2F%2Fimg5.duitang.com%2Fuploads%2Fitem%2F201610%2F11%2F20161011180349_tzeQC.jpeg";
81 | int thumbnailSize = 10;//越小,图片越小,低网络的情况,图片越小
82 | GlideApp.with(this)
83 | .load(urlnoData)
84 | .diskCacheStrategy(DiskCacheStrategy.NONE)//为了测试不缓存
85 | .thumbnail(GlideApp.with(this)
86 | .load(urlnoData)
87 | .override(thumbnailSize))// API 来强制 Glide 在缩略图请求中加载一个低分辨率图像
88 | .into(mImageView_4);
89 | /**
90 | * thumbnail 方法有一个简化版本,它只需要一个 sizeMultiplier 参数。
91 | * 如果你只是想为你的加载相同的图片,但尺寸为 View 或 Target 的某个百分比的话特别有用:
92 | */
93 | GlideApp.with(this)
94 | .load(urlnoData)
95 | .thumbnail(/*sizeMultiplier=*/ 0.25f)
96 | .into(mImageView_5);
97 | //以在主请求失败时开始一次新的加载。例如,在请求 primaryUrl 失败后加载 fallbackUrl:
98 | // Glide.with(this)
99 | // .load(primaryUrl)
100 | // .error(Glide.with(fragment)
101 | // .load(fallbackUrl))
102 | // .into(imageView);
103 |
104 | // GlideApp.with(this)
105 | // .load(url)
106 | // .apply(option(MyCustomModelLoader.TIMEOUT_MS, 1000L))
107 | // .into(mImageView_6);
108 | //
109 | // RequestOptions options = new RequestOptions()
110 | // .set(MyCustomModelLoader.TIMEOUT_MS, 1000L);
111 |
112 | // Glide.with(this)
113 | // .applyDefaultRequestOptions(
114 | // new RequestOptions()
115 | // .format(DecodeFormat.PREFER_ARGB_8888)
116 | // .disallowHardwareBitmaps());
117 |
118 | ImageLoaderV4.getInstance().displayImageInResource(this, R.mipmap.test, mImageView_1, new BlurBitmapTranformation( 200));
119 |
120 | GlideApp.with(this).load( R.mipmap.test).disallowHardwareConfig().diskCacheStrategy(DiskCacheStrategy.NONE).transform(new BlurBitmapTranformation( 200)).into(mImageView_2);
121 |
122 |
123 |
124 | GlideApp.with(this)
125 | .asBitmap()
126 | .load(ur11)
127 | .transition(BitmapTransitionOptions.withCrossFade())
128 | .into(mImageView_9);
129 |
130 | GlideApp.with(this)
131 | .asBitmap()
132 | .load(ur11)
133 | .transition(GenericTransitionOptions.withNoTransition())
134 | .into(mImageView_10);
135 | }
136 |
137 | private void findView() {
138 | mImageView_1 = (ImageView) findViewById(R.id.image_view_1);
139 | mImageView_2 = (ImageView) findViewById(R.id.image_view_2);
140 | mImageView_3 = (ImageView) findViewById(R.id.image_view_3);
141 | mImageView_4 = (ImageView) findViewById(R.id.image_view_4);
142 | mImageView_5 = (ImageView) findViewById(R.id.image_view_5);
143 | mImageView_6 = (ImageView) findViewById(R.id.image_view_6);
144 | mImageView_7 = (ImageView) findViewById(R.id.image_view_7);
145 | mImageView_8 = (ImageView) findViewById(R.id.image_view_8);
146 | mImageView_9 = (ImageView) findViewById(R.id.image_view_9);
147 | mImageView_10 = (ImageView) findViewById(R.id.image_view_10);
148 |
149 | mProgress = findViewById(R.id.tv_progress);
150 |
151 |
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/layout/activity_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
11 |
12 |
17 |
18 |
23 |
24 |
29 |
30 |
36 |
37 |
43 |
44 |
50 |
51 |
57 |
58 |
63 |
69 |
75 |
81 |
87 |
88 |
93 |
99 |
105 |
111 |
117 |
123 |
129 |
135 |
136 |
142 |
148 |
149 |
150 |
151 |
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/layout/activity_image_progress.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
13 |
17 |
21 |
22 |
27 |
31 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
15 |
16 |
21 |
26 |
27 |
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/layout/activity_transition_options.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
11 |
16 |
21 |
22 |
27 |
28 |
33 |
34 |
40 |
41 |
47 |
48 |
54 |
55 |
61 |
62 |
67 |
71 |
75 |
76 |
77 |
83 |
89 |
95 |
96 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/glide4.7.1demo/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/glide4.7.1demo/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/glide4.7.1demo/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/glide4.7.1demo/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/glide4.7.1demo/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/glide4.7.1demo/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/glide4.7.1demo/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/glide4.7.1demo/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/glide4.7.1demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/glide4.7.1demo/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/mipmap-xxxhdpi/icon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/glide4.7.1demo/src/main/res/mipmap-xxxhdpi/icon.jpg
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/mipmap-xxxhdpi/test.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/glide4.7.1demo/src/main/res/mipmap-xxxhdpi/test.jpg
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Glide4.7.1Demo
3 |
4 |
--------------------------------------------------------------------------------
/glide4.7.1demo/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/glide4.7.1demo/src/test/java/code/shiming/com/glide471demo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package code.shiming.com.glide471demo;
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 | }
--------------------------------------------------------------------------------
/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 | android.useDeprecatedNdk=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shimingli/ImageLoader/0805ba9384d2836e6c5a6af2bafa431d6e8b01dc/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Jul 30 14:52:29 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-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties.bak:
--------------------------------------------------------------------------------
1 | #Sun Jul 30 14:52:29 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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/imageloader4.7.1/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/imageloader4.7.1/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 27
5 | buildToolsVersion "25.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 27
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 |
24 | }
25 |
26 | dependencies {
27 | compile fileTree(dir: 'libs', include: ['*.jar'])
28 | //noinspection GradleCompatible
29 | compile 'com.android.support:appcompat-v7:27.0.0'
30 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
31 | testCompile 'junit:junit:4.12'
32 | androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.1', {
33 | exclude group: 'com.android.support', module: 'support-annotations'
34 | })
35 |
36 | compile 'com.github.bumptech.glide:glide:4.7.1'
37 | annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
38 |
39 | compile "com.github.bumptech.glide:okhttp3-integration:4.5.0"
40 | }
41 |
--------------------------------------------------------------------------------
/imageloader4.7.1/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
23 | -keep public class * implements com.bumptech.glide.module.GlideModule
24 | -keep public class * extends com.bumptech.glide.AppGlideModule
25 | -keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
26 | **[] $VALUES;
27 | public *;
28 | }
--------------------------------------------------------------------------------
/imageloader4.7.1/src/androidTest/java/code/shiming/com/imageloader471/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package code.shiming.com.imageloader471;
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 | * Instrumented 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("code.shiming.com.imageloader471.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/imageloader4.7.1/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/imageloader4.7.1/src/main/java/code/shiming/com/imageloader471/AppGlideModuleProgress.java:
--------------------------------------------------------------------------------
1 | package code.shiming.com.imageloader471;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.NonNull;
5 |
6 | import com.bumptech.glide.Glide;
7 | import com.bumptech.glide.GlideBuilder;
8 | import com.bumptech.glide.Registry;
9 | import com.bumptech.glide.annotation.GlideModule;
10 | import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader;
11 | import com.bumptech.glide.load.model.GlideUrl;
12 | import com.bumptech.glide.module.AppGlideModule;
13 |
14 | import java.io.InputStream;
15 |
16 | import code.shiming.com.imageloader471.okhttp.ProgressManager;
17 |
18 |
19 | @GlideModule
20 | public class AppGlideModuleProgress extends AppGlideModule {
21 | /**
22 | OkHttp 是一个底层网络库(相较于 Cronet 或 Volley 而言),尽管它也包含了 SPDY 的支持。
23 | OkHttp 与 Glide 一起使用可以提供可靠的性能,并且在加载图片时通常比 Volley 产生的垃圾要少。
24 | 对于那些想要使用比 Android 提供的 HttpUrlConnection 更 nice 的 API,
25 | 或者想确保网络层代码不依赖于 app 安装的设备上 Android OS 版本的应用,OkHttp 是一个合理的选择。
26 | 如果你已经在 app 中某个地方使用了 OkHttp ,这也是选择继续为 Glide 使用 OkHttp 的一个很好的理由,就像选择其他网络库一样。
27 | 添加 OkHttp 集成库的 Gradle 依赖将使 Glide 自动开始使用 OkHttp 来加载所有来自 http 和 https URL 的图片
28 | * @param context
29 | * @param glide
30 | * @param registry
31 | */
32 | @Override
33 | public void registerComponents(Context context, Glide glide, Registry registry) {
34 | super.registerComponents(context, glide, registry);
35 | registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(ProgressManager.getOkHttpClient()));
36 | }
37 |
38 | /**
39 | * 默认情况下,Glide使用 LruResourceCache ,
40 | * 这是 MemoryCache 接口的一个缺省实现,使用固定大小的内存和 LRU 算法。
41 | * LruResourceCache 的大小由 Glide 的 MemorySizeCalculator 类来决定,这个类主要关注设备的内存类型,
42 | * 设备 RAM 大小,以及屏幕分辨率。应用程序可以自定义 MemoryCache 的大小,
43 | * 具体是在它们的 AppGlideModule 中使用applyOptions(Context, GlideBuilder) 方法配置 MemorySizeCalculator
44 | *
45 | * 建议使用glide 默认的情况
46 | * @param context
47 | * @param builder
48 | */
49 |
50 | //Glide会自动合理分配内存缓存,但是也可以自己手动分配。
51 | // @Override
52 | // public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
53 | // super.applyOptions(context, builder);
54 | // //1、setMemoryCacheScreens设置MemoryCache应该能够容纳的像素值的设备屏幕数,
55 | // // 说白了就是缓存多少屏图片,默认值是2。
56 | // //todo 建议不要设置,使用glide 默认
57 | //// MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context)
58 | //// .setMemoryCacheScreens(2)
59 | //// .build();
60 | //// builder.setMemoryCache(new LruResourceCache(calculator.getMemoryCacheSize()));
61 | //
62 | // //2。也可以直接覆写缓存大小:todo 建议不要设置,使用glide 默认
63 | //// int memoryCacheSizeBytes = 1024 * 1024 * 20; // 20mb
64 | //// builder.setMemoryCache(new LruResourceCache(memoryCacheSizeBytes));
65 | //// 3.甚至可以提供自己的 MemoryCache 实现:
66 | //// builder.setMemoryCache(new YourAppMemoryCacheImpl());
67 | // }
68 | //
69 |
70 | /**
71 | * Bitmap 池
72 | Glide 使用 LruBitmapPool 作为默认的 BitmapPool 。
73 | LruBitmapPool 是一个内存中的固定大小的 BitmapPool,使用 LRU 算法清理。
74 | 默认大小基于设备的分辨率和密度,同时也考虑内存类和 isLowRamDevice 的返回值。
75 | 具体的计算通过 Glide 的 MemorySizeCalculator 来完成,与 Glide 的 MemoryCache 的大小检测方法相似。
76 | * @param context
77 | * @param builder
78 | */
79 | // @Override
80 | // public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
81 | // super.applyOptions(context, builder);
82 | // //1 .应用可以在它们的 AppGlideModule 中定制 [BitmapPool] 的尺寸,
83 | // // 使用 applyOptions(Context, GlideBuilder) 方法并配置 MemorySizeCalculator
84 | //// MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context)
85 | //// .setBitmapPoolScreens(3)
86 | //// .build();
87 | //// builder.setBitmapPool(new LruBitmapPool(calculator.getBitmapPoolSize()));
88 | //
89 | // //2、应用也可以直接复写这个池的大小:
90 | //
91 | //// int bitmapPoolSizeBytes = 1024 * 1024 * 30; // 30mb
92 | //// builder.setBitmapPool(new LruBitmapPool(bitmapPoolSizeBytes));
93 | //
94 | //
95 | // //3、甚至可以提供 BitmapPool 的完全自定义实现:
96 | //
97 | //// builder.setBitmapPool(new YourAppBitmapPoolImpl());
98 | // }
99 |
100 | /**
101 | * 磁盘缓存
102 | Glide 使用 DiskLruCacheWrapper 作为默认的 磁盘缓存 。
103 | DiskLruCacheWrapper 是一个使用 LRU 算法的固定大小的磁盘缓存。默认磁盘大小为 250 MB ,
104 | 位置是在应用的 缓存文件夹 中的一个 特定目录 。
105 |
106 | * @param context
107 | * @param builder
108 | */
109 | @Override
110 | public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
111 | super.applyOptions(context, builder);
112 | //假如应用程序展示的媒体内容是公开的(从无授权机制的网站上加载,或搜索引擎等),
113 | //那么应用可以将这个缓存位置改到外部存储:
114 | // builder.setDiskCache(new ExternalDiskCacheFactory(context));
115 |
116 |
117 | //2、无论使用内部或外部磁盘缓存,应用程序都可以改变磁盘缓存的大小:
118 | // int diskCacheSizeBytes = 1024 *1024 *100; //100 MB
119 | // builder.setDiskCache(new InternalDiskCacheFactory(context, diskCacheSizeBytes));
120 |
121 |
122 | //3、应用程序还可以改变缓存文件夹在外存或内存上的名字:
123 | // int diskCacheSizeBytes = 1024 * 1024 *100; // 100 MB
124 | // builder.setDiskCache(new InternalDiskCacheFactory(context, cacheFolderName, diskCacheSizeBytes));
125 |
126 |
127 | //4、应用程序还可以自行选择 DiskCache 接口的实现,并提供自己的 DiskCache.Factory 来创建缓存。
128 | // Glide 使用一个工厂接口来在后台线程中打开 磁盘缓存 ,
129 | // 这样方便缓存做诸如检查路径存在性等的IO操作而不用触发 严格模式 。
130 | // builder.setDiskCache(new DiskCache.Factory() {
131 | // @Override
132 | // public DiskCache build() {
133 | // return new YourAppCustomDiskCache();
134 | // }
135 | // });
136 |
137 | }
138 |
139 | /**
140 | * 为了维持对 Glide v3 的 GlideModules 的向后兼容性,
141 | * Glide 仍然会解析应用程序和所有被包含的库中的 AndroidManifest.xml 文件,
142 | * 并包含在这些清单中列出的旧 GlideModules 模块类。
143 | 如果你已经迁移到 Glide v4 的 AppGlideModule 和 LibraryGlideModule ,你可以完全禁用清单解析。
144 | 这样可以改善 Glide 的初始启动时间,并避免尝试解析元数据时的一些潜在问题。要禁用清单解析,
145 | 请在你的 AppGlideModule 实现中复写 isManifestParsingEnabled() 方法:
146 | * @return
147 | */
148 | @Override
149 | public boolean isManifestParsingEnabled() {
150 | return false;
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/imageloader4.7.1/src/main/java/code/shiming/com/imageloader471/ExternalDiskCacheFactory.java:
--------------------------------------------------------------------------------
1 | package code.shiming.com.imageloader471;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.Nullable;
5 |
6 | import com.bumptech.glide.load.engine.cache.DiskCache;
7 |
8 | /**
9 | * author: Created by shiming on 2018/4/20 15:13
10 | * mailbox:lamshiming@sina.com
11 | 磁盘缓存
12 | Glide 使用 DiskLruCacheWrapper 作为默认的 磁盘缓存 。
13 | DiskLruCacheWrapper 是一个使用 LRU 算法的固定大小的磁盘缓存。默认磁盘大小为 250 MB ,
14 | 位置是在应用的 缓存文件夹 中的一个 特定目录 。
15 | 假如应用程序展示的媒体内容是公开的(从无授权机制的网站上加载,或搜索引擎等),
16 | 那么应用可以将这个缓存位置改到外部存储:
17 | */
18 |
19 | class ExternalDiskCacheFactory implements DiskCache.Factory {
20 | public ExternalDiskCacheFactory(Context context) {
21 | }
22 |
23 | @Nullable
24 | @Override
25 | public DiskCache build() {
26 | return null;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/imageloader4.7.1/src/main/java/code/shiming/com/imageloader471/listener/IGetBitmapListener.java:
--------------------------------------------------------------------------------
1 | package code.shiming.com.imageloader471.listener;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | /**
6 | * Created by shiming on 2016/10/26.
7 | */
8 |
9 | public interface IGetBitmapListener {
10 | void onBitmap(Bitmap bitmap);
11 | }
12 |
--------------------------------------------------------------------------------
/imageloader4.7.1/src/main/java/code/shiming/com/imageloader471/listener/IGetDrawableListener.java:
--------------------------------------------------------------------------------
1 | package code.shiming.com.imageloader471.listener;
2 |
3 | import android.graphics.drawable.Drawable;
4 |
5 | /**
6 | * Created by shiming on 2016/10/26.
7 | * 设置此皆苦是为了业务需要,一般不需要关心网络请求回来的drawable,但是业务需要切换的地方的话,需要拿到网络请求回来的drawable
8 | */
9 |
10 | public interface IGetDrawableListener {
11 | void onDrawable(Drawable drawable);
12 | }
13 |
--------------------------------------------------------------------------------
/imageloader4.7.1/src/main/java/code/shiming/com/imageloader471/listener/IImageLoaderListener.java:
--------------------------------------------------------------------------------
1 | package code.shiming.com.imageloader471.listener;
2 |
3 | import android.widget.ImageView;
4 |
5 | /**
6 | * Created by shiming on 2016/10/26.
7 | * 监听图片下载进度
8 | */
9 | public interface IImageLoaderListener {
10 |
11 | //监听图片下载错误
12 | void onLoadingFailed(String url, ImageView target, Exception exception);
13 | //监听图片加载成功
14 | void onLoadingComplete(String url, ImageView target);
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/imageloader4.7.1/src/main/java/code/shiming/com/imageloader471/listener/ImageSize.java:
--------------------------------------------------------------------------------
1 | package code.shiming.com.imageloader471.listener;
2 |
3 | /**
4 | * Created by shiming on 2016/10/26.
5 | */
6 |
7 | public final class ImageSize {
8 | private final static String SEPARATOR = "x";
9 |
10 | private final int width;
11 | private final int height;
12 |
13 | public ImageSize(int width, int height) {
14 | this.width = width;
15 | this.height = height;
16 | }
17 |
18 | public int getWidth() {
19 | return width;
20 | }
21 |
22 | public int getHeight() {
23 | return height;
24 | }
25 |
26 | @Override
27 | public String toString() {
28 | return new StringBuilder().append(width).append(SEPARATOR).append(height).toString();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/imageloader4.7.1/src/main/java/code/shiming/com/imageloader471/okhttp/OnGlideImageViewListener.java:
--------------------------------------------------------------------------------
1 | package code.shiming.com.imageloader471.okhttp;
2 |
3 | import com.bumptech.glide.load.engine.GlideException;
4 |
5 |
6 | public interface OnGlideImageViewListener {
7 | /**
8 | *
9 | * @param percent 下载进度的百分比,不关心,大小
10 | * @param isDone 是否完成
11 | * @param exception 异常
12 | */
13 | void onProgress(int percent, boolean isDone, GlideException exception);
14 | }
15 |
--------------------------------------------------------------------------------
/imageloader4.7.1/src/main/java/code/shiming/com/imageloader471/okhttp/OnProgressListener.java:
--------------------------------------------------------------------------------
1 | package code.shiming.com.imageloader471.okhttp;
2 |
3 | import com.bumptech.glide.load.engine.GlideException;
4 |
5 |
6 | public interface OnProgressListener {
7 | /**
8 | *
9 | * @param imageUrl 图片地址
10 | * @param bytesRead 下载了多少字节
11 | * @param totalBytes 总共的大小
12 | * @param isDone 是否完成
13 | * @param exception 异常
14 | */
15 | void onProgress(String imageUrl, long bytesRead, long totalBytes, boolean isDone, GlideException exception);
16 | }
17 |
--------------------------------------------------------------------------------
/imageloader4.7.1/src/main/java/code/shiming/com/imageloader471/okhttp/ProgressManager.java:
--------------------------------------------------------------------------------
1 | package code.shiming.com.imageloader471.okhttp;
2 |
3 | import android.support.annotation.NonNull;
4 |
5 | import com.bumptech.glide.load.engine.GlideException;
6 |
7 | import java.io.IOException;
8 | import java.lang.ref.WeakReference;
9 | import java.util.ArrayList;
10 | import java.util.Collections;
11 | import java.util.List;
12 |
13 |
14 | import okhttp3.Interceptor;
15 | import okhttp3.OkHttpClient;
16 | import okhttp3.Request;
17 | import okhttp3.Response;
18 |
19 |
20 | public class ProgressManager {
21 |
22 | private static List> listeners = Collections.synchronizedList(new ArrayList>());
23 | private static OkHttpClient okHttpClient;
24 |
25 | private ProgressManager() {
26 | }
27 |
28 | public static OkHttpClient getOkHttpClient() {
29 | if (okHttpClient == null) {
30 | okHttpClient = new OkHttpClient.Builder()
31 | .addNetworkInterceptor(new Interceptor() {
32 | @Override
33 | public Response intercept(@NonNull Chain chain) throws IOException {
34 | Request request = chain.request();
35 | Response response = chain.proceed(request);
36 | return response.newBuilder()
37 | .body(new ProgressResponseBody(request.url().toString(), response.body(), LISTENER))
38 | .build();
39 | }
40 | })
41 | .build();
42 | }
43 | return okHttpClient;
44 | }
45 |
46 | private static final OnProgressListener LISTENER = new OnProgressListener() {
47 | @Override
48 | public void onProgress(String imageUrl, long bytesRead, long totalBytes, boolean isDone, GlideException exception) {
49 | if (listeners == null || listeners.size() == 0) return;
50 |
51 | for (int i = 0; i < listeners.size(); i++) {
52 | WeakReference listener = listeners.get(i);
53 | OnProgressListener progressListener = listener.get();
54 | if (progressListener == null) {
55 | listeners.remove(i);
56 | } else {
57 | progressListener.onProgress(imageUrl, bytesRead, totalBytes, isDone, exception);
58 | }
59 | }
60 | }
61 | };
62 |
63 | public static void addProgressListener(OnProgressListener progressListener) {
64 | if (progressListener == null) return;
65 |
66 | if (findProgressListener(progressListener) == null) {
67 | listeners.add(new WeakReference<>(progressListener));
68 | }
69 | }
70 |
71 | public static void removeProgressListener(OnProgressListener progressListener) {
72 | if (progressListener == null) return;
73 |
74 | WeakReference listener = findProgressListener(progressListener);
75 | if (listener != null) {
76 | listeners.remove(listener);
77 | }
78 | }
79 |
80 | private static WeakReference findProgressListener(OnProgressListener listener) {
81 | if (listener == null) return null;
82 | if (listeners == null || listeners.size() == 0) return null;
83 |
84 | for (int i = 0; i < listeners.size(); i++) {
85 | WeakReference progressListener = listeners.get(i);
86 | if (progressListener.get() == listener) {
87 | return progressListener;
88 | }
89 | }
90 | return null;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/imageloader4.7.1/src/main/java/code/shiming/com/imageloader471/okhttp/ProgressResponseBody.java:
--------------------------------------------------------------------------------
1 | package code.shiming.com.imageloader471.okhttp;
2 |
3 | import android.support.annotation.NonNull;
4 |
5 | import java.io.IOException;
6 |
7 | import okhttp3.MediaType;
8 | import okhttp3.ResponseBody;
9 | import okio.Buffer;
10 | import okio.BufferedSource;
11 | import okio.ForwardingSource;
12 | import okio.Okio;
13 | import okio.Source;
14 |
15 |
16 | public class ProgressResponseBody extends ResponseBody {
17 |
18 | private String imageUrl;
19 | private ResponseBody responseBody;
20 | private OnProgressListener progressListener;
21 | private BufferedSource bufferedSource;
22 |
23 | public ProgressResponseBody(String url, ResponseBody responseBody, OnProgressListener progressListener) {
24 | this.imageUrl = url;
25 | this.responseBody = responseBody;
26 | this.progressListener = progressListener;
27 | }
28 |
29 | @Override
30 | public MediaType contentType() {
31 | return responseBody.contentType();
32 | }
33 |
34 | @Override
35 | public long contentLength() {
36 | return responseBody.contentLength();
37 | }
38 |
39 | @Override
40 | public BufferedSource source() {
41 | if (bufferedSource == null) {
42 | bufferedSource = Okio.buffer(source(responseBody.source()));
43 | }
44 | return bufferedSource;
45 | }
46 |
47 | private Source source(Source source) {
48 | return new ForwardingSource(source) {
49 | long totalBytesRead = 0;
50 |
51 | @Override
52 | public long read(@NonNull Buffer sink, long byteCount) throws IOException {
53 | long bytesRead = super.read(sink, byteCount);
54 | totalBytesRead += (bytesRead == -1) ? 0 : bytesRead;
55 |
56 | if (progressListener != null) {
57 | progressListener.onProgress(imageUrl, totalBytesRead, contentLength(), (bytesRead == -1), null);
58 | }
59 | return bytesRead;
60 | }
61 | };
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/imageloader4.7.1/src/main/java/code/shiming/com/imageloader471/tranform/BlurBitmapTranformation.java:
--------------------------------------------------------------------------------
1 | package code.shiming.com.imageloader471.tranform;
2 |
3 |
4 | import android.graphics.Bitmap;
5 | import android.support.annotation.NonNull;
6 |
7 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
8 | import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
9 |
10 | import java.security.MessageDigest;
11 |
12 | /**
13 | * author: Created by shiming on 2018/4/19 18:23
14 | * mailbox:lamshiming@sina.com
15 | */
16 |
17 | public class BlurBitmapTranformation extends BitmapTransformation {
18 |
19 | private int radius;
20 |
21 | public BlurBitmapTranformation(int radius) {
22 | super();
23 | this.radius = radius;
24 |
25 | }
26 |
27 | @Override
28 | protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {
29 | return blurCrop(pool, toTransform);
30 | }
31 |
32 | private Bitmap blurCrop(BitmapPool pool, Bitmap toTransform) {
33 |
34 | if (toTransform == null) {
35 | return null;
36 | }
37 | if (radius <= 0) {
38 | radius = 25;
39 | }
40 | Bitmap target;
41 | //前面使用的资源,后面使用的是pool,
42 | target = blur(toTransform, radius,pool);
43 |
44 | return target;
45 | }
46 |
47 | @Override
48 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
49 |
50 | }
51 |
52 | private Bitmap blur(Bitmap source, int radius, BitmapPool pool) {
53 | // int w = source.getWidth();
54 | // int h = source.getHeight();
55 | // //由于有这个对象,可以这样的获取尺寸,方便对图片的操作,和对垃圾的回收
56 | // Bitmap target = pool.get(w, h, Bitmap.Config.ARGB_8888);
57 | // //copy
58 | // Bitmap bitmap = target.copy(source.getConfig(), true);
59 | Bitmap bitmap = source.copy(source.getConfig(), true);
60 | int w = source.getWidth();
61 | int h = source.getHeight();
62 | int[] pix = new int[w * h];
63 | // 像素颜色写入位图
64 | // 要跳过的像素[ [] ]中的条目数
65 | //*行(必须是=位图的宽度)。
66 | // 从每行读取的像素数
67 | // 要读取的行数。
68 | bitmap.getPixels(pix, 0, w, 0, 0, w, h);
69 |
70 | int wm = w - 1;
71 | int hm = h - 1;
72 | int wh = w * h;
73 | int div = radius + radius + 1;
74 |
75 | int r[] = new int[wh];
76 | int g[] = new int[wh];
77 | int b[] = new int[wh];
78 | int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
79 | int vmin[] = new int[Math.max(w, h)];
80 |
81 | int divsum = (div + 1) >> 1;
82 | divsum *= divsum;
83 | int dv[] = new int[256 * divsum];
84 | for (i = 0; i < 256 * divsum; i++) {
85 | dv[i] = (i / divsum);
86 | }
87 |
88 | yw = yi = 0;
89 |
90 | int[][] stack = new int[div][3];
91 | int stackPointer;
92 | int stackStart;
93 | int[] sir;
94 | int rbs;
95 | int r1 = radius + 1;
96 | int routSum, goutSum, boutSum;
97 | int rinSum, ginSum, binSum;
98 |
99 | for (y = 0; y < h; y++) {
100 | rinSum = ginSum = binSum = routSum = goutSum = boutSum = rsum = gsum = bsum = 0;
101 | for (i = -radius; i <= radius; i++) {
102 | p = pix[yi + Math.min(wm, Math.max(i, 0))];
103 | sir = stack[i + radius];
104 | // 12&5 的值是多少?答:12转成二进制数是1100(前四位省略了),
105 | // 5转成二进制数是0101,则运算后的结果为0100即4 这是两侧为数值时;
106 | sir[0] = (p & 0xff0000) >> 16;
107 | sir[1] = (p & 0x00ff00) >> 8;
108 | sir[2] = (p & 0x0000ff);
109 | rbs = r1 - Math.abs(i);
110 | rsum += sir[0] * rbs;
111 | gsum += sir[1] * rbs;
112 | bsum += sir[2] * rbs;
113 | if (i > 0) {
114 | rinSum += sir[0];
115 | ginSum += sir[1];
116 | binSum += sir[2];
117 | } else {
118 | routSum += sir[0];
119 | goutSum += sir[1];
120 | boutSum += sir[2];
121 | }
122 | }
123 | stackPointer = radius;
124 |
125 | for (x = 0; x < w; x++) {
126 |
127 | r[yi] = dv[rsum];
128 | g[yi] = dv[gsum];
129 | b[yi] = dv[bsum];
130 |
131 | rsum -= routSum;
132 | gsum -= goutSum;
133 | bsum -= boutSum;
134 |
135 | stackStart = stackPointer - radius + div;
136 | sir = stack[stackStart % div];
137 |
138 | routSum -= sir[0];
139 | goutSum -= sir[1];
140 | boutSum -= sir[2];
141 |
142 | if (y == 0) {
143 | vmin[x] = Math.min(x + radius + 1, wm);
144 | }
145 | p = pix[yw + vmin[x]];
146 |
147 | sir[0] = (p & 0xff0000) >> 16;
148 | sir[1] = (p & 0x00ff00) >> 8;
149 | sir[2] = (p & 0x0000ff);
150 |
151 | rinSum += sir[0];
152 | ginSum += sir[1];
153 | binSum += sir[2];
154 |
155 | rsum += rinSum;
156 | gsum += ginSum;
157 | bsum += binSum;
158 |
159 | stackPointer = (stackPointer + 1) % div;
160 | sir = stack[(stackPointer) % div];
161 |
162 | routSum += sir[0];
163 | goutSum += sir[1];
164 | boutSum += sir[2];
165 |
166 | rinSum -= sir[0];
167 | ginSum -= sir[1];
168 | binSum -= sir[2];
169 |
170 | yi++;
171 | }
172 | yw += w;
173 | }
174 | for (x = 0; x < w; x++) {
175 | rinSum = ginSum = binSum = routSum = goutSum = boutSum = rsum = gsum = bsum = 0;
176 | yp = -radius * w;
177 | for (i = -radius; i <= radius; i++) {
178 | yi = Math.max(0, yp) + x;
179 |
180 | sir = stack[i + radius];
181 |
182 | sir[0] = r[yi];
183 | sir[1] = g[yi];
184 | sir[2] = b[yi];
185 |
186 | rbs = r1 - Math.abs(i);
187 |
188 | rsum += r[yi] * rbs;
189 | gsum += g[yi] * rbs;
190 | bsum += b[yi] * rbs;
191 |
192 | if (i > 0) {
193 | rinSum += sir[0];
194 | ginSum += sir[1];
195 | binSum += sir[2];
196 | } else {
197 | routSum += sir[0];
198 | goutSum += sir[1];
199 | boutSum += sir[2];
200 | }
201 |
202 | if (i < hm) {
203 | yp += w;
204 | }
205 | }
206 | yi = x;
207 | stackPointer = radius;
208 | for (y = 0; y < h; y++) {
209 | // Preserve alpha channel: ( 0xff000000 & pix[yi] )
210 | //在该位置点出现一个萌白的点
211 | pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];
212 |
213 | rsum -= routSum;
214 | gsum -= goutSum;
215 | bsum -= boutSum;
216 |
217 | stackStart = stackPointer - radius + div;
218 | sir = stack[stackStart % div];
219 |
220 | routSum -= sir[0];
221 | goutSum -= sir[1];
222 | boutSum -= sir[2];
223 |
224 | if (x == 0) {
225 | vmin[y] = Math.min(y + r1, hm) * w;
226 | }
227 | p = x + vmin[y];
228 |
229 | sir[0] = r[p];
230 | sir[1] = g[p];
231 | sir[2] = b[p];
232 |
233 | rinSum += sir[0];
234 | ginSum += sir[1];
235 | binSum += sir[2];
236 |
237 | rsum += rinSum;
238 | gsum += ginSum;
239 | bsum += binSum;
240 |
241 | stackPointer = (stackPointer + 1) % div;
242 | sir = stack[stackPointer];
243 |
244 | routSum += sir[0];
245 | goutSum += sir[1];
246 | boutSum += sir[2];
247 | rinSum -= sir[0];
248 | ginSum -= sir[1];
249 | binSum -= sir[2];
250 | yi += w;
251 | }
252 | }
253 | bitmap.setPixels(pix, 0, w, 0, 0, w, h);
254 | return bitmap;
255 | }
256 | }
257 |
--------------------------------------------------------------------------------
/imageloader4.7.1/src/main/java/code/shiming/com/imageloader471/tranform/GlideCircleTransformation.java:
--------------------------------------------------------------------------------
1 | package code.shiming.com.imageloader471.tranform;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapShader;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 |
8 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
9 | import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
10 |
11 | import java.security.MessageDigest;
12 |
13 | /**
14 | * Created by sunfusheng on 2017/6/6.
15 | */
16 | public class GlideCircleTransformation extends BitmapTransformation {
17 |
18 | public GlideCircleTransformation() {
19 | }
20 |
21 | @Override
22 | protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
23 | return circleCrop(pool, toTransform);
24 | }
25 |
26 | private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
27 | if (source == null) return null;
28 |
29 | int size = Math.min(source.getWidth(), source.getHeight());
30 | int x = (source.getWidth() - size) / 2;
31 | int y = (source.getHeight() - size) / 2;
32 |
33 | Bitmap square = Bitmap.createBitmap(source, x, y, size, size);
34 | Bitmap circle = pool.get(size, size, Bitmap.Config.ARGB_8888);
35 |
36 | Canvas canvas = new Canvas(circle);
37 | Paint paint = new Paint();
38 | paint.setShader(new BitmapShader(square, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
39 | paint.setAntiAlias(true);
40 | float r = size / 2f;
41 | canvas.drawCircle(r, r, r, paint);
42 | return circle;
43 | }
44 |
45 | @Override
46 | public void updateDiskCacheKey(MessageDigest messageDigest) {
47 |
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/imageloader4.7.1/src/main/java/code/shiming/com/imageloader471/tranform/RoundBitmapTranformation.java:
--------------------------------------------------------------------------------
1 | package code.shiming.com.imageloader471.tranform;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.graphics.PorterDuff;
8 | import android.graphics.PorterDuffXfermode;
9 | import android.graphics.RectF;
10 | import android.graphics.drawable.Drawable;
11 | import android.support.annotation.NonNull;
12 | import android.support.v4.content.ContextCompat;
13 |
14 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
15 | import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
16 |
17 | import java.security.MessageDigest;
18 |
19 | /**
20 | * author: Created by shiming on 2018/4/19 18:11
21 | * mailbox:lamshiming@sina.com
22 | */
23 |
24 | public class RoundBitmapTranformation extends BitmapTransformation {
25 | private int radius;
26 |
27 | public RoundBitmapTranformation( int radius) {
28 | this.radius = radius;
29 | }
30 | @Override
31 | protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {
32 | return roundCrop(pool, toTransform);
33 | }
34 |
35 | /**
36 | *Glide 使用 LruBitmapPool 作为默认的 BitmapPool 。
37 | * LruBitmapPool 是一个内存中的固定大小的 BitmapPool,
38 | * 使用 LRU 算法清理。默认大小基于设备的分辨率和密度,
39 | * 同时也考虑内存类和 isLowRamDevice 的返回值。
40 | * 具体的计算通过 Glide 的 MemorySizeCalculator 来完成,
41 | * 与 Glide 的 MemoryCache 的大小检测方法相似。
42 | * @param pool
43 | * @param toTransform
44 | * @return
45 | */
46 | private Bitmap roundCrop(BitmapPool pool, Bitmap toTransform) {
47 | int bw = toTransform.getWidth();
48 | int bh = toTransform.getHeight();
49 |
50 |
51 | // int width = toTransform.getWidth(); // 图片的宽
52 | // int height = toTransform.getHeight(); // 图片的高
53 | //
54 | // if (width > height) {
55 | // // 如果图片的宽大于高,则以高为基准,以形状的宽高比重新设置宽度
56 | // width = (int) (height * (shapeWidth / shapeHeight));
57 | // } else {
58 | // // 如果图片的宽小于等于高,则以宽为基准,以形状的宽高比重新设置高度度
59 | // height = (int) (width * (shapeHeight / shapeWidth));
60 | // }
61 |
62 | //由于有这个对象,可以这样的获取尺寸,方便对图片的操作,和对垃圾的回收
63 | Bitmap target = pool.get(bw, bh, Bitmap.Config.ARGB_8888);
64 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
65 | paint.setAntiAlias(true);
66 | RectF f = new RectF(0, 0, bw, bh);
67 | Canvas canvas = new Canvas(target);
68 | canvas.drawRoundRect(f, radius, radius, paint);
69 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
70 | canvas.drawBitmap(toTransform, 0, 0, paint);
71 | return target;
72 | }
73 |
74 | @Override
75 | public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
76 |
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/imageloader4.7.1/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | imageloader4.7.1
3 |
4 |
--------------------------------------------------------------------------------
/imageloader4.7.1/src/test/java/code/shiming/com/imageloader471/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package code.shiming.com.imageloader471;
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 | }
--------------------------------------------------------------------------------
/imageloaderlibrary/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/imageloaderlibrary/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 27
5 | buildToolsVersion "25.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 27
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
27 | exclude group: 'com.android.support', module: 'support-annotations'
28 | })
29 | compile 'com.android.support:appcompat-v7:27.0.0'
30 | testCompile 'junit:junit:4.12'
31 | compile 'com.github.bumptech.glide:glide:3.6.1'
32 | }
33 |
--------------------------------------------------------------------------------
/imageloaderlibrary/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 E:\android-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 |
--------------------------------------------------------------------------------
/imageloaderlibrary/src/androidTest/java/imageloader/shiming/com/imageloaderlibrary/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package imageloader.shiming.com.imageloaderlibrary;
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.shiming.com.imageloaderlibrary.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/imageloaderlibrary/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/imageloaderlibrary/src/main/java/iamgeloader/client/IImageLoaderClient.java:
--------------------------------------------------------------------------------
1 | package iamgeloader.client;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.support.v4.app.Fragment;
6 | import android.widget.ImageView;
7 |
8 | import java.io.File;
9 |
10 | import iamgeloader.client.listener.IGetBitmapListenerByCall;
11 | import iamgeloader.client.listener.IGetDrawableListenerByCall;
12 | import iamgeloader.client.listener.IImageLoaderListenerByCall;
13 | import iamgeloader.client.listener.ImageSizeTwo;
14 | import iamgeloader.client.tranform.IBitmapTransformationD;
15 |
16 | /**
17 | * Created by shiming on 2016/10/26.
18 | */
19 |
20 | public interface IImageLoaderClient {
21 | public void init(Context context);
22 |
23 | public void destroy(Context context);
24 |
25 | public File getCacheDir(Context context);
26 |
27 | public void clearMemoryCache(Context context);
28 |
29 | public void clearDiskCache(Context context);
30 |
31 | public Bitmap getBitmapFromCache(Context context, String url);
32 |
33 | public void getBitmapFromCache(Context context, String url, IGetBitmapListenerByCall listener);
34 |
35 | public void displayImage(Context context, int resId, ImageView imageView);
36 |
37 | public void displayImage(Context context, String url, ImageView imageView);
38 |
39 | public void displayImage(Context context, String url, ImageView imageView, boolean isCache);
40 |
41 | public void displayImage(Fragment fragment, String url, ImageView imageView);
42 |
43 | public void displayImage(Context context, String url, ImageView imageView, int defRes);
44 |
45 | public void displayImage(Fragment fragment, String url, ImageView imageView, int defRes);
46 |
47 | public void displayImage(Context context, String url, ImageView imageView, int defRes, IBitmapTransformationD... transformations);
48 |
49 | public void displayImage(Fragment fragment, String url, ImageView imageView, int defRes, IBitmapTransformationD... transformations);
50 |
51 | public void displayImage(Context context, String url, ImageView imageView, int defRes, ImageSizeTwo size);
52 |
53 | public void displayImage(Fragment fragment, String url, ImageView imageView, int defRes, ImageSizeTwo size);
54 |
55 | public void displayImage(Context context, String url, ImageView imageView, int defRes, boolean cacheInMemory);
56 |
57 | public void displayImage(Fragment fragment, String url, ImageView imageView, int defRes, boolean cacheInMemory);
58 |
59 |
60 | public void displayImage(Context context, String url, ImageView imageView, IImageLoaderListenerByCall listener);
61 |
62 | public void displayImage(Fragment fragment, String url, ImageView imageView, IImageLoaderListenerByCall listener);
63 |
64 | public void displayImage(Context context, String url, ImageView imageView, int defRes, IImageLoaderListenerByCall listener);
65 |
66 | public void displayImage(Fragment fragment, String url, ImageView imageView, int defRes, IImageLoaderListenerByCall listener);
67 |
68 |
69 | public void displayCircleImage(Context context, String url, ImageView imageView, int defRes);
70 |
71 | public void displayCircleImage(Fragment fragment, String url, ImageView imageView, int defRes);
72 |
73 | public void displayRoundImage(Context context, String url, ImageView imageView, int defRes, int radius);
74 |
75 | public void displayRoundImage(Fragment fragment, String url, ImageView imageView, int defRes, int radius);
76 |
77 | public void displayBlurImage(Context context, String url, int blurRadius, IGetDrawableListenerByCall listener);
78 |
79 | public void displayBlurImage(Context context, String url, ImageView imageView, int defRes, int blurRadius);
80 |
81 | public void displayBlurImage(Context context, int resId, ImageView imageView, int blurRadius);
82 |
83 | public void displayBlurImage(Fragment fragment, String url, ImageView imageView, int defRes, int blurRadius);
84 |
85 | public void displayImageInResource(Context context, int resId, ImageView imageView);
86 |
87 | public void displayImageInResource(Fragment fragment, int resId, ImageView imageView);
88 |
89 | public void displayImageInResource(Context context, int resId, ImageView imageView, IBitmapTransformationD... transformations);
90 |
91 | public void displayImageInResource(Fragment fragment, int resId, ImageView imageView, IBitmapTransformationD... transformations);
92 |
93 | public void displayImageInResource(Context context, int resId, ImageView imageView, int defRes);
94 |
95 | public void displayImageInResource(Fragment fragment, int resId, ImageView imageView, int defRes);
96 |
97 | public void displayImageInResource(Context context, int resId, ImageView imageView, int defRes, IBitmapTransformationD... transformations);
98 |
99 | public void displayImageInResource(Fragment fragment, int resId, ImageView imageView, int defRes, IBitmapTransformationD... transformations);
100 | }
101 |
--------------------------------------------------------------------------------
/imageloaderlibrary/src/main/java/iamgeloader/client/ImageLoader.java:
--------------------------------------------------------------------------------
1 | package iamgeloader.client;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.support.v4.app.Fragment;
6 | import android.widget.ImageView;
7 |
8 | import java.io.File;
9 |
10 | import iamgeloader.client.listener.IGetBitmapListenerByCall;
11 | import iamgeloader.client.listener.IGetDrawableListenerByCall;
12 | import iamgeloader.client.listener.IImageLoaderListenerByCall;
13 | import iamgeloader.client.listener.ImageSizeTwo;
14 | import iamgeloader.client.tranform.IBitmapTransformationD;
15 |
16 | /**
17 | * Created by shiming on 2016/10/26.
18 | */
19 |
20 |
21 | public class ImageLoader implements IImageLoaderClient {
22 |
23 | private volatile static ImageLoader instance;
24 | private IImageLoaderClient client;
25 | // private Context context;
26 |
27 | private ImageLoader() {
28 | client = new GlideImageLoaderClient();
29 | // this.context = context.getApplicationContext();
30 | // init(this.context);
31 | }
32 |
33 | /***
34 | * 设置 图片加载库客户端
35 | */
36 |
37 | public void setImageLoaderClient(Context context, IImageLoaderClient client) {
38 | if (this.client != null) {
39 | this.client.clearMemoryCache(context);
40 | }
41 |
42 | if (this.client != client) {
43 | this.client = client;
44 | if (this.client != null) {
45 | this.client.init(context);
46 | }
47 | }
48 |
49 | }
50 |
51 | public static ImageLoader getInstance() {
52 | if (instance == null) {
53 | synchronized (ImageLoader.class) {
54 | if (instance == null) {
55 | instance = new ImageLoader();
56 | }
57 | }
58 | }
59 |
60 | return instance;
61 | }
62 |
63 |
64 | @Override
65 | public void init(Context context) {
66 |
67 | }
68 |
69 | @Override
70 | public void destroy(Context context) {
71 | if (client != null) {
72 | client.destroy(context);
73 | client = null;
74 | }
75 |
76 | instance = null;
77 | }
78 |
79 | @Override
80 | public File getCacheDir(Context context) {
81 | if (client != null) {
82 | return client.getCacheDir(context);
83 | }
84 | return null;
85 | }
86 |
87 | @Override
88 | public void clearMemoryCache(Context context) {
89 | if (client != null) {
90 | client.clearMemoryCache(context);
91 | }
92 | }
93 |
94 | @Override
95 | public void clearDiskCache(Context context) {
96 | if (client != null) {
97 | client.clearDiskCache(context);
98 | }
99 | }
100 |
101 | @Override
102 | public Bitmap getBitmapFromCache(Context context, String url) {
103 | if (client != null) {
104 | return client.getBitmapFromCache(context, url);
105 | }
106 | return null;
107 | }
108 |
109 | /**
110 | * 不是
111 | * @param context
112 | * @param url
113 | * @param listener
114 | */
115 | @Override
116 | public void getBitmapFromCache(Context context, String url, IGetBitmapListenerByCall listener) {
117 | if (client != null) {
118 | client.getBitmapFromCache(context, url, listener);
119 | }
120 | }
121 |
122 | @Override
123 | public void displayImage(Context context, int resId, ImageView imageView) {
124 | if (client != null) {
125 | client.displayImage(context, resId, imageView);
126 | }
127 | }
128 |
129 | @Override
130 | public void displayImage(Context context, String url, ImageView imageView) {
131 | if (client != null) {
132 | client.displayImage(context, url, imageView);
133 | }
134 | }
135 |
136 | @Override
137 | public void displayImage(Context context, String url, ImageView imageView, boolean isCache) {
138 | if (client != null) {
139 | client.displayImage(context, url, imageView,isCache);
140 | }
141 | }
142 |
143 | @Override
144 | public void displayImage(Fragment fragment, String url, ImageView imageView) {
145 | if (client != null) {
146 | client.displayImage(fragment, url, imageView);
147 | }
148 | }
149 |
150 | @Override
151 | public void displayImage(Context context, String url, ImageView imageView, int defRes) {
152 | if (client != null) {
153 | client.displayImage(context, url, imageView, defRes);
154 | }
155 | }
156 |
157 | @Override
158 | public void displayImage(Fragment fragment, String url, ImageView imageView, int defRes) {
159 | if (client != null) {
160 | client.displayImage(fragment, url, imageView, defRes);
161 | }
162 | }
163 |
164 | @Override
165 | public void displayImage(Context context, String url, ImageView imageView, int defRes, IBitmapTransformationD... transformations) {
166 | if (client != null) {
167 | client.displayImage(context, url, imageView, defRes, transformations);
168 | }
169 | }
170 |
171 | @Override
172 | public void displayImage(Fragment fragment, String url, ImageView imageView, int defRes, IBitmapTransformationD... transformations) {
173 | if (client != null) {
174 | client.displayImage(fragment, url, imageView, defRes, transformations);
175 | }
176 | }
177 |
178 | @Override
179 | public void displayImage(Context context, String url, ImageView imageView, int defRes, ImageSizeTwo size) {
180 | if (client != null) {
181 | client.displayImage(context, url, imageView, defRes, size);
182 | }
183 | }
184 |
185 | @Override
186 | public void displayImage(Fragment fragment, String url, ImageView imageView, int defRes, ImageSizeTwo size) {
187 | if (client != null) {
188 | client.displayImage(fragment, url, imageView, defRes, size);
189 | }
190 | }
191 |
192 | @Override
193 | public void displayImage(Context context, String url, ImageView imageView, int defRes, boolean cacheInMemory) {
194 | if (client != null) {
195 | client.displayImage(context, url, imageView, defRes, cacheInMemory);
196 | }
197 | }
198 |
199 | @Override
200 | public void displayImage(Fragment fragment, String url, ImageView imageView, int defRes, boolean cacheInMemory) {
201 | if (client != null) {
202 | client.displayImage(fragment, url, imageView, defRes, cacheInMemory);
203 | }
204 | }
205 |
206 | @Override
207 | public void displayImage(Context context, String url, ImageView imageView, IImageLoaderListenerByCall listener) {
208 | if (client != null) {
209 | client.displayImage(context, url, imageView, listener);
210 | }
211 | }
212 |
213 | @Override
214 | public void displayImage(Fragment fragment, String url, ImageView imageView, IImageLoaderListenerByCall listener) {
215 | if (client != null) {
216 | client.displayImage(fragment, url, imageView, listener);
217 | }
218 | }
219 |
220 | @Override
221 | public void displayImage(Context context, String url, ImageView imageView, int defRes, IImageLoaderListenerByCall listener) {
222 | if (client != null) {
223 | client.displayImage(context, url, imageView, defRes, listener);
224 | }
225 | }
226 |
227 | @Override
228 | public void displayImage(Fragment fragment, String url, ImageView imageView, int defRes, IImageLoaderListenerByCall listener) {
229 | if (client != null) {
230 | client.displayImage(fragment, url, imageView, defRes, listener);
231 | }
232 | }
233 |
234 | @Override
235 | public void displayCircleImage(Context context, String url, ImageView imageView, int defRes) {
236 | if (client != null) {
237 | client.displayCircleImage(context, url, imageView, defRes);
238 | }
239 | }
240 |
241 | @Override
242 | public void displayCircleImage(Fragment fragment, String url, ImageView imageView, int defRes) {
243 | if (client != null) {
244 | client.displayCircleImage(fragment, url, imageView, defRes);
245 | }
246 | }
247 |
248 | @Override
249 | public void displayRoundImage(Context context, String url, ImageView imageView, int defRes, int radius) {
250 | if (client != null) {
251 | client.displayRoundImage(context, url, imageView, defRes, radius);
252 | }
253 | }
254 |
255 | @Override
256 | public void displayBlurImage(Context context, String url, int blurRadius, final IGetDrawableListenerByCall listener) {
257 | if (client != null) {
258 | client.displayBlurImage(context, url, blurRadius, listener);
259 | }
260 | }
261 |
262 | @Override
263 | public void displayRoundImage(Fragment fragment, String url, ImageView imageView, int defRes, int radius) {
264 | if (client != null) {
265 | client.displayRoundImage(fragment, url, imageView, defRes, radius);
266 | }
267 | }
268 |
269 | @Override
270 | public void displayBlurImage(Context context, String url, ImageView imageView, int defRes, int blurRadius) {
271 | if (client != null) {
272 | client.displayBlurImage(context, url, imageView, defRes, blurRadius);
273 | }
274 | }
275 |
276 | @Override
277 | public void displayBlurImage(Context context, int resId, ImageView imageView, int blurRadius) {
278 | if (client != null) {
279 | client.displayBlurImage(context, resId, imageView, blurRadius);
280 | }
281 | }
282 |
283 | @Override
284 | public void displayBlurImage(Fragment fragment, String url, ImageView imageView, int defRes, int blurRadius) {
285 | if (client != null) {
286 | client.displayBlurImage(fragment, url, imageView, defRes, blurRadius);
287 | }
288 | }
289 |
290 | @Override
291 | public void displayImageInResource(Context context, int resId, ImageView imageView) {
292 | if (client != null) {
293 | client.displayImageInResource(context, resId, imageView);
294 | }
295 | }
296 |
297 | @Override
298 | public void displayImageInResource(Fragment fragment, int resId, ImageView imageView) {
299 | if (client != null) {
300 | client.displayImageInResource(fragment, resId, imageView);
301 | }
302 | }
303 |
304 | @Override
305 | public void displayImageInResource(Context context, int resId, ImageView imageView, IBitmapTransformationD... transformations) {
306 | if (client != null) {
307 | client.displayImageInResource(context, resId, imageView, transformations);
308 | }
309 | }
310 |
311 | @Override
312 | public void displayImageInResource(Fragment fragment, int resId, ImageView imageView, IBitmapTransformationD... transformations) {
313 | if (client != null) {
314 | client.displayImageInResource(fragment, resId, imageView, transformations);
315 | }
316 | }
317 |
318 | @Override
319 | public void displayImageInResource(Context context, int resId, ImageView imageView, int defRes) {
320 | if (client != null) {
321 | client.displayImageInResource(context, resId, imageView, defRes);
322 | }
323 | }
324 |
325 | @Override
326 | public void displayImageInResource(Fragment fragment, int resId, ImageView imageView, int defRes) {
327 | if (client != null) {
328 | client.displayImageInResource(fragment, resId, imageView, defRes);
329 | }
330 | }
331 |
332 | @Override
333 | public void displayImageInResource(Context context, int resId, ImageView imageView, int defRes, IBitmapTransformationD... transformations) {
334 | if (client != null) {
335 | client.displayImageInResource(context, resId, imageView, defRes, transformations);
336 | }
337 | }
338 |
339 | @Override
340 | public void displayImageInResource(Fragment fragment, int resId, ImageView imageView, int defRes, IBitmapTransformationD... transformations) {
341 | if (client != null) {
342 | client.displayImageInResource(fragment, resId, imageView, defRes, transformations);
343 | }
344 | }
345 |
346 |
347 | }
348 |
--------------------------------------------------------------------------------
/imageloaderlibrary/src/main/java/iamgeloader/client/listener/IGetBitmapListenerByCall.java:
--------------------------------------------------------------------------------
1 | package iamgeloader.client.listener;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | /**
6 | * Created by shiming on 2016/10/26.
7 | */
8 |
9 | public interface IGetBitmapListenerByCall {
10 | void onBitmap(Bitmap bitmap);
11 | }
12 |
--------------------------------------------------------------------------------
/imageloaderlibrary/src/main/java/iamgeloader/client/listener/IGetDrawableListenerByCall.java:
--------------------------------------------------------------------------------
1 | package iamgeloader.client.listener;
2 |
3 | import android.graphics.drawable.Drawable;
4 |
5 | /**
6 | * Created by shiming on 2016/10/26.
7 | * 设置此皆苦是为了业务需要,一般不需要关心网络请求回来的drawable,但是业务需要切换的地方的话,需要拿到网络请求回来的drawable
8 | */
9 |
10 | public interface IGetDrawableListenerByCall {
11 | void onDrawable(Drawable drawable);
12 | }
13 |
--------------------------------------------------------------------------------
/imageloaderlibrary/src/main/java/iamgeloader/client/listener/IImageLoaderListenerByCall.java:
--------------------------------------------------------------------------------
1 | package iamgeloader.client.listener;
2 |
3 | import android.widget.ImageView;
4 |
5 | /**
6 | * Created by shiming on 2016/10/26.
7 | * 监听图片下载进度
8 | */
9 | public interface IImageLoaderListenerByCall {
10 |
11 | //监听图片下载错误
12 | void onLoadingFailed(String url, ImageView target, Exception exception);
13 | //监听图片加载成功
14 | void onLoadingComplete(String url, ImageView target);
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/imageloaderlibrary/src/main/java/iamgeloader/client/listener/ImageSizeTwo.java:
--------------------------------------------------------------------------------
1 | package iamgeloader.client.listener;
2 |
3 | /**
4 | * Created by shiming on 2016/10/26.
5 | */
6 |
7 | public final class ImageSizeTwo {
8 | private final static String SEPARATOR = "x";
9 |
10 | private final int width;
11 | private final int height;
12 |
13 | public ImageSizeTwo(int width, int height) {
14 | this.width = width;
15 | this.height = height;
16 | }
17 |
18 | public int getWidth() {
19 | return width;
20 | }
21 |
22 | public int getHeight() {
23 | return height;
24 | }
25 |
26 | @Override
27 | public String toString() {
28 | return new StringBuilder().append(width).append(SEPARATOR).append(height).toString();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/imageloaderlibrary/src/main/java/iamgeloader/client/tranform/BlurBitmapTransformationDD.java:
--------------------------------------------------------------------------------
1 | package iamgeloader.client.tranform;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.widget.ImageView;
6 |
7 | /**
8 | * Created by shiming on 2016/10/26.
9 | * 处理模糊图片,但是不能达到高斯模糊的效果
10 | */
11 |
12 |
13 | public class BlurBitmapTransformationDD implements IBitmapTransformationD {
14 |
15 | private int radius;
16 | private Context context;
17 |
18 | public BlurBitmapTransformationDD(Context context, int radius) {
19 | this.radius = radius;
20 | this.context = context;
21 | }
22 |
23 | @Override
24 | public Bitmap transform(Bitmap source, ImageView imageView) {
25 |
26 | if (source == null) {
27 | return null;
28 | }
29 |
30 | if (radius <= 0) {
31 | radius = 25;
32 | }
33 |
34 | Bitmap target;
35 |
36 | // if(Build.VERSION.SDK_INT >= 17){
37 | // target = Bitmap.createBitmap(source.getWidth(),source.getHeight(),Bitmap.Config.ARGB_8888);
38 | // final RenderScript rs = RenderScript.create(context.getApplicationContext());
39 | // final Allocation input = Allocation.createFromBitmap(rs, source);
40 | // final Allocation output = Allocation.createFromBitmap(rs, target);
41 | // final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
42 | // script.setRadius(radius);
43 | // script.setInput(input);
44 | // script.forEach(output);
45 | // output.copyTo(target);
46 | // rs.destroy();
47 | // context = null;
48 | // return target;
49 | // }
50 |
51 | target = blur(source, radius);
52 | context = null;
53 | return target;
54 |
55 | }
56 |
57 | @Override
58 | public Context getContext() {
59 | return context;
60 | }
61 |
62 | /**
63 | * 当设置过大的radius 容易内存溢出
64 | * at iamgeloader.client.tranform.BlurBitmapTransformationDD.blur(BlurBitmapTransformationDD.java:80)
65 | * @param source
66 | * @param radius
67 | * @return
68 | */
69 | private Bitmap blur(Bitmap source, int radius) {
70 | Bitmap bitmap = source.copy(source.getConfig(), true);
71 | int w = source.getWidth();
72 | int h = source.getHeight();
73 | int[] pix = new int[w * h];
74 | // 像素颜色写入位图
75 | // 要跳过的像素[ [] ]中的条目数
76 | //*行(必须是=位图的宽度)。
77 | // 从每行读取的像素数
78 | // 要读取的行数。
79 | bitmap.getPixels(pix, 0, w, 0, 0, w, h);
80 |
81 | int wm = w - 1;
82 | int hm = h - 1;
83 | int wh = w * h;
84 | int div = radius + radius + 1;
85 |
86 | int r[] = new int[wh];
87 | int g[] = new int[wh];
88 | int b[] = new int[wh];
89 | int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
90 | int vmin[] = new int[Math.max(w, h)];
91 |
92 | int divsum = (div + 1) >> 1;
93 | divsum *= divsum;
94 | int dv[] = new int[256 * divsum];
95 | for (i = 0; i < 256 * divsum; i++) {
96 | dv[i] = (i / divsum);
97 | }
98 |
99 | yw = yi = 0;
100 |
101 | int[][] stack = new int[div][3];
102 | int stackPointer;
103 | int stackStart;
104 | int[] sir;
105 | int rbs;
106 | int r1 = radius + 1;
107 | int routSum, goutSum, boutSum;
108 | int rinSum, ginSum, binSum;
109 |
110 | for (y = 0; y < h; y++) {
111 | rinSum = ginSum = binSum = routSum = goutSum = boutSum = rsum = gsum = bsum = 0;
112 | for (i = -radius; i <= radius; i++) {
113 | p = pix[yi + Math.min(wm, Math.max(i, 0))];
114 | sir = stack[i + radius];
115 | // 12&5 的值是多少?答:12转成二进制数是1100(前四位省略了),
116 | // 5转成二进制数是0101,则运算后的结果为0100即4 这是两侧为数值时;
117 | sir[0] = (p & 0xff0000) >> 16;
118 | sir[1] = (p & 0x00ff00) >> 8;
119 | sir[2] = (p & 0x0000ff);
120 | rbs = r1 - Math.abs(i);
121 | rsum += sir[0] * rbs;
122 | gsum += sir[1] * rbs;
123 | bsum += sir[2] * rbs;
124 | if (i > 0) {
125 | rinSum += sir[0];
126 | ginSum += sir[1];
127 | binSum += sir[2];
128 | } else {
129 | routSum += sir[0];
130 | goutSum += sir[1];
131 | boutSum += sir[2];
132 | }
133 | }
134 | stackPointer = radius;
135 |
136 | for (x = 0; x < w; x++) {
137 |
138 | r[yi] = dv[rsum];
139 | g[yi] = dv[gsum];
140 | b[yi] = dv[bsum];
141 |
142 | rsum -= routSum;
143 | gsum -= goutSum;
144 | bsum -= boutSum;
145 |
146 | stackStart = stackPointer - radius + div;
147 | sir = stack[stackStart % div];
148 |
149 | routSum -= sir[0];
150 | goutSum -= sir[1];
151 | boutSum -= sir[2];
152 |
153 | if (y == 0) {
154 | vmin[x] = Math.min(x + radius + 1, wm);
155 | }
156 | p = pix[yw + vmin[x]];
157 |
158 | sir[0] = (p & 0xff0000) >> 16;
159 | sir[1] = (p & 0x00ff00) >> 8;
160 | sir[2] = (p & 0x0000ff);
161 |
162 | rinSum += sir[0];
163 | ginSum += sir[1];
164 | binSum += sir[2];
165 |
166 | rsum += rinSum;
167 | gsum += ginSum;
168 | bsum += binSum;
169 |
170 | stackPointer = (stackPointer + 1) % div;
171 | sir = stack[(stackPointer) % div];
172 |
173 | routSum += sir[0];
174 | goutSum += sir[1];
175 | boutSum += sir[2];
176 |
177 | rinSum -= sir[0];
178 | ginSum -= sir[1];
179 | binSum -= sir[2];
180 |
181 | yi++;
182 | }
183 | yw += w;
184 | }
185 | for (x = 0; x < w; x++) {
186 | rinSum = ginSum = binSum = routSum = goutSum = boutSum = rsum = gsum = bsum = 0;
187 | yp = -radius * w;
188 | for (i = -radius; i <= radius; i++) {
189 | yi = Math.max(0, yp) + x;
190 |
191 | sir = stack[i + radius];
192 |
193 | sir[0] = r[yi];
194 | sir[1] = g[yi];
195 | sir[2] = b[yi];
196 |
197 | rbs = r1 - Math.abs(i);
198 |
199 | rsum += r[yi] * rbs;
200 | gsum += g[yi] * rbs;
201 | bsum += b[yi] * rbs;
202 |
203 | if (i > 0) {
204 | rinSum += sir[0];
205 | ginSum += sir[1];
206 | binSum += sir[2];
207 | } else {
208 | routSum += sir[0];
209 | goutSum += sir[1];
210 | boutSum += sir[2];
211 | }
212 |
213 | if (i < hm) {
214 | yp += w;
215 | }
216 | }
217 | yi = x;
218 | stackPointer = radius;
219 | for (y = 0; y < h; y++) {
220 | // Preserve alpha channel: ( 0xff000000 & pix[yi] )
221 | //在该位置点出现一个萌白的点
222 | pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];
223 |
224 | rsum -= routSum;
225 | gsum -= goutSum;
226 | bsum -= boutSum;
227 |
228 | stackStart = stackPointer - radius + div;
229 | sir = stack[stackStart % div];
230 |
231 | routSum -= sir[0];
232 | goutSum -= sir[1];
233 | boutSum -= sir[2];
234 |
235 | if (x == 0) {
236 | vmin[y] = Math.min(y + r1, hm) * w;
237 | }
238 | p = x + vmin[y];
239 |
240 | sir[0] = r[p];
241 | sir[1] = g[p];
242 | sir[2] = b[p];
243 |
244 | rinSum += sir[0];
245 | ginSum += sir[1];
246 | binSum += sir[2];
247 |
248 | rsum += rinSum;
249 | gsum += ginSum;
250 | bsum += binSum;
251 |
252 | stackPointer = (stackPointer + 1) % div;
253 | sir = stack[stackPointer];
254 |
255 | routSum += sir[0];
256 | goutSum += sir[1];
257 | boutSum += sir[2];
258 |
259 | rinSum -= sir[0];
260 | ginSum -= sir[1];
261 | binSum -= sir[2];
262 |
263 | yi += w;
264 | }
265 | }
266 |
267 | bitmap.setPixels(pix, 0, w, 0, 0, w, h);
268 |
269 | return bitmap;
270 | }
271 | }
272 |
--------------------------------------------------------------------------------
/imageloaderlibrary/src/main/java/iamgeloader/client/tranform/CircleBitmapTransformationDD.java:
--------------------------------------------------------------------------------
1 | package iamgeloader.client.tranform;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapShader;
6 | import android.graphics.Canvas;
7 | import android.graphics.Matrix;
8 | import android.graphics.Paint;
9 | import android.widget.ImageView;
10 |
11 |
12 | /**
13 | * Created by shiming on 2016/10/26.
14 | */
15 |
16 | public class CircleBitmapTransformationDD implements IBitmapTransformationD {
17 |
18 | private Context context;
19 |
20 | public CircleBitmapTransformationDD(Context context) {
21 | this.context = context;
22 | }
23 |
24 | @Override
25 | public Bitmap transform(Bitmap source, ImageView imageView) {
26 | int size = Math.min(source.getWidth(), source.getHeight());
27 | int width = (source.getWidth() - size) / 2;
28 | int height = (source.getHeight() - size) / 2;
29 | Bitmap target = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
30 |
31 | Canvas canvas = new Canvas(target);
32 | Paint paint = new Paint();
33 |
34 | BitmapShader shader = new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
35 | if (width != 0 || height != 0) {
36 | // source isn't square, move viewport to center
37 | Matrix matrix = new Matrix();
38 | matrix.setTranslate(-width, -height);
39 | shader.setLocalMatrix(matrix);
40 | }
41 | paint.setShader(shader);
42 | paint.setAntiAlias(true);
43 |
44 | float r = size / 2f;
45 | canvas.drawCircle(r, r, r, paint);
46 | context = null;
47 | return target;
48 | }
49 |
50 | @Override
51 | public Context getContext() {
52 | return context;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/imageloaderlibrary/src/main/java/iamgeloader/client/tranform/GlideTransformD.java:
--------------------------------------------------------------------------------
1 | package iamgeloader.client.tranform;
2 |
3 |
4 | import android.content.Context;
5 | import android.graphics.Bitmap;
6 | import android.os.Looper;
7 | import android.util.Log;
8 |
9 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
10 |
11 | /**
12 | * Created by shiming on 2016/10/26.
13 | */
14 |
15 | public class GlideTransformD extends com.bumptech.glide.load.resource.bitmap.BitmapTransformation {
16 |
17 | private IBitmapTransformationD transformation;
18 |
19 | /**
20 | *
21 | * @param context
22 | * @param transformation 自定义图片装换接口,在构造方法中传入
23 | */
24 | public GlideTransformD(Context context, IBitmapTransformationD transformation) {
25 | super(context);
26 | this.transformation = transformation;
27 | }
28 |
29 | @Override
30 | protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
31 | if (toTransform == null) {
32 | return null;
33 | }
34 | Log.d(getClass().getCanonicalName(), "transform in child thread : " + String.valueOf(Looper.getMainLooper() != Looper.myLooper()));
35 | return transformation.transform(toTransform, null);
36 | }
37 |
38 | @Override
39 | public String getId() {
40 | return getClass().getName() + transformation.hashCode();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/imageloaderlibrary/src/main/java/iamgeloader/client/tranform/IBitmapTransformationD.java:
--------------------------------------------------------------------------------
1 | package iamgeloader.client.tranform;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.widget.ImageView;
6 |
7 |
8 | /**
9 | * Created by shiming on 2016/10/26.
10 | * 摒弃掉glide中使用的方法处理图片的方法 ,自定义transform的方法转化bitmap
11 | */
12 |
13 | public interface IBitmapTransformationD {
14 | public Bitmap transform(Bitmap source, ImageView imageView);
15 | //context 需要被使用的地方持有
16 | public Context getContext();
17 | }
18 |
--------------------------------------------------------------------------------
/imageloaderlibrary/src/main/java/iamgeloader/client/tranform/RoundBitmapTransformationD.java:
--------------------------------------------------------------------------------
1 | package iamgeloader.client.tranform;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.graphics.PorterDuff;
8 | import android.graphics.PorterDuffXfermode;
9 | import android.graphics.RectF;
10 | import android.widget.ImageView;
11 |
12 | /**
13 | * Created by shiming on 2016/10/26.
14 | */
15 |
16 | public class RoundBitmapTransformationD implements IBitmapTransformationD {
17 | private int radius;
18 | private Context context;
19 |
20 |
21 | public RoundBitmapTransformationD(Context context, int radius) {
22 | this.context = context;
23 | this.radius = radius;
24 | }
25 |
26 | @Override
27 | public Bitmap transform(Bitmap source, ImageView imageView) {
28 |
29 | int bw = source.getWidth();
30 | int bh = source.getHeight();
31 |
32 |
33 | Bitmap target = Bitmap.createBitmap(bw, bh, Bitmap.Config.ARGB_8888);
34 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
35 | paint.setAntiAlias(true);
36 | RectF f = new RectF(0, 0, bw, bh);
37 | Canvas canvas = new Canvas(target);
38 | canvas.drawRoundRect(f, radius, radius, paint);
39 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
40 | canvas.drawBitmap(source, 0, 0, paint);
41 | context = null;
42 | return target;
43 | }
44 |
45 | @Override
46 | public Context getContext() {
47 | return context;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/imageloaderlibrary/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ImageLoaderLibrary
3 |
4 |
--------------------------------------------------------------------------------
/imageloaderlibrary/src/test/java/imageloader/shiming/com/imageloaderlibrary/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package imageloader.shiming.com.imageloaderlibrary;
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 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':imageloaderlibrary', ':compresspic', ':imageloader4.7.1', ':glide4.7.1demo'
2 |
--------------------------------------------------------------------------------