From 2259020403e7799cb0e4f1e14b08240e2aa8820d Mon Sep 17 00:00:00 2001 From: hyb1996 <946994919@qq.com> Date: Sat, 29 Sep 2018 11:13:15 +0800 Subject: [PATCH 1/2] fix: dev plugin save creating dir --- .idea/caches/build_file_checksums.ser | Bin 733 -> 733 bytes .../pluginclient/DevPluginResponseHandler.java | 4 +++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 259a89dcb7414dbe3332924ae967a0d3230dabae..5257cc7635d1687e3035bfa4131367f295d8ee47 100644 GIT binary patch delta 37 tcmcc1dY5&=bk;OwkD!o=b1nFUZmjz|({&A#{oYN4($JQifsG{-e*`Lcuo$NTXe*s Date: Thu, 11 Oct 2018 10:56:16 +0800 Subject: [PATCH 2/2] save works --- .../autojs/core/ui/widget/NativeView.java | 182 ++++++++++++++++++ .../rhino/NativeJavaObjectWithPrototype.java | 7 + .../com/stardust/autojs/runtime/api/UI.java | 8 + 3 files changed, 197 insertions(+) create mode 100644 autojs/src/main/java/com/stardust/autojs/core/ui/widget/NativeView.java diff --git a/autojs/src/main/java/com/stardust/autojs/core/ui/widget/NativeView.java b/autojs/src/main/java/com/stardust/autojs/core/ui/widget/NativeView.java new file mode 100644 index 00000000..c35e2094 --- /dev/null +++ b/autojs/src/main/java/com/stardust/autojs/core/ui/widget/NativeView.java @@ -0,0 +1,182 @@ +package com.stardust.autojs.core.ui.widget; + +import android.graphics.drawable.Drawable; +import android.support.annotation.CallSuper; +import android.view.View; + +import com.stardust.autojs.core.ui.inflater.util.Drawables; +import com.stardust.autojs.core.ui.inflater.util.Ids; +import com.stardust.autojs.rhino.NativeJavaObjectWithPrototype; + +import org.mozilla.javascript.ScriptRuntime; +import org.mozilla.javascript.Scriptable; + +import java.util.HashMap; +import java.util.Map; + +public class NativeView extends NativeJavaObjectWithPrototype { + + protected interface Attribute { + String get(); + + void set(String value); + } + + + protected class BaseAttribute implements Attribute { + + private String mValue; + private final AttributeSetter mAttributeSetter; + + public BaseAttribute(AttributeSetter attributeSetter) { + mAttributeSetter = attributeSetter; + } + + @Override + public String get() { + return mValue; + } + + @Override + public void set(String value) { + mValue = value; + mAttributeSetter.set(value); + } + } + + protected interface AttributeGetter { + String get(); + } + + + protected interface AttributeSetter { + void set(String value); + } + + protected interface ValueConverter { + T convert(String value); + } + + protected interface ValueApplier { + void apply(T value); + } + + protected static class MappingAttributeSetter implements AttributeSetter { + + private final ValueConverter mValueConverter; + private final ValueApplier mValueApplier; + + public MappingAttributeSetter(ValueConverter valueConverter, ValueApplier valueApplier) { + mValueConverter = valueConverter; + mValueApplier = valueApplier; + } + + @Override + public void set(String value) { + mValueApplier.apply(mValueConverter.convert(value)); + } + } + + + private Map mAttributes = new HashMap<>(); + private final com.stardust.autojs.runtime.ScriptRuntime mRuntime; + private final Drawables mDrawables; + private final View mView; + + public NativeView(Scriptable scope, View javaObject, Class staticType, com.stardust.autojs.runtime.ScriptRuntime runtime) { + super(scope, javaObject, staticType); + mRuntime = runtime; + mDrawables = mRuntime.ui.getResourceParser().getDrawables(); + mView = javaObject; + init(); + } + + + public NativeView(Scriptable scope, View javaObject, Class staticType, boolean isAdapter, com.stardust.autojs.runtime.ScriptRuntime runtime) { + super(scope, javaObject, staticType, isAdapter); + mRuntime = runtime; + mDrawables = mRuntime.ui.getResourceParser().getDrawables(); + mView = javaObject; + init(); + } + + private void init() { + onRegisterAttrs(); + } + + @CallSuper + protected void onRegisterAttrs() { + registerAttr("id", Ids::parse, mView::setId); + registerDrawableAttr("bg", mView::setBackground); + + + } + + @Override + public boolean has(String name, Scriptable start) { + if (mAttributes.containsKey(name)) { + return true; + } + return super.has(name, start); + } + + @Override + public void put(String name, Scriptable start, Object value) { + Attribute attribute = mAttributes.get(name); + if (attribute != null) { + attribute.set(ScriptRuntime.toString(value)); + return; + } + super.put(name, start, value); + } + + @Override + public Object get(String name, Scriptable start) { + Attribute attribute = mAttributes.get(name); + if (attribute != null) { + return attribute.get(); + } + return super.get(name, start); + } + + protected void registerAttr(String name, Attribute attribute) { + mAttributes.put(name, attribute); + } + + protected void registerAttr(String name, AttributeGetter getter, AttributeSetter setter) { + mAttributes.put(name, new Attribute() { + @Override + public String get() { + return getter.get(); + } + + @Override + public void set(String value) { + setter.set(value); + } + }); + } + + protected void registerAttr(String name, AttributeSetter setter) { + mAttributes.put(name, new BaseAttribute(setter)); + } + + protected void registerAttr(String name, ValueConverter converter, ValueApplier applier) { + mAttributes.put(name, new BaseAttribute(new MappingAttributeSetter<>(converter, applier))); + } + + protected void registerDrawableAttr(String name, ValueApplier applier) { + mAttributes.put(name, new BaseAttribute(new MappingAttributeSetter<>( + this::parseDrawable, applier))); + } + + + protected Drawable parseDrawable(String value) { + return mDrawables.parse(mView, value); + } + + @Override + public View unwrap() { + return mView; + } +} diff --git a/autojs/src/main/java/com/stardust/autojs/rhino/NativeJavaObjectWithPrototype.java b/autojs/src/main/java/com/stardust/autojs/rhino/NativeJavaObjectWithPrototype.java index 0a5ae184..c12c474f 100644 --- a/autojs/src/main/java/com/stardust/autojs/rhino/NativeJavaObjectWithPrototype.java +++ b/autojs/src/main/java/com/stardust/autojs/rhino/NativeJavaObjectWithPrototype.java @@ -14,6 +14,13 @@ public class NativeJavaObjectWithPrototype extends NativeJavaObject { super(scope, javaObject, staticType); } + public NativeJavaObjectWithPrototype(Scriptable scope, Object javaObject, Class staticType, boolean isAdapter) { + super(scope, javaObject, staticType, isAdapter); + } + + public NativeJavaObjectWithPrototype() { + } + @Override public boolean has(String name, Scriptable start) { return super.has(name, start) || (prototype != null && prototype.has(name, start)) diff --git a/autojs/src/main/java/com/stardust/autojs/runtime/api/UI.java b/autojs/src/main/java/com/stardust/autojs/runtime/api/UI.java index e7b3980a..65679930 100644 --- a/autojs/src/main/java/com/stardust/autojs/runtime/api/UI.java +++ b/autojs/src/main/java/com/stardust/autojs/runtime/api/UI.java @@ -55,6 +55,14 @@ public class UI extends ProxyObject { mProperties.put("layoutInflater", this.mDynamicLayoutInflater); } + public DynamicLayoutInflater getDynamicLayoutInflater() { + return mDynamicLayoutInflater; + } + + public ResourceParser getResourceParser() { + return mResourceParser; + } + @SuppressWarnings("unchecked") public static V unwrapJsViewObject(@Nullable NativeObject object, Class c) { if (object == null)