├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── menu
│ │ │ │ └── menu_main.xml
│ │ │ └── layout
│ │ │ │ ├── content_main.xml
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── sunzxy
│ │ │ │ └── frescoplus
│ │ │ │ ├── App.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── sunzxy
│ │ │ └── frescoplus
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── sunzxy
│ │ └── frescoplus
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── frescopluslib
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── sunzxy
│ │ │ │ └── frescopluslib
│ │ │ │ ├── request
│ │ │ │ ├── callback
│ │ │ │ │ ├── FPFetchCallback.java
│ │ │ │ │ ├── FPCacheCallback.java
│ │ │ │ │ └── FPLoadCallback.java
│ │ │ │ ├── supplier
│ │ │ │ │ ├── BaseProcessorSupplier.java
│ │ │ │ │ ├── FPProgressBarDrawable.java
│ │ │ │ │ └── FetchImageControllerListenerSupplier.java
│ │ │ │ ├── Fetcher.java
│ │ │ │ └── impl
│ │ │ │ │ ├── AbsBaseFetcher.java
│ │ │ │ │ └── FrescoPlusFetcher.java
│ │ │ │ ├── exception
│ │ │ │ ├── FPNullPointerException.java
│ │ │ │ ├── FPIllegalArgumentException.java
│ │ │ │ └── FPRuntimeException.java
│ │ │ │ ├── core
│ │ │ │ ├── FrescoPriority.java
│ │ │ │ ├── FrescoUri.java
│ │ │ │ ├── DefaultConfigCentre.java
│ │ │ │ ├── FrescoPlusCore.java
│ │ │ │ ├── FrescoCacheStatsTracker.java
│ │ │ │ ├── FrescoPlusConfig.java
│ │ │ │ └── FrescoCacheManager.java
│ │ │ │ ├── logger
│ │ │ │ ├── FrescoLogger.java
│ │ │ │ └── FrescoLogTracker.java
│ │ │ │ ├── widget
│ │ │ │ └── FrescoPlusView.java
│ │ │ │ ├── util
│ │ │ │ ├── DiskCacheUtil.java
│ │ │ │ ├── ParamCheckUtil.java
│ │ │ │ └── UriUtil.java
│ │ │ │ └── FrescoPlusInitializer.java
│ │ └── AndroidManifest.xml
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── sunzxy
│ │ └── frescopluslib
│ │ └── ApplicationTest.java
├── build.gradle
└── proguard-rules.pro
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── README.md
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/frescopluslib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':frescopluslib'
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sunzxyong/FrescoPlus/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/frescopluslib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FrescoPlusLib
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sunzxyong/FrescoPlus/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sunzxyong/FrescoPlus/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sunzxyong/FrescoPlus/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sunzxyong/FrescoPlus/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sunzxyong/FrescoPlus/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FrescoPlus
3 | Settings
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
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-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 |
7 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/request/callback/FPFetchCallback.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.request.callback;
2 |
3 | /**
4 | * Created by zhengxiaoyong on 16/1/10.
5 | */
6 | public interface FPFetchCallback {
7 |
8 | void onSuccess(T result);
9 |
10 | void onFailure(Throwable throwable);
11 | }
12 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/request/callback/FPCacheCallback.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.request.callback;
2 |
3 | /**
4 | * Created by zhengxiaoyong on 16/1/12.
5 | */
6 | public interface FPCacheCallback {
7 | /**
8 | * @param result The result of the image was found in disk cache.
9 | */
10 | void onResult(T result);
11 | }
12 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/exception/FPNullPointerException.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.exception;
2 |
3 | /**
4 | * Created by zhengxiaoyong on 16/1/9.
5 | */
6 | public class FPNullPointerException extends NullPointerException {
7 |
8 | public FPNullPointerException(String detailMessage) {
9 | super(detailMessage);
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/exception/FPIllegalArgumentException.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.exception;
2 |
3 | /**
4 | * Created by zhengxiaoyong on 16/1/9.
5 | */
6 | public class FPIllegalArgumentException extends IllegalArgumentException {
7 | public FPIllegalArgumentException(String detailMessage) {
8 | super(detailMessage);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/test/java/com/sunzxy/frescoplus/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescoplus;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/request/callback/FPLoadCallback.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.request.callback;
2 |
3 | import android.net.Uri;
4 |
5 | /**
6 | * Created by zhengxiaoyong on 16/1/10.
7 | */
8 | public interface FPLoadCallback {
9 |
10 | void onSuccess(Uri uri, T result);
11 |
12 | void onFailure(Uri uri, Throwable throwable);
13 |
14 | void onCancel(Uri uri);
15 | }
16 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/core/FrescoPriority.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.core;
2 |
3 | /**
4 | * Created by zhengxiaoyong on 16/1/10.
5 | */
6 | public final class FrescoPriority {
7 | /**
8 | * Will be the first to perform.
9 | */
10 | public static final int HIGH = 0x101;
11 | /**
12 | * after the HIGH priority.
13 | */
14 | public static final int LOW = 0x100;
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/sunzxy/frescoplus/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescoplus;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/frescopluslib/src/androidTest/java/com/sunzxy/frescopluslib/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/exception/FPRuntimeException.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.exception;
2 |
3 | /**
4 | * Created by zhengxiaoyong on 16/1/10.
5 | */
6 | public class FPRuntimeException extends RuntimeException {
7 | public FPRuntimeException(String detailMessage) {
8 | super(detailMessage);
9 | }
10 |
11 | public FPRuntimeException(String detailMessage, Throwable throwable) {
12 | super(detailMessage, throwable);
13 | initCause(throwable);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Log Files
26 | *.log
27 |
28 | # Android Studio Navigation editor temp files
29 | .navigation/
30 |
31 | # Android Studio captures folder
32 | captures/
33 | *.iml
34 | gradlew
35 | gradlew.bat
36 | .idea
37 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/core/FrescoUri.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.core;
2 |
3 | /**
4 | * Created by zhengxiaoyong on 16/1/9.
5 | */
6 | public final class FrescoUri {
7 | public static final String HTTP_SCHEME = "http";
8 | public static final String HTTPS_SCHEME = "https";
9 | public static final String LOCAL_FILE_SCHEME = "file";
10 | public static final String LOCAL_CONTENT_SCHEME = "content";
11 | public static final String LOCAL_ASSET_SCHEME = "asset";
12 | public static final String LOCAL_RESOURCE_SCHEME = "res";
13 | public static final String DATA_SCHEME = "data";
14 | }
15 |
--------------------------------------------------------------------------------
/frescopluslib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | android {
3 | compileSdkVersion 23
4 | buildToolsVersion "23.0.2"
5 | defaultConfig {
6 | minSdkVersion 15
7 | targetSdkVersion 23
8 | versionCode 1
9 | versionName "1.0"
10 | }
11 | buildTypes {
12 | release {
13 | minifyEnabled false
14 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
15 | }
16 | }
17 | }
18 |
19 | dependencies {
20 | compile fileTree(include: ['*.jar'], dir: 'libs')
21 | compile 'com.facebook.fresco:fresco:0.8.1'
22 | }
23 |
24 |
25 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/request/supplier/BaseProcessorSupplier.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.request.supplier;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import com.facebook.imagepipeline.request.BasePostprocessor;
6 |
7 | /**
8 | * Created by zhengxiaoyong on 16/1/10.
9 | */
10 | public abstract class BaseProcessorSupplier extends BasePostprocessor {
11 | @Override
12 | public String getName() {
13 | return "BaseProcessorSupplier";
14 | }
15 |
16 | @Override
17 | public void process(Bitmap bitmap) {
18 | super.process(bitmap);
19 | processBitmap(bitmap);
20 | }
21 |
22 | public abstract void processBitmap(Bitmap bitmap);
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/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 /Users/Sunzxyong/Library/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 |
--------------------------------------------------------------------------------
/frescopluslib/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 /Users/Sunzxyong/Library/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 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 'Google Inc.:Google APIs:23'
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.sunzxy.frescoplus"
9 | minSdkVersion 15
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.+'
26 | compile 'com.android.support:design:23.+'
27 | compile project(':frescopluslib')
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunzxy/frescoplus/App.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescoplus;
2 |
3 | import android.app.Application;
4 | import android.graphics.Bitmap;
5 |
6 | import com.sunzxy.frescopluslib.FrescoPlusInitializer;
7 | import com.sunzxy.frescopluslib.core.FrescoPlusConfig;
8 |
9 | /**
10 | * Created by zhengxiaoyong on 16/1/29.
11 | */
12 | public class App extends Application {
13 | @Override
14 | public void onCreate() {
15 | super.onCreate();
16 |
17 | FrescoPlusConfig config = FrescoPlusConfig.newBuilder(this)
18 | .setDebug(true)
19 | .setTag("Sunzxyong")
20 | .setBitmapConfig(Bitmap.Config.RGB_565)
21 | .setDiskCacheDir(this.getCacheDir())
22 | .setMaxDiskCacheSize(80)
23 | .build();
24 | FrescoPlusInitializer.getInstance().init(this,config);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/request/Fetcher.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.request;
2 |
3 | import android.graphics.Bitmap;
4 | import android.net.Uri;
5 | import android.support.annotation.DrawableRes;
6 |
7 | import com.facebook.imagepipeline.image.ImageInfo;
8 | import com.sunzxy.frescopluslib.request.callback.FPFetchCallback;
9 | import com.sunzxy.frescopluslib.request.callback.FPLoadCallback;
10 |
11 | /**
12 | * Created by zhengxiaoyong on 16/1/10.
13 | */
14 | public interface Fetcher {
15 |
16 | void fetch(T view, Uri uri);
17 |
18 | void fetch(T view, String uriPath);
19 |
20 | void fetch(T view, @DrawableRes int resId);
21 |
22 | void fetch(T view, @DrawableRes int resId, FPFetchCallback callback);
23 |
24 | void fetch(T view, Uri uri, FPFetchCallback callback);
25 |
26 | void fetch(T view, String uriPath, FPFetchCallback callback);
27 |
28 | void fetch(Uri uri, FPLoadCallback callback);
29 |
30 | void fetch(String uriPath, FPLoadCallback callback);
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
21 |
22 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/logger/FrescoLogger.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.logger;
2 |
3 |
4 | import com.sunzxy.frescopluslib.FrescoPlusInitializer;
5 |
6 | /**
7 | * Created by zhengxiaoyong on 16/1/12.
8 | */
9 | public class FrescoLogger {
10 | private static volatile FrescoLogger instance;
11 |
12 | private FrescoLogger() {
13 | }
14 |
15 | public static FrescoLogger getLogger() {
16 | if (instance == null) {
17 | synchronized (FrescoLogger.class) {
18 | if (instance == null) {
19 | instance = new FrescoLogger();
20 | }
21 | }
22 | }
23 | return instance;
24 | }
25 |
26 | public void log(Object t) {
27 | boolean isDebug = FrescoPlusInitializer.getInstance().isDebug();
28 | if (isDebug) {
29 | FrescoLogTracker.d(String.valueOf(t));
30 | }
31 | }
32 |
33 | public void log(String tag, Object t) {
34 | boolean isDebug = FrescoPlusInitializer.getInstance().isDebug();
35 | if (isDebug) {
36 | FrescoLogTracker.d(FrescoLogTracker.wrapTagIfNull(tag), String.valueOf(t));
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/request/supplier/FPProgressBarDrawable.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.request.supplier;
2 |
3 | import android.graphics.Color;
4 |
5 | import com.facebook.drawee.drawable.ProgressBarDrawable;
6 |
7 | /**
8 | * Created by zhengxiaoyong on 16/1/11.
9 | */
10 | public class FPProgressBarDrawable extends ProgressBarDrawable {
11 | private int mProgressBarColor = Color.parseColor("#FDD11A");
12 | private int mProgressBarPadding = 0;
13 | private int mProgressBarWidth = 15;
14 |
15 | public FPProgressBarDrawable() {
16 | this(-1);
17 | }
18 |
19 | public FPProgressBarDrawable(int progressBarColor) {
20 | setColor(progressBarColor == -1 ? mProgressBarColor : progressBarColor);
21 | setPadding(mProgressBarPadding);
22 | setBarWidth(mProgressBarWidth);
23 | }
24 |
25 | @Override
26 | public void setColor(int color) {
27 | super.setColor(color);
28 | }
29 |
30 | @Override
31 | public void setPadding(int padding) {
32 | super.setPadding(padding);
33 | }
34 |
35 | @Override
36 | public void setBarWidth(int barWidth) {
37 | super.setBarWidth(barWidth);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/widget/FrescoPlusView.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.widget;
2 |
3 |
4 | import android.content.Context;
5 | import android.net.Uri;
6 | import android.support.annotation.DrawableRes;
7 | import android.util.AttributeSet;
8 |
9 | import com.facebook.drawee.view.SimpleDraweeView;
10 | import com.sunzxy.frescopluslib.request.impl.FrescoPlusFetcher;
11 | import com.sunzxy.frescopluslib.util.UriUtil;
12 |
13 |
14 | /**
15 | * Created by zhengxiaoyong on 16/1/5.
16 | */
17 | public class FrescoPlusView extends SimpleDraweeView {
18 |
19 | public FrescoPlusView(Context context) {
20 | super(context);
21 | }
22 |
23 | public FrescoPlusView(Context context, AttributeSet attrs) {
24 | super(context, attrs);
25 | }
26 |
27 | public FrescoPlusView(Context context, AttributeSet attrs, int defStyle) {
28 | super(context, attrs, defStyle);
29 | }
30 |
31 | public final void showImage(Uri uri) {
32 | FrescoPlusFetcher.newFetcher().build().fetch(this, uri);
33 | }
34 |
35 | public final void showImage(String uriPath) {
36 | showImage(UriUtil.parseUri(uriPath));
37 | }
38 |
39 | public final void showImage(@DrawableRes int resId) {
40 | FrescoPlusFetcher.newFetcher().build().fetch(this, resId);
41 | }
42 |
43 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/core/DefaultConfigCentre.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.core;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import com.facebook.drawee.drawable.ScalingUtils;
6 | import com.facebook.imagepipeline.request.ImageRequest;
7 |
8 | /**
9 | * Created by zhengxiaoyong on 16/1/9.
10 | */
11 | public class DefaultConfigCentre {
12 |
13 | private DefaultConfigCentre() {
14 | }
15 | public static final boolean DEFAULT_IS_DEBUG = false;
16 |
17 | public static final String DEFAULT_TAG = "fp_image";
18 |
19 | public static final int KB = 1024;
20 |
21 | public static final int MB = KB << 10;
22 |
23 | public static final Bitmap.Config DEFAULT_BITMAP_CONFIG = Bitmap.Config.ARGB_8888;
24 |
25 | public static final int DEFAULT_MAX_DISK_CACHE_SIZE = 60 * MB;
26 |
27 | public static final int DEFAULT_LOW_SPACE_DISK_CACHE_SIZE = 20 * MB;
28 |
29 | public static final int DEFAULT_VERY_LOW_SPACE_DISK_CACHE_SIZE = 8 * MB;
30 |
31 | public static final String DEFAULT_DISK_CACHE_DIR_NAME = "FPCache";
32 |
33 | public static final int DEFAULT_FADE_DURATION = 300;
34 |
35 | public static final ScalingUtils.ScaleType DEFAULT_SCALE_TYPE = ScalingUtils.ScaleType.CENTER_CROP;
36 |
37 | public static final float DEFAULT_RADIUS = 0;
38 |
39 | public static final int DEFAULT_PRIORITY = FrescoPriority.HIGH;
40 |
41 | public static final boolean DEFAULT_AUTO_ROTATE = false;
42 |
43 | public static final ImageRequest.RequestLevel DEFAULT_REQUEST_LEVEL = ImageRequest.RequestLevel.FULL_FETCH;
44 |
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/util/DiskCacheUtil.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.util;
2 |
3 | import android.annotation.TargetApi;
4 | import android.app.Application;
5 | import android.content.Context;
6 | import android.os.Build;
7 | import android.os.Environment;
8 | import android.os.StatFs;
9 |
10 | import com.sunzxy.frescopluslib.exception.FPNullPointerException;
11 |
12 | import java.io.File;
13 |
14 | /**
15 | * Created by zhengxiaoyong on 16/1/12.
16 | */
17 | public class DiskCacheUtil {
18 | public static File getDiskLruCacheDir(Context context) {
19 | if (context == null)
20 | throw new FPNullPointerException("context can not be null");
21 | if (!(context instanceof Application))
22 | context = context.getApplicationContext();
23 | File cacheDir = null;
24 | if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
25 | || !Environment.isExternalStorageRemovable()) {
26 | cacheDir = getSDFreeSize() > 100 ? context.getExternalCacheDir() : context.getCacheDir();
27 | } else {
28 | cacheDir = context.getCacheDir();
29 | }
30 | return cacheDir;
31 | }
32 |
33 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
34 | public static long getSDFreeSize() {
35 | File path = Environment.getExternalStorageDirectory();
36 | if (path != null && path.exists() && path.isDirectory()) {
37 | StatFs sf = new StatFs(path.getPath());
38 | long blockSize = sf.getBlockSizeLong();
39 | long freeBlocks = sf.getAvailableBlocksLong();
40 | return (freeBlocks * blockSize) / 1024 / 1024;
41 | }
42 | return -1;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/request/supplier/FetchImageControllerListenerSupplier.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.request.supplier;
2 |
3 | import android.graphics.drawable.Animatable;
4 |
5 | import com.facebook.drawee.controller.BaseControllerListener;
6 | import com.facebook.imagepipeline.image.ImageInfo;
7 | import com.sunzxy.frescopluslib.logger.FrescoLogger;
8 | import com.sunzxy.frescopluslib.request.callback.FPFetchCallback;
9 |
10 | /**
11 | * Created by zhengxiaoyong on 16/1/10.
12 | */
13 | public class FetchImageControllerListenerSupplier extends BaseControllerListener {
14 | private FPFetchCallback FPFetchCallback;
15 |
16 | private FetchImageControllerListenerSupplier(FPFetchCallback callback) {
17 | this.FPFetchCallback = callback;
18 | }
19 |
20 | public static FetchImageControllerListenerSupplier newInstance(FPFetchCallback callback) {
21 | return new FetchImageControllerListenerSupplier(callback);
22 | }
23 |
24 | @Override
25 | public void onFailure(String id, Throwable throwable) {
26 | super.onFailure(id, throwable);
27 | if(FPFetchCallback ==null)
28 | return ;
29 | FrescoLogger.getLogger().log(throwable.getLocalizedMessage());
30 | FPFetchCallback.onFailure(throwable);
31 | }
32 |
33 | @Override
34 | public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
35 | super.onFinalImageSet(id, imageInfo, animatable);
36 | if(FPFetchCallback ==null || imageInfo == null)
37 | return;
38 | FrescoLogger.getLogger().log("Bitmap:[height="+imageInfo.getHeight()+",width="+imageInfo.getWidth()+"]");
39 | FPFetchCallback.onSuccess(imageInfo);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/core/FrescoPlusCore.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.core;
2 |
3 | import android.content.Context;
4 |
5 | import com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder;
6 | import com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilderSupplier;
7 | import com.facebook.imagepipeline.core.ImagePipeline;
8 | import com.facebook.imagepipeline.core.ImagePipelineConfig;
9 | import com.facebook.imagepipeline.core.ImagePipelineFactory;
10 | import com.sunzxy.frescopluslib.util.ParamCheckUtil;
11 | import com.sunzxy.frescopluslib.widget.FrescoPlusView;
12 |
13 | /**
14 | * Created by zhengxiaoyong on 16/1/9.
15 | */
16 | public class FrescoPlusCore {
17 | private static PipelineDraweeControllerBuilderSupplier mDraweeControllerBuilderSupplier;
18 |
19 | public static void init(Context context,ImagePipelineConfig imagePipelineConfig){
20 | ImagePipelineFactory.initialize(imagePipelineConfig);
21 | mDraweeControllerBuilderSupplier = new PipelineDraweeControllerBuilderSupplier(context);
22 | FrescoPlusView.initialize(mDraweeControllerBuilderSupplier);
23 | }
24 | /**
25 | * @return create a new DraweeControllerBuilder instance.
26 | */
27 | public static PipelineDraweeControllerBuilder newDraweeControllerBuilder() {
28 | ParamCheckUtil.checkNotNull(mDraweeControllerBuilderSupplier,"FrescoPlusCore not initialize");
29 | return mDraweeControllerBuilderSupplier.get();
30 | }
31 |
32 | public static ImagePipelineFactory getImagePipelineFactory() {
33 | return ImagePipelineFactory.getInstance();
34 | }
35 |
36 | /**
37 | * @return get ImagePipeline instance from ImagePipelineFactory.
38 | */
39 | public static ImagePipeline getImagePipeline() {
40 | return getImagePipelineFactory().getImagePipeline();
41 | }
42 |
43 | /**
44 | * shut down .
45 | */
46 | public static void shutDownDraweeControllerBuilderSupplier(){
47 | mDraweeControllerBuilderSupplier = null;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/request/impl/AbsBaseFetcher.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.request.impl;
2 |
3 | import android.graphics.Bitmap;
4 | import android.net.Uri;
5 | import android.support.annotation.DrawableRes;
6 |
7 | import com.facebook.imagepipeline.image.ImageInfo;
8 | import com.sunzxy.frescopluslib.request.Fetcher;
9 | import com.sunzxy.frescopluslib.request.callback.FPFetchCallback;
10 | import com.sunzxy.frescopluslib.request.callback.FPLoadCallback;
11 | import com.sunzxy.frescopluslib.util.ParamCheckUtil;
12 | import com.sunzxy.frescopluslib.util.UriUtil;
13 |
14 | /**
15 | * Created by zhengxiaoyong on 16/1/10.
16 | */
17 | public abstract class AbsBaseFetcher implements Fetcher {
18 | @Override
19 | public void fetch(T view, Uri uri) {
20 | ParamCheckUtil.checkNotNull(view);
21 | ParamCheckUtil.checkUriIsLegal(uri);
22 | beforeExecute(uri);
23 | }
24 |
25 | @Override
26 | public void fetch(T view, String uriPath) {
27 | fetch(view, UriUtil.parseUri(uriPath));
28 | }
29 |
30 | @Override
31 | public void fetch(T view, Uri uri, FPFetchCallback callback) {
32 | ParamCheckUtil.checkNotNull(view);
33 | ParamCheckUtil.checkUriIsLegal(uri);
34 | beforeExecute(uri);
35 | }
36 |
37 | @Override
38 | public void fetch(T view, String uriPath, FPFetchCallback callback) {
39 | fetch(view,UriUtil.parseUri(uriPath),callback);
40 | }
41 |
42 | @Override
43 | public void fetch(T view, @DrawableRes int resId) {
44 | fetch(view,UriUtil.parseUriFromResId(resId));
45 | }
46 |
47 | @Override
48 | public void fetch(T view, @DrawableRes int resId, FPFetchCallback callback) {
49 | fetch(view,UriUtil.parseUriFromResId(resId),callback);
50 | }
51 |
52 | @Override
53 | public void fetch(Uri uri, FPLoadCallback callback) {
54 | ParamCheckUtil.checkUriIsLegal(uri);
55 | beforeExecute(uri);
56 | }
57 |
58 | @Override
59 | public void fetch(String uriPath, FPLoadCallback callback) {
60 | fetch(UriUtil.parseUri(uriPath), callback);
61 | }
62 |
63 | protected abstract Object beforeExecute(Uri uri);
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/core/FrescoCacheStatsTracker.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.core;
2 |
3 | import com.facebook.imagepipeline.cache.CountingMemoryCache;
4 | import com.facebook.imagepipeline.cache.ImageCacheStatsTracker;
5 | import com.sunzxy.frescopluslib.logger.FrescoLogger;
6 |
7 | /**
8 | * Created by zhengxiaoyong on 16/1/5.
9 | */
10 | public class FrescoCacheStatsTracker implements ImageCacheStatsTracker {
11 | private static volatile FrescoCacheStatsTracker instance;
12 | private FrescoCacheStatsTracker() {
13 | }
14 |
15 | public static FrescoCacheStatsTracker getInstance() {
16 | if (instance == null) {
17 | synchronized (FrescoCacheStatsTracker.class) {
18 | if (instance == null) {
19 | instance = new FrescoCacheStatsTracker();
20 | }
21 | }
22 | }
23 | return instance;
24 | }
25 |
26 | @Override
27 | public void onBitmapCachePut() {
28 | FrescoLogger.getLogger().log("onBitmapCachePut");
29 | }
30 |
31 | @Override
32 | public void onBitmapCacheHit() {
33 | FrescoLogger.getLogger().log("onBitmapCacheHit");
34 | }
35 |
36 | @Override
37 | public void onBitmapCacheMiss() {
38 | FrescoLogger.getLogger().log("onBitmapCacheMiss");
39 | }
40 |
41 | @Override
42 | public void onMemoryCachePut() {
43 | FrescoLogger.getLogger().log("onMemoryCachePut");
44 | }
45 |
46 | @Override
47 | public void onMemoryCacheHit() {
48 | FrescoLogger.getLogger().log("onMemoryCacheHit");
49 | }
50 |
51 | @Override
52 | public void onMemoryCacheMiss() {
53 | FrescoLogger.getLogger().log("onMemoryCacheMiss");
54 | }
55 |
56 | @Override
57 | public void onStagingAreaHit() {
58 | FrescoLogger.getLogger().log("onStagingAreaHit");
59 | }
60 |
61 | @Override
62 | public void onStagingAreaMiss() {
63 | FrescoLogger.getLogger().log("onStagingAreaMiss");
64 | }
65 |
66 | @Override
67 | public void onDiskCacheHit() {
68 | FrescoLogger.getLogger().log("onDiskCacheHit");
69 | }
70 |
71 | @Override
72 | public void onDiskCacheMiss() {
73 | FrescoLogger.getLogger().log("onDiskCacheMiss");
74 | }
75 |
76 | @Override
77 | public void onDiskCacheGetFail() {
78 | FrescoLogger.getLogger().log("onDiskCacheGetFail");
79 | }
80 |
81 | @Override
82 | public void registerBitmapMemoryCache(CountingMemoryCache, ?> bitmapMemoryCache) {
83 |
84 | }
85 |
86 | @Override
87 | public void registerEncodedMemoryCache(CountingMemoryCache, ?> encodedMemoryCache) {
88 |
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/util/ParamCheckUtil.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.util;
2 |
3 | import android.net.Uri;
4 | import android.support.annotation.Nullable;
5 | import android.text.TextUtils;
6 |
7 | import com.sunzxy.frescopluslib.core.FrescoUri;
8 | import com.sunzxy.frescopluslib.exception.FPIllegalArgumentException;
9 | import com.sunzxy.frescopluslib.exception.FPNullPointerException;
10 | import com.sunzxy.frescopluslib.exception.FPRuntimeException;
11 |
12 |
13 | /**
14 | * Created by zhengxiaoyong on 16/1/5.
15 | */
16 | public final class ParamCheckUtil {
17 | private ParamCheckUtil() {
18 | }
19 |
20 |
21 | public static T checkNotNull(T reference) {
22 | if (reference == null)
23 | throw new FPNullPointerException("The reference is null!");
24 | return reference;
25 | }
26 |
27 | public static T checkNotNull(T reference, @Nullable Object errorMessage) {
28 | if (reference == null) {
29 | throw new FPNullPointerException(String.valueOf(errorMessage));
30 | }
31 | return reference;
32 | }
33 |
34 | public static void checkUriIsLegal(Uri uri) {
35 | ParamCheckUtil.checkNotNull(uri, "uri is null");
36 | String scheme = UriUtil.getSchemeOrNull(uri);
37 | if (TextUtils.isEmpty(scheme))
38 | throw new FPIllegalArgumentException("uri is illegal,cause:This scheme is null or empty");
39 | switch (scheme) {
40 | case FrescoUri.HTTP_SCHEME:
41 | case FrescoUri.HTTPS_SCHEME:
42 | case FrescoUri.LOCAL_FILE_SCHEME:
43 | case FrescoUri.LOCAL_ASSET_SCHEME:
44 | case FrescoUri.LOCAL_CONTENT_SCHEME:
45 | case FrescoUri.LOCAL_RESOURCE_SCHEME:
46 | case FrescoUri.DATA_SCHEME:
47 | break;
48 | default:
49 | throw new FPIllegalArgumentException("uri is illegal,cause:This scheme not supported");
50 | }
51 | validate(uri);
52 | }
53 | private static void validate(Uri uri) {
54 | if (UriUtil.isLocalResourceUri(uri)) {
55 | if (!uri.isAbsolute()) {
56 | throw new FPRuntimeException("Resource URI path must be absolute.");
57 | }
58 | if (uri.getPath().isEmpty()) {
59 | throw new FPRuntimeException("Resource URI must not be empty");
60 | }
61 | try {
62 | Integer.parseInt(uri.getPath().substring(1));
63 | } catch (NumberFormatException ignored) {
64 | throw new FPRuntimeException("Resource URI path must be a resource id.",ignored.getCause());
65 | }
66 | }
67 | if (UriUtil.isLocalAssetUri(uri) && !uri.isAbsolute()) {
68 | throw new FPRuntimeException("Asset URI path must be absolute.");
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/logger/FrescoLogTracker.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.logger;
2 |
3 | import android.text.TextUtils;
4 | import android.util.Log;
5 |
6 | import com.sunzxy.frescopluslib.FrescoPlusInitializer;
7 |
8 |
9 | /**
10 | * Created by zhengxiaoyong on 16/1/12.
11 | */
12 | public class FrescoLogTracker {
13 |
14 | public static void d(String message) {
15 | Log.d(FrescoPlusInitializer.getInstance().getLogTag(), packMessage(message));
16 | }
17 |
18 | public static void d(String tag, String message) {
19 | Log.d(wrapTagIfNull(tag), packMessage(message));
20 | }
21 |
22 | public static void v(String message) {
23 | Log.v(FrescoPlusInitializer.getInstance().getLogTag(), packMessage(message));
24 | }
25 |
26 | public static void v(String tag, String message) {
27 | Log.v(wrapTagIfNull(tag), packMessage(message));
28 | }
29 |
30 | public static void i(String message) {
31 | Log.i(FrescoPlusInitializer.getInstance().getLogTag(), packMessage(message));
32 | }
33 |
34 | public static void i(String tag, String message) {
35 | Log.i(wrapTagIfNull(tag), packMessage(message));
36 | }
37 |
38 | public static void e(String message) {
39 | Log.e(FrescoPlusInitializer.getInstance().getLogTag(), packMessage(message));
40 | }
41 |
42 | public static void e(String tag, String message) {
43 | Log.e(wrapTagIfNull(tag), packMessage(message));
44 | }
45 |
46 | public static void w(String message) {
47 | Log.w(FrescoPlusInitializer.getInstance().getLogTag(), packMessage(message));
48 | }
49 |
50 | public static void w(String tag, String message) {
51 | Log.w(wrapTagIfNull(tag), packMessage(message));
52 | }
53 |
54 | public static String wrapTagIfNull(String tag) {
55 | return TextUtils.isEmpty(tag) ? FrescoPlusInitializer.getInstance().getLogTag() : tag;
56 | }
57 | private static StackTraceElement generateSTE(Thread thread,int index){
58 | return thread.getStackTrace()[index];
59 | }
60 | private static String packMessage(String message) {
61 | StringBuilder builder = new StringBuilder();
62 | Thread thread = Thread.currentThread();
63 | StackTraceElement element = generateSTE(thread,6);
64 | if (element == null)
65 | return ""+message;
66 | String threadName = thread.getName();
67 | builder.append("ThreadName:")
68 | .append(threadName)
69 | .append("->")
70 | .append(element.getClassName())
71 | .append("->")
72 | .append(element.getMethodName())
73 | .append("[line:")
74 | .append(element.getLineNumber())
75 | .append("],message:")
76 | .append(message);
77 | return builder.toString();
78 | }
79 | }
80 |
81 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/util/UriUtil.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.util;
2 |
3 | import android.net.Uri;
4 | import android.support.annotation.DrawableRes;
5 |
6 | import com.sunzxy.frescopluslib.core.FrescoUri;
7 | import com.sunzxy.frescopluslib.exception.FPRuntimeException;
8 |
9 |
10 | /**
11 | * Created by zhengxiaoyong on 16/1/9.
12 | */
13 | public class UriUtil {
14 |
15 | /**
16 | * Check if uri represents network resource
17 | *
18 | * @param uri uri to check
19 | * @return true if uri's scheme is equal to "http" or "https"
20 | */
21 | public static boolean isNetworkUri(Uri uri) {
22 | final String scheme = getSchemeOrNull(uri);
23 | return FrescoUri.HTTPS_SCHEME.equals(scheme) || FrescoUri.HTTP_SCHEME.equals(scheme);
24 | }
25 |
26 | /**
27 | * Check if uri represents local file
28 | *
29 | * @param uri uri to check
30 | * @return true if uri's scheme is equal to "file"
31 | */
32 | public static boolean isLocalFileUri(Uri uri) {
33 | final String scheme = getSchemeOrNull(uri);
34 | return FrescoUri.LOCAL_FILE_SCHEME.equals(scheme);
35 | }
36 |
37 | /**
38 | * Check if uri represents local content
39 | *
40 | * @param uri uri to check
41 | * @return true if uri's scheme is equal to "content"
42 | */
43 | public static boolean isLocalContentUri(Uri uri) {
44 | final String scheme = getSchemeOrNull(uri);
45 | return FrescoUri.LOCAL_CONTENT_SCHEME.equals(scheme);
46 | }
47 |
48 | /**
49 | * Check if uri represents local asset
50 | *
51 | * @param uri uri to check
52 | * @return true if uri's scheme is equal to "asset"
53 | */
54 | public static boolean isLocalAssetUri(Uri uri) {
55 | final String scheme = getSchemeOrNull(uri);
56 | return FrescoUri.LOCAL_ASSET_SCHEME.equals(scheme);
57 | }
58 |
59 | /**
60 | * Check if uri represents local resource
61 | *
62 | * @param uri uri to check
63 | * @return true if uri's scheme is equal to "res"
64 | */
65 | public static boolean isLocalResourceUri(Uri uri) {
66 | final String scheme = getSchemeOrNull(uri);
67 | return FrescoUri.LOCAL_RESOURCE_SCHEME.equals(scheme);
68 | }
69 |
70 | /**
71 | * Check if the uri is a data uri
72 | */
73 | public static boolean isDataUri(Uri uri) {
74 | return FrescoUri.DATA_SCHEME.equals(getSchemeOrNull(uri));
75 | }
76 |
77 | public static Uri parseUriFromResId(@DrawableRes int resId){
78 | return new Uri.Builder()
79 | .scheme(FrescoUri.LOCAL_RESOURCE_SCHEME)
80 | .path(String.valueOf(resId))
81 | .build();
82 | }
83 |
84 | /**
85 | * @param uri uri to extract scheme from, possibly null
86 | * @return null if uri is null, result of uri.getScheme() otherwise
87 | */
88 | public static String getSchemeOrNull(Uri uri) {
89 | return uri == null ? null : uri.getScheme();
90 | }
91 |
92 | /**
93 | * @param uriAsString the uri as a string
94 | * @return the parsed Uri or null if the input was null
95 | */
96 | public static Uri parseUri(String uriAsString) {
97 | Uri uri;
98 | try {
99 | uri = Uri.parse(uriAsString);
100 | } catch (Exception e) {
101 | e.printStackTrace();
102 | throw new FPRuntimeException("uriPath is null",e.getCause());
103 | }
104 | return uri;
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/core/FrescoPlusConfig.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.core;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 |
6 | import com.sunzxy.frescopluslib.exception.FPIllegalArgumentException;
7 | import com.sunzxy.frescopluslib.util.DiskCacheUtil;
8 |
9 | import java.io.File;
10 |
11 | /**
12 | * Created by zhengxiaoyong on 16/1/6.
13 | */
14 | public class FrescoPlusConfig {
15 | private boolean isDebug;
16 |
17 | private String logTag;
18 |
19 | private Context mContext;
20 |
21 | private Bitmap.Config mBitmapConfig;
22 |
23 | private int mMaxDiskCacheSize;
24 |
25 | private File mDiskCacheDir;
26 |
27 | private FrescoPlusConfig(Builder builder) {
28 | isDebug = builder.isDebug;
29 | logTag = builder.logTag == null ? DefaultConfigCentre.DEFAULT_TAG : builder.logTag;
30 | mContext = builder.mContext;
31 | mBitmapConfig = builder.mBitmapConfig == null ? DefaultConfigCentre.DEFAULT_BITMAP_CONFIG : builder.mBitmapConfig;
32 | mMaxDiskCacheSize = builder.mMaxDiskCacheSize <= 0 ? DefaultConfigCentre.DEFAULT_MAX_DISK_CACHE_SIZE : builder.mMaxDiskCacheSize;
33 | mDiskCacheDir = builder.mDiskCacheDir == null ? getDefaultDiskCacheDir() : builder.mDiskCacheDir;
34 | }
35 |
36 | public boolean isDebug() {
37 | return isDebug;
38 | }
39 |
40 | public String getLogTag() {
41 | return logTag;
42 | }
43 |
44 | public Bitmap.Config getBitmapConfig() {
45 | return mBitmapConfig;
46 | }
47 |
48 | public int getMaxDiskCacheSize() {
49 | return mMaxDiskCacheSize;
50 | }
51 |
52 | public File getDiskCacheDir() {
53 | return mDiskCacheDir;
54 | }
55 |
56 | public static Builder newBuilder(Context context) {
57 | return new Builder(context);
58 | }
59 |
60 | public static final class Builder {
61 | private boolean isDebug = DefaultConfigCentre.DEFAULT_IS_DEBUG;
62 | private String logTag = DefaultConfigCentre.DEFAULT_TAG;
63 | private Context mContext;
64 | private Bitmap.Config mBitmapConfig;
65 | private int mMaxDiskCacheSize;
66 | private File mDiskCacheDir;
67 |
68 | private Builder(Context context) {
69 | mContext = context;
70 | }
71 |
72 | public Builder setDebug(boolean debug) {
73 | isDebug = debug;
74 | return this;
75 | }
76 |
77 | public Builder setTag(String tag) {
78 | logTag = tag;
79 | return this;
80 | }
81 | /**
82 | * @param val The Bitmap Config,such as:RGB_565,ARGB_8888,ARGB_4444.
83 | * @return this
84 | */
85 | public Builder setBitmapConfig(Bitmap.Config val) {
86 | mBitmapConfig = val;
87 | return this;
88 | }
89 |
90 | /**
91 | * @param val The disk cache max size,unit is MB
92 | * @return this
93 | */
94 | public Builder setMaxDiskCacheSize(int val) {
95 | mMaxDiskCacheSize = val;
96 | return this;
97 | }
98 |
99 | /**
100 | * @param val The disk cache dir,example:context.getApplicationContext().getCacheDir().
101 | * @return this
102 | */
103 | public Builder setDiskCacheDir(File val) {
104 | mDiskCacheDir = val;
105 | return this;
106 | }
107 |
108 | public FrescoPlusConfig build() {
109 | return new FrescoPlusConfig(this);
110 | }
111 | }
112 |
113 | public File getDefaultDiskCacheDir() {
114 | if(mContext == null)
115 | throw new FPIllegalArgumentException("Context can not be null");
116 | return DiskCacheUtil.getDiskLruCacheDir(mContext);
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FrescoPlus
2 |
3 | [  ](https://bintray.com/sunzxyong/maven/FrescoPlus/_latestVersion)
4 |
5 | ##基于Fresco图片库的二次封装,只需2步就可以让你的应用接入Fresco!
6 | 由于Fresco的使用和配置起来需要写一堆代码,没认真看文档和源码根本无法很好的了解Fresco,所以基于Fresco二次封装,配置目前基本保持最优。
7 | #使用
8 |
9 | ##引用
10 |
11 | Maven:
12 | ```
13 |
14 | com.sunzxy.android
15 | frescopluslib
16 | 1.0.0
17 | pom
18 |
19 | ```
20 | Gradle:
21 |
22 | ```
23 | compile 'com.sunzxy.android:frescopluslib:1.0.0'
24 | ```
25 |
26 | ##1、在Application初始化FrescoPlus
27 | ```
28 | FrescoPlusConfig config = FrescoPlusConfig.newBuilder(this)
29 | .setDebug(true)
30 | .setTag("Sunzxyong")
31 | .setBitmapConfig(Bitmap.Config.RGB_565)
32 | .setDiskCacheDir(this.getCacheDir())
33 | .setMaxDiskCacheSize(80)
34 | .build();
35 | FrescoPlusInitializer.getInstance().init(this,config);
36 | ```
37 | ##2、在xml中使用FrescoPlusView作为显示图片的View,然后直接使用即可,有五种加载方式,如下
38 | ```
39 |
45 | ```
46 | ###2.1、五种加载图片的方式:
47 | 分别提供了精简使用和三种不同的回调,有图片加载成功的回调和下载Bitmap成功并返回的回调。
48 | ```
49 | FrescoPlusView mFrescoPlusView = (FrescoPlusView) findViewById(R.id.fresco_view);
50 | Uri uri = Uri.parse("http://pic23.nipic.com/20120812/4277683_204018483000_2.jpg");
51 | //Use
52 | //——————————————————————————————————————————————————————————————————————————————————————————
53 | //第一种.默认配置加载图片,默认配置可在配置中心DefaultConfigCentre更改作为全局配置
54 | mFrescoPlusView.showImage(uri);
55 | //第二种.默认配置加载图片
56 | mFrescoPlusView.showImage(R.mipmap.ic_launcher);
57 | //第三种.加载图片
58 | FrescoPlusFetcher.newFetcher()
59 | .withFadeDuration(350)
60 | .withDefaultDrawable(getResources().getDrawable(R.mipmap.ic_launcher))
61 | .build()
62 | .fetch(mFrescoPlusView,uri);
63 | //第四种.加载图片成功的回调
64 | FrescoPlusFetcher.newFetcher()
65 | .withFadeDuration(350)
66 | .withDefaultDrawable(getResources().getDrawable(R.mipmap.ic_launcher))
67 | .build()
68 | .fetch(mFrescoPlusView, uri, new FPFetchCallback() {
69 | @Override
70 | public void onSuccess(ImageInfo result) {
71 | // do something
72 | }
73 |
74 | @Override
75 | public void onFailure(Throwable throwable) {
76 |
77 | }
78 | });
79 | //第五种.不显示图片直接返回Bitmap
80 | FrescoPlusFetcher.newFetcher()
81 | .withFadeDuration(350)
82 | .withRequestPriority(FrescoPriority.HIGH)
83 | .withAutoRotateEnabled(true)
84 | .build()
85 | .fetch(uri, new FPLoadCallback() {
86 | @Override
87 | public void onSuccess(Uri uri, Bitmap result) {
88 | // do something
89 | }
90 |
91 | @Override
92 | public void onFailure(Uri uri, Throwable throwable) {
93 |
94 | }
95 |
96 | @Override
97 | public void onCancel(Uri uri) {
98 |
99 | }
100 | });
101 | ```
102 | ###2.2、关于Fresco更多内容,请看官方文档
103 |
104 |
105 | #License
106 | >
107 | >Copyright {yyyy} {name of copyright owner}
108 | >
109 | > Licensed under the Apache License, Version 2.0 (the "License");
110 | you may not use this file except in compliance with the License.
111 | You may obtain a copy of the License at
112 | http://www.apache.org/licenses/LICENSE-2.0
113 | Unless required by applicable law or agreed to in writing, software
114 | distributed under the License is distributed on an "AS IS" BASIS,
115 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
116 | See the License for the specific language governing permissions and
117 | limitations under the License.
118 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunzxy/frescoplus/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescoplus;
2 |
3 | import android.graphics.Bitmap;
4 | import android.net.Uri;
5 | import android.os.Bundle;
6 | import android.support.design.widget.FloatingActionButton;
7 | import android.support.design.widget.Snackbar;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.support.v7.widget.Toolbar;
10 | import android.view.Menu;
11 | import android.view.MenuItem;
12 | import android.view.View;
13 |
14 | import com.facebook.imagepipeline.image.ImageInfo;
15 | import com.sunzxy.frescopluslib.core.FrescoPriority;
16 | import com.sunzxy.frescopluslib.request.callback.FPFetchCallback;
17 | import com.sunzxy.frescopluslib.request.callback.FPLoadCallback;
18 | import com.sunzxy.frescopluslib.request.impl.FrescoPlusFetcher;
19 | import com.sunzxy.frescopluslib.widget.FrescoPlusView;
20 |
21 | public class MainActivity extends AppCompatActivity {
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_main);
27 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
28 | setSupportActionBar(toolbar);
29 |
30 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
31 | fab.setOnClickListener(new View.OnClickListener() {
32 | @Override
33 | public void onClick(View view) {
34 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
35 | .setAction("Action", null).show();
36 | }
37 | });
38 |
39 | FrescoPlusView mFrescoPlusView = (FrescoPlusView) findViewById(R.id.fresco_view);
40 | Uri uri = Uri.parse("http://pic23.nipic.com/20120812/4277683_204018483000_2.jpg");
41 | //Use
42 | //——————————————————————————————————————————————————————————————————————————————————————————
43 | //1.
44 | mFrescoPlusView.showImage(uri);
45 | //2.
46 | mFrescoPlusView.showImage(R.mipmap.ic_launcher);
47 | //3.
48 | FrescoPlusFetcher.newFetcher()
49 | .withFadeDuration(350)
50 | .withDefaultDrawable(getResources().getDrawable(R.mipmap.ic_launcher))
51 | .build()
52 | .fetch(mFrescoPlusView,uri);
53 | //4.
54 | FrescoPlusFetcher.newFetcher()
55 | .withFadeDuration(350)
56 | .withDefaultDrawable(getResources().getDrawable(R.mipmap.ic_launcher))
57 | .build()
58 | .fetch(mFrescoPlusView, uri, new FPFetchCallback() {
59 | @Override
60 | public void onSuccess(ImageInfo result) {
61 | // do something
62 | }
63 |
64 | @Override
65 | public void onFailure(Throwable throwable) {
66 |
67 | }
68 | });
69 | //5.
70 | FrescoPlusFetcher.newFetcher()
71 | .withFadeDuration(350)
72 | .withRequestPriority(FrescoPriority.HIGH)
73 | .withAutoRotateEnabled(true)
74 | .build()
75 | .fetch(uri, new FPLoadCallback() {
76 | @Override
77 | public void onSuccess(Uri uri, Bitmap result) {
78 | // do something
79 | }
80 |
81 | @Override
82 | public void onFailure(Uri uri, Throwable throwable) {
83 |
84 | }
85 |
86 | @Override
87 | public void onCancel(Uri uri) {
88 |
89 | }
90 | });
91 | }
92 |
93 | @Override
94 | public boolean onCreateOptionsMenu(Menu menu) {
95 | // Inflate the menu; this adds items to the action bar if it is present.
96 | getMenuInflater().inflate(R.menu.menu_main, menu);
97 | return true;
98 | }
99 |
100 | @Override
101 | public boolean onOptionsItemSelected(MenuItem item) {
102 | // Handle action bar item clicks here. The action bar will
103 | // automatically handle clicks on the Home/Up button, so long
104 | // as you specify a parent activity in AndroidManifest.xml.
105 | int id = item.getItemId();
106 |
107 | //noinspection SimplifiableIfStatement
108 | if (id == R.id.action_settings) {
109 | return true;
110 | }
111 |
112 | return super.onOptionsItemSelected(item);
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/FrescoPlusInitializer.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 | import android.util.Log;
6 |
7 | import com.facebook.cache.disk.DiskCacheConfig;
8 | import com.facebook.imagepipeline.core.ImagePipelineConfig;
9 | import com.facebook.imagepipeline.core.ImagePipelineFactory;
10 | import com.sunzxy.frescopluslib.core.DefaultConfigCentre;
11 | import com.sunzxy.frescopluslib.core.FrescoCacheStatsTracker;
12 | import com.sunzxy.frescopluslib.core.FrescoPlusConfig;
13 | import com.sunzxy.frescopluslib.core.FrescoPlusCore;
14 | import com.sunzxy.frescopluslib.exception.FPNullPointerException;
15 | import com.sunzxy.frescopluslib.widget.FrescoPlusView;
16 |
17 |
18 | /**
19 | * Created by zhengxiaoyong on 16/1/5.
20 | */
21 | public class FrescoPlusInitializer {
22 | private static volatile FrescoPlusInitializer mInstance = null;
23 | private Context mContext;
24 | private boolean isDebug;
25 | private String logTag;
26 |
27 | private FrescoPlusInitializer() {
28 | }
29 |
30 | public static FrescoPlusInitializer getInstance() {
31 | if (mInstance == null) {
32 | synchronized (FrescoPlusInitializer.class) {
33 | if (mInstance == null) {
34 | mInstance = new FrescoPlusInitializer();
35 | }
36 | }
37 | }
38 | return mInstance;
39 | }
40 |
41 | public void init(Context context) {
42 | init(context, null);
43 | }
44 |
45 | public void init(Context context, FrescoPlusConfig frescoPlusConfig) {
46 | if (context == null) {
47 | throw new FPNullPointerException("WDImage initialize error,cause:context is null");
48 | }
49 | mContext = !(context instanceof Application) ? context.getApplicationContext() : context;
50 | initialize(frescoPlusConfig);
51 | }
52 |
53 | private void initialize(FrescoPlusConfig config) {
54 | final FrescoPlusConfig frescoPlusConfig;
55 | if (config == null)
56 | config = FrescoPlusConfig.newBuilder(mContext).build();
57 | frescoPlusConfig = config;
58 |
59 | isDebug = frescoPlusConfig.isDebug();
60 | logTag = frescoPlusConfig.getLogTag();
61 |
62 | printWDImageConfigLog(frescoPlusConfig);
63 |
64 | DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder()
65 | .setBaseDirectoryName(DefaultConfigCentre.DEFAULT_DISK_CACHE_DIR_NAME)
66 | .setBaseDirectoryPath(frescoPlusConfig.getDiskCacheDir())
67 | .setMaxCacheSize(frescoPlusConfig.getMaxDiskCacheSize() * DefaultConfigCentre.MB)
68 | .setMaxCacheSizeOnLowDiskSpace(DefaultConfigCentre.DEFAULT_LOW_SPACE_DISK_CACHE_SIZE)
69 | .setMaxCacheSizeOnVeryLowDiskSpace(DefaultConfigCentre.DEFAULT_VERY_LOW_SPACE_DISK_CACHE_SIZE)
70 | .build();
71 |
72 | ImagePipelineConfig pipelineConfig = ImagePipelineConfig.newBuilder(mContext)
73 | .setBitmapsConfig(frescoPlusConfig.getBitmapConfig())
74 | .setImageCacheStatsTracker(FrescoCacheStatsTracker.getInstance())
75 | .setDownsampleEnabled(true)
76 | .setResizeAndRotateEnabledForNetwork(true)
77 | .setMainDiskCacheConfig(diskCacheConfig)
78 | .build();
79 |
80 | FrescoPlusCore.init(mContext, pipelineConfig);
81 | }
82 |
83 | /**
84 | * Shuts FrescoPlusInitializer down.
85 | */
86 | public void shutDown() {
87 | FrescoPlusCore.shutDownDraweeControllerBuilderSupplier();
88 | FrescoPlusView.shutDown();
89 | ImagePipelineFactory.shutDown();
90 | }
91 |
92 | public Context getContext() {
93 | return mContext;
94 | }
95 |
96 | public boolean isDebug() {
97 | return isDebug;
98 | }
99 |
100 | public String getLogTag() {
101 | return logTag;
102 | }
103 |
104 | /**
105 | * print FrescoPlusConfig log
106 | * @param frescoPlusConfig config
107 | */
108 | private void printWDImageConfigLog(FrescoPlusConfig frescoPlusConfig) {
109 | if (isDebug) {
110 | Log.d(FrescoPlusInitializer.getInstance().getLogTag(), "FrescoPlusInitializer init...Config:"
111 | + "DiskCacheDir->" + frescoPlusConfig.getDiskCacheDir()
112 | + ",MaxDiskCacheSize->" + frescoPlusConfig.getMaxDiskCacheSize()
113 | + ",BitmapConfig->" + frescoPlusConfig.getBitmapConfig()
114 | + ",IsDebug->" + frescoPlusConfig.isDebug()
115 | + ",Tag->" + frescoPlusConfig.getLogTag());
116 | }
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/core/FrescoCacheManager.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.core;
2 |
3 | import android.net.Uri;
4 |
5 | import com.facebook.common.executors.UiThreadImmediateExecutorService;
6 | import com.facebook.datasource.BaseBooleanSubscriber;
7 | import com.facebook.datasource.DataSource;
8 | import com.sunzxy.frescopluslib.logger.FrescoLogger;
9 | import com.sunzxy.frescopluslib.request.callback.FPCacheCallback;
10 | import com.sunzxy.frescopluslib.util.ParamCheckUtil;
11 |
12 | import java.text.DecimalFormat;
13 |
14 | /**
15 | * Created by zhengxiaoyong on 16/1/9.
16 | */
17 | public class FrescoCacheManager {
18 | private static volatile FrescoCacheManager mInstance;
19 |
20 | private FrescoCacheManager() {
21 | }
22 |
23 | public static FrescoCacheManager getInstance() {
24 | if (mInstance == null) {
25 | synchronized (FrescoCacheManager.class) {
26 | if (mInstance == null) {
27 | mInstance = new FrescoCacheManager();
28 | }
29 | }
30 | }
31 | return mInstance;
32 | }
33 |
34 | private long getHasUseDiskCacheSize() {
35 | return FrescoPlusCore.getImagePipelineFactory().getMainDiskStorageCache().getSize();
36 | }
37 |
38 | /**
39 | * @return has use disk cache space size,unit 'KB'.
40 | * Keep two decimal places,example:2.2222->2.22.
41 | */
42 | public String getHasUseDiskCacheSizeWithKB() {
43 | long size = getHasUseDiskCacheSize();
44 | if (size <= 0)
45 | return "0";
46 | return new DecimalFormat("0.00").format(size / 1024.0);
47 | }
48 |
49 | /**
50 | * @return has use disk cache space size,unit 'MB'.
51 | * Keep two decimal places,example:2.2222 is 2.22.
52 | */
53 | public String getHasUseDiskCacheSizeWithMB() {
54 | long size = getHasUseDiskCacheSize();
55 | if (size <= 0)
56 | return "0";
57 | return new DecimalFormat("0.00").format((size / 1024.0) / 1024.0);
58 | }
59 |
60 | /**
61 | * @param uri uri
62 | * @return true if the image was found in the disk cache,false otherwise.
63 | */
64 | public void isInDiskCache(final Uri uri, final FPCacheCallback callback) {
65 | FrescoLogger.getLogger().log(uri);
66 | ParamCheckUtil.checkNotNull(uri, "uri is null");
67 | DataSource dataSource = FrescoPlusCore.getImagePipeline().isInDiskCache(uri);
68 | if (dataSource == null)
69 | return;
70 | dataSource.subscribe(new BaseBooleanSubscriber() {
71 | @Override
72 | protected void onNewResultImpl(boolean isFoundInDisk) {
73 | if (callback != null)
74 | callback.onResult(isFoundInDisk);
75 | }
76 |
77 | @Override
78 | protected void onFailureImpl(DataSource dataSource) {
79 | if (callback != null)
80 | callback.onResult(false);
81 | }
82 | }, UiThreadImmediateExecutorService.getInstance());
83 | }
84 |
85 | /**
86 | * @param uri uri
87 | * @return true if the image was found in the bitmap memory cache,false otherwise.
88 | */
89 | public boolean isInBitmapMemoryCache(Uri uri) {
90 | FrescoLogger.getLogger().log(uri);
91 | ParamCheckUtil.checkNotNull(uri, "uri is null");
92 | return FrescoPlusCore.getImagePipeline().isInBitmapMemoryCache(uri);
93 | }
94 |
95 | /**
96 | * @param uri The uri of the image will to remove,include memory and disk cache.
97 | */
98 | public void removeFromMemoryAndDiskCache(Uri uri) {
99 | FrescoLogger.getLogger().log(uri);
100 | ParamCheckUtil.checkNotNull(uri, "uri is null");
101 | FrescoPlusCore.getImagePipeline().evictFromCache(uri);
102 | }
103 |
104 | /**
105 | * @param uri The uri of the image will to remove,only include memory cache.
106 | */
107 | public void removeFromMemoryCache(Uri uri) {
108 | FrescoLogger.getLogger().log(uri);
109 | ParamCheckUtil.checkNotNull(uri, "uri is null");
110 | FrescoPlusCore.getImagePipeline().evictFromMemoryCache(uri);
111 | }
112 |
113 | /**
114 | * @param uri The uri of the image will to remove,only include disk cache.
115 | */
116 | public void removeFromDiskCache(Uri uri) {
117 | FrescoLogger.getLogger().log(uri);
118 | ParamCheckUtil.checkNotNull(uri, "uri is null");
119 | FrescoPlusCore.getImagePipeline().evictFromDiskCache(uri);
120 | }
121 |
122 | /**
123 | * clear disk caches.
124 | */
125 | public void clearDiskCaches() {
126 | FrescoPlusCore.getImagePipeline().clearDiskCaches();
127 | }
128 |
129 | /**
130 | * clear the memory cache(include Bitmap cache and Encode image cache).
131 | */
132 | public void clearMemoryCaches() {
133 | FrescoPlusCore.getImagePipeline().clearMemoryCaches();
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/frescopluslib/src/main/java/com/sunzxy/frescopluslib/request/impl/FrescoPlusFetcher.java:
--------------------------------------------------------------------------------
1 | package com.sunzxy.frescopluslib.request.impl;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.drawable.Drawable;
5 | import android.net.Uri;
6 | import android.os.Handler;
7 | import android.os.Looper;
8 | import android.support.annotation.Nullable;
9 |
10 | import com.facebook.common.executors.UiThreadImmediateExecutorService;
11 | import com.facebook.common.references.CloseableReference;
12 | import com.facebook.datasource.DataSource;
13 | import com.facebook.drawee.drawable.ScalingUtils;
14 | import com.facebook.drawee.generic.GenericDraweeHierarchy;
15 | import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
16 | import com.facebook.drawee.generic.RoundingParams;
17 | import com.facebook.drawee.interfaces.DraweeController;
18 | import com.facebook.imagepipeline.common.Priority;
19 | import com.facebook.imagepipeline.common.ResizeOptions;
20 | import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber;
21 | import com.facebook.imagepipeline.image.CloseableImage;
22 | import com.facebook.imagepipeline.image.ImageInfo;
23 | import com.facebook.imagepipeline.request.ImageRequest;
24 | import com.facebook.imagepipeline.request.ImageRequestBuilder;
25 | import com.facebook.imagepipeline.request.Postprocessor;
26 | import com.sunzxy.frescopluslib.core.DefaultConfigCentre;
27 | import com.sunzxy.frescopluslib.core.FrescoPlusCore;
28 | import com.sunzxy.frescopluslib.core.FrescoPriority;
29 | import com.sunzxy.frescopluslib.logger.FrescoLogger;
30 | import com.sunzxy.frescopluslib.request.callback.FPFetchCallback;
31 | import com.sunzxy.frescopluslib.request.callback.FPLoadCallback;
32 | import com.sunzxy.frescopluslib.request.supplier.FetchImageControllerListenerSupplier;
33 | import com.sunzxy.frescopluslib.widget.FrescoPlusView;
34 |
35 | import java.util.concurrent.Callable;
36 | import java.util.concurrent.ExecutorService;
37 | import java.util.concurrent.Executors;
38 | import java.util.concurrent.Future;
39 |
40 | /**
41 | * Created by zhengxiaoyong on 16/1/10.
42 | */
43 | public class FrescoPlusFetcher extends AbsBaseFetcher {
44 | private boolean autoRotateEnabled;
45 | private int fadeDuration;
46 | private Drawable failureDrawable;
47 | private Drawable defaultDrawable;
48 | private Drawable overlayDrawable;
49 | private Drawable progressDrawable;
50 | private Drawable retryDrawable;
51 | private Drawable pressedDrawable;
52 | private int resizeWidth;
53 | private int resizeHeight;
54 | private ScalingUtils.ScaleType scaleType;
55 | private float radius;
56 | private int requestPriority;
57 | private ImageRequest.RequestLevel requestLevel;
58 | private Postprocessor postprocessor;
59 | private ExecutorService executeBackgroundTask = Executors.newSingleThreadExecutor();
60 | private FrescoPlusFetcher(Builder builder) {
61 | autoRotateEnabled = builder.autoRotateEnabled;
62 | fadeDuration = builder.fadeDuration <= 0 ? DefaultConfigCentre.DEFAULT_FADE_DURATION : builder.fadeDuration;
63 | failureDrawable = builder.failureDrawable;
64 | defaultDrawable = builder.defaultDrawable;
65 | overlayDrawable = builder.overlayDrawable;
66 | progressDrawable = builder.progressDrawable;
67 | retryDrawable = builder.retryDrawable;
68 | pressedDrawable = builder.pressedDrawable;
69 | resizeWidth = builder.resizeWidth <= 0 ? 0 : builder.resizeWidth;
70 | resizeHeight = builder.resizeHeight <= 0 ? 0 : builder.resizeHeight;
71 | scaleType = builder.scaleType == null ? DefaultConfigCentre.DEFAULT_SCALE_TYPE : builder.scaleType;
72 | radius = builder.radius <= 0 ? DefaultConfigCentre.DEFAULT_RADIUS : builder.radius;
73 | requestPriority = builder.requestPriority <= 0 ? DefaultConfigCentre.DEFAULT_PRIORITY : builder.requestPriority;
74 | requestLevel = builder.requestLevel == null ? DefaultConfigCentre.DEFAULT_REQUEST_LEVEL : builder.requestLevel;
75 | postprocessor = builder.postprocessor;
76 | }
77 |
78 | public static Builder newFetcher() {
79 | return new Builder();
80 | }
81 |
82 |
83 | @Override
84 | public void fetch(FrescoPlusView imageView, Uri uri) {
85 | super.fetch(imageView, uri);
86 | FrescoLogger.getLogger().log(uri);
87 | fetchImage(imageView, uri, null);
88 | }
89 |
90 | @Override
91 | public void fetch(FrescoPlusView imageView, Uri uri, FPFetchCallback callback) {
92 | super.fetch(imageView, uri, callback);
93 | FrescoLogger.getLogger().log(uri);
94 | fetchImage(imageView, uri, callback);
95 | }
96 |
97 | @Override
98 | public void fetch(Uri uri, FPLoadCallback callback) {
99 | super.fetch(uri, callback);
100 | FrescoLogger.getLogger().log(uri);
101 | fetchImage(uri, callback);
102 | }
103 |
104 |
105 | @Override
106 | protected Object beforeExecute(Uri uri) {
107 | return null;
108 | }
109 |
110 | /**
111 | * @param frescoPlusView The draweeView is to display the bitmap
112 | * @param uri The source uri
113 | * @param callback Listening to the success or failure
114 | */
115 | private void fetchImage(FrescoPlusView frescoPlusView, Uri uri, FPFetchCallback callback) {
116 | GenericDraweeHierarchyBuilder hierarchyBuilder = new GenericDraweeHierarchyBuilder(null);
117 | hierarchyBuilder.setFadeDuration(fadeDuration);
118 | hierarchyBuilder.setRoundingParams(RoundingParams.fromCornersRadius(radius));
119 | hierarchyBuilder.setActualImageScaleType(scaleType);
120 | if (defaultDrawable != null)
121 | hierarchyBuilder.setPlaceholderImage(defaultDrawable, scaleType);
122 | if (pressedDrawable != null)
123 | hierarchyBuilder.setPressedStateOverlay(pressedDrawable);
124 | if (retryDrawable != null)
125 | hierarchyBuilder.setRetryImage(retryDrawable);
126 | if (overlayDrawable != null)
127 | hierarchyBuilder.setOverlay(overlayDrawable);
128 | if (failureDrawable != null)
129 | hierarchyBuilder.setFailureImage(failureDrawable, scaleType);
130 | if (progressDrawable != null)
131 | hierarchyBuilder.setProgressBarImage(progressDrawable);
132 | GenericDraweeHierarchy hierarchy = hierarchyBuilder.build();
133 |
134 | ImageRequestBuilder requestBuilder = ImageRequestBuilder.newBuilderWithSource(uri);
135 | requestBuilder.setLowestPermittedRequestLevel(requestLevel);
136 | requestBuilder.setAutoRotateEnabled(autoRotateEnabled);
137 | if (postprocessor != null)
138 | requestBuilder.setPostprocessor(postprocessor);
139 | Priority priority = requestPriority == FrescoPriority.HIGH ? Priority.HIGH : Priority.MEDIUM;
140 | requestBuilder.setRequestPriority(priority);
141 | if (resizeWidth > 0 && resizeHeight > 0)
142 | requestBuilder.setResizeOptions(new ResizeOptions(resizeWidth, resizeHeight));
143 | ImageRequest imageRequest = requestBuilder.build();
144 |
145 | DraweeController draweeController = FrescoPlusCore.newDraweeControllerBuilder()
146 | .setOldController(frescoPlusView.getController())
147 | .setAutoPlayAnimations(true)
148 | .setRetainImageOnFailure(true)
149 | .setTapToRetryEnabled(true)
150 | .setImageRequest(imageRequest)
151 | .setControllerListener(FetchImageControllerListenerSupplier.newInstance(callback))
152 | .build();
153 | frescoPlusView.setHierarchy(hierarchy);
154 | frescoPlusView.setController(draweeController);
155 | }
156 |
157 | private void fetchImage(final Uri uri, final FPLoadCallback callback) {
158 | ImageRequestBuilder requestBuilder = ImageRequestBuilder.newBuilderWithSource(uri);
159 | requestBuilder.setLowestPermittedRequestLevel(requestLevel);
160 | requestBuilder.setAutoRotateEnabled(autoRotateEnabled);
161 | if (postprocessor != null)
162 | requestBuilder.setPostprocessor(postprocessor);
163 | Priority priority = requestPriority == FrescoPriority.HIGH ? Priority.HIGH : Priority.MEDIUM;
164 | requestBuilder.setRequestPriority(priority);
165 | if (resizeWidth > 0 && resizeHeight > 0)
166 | requestBuilder.setResizeOptions(new ResizeOptions(resizeWidth, resizeHeight));
167 | ImageRequest imageRequest = requestBuilder.build();
168 | DataSource>
169 | dataSource = FrescoPlusCore.getImagePipeline().fetchDecodedImage(imageRequest, null);
170 | //callback event processing thread pool.If you pass the UI thread pool you can not handle time-consuming operation.
171 | dataSource.subscribe(new BaseBitmapDataSubscriber() {
172 | @Override
173 | public void onNewResultImpl(@Nullable final Bitmap bitmap) {
174 | if (callback == null)
175 | return;
176 | if (bitmap != null && !bitmap.isRecycled()) {
177 | FrescoLogger.getLogger().log("Bitmap:[height="+bitmap.getHeight()+",width="+bitmap.getWidth()+"]");
178 | handlerBackgroundTask(new Callable() {
179 | @Override
180 | public Bitmap call() throws Exception {
181 | final Bitmap resultBitmap = bitmap.copy(bitmap.getConfig(), bitmap.isMutable());
182 | if (resultBitmap != null && !resultBitmap.isRecycled())
183 | postResult(resultBitmap,uri,callback);
184 | return resultBitmap;
185 | }
186 | });
187 | }
188 | }
189 |
190 | @Override
191 | public void onCancellation(DataSource> dataSource) {
192 | super.onCancellation(dataSource);
193 | if (callback == null)
194 | return;
195 | FrescoLogger.getLogger().log("onCancel");
196 | callback.onCancel(uri);
197 | }
198 |
199 | @Override
200 | public void onFailureImpl(DataSource dataSource) {
201 | if (callback == null)
202 | return;
203 | Throwable throwable = null;
204 | if (dataSource != null) {
205 | throwable = dataSource.getFailureCause();
206 | }
207 | FrescoLogger.getLogger().log(throwable);
208 | callback.onFailure(uri, throwable);
209 | }
210 | },
211 | UiThreadImmediateExecutorService.getInstance());
212 | }
213 |
214 | private Future handlerBackgroundTask(Callable callable){
215 | return executeBackgroundTask.submit(callable);
216 | }
217 |
218 | /**
219 | * 回调UI线程中去
220 | * @param result
221 | * @param uri
222 | * @param callback
223 | * @param
224 | */
225 | private void postResult(final T result, final Uri uri, final FPLoadCallback callback){
226 | new Handler(Looper.getMainLooper()).post(new Runnable() {
227 | @Override
228 | public void run() {
229 | callback.onSuccess(uri,result);
230 | }
231 | });
232 | }
233 |
234 | public static final class Builder {
235 | private int fadeDuration;
236 | private Drawable failureDrawable;
237 | private Drawable defaultDrawable;
238 | private Drawable overlayDrawable;
239 | private Drawable progressDrawable;
240 | private Drawable retryDrawable;
241 | private Drawable pressedDrawable;
242 | private int resizeWidth;
243 | private int resizeHeight;
244 | private ScalingUtils.ScaleType scaleType;
245 | private float radius;
246 | private int requestPriority;
247 | private boolean autoRotateEnabled = DefaultConfigCentre.DEFAULT_AUTO_ROTATE;
248 | private ImageRequest.RequestLevel requestLevel;
249 | private Postprocessor postprocessor;
250 |
251 | private Builder() {
252 | }
253 |
254 | public Builder withAutoRotateEnabled(boolean val) {
255 | autoRotateEnabled = val;
256 | return this;
257 | }
258 |
259 | public Builder withFadeDuration(int val) {
260 | fadeDuration = val;
261 | return this;
262 | }
263 |
264 | public Builder withFailureDrawable(Drawable val) {
265 | failureDrawable = val;
266 | return this;
267 | }
268 |
269 | public Builder withDefaultDrawable(Drawable val) {
270 | defaultDrawable = val;
271 | return this;
272 | }
273 |
274 | public Builder withOverlayDrawable(Drawable val) {
275 | overlayDrawable = val;
276 | return this;
277 | }
278 |
279 | public Builder withProgressDrawable(Drawable val) {
280 | progressDrawable = val;
281 | return this;
282 | }
283 |
284 | public Builder withRetryDrawable(Drawable val) {
285 | retryDrawable = val;
286 | return this;
287 | }
288 |
289 | public Builder withPressedDrawable(Drawable val) {
290 | pressedDrawable = val;
291 | return this;
292 | }
293 |
294 | public Builder withResizeWidth(int val) {
295 | resizeWidth = val;
296 | return this;
297 | }
298 |
299 | public Builder withResizeHeight(int val) {
300 | resizeHeight = val;
301 | return this;
302 | }
303 |
304 | public Builder withScaleType(ScalingUtils.ScaleType val) {
305 | scaleType = val;
306 | return this;
307 | }
308 |
309 | public Builder withRadius(float val) {
310 | radius = val;
311 | return this;
312 | }
313 |
314 | public Builder withRequestPriority(int val) {
315 | requestPriority = val;
316 | return this;
317 | }
318 |
319 | public Builder withRequestLevel(ImageRequest.RequestLevel val) {
320 | requestLevel = val;
321 | return this;
322 | }
323 |
324 | public Builder withPostprocessor(Postprocessor val) {
325 | postprocessor = val;
326 | return this;
327 | }
328 |
329 | public FrescoPlusFetcher build() {
330 | return new FrescoPlusFetcher(this);
331 | }
332 | }
333 | }
334 |
--------------------------------------------------------------------------------