try to fix crash under android19

This commit is contained in:
hyb1996 2017-07-12 12:09:32 +08:00
parent fcfb3a69e0
commit c827ef7c64
5 changed files with 38 additions and 15 deletions

View File

@ -9,8 +9,8 @@ android {
applicationId "com.stardust.scriptdroid"
minSdkVersion 17
targetSdkVersion 23
versionCode 145
versionName "2.0.13 Beta3"
versionCode 146
versionName "2.0.14 Alpha"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
ndk {

View File

@ -1,3 +0,0 @@
module.exports = function(){
}

View File

@ -0,0 +1,12 @@
if(!requestScreenCapture()){
toast("请求截图失败");
}
sleep(2000);
var x = 760;
var y = 180;
//获取在点(x, y)处的颜色
var c = images.pixel(captureScreen(), x, y);
//显示该颜色
toast((c >>> 0).toString(16));
//检测在点(x, y)处是否有颜色0x73bdb6 (模糊比较)
toast(images.detectsColor(captureScreen(), x, y, 0x73bdb6))

View File

@ -1,18 +1,23 @@
module.exports = function(__runtime__, scope){
var images = {};
if(android.os.Build.VERSION.SDK_INT < 19){
return images;
}
var colorFinder = __runtime__.images.colorFinder;
var rtImages = __runtime__.getImages();
images.requestScreenCapture = __runtime__.images.requestScreenCapture.bind(__runtime__.images);
var colorFinder = rtImages.colorFinder;
images.captureScreen = __runtime__.images.captureScreen.bind(__runtime__.images);
images.requestScreenCapture = rtImages.requestScreenCapture.bind(rtImages);
images.saveImage = __runtime__.images.saveImage.bind(__runtime__.images);
images.captureScreen = rtImages.captureScreen.bind(rtImages);
images.pixel = __runtime__.images.pixel;
images.saveImage = rtImages.saveImage.bind(rtImages);
images.detectsColor = __runtime__.images.detectsColor.bind(__runtime__.images);
images.pixel = rtImages.pixel;
images.detectsColor = rtImages.detectsColor.bind(rtImages);
images.findColor = function(img, color, options){
if(typeof(color) == 'string'){

View File

@ -1,6 +1,7 @@
package com.stardust.autojs.runtime;
import android.content.Context;
import android.os.Build;
import android.support.annotation.CallSuper;
import com.stardust.autojs.engine.ScriptEngine;
@ -40,12 +41,12 @@ public abstract class AbstractScriptRuntime {
@ScriptVariable
public UI ui;
@ScriptVariable
public Images images;
@ScriptVariable
public Dialogs dialogs;
private Images images;
private static WeakReference<Context> applicationContext;
public AbstractScriptRuntime(UiHandler uiHandler, Console console, AccessibilityBridge bridge, AppUtils appUtils, ScreenCaptureRequester screenCaptureRequester) {
@ -54,7 +55,9 @@ public abstract class AbstractScriptRuntime {
this.automator = new SimpleActionAutomator(bridge, this);
this.info = bridge.getInfoProvider();
this.ui = new UI(uiHandler.getContext());
images = new Images(uiHandler.getContext(), this, screenCaptureRequester);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
images = new Images(uiHandler.getContext(), this, screenCaptureRequester);
}
dialogs = new Dialogs(app, uiHandler);
}
@ -109,6 +112,12 @@ public abstract class AbstractScriptRuntime {
@CallSuper
public void onStop() {
images.releaseScreenCapturer();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
images.releaseScreenCapturer();
}
}
public Object getImages() {
return images;
}
}