From b3b4048f98a2d18089aa4a453a5909ce4a266899 Mon Sep 17 00:00:00 2001 From: Trinea Date: Mon, 25 Nov 2013 16:49:12 +0800 Subject: [PATCH] modify OnImageCallbackListener --- AndroidManifest.xml | 2 +- project.properties | 3 +- .../trinea/android/demo/ImageCacheDemo.java | 41 +++++++++++++++++-- .../android/demo/ImageSDCardCacheDemo.java | 41 ++++++++++++++++++- 4 files changed, 79 insertions(+), 8 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index aa790c3..5c4b9ff 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -2,7 +2,7 @@ + android:versionName="2.11.11" > diff --git a/project.properties b/project.properties index 45331c5..d12ec3f 100644 --- a/project.properties +++ b/project.properties @@ -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 diff --git a/src/cn/trinea/android/demo/ImageCacheDemo.java b/src/cn/trinea/android/demo/ImageCacheDemo.java index 37aabc4..19e5d10 100644 --- a/src/cn/trinea/android/demo/ImageCacheDemo.java +++ b/src/cn/trinea/android/demo/ImageCacheDemo.java @@ -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; @@ -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; @@ -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); @@ -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()); diff --git a/src/cn/trinea/android/demo/ImageSDCardCacheDemo.java b/src/cn/trinea/android/demo/ImageSDCardCacheDemo.java index a0d30dd..6d7a925 100644 --- a/src/cn/trinea/android/demo/ImageSDCardCacheDemo.java +++ b/src/cn/trinea/android/demo/ImageSDCardCacheDemo.java @@ -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; @@ -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; @@ -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 @@ -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()); @@ -149,7 +186,7 @@ private static class ImageAdapter extends BaseAdapter { private LayoutInflater inflater; public List imageUrlList; - public ImageAdapter(Context context) { + public ImageAdapter(Context context){ super(); inflater = LayoutInflater.from(context); }