GithubHelp home page GithubHelp logo

zhangzwei1988 / android-universal-image-loader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nostra13/android-universal-image-loader

0.0 2.0 0.0 1.72 MB

This project aims to provide a reusable instrument for asynchronous image loading, caching and displaying.

License: Other

android-universal-image-loader's Introduction

Universal Image Loader for Android

This project aims to provide a reusable instrument for asynchronous image loading, caching and displaying. It is originally based on Fedor Vlasov's project and has been vastly refactored and improved since then.

Screenshot

Features

  • Multithread image loading
  • Possibility of wide tuning ImageLoader's configuration (thread pool size, HTTP options, memory and disc cache, display image options, and others)
  • Possibility of image caching in memory and/or on device's file sysytem (or SD card)
  • Possibility to "listen" loading process
  • Possibility to customize every display image call with separated options

Documentation

  • Universal Image Loader. Part 1 - Introduction [RU | EN]
  • Universal Image Loader. Part 2 - Configuration [RU | EN]
  • Universal Image Loader. Part 3 - Usage [RU | EN]

Usage

Simple

ImageView imageView = ...
String imageUrl = "http://site.com/image.png"; // or "file:///mnt/sdcard/images/image.jpg"

// Get singletone instance of ImageLoader
ImageLoader imageLoader = ImageLoader.getInstance();
// Initialize ImageLoader with configuration. Do it once.
imageLoader.init(ImageLoaderConfiguration.createDefault(context));
// Load and display image asynchronously
imageLoader.displayImage(imageUrl, imageView);

Most detailed

ImageView imageView = ...
String imageUrl = "http://site.com/image.png"; // or "file:///mnt/sdcard/images/image.jpg"
ProgressBar spinner = ...
File cacheDir = StorageUtils.getOwnCacheDirectory(getApplicationContext(), "UniversalImageLoader/Cache");

// Get singletone instance of ImageLoader
ImageLoader imageLoader = ImageLoader.getInstance();
// Create configuration for ImageLoader (all options are optional)
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
			.memoryCacheExtraOptions(480, 800)
			.discCacheExtraOptions(480, 800, CompressFormat.JPEG, 75) // Can slow ImageLoader, use it carefully (Better don't use it)
			.threadPoolSize(5)
			.threadPriority(Thread.MIN_PRIORITY + 2)
			.denyCacheImageMultipleSizesInMemory()
			.offOutOfMemoryHandling()
			.memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) // You can pass your own memory cache implementation
			.discCache(new UnlimitedDiscCache(cacheDir)) // You can pass your own disc cache implementation
			.discCacheFileNameGenerator(new HashCodeFileNameGenerator())
			.imageDownloader(new DefaultImageDownloader(5 * 1000, 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s)
			.defaultDisplayImageOptions(DisplayImageOptions.createSimple())
			.enableLogging()
			.build();
// Initialize ImageLoader with created configuration. Do it once.
imageLoader.init(config);

// Creates display image options for custom display task (all options are optional)
DisplayImageOptions options = new DisplayImageOptions.Builder()
                                       .showStubImage(R.drawable.stub_image)
									   .showImageForEmptyUri(R.drawable.image_for_empty_url)
                                       .cacheInMemory()
                                       .cacheOnDisc()
									   .imageScaleType(ImageScaleType.POWER_OF_2)
                                       .build();
// Load and display image
imageLoader.displayImage(imageUrl, imageView, options, new ImageLoadingListener() {
    @Override
    public void onLoadingStarted() {
       spinner.show();
    }
	@Override
	public void onLoadingFailed(FailReason failReason) {
		spinner.hide();
	}
    @Override
    public void onLoadingComplete() {
        spinner.hide();
    }
	@Override
    public void onLoadingCancelled() {
        // Do nothing
    }
});

Useful info

For memory cache configuration (ImageLoaderConfiguration.Builder.memoryCache(...)) you can use already prepared implementations:

  • UsingFreqLimitedMemoryCache (The least frequently used bitmap is deleted when cache size limit is exceeded) - Used by default
  • LRULimitedMemoryCache (Least recently used bitmap is deleted when cache size limit is exceeded)
  • FIFOLimitedMemoryCache (FIFO rule is used for deletion when cache size limit is exceeded)
  • LargestLimitedMemoryCache (The largest bitmap is deleted when cache size limit is exceeded)
  • LimitedAgeMemoryCache (Decorator. Cached object is deleted when its age exceeds defined value)

For disc cache configuration (ImageLoaderConfiguration.Builder.discCache(...)) you can use already prepared implementations:

  • UnlimitedDiscCache (The fastest cache, doesn't limit cache size) - Used by default
  • TotalSizeLimitedDiscCache (Cache limited by total cache size. If cache size exceeds specified limit then file with the most oldest last usage date will be deleted)
  • FileCountLimitedDiscCache (Cache limited by file count. If file count in cache directory exceeds specified limit then file with the most oldest last usage date will be deleted. Use it if your cached files are of about the same size.)
  • LimitedAgeDiscCache (Size-unlimited cache with limited files' lifetime. If age of cached file exceeds defined limit then it will be deleted from cache.)

NOTE: UnlimitedDiscCache is 30%-faster than other limited disc cache implementations.

Applications using Universal Image Loader

License

Copyright (c) 2011-2012, Sergey Tarasevich

If you use Universal Image Loader code in your application you have to inform the author about it (email: nostra13[at]gmail[dot]com). Also you should (but you don't have to) mention it in application UI with string "Used Universal-Image-Loader (c) 2011-2012, Sergey Tarasevich" (e.g. in some "About" section).

Licensed under the BSD 3-clause

android-universal-image-loader's People

Watchers

 avatar  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.