feat: intent task
This commit is contained in:
@@ -164,6 +164,14 @@
|
|||||||
<action android:name="android.intent.action.USER_PRESENT"/>
|
<action android:name="android.intent.action.USER_PRESENT"/>
|
||||||
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
|
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.PACKAGE_ADDED"/>
|
||||||
|
<action android:name="android.intent.action.PACKAGE_CHANGED"/>
|
||||||
|
<action android:name="android.intent.action.PACKAGE_DATA_CLEARED"/>
|
||||||
|
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
|
||||||
|
<action android:name="android.intent.action.PACKAGE_RESTARTED"/>
|
||||||
|
<data android:scheme="package"/>
|
||||||
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.autojs.autojs;
|
package org.autojs.autojs;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
@@ -21,15 +22,16 @@ import com.tencent.bugly.crashreport.CrashReport;
|
|||||||
|
|
||||||
import org.autojs.autojs.autojs.AutoJs;
|
import org.autojs.autojs.autojs.AutoJs;
|
||||||
import org.autojs.autojs.autojs.key.GlobalKeyObserver;
|
import org.autojs.autojs.autojs.key.GlobalKeyObserver;
|
||||||
import org.autojs.autojs.external.receiver.DynamicBroadcastReceiver;
|
import org.autojs.autojs.external.receiver.DynamicBroadcastReceivers;
|
||||||
import org.autojs.autojs.network.GlideApp;
|
import org.autojs.autojs.network.GlideApp;
|
||||||
import org.autojs.autojs.storage.database.IntentTaskDatabase;
|
import org.autojs.autojs.timing.IntentTask;
|
||||||
import org.autojs.autojs.storage.database.TimedTaskDatabase;
|
import org.autojs.autojs.timing.TimedTaskManager;
|
||||||
import org.autojs.autojs.timing.TimedTaskScheduler;
|
import org.autojs.autojs.timing.TimedTaskScheduler;
|
||||||
import org.autojs.autojs.tool.CrashHandler;
|
import org.autojs.autojs.tool.CrashHandler;
|
||||||
import org.autojs.autojs.ui.error.ErrorReportActivity;
|
import org.autojs.autojs.ui.error.ErrorReportActivity;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/1/27.
|
* Created by Stardust on 2017/1/27.
|
||||||
@@ -41,7 +43,7 @@ public class App extends MultiDexApplication {
|
|||||||
private static final String BUGLY_APP_ID = "19b3607b53";
|
private static final String BUGLY_APP_ID = "19b3607b53";
|
||||||
|
|
||||||
private static WeakReference<App> instance;
|
private static WeakReference<App> instance;
|
||||||
private DynamicBroadcastReceiver mDynamicBroadcastReceiver;
|
private DynamicBroadcastReceivers mDynamicBroadcastReceivers;
|
||||||
|
|
||||||
public static App getApp() {
|
public static App getApp() {
|
||||||
return instance.get();
|
return instance.get();
|
||||||
@@ -56,6 +58,10 @@ public class App extends MultiDexApplication {
|
|||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DynamicBroadcastReceivers getDynamicBroadcastReceivers() {
|
||||||
|
return mDynamicBroadcastReceivers;
|
||||||
|
}
|
||||||
|
|
||||||
private void setUpStaticsTool() {
|
private void setUpStaticsTool() {
|
||||||
if (BuildConfig.DEBUG)
|
if (BuildConfig.DEBUG)
|
||||||
return;
|
return;
|
||||||
@@ -98,7 +104,18 @@ public class App extends MultiDexApplication {
|
|||||||
}
|
}
|
||||||
setupDrawableImageLoader();
|
setupDrawableImageLoader();
|
||||||
TimedTaskScheduler.checkTasksRepeatedlyIfNeeded(this);
|
TimedTaskScheduler.checkTasksRepeatedlyIfNeeded(this);
|
||||||
mDynamicBroadcastReceiver = new DynamicBroadcastReceiver(this);
|
initDynamicBroadcastReceivers();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("CheckResult")
|
||||||
|
private void initDynamicBroadcastReceivers() {
|
||||||
|
mDynamicBroadcastReceivers = new DynamicBroadcastReceivers(this);
|
||||||
|
TimedTaskManager.getInstance().getAllIntentTasks()
|
||||||
|
.filter(task -> task.getAction() != null)
|
||||||
|
.map(IntentTask::getAction)
|
||||||
|
.collectInto(new ArrayList<String>(), ArrayList::add)
|
||||||
|
.subscribe(list -> mDynamicBroadcastReceivers.register(list),
|
||||||
|
Throwable::printStackTrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupDrawableImageLoader() {
|
private void setupDrawableImageLoader() {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
|
|||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ public class BaseBroadcastReceiver extends BroadcastReceiver {
|
|||||||
|
|
||||||
@SuppressLint("CheckResult")
|
@SuppressLint("CheckResult")
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
Log.d(LOG_TAG, "onReceive: action = " + intent.getAction() + ", intent = " + intent);
|
Log.d(LOG_TAG, "onReceive: intent = " + intent + ", this = " + this);
|
||||||
try {
|
try {
|
||||||
TimedTaskManager.getInstance().getIntentTaskOfAction(intent.getAction())
|
TimedTaskManager.getInstance().getIntentTaskOfAction(intent.getAction())
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
|
|||||||
@@ -1,41 +1,31 @@
|
|||||||
package org.autojs.autojs.external.receiver;
|
package org.autojs.autojs.external.receiver;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.media.AudioManager;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
import org.autojs.autojs.BuildConfig;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static android.content.Intent.ACTION_BATTERY_CHANGED;
|
import static android.content.Intent.ACTION_BATTERY_CHANGED;
|
||||||
import static android.content.Intent.ACTION_CONFIGURATION_CHANGED;
|
import static android.content.Intent.ACTION_CONFIGURATION_CHANGED;
|
||||||
import static android.content.Intent.ACTION_DATE_CHANGED;
|
|
||||||
import static android.content.Intent.ACTION_PACKAGES_SUSPENDED;
|
import static android.content.Intent.ACTION_PACKAGES_SUSPENDED;
|
||||||
import static android.content.Intent.ACTION_PACKAGES_UNSUSPENDED;
|
import static android.content.Intent.ACTION_PACKAGES_UNSUSPENDED;
|
||||||
import static android.content.Intent.ACTION_PACKAGE_ADDED;
|
import static android.content.Intent.ACTION_SCREEN_OFF;
|
||||||
import static android.content.Intent.ACTION_PACKAGE_CHANGED;
|
import static android.content.Intent.ACTION_SCREEN_ON;
|
||||||
import static android.content.Intent.ACTION_PACKAGE_DATA_CLEARED;
|
|
||||||
import static android.content.Intent.ACTION_PACKAGE_REMOVED;
|
|
||||||
import static android.content.Intent.ACTION_PACKAGE_RESTARTED;
|
|
||||||
import static android.content.Intent.ACTION_POWER_CONNECTED;
|
|
||||||
import static android.content.Intent.ACTION_POWER_DISCONNECTED;
|
|
||||||
import static android.content.Intent.ACTION_SHUTDOWN;
|
|
||||||
import static android.content.Intent.ACTION_TIMEZONE_CHANGED;
|
|
||||||
import static android.content.Intent.ACTION_TIME_CHANGED;
|
|
||||||
import static android.content.Intent.ACTION_TIME_TICK;
|
import static android.content.Intent.ACTION_TIME_TICK;
|
||||||
import static android.content.Intent.ACTION_UID_REMOVED;
|
|
||||||
|
|
||||||
public class DynamicBroadcastReceiver extends BaseBroadcastReceiver {
|
public class DynamicBroadcastReceivers {
|
||||||
|
|
||||||
private static final List<String> DEFAULT_ACTIONS = new ArrayList<>(Arrays.asList(
|
private static final List<String> DEFAULT_ACTIONS = new ArrayList<>(Arrays.asList(
|
||||||
ACTION_TIME_TICK,
|
ACTION_TIME_TICK,
|
||||||
|
ACTION_SCREEN_OFF,
|
||||||
|
ACTION_SCREEN_ON,
|
||||||
ACTION_BATTERY_CHANGED,
|
ACTION_BATTERY_CHANGED,
|
||||||
ACTION_CONFIGURATION_CHANGED
|
ACTION_CONFIGURATION_CHANGED
|
||||||
));
|
));
|
||||||
@@ -49,31 +39,40 @@ public class DynamicBroadcastReceiver extends BaseBroadcastReceiver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean mRegistered = false;
|
|
||||||
private final Set<String> mActions = new LinkedHashSet<>();
|
private final Set<String> mActions = new LinkedHashSet<>();
|
||||||
|
private final List<BroadcastReceiver> mReceivers = new ArrayList<>();
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
|
|
||||||
public DynamicBroadcastReceiver(Context context) {
|
public DynamicBroadcastReceivers(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
register(DEFAULT_ACTIONS);
|
register(DEFAULT_ACTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(List<String> actions) {
|
public void register(String action) {
|
||||||
int oldSize = mActions.size();
|
register(Collections.singletonList(action));
|
||||||
mActions.addAll(actions);
|
|
||||||
if (oldSize == mActions.size()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
IntentFilter filter = new IntentFilter();
|
|
||||||
for (String action : mActions) {
|
|
||||||
filter.addAction(action);
|
|
||||||
}
|
|
||||||
if(mRegistered){
|
|
||||||
mContext.unregisterReceiver(this);
|
|
||||||
}
|
|
||||||
mContext.registerReceiver(this, filter);
|
|
||||||
mRegistered = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void register(List<String> actions) {
|
||||||
|
IntentFilter filter = new IntentFilter();
|
||||||
|
for (String action : actions) {
|
||||||
|
if (!StaticBroadcastReceiver.ACTIONS.contains(action)
|
||||||
|
&& !mActions.contains(action)) {
|
||||||
|
mActions.add(action);
|
||||||
|
filter.addAction(action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (filter.countActions() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BaseBroadcastReceiver receiver = new BaseBroadcastReceiver();
|
||||||
|
mContext.registerReceiver(receiver, filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unregisterAll() {
|
||||||
|
for (BroadcastReceiver receiver : mReceivers) {
|
||||||
|
mContext.unregisterReceiver(receiver);
|
||||||
|
}
|
||||||
|
mReceivers.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,6 @@ import static org.autojs.autojs.ui.edit.EditorView.EXTRA_SAVE_ENABLED;
|
|||||||
public class TaskerScriptEditActivity extends BaseActivity {
|
public class TaskerScriptEditActivity extends BaseActivity {
|
||||||
|
|
||||||
public static final int REQUEST_CODE = 10016;
|
public static final int REQUEST_CODE = 10016;
|
||||||
public static final String EXTRA_INTENT_TASK_ID = "intent_task_id";
|
|
||||||
public static final String EXTRA_TASK_ID = TaskReceiver.EXTRA_TASK_ID;
|
public static final String EXTRA_TASK_ID = TaskReceiver.EXTRA_TASK_ID;
|
||||||
|
|
||||||
public static void edit(Activity activity, String title, String summary, String content) {
|
public static void edit(Activity activity, String title, String summary, String content) {
|
||||||
|
|||||||
@@ -12,10 +12,9 @@ import android.util.Pair;
|
|||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.stardust.util.MapEntries;
|
import com.stardust.util.MapBuilder;
|
||||||
|
|
||||||
import org.autojs.autojs.BuildConfig;
|
import org.autojs.autojs.BuildConfig;
|
||||||
import org.autojs.autojs.tool.EmptyObservers;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
@@ -24,7 +23,6 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
|
||||||
import io.reactivex.subjects.PublishSubject;
|
import io.reactivex.subjects.PublishSubject;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
@@ -171,12 +169,12 @@ public class DevPluginService {
|
|||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
private void sayHelloToServer(JsonWebSocket socket) throws IOException {
|
private void sayHelloToServer(JsonWebSocket socket) throws IOException {
|
||||||
writeMap(socket, TYPE_HELLO, new MapEntries<String, Object>()
|
writeMap(socket, TYPE_HELLO, new MapBuilder<String, Object>()
|
||||||
.entry("device_name", Build.BRAND + " " + Build.MODEL)
|
.put("device_name", Build.BRAND + " " + Build.MODEL)
|
||||||
.entry("client_version", CLIENT_VERSION)
|
.put("client_version", CLIENT_VERSION)
|
||||||
.entry("app_version", BuildConfig.VERSION_NAME)
|
.put("app_version", BuildConfig.VERSION_NAME)
|
||||||
.entry("app_version_code", BuildConfig.VERSION_CODE)
|
.put("app_version_code", BuildConfig.VERSION_CODE)
|
||||||
.map());
|
.build());
|
||||||
mHandshakeTimeoutHandler.postDelayed(() -> {
|
mHandshakeTimeoutHandler.postDelayed(() -> {
|
||||||
if (mSocket != socket && !socket.isClosed()) {
|
if (mSocket != socket && !socket.isClosed()) {
|
||||||
onHandshakeTimeout(socket);
|
onHandshakeTimeout(socket);
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ package org.autojs.autojs.timing;
|
|||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.stardust.app.GlobalAppContext;
|
import com.stardust.app.GlobalAppContext;
|
||||||
|
|
||||||
|
import org.autojs.autojs.App;
|
||||||
import org.autojs.autojs.storage.database.IntentTaskDatabase;
|
import org.autojs.autojs.storage.database.IntentTaskDatabase;
|
||||||
import org.autojs.autojs.storage.database.ModelChange;
|
import org.autojs.autojs.storage.database.ModelChange;
|
||||||
import org.autojs.autojs.storage.database.TimedTaskDatabase;
|
import org.autojs.autojs.storage.database.TimedTaskDatabase;
|
||||||
@@ -15,7 +17,6 @@ import java.util.List;
|
|||||||
|
|
||||||
import io.reactivex.Flowable;
|
import io.reactivex.Flowable;
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
import io.reactivex.subjects.PublishSubject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/11/27.
|
* Created by Stardust on 2017/11/27.
|
||||||
@@ -82,7 +83,12 @@ public class TimedTaskManager {
|
|||||||
@SuppressLint("CheckResult")
|
@SuppressLint("CheckResult")
|
||||||
public void addTask(IntentTask intentTask) {
|
public void addTask(IntentTask intentTask) {
|
||||||
mIntentTaskDatabase.insert(intentTask)
|
mIntentTaskDatabase.insert(intentTask)
|
||||||
.subscribe(EmptyObservers.consumer(), Throwable::printStackTrace);
|
.subscribe(i -> {
|
||||||
|
if(!TextUtils.isEmpty(intentTask.getAction())){
|
||||||
|
App.getApp().getDynamicBroadcastReceivers()
|
||||||
|
.register(intentTask.getAction());
|
||||||
|
}
|
||||||
|
}, Throwable::printStackTrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("CheckResult")
|
@SuppressLint("CheckResult")
|
||||||
@@ -128,6 +134,17 @@ public class TimedTaskManager {
|
|||||||
TimedTaskScheduler.scheduleTaskIfNeeded(mContext, task);
|
TimedTaskScheduler.scheduleTaskIfNeeded(mContext, task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("CheckResult")
|
||||||
|
public void updateTask(IntentTask task) {
|
||||||
|
mIntentTaskDatabase.update(task)
|
||||||
|
.subscribe(i -> {
|
||||||
|
if(i > 0 && !TextUtils.isEmpty(task.getAction())){
|
||||||
|
App.getApp().getDynamicBroadcastReceivers()
|
||||||
|
.register(task.getAction());
|
||||||
|
}
|
||||||
|
}, Throwable::printStackTrace);
|
||||||
|
}
|
||||||
|
|
||||||
public long countTasks() {
|
public long countTasks() {
|
||||||
return mTimedTaskDatabase.count();
|
return mTimedTaskDatabase.count();
|
||||||
}
|
}
|
||||||
@@ -139,4 +156,12 @@ public class TimedTaskManager {
|
|||||||
public Observable<ModelChange<IntentTask>> getIntentTaskChanges() {
|
public Observable<ModelChange<IntentTask>> getIntentTaskChanges() {
|
||||||
return mIntentTaskDatabase.getModelChange();
|
return mIntentTaskDatabase.getModelChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IntentTask getIntentTask(long intentTaskId) {
|
||||||
|
return mIntentTaskDatabase.queryById(intentTaskId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Flowable<IntentTask> getAllIntentTasks() {
|
||||||
|
return mIntentTaskDatabase.queryAllAsFlowable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
package org.autojs.autojs.ui.main.task;
|
package org.autojs.autojs.ui.main.task;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
|
||||||
import com.stardust.app.GlobalAppContext;
|
import com.stardust.app.GlobalAppContext;
|
||||||
import com.stardust.autojs.engine.ScriptEngine;
|
import com.stardust.autojs.engine.ScriptEngine;
|
||||||
import com.stardust.autojs.execution.ScriptExecution;
|
import com.stardust.autojs.execution.ScriptExecution;
|
||||||
import com.stardust.autojs.script.AutoFileSource;
|
import com.stardust.autojs.script.AutoFileSource;
|
||||||
import com.stardust.autojs.script.JavaScriptSource;
|
import com.stardust.autojs.script.JavaScriptSource;
|
||||||
import com.stardust.pio.PFiles;
|
import com.stardust.pio.PFiles;
|
||||||
|
import com.stardust.util.MapBuilder;
|
||||||
|
|
||||||
import org.autojs.autojs.R;
|
import org.autojs.autojs.R;
|
||||||
import org.autojs.autojs.timing.IntentTask;
|
import org.autojs.autojs.timing.IntentTask;
|
||||||
@@ -14,12 +17,17 @@ import org.autojs.autojs.timing.TimedTaskManager;
|
|||||||
|
|
||||||
import org.joda.time.format.DateTimeFormat;
|
import org.joda.time.format.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.autojs.autojs.ui.timing.TimedTaskSettingActivity.ACTION_DESC_MAP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/11/28.
|
* Created by Stardust on 2017/11/28.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public abstract class Task {
|
public abstract class Task {
|
||||||
|
|
||||||
|
|
||||||
public abstract String getName();
|
public abstract String getName();
|
||||||
|
|
||||||
public abstract String getDesc();
|
public abstract String getDesc();
|
||||||
@@ -30,6 +38,7 @@ public abstract class Task {
|
|||||||
|
|
||||||
public static class PendingTask extends Task {
|
public static class PendingTask extends Task {
|
||||||
|
|
||||||
|
|
||||||
private TimedTask mTimedTask;
|
private TimedTask mTimedTask;
|
||||||
private IntentTask mIntentTask;
|
private IntentTask mIntentTask;
|
||||||
|
|
||||||
@@ -44,8 +53,8 @@ public abstract class Task {
|
|||||||
mTimedTask = null;
|
mTimedTask = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean taskEquals(Object task){
|
public boolean taskEquals(Object task) {
|
||||||
if(mTimedTask != null){
|
if (mTimedTask != null) {
|
||||||
return mTimedTask.equals(task);
|
return mTimedTask.equals(task);
|
||||||
}
|
}
|
||||||
return mIntentTask.equals(task);
|
return mIntentTask.equals(task);
|
||||||
@@ -68,6 +77,10 @@ public abstract class Task {
|
|||||||
DateTimeFormat.shortDateTime().print(nextTime);
|
DateTimeFormat.shortDateTime().print(nextTime);
|
||||||
} else {
|
} else {
|
||||||
assert mIntentTask != null;
|
assert mIntentTask != null;
|
||||||
|
Integer desc = ACTION_DESC_MAP.get(mIntentTask.getAction());
|
||||||
|
if(desc != null){
|
||||||
|
return GlobalAppContext.getString(desc);
|
||||||
|
}
|
||||||
return mIntentTask.getAction();
|
return mIntentTask.getAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +88,11 @@ public abstract class Task {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
TimedTaskManager.getInstance().removeTask(mTimedTask);
|
if (mTimedTask != null) {
|
||||||
|
TimedTaskManager.getInstance().removeTask(mTimedTask);
|
||||||
|
} else {
|
||||||
|
TimedTaskManager.getInstance().removeTask(mIntentTask);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getScriptPath() {
|
private String getScriptPath() {
|
||||||
@@ -103,6 +120,12 @@ public abstract class Task {
|
|||||||
public void setIntentTask(IntentTask intentTask) {
|
public void setIntentTask(IntentTask intentTask) {
|
||||||
mIntentTask = intentTask;
|
mIntentTask = intentTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
if(mTimedTask != null)
|
||||||
|
return mTimedTask.getId();
|
||||||
|
return mIntentTask.getId();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class RunningTask extends Task {
|
public static class RunningTask extends Task {
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ public abstract class TaskGroup implements Parent<Task> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
|
mTasks.clear();
|
||||||
for (TimedTask timedTask : TimedTaskManager.getInstance().getAllTasksAsList()) {
|
for (TimedTask timedTask : TimedTaskManager.getInstance().getAllTasksAsList()) {
|
||||||
mTasks.add(new Task.PendingTask(timedTask));
|
mTasks.add(new Task.PendingTask(timedTask));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import org.autojs.autojs.timing.IntentTask;
|
|||||||
import org.autojs.autojs.timing.TaskReceiver;
|
import org.autojs.autojs.timing.TaskReceiver;
|
||||||
import org.autojs.autojs.timing.TimedTask;
|
import org.autojs.autojs.timing.TimedTask;
|
||||||
import org.autojs.autojs.timing.TimedTaskManager;
|
import org.autojs.autojs.timing.TimedTaskManager;
|
||||||
|
import org.autojs.autojs.ui.timing.TimedTaskSettingActivity;
|
||||||
import org.autojs.autojs.ui.timing.TimedTaskSettingActivity_;
|
import org.autojs.autojs.ui.timing.TimedTaskSettingActivity_;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -248,8 +249,11 @@ public class TaskListRecyclerView extends ThemeColorRecyclerView {
|
|||||||
|
|
||||||
void onItemClick(View view) {
|
void onItemClick(View view) {
|
||||||
if (mTask instanceof Task.PendingTask) {
|
if (mTask instanceof Task.PendingTask) {
|
||||||
|
Task.PendingTask task = (Task.PendingTask) mTask;
|
||||||
|
String extra = task.getTimedTask() == null ? TimedTaskSettingActivity.EXTRA_INTENT_TASK_ID
|
||||||
|
: TimedTaskSettingActivity.EXTRA_TASK_ID;
|
||||||
TimedTaskSettingActivity_.intent(getContext())
|
TimedTaskSettingActivity_.intent(getContext())
|
||||||
.extra(TaskerScriptEditActivity.EXTRA_TASK_ID, ((Task.PendingTask) mTask).getTimedTask().getId())
|
.extra(extra, task.getId())
|
||||||
.start();
|
.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import android.view.View;
|
|||||||
import com.stardust.theme.app.ColorSelectActivity;
|
import com.stardust.theme.app.ColorSelectActivity;
|
||||||
import com.stardust.theme.preference.ThemeColorPreferenceFragment;
|
import com.stardust.theme.preference.ThemeColorPreferenceFragment;
|
||||||
import com.stardust.theme.util.ListBuilder;
|
import com.stardust.theme.util.ListBuilder;
|
||||||
import com.stardust.util.MapEntries;
|
import com.stardust.util.MapBuilder;
|
||||||
|
|
||||||
import org.androidannotations.annotations.AfterViews;
|
import org.androidannotations.annotations.AfterViews;
|
||||||
import org.androidannotations.annotations.EActivity;
|
import org.androidannotations.annotations.EActivity;
|
||||||
@@ -100,14 +100,14 @@ public class SettingsActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
ACTION_MAP = new MapEntries<String, Runnable>()
|
ACTION_MAP = new MapBuilder<String, Runnable>()
|
||||||
.entry(getString(R.string.text_theme_color), () -> selectThemeColor(getActivity()))
|
.put(getString(R.string.text_theme_color), () -> selectThemeColor(getActivity()))
|
||||||
.entry(getString(R.string.text_check_for_updates), () -> new UpdateCheckDialog(getActivity())
|
.put(getString(R.string.text_check_for_updates), () -> new UpdateCheckDialog(getActivity())
|
||||||
.show())
|
.show())
|
||||||
.entry(getString(R.string.text_issue_report), () -> startActivity(new Intent(getActivity(), IssueReporterActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)))
|
.put(getString(R.string.text_issue_report), () -> startActivity(new Intent(getActivity(), IssueReporterActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)))
|
||||||
.entry(getString(R.string.text_about_me_and_repo), () -> startActivity(new Intent(getActivity(), AboutActivity_.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)))
|
.put(getString(R.string.text_about_me_and_repo), () -> startActivity(new Intent(getActivity(), AboutActivity_.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)))
|
||||||
.entry(getString(R.string.text_licenses), () -> showLicenseDialog())
|
.put(getString(R.string.text_licenses), () -> showLicenseDialog())
|
||||||
.map();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package org.autojs.autojs.ui.timing;
|
|||||||
import android.app.DatePickerDialog;
|
import android.app.DatePickerDialog;
|
||||||
import android.app.TimePickerDialog;
|
import android.app.TimePickerDialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.ColorFilter;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -30,7 +32,7 @@ import com.github.aakira.expandablelayout.ExpandableRelativeLayout;
|
|||||||
import com.stardust.autojs.execution.ExecutionConfig;
|
import com.stardust.autojs.execution.ExecutionConfig;
|
||||||
import com.stardust.util.BiMap;
|
import com.stardust.util.BiMap;
|
||||||
import com.stardust.util.BiMaps;
|
import com.stardust.util.BiMaps;
|
||||||
import com.stardust.util.MapEntries;
|
import com.stardust.util.MapBuilder;
|
||||||
|
|
||||||
import org.androidannotations.annotations.AfterViews;
|
import org.androidannotations.annotations.AfterViews;
|
||||||
import org.androidannotations.annotations.CheckedChange;
|
import org.androidannotations.annotations.CheckedChange;
|
||||||
@@ -61,16 +63,44 @@ import java.util.Map;
|
|||||||
@EActivity(R.layout.activity_timed_task_setting)
|
@EActivity(R.layout.activity_timed_task_setting)
|
||||||
public class TimedTaskSettingActivity extends BaseActivity {
|
public class TimedTaskSettingActivity extends BaseActivity {
|
||||||
|
|
||||||
|
public static final String EXTRA_INTENT_TASK_ID = "intent_task_id";
|
||||||
|
public static final String EXTRA_TASK_ID = TaskReceiver.EXTRA_TASK_ID;
|
||||||
|
|
||||||
private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormat.forPattern("HH:mm");
|
private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormat.forPattern("HH:mm");
|
||||||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormat.forPattern("yy-MM-dd");
|
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormat.forPattern("yy-MM-dd");
|
||||||
private static final int REQUEST_CODE_IGNORE_BATTERY = 27101;
|
private static final int REQUEST_CODE_IGNORE_BATTERY = 27101;
|
||||||
|
|
||||||
private static final String LOG_TAG = "TimedTaskSettings";
|
private static final String LOG_TAG = "TimedTaskSettings";
|
||||||
|
|
||||||
|
|
||||||
|
public static final Map<String, Integer> ACTION_DESC_MAP = new MapBuilder<String, Integer>()
|
||||||
|
.put(Intent.ACTION_BOOT_COMPLETED, R.string.text_run_on_boot)
|
||||||
|
.put(Intent.ACTION_SCREEN_OFF, R.string.text_run_on_screen_off)
|
||||||
|
.put(Intent.ACTION_SCREEN_ON, R.string.text_run_on_screen_on)
|
||||||
|
.put(Intent.ACTION_USER_PRESENT, R.string.text_run_on_screen_unlock)
|
||||||
|
.put(Intent.ACTION_BATTERY_CHANGED, R.string.text_run_on_battery_change)
|
||||||
|
.put(Intent.ACTION_POWER_CONNECTED, R.string.text_run_on_power_connect)
|
||||||
|
.put(Intent.ACTION_POWER_DISCONNECTED, R.string.text_run_on_power_disconnect)
|
||||||
|
.put(ConnectivityManager.CONNECTIVITY_ACTION, R.string.text_run_on_conn_change)
|
||||||
|
.put(Intent.ACTION_PACKAGE_ADDED, R.string.text_run_on_package_install)
|
||||||
|
.put(Intent.ACTION_PACKAGE_REMOVED, R.string.text_run_on_package_uninstall)
|
||||||
|
.put(Intent.ACTION_PACKAGE_REPLACED, R.string.text_run_on_package_update)
|
||||||
|
.put(Intent.ACTION_HEADSET_PLUG, R.string.text_run_on_headset_plug)
|
||||||
|
.build();
|
||||||
|
|
||||||
private static final BiMap<Integer, String> ACTIONS = BiMaps.<Integer, String>newBuilder()
|
private static final BiMap<Integer, String> ACTIONS = BiMaps.<Integer, String>newBuilder()
|
||||||
.put(R.id.run_on_boot, Intent.ACTION_BOOT_COMPLETED)
|
.put(R.id.run_on_boot, Intent.ACTION_BOOT_COMPLETED)
|
||||||
.put(R.id.run_on_screen_off, Intent.ACTION_SCREEN_OFF)
|
.put(R.id.run_on_screen_off, Intent.ACTION_SCREEN_OFF)
|
||||||
.put(R.id.run_on_screen_on, Intent.ACTION_SCREEN_ON)
|
.put(R.id.run_on_screen_on, Intent.ACTION_SCREEN_ON)
|
||||||
|
.put(R.id.run_on_screen_unlock, Intent.ACTION_USER_PRESENT)
|
||||||
|
.put(R.id.run_on_battery_change, Intent.ACTION_BATTERY_CHANGED)
|
||||||
|
.put(R.id.run_on_power_connect, Intent.ACTION_POWER_CONNECTED)
|
||||||
|
.put(R.id.run_on_power_disconnect, Intent.ACTION_POWER_DISCONNECTED)
|
||||||
|
.put(R.id.run_on_conn_change, ConnectivityManager.CONNECTIVITY_ACTION)
|
||||||
|
.put(R.id.run_on_package_install, Intent.ACTION_PACKAGE_ADDED)
|
||||||
|
.put(R.id.run_on_package_uninstall, Intent.ACTION_PACKAGE_REMOVED)
|
||||||
|
.put(R.id.run_on_package_update, Intent.ACTION_PACKAGE_REPLACED)
|
||||||
|
.put(R.id.run_on_headset_plug, Intent.ACTION_HEADSET_PLUG)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
||||||
@@ -90,7 +120,10 @@ public class TimedTaskSettingActivity extends BaseActivity {
|
|||||||
RadioButton mWeeklyTaskRadio;
|
RadioButton mWeeklyTaskRadio;
|
||||||
|
|
||||||
@ViewById(R.id.run_on_broadcast)
|
@ViewById(R.id.run_on_broadcast)
|
||||||
RadioButton mRunOnBroadcast;
|
RadioButton mRunOnBroadcastRadio;
|
||||||
|
|
||||||
|
@ViewById(R.id.run_on_other_broadcast)
|
||||||
|
RadioButton mRunOnOtherBroadcast;
|
||||||
|
|
||||||
@ViewById(R.id.action)
|
@ViewById(R.id.action)
|
||||||
EditText mOtherBroadcastAction;
|
EditText mOtherBroadcastAction;
|
||||||
@@ -117,22 +150,31 @@ public class TimedTaskSettingActivity extends BaseActivity {
|
|||||||
|
|
||||||
private ScriptFile mScriptFile;
|
private ScriptFile mScriptFile;
|
||||||
private TimedTask mTimedTask;
|
private TimedTask mTimedTask;
|
||||||
|
private IntentTask mIntentTask;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
long taskId = getIntent().getLongExtra(TaskReceiver.EXTRA_TASK_ID, -1);
|
long taskId = getIntent().getLongExtra(EXTRA_TASK_ID, -1);
|
||||||
if (taskId != -1) {
|
if (taskId != -1) {
|
||||||
mTimedTask = TimedTaskManager.getInstance().getTimedTask(taskId);
|
mTimedTask = TimedTaskManager.getInstance().getTimedTask(taskId);
|
||||||
if (mTimedTask != null) {
|
if (mTimedTask != null) {
|
||||||
mScriptFile = new ScriptFile(mTimedTask.getScriptPath());
|
mScriptFile = new ScriptFile(mTimedTask.getScriptPath());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String path = getIntent().getStringExtra(ScriptIntents.EXTRA_KEY_PATH);
|
long intentTaskId = getIntent().getLongExtra(EXTRA_INTENT_TASK_ID, -1);
|
||||||
if (TextUtils.isEmpty(path)) {
|
if (intentTaskId != -1) {
|
||||||
finish();
|
mIntentTask = TimedTaskManager.getInstance().getIntentTask(intentTaskId);
|
||||||
|
if (mIntentTask != null) {
|
||||||
|
mScriptFile = new ScriptFile(mIntentTask.getScriptPath());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
String path = getIntent().getStringExtra(ScriptIntents.EXTRA_KEY_PATH);
|
||||||
|
if (TextUtils.isEmpty(path)) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
mScriptFile = new ScriptFile(path);
|
||||||
}
|
}
|
||||||
mScriptFile = new ScriptFile(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -144,7 +186,7 @@ public class TimedTaskSettingActivity extends BaseActivity {
|
|||||||
mToolbar.setSubtitle(mScriptFile.getName());
|
mToolbar.setSubtitle(mScriptFile.getName());
|
||||||
}
|
}
|
||||||
findDayOfWeekCheckBoxes(mWeeklyTaskContainer);
|
findDayOfWeekCheckBoxes(mWeeklyTaskContainer);
|
||||||
setUpTime();
|
setUpTaskSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void findDayOfWeekCheckBoxes(ViewGroup parent) {
|
private void findDayOfWeekCheckBoxes(ViewGroup parent) {
|
||||||
@@ -161,13 +203,32 @@ public class TimedTaskSettingActivity extends BaseActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpTime() {
|
private void setUpTaskSettings() {
|
||||||
mDisposableTaskDate.setText(DATE_FORMATTER.print(LocalDate.now()));
|
mDisposableTaskDate.setText(DATE_FORMATTER.print(LocalDate.now()));
|
||||||
mDisposableTaskTime.setText(TIME_FORMATTER.print(LocalTime.now()));
|
mDisposableTaskTime.setText(TIME_FORMATTER.print(LocalTime.now()));
|
||||||
if (mTimedTask == null) {
|
if (mTimedTask != null) {
|
||||||
mDailyTaskRadio.setChecked(true);
|
setupTime();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (mIntentTask != null) {
|
||||||
|
setupAction();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mDailyTaskRadio.setChecked(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupAction() {
|
||||||
|
mRunOnBroadcastRadio.setChecked(true);
|
||||||
|
Integer buttonId = ACTIONS.getKey(mIntentTask.getAction());
|
||||||
|
if (buttonId == null) {
|
||||||
|
mRunOnOtherBroadcast.setChecked(true);
|
||||||
|
mOtherBroadcastAction.setText(mIntentTask.getAction());
|
||||||
|
} else {
|
||||||
|
((RadioButton) findViewById(buttonId)).setChecked(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupTime() {
|
||||||
if (mTimedTask.isDisposable()) {
|
if (mTimedTask.isDisposable()) {
|
||||||
mDisposableTaskRadio.setChecked(true);
|
mDisposableTaskRadio.setChecked(true);
|
||||||
mDisposableTaskTime.setText(TIME_FORMATTER.print(mTimedTask.getMillis()));
|
mDisposableTaskTime.setText(TIME_FORMATTER.print(mTimedTask.getMillis()));
|
||||||
@@ -187,7 +248,6 @@ public class TimedTaskSettingActivity extends BaseActivity {
|
|||||||
mDayOfWeekCheckBoxes.get(i).setChecked(mTimedTask.hasDayOfWeek(i + 1));
|
mDayOfWeekCheckBoxes.get(i).setChecked(mTimedTask.hasDayOfWeek(i + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -285,7 +345,7 @@ public class TimedTaskSettingActivity extends BaseActivity {
|
|||||||
startActivityForResult(new Intent().setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
|
startActivityForResult(new Intent().setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
|
||||||
.setData(Uri.parse("package:" + getPackageName())), REQUEST_CODE_IGNORE_BATTERY);
|
.setData(Uri.parse("package:" + getPackageName())), REQUEST_CODE_IGNORE_BATTERY);
|
||||||
} else {
|
} else {
|
||||||
createOrUpdateTimedTask();
|
createOrUpdateTask();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -296,14 +356,14 @@ public class TimedTaskSettingActivity extends BaseActivity {
|
|||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (requestCode == REQUEST_CODE_IGNORE_BATTERY) {
|
if (requestCode == REQUEST_CODE_IGNORE_BATTERY) {
|
||||||
Log.d(LOG_TAG, "result code = " + requestCode);
|
Log.d(LOG_TAG, "result code = " + requestCode);
|
||||||
createOrUpdateTimedTask();
|
createOrUpdateTask();
|
||||||
}
|
}
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createOrUpdateTimedTask() {
|
private void createOrUpdateTask() {
|
||||||
if (mRunOnBroadcast.isChecked()) {
|
if (mRunOnBroadcastRadio.isChecked()) {
|
||||||
createIntentTask();
|
createOrUpdateIntentTask();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TimedTask task = createTimedTask();
|
TimedTask task = createTimedTask();
|
||||||
@@ -311,6 +371,9 @@ public class TimedTaskSettingActivity extends BaseActivity {
|
|||||||
return;
|
return;
|
||||||
if (mTimedTask == null) {
|
if (mTimedTask == null) {
|
||||||
TimedTaskManager.getInstance().addTask(task);
|
TimedTaskManager.getInstance().addTask(task);
|
||||||
|
if (mIntentTask != null) {
|
||||||
|
TimedTaskManager.getInstance().removeTask(mIntentTask);
|
||||||
|
}
|
||||||
Toast.makeText(this, R.string.text_already_create, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.text_already_create, Toast.LENGTH_SHORT).show();
|
||||||
} else {
|
} else {
|
||||||
task.setId(mTimedTask.getId());
|
task.setId(mTimedTask.getId());
|
||||||
@@ -320,22 +383,36 @@ public class TimedTaskSettingActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void createIntentTask() {
|
private void createOrUpdateIntentTask() {
|
||||||
int buttonId = mBroadcastGroup.getCheckedRadioButtonId();
|
int buttonId = mBroadcastGroup.getCheckedRadioButtonId();
|
||||||
|
if (buttonId == -1) {
|
||||||
|
Toast.makeText(this, R.string.error_empty_selection, Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
String action;
|
String action;
|
||||||
if(buttonId == R.id.run_on_other_broadcast){
|
if (buttonId == R.id.run_on_other_broadcast) {
|
||||||
action = mOtherBroadcastAction.getText().toString();
|
action = mOtherBroadcastAction.getText().toString();
|
||||||
if(action.isEmpty()){
|
if (action.isEmpty()) {
|
||||||
mOtherBroadcastAction.setError(getString(R.string.text_should_not_be_empty));
|
mOtherBroadcastAction.setError(getString(R.string.text_should_not_be_empty));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
action = ACTIONS.get(buttonId);
|
action = ACTIONS.get(buttonId);
|
||||||
}
|
}
|
||||||
IntentTask task = new IntentTask();
|
IntentTask task = new IntentTask();
|
||||||
task.setAction(action);
|
task.setAction(action);
|
||||||
task.setScriptPath(mScriptFile.getPath());
|
task.setScriptPath(mScriptFile.getPath());
|
||||||
TimedTaskManager.getInstance().addTask(task);
|
if (mIntentTask != null) {
|
||||||
|
task.setId(mIntentTask.getId());
|
||||||
|
TimedTaskManager.getInstance().updateTask(task);
|
||||||
|
Toast.makeText(this, R.string.text_already_create, Toast.LENGTH_SHORT).show();
|
||||||
|
} else {
|
||||||
|
TimedTaskManager.getInstance().addTask(task);
|
||||||
|
if (mTimedTask != null) {
|
||||||
|
TimedTaskManager.getInstance().removeTask(mTimedTask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -303,6 +303,78 @@
|
|||||||
android:paddingLeft="8dp"
|
android:paddingLeft="8dp"
|
||||||
android:text="@string/text_run_on_screen_off"/>
|
android:text="@string/text_run_on_screen_off"/>
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/run_on_screen_unlock"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:paddingLeft="8dp"
|
||||||
|
android:text="@string/text_run_on_screen_unlock"/>
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/run_on_battery_change"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:paddingLeft="8dp"
|
||||||
|
android:text="@string/text_run_on_battery_change"/>
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/run_on_power_connect"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:paddingLeft="8dp"
|
||||||
|
android:text="@string/text_run_on_power_connect"/>
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/run_on_power_disconnect"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:paddingLeft="8dp"
|
||||||
|
android:text="@string/text_run_on_power_disconnect"/>
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/run_on_conn_change"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:paddingLeft="8dp"
|
||||||
|
android:text="@string/text_run_on_conn_change"/>
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/run_on_package_install"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:paddingLeft="8dp"
|
||||||
|
android:text="@string/text_run_on_package_install"/>
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/run_on_package_uninstall"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:paddingLeft="8dp"
|
||||||
|
android:text="@string/text_run_on_package_uninstall"/>
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/run_on_package_update"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:paddingLeft="8dp"
|
||||||
|
android:text="@string/text_run_on_package_update"/>
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/run_on_headset_plug"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:paddingLeft="8dp"
|
||||||
|
android:text="@string/text_run_on_headset_plug"/>
|
||||||
|
|
||||||
<RadioButton
|
<RadioButton
|
||||||
android:id="@+id/run_on_other_broadcast"
|
android:id="@+id/run_on_other_broadcast"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -403,10 +403,20 @@
|
|||||||
<string name="foreground_notification_channel_name">前台服务通知</string>
|
<string name="foreground_notification_channel_name">前台服务通知</string>
|
||||||
<string name="foreground_notification_title">Auto.js保持运行中</string>
|
<string name="foreground_notification_title">Auto.js保持运行中</string>
|
||||||
<string name="foreground_notification_text">点击进入主界面</string>
|
<string name="foreground_notification_text">点击进入主界面</string>
|
||||||
<string name="text_run_on_boot">开机时运行</string>
|
|
||||||
<string name="text_run_on_screen_on">亮屏时运行</string>
|
|
||||||
<string name="text_run_on_screen_off">息屏时运行</string>
|
|
||||||
<string name="text_run_on_other_broadcast">其他事件(广播)</string>
|
<string name="text_run_on_other_broadcast">其他事件(广播)</string>
|
||||||
<string name="text_broadcast_action">广播Action</string>
|
<string name="text_broadcast_action">广播Action</string>
|
||||||
<string name="text_broadcast_action_prefix">android.intent.action.</string>
|
<string name="text_broadcast_action_prefix">android.intent.action.</string>
|
||||||
|
<string name="text_run_on_boot">开机时</string>
|
||||||
|
<string name="text_run_on_screen_on">亮屏时</string>
|
||||||
|
<string name="text_run_on_screen_off">息屏时</string>
|
||||||
|
<string name="error_empty_selection">请选择一个广播事件选项</string>
|
||||||
|
<string name="text_run_on_battery_change">电量变化时</string>
|
||||||
|
<string name="text_run_on_screen_unlock">屏幕解锁时</string>
|
||||||
|
<string name="text_run_on_power_connect">电源连接时</string>
|
||||||
|
<string name="text_run_on_power_disconnect">电源断开时</string>
|
||||||
|
<string name="text_run_on_conn_change">网络连接变化时</string>
|
||||||
|
<string name="text_run_on_package_install">新应用安装时</string>
|
||||||
|
<string name="text_run_on_package_uninstall">应用卸载时</string>
|
||||||
|
<string name="text_run_on_package_update">应用更新时</string>
|
||||||
|
<string name="text_run_on_headset_plug">耳机插拔时</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import com.stardust.autojs.core.eventloop.EventEmitter;
|
|||||||
import com.stardust.autojs.core.looper.Loopers;
|
import com.stardust.autojs.core.looper.Loopers;
|
||||||
import com.stardust.autojs.runtime.ScriptBridges;
|
import com.stardust.autojs.runtime.ScriptBridges;
|
||||||
import com.stardust.autojs.runtime.ScriptRuntime;
|
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||||
import com.stardust.util.MapEntries;
|
import com.stardust.util.MapBuilder;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -59,21 +59,21 @@ public class Sensors extends EventEmitter implements Loopers.LooperQuitHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final Map<String, Integer> SENSORS = new MapEntries<String, Integer>()
|
private static final Map<String, Integer> SENSORS = new MapBuilder<String, Integer>()
|
||||||
.entry("ACCELEROMETER", Sensor.TYPE_ACCELEROMETER)
|
.put("ACCELEROMETER", Sensor.TYPE_ACCELEROMETER)
|
||||||
.entry("MAGNETIC_FIELD", Sensor.TYPE_MAGNETIC_FIELD)
|
.put("MAGNETIC_FIELD", Sensor.TYPE_MAGNETIC_FIELD)
|
||||||
.entry("ORIENTATION", Sensor.TYPE_ORIENTATION)
|
.put("ORIENTATION", Sensor.TYPE_ORIENTATION)
|
||||||
.entry("GYROSCOPE", Sensor.TYPE_GYROSCOPE)
|
.put("GYROSCOPE", Sensor.TYPE_GYROSCOPE)
|
||||||
.entry("LIGHT", Sensor.TYPE_LIGHT)
|
.put("LIGHT", Sensor.TYPE_LIGHT)
|
||||||
.entry("TEMPERATURE", Sensor.TYPE_TEMPERATURE)
|
.put("TEMPERATURE", Sensor.TYPE_TEMPERATURE)
|
||||||
.entry("PRESSURE", Sensor.TYPE_PRESSURE)
|
.put("PRESSURE", Sensor.TYPE_PRESSURE)
|
||||||
.entry("AMBIENT_TEMPERATURE", Sensor.TYPE_AMBIENT_TEMPERATURE)
|
.put("AMBIENT_TEMPERATURE", Sensor.TYPE_AMBIENT_TEMPERATURE)
|
||||||
.entry("PROXIMITY", Sensor.TYPE_PROXIMITY)
|
.put("PROXIMITY", Sensor.TYPE_PROXIMITY)
|
||||||
.entry("GRAVITY", Sensor.TYPE_GRAVITY)
|
.put("GRAVITY", Sensor.TYPE_GRAVITY)
|
||||||
.entry("LINEAR_ACCELERATION", Sensor.TYPE_LINEAR_ACCELERATION)
|
.put("LINEAR_ACCELERATION", Sensor.TYPE_LINEAR_ACCELERATION)
|
||||||
.entry("RELATIVE_HUMIDITY", Sensor.TYPE_RELATIVE_HUMIDITY)
|
.put("RELATIVE_HUMIDITY", Sensor.TYPE_RELATIVE_HUMIDITY)
|
||||||
.entry("AMBIENT_TEMPERATURE", Sensor.TYPE_AMBIENT_TEMPERATURE)
|
.put("AMBIENT_TEMPERATURE", Sensor.TYPE_AMBIENT_TEMPERATURE)
|
||||||
.map();
|
.build();
|
||||||
|
|
||||||
public boolean ignoresUnsupportedSensor = false;
|
public boolean ignoresUnsupportedSensor = false;
|
||||||
public final Delay delay = new Delay();
|
public final Delay delay = new Delay();
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.stardust.autojs.script;
|
|||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import com.stardust.util.MapEntries;
|
import com.stardust.util.MapBuilder;
|
||||||
|
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
@@ -23,10 +23,10 @@ public abstract class JavaScriptSource extends ScriptSource {
|
|||||||
public static final int EXECUTION_MODE_UI = 0x00000001;
|
public static final int EXECUTION_MODE_UI = 0x00000001;
|
||||||
public static final int EXECUTION_MODE_AUTO = 0x00000002;
|
public static final int EXECUTION_MODE_AUTO = 0x00000002;
|
||||||
|
|
||||||
private static final Map<String, Integer> EXECUTION_MODES = new MapEntries<String, Integer>()
|
private static final Map<String, Integer> EXECUTION_MODES = new MapBuilder<String, Integer>()
|
||||||
.entry("ui", EXECUTION_MODE_UI)
|
.put("ui", EXECUTION_MODE_UI)
|
||||||
.entry("auto", EXECUTION_MODE_AUTO)
|
.put("auto", EXECUTION_MODE_AUTO)
|
||||||
.map();
|
.build();
|
||||||
private static final int EXECUTION_MODE_STRING_MAX_LENGTH = 7;
|
private static final int EXECUTION_MODE_STRING_MAX_LENGTH = 7;
|
||||||
|
|
||||||
private int mExecutionMode = -1;
|
private int mExecutionMode = -1;
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
package com.stardust.autojs.script;
|
package com.stardust.autojs.script;
|
||||||
|
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
import com.stardust.util.MapEntries;
|
|
||||||
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.io.StringReader;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/4/2.
|
* Created by Stardust on 2017/4/2.
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import android.support.annotation.RequiresApi;
|
|||||||
import android.view.accessibility.AccessibilityNodeInfo;
|
import android.view.accessibility.AccessibilityNodeInfo;
|
||||||
|
|
||||||
import com.stardust.automator.UiObject;
|
import com.stardust.automator.UiObject;
|
||||||
import com.stardust.util.MapEntries;
|
import com.stardust.util.MapBuilder;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -17,15 +17,15 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class ActionFactory {
|
public class ActionFactory {
|
||||||
|
|
||||||
private static Map<Integer, Object> searchUpAction = new MapEntries<Integer, Object>()
|
private static Map<Integer, Object> searchUpAction = new MapBuilder<Integer, Object>()
|
||||||
.entry(AccessibilityNodeInfo.ACTION_CLICK, null)
|
.put(AccessibilityNodeInfo.ACTION_CLICK, null)
|
||||||
.entry(AccessibilityNodeInfo.ACTION_LONG_CLICK, null)
|
.put(AccessibilityNodeInfo.ACTION_LONG_CLICK, null)
|
||||||
.entry(AccessibilityNodeInfo.ACTION_SELECT, null)
|
.put(AccessibilityNodeInfo.ACTION_SELECT, null)
|
||||||
.entry(AccessibilityNodeInfo.ACTION_FOCUS, null)
|
.put(AccessibilityNodeInfo.ACTION_FOCUS, null)
|
||||||
.entry(AccessibilityNodeInfo.ACTION_SELECT, null)
|
.put(AccessibilityNodeInfo.ACTION_SELECT, null)
|
||||||
.entry(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD, null)
|
.put(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD, null)
|
||||||
.entry(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD, null)
|
.put(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD, null)
|
||||||
.map();
|
.build();
|
||||||
|
|
||||||
public static SimpleAction createActionWithTextFilter(int action, String text, int index) {
|
public static SimpleAction createActionWithTextFilter(int action, String text, int index) {
|
||||||
if (searchUpAction.containsKey(action))
|
if (searchUpAction.containsKey(action))
|
||||||
|
|||||||
@@ -2,30 +2,29 @@ package com.stardust.util;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/1/26.
|
* Created by Stardust on 2017/1/26.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class MapEntries<K, V> {
|
public class MapBuilder<K, V> {
|
||||||
|
|
||||||
private Map<K, V> mMap;
|
private Map<K, V> mMap;
|
||||||
|
|
||||||
public MapEntries() {
|
public MapBuilder() {
|
||||||
this(new HashMap<K, V>());
|
this(new HashMap<K, V>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapEntries(Map<K, V> map) {
|
public MapBuilder(Map<K, V> map) {
|
||||||
mMap = map;
|
mMap = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapEntries<K, V> entry(K key, V value) {
|
public MapBuilder<K, V> put(K key, V value) {
|
||||||
mMap.put(key, value);
|
mMap.put(key, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<K, V> map() {
|
public Map<K, V> build() {
|
||||||
return mMap;
|
return mMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user