From ee40fb4f914440e79b8f527102e961f8728638ff Mon Sep 17 00:00:00 2001 From: yao <294149113@qq.com> Date: Thu, 12 Dec 2019 16:57:55 +0800 Subject: [PATCH] add image Blur --- doric/build.gradle | 1 + .../main/java/pub/doric/shader/ImageNode.java | 36 ++++++++++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/doric/build.gradle b/doric/build.gradle index 500eec5f..851a65e0 100644 --- a/doric/build.gradle +++ b/doric/build.gradle @@ -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' diff --git a/doric/src/main/java/pub/doric/shader/ImageNode.java b/doric/src/main/java/pub/doric/shader/ImageNode.java index 9157c80d..240ae2f4 100644 --- a/doric/src/main/java/pub/doric/shader/ImageNode.java +++ b/doric/src/main/java/pub/doric/shader/ImageNode.java @@ -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 { private String loadCallbackId = ""; + private boolean isBlur; public ImageNode(DoricContext doricContext) { super(doricContext); @@ -60,11 +60,29 @@ public class ImageNode extends ViewNode { 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() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {