android: fix when load image from remote server cause non ui thread touch view (#561)
This commit is contained in:
parent
9be6bb2051
commit
0668e0fe86
@ -32,16 +32,12 @@ import android.graphics.drawable.ColorDrawable;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.NinePatchDrawable;
|
import android.graphics.drawable.NinePatchDrawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.Looper;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.appcompat.widget.AppCompatImageView;
|
|
||||||
import androidx.vectordrawable.graphics.drawable.Animatable2Compat;
|
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.RequestBuilder;
|
import com.bumptech.glide.RequestBuilder;
|
||||||
import com.bumptech.glide.load.DataSource;
|
import com.bumptech.glide.load.DataSource;
|
||||||
@ -65,6 +61,10 @@ import java.io.File;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.widget.AppCompatImageView;
|
||||||
|
import androidx.vectordrawable.graphics.drawable.Animatable2Compat;
|
||||||
import pub.doric.DoricContext;
|
import pub.doric.DoricContext;
|
||||||
import pub.doric.async.AsyncResult;
|
import pub.doric.async.AsyncResult;
|
||||||
import pub.doric.extension.bridge.DoricMethod;
|
import pub.doric.extension.bridge.DoricMethod;
|
||||||
@ -428,15 +428,33 @@ public class ImageNode extends ViewNode<ImageView> {
|
|||||||
if (doricResource != null) {
|
if (doricResource != null) {
|
||||||
doricResource.fetch().setCallback(new AsyncResult.Callback<byte[]>() {
|
doricResource.fetch().setCallback(new AsyncResult.Callback<byte[]>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResult(byte[] imageData) {
|
public void onResult(final byte[] imageData) {
|
||||||
loadIntoTarget(Glide.with(getContext()).load(imageData));
|
if (Looper.getMainLooper() != Looper.myLooper()) {
|
||||||
|
mView.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
loadIntoTarget(Glide.with(getContext()).load(imageData));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
loadIntoTarget(Glide.with(getContext()).load(imageData));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Throwable t) {
|
public void onError(Throwable t) {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
DoricLog.e("Cannot load resource %s, %s", resource.toString(), t.getLocalizedMessage());
|
DoricLog.e("Cannot load resource %s, %s", resource.toString(), t.getLocalizedMessage());
|
||||||
view.setImageDrawable(null);
|
if (Looper.getMainLooper() != Looper.myLooper()) {
|
||||||
|
mView.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
view.setImageDrawable(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
view.setImageDrawable(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user