Skip to content

Commit

Permalink
modify OnImageCallbackListener
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinea committed Nov 25, 2013
1 parent 3725468 commit b3b4048
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 8 deletions.
2 changes: 1 addition & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cn.trinea.android.demo"
android:versionCode="35"
android:versionName="2.10.11" >
android:versionName="2.11.11" >

<uses-sdk android:minSdkVersion="14" />

Expand Down
3 changes: 1 addition & 2 deletions project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@

# Project target.
target=android-14
android.library.reference.1=..\\trinea-android-common
proguard.config=proguard.cfg
android.library.reference.2=../../TrineaOnline/trinea-android-common
android.library.reference.1=../trinea-android-common
41 changes: 38 additions & 3 deletions src/cn/trinea/android/demo/ImageCacheDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.animation.AlphaAnimation;
Expand All @@ -14,6 +15,7 @@
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import cn.trinea.android.common.service.impl.ImageCache;
import cn.trinea.android.common.entity.FailedReason;
import cn.trinea.android.common.service.impl.ImageMemoryCache.OnImageCallbackListener;
import cn.trinea.android.common.service.impl.RemoveTypeLastUsedTimeFirst;

Expand Down Expand Up @@ -90,10 +92,16 @@ protected void onDestroy() {
/** init icon cache **/
OnImageCallbackListener imageCallBack = new OnImageCallbackListener() {

private static final long serialVersionUID = 1L;

/**
* callback function after get image successfully, run on ui thread
*
* @param imageUrl imageUrl
* @param imageDrawable drawable
* @param view view need the image
* @param isInCache whether already in cache or got realtime
*/
@Override
public void onImageLoaded(String imageUrl, Drawable imageDrawable, View view, boolean isInCache) {
public void onGetSuccess(String imageUrl, Drawable imageDrawable, View view, boolean isInCache) {
if (view != null && imageDrawable != null) {
ImageView imageView = (ImageView)view;
imageView.setImageDrawable(imageDrawable);
Expand All @@ -109,6 +117,33 @@ public void onImageLoaded(String imageUrl, Drawable imageDrawable, View view, bo
imageView.setScaleType(ScaleType.FIT_XY);
}
}

/**
* callback function before get image, run on ui thread
*
* @param imageUrl imageUrl
* @param view view need the image
*/
@Override
public void onPreGet(String imageUrl, View view) {
// Log.e(TAG_CACHE, "pre get image");
}

/**
* callback function after get image failed, run on ui thread
*
* @param imageUrl imageUrl
* @param imageDrawable drawable
* @param view view need the image
* @param failedReason failed reason for get image
*/
@Override
public void onGetFailed(String imageUrl, Drawable imageDrawable, View view, FailedReason failedReason) {
Log.e(TAG_CACHE,
new StringBuilder(128).append("get image ").append(imageUrl).append(" error, failed type is: ")
.append(failedReason.getFailedType()).append(", failed reason is: ")
.append(failedReason.getCause().getMessage()).toString());
}
};
IMAGE_CACHE.setOnImageCallbackListener(imageCallBack);
IMAGE_CACHE.setCacheFullRemoveType(new RemoveTypeLastUsedTimeFirst<Drawable>());
Expand Down
41 changes: 39 additions & 2 deletions src/cn/trinea/android/demo/ImageSDCardCacheDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -15,6 +16,7 @@
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.RelativeLayout.LayoutParams;
import cn.trinea.android.common.entity.FailedReason;
import cn.trinea.android.common.service.impl.FileNameRuleImageUrl;
import cn.trinea.android.common.service.impl.ImageSDCardCache;
import cn.trinea.android.common.service.impl.ImageSDCardCache.OnImageSDCallbackListener;
Expand Down Expand Up @@ -62,8 +64,16 @@ protected void onDestroy() {

private static final long serialVersionUID = 1L;

/**
* callback function after get image successfully, run on ui thread
*
* @param imageUrl imageUrl
* @param imagePath image path
* @param view view need the image
* @param isInCache whether already in cache or got realtime
*/
@Override
public void onImageLoaded(String imageUrl, String imagePath, View view, boolean isInCache) {
public void onGetSuccess(String imageUrl, String imagePath, View view, boolean isInCache) {
ImageView imageView = (ImageView)view;

// avoid oom caused by bitmap size exceeds VM budget
Expand All @@ -83,6 +93,33 @@ public void onImageLoaded(String imageUrl, String imagePath, View view, boolean
}
}
}

/**
* callback function before get image, run on ui thread
*
* @param imageUrl imageUrl
* @param view view need the image
*/
@Override
public void onPreGet(String imageUrl, View view) {
// Log.e(TAG_CACHE, "pre get image");
}

/**
* callback function after get image failed, run on ui thread
*
* @param imageUrl imageUrl
* @param imagePath image path
* @param view view need the image
* @param failedReason failed reason for get image
*/
@Override
public void onGetFailed(String imageUrl, String imagePath, View view, FailedReason failedReason) {
Log.e(TAG_CACHE,
new StringBuilder(128).append("get image ").append(imageUrl).append(" error, failed type is: ")
.append(failedReason.getFailedType()).append(", failed reason is: ")
.append(failedReason.getCause().getMessage()).toString());
}
};
IMAGE_SD_CACHE.setOnImageSDCallbackListener(imageCallBack);
IMAGE_SD_CACHE.setCacheFullRemoveType(new RemoveTypeLastUsedTimeFirst<String>());
Expand Down Expand Up @@ -149,7 +186,7 @@ private static class ImageAdapter extends BaseAdapter {
private LayoutInflater inflater;
public List<String> imageUrlList;

public ImageAdapter(Context context) {
public ImageAdapter(Context context){
super();
inflater = LayoutInflater.from(context);
}
Expand Down

0 comments on commit b3b4048

Please sign in to comment.