Skip to content

Commit

Permalink
Changed API: Removed extra Object from ImageLoadingListener callbacks.
Browse files Browse the repository at this point in the history
Added View param instead.
  • Loading branch information
nostra13 committed Feb 9, 2013
1 parent 78c5e26 commit 62270fe
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class DisplayBitmapTask implements Runnable {
private final String imageUri;
private final ImageView imageView;
private final String memoryCacheKey;
private final DisplayImageOptions options;
private final BitmapDisplayer displayer;
private final ImageLoadingListener listener;
private final ImageLoaderEngine engine;

Expand All @@ -33,19 +33,19 @@ public DisplayBitmapTask(Bitmap bitmap, ImageLoadingInfo imageLoadingInfo, Image
imageUri = imageLoadingInfo.uri;
imageView = imageLoadingInfo.imageView;
memoryCacheKey = imageLoadingInfo.memoryCacheKey;
options = imageLoadingInfo.options;
displayer = imageLoadingInfo.options.getDisplayer();
listener = imageLoadingInfo.listener;
this.engine = engine;
}

public void run() {
if (isViewWasReused()) {
if (loggingEnabled) L.i(LOG_TASK_CANCELLED, memoryCacheKey);
listener.onLoadingCancelled(imageUri, options.getExtraForListener());
listener.onLoadingCancelled(imageUri, imageView);
} else {
if (loggingEnabled) L.i(LOG_DISPLAY_IMAGE_IN_IMAGEVIEW, memoryCacheKey);
Bitmap displayedBitmap = options.getDisplayer().display(bitmap, imageView);
listener.onLoadingComplete(imageUri, options.getExtraForListener(), displayedBitmap);
Bitmap displayedBitmap = displayer.display(bitmap, imageView);
listener.onLoadingComplete(imageUri, imageView, displayedBitmap);
engine.cancelDisplayTaskFor(imageView);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.graphics.Bitmap;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.assist.ImageLoadingListener;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.BitmapDisplayer;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
Expand Down Expand Up @@ -47,7 +46,6 @@ public final class DisplayImageOptions {
private final Bitmap.Config bitmapConfig;
private final int delayBeforeLoading;
private final Object extraForDownloader;
private final Object extraForListener;
private final BitmapProcessor preProcessor;
private final BitmapProcessor postProcessor;
private final BitmapDisplayer displayer;
Expand All @@ -63,7 +61,6 @@ private DisplayImageOptions(Builder builder) {
bitmapConfig = builder.bitmapConfig;
delayBeforeLoading = builder.delayBeforeLoading;
extraForDownloader = builder.extraForDownloader;
extraForListener = builder.extraForListener;
preProcessor = builder.preProcessor;
postProcessor = builder.postProcessor;
displayer = builder.displayer;
Expand Down Expand Up @@ -133,10 +130,6 @@ Object getExtraForDownloader() {
return extraForDownloader;
}

Object getExtraForListener() {
return extraForListener;
}

BitmapProcessor getPreProcessor() {
return preProcessor;
}
Expand Down Expand Up @@ -165,7 +158,6 @@ public static class Builder {
private Bitmap.Config bitmapConfig = Bitmap.Config.ARGB_8888;
private int delayBeforeLoading = 0;
private Object extraForDownloader = null;
private Object extraForListener = null;
private BitmapProcessor preProcessor = null;
private BitmapProcessor postProcessor = null;
private BitmapDisplayer displayer = DefaultConfigurationFactory.createBitmapDisplayer();
Expand Down Expand Up @@ -247,15 +239,6 @@ public Builder extraForDownloader(Object extra) {
return this;
}

/**
* Sets auxiliary object which will be passed to {@link ImageLoadingListener
* ImageLoadingListener.onLoading***(...)} callbacks
*/
public Builder extraForListener(Object extra) {
this.extraForListener = extra;
return this;
}

/**
* Sets bitmap processor which will be process bitmaps before they will be cached in memory. So memory cache
* will contain bitmap processed by incoming preProcessor.<br />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,21 +183,21 @@ public void displayImage(String uri, ImageView imageView, DisplayImageOptions op

if (uri == null || uri.length() == 0) {
engine.cancelDisplayTaskFor(imageView);
listener.onLoadingStarted(uri, options.getExtraForListener());
listener.onLoadingStarted(uri, imageView);
if (options.shouldShowImageForEmptyUri()) {
imageView.setImageResource(options.getImageForEmptyUri());
} else {
imageView.setImageBitmap(null);
}
listener.onLoadingComplete(uri, options.getExtraForListener(), null);
listener.onLoadingComplete(uri, imageView, null);
return;
}

ImageSize targetSize = getImageSizeScaleTo(imageView);
String memoryCacheKey = MemoryCacheUtil.generateKey(uri, targetSize);
engine.prepareDisplayTaskFor(imageView, memoryCacheKey);

listener.onLoadingStarted(uri, options.getExtraForListener());
listener.onLoadingStarted(uri, imageView);
Bitmap bmp = configuration.memoryCache.get(memoryCacheKey);
if (bmp != null && !bmp.isRecycled()) {
if (configuration.loggingEnabled) L.i(LOG_LOAD_IMAGE_FROM_MEMORY_CACHE, memoryCacheKey);
Expand All @@ -208,7 +208,7 @@ public void displayImage(String uri, ImageView imageView, DisplayImageOptions op
engine.submit(displayTask);
} else {
options.getDisplayer().display(bmp, imageView);
listener.onLoadingComplete(uri, options.getExtraForListener(), bmp);
listener.onLoadingComplete(uri, imageView, bmp);
}
} else {
if (options.shouldShowStubImage()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private boolean checkTaskIsNotActual() {
handler.post(new Runnable() {
@Override
public void run() {
listener.onLoadingCancelled(uri, options.getExtraForListener());
listener.onLoadingCancelled(uri, imageView);
}
});
}
Expand Down Expand Up @@ -335,7 +335,7 @@ public void run() {
if (options.shouldShowImageOnFail()) {
imageView.setImageResource(options.getImageOnFail());
}
listener.onLoadingFailed(uri, options.getExtraForListener(), failReason);
listener.onLoadingFailed(uri, imageView, failReason);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.nostra13.universalimageloader.core.assist;

import android.graphics.Bitmap;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import android.view.View;

/**
* Listener for image loading process.<br />
Expand All @@ -19,37 +17,33 @@ public interface ImageLoadingListener {
* Is called when image loading task was started
*
* @param imageUri Loading image URI
* @param extra Auxiliary object which was passed to {@link DisplayImageOptions.Builder#extraForListener(Object)
* DisplayImageOptions.extraForListener(Object)}
* @param view View for image
*/
void onLoadingStarted(String imageUri, Object extra);
void onLoadingStarted(String imageUri, View view);

/**
* Is called when an error was occurred during image loading
*
* @param imageUri Loading image URI
* @param extra Auxiliary object which was passed to {@link DisplayImageOptions.Builder#extraForListener(Object)
* DisplayImageOptions.extraForListener(Object)}
* @param view View for image
* @param failReason {@linkplain FailReason The reason} why image loading was failed
*/
void onLoadingFailed(String imageUri, Object extra, FailReason failReason);
void onLoadingFailed(String imageUri, View view, FailReason failReason);

/**
* Is called when image is loaded successfully (and displayed in {@link ImageView} if one was specified)
* Is called when image is loaded successfully (and displayed in View if one was specified)
*
* @param imageUri Loaded image URI
* @param extra Auxiliary object which was passed to {@link DisplayImageOptions.Builder#extraForListener(Object)
* DisplayImageOptions.extraForListener(Object)}
* @param view View for image
* @param loadedImage Bitmap of loaded and decoded image
*/
void onLoadingComplete(String imageUri, Object extra, Bitmap loadedImage);
void onLoadingComplete(String imageUri, View view, Bitmap loadedImage);

/**
* Is called when image loading task was cancelled because {@link ImageView} was reused in newer task
* Is called when image loading task was cancelled because View for image was reused in newer task
*
* @param imageUri Loading image URI
* @param extra Auxiliary object which was passed to {@link DisplayImageOptions.Builder#extraForListener(Object)
* DisplayImageOptions.extraForListener(Object)}
* @param view View for image
*/
void onLoadingCancelled(String imageUri, Object extra);
void onLoadingCancelled(String imageUri, View view);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.nostra13.universalimageloader.core.assist;

import android.graphics.Bitmap;
import android.view.View;

/**
* A convenient class to extend when you only want to listen for a subset of all the image loading events. This
Expand All @@ -10,22 +11,22 @@
*/
public class SimpleImageLoadingListener implements ImageLoadingListener {
@Override
public void onLoadingStarted(String imageUri, Object extra) {
public void onLoadingStarted(String imageUri, View view) {
// Empty implementation
}

@Override
public void onLoadingFailed(String imageUri, Object extra, FailReason failReason) {
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
// Empty implementation
}

@Override
public void onLoadingComplete(String imageUri, Object extra, Bitmap loadedImage) {
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
// Empty implementation
}

@Override
public void onLoadingCancelled(String imageUri, Object extra) {
public void onLoadingCancelled(String imageUri, View view) {
// Empty implementation
}
}

0 comments on commit 62270fe

Please sign in to comment.