fix:android ImageNode check error context

This commit is contained in:
刘涛 2020-08-28 16:26:53 +08:00 committed by osborn
parent 3d656e13c6
commit f6eb8632d6
2 changed files with 13 additions and 2 deletions

View File

@ -17,6 +17,7 @@ package pub.doric.shader;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
@ -223,12 +224,13 @@ public class ImageNode extends ViewNode<ImageView> {
}
private void loadImageUrl(String url) {
Context context = DoricUtils.unwrap(getContext());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
if (getContext() instanceof Activity && ((Activity) getContext()).isDestroyed()) {
if (context instanceof Activity && ((Activity) context).isDestroyed()) {
return;
}
}
RequestBuilder<Drawable> requestBuilder = Glide.with(getContext())
RequestBuilder<Drawable> requestBuilder = Glide.with(context)
.load(url);
loadIntoTarget(requestBuilder);
}

View File

@ -16,6 +16,7 @@
package pub.doric.utils;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
@ -320,4 +321,12 @@ public class DoricUtils {
return null;
}
public static Context unwrap(Context context) {
while (context instanceof ContextWrapper) {
context = ((ContextWrapper) context).getBaseContext();
}
return context;
}
}