fix some bugs
This commit is contained in:
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
@@ -45,7 +45,7 @@ public class AutoJs extends com.stardust.autojs.AutoJs {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Console createGlobalConsole() {
|
||||
protected GlobalStardustConsole createGlobalConsole() {
|
||||
return new GlobalStardustConsole(getUiHandler()) {
|
||||
@Override
|
||||
public String println(int level, CharSequence charSequence) {
|
||||
|
||||
@@ -41,6 +41,7 @@ public class ScriptIntents {
|
||||
long interval = intent.getLongExtra(EXTRA_KEY_LOOP_INTERVAL, 0);
|
||||
ScriptSource source = null;
|
||||
ExecutionConfig config = new ExecutionConfig().loop(delay, loopTimes, interval);
|
||||
config.setArgument("intent", intent);
|
||||
if (path == null && script != null) {
|
||||
source = new StringScriptSource(script);
|
||||
} else if (path != null && new PathChecker(context).checkAndToastError(path)) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.autojs.autojs.model.script;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.Nullable;
|
||||
@@ -147,9 +148,10 @@ public class Scripts {
|
||||
}
|
||||
|
||||
public static void send(ScriptFile file) {
|
||||
GlobalAppContext.get().startActivity(Intent.createChooser(new Intent(Intent.ACTION_SEND)
|
||||
Context context = GlobalAppContext.get();
|
||||
context.startActivity(Intent.createChooser(new Intent(Intent.ACTION_SEND)
|
||||
.setType("text/plain")
|
||||
.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)),
|
||||
.putExtra(Intent.EXTRA_STREAM, IntentUtil.getUriOfFile(context, file.getPath(), AppFileProvider.AUTHORITY)),
|
||||
GlobalAppContext.getString(R.string.text_send)
|
||||
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public abstract class FullScreenFloatyWindow implements FloatyWindow {
|
||||
mLayoutParams = new WindowManager.LayoutParams(
|
||||
WindowManager.LayoutParams.MATCH_PARENT,
|
||||
WindowManager.LayoutParams.MATCH_PARENT,
|
||||
WindowManager.LayoutParams.TYPE_PHONE,
|
||||
FloatyWindowManger.getWindowType(),
|
||||
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
|
||||
PixelFormat.TRANSLUCENT);
|
||||
mWindowManager.addView(mView, mLayoutParams);
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.stardust.app.DialogUtils;
|
||||
import com.stardust.enhancedfloaty.FloatyService;
|
||||
import org.autojs.autojs.R;
|
||||
import org.autojs.autojs.ui.codegeneration.CodeGenerateDialog;
|
||||
import org.autojs.autojs.ui.floating.FloatyWindowManger;
|
||||
import org.autojs.autojs.ui.floating.FullScreenFloatyWindow;
|
||||
import com.stardust.view.accessibility.NodeInfo;
|
||||
import org.autojs.autojs.ui.widget.BubblePopupMenu;
|
||||
@@ -115,7 +116,7 @@ public class LayoutBoundsFloatyWindow extends FullScreenFloatyWindow {
|
||||
.customView(mNodeInfoView, false)
|
||||
.theme(Theme.LIGHT)
|
||||
.build();
|
||||
mNodeInfoDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
|
||||
mNodeInfoDialog.getWindow().setType(FloatyWindowManger.getWindowType());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.stardust.app.DialogUtils;
|
||||
import com.stardust.enhancedfloaty.FloatyService;
|
||||
import org.autojs.autojs.R;
|
||||
import org.autojs.autojs.ui.codegeneration.CodeGenerateDialog;
|
||||
import org.autojs.autojs.ui.floating.FloatyWindowManger;
|
||||
import org.autojs.autojs.ui.floating.FullScreenFloatyWindow;
|
||||
import com.stardust.view.accessibility.NodeInfo;
|
||||
import org.autojs.autojs.ui.widget.BubblePopupMenu;
|
||||
@@ -124,7 +125,7 @@ public class LayoutHierarchyFloatyWindow extends FullScreenFloatyWindow {
|
||||
.theme(Theme.LIGHT)
|
||||
.build();
|
||||
if (mNodeInfoDialog.getWindow() != null)
|
||||
mNodeInfoDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
|
||||
mNodeInfoDialog.getWindow().setType(FloatyWindowManger.getWindowType());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,15 +2,14 @@ package org.autojs.autojs.ui.project;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.TextInputEditText;
|
||||
import android.support.design.widget.TextInputLayout;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
@@ -25,7 +24,6 @@ import org.androidannotations.annotations.AfterViews;
|
||||
import org.androidannotations.annotations.Click;
|
||||
import org.androidannotations.annotations.EActivity;
|
||||
import org.androidannotations.annotations.ViewById;
|
||||
import org.autojs.autojs.App;
|
||||
import org.autojs.autojs.Pref;
|
||||
import org.autojs.autojs.R;
|
||||
import org.autojs.autojs.autojs.build.AutoJsApkBuilder;
|
||||
@@ -41,9 +39,9 @@ import org.autojs.autojs.ui.shortcut.ShortcutIconSelectActivity_;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.security.KeyStore;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
@@ -60,6 +58,7 @@ public class BuildActivity extends BaseActivity implements AutoJsApkBuilder.Prog
|
||||
public static final String EXTRA_SOURCE = BuildActivity.class.getName() + ".extra_source_file";
|
||||
|
||||
private static final String LOG_TAG = "BuildActivity";
|
||||
private static final Pattern REGEX_PACKAGE_NAME = Pattern.compile("^([A-Za-z][A-Za-z\\d_]*\\.)+([A-Za-z][A-Za-z\\d_]*)$");
|
||||
|
||||
@ViewById(R.id.source_path)
|
||||
TextInputEditText mSourcePath;
|
||||
@@ -221,10 +220,25 @@ public class BuildActivity extends BaseActivity implements AutoJsApkBuilder.Prog
|
||||
inputValid &= checkNotEmpty(mSourcePath);
|
||||
inputValid &= checkNotEmpty(mVersionCode);
|
||||
inputValid &= checkNotEmpty(mVersionName);
|
||||
inputValid &= checkNotEmpty(mPackageName);
|
||||
inputValid &= checkPackageNameValid(mPackageName);
|
||||
return inputValid;
|
||||
}
|
||||
|
||||
private boolean checkPackageNameValid(TextInputEditText editText) {
|
||||
Editable text = editText.getText();
|
||||
String hint = ((TextInputLayout) editText.getParent().getParent()).getHint().toString();
|
||||
if(TextUtils.isEmpty(text)){
|
||||
editText.setError(hint + getString(R.string.text_should_not_be_empty));
|
||||
return false;
|
||||
}
|
||||
if(!REGEX_PACKAGE_NAME.matcher(text).matches()){
|
||||
editText.setError(getString(R.string.text_invalid_package_name));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private boolean checkNotEmpty(TextInputEditText editText) {
|
||||
if (!TextUtils.isEmpty(editText.getText()) || !editText.isShown())
|
||||
return true;
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.TextInputEditText;
|
||||
import android.support.design.widget.TextInputLayout;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
@@ -35,6 +36,7 @@ import org.autojs.autojs.ui.widget.SimpleTextWatcher;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
@@ -50,6 +52,7 @@ public class ProjectConfigActivity extends BaseActivity {
|
||||
public static final String EXTRA_DIRECTORY = "directory";
|
||||
|
||||
private static final int REQUEST_CODE = 12477;
|
||||
private static final Pattern REGEX_PACKAGE_NAME = Pattern.compile("^([A-Za-z][A-Za-z\\d_]*\\.)+([A-Za-z][A-Za-z\\d_]*)$");
|
||||
|
||||
|
||||
@ViewById(R.id.project_location)
|
||||
@@ -138,10 +141,10 @@ public class ProjectConfigActivity extends BaseActivity {
|
||||
@SuppressLint("CheckResult")
|
||||
@Click(R.id.fab)
|
||||
void commit() {
|
||||
syncProjectConfig();
|
||||
if (!checkInputs()) {
|
||||
return;
|
||||
}
|
||||
syncProjectConfig();
|
||||
if (mIconBitmap != null) {
|
||||
saveIcon(mIconBitmap)
|
||||
.subscribe(ignored -> saveProjectConfig(), e -> {
|
||||
@@ -209,10 +212,25 @@ public class ProjectConfigActivity extends BaseActivity {
|
||||
inputValid &= checkNotEmpty(mAppName);
|
||||
inputValid &= checkNotEmpty(mVersionCode);
|
||||
inputValid &= checkNotEmpty(mVersionName);
|
||||
inputValid &= checkNotEmpty(mPackageName);
|
||||
inputValid &= checkPackageNameValid(mPackageName);
|
||||
return inputValid;
|
||||
}
|
||||
|
||||
private boolean checkPackageNameValid(TextInputEditText editText) {
|
||||
Editable text = editText.getText();
|
||||
String hint = ((TextInputLayout) editText.getParent().getParent()).getHint().toString();
|
||||
if(TextUtils.isEmpty(text)){
|
||||
editText.setError(hint + getString(R.string.text_should_not_be_empty));
|
||||
return false;
|
||||
}
|
||||
if(!REGEX_PACKAGE_NAME.matcher(text).matches()){
|
||||
editText.setError(getString(R.string.text_invalid_package_name));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private boolean checkNotEmpty(TextInputEditText editText) {
|
||||
if (!TextUtils.isEmpty(editText.getText()))
|
||||
return true;
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.autojs.autojs.ui.timing;
|
||||
|
||||
import android.app.DatePickerDialog;
|
||||
import android.app.TimePickerDialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
@@ -346,8 +347,13 @@ public class TimedTaskSettingActivity extends BaseActivity {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == R.id.action_done) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !((PowerManager) getSystemService(POWER_SERVICE)).isIgnoringBatteryOptimizations(getPackageName())) {
|
||||
startActivityForResult(new Intent().setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
|
||||
.setData(Uri.parse("package:" + getPackageName())), REQUEST_CODE_IGNORE_BATTERY);
|
||||
try{
|
||||
startActivityForResult(new Intent().setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
|
||||
.setData(Uri.parse("package:" + getPackageName())), REQUEST_CODE_IGNORE_BATTERY);
|
||||
}catch(ActivityNotFoundException e){
|
||||
e.printStackTrace();
|
||||
createOrUpdateTask();
|
||||
}
|
||||
} else {
|
||||
createOrUpdateTask();
|
||||
}
|
||||
|
||||
@@ -422,4 +422,5 @@
|
||||
<string name="text_run_on_time_tick">每分钟一次</string>
|
||||
<string name="text_run_on_config_change">某些设置(屏幕方向,地区等)更改时</string>
|
||||
<string name="error_pattern_syntax">正则表达式错误</string>
|
||||
<string name="text_invalid_package_name">非法包名</string>
|
||||
</resources>
|
||||
|
||||
@@ -54,7 +54,7 @@ public abstract class AutoJs {
|
||||
private final AccessibilityInfoProvider mAccessibilityInfoProvider;
|
||||
private final ScreenCaptureRequester mScreenCaptureRequester = new ScreenCaptureRequesterImpl();
|
||||
private final ScriptEngineService mScriptEngineService;
|
||||
private final Console mGlobalConsole;
|
||||
private final GlobalStardustConsole mGlobalConsole;
|
||||
|
||||
|
||||
protected AutoJs(final Application application) {
|
||||
@@ -70,7 +70,7 @@ public abstract class AutoJs {
|
||||
init();
|
||||
}
|
||||
|
||||
protected Console createGlobalConsole() {
|
||||
protected GlobalStardustConsole createGlobalConsole() {
|
||||
return new GlobalStardustConsole(mUiHandler);
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ public abstract class AutoJs {
|
||||
return mLayoutInspector;
|
||||
}
|
||||
|
||||
public Console getGlobalConsole() {
|
||||
public GlobalStardustConsole getGlobalConsole() {
|
||||
return mGlobalConsole;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.stardust.autojs.core.console;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.stardust.autojs.R;
|
||||
@@ -17,6 +18,8 @@ import com.stardust.enhancedfloaty.ResizableExpandableFloatyWindow;
|
||||
import com.stardust.util.UiHandler;
|
||||
import com.stardust.util.ViewUtil;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
@@ -115,6 +118,13 @@ public class StardustConsole extends AbstractConsole {
|
||||
return mLogs;
|
||||
}
|
||||
|
||||
public void printStackTrace(Throwable t) {
|
||||
StringWriter out = new StringWriter();
|
||||
PrintWriter printWriter = new PrintWriter(out);
|
||||
t.printStackTrace(printWriter);
|
||||
println(android.util.Log.ERROR, t.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String println(int level, CharSequence charSequence) {
|
||||
Log log = new Log(mIdCounter.getAndIncrement(), level, charSequence, true);
|
||||
|
||||
@@ -2,10 +2,12 @@ package com.stardust.autojs.core.floaty;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
@@ -115,10 +117,16 @@ public class BaseResizableFloatyWindow extends ResizableFloatyWindow {
|
||||
}
|
||||
|
||||
private WindowManager.LayoutParams createWindowLayoutParams() {
|
||||
int type;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
||||
} else {
|
||||
type = WindowManager.LayoutParams.TYPE_PHONE;
|
||||
}
|
||||
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
|
||||
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
WindowManager.LayoutParams.TYPE_PHONE,
|
||||
type,
|
||||
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
|
||||
PixelFormat.TRANSLUCENT);
|
||||
layoutParams.gravity = Gravity.TOP | Gravity.START;
|
||||
|
||||
@@ -112,7 +112,8 @@ public class ColorFinder {
|
||||
ColorDetector colorDetector = new ColorDetector.DifferenceDetector(color, threshold);
|
||||
x += startingPoint.x;
|
||||
y += startingPoint.y;
|
||||
if (x >= image.getWidth() || y >= image.getHeight()) {
|
||||
if (x >= image.getWidth() || y >= image.getHeight()
|
||||
|| x < 0 || y < 0) {
|
||||
return false;
|
||||
}
|
||||
int c = image.pixel(x, y);
|
||||
|
||||
@@ -81,14 +81,17 @@ public class ImageWrapper {
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
ensureNotRecycled();
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
ensureNotRecycled();
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
public Mat getMat() {
|
||||
ensureNotRecycled();
|
||||
if (mMat == null && mBitmap != null) {
|
||||
mMat = new Mat();
|
||||
Utils.bitmapToMat(mBitmap, mMat);
|
||||
@@ -119,6 +122,7 @@ public class ImageWrapper {
|
||||
}
|
||||
|
||||
public Bitmap getBitmap() {
|
||||
ensureNotRecycled();
|
||||
return mBitmap;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,10 @@ package com.stardust.autojs.core.ui.dialog;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.os.Build;
|
||||
import android.os.Looper;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
@@ -29,7 +31,13 @@ public class BlockedMaterialDialog extends MaterialDialog {
|
||||
@Override
|
||||
public void show() {
|
||||
if (!isActivityContext(getContext())) {
|
||||
getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
|
||||
int type;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
||||
} else {
|
||||
type = WindowManager.LayoutParams.TYPE_PHONE;
|
||||
}
|
||||
getWindow().setType(type);
|
||||
}
|
||||
super.show();
|
||||
}
|
||||
|
||||
@@ -79,8 +79,15 @@ public class JsDialog {
|
||||
Context context = mDialog.getContext();
|
||||
if (!DialogUtils.isActivityContext(context)) {
|
||||
Window window = mDialog.getWindow();
|
||||
if (window != null)
|
||||
window.setType(WindowManager.LayoutParams.TYPE_PHONE);
|
||||
if (window != null){
|
||||
int type;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
||||
} else {
|
||||
type = WindowManager.LayoutParams.TYPE_PHONE;
|
||||
}
|
||||
window.setType(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -193,6 +193,7 @@ public class RhinoJavaScriptEngine extends JavaScriptEngine {
|
||||
}
|
||||
return super.wrap(cx, scope, obj, staticType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class InterruptibleAndroidContextFactory extends AndroidContextFactory {
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public class NativeJavaClassWithPrototype extends NativeJavaClass {
|
||||
|
||||
private static final Object NULL = new Object();
|
||||
private ConcurrentHashMap<String, Object> mProperties = new ConcurrentHashMap();
|
||||
private ConcurrentHashMap<String, Object> mProperties = new ConcurrentHashMap<>();
|
||||
|
||||
public NativeJavaClassWithPrototype(Scriptable scope, Class<?> javaClass) {
|
||||
super(scope, javaClass);
|
||||
|
||||
@@ -14,6 +14,14 @@ public class NativeJavaObjectWithPrototype extends NativeJavaObject {
|
||||
super(scope, javaObject, staticType);
|
||||
}
|
||||
|
||||
public NativeJavaObjectWithPrototype(Scriptable scope, Object javaObject, Class<?> staticType, boolean isAdapter) {
|
||||
super(scope, javaObject, staticType, isAdapter);
|
||||
}
|
||||
|
||||
public NativeJavaObjectWithPrototype() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean has(String name, Scriptable start) {
|
||||
return super.has(name, start) || (prototype != null && prototype.has(name, start))
|
||||
|
||||
@@ -63,6 +63,7 @@ public class UiObject extends AccessibilityNodeInfoCompat {
|
||||
mIndexInParent = indexInParent;
|
||||
if (DEBUG)
|
||||
mStackTrace = Arrays.toString(Thread.currentThread().getStackTrace());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import android.app.NativeActivity;
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.Environment;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.stardust.util.Func1;
|
||||
|
||||
@@ -18,6 +20,7 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
@@ -284,31 +287,36 @@ public class PFiles {
|
||||
}
|
||||
|
||||
|
||||
public static boolean copyAssetDir(Context context, String assetsDir, String toDir) {
|
||||
public static void copyAssetDir(Context context, String assetsDir, String toDir, String[] list) throws IOException {
|
||||
new File(toDir).mkdirs();
|
||||
AssetManager manager = context.getAssets();
|
||||
try {
|
||||
String[] list = manager.list(assetsDir);
|
||||
if (list == null)
|
||||
return false;
|
||||
for (String file : list) {
|
||||
InputStream stream;
|
||||
try {
|
||||
stream = manager.open(join(assetsDir, file));
|
||||
} catch (IOException e) {
|
||||
if (!copyAssetDir(context, join(assetsDir, file), join(toDir, file))) {
|
||||
return false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
copyStream(stream, join(toDir, file));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
if (list == null) {
|
||||
list = manager.list(assetsDir);
|
||||
}
|
||||
if (list == null)
|
||||
throw new IOException("not a directory: " + assetsDir);
|
||||
for (String file : list) {
|
||||
if(TextUtils.isEmpty(file)){
|
||||
continue;
|
||||
}
|
||||
String fullAssetsPath = join(assetsDir, file);
|
||||
String[] children = manager.list(fullAssetsPath);
|
||||
if (children == null || children.length == 0) {
|
||||
InputStream stream = null;
|
||||
try {
|
||||
stream = manager.open(fullAssetsPath);
|
||||
copyStream(stream, join(toDir, file));
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
} finally {
|
||||
if (stream != null) {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
copyAssetDir(context, fullAssetsPath, join(toDir, file), children);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public static String renameWithoutExtensionAndReturnNewPath(String path, String newName) {
|
||||
|
||||
@@ -12,17 +12,16 @@ import android.support.annotation.Nullable;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.auojs.inrt.launch.AssetsProjectLauncher;
|
||||
import com.stardust.auojs.inrt.autojs.AutoJs;
|
||||
import com.stardust.auojs.inrt.launch.GlobalProjectLauncher;
|
||||
import com.stardust.autojs.core.image.OpenCVHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static android.content.pm.PackageManager.PERMISSION_DENIED;
|
||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2018/2/2.
|
||||
@@ -58,7 +57,18 @@ public class SplashActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
private void runScript() {
|
||||
new Thread(() -> GlobalProjectLauncher.getInstance().launch(this)).start();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
GlobalProjectLauncher.getInstance().launch(this);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
runOnUiThread(() -> {
|
||||
Toast.makeText(SplashActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
startActivity(new Intent(SplashActivity.this, LogActivity.class));
|
||||
AutoJs.getInstance().getGlobalConsole().printStackTrace(e);
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,8 +17,10 @@ import com.stardust.autojs.execution.ScriptExecution;
|
||||
import com.stardust.autojs.project.ProjectConfig;
|
||||
import com.stardust.autojs.script.JavaScriptFileSource;
|
||||
import com.stardust.pio.PFiles;
|
||||
import com.stardust.pio.UncheckedIOException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2018/1/24.
|
||||
@@ -86,8 +88,12 @@ public class AssetsProjectLauncher {
|
||||
TextUtils.equals(projectConfig.getBuildInfo().getBuildId(), mProjectConfig.getBuildInfo().getBuildId())) {
|
||||
return;
|
||||
}
|
||||
PFiles.deleteRecursively(new File(mAssetsProjectDir));
|
||||
PFiles.copyAssetDir(mActivity, mAssetsProjectDir, mProjectDir);
|
||||
PFiles.deleteRecursively(new File(mProjectDir));
|
||||
try {
|
||||
PFiles.copyAssetDir(mActivity, mAssetsProjectDir, mProjectDir, null);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user