add image Blur

This commit is contained in:
yao 2019-12-12 16:57:55 +08:00
parent c55da9c640
commit ee40fb4f91
2 changed files with 28 additions and 9 deletions

View File

@ -38,6 +38,7 @@ dependencies {
api 'com.github.pengfeizhou:jsc4a:0.1.0'
implementation 'com.squareup.okhttp3:okhttp:4.2.2'
implementation 'com.github.penfeizhou.android.animation:glide-plugin:1.3.1'
implementation 'jp.wasabeef:glide-transformations:4.1.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation "com.google.android.material:material:1.0.0"
testImplementation 'junit:junit:4.12'

View File

@ -17,11 +17,7 @@ package pub.doric.shader;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import androidx.annotation.Nullable;
import android.text.TextUtils;
import android.util.Base64;
import android.widget.ImageView;
@ -30,18 +26,21 @@ import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import pub.doric.DoricContext;
import pub.doric.extension.bridge.DoricPlugin;
import pub.doric.utils.DoricUtils;
import com.github.pengfeizhou.jscore.JSONBuilder;
import com.github.pengfeizhou.jscore.JSObject;
import com.github.pengfeizhou.jscore.JSValue;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import androidx.annotation.Nullable;
import jp.wasabeef.glide.transformations.BlurTransformation;
import pub.doric.DoricContext;
import pub.doric.extension.bridge.DoricPlugin;
import pub.doric.utils.DoricUtils;
/**
* @Description: com.github.penfeizhou.doric.widget
* @Author: pengfei.zhou
@ -50,6 +49,7 @@ import java.util.regex.Pattern;
@DoricPlugin(name = "Image")
public class ImageNode extends ViewNode<ImageView> {
private String loadCallbackId = "";
private boolean isBlur;
public ImageNode(DoricContext doricContext) {
super(doricContext);
@ -60,11 +60,29 @@ public class ImageNode extends ViewNode<ImageView> {
return new ImageView(getContext());
}
@Override
public void blend(JSObject jsObject) {
if(jsObject != null) {
JSValue jsValue = jsObject.getProperty("isBlur");
if(jsValue.isBoolean()) {
isBlur = jsValue.asBoolean().value();
}
}
super.blend(jsObject);
}
@Override
protected void blend(ImageView view, String name, JSValue prop) {
switch (name) {
case "imageUrl":
RequestOptions options;
if(isBlur) {
options = RequestOptions.bitmapTransform(new BlurTransformation(25, 3));
} else {
options = new RequestOptions();
}
Glide.with(getContext()).load(prop.asString().value())
.apply(options)
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {