fix:android ImageNode check error context
This commit is contained in:
parent
3d656e13c6
commit
f6eb8632d6
@ -17,6 +17,7 @@ package pub.doric.shader;
|
|||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
@ -223,12 +224,13 @@ public class ImageNode extends ViewNode<ImageView> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadImageUrl(String url) {
|
private void loadImageUrl(String url) {
|
||||||
|
Context context = DoricUtils.unwrap(getContext());
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RequestBuilder<Drawable> requestBuilder = Glide.with(getContext())
|
RequestBuilder<Drawable> requestBuilder = Glide.with(context)
|
||||||
.load(url);
|
.load(url);
|
||||||
loadIntoTarget(requestBuilder);
|
loadIntoTarget(requestBuilder);
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
package pub.doric.utils;
|
package pub.doric.utils;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.ContextWrapper;
|
||||||
import android.content.res.AssetManager;
|
import android.content.res.AssetManager;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
@ -320,4 +321,12 @@ public class DoricUtils {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Context unwrap(Context context) {
|
||||||
|
while (context instanceof ContextWrapper) {
|
||||||
|
context = ((ContextWrapper) context).getBaseContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
return context;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user