fix: Swipe()

This commit is contained in:
hyb1996
2017-07-31 13:02:15 +08:00
parent 63bc8c0e09
commit 6307d3aa96
9 changed files with 36 additions and 36 deletions

View File

@@ -15,7 +15,7 @@ import com.stardust.autojs.engine.RhinoJavaScriptEngineManager;
import com.stardust.autojs.engine.ScriptEngineManager; import com.stardust.autojs.engine.ScriptEngineManager;
import com.stardust.autojs.runtime.AccessibilityBridge; import com.stardust.autojs.runtime.AccessibilityBridge;
import com.stardust.autojs.runtime.ScriptRuntime; 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.AbstractShell;
import com.stardust.autojs.runtime.api.AppUtils; import com.stardust.autojs.runtime.api.AppUtils;
import com.stardust.autojs.runtime.api.Console; import com.stardust.autojs.runtime.api.Console;
@@ -174,7 +174,7 @@ public class AutoJs {
} }
if (errorMessage != null) { if (errorMessage != null) {
AccessibilityServiceTool.goToAccessibilitySetting(); AccessibilityServiceTool.goToAccessibilitySetting();
throw new ScriptStopException(errorMessage); throw new ScriptException(errorMessage);
} }
} }
} }

View File

@@ -1,5 +1,6 @@
package com.stardust.autojs.engine; package com.stardust.autojs.engine;
import com.stardust.autojs.runtime.ScriptException;
import com.stardust.autojs.script.ScriptSource; 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. * When the execution finish successfully, the engine should be destroy in the thread that created it.
* <p> * <p>
* If you want to stop the engine in other threads, you should call {@link ScriptEngine#forceStop()}. * 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 { public interface ScriptEngine {

View File

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

View File

@@ -4,7 +4,7 @@ package com.stardust.autojs.runtime;
* Created by Stardust on 2017/4/30. * Created by Stardust on 2017/4/30.
*/ */
public class ScriptInterruptedException extends ScriptStopException { public class ScriptInterruptedException extends ScriptException {
public static boolean causedByInterrupted(Throwable e) { public static boolean causedByInterrupted(Throwable e) {
return e instanceof ScriptInterruptedException || e.getCause() instanceof ScriptInterruptedException; return e instanceof ScriptInterruptedException || e.getCause() instanceof ScriptInterruptedException;

View File

@@ -226,9 +226,6 @@ public class ScriptRuntime {
private void ensureRootShell() { private void ensureRootShell() {
if (mRootShell == null) { if (mRootShell == null) {
if (mShellSupplier == null) {
throw new ScriptInterruptedException();
}
mRootShell = mShellSupplier.get(); mRootShell = mShellSupplier.get();
mRootShell.SetScreenMetrics(mScreenMetrics); mRootShell.SetScreenMetrics(mScreenMetrics);
mShellSupplier = null; mShellSupplier = null;
@@ -249,7 +246,7 @@ public class ScriptRuntime {
public void requiresApi(int i) { public void requiresApi(int i) {
if (Build.VERSION.SDK_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));
} }
} }

View File

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

View File

@@ -3,7 +3,7 @@ package com.stardust.autojs.runtime.api;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.Log; import android.util.Log;
import com.stardust.autojs.runtime.ScriptStopException; import com.stardust.autojs.runtime.ScriptException;
/** /**
* Created by Stardust on 2017/5/1. * 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) { public void assertTrue(boolean value, @Nullable Object data, Object... options) {
if (!value) { if (!value) {
printf(Log.ASSERT, data, options); printf(Log.ASSERT, data, options);
throw new ScriptStopException(new AssertionError(format(data, options))); throw new ScriptException(new AssertionError(format(data, options)));
} }
} }

View File

@@ -118,7 +118,7 @@ public abstract class AbstractShell {
} }
public void Swipe(int x1, int y1, int x2, int y2, int time) { 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) { public void KeyCode(int keyCode) {

View File

@@ -60,7 +60,9 @@ public class VolatileBox<T> {
} catch (InterruptedException e) { } catch (InterruptedException e) {
try { try {
throw exception.newInstance(); throw exception.newInstance();
} catch (InstantiationException | IllegalAccessException e1) { } catch (InstantiationException e1) {
throw new RuntimeException(e1);
} catch (IllegalAccessException e1) {
throw new RuntimeException(e1); throw new RuntimeException(e1);
} }
} }