From 68e4329a03ba6cfe4774965594e20460ad5c0d46 Mon Sep 17 00:00:00 2001 From: hss Date: Wed, 6 Nov 2019 10:32:41 +0800 Subject: [PATCH] =?UTF-8?q?log=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hss01248/imageloaderdemo/BaseApp.java | 2 +- .../com/hss01248/glideloader/GlideLoader.java | 71 +++++++++++++------ .../main/java/com/hss01248/image/MyUtil.java | 2 + 3 files changed, 52 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/com/hss01248/imageloaderdemo/BaseApp.java b/app/src/main/java/com/hss01248/imageloaderdemo/BaseApp.java index b976db3d..58e2788a 100644 --- a/app/src/main/java/com/hss01248/imageloaderdemo/BaseApp.java +++ b/app/src/main/java/com/hss01248/imageloaderdemo/BaseApp.java @@ -33,7 +33,7 @@ public class BaseApp extends Application { public void onCreate() { super.onCreate(); ImageLoader.init(getApplicationContext(), 500,new GlideLoader()); - GlobalConfig.debug = true; + GlobalConfig.debug = false; GlobalConfig.interceptor = new LoadInterceptor() { @Override public boolean intercept(SingleConfig config) { diff --git a/glide/src/main/java/com/hss01248/glideloader/GlideLoader.java b/glide/src/main/java/com/hss01248/glideloader/GlideLoader.java index 96468f15..0773c6e6 100644 --- a/glide/src/main/java/com/hss01248/glideloader/GlideLoader.java +++ b/glide/src/main/java/com/hss01248/glideloader/GlideLoader.java @@ -256,15 +256,16 @@ public void onLoadFailed(Exception e, Drawable errorDrawable) { builder.listener(new RequestListener() { @Override public boolean onException(Exception e, Object model, Target target, boolean isFirstResource) { - Log.d("onException","thread :"+Thread.currentThread().getName() +",onException"); - Log.d("onException","model :"+model); - Log.d("onException","Target :"+target); - Log.d("onException","isFirstResource :"+isFirstResource); - if(e != null){ - e.printStackTrace(); + if(GlobalConfig.debug){ + Log.d("onException","thread :"+Thread.currentThread().getName() +",onException"); + Log.d("onException","model :"+model); + Log.d("onException","Target :"+target); + Log.d("onException","isFirstResource :"+isFirstResource); + if(e != null){ + e.printStackTrace(); + } } - if(config.getImageListener() != null){ config.getImageListener().onFail(e == null ? new Throwable("unexpected error") : e); } @@ -274,25 +275,34 @@ public boolean onException(Exception e, Object model, Target target, boolean isF @Override public boolean onResourceReady(Object resource, final Object model, Target target, boolean isFromMemoryCache, boolean isFirstResource) { + if(GlobalConfig.debug){ + Log.d("onResourceReady","thread :"+Thread.currentThread().getName() +",onResourceReady"); + Log.d("onResourceReady","resource :"+resource); + } - Log.d("onResourceReady","thread :"+Thread.currentThread().getName() +",onResourceReady"); - Log.d("onResourceReady","resource :"+resource); if(resource instanceof GlideBitmapDrawable){ GlideBitmapDrawable drawable = (GlideBitmapDrawable) resource; Bitmap bitmap = drawable.getBitmap(); - Log.i("onResourceReady","drawable :"+drawable.getIntrinsicWidth()+"x"+drawable.getIntrinsicHeight()+"," + - "bitmap:"+bitmap.getWidth()+"x"+bitmap.getHeight()); + if(GlobalConfig.debug){ + Log.d("onResourceReady",MyUtil.printBitmap(bitmap)); + } }else if(resource instanceof GifDrawable){ GifDrawable gifDrawable = (GifDrawable) resource; //Grow heap (frag case) to 74.284MB for 8294412-byte allocation Log.w("onResourceReady","gif :"+gifDrawable.getIntrinsicWidth()+"x"+gifDrawable.getIntrinsicHeight()+"x"+gifDrawable.getFrameCount()); }else{ - Log.e("onResourceReady",resource+""); + if(GlobalConfig.debug){ + Log.e("onResourceReady",resource+""); + } + + } + if(GlobalConfig.debug){ + Log.d("onResourceReady","model :"+model); + Log.d("onResourceReady","Target :"+target); + Log.d("onResourceReady","isFromMemoryCache :"+isFromMemoryCache); + Log.d("onResourceReady","isFirstResource :"+isFirstResource); } - Log.d("onResourceReady","model :"+model); - Log.d("onResourceReady","Target :"+target); - Log.d("onResourceReady","isFromMemoryCache :"+isFromMemoryCache); - Log.d("onResourceReady","isFirstResource :"+isFirstResource); + if(config.getImageListener() != null ) { if(resource instanceof GlideBitmapDrawable){ GlideBitmapDrawable drawable = (GlideBitmapDrawable) resource; @@ -302,10 +312,16 @@ public boolean onResourceReady(Object resource, final Object model, Target targe final GifDrawable gifDrawable = (GifDrawable) resource; config.getImageListener().onSuccess(gifDrawable,gifDrawable.getFirstFrame(),gifDrawable.getFirstFrame().getWidth(),gifDrawable.getFirstFrame().getHeight()); if(gifDrawable.getFrameCount()> 8){ - Log.e("onResourceReady gif","gif frame count too many:"+gifDrawable.getFrameCount()); + if(GlobalConfig.debug){ + Log.e("onResourceReady gif","gif frame count too many:"+gifDrawable.getFrameCount()); + } + } //Grow heap (frag case) to 74.284MB for 8294412-byte allocation - Log.w("onResourceReady","gif :"+gifDrawable.getIntrinsicWidth()+"x"+gifDrawable.getIntrinsicHeight()+"x"+gifDrawable.getFrameCount()); + if(GlobalConfig.debug){ + Log.w("onResourceReady","gif :"+gifDrawable.getIntrinsicWidth()+"x"+gifDrawable.getIntrinsicHeight()+"x"+gifDrawable.getFrameCount()); + } + if(GlobalConfig.useThirdPartyGifLoader){ ImageLoader.getActualLoader().getFileFromDiskCache((String) model, new FileGetter() { @Override @@ -319,7 +335,9 @@ public void onSuccess(File file, int width, int height) { imageView.setImageDrawable(gifDrawable2); gifDrawable.stop(); } catch (Throwable e) { - e.printStackTrace(); + if(GlobalConfig.debug){ + e.printStackTrace(); + } imageView.setImageDrawable(gifDrawable); } } @@ -329,19 +347,28 @@ public void onFail(Throwable e) { if(!config.equals(imageView.getTag(R.drawable.im_item_list_opt))){ return; } - e.printStackTrace(); + if(GlobalConfig.debug){ + e.printStackTrace(); + } + imageView.setImageDrawable(gifDrawable); } }); return true; } }else { - Log.e("onResourceReady",resource+""); + if(GlobalConfig.debug){ + Log.e("onResourceReady",resource+""); + } + if(resource instanceof Drawable){ config.getImageListener().onSuccess((Drawable)resource,null,0,0); }else{ config.getImageListener().onSuccess(null,null,0,0); - Log.e("onResourceReady!!!",resource+", not instance of drawable"); + if(GlobalConfig.debug){ + Log.e("onResourceReady!!!",resource+", not instance of drawable"); + } + } } diff --git a/imageloader/src/main/java/com/hss01248/image/MyUtil.java b/imageloader/src/main/java/com/hss01248/image/MyUtil.java index bb7c1b48..b61823b3 100644 --- a/imageloader/src/main/java/com/hss01248/image/MyUtil.java +++ b/imageloader/src/main/java/com/hss01248/image/MyUtil.java @@ -597,6 +597,8 @@ public static String printBitmap(Bitmap bitmap){ + + /*--------------------- 作者:yyanjun 来源:CSDN