Skip to content

Latest commit

 

History

History
140 lines (99 loc) · 4.4 KB

README.textile

File metadata and controls

140 lines (99 loc) · 4.4 KB

ImageLoader

Image loader is a simple library that give you the ability to decouple the logic to fetch, load and cache images.
It does that away from the ui thread, and by caching images with two level in memory or in the sdcard if awailable.

How to use the library

Using maven

If you are using maven you need to define the repo and then the dependency

<repositories>
  <repository>
    <id>public-mvn-repo-releases</id>
    <url>https://github.com/novoda/public-mvn-repo/raw/master/releases</url>
  </repository>
</repositories>
<dependency>
  <groupId>com.novoda.imageloader.core</groupId>
  <artifactId>imageloader-core</artifactId>
 <version>1.3.11</version>
</dependency>

Direct jar usage

If you don’t care about building tool you can just download the jar manually from this link

https://github.com/novoda/public-mvn-repo/raw/master/releases/com/novoda/imageloader/imageloader-core/1.3.11/imageloader-core-1.3.11.jar

How to implement

The demo project is a good way to start. Import it in eclipse and check the task list to see where are all the TODO list.
If you are lazy this are the steps :

Application

In the application add the folling code the instantiate the image loader:


  @Override
  public void onCreate() {
    super.onCreate();
    SettingsBuilder builder = new SettingsBuilder();
    builder.defaultImageId(R.drawable.bg_img_loading);
    Settings settings = builder.build(this);
    imageLoader = new BaseImageLoader(this, settings);
  }

  public static final ImageManager getImageLoader() {
    return imageLoader;
  }

This is setting up the image loader with size of the images that are taken from the display and the background image use while the image loader is fetching the real image.

Cleaning up sdcard

If you want the image loader to clean up the sdcard, you can use the following line of code on the create of the application:


imageManager.reduceFileCache(this);

In the settings you can override the default expiration period that is set to 7 days.

In the activity

When you need to load the image in a view object you just need to get the imageLoader from the application and call load.
This is an example of a list view with the binder setting the url in the imageView as a tag.


private ViewBinder getViewBinder() {
  return new ViewBinder() {
    @Override
    public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
      try {
        ((ImageView) view).setTag(cursor.getString(columnIndex));
        // TODO add this to your class
        imageLoader.load(cursor.getString(columnIndex), ImageLoaderDemoActivity.this,
            (ImageView) view);
        //
      } catch (Exception e) {
        Log.e("ImageLoader", "exception : " + e.getMessage());
      }
      return true;
    }
  };
}

The image loader will fetch the image from the cache if is still there or from the sdcard or will fetch the resource from the network in the worse scenario.

In the manifest

There are two things you need to add : Permissions and the service to clean up the files.


<uses-permission a:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission a:name="android.permission.INTERNET" />
<uses-permission a:name="android.permission.ACCESS_NETWORK_STATE" />


<service android:name="com.novoda.imageloader.core.service.CacheCleaner" android:exported="true">
  <intent-filter>
    <action android:name="com.novoda.imageloader.core.action.CLEAN_CACHE" />
  </intent-filter>
</service>

Helping out with the project

Report issues

If you have any problem with the library or new functionality you need to add, let us know and we will do something about it.
Send us a message or create an issue with github.

ImageLoader projects

  • core contains a java maven based project
  • demo mvn android based project to test imageLoader
  • acceptance mvn android based project with robotium test
  • monkey some example that take a snapshot using monkey runner (deprecated)

Parent project and core

Import the projects with maven, should be easy and painless.

For demo and acceptance

  • run : mvn clean initialize
  • create a new android project in eclipse
  • add the necessary jars from the lib folder

Notes

  • Note : build support sdk 14 as is using the new android-maven-plugin:3.0.0-alpha13