Skip to content

Commit

Permalink
log开关
Browse files Browse the repository at this point in the history
  • Loading branch information
hss committed Nov 6, 2019
1 parent 4b7ad54 commit 68e4329
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
71 changes: 49 additions & 22 deletions glide/src/main/java/com/hss01248/glideloader/GlideLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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);
}
}
Expand All @@ -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");
}

}

}
Expand Down
2 changes: 2 additions & 0 deletions imageloader/src/main/java/com/hss01248/image/MyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,8 @@ public static String printBitmap(Bitmap bitmap){





/*---------------------
作者:yyanjun
来源:CSDN
Expand Down

0 comments on commit 68e4329

Please sign in to comment.