Skip to content

Commit

Permalink
Added source support
Browse files Browse the repository at this point in the history
  • Loading branch information
DHuckaby committed Sep 11, 2013
1 parent b455c3d commit d0bdc7e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
22 changes: 14 additions & 8 deletions library/src/com/handlerexploit/prime/utils/ImageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ public String getSource() {
}

@Override
public void onImageReceived(String source, Bitmap bitmap) {
public void onImageReceived(String url, Bitmap bitmap, Source source) {
if (listener != null) {
listener.onImageReceived(source, bitmap);
listener.onImageReceived(url, bitmap, source);
}
}
});
Expand Down Expand Up @@ -228,7 +228,7 @@ private void get(final ExtendedRequest request) {
final String key = getKey(source);
Bitmap bitmap = getBitmapFromMemory(key, request);
if (bitmap != null) {
request.onImageReceived(source, bitmap);
request.onImageReceived(source, bitmap, Source.MEMORY);
} else {
synchronized (mBadUrlCache) {
if (mBadUrlCache.get(key) != null) {
Expand All @@ -248,7 +248,7 @@ public void run() {

@Override
public void run() {
request.onImageReceived(source, bitmap);
request.onImageReceived(source, bitmap, Source.DISK);
}
});
} else {
Expand All @@ -262,7 +262,7 @@ public void run() {

@Override
public void run() {
request.onImageReceived(source, bitmap);
request.onImageReceived(source, bitmap, Source.NETWORK);
}
});
} else {
Expand Down Expand Up @@ -515,6 +515,12 @@ private static ExecutorService newLowPriorityCachedFixedThreadPool(int maximumPo
return new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, factory, handler);
}

public static enum Source {
MEMORY,
DISK,
NETWORK
}

public static interface BitmapOptionsFactory {

public BitmapFactory.Options newOptionsFromStream(InputStream inputStream, int width, int height);
Expand All @@ -540,7 +546,7 @@ public static interface OnImageReceivedListener {
* Notification that an image was retrieved, this is guaranteed to be
* called on the UI thread.
*/
public void onImageReceived(String source, Bitmap bitmap);
public void onImageReceived(String url, Bitmap bitmap, Source source);
}

/**
Expand Down Expand Up @@ -602,8 +608,8 @@ public SimpleRequest(Request request) {
}

@Override
public void onImageReceived(String source, Bitmap bitmap) {
mRequest.onImageReceived(source, bitmap);
public void onImageReceived(String url, Bitmap bitmap, Source source) {
mRequest.onImageReceived(url, bitmap, source);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.handlerexploit.prime.utils.ImageManager;
import com.handlerexploit.prime.utils.ImageManager.Request;
import com.handlerexploit.prime.utils.ImageManager.Source;

/**
* <h3>Usage Example</h3>
Expand All @@ -48,8 +49,8 @@ public class RemoteImageView extends ImageView {
private Request mRequest = new Request() {

@Override
public void onImageReceived(String source, Bitmap bitmap) {
if (mImageURL != null && mImageURL.equals(source) && bitmap != null) {
public void onImageReceived(String url, Bitmap bitmap, Source source) {
if (mImageURL != null && mImageURL.equals(url) && bitmap != null) {
if (mOnImageLoadListener != null) {
mOnImageLoadListener.onImageLoad(RemoteImageView.this, bitmap);
} else {
Expand Down

0 comments on commit d0bdc7e

Please sign in to comment.