Android Explorer Image Cache < Glide> (iii)

Source: Internet
Author: User

Objective:

Before summing up the use of pictures and the LRU algorithm, today to learn a better picture cache open source framework. Technology itself will continue to change, from the original use of softreference to achieve their own picture cache, and then do the e-commerce project their own implementation plan can not meet the needs of the project to Afinal, because afinal no longer maintenance and chose the teacher out of the same xutils, In the middle also exposed to other open source framework such as Picasso, the first impression on the Picasso is not very good, the first contact is to get the company just from the outsourcing company took over the photo-class app, the memory consumption is too large, the direct feeling is caused by the ListView sliding a little bit of lag, Old picture Cache frame Universalimageloader heard that has not really been used, the project is very small, almost millions of levels of the app, has been using the xutils, recently felt that the project is big up, In case Xutils does not maintain or the need to support the picture format more, perhaps Xutils is not the best choice, this is to learn the fundamental motive of Gilde it. Actually wanted to learn Facebook fresco picture frame, but a simple look, need to use with custom control, although powerful, but for the maintenance of the project modification cost that is not general high, later interested in learning it!

Glide Introduction:

Glide is an open source project for Google employees, recommended for Google I/O, a media management framework on an efficient, open source, Android device that follows the BSD, MIT, and Apache 2.0 protocols. Glide has the ability to capture, decode, and display video stills, pictures, animations, and more, as well as flexible APIs that enable developers to apply glide to virtually any network stack. There are two main purposes for creating glide, one is to achieve a smooth picture list scrolling effect, and the other is to support remote picture acquisition, sizing and presentation.

GitHub Address: Https://github.com/bumptech/glide

Glide features
    • Easy to use
    • High degree of adaptability and high degree of adaptation
    • Support Common image format Jpg png gif webp
    • Support multiple data source networks, local, resource, Assets, etc.
    • Efficient cache policy supports memory and disk picture cache default bitmap format is reduced by at least half of rgb_565 RAM usage
    • Lifecycle Integration automates management of requests based on the Activity/fragment life cycle
    • Efficient handling of bitmap use bitmap pool to make bitmap reuse, actively call recycle Reclaim bitmap that need to be recycled, reduce system recovery pressure
Glide simple use 1.) Add Reference build.gradle add configuration
  Compile ' com.github.bumptech.glide:glide:3.7.0 '
2.) Simple loading of picture instances
Glide.with (this). Load (IMAGEURL). into (ImageView);
3.) Configure load and load failed pictures

The API inside the placeholder (), error () function in the polymorphic implementation of the time can be specifically familiar with

Glide.with (this). Load (IMAGEURL). Placeholder (r.mipmap.ic_launcher). Error (R.mipmap.ic_launcher). into ( ImageView);
3.) Configure Load Animations

The API also provides several common animations: such as Crossfade ()

  Glide.with (this). Load (IMAGEURL). Placeholder (r.mipmap.ic_launcher). Error (R.mipmap.ic_launcher). Animate (r.anim.item_alpha_in). into (ImageView);
4.) Configure thumbnail support

This will load the thumbnail and then load the full map

Glide.with (this). Load (IMAGEURL). Placeholder (r.mipmap.ic_launcher). Error (R.mipmap.ic_launcher). Animate (r.anim.item_alpha_in). Thumbnail (0.1f). into (ImageView);
5.) Configure Load Dimensions
Glide.with (this). Load (IMAGEURL). Placeholder (r.mipmap.ic_launcher). Error (R.mipmap.ic_launcher). Animate (r.anim.item_alpha_in). Thumbnail (0.1f). Override (On/off). into (ImageView);
6.) Configure dynamic cropping
Glide.with (this). Load (IMAGEURL). Placeholder (r.mipmap.ic_launcher). Error (R.mipmap.ic_launcher). Animate (r.anim.item_alpha_in). Thumbnail (0.1f). Override (.). Centercrop (). into (ImageView);

The API provides examples such as: Centercrop (), Fitcenter () and other functions can also be customized transformation, such as a person's corner converter

   Public classGlideroundtransformextendsbitmaptransformation {Private floatRadius =0f;  PublicGlideroundtransform (Context context) { This(Context, 4); }         PublicGlideroundtransform (Context context,intDP) {            Super(context);  This. Radius = Resources.getsystem (). Getdisplaymetrics (). Density *DP; } @OverrideprotectedBitmap transform (Bitmappool pool, Bitmap totransform,intOutwidth,intoutheight) {            returnRoundcrop (pool, totransform); }        PrivateBitmap Roundcrop (Bitmappool pool, Bitmap source) {if(Source = =NULL)return NULL; Bitmap result=Pool.get (Source.getwidth (), Source.getheight (), Bitmap.Config.ARGB_8888); if(Result = =NULL) {result=Bitmap.createbitmap (Source.getwidth (), Source.getheight (), Bitmap.Config.ARGB_8888); } Canvas Canvas=NewCanvas (Result); Paint Paint=NewPaint (); Paint.setshader (NewBitmapshader (source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); Paint.setantialias (true); RECTF RECTF=NewRECTF (0f, 0f, Source.getwidth (), Source.getheight ());            Canvas.drawroundrect (RECTF, radius, radius, paint); returnresult; } @Override PublicString getId () {returnGetClass (). GetName () +Math.Round (RADIUS); }    }

Specific use

Glide.with (this). Load (IMAGEURL). Placeholder (r.mipmap.ic_launcher). Error (R.mipmap.ic_launcher). Animate (r.anim.item_alpha_in). Thumbnail (0.1f). Override (On/off). Transform (new glideroundtransform (this ). into (ImageView);
6.) Configure the dynamic target receive picture

There are many things in the project that need to be downloaded before you can do some compositing functions, such as the picture-and-text mix that appears in the project, how to achieve the target

        Glide.with (this). Load (IMAGEURL). Centercrop (). to (new simpletarget<glidedrawable>() {            @Override            publicvoidSuper glidedrawable> glideanimation) {                Imageview.setimagedrawable (Resource);            }        });

Android Explorer Image Cache < Glide> (iii)

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.