random click and gesture for android 7.0+!!!

This commit is contained in:
hyb1996
2017-05-16 21:40:23 +08:00
parent ec98d75d3b
commit c4ec951a10
42 changed files with 757 additions and 564 deletions

View File

@@ -13,17 +13,60 @@ module.exports = function(__runtime__, scope){
}
automator.click = function(){
if(arguments.length >= 2 && typeof(arguments[0]) == 'number' && typeof(arguments[1]) == 'number'){
return __runtime__.automator.click(arguments[0], arguments[1]);
}
return performAction(function(target){
return __runtime__.automator.click(target);
}, arguments);
}
automator.longClick = function(a, b, c, d){
if(arguments.length == 2 && typeof(arguments[0]) == 'number' && typeof(arguments[1]) == 'number'){
return __runtime__.automator.longClick(arguments[0], arguments[1]);
}
return performAction(function(target){
return __runtime__.automator.longClick(target);
}, arguments);
}
automator.press = __runtime__.automator.press.bind(__runtime__.automator);
automator.gesture = __runtime__.automator.gesture.bind(__runtime__.automator, 0);
automator.gestureAsync = __runtime__.automator.gestureAsync.bind(__runtime__.automator, 0);
automator.swipe = __runtime__.automator.swipe.bind(__runtime__.automator);
automator.gestures = function(){
return __runtime__.automator.gestures(toStrokes(arguments));
}
automator.gesturesAsync = function(){
__runtime__.automator.gesturesAsync(toStrokes(arguments));
}
function toStrokes(args){
var screenMetrics = __runtime__.getScreenMetrics();
var len = args.length;
var strokes = [];
for(var i = 0; i < len; i++){
var gesture = args[i];
var pointsIndex = 1;
if(typeof(gesture[1]) == 'number'){
var start = gesture[0];
var delay = gesture[1];
pointsIndex = 2;
}else{
var start = 0;
var delay = gesture[0];
}
var gestureLen = gesture.length;
var path = new android.graphics.Path();
path.moveTo(screenMetrics.scaleX(gesture[pointsIndex][0]), screenMetrics.scaleY(gesture[pointsIndex][1]));
for(var j = pointsIndex + 1; j < gestureLen; j++){
path.lineTo(screenMetrics.scaleX(gesture[j][0]), screenMetrics.scaleY(gesture[j][1]));
}
strokes.push(new android.accessibilityservice.GestureDescription.StrokeDescription(path, start, delay));
}
return strokes;
}
automator.scrollDown = function(a, b, c, d){
if(arguments.length == 0)
@@ -54,7 +97,7 @@ module.exports = function(__runtime__, scope){
}
scope.__asGlobal__(__runtime__.automator, ['back', 'home', 'powerDialog', 'notifications', 'quickSettings', 'recents', 'splitScreen']);
scope.__asGlobal__(automator, ['click', 'longClick', 'scrollDown', 'scrollUp', 'input']);
scope.__asGlobal__(automator, ['click', 'longClick', 'press', 'swipe', 'gesture', 'gestures', 'gestureAsync', 'gesturesAsync', 'scrollDown', 'scrollUp', 'input']);
return automator;
}

View File

@@ -42,4 +42,6 @@ module.exports = function(__runtime__, scope){
sleep(delay);
}
}
scope.setScreenMetrics = __runtime__.setScreenMetrics.bind(__runtime__);
}

View File

@@ -1,5 +1,5 @@
module.exports = function(__runtime__, scope){
var ui = Object(__runtime__.ui);
var ui = Object.create(__runtime__.ui);
ui.__id_cache__ = {};
ui.layout = function(xml){
@@ -39,7 +39,13 @@ module.exports = function(__runtime__, scope){
if(typeof(color) == 'string'){
color = android.graphics.Color.parseColor(color);
}
activity.getWindow().setStatusBarColor(color);
if(Build.VERSION.SDK_INT >= 21){
activity.getWindow().setStatusBarColor(color);
}
}
ui.finish = function(){
activity.finish();
}
function decorate(view){