();
78 | if (options.isBlurImage()) {
79 | list.add(new BlurTransformation(options.getBlurValue()));
80 | // requestOptions.transforms(new BlurTransformation(options.getBlurValue()));
81 | }
82 | if (options.needImageRadius()) {
83 | list.add(new RoundedCorners(options.getImageRadius()));
84 | // requestOptions.transforms(new RoundedCorners(options.getImageRadius()));
85 | }
86 | if (options.isCircle()) {
87 | list.add(new CircleTransformation());
88 |
89 | // requestOptions.transforms(new CircleTransformation());
90 | }
91 | if (list.size() > 0) {
92 | Transformation[] transformations = list.toArray(new Transformation[list.size()]);
93 | requestOptions.transforms(transformations);
94 |
95 | }
96 |
97 |
98 | RequestBuilder builder = getRequestBuilder(options);
99 | builder.listener(new RequestListener() {
100 | @Override
101 | public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
102 |
103 | if (options.getLoaderResultCallBack() != null) {
104 | options.getLoaderResultCallBack().onFail();
105 | }
106 | return false;
107 | }
108 |
109 | @Override
110 | public boolean onResourceReady(Object resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
111 | if (options.getLoaderResultCallBack() != null) {
112 | options.getLoaderResultCallBack().onSucc();
113 | }
114 | return false;
115 | }
116 | });
117 |
118 | builder.apply(requestOptions).into((ImageView) options.getViewContainer());
119 | }
120 |
121 | private RequestManager getRequestManager(View view) {
122 | return Glide.with(view);
123 |
124 | }
125 |
126 | private RequestBuilder getRequestBuilder(ImageLoaderOptions options) {
127 | RequestBuilder builder = null;
128 | if (options.isAsGif()) {
129 | builder = getRequestManager(options.getViewContainer()).asGif();
130 | } else {
131 | builder = getRequestManager(options.getViewContainer()).asBitmap();
132 | }
133 |
134 | if (!TextUtils.isEmpty(options.getUrl())) {
135 | builder.load(options.getUrl());
136 | } else {
137 | builder.load(options.getResource());
138 | }
139 | return builder;
140 |
141 | }
142 |
143 | @Override
144 | public void hideImage(@NonNull View view, int visiable) {
145 | if (view != null) {
146 | view.setVisibility(visiable);
147 | }
148 | }
149 |
150 | @Override
151 | public void cleanMemory(Context context) {
152 | if (Looper.myLooper() == Looper.getMainLooper()) {
153 | Glide.get(context).clearMemory();
154 |
155 | }
156 | }
157 |
158 | @Override
159 | public void pause(Context context) {
160 | Glide.with(context).pauseRequests();
161 | }
162 |
163 | @Override
164 | public void resume(Context context) {
165 | Glide.with(context).resumeRequests();
166 |
167 | }
168 |
169 | @Override
170 | public void init(Context context ,ImageLoaderConfig config) {
171 | // 暂时不做配置
172 |
173 | }
174 | }
175 |
--------------------------------------------------------------------------------
/glide/src/main/java/com/ladingwu/glidelibrary/MyGlideModule.java:
--------------------------------------------------------------------------------
1 | package com.ladingwu.glidelibrary;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.NonNull;
5 |
6 | import com.bumptech.glide.Glide;
7 | import com.bumptech.glide.Registry;
8 | import com.bumptech.glide.annotation.GlideModule;
9 | import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader;
10 | import com.bumptech.glide.load.model.GlideUrl;
11 | import com.bumptech.glide.module.AppGlideModule;
12 |
13 | import java.io.InputStream;
14 |
15 | @GlideModule
16 | public class MyGlideModule extends AppGlideModule {
17 | @Override
18 | public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
19 | super.registerComponents(context, glide, registry);
20 | registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(DownLoadManager.getOkHttpClient()));
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/glide/src/main/java/com/ladingwu/glidelibrary/ProgressResponseBody.java:
--------------------------------------------------------------------------------
1 | package com.ladingwu.glidelibrary;
2 |
3 | import android.os.Handler;
4 | import android.os.Looper;
5 | import android.support.annotation.NonNull;
6 |
7 | import com.lasingwu.baselibrary.OnLoaderProgressCallback;
8 |
9 | import java.io.IOException;
10 |
11 | import okhttp3.MediaType;
12 | import okhttp3.ResponseBody;
13 | import okio.Buffer;
14 | import okio.BufferedSource;
15 | import okio.ForwardingSource;
16 | import okio.Okio;
17 | import okio.Source;
18 |
19 | public class ProgressResponseBody extends ResponseBody {
20 | private OnProgressListener onLoaderProgressCallback;
21 | private ResponseBody responseBody;
22 | private BufferedSource bufferedSource;
23 | private String url;
24 | private static Handler mainThreadHandler = new Handler(Looper.getMainLooper());
25 |
26 | ProgressResponseBody(String url,OnProgressListener onLoaderProgressCallback, ResponseBody responseBody) {
27 | this.url = url;
28 | this.onLoaderProgressCallback = onLoaderProgressCallback;
29 | this.responseBody = responseBody;
30 | }
31 |
32 | @Override
33 | public BufferedSource source() {
34 | if (bufferedSource == null) {
35 | bufferedSource = Okio.buffer(source(responseBody.source()));
36 | }
37 | return bufferedSource;
38 | }
39 |
40 | private Source source(Source source) {
41 | return new ForwardingSource(source) {
42 | long total;
43 | long preReaded;
44 |
45 | @Override
46 | public long read(@NonNull Buffer sink, long byteCount) throws IOException {
47 | long bytesRead = super.read(sink, byteCount);
48 | total += (bytesRead == -1) ? 0 : bytesRead;
49 |
50 | if (onLoaderProgressCallback != null && preReaded != total) {
51 | preReaded = total;
52 | final float a = total/(contentLength()*1.0f);
53 | mainThreadHandler.post(new Runnable() {
54 | @Override
55 | public void run() {
56 | onLoaderProgressCallback.onLoad(url,(int) (a * 10000),a>=1);
57 | }
58 | });
59 | }
60 | return bytesRead;
61 | }
62 | };
63 | }
64 |
65 | @Override
66 | public MediaType contentType() {
67 | return responseBody.contentType();
68 | }
69 |
70 | @Override
71 | public long contentLength() {
72 | return responseBody.contentLength();
73 | }
74 |
75 | public interface OnProgressListener{
76 | void onLoad(String url,int progress,boolean complete);
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/glide/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | GlideLibrary
3 |
4 |
--------------------------------------------------------------------------------
/glide/src/test/java/com/ladingwu/glidelibrary/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.ladingwu.glidelibrary;
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 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ladingwu/ImageLoaderFramework/7e1af0e6dc3f3c92614bc16f052cd02054b68980/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Jan 28 14:12:51 CST 2018
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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/imageloader-framework/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/imageloader-framework/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | //apply plugin: 'com.novoda.bintray-release'
3 | android {
4 | compileSdkVersion 26
5 |
6 |
7 | defaultConfig {
8 | minSdkVersion 17
9 | targetSdkVersion 26
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 | lintOptions {
24 | abortOnError false
25 | }
26 | }
27 | //新添加
28 | //publish {
29 | // userOrg = 'ladingwu' //在https://bintray.com上注册的用户名
30 | // repoName='Maven'
31 | // groupId = 'com.ladingwu.library' //jCenter上的路径
32 | // artifactId = 'imageloader-framework' //要上传的library名称
33 | // publishVersion ="$library_version" //library的版本号
34 | // desc = '' //library的简单描述
35 | // website = 'https://github.com/ladingwu/ImageLoaderFramework' //library的开源地址,例如在github上的地址
36 | //}
37 | dependencies {
38 | implementation fileTree(dir: 'libs', include: ['*.jar'])
39 |
40 | // implementation 'com.android.support:appcompat-v7:26.1.0'
41 | compileOnly "com.android.support:support-annotations:27.0.2"
42 | testImplementation 'junit:junit:4.12'
43 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
44 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
45 | }
46 |
--------------------------------------------------------------------------------
/imageloader-framework/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 |
--------------------------------------------------------------------------------
/imageloader-framework/src/androidTest/java/com/lasingwu/baselibrary/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.lasingwu.baselibrary;
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.lasingwu.baselibrary.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/imageloader-framework/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/imageloader-framework/src/main/java/com/lasingwu/baselibrary/BitmapUtils.java:
--------------------------------------------------------------------------------
1 | package com.lasingwu.baselibrary;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.ContentUris;
5 | import android.content.Context;
6 | import android.database.Cursor;
7 | import android.graphics.Bitmap;
8 | import android.graphics.Matrix;
9 | import android.net.Uri;
10 | import android.os.Build;
11 | import android.os.Environment;
12 | import android.provider.DocumentsContract;
13 | import android.provider.MediaStore;
14 |
15 |
16 | /**
17 | * 图片工具类
18 | *
19 | * @author andy
20 | */
21 | public class BitmapUtils {
22 |
23 | /**
24 | * 设置图片大小
25 | *
26 | * @param bitmap
27 | * @param width
28 | * @param height
29 | * @return
30 | */
31 | public static Bitmap bitmapSetSize(Bitmap bitmap, int width, int height) {
32 | int bitmapWidth = bitmap.getWidth();
33 | int bitmapHeight = bitmap.getHeight();
34 |
35 | float scaleWidth = (float) width / bitmapWidth;
36 | float scaleHeight = (float) height / bitmapHeight;
37 | Matrix matrix = new Matrix();
38 | matrix.postScale(scaleWidth, scaleHeight);
39 | Bitmap newBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmapWidth, bitmapHeight, matrix, true);
40 | return newBitmap;
41 | }
42 |
43 | /**
44 | * 按比例缩放图片
45 | *
46 | * @param bitmap
47 | * @param prop
48 | * @return
49 | */
50 | public static Bitmap bitmapSetSize(Bitmap bitmap, float prop) {
51 | int bitmapWidth = bitmap.getWidth();
52 | int bitmapHeight = bitmap.getHeight();
53 |
54 | Matrix matrix = new Matrix();
55 | matrix.postScale(prop, prop);
56 | Bitmap newBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmapWidth, bitmapHeight, matrix, true);
57 | return newBitmap;
58 | }
59 |
60 | /**
61 | * 判断图片宽高比例
62 | *
63 | * @param bitmap
64 | * @return
65 | */
66 | public static boolean bitmapSizeOk(Bitmap bitmap) {
67 | int width = bitmap.getWidth();
68 | int height = bitmap.getHeight();
69 | float proportion = (float) width / height;
70 | return proportion >= 1.5;
71 | }
72 |
73 | /**
74 | * @param context
75 | * @param bpin
76 | * @param prop 缩放比例
77 | * @param radius
78 | * @return
79 | */
80 | public static Bitmap fastBlur(Context context, Bitmap bpin, float prop, int radius) {
81 | Bitmap bp = bitmapSetSize(bpin, prop);
82 | return fastBlur(bp, radius);
83 | }
84 |
85 | /**
86 | * 高斯模糊算法
87 | *
88 | * @param sentBitmap
89 | * @param radius
90 | * @return
91 | */
92 | public static Bitmap fastBlur(Bitmap sentBitmap, int radius) {
93 | // Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
94 | Bitmap bitmap = sentBitmap;
95 | if (bitmap == null) {
96 | return null;
97 | }
98 | if (radius < 1) {
99 | return null;
100 | }
101 |
102 | int w = bitmap.getWidth();
103 | int h = bitmap.getHeight();
104 |
105 | int[] pix = new int[w * h];
106 | // Log.e("pix", w + " " + h + " " + pix.length);
107 | bitmap.getPixels(pix, 0, w, 0, 0, w, h);
108 |
109 | int wm = w - 1;
110 | int hm = h - 1;
111 | int wh = w * h;
112 | int div = radius + radius + 1;
113 |
114 | int r[] = new int[wh];
115 | int g[] = new int[wh];
116 | int b[] = new int[wh];
117 | int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
118 | int vmin[] = new int[Math.max(w, h)];
119 |
120 | int divsum = (div + 1) >> 1;
121 | divsum *= divsum;
122 | int temp = 256 * divsum;
123 | int dv[] = new int[temp];
124 | for (i = 0; i < temp; i++) {
125 | dv[i] = (i / divsum);
126 | }
127 |
128 | yw = yi = 0;
129 |
130 | int[][] stack = new int[div][3];
131 | int stackpointer;
132 | int stackstart;
133 | int[] sir;
134 | int rbs;
135 | int r1 = radius + 1;
136 | int routsum, goutsum, boutsum;
137 | int rinsum, ginsum, binsum;
138 |
139 | for (y = 0; y < h; y++) {
140 | rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
141 | for (i = -radius; i <= radius; i++) {
142 | p = pix[yi + Math.min(wm, Math.max(i, 0))];
143 | sir = stack[i + radius];
144 | sir[0] = (p & 0xff0000) >> 16;
145 | sir[1] = (p & 0x00ff00) >> 8;
146 | sir[2] = (p & 0x0000ff);
147 | rbs = r1 - Math.abs(i);
148 | rsum += sir[0] * rbs;
149 | gsum += sir[1] * rbs;
150 | bsum += sir[2] * rbs;
151 | if (i > 0) {
152 | rinsum += sir[0];
153 | ginsum += sir[1];
154 | binsum += sir[2];
155 | } else {
156 | routsum += sir[0];
157 | goutsum += sir[1];
158 | boutsum += sir[2];
159 | }
160 | }
161 | stackpointer = radius;
162 |
163 | for (x = 0; x < w; x++) {
164 |
165 | r[yi] = dv[rsum];
166 | g[yi] = dv[gsum];
167 | b[yi] = dv[bsum];
168 |
169 | rsum -= routsum;
170 | gsum -= goutsum;
171 | bsum -= boutsum;
172 |
173 | stackstart = stackpointer - radius + div;
174 | sir = stack[stackstart % div];
175 |
176 | routsum -= sir[0];
177 | goutsum -= sir[1];
178 | boutsum -= sir[2];
179 |
180 | if (y == 0) {
181 | vmin[x] = Math.min(x + radius + 1, wm);
182 | }
183 | p = pix[yw + vmin[x]];
184 |
185 | sir[0] = (p & 0xff0000) >> 16;
186 | sir[1] = (p & 0x00ff00) >> 8;
187 | sir[2] = (p & 0x0000ff);
188 |
189 | rinsum += sir[0];
190 | ginsum += sir[1];
191 | binsum += sir[2];
192 |
193 | rsum += rinsum;
194 | gsum += ginsum;
195 | bsum += binsum;
196 |
197 | stackpointer = (stackpointer + 1) % div;
198 | sir = stack[(stackpointer) % div];
199 |
200 | routsum += sir[0];
201 | goutsum += sir[1];
202 | boutsum += sir[2];
203 |
204 | rinsum -= sir[0];
205 | ginsum -= sir[1];
206 | binsum -= sir[2];
207 | yi++;
208 | }
209 | yw += w;
210 | }
211 | for (x = 0; x < w; x++) {
212 | rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
213 | yp = -radius * w;
214 | for (i = -radius; i <= radius; i++) {
215 | yi = Math.max(0, yp) + x;
216 |
217 | sir = stack[i + radius];
218 |
219 | sir[0] = r[yi];
220 | sir[1] = g[yi];
221 | sir[2] = b[yi];
222 |
223 | rbs = r1 - Math.abs(i);
224 |
225 | rsum += r[yi] * rbs;
226 | gsum += g[yi] * rbs;
227 | bsum += b[yi] * rbs;
228 |
229 | if (i > 0) {
230 | rinsum += sir[0];
231 | ginsum += sir[1];
232 | binsum += sir[2];
233 | } else {
234 | routsum += sir[0];
235 | goutsum += sir[1];
236 | boutsum += sir[2];
237 | }
238 |
239 | if (i < hm) {
240 | yp += w;
241 | }
242 | }
243 | yi = x;
244 | stackpointer = radius;
245 | for (y = 0; y < h; y++) {
246 | // Preserve alpha channel: ( 0xff000000 & pix[yi] )
247 | pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];
248 |
249 | rsum -= routsum;
250 | gsum -= goutsum;
251 | bsum -= boutsum;
252 |
253 | stackstart = stackpointer - radius + div;
254 | sir = stack[stackstart % div];
255 |
256 | routsum -= sir[0];
257 | goutsum -= sir[1];
258 | boutsum -= sir[2];
259 |
260 | if (x == 0) {
261 | vmin[y] = Math.min(y + r1, hm) * w;
262 | }
263 | p = x + vmin[y];
264 |
265 | sir[0] = r[p];
266 | sir[1] = g[p];
267 | sir[2] = b[p];
268 |
269 | rinsum += sir[0];
270 | ginsum += sir[1];
271 | binsum += sir[2];
272 |
273 | rsum += rinsum;
274 | gsum += ginsum;
275 | bsum += binsum;
276 |
277 | stackpointer = (stackpointer + 1) % div;
278 | sir = stack[stackpointer];
279 |
280 | routsum += sir[0];
281 | goutsum += sir[1];
282 | boutsum += sir[2];
283 |
284 | rinsum -= sir[0];
285 | ginsum -= sir[1];
286 | binsum -= sir[2];
287 |
288 | yi += w;
289 | }
290 | }
291 | // bitmap.setPixels(pix, 0, w, 0, 0, w, h);
292 | // return (bitmap);
293 | return Bitmap.createBitmap(pix, 0, w, w, h, Bitmap.Config.ARGB_8888);
294 | }
295 |
296 | /**
297 | * 获取相片路径
298 | *
299 | * 参考: http://blog.csdn.net/tempersitu/article/details/20557383
300 | *
301 | * @param context
302 | * @param uri
303 | * @return
304 | */
305 | @SuppressLint("NewApi")
306 | public static String getPhotoPath(final Context context, final Uri uri) {
307 |
308 | final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
309 |
310 | // DocumentProvider
311 | if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
312 | // ExternalStorageProvider
313 | if (isExternalStorageDocument(uri)) {
314 | final String docId = DocumentsContract.getDocumentId(uri);
315 | final String[] split = docId.split(":");
316 | final String type = split[0];
317 |
318 | if ("primary".equalsIgnoreCase(type)) {
319 | return Environment.getExternalStorageDirectory() + "/" + split[1];
320 | }
321 |
322 | // TODO handle non-primary volumes
323 | }
324 | // DownloadsProvider
325 | else if (isDownloadsDocument(uri)) {
326 |
327 | final String id = DocumentsContract.getDocumentId(uri);
328 | final Uri contentUri = ContentUris.withAppendedId(
329 | Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
330 |
331 | return getDataColumn(context, contentUri, null, null);
332 | }
333 | // MediaProvider
334 | else if (isMediaDocument(uri)) {
335 | final String docId = DocumentsContract.getDocumentId(uri);
336 | final String[] split = docId.split(":");
337 | final String type = split[0];
338 |
339 | Uri contentUri = null;
340 | if ("image".equals(type)) {
341 | // 获取要查询的那张图片在 MediaProvider 中的 uri.
342 | contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
343 | } else if ("video".equals(type)) {
344 | contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
345 | } else if ("audio".equals(type)) {
346 | contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
347 | }
348 |
349 | final String selection = "_id=?";
350 | final String[] selectionArgs = new String[]{
351 | split[1]
352 | };
353 |
354 | return getDataColumn(context, contentUri, selection, selectionArgs);
355 | }
356 | }
357 | // MediaStore (and general)
358 | else if ("content".equalsIgnoreCase(uri.getScheme())) {
359 |
360 | // Return the remote address
361 | if (isGooglePhotosUri(uri))
362 | return uri.getLastPathSegment();
363 |
364 | return getDataColumn(context, uri, null, null);
365 | }
366 | // File
367 | else if ("file".equalsIgnoreCase(uri.getScheme())) {
368 | return uri.getPath();
369 | }
370 |
371 | return null;
372 | }
373 |
374 | /**
375 | * Get the value of the data column for this Uri. This is useful for
376 | * MediaStore Uris, and other file-based ContentProviders.
377 | *
378 | * @param context The context.
379 | * @param uri The Uri to query.
380 | * @param selection (Optional) Filter used in the query.
381 | * @param selectionArgs (Optional) Selection arguments used in the query.
382 | * @return The value of the _data column, which is typically a file path.
383 | */
384 | public static String getDataColumn(Context context, Uri uri, String selection,
385 | String[] selectionArgs) {
386 |
387 | Cursor cursor = null;
388 | final String column = "_data";
389 | final String[] projection = {
390 | column
391 | };
392 |
393 | try {
394 | cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
395 | null);
396 | if (cursor != null && cursor.moveToFirst()) {
397 | final int index = cursor.getColumnIndexOrThrow(column);
398 | return cursor.getString(index);
399 | }
400 | } finally {
401 | if (cursor != null)
402 | cursor.close();
403 | }
404 | return null;
405 | }
406 |
407 | /**
408 | * @param uri The Uri to check.
409 | * @return Whether the Uri authority is ExternalStorageProvider.
410 | */
411 | public static boolean isExternalStorageDocument(Uri uri) {
412 | return "com.android.externalstorage.documents".equals(uri.getAuthority());
413 | }
414 |
415 | /**
416 | * @param uri The Uri to check.
417 | * @return Whether the Uri authority is DownloadsProvider.
418 | */
419 | public static boolean isDownloadsDocument(Uri uri) {
420 | return "com.android.providers.downloads.documents".equals(uri.getAuthority());
421 | }
422 |
423 | /**
424 | * @param uri The Uri to check.
425 | * @return Whether the Uri authority is MediaProvider.
426 | */
427 | public static boolean isMediaDocument(Uri uri) {
428 | return "com.android.providers.media.documents".equals(uri.getAuthority());
429 | }
430 |
431 | /**
432 | * @param uri The Uri to check.
433 | * @return Whether the Uri authority is Google Photos.
434 | */
435 | public static boolean isGooglePhotosUri(Uri uri) {
436 | return "com.google.android.apps.photos.content".equals(uri.getAuthority());
437 | }
438 |
439 |
440 | }
441 |
--------------------------------------------------------------------------------
/imageloader-framework/src/main/java/com/lasingwu/baselibrary/IImageLoaderstrategy.java:
--------------------------------------------------------------------------------
1 | package com.lasingwu.baselibrary;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.NonNull;
5 | import android.view.View;
6 |
7 |
8 | /**
9 | * Created by Administrator on 2017/3/20 0020.
10 | */
11 |
12 | public interface IImageLoaderstrategy {
13 | void showImage(@NonNull ImageLoaderOptions options);
14 | void hideImage(@NonNull View view,int visiable);
15 | void cleanMemory(Context context);
16 | void pause(Context context);
17 | void resume(Context context);
18 | // 在application的oncreate中初始化
19 | void init(Context context,ImageLoaderConfig config);
20 | }
21 |
--------------------------------------------------------------------------------
/imageloader-framework/src/main/java/com/lasingwu/baselibrary/ImageLoader.java:
--------------------------------------------------------------------------------
1 | package com.lasingwu.baselibrary;
2 |
3 | import android.support.annotation.NonNull;
4 | import android.view.View;
5 |
6 | public class ImageLoader {
7 | public static ImageLoaderOptions.Builder createImageOptions(@NonNull View v, @NonNull String url){
8 | return new ImageLoaderOptions.Builder(v, url);
9 | }
10 | public static ImageLoaderOptions.Builder createImageOptions(@NonNull View v, @NonNull int resource){
11 | return new ImageLoaderOptions.Builder(v, resource);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/imageloader-framework/src/main/java/com/lasingwu/baselibrary/ImageLoaderConfig.java:
--------------------------------------------------------------------------------
1 | package com.lasingwu.baselibrary;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | /**
7 | * Created by wuzhao on 2018/2/23.
8 | */
9 |
10 | public class ImageLoaderConfig {
11 | private HashMap imageloaderMap;
12 | private long maxMemory=0;
13 | private ImageLoaderConfig(Builder builder){
14 | imageloaderMap=builder.imageloaderMap;
15 | maxMemory=builder.maxMemory;
16 | }
17 |
18 | public long getMaxMemory() {
19 | return maxMemory <= 0 ? 40*1024*1024 : maxMemory;
20 | }
21 |
22 | public HashMap getImageloaderMap() {
23 | return imageloaderMap;
24 | }
25 |
26 | public static class Builder{
27 | private HashMap imageloaderMap =new HashMap<>();
28 | private long maxMemory=40*1024*1024;
29 | public Builder(LoaderEnum emun,IImageLoaderstrategy loaderstrategy){
30 | imageloaderMap.put(emun,loaderstrategy);
31 | }
32 | public Builder addImageLodaer(LoaderEnum emun,IImageLoaderstrategy loaderstrategy){
33 | imageloaderMap.put(emun,loaderstrategy);
34 | return this;
35 | }
36 |
37 | /**
38 | *
39 | * @param maxMemory 单位为 Byte
40 | * @return
41 | */
42 | public Builder maxMemory(Long maxMemory){
43 | this.maxMemory = maxMemory;
44 | return this;
45 | }
46 | public ImageLoaderConfig build(){
47 | return new ImageLoaderConfig(this);
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/imageloader-framework/src/main/java/com/lasingwu/baselibrary/ImageLoaderManager.java:
--------------------------------------------------------------------------------
1 | package com.lasingwu.baselibrary;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.NonNull;
5 | import android.view.View;
6 |
7 | import java.util.HashMap;
8 | import java.util.Map;
9 |
10 |
11 | /**
12 | * Created by Administrator on 2017/3/22 0022.
13 | */
14 |
15 | public class ImageLoaderManager {
16 | private static final ImageLoaderManager INSTANCE=new ImageLoaderManager();
17 | private IImageLoaderstrategy loaderstrategy;
18 | private HashMap imageloaderMap=new HashMap<>();
19 | private LoaderEnum curLoader = null;
20 | private ImageLoaderManager(){
21 | }
22 | public static ImageLoaderManager getInstance(){
23 | return INSTANCE;
24 | }
25 |
26 | /*
27 | * 可创建默认的Options设置,假如不需要使用ImageView ,
28 | * 请自行new一个Imageview传入即可
29 | * 内部只需要获取Context
30 | */
31 | public static ImageLoaderOptions getDefaultOptions(@NonNull View container, @NonNull String url){
32 | return new ImageLoaderOptions.Builder(container,url).isCrossFade(true).build();
33 | }
34 |
35 | public void showImage(@NonNull ImageLoaderOptions options) {
36 | if (getLoaderstrategy(curLoader) != null) {
37 | getLoaderstrategy(curLoader).showImage(options);
38 | }
39 | }
40 | public void showImage(@NonNull ImageLoaderOptions options,LoaderEnum loaderEnum) {
41 | if (getLoaderstrategy(loaderEnum) != null) {
42 | getLoaderstrategy(loaderEnum).showImage(options);
43 | }
44 | }
45 |
46 | public void hideImage(@NonNull View view, int visiable) {
47 | if (getLoaderstrategy(curLoader) != null) {
48 | getLoaderstrategy(curLoader).hideImage(view,visiable);
49 | }
50 | }
51 |
52 |
53 | public void cleanMemory(Context context) {
54 | getLoaderstrategy(curLoader).cleanMemory(context);
55 | }
56 |
57 | public void pause(Context context) {
58 | if (getLoaderstrategy(curLoader) != null) {
59 | getLoaderstrategy(curLoader).pause(context);
60 | }
61 | }
62 |
63 | public void resume(Context context) {
64 | if (getLoaderstrategy(curLoader) != null) {
65 | getLoaderstrategy(curLoader).resume(context);
66 | }
67 | }
68 | public void setCurImageLoader(LoaderEnum loader) {
69 | curLoader=loader;
70 | }
71 | // 在application的oncreate中初始化
72 | public void init(Context context,ImageLoaderConfig config) {
73 | imageloaderMap = config.getImageloaderMap();
74 | for (Map.Entry entry : imageloaderMap.entrySet()) {
75 | if (entry.getValue() != null) {
76 | entry.getValue().init(context,config);
77 | }
78 |
79 | if (curLoader == null) {
80 | curLoader=entry.getKey();
81 | }
82 | }
83 |
84 |
85 | // loaderstrategy=new GlideImageLocader();
86 | // loaderstrategy.init(context);
87 | }
88 | private IImageLoaderstrategy getLoaderstrategy(LoaderEnum loaderEnum){
89 | return imageloaderMap.get(loaderEnum);
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/imageloader-framework/src/main/java/com/lasingwu/baselibrary/ImageLoaderOptions.java:
--------------------------------------------------------------------------------
1 | package com.lasingwu.baselibrary;
2 |
3 | import android.support.annotation.Dimension;
4 | import android.support.annotation.DrawableRes;
5 | import android.support.annotation.IntRange;
6 | import android.support.annotation.NonNull;
7 | import android.util.TypedValue;
8 | import android.view.View;
9 |
10 |
11 | /**
12 | * Created by Administrator on 2017/3/20 0020.
13 | */
14 | public class ImageLoaderOptions {
15 | private View viewContainer; // 图片容器
16 | private String url; // 图片地址
17 | private int resource; // 图片地址
18 | private int holderDrawable; // 设置展位图
19 | private ImageSize imageSize; //设置图片的大小
20 | private int errorDrawable; //是否展示加载错误的图片
21 | private boolean asGif=false; //是否作为gif展示
22 | private boolean isCrossFade=true; //是否渐变平滑的显示图片,默认为true
23 | private boolean isSkipMemoryCache = false; //是否跳过内存缓存
24 | private DiskCacheStrategy mDiskCacheStrategy = DiskCacheStrategy.DEFAULT; //磁盘缓存策略
25 | private boolean blurImage = false; //是否使用高斯模糊
26 | private LoaderResultCallBack loaderResultCallBack; // 返回图片加载结果
27 | private int blurValue; // 高斯模糊参数,越大越模糊
28 | private int imageRadius= 0;
29 | private boolean isCircle=false;
30 | private OnLoaderProgressCallback onLoaderProgressCallback;
31 | private ImageLoaderOptions (Builder builder ){
32 | this.asGif=builder.asGif;
33 | this.errorDrawable=builder.errorDrawable;
34 | this.holderDrawable=builder.holderDrawable;
35 | this.imageSize=builder.mImageSize;
36 | this.isCrossFade=builder.isCrossFade;
37 | this.isSkipMemoryCache=builder.isSkipMemoryCache;
38 | this.mDiskCacheStrategy=builder.mDiskCacheStrategy;
39 | this.url=builder.url;
40 | this.resource=builder.resource;
41 | this.viewContainer=builder.mViewContainer;
42 | this.blurImage=builder.blurImage;
43 | this.loaderResultCallBack=builder.loaderResultCallBack;
44 | this.isCircle=builder.isCircle;
45 | this.blurValue=builder.blurValue;
46 | this.imageRadius=builder.imageRadius;
47 | this.onLoaderProgressCallback=builder.onLoaderProgressCallback;
48 | }
49 |
50 | public LoaderResultCallBack getLoaderResultCallBack() {
51 | return loaderResultCallBack;
52 | }
53 |
54 |
55 |
56 | public int getBlurValue() {
57 | return blurValue;
58 | }
59 | public boolean needImageRadius() {
60 | return imageRadius>0;
61 | }
62 | public int getImageRadius() {
63 | return imageRadius;
64 | }
65 | public int getResource() {
66 | return resource;
67 | }
68 |
69 | public boolean isBlurImage() {
70 | return blurImage;
71 | }
72 |
73 | public View getViewContainer() {
74 | return viewContainer;
75 | }
76 |
77 | public String getUrl() {
78 | return url;
79 | }
80 |
81 | public boolean isCircle() {
82 | return isCircle;
83 | }
84 |
85 | public int getHolderDrawable() {
86 | return holderDrawable;
87 | }
88 |
89 |
90 | public OnLoaderProgressCallback getOnLoaderProgressCallback() {
91 | return onLoaderProgressCallback;
92 | }
93 |
94 | public ImageSize getImageSize() {
95 | return imageSize;
96 | }
97 |
98 |
99 | public int getErrorDrawable() {
100 | return errorDrawable;
101 | }
102 |
103 |
104 |
105 | public boolean isAsGif() {
106 | return asGif;
107 | }
108 |
109 |
110 | public boolean isCrossFade() {
111 | return isCrossFade;
112 | }
113 |
114 |
115 |
116 | public boolean isSkipMemoryCache() {
117 | return isSkipMemoryCache;
118 | }
119 |
120 |
121 |
122 | public DiskCacheStrategy getDiskCacheStrategy() {
123 | return mDiskCacheStrategy;
124 | }
125 | public static ImageLoaderOptions.Builder createImageOptions(@NonNull View v, @NonNull String url){
126 | return new ImageLoaderOptions.Builder(v, url);
127 | }
128 | public static ImageLoaderOptions.Builder createImageOptions(@NonNull View v, @NonNull int resource){
129 | return new ImageLoaderOptions.Builder(v, resource);
130 | }
131 | public void show(){
132 | ImageLoaderManager.getInstance().showImage(this);
133 | }
134 |
135 |
136 | public final static class Builder{
137 |
138 | private int holderDrawable=-1; // 设置展位图
139 | private View mViewContainer; // 图片容器
140 | private String url; // 图片地址
141 | private int resource = -1; // 图片地址
142 | private ImageSize mImageSize; //设置图片的大小
143 | private int errorDrawable=-1; //是否展示加载错误的图片
144 | private boolean asGif=false; //是否作为gif展示
145 | private boolean isCrossFade=false; //是否渐变平滑的显示图片
146 | private boolean isSkipMemoryCache = false; //是否跳过内存缓存
147 | private boolean blurImage = false; //是否使用高斯模糊
148 | private DiskCacheStrategy mDiskCacheStrategy = DiskCacheStrategy.DEFAULT; //磁盘缓存策略
149 | private LoaderResultCallBack loaderResultCallBack; // 返回图片加载结果
150 | private int blurValue=15; // 高斯模糊参数,越大越模糊
151 | private int imageRadius= 0;
152 | private boolean isCircle=false;
153 | private OnLoaderProgressCallback onLoaderProgressCallback;
154 |
155 |
156 | public Builder(@NonNull View v, @NonNull String url){
157 | this.url=url;
158 | this.mViewContainer=v;
159 | }
160 | public Builder(@NonNull View v, @NonNull int resource){
161 | this.resource=resource;
162 | this.mViewContainer=v;
163 | }
164 |
165 | public Builder placeholder(@DrawableRes int holderDrawable){
166 | this.holderDrawable=holderDrawable;
167 | return this;
168 | }
169 | public Builder isCrossFade(boolean isCrossFade){
170 | this.isCrossFade=isCrossFade;
171 | return this;
172 | }
173 | public Builder blurImage(boolean blurImage){
174 | this.blurImage=blurImage;
175 | return this;
176 | }
177 |
178 | public Builder isCircle(){
179 | this.isCircle=true;
180 | return this;
181 | }
182 |
183 |
184 | public Builder imageRadiusPx(@Dimension(unit = Dimension.PX) int rdius){
185 | this.imageRadius= (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, rdius, mViewContainer.getContext().getApplicationContext().getResources().getDisplayMetrics());
186 |
187 | return this;
188 | }
189 | public Builder imageRadiusDp(@Dimension(unit = Dimension.DP) int rdius){
190 | this.imageRadius= (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, rdius, mViewContainer.getContext().getApplicationContext().getResources().getDisplayMetrics());
191 | return this;
192 | }
193 |
194 | public Builder blurValue(@IntRange(from = 0) int blurvalue){
195 | this.blurValue=blurvalue;
196 | return this;
197 | }
198 | public Builder isSkipMemoryCache(boolean isSkipMemoryCache){
199 | this.isSkipMemoryCache=isSkipMemoryCache;
200 | return this;
201 |
202 | }
203 | public Builder override(int width,int height){
204 | this.mImageSize=new ImageSize(width,height);
205 | return this;
206 | }
207 | public Builder asGif(boolean asGif){
208 | this.asGif=asGif;
209 | return this;
210 | }
211 | public Builder error(@DrawableRes int errorDrawable){
212 | this.errorDrawable=errorDrawable;
213 | return this;
214 | }
215 | public Builder error(LoaderResultCallBack resultCallBack){
216 | this.loaderResultCallBack=resultCallBack;
217 | return this;
218 | }
219 |
220 | public Builder diskCacheStrategy(DiskCacheStrategy mDiskCacheStrategy){
221 | this.mDiskCacheStrategy=mDiskCacheStrategy;
222 | return this;
223 |
224 | }
225 |
226 | public ImageLoaderOptions build(){
227 | return new ImageLoaderOptions(this);
228 | }
229 |
230 | public Builder setOnLoaderProgressCallback(OnLoaderProgressCallback onLoaderProgressCallback) {
231 | this.onLoaderProgressCallback = onLoaderProgressCallback;
232 | return this;
233 | }
234 | }
235 |
236 | //对应重写图片size
237 | public final static class ImageSize{
238 | private int width=0;
239 | private int height=0;
240 | public ImageSize(int width, int heigh){
241 | this.width=width;
242 | this.height=heigh;
243 | }
244 |
245 | public int getHeight() {
246 | return height;
247 | }
248 |
249 | public int getWidth() {
250 | return width;
251 | }
252 | }
253 | //对应磁盘缓存策略
254 | public enum DiskCacheStrategy{
255 | All,NONE,SOURCE,RESULT,DEFAULT
256 | }
257 | }
258 |
--------------------------------------------------------------------------------
/imageloader-framework/src/main/java/com/lasingwu/baselibrary/LoaderEnum.java:
--------------------------------------------------------------------------------
1 | package com.lasingwu.baselibrary;
2 |
3 | /**
4 | * Created by wuzhao on 2018/2/3.
5 | */
6 |
7 | public enum LoaderEnum {
8 | GLIDE,FRESCO,OTHER,WHATEVER
9 | }
10 |
--------------------------------------------------------------------------------
/imageloader-framework/src/main/java/com/lasingwu/baselibrary/LoaderResultCallBack.java:
--------------------------------------------------------------------------------
1 | package com.lasingwu.baselibrary;
2 |
3 | /**
4 | * Created by wuzhao on 2018/1/14.
5 | */
6 |
7 | public interface LoaderResultCallBack {
8 | void onSucc();
9 | void onFail();
10 | }
11 |
--------------------------------------------------------------------------------
/imageloader-framework/src/main/java/com/lasingwu/baselibrary/OnLoaderProgressCallback.java:
--------------------------------------------------------------------------------
1 | package com.lasingwu.baselibrary;
2 |
3 | public interface OnLoaderProgressCallback {
4 | /**
5 | *
6 | * @param progress 0-10000
7 | */
8 | void onProgress(int progress);
9 | }
10 |
--------------------------------------------------------------------------------
/imageloader-framework/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BaseLibrary
3 |
4 |
--------------------------------------------------------------------------------
/imageloader-framework/src/test/java/com/lasingwu/baselibrary/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.lasingwu.baselibrary;
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', ':fresco', ':glide', ':imageloader-framework'
2 |
--------------------------------------------------------------------------------