release 2.0.12 Beta

This commit is contained in:
hyb1996
2017-05-29 20:56:12 +08:00
parent 7c88e578fe
commit 5a79bb577f
13 changed files with 59 additions and 28 deletions

View File

@@ -9,8 +9,8 @@ android {
applicationId "com.stardust.scriptdroid" applicationId "com.stardust.scriptdroid"
minSdkVersion 19 minSdkVersion 19
targetSdkVersion 23 targetSdkVersion 23
versionCode 136 versionCode 137
versionName "2.0.12 Alpha3日志版" versionName "2.0.12 Beta"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true multiDexEnabled true
ndk { ndk {

View File

@@ -1,3 +1,3 @@
### requestScreenCapture(\[width, height\]) ### requestScreenCapture(\[width, height\])
* width \<Number\> 可选参数 参数width和height用于指定截图的分辨率默认为屏幕宽高。

View File

@@ -0,0 +1,11 @@
"auto";
while (true) {
className("ImageButton").descStartsWith("更多功能按钮").click();
while(!click("相册"));
sleep(500);
className("GridView").findOne().child(1).click();
sleep(200);
while(!click("发送"));
sleep(300);
}

View File

@@ -7,7 +7,7 @@ var img = captureScreen();
toastLog("开始找色"); toastLog("开始找色");
//指定在位置(90, 220)宽高为900*1000的区域找色。 //指定在位置(90, 220)宽高为900*1000的区域找色。
//0xff00cc是编辑器的深粉红色字体(字符串)颜色 //0xff00cc是编辑器的深粉红色字体(字符串)颜色
var point = findColorInRegion(img, 0xff00cc, 90, 220, 900, 1000); var point = findColorInRegion(img, "#ff00cc", 90, 220, 900, 1000);
if(point){ if(point){
toastLog("x = " + point.x + ", y = " + point.y); toastLog("x = " + point.x + ", y = " + point.y);
}else{ }else{

View File

@@ -7,7 +7,7 @@ var img = captureScreen();
toastLog("开始找色"); toastLog("开始找色");
//指定在位置(90, 220)宽高为900*1000的区域找色。 //指定在位置(90, 220)宽高为900*1000的区域找色。
//0xff00cc是编辑器的深粉红色字体(字符串)颜色 //0xff00cc是编辑器的深粉红色字体(字符串)颜色
var point = findColor(img, 0xff00cc, { var point = findColor(img, "#ff00cc", {
region: [90, 220, 900, 1000], region: [90, 220, 900, 1000],
threads: 8 threads: 8
}); });

View File

@@ -6,7 +6,7 @@ launchApp("QQ");
sleep(2000); sleep(2000);
var img = captureScreen(); var img = captureScreen();
toastLog("开始找色"); toastLog("开始找色");
var point = findColor(img, 0xf64d30); var point = findColor(img, "#f64d30");
if(point){ if(point){
toastLog("x = " + point.x + ", y = " + point.y); toastLog("x = " + point.x + ", y = " + point.y);
}else{ }else{

View File

@@ -6,7 +6,7 @@ var img = captureScreen();
//0xffffff为白色 //0xffffff为白色
toastLog("开始找色"); toastLog("开始找色");
var point = findColor(img, 0xffffff, { var point = findColor(img, 0xffffff, {
//指定算法为rgb+,默认算法rgb更准确,但时间更久 //指定算法为rgb+,默认算法rgb更准确,但时间更久
algorithm: "rgb+", algorithm: "rgb+",
//指定颜色临界值为16 //指定颜色临界值为16
threshold: 16, threshold: 16,
@@ -19,4 +19,14 @@ if(point){
toastLog("没有找到"); toastLog("没有找到");
} }
point = findColor(img, 0xffffff, {
//指定算法为颜色差值比默认算法rgb更快
algorithm: "diff",
//指定r, b, b分别都在范围ff±20内
threshold: 0x202020,
});
if(point){
toastLog("x = " + point.x + ", y = " + point.y);
}else{
toastLog("没有找到");
}

View File

@@ -44,8 +44,6 @@ public class App extends MultiDexApplication {
setUpDebugEnvironment(); setUpDebugEnvironment();
init(); init();
registerActivityLifecycleCallback(); registerActivityLifecycleCallback();
Logcat.deleteLogFile();
Logcat.startLogSavingIfNeeded();
} }
private void setUpStaticsTool() { private void setUpStaticsTool() {

View File

@@ -24,7 +24,7 @@ module.exports = function(__runtime__, scope){
y = region[1] || 0; y = region[1] || 0;
width = region[2] || (img.getWidth() - x); width = region[2] || (img.getWidth() - x);
height = region[3] || (img.getHeight() - y); height = region[3] || (img.getHeight() - y);
threads = options.threads || 4; threads = options.threads || 2;
if(options.threshold !== 0){ if(options.threshold !== 0){
threshold = options.threshold || 8; threshold = options.threshold || 8;
} }
@@ -57,6 +57,8 @@ module.exports = function(__runtime__, scope){
return new com.stardust.autojs.runtime.api.image.ColorDetector.RGBDistanceDetector(color, threshold); return new com.stardust.autojs.runtime.api.image.ColorDetector.RGBDistanceDetector(color, threshold);
case "equal": case "equal":
return new com.stardust.autojs.runtime.api.image.ColorDetector.EqualityDetector(color); return new com.stardust.autojs.runtime.api.image.ColorDetector.EqualityDetector(color);
case "diff":
return new com.stardust.autojs.runtime.api.image.ColorDetector.DifferenceDetector(color, threshold);
case "rgb+": case "rgb+":
return new com.stardust.autojs.runtime.api.image.ColorDetector.WeightedRGBDistanceDetector(color, threshold); return new com.stardust.autojs.runtime.api.image.ColorDetector.WeightedRGBDistanceDetector(color, threshold);
case "hs": case "hs":

View File

@@ -210,7 +210,6 @@ public class ColorFinder {
Thread thread = Thread.currentThread(); Thread thread = Thread.currentThread();
ColorIterator.Pixel pixel = new ColorIterator.Pixel(); ColorIterator.Pixel pixel = new ColorIterator.Pixel();
while (mResultBox.isNull() && mColorIterator.hasNext() && !thread.isInterrupted()) { while (mResultBox.isNull() && mColorIterator.hasNext() && !thread.isInterrupted()) {
mColorIterator.nextColor(pixel);
mColorIterator.nextColor(pixel); mColorIterator.nextColor(pixel);
if (mColorDetector.detectsColor(pixel.red, pixel.green, pixel.blue)) { if (mColorDetector.detectsColor(pixel.red, pixel.green, pixel.blue)) {
mResultBox.set(new Point(mColorIterator.getX(), mColorIterator.getY())); mResultBox.set(new Point(mColorIterator.getX(), mColorIterator.getY()));

View File

@@ -111,13 +111,12 @@ public interface ColorIterator {
pixel.red = mByteBuffer.get() & 0xff; pixel.red = mByteBuffer.get() & 0xff;
pixel.green = mByteBuffer.get() & 0xff; pixel.green = mByteBuffer.get() & 0xff;
pixel.blue = mByteBuffer.get() & 0xff; pixel.blue = mByteBuffer.get() & 0xff;
mByteBuffer.get();
} }
} }
/** // TODO: 2017/5/29 中心螺旋。未完成。
* 中心螺旋。未完成。
*/
class CentralSpiralIterator extends ImageColorIterator { class CentralSpiralIterator extends ImageColorIterator {
private static final int DIRECTION_RIGHT = 0; private static final int DIRECTION_RIGHT = 0;

View File

@@ -25,7 +25,7 @@ public class ScreenCapturer {
private ImageReader mImageReader; private ImageReader mImageReader;
private MediaProjection mMediaProjection; private MediaProjection mMediaProjection;
private VirtualDisplay mVirtualDisplay; private VirtualDisplay mVirtualDisplay;
private final Object mImageLock = new Object(); private Image mImage;
public ScreenCapturer(Context context, Intent data, int screenWidth, int screenHeight, int screenDensity) { public ScreenCapturer(Context context, Intent data, int screenWidth, int screenHeight, int screenDensity) {
MediaProjectionManager manager = (MediaProjectionManager) context.getSystemService(Context.MEDIA_PROJECTION_SERVICE); MediaProjectionManager manager = (MediaProjectionManager) context.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
@@ -49,8 +49,11 @@ public class ScreenCapturer {
} }
public Image capture() { public Image capture() {
Image image = mImageReader.acquireLatestImage(); if (mImage != null) {
if (image == null) { mImage.close();
}
mImage = mImageReader.acquireLatestImage();
if (mImage == null) {
Looper.prepare(); Looper.prepare();
mImageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() { mImageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {
@Override @Override
@@ -59,9 +62,9 @@ public class ScreenCapturer {
} }
}, null); }, null);
Looper.loop(); Looper.loop();
image = mImageReader.acquireLatestImage(); mImage = mImageReader.acquireLatestImage();
} }
return image; return mImage;
} }
@@ -73,5 +76,8 @@ public class ScreenCapturer {
if (mVirtualDisplay != null) { if (mVirtualDisplay != null) {
mVirtualDisplay.release(); mVirtualDisplay.release();
} }
if (mImage != null) {
mImage.close();
}
} }
} }

View File

@@ -3,7 +3,10 @@ package com.stardust.automator.simple_action;
import android.graphics.Rect; import android.graphics.Rect;
import com.stardust.automator.UiObject; import com.stardust.automator.UiObject;
import com.stardust.automator.filter.BoundsFilter;
import com.stardust.view.accessibility.AccessibilityNodeInfoHelper;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@@ -59,26 +62,29 @@ public abstract class FilterAction extends SimpleAction {
@Override @Override
public List<UiObject> filter(UiObject root) { public List<UiObject> filter(UiObject root) {
return Collections.singletonList(findAccessibilityNodeInfosByBounds(root)); List<UiObject> list = new ArrayList<>();
findAccessibilityNodeInfosByBounds(root, list);
return list;
} }
private UiObject findAccessibilityNodeInfosByBounds(UiObject root) { private void findAccessibilityNodeInfosByBounds(UiObject root, List<UiObject> list) {
if (root == null) if (root == null)
return null; return;
Rect rect = new Rect(); Rect rect = new Rect();
root.getBoundsInScreen(rect); root.getBoundsInScreen(rect);
if (rect.equals(mBoundsInScreen)) { if (rect.equals(mBoundsInScreen)) {
return root; list.add(root);
} }
int oldSize = list.size();
for (int i = 0; i < root.getChildCount(); i++) { for (int i = 0; i < root.getChildCount(); i++) {
UiObject child = root.child(i); UiObject child = root.child(i);
if (child == null) if (child == null)
continue; continue;
UiObject nodeInfo = findAccessibilityNodeInfosByBounds(child); findAccessibilityNodeInfosByBounds(child, list);
if (nodeInfo != null) }
return nodeInfo; if (oldSize == list.size() && rect.contains(mBoundsInScreen)) {
list.add(root);
} }
return null;
} }
@Override @Override