From 471e87badcc261d841224e22b19341a36d83174e Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Tue, 6 Aug 2019 19:37:08 +0800 Subject: [PATCH] android add image node --- Android/app/build.gradle | 4 +++ .../penfeizhou/doricdemo/MyGlideModule.java | 13 ++++++++ Android/doric/build.gradle | 3 +- .../penfeizhou/doric/shader/ImageNode.java | 32 ++++++++++++++++++- LICENSE | 2 +- js-framework/demo.ts | 7 +++- 6 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 Android/app/src/main/java/com/github/penfeizhou/doricdemo/MyGlideModule.java diff --git a/Android/app/build.gradle b/Android/app/build.gradle index 95261a33..db16d9ce 100644 --- a/Android/app/build.gradle +++ b/Android/app/build.gradle @@ -29,4 +29,8 @@ dependencies { implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation project(':doric') implementation 'org.nanohttpd:nanohttpd:2.3.1' + implementation 'com.github.bumptech.glide:glide:4.8.0' + implementation 'com.github.bumptech.glide:annotations:4.8.0' + implementation 'com.github.penfeizhou.android.animation:glide-plugin:1.0.1' + annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0' } diff --git a/Android/app/src/main/java/com/github/penfeizhou/doricdemo/MyGlideModule.java b/Android/app/src/main/java/com/github/penfeizhou/doricdemo/MyGlideModule.java new file mode 100644 index 00000000..5f92e222 --- /dev/null +++ b/Android/app/src/main/java/com/github/penfeizhou/doricdemo/MyGlideModule.java @@ -0,0 +1,13 @@ +package com.github.penfeizhou.doricdemo; + +import com.bumptech.glide.annotation.GlideModule; +import com.bumptech.glide.module.AppGlideModule; + +/** + * @Description: com.github.penfeizhou.doricdemo + * @Author: pengfei.zhou + * @CreateDate: 2019-08-06 + */ +@GlideModule +public class MyGlideModule extends AppGlideModule { +} diff --git a/Android/doric/build.gradle b/Android/doric/build.gradle index d527b9c6..ead263ba 100644 --- a/Android/doric/build.gradle +++ b/Android/doric/build.gradle @@ -45,5 +45,6 @@ dependencies { androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' api 'com.github.pengfeizhou:jsc4a:0.1.0' - implementation("com.squareup.okhttp3:okhttp:3.11.0") + implementation "com.squareup.okhttp3:okhttp:3.11.0" + implementation 'com.github.penfeizhou.android.animation:glide-plugin:1.0.1' } diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/ImageNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/ImageNode.java index 7ab221d8..b165e5ca 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/ImageNode.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/ImageNode.java @@ -1,10 +1,19 @@ package com.github.penfeizhou.doric.shader; +import android.graphics.drawable.Drawable; +import android.support.annotation.Nullable; +import android.view.ViewGroup; import android.widget.ImageView; +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.target.Target; import com.github.penfeizhou.doric.DoricContext; import com.github.penfeizhou.doric.extension.bridge.DoricPlugin; import com.github.pengfeizhou.jscore.JSObject; +import com.github.pengfeizhou.jscore.JSValue; /** * @Description: com.github.penfeizhou.doric.widget @@ -19,6 +28,27 @@ public class ImageNode extends ViewNode { @Override protected ImageView build(JSObject jsObject) { - return null; + return new ImageView(getContext()); + } + + @Override + protected void blend(ImageView view, ViewGroup.LayoutParams layoutParams, String name, JSValue prop) { + if ("imageUrl".equals(name)) { + Glide.with(getContext()).load(prop.asString().value()) + .listener(new RequestListener() { + @Override + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { + return false; + } + + @Override + public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { + return false; + } + }) + .into(view); + } else { + super.blend(view, layoutParams, name, prop); + } } } diff --git a/LICENSE b/LICENSE index 261eeb9e..cc318bb6 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright [2019] [Zhou Pengfei] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/js-framework/demo.ts b/js-framework/demo.ts index e5320b44..6054742c 100644 --- a/js-framework/demo.ts +++ b/js-framework/demo.ts @@ -1,4 +1,4 @@ -import { HLayout, StackConfig, ViewHolder, VMPanel, View, ViewModel, WRAP_CONTENT, Gravity, Mutable, NativeCall, Text, Color, VLayout, Panel, log, logw, loge, Group, Stack, } from "./index" +import { HLayout, Image, ViewHolder, VMPanel, View, ViewModel, WRAP_CONTENT, Gravity, Mutable, NativeCall, Text, Color, VLayout, Panel, log, logw, loge, Group, Stack, } from "./index" interface CountModel { @@ -53,6 +53,11 @@ class CounterView extends ViewHolder { // root.bgColor = Color.parse('#00ff00') vlayout.bgColor = Color.parse('#ff00ff') root.addChild(vlayout) + const iv = new Image + // iv.width = iv.height = 100 + iv.imageUrl = "https://misc.aotu.io/ONE-SUNDAY/SteamEngine.png" + //iv.bgColor = Color.parse('#00ff00') + root.addChild(iv) } setNumber(n: number) {