mirror of
https://github.com/TonyJiangWJ/Auto.js.git
synced 2026-06-21 21:01:43 +08:00
fix: require for absolute path
This commit is contained in:
parent
328ab6efa7
commit
d775b5e77c
@ -2,11 +2,13 @@ package com.stardust.scriptdroid.ui.edit;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.ActionMode;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toolbar;
|
||||
|
||||
import com.stardust.app.OnActivityResultDelegate;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.model.script.ScriptFile;
|
||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||
@ -25,7 +27,9 @@ import static com.stardust.scriptdroid.ui.edit.EditorView.EXTRA_READ_ONLY;
|
||||
* Created by Stardust on 2017/1/29.
|
||||
*/
|
||||
@EActivity(R.layout.activity_edit)
|
||||
public class EditActivity extends BaseActivity {
|
||||
public class EditActivity extends BaseActivity implements OnActivityResultDelegate.DelegateHost {
|
||||
|
||||
private OnActivityResultDelegate.Mediator mMediator = new OnActivityResultDelegate.Mediator();
|
||||
|
||||
@ViewById(R.id.editor_view)
|
||||
EditorView mEditor;
|
||||
@ -113,4 +117,14 @@ public class EditActivity extends BaseActivity {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public OnActivityResultDelegate.Mediator getOnActivityResultDelegateMediator() {
|
||||
return mMediator;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
mMediator.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,9 +42,9 @@ module.exports = function(__runtime__, scope){
|
||||
var threshold = options.threshold || 16;
|
||||
}
|
||||
if(options.region){
|
||||
return rtImages.toAndroidPoint(colorFinder.findColor(img, color, threshold, buildRegion(options.region, img)));
|
||||
return colorFinder.findColor(img, color, threshold, buildRegion(options.region, img));
|
||||
}else{
|
||||
return rtImages.toAndroidPoint(colorFinder.findColor(img, color, threshold, null));
|
||||
return colorFinder.findColor(img, color, threshold, null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ module.exports = function(__runtime__, scope){
|
||||
function toPointArray(points){
|
||||
var arr = [];
|
||||
for(var i = 0; i < points.length; i++){
|
||||
arr.push(rtImages.toAndroidPoint(points[i]));
|
||||
arr.push(points[i]);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
@ -111,12 +111,12 @@ public class TemplateMatching {
|
||||
}
|
||||
|
||||
private static Rect getROI(Point p, Mat src, Mat currentTemplate) {
|
||||
int x = (int) (p.x * 2 - currentTemplate.rows() / 4);
|
||||
int x = (int) (p.x * 2 - currentTemplate.cols() / 4);
|
||||
x = Math.max(0, x);
|
||||
int y = (int) (p.y * 2 - currentTemplate.cols() / 4);
|
||||
int y = (int) (p.y * 2 - currentTemplate.rows() / 4);
|
||||
y = Math.max(0, y);
|
||||
int w = (int) (currentTemplate.rows() * 1.5);
|
||||
int h = (int) (currentTemplate.cols() * 1.5);
|
||||
int w = (int) (currentTemplate.cols() * 1.5);
|
||||
int h = (int) (currentTemplate.rows() * 1.5);
|
||||
if (x + w >= src.cols()) {
|
||||
w = src.cols() - x - 1;
|
||||
}
|
||||
|
||||
@ -1,13 +1,18 @@
|
||||
package com.stardust.autojs.engine;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
import org.mozilla.javascript.commonjs.module.provider.ModuleSource;
|
||||
import org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -31,7 +36,6 @@ public class AssetAndUrlModuleSourceProvider extends UrlModuleSourceProvider {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected ModuleSource loadFromPrivilegedLocations(String moduleId, Object validator) throws IOException, URISyntaxException {
|
||||
String moduleIdWithExtension = moduleId;
|
||||
|
||||
@ -132,7 +132,7 @@ public class RhinoJavaScriptEngine extends JavaScriptEngine {
|
||||
AssetAndUrlModuleSourceProvider provider = new AssetAndUrlModuleSourceProvider(mAndroidContext, list);
|
||||
new RequireBuilder()
|
||||
.setModuleScriptProvider(new SoftCachingModuleScriptProvider(provider))
|
||||
.setSandboxed(true)
|
||||
.setSandboxed(false)
|
||||
.createRequire(context, scope)
|
||||
.install(scope);
|
||||
|
||||
|
||||
@ -6,7 +6,6 @@ import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Point;
|
||||
import android.media.Image;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
@ -16,6 +15,7 @@ import android.view.Display;
|
||||
import android.view.Surface;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.stardust.autojs.annotation.ScriptVariable;
|
||||
import com.stardust.autojs.core.image.ColorFinder;
|
||||
import com.stardust.autojs.core.image.ImageWrapper;
|
||||
import com.stardust.autojs.core.image.ScreenCaptureRequester;
|
||||
@ -23,23 +23,18 @@ import com.stardust.autojs.core.image.ScreenCapturer;
|
||||
import com.stardust.autojs.core.image.TemplateMatching;
|
||||
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||
import com.stardust.autojs.runtime.exception.ScriptInterruptedException;
|
||||
import com.stardust.autojs.annotation.ScriptVariable;
|
||||
import com.stardust.concurrent.VolatileBox;
|
||||
import com.stardust.concurrent.VolatileDispose;
|
||||
import com.stardust.pio.UncheckedIOException;
|
||||
import com.stardust.util.ScreenMetrics;
|
||||
|
||||
import org.opencv.android.Utils;
|
||||
import org.opencv.contrib.FaceRecognizer;
|
||||
import org.opencv.core.Core;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Rect;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.highgui.Highgui;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
@ -68,18 +63,14 @@ public class Images {
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public boolean requestScreenCapture(final int width, final int height) {
|
||||
mScriptRuntime.requiresApi(21);
|
||||
final VolatileBox<Boolean> requestResult = new VolatileBox<>();
|
||||
mScreenCaptureRequester.setOnActivityResultCallback(new ScreenCaptureRequester.Callback() {
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public void onRequestResult(int result, Intent data) {
|
||||
if (result == Activity.RESULT_OK) {
|
||||
mScreenCapturer = new ScreenCapturer(mContext, data, width, height, ScreenMetrics.getDeviceScreenDensity(),
|
||||
new Handler(mScriptRuntime.loopers.getServantLooper()));
|
||||
requestResult.setAndNotify(true);
|
||||
} else {
|
||||
requestResult.setAndNotify(false);
|
||||
}
|
||||
final VolatileDispose<Boolean> requestResult = new VolatileDispose<>();
|
||||
mScreenCaptureRequester.setOnActivityResultCallback((result, data) -> {
|
||||
if (result == Activity.RESULT_OK) {
|
||||
mScreenCapturer = new ScreenCapturer(mContext, data, width, height, ScreenMetrics.getDeviceScreenDensity(),
|
||||
new Handler(mScriptRuntime.loopers.getServantLooper()));
|
||||
requestResult.setAndNotify(true);
|
||||
} else {
|
||||
requestResult.setAndNotify(false);
|
||||
}
|
||||
});
|
||||
mScreenCaptureRequester.request();
|
||||
@ -139,7 +130,8 @@ public class Images {
|
||||
|
||||
|
||||
public ImageWrapper read(String path) {
|
||||
return ImageWrapper.ofBitmap(BitmapFactory.decodeFile(path));
|
||||
Bitmap bitmap = BitmapFactory.decodeFile(path);
|
||||
return ImageWrapper.ofBitmap(bitmap);
|
||||
}
|
||||
|
||||
public static void saveBitmap(Bitmap bitmap, String path) {
|
||||
@ -191,15 +183,8 @@ public class Images {
|
||||
point.x += rect.x;
|
||||
point.y += rect.y;
|
||||
}
|
||||
return toAndroidPoint(point);
|
||||
return point;
|
||||
}
|
||||
|
||||
|
||||
public static Point toAndroidPoint(org.opencv.core.Point p) {
|
||||
if (p == null) {
|
||||
return null;
|
||||
}
|
||||
return new Point((int) p.x, (int) p.y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user