├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── acmenxd
│ │ └── frescoview
│ │ └── demo
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── acmenxd
│ │ │ └── frescoview
│ │ │ └── demo
│ │ │ ├── BaseApplication.java
│ │ │ ├── MainActivity.java
│ │ │ └── SplashActivity.java
│ └── res
│ │ ├── anim
│ │ ├── hold.xml
│ │ ├── right_in.xml
│ │ └── right_out.xml
│ │ ├── drawable
│ │ ├── divider.xml
│ │ ├── divider_bg.xml
│ │ └── splash.png
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ └── activity_splash.xml
│ │ ├── 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-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── acmenxd
│ └── frescoview
│ └── demo
│ └── ExampleUnitTest.java
├── build.gradle
├── config.gradle
├── frescoview
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── acmenxd
│ │ └── frescoview
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── acmenxd
│ │ │ └── frescoview
│ │ │ ├── FrescoCallback.java
│ │ │ ├── FrescoManager.java
│ │ │ ├── FrescoUtils.java
│ │ │ ├── FrescoView.java
│ │ │ └── FrescoViewDoc.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── acmenxd
│ └── frescoview
│ └── ExampleUnitTest.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── pic
└── 1.jpg
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # IntelliJ
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/assetWizardSettings.xml
41 | .idea/dictionaries
42 | .idea/libraries
43 | .idea/caches
44 | .idea/.name
45 | .idea/encodings.xml
46 | .idea/inspectionProfiles/Project_Default.xml
47 | .idea/inspectionProfiles/profiles_settings.xml
48 | .idea/misc.xml
49 | .idea/modules.xml
50 | .idea/scopes/scope_settings.xml
51 | .idea/vcs.xml
52 | .idea/*
53 |
54 | # Keystore files
55 | # Uncomment the following line if you do not want to check your keystore files in.
56 | #*.jks
57 |
58 | # External native build folder generated in Android Studio 2.2 and later
59 | .externalNativeBuild
60 |
61 | # Google Services (e.g. APIs or Firebase)
62 | google-services.json
63 |
64 | # Freeline
65 | freeline.py
66 | freeline/
67 | freeline_project_description.json
68 |
69 | # fastlane
70 | fastlane/report.xml
71 | fastlane/Preview.html
72 | fastlane/screenshots
73 | fastlane/test_output
74 | fastlane/readme.md
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FrescoView
2 | 基于facebook出品的fresco( 强大的图片加载组件 https://www.fresco-cn.org )进行二次开发, 更易于开发者使用的库.
3 |
4 | 如要了解功能实现,请运行app程序查看控制台日志和源代码!
5 | * 源代码 : AcmenXD/FrescoView
6 | * apk下载路径 : FrescoView.apk
7 |
8 | 
9 |
10 | ### 依赖
11 | ---
12 | - AndroidStudio
13 | ```
14 | allprojects {
15 | repositories {
16 | ...
17 | maven { url 'https://jitpack.io' }
18 | }
19 | }
20 | ```
21 | ```
22 | compile 'com.github.AcmenXD:FrescoView:3.0'
23 | ```
24 | ### 混淆
25 | ---
26 | ```
27 | -dontwarn okio.**
28 | -dontwarn okhttp3.**
29 | -dontwarn com.squareup.okhttp3.**
30 | -dontwarn javax.annotation.**
31 | -dontwarn com.android.volley.toolbox.**
32 | -keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip
33 | -keep @com.facebook.common.internal.DoNotStrip class *
34 | -keepclassmembers class * {
35 | @com.facebook.common.internal.DoNotStrip *;
36 | }
37 | -keepclassmembers class * {
38 | native ;
39 | }
40 | ```
41 | ### 功能
42 | ---
43 | - 支持fresco所支持的大多数功能
44 | - 支持JPEG / PNG / GIF / WebP 格式
45 | - 支持加载网络 / res资源 / 本地资源
46 | - 支持低分辨率&高分辨率加载 / 缩略图式加载 > 渐进式加载
47 | - 支持监听加载进度,加载成功和失败回调
48 | - 支持多层构图, 占位图 -> 背景图 -> 覆盖图 -> 加载失败图 -> 失败重试图 -> 进度条图
49 | - 支持加载失败后,点击再次加载
50 | - 支持加载过程中显示加载动画
51 | - 支持圆角 / 圆形 / 边框 处理,并可设置颜色
52 | - 支持图片渐显动画
53 | - 支持控制gif动画的播放和停止
54 | - 支持函数链式调用,方便使用
55 | - 更多功能请查看项目根目录下frescoview/src/main/java/com/acmenxd/frescoview/FrescoViewDoc.java文件,有xml或代码中每个函数的具体含义
56 | ### 配置
57 | ---
58 | **在Application中配置**
59 | ```java
60 | /**
61 | * 设置Log开关 & 等级
62 | * * 默认为 开 & Log.VERBOSE
63 | */
64 | FrescoManager.LOG_OPEN = true;
65 | FrescoManager.LOG_LEVEL = Log.VERBOSE;
66 | /**
67 | * 设置缓存图片的存放路径
68 | * Environment.getExternalStorageDirectory().getAbsolutePath() + "/FrescoView/"
69 | * * 路径:默认为SD卡根目录FrescoView下 (此路径非直接存储图片的路径,还需要以下目录设置)
70 | * * 大图片存放目录:默认为MainCache目录
71 | * * 小图片存放目录:默认为SmallCache目录 (如不想区分大小图片,可设置为null或者"",表示大小图片都放在mainCacheDir目录下)
72 | */
73 | FrescoManager.IMAGE_CACHE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + "/FrescoView/";
74 | FrescoManager.MAIN_CACHE_DIR = "MainCache";
75 | FrescoManager.SMALL_CACHE_DIR = "SmallCache";
76 | /**
77 | * 设置缓存磁盘大小
78 | * * mainCacheSize 大图片磁盘大小(MB) 默认为50MB
79 | * * smallCacheSize 小图片磁盘大小(MB) 默认为20MB
80 | */
81 | FrescoManager.MAX_DISK_CACHE_SIZE = 50;
82 | FrescoManager.MAX_SMALL_DISK_LOW_CACHE_SIZE = 20;
83 | /**
84 | * 初始化
85 | * * context必须设置
86 | * * 配置完成后必须调用此函数生效
87 | */
88 | FrescoManager.init(context);
89 | ```
90 | ### 使用 -> 以下代码 注释很详细、很重要很重要很重要!!!
91 | ---
92 | ```xml
93 |
94 |
122 | ```
123 | ---
124 | ```java
125 | // ** 请查看FrescoViewDoc.java,有详细的参数解释
126 | FrescoView iv = (FrescoView) findViewById(R.id.imageView1);
127 | /**
128 | * 加载回调
129 | */
130 | FrescoCallback callback = new FrescoCallback() {
131 | @Override
132 | public void succeed(String id, ImageInfo imageInfo, Animatable animatable) {
133 | super.succeed(id, imageInfo, animatable);
134 | Log.e("AcmenXD", "onSuccess");
135 | if (imageInfo != null) {
136 | QualityInfo qualityInfo = imageInfo.getQualityInfo();
137 | Log.e("AcmenXD", appendStrs("Size: ", imageInfo.getWidth(), " x ", imageInfo.getHeight()));
138 | Log.e("AcmenXD", appendStrs("Quality level: ", qualityInfo.getQuality()));
139 | Log.e("AcmenXD", appendStrs("good enough: ", qualityInfo.isOfGoodEnoughQuality()));
140 | Log.e("AcmenXD", appendStrs("full quality: ", qualityInfo.isOfFullQuality()));
141 | }
142 | if (animatable != null) {
143 | animatable.start();
144 | }
145 | }
146 | @Override
147 | public void failed(String id, Throwable throwable) {
148 | super.failed(id, throwable);
149 | Log.e("AcmenXD", "onFailure");
150 | }
151 | };
152 | iv.image()
153 | .setImageURI(R.color.colorAccent)
154 | .setImageURI(R.mipmap.ic_launcher)
155 | .setImageURI("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1854928198,1677845423&fm=23&gp=0.jpg") //gif|webp格式
156 | .setBackgroundImage(getResources().getDrawable(R.color.colorPrimary))
157 | .setPlaceholderImage(R.color.colorAccent)
158 | .setProgressBarImage(R.mipmap.ic_launcher)
159 | .setFailureImage(R.color.colorAccent)
160 | .setRetryImage(R.mipmap.ic_launcher)
161 | .setProgressBarImage(R.color.colorAccent)
162 | .setLocalThumbnailPreviewsEnabled(true)
163 | .setProgressiveRenderingEnabled(true)
164 | .setAutoPlayAnimations(true)
165 | .setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER)
166 | .setRoundingParams(30, Color.BLACK, 0, 0, false)
167 | .setFadeDuration(0)
168 | .setControllerListener(callback)
169 | // .setFirstAvailableImageURIs(
170 | // "http://image52.360doc.com/DownloadImg/2012/06/0316/24581213_7.jpg",
171 | // "http://image52.360doc.com/DownloadImg/2012/06/0316/24581213_6.jpg")
172 | // .setAspectRatio(10, 3)
173 | // .setPressedStateOverlay(getResources().getDrawable(R.mipmap.ic_launcher))
174 | .commit();
175 | ```
176 | ---
177 | **gitHub** : https://github.com/AcmenXD 如对您有帮助,欢迎点Star支持,谢谢~
178 |
179 | **技术博客** : http://blog.csdn.net/wxd_beijing
180 | # END
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | def config = rootProject.ext
4 |
5 | android {
6 | compileSdkVersion config.compileSdkVersion
7 | buildToolsVersion config.buildToolsVersion
8 | defaultConfig {
9 | minSdkVersion config.minSdkVersion
10 | targetSdkVersion config.targetSdkVersion
11 | applicationId "com.acmenxd.frescoview.demo"
12 | versionCode 1
13 | versionName "1.0"
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile config.frescoview
26 | // compile project(':frescoview')
27 | }
28 |
--------------------------------------------------------------------------------
/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 D:\Android\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/androidTest/java/com/acmenxd/frescoview/demo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.acmenxd.frescoview.demo;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.acmenxd.frescoview.demo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
13 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/acmenxd/frescoview/demo/BaseApplication.java:
--------------------------------------------------------------------------------
1 | package com.acmenxd.frescoview.demo;
2 |
3 | import android.app.Application;
4 | import android.content.res.Configuration;
5 | import android.os.Environment;
6 | import android.util.Log;
7 |
8 | import com.acmenxd.frescoview.FrescoManager;
9 |
10 | /**
11 | * @author AcmenXD
12 | * @version v1.0
13 | * @github https://github.com/AcmenXD
14 | * @date 2016/11/22 14:36
15 | * @detail 顶级Application
16 | */
17 | public final class BaseApplication extends Application {
18 | protected final String TAG = this.getClass().getSimpleName();
19 |
20 | private static BaseApplication sInstance = null;
21 | // 初始化状态 -> 默认false,初始化完成为true
22 | public boolean isInitFinish = false;
23 | // 记录启动时间
24 | public long startTime = 0;
25 |
26 | public BaseApplication() {
27 | super();
28 | sInstance = this;
29 | }
30 |
31 | public static synchronized BaseApplication instance() {
32 | if (sInstance == null) {
33 | new RuntimeException("BaseApplication == null ?? you should extends BaseApplication in you app");
34 | }
35 | return sInstance;
36 | }
37 |
38 | @Override
39 | public void onCreate() {
40 | super.onCreate();
41 | startTime = System.currentTimeMillis();
42 | /**
43 | * 配置FrescoView
44 | */
45 | FrescoManager.LOG_OPEN = true;
46 | FrescoManager.LOG_LEVEL = Log.VERBOSE;
47 | FrescoManager.IMAGE_CACHE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + "/FrescoView/";
48 | FrescoManager.MAIN_CACHE_DIR = "MainCache";
49 | FrescoManager.SMALL_CACHE_DIR = "SmallCache";
50 | FrescoManager.MAX_DISK_CACHE_SIZE = 50;
51 | FrescoManager.MAX_SMALL_DISK_LOW_CACHE_SIZE = 20;
52 | FrescoManager.init(this);
53 | // 初始化完毕
54 | isInitFinish = true;
55 | }
56 |
57 | @Override
58 | public void onTerminate() {
59 | // 程序终止的时候执行
60 | super.onTerminate();
61 | }
62 |
63 | @Override
64 | public void onLowMemory() {
65 | // 低内存的时候执行
66 | super.onLowMemory();
67 | }
68 |
69 | @Override
70 | public void onTrimMemory(int level) {
71 | // 程序在内存清理的时候执行
72 | super.onTrimMemory(level);
73 | }
74 |
75 | @Override
76 | public void onConfigurationChanged(Configuration newConfig) {
77 | // 应用配置变更~
78 | super.onConfigurationChanged(newConfig);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/app/src/main/java/com/acmenxd/frescoview/demo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.acmenxd.frescoview.demo;
2 |
3 | import android.content.res.Resources;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Color;
6 | import android.graphics.drawable.Animatable;
7 | import android.os.Bundle;
8 | import android.support.annotation.FloatRange;
9 | import android.support.annotation.NonNull;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.util.Log;
12 | import android.view.View;
13 | import android.widget.LinearLayout;
14 |
15 | import com.acmenxd.frescoview.FrescoCallback;
16 | import com.acmenxd.frescoview.FrescoUtils;
17 | import com.acmenxd.frescoview.FrescoView;
18 | import com.facebook.drawee.drawable.ScalingUtils;
19 | import com.facebook.imagepipeline.image.ImageInfo;
20 | import com.facebook.imagepipeline.image.QualityInfo;
21 | import com.facebook.imagepipeline.request.BasePostprocessor;
22 | import com.facebook.imagepipeline.request.Postprocessor;
23 |
24 | /**
25 | * @author AcmenXD
26 | * @version v1.0
27 | * @github https://github.com/AcmenXD
28 | * @date 2017/2/6 17:35
29 | * @detail 包含了所有集成功能, 所以篇幅有点长
30 | */
31 | public class MainActivity extends AppCompatActivity {
32 | private final String TAG = this.getClass().getSimpleName();
33 |
34 | private FrescoView iv1;
35 | private FrescoView iv2;
36 | private FrescoView iv3;
37 |
38 | @Override
39 | public void onCreate(Bundle savedInstanceState) {
40 | super.onCreate(savedInstanceState);
41 | setTitle("FrescoView使用演示");
42 | setContentView(R.layout.activity_main);
43 | iv1 = findViewById(R.id.imageView1);
44 | iv2 = findViewById(R.id.imageView2);
45 | iv3 = findViewById(R.id.imageView3);
46 | iv2.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (int) dp2px(200)));
47 | iv3.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (int) dp2px(200)));
48 | }
49 |
50 | public void btnClick1(View view) {
51 | // 加载回调
52 | FrescoCallback callback = new FrescoCallback() {
53 | @Override
54 | public void succeed(String id, ImageInfo imageInfo, Animatable animatable) {
55 | super.succeed(id, imageInfo, animatable);
56 | Log.e(TAG, "onSuccess");
57 | if (imageInfo != null) {
58 | QualityInfo qualityInfo = imageInfo.getQualityInfo();
59 | Log.e(TAG, FrescoUtils.appendStrs("Size: ", imageInfo.getWidth(), " x ", imageInfo.getHeight()));
60 | Log.e(TAG, FrescoUtils.appendStrs("Quality level: ", qualityInfo.getQuality()));
61 | Log.e(TAG, FrescoUtils.appendStrs("good enough: ", qualityInfo.isOfGoodEnoughQuality()));
62 | Log.e(TAG, FrescoUtils.appendStrs("full quality: ", qualityInfo.isOfFullQuality()));
63 | }
64 | if (animatable != null) {
65 | animatable.start();
66 | }
67 | }
68 |
69 | @Override
70 | public void failed(String id, Throwable throwable) {
71 | super.failed(id, throwable);
72 | Log.e(TAG, "onFailure");
73 | }
74 | };
75 | iv2.image()
76 | .setImageURI(R.color.colorAccent)
77 | .setImageURI(R.mipmap.ic_launcher)
78 | .setImageURI("http://ww2.sinaimg.cn/mw690/c2adb464tw1eb6k8q1yflg20dw07hqv5.gif") //gif|webp格式
79 | .setBackgroundImage(getResources().getDrawable(R.color.colorPrimary))
80 | .setPlaceholderImage(R.color.colorAccent)
81 | .setProgressBarImage(R.mipmap.ic_launcher)
82 | .setFailureImage(R.color.colorAccent)
83 | .setRetryImage(R.mipmap.ic_launcher)
84 | .setProgressBarImage(R.color.colorAccent)
85 | .setLocalThumbnailPreviewsEnabled(true)
86 | .setProgressiveRenderingEnabled(true)
87 | .setAutoPlayAnimations(true)
88 | .setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER)
89 | .setRoundingParams(30, Color.BLACK, 0, 0, false)
90 | .setFadeDuration(0)
91 | .setControllerListener(callback)
92 | // .setFirstAvailableImageURIs(
93 | // "http://image52.360doc.com/DownloadImg/2012/06/0316/24581213_7.jpg",
94 | // "http://image52.360doc.com/DownloadImg/2012/06/0316/24581213_6.jpg")
95 | // .setAspectRatio(10, 3)
96 | // .setPressedStateOverlay(getResources().getDrawable(R.mipmap.ic_launcher))
97 | .commit();
98 | }
99 |
100 |
101 | public void btnClick2(View view) {
102 | // 后处理器
103 | Postprocessor customPostprocessor = new BasePostprocessor() {
104 | @Override
105 | public String getName() {
106 | return "customPostprocessor";
107 | }
108 |
109 | //* 不要重写多于 1 个的 process 方法。这么做可能造成无法预测的结果。
110 | @Override
111 | public void process(Bitmap bitmap) {
112 | // 图片加了红色网格
113 | for (int x = 0; x < bitmap.getWidth(); x += 2) {
114 | for (int y = 0; y < bitmap.getHeight(); y += 2) {
115 | bitmap.setPixel(x, y, Color.RED);
116 | }
117 | }
118 | }
119 |
120 | /* @Override
121 | public void process(Bitmap destBitmap, Bitmap sourceBitmap) {
122 | // 复制 bitmap
123 | // 不要修改源图片。在未来的版本中这会抛出一个异常。
124 | // 不要保存对任何一个图片的引用。它们的内存会由 image pipeline 进行管理,目标图片会在 Drawww 或 DataSource 中正常地销毁。
125 | for (int x = 0; x < destBitmap.getWidth(); x++) {
126 | for (int y = 0; y < destBitmap.getHeight(); y++) {
127 | destBitmap.setPixel(destBitmap.getWidth() - x, y, sourceBitmap.getPixel(x, y));
128 | }
129 | }
130 | }*/
131 |
132 | /*@Override
133 | public CloseableReference process(Bitmap sourceBitmap, PlatformBitmapFactory bitmapFactory) {
134 | // 复制成不同大小的bitmap
135 | // 将源图片复制为 1 / 4 大小
136 | // 不要使用 Android 中 Bitmap.createBitmap() 方法,它会在 Java 堆内存中产生一个 bitmap 对象
137 | CloseableReference bitmapRef = bitmapFactory.createBitmap(
138 | sourceBitmap.getWidth() / 2,
139 | sourceBitmap.getHeight() / 2);
140 | try {
141 | Bitmap destBitmap = bitmapRef.get();
142 | for (int x = 0; x < destBitmap.getWidth(); x+=2) {
143 | for (int y = 0; y < destBitmap.getHeight(); y+=2) {
144 | destBitmap.setPixel(x, y, sourceBitmap.getPixel(x, y));
145 | }
146 | }
147 | return CloseableReference.cloneOrNull(bitmapRef);
148 | } finally {
149 | CloseableReference.closeSafely(bitmapRef);
150 | }
151 | }*/
152 | };
153 | iv3.image()
154 | .setHighImageURI("https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2994123101,43895145&fm=23&gp=0.jpg")
155 | // .setLowImageURI("http://image52.360doc.com/DownloadImg/2012/06/0316/24581213_8.jpg")
156 | // .setHighImageURI("http://image52.360doc.com/DownloadImg/2012/06/0316/24581213_1.jpg")
157 | .setRoundingParams(100, Color.BLACK, 10, Color.YELLOW, false)
158 | .setFadeDuration(1000)
159 | .setPostprocessor(customPostprocessor)
160 | .commit();
161 | }
162 |
163 | public void btnClick3(View view) {
164 | iv2.image().animatableStart();
165 | }
166 |
167 | public void btnClick4(View view) {
168 | iv2.image().animatableStop();
169 | }
170 |
171 | public float dp2px(@FloatRange(from = 0.0D) float dp) {
172 | return dp2px(this.getResources(), dp);
173 | }
174 |
175 | public float dp2px(@NonNull Resources resources, @FloatRange(from = 0.0D) float dp) {
176 | float scale = resources.getDisplayMetrics().density;
177 | return dp * scale + 0.5F;
178 | }
179 | }
180 |
--------------------------------------------------------------------------------
/app/src/main/java/com/acmenxd/frescoview/demo/SplashActivity.java:
--------------------------------------------------------------------------------
1 | package com.acmenxd.frescoview.demo;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.os.Handler;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.util.Log;
8 |
9 | /**
10 | * @author AcmenXD
11 | * @version v1.0
12 | * @github https://github.com/AcmenXD
13 | * @date 2017/3/31 14:02
14 | * @detail something
15 | */
16 | public class SplashActivity extends AppCompatActivity {
17 | private Handler mHandler;
18 | private int duration = 2000;
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_splash);
24 | Log.w("AcmenXD","App进入SplashActivity!");
25 |
26 | long time = 0;
27 | if (BaseApplication.instance().startTime > 0) {
28 | time = System.currentTimeMillis() - BaseApplication.instance().startTime;
29 | BaseApplication.instance().startTime = 0;
30 | }
31 | if (time > duration) {
32 | startNextActivity();
33 | } else {
34 | mHandler = new Handler();
35 | mHandler.postDelayed(new Runnable() {
36 | @Override
37 | public void run() {
38 | startNextActivity();
39 | }
40 | }, duration - time);
41 | }
42 | }
43 |
44 | /**
45 | * 启动下个Activity
46 | */
47 | private void startNextActivity() {
48 | startActivity(new Intent(SplashActivity.this, MainActivity.class));
49 | finish();
50 | }
51 |
52 | @Override
53 | protected void onDestroy() {
54 | super.onDestroy();
55 | if (mHandler != null) {
56 | mHandler.removeCallbacksAndMessages(null);
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/hold.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/right_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/right_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/divider.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/divider_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/splash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AcmenXD/FrescoView/af6e3f4c4e8fb352ee3c2b69665522c8decedf64/app/src/main/res/drawable/splash.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
19 |
20 |
27 |
28 |
35 |
36 |
43 |
44 |
71 |
72 |
76 |
77 |
81 |
82 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_splash.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AcmenXD/FrescoView/af6e3f4c4e8fb352ee3c2b69665522c8decedf64/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AcmenXD/FrescoView/af6e3f4c4e8fb352ee3c2b69665522c8decedf64/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AcmenXD/FrescoView/af6e3f4c4e8fb352ee3c2b69665522c8decedf64/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AcmenXD/FrescoView/af6e3f4c4e8fb352ee3c2b69665522c8decedf64/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AcmenXD/FrescoView/af6e3f4c4e8fb352ee3c2b69665522c8decedf64/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FrescoView
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
13 |
14 |
19 |
20 |
24 |
25 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/test/java/com/acmenxd/frescoview/demo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.acmenxd.frescoview.demo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | apply from: 'config.gradle'
3 |
4 | buildscript {
5 | repositories {
6 | google()
7 | jcenter()
8 | mavenCentral()
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:3.0.0'
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | google()
20 | jcenter()
21 | maven { url 'https://jitpack.io' }
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/config.gradle:
--------------------------------------------------------------------------------
1 | /**
2 | * build.gradle Module统一配置
3 | */
4 | ext {
5 | compileSdkVersion = 26
6 | buildToolsVersion = "27.0.3"
7 | minSdkVersion = 14
8 | targetSdkVersion = 26
9 |
10 | // 图片加载库
11 | frescoview = "com.github.AcmenXD:FrescoView:3.0"
12 |
13 | // 系统库
14 | system = [
15 | appcompatV7 : "com.android.support:appcompat-v7:26.1.0",
16 | ]
17 |
18 | fresco = [
19 | // facebook推出的图片处理库
20 | fresco : "com.facebook.fresco:fresco:1.0.1",
21 | // 支持okhttp3网络库请求
22 | fresco_okhttp3 : "com.facebook.fresco:imagepipeline-okhttp3:1.0.1",
23 | // 支持gif时需要添加
24 | fresco_gif : "com.facebook.fresco:animated-gif:1.0.1",
25 | // 支持 WebP (静态图+动图),需要添加
26 | fresco_webp : "com.facebook.fresco:animated-webp:1.0.1",
27 | // 在 API < 14(4.0) 上的机器支持 WebP 时,需要添加
28 | fresco_support : "com.facebook.fresco:animated-base-support:1.0.1",
29 | // 支持 WebP 静态图,需要添加
30 | fresco_webpsupport: "com.facebook.fresco:webpsupport:1.0.1",
31 | ]
32 | }
--------------------------------------------------------------------------------
/frescoview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/frescoview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | def config = rootProject.ext
4 |
5 | android {
6 | compileSdkVersion config.compileSdkVersion
7 | buildToolsVersion config.buildToolsVersion
8 | defaultConfig {
9 | minSdkVersion config.minSdkVersion
10 | targetSdkVersion config.targetSdkVersion
11 | versionCode 1
12 | versionName "1.0"
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 | dependencies {
23 | compile config.system.appcompatV7
24 | compile config.fresco.fresco
25 | compile config.fresco.fresco_okhttp3
26 | compile config.fresco.fresco_gif
27 | compile config.fresco.fresco_webp
28 | // compile config.fresco.fresco_support
29 | // compile config.fresco.fresco_webpsupport
30 | }
31 |
--------------------------------------------------------------------------------
/frescoview/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 D:\Android\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 |
--------------------------------------------------------------------------------
/frescoview/src/androidTest/java/com/acmenxd/frescoview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.acmenxd.frescoview;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.acmenxd.frescoview.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/frescoview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/frescoview/src/main/java/com/acmenxd/frescoview/FrescoCallback.java:
--------------------------------------------------------------------------------
1 | package com.acmenxd.frescoview;
2 |
3 | import android.graphics.drawable.Animatable;
4 | import android.support.annotation.NonNull;
5 |
6 | import com.facebook.drawee.controller.BaseControllerListener;
7 | import com.facebook.imagepipeline.image.ImageInfo;
8 |
9 | /**
10 | * @author AcmenXD
11 | * @version v1.0
12 | * @github https://github.com/AcmenXD
13 | * @date 2017/1/22 10:31
14 | * @detail 图片加载回调
15 | */
16 | public abstract class FrescoCallback extends BaseControllerListener {
17 | @Override
18 | public final void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
19 | super.onFinalImageSet(id, imageInfo, animatable);
20 | succeed(id, imageInfo, animatable);
21 | }
22 |
23 | @Override
24 | public final void onFailure(String id, Throwable throwable) {
25 | super.onFailure(id, throwable);
26 | failed(id, throwable);
27 | }
28 |
29 | @Override
30 | public final void onIntermediateImageSet(String id, ImageInfo imageInfo) {
31 | super.onIntermediateImageSet(id, imageInfo);
32 | //如果允许呈现渐进式JPEG,同时图片也是渐进式图片,onIntermediateImageSet会在每个扫描被解码后回调
33 | }
34 |
35 | @Override
36 | public final void onIntermediateImageFailed(String id, Throwable throwable) {
37 | super.onIntermediateImageFailed(id, throwable);
38 | }
39 |
40 | @Override
41 | public final void onRelease(String id) {
42 | super.onRelease(id);
43 | }
44 |
45 | @Override
46 | public final void onSubmit(String id, Object callerContext) {
47 | super.onSubmit(id, callerContext);
48 | }
49 |
50 | /**
51 | * 请求成功被回调
52 | * * 非必须重写函数,如需要进行重写
53 | *
54 | * @param id : 图片的id值
55 | * @param imageInfo : 图片的一些信息,如尺寸等
56 | * @param animatable : 此参数用来操作相关动画,如gif|webp等动画格式
57 | */
58 | public void succeed(@NonNull String id, @NonNull ImageInfo imageInfo, @NonNull Animatable animatable) {
59 |
60 | }
61 |
62 | /**
63 | * 请求失败被回调
64 | * * 非必须重写函数,如需要进行重写
65 | *
66 | * @param id : 图片的id值
67 | * @param throwable : 错误信息
68 | */
69 | public void failed(@NonNull String id, @NonNull Throwable throwable) {
70 |
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/frescoview/src/main/java/com/acmenxd/frescoview/FrescoManager.java:
--------------------------------------------------------------------------------
1 | package com.acmenxd.frescoview;
2 |
3 | import android.content.Context;
4 | import android.net.Uri;
5 | import android.os.Environment;
6 | import android.support.annotation.NonNull;
7 | import android.text.TextUtils;
8 | import android.util.Log;
9 |
10 | import com.facebook.cache.disk.DiskCacheConfig;
11 | import com.facebook.common.internal.Supplier;
12 | import com.facebook.common.logging.FLog;
13 | import com.facebook.common.util.ByteConstants;
14 | import com.facebook.drawee.backends.pipeline.Fresco;
15 | import com.facebook.imagepipeline.backends.okhttp3.OkHttpImagePipelineConfigFactory;
16 | import com.facebook.imagepipeline.cache.MemoryCacheParams;
17 | import com.facebook.imagepipeline.core.ImagePipeline;
18 | import com.facebook.imagepipeline.core.ImagePipelineConfig;
19 | import com.facebook.imagepipeline.listener.RequestListener;
20 | import com.facebook.imagepipeline.listener.RequestLoggingListener;
21 |
22 | import java.io.File;
23 | import java.util.HashSet;
24 | import java.util.Set;
25 |
26 | import okhttp3.OkHttpClient;
27 |
28 | /**
29 | * @author AcmenXD
30 | * @version v1.0
31 | * @github https://github.com/AcmenXD
32 | * @date 2017/1/17 15:39
33 | * @detail 图片加载配置工具
34 | * * 混淆 参考-> https://www.fresco-cn.org/docs/proguard.html
35 | * * 打包 参考-> https://www.fresco-cn.org/docs/multiple-apks.html
36 | */
37 | public final class FrescoManager {
38 | // 分配的可用内存
39 | private static final int MAX_HEAP_SIZE = (int) Runtime.getRuntime().maxMemory();
40 | // 使用的缓存数量
41 | private static final int MAX_MEMORY_CACHE_SIZE = MAX_HEAP_SIZE / 4;
42 | // 默认图磁盘缓存的最大值 单位:MB
43 | public static long MAX_DISK_CACHE_SIZE = 50;
44 | // 默认图低磁盘空间缓存的最大值
45 | private static final long MAX_DISK_CACHE_LOW_SIZE = 20 * ByteConstants.MB;
46 | // 默认图极低磁盘空间缓存的最大值
47 | private static final long MAX_DISK_CACHE_VERYLOW_SIZE = 8 * ByteConstants.MB;
48 | // 小图低磁盘空间缓存的最大值(特性:可将大量的小图放到额外放在另一个磁盘空间防止大图占用磁盘空间而删除了大量的小图) 单位:MB
49 | public static long MAX_SMALL_DISK_LOW_CACHE_SIZE = 20;
50 | // 小图极低磁盘空间缓存的最大值(特性:可将大量的小图放到额外放在另一个磁盘空间防止大图占用磁盘空间而删除了大量的小图)
51 | private static final long MAX_SMALL_DISK_VERYLOW_CACHE_SIZE = 8 * ByteConstants.MB;
52 |
53 | /**
54 | * 使用配置
55 | */
56 | protected static String APP_PKG_NAME = "FrescoView"; // 包名 -> 用于存取资源图片的路径拼接
57 | private static Context sContext; // 上下文对象
58 | public static boolean LOG_OPEN = true; // Log开关
59 | public static int LOG_LEVEL = Log.VERBOSE; // Log等级
60 | //设置缓存图片的存放路径 - 路径:默认为SD卡根目录FrescoView下 (此路径非直接存储图片的路径,还需要以下目录设置)
61 | public static String IMAGE_CACHE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + "/FrescoView/";
62 | //大图片存放目录:默认为MainCache目录
63 | public static String MAIN_CACHE_DIR = "MainCache";
64 | //小图片存放目录:默认为SmallCache目录 (如不想区分大小图片,可设置为null或者"",表示大小图片都放在mainCacheDir目录下)
65 | public static String SMALL_CACHE_DIR = "SmallCache";
66 |
67 | /**
68 | * 初始化
69 | * * context必须设置
70 | * * 配置完成后必须调用此函数生效
71 | */
72 | public static void init(@NonNull Context pContext) {
73 | sContext = pContext;
74 | APP_PKG_NAME = sContext.getPackageName();
75 | init();
76 | }
77 |
78 | /**
79 | * 初始化 -> 配置完成后必须调用此函数生效
80 | */
81 | private static synchronized void init() {
82 | // 内存配置
83 | final MemoryCacheParams memoryCacheParams = new MemoryCacheParams(
84 | MAX_MEMORY_CACHE_SIZE,// 内存缓存中总图片的最大大小,以字节为单位。
85 | Integer.MAX_VALUE,// 内存缓存中图片的最大数量。
86 | MAX_MEMORY_CACHE_SIZE,// 内存缓存中准备清除但尚未被删除的总图片的最大大小,以字节为单位。
87 | Integer.MAX_VALUE,// 内存缓存中准备清除的总图片的最大数量。
88 | Integer.MAX_VALUE);// 内存缓存中单个图片的最大大小。
89 | // 修改内存图片缓存数量
90 | Supplier bitmapMemoryCacheParamsSupplier = new Supplier() {
91 | @Override
92 | public MemoryCacheParams get() {
93 | return memoryCacheParams;
94 | }
95 | };
96 | // 默认图片的磁盘配置
97 | DiskCacheConfig mainDiskCacheConfig = DiskCacheConfig.newBuilder(sContext)
98 | .setBaseDirectoryPath(new File(IMAGE_CACHE_PATH))
99 | .setBaseDirectoryName(MAIN_CACHE_DIR)
100 | .setMaxCacheSize(MAX_DISK_CACHE_SIZE * ByteConstants.MB)//默认缓存的最大大小。
101 | .setMaxCacheSizeOnLowDiskSpace(MAX_DISK_CACHE_LOW_SIZE)//缓存的最大大小,使用设备时低磁盘空间。
102 | .setMaxCacheSizeOnVeryLowDiskSpace(MAX_DISK_CACHE_VERYLOW_SIZE)//缓存的最大大小,当设备极低磁盘空间
103 | .build();
104 | // 小图片的磁盘配置
105 | DiskCacheConfig smallImageDiskCacheConfig = null;
106 | if (!TextUtils.isEmpty(SMALL_CACHE_DIR)) {
107 | smallImageDiskCacheConfig = DiskCacheConfig.newBuilder(sContext)
108 | .setBaseDirectoryPath(new File(IMAGE_CACHE_PATH)) //存储路径
109 | .setBaseDirectoryName(SMALL_CACHE_DIR) //文件名
110 | .setMaxCacheSize(MAX_DISK_CACHE_SIZE * ByteConstants.MB) //默认缓存的最大大小
111 | .setMaxCacheSizeOnLowDiskSpace(MAX_SMALL_DISK_LOW_CACHE_SIZE * ByteConstants.MB) //缓存的最大大小,使用设备时低磁盘空间
112 | .setMaxCacheSizeOnVeryLowDiskSpace(MAX_SMALL_DISK_VERYLOW_CACHE_SIZE) //缓存的最大大小,当设备极低磁盘空间
113 | .build();
114 | }
115 | // 设置Log & 显示等级
116 | Set requestListeners = new HashSet<>();
117 | if (LOG_OPEN) {
118 | requestListeners.add(new RequestLoggingListener());
119 | FLog.setMinimumLoggingLevel(LOG_LEVEL);
120 |
121 | }
122 | // 配置 -> 使用OkHttp网络库加载图片
123 | ImagePipelineConfig.Builder builder = OkHttpImagePipelineConfigFactory
124 | .newBuilder(sContext, new OkHttpClient())
125 | .setBitmapMemoryCacheParamsSupplier(bitmapMemoryCacheParamsSupplier)
126 | .setMainDiskCacheConfig(mainDiskCacheConfig);
127 | if (smallImageDiskCacheConfig != null) {
128 | builder.setSmallImageDiskCacheConfig(smallImageDiskCacheConfig);
129 | }
130 | builder.setRequestListeners(requestListeners);
131 | // .setBitmapsConfig(Bitmap.Config.RGB_565)
132 | // .setDownsampleEnabled(true)
133 | // .setWebpSupportEnabled(true)
134 | // .setCacheKeyFactory(cacheKeyFactory)
135 | // .setEncodedMemoryCacheParamsSupplier(encodedCacheParamsSupplier)
136 | // .setExecutorSupplier(executorSupplier)
137 | // .setImageCacheStatsTracker(imageCacheStatsTracker)
138 | // .setMemoryTrimmableRegistry(memoryTrimmableRegistry)
139 | // .setNetworkFetchProducer(networkFetchProducer)
140 | // .setPoolFactory(poolFactory)
141 | // .setProgressiveJpegConfig(progressiveJpegConfig)
142 | ImagePipelineConfig config = builder.build();
143 | Fresco.initialize(sContext, config);
144 | }
145 |
146 | /**
147 | * 根据uri检查是否被缓存
148 | *
149 | * @param uri
150 | * @return
151 | */
152 | public static boolean checkMemoryCache(@NonNull String uri) {
153 | return Fresco.getImagePipeline().isInBitmapMemoryCache(Uri.parse(uri));
154 | }
155 |
156 | public static boolean checkMemoryCache(int resId) {
157 | return checkMemoryCache(FrescoUtils.appendStrs("res://", APP_PKG_NAME, "/", resId));
158 | }
159 |
160 | /**
161 | * 根据uri删除缓存
162 | */
163 | public static void deleteCache(@NonNull String uri) {
164 | Uri uri1 = Uri.parse(uri);
165 | ImagePipeline imagePipeline = Fresco.getImagePipeline();
166 | imagePipeline.evictFromMemoryCache(uri1);
167 | imagePipeline.evictFromDiskCache(uri1);
168 | imagePipeline.evictFromCache(uri1);
169 | }
170 |
171 | /**
172 | * 清空缓存
173 | */
174 | public static void clearCache() {
175 | ImagePipeline imagePipeline = Fresco.getImagePipeline();
176 | imagePipeline.clearMemoryCaches();
177 | imagePipeline.clearDiskCaches();
178 | imagePipeline.clearCaches();
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/frescoview/src/main/java/com/acmenxd/frescoview/FrescoUtils.java:
--------------------------------------------------------------------------------
1 | package com.acmenxd.frescoview;
2 |
3 | import android.support.annotation.NonNull;
4 |
5 | /**
6 | * @author AcmenXD
7 | * @version v1.0
8 | * @github https://github.com/AcmenXD
9 | * @date 2018/5/22 17:47
10 | * @detail Fresco工具类
11 | */
12 | public class FrescoUtils {
13 | /**
14 | * 串拼接
15 | *
16 | * @param strs 可变参数类型
17 | * @return 拼接后的字符串
18 | */
19 | public static String appendStrs(@NonNull Object... strs) {
20 | StringBuilder sb = new StringBuilder();
21 | if (strs != null && strs.length > 0) {
22 | for (Object str : strs) {
23 | sb.append(String.valueOf(str));
24 | }
25 | }
26 | return sb.toString();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/frescoview/src/main/java/com/acmenxd/frescoview/FrescoView.java:
--------------------------------------------------------------------------------
1 | package com.acmenxd.frescoview;
2 |
3 | import android.content.Context;
4 | import android.graphics.ColorFilter;
5 | import android.graphics.PointF;
6 | import android.graphics.drawable.Drawable;
7 | import android.net.Uri;
8 | import android.support.annotation.AnyRes;
9 | import android.support.annotation.ColorInt;
10 | import android.support.annotation.DrawableRes;
11 | import android.support.annotation.FloatRange;
12 | import android.support.annotation.IntRange;
13 | import android.support.annotation.NonNull;
14 | import android.text.TextUtils;
15 | import android.util.AttributeSet;
16 |
17 | import com.facebook.drawee.backends.pipeline.Fresco;
18 | import com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder;
19 | import com.facebook.drawee.controller.ControllerListener;
20 | import com.facebook.drawee.drawable.ScalingUtils;
21 | import com.facebook.drawee.generic.GenericDraweeHierarchy;
22 | import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
23 | import com.facebook.drawee.generic.RoundingParams;
24 | import com.facebook.drawee.view.SimpleDraweeView;
25 | import com.facebook.imagepipeline.common.ResizeOptions;
26 | import com.facebook.imagepipeline.image.ImageInfo;
27 | import com.facebook.imagepipeline.request.ImageRequest;
28 | import com.facebook.imagepipeline.request.ImageRequestBuilder;
29 | import com.facebook.imagepipeline.request.Postprocessor;
30 |
31 | /**
32 | * @author AcmenXD
33 | * @version v1.0
34 | * @github https://github.com/AcmenXD
35 | * @date 2017/1/18 14:30
36 | * @detail 支持图片格式:PNG / GIF / WebP / JPEG
37 | * * 注意 : 此控件虽继承自ImageView,但是不要适用所有ImageView的属性和方法
38 | * * 注意 : 此空间不允许指定:android:layout_height="wrap_content",除非你指定了特定的宽高比:Image.setAspectRatio(4:3)
39 | * * 封装注意: 与原生相比,此封装使用GenericDraweeHierarchy的功能,无法支持GenericDraweeHierarchyBuilder的功能
40 | * * 优先级 : 加载最先可用图片 > 低分辨率&高分辨率 > 缩略图式加载 > 渐进式加载
41 | * * 优先级 : setFirstAvailableImageURIs > setLowImageURI > setHighImageURI > setImageURI
42 | * * 后处理器 : setPostprocessor() 图片加载完成后对图片进行特殊处理 参考-> https://www.fresco-cn.org/docs/modifying-image.html
43 | * * 自定义View : 单图 | 多图 参考-> https://www.fresco-cn.org/docs/writing-custom-views.html
44 | * * 缩放模式 :
45 | * -----1.Scaling 画布操作,通常是由硬件加速的.图片实际大小保持不变,只是在绘制时被放大或缩小.(Android 4.0 及以后,在配置 GPU 的设备上会启用硬件加速)
46 | * -------适用: 图片的像素数 < 视图量级(长 x 宽) x 2
47 | * -------用法: layout_width 和 layout_height 并制定缩放类型ScalingUtils.ScaleType
48 | * -----2.Resizing 不改变原始图片,只是在解码前修改内存中的图片大小.(目前只支持JPEG格式,由软件执行的,相比硬件加速的scale操作较慢)
49 | * -------适用: 图片的像素数 > 视图量级(长 x 宽) x 2
50 | * -------用法:setResizeOptions(width,height)
51 | * -----3.Downsampling (向下采样)如果开启该选项,会向下采样你的图片,代替Resizing操作,但仍然需要在每个图片请求中调用setResizeOptions(width,height)
52 | * -------在大部分情况下比Resizing更快.除了支持JPEG图片,它还支持PNG和WebP(除动画外)图片
53 | * -------目前存在一个缺陷: 在Android 4.4上会在解码时造成更多的内存开销(相比于Resizing).这在同时解码许多大图时会非常显著
54 | * -------适用: 图片的像素数 > 视图量级(长 x 宽) x 2 的 非JPEG格式图片
55 | * -------用法: 在ImageUtils的config中配置setDownsampleEnabled(true) 并 在每个图片请求中调用setResizeOptions(width,height)
56 | */
57 | public final class FrescoView extends SimpleDraweeView {
58 | private Image mImage;
59 | private Context mContext;
60 |
61 | public FrescoView(Context context) {
62 | super(context);
63 | mContext = context;
64 | }
65 |
66 | public FrescoView(Context context, AttributeSet attrs) {
67 | super(context, attrs);
68 | mContext = context;
69 | }
70 |
71 | public FrescoView(Context context, GenericDraweeHierarchy hierarchy) {
72 | super(context, hierarchy);
73 | mContext = context;
74 | }
75 |
76 | public FrescoView(Context context, AttributeSet attrs, int defStyle) {
77 | super(context, attrs, defStyle);
78 | mContext = context;
79 | }
80 |
81 | public FrescoView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
82 | super(context, attrs, defStyleAttr, defStyleRes);
83 | mContext = context;
84 | }
85 |
86 | /**
87 | * 获取ImageView2功能操作类 实例
88 | */
89 | public Image image() {
90 | if (mImage == null) {
91 | mImage = new Image(mContext, this);
92 | }
93 | return mImage;
94 | }
95 |
96 | /**
97 | * 重置ImageView2参数
98 | */
99 | public Image reset() {
100 | if (mImage != null) {
101 | mImage.reset();
102 | }
103 | return mImage;
104 | }
105 |
106 | /**
107 | * ImageView2 功能操作类
108 | */
109 | public final class Image {
110 | private Context mContext;
111 | private FrescoView mImageView2;
112 | private String mImageUri;
113 | private String mLowImageUri;
114 | private String mHighImageUri;
115 | private String[] mFirstAvailableImageUris;
116 | private Object mCallerContext;
117 | private Postprocessor mPostprocessor;// 后处理器 -> 图片加载完成后对图片进行特殊处理(不支持动图加载)
118 | private ResizeOptions mResizeOptions;// Resizing缩放模式所需宽高参数
119 | private boolean isAutoPlayAnimations = false; // 动画图是否自动播放
120 | private int isAutoRotateEnabled = -1;// 自动旋转(支持JPEG格式) 默认:-1 不启用:0 启用:1 (不管图片方向是怎样的,显示时都会将图片的方向与设备屏幕的方向保持一致)
121 | private int isLocalThumbnailPreviewsEnabled = -1; // 缩略图式加载 默认:-1 不启用:0 启用:1
122 | private int isProgressiveRenderingEnabled = -1; // 开启渐进式加载 默认:-1 不启用:0 启用:1
123 |
124 | private Image(@NonNull Context pContext, @NonNull FrescoView pImageView2) {
125 | mContext = pContext;
126 | mImageView2 = pImageView2;
127 | }
128 |
129 | /**
130 | * 重置所有配置
131 | */
132 | public void reset() {
133 | init();
134 | getGenericDraweeHierarchy().reset();
135 | mPipelineDraweeControllerBuilder = Fresco.newDraweeControllerBuilder();
136 | }
137 |
138 | /**
139 | * 设置图片请求地址 *格式说明 (Content provider -> 待验证 -> content://)
140 | */
141 | //支持网络资源
142 | public Image setImageURI(@NonNull String pImageUri) {
143 | if (pImageUri.startsWith("http://") || pImageUri.startsWith("https://")) {
144 | setImageURI(pImageUri, null);
145 | }
146 | return getThis();
147 | }
148 |
149 | //支持res目录下的资源
150 | public Image setImageURI(@AnyRes int resId) {
151 | setImageURI(FrescoUtils.appendStrs("res://", FrescoManager.APP_PKG_NAME, "/", resId), null);
152 | return getThis();
153 | }
154 |
155 | //支持本地文件资源
156 | public Image setImageURI_File(@NonNull String filePath) {
157 | setImageURI(FrescoUtils.appendStrs("file://", filePath), null);
158 | return getThis();
159 | }
160 |
161 | //支持asset目录下的资源
162 | public Image setImageURI_Asset(@NonNull String assetPath) {
163 | setImageURI(FrescoUtils.appendStrs("asset://", assetPath), null);
164 | return getThis();
165 | }
166 |
167 | /**
168 | * 先显示低分辨率的图,然后是高分辨率的图(优先级 > setHighImageURI > setImageURI)
169 | */
170 | public Image setLowImageURI(@NonNull String pLowImageUri) {
171 | if (TextUtils.isEmpty(pLowImageUri)) {
172 | throw new NullPointerException("lowImageURI can't null or ''");
173 | }
174 | mLowImageUri = pLowImageUri;
175 | return getThis();
176 | }
177 |
178 | /**
179 | * 先显示低分辨率的图,然后是高分辨率的图(优先级 > setImageURI)
180 | */
181 | public Image setHighImageURI(@NonNull String pHighImageUri) {
182 | if (TextUtils.isEmpty(pHighImageUri)) {
183 | throw new NullPointerException("highImageURI can't null or ''");
184 | }
185 | mHighImageUri = pHighImageUri;
186 | return getThis();
187 | }
188 |
189 | /**
190 | * 加载最先可用的图像(同一个图片有多个Uri的情况下,设置多个Uri路径)
191 | * * 显示规则:检查集合中任意uri是否存在,如存在则显示,如不存在,则寻找磁盘缓存,如不存在,则外部请求
192 | */
193 | public Image setFirstAvailableImageURIs(@NonNull String... pFirstAvailableImageUris) {
194 | if (pFirstAvailableImageUris == null || pFirstAvailableImageUris.length <= 0) {
195 | throw new NullPointerException("highImageURI can't null or ''");
196 | }
197 | mFirstAvailableImageUris = pFirstAvailableImageUris;
198 | return getThis();
199 | }
200 |
201 | /**
202 | * 修改占位图
203 | */
204 | public Image setPlaceholderImage(@DrawableRes int resId) {
205 | getGenericDraweeHierarchy().setPlaceholderImage(resId);
206 | return getThis();
207 | }
208 |
209 | public Image setPlaceholderImage(@DrawableRes int resId, ScalingUtils.ScaleType pScaleType) {
210 | getGenericDraweeHierarchy().setPlaceholderImage(resId, pScaleType);
211 | return getThis();
212 | }
213 |
214 | public Image setPlaceholderImage(@NonNull Drawable pDrawable) {
215 | getGenericDraweeHierarchy().setPlaceholderImage(pDrawable);
216 | return getThis();
217 | }
218 |
219 | public Image setPlaceholderImage(@NonNull Drawable pDrawable, @NonNull ScalingUtils.ScaleType pScaleType) {
220 | getGenericDraweeHierarchy().setPlaceholderImage(pDrawable, pScaleType);
221 | return getThis();
222 | }
223 |
224 | /**
225 | * 修改请求失败的图像
226 | */
227 | public Image setFailureImage(@DrawableRes int resId) {
228 | getGenericDraweeHierarchy().setFailureImage(resId);
229 | return getThis();
230 | }
231 |
232 | public Image setFailureImage(@DrawableRes int resId, @NonNull ScalingUtils.ScaleType pScaleType) {
233 | getGenericDraweeHierarchy().setFailureImage(resId, pScaleType);
234 | return getThis();
235 | }
236 |
237 | public Image setFailureImage(@NonNull Drawable pDrawable) {
238 | getGenericDraweeHierarchy().setFailureImage(pDrawable);
239 | return getThis();
240 | }
241 |
242 | public Image setFailureImage(@NonNull Drawable pDrawable, @NonNull ScalingUtils.ScaleType pScaleType) {
243 | getGenericDraweeHierarchy().setFailureImage(pDrawable, pScaleType);
244 | return getThis();
245 | }
246 |
247 | /**
248 | * 加载失败重试显示的图片,会触发点击重试四次,如果还是加载失败,则显示请求失败的图像
249 | */
250 | public Image setRetryImage(@DrawableRes int resId) {
251 | getPipelineDraweeControllerBuilder().setTapToRetryEnabled(true);
252 | getGenericDraweeHierarchy().setRetryImage(resId);
253 | return getThis();
254 | }
255 |
256 | public Image setRetryImage(@DrawableRes int resId, @NonNull ScalingUtils.ScaleType pScaleType) {
257 | getPipelineDraweeControllerBuilder().setTapToRetryEnabled(true);
258 | getGenericDraweeHierarchy().setRetryImage(resId, pScaleType);
259 | return getThis();
260 | }
261 |
262 | public Image setRetryImage(@NonNull Drawable pDrawable) {
263 | getPipelineDraweeControllerBuilder().setTapToRetryEnabled(true);
264 | getGenericDraweeHierarchy().setRetryImage(pDrawable);
265 | return getThis();
266 | }
267 |
268 | public Image setRetryImage(@NonNull Drawable pDrawable, @NonNull ScalingUtils.ScaleType pScaleType) {
269 | getPipelineDraweeControllerBuilder().setTapToRetryEnabled(true);
270 | getGenericDraweeHierarchy().setRetryImage(pDrawable, pScaleType);
271 | return getThis();
272 | }
273 |
274 | /**
275 | * 显示进度条图片 -> view底部会有一个深蓝色的矩形进度条
276 | * * 支持AnimationDrawable动画,xml自定义动画
277 | * * 如需精确显示进度 参考-> https://www.fresco-cn.org/docs/progress-bars.html
278 | */
279 | public Image setProgressBarImage(@DrawableRes int resId) {
280 | getGenericDraweeHierarchy().setProgressBarImage(resId);
281 | return getThis();
282 | }
283 |
284 | public Image setProgressBarImage(@DrawableRes int resId, @NonNull ScalingUtils.ScaleType pScaleType) {
285 | getGenericDraweeHierarchy().setProgressBarImage(resId, pScaleType);
286 | return getThis();
287 | }
288 |
289 | public Image setProgressBarImage(@NonNull Drawable pDrawable) {
290 | getGenericDraweeHierarchy().setProgressBarImage(pDrawable);
291 | return getThis();
292 | }
293 |
294 | public Image setProgressBarImage(@NonNull Drawable pDrawable, @NonNull ScalingUtils.ScaleType pScaleType) {
295 | getGenericDraweeHierarchy().setProgressBarImage(pDrawable, pScaleType);
296 | return getThis();
297 | }
298 |
299 | /**
300 | * 设置背景图像
301 | */
302 | public Image setBackgroundImage(@NonNull Drawable pDrawable) {
303 | getGenericDraweeHierarchy().setBackgroundImage(pDrawable);
304 | return getThis();
305 | }
306 |
307 | /**
308 | * 设置一个新的覆盖图像 -> 在指定的索引位置。
309 | */
310 | public Image setOverlayImage(@NonNull Drawable pDrawable) {
311 | getGenericDraweeHierarchy().setOverlayImage(pDrawable);
312 | return getThis();
313 | }
314 |
315 | public Image setOverlayImage(@IntRange(from = 0) int index, @NonNull Drawable pDrawable) {
316 | getGenericDraweeHierarchy().setOverlayImage(index, pDrawable);
317 | return getThis();
318 | }
319 |
320 | /**
321 | * 设置控制器监听
322 | */
323 | public Image setControllerListener(@NonNull ControllerListener super ImageInfo> pListener) {
324 | getPipelineDraweeControllerBuilder().setControllerListener(pListener);
325 | return getThis();
326 | }
327 |
328 | /**
329 | * 指定ImageView2的宽高比
330 | */
331 | public Image setAspectRatio(@IntRange(from = 0) int widthRatio, @IntRange(from = 0) int heightRatio) {
332 | if (widthRatio <= 0 || heightRatio <= 0) {
333 | throw new ArithmeticException("widthRatio or heightRatio must > 0");
334 | }
335 | mImageView2.setAspectRatio(Float.parseFloat(String.valueOf(widthRatio)) / heightRatio);
336 | return getThis();
337 | }
338 |
339 | /**
340 | * 修改"要显示的图片"的缩放类型
341 | */
342 | public Image setActualImageScaleType(@NonNull ScalingUtils.ScaleType pScaleType) {
343 | getGenericDraweeHierarchy().setActualImageScaleType(pScaleType);
344 | return getThis();
345 | }
346 |
347 | /**
348 | * 修改"要显示的图片"的color filter
349 | */
350 | public Image setActualImageColorFilter(@NonNull ColorFilter pColorFilter) {
351 | getGenericDraweeHierarchy().setActualImageColorFilter(pColorFilter);
352 | return getThis();
353 | }
354 |
355 | /**
356 | * 如果选择缩放类型为ScalingUtils.ScaleType.FOCUS_CROP
357 | * 需要指定一个居中点:new PointF(0.5f,0.5f)
358 | */
359 | public Image setActualImageFocusPoint(@NonNull PointF pFocusPoint) {
360 | getGenericDraweeHierarchy().setActualImageFocusPoint(pFocusPoint);
361 | return getThis();
362 | }
363 |
364 | /**
365 | * 修改圆角|圆形参数
366 | */
367 | public Image setRoundingParams(@FloatRange(from = 0) float pRadius, @ColorInt int pOverlayColor, @IntRange(from = 0) int pBorder, @ColorInt int pBorderColor, boolean isCircle) {
368 | RoundingParams roundingParams = getGenericDraweeHierarchy().getRoundingParams();
369 | if (roundingParams == null) {
370 | roundingParams = new RoundingParams();
371 | }
372 | roundingParams.setCornersRadius(pRadius); // 设置圆角|圆形的角度 180度会变成圆形
373 | roundingParams.setOverlayColor(pOverlayColor); // 设置覆盖的颜色
374 | roundingParams.setBorder(pBorderColor, pBorder); // 设置边框尺寸和颜色
375 | roundingParams.setRoundAsCircle(isCircle); // 是否设置为圆型
376 | setRoundingParams(roundingParams);
377 | return getThis();
378 | }
379 |
380 | public Image setRoundingParams(@NonNull RoundingParams pRoundingParams) {
381 | getGenericDraweeHierarchy().setRoundingParams(pRoundingParams);
382 | return getThis();
383 | }
384 |
385 | /**
386 | * 渐显的时长 -> 毫秒
387 | */
388 | public Image setFadeDuration(@IntRange(from = 0) int pFadeDuration) {
389 | getGenericDraweeHierarchy().setFadeDuration(pFadeDuration);
390 | return getThis();
391 | }
392 |
393 | /**
394 | * Resizing缩放模式所需宽高参数
395 | */
396 | public Image setResizeOptions(@IntRange(from = 0) int width, @IntRange(from = 0) int height) {
397 | return setResizeOptions(new ResizeOptions(width, height));
398 | }
399 |
400 | public Image setResizeOptions(@NonNull ResizeOptions pResizeOptions) {
401 | getPipelineDraweeControllerBuilder();
402 | mResizeOptions = pResizeOptions;
403 | return getThis();
404 | }
405 |
406 | /**
407 | * 自动旋转(支持JPEG格式) -> 不管图片方向是怎样的,显示时都会将图片的方向与设备屏幕的方向保持一致
408 | */
409 | public Image setAutoRotateEnabled(boolean isEnabled) {
410 | getPipelineDraweeControllerBuilder();
411 | isAutoRotateEnabled = isEnabled ? 1 : 0;
412 | return getThis();
413 | }
414 |
415 | /**
416 | * 设置后处理器 -> 图片加载完成后对图片进行特殊处理(不支持动图加载)
417 | */
418 | public Image setPostprocessor(@NonNull Postprocessor pPostprocessor) {
419 | getPipelineDraweeControllerBuilder();
420 | mPostprocessor = pPostprocessor;
421 | return getThis();
422 | }
423 |
424 | /**
425 | * 是否开启缩略图式加载
426 | */
427 | public Image setLocalThumbnailPreviewsEnabled(boolean isEnabled) {
428 | getPipelineDraweeControllerBuilder();
429 | isLocalThumbnailPreviewsEnabled = isEnabled ? 1 : 0;
430 | return getThis();
431 | }
432 |
433 | /**
434 | * 是否开启渐进式加载
435 | */
436 | public Image setProgressiveRenderingEnabled(boolean isEnabled) {
437 | getPipelineDraweeControllerBuilder();
438 | isProgressiveRenderingEnabled = isEnabled ? 1 : 0;
439 | return getThis();
440 | }
441 |
442 | /**
443 | * 动画图加载完是否自动播放
444 | */
445 | public Image setAutoPlayAnimations(boolean isAuto) {
446 | getPipelineDraweeControllerBuilder();
447 | isAutoPlayAnimations = isAuto;
448 | return getThis();
449 | }
450 |
451 | /**
452 | * 图片为 GIF | WebP 格式时,设置播放
453 | */
454 | public void animatableStart() {
455 | if (mImageView2 != null && mImageView2.getController() != null && mImageView2.getController().getAnimatable() != null) {
456 | mImageView2.getController().getAnimatable().start();
457 | }
458 | }
459 |
460 | /**
461 | * 图片为 GIF | WebP 格式时,设置暂停
462 | */
463 | public void animatableStop() {
464 | if (mImageView2 != null && mImageView2.getController() != null && mImageView2.getController().getAnimatable() != null) {
465 | mImageView2.getController().getAnimatable().stop();
466 | }
467 | }
468 |
469 | /**
470 | * 图片为 GIF | WebP 格式时,检查是否在播放
471 | */
472 | public boolean animatableIsRunning() {
473 | if (mImageView2 != null && mImageView2.getController() != null && mImageView2.getController().getAnimatable() != null) {
474 | return mImageView2.getController().getAnimatable().isRunning();
475 | }
476 | return false;
477 | }
478 |
479 | /**
480 | * 提交生效
481 | */
482 | public void commit() {
483 | ImageRequest[] imageRequests = null;
484 | String uriStr = "";
485 | if (mFirstAvailableImageUris != null && mFirstAvailableImageUris.length > 0) {
486 | int len = mFirstAvailableImageUris.length;
487 | imageRequests = new ImageRequest[len];
488 | for (int i = 0; i < len; i++) {
489 | imageRequests[i] = ImageRequest.fromUri(mFirstAvailableImageUris[i]);
490 | }
491 | getPipelineDraweeControllerBuilder();
492 | } else if (!TextUtils.isEmpty(mLowImageUri)) {
493 | uriStr = mLowImageUri;
494 | getPipelineDraweeControllerBuilder();
495 | } else if (!TextUtils.isEmpty(mHighImageUri)) {
496 | uriStr = mHighImageUri;
497 | getPipelineDraweeControllerBuilder();
498 | } else if (!TextUtils.isEmpty(mImageUri)) {
499 | uriStr = mImageUri;
500 | }
501 | // 检查路径
502 | if (TextUtils.isEmpty(uriStr)) {
503 | throw new NullPointerException("uri can't null");
504 | }
505 | if (mPipelineDraweeControllerBuilder != null) {
506 | ImageRequest request = mPipelineDraweeControllerBuilder.getImageRequest();
507 | ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(uriStr));
508 | boolean isImageRequestBuilder = false;
509 | // 优先级 : 低分辨率&高分辨率模式 > 缩略图式加载 > 渐进式加载 > 普通加载
510 | // 设置低分辨率&高分辨率模式
511 | if (!TextUtils.isEmpty(mLowImageUri) || !TextUtils.isEmpty(mHighImageUri)) {
512 | if (!TextUtils.isEmpty(mLowImageUri)) {
513 | mPipelineDraweeControllerBuilder.setLowResImageRequest(ImageRequest.fromUri(mLowImageUri));
514 | }
515 | if (!TextUtils.isEmpty(mHighImageUri)) {
516 | mPipelineDraweeControllerBuilder.setImageRequest(ImageRequest.fromUri(mHighImageUri));
517 | }
518 | } else if (isLocalThumbnailPreviewsEnabled == 0 || isLocalThumbnailPreviewsEnabled == 1) {
519 | boolean isEnabled = isLocalThumbnailPreviewsEnabled == 1;
520 | // 设置缩略图式加载
521 | if (request == null || request.getLocalThumbnailPreviewsEnabled() != isEnabled) {
522 | imageRequestBuilder.setLocalThumbnailPreviewsEnabled(isEnabled);
523 | isImageRequestBuilder = true;
524 | }
525 | } else if (isProgressiveRenderingEnabled == 0 || isProgressiveRenderingEnabled == 1) {
526 | boolean isEnabled = isProgressiveRenderingEnabled == 1;
527 | // 设置渐进式加载
528 | if (request == null || request.getProgressiveRenderingEnabled() != isEnabled) {
529 | imageRequestBuilder.setProgressiveRenderingEnabled(isEnabled);
530 | isImageRequestBuilder = true;
531 | }
532 | } else {
533 | // 设置图片请求地址
534 | mPipelineDraweeControllerBuilder.setUri(uriStr);
535 | }
536 | // 设置动画图是否自动播放
537 | if (isAutoPlayAnimations != mPipelineDraweeControllerBuilder.getAutoPlayAnimations()) {
538 | mPipelineDraweeControllerBuilder.setAutoPlayAnimations(isAutoPlayAnimations);
539 | }
540 | // 加载最先可用的图像
541 | if (imageRequests != null && imageRequests.length > 0) {
542 | mPipelineDraweeControllerBuilder.setFirstAvailableImageRequests(imageRequests);
543 | }
544 | // 设置自动旋转(支持JPEG格式) -> 不管图片方向是怎样的,显示时都会将图片的方向与设备屏幕的方向保持一致
545 | if (isAutoRotateEnabled != -1) {
546 | boolean isEnabled = isAutoRotateEnabled == 1;
547 | imageRequestBuilder.setAutoRotateEnabled(isEnabled);
548 | isImageRequestBuilder = true;
549 | }
550 | // 后处理器 -> 图片加载完成后对图片进行特殊处理(不支持动图加载)
551 | if (mPostprocessor != null) {
552 | imageRequestBuilder.setPostprocessor(mPostprocessor);
553 | isImageRequestBuilder = true;
554 | }
555 | // 设置Resizing缩放模式
556 | if (mResizeOptions != null) {
557 | imageRequestBuilder.setResizeOptions(mResizeOptions);
558 | isImageRequestBuilder = true;
559 | }
560 | // 设置ImageRequest
561 | if (isImageRequestBuilder) {
562 | mPipelineDraweeControllerBuilder.setImageRequest(imageRequestBuilder.build());
563 | }
564 | mPipelineDraweeControllerBuilder.setOldController(mImageView2.getController());
565 | mImageView2.setController(mPipelineDraweeControllerBuilder.build());
566 | } else {
567 | // 设置图片请求地址
568 | mImageView2.setImageURI(uriStr, mCallerContext);
569 | }
570 | }
571 |
572 | //------------------------- 阉割部分功能,无法正常支持-------------------------
573 |
574 | /**
575 | * ImageRequest的更多功能
576 | */
577 | private Image setImageDecodeOptions() {
578 | /*ImageDecodeOptions decodeOptions = ImageDecodeOptions.newBuilder()
579 | .setBackgroundColor(Color.GREEN)
580 | .build();
581 | ImageRequest.setImageDecodeOptions(decodeOptions);*/
582 | return getThis();
583 | }
584 |
585 | /**
586 | * 设置图片请求等级 : 参考-> https://www.fresco-cn.org/docs/image-requests.html
587 | */
588 | private Image setLowestPermittedRequestLevel() {
589 | //ImageRequest.setLowestPermittedRequestLevel(RequestLevel.FULL_FETCH);
590 | return getThis();
591 | }
592 |
593 | /**
594 | * 设置按压状态下的叠加图
595 | */
596 | private Image setPressedStateOverlay(@NonNull Drawable pDrawable) {
597 | //GenericDraweeHierarchyBuilder.setPressedStateOverlay(pDrawable);
598 | return getThis();
599 | }
600 |
601 | //------------------------------private 函数 -> 无需关心 -----------------------------
602 | private Image getThis() {
603 | return this;
604 | }
605 |
606 | private void init() {
607 | mImageUri = "";
608 | mLowImageUri = "";
609 | mHighImageUri = "";
610 | mFirstAvailableImageUris = null;
611 | mCallerContext = null;
612 | mPostprocessor = null;
613 | mResizeOptions = null;
614 | isAutoPlayAnimations = false;
615 | isAutoRotateEnabled = -1;
616 | isLocalThumbnailPreviewsEnabled = -1;
617 | isProgressiveRenderingEnabled = -1;
618 | }
619 |
620 | private Image setImageURI(@NonNull String pImageUri, @NonNull Object pCallerContext) {
621 | if (TextUtils.isEmpty(pImageUri)) {
622 | throw new NullPointerException("imageUri can't null or ''");
623 | }
624 | mImageUri = pImageUri;
625 | mCallerContext = pCallerContext;
626 | return getThis();
627 | }
628 |
629 | private GenericDraweeHierarchy mGenericDraweeHierarchy;
630 |
631 | private GenericDraweeHierarchy getGenericDraweeHierarchy() {
632 | mGenericDraweeHierarchy = mImageView2.getHierarchy();
633 | if (mGenericDraweeHierarchy == null) {
634 | mImageView2.setHierarchy(new GenericDraweeHierarchyBuilder(mContext.getResources()).build());
635 | mGenericDraweeHierarchy = mImageView2.getHierarchy();
636 | }
637 | return mGenericDraweeHierarchy;
638 | }
639 |
640 | private PipelineDraweeControllerBuilder mPipelineDraweeControllerBuilder;
641 |
642 | private PipelineDraweeControllerBuilder getPipelineDraweeControllerBuilder() {
643 | if (mPipelineDraweeControllerBuilder == null) {
644 | mPipelineDraweeControllerBuilder = Fresco.newDraweeControllerBuilder();
645 | }
646 | return mPipelineDraweeControllerBuilder;
647 | }
648 | }
649 | }
650 |
--------------------------------------------------------------------------------
/frescoview/src/main/java/com/acmenxd/frescoview/FrescoViewDoc.java:
--------------------------------------------------------------------------------
1 | package com.acmenxd.frescoview;
2 |
3 | /**
4 | * @author AcmenXD
5 | * @version v1.0
6 | * @github https://github.com/AcmenXD
7 | * @date 2017/1/20 11:34
8 | * @detail ImageView2 说明文档
9 | * 支持图片格式:PNG / GIF / WebP / JPEG
10 | * * 注意 : 此控件虽继承自ImageView,但是不要适用所有ImageView的属性和方法
11 | * * 注意 : 此空间不允许指定:android:layout_height="wrap_content",除非你指定了特定的宽高比:Image.setAspectRatio(4:3)
12 | * * 封装注意: 与原生相比,此封装使用GenericDraweeHierarchy的功能,无法支持GenericDraweeHierarchyBuilder的功能
13 | * * 优先级 : 加载最先可用图片 > 低分辨率&高分辨率 > 缩略图式加载 > 渐进式加载
14 | * * 优先级 : setFirstAvailableImageURIs > setLowImageURI > setHighImageURI > setImageURI
15 | * * 后处理器 : setPostprocessor() 图片加载完成后对图片进行特殊处理 参考-> https://www.fresco-cn.org/docs/modifying-image.html
16 | * * 自定义View : 单图 | 多图 参考-> https://www.fresco-cn.org/docs/writing-custom-views.html
17 | * * 缩放模式 :
18 | * -----1.Scaling 画布操作,通常是由硬件加速的.图片实际大小保持不变,只是在绘制时被放大或缩小.(Android 4.0 及以后,在配置 GPU 的设备上会启用硬件加速)
19 | * -------适用: 图片的像素数 < 视图量级(长 x 宽) x 2
20 | * -------用法: layout_width 和 layout_height 并制定缩放类型ScalingUtils.ScaleType
21 | * -----2.Resizing 不改变原始图片,只是在解码前修改内存中的图片大小.(目前只支持JPEG格式,由软件执行的,相比硬件加速的scale操作较慢)
22 | * -------适用: 图片的像素数 > 视图量级(长 x 宽) x 2
23 | * -------用法:setResizeOptions(width,height)
24 | * -----3.Downsampling (向下采样)如果开启该选项,会向下采样你的图片,代替Resizing操作,但仍然需要在每个图片请求中调用setResizeOptions(width,height)
25 | * -------在大部分情况下比Resizing更快.除了支持JPEG图片,它还支持PNG和WebP(除动画外)图片
26 | * -------目前存在一个缺陷: 在Android 4.4上会在解码时造成更多的内存开销(相比于Resizing).这在同时解码许多大图时会非常显著
27 | * -------适用: 图片的像素数 > 视图量级(长 x 宽) x 2 的 非JPEG格式图片
28 | * -------用法: 在ImageUtils的config中配置setDownsampleEnabled(true) 并 在每个图片请求中调用setResizeOptions(width,height)
29 | */
30 | public class FrescoViewDoc {
31 | /*
32 | -----------------------------xml布局属性详解-------------------------------------
33 | fresco:fadeDuration="300" //渐显的时长
34 | fresco:actualImageScaleType="focusCrop" //设置图片缩放. 通常使用focusCrop,该属性值会通过算法把人头像放在中间
35 | fresco:placeholderImage="@color/wait_color" //占位图,请求图片加载完成之前显示
36 | fresco:placeholderImageScaleType="fitCenter" //占位图缩放类型
37 | fresco:failureImage="@drawable/error" //加载失败的时候显示的图片
38 | fresco:failureImageScaleType="centerInside" //缩放类型
39 | fresco:retryImage="@drawable/retrying" //加载失败,提示用户点击重新加载的图片,会重试4次,都失败后会显示failureImage
40 | fresco:retryImageScaleType="centerCrop" //缩放类型
41 | fresco:progressBarImage="@drawable/progress_bar" //提示用户正在加载,和加载进度无关(下载过程中显示的图片)
42 | fresco:progressBarImageScaleType="centerInside"//缩放类型
43 | fresco:progressBarAutoRotateInterval="1000"
44 | fresco:backgroundImage="@color/blue" //背景图片
45 | fresco:overlayImage="@drawable/watermark" //覆盖图像
46 | fresco:pressedStateOverlayImage="@color/red" //按压状态下的叠加图
47 | fresco:roundAsCircle="false" //是否设置为圆形
48 | fresco:roundedCornerRadius="1dp" //圆角角度,180的时候会变成圆形图片
49 | fresco:roundTopLeft="true" //左上角是否改变角度
50 | fresco:roundTopRight="false" //右上角是否改变角度
51 | fresco:roundBottomLeft="false" //左下角是否改变角度
52 | fresco:roundBottomRight="true" //右下角是否改变角度
53 | fresco:roundWithOverlayColor="@color/corner_color" //覆盖色,圆角|圆形 之外的填充色
54 | fresco:roundingBorderWidth="2dp" //边框宽度
55 | fresco:roundingBorderColor="@color/border_color" //边框颜色
56 | */
57 | /*
58 | ----------------------------ScalingUtils.ScaleType : 缩放类型详解 -> https://www.fresco-cn.org/docs/scaling.html-------------------------------------
59 | center 居中,无缩放。
60 | centerCrop 保持宽高比缩小或放大,使得两边都大于或等于显示边界,且宽或高契合显示边界。居中显示。
61 | focusCrop 同centerCrop, 但居中点不是中点,而是指定的某个点。
62 | centerInside 缩放图片使两边都在显示边界内,居中显示。和 fitCenter 不同,不会对图片进行放大。
63 | 如果图尺寸大于显示边界,则保持长宽比缩小图片。
64 | fitCenter 保持宽高比,缩小或者放大,使得图片完全显示在显示边界内,且宽或高契合显示边界。居中显示。
65 | fitStart 同上。但不居中,和显示边界左上对齐。
66 | fitEnd 同fitCenter, 但不居中,和显示边界右下对齐。
67 | fitXY 不保存宽高比,填充满显示边界。
68 | none 如要使用tile mode(平铺)显示, 需要设置为none
69 | */
70 | /*
71 | ----------------------------ImageView2.image 方法解释 -------------------------------------
72 | void reset(); //重置所有配置
73 | Image setImageURI(String pImageUri); //设置图片请求地址 *远程图片 http:// https:// *本地文件 file:// *res目录下的资源 res:// *asset目录下的资源 asset:// *Content provider content://
74 | Image setImageURI(int resId);
75 | Image setLowImageURI(String pLowImageUri); //先显示低分辨率的图,然后是高分辨率的图(优先级 > setHighImageURI > setImageURI)
76 | Image setHighImageURI(String pHighImageUri); //先显示低分辨率的图,然后是高分辨率的图(优先级 > setImageURI)
77 | Image setFirstAvailableImageURIs(String... pFirstAvailableImageUris) //加载最先可用的图像(同一个图片有多个Uri的情况下,设置多个Uri路径) * 显示规则:检查集合中任意uri是否存在,如存在则显示,如不存在,则寻找磁盘缓存,如不存在,则外部请求
78 | Image setPlaceholderImage(int resId) //修改占位图
79 | Image setPlaceholderImage(int resId, ScalingUtils.ScaleType pScaleType)
80 | Image setPlaceholderImage(Drawable pDrawable)
81 | setPlaceholderImage(Drawable pDrawable, ScalingUtils.ScaleType pScaleType)
82 | Image setFailureImage(int resId) //修改请求失败的图像
83 | Image setFailureImage(int resId, ScalingUtils.ScaleType pScaleType)
84 | Image setFailureImage(Drawable pDrawable)
85 | Image setFailureImage(Drawable pDrawable, ScalingUtils.ScaleType pScaleType)
86 | Image setRetryImage(int resId) //加载失败重试显示的图片,会触发点击重试四次,如果还是加载失败,则显示请求失败的图像
87 | Image setRetryImage(int resId, ScalingUtils.ScaleType pScaleType)
88 | Image setRetryImage(Drawable pDrawable)
89 | Image setRetryImage(Drawable pDrawable, ScalingUtils.ScaleType pScaleType)
90 | Image setProgressBarImage(int resId) //显示进度条图片 -> view底部会有一个深蓝色的矩形进度条 * 支持AnimationDrawable动画,xml自定义动画 * 如需精确显示进度 参考-> https://www.fresco-cn.org/docs/progress-bars.html
91 | Image setProgressBarImage(int resId, ScalingUtils.ScaleType pScaleType)
92 | Image setProgressBarImage(Drawable pDrawable)
93 | Image setProgressBarImage(Drawable pDrawable, ScalingUtils.ScaleType pScaleType)
94 | Image setBackgroundImage(Drawable pDrawable) //设置背景图像
95 | Image setOverlayImage(Drawable pDrawable) //设置一个新的覆盖图像 -> 在指定的索引位置。
96 | Image setOverlayImage(Drawable pDrawable) //设置一个新的覆盖图像 -> 在指定的索引位置。
97 | Image setOverlayImage(int index, Drawable pDrawable)
98 | Image setControllerListener(ControllerListener super ImageInfo> pListener) //设置控制器监听
99 | Image setAspectRatio(int widthRatio, int heightRatio) //指定ImageView2的宽高比
100 | Image setActualImageScaleType(ScalingUtils.ScaleType pScaleType) //修改"要显示的图片"的缩放类型
101 | Image setActualImageColorFilter(ColorFilter pColorFilter) //修改"要显示的图片"的color filter
102 | Image setActualImageFocusPoint(PointF pFocusPoint) //如果选择缩放类型为ScalingUtils.ScaleType.FOCUS_CROP 需要指定一个居中点:new PointF(0.5f,0.5f)
103 | Image setRoundingParams(float pRadius, int pOverlayColor, int pBorder, int pBorderColor, boolean isCircle) // 修改圆角|圆形参数
104 | Image setRoundingParams(RoundingParams pRoundingParams)
105 | // 设置圆角|圆形的角度 180度会变成圆形 // 设置覆盖的颜色 // 设置边框尺寸和颜色 // 是否设置为圆型
106 | Image setFadeDuration(int pFadeDuration) //渐显的时长 -> 毫秒
107 | Image setResizeOptions(int width, int height) //Resizing缩放模式所需宽高参数
108 | Image setResizeOptions(ResizeOptions pResizeOptions)
109 | Image setAutoRotateEnabled(boolean isEnabled) //自动旋转(支持JPEG格式) -> 不管图片方向是怎样的,显示时都会将图片的方向与设备屏幕的方向保持一致
110 | Image setPostprocessor(Postprocessor pPostprocessor) //设置后处理器 -> 图片加载完成后对图片进行特殊处理(不支持动图加载)
111 | Image setLocalThumbnailPreviewsEnabled(boolean isEnabled) //是否开启缩略图式加载
112 | Image setProgressiveRenderingEnabled(boolean isEnabled) //是否开启渐进式加载
113 | Image setAutoPlayAnimations(boolean isAuto) //动画图加载完是否自动播放
114 | void animatableStart() //图片为 GIF | WebP 格式时,设置播放
115 | void animatableStop() //图片为 GIF | WebP 格式时,设置暂停
116 | boolean animatableIsRunning() //图片为 GIF | WebP 格式时,检查是否在播放
117 | void commit() //提交生效
118 | */
119 |
120 | }
--------------------------------------------------------------------------------
/frescoview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | frescoview
3 |
4 |
--------------------------------------------------------------------------------
/frescoview/src/test/java/com/acmenxd/frescoview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.acmenxd.frescoview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AcmenXD/FrescoView/af6e3f4c4e8fb352ee3c2b69665522c8decedf64/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jun 14 10:26:59 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/pic/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AcmenXD/FrescoView/af6e3f4c4e8fb352ee3c2b69665522c8decedf64/pic/1.jpg
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':frescoview'
2 |
--------------------------------------------------------------------------------