make autojs module more independent
@@ -97,7 +97,6 @@ dependencies {
|
||||
compile 'com.android.support:multidex:1.0.1'
|
||||
// Personal libraries
|
||||
compile 'com.github.hyb1996:MutableTheme:0.2.2'
|
||||
compile 'com.github.hyb1996:EnhancedFloaty:0.17'
|
||||
// Material Dialogs
|
||||
compile 'com.afollestad.material-dialogs:core:0.9.2.3'
|
||||
// Gson
|
||||
@@ -121,10 +120,6 @@ dependencies {
|
||||
compile 'com.android.volley:volley:1.0.0'
|
||||
compile 'com.flurry.android:analytics:7.0.0@aar'
|
||||
compile 'com.pushtorefresh.storio:sqlite:1.12.3'
|
||||
// Terminal emulator
|
||||
compile(name: 'libtermexec-release', ext: 'aar')
|
||||
compile(name: 'emulatorview-release', ext: 'aar')
|
||||
compile(name: 'term-debug', ext: 'aar')
|
||||
// 920 Text Editor
|
||||
compile 'com.afollestad.material-dialogs:commons:0.9.2.3'
|
||||
compile 'com.makeramen:roundedimageview:2.2.1'
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
android:theme="@style/AppTheme"
|
||||
tools:replace="android:label, android:icon, android:allowBackup">
|
||||
<activity
|
||||
android:name=".ui.main.MainActivity"
|
||||
android:name=".ui.main.MainActivity_"
|
||||
android:hardwareAccelerated="true"
|
||||
android:label="@string/_app_name"
|
||||
android:launchMode="singleTask"
|
||||
@@ -46,21 +46,6 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:name=".service.AccessibilityWatchDogService"
|
||||
android:enabled="true"
|
||||
android:exported="true"
|
||||
android:label="@string/_app_name"
|
||||
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
|
||||
<intent-filter>
|
||||
<action android:name="android.accessibilityservice.AccessibilityService"/>
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="android.accessibilityservice"
|
||||
android:resource="@xml/accessibility_service_config"/>
|
||||
|
||||
</service>
|
||||
|
||||
<provider
|
||||
android:name="android.support.v4.content.FileProvider"
|
||||
android:authorities="com.stardust.scriptdroid.fileprovider"
|
||||
@@ -72,21 +57,21 @@
|
||||
</provider>
|
||||
|
||||
<activity
|
||||
android:name=".ui.edit.EditActivity"
|
||||
android:name=".ui.edit.EditActivity_"
|
||||
android:multiprocess="true">
|
||||
|
||||
</activity>
|
||||
<activity android:name=".ui.help.DocumentationActivity"/>
|
||||
<activity android:name=".ui.help.HelpCatalogueActivity"/>
|
||||
<activity android:name=".ui.settings.AboutActivity"/>
|
||||
<activity android:name=".ui.settings.SettingsActivity"/>
|
||||
<activity android:name=".ui.console.LogActivity"/>
|
||||
<activity android:name=".ui.settings.AboutActivity_"/>
|
||||
<activity android:name=".ui.settings.SettingsActivity_"/>
|
||||
<activity android:name=".ui.console.LogActivity_"/>
|
||||
<activity android:name=".ui.error.ErrorReportActivity"/>
|
||||
<activity android:name=".ui.help.LocalWebViewActivity"/>
|
||||
<activity android:name=".external.tasker.TaskerScriptEditActivity"/>
|
||||
<activity android:name=".ui.edit.ViewSampleActivity"/>
|
||||
<activity
|
||||
android:name=".autojs.api.ScreenCaptureRequestActivity"
|
||||
android:name="com.stardust.autojs.runtime.api.image.ScreenCaptureRequestActivity"
|
||||
android:taskAffinity="com.stardust.scriptdroid.autojs.api.ScreenCaptureRequestActivity"/>
|
||||
|
||||
<activity
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
__importClass__(com.stardust.scriptdroid.autojs.api.Shell);
|
||||
|
||||
|
||||
var dialogs = {};
|
||||
|
||||
dialogs.rawInput = function(title, prefill){
|
||||
prefill = prefill || "";
|
||||
var s = __runtime__.dialogs.rawInput(title, prefill);
|
||||
return s ? String(s) : null;
|
||||
};
|
||||
|
||||
dialogs.input = function(title, prefill){
|
||||
return eval(dialogs.rawInput(title, prefill));
|
||||
}
|
||||
|
||||
dialogs.prompt = dialogs.rawInput;
|
||||
|
||||
dialogs.alert = function(title, prefill){
|
||||
prefill = prefill || "";
|
||||
return __runtime__.dialogs.alert(title, prefill);
|
||||
}
|
||||
|
||||
dialogs.confirm = function(title, prefill){
|
||||
prefill = prefill || "";
|
||||
return __runtime__.dialogs.confirm(title, prefill);
|
||||
}
|
||||
|
||||
dialogs.select = function(title, items){
|
||||
if(items instanceof Array){
|
||||
return __runtime__.dialogs.select(title, items);
|
||||
}
|
||||
return __runtime__.dialogs.select(title, [].slice.call(arguments, 1));
|
||||
}
|
||||
|
||||
dialogs.singleChoice = function(title, items, index){
|
||||
index = index || 0;
|
||||
return __runtime__.dialogs.singleChoice(title, index, items);
|
||||
}
|
||||
|
||||
dialogs.multiChoice = function(title, items, index){
|
||||
index = index || [];
|
||||
var javaArray = __runtime__.dialogs.multiChoice(title, index, items);
|
||||
var jsArray = [];
|
||||
var len = javaArray.length;
|
||||
for (var i = 0;i < len;i++){
|
||||
jsArray.push(javaArray[i]);
|
||||
}
|
||||
return jsArray;
|
||||
}
|
||||
|
||||
var rawInput = function(title, prefill){
|
||||
return dialogs.rawInput(title, prefill);
|
||||
}
|
||||
|
||||
var alert = function(title, prefill){
|
||||
dialogs.alert(title, prefill);
|
||||
}
|
||||
|
||||
var confirm = function(title, prefill){
|
||||
return dialogs.confirm(title, prefill);
|
||||
}
|
||||
|
||||
var prompt = function(title, prefill){
|
||||
return dialogs.prompt(title, prefill);
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package com.stardust.app;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.os.Bundle;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/2.
|
||||
*/
|
||||
|
||||
public class SimpleActivityLifecycleCallbacks implements Application.ActivityLifecycleCallbacks {
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStarted(Activity activity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResumed(Activity activity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityPaused(Activity activity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStopped(Activity activity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityDestroyed(Activity activity) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,6 @@ public class App extends MultiDexApplication {
|
||||
setUpStaticsTool();
|
||||
setUpDebugEnvironment();
|
||||
init();
|
||||
registerActivityLifecycleCallback();
|
||||
}
|
||||
|
||||
private void setUpStaticsTool() {
|
||||
@@ -83,9 +82,6 @@ public class App extends MultiDexApplication {
|
||||
});
|
||||
}
|
||||
|
||||
private void registerActivityLifecycleCallback() {
|
||||
|
||||
}
|
||||
|
||||
public static String getResString(int id) {
|
||||
return getApp().getString(id);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.stardust.scriptdroid.autojs;
|
||||
|
||||
import android.accessibilityservice.AccessibilityService;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
@@ -15,33 +14,31 @@ import com.stardust.autojs.ScriptEngineServiceBuilder;
|
||||
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.api.AbstractShell;
|
||||
import com.stardust.autojs.runtime.api.AppUtils;
|
||||
import com.stardust.autojs.runtime.api.Console;
|
||||
import com.stardust.autojs.runtime.api.image.ScreenCaptureRequester;
|
||||
import com.stardust.automator.AccessibilityEventCommandHost;
|
||||
import com.stardust.automator.simple_action.SimpleActionPerformHost;
|
||||
import com.stardust.pio.PFile;
|
||||
import com.stardust.pio.UncheckedIOException;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.Pref;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.autojs.api.ScreenCaptureRequestActivity;
|
||||
import com.stardust.scriptdroid.autojs.api.Shell;
|
||||
import com.stardust.scriptdroid.ui.console.StardustConsole;
|
||||
import com.stardust.autojs.runtime.api.image.ScreenCaptureRequestActivity;
|
||||
import com.stardust.autojs.runtime.api.Shell;
|
||||
import com.stardust.autojs.runtime.console.StardustConsole;
|
||||
import com.stardust.util.ScreenMetrics;
|
||||
import com.stardust.util.Supplier;
|
||||
import com.stardust.util.UiHandler;
|
||||
import com.stardust.view.accessibility.AccessibilityInfoProvider;
|
||||
import com.stardust.scriptdroid.external.floatingwindow.menu.layout_inspector.LayoutInspector;
|
||||
import com.stardust.scriptdroid.external.floatingwindow.menu.record.accessibility.AccessibilityActionRecorder;
|
||||
import com.stardust.scriptdroid.service.AccessibilityWatchDogService;
|
||||
import com.stardust.view.accessibility.AccessibilityService;
|
||||
import com.stardust.scriptdroid.tool.AccessibilityServiceTool;
|
||||
import com.stardust.scriptdroid.ui.console.JraskaConsole;
|
||||
import com.stardust.view.accessibility.AccessibilityServiceUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/2.
|
||||
@@ -50,7 +47,6 @@ import java.io.IOException;
|
||||
public class AutoJs implements AccessibilityBridge {
|
||||
|
||||
private static AutoJs instance;
|
||||
private static final String INIT_SCRIPT_PATH = "js/autojs_init.js";
|
||||
|
||||
public static AutoJs getInstance() {
|
||||
return instance;
|
||||
@@ -92,16 +88,17 @@ public class AutoJs implements AccessibilityBridge {
|
||||
mAppUtils = new AppUtils(context);
|
||||
mAccessibilityInfoProvider = new AccessibilityInfoProvider(context.getPackageManager());
|
||||
ScriptEngineManager manager = createScriptEngineManager(context);
|
||||
final Console globalConsole = new JraskaConsole();
|
||||
mScriptEngineService = new ScriptEngineServiceBuilder()
|
||||
.uiHandler(mUiHandler)
|
||||
.globalConsole(new JraskaConsole())
|
||||
.globalConsole(globalConsole)
|
||||
.engineManger(manager)
|
||||
.runtime(new Supplier<com.stardust.autojs.runtime.ScriptRuntime>() {
|
||||
|
||||
@Override
|
||||
public com.stardust.autojs.runtime.ScriptRuntime get() {
|
||||
return new ScriptRuntime.Builder()
|
||||
.setConsole(new StardustConsole(mUiHandler))
|
||||
.setConsole(new StardustConsole(mUiHandler, globalConsole))
|
||||
.setScreenCaptureRequester(mScreenCaptureRequester)
|
||||
.setAccessibilityBridge(AutoJs.this)
|
||||
.setUiHandler(mUiHandler)
|
||||
@@ -109,7 +106,7 @@ public class AutoJs implements AccessibilityBridge {
|
||||
.setShellSupplier(new Supplier<AbstractShell>() {
|
||||
@Override
|
||||
public AbstractShell get() {
|
||||
return new Shell(true);
|
||||
return new Shell(context, true);
|
||||
}
|
||||
}).build();
|
||||
}
|
||||
@@ -142,20 +139,14 @@ public class AutoJs implements AccessibilityBridge {
|
||||
}
|
||||
|
||||
private ScriptEngineManager createScriptEngineManager(Context context) {
|
||||
RhinoJavaScriptEngineManager manager = new RhinoJavaScriptEngineManager(context);
|
||||
try {
|
||||
manager.setInitScript(PFile.read(context.getAssets().open(INIT_SCRIPT_PATH)));
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return manager;
|
||||
return new RhinoJavaScriptEngineManager(context);
|
||||
}
|
||||
|
||||
private void addAccessibilityServiceDelegates() {
|
||||
AccessibilityWatchDogService.addDelegate(100, mAccessibilityInfoProvider);
|
||||
AccessibilityWatchDogService.addDelegate(300, mAccessibilityActionRecorder);
|
||||
// AccessibilityWatchDogService.addDelegate(400, mSimpleActionPerformHost);
|
||||
//AccessibilityWatchDogService.addDelegate(500, mAccessibilityEventCommandHost);
|
||||
AccessibilityService.addDelegate(100, mAccessibilityInfoProvider);
|
||||
AccessibilityService.addDelegate(300, mAccessibilityActionRecorder);
|
||||
// AccessibilityService.addDelegate(400, mSimpleActionPerformHost);
|
||||
//AccessibilityService.addDelegate(500, mAccessibilityEventCommandHost);
|
||||
}
|
||||
|
||||
public AccessibilityActionRecorder getAccessibilityActionRecorder() {
|
||||
@@ -186,15 +177,15 @@ public class AutoJs implements AccessibilityBridge {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AccessibilityService getService() {
|
||||
return AccessibilityWatchDogService.getInstance();
|
||||
public android.accessibilityservice.AccessibilityService getService() {
|
||||
return AccessibilityService.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ensureServiceEnabled() {
|
||||
if (AccessibilityWatchDogService.getInstance() == null) {
|
||||
if (AccessibilityService.getInstance() == null) {
|
||||
String errorMessage = null;
|
||||
if (AccessibilityServiceUtils.isAccessibilityServiceEnabled(App.getApp(), AccessibilityWatchDogService.class)) {
|
||||
if (AccessibilityServiceUtils.isAccessibilityServiceEnabled(App.getApp(), AccessibilityService.class)) {
|
||||
errorMessage = App.getApp().getString(R.string.text_auto_operate_service_enabled_but_not_running);
|
||||
} else {
|
||||
if (Pref.enableAccessibilityServiceByRoot()) {
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.stardust.scriptdroid.autojs;
|
||||
|
||||
import com.stardust.autojs.runtime.AccessibilityBridge;
|
||||
import com.stardust.autojs.runtime.ScriptVariable;
|
||||
import com.stardust.autojs.runtime.api.AbstractShell;
|
||||
import com.stardust.autojs.runtime.api.AppUtils;
|
||||
import com.stardust.autojs.runtime.api.Console;
|
||||
import com.stardust.scriptdroid.autojs.api.Dialogs;
|
||||
import com.stardust.util.Supplier;
|
||||
import com.stardust.util.UiHandler;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/8.
|
||||
*/
|
||||
|
||||
public class ScriptRuntime extends com.stardust.autojs.runtime.ScriptRuntime {
|
||||
|
||||
|
||||
public static class Builder extends com.stardust.autojs.runtime.ScriptRuntime.Builder {
|
||||
|
||||
|
||||
public Builder() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ScriptRuntime build() {
|
||||
return new ScriptRuntime(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ScriptVariable
|
||||
public Dialogs dialogs;
|
||||
|
||||
private ScriptRuntime(Builder builder) {
|
||||
super(builder);
|
||||
dialogs = new Dialogs(app, getUiHandler());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
package com.stardust.scriptdroid.autojs.api;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.concurrent.VolatileBox;
|
||||
import com.stardust.util.UiHandler;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/8.
|
||||
*/
|
||||
|
||||
public class BlockedMaterialDialog extends MaterialDialog {
|
||||
|
||||
protected BlockedMaterialDialog(MaterialDialog.Builder builder) {
|
||||
super(builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
if (!isActivityContext(getContext())) {
|
||||
getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
|
||||
}
|
||||
super.show();
|
||||
}
|
||||
|
||||
private boolean isActivityContext(Context context) {
|
||||
if (context == null)
|
||||
return false;
|
||||
if (context instanceof Activity)
|
||||
return true;
|
||||
if (context instanceof ContextWrapper) {
|
||||
return isActivityContext(((ContextWrapper) context).getBaseContext());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static class Builder extends MaterialDialog.Builder {
|
||||
|
||||
private UiHandler mUiHandler;
|
||||
|
||||
public Builder(Context context, UiHandler uiHandler) {
|
||||
super(context);
|
||||
mUiHandler = uiHandler;
|
||||
}
|
||||
|
||||
public MaterialDialog.Builder input(@Nullable CharSequence hint, @Nullable CharSequence prefill, boolean allowEmptyInput, final VolatileBox<String> result) {
|
||||
dismissListener(result);
|
||||
super.input(hint, prefill, allowEmptyInput, new MaterialDialog.InputCallback() {
|
||||
@Override
|
||||
public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
|
||||
result.set(input.toString());
|
||||
synchronized (result) {
|
||||
result.notify();
|
||||
}
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder confirm(final VolatileBox<Boolean> result) {
|
||||
onAny(new SingleButtonCallback() {
|
||||
@Override
|
||||
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
|
||||
if (which == DialogAction.POSITIVE) {
|
||||
result.setAndNotify(true);
|
||||
} else {
|
||||
result.setAndNotify(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
public MaterialDialog.Builder itemsCallback(final VolatileBox<Integer> result) {
|
||||
dismissListener(result);
|
||||
super.itemsCallback(new ListCallback() {
|
||||
@Override
|
||||
public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
|
||||
result.setAndNotify(position);
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
public MaterialDialog.Builder itemsCallbackMultiChoice(@Nullable Integer[] selectedIndices, final VolatileBox<Integer[]> result) {
|
||||
dismissListener(result);
|
||||
super.itemsCallbackMultiChoice(selectedIndices, new ListCallbackMultiChoice() {
|
||||
@Override
|
||||
public boolean onSelection(MaterialDialog dialog, Integer[] which, CharSequence[] text) {
|
||||
result.setAndNotify(which);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
public MaterialDialog.Builder itemsCallbackSingleChoice(int selectedIndex, final VolatileBox<Integer> result) {
|
||||
dismissListener(result);
|
||||
super.itemsCallbackSingleChoice(selectedIndex, new ListCallbackSingleChoice() {
|
||||
@Override
|
||||
public boolean onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
|
||||
result.setAndNotify(which);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder dismissListener(final VolatileBox<?> result) {
|
||||
super.dismissListener(new OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
synchronized (result) {
|
||||
result.notify();
|
||||
}
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialDialog show() {
|
||||
mUiHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Builder.super.show();
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialDialog build() {
|
||||
return new BlockedMaterialDialog(this);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
package com.stardust.scriptdroid.autojs.api;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.text.TextUtils;
|
||||
import android.view.ContextThemeWrapper;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.autojs.runtime.ScriptInterface;
|
||||
import com.stardust.autojs.runtime.ScriptInterruptedException;
|
||||
import com.stardust.autojs.runtime.api.AppUtils;
|
||||
import com.stardust.concurrent.VolatileBox;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.util.ArrayUtils;
|
||||
import com.stardust.util.UiHandler;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/8.
|
||||
*/
|
||||
|
||||
public class Dialogs {
|
||||
|
||||
private AppUtils mAppUtils;
|
||||
private UiHandler mUiHandler;
|
||||
private ContextWrapper mContextWrapper;
|
||||
|
||||
public Dialogs(AppUtils appUtils, UiHandler uiHandler) {
|
||||
mAppUtils = appUtils;
|
||||
mUiHandler = uiHandler;
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
public String rawInput(String title, String prefill) {
|
||||
VolatileBox<String> result = new VolatileBox<>(null);
|
||||
dialogBuilder()
|
||||
.input(null, prefill, true, result)
|
||||
.title(title)
|
||||
.show();
|
||||
return result.blockedGetOrThrow(ScriptInterruptedException.class);
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
public void alert(String title, String content) {
|
||||
VolatileBox<Void> lock = new VolatileBox<>();
|
||||
MaterialDialog.Builder builder = dialogBuilder()
|
||||
.dismissListener(lock)
|
||||
.title(title)
|
||||
.positiveText(R.string.ok);
|
||||
if (!TextUtils.isEmpty(content)) {
|
||||
builder.content(content);
|
||||
}
|
||||
builder.show();
|
||||
lock.blockedGetOrThrow(ScriptInterruptedException.class);
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
public boolean confirm(String title, String content) {
|
||||
VolatileBox<Boolean> result = new VolatileBox<>(false);
|
||||
MaterialDialog.Builder builder = dialogBuilder()
|
||||
.dismissListener(result)
|
||||
.confirm(result)
|
||||
.title(title)
|
||||
.positiveText(R.string.ok)
|
||||
.negativeText(R.string.cancel);
|
||||
if (!TextUtils.isEmpty(content)) {
|
||||
builder.content(content);
|
||||
}
|
||||
builder.show();
|
||||
return result.blockedGetOrThrow(ScriptInterruptedException.class);
|
||||
}
|
||||
|
||||
private Context getContext() {
|
||||
if (mContextWrapper == null) {
|
||||
mContextWrapper = new ContextThemeWrapper(mUiHandler.getContext(), R.style.AppTheme);
|
||||
}
|
||||
return mContextWrapper;
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
public int select(String title, String... items) {
|
||||
VolatileBox<Integer> result = new VolatileBox<>(-1);
|
||||
dialogBuilder()
|
||||
.itemsCallback(result)
|
||||
.title(title)
|
||||
.items((CharSequence[]) items)
|
||||
.show();
|
||||
return result.blockedGetOrThrow(ScriptInterruptedException.class);
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
public int singleChoice(String title, int selectedIndex, String... items) {
|
||||
VolatileBox<Integer> result = new VolatileBox<>(-1);
|
||||
dialogBuilder()
|
||||
.itemsCallbackSingleChoice(selectedIndex, result)
|
||||
.title(title)
|
||||
.positiveText(R.string.ok)
|
||||
.items((CharSequence[]) items)
|
||||
.show();
|
||||
return result.blockedGetOrThrow(ScriptInterruptedException.class);
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
public int[] multiChoice(String title, int[] indices, String... items) {
|
||||
VolatileBox<Integer[]> result = new VolatileBox<>(new Integer[0]);
|
||||
dialogBuilder()
|
||||
.itemsCallbackMultiChoice(ArrayUtils.box(indices), result)
|
||||
.title(title)
|
||||
.positiveText(R.string.ok)
|
||||
.items((CharSequence[]) items)
|
||||
.show();
|
||||
return ArrayUtils.unbox(result.blockedGetOrThrow(ScriptInterruptedException.class));
|
||||
}
|
||||
|
||||
|
||||
private BlockedMaterialDialog.Builder dialogBuilder() {
|
||||
Context context = mAppUtils.getCurrentActivity();
|
||||
if (context == null) {
|
||||
context = getContext();
|
||||
}
|
||||
return new BlockedMaterialDialog.Builder(context, mUiHandler);
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package com.stardust.scriptdroid.autojs.api;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.RequiresApi;
|
||||
|
||||
import com.stardust.app.OnActivityResultDelegate;
|
||||
import com.stardust.autojs.runtime.api.image.ScreenCaptureRequester;
|
||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/22.
|
||||
*/
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public class ScreenCaptureRequestActivity extends BaseActivity {
|
||||
|
||||
|
||||
private static ScreenCaptureRequester.Callback sCallback;
|
||||
|
||||
public static void request(Context context, ScreenCaptureRequester.Callback callback) {
|
||||
if (sCallback != null) {
|
||||
return;
|
||||
}
|
||||
sCallback = callback;
|
||||
context.startActivity(new Intent(context, ScreenCaptureRequestActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
private OnActivityResultDelegate.Mediator mOnActivityResultDelegateMediator = new OnActivityResultDelegate.Mediator();
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
ScreenCaptureRequester requester = new ScreenCaptureRequester.ActivityScreenCaptureRequester(mOnActivityResultDelegateMediator, this);
|
||||
requester.setOnActivityResultCallback(sCallback);
|
||||
requester.request();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
mOnActivityResultDelegateMediator.onActivityResult(requestCode, resultCode, data);
|
||||
finish();
|
||||
sCallback = null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,292 +0,0 @@
|
||||
package com.stardust.scriptdroid.autojs.api;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.stardust.autojs.runtime.ScriptInterruptedException;
|
||||
import com.stardust.autojs.runtime.api.AbstractShell;
|
||||
import com.stardust.lang.ThreadCompat;
|
||||
import com.stardust.pio.UncheckedIOException;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.tool.UpdateChecker;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
|
||||
import jackpal.androidterm.ShellTermSession;
|
||||
import jackpal.androidterm.emulatorview.TermSession;
|
||||
import jackpal.androidterm.util.TermSettings;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/24.
|
||||
*/
|
||||
|
||||
public class Shell extends AbstractShell implements AutoCloseable {
|
||||
|
||||
public interface Callback {
|
||||
|
||||
void onOutput(String str);
|
||||
|
||||
void onNewLine(String line);
|
||||
|
||||
void onInitialized();
|
||||
|
||||
void onInterrupted(InterruptedException e);
|
||||
}
|
||||
|
||||
public static class SimpleCallback implements Callback {
|
||||
|
||||
@Override
|
||||
public void onOutput(String str) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewLine(String str) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitialized() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInterrupted(InterruptedException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static final String TAG = "Shell";
|
||||
|
||||
private TermSession mTermSession;
|
||||
private final Object mInitLock = new Object();
|
||||
private final Object mExitLock = new Object();
|
||||
private volatile RuntimeException mInitException;
|
||||
private volatile boolean mInitialized = false;
|
||||
private volatile boolean mWaitingExit = false;
|
||||
private Callback mCallback;
|
||||
|
||||
public Shell() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Shell(boolean root) {
|
||||
super(root);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(String initialCommand) {
|
||||
init(initialCommand, App.getApp(), AutoJs.getInstance().getUiHandler());
|
||||
}
|
||||
|
||||
private void init(final String initialCommand, final Context context, Handler uiHandler) {
|
||||
uiHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TermSettings settings = new TermSettings(context.getResources(), PreferenceManager.getDefaultSharedPreferences(context));
|
||||
try {
|
||||
mTermSession = new MyShellTermSession(settings, initialCommand);
|
||||
mTermSession.initializeEmulator(40, 40);
|
||||
} catch (IOException e) {
|
||||
mInitException = new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void exec(String command) {
|
||||
ensureInitialized();
|
||||
mTermSession.write(command + "\n");
|
||||
}
|
||||
|
||||
public void setCallback(Callback callback) {
|
||||
mCallback = callback;
|
||||
}
|
||||
|
||||
public boolean isInitialized() {
|
||||
return mInitialized;
|
||||
}
|
||||
|
||||
private void ensureInitialized() {
|
||||
if (mTermSession == null) {
|
||||
checkInitException();
|
||||
waitInitialization();
|
||||
if (mTermSession == null) {
|
||||
checkInitException();
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkInitException() {
|
||||
if (mInitException != null) {
|
||||
throw mInitException;
|
||||
}
|
||||
}
|
||||
|
||||
private void waitInitialization() {
|
||||
if (mInitialized)
|
||||
throw new IllegalStateException("already initialized");
|
||||
synchronized (mInitLock) {
|
||||
try {
|
||||
mInitLock.wait();
|
||||
} catch (InterruptedException e) {
|
||||
onInterrupted(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onInterrupted(InterruptedException e) {
|
||||
if (mCallback == null) {
|
||||
exit();
|
||||
throw new ScriptInterruptedException();
|
||||
} else {
|
||||
mCallback.onInterrupted(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit() {
|
||||
mTermSession.finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exitAndWaitFor() {
|
||||
execExitAndWait();
|
||||
if (!isRoot()) {
|
||||
return;
|
||||
}
|
||||
execExitAndWait();
|
||||
}
|
||||
|
||||
private void execExitAndWait() {
|
||||
synchronized (mExitLock) {
|
||||
mWaitingExit = true;
|
||||
exec("exit");
|
||||
try {
|
||||
mExitLock.wait();
|
||||
} catch (InterruptedException e) {
|
||||
onInterrupted(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
exit();
|
||||
}
|
||||
|
||||
private class MyShellTermSession extends ShellTermSession {
|
||||
|
||||
private BufferedReader mBufferedReader;
|
||||
private OutputStream mOutputStream;
|
||||
private Thread mReadingThread;
|
||||
|
||||
public MyShellTermSession(TermSettings settings, String initialCommand) throws IOException {
|
||||
super(settings, initialCommand);
|
||||
PipedInputStream pipedInputStream = new PipedInputStream(8192);
|
||||
mBufferedReader = new BufferedReader(new InputStreamReader(pipedInputStream));
|
||||
mOutputStream = new PipedOutputStream(pipedInputStream);
|
||||
startReadingThread();
|
||||
}
|
||||
|
||||
private void startReadingThread() {
|
||||
mReadingThread = new ThreadCompat(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String line;
|
||||
try {
|
||||
while (!Thread.currentThread().isInterrupted()
|
||||
&& (line = mBufferedReader.readLine()) != null) {
|
||||
onNewLine(line);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
mReadingThread.start();
|
||||
}
|
||||
|
||||
private void onNewLine(String line) {
|
||||
Log.d(TAG, line);
|
||||
if (!mInitialized) {
|
||||
if (isRoot() && line.endsWith(" $ su")) {
|
||||
notifyInitialized();
|
||||
return;
|
||||
}
|
||||
if (!isRoot() && line.endsWith(" $ sh")) {
|
||||
notifyInitialized();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (mCallback != null) {
|
||||
mCallback.onNewLine(line);
|
||||
}
|
||||
if (mWaitingExit && line.endsWith(" exit")) {
|
||||
notifyExit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void processInput(byte[] data, int offset, int count) {
|
||||
try {
|
||||
if (mCallback != null) {
|
||||
mCallback.onOutput(new String(data, offset, count));
|
||||
}
|
||||
mOutputStream.write(data, offset, count);
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyExit() {
|
||||
synchronized (mExitLock) {
|
||||
mWaitingExit = false;
|
||||
mExitLock.notify();
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyInitialized() {
|
||||
mInitialized = true;
|
||||
synchronized (mInitLock) {
|
||||
mInitLock.notifyAll();
|
||||
}
|
||||
if (mCallback != null) {
|
||||
mCallback.onInitialized();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProcessExit() {
|
||||
super.onProcessExit();
|
||||
synchronized (mExitLock) {
|
||||
mWaitingExit = false;
|
||||
mExitLock.notify();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
super.finish();
|
||||
mReadingThread.interrupt();
|
||||
try {
|
||||
mBufferedReader.close();
|
||||
mOutputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,8 +13,8 @@ import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.external.floatingwindow.menu.HoverMenuService;
|
||||
import com.stardust.scriptdroid.external.floatingwindow.menu.layout_inspector.LayoutInspector;
|
||||
import com.stardust.scriptdroid.ui.main.MainActivity_;
|
||||
import com.stardust.util.ClipboardUtil;
|
||||
import com.stardust.scriptdroid.ui.main.MainActivity;
|
||||
import com.stardust.util.MessageEvent;
|
||||
import com.stardust.view.ViewBinder;
|
||||
import com.stardust.view.ViewBinding;
|
||||
@@ -82,7 +82,7 @@ public class MainMenuNavigatorContent implements NavigatorContent {
|
||||
|
||||
@ViewBinding.Click(R.id.open_launcher)
|
||||
private void openMainActivity() {
|
||||
App.getApp().startActivity(new Intent(App.getApp(), MainActivity.class)
|
||||
App.getApp().startActivity(new Intent(App.getApp(), MainActivity_.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY | Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
HoverMenuService.postIntent(new Intent(HoverMenuService.ACTION_COLLAPSE_MENU));
|
||||
}
|
||||
@@ -95,7 +95,6 @@ public class MainMenuNavigatorContent implements NavigatorContent {
|
||||
|
||||
@Override
|
||||
public void onShown(@NonNull Navigator navigator) {
|
||||
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
|
||||
@@ -79,7 +79,7 @@ public class RecordNavigatorContent implements NavigatorContent, Recorder.OnStat
|
||||
HoverMenuService.getEventBus().register(this);
|
||||
App.getApp().getVolumeChangeObserver().addOnVolumeChangeListener(mOnVolumeChangeListener);
|
||||
if (Pref.hasRecordTrigger()) {
|
||||
mKeyObserver = new KeyObserver();
|
||||
mKeyObserver = new KeyObserver(mContext);
|
||||
mKeyObserver.startListening();
|
||||
mKeyObserver.setKeyListener(this);
|
||||
}
|
||||
@@ -134,7 +134,7 @@ public class RecordNavigatorContent implements NavigatorContent, Recorder.OnStat
|
||||
}
|
||||
|
||||
private void startRecord() {
|
||||
mRecorder = mRecordedByRootSwitch.isChecked() ? new TouchRecorder() : AutoJs.getInstance().getAccessibilityActionRecorder();
|
||||
mRecorder = mRecordedByRootSwitch.isChecked() ? new TouchRecorder(mContext) : AutoJs.getInstance().getAccessibilityActionRecorder();
|
||||
mRecorder.setOnStateChangedListener(this);
|
||||
mRecorder.start();
|
||||
setState(Recorder.STATE_RECORDING);
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.stardust.scriptdroid.external.floatingwindow.menu.layout_inspector;
|
||||
|
||||
import android.accessibilityservice.AccessibilityService;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
import com.stardust.scriptdroid.service.AccessibilityWatchDogService;
|
||||
import com.stardust.view.accessibility.AccessibilityService;
|
||||
import com.stardust.util.UnderuseExecutors;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -19,7 +18,7 @@ public class LayoutInspector {
|
||||
private Executor mExecutor = UnderuseExecutors.getExecutor();
|
||||
|
||||
public void captureCurrentWindow() {
|
||||
AccessibilityWatchDogService service = AccessibilityWatchDogService.getInstance();
|
||||
AccessibilityService service = AccessibilityService.getInstance();
|
||||
if (service == null) {
|
||||
mCapture = null;
|
||||
} else {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.stardust.scriptdroid.external.floatingwindow.menu.record.inputevent;
|
||||
|
||||
import com.stardust.scriptdroid.autojs.api.Shell;
|
||||
import android.content.Context;
|
||||
|
||||
import com.stardust.autojs.runtime.api.Shell;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.external.floatingwindow.menu.record.Recorder;
|
||||
|
||||
/**
|
||||
@@ -13,15 +16,17 @@ public class InputEventRecorder extends Recorder.AbstractRecorder {
|
||||
private String mGetEventCommand;
|
||||
private Shell mShell;
|
||||
protected InputEventConverter mInputEventConverter;
|
||||
private Context mContext;
|
||||
|
||||
|
||||
protected InputEventRecorder(InputEventConverter inputEventConverter) {
|
||||
protected InputEventRecorder(Context context, InputEventConverter inputEventConverter) {
|
||||
mGetEventCommand = inputEventConverter.getGetEventCommand();
|
||||
mInputEventConverter = inputEventConverter;
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public void listen() {
|
||||
mShell = new Shell(true);
|
||||
mShell = new Shell(mContext, true);
|
||||
mShell.setCallback(new Shell.SimpleCallback() {
|
||||
@Override
|
||||
public void onNewLine(String str) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.stardust.scriptdroid.external.floatingwindow.menu.record.inputevent;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
/**
|
||||
@@ -19,14 +20,14 @@ public class KeyObserver {
|
||||
private InputEventRecorder mObserver;
|
||||
private KeyListener mKeyListener;
|
||||
|
||||
public KeyObserver(){
|
||||
mObserver = new InputEventRecorder(new InputEventConverter() {
|
||||
public KeyObserver(Context context) {
|
||||
mObserver = new InputEventRecorder(context, new InputEventConverter() {
|
||||
@Override
|
||||
public void convertEvent(@NonNull Event event) {
|
||||
if(event.value.equalsIgnoreCase("UP")){
|
||||
if (event.value.equalsIgnoreCase("UP")) {
|
||||
notifyKeyUp(event.code);
|
||||
}
|
||||
if(event.value.equalsIgnoreCase("DOWN")){
|
||||
if (event.value.equalsIgnoreCase("DOWN")) {
|
||||
notifyKeyDown(event.code);
|
||||
}
|
||||
}
|
||||
@@ -42,23 +43,23 @@ public class KeyObserver {
|
||||
mKeyListener = keyListener;
|
||||
}
|
||||
|
||||
public void startListening(){
|
||||
public void startListening() {
|
||||
mObserver.listen();
|
||||
mObserver.start();
|
||||
}
|
||||
|
||||
public void stopListening(){
|
||||
public void stopListening() {
|
||||
mObserver.stopImpl();
|
||||
}
|
||||
|
||||
private void notifyKeyDown(String keyName) {
|
||||
if(mKeyListener != null){
|
||||
if (mKeyListener != null) {
|
||||
mKeyListener.onKeyDown(keyName);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyKeyUp(String keyName) {
|
||||
if(mKeyListener != null){
|
||||
if (mKeyListener != null) {
|
||||
mKeyListener.onKeyUp(keyName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package com.stardust.scriptdroid.external.floatingwindow.menu.record.inputevent;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/3/16.
|
||||
*/
|
||||
|
||||
public class TouchRecorder extends InputEventRecorder {
|
||||
|
||||
public TouchRecorder() {
|
||||
super(new InputEventToSendEventJsConverter());
|
||||
public TouchRecorder(Context context) {
|
||||
super(context, new InputEventToSendEventJsConverter());
|
||||
listen();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
package com.stardust.scriptdroid.service;
|
||||
|
||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
import com.nickandjerry.dynamiclayoutinflator.lib.DynamicLayoutInflator;
|
||||
import com.stardust.scriptdroid.tool.AccessibilityServiceTool;
|
||||
import com.stardust.view.accessibility.AccessibilityDelegate;
|
||||
import com.stardust.view.accessibility.AccessibilityService;
|
||||
import com.stardust.view.accessibility.AccessibilityServiceUtils;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/2/14.
|
||||
*/
|
||||
|
||||
public class AccessibilityWatchDogService extends AccessibilityService {
|
||||
|
||||
private static final String TAG = "AccessibilityWatchDog";
|
||||
|
||||
private static final SortedMap<Integer, AccessibilityDelegate> mDelegates = new TreeMap<>();
|
||||
private static final Object LOCK = new Object();
|
||||
private static AccessibilityWatchDogService instance;
|
||||
private static boolean containsAllEventTypes = false;
|
||||
private static final Set<Integer> eventTypes = new HashSet<>();
|
||||
|
||||
public static void addDelegate(int uniquePriority, AccessibilityDelegate delegate) {
|
||||
mDelegates.put(uniquePriority, delegate);
|
||||
Set<Integer> set = delegate.getEventTypes();
|
||||
if (set == null)
|
||||
containsAllEventTypes = true;
|
||||
else
|
||||
eventTypes.addAll(set);
|
||||
}
|
||||
|
||||
public static boolean isEnable(Context context) {
|
||||
return AccessibilityServiceUtils.isAccessibilityServiceEnabled(context, AccessibilityWatchDogService.class);
|
||||
}
|
||||
|
||||
public static AccessibilityWatchDogService getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccessibilityEvent(final AccessibilityEvent event) {
|
||||
Log.v(TAG, "onAccessibilityEvent: " + event);
|
||||
super.onAccessibilityEvent(event);
|
||||
if (!containsAllEventTypes && !eventTypes.contains(event.getEventType()))
|
||||
return;
|
||||
for (Map.Entry<Integer, AccessibilityDelegate> entry : mDelegates.entrySet()) {
|
||||
AccessibilityDelegate delegate = entry.getValue();
|
||||
Set<Integer> types = delegate.getEventTypes();
|
||||
if (types != null && !delegate.getEventTypes().contains(event.getEventType()))
|
||||
continue;
|
||||
long start = System.currentTimeMillis();
|
||||
if (delegate.onAccessibilityEvent(AccessibilityWatchDogService.this, event))
|
||||
break;
|
||||
Log.v(TAG, "millis: " + (System.currentTimeMillis() - start) + " delegate: " + entry.getValue().getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onKeyEvent(KeyEvent event) {
|
||||
Log.v(TAG, "onKeyEvent: " + event);
|
||||
return super.onKeyEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onGesture(int gestureId) {
|
||||
Log.v(TAG, "onGesture: " + gestureId);
|
||||
return super.onGesture(gestureId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInterrupt() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
instance = null;
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onServiceConnected() {
|
||||
Log.v(TAG, "onServiceConnected: " + getServiceInfo().toString());
|
||||
instance = this;
|
||||
super.onServiceConnected();
|
||||
synchronized (LOCK) {
|
||||
LOCK.notifyAll();
|
||||
}
|
||||
// FIXME: 2017/2/12 有时在无障碍中开启服务后这里不会调用服务也不会运行,安卓的BUG???
|
||||
}
|
||||
|
||||
public static void disable() {
|
||||
if (instance != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
instance.disableSelf();
|
||||
} else {
|
||||
AccessibilityServiceTool.goToAccessibilitySetting();
|
||||
}
|
||||
}
|
||||
|
||||
public static void waitForEnabled(long timeOut) {
|
||||
synchronized (LOCK) {
|
||||
try {
|
||||
LOCK.wait(timeOut);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
package com.stardust.scriptdroid.tool;
|
||||
|
||||
import android.accessibilityservice.AccessibilityService;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.scriptdroid.Pref;
|
||||
import com.stardust.scriptdroid.service.AccessibilityWatchDogService;
|
||||
import com.stardust.view.accessibility.AccessibilityService;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.autojs.runtime.api.ProcessShell;
|
||||
@@ -23,7 +22,7 @@ public class AccessibilityServiceTool {
|
||||
|
||||
public static void enableAccessibilityService() {
|
||||
if (Pref.enableAccessibilityServiceByRoot()) {
|
||||
if (!enableAccessibilityServiceByRoot(AccessibilityWatchDogService.class)) {
|
||||
if (!enableAccessibilityServiceByRoot(AccessibilityService.class)) {
|
||||
goToAccessibilitySetting();
|
||||
}
|
||||
} else {
|
||||
@@ -53,22 +52,22 @@ public class AccessibilityServiceTool {
|
||||
"settings put secure enabled_accessibility_services $enabled\n" +
|
||||
"fi";
|
||||
|
||||
public static boolean enableAccessibilityServiceByRoot(Class<? extends AccessibilityService> accessibilityService) {
|
||||
public static boolean enableAccessibilityServiceByRoot(Class<? extends android.accessibilityservice.AccessibilityService> accessibilityService) {
|
||||
String serviceName = App.getApp().getPackageName() + "/" + accessibilityService.getName();
|
||||
return TextUtils.isEmpty(ProcessShell.execCommand(String.format(Locale.getDefault(), cmd, serviceName), true).error);
|
||||
}
|
||||
|
||||
public static boolean enableAccessibilityServiceByRootAndWaitFor(long timeOut) {
|
||||
if (enableAccessibilityServiceByRoot(AccessibilityWatchDogService.class)) {
|
||||
AccessibilityWatchDogService.waitForEnabled(timeOut);
|
||||
if (enableAccessibilityServiceByRoot(AccessibilityService.class)) {
|
||||
AccessibilityService.waitForEnabled(timeOut);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void enableAccessibilityServiceByRootIfNeeded() {
|
||||
if (AccessibilityWatchDogService.getInstance() == null)
|
||||
if (AccessibilityService.getInstance() == null)
|
||||
if (Pref.enableAccessibilityServiceByRoot()) {
|
||||
AccessibilityServiceTool.enableAccessibilityServiceByRoot(AccessibilityWatchDogService.class);
|
||||
AccessibilityServiceTool.enableAccessibilityServiceByRoot(AccessibilityService.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,143 +0,0 @@
|
||||
package com.stardust.scriptdroid.ui.console;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.stardust.enhancedfloaty.FloatyService;
|
||||
import com.stardust.enhancedfloaty.ResizableExpandableFloaty;
|
||||
import com.stardust.enhancedfloaty.ResizableExpandableFloatyWindow;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.util.ViewUtil;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/20.
|
||||
*/
|
||||
|
||||
public class ConsoleFloaty extends ResizableExpandableFloaty.AbstractResizableExpandableFloaty {
|
||||
|
||||
private ContextWrapper mContextWrapper;
|
||||
private View mResizer, mMoveCursor;
|
||||
private TextView mTitleView;
|
||||
private StardustConsole mConsole;
|
||||
private CharSequence mTitle;
|
||||
|
||||
public ConsoleFloaty(StardustConsole console) {
|
||||
mConsole = console;
|
||||
setShouldRequestFocusWhenExpand(false);
|
||||
setInitialX(100);
|
||||
setInitialY(1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View inflateCollapsedView(FloatyService service, final ResizableExpandableFloatyWindow window) {
|
||||
ensureContextWrapper(service);
|
||||
View view = View.inflate(mContextWrapper, R.layout.floating_window_collapse, null);
|
||||
view.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
window.expand();
|
||||
}
|
||||
});
|
||||
return view;
|
||||
}
|
||||
|
||||
private void ensureContextWrapper(Context context) {
|
||||
if (mContextWrapper == null) {
|
||||
mContextWrapper = new ContextThemeWrapper(context, R.style.AppTheme);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View inflateExpandedView(FloatyService service, ResizableExpandableFloatyWindow window) {
|
||||
ensureContextWrapper(service);
|
||||
View view = View.inflate(mContextWrapper, R.layout.floating_console_expand, null);
|
||||
setListeners(view, window);
|
||||
setUpConsole(view, window);
|
||||
setInitialMeasure(view);
|
||||
return view;
|
||||
}
|
||||
|
||||
private void setInitialMeasure(final View view) {
|
||||
view.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ViewUtil.setViewMeasure(view, 800, 800);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initConsoleTitle(View view) {
|
||||
mTitleView = (TextView) view.findViewById(R.id.title);
|
||||
if (mTitle != null) {
|
||||
mTitleView.setText(mTitle);
|
||||
}
|
||||
}
|
||||
|
||||
private void setListeners(final View view, final ResizableExpandableFloatyWindow window) {
|
||||
setWindowOperationIconListeners(view, window);
|
||||
}
|
||||
|
||||
private void setUpConsole(View view, ResizableExpandableFloatyWindow window) {
|
||||
ConsoleView consoleView = (ConsoleView) view.findViewById(R.id.console);
|
||||
consoleView.setConsole(mConsole);
|
||||
consoleView.setWindow(window);
|
||||
initConsoleTitle(view);
|
||||
}
|
||||
|
||||
private void setWindowOperationIconListeners(View view, final ResizableExpandableFloatyWindow window) {
|
||||
view.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
window.close();
|
||||
}
|
||||
});
|
||||
view.findViewById(R.id.move_or_resize).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mMoveCursor.getVisibility() == View.VISIBLE) {
|
||||
mMoveCursor.setVisibility(View.GONE);
|
||||
mResizer.setVisibility(View.GONE);
|
||||
} else {
|
||||
mMoveCursor.setVisibility(View.VISIBLE);
|
||||
mResizer.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
});
|
||||
view.findViewById(R.id.minimize).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
window.collapse();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View getResizerView(View expandedView) {
|
||||
mResizer = expandedView.findViewById(R.id.resizer);
|
||||
return mResizer;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View getMoveCursorView(View expandedView) {
|
||||
mMoveCursor = expandedView.findViewById(R.id.move_cursor);
|
||||
return mMoveCursor;
|
||||
}
|
||||
|
||||
public void setTitle(final CharSequence title) {
|
||||
mTitle = title;
|
||||
if (mTitleView != null) {
|
||||
mTitleView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mTitleView.setText(title);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,178 +0,0 @@
|
||||
package com.stardust.scriptdroid.ui.console;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.method.ScrollingMovementMethod;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.stardust.enhancedfloaty.ResizableExpandableFloatyWindow;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.util.SparseArrayEntries;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/2.
|
||||
*/
|
||||
|
||||
public class ConsoleView extends FrameLayout implements StardustConsole.LogListener {
|
||||
|
||||
private static final SparseArray<Integer> COLORS = new SparseArrayEntries<Integer>()
|
||||
.entry(Log.VERBOSE, 0xdfc0c0c0)
|
||||
.entry(Log.DEBUG, 0xdfffffff)
|
||||
.entry(Log.INFO, 0xff64dd17)
|
||||
.entry(Log.WARN, 0xff2962ff)
|
||||
.entry(Log.ERROR, 0xffd50000)
|
||||
.entry(Log.ASSERT, 0xffff534e)
|
||||
.sparseArray();
|
||||
|
||||
private StardustConsole mConsole;
|
||||
private TextView mTextView;
|
||||
private EditText mEditText;
|
||||
private ResizableExpandableFloatyWindow mWindow;
|
||||
private LinearLayout mInputContainer;
|
||||
private ScrollView mContentContainer;
|
||||
|
||||
public ConsoleView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public ConsoleView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public ConsoleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
inflate(getContext(), R.layout.console_view, this);
|
||||
mTextView = (TextView) findViewById(R.id.content);
|
||||
mTextView.setMovementMethod(new ScrollingMovementMethod());
|
||||
mContentContainer = (ScrollView) findViewById(R.id.content_container);
|
||||
initEditText();
|
||||
initSubmitButton();
|
||||
}
|
||||
|
||||
private void initSubmitButton() {
|
||||
final Button submit = (Button) findViewById(R.id.submit);
|
||||
submit.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
CharSequence input = mEditText.getText();
|
||||
submitInput(input);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void submitInput(CharSequence input) {
|
||||
if (android.text.TextUtils.isEmpty(input)) {
|
||||
return;
|
||||
}
|
||||
if (mConsole.submitInput(input)) {
|
||||
mEditText.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
private void initEditText() {
|
||||
mEditText = (EditText) findViewById(R.id.input);
|
||||
mEditText.setFocusableInTouchMode(true);
|
||||
mInputContainer = (LinearLayout) findViewById(R.id.input_container);
|
||||
OnClickListener listener = new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mWindow != null) {
|
||||
mWindow.requestWindowFocus();
|
||||
mEditText.requestFocus();
|
||||
}
|
||||
}
|
||||
};
|
||||
mEditText.setOnClickListener(listener);
|
||||
mInputContainer.setOnClickListener(listener);
|
||||
}
|
||||
|
||||
public void setConsole(StardustConsole console) {
|
||||
mConsole = console;
|
||||
mConsole.setConsoleView(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewLog(StardustConsole.Log log) {
|
||||
log(log.level, log.content);
|
||||
}
|
||||
|
||||
private void log(int level, CharSequence log) {
|
||||
int color = getColorForLevel(level);
|
||||
final Spannable spannable = buildColorSpannable(log, color);
|
||||
post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mTextView.append(spannable);
|
||||
mContentContainer.fullScroll(View.FOCUS_DOWN);
|
||||
mEditText.requestFocus();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private Spannable buildColorSpannable(CharSequence log, int color) {
|
||||
Spannable spannable = new SpannableString(log);
|
||||
spannable.setSpan(new ForegroundColorSpan(color), 0, log.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
return spannable;
|
||||
}
|
||||
|
||||
private int getColorForLevel(int level) {
|
||||
return COLORS.get(level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLogClear() {
|
||||
mTextView.setText("");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onWindowVisibilityChanged(int visibility) {
|
||||
super.onWindowVisibilityChanged(visibility);
|
||||
if (visibility == VISIBLE) {
|
||||
refreshLog();
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshLog() {
|
||||
if (mConsole != null) {
|
||||
mTextView.setText("");
|
||||
for (StardustConsole.Log log : mConsole.getLogs()) {
|
||||
onNewLog(log);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setWindow(ResizableExpandableFloatyWindow window) {
|
||||
mWindow = window;
|
||||
}
|
||||
|
||||
public void showEditText() {
|
||||
post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mWindow.requestWindowFocus();
|
||||
mInputContainer.setVisibility(VISIBLE);
|
||||
mEditText.requestFocus();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,7 @@ public class JraskaConsole extends AbstractConsole {
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
App.getApp().startActivity(new Intent(App.getApp(), LogActivity.class)
|
||||
App.getApp().startActivity(new Intent(App.getApp(), LogActivity_.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
|
||||
@@ -13,20 +13,17 @@ import com.stardust.scriptdroid.ui.BaseActivity;
|
||||
import com.jraska.console.Console;
|
||||
import com.stardust.scriptdroid.R;
|
||||
|
||||
import org.androidannotations.annotations.AfterViews;
|
||||
import org.androidannotations.annotations.EActivity;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/2/12.
|
||||
*/
|
||||
|
||||
@EActivity(R.layout.activity_console)
|
||||
public class LogActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setUpUI();
|
||||
}
|
||||
|
||||
private void setUpUI() {
|
||||
setContentView(R.layout.activity_console);
|
||||
@AfterViews
|
||||
void setUpUI() {
|
||||
setToolbarAsBack(getString(R.string.text_log));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,185 +0,0 @@
|
||||
package com.stardust.scriptdroid.ui.console;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.stardust.autojs.runtime.ScriptInterface;
|
||||
import com.stardust.autojs.runtime.ScriptInterruptedException;
|
||||
import com.stardust.autojs.runtime.api.AbstractConsole;
|
||||
import com.stardust.autojs.runtime.api.Console;
|
||||
import com.stardust.enhancedfloaty.FloatyService;
|
||||
import com.stardust.enhancedfloaty.ResizableExpandableFloatyWindow;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.external.floatingwindow.FloatingWindowManger;
|
||||
import com.stardust.util.UiHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/2.
|
||||
*/
|
||||
|
||||
public class StardustConsole extends AbstractConsole {
|
||||
|
||||
public static class Log {
|
||||
|
||||
public int level;
|
||||
public CharSequence content;
|
||||
|
||||
public Log(int level, CharSequence content) {
|
||||
this.level = level;
|
||||
this.content = content;
|
||||
}
|
||||
}
|
||||
|
||||
public interface LogListener {
|
||||
void onNewLog(Log log);
|
||||
|
||||
void onLogClear();
|
||||
}
|
||||
|
||||
private final Console GLOBAL_CONSOLE = AutoJs.getInstance().getScriptEngineService().getGlobalConsole();
|
||||
private List<Log> mLogs = new ArrayList<>();
|
||||
private ResizableExpandableFloatyWindow mFloatyWindow;
|
||||
private ConsoleFloaty mConsoleFloaty;
|
||||
private LogListener mLogListener;
|
||||
private UiHandler mUiHandler;
|
||||
private BlockingQueue<String> mInput = new ArrayBlockingQueue<>(1);
|
||||
private ConsoleView mConsoleView;
|
||||
private volatile boolean mShown = false;
|
||||
|
||||
public StardustConsole(UiHandler uiHandler) {
|
||||
mUiHandler = uiHandler;
|
||||
mConsoleFloaty = new ConsoleFloaty(this);
|
||||
mFloatyWindow = new ResizableExpandableFloatyWindow(mConsoleFloaty);
|
||||
}
|
||||
|
||||
public void setConsoleView(ConsoleView consoleView) {
|
||||
mConsoleView = consoleView;
|
||||
setLogListener(consoleView);
|
||||
synchronized (this) {
|
||||
this.notify();
|
||||
}
|
||||
}
|
||||
|
||||
public void setLogListener(LogListener logListener) {
|
||||
mLogListener = logListener;
|
||||
}
|
||||
|
||||
public List<Log> getLogs() {
|
||||
return mLogs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(int level, CharSequence charSequence) {
|
||||
Log log = new Log(level, charSequence + "\n");
|
||||
mLogs.add(log);
|
||||
GLOBAL_CONSOLE.println(level, charSequence);
|
||||
if (mLogListener != null) {
|
||||
mLogListener.onNewLog(log);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void write(int level, CharSequence charSequence) {
|
||||
Log log = new Log(level, charSequence);
|
||||
mLogs.add(log);
|
||||
GLOBAL_CONSOLE.print(level, charSequence);
|
||||
if (mLogListener != null) {
|
||||
mLogListener.onNewLog(log);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
mLogs.clear();
|
||||
if (mLogListener != null) {
|
||||
mLogListener.onLogClear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
if (!FloatingWindowManger.hasFloatingWindowPermission(mUiHandler.getContext())) {
|
||||
FloatingWindowManger.goToFloatingWindowPermissionSetting();
|
||||
mUiHandler.toast(R.string.text_no_floating_window_permission);
|
||||
}
|
||||
startFloatyService();
|
||||
mUiHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
FloatyService.addWindow(mFloatyWindow);
|
||||
} catch (WindowManager.BadTokenException e) {
|
||||
e.printStackTrace();
|
||||
mUiHandler.toast(R.string.text_no_floating_window_permission);
|
||||
}
|
||||
}
|
||||
});
|
||||
mShown = true;
|
||||
}
|
||||
|
||||
private void startFloatyService() {
|
||||
Context context = mUiHandler.getContext();
|
||||
context.startService(new Intent(context, FloatyService.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() {
|
||||
try {
|
||||
mFloatyWindow.close();
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
|
||||
}
|
||||
mShown = false;
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
public String rawInput() {
|
||||
if (mConsoleView == null) {
|
||||
if (!mShown) {
|
||||
show();
|
||||
}
|
||||
waitConsoleView();
|
||||
}
|
||||
mConsoleView.showEditText();
|
||||
try {
|
||||
return mInput.take();
|
||||
} catch (InterruptedException e) {
|
||||
throw new ScriptInterruptedException();
|
||||
}
|
||||
}
|
||||
|
||||
private void waitConsoleView() {
|
||||
synchronized (this) {
|
||||
try {
|
||||
this.wait();
|
||||
} catch (InterruptedException e) {
|
||||
throw new ScriptInterruptedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
public String rawInput(Object data, Object... param) {
|
||||
log(data, param);
|
||||
return rawInput();
|
||||
}
|
||||
|
||||
boolean submitInput(@NonNull CharSequence input) {
|
||||
return mInput.offer(input.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(CharSequence title) {
|
||||
mConsoleFloaty.setTitle(title);
|
||||
}
|
||||
}
|
||||
@@ -39,16 +39,19 @@ import com.stardust.scriptdroid.ui.help.HelpCatalogueActivity;
|
||||
import com.stardust.theme.ThemeColorManager;
|
||||
import com.stardust.theme.dialog.ThemeColorMaterialDialogBuilder;
|
||||
import com.stardust.util.SparseArrayEntries;
|
||||
import com.stardust.view.ViewBinder;
|
||||
import com.stardust.view.ViewBinding;
|
||||
import com.stardust.widget.ToolbarMenuItem;
|
||||
|
||||
import org.androidannotations.annotations.AfterViews;
|
||||
import org.androidannotations.annotations.Click;
|
||||
import org.androidannotations.annotations.EActivity;
|
||||
import org.androidannotations.annotations.ViewById;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/1/29.
|
||||
*/
|
||||
|
||||
@EActivity(R.layout.activity_edit)
|
||||
public class EditActivity extends Editor920Activity implements OnActivityResultDelegate.DelegateHost {
|
||||
|
||||
|
||||
@@ -81,26 +84,28 @@ public class EditActivity extends Editor920Activity implements OnActivityResultD
|
||||
}
|
||||
|
||||
|
||||
public static final String EXTRA_CONTENT = "Still Love Eating 17.4.5";
|
||||
public static final String EXTRA_PATH = "Still Love Eating 17.4.5";
|
||||
private static final String EXTRA_NAME = "Still love you 17.6.29 But....(ಥ_ಥ)";
|
||||
|
||||
public static void editFile(Context context, String path) {
|
||||
editFile(context, null, path);
|
||||
}
|
||||
|
||||
public static void editFile(Context context, String name, String path) {
|
||||
context.startActivity(new Intent(context, EditActivity.class)
|
||||
context.startActivity(new Intent(context, EditActivity_.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra("path", path)
|
||||
.putExtra("name", name));
|
||||
.putExtra(EXTRA_PATH, path)
|
||||
.putExtra(EXTRA_NAME, name));
|
||||
}
|
||||
|
||||
public static void editFile(Context context, ScriptFile file) {
|
||||
editFile(context, file.getSimplifiedName(), file.getPath());
|
||||
}
|
||||
|
||||
@ViewById(R.id.content_view)
|
||||
View mView;
|
||||
private String mName;
|
||||
private File mFile;
|
||||
private View mView;
|
||||
private EditorDelegate mEditorDelegate;
|
||||
private SparseArray<ToolbarMenuItem> mMenuMap;
|
||||
private boolean mReadOnly = false;
|
||||
@@ -124,17 +129,21 @@ public class EditActivity extends Editor920Activity implements OnActivityResultD
|
||||
public void onCreate(Bundle b) {
|
||||
super.onCreate(b);
|
||||
setTheme(R.style.EditorTheme);
|
||||
mView = View.inflate(this, R.layout.activity_edit, null);
|
||||
setContentView(mView);
|
||||
handleIntent(getIntent());
|
||||
setUpUI();
|
||||
setUpEditor();
|
||||
registerReceiver(mOnRunFinishedReceiver, new IntentFilter(Scripts.ACTION_ON_EXECUTION_FINISHED));
|
||||
}
|
||||
|
||||
@AfterViews
|
||||
void setUpViews() {
|
||||
ThemeColorManager.addActivityStatusBar(this);
|
||||
setUpToolbar();
|
||||
initMenuItem();
|
||||
setUpEditor();
|
||||
}
|
||||
|
||||
private void handleIntent(Intent intent) {
|
||||
String path = intent.getStringExtra("path");
|
||||
mName = intent.getStringExtra("name");
|
||||
String path = intent.getStringExtra(EXTRA_PATH);
|
||||
mName = intent.getStringExtra(EXTRA_NAME);
|
||||
mReadOnly = intent.getBooleanExtra("readOnly", false);
|
||||
boolean saveEnabled = intent.getBooleanExtra("saveEnabled", true);
|
||||
if (mReadOnly || !saveEnabled) {
|
||||
@@ -152,13 +161,6 @@ public class EditActivity extends Editor920Activity implements OnActivityResultD
|
||||
}
|
||||
}
|
||||
|
||||
private void setUpUI() {
|
||||
ThemeColorManager.addActivityStatusBar(this);
|
||||
setUpToolbar();
|
||||
initMenuItem();
|
||||
ViewBinder.bind(this);
|
||||
}
|
||||
|
||||
private void setUpEditor() {
|
||||
final EditorView editorView = (EditorView) findViewById(R.id.editor);
|
||||
mEditorDelegate.setEditorView(editorView);
|
||||
@@ -184,8 +186,8 @@ public class EditActivity extends Editor920Activity implements OnActivityResultD
|
||||
BaseActivity.setToolbarAsBack(this, R.id.toolbar, mName);
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.run)
|
||||
private void runAndSaveFileIFNeeded() {
|
||||
@Click(R.id.run)
|
||||
void runAndSaveFileIFNeeded() {
|
||||
if (!mReadOnly && mEditorDelegate.isChanged()) {
|
||||
saveFile(false, new SaveListener() {
|
||||
@Override
|
||||
@@ -213,21 +215,21 @@ public class EditActivity extends Editor920Activity implements OnActivityResultD
|
||||
}
|
||||
|
||||
|
||||
@ViewBinding.Click(R.id.undo)
|
||||
private void undo() {
|
||||
@Click(R.id.undo)
|
||||
void undo() {
|
||||
Command command = new Command(Command.CommandEnum.UNDO);
|
||||
mEditorDelegate.doCommand(command);
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.redo)
|
||||
private void redo() {
|
||||
@Click(R.id.redo)
|
||||
void redo() {
|
||||
Command command = new Command(Command.CommandEnum.REDO);
|
||||
mEditorDelegate.doCommand(command);
|
||||
}
|
||||
|
||||
|
||||
@ViewBinding.Click(R.id.save)
|
||||
private void saveFile() {
|
||||
@Click(R.id.save)
|
||||
void saveFile() {
|
||||
saveFile(false, null);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.stardust.app.Fragment;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.external.floatingwindow.FloatingWindowManger;
|
||||
import com.stardust.scriptdroid.external.floatingwindow.menu.HoverMenuService;
|
||||
import com.stardust.view.ViewBinding;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.ui.console.LogActivity;
|
||||
import com.stardust.scriptdroid.ui.console.LogActivity_;
|
||||
import com.stardust.scriptdroid.ui.help.HelpCatalogueActivity;
|
||||
import com.stardust.view.ViewBinder;
|
||||
import com.stardust.view.ViewBinding;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
@@ -92,7 +92,7 @@ public class EditSideMenuFragment extends Fragment {
|
||||
|
||||
@ViewBinding.Click(R.id.console)
|
||||
private void startConsoleActivity() {
|
||||
startActivity(new Intent(getContext(), LogActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
startActivity(new Intent(getContext(), LogActivity_.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
@ViewBinding.Check(R.id.sw_floating_window)
|
||||
|
||||
@@ -38,7 +38,7 @@ import com.stardust.scriptdroid.external.floatingwindow.FloatingWindowManger;
|
||||
import com.stardust.scriptdroid.script.ScriptFile;
|
||||
import com.stardust.scriptdroid.script.StorageScriptProvider;
|
||||
import com.stardust.scriptdroid.script.sample.Sample;
|
||||
import com.stardust.scriptdroid.service.AccessibilityWatchDogService;
|
||||
import com.stardust.view.accessibility.AccessibilityService;
|
||||
import com.stardust.scriptdroid.tool.AccessibilityServiceTool;
|
||||
import com.stardust.scriptdroid.tool.DrawableSaver;
|
||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||
@@ -46,25 +46,27 @@ import com.stardust.scriptdroid.ui.main.sample_list.SampleScriptListFragment;
|
||||
import com.stardust.scriptdroid.ui.main.script_list.MyScriptListFragment;
|
||||
import com.stardust.scriptdroid.ui.main.script_list.ScriptFileChooserDialogBuilder;
|
||||
import com.stardust.scriptdroid.ui.main.task.TaskManagerFragment;
|
||||
import com.stardust.scriptdroid.ui.settings.SettingsActivity;
|
||||
import com.stardust.scriptdroid.ui.settings.SettingsActivity_;
|
||||
import com.stardust.scriptdroid.ui.update.VersionGuard;
|
||||
import com.stardust.theme.dialog.ThemeColorMaterialDialogBuilder;
|
||||
import com.stardust.util.BackPressedHandler;
|
||||
import com.stardust.util.Callback;
|
||||
import com.stardust.util.MessageEvent;
|
||||
import com.stardust.view.DrawerAutoClose;
|
||||
import com.stardust.view.ViewBinder;
|
||||
import com.stardust.view.ViewBinding;
|
||||
import com.stardust.view.accessibility.AccessibilityServiceUtils;
|
||||
import com.stardust.widget.CommonMarkdownView;
|
||||
import com.stardust.widget.SlidingUpPanel;
|
||||
|
||||
import org.androidannotations.annotations.AfterViews;
|
||||
import org.androidannotations.annotations.Click;
|
||||
import org.androidannotations.annotations.EActivity;
|
||||
import org.androidannotations.annotations.ViewById;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@EActivity(R.layout.activity_main)
|
||||
public class MainActivity extends BaseActivity implements OnActivityResultDelegate.DelegateHost {
|
||||
|
||||
public static final String MESSAGE_CLEAR_BACKGROUND_SETTINGS = "MESSAGE_CLEAR_BACKGROUND_SETTINGS";
|
||||
@@ -80,21 +82,22 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
private static final String ARGUMENT_SAMPLE = "Take a chance on me...ok...?";
|
||||
|
||||
|
||||
private DrawerLayout mDrawerLayout;
|
||||
@ViewBinding.Id(R.id.bottom_menu)
|
||||
private SlidingUpPanel mAddBottomMenuPanel;
|
||||
@ViewById(R.id.drawer_layout)
|
||||
DrawerLayout mDrawerLayout;
|
||||
@ViewById(R.id.bottom_menu)
|
||||
SlidingUpPanel mAddBottomMenuPanel;
|
||||
@ViewById(R.id.viewpager)
|
||||
ViewPager mViewPager;
|
||||
private FragmentPagerAdapterBuilder.StoredFragmentPagerAdapter mPagerAdapter;
|
||||
|
||||
private OnActivityResultDelegate.Mediator mActivityResultMediator = new OnActivityResultDelegate.Mediator();
|
||||
private DrawableSaver mDrawerHeaderBackgroundSaver, mAppbarBackgroundSaver;
|
||||
private VersionGuard mVersionGuard;
|
||||
private Intent mIntentToHandle;
|
||||
private ViewPager mViewPager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setUpUI();
|
||||
checkPermissions();
|
||||
registerBackPressHandlers();
|
||||
mIntentToHandle = getIntent();
|
||||
@@ -103,9 +106,14 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
showAnnunciationIfNeeded();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
@AfterViews
|
||||
void setUpViews() {
|
||||
setUpToolbar();
|
||||
setUpTabViewPager();
|
||||
setUpDrawerHeader();
|
||||
setUpFragment();
|
||||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
||||
|
||||
}
|
||||
|
||||
private void showAnnunciationIfNeeded() {
|
||||
@@ -143,7 +151,7 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
}
|
||||
|
||||
private void showAccessibilitySettingPromptIfDisabled() {
|
||||
if (!AccessibilityServiceUtils.isAccessibilityServiceEnabled(this, AccessibilityWatchDogService.class)) {
|
||||
if (!AccessibilityServiceUtils.isAccessibilityServiceEnabled(this, AccessibilityService.class)) {
|
||||
new NotAskAgainDialog.Builder(this, "Eating...love you...miss you...17.4.12")
|
||||
.title(R.string.text_need_to_enable_accessibility_service)
|
||||
.content(R.string.explain_accessibility_permission)
|
||||
@@ -158,17 +166,6 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
}
|
||||
}
|
||||
|
||||
private void setUpUI() {
|
||||
mDrawerLayout = (DrawerLayout) View.inflate(this, R.layout.activity_main, null);
|
||||
setContentView(mDrawerLayout);
|
||||
setUpToolbar();
|
||||
setUpTabViewPager();
|
||||
setUpDrawerHeader();
|
||||
setUpFragment();
|
||||
ViewBinder.bind(this);
|
||||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
||||
}
|
||||
|
||||
private void setUpFragment() {
|
||||
SideMenuFragment.setFragment(this, R.id.fragment_slide_menu);
|
||||
}
|
||||
@@ -193,7 +190,6 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
|
||||
private void setUpTabViewPager() {
|
||||
TabLayout tabLayout = $(R.id.tab);
|
||||
mViewPager = $(R.id.viewpager);
|
||||
mPagerAdapter = new FragmentPagerAdapterBuilder(this)
|
||||
.add(new MyScriptListFragment(), R.string.text_my_script)
|
||||
.add(new SampleScriptListFragment(), R.string.text_sample_script)
|
||||
@@ -212,13 +208,13 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
});
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.add)
|
||||
private void showAddFilePanel() {
|
||||
@Click(R.id.add)
|
||||
void showAddFilePanel() {
|
||||
mAddBottomMenuPanel.show();
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.create_new_file)
|
||||
private void createScriptFile() {
|
||||
@Click(R.id.create_new_file)
|
||||
void createScriptFile() {
|
||||
doWithMyScriptListFragment(new Callback<MyScriptListFragment>() {
|
||||
@Override
|
||||
public void call(MyScriptListFragment myScriptListFragment) {
|
||||
@@ -227,8 +223,8 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
});
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.create_new_directory)
|
||||
private void createNewDirectory() {
|
||||
@Click(R.id.create_new_directory)
|
||||
void createNewDirectory() {
|
||||
doWithMyScriptListFragment(new Callback<MyScriptListFragment>() {
|
||||
@Override
|
||||
public void call(MyScriptListFragment myScriptListFragment) {
|
||||
@@ -237,8 +233,8 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
});
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.import_from_file)
|
||||
private void showFileChooser() {
|
||||
@Click(R.id.import_from_file)
|
||||
void showFileChooser() {
|
||||
final StorageScriptProvider provider = StorageScriptProvider.getExternalStorageProvider();
|
||||
new ScriptFileChooserDialogBuilder(this)
|
||||
.scriptProvider(provider)
|
||||
@@ -272,12 +268,12 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
.show();
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.setting)
|
||||
private void startSettingActivity() {
|
||||
startActivity(new Intent(this, SettingsActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
@Click(R.id.setting)
|
||||
void startSettingActivity() {
|
||||
startActivity(new Intent(this, SettingsActivity_.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.exit)
|
||||
@Click(R.id.exit)
|
||||
public void exitCompletely() {
|
||||
FloatingWindowManger.hideHoverMenu();
|
||||
stopService(new Intent(this, FloatyService.class));
|
||||
@@ -285,7 +281,7 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
finish();
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.drawer_header_img)
|
||||
@Click(R.id.drawer_header_img)
|
||||
public void selectHeaderImage() {
|
||||
mDrawerHeaderBackgroundSaver.select(this, mActivityResultMediator);
|
||||
}
|
||||
@@ -384,14 +380,14 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
|
||||
|
||||
public static void importScriptFile(Context context, String path) {
|
||||
context.startActivity(new Intent(context, MainActivity.class)
|
||||
context.startActivity(new Intent(context, MainActivity_.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
||||
.putExtra(EXTRA_ACTION, ACTION_IMPORT_SCRIPT)
|
||||
.putExtra(ARGUMENT_PATH, path));
|
||||
}
|
||||
|
||||
public static void importSample(Context context, Sample sample) {
|
||||
context.startActivity(new Intent(context, MainActivity.class)
|
||||
context.startActivity(new Intent(context, MainActivity_.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
||||
.putExtra(EXTRA_ACTION, ACTION_IMPORT_SAMPLE)
|
||||
.putExtra(ARGUMENT_SAMPLE, sample));
|
||||
@@ -424,7 +420,7 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
return ((MyScriptListFragment) mPagerAdapter.getStoredFragment(0));
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.toolbar)
|
||||
@Click(R.id.toolbar)
|
||||
public void OnToolbarClick() {
|
||||
mAppbarBackgroundSaver.select(this, mActivityResultMediator);
|
||||
}
|
||||
@@ -456,7 +452,7 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
|
||||
|
||||
public static void onRecordStop(Context context, String script) {
|
||||
Intent intent = new Intent(context, MainActivity.class)
|
||||
Intent intent = new Intent(context, MainActivity_.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra(EXTRA_ACTION, ACTION_ON_ACTION_RECORD_STOPPED)
|
||||
.putExtra(ARGUMENT_SCRIPT, script);
|
||||
|
||||
@@ -10,7 +10,6 @@ import android.support.v7.widget.SwitchCompat;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
@@ -21,12 +20,12 @@ import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.external.floatingwindow.FloatingWindowManger;
|
||||
import com.stardust.scriptdroid.external.floatingwindow.menu.HoverMenuService;
|
||||
import com.stardust.scriptdroid.service.AccessibilityWatchDogService;
|
||||
import com.stardust.view.accessibility.AccessibilityService;
|
||||
import com.stardust.scriptdroid.sublime.SublimePluginClient;
|
||||
import com.stardust.scriptdroid.sublime.SublimePluginService;
|
||||
import com.stardust.scriptdroid.tool.AccessibilityServiceTool;
|
||||
import com.stardust.scriptdroid.tool.WifiTool;
|
||||
import com.stardust.scriptdroid.ui.console.LogActivity;
|
||||
import com.stardust.scriptdroid.ui.console.LogActivity_;
|
||||
import com.stardust.scriptdroid.ui.help.HelpCatalogueActivity;
|
||||
import com.stardust.util.IntentUtil;
|
||||
import com.stardust.util.UnderuseExecutors;
|
||||
@@ -89,7 +88,7 @@ public class SideMenuFragment extends Fragment {
|
||||
mExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final boolean checked = AccessibilityWatchDogService.isEnable(App.getApp());
|
||||
final boolean checked = AccessibilityService.isEnable(App.getApp());
|
||||
mAccessibilityServiceSwitch.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -112,7 +111,7 @@ public class SideMenuFragment extends Fragment {
|
||||
|
||||
@ViewBinding.Click(R.id.console)
|
||||
private void startConsoleActivity() {
|
||||
startActivity(new Intent(getActivity(), LogActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
startActivity(new Intent(getActivity(), LogActivity_.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.syntax_and_api)
|
||||
@@ -127,11 +126,13 @@ public class SideMenuFragment extends Fragment {
|
||||
|
||||
@ViewBinding.Check(R.id.sw_auto_operate_service)
|
||||
private void setAutoOperateServiceEnable(boolean enable) {
|
||||
boolean isWatchDogServiceEnabled = AccessibilityWatchDogService.isEnable(App.getApp());
|
||||
if (enable && !isWatchDogServiceEnabled) {
|
||||
boolean isAccessibilityServiceEnabled = AccessibilityService.isEnable(App.getApp());
|
||||
if (enable && !isAccessibilityServiceEnabled) {
|
||||
AccessibilityServiceTool.enableAccessibilityService();
|
||||
} else if (!enable && isWatchDogServiceEnabled) {
|
||||
AccessibilityWatchDogService.disable();
|
||||
} else if (!enable && isAccessibilityServiceEnabled) {
|
||||
if (!AccessibilityService.disable()) {
|
||||
AccessibilityServiceTool.goToAccessibilitySetting();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package com.stardust.scriptdroid.ui.settings;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
@@ -15,35 +11,37 @@ import android.widget.Toast;
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.automator.UiObject;
|
||||
import com.stardust.scriptdroid.service.AccessibilityWatchDogService;
|
||||
import com.stardust.view.accessibility.AccessibilityService;
|
||||
import com.stardust.scriptdroid.tool.IntentTool;
|
||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||
import com.stardust.theme.dialog.ThemeColorMaterialDialogBuilder;
|
||||
import com.stardust.util.IntentUtil;
|
||||
import com.stardust.view.ViewBinding;
|
||||
import com.stardust.scriptdroid.BuildConfig;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.view.ViewBinder;
|
||||
|
||||
import org.androidannotations.annotations.AfterViews;
|
||||
import org.androidannotations.annotations.Click;
|
||||
import org.androidannotations.annotations.EActivity;
|
||||
import org.androidannotations.annotations.ViewById;
|
||||
|
||||
import moe.feng.alipay.zerosdk.AlipayZeroSdk;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/2/2.
|
||||
*/
|
||||
|
||||
@EActivity(R.layout.activity_about)
|
||||
public class AboutActivity extends BaseActivity {
|
||||
|
||||
private static final String TAG = "AboutActivity";
|
||||
@ViewById(R.id.version)
|
||||
TextView mVersion;
|
||||
|
||||
private int mLolClickCount = 0;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setUpUI();
|
||||
}
|
||||
|
||||
private void setUpUI() {
|
||||
setContentView(R.layout.activity_about);
|
||||
@AfterViews
|
||||
void setUpViews() {
|
||||
setVersionName();
|
||||
setToolbarAsBack(getString(R.string.text_about));
|
||||
ViewBinder.bind(this);
|
||||
@@ -51,32 +49,31 @@ public class AboutActivity extends BaseActivity {
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private void setVersionName() {
|
||||
TextView version = $(R.id.version);
|
||||
version.setText("Version " + BuildConfig.VERSION_NAME);
|
||||
mVersion.setText("Version " + BuildConfig.VERSION_NAME);
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.github)
|
||||
private void openGitHub() {
|
||||
@Click(R.id.github)
|
||||
void openGitHub() {
|
||||
IntentTool.browse(this, getString(R.string.my_github));
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.qq)
|
||||
private void openQQToChatWithMe() {
|
||||
@Click(R.id.qq)
|
||||
void openQQToChatWithMe() {
|
||||
String qq = getString(R.string.qq);
|
||||
if (!IntentUtil.chatWithQQ(this, qq)) {
|
||||
Toast.makeText(this, R.string.text_mobile_qq_not_installed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.email)
|
||||
private void openEmailToSendMe() {
|
||||
@Click(R.id.email)
|
||||
void openEmailToSendMe() {
|
||||
String email = getString(R.string.email);
|
||||
IntentUtil.sendMailTo(this, email);
|
||||
}
|
||||
|
||||
|
||||
@ViewBinding.Click(R.id.donate)
|
||||
private void showDonateMeDialog() {
|
||||
@Click(R.id.donate)
|
||||
void showDonateMeDialog() {
|
||||
new ThemeColorMaterialDialogBuilder(this)
|
||||
.title(R.string.donate)
|
||||
.items("支付宝")
|
||||
@@ -95,13 +92,13 @@ public class AboutActivity extends BaseActivity {
|
||||
.show();
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.share)
|
||||
private void share() {
|
||||
@Click(R.id.share)
|
||||
void share() {
|
||||
IntentUtil.shareText(this, getString(R.string.share_app));
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.icon)
|
||||
private void lol() {
|
||||
@Click(R.id.icon)
|
||||
void lol() {
|
||||
mLolClickCount++;
|
||||
Toast.makeText(this, R.string.text_lll, Toast.LENGTH_LONG).show();
|
||||
if (mLolClickCount >= 5) {
|
||||
@@ -121,7 +118,7 @@ public class AboutActivity extends BaseActivity {
|
||||
public void run() {
|
||||
int i = 0;
|
||||
while (true) {
|
||||
AccessibilityNodeInfo root = AccessibilityWatchDogService.getInstance().getRootInActiveWindow();
|
||||
AccessibilityNodeInfo root = AccessibilityService.getInstance().getRootInActiveWindow();
|
||||
if (root != null) {
|
||||
UiObject uiObject = UiObject.createRoot(root);
|
||||
UiObject child = uiObject.child(0);
|
||||
@@ -153,8 +150,8 @@ public class AboutActivity extends BaseActivity {
|
||||
}).show();
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.developer)
|
||||
private void hhh() {
|
||||
@Click(R.id.developer)
|
||||
void hhh() {
|
||||
Toast.makeText(this, R.string.text_it_is_the_developer_of_app, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ import com.stardust.theme.app.ColorSelectActivity;
|
||||
import com.stardust.theme.util.ListBuilder;
|
||||
import com.stardust.util.MessageEvent;
|
||||
|
||||
import org.androidannotations.annotations.AfterViews;
|
||||
import org.androidannotations.annotations.EActivity;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.List;
|
||||
@@ -35,7 +37,7 @@ import de.psdev.licensesdialog.licenses.License;
|
||||
/**
|
||||
* Created by Stardust on 2017/2/2.
|
||||
*/
|
||||
|
||||
@EActivity(R.layout.activity_settings)
|
||||
public class SettingsActivity extends BaseActivity {
|
||||
|
||||
private static final List<ColorSelectActivity.ColorItem> COLOR_ITEMS;
|
||||
@@ -64,14 +66,8 @@ public class SettingsActivity extends BaseActivity {
|
||||
.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setUpUI();
|
||||
}
|
||||
|
||||
private void setUpUI() {
|
||||
setContentView(R.layout.activity_settings);
|
||||
@AfterViews
|
||||
void setUpUI() {
|
||||
setUpToolbar();
|
||||
getFragmentManager().beginTransaction().replace(R.id.fragment_setting, new PreferenceFragment()).commit();
|
||||
}
|
||||
@@ -141,7 +137,7 @@ public class SettingsActivity extends BaseActivity {
|
||||
.entry(getString(R.string.text_about_me_and_repo), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startActivity(new Intent(getActivity(), AboutActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
startActivity(new Intent(getActivity(), AboutActivity_.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
})
|
||||
.entry(getString(R.string.text_licenses), new Runnable() {
|
||||
|
||||
|
Before Width: | Height: | Size: 221 B |
|
Before Width: | Height: | Size: 548 B |
|
Before Width: | Height: | Size: 367 B |
|
Before Width: | Height: | Size: 175 B |
|
Before Width: | Height: | Size: 352 B |
|
Before Width: | Height: | Size: 269 B |
|
Before Width: | Height: | Size: 257 B |
|
Before Width: | Height: | Size: 726 B |
|
Before Width: | Height: | Size: 456 B |
|
Before Width: | Height: | Size: 347 B |
|
Before Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 690 B |
|
Before Width: | Height: | Size: 436 B |
|
Before Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 930 B |
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:innerRadius="0dp"
|
||||
android:shape="ring"
|
||||
android:thicknessRatio="2"
|
||||
android:useLevel="false">
|
||||
<solid android:color="#161616"/>
|
||||
</shape>
|
||||
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<solid android:color="#99262626"/>
|
||||
|
||||
<corners
|
||||
android:bottomLeftRadius="12dp"
|
||||
android:bottomRightRadius="12dp"/>
|
||||
</shape>
|
||||
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<solid android:color="#cc181818"/>
|
||||
|
||||
<corners
|
||||
android:topLeftRadius="12dp"
|
||||
android:topRightRadius="12dp"/>
|
||||
</shape>
|
||||
|
Before Width: | Height: | Size: 905 B |
|
Before Width: | Height: | Size: 82 B |
|
Before Width: | Height: | Size: 1.1 KiB |
@@ -3,6 +3,7 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/content_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:animateLayoutChanges="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/content_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:paddingLeft="3dp"
|
||||
android:textIsSelectable="true"
|
||||
android:textSize="14sp"
|
||||
tools:text="12345\n678\n9\n0"/>
|
||||
</ScrollView>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/input_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/input"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:lines="1"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="14sp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/submit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/ok"
|
||||
android:textColor="@android:color/white"
|
||||
android:theme="@style/AppTheme.Console"/>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -68,7 +68,7 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.stardust.scriptdroid.ui.console.ConsoleView
|
||||
<com.stardust.autojs.runtime.console.ConsoleView
|
||||
android:id="@+id/console"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="46dp"
|
||||
android:layout_height="46dp"
|
||||
android:background="@android:color/transparent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="46dp"
|
||||
android:layout_height="46dp"
|
||||
android:padding="5dp"
|
||||
android:src="@drawable/ic_debug_console"/>
|
||||
</LinearLayout>
|
||||
@@ -1,7 +1,6 @@
|
||||
<resources>
|
||||
<string name="_app_name">AutoJs</string>
|
||||
<string name="action_settings">设置</string>
|
||||
<string name="text_accessibility_service_description">使脚本自动操作(点击、长按、滑动等)所需,若关闭则只能执行不涉及自动操作的脚本。</string>
|
||||
<string name="text_new_file">新建文件</string>
|
||||
<string name="text_import_from_file">从文件导入</string>
|
||||
<string name="text_create_fail">创建失败</string>
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:accessibilityEventTypes="typeAllMask"
|
||||
android:accessibilityFeedbackType="feedbackGeneric"
|
||||
android:accessibilityFlags="flagReportViewIds|flagRequestEnhancedWebAccessibility|flagRequestFilterKeyEvents"
|
||||
android:canPerformGestures="true"
|
||||
android:canRequestEnhancedWebAccessibility="true"
|
||||
android:canRetrieveWindowContent="true"
|
||||
android:description="@string/text_accessibility_service_description"
|
||||
android:notificationTimeout="100"/>
|
||||