optimize: code generation

This commit is contained in:
hyb1996
2017-12-07 22:32:13 +08:00
parent 8db26f5b11
commit be023ceefe
4 changed files with 18 additions and 7 deletions

View File

@@ -8,8 +8,8 @@ android {
applicationId "com.stardust.scriptdroid" applicationId "com.stardust.scriptdroid"
minSdkVersion 17 minSdkVersion 17
targetSdkVersion 23 targetSdkVersion 23
versionCode 231 versionCode 233
versionName "3.0.0 Alpha31" versionName "3.0.0 Alpha33"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true multiDexEnabled true
ndk { ndk {

View File

@@ -73,10 +73,15 @@ public class CodeGenerator {
} }
protected String generateCode(UiSelectorGenerator generator, UiObject root, UiObject target, int maxParentLevel, int maxChildrenLevel) { protected String generateCode(UiSelectorGenerator generator, UiObject root, UiObject target, int maxParentLevel, int maxChildrenLevel) {
String selector = generator.generateSelectorCode(); return generateCode(generator, root, target, maxParentLevel, maxChildrenLevel, true);
}
protected String generateCode(UiSelectorGenerator generator, UiObject root, UiObject target, int maxParentLevel, int maxChildrenLevel, boolean withFind) {
String selector = withFind ? generator.generateSelectorCode() : generator.generateSelector().toString();
if (selector != null) { if (selector != null) {
return selector; return selector;
} }
if (maxChildrenLevel > 0) { if (maxChildrenLevel > 0) {
for (int i = 0; i < target.childCount(); i++) { for (int i = 0; i < target.childCount(); i++) {
UiObject child = target.child(i); UiObject child = target.child(i);
@@ -101,9 +106,13 @@ public class CodeGenerator {
} }
protected String generateCode(UiObject root, UiObject target, int maxParentLevel, int maxChildrenLevel) { protected String generateCode(UiObject root, UiObject target, int maxParentLevel, int maxChildrenLevel) {
return generateCode(root, target, maxParentLevel, maxChildrenLevel, true);
}
protected String generateCode(UiObject root, UiObject target, int maxParentLevel, int maxChildrenLevel, boolean withFind) {
UiSelectorGenerator generator = new UiSelectorGenerator(root, target); UiSelectorGenerator generator = new UiSelectorGenerator(root, target);
generator.setUsingId(mUsingId); generator.setUsingId(mUsingId);
return generateCode(generator, root, target, maxParentLevel, maxChildrenLevel); return generateCode(generator, root, target, maxParentLevel, maxChildrenLevel, withFind);
} }
private String generateAction(String selector) { private String generateAction(String selector) {
@@ -158,10 +167,10 @@ public class CodeGenerator {
String collectionCode = generateCode(mRoot, collection, 2, 0); String collectionCode = generateCode(mRoot, collection, 2, 0);
if (collectionCode == null) if (collectionCode == null)
return null; return null;
String itemCode = generateCode(collectionItem, target, 1, 2); String itemCode = generateCode(collectionItem, target, 1, 2, false);
if (itemCode == null) if (itemCode == null)
return null; return null;
return collectionCode + ".findOne().children().forEach(child => {\n" return collectionCode + ".children().forEach(child => {\n"
+ "var target = child.findOne(" + itemCode + ");\n" + "var target = child.findOne(" + itemCode + ");\n"
+ "target." + getAction() + ";\n" + "target." + getAction() + ";\n"
+ "});"; + "});";

View File

@@ -32,6 +32,7 @@ public class TemplateMatching {
return fastTemplateMatching(img, template, MATCHING_METHOD_DEFAULT, 0.75f, threshold, MAX_LEVEL_AUTO); return fastTemplateMatching(img, template, MATCHING_METHOD_DEFAULT, 0.75f, threshold, MAX_LEVEL_AUTO);
} }
public static Point fastTemplateMatching(Mat img, Mat template, int matchMethod, float weakThreshold, float strictThreshold, int maxLevel) { public static Point fastTemplateMatching(Mat img, Mat template, int matchMethod, float weakThreshold, float strictThreshold, int maxLevel) {
TimingLogger logger = new TimingLogger(LOG_TAG, "fast_tm"); TimingLogger logger = new TimingLogger(LOG_TAG, "fast_tm");
if (maxLevel == MAX_LEVEL_AUTO) { if (maxLevel == MAX_LEVEL_AUTO) {

View File

@@ -1,6 +1,7 @@
package com.stardust.autojs.engine; package com.stardust.autojs.engine;
import android.util.Log; import android.util.Log;
import android.widget.TextView;
import com.stardust.autojs.BuildConfig; import com.stardust.autojs.BuildConfig;
import com.stardust.autojs.rhino.AndroidContextFactory; import com.stardust.autojs.rhino.AndroidContextFactory;
@@ -165,7 +166,7 @@ public class RhinoJavaScriptEngine extends JavaScriptEngine {
private class WrapFactory extends org.mozilla.javascript.WrapFactory { private class WrapFactory extends org.mozilla.javascript.WrapFactory {
@Override @Override
public Object wrap(Context cx, Scriptable scope, Object obj, Class<?> staticType) { public Object wrap(Context cx, Scriptable scope, Object obj, Class<?> staticType) {
if (obj instanceof CharSequence) { if (obj instanceof String) {
return getRuntime().bridges.toString(obj.toString()); return getRuntime().bridges.toString(obj.toString());
} }
if (staticType == UiObjectCollection.class) { if (staticType == UiObjectCollection.class) {