Android Fresco image processing library usage API Original English document 4 (Facebook open-source Android Image Library)

Source: Internet
Author: User
Tags image processing library version control system android sdk manager

Android Fresco image processing library usage API Original English document 4 (Facebook open-source Android Image Library)

This is the third part of the English document:THIRD PARTY LIBRARIES

 

 

Using Other Network Layers

 

 

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

Using OkHttp

OkHttp is 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,dependenciesSection of yourbuild.gradleFile needs to be changed. Donot use the Gradle dependencies given on the download page. 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 shoshould behave, you can provide one for your app. you must subclass NetworkFetcher, which controls communications to the network. you can also optionally subclass FetchState, which is a data structure for request-specific information.

Our default implementationHttpURLConnectionCan be used as an example. See its source code.

You must pass your network producer to the image pipeline when processing ing it:

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

 

Drawee is not tied to a participant 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 an ImageRequest or configuration may not work with a different loader.

Using Drawee with Volley ImageLoader

We have an backend for Drawee that allows Volley's ImageLoader to 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,dependenciesSection of yourbuild.gradleFile needs to be changed. Donot use the Gradle dependencies given on the download page. 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 letVolleyDraweeControllerBuilderSupplierOut 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 the Volley example as a model.

Part 1: contributing to FRESCOBuilding from Source

 

You shoshould only build from source if you need to modify Fresco code itself. Most applications shoshould simply include Fresco in their project.

Prerequisites

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

  1. The Android SDK
  2. From the Android SDK Manager, install the Support Library and the Support Repository. Both are found in the Extras section.
  3. The Android NDK. Version 10c or later is required.
  4. The git version 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 still include Fresco, and we hope to later add Eclipse and Ant support.

    Refreshing ing Gradle

    Both command-line and Android Studio users need to editgradle.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 onbuild.gradleFile.

    Android Studio shocould 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 our CONTRIBUTING page.



     

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.