@linux1s1s
2016-11-21T17:56:35.000000Z
字数 2914
阅读 1908
AndroidRefine
2016-11
系列博文
Android 开源库 - OkHttp
Android 开源库 - Retrofit
Android 开源库 - Okio
Android 开源库 - Fresco
这里仅仅给个如何使用的示例,至于源码剖析可以移步Fresco源码分析的系列文章。
//Fresco
compile 'com.facebook.fresco:fresco:0.14.1'
//Maven
// https://mvnrepository.com/artifact/com.facebook.fresco/
//WebP Not Animated
//compile group: 'com.facebook.fresco', name: 'webpsupport', version: '0.14.1'
//WebP Animated
compile group: 'com.facebook.fresco', name: 'webpsupport', version: '0.14.1'
compile group: 'com.facebook.fresco', name: 'animated-webp', version: '0.14.1'
// GIF
compile group: 'com.facebook.fresco', name: 'animated-gif', version: '0.14.1'
TIPS: 虽然这里没有加入okhttp的依赖,但是
fresco 0.14.1
会自动依赖okhttp(3.3.0)
当然如果你手动指定了okhttp
的版本,这里会自动替换
比如这样指定
// OkHttp
compile 'com.squareup.okhttp3:okhttp:3.4.2'
// OkIo
compile 'com.squareup.okio:okio:1.11.0'
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="okhttp.mutex.com.okhttpdemo">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".OkhttpApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="okhttp.mutex.com.okhttpdemo.MainActivity">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/simple_drawee_view"
android:layout_width="141dp"
android:layout_height="146dp"
android:layout_centerHorizontal="true" />
</ScrollView>
public class MainActivity extends AppCompatActivity {
private static final String WEBP = "http://7xinl9.com1.z0.glb.clouddn.com/Boston-City-Flow.webp";
private static final String WEBP_ANIMATED = "http://7xinl9.com1.z0.glb.clouddn.com/BladeRunner.webp";
private static final String JPG = "http://7xinl9.com1.z0.glb.clouddn.com/20160425150855.png";
private static final String GIF = "http://7xinl9.com1.z0.glb.clouddn.com/10.gif";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initContentView();
}
private void initContentView() {
SimpleDraweeView view = (SimpleDraweeView) findViewById(R.id.simple_drawee_view);
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setUri(Uri.parse(GIF))
.setAutoPlayAnimations(true)
.build();
view.setController(controller);
}
}
经验证,
Fresco-0.14.1
支持JPG,PNG,GIF,Webp,Animated WebP等常见的图片格式。
Tools:JPG Converter to Webp
参考文章:
OkHttp GitHub Doc
Retrofit GitHub DocR Doc
Fresco GitHub Doc
Okio GitHub Video