Fix and improve root rocording
This commit is contained in:
@@ -78,6 +78,13 @@ public class Pref {
|
||||
return def().getString(getString(R.string.key_stop_record_trigger), null);
|
||||
}
|
||||
|
||||
public static boolean hasRecordTrigger(){
|
||||
String startTrigger = getStartRecordTrigger();
|
||||
String stopTrigger = getStartRecordTrigger();
|
||||
return startTrigger != null && !startTrigger.equals("NONE")
|
||||
&& stopTrigger != null && !startTrigger.equals("NONE");
|
||||
}
|
||||
|
||||
public static boolean enableAccessibilityServiceByRoot() {
|
||||
return def().getBoolean(getString(R.string.key_enable_accessibility_service_by_root), false);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import com.stardust.automator.simple_action.SimpleActionPerformHost;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.Pref;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.scripts.StorageScriptProvider;
|
||||
import com.stardust.scriptdroid.script.StorageScriptProvider;
|
||||
import com.stardust.scriptdroid.ui.console.StardustConsole;
|
||||
import com.stardust.util.Supplier;
|
||||
import com.stardust.util.UiHandler;
|
||||
@@ -22,7 +22,7 @@ import com.stardust.scriptdroid.layout_inspector.LayoutInspector;
|
||||
import com.stardust.scriptdroid.record.accessibility.AccessibilityActionRecorder;
|
||||
import com.stardust.scriptdroid.service.AccessibilityWatchDogService;
|
||||
import com.stardust.scriptdroid.tool.AccessibilityServiceTool;
|
||||
import com.stardust.scriptdroid.ui.console.TimberConsole;
|
||||
import com.stardust.scriptdroid.ui.console.JraskaConsole;
|
||||
import com.stardust.view.accessibility.AccessibilityServiceUtils;
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ public class AutoJs implements AccessibilityBridge {
|
||||
manager.setRequirePath(StorageScriptProvider.DEFAULT_DIRECTORY_PATH);
|
||||
mScriptEngineService = new ScriptEngineServiceBuilder()
|
||||
.uiHandler(mUiHandler)
|
||||
.globalConsole(new TimberConsole())
|
||||
.globalConsole(new JraskaConsole())
|
||||
.engineManger(manager)
|
||||
.runtime(new Supplier<ScriptRuntime>() {
|
||||
|
||||
@@ -83,6 +83,10 @@ public class AutoJs implements AccessibilityBridge {
|
||||
return mAccessibilityActionRecorder;
|
||||
}
|
||||
|
||||
public UiHandler getUiHandler() {
|
||||
return mUiHandler;
|
||||
}
|
||||
|
||||
public LayoutInspector getLayoutInspector() {
|
||||
return mLayoutInspector;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
package com.stardust.scriptdroid.autojs;
|
||||
|
||||
import com.flurry.android.FlurryAgent;
|
||||
import com.stardust.autojs.ScriptEngineService;
|
||||
import com.stardust.autojs.execution.ScriptExecution;
|
||||
import com.stardust.autojs.execution.ScriptExecutionListener;
|
||||
import com.stardust.autojs.runtime.ScriptInterruptedException;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.R;
|
||||
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/3.
|
||||
*/
|
||||
@@ -29,8 +25,11 @@ public class ScriptExecutionGlobalListener implements ScriptExecutionListener {
|
||||
}
|
||||
|
||||
private void onFinish(ScriptExecution execution) {
|
||||
long millis = System.currentTimeMillis() - (long) execution.getEngine().getTag(ENGINE_TAG_START_TIME);
|
||||
execution.getRuntime().console.verbose(App.getApp().getString(R.string.text_execution_finished), execution.getSource().toString(), (double) millis / 1000);
|
||||
Long millis = (Long) execution.getEngine().getTag(ENGINE_TAG_START_TIME);
|
||||
if (millis == null)
|
||||
return;
|
||||
double seconds = (System.currentTimeMillis() - millis) / 1000.0;
|
||||
execution.getRuntime().console.verbose(App.getApp().getString(R.string.text_execution_finished), execution.getSource().toString(), seconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
191
app/src/main/java/com/stardust/scriptdroid/autojs/Shell.java
Normal file
191
app/src/main/java/com/stardust/scriptdroid/autojs/Shell.java
Normal file
@@ -0,0 +1,191 @@
|
||||
package com.stardust.scriptdroid.autojs;
|
||||
|
||||
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.pio.UncheckedIOException;
|
||||
import com.stardust.scriptdroid.App;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
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 OutputListener {
|
||||
void onNewOutput(String str);
|
||||
}
|
||||
|
||||
private static final String TAG = "Shell";
|
||||
|
||||
private TermSession mTermSession;
|
||||
private RuntimeException mInitException;
|
||||
private final Object mInitLock = new Object();
|
||||
private final Object mExitLock = new Object();
|
||||
private boolean mInitialized = false;
|
||||
private boolean mWaitingExit = false;
|
||||
private OutputListener mOutputListener;
|
||||
|
||||
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 setOutputListener(OutputListener outputListener) {
|
||||
mOutputListener = outputListener;
|
||||
}
|
||||
|
||||
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) {
|
||||
exit();
|
||||
throw new ScriptInterruptedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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) {
|
||||
exit();
|
||||
throw new ScriptInterruptedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
exit();
|
||||
}
|
||||
|
||||
private class MyShellTermSession extends ShellTermSession {
|
||||
|
||||
public MyShellTermSession(TermSettings settings, String initialCommand) throws IOException {
|
||||
super(settings, initialCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processInput(byte[] data, int offset, int count) {
|
||||
String output = new String(data, offset, count);
|
||||
Log.d(TAG, output);
|
||||
if(mOutputListener != null){
|
||||
mOutputListener.onNewOutput(output);
|
||||
}
|
||||
if (mInitialized && !mWaitingExit) {
|
||||
return;
|
||||
}
|
||||
String[] lines = new String(data, offset, count).split("\n");
|
||||
for (String line : lines) {
|
||||
if (!mInitialized && line.endsWith(" # ")) {
|
||||
notifyInitialized();
|
||||
return;
|
||||
}
|
||||
if (mWaitingExit && line.endsWith(" $ ")) {
|
||||
notifyExit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyExit() {
|
||||
synchronized (mExitLock) {
|
||||
mWaitingExit = false;
|
||||
mExitLock.notify();
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyInitialized() {
|
||||
mInitialized = true;
|
||||
synchronized (mInitLock) {
|
||||
mInitLock.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProcessExit() {
|
||||
super.onProcessExit();
|
||||
synchronized (mExitLock) {
|
||||
mWaitingExit = false;
|
||||
mExitLock.notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import com.stardust.scriptdroid.external.floating_window.menu.HoverMenuService;
|
||||
import com.stardust.scriptdroid.record.Recorder;
|
||||
import com.stardust.scriptdroid.record.accessibility.AccessibilityActionRecorder;
|
||||
import com.stardust.scriptdroid.record.inputevent.InputEventConverter;
|
||||
import com.stardust.scriptdroid.record.inputevent.KeyObserver;
|
||||
import com.stardust.scriptdroid.record.inputevent.TouchRecorder;
|
||||
import com.stardust.scriptdroid.ui.main.MainActivity;
|
||||
import com.stardust.util.MessageEvent;
|
||||
@@ -35,7 +36,7 @@ import io.mattcarroll.hover.NavigatorContent;
|
||||
* Created by Stardust on 2017/3/12.
|
||||
*/
|
||||
|
||||
public class RecordNavigatorContent implements NavigatorContent, Recorder.OnStateChangedListener {
|
||||
public class RecordNavigatorContent implements NavigatorContent, Recorder.OnStateChangedListener, KeyObserver.KeyListener {
|
||||
|
||||
private View mView;
|
||||
@ViewBinding.Id(R.id.sw_recorded_by_root)
|
||||
@@ -57,6 +58,8 @@ public class RecordNavigatorContent implements NavigatorContent, Recorder.OnStat
|
||||
private Recorder mRecorder;
|
||||
private Context mContext;
|
||||
|
||||
private KeyObserver mKeyObserver;
|
||||
|
||||
private VolumeChangeObserver.OnVolumeChangeListener mOnVolumeChangeListener = new VolumeChangeObserver.OnVolumeChangeListener() {
|
||||
@Override
|
||||
public void onVolumeChange() {
|
||||
@@ -74,8 +77,13 @@ public class RecordNavigatorContent implements NavigatorContent, Recorder.OnStat
|
||||
mContext = context;
|
||||
mView = View.inflate(context, R.layout.floating_window_record, null);
|
||||
ViewBinder.bind(this);
|
||||
EventBus.getDefault().register(this);
|
||||
HoverMenuService.getEventBus().register(this);
|
||||
App.getApp().getVolumeChangeObserver().addOnVolumeChangeListener(mOnVolumeChangeListener);
|
||||
if (Pref.hasRecordTrigger()) {
|
||||
mKeyObserver = new KeyObserver();
|
||||
mKeyObserver.startListening();
|
||||
mKeyObserver.setKeyListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -158,10 +166,18 @@ public class RecordNavigatorContent implements NavigatorContent, Recorder.OnStat
|
||||
@Subscribe
|
||||
public void onMessageEvent(MessageEvent event) {
|
||||
if (event.message.equals(HoverMenuService.MESSAGE_MENU_EXPANDING)) {
|
||||
pauseRecord();
|
||||
if (mRecorder != null && mRecorder.getState() == Recorder.STATE_RECORDING)
|
||||
pauseRecord();
|
||||
} else if (event.message.equals(HoverMenuService.MESSAGE_MENU_EXIT)) {
|
||||
EventBus.getDefault().unregister(this);
|
||||
App.getApp().getVolumeChangeObserver().removeOnVolumeChangeListener(mOnVolumeChangeListener);
|
||||
onMenuExit();
|
||||
}
|
||||
}
|
||||
|
||||
public void onMenuExit() {
|
||||
HoverMenuService.getEventBus().unregister(this);
|
||||
App.getApp().getVolumeChangeObserver().removeOnVolumeChangeListener(mOnVolumeChangeListener);
|
||||
if (mKeyObserver != null) {
|
||||
mKeyObserver.stopListening();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,13 +188,6 @@ public class RecordNavigatorContent implements NavigatorContent, Recorder.OnStat
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onTouchRecorderStateChanged(InputEventConverter.RecordStateChangeEvent event) {
|
||||
if (!event.isRecording()) {
|
||||
stopRecord();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
Toast.makeText(mContext, R.string.text_start_record, Toast.LENGTH_SHORT).show();
|
||||
@@ -198,4 +207,20 @@ public class RecordNavigatorContent implements NavigatorContent, Recorder.OnStat
|
||||
public void onResume() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyDown(String keyName) {
|
||||
if (keyName.equals(Pref.getStopRecordTrigger())) {
|
||||
if (mRecorder != null && mRecorder.getState() == Recorder.STATE_RECORDING && mRecorder.getState() == Recorder.STATE_PAUSED)
|
||||
stopRecord();
|
||||
} else if (keyName.equals(Pref.getStartRecordTrigger())) {
|
||||
if (mRecorder == null)
|
||||
startRecord();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyUp(String keyName) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,9 @@ import com.stardust.autojs.script.FileScriptSource;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.external.floating_window.menu.HoverMenuService;
|
||||
import com.stardust.scriptdroid.scripts.ScriptFile;
|
||||
import com.stardust.scriptdroid.scripts.StorageScriptProvider;
|
||||
import com.stardust.scriptdroid.script.ScriptFile;
|
||||
import com.stardust.scriptdroid.script.Scripts;
|
||||
import com.stardust.scriptdroid.script.StorageScriptProvider;
|
||||
import com.stardust.scriptdroid.ui.edit.EditActivity;
|
||||
import com.stardust.scriptdroid.ui.main.script_list.ScriptAndFolderListRecyclerView;
|
||||
import com.stardust.scriptdroid.ui.main.script_list.ScriptListWithProgressBarView;
|
||||
@@ -53,7 +54,7 @@ public class ScriptListNavigatorContent implements NavigatorContent {
|
||||
|
||||
@Override
|
||||
public void onClick(ScriptFile file, int position) {
|
||||
AutoJs.getInstance().getScriptEngineService().execute(new FileScriptSource(file));
|
||||
Scripts.run(file);
|
||||
HoverMenuService.postEvent(new MessageEvent(HoverMenuService.MESSAGE_COLLAPSE_MENU));
|
||||
}
|
||||
|
||||
|
||||
@@ -7,13 +7,14 @@ import android.support.annotation.Nullable;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.scripts.PathChecker;
|
||||
import com.stardust.scriptdroid.script.PathChecker;
|
||||
import com.stardust.autojs.script.FileScriptSource;
|
||||
import com.stardust.autojs.script.MultiScriptSource;
|
||||
import com.stardust.autojs.script.ScriptSourceWithInit;
|
||||
import com.stardust.autojs.script.ScriptSource;
|
||||
import com.stardust.autojs.script.StringScriptSource;
|
||||
import com.stardust.scriptdroid.external.CommonUtils;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.script.Scripts;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/2/22.
|
||||
@@ -40,10 +41,10 @@ public class RunIntentActivity extends Activity {
|
||||
if (path == null && script != null) {
|
||||
source = new StringScriptSource(script);
|
||||
} else if (path != null && new PathChecker(this).checkAndToastError(path)) {
|
||||
source = new MultiScriptSource(new StringScriptSource(script), new FileScriptSource(path));
|
||||
source = new ScriptSourceWithInit(new StringScriptSource(script), new FileScriptSource(path));
|
||||
}
|
||||
if (source != null) {
|
||||
AutoJs.getInstance().getScriptEngineService().execute(source);
|
||||
Scripts.run(source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,11 @@ import android.os.Bundle;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.scripts.PathChecker;
|
||||
import com.stardust.scriptdroid.script.PathChecker;
|
||||
import com.stardust.autojs.script.FileScriptSource;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.external.CommonUtils;
|
||||
import com.stardust.scriptdroid.script.ScriptFile;
|
||||
import com.stardust.scriptdroid.script.Scripts;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/1/23.
|
||||
@@ -31,7 +32,7 @@ public class ShortcutActivity extends Activity {
|
||||
|
||||
private void runScriptFile(String path) {
|
||||
try {
|
||||
AutoJs.getInstance().getScriptEngineService().execute(new FileScriptSource(path));
|
||||
Scripts.run(new ScriptFile(path));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
|
||||
@@ -10,8 +10,8 @@ import android.view.MenuItem;
|
||||
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.external.CommonUtils;
|
||||
import com.stardust.scriptdroid.scripts.ScriptFile;
|
||||
import com.stardust.scriptdroid.scripts.StorageScriptProvider;
|
||||
import com.stardust.scriptdroid.script.ScriptFile;
|
||||
import com.stardust.scriptdroid.script.StorageScriptProvider;
|
||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||
import com.stardust.scriptdroid.ui.main.script_list.ScriptAndFolderListRecyclerView;
|
||||
import com.stardust.scriptdroid.ui.main.script_list.ScriptListWithProgressBarView;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.stardust.scriptdroid.record;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/3/16.
|
||||
*/
|
||||
@@ -18,27 +20,25 @@ public interface Recorder {
|
||||
|
||||
}
|
||||
|
||||
OnStateChangedListener NO_OPERATION_LISTENER = new OnStateChangedListener() {
|
||||
@Override
|
||||
public void onStart() {
|
||||
class StateChangeEvent {
|
||||
|
||||
private int mOldState;
|
||||
private int mCurrentState;
|
||||
|
||||
public StateChangeEvent(int oldState, int currentState) {
|
||||
mOldState = oldState;
|
||||
mCurrentState = currentState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
|
||||
public int getOldState() {
|
||||
return mOldState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
|
||||
public int getCurrentState() {
|
||||
return mCurrentState;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
int STATE_NOT_START = 0;
|
||||
int STATE_RECORDING = 1;
|
||||
@@ -59,44 +59,65 @@ public interface Recorder {
|
||||
|
||||
void setOnStateChangedListener(OnStateChangedListener onStateChangedListener);
|
||||
|
||||
abstract class DefaultIMPL implements Recorder {
|
||||
abstract class AbstractRecorder implements Recorder {
|
||||
|
||||
private static final OnStateChangedListener NO_OPERATION_LISTENER = new OnStateChangedListener() {
|
||||
@Override
|
||||
public void onStart() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private OnStateChangedListener mOnStateChangedListener = NO_OPERATION_LISTENER;
|
||||
|
||||
|
||||
private final boolean mSync;
|
||||
private int mState = STATE_NOT_START;
|
||||
|
||||
public DefaultIMPL(boolean syncOfState) {
|
||||
public AbstractRecorder(boolean syncOfState) {
|
||||
mSync = syncOfState;
|
||||
}
|
||||
|
||||
public DefaultIMPL() {
|
||||
public AbstractRecorder() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
checkState(STATE_NOT_START);
|
||||
ensureIsStateOf(STATE_NOT_START);
|
||||
setState(STATE_RECORDING);
|
||||
startImpl();
|
||||
mOnStateChangedListener.onStart();
|
||||
}
|
||||
|
||||
|
||||
private void checkState(int... expectedStates) {
|
||||
private void ensureIsStateOf(int... expectedStates) {
|
||||
for (int expectedState : expectedStates) {
|
||||
if (mState == expectedState)
|
||||
return;
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
throw new IllegalStateException("expected=" + Arrays.toString(expectedStates) + " state=" + mState);
|
||||
}
|
||||
|
||||
|
||||
protected abstract void startImpl();
|
||||
|
||||
public void stop() {
|
||||
checkState(STATE_RECORDING, STATE_PAUSED);
|
||||
ensureIsStateOf(STATE_RECORDING, STATE_PAUSED);
|
||||
setState(STATE_STOPPED);
|
||||
stopImpl();
|
||||
mOnStateChangedListener.onStop();
|
||||
@@ -105,7 +126,7 @@ public interface Recorder {
|
||||
protected abstract void stopImpl();
|
||||
|
||||
public void pause() {
|
||||
checkState(STATE_RECORDING);
|
||||
ensureIsStateOf(STATE_RECORDING);
|
||||
setState(STATE_PAUSED);
|
||||
pauseImpl();
|
||||
mOnStateChangedListener.onPause();
|
||||
@@ -136,7 +157,7 @@ public interface Recorder {
|
||||
}
|
||||
|
||||
public void resume() {
|
||||
checkState(STATE_PAUSED);
|
||||
ensureIsStateOf(STATE_PAUSED);
|
||||
setState(STATE_RECORDING);
|
||||
resumeImpl();
|
||||
mOnStateChangedListener.onResume();
|
||||
|
||||
@@ -2,12 +2,10 @@ package com.stardust.scriptdroid.record.accessibility;
|
||||
|
||||
import android.accessibilityservice.AccessibilityService;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
import com.stardust.scriptdroid.record.Recorder;
|
||||
import com.stardust.view.accessibility.AccessibilityDelegate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -17,7 +15,7 @@ import java.util.Set;
|
||||
* Created by Stardust on 2017/2/14.
|
||||
*/
|
||||
|
||||
public class AccessibilityActionRecorder extends Recorder.DefaultIMPL implements AccessibilityDelegate {
|
||||
public class AccessibilityActionRecorder extends Recorder.AbstractRecorder implements AccessibilityDelegate {
|
||||
|
||||
public static class AccessibilityActionRecordEvent {
|
||||
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
package com.stardust.scriptdroid.record.inputevent;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.flurry.android.FlurryAgent;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.record.Recorder;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
@@ -13,22 +21,6 @@ import java.util.regex.Pattern;
|
||||
|
||||
public abstract class InputEventConverter {
|
||||
|
||||
|
||||
public static class RecordStateChangeEvent {
|
||||
|
||||
private boolean mIsRecording;
|
||||
|
||||
public RecordStateChangeEvent(boolean isRecording) {
|
||||
this.mIsRecording = isRecording;
|
||||
}
|
||||
|
||||
|
||||
public boolean isRecording() {
|
||||
return mIsRecording;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class Event {
|
||||
|
||||
static final Pattern PATTERN = Pattern.compile("^\\[([^\\]]*)\\]\\s+([^:]*):\\s+([^\\s]*)\\s+([^\\s]*)\\s+([^\\s]*)\\s*$");
|
||||
@@ -76,47 +68,63 @@ public abstract class InputEventConverter {
|
||||
}
|
||||
|
||||
|
||||
protected boolean mStarted = false;
|
||||
protected boolean mConverting = false;
|
||||
private int mState = Recorder.STATE_NOT_START;
|
||||
|
||||
public void parseAndAddEventIfFormatCorrect(String eventStr) {
|
||||
public void convertEventIfFormatCorrect(String eventStr) {
|
||||
if(!mConverting)
|
||||
return;
|
||||
if(TextUtils.isEmpty(eventStr) || !eventStr.startsWith("["))
|
||||
return;
|
||||
Event event = parseEventOrNull(eventStr);
|
||||
if (event != null) {
|
||||
addEvent(event);
|
||||
convertEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void addEvent(@NonNull Event event);
|
||||
public abstract void convertEvent(@NonNull Event event);
|
||||
|
||||
public String getGetEventCommand() {
|
||||
return "getevent -t -l";
|
||||
}
|
||||
|
||||
|
||||
public void start() {
|
||||
mStarted = true;
|
||||
mConverting = true;
|
||||
mState = Recorder.STATE_RECORDING;
|
||||
}
|
||||
|
||||
public void resume(){
|
||||
mConverting = true;
|
||||
mState = Recorder.STATE_RECORDING;
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
mStarted = false;
|
||||
mConverting = false;
|
||||
mState = Recorder.STATE_PAUSED;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
mStarted = false;
|
||||
mConverting = false;
|
||||
mState = Recorder.STATE_STOPPED;
|
||||
}
|
||||
|
||||
public abstract String getCode();
|
||||
|
||||
private boolean mFirstEventFormatError = true;
|
||||
|
||||
public Event parseEventOrNull(String eventStr) {
|
||||
try {
|
||||
return Event.parseEvent(eventStr);
|
||||
} catch (EventFormatException e) {
|
||||
e.printStackTrace();
|
||||
if(mFirstEventFormatError){
|
||||
Toast.makeText(App.getApp(), R.string.text_record_format_error, Toast.LENGTH_SHORT).show();
|
||||
mFirstEventFormatError = false;
|
||||
FlurryAgent.logEvent("EventFormatException:" + e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyRecordStopped() {
|
||||
EventBus.getDefault().post(new RecordStateChangeEvent(false));
|
||||
}
|
||||
|
||||
public void notifyRecordStarted() {
|
||||
EventBus.getDefault().post(new RecordStateChangeEvent(true));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
package com.stardust.scriptdroid.record.inputevent;
|
||||
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.stardust.pio.UncheckedIOException;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.record.Recorder;
|
||||
|
||||
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;
|
||||
@@ -15,23 +22,23 @@ import jackpal.androidterm.util.TermSettings;
|
||||
* Created by Stardust on 2017/3/6.
|
||||
*/
|
||||
|
||||
public abstract class InputEventRecorder extends Recorder.DefaultIMPL {
|
||||
public class InputEventRecorder extends Recorder.AbstractRecorder {
|
||||
|
||||
private static final String TAG = "InputEventRecorder";
|
||||
private TermSession mTermSession;
|
||||
private String mGetEventCommand;
|
||||
protected InputEventConverter mInputEventConverter;
|
||||
|
||||
protected InputEventRecorder(String getEventCommand, InputEventConverter inputEventConverter) {
|
||||
mGetEventCommand = getEventCommand;
|
||||
protected InputEventRecorder(InputEventConverter inputEventConverter) {
|
||||
mGetEventCommand = inputEventConverter.getGetEventCommand();
|
||||
mInputEventConverter = inputEventConverter;
|
||||
}
|
||||
|
||||
public void listen() {
|
||||
TermSettings settings = new TermSettings(App.getApp().getResources(), PreferenceManager.getDefaultSharedPreferences(App.getApp()));
|
||||
try {
|
||||
mTermSession = new MyShellTermSession(settings, "su\r");
|
||||
mTermSession = new MyShellTermSession(settings, "su");
|
||||
mTermSession.initializeEmulator(80, 40);
|
||||
mTermSession.write("su\r");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -50,7 +57,7 @@ public abstract class InputEventRecorder extends Recorder.DefaultIMPL {
|
||||
|
||||
@Override
|
||||
protected void resumeImpl() {
|
||||
mInputEventConverter.start();
|
||||
mInputEventConverter.resume();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,31 +66,79 @@ public abstract class InputEventRecorder extends Recorder.DefaultIMPL {
|
||||
mInputEventConverter.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
return mInputEventConverter.getCode();
|
||||
}
|
||||
|
||||
protected abstract void parseAndRecordEvent(String eventStr);
|
||||
protected void convertEvent(String eventStr) {
|
||||
mInputEventConverter.convertEventIfFormatCorrect(eventStr);
|
||||
}
|
||||
|
||||
private class MyShellTermSession extends ShellTermSession {
|
||||
|
||||
private boolean mGettingEvents = false;
|
||||
private volatile boolean mGettingEvents = false;
|
||||
|
||||
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 Thread(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 (!mGettingEvents && line.endsWith(" $ su")) {
|
||||
mTermSession.write(mGetEventCommand + "\r");
|
||||
mGettingEvents = true;
|
||||
} else if (mGettingEvents) {
|
||||
convertEvent(line);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void processInput(byte[] data, int offset, int count) {
|
||||
String[] lines = new String(data, offset, count).split("\n");
|
||||
for (String line : lines) {
|
||||
System.out.println(line);
|
||||
if (!mGettingEvents && line.endsWith("data # ")) {
|
||||
mTermSession.write(mGetEventCommand + "\r");
|
||||
mGettingEvents = true;
|
||||
} else if (mGettingEvents) {
|
||||
parseAndRecordEvent(line);
|
||||
}
|
||||
try {
|
||||
mOutputStream.write(data, offset, count);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
super.finish();
|
||||
mReadingThread.interrupt();
|
||||
try {
|
||||
mBufferedReader.close();
|
||||
mOutputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
appendToEmulator(data, offset, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public class InputEventToJsConverter extends InputEventConverter {
|
||||
}
|
||||
|
||||
private void appendCodeIfNotStopped(Event event) {
|
||||
if (!mStarted)
|
||||
if (!mConverting)
|
||||
return;
|
||||
long interval = (long) (1000 * (event.time - mTouchTime));
|
||||
mCode.append("sh.Swipe(")
|
||||
@@ -115,20 +115,12 @@ public class InputEventToJsConverter extends InputEventConverter {
|
||||
if (event.code.equals("BTN_TOUCH")) {
|
||||
mTouchDown = event.value.equals("DOWN");
|
||||
if (!mTouchDown && mSwipe) {
|
||||
if (mStarted)
|
||||
if (mConverting)
|
||||
mCode.append("sh.Tap(").append(mLastTouchPoint.x).append(", ").append(mLastTouchPoint.y).append(");\n");
|
||||
mSwipe = false;
|
||||
}
|
||||
} else if (event.value.equals("UP")) {
|
||||
if (!mStarted && event.code.equals(mStartTriggerKey)) {
|
||||
mStarted = true;
|
||||
notifyRecordStarted();
|
||||
} else if (mStarted && event.code.equals(mStopTriggerKey)) {
|
||||
mStarted = false;
|
||||
notifyRecordStopped();
|
||||
} else {
|
||||
appendKeyPressCode(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +133,6 @@ public class InputEventToJsConverter extends InputEventConverter {
|
||||
}
|
||||
|
||||
private EventHandler mEventHandler = new TypeRouter();
|
||||
private String mStartTriggerKey, mStopTriggerKey;
|
||||
private StringBuilder mCode = new StringBuilder().append("var sh = new Shell(true);\n");
|
||||
private Point mTouchPoint = new Point(), mLastTouchPoint = new Point();
|
||||
private boolean mTouchDown = false, mSwipe = false;
|
||||
@@ -149,7 +140,7 @@ public class InputEventToJsConverter extends InputEventConverter {
|
||||
|
||||
|
||||
@Override
|
||||
public void addEvent(@NonNull Event event) {
|
||||
public void convertEvent(@NonNull Event event) {
|
||||
mEventHandler.handle(event);
|
||||
}
|
||||
|
||||
@@ -163,13 +154,5 @@ public class InputEventToJsConverter extends InputEventConverter {
|
||||
return mCode.toString();
|
||||
}
|
||||
|
||||
public void setStartTriggerKey(String startTriggerKey) {
|
||||
mStartTriggerKey = startTriggerKey;
|
||||
}
|
||||
|
||||
public void setStopTriggerKey(String stopTriggerKey) {
|
||||
mStopTriggerKey = stopTriggerKey;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.stardust.scriptdroid.record.inputevent;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/3/7.
|
||||
*/
|
||||
|
||||
public class InputEventToJsRecorder extends InputEventRecorder {
|
||||
|
||||
private InputEventToJsConverter mInputEventToJsConverter;
|
||||
|
||||
public InputEventToJsRecorder() {
|
||||
super("getevent -t -l", new InputEventToJsConverter());
|
||||
mInputEventToJsConverter = (InputEventToJsConverter) mInputEventConverter;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void parseAndRecordEvent(String eventStr) {
|
||||
mInputEventConverter.parseAndAddEventIfFormatCorrect(eventStr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
return mInputEventConverter.getCode();
|
||||
}
|
||||
|
||||
public void setStartTriggerKey(String startTriggerKey) {
|
||||
mInputEventToJsConverter.setStartTriggerKey(startTriggerKey);
|
||||
}
|
||||
|
||||
public void setStopTriggerKey(String stopTriggerKey) {
|
||||
mInputEventToJsConverter.setStopTriggerKey(stopTriggerKey);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public class InputEventToSendEventConverter extends InputEventConverter {
|
||||
private StringBuilder mSendEventCommands = new StringBuilder();
|
||||
|
||||
@Override
|
||||
public void addEvent(@NonNull Event event) {
|
||||
public void convertEvent(@NonNull Event event) {
|
||||
if (mLastEventTime == 0) {
|
||||
mLastEventTime = event.time;
|
||||
} else if (event.time - mLastEventTime > 0.1) {
|
||||
@@ -32,6 +32,11 @@ public class InputEventToSendEventConverter extends InputEventConverter {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGetEventCommand() {
|
||||
return "getevent -t";
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return mSendEventCommands.toString();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.stardust.scriptdroid.record.inputevent;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.stardust.util.ScreenMetrics.getScreenHeight;
|
||||
import static com.stardust.util.ScreenMetrics.getScreenWidth;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/3.
|
||||
*/
|
||||
|
||||
public class InputEventToSendEventJsConverter extends InputEventConverter {
|
||||
|
||||
private final static Pattern LAST_INT_PATTERN = Pattern.compile("[^0-9]+([0-9]+)$");
|
||||
private double mLastEventTime;
|
||||
private StringBuilder mCode = new StringBuilder();
|
||||
private int mTouchDevice = -1;
|
||||
private int mLastTouchX = -1;
|
||||
private int mLastTouchY = -1;
|
||||
|
||||
public InputEventToSendEventJsConverter() {
|
||||
mCode.append("var sh = new Shell(true);\n")
|
||||
.append("sh.SetScreenScale(").append(getScreenWidth()).append(", ")
|
||||
.append(getScreenHeight()).append(");\n");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void convertEvent(@NonNull Event event) {
|
||||
if (mLastEventTime == 0) {
|
||||
mLastEventTime = event.time;
|
||||
} else if (event.time - mLastEventTime > 0.03) {
|
||||
mCode.append("sleep(").append((long) (1000 * (event.time - mLastEventTime))).append(");\n");
|
||||
mLastEventTime = event.time;
|
||||
}
|
||||
int device = parseDeviceNumber(event.device);
|
||||
int type = (int) Long.parseLong(event.type, 16);
|
||||
int code = (int) Long.parseLong(event.code, 16);
|
||||
int value = (int) Long.parseLong(event.value, 16);
|
||||
if (type == 3) {
|
||||
if (code == 53) {
|
||||
onTouchX(device, value);
|
||||
return;
|
||||
}
|
||||
if (code == 54) {
|
||||
onTouchY(device, value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
checkLastTouch();
|
||||
mCode.append("sh.SendEvent(");
|
||||
if (device != mTouchDevice) {
|
||||
mCode.append(device).append(", ");
|
||||
}
|
||||
mCode.append(type).append(", ")
|
||||
.append(code).append(", ")
|
||||
.append(value).append(");\n");
|
||||
}
|
||||
|
||||
private void checkLastTouch() {
|
||||
if (mLastTouchX >= 0) {
|
||||
mCode.append("sh.TouchX(").append(mLastTouchX).append(");\n");
|
||||
mLastTouchX = -1;
|
||||
}
|
||||
if (mLastTouchY >= 0) {
|
||||
mCode.append("sh.TouchY(").append(mLastTouchY).append(");\n");
|
||||
mLastTouchY = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int parseDeviceNumber(String device) {
|
||||
Matcher matcher = LAST_INT_PATTERN.matcher(device);
|
||||
if (matcher.find()) {
|
||||
String someNumberStr = matcher.group(1);
|
||||
return Integer.parseInt(someNumberStr);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void onTouchX(int device, int value) {
|
||||
if (mTouchDevice == -1) {
|
||||
setTouchDevice(device);
|
||||
}
|
||||
mLastTouchX = value;
|
||||
}
|
||||
|
||||
private void onTouchY(int device, int value) {
|
||||
if (mTouchDevice == -1) {
|
||||
setTouchDevice(device);
|
||||
}
|
||||
if (mLastTouchX >= 0) {
|
||||
mCode.append("sh.Touch(")
|
||||
.append(mLastTouchX).append(", ")
|
||||
.append(value).append(");\n");
|
||||
mLastTouchX = -1;
|
||||
} else {
|
||||
mLastTouchY = value;
|
||||
}
|
||||
}
|
||||
|
||||
private void setTouchDevice(int i) {
|
||||
mCode.append("sh.SetTouchDevice(").append(i).append(");\n");
|
||||
mTouchDevice = i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGetEventCommand() {
|
||||
return "getevent -t";
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return mCode.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
super.stop();
|
||||
mCode.append("sh.exitAndWaitFor();");
|
||||
}
|
||||
|
||||
private static String hex2dec(String hex) {
|
||||
try {
|
||||
return String.valueOf((int) Long.parseLong(hex, 16));
|
||||
} catch (NumberFormatException e) {
|
||||
throw new EventFormatException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.stardust.scriptdroid.record.inputevent;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/3/7.
|
||||
*/
|
||||
|
||||
public class InputEventToSendEventRecorder extends InputEventRecorder {
|
||||
|
||||
private InputEventToSendEventConverter mEventConverter;
|
||||
|
||||
protected InputEventToSendEventRecorder() {
|
||||
super("getevent -t", new InputEventToSendEventConverter());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void parseAndRecordEvent(String eventStr) {
|
||||
mEventConverter.parseAndAddEventIfFormatCorrect(eventStr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
return mEventConverter.getCode();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.stardust.scriptdroid.record.inputevent;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/4.
|
||||
*/
|
||||
|
||||
public class KeyObserver {
|
||||
|
||||
public interface KeyListener {
|
||||
|
||||
void onKeyDown(String keyName);
|
||||
|
||||
void onKeyUp(String keyName);
|
||||
|
||||
}
|
||||
|
||||
private InputEventRecorder mObserver;
|
||||
private KeyListener mKeyListener;
|
||||
|
||||
public KeyObserver(){
|
||||
mObserver = new InputEventRecorder(new InputEventConverter() {
|
||||
@Override
|
||||
public void convertEvent(@NonNull Event event) {
|
||||
if(event.value.equalsIgnoreCase("UP")){
|
||||
notifyKeyUp(event.code);
|
||||
}
|
||||
if(event.value.equalsIgnoreCase("DOWN")){
|
||||
notifyKeyDown(event.code);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setKeyListener(KeyListener keyListener) {
|
||||
mKeyListener = keyListener;
|
||||
}
|
||||
|
||||
public void startListening(){
|
||||
mObserver.listen();
|
||||
mObserver.start();
|
||||
}
|
||||
|
||||
public void stopListening(){
|
||||
mObserver.stopImpl();
|
||||
}
|
||||
|
||||
private void notifyKeyDown(String keyName) {
|
||||
if(mKeyListener != null){
|
||||
mKeyListener.onKeyDown(keyName);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyKeyUp(String keyName) {
|
||||
if(mKeyListener != null){
|
||||
mKeyListener.onKeyUp(keyName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +1,32 @@
|
||||
package com.stardust.scriptdroid.record.inputevent;
|
||||
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.Pref;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.record.Recorder;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/3/16.
|
||||
*/
|
||||
|
||||
public class TouchRecorder extends InputEventToJsRecorder {
|
||||
|
||||
public class TouchRecorder extends InputEventRecorder implements KeyObserver.KeyListener {
|
||||
|
||||
public TouchRecorder() {
|
||||
super(new InputEventToSendEventJsConverter());
|
||||
listen();
|
||||
setUpTriggers();
|
||||
}
|
||||
|
||||
private void setUpTriggers() {
|
||||
setStartTriggerKey(Pref.getStartRecordTrigger());
|
||||
setStopTriggerKey(Pref.getStopRecordTrigger());
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
super.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyDown(String keyName) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyUp(String keyName) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.stardust.scriptdroid.scripts;
|
||||
package com.stardust.scriptdroid.script;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Build;
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.stardust.scriptdroid.scripts;
|
||||
package com.stardust.scriptdroid.script;
|
||||
|
||||
import android.os.Environment;
|
||||
|
||||
import com.android.dex.util.FileUtils;
|
||||
import com.stardust.pio.PFile;
|
||||
|
||||
import java.io.File;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.stardust.scriptdroid.scripts;
|
||||
package com.stardust.scriptdroid.script;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
113
app/src/main/java/com/stardust/scriptdroid/script/Scripts.java
Normal file
113
app/src/main/java/com/stardust/scriptdroid/script/Scripts.java
Normal file
@@ -0,0 +1,113 @@
|
||||
package com.stardust.scriptdroid.script;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.stardust.autojs.execution.ScriptExecution;
|
||||
import com.stardust.autojs.execution.ScriptExecutionListener;
|
||||
import com.stardust.autojs.execution.SimpleScriptExecutionListener;
|
||||
import com.stardust.autojs.runtime.ScriptInterruptedException;
|
||||
import com.stardust.autojs.script.FileScriptSource;
|
||||
import com.stardust.autojs.script.ScriptSource;
|
||||
import com.stardust.autojs.script.ScriptSourceWithInit;
|
||||
import com.stardust.autojs.script.StringScriptSource;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.BuildConfig;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.external.CommonUtils;
|
||||
import com.stardust.scriptdroid.external.shortcut.Shortcut;
|
||||
import com.stardust.scriptdroid.external.shortcut.ShortcutActivity;
|
||||
import com.stardust.scriptdroid.script.sample.Sample;
|
||||
import com.stardust.scriptdroid.ui.edit.EditActivity;
|
||||
import com.stardust.util.AssetsCache;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/3.
|
||||
*/
|
||||
|
||||
public class Scripts {
|
||||
|
||||
public static final String ACTION_ON_EXECUTION_FINISHED = "Don't leave me alone...";
|
||||
public static final String EXTRA_EXCEPTION_MESSAGE = "Say something...Eating...17.5.3";
|
||||
|
||||
private static final ScriptExecutionListener BROADCAST_SENDER_SCRIPT_EXECUTION_LISTENER = new SimpleScriptExecutionListener() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(ScriptExecution execution, Object result) {
|
||||
App.getApp().sendBroadcast(new Intent(ACTION_ON_EXECUTION_FINISHED));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(ScriptExecution execution, Exception e) {
|
||||
if (ScriptInterruptedException.causedByInterrupted(e)) {
|
||||
App.getApp().sendBroadcast(new Intent(ACTION_ON_EXECUTION_FINISHED));
|
||||
} else {
|
||||
App.getApp().sendBroadcast(new Intent(ACTION_ON_EXECUTION_FINISHED)
|
||||
.putExtra(EXTRA_EXCEPTION_MESSAGE, e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
private static final String INIT_SCRIPT_PATH = "js/autojs_init.js";
|
||||
private static ScriptSource initScriptSource;
|
||||
|
||||
|
||||
public static void openByOtherApps(String path) {
|
||||
Uri uri = Uri.parse("file://" + path);
|
||||
App.getApp().startActivity(new Intent(Intent.ACTION_VIEW).setDataAndType(uri, "text/plain").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
public static void openByOtherApps(File file) {
|
||||
openByOtherApps(file.getPath());
|
||||
}
|
||||
|
||||
public static void createShortcut(ScriptFile scriptFile) {
|
||||
new Shortcut(App.getApp()).name(scriptFile.getSimplifiedName())
|
||||
.targetClass(ShortcutActivity.class)
|
||||
.icon(R.drawable.ic_node_js_black)
|
||||
.extras(new Intent().putExtra(CommonUtils.EXTRA_KEY_PATH, scriptFile.getPath()))
|
||||
.send();
|
||||
}
|
||||
|
||||
|
||||
public static void edit(ScriptFile file) {
|
||||
EditActivity.editFile(App.getApp(), file.getSimplifiedName(), file.getPath());
|
||||
}
|
||||
|
||||
public static void edit(String path) {
|
||||
edit(new ScriptFile(path));
|
||||
}
|
||||
|
||||
public static ScriptExecution run(ScriptFile file) {
|
||||
return run(new FileScriptSource(file));
|
||||
}
|
||||
|
||||
public static ScriptExecution run(ScriptSource source) {
|
||||
return AutoJs.getInstance().getScriptEngineService().execute(wrappedWithInitSource(source));
|
||||
}
|
||||
|
||||
private static ScriptSource wrappedWithInitSource(ScriptSource source) {
|
||||
return new ScriptSourceWithInit(getInitScriptSource(), source);
|
||||
}
|
||||
|
||||
public static ScriptExecution runWithBroadcastSender(ScriptSource scriptSource) {
|
||||
return AutoJs.getInstance().getScriptEngineService().execute(wrappedWithInitSource(scriptSource), BROADCAST_SENDER_SCRIPT_EXECUTION_LISTENER);
|
||||
}
|
||||
|
||||
public static ScriptExecution run(Context context, Sample file) {
|
||||
ScriptSource source = new StringScriptSource(file.name, AssetsCache.get(context.getAssets(), file.path));
|
||||
return AutoJs.getInstance().getScriptEngineService().execute(wrappedWithInitSource(source));
|
||||
}
|
||||
|
||||
private static ScriptSource getInitScriptSource() {
|
||||
if(initScriptSource == null || BuildConfig.DEBUG){
|
||||
String initScript = AssetsCache.get(App.getApp().getAssets(), INIT_SCRIPT_PATH);
|
||||
initScriptSource = new StringScriptSource(initScript);
|
||||
}
|
||||
return initScriptSource;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.stardust.scriptdroid.scripts;
|
||||
package com.stardust.scriptdroid.script;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.stardust.scriptdroid.scripts;
|
||||
package com.stardust.scriptdroid.script;
|
||||
|
||||
import android.os.Environment;
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.util.FileSorter;
|
||||
import com.stardust.util.LimitedHashMap;
|
||||
import com.stardust.util.MapEntries;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
package com.stardust.scriptdroid.scripts.sample;
|
||||
package com.stardust.scriptdroid.script.sample;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.stardust.autojs.script.StringScriptSource;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.util.AssetsCache;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.stardust.scriptdroid.scripts.sample;
|
||||
package com.stardust.scriptdroid.script.sample;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.stardust.scriptdroid.scripts.sample;
|
||||
package com.stardust.scriptdroid.script.sample;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -4,20 +4,17 @@ import android.accessibilityservice.AccessibilityService;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.scriptdroid.Pref;
|
||||
import com.stardust.scriptdroid.service.AccessibilityWatchDogService;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.util.Shell;
|
||||
import com.stardust.autojs.runtime.api.ProcessShell;
|
||||
import com.stardust.view.accessibility.AccessibilityServiceUtils;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.stardust.view.accessibility.AccessibilityServiceUtils.isAccessibilityServiceEnabled;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/1/26.
|
||||
*/
|
||||
@@ -58,7 +55,7 @@ public class AccessibilityServiceTool {
|
||||
|
||||
public static boolean enableAccessibilityServiceByRoot(Class<? extends AccessibilityService> accessibilityService) {
|
||||
String serviceName = App.getApp().getPackageName() + "/" + accessibilityService.getName();
|
||||
return TextUtils.isEmpty(Shell.execCommand(String.format(Locale.getDefault(), cmd, serviceName), true).error);
|
||||
return TextUtils.isEmpty(ProcessShell.exec(String.format(Locale.getDefault(), cmd, serviceName), true).error);
|
||||
}
|
||||
|
||||
public static boolean enableAccessibilityServiceByRootAndWaitFor(long timeOut) {
|
||||
|
||||
@@ -76,13 +76,13 @@ public abstract class DrawableSaver {
|
||||
|
||||
}
|
||||
|
||||
public void select(Activity activity, final OnActivityResultDelegate.Intermediary intermediary) {
|
||||
new ImageSelector(activity, intermediary, new ImageSelector.ImageSelectorCallback() {
|
||||
public void select(Activity activity, final OnActivityResultDelegate.Mediator mediator) {
|
||||
new ImageSelector(activity, mediator, new ImageSelector.ImageSelectorCallback() {
|
||||
@Override
|
||||
public void onImageSelected(ImageSelector selector, InputStream inputStream) {
|
||||
if (inputStream != null)
|
||||
setDrawable(inputStream);
|
||||
intermediary.removeDelegate(selector);
|
||||
mediator.removeDelegate(selector);
|
||||
}
|
||||
}).select();
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ public class ImageSelector implements OnActivityResultDelegate {
|
||||
private Activity mActivity;
|
||||
private ImageSelectorCallback mCallback;
|
||||
|
||||
public ImageSelector(Activity activity, Intermediary intermediary, ImageSelectorCallback callback) {
|
||||
intermediary.addDelegate(REQUEST_CODE, this);
|
||||
public ImageSelector(Activity activity, Mediator mediator, ImageSelectorCallback callback) {
|
||||
mediator.addDelegate(REQUEST_CODE, this);
|
||||
mActivity = activity;
|
||||
mCallback = callback;
|
||||
}
|
||||
|
||||
@@ -1,161 +0,0 @@
|
||||
package com.stardust.scriptdroid.tool;
|
||||
|
||||
import android.content.Context;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.stardust.pio.UncheckedIOException;
|
||||
import com.stardust.scriptdroid.App;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import jackpal.androidterm.ShellTermSession;
|
||||
import jackpal.androidterm.emulatorview.TermSession;
|
||||
import jackpal.androidterm.util.TermSettings;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/24.
|
||||
*/
|
||||
|
||||
public class Shell {
|
||||
|
||||
private TermSession mTermSession;
|
||||
private String mOutput;
|
||||
|
||||
public Shell(boolean root) {
|
||||
this(App.getApp(), root ? "su\n" : "sh\n");
|
||||
}
|
||||
|
||||
public Shell(Context context, String initialCommand) {
|
||||
TermSettings settings = new TermSettings(context.getResources(), PreferenceManager.getDefaultSharedPreferences(context));
|
||||
try {
|
||||
mTermSession = new MyShellTermSession(settings, initialCommand);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String execAndWaitFor(String command) {
|
||||
mTermSession.write(command + "\n");
|
||||
mOutput = null;
|
||||
synchronized (this) {
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return mOutput;
|
||||
}
|
||||
|
||||
public String execAndWaitFor(String command, int millis) {
|
||||
mTermSession.write(command + "\n");
|
||||
mOutput = null;
|
||||
synchronized (this) {
|
||||
try {
|
||||
wait(millis);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return mOutput;
|
||||
}
|
||||
|
||||
public void exec(String command) {
|
||||
mTermSession.write(command);
|
||||
}
|
||||
|
||||
public void execute(String command) {
|
||||
mTermSession.write(command);
|
||||
}
|
||||
|
||||
|
||||
public void Tap(int x, int y) {
|
||||
execute("input tap " + x + " " + y);
|
||||
}
|
||||
|
||||
public void Swipe(int x1, int y1, int x2, int y2) {
|
||||
execute("input swipe " + x1 + " " + y1 + " " + x2 + " " + y2);
|
||||
}
|
||||
|
||||
public void Swipe(int x1, int y1, int x2, int y2, long duration) {
|
||||
execute("input swipe " + x1 + " " + y1 + " " + x2 + " " + y2 + " " + duration);
|
||||
}
|
||||
|
||||
public void KeyCode(int keyCode) {
|
||||
execute("input keyevent " + keyCode);
|
||||
}
|
||||
|
||||
public void KeyCode(String keyCode) {
|
||||
execute("input keyevent " + keyCode);
|
||||
}
|
||||
|
||||
public void Home() {
|
||||
KeyCode(3);
|
||||
}
|
||||
|
||||
public void Back() {
|
||||
KeyCode(4);
|
||||
}
|
||||
|
||||
public void Power() {
|
||||
KeyCode(26);
|
||||
}
|
||||
|
||||
public void Up() {
|
||||
KeyCode(19);
|
||||
}
|
||||
|
||||
public void Down() {
|
||||
KeyCode(20);
|
||||
}
|
||||
|
||||
public void Left() {
|
||||
KeyCode(21);
|
||||
}
|
||||
|
||||
public void Right() {
|
||||
KeyCode(22);
|
||||
}
|
||||
|
||||
public void OK() {
|
||||
KeyCode(23);
|
||||
}
|
||||
|
||||
public void VolumeUp() {
|
||||
KeyCode(24);
|
||||
}
|
||||
|
||||
public void VolumeDown() {
|
||||
KeyCode(25);
|
||||
}
|
||||
|
||||
public void Menu() {
|
||||
KeyCode(1);
|
||||
}
|
||||
|
||||
public void Camera() {
|
||||
KeyCode(27);
|
||||
}
|
||||
|
||||
public void Text(String text) {
|
||||
execute("input text " + text);
|
||||
}
|
||||
|
||||
private class MyShellTermSession extends ShellTermSession {
|
||||
|
||||
public MyShellTermSession(TermSettings settings, String initialCommand) throws IOException {
|
||||
super(settings, initialCommand);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void processInput(byte[] data, int offset, int count) {
|
||||
mOutput = new String(data, offset, count);
|
||||
synchronized (Shell.this) {
|
||||
Shell.this.notifyAll();
|
||||
}
|
||||
appendToEmulator(data, offset, count);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,7 +27,7 @@ public class ConsoleActivity extends BaseActivity {
|
||||
|
||||
private void setUpUI() {
|
||||
setContentView(R.layout.activity_console);
|
||||
setToolbarAsBack(getString(R.string.text_console));
|
||||
setToolbarAsBack(getString(R.string.text_log));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.stardust.scriptdroid.ui.console;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.jraska.console.Console;
|
||||
import com.stardust.autojs.runtime.api.AbstractConsole;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.util.SparseArrayEntries;
|
||||
import com.stardust.util.TextUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/2.
|
||||
*/
|
||||
|
||||
public class JraskaConsole extends AbstractConsole {
|
||||
|
||||
|
||||
private static final SparseArray<Integer> COLORS = new SparseArrayEntries<Integer>()
|
||||
.entry(Log.VERBOSE, 0xff909090)
|
||||
.entry(Log.DEBUG, 0xdf000000)
|
||||
.entry(Log.INFO, 0xdf4caf50)
|
||||
.entry(Log.WARN, 0xff2196f3)
|
||||
.entry(Log.ERROR, 0xffff534e)
|
||||
.entry(Log.ASSERT, 0xffff534e)
|
||||
.sparseArray();
|
||||
|
||||
private static final SparseArray<String> TAGS = new SparseArrayEntries<String>()
|
||||
.entry(Log.VERBOSE, "V")
|
||||
.entry(Log.DEBUG, "D")
|
||||
.entry(Log.INFO, "I")
|
||||
.entry(Log.WARN, "W")
|
||||
.entry(Log.ERROR, "E")
|
||||
.entry(Log.ASSERT, "A")
|
||||
.sparseArray();
|
||||
|
||||
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("HH:mm:ss.SSS/", Locale.getDefault());
|
||||
|
||||
@Override
|
||||
public void println(int level, CharSequence charSequence) {
|
||||
Console.write(getLevelSpannable(level, getTag(level)));
|
||||
Console.writeLine(getLevelSpannable(level, charSequence));
|
||||
}
|
||||
|
||||
private CharSequence getTag(int level) {
|
||||
return TextUtils.join("", DATE_FORMAT.format(new Date()), TAGS.get(level), ": ");
|
||||
}
|
||||
|
||||
private SpannableString getLevelSpannable(int level, CharSequence charSequence) {
|
||||
SpannableString spannable = new SpannableString(charSequence);
|
||||
spannable.setSpan(new ForegroundColorSpan(COLORS.get(level)), 0, charSequence.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
return spannable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
com.jraska.console.Console.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
App.getApp().startActivity(new Intent(App.getApp(), ConsoleActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(CharSequence title) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package com.stardust.scriptdroid.ui.console;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.stardust.autojs.runtime.AbstractConsole;
|
||||
import com.stardust.autojs.runtime.api.AbstractConsole;
|
||||
import com.stardust.autojs.runtime.api.Console;
|
||||
import com.stardust.enhancedfloaty.FloatyService;
|
||||
import com.stardust.enhancedfloaty.ResizableExpandableFloatyWindow;
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
package com.stardust.scriptdroid.ui.console;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.Log;
|
||||
|
||||
import com.jraska.console.Console;
|
||||
import com.jraska.console.timber.ConsoleTree;
|
||||
import com.stardust.autojs.runtime.AbstractConsole;
|
||||
import com.stardust.scriptdroid.App;
|
||||
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/2.
|
||||
*/
|
||||
|
||||
public class TimberConsole extends AbstractConsole {
|
||||
|
||||
static {
|
||||
Timber.plant(new ConsoleTree.Builder()
|
||||
.minPriority(Log.VERBOSE)
|
||||
.verboseColor(0xff909090)
|
||||
.debugColor(0xdf000000)
|
||||
.infoColor(0xdf4caf50)
|
||||
.warnColor(0xff2196f3)
|
||||
.errorColor(0xffff534e)
|
||||
.assertColor(0xffff534e)
|
||||
.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(int level, CharSequence charSequence) {
|
||||
if (level == Log.DEBUG) {
|
||||
SpannableString spannable = new SpannableString(charSequence);
|
||||
spannable.setSpan(new ForegroundColorSpan(0xdd000000), 0, charSequence.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
Console.writeLine(spannable);
|
||||
} else {
|
||||
Timber.log(level, charSequence.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
com.jraska.console.Console.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
App.getApp().startActivity(new Intent(App.getApp(), ConsoleActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(CharSequence title) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,8 @@ import com.stardust.autojs.script.JsBeautifier;
|
||||
import com.stardust.autojs.script.StringScriptSource;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.scripts.ScriptFile;
|
||||
import com.stardust.scriptdroid.script.ScriptFile;
|
||||
import com.stardust.scriptdroid.script.Scripts;
|
||||
import com.stardust.scriptdroid.tool.JsBeautifierFactory;
|
||||
import com.stardust.scriptdroid.tool.MaterialDialogFactory;
|
||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||
@@ -35,7 +36,6 @@ import com.stardust.scriptdroid.ui.edit.completion.InputMethodEnhanceBar;
|
||||
import com.stardust.scriptdroid.ui.edit.editor920.Editor920Activity;
|
||||
import com.stardust.scriptdroid.ui.edit.editor920.Editor920Utils;
|
||||
import com.stardust.scriptdroid.ui.help.HelpCatalogueActivity;
|
||||
import com.stardust.scriptdroid.ui.main.operation.ScriptFileOperation;
|
||||
import com.stardust.theme.ThemeColorManager;
|
||||
import com.stardust.theme.dialog.ThemeColorMaterialDialogBuilder;
|
||||
import com.stardust.util.SparseArrayEntries;
|
||||
@@ -45,11 +45,6 @@ import com.stardust.widget.ToolbarMenuItem;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.stardust.scriptdroid.ui.main.operation.ScriptFileOperation.ACTION_ON_RUN_FINISHED;
|
||||
import static com.stardust.scriptdroid.ui.main.operation.ScriptFileOperation.EXTRA_EXCEPTION_MESSAGE;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/1/29.
|
||||
*/
|
||||
@@ -83,6 +78,7 @@ public class EditActivity extends Editor920Activity {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static final String EXTRA_CONTENT = "Still Love Eating 17.4.5";
|
||||
|
||||
public static void editFile(Context context, String path) {
|
||||
@@ -109,13 +105,12 @@ public class EditActivity extends Editor920Activity {
|
||||
private BroadcastReceiver mOnRunFinishedReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(ACTION_ON_RUN_FINISHED)) {
|
||||
if (intent.getAction().equals(Scripts.ACTION_ON_EXECUTION_FINISHED)) {
|
||||
mScriptExecution = null;
|
||||
setMenuStatus(R.id.run, MenuDef.STATUS_NORMAL);
|
||||
String msg = intent.getStringExtra(EXTRA_EXCEPTION_MESSAGE);
|
||||
String msg = intent.getStringExtra(Scripts.EXTRA_EXCEPTION_MESSAGE);
|
||||
if (msg != null) {
|
||||
Snackbar.make(mView, getString(R.string.text_error) + ": " + msg, Snackbar.LENGTH_LONG).show();
|
||||
Timber.e(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,7 +126,7 @@ public class EditActivity extends Editor920Activity {
|
||||
handleIntent(getIntent());
|
||||
setUpUI();
|
||||
setUpEditor();
|
||||
registerReceiver(mOnRunFinishedReceiver, new IntentFilter(ACTION_ON_RUN_FINISHED));
|
||||
registerReceiver(mOnRunFinishedReceiver, new IntentFilter(Scripts.ACTION_ON_EXECUTION_FINISHED));
|
||||
}
|
||||
|
||||
private void handleIntent(Intent intent) {
|
||||
@@ -212,12 +207,13 @@ public class EditActivity extends Editor920Activity {
|
||||
Snackbar.make(mView, R.string.text_start_running, Snackbar.LENGTH_SHORT).show();
|
||||
setMenuStatus(R.id.run, MenuDef.STATUS_DISABLED);
|
||||
if (mFile != null) {
|
||||
mScriptExecution = ScriptFileOperation.runOnEditView(new FileScriptSource(mName, mFile));
|
||||
mScriptExecution = Scripts.runWithBroadcastSender(new FileScriptSource(mName, mFile));
|
||||
} else {
|
||||
mScriptExecution = ScriptFileOperation.runOnEditView(new StringScriptSource(mName, mEditorDelegate.getText()));
|
||||
mScriptExecution = Scripts.runWithBroadcastSender(new StringScriptSource(mName, mEditorDelegate.getText()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ViewBinding.Click(R.id.undo)
|
||||
private void undo() {
|
||||
Command command = new Command(Command.CommandEnum.UNDO);
|
||||
@@ -266,6 +262,9 @@ public class EditActivity extends Editor920Activity {
|
||||
case R.id.action_console:
|
||||
showConsole();
|
||||
return true;
|
||||
case R.id.action_log:
|
||||
showLog();
|
||||
return true;
|
||||
case R.id.action_help:
|
||||
HelpCatalogueActivity.showMainCatalogue(this);
|
||||
return true;
|
||||
@@ -282,11 +281,13 @@ public class EditActivity extends Editor920Activity {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void showLog() {
|
||||
AutoJs.getInstance().getScriptEngineService().getGlobalConsole().show();
|
||||
}
|
||||
|
||||
private void showConsole() {
|
||||
if (mScriptExecution != null) {
|
||||
mScriptExecution.getRuntime().console.show();
|
||||
} else {
|
||||
AutoJs.getInstance().getScriptEngineService().getGlobalConsole().show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,8 +299,7 @@ public class EditActivity extends Editor920Activity {
|
||||
|
||||
private void openByOtherApps() {
|
||||
if (mFile != null)
|
||||
ScriptFileOperation.openByOtherApps(mFile.getPath());
|
||||
|
||||
Scripts.openByOtherApps(mFile);
|
||||
}
|
||||
|
||||
private void beautifyCode() {
|
||||
|
||||
@@ -15,16 +15,18 @@ import com.jecelyin.editor.v2.common.Command;
|
||||
import com.jecelyin.editor.v2.ui.EditorDelegate;
|
||||
import com.jecelyin.editor.v2.view.EditorView;
|
||||
import com.jecelyin.editor.v2.view.menu.MenuDef;
|
||||
import com.stardust.autojs.execution.ScriptExecution;
|
||||
import com.stardust.autojs.script.StringScriptSource;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.scripts.sample.Sample;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.script.Scripts;
|
||||
import com.stardust.scriptdroid.script.sample.Sample;
|
||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||
import com.stardust.scriptdroid.ui.console.ConsoleActivity;
|
||||
import com.stardust.scriptdroid.ui.edit.editor920.Editor920Activity;
|
||||
import com.stardust.scriptdroid.ui.edit.editor920.Editor920Utils;
|
||||
import com.stardust.scriptdroid.ui.help.HelpCatalogueActivity;
|
||||
import com.stardust.scriptdroid.ui.main.MainActivity;
|
||||
import com.stardust.scriptdroid.ui.main.operation.ScriptFileOperation;
|
||||
import com.stardust.theme.ThemeColorManager;
|
||||
import com.stardust.util.AssetsCache;
|
||||
import com.stardust.util.SparseArrayEntries;
|
||||
@@ -32,10 +34,10 @@ import com.stardust.view.ViewBinder;
|
||||
import com.stardust.view.ViewBinding;
|
||||
import com.stardust.widget.ToolbarMenuItem;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.stardust.scriptdroid.ui.main.operation.ScriptFileOperation.ACTION_ON_RUN_FINISHED;
|
||||
import static com.stardust.scriptdroid.ui.main.operation.ScriptFileOperation.EXTRA_EXCEPTION_MESSAGE;
|
||||
import static com.stardust.scriptdroid.script.Scripts.ACTION_ON_EXECUTION_FINISHED;
|
||||
import static com.stardust.scriptdroid.script.Scripts.EXTRA_EXCEPTION_MESSAGE;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/29.
|
||||
@@ -43,6 +45,7 @@ import static com.stardust.scriptdroid.ui.main.operation.ScriptFileOperation.EXT
|
||||
|
||||
public class ViewSampleActivity extends Editor920Activity {
|
||||
|
||||
|
||||
public static void view(Context context, Sample sample) {
|
||||
context.startActivity(new Intent(context, ViewSampleActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
@@ -51,17 +54,18 @@ public class ViewSampleActivity extends Editor920Activity {
|
||||
|
||||
private View mView;
|
||||
private Sample mSample;
|
||||
private ScriptExecution mScriptExecution;
|
||||
private EditorDelegate mEditorDelegate;
|
||||
private SparseArray<ToolbarMenuItem> mMenuMap;
|
||||
private BroadcastReceiver mOnRunFinishedReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(ACTION_ON_RUN_FINISHED)) {
|
||||
if (intent.getAction().equals(ACTION_ON_EXECUTION_FINISHED)) {
|
||||
mScriptExecution = null;
|
||||
setMenuStatus(R.id.run, MenuDef.STATUS_NORMAL);
|
||||
String msg = intent.getStringExtra(EXTRA_EXCEPTION_MESSAGE);
|
||||
if (msg != null) {
|
||||
Snackbar.make(mView, getString(R.string.text_error) + ": " + msg, Snackbar.LENGTH_LONG).show();
|
||||
Timber.e(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,7 +79,7 @@ public class ViewSampleActivity extends Editor920Activity {
|
||||
handleIntent(getIntent());
|
||||
setUpUI();
|
||||
setUpEditor();
|
||||
registerReceiver(mOnRunFinishedReceiver, new IntentFilter(ACTION_ON_RUN_FINISHED));
|
||||
registerReceiver(mOnRunFinishedReceiver, new IntentFilter(ACTION_ON_EXECUTION_FINISHED));
|
||||
}
|
||||
|
||||
private void handleIntent(Intent intent) {
|
||||
@@ -107,7 +111,7 @@ public class ViewSampleActivity extends Editor920Activity {
|
||||
private void run() {
|
||||
Snackbar.make(mView, R.string.text_start_running, Snackbar.LENGTH_SHORT).show();
|
||||
setMenuStatus(R.id.run, MenuDef.STATUS_DISABLED);
|
||||
ScriptFileOperation.runOnEditView(new StringScriptSource(mSample.name, mEditorDelegate.getText()));
|
||||
mScriptExecution = Scripts.runWithBroadcastSender(new StringScriptSource(mSample.name, mEditorDelegate.getText()));
|
||||
}
|
||||
|
||||
private void initMenuItem() {
|
||||
@@ -135,7 +139,10 @@ public class ViewSampleActivity extends Editor920Activity {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_console:
|
||||
startActivity(new Intent(getContext(), ConsoleActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
showConsole();
|
||||
return true;
|
||||
case R.id.action_log:
|
||||
showLog();
|
||||
return true;
|
||||
case R.id.action_help:
|
||||
HelpCatalogueActivity.showMainCatalogue(this);
|
||||
@@ -147,6 +154,17 @@ public class ViewSampleActivity extends Editor920Activity {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
private void showLog() {
|
||||
AutoJs.getInstance().getScriptEngineService().getGlobalConsole().show();
|
||||
}
|
||||
|
||||
private void showConsole() {
|
||||
if (mScriptExecution != null) {
|
||||
mScriptExecution.getRuntime().console.show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doCommand(Command command) {
|
||||
mEditorDelegate.doCommand(command);
|
||||
|
||||
@@ -29,9 +29,9 @@ import com.stardust.app.NotAskAgainDialog;
|
||||
import com.stardust.app.OnActivityResultDelegate;
|
||||
import com.stardust.scriptdroid.BuildConfig;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.scripts.ScriptFile;
|
||||
import com.stardust.scriptdroid.scripts.StorageScriptProvider;
|
||||
import com.stardust.scriptdroid.scripts.sample.Sample;
|
||||
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.scriptdroid.tool.AccessibilityServiceTool;
|
||||
import com.stardust.scriptdroid.tool.DrawableSaver;
|
||||
@@ -75,7 +75,7 @@ public class MainActivity extends BaseActivity {
|
||||
private SlidingUpPanel mAddBottomMenuPanel;
|
||||
private FragmentPagerAdapterBuilder.StoredFragmentPagerAdapter mPagerAdapter;
|
||||
|
||||
private OnActivityResultDelegate.Intermediary mActivityResultIntermediary = new OnActivityResultDelegate.Intermediary();
|
||||
private OnActivityResultDelegate.Mediator mActivityResultMediator = new OnActivityResultDelegate.Mediator();
|
||||
private DrawableSaver mDrawerHeaderBackgroundSaver, mAppbarBackgroundSaver;
|
||||
private VersionGuard mVersionGuard;
|
||||
private Intent mIntentToHandle;
|
||||
@@ -240,7 +240,7 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
@ViewBinding.Click(R.id.drawer_header_img)
|
||||
public void selectHeaderImage() {
|
||||
mDrawerHeaderBackgroundSaver.select(this, mActivityResultIntermediary);
|
||||
mDrawerHeaderBackgroundSaver.select(this, mActivityResultMediator);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -330,7 +330,7 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
@ViewBinding.Click(R.id.toolbar)
|
||||
public void OnToolbarClick() {
|
||||
mAppbarBackgroundSaver.select(this, mActivityResultIntermediary);
|
||||
mAppbarBackgroundSaver.select(this, mActivityResultMediator);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -343,7 +343,7 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
mActivityResultIntermediary.onActivityResult(requestCode, resultCode, data);
|
||||
mActivityResultMediator.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
package com.stardust.scriptdroid.ui.main.operation;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.stardust.autojs.execution.ScriptExecution;
|
||||
import com.stardust.autojs.execution.ScriptExecutionListener;
|
||||
import com.stardust.autojs.execution.SimpleScriptExecutionListener;
|
||||
import com.stardust.autojs.runtime.ScriptInterruptedException;
|
||||
import com.stardust.autojs.script.FileScriptSource;
|
||||
import com.stardust.autojs.script.ScriptSource;
|
||||
import com.stardust.autojs.script.StringScriptSource;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.external.CommonUtils;
|
||||
import com.stardust.scriptdroid.external.shortcut.Shortcut;
|
||||
import com.stardust.scriptdroid.external.shortcut.ShortcutActivity;
|
||||
import com.stardust.scriptdroid.scripts.ScriptFile;
|
||||
import com.stardust.scriptdroid.scripts.sample.Sample;
|
||||
import com.stardust.scriptdroid.ui.edit.EditActivity;
|
||||
import com.stardust.util.AssetsCache;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/1/23.
|
||||
*/
|
||||
|
||||
public abstract class ScriptFileOperation {
|
||||
|
||||
public static final String ACTION_ON_RUN_FINISHED = "ACTION_ON_RUN_FINISHED";
|
||||
public static final String EXTRA_EXCEPTION_MESSAGE = "EXTRA_EXCEPTION_MESSAGE";
|
||||
|
||||
|
||||
private static final ScriptExecutionListener RUN_ON_EDIT_VIEW_SCRIPT_EXECUTION_LISTENER = new SimpleScriptExecutionListener() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(ScriptExecution execution, Object result) {
|
||||
App.getApp().sendBroadcast(new Intent(ACTION_ON_RUN_FINISHED));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(ScriptExecution execution, Exception e) {
|
||||
if (ScriptInterruptedException.causedByInterrupted(e)) {
|
||||
return;
|
||||
}
|
||||
App.getApp().sendBroadcast(new Intent(ACTION_ON_RUN_FINISHED)
|
||||
.putExtra(EXTRA_EXCEPTION_MESSAGE, e.getMessage()));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
public static void openByOtherApps(String path) {
|
||||
Uri uri = Uri.parse("file://" + path);
|
||||
App.getApp().startActivity(new Intent(Intent.ACTION_VIEW).setDataAndType(uri, "text/plain").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
public static void createShortcut(ScriptFile scriptFile) {
|
||||
new Shortcut(App.getApp()).name(scriptFile.getSimplifiedName())
|
||||
.targetClass(ShortcutActivity.class)
|
||||
.icon(R.drawable.ic_node_js_black)
|
||||
.extras(new Intent().putExtra(CommonUtils.EXTRA_KEY_PATH, scriptFile.getPath()))
|
||||
.send();
|
||||
}
|
||||
|
||||
|
||||
public static void edit(ScriptFile file) {
|
||||
EditActivity.editFile(App.getApp(), file.getSimplifiedName(), file.getPath());
|
||||
}
|
||||
|
||||
public static void run(ScriptFile file) {
|
||||
AutoJs.getInstance().getScriptEngineService().execute(new FileScriptSource(file));
|
||||
}
|
||||
|
||||
public static void run(Context context, Sample file) {
|
||||
AutoJs.getInstance().getScriptEngineService().execute(new StringScriptSource(file.name, AssetsCache.get(context.getAssets(), file.path)));
|
||||
}
|
||||
|
||||
public static ScriptExecution runOnEditView(ScriptSource scriptSource) {
|
||||
return AutoJs.getInstance().getScriptEngineService().execute(scriptSource, RUN_ON_EDIT_VIEW_SCRIPT_EXECUTION_LISTENER);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package com.stardust.scriptdroid.ui.main.sample_list;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -10,13 +9,11 @@ import android.view.ViewGroup;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.app.Fragment;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.scripts.sample.Sample;
|
||||
import com.stardust.scriptdroid.scripts.sample.SampleFileManager;
|
||||
import com.stardust.scriptdroid.script.Scripts;
|
||||
import com.stardust.scriptdroid.script.sample.Sample;
|
||||
import com.stardust.scriptdroid.script.sample.SampleFileManager;
|
||||
import com.stardust.scriptdroid.ui.edit.ViewSampleActivity;
|
||||
import com.stardust.scriptdroid.ui.main.MainActivity;
|
||||
import com.stardust.scriptdroid.ui.main.operation.ScriptFileOperation;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/3/13.
|
||||
@@ -59,7 +56,7 @@ public class SampleScriptListFragment extends Fragment {
|
||||
@Override
|
||||
public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
|
||||
if (position == 0) {
|
||||
ScriptFileOperation.run(getActivity(), sample);
|
||||
Scripts.run(getActivity(), sample);
|
||||
} else {
|
||||
copySampleToMyScripts(sample);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.stardust.scriptdroid.ui.main.sample_list;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.DividerItemDecoration;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -17,7 +16,7 @@ import com.bignerdranch.expandablerecyclerview.ExpandableRecyclerAdapter;
|
||||
import com.bignerdranch.expandablerecyclerview.ParentViewHolder;
|
||||
import com.bignerdranch.expandablerecyclerview.model.Parent;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.scripts.sample.Sample;
|
||||
import com.stardust.scriptdroid.script.sample.Sample;
|
||||
import com.stardust.widget.LevelBeamView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -87,9 +86,9 @@ public class SampleScriptListRecyclerView extends RecyclerView {
|
||||
mOnItemClickListener = onItemClickListener;
|
||||
}
|
||||
|
||||
public void setSamples(List<com.stardust.scriptdroid.scripts.sample.SampleGroup> samples) {
|
||||
public void setSamples(List<com.stardust.scriptdroid.script.sample.SampleGroup> samples) {
|
||||
mSampleGroups.clear();
|
||||
for (com.stardust.scriptdroid.scripts.sample.SampleGroup sampleGroup : samples) {
|
||||
for (com.stardust.scriptdroid.script.sample.SampleGroup sampleGroup : samples) {
|
||||
mSampleGroups.add(new SampleGroup(sampleGroup));
|
||||
}
|
||||
mAdapter = new Adapter(mSampleGroups);
|
||||
@@ -103,9 +102,9 @@ public class SampleScriptListRecyclerView extends RecyclerView {
|
||||
|
||||
private class SampleGroup implements Parent<Sample> {
|
||||
|
||||
private com.stardust.scriptdroid.scripts.sample.SampleGroup mSampleGroup;
|
||||
private com.stardust.scriptdroid.script.sample.SampleGroup mSampleGroup;
|
||||
|
||||
SampleGroup(com.stardust.scriptdroid.scripts.sample.SampleGroup sampleGroup) {
|
||||
SampleGroup(com.stardust.scriptdroid.script.sample.SampleGroup sampleGroup) {
|
||||
mSampleGroup = sampleGroup;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.text.InputType;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -14,12 +13,12 @@ import android.widget.EditText;
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.app.Fragment;
|
||||
import com.stardust.scriptdroid.scripts.ScriptFile;
|
||||
import com.stardust.scriptdroid.script.ScriptFile;
|
||||
import com.stardust.pio.PFile;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.scripts.StorageScriptProvider;
|
||||
import com.stardust.scriptdroid.script.Scripts;
|
||||
import com.stardust.scriptdroid.script.StorageScriptProvider;
|
||||
import com.stardust.scriptdroid.ui.edit.EditActivity;
|
||||
import com.stardust.scriptdroid.ui.main.operation.ScriptFileOperation;
|
||||
import com.stardust.theme.dialog.ThemeColorMaterialDialogBuilder;
|
||||
import com.stardust.view.ViewBinder;
|
||||
import com.stardust.view.ViewBinding;
|
||||
@@ -142,7 +141,7 @@ public class MyScriptListFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
notifyScriptFileChanged();
|
||||
ScriptFileOperation.edit(new ScriptFile(path));
|
||||
Scripts.edit(path);
|
||||
} else {
|
||||
Snackbar.make(getView(), R.string.text_create_fail, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
@@ -255,7 +254,7 @@ public class MyScriptListFragment extends Fragment {
|
||||
@ViewBinding.Click(R.id.open_by_other_apps)
|
||||
private void openByOtherApps() {
|
||||
dismissDialogs();
|
||||
ScriptFileOperation.openByOtherApps(mSelectedScriptFile.getPath());
|
||||
Scripts.openByOtherApps(mSelectedScriptFile);
|
||||
onScriptFileOperated();
|
||||
}
|
||||
|
||||
@@ -272,7 +271,7 @@ public class MyScriptListFragment extends Fragment {
|
||||
@ViewBinding.Click(R.id.create_shortcut)
|
||||
private void createShortcut() {
|
||||
dismissDialogs();
|
||||
ScriptFileOperation.createShortcut(mSelectedScriptFile);
|
||||
Scripts.createShortcut(mSelectedScriptFile);
|
||||
Snackbar.make(getView(), R.string.text_already_create, Snackbar.LENGTH_SHORT).show();
|
||||
onScriptFileOperated();
|
||||
}
|
||||
|
||||
@@ -10,17 +10,14 @@ import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.workground.WrapContentLinearLayoutManager;
|
||||
|
||||
import com.stardust.autojs.script.FileScriptSource;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.scripts.ScriptFile;
|
||||
import com.stardust.scriptdroid.script.ScriptFile;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.scripts.StorageScriptProvider;
|
||||
import com.stardust.scriptdroid.ui.main.operation.ScriptFileOperation;
|
||||
import com.stardust.scriptdroid.script.Scripts;
|
||||
import com.stardust.scriptdroid.script.StorageScriptProvider;
|
||||
import com.stardust.widget.ViewHolderMutableAdapter;
|
||||
import com.stardust.widget.ViewHolderSupplier;
|
||||
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;
|
||||
@@ -111,7 +108,7 @@ public class ScriptAndFolderListRecyclerView extends RecyclerView {
|
||||
public void onClick(View v) {
|
||||
int position = getChildViewHolder((View) v.getParent()).getAdapterPosition();
|
||||
ScriptFile file = mAdapter.getScriptFileAt(position);
|
||||
ScriptFileOperation.run(file);
|
||||
Scripts.run(file);
|
||||
}
|
||||
};
|
||||
private final ViewHolderSupplier<ViewHolder> mDefaultViewHolderSupplier = new ViewHolderSupplier<ViewHolder>() {
|
||||
|
||||
@@ -4,8 +4,8 @@ import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.scriptdroid.scripts.ScriptFile;
|
||||
import com.stardust.scriptdroid.scripts.StorageScriptProvider;
|
||||
import com.stardust.scriptdroid.script.ScriptFile;
|
||||
import com.stardust.scriptdroid.script.StorageScriptProvider;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/3.
|
||||
|
||||
@@ -13,8 +13,8 @@ import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.scripts.ScriptFile;
|
||||
import com.stardust.scriptdroid.scripts.StorageScriptProvider;
|
||||
import com.stardust.scriptdroid.script.ScriptFile;
|
||||
import com.stardust.scriptdroid.script.StorageScriptProvider;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/3.
|
||||
|
||||
@@ -16,7 +16,7 @@ import android.widget.Toast;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.scriptdroid.BuildConfig;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.scripts.StorageScriptProvider;
|
||||
import com.stardust.scriptdroid.script.StorageScriptProvider;
|
||||
import com.stardust.scriptdroid.tool.IntentTool;
|
||||
import com.stardust.scriptdroid.tool.UpdateChecker;
|
||||
import com.stardust.util.DownloadTask;
|
||||
|
||||
Reference in New Issue
Block a user