├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── lhh │ │ └── frescoimageview │ │ └── demo │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── lhh │ │ │ └── frescoimageview │ │ │ └── demo │ │ │ ├── App.java │ │ │ ├── FrescoGifImageViewActivity.java │ │ │ ├── FrescoImageViewActivity.java │ │ │ ├── FrescoZoomImageViewActivity.java │ │ │ └── MainActivity.java │ └── res │ │ ├── layout │ │ ├── activity_fresco_imgeview.xml │ │ ├── activity_fresco_zoom_imageview.xml │ │ └── activity_main.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 │ └── lhh │ └── frescoimageview │ └── demo │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lib.lhh.fiv.library ├── .gitignore ├── AndroidManifest.xml ├── build.gradle ├── proguard-rules.pro └── src │ └── lib.lhh.fiv │ └── library │ ├── BaseFrescoImageView.java │ ├── FrescoController.java │ ├── FrescoFactory.java │ ├── FrescoImageView.java │ ├── FrescoZoomImageView.java │ ├── gestures │ ├── MultiPointerGestureDetector.java │ └── TransformGestureDetector.java │ └── zoomable │ ├── DefaultZoomableController.java │ ├── ZoomableController.java │ └── ZoomableDraweeView.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | FrescoImageView -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 25 | 26 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fresco-ImageView 2 | 3 | FrescoImageView是一种Android平台的图像控件,可以异步加载网络图片、项目资源和本地图片,并且支持双指缩放、图片的基本处理以及Fresco的所有特性。 4 | 5 | 该控件基于Facebook的图像加载库Fresco封装,Fresco的所有方法和属性都可以使用。 6 | 7 | Fresco-ImageView本身继承自DraweeView,所以可以直接把它当作DraweeView使用,除使用控件封装的加载方法外还可以通过Fresco原始的ImageRequest来加载图片。 8 | 9 | ## 特性 10 | * 直接继承Fresco的DraweeView,本质是View,同时兼容Fresco的所有参数和方法 11 | * 加载图片只需一步,无需繁杂的设置 12 | * 支持双指缩放,并且支持点击事件,替代PhotoView的控件 13 | 14 | Project site: . 15 | 16 | 最新版本:v1.3.0 17 | 18 | ##导入项目 19 | 20 | **Gradle dependency:** 21 | ``` groovy 22 | compile 'homhomlin.lib:frescoimageview:1.3.0' 23 | ``` 24 | 25 | or 26 | 27 | **Maven dependency:** 28 | ``` xml 29 | 30 | homhomlin.lib 31 | frescoimageview 32 | 1.3.0 33 | 34 | ``` 35 | 36 | 37 | ##用法 38 | 39 | ###导入Fresco 40 | 41 | 在项目导入FrescoImageView后,还需要导入Fresco,如下: 42 | 43 | ``` groovy 44 | compile 'com.facebook.fresco:fresco:0.10.0' 45 | ``` 46 | 47 | 截止至当前Readme编写时间,Fresco的最新版本为0.10.0。 48 | 49 | FrescoImageView本身并不包含Fresco,如果你还需要OKHTTP请查阅Fresco用法或者看这个[DEMO](https://github.com/HomHomLin/FrescoImageView/blob/master/app/src/main/java/com/lhh/frescoimageview/demo/App.java)。 50 | 51 | Fresco-0.10.0与之前版本有所区别,它将GIF和WEBP的库分离出来,所以如果你的项目使用了Fresco-0.10.0并且需要FrescoImageView实现gif和webp的功能,那么请添加以下依赖: 52 | 53 | ``` groovy 54 | compile 'com.facebook.fresco:animated-webp:0.10.0' 55 | compile 'com.facebook.fresco:animated-gif:0.10.0' 56 | ``` 57 | 58 | 如果需要Android2.3版本实现Gif,需要添加额外依赖: 59 | 60 | ``` groovy 61 | compile 'com.facebook.fresco:animated-base-support:0.10.0' 62 | ``` 63 | 64 | ###配置Fresco 65 | 66 | 在项目的AndroidManifest.xml中添加网络访问权限(视需求而定),example中使用了OkHttp,如果你有需要请参照example。 67 | 68 | ```xml 69 | 70 | ``` 71 | 72 | 在项目的Application类中配置Fresco,这里其实是Fresco的内容。 73 | 74 | ``` java 75 | public class App extends Application{ 76 | @Override 77 | public void onCreate() { 78 | super.onCreate(); 79 | Fresco.initialize(this); 80 | } 81 | } 82 | ``` 83 | 84 | ###添加控件到XML 85 | 86 | 在需要添加的界面xml中添加组件。 87 | 88 | FrescoImageView提供两种组件,分别是FrescoImageView(普通控件)和FrescoZoomImageView(可缩放控件),根据需要添加控件,以下以FrescoZoomImageView为例: 89 | 90 | ``` xml 91 | 96 | ``` 97 | 98 | 在代码中find该组件。 99 | 100 | ```java 101 | FrescoZoomImageView frescoImageView = (FrescoZoomImageView)findViewById(R.id.fiv); 102 | ``` 103 | 104 | ###加载网络图片 105 | 106 | 调用void loadView(String url, int defaultResID)方法。 107 | 108 | url表示需要加载的网络图片地址,defaultResID表示占位图(默认图)。 109 | 110 | ```java 111 | frescoImageView.loadView(mImgUrl,R.mipmap.ic_launcher); 112 | ``` 113 | 114 | 如果需要先显示默认图,然后加载显示一张低分辨率的图,最后再显示原图,可以使用void loadView(String lowUrl ,String url, int defaultResID)方法,lowUrl表示低分辨率图片地址。 115 | 116 | ###加载本地图片 117 | 118 | 调用void loadLocalImage(String path, int defaultRes)方法。 119 | 120 | path表示本地图片的绝对路径。 121 | 122 | ```java 123 | frescoImageView.loadLocalImage(path,R.mipmap.ic_launcher); 124 | ``` 125 | 126 | ###加载项目资源 127 | 128 | 选择以上任意一个方法,非defaultResId参数填写为null即可。 129 | 130 | ```java 131 | frescoImageView.loadLocalImage(null,R.mipmap.ic_launcher); 132 | ``` 133 | 134 | ###点击监听 135 | 136 | 如果你使用的是FrescoZoomImageView,则需要调用setOnDraweeClickListener(OnClickListener l)方法来设置点击事件的监听。 137 | 138 | 如果你使用的是FrescoImageView,则可以直接使用setOnClicklistener(OnClickListener l)。 139 | 140 | ###开启和关闭gif动画 141 | 142 | 如果你的图片是gif类型的,则我们可以控制FrescoImageView的Gif动画,通过FrescoImageView的setAnim(boolean anim)来控制,默认情况下,我们是开启动画的。 143 | 144 | ###设置圆形 145 | 146 | 如果你需要将显示的图片变为圆形,则可以通过asCircle()方法。 147 | 148 | ```java 149 | frescoImageView.asCircle(); 150 | ``` 151 | 152 | ###Gif图片设置为圆形 153 | 154 | 由于Fresco的原因,如果你需要将gif设置为圆形,则需要使用setCircle(int overlay_color)方法,overlay_color为背景图颜色。 155 | 156 | ```java 157 | frescoImageView.setCircle(Color.WHITE); 158 | ``` 159 | 160 | ###设置圆角 161 | 162 | 通过setCornerRadius(float radius)方法,并传入需要的角度即可实现圆角和边角的切割。 163 | 164 | ```java 165 | frescoImageView.setCornerRadius(10); 166 | ``` 167 | 168 | ###设置图像处理器 169 | 170 | 你可能需要对图片做额外的处理,那么你可以编写一个Fresco的PostProcessor,并通过setPostProcessor(PostProcessor)方法来设置一个处理器。 171 | 172 | ```java 173 | frescoImageView.setPostProcessor(postProcessor); 174 | ``` 175 | 176 | ###设置是否点击重试加载 177 | 178 | 有时候图片会加载失败,这时候你可以设置是否允许让用户点击该图片重试加载,通过setTapToRetryEnabled(boolean tapToRetryEnabled)方法来设置。 179 | 180 | ```java 181 | frescoImageView.setTapToRetryEnabled(true); 182 | ``` 183 | 184 | ###设置图片边框 185 | 186 | 通过setBorder(int color, float width)方法来设置。 187 | 188 | ```java 189 | frescoImageView.setBorder(Color.BLACK, 3.0f); 190 | ``` 191 | 192 | ###清除图片圆角属性 193 | 194 | 也许你曾经设置过图片的圆角属性了,通过clearRoundingParams()方法可以清除他们来恢复到初始状态。 195 | 196 | ```java 197 | frescoImageView.clearRoundingParams(); 198 | ``` 199 | 200 | ###设置加载监听 201 | 202 | 有时候我们想监听图片加载的情况,通过setControllerListener(ControllerListener controllerListener)方法可以添加监听。 203 | 204 | 通过ControllerListener controllerListener = new BaseControllerListener()可以创建监听器。 205 | 206 | ```java 207 | frescoImageView.setControllerListener(controllerListener); 208 | ``` 209 | 210 | ###其他 211 | 212 | FrescoImageView基于Fresco封装,因此Fresco的用法同样适用于FrescoImageView。 213 | 214 | 同样,FrescoZoomImageView也支持以上说的api和Fresco的方法。 215 | 216 | 具体请看Fresco:[Fresco的Github](https://github.com/facebook/fresco) 217 | 218 | ## Developed By 219 | 220 | * Linhonghong - 221 | 222 | ##License 223 | Copyright 2016 LinHongHong 224 | 225 | Licensed under the Apache License, Version 2.0 (the "License"); 226 | you may not use this file except in compliance with the License. 227 | You may obtain a copy of the License at 228 | 229 | http://www.apache.org/licenses/LICENSE-2.0 230 | 231 | Unless required by applicable law or agreed to in writing, software 232 | distributed under the License is distributed on an "AS IS" BASIS, 233 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 234 | See the License for the specific language governing permissions and 235 | limitations under the License. -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.lhh.frescoimageview.demo" 9 | minSdkVersion 9 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(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.1.1' 26 | compile 'homhomlin.lib:frescoimageview:1.3.0' 27 | compile 'com.facebook.fresco:fresco:0.9.0' 28 | // compile project(':lib.lhh.fiv.library') 29 | compile 'com.facebook.fresco:fresco:0.10.0' 30 | compile 'com.facebook.fresco:animated-gif:0.10.0' 31 | compile 'com.facebook.fresco:imagepipeline-okhttp3:0.10.0' 32 | compile 'com.squareup.okhttp3:okhttp:3.2.0' 33 | } 34 | -------------------------------------------------------------------------------- /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/Linhh/Develop/Android/android-sdk-macosx/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/lhh/frescoimageview/demo/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.lhh.frescoimageview.demo; 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/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/lhh/frescoimageview/demo/App.java: -------------------------------------------------------------------------------- 1 | package com.lhh.frescoimageview.demo; 2 | 3 | import android.app.Application; 4 | 5 | import com.facebook.drawee.backends.pipeline.Fresco; 6 | import com.facebook.imagepipeline.backends.okhttp3.OkHttpImagePipelineConfigFactory; 7 | import com.facebook.imagepipeline.core.ImagePipelineConfig; 8 | 9 | import okhttp3.OkHttpClient; 10 | 11 | /** 12 | * Created by Linhh on 16/2/18. 13 | */ 14 | public class App extends Application{ 15 | @Override 16 | public void onCreate() { 17 | super.onCreate(); 18 | initOKFresco(); 19 | } 20 | 21 | private void initFresco(){ 22 | Fresco.initialize(this); 23 | } 24 | 25 | private void initOKFresco(){ 26 | ImagePipelineConfig frescoConfig = OkHttpImagePipelineConfigFactory 27 | .newBuilder(this, new OkHttpClient()) 28 | .build(); 29 | Fresco.initialize(this,frescoConfig); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/lhh/frescoimageview/demo/FrescoGifImageViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.lhh.frescoimageview.demo; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | 6 | import lib.lhh.fiv.library.FrescoImageView; 7 | 8 | /** 9 | * Created by Linhh on 16/5/6. 10 | */ 11 | public class FrescoGifImageViewActivity extends AppCompatActivity { 12 | 13 | 14 | private String mImgUrl = "http://s1.dwstatic.com/group1/M00/32/EF/21871fbdd4ffa13d7cbf0249aea1d558.gif"; 15 | 16 | @Override 17 | protected void onCreate(Bundle savedInstanceState) { 18 | super.onCreate(savedInstanceState); 19 | setContentView(R.layout.activity_fresco_imgeview); 20 | FrescoImageView frescoImageView = (FrescoImageView)findViewById(R.id.fiv); 21 | frescoImageView.loadView(mImgUrl, R.mipmap.ic_launcher); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/lhh/frescoimageview/demo/FrescoImageViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.lhh.frescoimageview.demo; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | 6 | import lib.lhh.fiv.library.FrescoImageView; 7 | 8 | /** 9 | * Created by Linhh on 16/2/19. 10 | */ 11 | public class FrescoImageViewActivity extends AppCompatActivity { 12 | 13 | private String mImgUrl = "https://avatars1.githubusercontent.com/u/8758713?v=3&s=460"; 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_fresco_imgeview); 19 | FrescoImageView frescoImageView = (FrescoImageView)findViewById(R.id.fiv); 20 | frescoImageView.asCircle(); 21 | frescoImageView.loadView(mImgUrl, R.mipmap.ic_launcher); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/lhh/frescoimageview/demo/FrescoZoomImageViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.lhh.frescoimageview.demo; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.view.View; 6 | import android.widget.Toast; 7 | 8 | import lib.lhh.fiv.library.FrescoZoomImageView; 9 | 10 | /** 11 | * Created by Linhh on 16/2/19. 12 | */ 13 | public class FrescoZoomImageViewActivity extends AppCompatActivity { 14 | 15 | private String mImgUrl = "https://avatars1.githubusercontent.com/u/8758713?v=3&s=460"; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_fresco_zoom_imageview); 21 | final FrescoZoomImageView frescoImageView = (FrescoZoomImageView)findViewById(R.id.fiv); 22 | frescoImageView.loadView(mImgUrl,R.mipmap.ic_launcher); 23 | frescoImageView.setOnDraweeClickListener(new View.OnClickListener() { 24 | @Override 25 | public void onClick(View v) { 26 | Toast.makeText(FrescoZoomImageViewActivity.this,"OnClick",Toast.LENGTH_SHORT).show(); 27 | frescoImageView.asCircle(); 28 | frescoImageView.loadView("https://avatars0.githubusercontent.com/u/66577?v=3&s=460",R.mipmap.ic_launcher); 29 | } 30 | }); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/lhh/frescoimageview/demo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.lhh.frescoimageview.demo; 2 | 3 | import android.content.Intent; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.widget.Button; 8 | 9 | import lib.lhh.fiv.library.FrescoImageView; 10 | import lib.lhh.fiv.library.FrescoZoomImageView; 11 | 12 | public class MainActivity extends AppCompatActivity { 13 | 14 | Button mBtnFrescoNormal; 15 | Button mBtnFrescoZoom; 16 | Button mBtnFrescoGif; 17 | 18 | @Override 19 | protected void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | setContentView(R.layout.activity_main); 22 | mBtnFrescoNormal = (Button)findViewById(R.id.btn_fresco_normal); 23 | mBtnFrescoZoom = (Button)findViewById(R.id.btn_fresco_zoom); 24 | mBtnFrescoGif = (Button)findViewById(R.id.btn_fresco_gif); 25 | mBtnFrescoNormal.setOnClickListener(new View.OnClickListener() { 26 | @Override 27 | public void onClick(View v) { 28 | startActivity(new Intent(MainActivity.this,FrescoImageViewActivity.class)); 29 | } 30 | }); 31 | mBtnFrescoZoom.setOnClickListener(new View.OnClickListener() { 32 | @Override 33 | public void onClick(View v) { 34 | startActivity(new Intent(MainActivity.this,FrescoZoomImageViewActivity.class)); 35 | } 36 | }); 37 | mBtnFrescoGif.setOnClickListener(new View.OnClickListener() { 38 | @Override 39 | public void onClick(View v) { 40 | startActivity(new Intent(MainActivity.this,FrescoGifImageViewActivity.class)); 41 | } 42 | }); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_fresco_imgeview.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_fresco_zoom_imageview.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 |