How to use different configurations using Universal Image Loader?

42 Views Asked by At

I have images that needs to be displayed with different styles, rounded, normal and slightly rounded. How do I set different configurations for different image loaders. I created 2 different configurations and tried calling them, but it doesn't work.

Here is where I get the configurations.

public ImageLoaderConfiguration getConfiguration(int default_image) { Log.d(TAG, "getConfiguration: Setting configuration for image loader");

    DisplayImageOptions displayImageOptions = new DisplayImageOptions.Builder()
            .showImageForEmptyUri(default_image)
            .showImageOnLoading(default_image)
            .showImageOnFail(default_image)
            .cacheOnDisk(true).cacheInMemory(true)
            .cacheOnDisk(true).resetViewBeforeLoading(true)
            .displayer(new RoundedBitmapDisplayer(1000)).build();


    ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(context)
            .defaultDisplayImageOptions(displayImageOptions)
            .memoryCache(new WeakMemoryCache())
            .diskCacheSize(100 * 1024 * 1024).build();

    return configuration;
}


public ImageLoaderConfiguration getConfigurationNormal(int default_image)
{
    Log.d(TAG, "getConfiguration: Setting configuration for image loader");

    DisplayImageOptions displayImageOptions = new DisplayImageOptions.Builder()
            .showImageForEmptyUri(default_image)
            .showImageOnLoading(default_image)
            .showImageOnFail(default_image)
            .cacheOnDisk(true).cacheInMemory(true)
            .cacheOnDisk(true).resetViewBeforeLoading(true).build();


    ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(context)
            .defaultDisplayImageOptions(displayImageOptions)
            .memoryCache(new WeakMemoryCache())
            .diskCacheSize(100 * 1024 * 1024).build();

    return configuration;
}

Here is how I call them.

UniversalImageLoader universalImageLoader = new UniversalImageLoader(getContext());
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.init(universalImageLoader.getConfiguration(R.drawable.resident_boy));


ImageLoader imageLoader1 = ImageLoader.getInstance();
imageLoader1.init(universalImageLoader.getConfigurationNormal(R.drawable.resident_boy));
0

There are 0 best solutions below