Giter Club home page Giter Club logo

android-http-image-manager's Introduction

This is a simple library that can address most of the requirement of asynchronously dowloading, caching and managing network resource (images).

Loading an image is straightforward:

HttpImageManager.loadImage(new HttpImageManager.LoadRequest(uri, imageView));

Interface

To load an image, one will have to instantiate an HttpImageManager object, then

  • Set a target ImageView for displaying the loaded image
HttpImageManager.loadImage(new HttpImageManager.LoadRequest(uri, imageView));
  • Or set a listener for being notified of the result
        HttpImageManager.loadImage(new HttpImageManager.LoadRequest(uri, new HttpImageManager.OnLoadResponseListener() {

                    @Override
                    public void onLoadResponse(LoadRequest r, Bitmap data) {
                    }
        
                    @Override
                    public void onLoadError(LoadRequest r, Throwable e) {
                    }
        
                    @Override
                    public void onLoadProgress(LoadRequest r, long totalContentSize,
                                long loadedContentSize) {
                    }
        }));

Three-Level Caching Hierarchy

[memory cache] -> [persistent storage cache] -> [network loader]

The memory cache is optional. To use too much memory cache may kill the system resource very fast. It is important to do so with a list view, though.

LIFO Thread Pool

We use a LIFO queue for threading pool. This is to improve responsiveness of a listview, for example, when a user scrolls down the list that loads a quite number of images sequentially.

Write-back Protection for List Adapters

When used in list adapters that utilize techniques of reusing inflated view objects, the same ImageView object might be set as targets in a row of requests for difference resources. Since HttpImageManager works asynchronously, the previously requested resource may come late and gets written back to the wrong ImageView object. To prevent this write-back, we always bind the requested URL to the ImageView object. After the resource being downloaded, a comparison will be performed to check if the ImageView object is still representing the requested URL. This binding is realized by setting the ImageView's tag object. So, caller can not use the setTag() for other purpose during the process of HttpImageManager.

More features

  • Loading progress listener for large full-sized pictures
  • Post manipulation of the loaded image by plugging in BitmapFilter
  • Synchronous call wrapper

android-http-image-manager's People

Contributors

zonghai-li avatar

Watchers

WangJiasheng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.