新增 定时任务增加Auto.js启动时
This commit is contained in:
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
@@ -139,7 +139,7 @@ dependencies {
|
||||
implementation('com.github.bumptech.glide:glide:4.8.0', {
|
||||
exclude group: 'com.android.support'
|
||||
})
|
||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
|
||||
kapt 'com.github.bumptech.glide:compiler:4.8.0'
|
||||
//joda time
|
||||
implementation 'joda-time:joda-time:2.9.9'
|
||||
// Tasker Plugin
|
||||
|
||||
@@ -1,180 +0,0 @@
|
||||
package org.autojs.autojs;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.usage.UsageStatsManager;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.support.multidex.MultiDexApplication;
|
||||
import android.support.v7.app.AppCompatDelegate;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.flurry.android.FlurryAgent;
|
||||
import com.squareup.leakcanary.LeakCanary;
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.core.ui.inflater.ImageLoader;
|
||||
import com.stardust.autojs.core.ui.inflater.util.Drawables;
|
||||
import com.stardust.theme.ThemeColor;
|
||||
import com.stardust.theme.ThemeColorManager;
|
||||
import com.tencent.bugly.Bugly;
|
||||
import com.tencent.bugly.crashreport.CrashReport;
|
||||
|
||||
import org.autojs.autojs.autojs.AutoJs;
|
||||
import org.autojs.autojs.autojs.key.GlobalKeyObserver;
|
||||
import org.autojs.autojs.external.receiver.DynamicBroadcastReceivers;
|
||||
import org.autojs.autojs.network.GlideApp;
|
||||
import org.autojs.autojs.theme.ThemeColorManagerCompat;
|
||||
import org.autojs.autojs.timing.IntentTask;
|
||||
import org.autojs.autojs.timing.TimedTaskManager;
|
||||
import org.autojs.autojs.timing.TimedTaskScheduler;
|
||||
import org.autojs.autojs.tool.CrashHandler;
|
||||
import org.autojs.autojs.ui.error.ErrorReportActivity;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/1/27.
|
||||
*/
|
||||
|
||||
public class App extends MultiDexApplication {
|
||||
|
||||
private static final String TAG = "App";
|
||||
private static final String BUGLY_APP_ID = "19b3607b53";
|
||||
|
||||
private static WeakReference<App> instance;
|
||||
private DynamicBroadcastReceivers mDynamicBroadcastReceivers;
|
||||
|
||||
public static App getApp() {
|
||||
return instance.get();
|
||||
}
|
||||
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
GlobalAppContext.set(this);
|
||||
instance = new WeakReference<>(this);
|
||||
setUpStaticsTool();
|
||||
setUpDebugEnvironment();
|
||||
init();
|
||||
}
|
||||
|
||||
public DynamicBroadcastReceivers getDynamicBroadcastReceivers() {
|
||||
return mDynamicBroadcastReceivers;
|
||||
}
|
||||
|
||||
private void setUpStaticsTool() {
|
||||
if (BuildConfig.DEBUG)
|
||||
return;
|
||||
new FlurryAgent.Builder()
|
||||
.withLogEnabled(BuildConfig.DEBUG)
|
||||
.build(this, "D42MH48ZN4PJC5TKNYZD");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(base);
|
||||
}
|
||||
|
||||
private void setUpDebugEnvironment() {
|
||||
Bugly.isDev = false;
|
||||
CrashHandler crashHandler = new CrashHandler(ErrorReportActivity.class);
|
||||
|
||||
CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(getApplicationContext());
|
||||
strategy.setCrashHandleCallback(crashHandler);
|
||||
|
||||
CrashReport.initCrashReport(getApplicationContext(), BUGLY_APP_ID, false, strategy);
|
||||
|
||||
crashHandler.setBuglyHandler(Thread.getDefaultUncaughtExceptionHandler());
|
||||
Thread.setDefaultUncaughtExceptionHandler(crashHandler);
|
||||
if (LeakCanary.isInAnalyzerProcess(this)) {
|
||||
// This process is dedicated to LeakCanary for heap analysis.
|
||||
// You should not init your app in this process.
|
||||
return;
|
||||
}
|
||||
//LeakCanary.install(this);
|
||||
|
||||
}
|
||||
|
||||
private void init() {
|
||||
ThemeColorManagerCompat.init(this, new ThemeColor(getResources().getColor(R.color.colorPrimary), getResources().getColor(R.color.colorPrimaryDark), getResources().getColor(R.color.colorAccent)));
|
||||
AutoJs.initInstance(this);
|
||||
if (Pref.isRunningVolumeControlEnabled()) {
|
||||
GlobalKeyObserver.init();
|
||||
}
|
||||
setupDrawableImageLoader();
|
||||
TimedTaskScheduler.checkTasksRepeatedlyIfNeeded(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() {
|
||||
Drawables.setDefaultImageLoader(new ImageLoader() {
|
||||
@Override
|
||||
public void loadInto(ImageView imageView, Uri uri) {
|
||||
GlideApp.with(App.this)
|
||||
.load(uri)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadIntoBackground(View view, Uri uri) {
|
||||
GlideApp.with(App.this)
|
||||
.load(uri)
|
||||
.into(new SimpleTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
|
||||
view.setBackground(resource);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable load(View view, Uri uri) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(View view, Uri uri, DrawableCallback drawableCallback) {
|
||||
GlideApp.with(App.this)
|
||||
.load(uri)
|
||||
.into(new SimpleTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
|
||||
drawableCallback.onLoaded(resource);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(View view, Uri uri, BitmapCallback bitmapCallback) {
|
||||
GlideApp.with(App.this)
|
||||
.asBitmap()
|
||||
.load(uri)
|
||||
.into(new SimpleTarget<Bitmap>() {
|
||||
@Override
|
||||
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
|
||||
bitmapCallback.onLoaded(resource);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
177
app/src/main/java/org/autojs/autojs/App.kt
Normal file
177
app/src/main/java/org/autojs/autojs/App.kt
Normal file
@@ -0,0 +1,177 @@
|
||||
package org.autojs.autojs
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.support.multidex.MultiDexApplication
|
||||
import android.support.v4.content.LocalBroadcastManager
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.request.target.SimpleTarget
|
||||
import com.bumptech.glide.request.transition.Transition
|
||||
import com.flurry.android.FlurryAgent
|
||||
import com.squareup.leakcanary.LeakCanary
|
||||
import com.stardust.app.GlobalAppContext
|
||||
import com.stardust.autojs.core.ui.inflater.ImageLoader
|
||||
import com.stardust.autojs.core.ui.inflater.util.Drawables
|
||||
import com.stardust.theme.ThemeColor
|
||||
import com.tencent.bugly.Bugly
|
||||
import com.tencent.bugly.crashreport.CrashReport
|
||||
import org.autojs.autojs.autojs.AutoJs
|
||||
import org.autojs.autojs.autojs.key.GlobalKeyObserver
|
||||
import org.autojs.autojs.external.receiver.DynamicBroadcastReceivers
|
||||
import org.autojs.autojs.theme.ThemeColorManagerCompat
|
||||
import org.autojs.autojs.timing.TimedTaskManager
|
||||
import org.autojs.autojs.timing.TimedTaskScheduler
|
||||
import org.autojs.autojs.tool.CrashHandler
|
||||
import org.autojs.autojs.ui.error.ErrorReportActivity
|
||||
import java.lang.ref.WeakReference
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/1/27.
|
||||
*/
|
||||
|
||||
class App : MultiDexApplication() {
|
||||
lateinit var dynamicBroadcastReceivers: DynamicBroadcastReceivers
|
||||
private set
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
GlobalAppContext.set(this)
|
||||
instance = WeakReference(this)
|
||||
setUpStaticsTool()
|
||||
setUpDebugEnvironment()
|
||||
init()
|
||||
}
|
||||
|
||||
private fun setUpStaticsTool() {
|
||||
if (BuildConfig.DEBUG)
|
||||
return
|
||||
FlurryAgent.Builder()
|
||||
.withLogEnabled(BuildConfig.DEBUG)
|
||||
.build(this, "D42MH48ZN4PJC5TKNYZD")
|
||||
}
|
||||
|
||||
private fun setUpDebugEnvironment() {
|
||||
Bugly.isDev = false
|
||||
val crashHandler = CrashHandler(ErrorReportActivity::class.java)
|
||||
|
||||
val strategy = CrashReport.UserStrategy(applicationContext)
|
||||
strategy.setCrashHandleCallback(crashHandler)
|
||||
|
||||
CrashReport.initCrashReport(applicationContext, BUGLY_APP_ID, false, strategy)
|
||||
|
||||
crashHandler.setBuglyHandler(Thread.getDefaultUncaughtExceptionHandler())
|
||||
Thread.setDefaultUncaughtExceptionHandler(crashHandler)
|
||||
if (LeakCanary.isInAnalyzerProcess(this)) {
|
||||
// This process is dedicated to LeakCanary for heap analysis.
|
||||
// You should not init your app in this process.
|
||||
return
|
||||
}
|
||||
//LeakCanary.install(this);
|
||||
|
||||
}
|
||||
|
||||
private fun init() {
|
||||
ThemeColorManagerCompat.init(this, ThemeColor(resources.getColor(R.color.colorPrimary), resources.getColor(R.color.colorPrimaryDark), resources.getColor(R.color.colorAccent)))
|
||||
AutoJs.initInstance(this)
|
||||
if (Pref.isRunningVolumeControlEnabled()) {
|
||||
GlobalKeyObserver.init()
|
||||
}
|
||||
setupDrawableImageLoader()
|
||||
TimedTaskScheduler.checkTasksRepeatedlyIfNeeded(this)
|
||||
initDynamicBroadcastReceivers()
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
private fun initDynamicBroadcastReceivers() {
|
||||
dynamicBroadcastReceivers = DynamicBroadcastReceivers(this)
|
||||
val localActions = ArrayList<String>()
|
||||
val actions = ArrayList<String>()
|
||||
TimedTaskManager.getInstance().allIntentTasks
|
||||
.filter { task -> task.action != null }
|
||||
.doOnComplete {
|
||||
if (localActions.isNotEmpty()) {
|
||||
dynamicBroadcastReceivers.register(localActions, true)
|
||||
}
|
||||
if (actions.isNotEmpty()) {
|
||||
dynamicBroadcastReceivers.register(actions, false)
|
||||
}
|
||||
LocalBroadcastManager.getInstance(applicationContext).sendBroadcast(Intent(
|
||||
DynamicBroadcastReceivers.ACTION_STARTUP
|
||||
))
|
||||
}
|
||||
.subscribe({
|
||||
if (it.isLocal) {
|
||||
localActions.add(it.action)
|
||||
} else {
|
||||
actions.add(it.action)
|
||||
}
|
||||
}, { it.printStackTrace() })
|
||||
|
||||
|
||||
}
|
||||
|
||||
private fun setupDrawableImageLoader() {
|
||||
Drawables.setDefaultImageLoader(object : ImageLoader {
|
||||
override fun loadInto(imageView: ImageView, uri: Uri) {
|
||||
Glide.with(imageView)
|
||||
.load(uri)
|
||||
.into(imageView)
|
||||
}
|
||||
|
||||
override fun loadIntoBackground(view: View, uri: Uri) {
|
||||
Glide.with(view)
|
||||
.load(uri)
|
||||
.into(object : SimpleTarget<Drawable>() {
|
||||
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
|
||||
view.background = resource
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun load(view: View, uri: Uri): Drawable {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun load(view: View, uri: Uri, drawableCallback: ImageLoader.DrawableCallback) {
|
||||
Glide.with(view)
|
||||
.load(uri)
|
||||
.into(object : SimpleTarget<Drawable>() {
|
||||
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
|
||||
drawableCallback.onLoaded(resource)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun load(view: View, uri: Uri, bitmapCallback: ImageLoader.BitmapCallback) {
|
||||
Glide.with(view)
|
||||
.asBitmap()
|
||||
.load(uri)
|
||||
.into(object : SimpleTarget<Bitmap>() {
|
||||
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
|
||||
bitmapCallback.onLoaded(resource)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private val TAG = "App"
|
||||
private val BUGLY_APP_ID = "19b3607b53"
|
||||
|
||||
private lateinit var instance: WeakReference<App>
|
||||
|
||||
val app: App
|
||||
get() = instance.get()!!
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -2,14 +2,15 @@ package org.autojs.autojs.external.receiver;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Build;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import org.autojs.autojs.timing.IntentTask;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
@@ -17,15 +18,10 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static android.content.Intent.ACTION_BATTERY_CHANGED;
|
||||
import static android.content.Intent.ACTION_CONFIGURATION_CHANGED;
|
||||
import static android.content.Intent.ACTION_PACKAGES_SUSPENDED;
|
||||
import static android.content.Intent.ACTION_PACKAGES_UNSUSPENDED;
|
||||
import static android.content.Intent.ACTION_SCREEN_OFF;
|
||||
import static android.content.Intent.ACTION_SCREEN_ON;
|
||||
|
||||
public class DynamicBroadcastReceivers {
|
||||
|
||||
public static final String ACTION_STARTUP = "org.autojs.autojs.action.startup";
|
||||
|
||||
private static final String LOG_TAG = "DynBroadcastReceivers";
|
||||
|
||||
private final Set<String> mActions = new LinkedHashSet<>();
|
||||
@@ -43,15 +39,13 @@ public class DynamicBroadcastReceivers {
|
||||
filter.addDataScheme("package");
|
||||
mContext.registerReceiver(mPackageActionReceiver, filter);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void register(String action) {
|
||||
register(Collections.singletonList(action));
|
||||
public void register(IntentTask task) {
|
||||
register(Collections.singletonList(task.getAction()), task.isLocal());
|
||||
}
|
||||
|
||||
public synchronized void register(List<String> actions) {
|
||||
public synchronized void register(List<String> actions, boolean local) {
|
||||
LinkedHashSet<String> newActions = new LinkedHashSet<>();
|
||||
for (String action : actions) {
|
||||
if (!StaticBroadcastReceiver.ACTIONS.contains(action)
|
||||
@@ -63,7 +57,7 @@ public class DynamicBroadcastReceivers {
|
||||
if (newActions.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ReceiverRegistry receiverRegistry = new ReceiverRegistry(newActions);
|
||||
ReceiverRegistry receiverRegistry = new ReceiverRegistry(newActions, local);
|
||||
receiverRegistry.register();
|
||||
mReceiverRegistries.add(receiverRegistry);
|
||||
}
|
||||
@@ -110,21 +104,33 @@ public class DynamicBroadcastReceivers {
|
||||
private class ReceiverRegistry {
|
||||
BroadcastReceiver receiver;
|
||||
LinkedHashSet<String> actions;
|
||||
boolean local;
|
||||
|
||||
ReceiverRegistry(LinkedHashSet<String> actions) {
|
||||
ReceiverRegistry(LinkedHashSet<String> actions, boolean local) {
|
||||
this.actions = actions;
|
||||
this.local = local;
|
||||
receiver = new BaseBroadcastReceiver();
|
||||
}
|
||||
|
||||
void unregister() {
|
||||
mContext.unregisterReceiver(receiver);
|
||||
if (local) {
|
||||
LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(mContext);
|
||||
broadcastManager.unregisterReceiver(receiver);
|
||||
} else {
|
||||
mContext.unregisterReceiver(receiver);
|
||||
}
|
||||
}
|
||||
|
||||
boolean register() {
|
||||
if (actions.isEmpty())
|
||||
return false;
|
||||
IntentFilter intentFilter = createIntentFilter(actions);
|
||||
mContext.registerReceiver(receiver, intentFilter);
|
||||
if (local) {
|
||||
LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(mContext);
|
||||
broadcastManager.registerReceiver(receiver, intentFilter);
|
||||
} else {
|
||||
mContext.registerReceiver(receiver, intentFilter);
|
||||
}
|
||||
Log.d(LOG_TAG, "register: " + actions);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package org.autojs.autojs.network;
|
||||
|
||||
import com.bumptech.glide.annotation.GlideModule;
|
||||
import com.bumptech.glide.module.AppGlideModule;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/10/26.
|
||||
*/
|
||||
@GlideModule
|
||||
public class Glides extends AppGlideModule {
|
||||
}
|
||||
@@ -11,10 +11,10 @@ import org.autojs.autojs.timing.IntentTask;
|
||||
|
||||
public class IntentTaskDatabase extends Database<IntentTask> {
|
||||
|
||||
private static final int VERSION = 1;
|
||||
private static final int VERSION = 2;
|
||||
private static final String NAME = "IntentTaskDatabase";
|
||||
|
||||
public IntentTaskDatabase(Context context){
|
||||
public IntentTaskDatabase(Context context) {
|
||||
super(new SQLHelper(context), IntentTask.TABLE);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ public class IntentTaskDatabase extends Database<IntentTask> {
|
||||
values.put("action", model.getAction());
|
||||
values.put("category", model.getCategory());
|
||||
values.put("data_type", model.getDataType());
|
||||
values.put("local", model.isLocal() ? 1 : 0);
|
||||
return values;
|
||||
}
|
||||
|
||||
@@ -36,6 +37,7 @@ public class IntentTaskDatabase extends Database<IntentTask> {
|
||||
task.setAction(cursor.getString(2));
|
||||
task.setCategory(cursor.getString(3));
|
||||
task.setDataType(cursor.getString(4));
|
||||
task.setLocal(cursor.getInt(5) != 0);
|
||||
return task;
|
||||
}
|
||||
|
||||
@@ -53,12 +55,16 @@ public class IntentTaskDatabase extends Database<IntentTask> {
|
||||
"`script_path` TEXT NOT NULL ON CONFLICT FAIL, " +
|
||||
"`action` TEXT, " +
|
||||
"`category` TEXT, " +
|
||||
"`data_type` TEXT);");
|
||||
"`data_type` TEXT, " +
|
||||
"`local` INT);");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
|
||||
if (oldVersion == 1 && newVersion == 2) {
|
||||
db.execSQL("ALTER TABLE " + IntentTask.TABLE + "\n" +
|
||||
"ADD local INT");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ public class IntentTask extends BaseModel {
|
||||
|
||||
private String mDataType;
|
||||
|
||||
private boolean mLocal;
|
||||
|
||||
public IntentFilter getIntentFilter() {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
if (mAction != null) {
|
||||
@@ -65,4 +67,12 @@ public class IntentTask extends BaseModel {
|
||||
public void setDataType(String dataType) {
|
||||
mDataType = dataType;
|
||||
}
|
||||
|
||||
public boolean isLocal() {
|
||||
return mLocal;
|
||||
}
|
||||
|
||||
public void setLocal(boolean local) {
|
||||
mLocal = local;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,8 +85,8 @@ public class TimedTaskManager {
|
||||
mIntentTaskDatabase.insert(intentTask)
|
||||
.subscribe(i -> {
|
||||
if(!TextUtils.isEmpty(intentTask.getAction())){
|
||||
App.getApp().getDynamicBroadcastReceivers()
|
||||
.register(intentTask.getAction());
|
||||
App.Companion.getApp().getDynamicBroadcastReceivers()
|
||||
.register(intentTask);
|
||||
}
|
||||
}, Throwable::printStackTrace);
|
||||
}
|
||||
@@ -96,7 +96,7 @@ public class TimedTaskManager {
|
||||
mIntentTaskDatabase.delete(intentTask)
|
||||
.subscribe(i -> {
|
||||
if(!TextUtils.isEmpty(intentTask.getAction())){
|
||||
App.getApp().getDynamicBroadcastReceivers()
|
||||
App.Companion.getApp().getDynamicBroadcastReceivers()
|
||||
.unregister(intentTask.getAction());
|
||||
}
|
||||
}, Throwable::printStackTrace);
|
||||
@@ -144,8 +144,8 @@ public class TimedTaskManager {
|
||||
mIntentTaskDatabase.update(task)
|
||||
.subscribe(i -> {
|
||||
if(i > 0 && !TextUtils.isEmpty(task.getAction())){
|
||||
App.getApp().getDynamicBroadcastReceivers()
|
||||
.register(task.getAction());
|
||||
App.Companion.getApp().getDynamicBroadcastReceivers()
|
||||
.register(task);
|
||||
}
|
||||
}, Throwable::printStackTrace);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
@@ -15,7 +16,10 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.bumptech.glide.request.target.CustomViewTarget;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
@@ -24,7 +28,6 @@ import com.stardust.notification.NotificationListenerService;
|
||||
import org.autojs.autojs.Pref;
|
||||
import org.autojs.autojs.R;
|
||||
import org.autojs.autojs.external.foreground.ForegroundService;
|
||||
import org.autojs.autojs.network.GlideApp;
|
||||
import org.autojs.autojs.network.UserService;
|
||||
import org.autojs.autojs.tool.Observers;
|
||||
import org.autojs.autojs.ui.BaseActivity;
|
||||
@@ -62,6 +65,7 @@ import org.androidannotations.annotations.AfterViews;
|
||||
import org.androidannotations.annotations.Click;
|
||||
import org.androidannotations.annotations.EFragment;
|
||||
import org.androidannotations.annotations.ViewById;
|
||||
import org.autojs.autojs.ui.widget.BackgroundTarget;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
@@ -373,17 +377,12 @@ public class DrawerFragment extends android.support.v4.app.Fragment {
|
||||
} else {
|
||||
mDefaultCover.setVisibility(View.GONE);
|
||||
mShadow.setVisibility(View.VISIBLE);
|
||||
GlideApp.with(getContext())
|
||||
Glide.with(this)
|
||||
.load(NodeBB.BASE_URL + user.getCoverUrl())
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.into(new SimpleTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
|
||||
if (mHeaderView != null) {
|
||||
mHeaderView.setBackground(resource);
|
||||
}
|
||||
}
|
||||
});
|
||||
.apply(new RequestOptions()
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
)
|
||||
.into(new BackgroundTarget(mHeaderView));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.stardust.autojs.project.ProjectConfig;
|
||||
import com.stardust.pio.PFiles;
|
||||
|
||||
@@ -26,7 +27,6 @@ import org.autojs.autojs.model.explorer.ExplorerDirPage;
|
||||
import org.autojs.autojs.model.explorer.ExplorerFileItem;
|
||||
import org.autojs.autojs.model.explorer.Explorers;
|
||||
import org.autojs.autojs.model.project.ProjectTemplate;
|
||||
import org.autojs.autojs.network.GlideApp;
|
||||
import org.autojs.autojs.theme.dialog.ThemeColorMaterialDialogBuilder;
|
||||
import org.autojs.autojs.ui.BaseActivity;
|
||||
import org.autojs.autojs.ui.shortcut.ShortcutIconSelectActivity;
|
||||
@@ -35,7 +35,6 @@ import org.autojs.autojs.ui.widget.SimpleTextWatcher;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
@@ -131,7 +130,7 @@ public class ProjectConfigActivity extends BaseActivity {
|
||||
mProjectLocation.setVisibility(View.GONE);
|
||||
String icon = mProjectConfig.getIcon();
|
||||
if (icon != null) {
|
||||
GlideApp.with(this)
|
||||
Glide.with(this)
|
||||
.load(new File(mDirectory, icon))
|
||||
.into(mIcon);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.androidannotations.annotations.EActivity;
|
||||
import org.androidannotations.annotations.ViewById;
|
||||
import org.autojs.autojs.R;
|
||||
import org.autojs.autojs.external.ScriptIntents;
|
||||
import org.autojs.autojs.external.receiver.DynamicBroadcastReceivers;
|
||||
import org.autojs.autojs.model.script.ScriptFile;
|
||||
import org.autojs.autojs.timing.IntentTask;
|
||||
import org.autojs.autojs.timing.TaskReceiver;
|
||||
@@ -75,6 +76,7 @@ public class TimedTaskSettingActivity extends BaseActivity {
|
||||
|
||||
|
||||
public static final Map<String, Integer> ACTION_DESC_MAP = new MapBuilder<String, Integer>()
|
||||
.put(DynamicBroadcastReceivers.ACTION_STARTUP, R.string.text_run_on_startup)
|
||||
.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)
|
||||
@@ -92,6 +94,7 @@ public class TimedTaskSettingActivity extends BaseActivity {
|
||||
.build();
|
||||
|
||||
private static final BiMap<Integer, String> ACTIONS = BiMaps.<Integer, String>newBuilder()
|
||||
.put(R.id.run_on_startup, DynamicBroadcastReceivers.ACTION_STARTUP)
|
||||
.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_on, Intent.ACTION_SCREEN_ON)
|
||||
@@ -108,7 +111,6 @@ public class TimedTaskSettingActivity extends BaseActivity {
|
||||
.put(R.id.run_on_time_tick, Intent.ACTION_TIME_TICK)
|
||||
.build();
|
||||
|
||||
|
||||
@ViewById(R.id.toolbar)
|
||||
Toolbar mToolbar;
|
||||
|
||||
@@ -347,10 +349,10 @@ public class TimedTaskSettingActivity extends BaseActivity {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == R.id.action_done) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !((PowerManager) getSystemService(POWER_SERVICE)).isIgnoringBatteryOptimizations(getPackageName())) {
|
||||
try{
|
||||
try {
|
||||
startActivityForResult(new Intent().setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
|
||||
.setData(Uri.parse("package:" + getPackageName())), REQUEST_CODE_IGNORE_BATTERY);
|
||||
}catch(ActivityNotFoundException e){
|
||||
} catch (ActivityNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
createOrUpdateTask();
|
||||
}
|
||||
@@ -412,6 +414,7 @@ public class TimedTaskSettingActivity extends BaseActivity {
|
||||
IntentTask task = new IntentTask();
|
||||
task.setAction(action);
|
||||
task.setScriptPath(mScriptFile.getPath());
|
||||
task.setLocal(action.equals(DynamicBroadcastReceivers.ACTION_STARTUP));
|
||||
if (mIntentTask != null) {
|
||||
task.setId(mIntentTask.getId());
|
||||
TimedTaskManager.getInstance().updateTask(task);
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.autojs.autojs.ui.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.support.annotation.AttrRes;
|
||||
import android.support.annotation.NonNull;
|
||||
@@ -11,16 +10,14 @@ import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.makeramen.roundedimageview.RoundedImageView;
|
||||
|
||||
import org.autojs.autojs.R;
|
||||
import org.autojs.autojs.network.GlideApp;
|
||||
import org.autojs.autojs.network.Glides;
|
||||
import org.autojs.autojs.network.NodeBB;
|
||||
import org.autojs.autojs.network.entity.user.User;
|
||||
|
||||
@@ -80,10 +77,12 @@ public class AvatarView extends FrameLayout {
|
||||
mIcon.setVisibility(View.VISIBLE);
|
||||
mIconText.setVisibility(View.GONE);
|
||||
mIcon.setCornerRadius(getWidth() / 2);
|
||||
GlideApp.with(getContext())
|
||||
Glide.with(getContext())
|
||||
.load(NodeBB.BASE_URL + user.getPicture())
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.skipMemoryCache(true)
|
||||
.apply(new RequestOptions()
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.skipMemoryCache(true)
|
||||
)
|
||||
.into(mIcon);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.autojs.autojs.ui.widget
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.view.View
|
||||
import com.bumptech.glide.request.target.CustomViewTarget
|
||||
import com.bumptech.glide.request.transition.Transition
|
||||
|
||||
class BackgroundTarget(view: View) : CustomViewTarget<View, Drawable>(view) {
|
||||
override fun onLoadFailed(errorDrawable: Drawable?) {
|
||||
errorDrawable?.let {
|
||||
view.background = it
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResourceCleared(placeholder: Drawable?) {
|
||||
placeholder?.let {
|
||||
view.background = it
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
|
||||
view.background = resource
|
||||
}
|
||||
|
||||
}
|
||||
@@ -279,6 +279,14 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/run_on_startup"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:paddingLeft="8dp"
|
||||
android:text="@string/text_run_on_startup"/>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/run_on_boot"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -428,4 +428,5 @@
|
||||
<string name="text_project_save_error">项目保存失败 %s</string>
|
||||
<string name="text_night_mode">夜间模式</string>
|
||||
<string name="key_night_mode">key_night_mode</string>
|
||||
<string name="text_run_on_startup">Auto.js启动时</string>
|
||||
</resources>
|
||||
|
||||
@@ -367,7 +367,8 @@ open class UiObject(info: Any?, private val allocator: AccessibilityNodeInfoAllo
|
||||
}
|
||||
|
||||
override fun findAccessibilityNodeInfosByText(text: String): List<AccessibilityNodeInfoCompat> {
|
||||
return if (allocator == null) super.findAccessibilityNodeInfosByText(text) else allocator.findAccessibilityNodeInfosByText(this, text)
|
||||
return allocator?.findAccessibilityNodeInfosByText(this, text)
|
||||
?: super.findAccessibilityNodeInfosByText(text)
|
||||
}
|
||||
|
||||
fun findByText(text: String): List<UiObject> {
|
||||
@@ -375,7 +376,7 @@ open class UiObject(info: Any?, private val allocator: AccessibilityNodeInfoAllo
|
||||
}
|
||||
|
||||
override fun findAccessibilityNodeInfosByViewId(viewId: String): List<AccessibilityNodeInfoCompat> {
|
||||
return if (allocator == null) super.findAccessibilityNodeInfosByViewId(viewId) else allocator.findAccessibilityNodeInfosByViewId(this, viewId)
|
||||
return allocator?.findAccessibilityNodeInfosByViewId(this, viewId) ?: super.findAccessibilityNodeInfosByViewId(viewId)
|
||||
}
|
||||
|
||||
fun findByViewId(viewId: String): List<UiObject> {
|
||||
|
||||
Reference in New Issue
Block a user