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

@@ -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;
}
}