diff --git a/app/src/main/java/com/stardust/scriptdroid/autojs/AutoJs.java b/app/src/main/java/com/stardust/scriptdroid/autojs/AutoJs.java index 484aa209..14cbb43d 100644 --- a/app/src/main/java/com/stardust/scriptdroid/autojs/AutoJs.java +++ b/app/src/main/java/com/stardust/scriptdroid/autojs/AutoJs.java @@ -15,7 +15,7 @@ import com.stardust.autojs.engine.RhinoJavaScriptEngineManager; import com.stardust.autojs.engine.ScriptEngineManager; import com.stardust.autojs.runtime.AccessibilityBridge; import com.stardust.autojs.runtime.ScriptRuntime; -import com.stardust.autojs.runtime.ScriptStopException; +import com.stardust.autojs.runtime.ScriptException; import com.stardust.autojs.runtime.api.AbstractShell; import com.stardust.autojs.runtime.api.AppUtils; import com.stardust.autojs.runtime.api.Console; @@ -174,7 +174,7 @@ public class AutoJs { } if (errorMessage != null) { AccessibilityServiceTool.goToAccessibilitySetting(); - throw new ScriptStopException(errorMessage); + throw new ScriptException(errorMessage); } } } diff --git a/autojs/src/main/java/com/stardust/autojs/engine/ScriptEngine.java b/autojs/src/main/java/com/stardust/autojs/engine/ScriptEngine.java index f2b88fde..25506830 100644 --- a/autojs/src/main/java/com/stardust/autojs/engine/ScriptEngine.java +++ b/autojs/src/main/java/com/stardust/autojs/engine/ScriptEngine.java @@ -1,5 +1,6 @@ package com.stardust.autojs.engine; +import com.stardust.autojs.runtime.ScriptException; import com.stardust.autojs.script.ScriptSource; /** @@ -11,7 +12,7 @@ import com.stardust.autojs.script.ScriptSource; * When the execution finish successfully, the engine should be destroy in the thread that created it. *

* If you want to stop the engine in other threads, you should call {@link ScriptEngine#forceStop()}. - * It will throw a {@link com.stardust.autojs.runtime.ScriptStopException}. + * It will throw a {@link ScriptException}. */ public interface ScriptEngine { diff --git a/autojs/src/main/java/com/stardust/autojs/runtime/ScriptException.java b/autojs/src/main/java/com/stardust/autojs/runtime/ScriptException.java new file mode 100644 index 00000000..f54732e4 --- /dev/null +++ b/autojs/src/main/java/com/stardust/autojs/runtime/ScriptException.java @@ -0,0 +1,24 @@ +package com.stardust.autojs.runtime; + +/** + * Created by Stardust on 2017/1/29. + */ +public class ScriptException extends RuntimeException { + + + public ScriptException(String message, Throwable cause) { + super(message, cause); + } + + public ScriptException(String message) { + super(message); + } + + public ScriptException() { + + } + + public ScriptException(Throwable cause) { + super(cause); + } +} diff --git a/autojs/src/main/java/com/stardust/autojs/runtime/ScriptInterruptedException.java b/autojs/src/main/java/com/stardust/autojs/runtime/ScriptInterruptedException.java index a694478c..b20b90b8 100644 --- a/autojs/src/main/java/com/stardust/autojs/runtime/ScriptInterruptedException.java +++ b/autojs/src/main/java/com/stardust/autojs/runtime/ScriptInterruptedException.java @@ -4,7 +4,7 @@ package com.stardust.autojs.runtime; * Created by Stardust on 2017/4/30. */ -public class ScriptInterruptedException extends ScriptStopException { +public class ScriptInterruptedException extends ScriptException { public static boolean causedByInterrupted(Throwable e) { return e instanceof ScriptInterruptedException || e.getCause() instanceof ScriptInterruptedException; diff --git a/autojs/src/main/java/com/stardust/autojs/runtime/ScriptRuntime.java b/autojs/src/main/java/com/stardust/autojs/runtime/ScriptRuntime.java index 40dd947e..dd0d3ec3 100644 --- a/autojs/src/main/java/com/stardust/autojs/runtime/ScriptRuntime.java +++ b/autojs/src/main/java/com/stardust/autojs/runtime/ScriptRuntime.java @@ -226,9 +226,6 @@ public class ScriptRuntime { private void ensureRootShell() { if (mRootShell == null) { - if (mShellSupplier == null) { - throw new ScriptInterruptedException(); - } mRootShell = mShellSupplier.get(); mRootShell.SetScreenMetrics(mScreenMetrics); mShellSupplier = null; @@ -249,7 +246,7 @@ public class ScriptRuntime { public void requiresApi(int i) { if (Build.VERSION.SDK_INT < i) { - throw new ScriptStopException(mUiHandler.getContext().getString(R.string.text_requires_sdk_version_to_run_the_script) + SdkVersionUtil.sdkIntToString(i)); + throw new ScriptException(mUiHandler.getContext().getString(R.string.text_requires_sdk_version_to_run_the_script) + SdkVersionUtil.sdkIntToString(i)); } } diff --git a/autojs/src/main/java/com/stardust/autojs/runtime/ScriptStopException.java b/autojs/src/main/java/com/stardust/autojs/runtime/ScriptStopException.java deleted file mode 100644 index 8d39fc3f..00000000 --- a/autojs/src/main/java/com/stardust/autojs/runtime/ScriptStopException.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.stardust.autojs.runtime; - -/** - * Created by Stardust on 2017/1/29. - */ -public class ScriptStopException extends RuntimeException { - - - public ScriptStopException(String message, Throwable cause) { - super(message, cause); - } - - public ScriptStopException(String message) { - super(message); - } - - public ScriptStopException() { - - } - - public ScriptStopException(Throwable cause) { - super(cause); - } -} diff --git a/autojs/src/main/java/com/stardust/autojs/runtime/api/AbstractConsole.java b/autojs/src/main/java/com/stardust/autojs/runtime/api/AbstractConsole.java index 552c8129..a02379f8 100644 --- a/autojs/src/main/java/com/stardust/autojs/runtime/api/AbstractConsole.java +++ b/autojs/src/main/java/com/stardust/autojs/runtime/api/AbstractConsole.java @@ -3,7 +3,7 @@ package com.stardust.autojs.runtime.api; import android.support.annotation.Nullable; import android.util.Log; -import com.stardust.autojs.runtime.ScriptStopException; +import com.stardust.autojs.runtime.ScriptException; /** * Created by Stardust on 2017/5/1. @@ -59,7 +59,7 @@ public abstract class AbstractConsole implements Console { public void assertTrue(boolean value, @Nullable Object data, Object... options) { if (!value) { printf(Log.ASSERT, data, options); - throw new ScriptStopException(new AssertionError(format(data, options))); + throw new ScriptException(new AssertionError(format(data, options))); } } diff --git a/autojs/src/main/java/com/stardust/autojs/runtime/api/AbstractShell.java b/autojs/src/main/java/com/stardust/autojs/runtime/api/AbstractShell.java index d051e8ac..c37ddae9 100644 --- a/autojs/src/main/java/com/stardust/autojs/runtime/api/AbstractShell.java +++ b/autojs/src/main/java/com/stardust/autojs/runtime/api/AbstractShell.java @@ -118,7 +118,7 @@ public abstract class AbstractShell { } public void Swipe(int x1, int y1, int x2, int y2, int time) { - exec(com.stardust.util.TextUtils.join(" ", "input", "tap", scaleX(x1), scaleY(y1), scaleX(x2), scaleY(y2), time)); + exec(com.stardust.util.TextUtils.join(" ", "input", "swipe", scaleX(x1), scaleY(y1), scaleX(x2), scaleY(y2), time)); } public void KeyCode(int keyCode) { diff --git a/common/src/main/java/com/stardust/concurrent/VolatileBox.java b/common/src/main/java/com/stardust/concurrent/VolatileBox.java index 5648896d..894ee098 100644 --- a/common/src/main/java/com/stardust/concurrent/VolatileBox.java +++ b/common/src/main/java/com/stardust/concurrent/VolatileBox.java @@ -60,7 +60,9 @@ public class VolatileBox { } catch (InterruptedException e) { try { throw exception.newInstance(); - } catch (InstantiationException | IllegalAccessException e1) { + } catch (InstantiationException e1) { + throw new RuntimeException(e1); + } catch (IllegalAccessException e1) { throw new RuntimeException(e1); } }