这是英文文档的第三部分:THIRD PARTY LIBRARIES


Using Other Network Layers

By default, the image pipeline uses theHttpURLConnectionnetworking library bundled with Android. Apps may have their own network layer they may wish to use instead.

Using OkHttp

OkHttpis a popular open-source networking library. The image pipeline has a backend that uses OkHttp instead of the Android default.

In order to use it, thedependenciessection of yourbuild.gradlefile needs to be changed. Donotuse the Gradle dependencies given on thedownloadpage. Use these instead:

dependencies {  // your project's other dependencies  compile "com.facebook.fresco:fresco:0.2.0+"  compile "com.facebook.fresco:imagepipeline-okhttp:0.2.0+"}

You must also configure the image pipeline a little differently. Instead of usingImagePipelineConfig.newBuilder, useOkHttpImagePipelineConfigFactoryinstead:

Context context;OkHttpClient okHttpClient; // build on your ownImagePipelineConfig config = OkHttpImagePipelineConfigFactory    .newBuilder(context, okHttpClient)    . // other setters    . // setNetworkFetcher is already called for you    .build();Fresco.initialize(context, config);

Using your own network fetcher (optional)

For complete control on how the networking layer should behave, you can provide one for your app. You must subclassNetworkFetcher, which controls communications to the network. You can also optionally subclassFetchState, which is a data structure for request-specific information.

Our default implementation forHttpURLConnectioncan be used as an example. Seeits source code.

You must pass your network producer to the image pipeline whenconfiguring it:

ImagePipelineConfig config = ImagePipelineConfig.newBuilder()  .setNetworkFetcher(myNetworkFetcher);  . // other setters  .build();Fresco.initialize(context, config);


Using Other Image Loaders

Drawee is not tied to a particular image loading mechanism and can be used with other image loaders.

However, some of its features are only available on the Fresco image pipeline. Any feature in the preceding pages that required using anImageRequestorconfigurationmay not work with a different loader.

Using Drawee with Volley ImageLoader

We have an backend for Drawee that allows Volley'sImageLoaderto be used instead of Fresco's image pipeline.

We only recommend this for apps that already have a significant investment in Volley ImageLoader.

In order to use it, thedependenciessection of yourbuild.gradlefile needs to be changed. Donotuse the Gradle dependencies given on thedownloadpage. Use this instead:

dependencies {  // your project's other dependencies  compile: "com.facebook.fresco:drawee-volley:0.2.0+"}

Initializing with Volley ImageLoader

Do not callFresco.initialize. You must do yourself for Volley what it does with the image pipeline:

Context context;ImageLoader imageLoader; // build yourselfVolleyDraweeControllerBuilderSupplier mControllerBuilderSupplier    = new VolleyDraweeControllerBuilderSupplier(context, imageLoader);SimpleDraweeView.initialize(mControllerBuilderSupplier);

Do not let theVolleyDraweeControllerBuilderSupplierout of scope; you need it to build controllers, unless you always useSimpleDraweeView.setImageURI.

Using DraweeControllers with Volley ImageLoader

Instead of callingFresco.newControllerBuilder, call

VolleyController controller = mControllerBuilderSupplier    .newControllerBuilder()    . // setters    .build();mSimpleDraweeView.setController(controller);

Using Drawee with other image loaders

No other Drawee backends have been built yet, though it is possible to do so using theVolley exampleas a model.

第5部分:CONTRIBUTING TO FRESCO

Building from Source

You should only build from source if you need to modify Fresco code itself. Most applications should simplyincludeFresco in their project.

Prerequisites

The following tools must be installed on your system in order to build Fresco:

  1. The AndroidSDK
  2. From the Android SDK Manager, install the Support Libraryandthe Support Repository. Both are found in the Extras section.
  3. The AndroidNDK. Version 10c or later is required.
  4. Thegitversion control system.

You don't need to download Gradle itself; the build scripts or Android Studio will do that for you.

Fresco does not support source builds with Eclipse, Ant, or Maven. We do not plan to ever add such support. Maven projects can stillincludeFresco, and we hope to later add Eclipse and Ant support.

Configuring Gradle

Both command-line and Android Studio users need to edit thegradle.propertiesfile. This is normally located in your home directory, in a subdirectory called.gradle. If it is not already there, create it.

On Unix-like systems, including Mac OS X, add a line like this:

ndk.path=/path/to/android_ndk/r10d

On Windows systems, add a line like this:

ndk.path=C\:\\path\\to\\android_ndk\\r10d

Windows' backslashes and colons need to be escaped in order for Gradle to read them correctly.

Getting the source

git clone https://github.com/facebook/fresco.git

This will create a directoryfrescowhere the code will live.

Building from the Command Line

On Unix-like systems,cdto the directory containing Fresco. Run the following command:

./gradlew build

On Windows, open a Command Prompt,cdto the directory containing Fresco, and type in this command:

gradlew.bat build

Building from Android Studio

From Android Studio's Quick Start dialog, click Import Project. Navigate to the directory containing Fresco and click on thebuild.gradlefile.

Android Studio should build Fresco automatically.

Offline builds

The first time you build Fresco, your computer must be connected to the Internet. Incremental builds can use Gradle's--offlineoption.

Contributing code upstream

Please see ourCONTRIBUTINGpage.




更多相关文章

  1. Android设置通知栏/状态栏透明改变通知栏颜色和app最上部分颜色
  2. Android官方入门文档[1]创建一个Android项目
  3. Android读取Word文档
  4. [Android] ACTION_GET_CONTENT与ACTION_PICK的区别
  5. Android(安卓)常用RGB值以及中英文名称
  6. Android(安卓)Volley库源码简析(HTTP Request部分)
  7. Windows环境下Android(安卓)Studio系列4—界面介绍
  8. [中英文对照]android Designing for TV(二) ------ Optimizing N
  9. [中英文对照]android Designing for TV(一) ------ Optimizing L

随机推荐

  1. 开发规范真的很重要
  2. No instrumentation runner found for th
  3. 【Android】利用Strings资源文件来格式化
  4. Android(安卓)sd存储总结
  5. 【Tech-Android-View】Android4.0的横竖
  6. Android(安卓)搭建MVP+Retrofit+RxJava网
  7. Android获取目录
  8. 解决 android "launch error failed to c
  9. 【Android】WebView不完全总结
  10. React Navigation-StackNavigator