Glide-Custom Glide via modules

Source: Internet
Author: User
Preface:

We generally use glide are very simple, only with a simple call to a few methods can be very good to display the picture, but in fact glide in the initialization of a series of default configuration, such as cache configuration, image quality configuration and so on. Let's introduce a more advanced feature. , customize your own personality through modules Glide Glide Series Catalog 1.glide-get started tutorial 2.glide-take bitmap and load animation 3.glide-load local picture 4.glide-load gif 5. glide-binding life cycle 6.glide-memory cache and disk cache 7.glide-Glide 8.glide-custom cache 9.glide-images by modules custom compression 10.glide-picture preprocessing (fillet, Gaussian blur, etc.) 11. glide-picture Tailoring (scaletype) 12.glide-Source Details 1. Create a class implementation Glidemodule

public class Xiayuglidemodule implements Glidemodule {

    @Override public
    void Applyoptions (context context, Glidebuilder builder) {
       //todo
    }

    @Override public
    void registercomponents (context context, Glide Glide) {
       //todo
    }
}
2. Configure the manifest file

To Configure the glidemodule you just created in androidmanifest, you need to add it under the application node

<application> ...

    <meta-data
        android:name= "Com.xiayu.xiayuglidedemo.XiayuGlideModule"
        android:value= "Glidemodule"/ >
</application>

where Android:name is the implementation class of the Glidemodule just created 3. Make a custom configuration

just create the Glidemodule implementation class, will implement two methods, here is to use the Applyoptions method, Applyoptions method inside provides a glidebuilder, With Glidebuilder, we can implement a custom configuration.

public class Xiayuglidemodule implements Glidemodule {

    @Override public
    void Applyoptions (context context, Glidebuilder builder) {

        builder.setdiskcache ();//Custom disk cache

        Builder.setmemorycache ();//Custom Memory Cache

        Builder.setbitmappool (); Custom Picture Pool

        builder.setdiskcacheservice ();//custom local cache thread pool

        builder.setresizeservice ();//thread pool

        for custom core processing Builder.setdecodeformat ();//Custom picture quality

    }

    @Override public
    void registercomponents (context context, Glide Glide) {
        //to
    }
}
4. Example (configure default picture quality)

because glide configuration involves more things, in the future of the article will be on each configuration to explain the specific introduction, here first demonstration of a relatively simple configuration, that is, the picture quality configuration

used Picasso friends should know, Picasso default picture quality is argb_8888, and glide default picture quality is rgb_565, here we will modify the default configuration, let glide the default quality of argb_8888

(argb_8888 refers to a 32-bit graph, which is 4byte per pixel)
(rgb_565 is a 16-bit graph, which is 2byte per pixel)

public class Xiayuglidemodule implements Glidemodule {

    @Override public
    void Applyoptions (context context, Glidebuilder builder) {

        //Custom picture quality
        Builder.setdecodeformat (decodeformat.prefer_argb_8888);

    }

    @Override public
    void registercomponents (context context, Glide Glide) {
        //to
    }
}
5. Other

Multiple glidemodule,glide can be configured in the manifest file, which in turn traverses and reads

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.