add script running repleatedly support, change min sdk version to 17
This commit is contained in:
@@ -7,7 +7,7 @@ android {
|
||||
buildToolsVersion "25.0.2"
|
||||
defaultConfig {
|
||||
applicationId "com.stardust.scriptdroid"
|
||||
minSdkVersion 19
|
||||
minSdkVersion 17
|
||||
targetSdkVersion 23
|
||||
versionCode 143
|
||||
versionName "2.0.13 Beta2"
|
||||
|
||||
@@ -111,4 +111,12 @@ public class Scripts {
|
||||
return AutoJs.getInstance().getScriptEngineService().execute(source, BROADCAST_SENDER_SCRIPT_EXECUTION_LISTENER,
|
||||
new ExecutionConfig().requirePath(StorageScriptProvider.DEFAULT_DIRECTORY_PATH));
|
||||
}
|
||||
|
||||
public static ScriptExecution runRepeatedly(ScriptFile scriptFile, int loopTimes, long delay, long interval) {
|
||||
ScriptSource source = new FileScriptSource(scriptFile);
|
||||
String directoryPath = scriptFile.getParent();
|
||||
return AutoJs.getInstance().getScriptEngineService().execute(source, new ExecutionConfig()
|
||||
.requirePath(directoryPath, StorageScriptProvider.DEFAULT_DIRECTORY_PATH)
|
||||
.loop(delay, loopTimes, interval));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.stardust.scriptdroid.ui.common;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.TextInputEditText;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.script.ScriptFile;
|
||||
import com.stardust.scriptdroid.script.Scripts;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/7/8.
|
||||
*/
|
||||
|
||||
public class ScriptLoopDialog {
|
||||
|
||||
private ScriptFile mScriptFile;
|
||||
private MaterialDialog mDialog;
|
||||
|
||||
@BindView(R.id.loop_times)
|
||||
TextInputEditText mLoopTimes;
|
||||
|
||||
@BindView(R.id.loop_interval)
|
||||
TextInputEditText mLoopInterval;
|
||||
|
||||
@BindView(R.id.loop_delay)
|
||||
TextInputEditText mLoopDelay;
|
||||
|
||||
|
||||
public ScriptLoopDialog(Context context, ScriptFile file) {
|
||||
mScriptFile = file;
|
||||
View view = View.inflate(context, R.layout.dialog_script_loop, null);
|
||||
mDialog = new MaterialDialog.Builder(context)
|
||||
.title(R.string.text_run_repeatedly)
|
||||
.customView(view, false)
|
||||
.positiveText(R.string.ok)
|
||||
.onPositive(new MaterialDialog.SingleButtonCallback() {
|
||||
@Override
|
||||
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
|
||||
startScriptRunningLoop();
|
||||
}
|
||||
})
|
||||
.build();
|
||||
ButterKnife.bind(this, view);
|
||||
}
|
||||
|
||||
private void startScriptRunningLoop() {
|
||||
int loopTimes = Integer.parseInt(mLoopTimes.getText().toString());
|
||||
float loopInterval = Float.parseFloat(mLoopInterval.getText().toString());
|
||||
float loopDelay = Float.parseFloat(mLoopDelay.getText().toString());
|
||||
Scripts.runRepeatedly(mScriptFile, loopTimes, (long) (1000L * loopDelay), (long) (loopInterval * 1000L));
|
||||
}
|
||||
|
||||
public ScriptLoopDialog windowType(int windowType) {
|
||||
Window window = mDialog.getWindow();
|
||||
if (window != null) {
|
||||
window.setType(windowType);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void show() {
|
||||
mDialog.show();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import com.stardust.pio.PFile;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.script.Scripts;
|
||||
import com.stardust.scriptdroid.script.StorageScriptProvider;
|
||||
import com.stardust.scriptdroid.ui.common.ScriptLoopDialog;
|
||||
import com.stardust.scriptdroid.ui.edit.EditActivity;
|
||||
import com.stardust.theme.dialog.ThemeColorMaterialDialogBuilder;
|
||||
import com.stardust.util.UnderuseExecutors;
|
||||
@@ -106,6 +107,7 @@ public class MyScriptListFragment extends Fragment {
|
||||
|
||||
private void initDialogs() {
|
||||
mScriptFileOperationDialog = new OperationDialogBuilder(getContext())
|
||||
.item(R.id.loop, R.drawable.ic_loop_white_24dp, R.string.text_run_repeatedly)
|
||||
.item(R.id.rename, R.drawable.ic_ali_rename, R.string.text_rename)
|
||||
.item(R.id.open_by_other_apps, R.drawable.ic_ali_open, R.string.text_open_by_other_apps)
|
||||
.item(R.id.create_shortcut, R.drawable.ic_ali_shortcut, R.string.text_send_shortcut)
|
||||
@@ -228,6 +230,14 @@ public class MyScriptListFragment extends Fragment {
|
||||
});
|
||||
}
|
||||
|
||||
@Optional
|
||||
@OnClick(R.id.loop)
|
||||
void runScriptRepeatedly() {
|
||||
dismissDialogs();
|
||||
new ScriptLoopDialog(getActivity(), mSelectedScriptFile)
|
||||
.show();
|
||||
}
|
||||
|
||||
@Optional
|
||||
@OnClick(R.id.rename)
|
||||
void renameScriptFile() {
|
||||
|
||||
BIN
app/src/main/res/drawable-hdpi/ic_loop_white_24dp.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_loop_white_24dp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 387 B |
BIN
app/src/main/res/drawable-mdpi/ic_loop_white_24dp.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_loop_white_24dp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 261 B |
BIN
app/src/main/res/drawable-xhdpi/ic_loop_white_24dp.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_loop_white_24dp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 494 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_loop_white_24dp.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_loop_white_24dp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 734 B |
BIN
app/src/main/res/drawable-xxxhdpi/ic_loop_white_24dp.png
Normal file
BIN
app/src/main/res/drawable-xxxhdpi/ic_loop_white_24dp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 933 B |
@@ -1,60 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/rename"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingLeft="24dp"
|
||||
android:paddingTop="16dp">
|
||||
|
||||
<com.stardust.theme.widget.ThemeColorImageViewCompat
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:src="@drawable/ic_ali_rename"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/text_rename"
|
||||
android:textColor="@android:color/primary_text_light"
|
||||
android:textSize="16sp"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/delete"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingLeft="24dp"
|
||||
android:paddingTop="16dp">
|
||||
|
||||
<com.stardust.theme.widget.ThemeColorImageViewCompat
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:src="@drawable/ic_ali_delete"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/text_delete"
|
||||
android:textColor="@android:color/primary_text_light"
|
||||
android:textSize="16sp"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
@@ -1,112 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/rename"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingLeft="24dp"
|
||||
android:paddingTop="16dp">
|
||||
|
||||
<com.stardust.theme.widget.ThemeColorImageViewCompat
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:src="@drawable/ic_ali_rename"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/text_rename"
|
||||
android:textColor="@android:color/primary_text_light"
|
||||
android:textSize="16sp"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/open_by_other_apps"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingLeft="24dp"
|
||||
android:paddingTop="16dp">
|
||||
|
||||
<com.stardust.theme.widget.ThemeColorImageViewCompat
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:src="@drawable/ic_ali_open"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/text_open_by_other_apps"
|
||||
android:textColor="@android:color/primary_text_light"
|
||||
android:textSize="16sp"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/create_shortcut"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingLeft="24dp"
|
||||
android:paddingTop="16dp">
|
||||
|
||||
<com.stardust.theme.widget.ThemeColorImageViewCompat
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:src="@drawable/ic_ali_shortcut"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/text_send_shortcut"
|
||||
android:textColor="@android:color/primary_text_light"
|
||||
android:textSize="16sp"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/delete"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingLeft="24dp"
|
||||
android:paddingTop="16dp">
|
||||
|
||||
<com.stardust.theme.widget.ThemeColorImageViewCompat
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:src="@drawable/ic_ali_delete"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/text_delete"
|
||||
android:textColor="@android:color/primary_text_light"
|
||||
android:textSize="16sp"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
73
app/src/main/res/layout/dialog_script_loop.xml
Normal file
73
app/src/main/res/layout/dialog_script_loop.xml
Normal file
@@ -0,0 +1,73 @@
|
||||
<?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:orientation="vertical"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp">
|
||||
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
android:id="@+id/loop_times"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/text_loop_times"
|
||||
android:inputType="number"
|
||||
android:text="0"
|
||||
tools:ignore="HardcodedText"/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:text="@string/hint_loop_times"
|
||||
android:textColor="#77000000"
|
||||
android:textSize="12sp"/>
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
android:id="@+id/loop_interval"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/text_loop_interval"
|
||||
android:inputType="numberDecimal"
|
||||
android:text="1.0"
|
||||
tools:ignore="HardcodedText"/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
android:id="@+id/loop_delay"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/text_loop_delay"
|
||||
android:inputType="numberDecimal"
|
||||
android:text="0.0"
|
||||
tools:ignore="HardcodedText"/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:text="@string/hint_loop_delay"
|
||||
android:textColor="#77000000"
|
||||
android:textSize="12sp"/>
|
||||
</LinearLayout>
|
||||
8
app/src/main/res/values/ids.xml
Normal file
8
app/src/main/res/values/ids.xml
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<item name="rename" type="id"/>
|
||||
<item name="open_by_other_apps" type="id"/>
|
||||
<item name="create_shortcut" type="id"/>
|
||||
<item name="delete" type="id"/>
|
||||
<item name="loop" type="id"/>
|
||||
</resources>
|
||||
@@ -198,6 +198,12 @@
|
||||
<string name="text_ad_showing_settings">广告显示设置</string>
|
||||
<string name="text_default">Default</string>
|
||||
<string name="text_script_save_successfully">保存成功,请刷新目录</string>
|
||||
<string name="text_run_repeatedly">循环运行</string>
|
||||
<string name="text_loop_interval">循环间隔(秒)</string>
|
||||
<string name="text_loop_delay">延迟执行(秒)</string>
|
||||
<string name="text_loop_times">循环次数</string>
|
||||
<string name="hint_loop_times">0为无限循环</string>
|
||||
<string name="hint_loop_delay">延迟多少秒后开始循环</string>
|
||||
|
||||
<string-array name="record_control_keys">
|
||||
<item>无</item>
|
||||
|
||||
@@ -5,7 +5,7 @@ android {
|
||||
buildToolsVersion "25.0.2"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 19
|
||||
minSdkVersion 17
|
||||
targetSdkVersion 25
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
@@ -9,6 +9,9 @@ public class ExecutionConfig implements Serializable {
|
||||
|
||||
private String[] mRequirePath = new String[0];
|
||||
private static final ExecutionConfig DEFAULT = new ExecutionConfig();
|
||||
public long delay = 0;
|
||||
public long interval = 0;
|
||||
public int loopTimes = 1;
|
||||
|
||||
public static ExecutionConfig getDefault() {
|
||||
return DEFAULT;
|
||||
@@ -29,4 +32,11 @@ public class ExecutionConfig implements Serializable {
|
||||
public String[] getRequirePath() {
|
||||
return mRequirePath;
|
||||
}
|
||||
|
||||
public ExecutionConfig loop(long delay, int loopTimes, long interval) {
|
||||
this.delay = delay;
|
||||
this.loopTimes = loopTimes;
|
||||
this.interval = interval;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.util.Log;
|
||||
import com.stardust.autojs.ScriptEngineService;
|
||||
import com.stardust.autojs.engine.RhinoJavaScriptEngine;
|
||||
import com.stardust.autojs.engine.ScriptEngine;
|
||||
import com.stardust.autojs.runtime.ScriptInterruptedException;
|
||||
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||
import com.stardust.autojs.script.ScriptSource;
|
||||
|
||||
@@ -61,11 +62,34 @@ public class RunnableScriptExecution extends ScriptExecution.AbstractScriptExecu
|
||||
private Object doExecution(ScriptEngine engine) {
|
||||
engine.setTag("script", getSource());
|
||||
getListener().onStart(this);
|
||||
Object result = engine.execute(getSource());
|
||||
Object result = null;
|
||||
long delay = getConfig().delay;
|
||||
int times = getConfig().loopTimes;
|
||||
if (times == 0) {
|
||||
times = Integer.MAX_VALUE;
|
||||
}
|
||||
long interval = getConfig().interval;
|
||||
sleep(delay);
|
||||
ScriptSource source = getSource();
|
||||
for (int i = 0; i < times; i++) {
|
||||
result = engine.execute(source);
|
||||
sleep(interval);
|
||||
}
|
||||
getListener().onSuccess(this, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void sleep(long i) {
|
||||
if (i <= 0) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(i);
|
||||
} catch (InterruptedException e) {
|
||||
throw new ScriptInterruptedException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScriptEngine getEngine() {
|
||||
return mScriptEngine;
|
||||
|
||||
@@ -5,7 +5,7 @@ android {
|
||||
buildToolsVersion "25.0.2"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 19
|
||||
minSdkVersion 17
|
||||
targetSdkVersion 25
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
@@ -31,7 +31,6 @@ dependencies {
|
||||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
|
||||
exclude group: 'com.android.support', module: 'support-annotations'
|
||||
})
|
||||
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
|
||||
testCompile 'junit:junit:4.12'
|
||||
compile 'com.android.support:appcompat-v7:25.3.1'
|
||||
compile project(path: ':common')
|
||||
|
||||
@@ -5,7 +5,7 @@ android {
|
||||
buildToolsVersion "25.0.2"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 19
|
||||
minSdkVersion 17
|
||||
targetSdkVersion 25
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
@@ -6,7 +6,7 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.stardust.auojs.inrt"
|
||||
minSdkVersion 19
|
||||
minSdkVersion 17
|
||||
targetSdkVersion 23
|
||||
versionCode 1
|
||||
versionName "0.0.1"
|
||||
|
||||
Reference in New Issue
Block a user