refactor: use GlobalAppContext to replace App.getApp()
add: Canvas
This commit is contained in:
@@ -8,8 +8,8 @@ android {
|
||||
applicationId "com.stardust.scriptdroid"
|
||||
minSdkVersion 17
|
||||
targetSdkVersion 23
|
||||
versionCode 257
|
||||
versionName "3.1.1 Alpha"
|
||||
versionCode 258
|
||||
versionName "3.1.1 Alpha2"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
multiDexEnabled true
|
||||
ndk {
|
||||
|
||||
@@ -17,7 +17,7 @@ ui.layout(
|
||||
</vertical>
|
||||
);
|
||||
|
||||
id.cb1.on("check", (checked)=>{
|
||||
ui.cb1.on("check", (checked)=>{
|
||||
if(checked){
|
||||
toast("第一个框被勾选了");
|
||||
}else{
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.raizlabs.android.dbflow.config.FlowConfig;
|
||||
import com.raizlabs.android.dbflow.config.FlowManager;
|
||||
import com.raizlabs.android.dbflow.runtime.DirectModelNotifier;
|
||||
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.scriptdroid.autojs.AutoJs;
|
||||
@@ -40,7 +41,6 @@ public class App extends MultiDexApplication {
|
||||
private static final String TAG = "App";
|
||||
|
||||
private static WeakReference<App> instance;
|
||||
private UiHandler mUiHandler;
|
||||
|
||||
public static App getApp() {
|
||||
return instance.get();
|
||||
@@ -48,8 +48,8 @@ public class App extends MultiDexApplication {
|
||||
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
GlobalAppContext.set(this);
|
||||
instance = new WeakReference<>(this);
|
||||
mUiHandler = new UiHandler(this);
|
||||
setUpStaticsTool();
|
||||
setUpDebugEnvironment();
|
||||
init();
|
||||
@@ -142,7 +142,4 @@ public class App extends MultiDexApplication {
|
||||
}
|
||||
|
||||
|
||||
public UiHandler getUiHandler() {
|
||||
return mUiHandler;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.runtime.accessibility.AccessibilityConfig;
|
||||
import com.stardust.scriptdroid.autojs.key.GlobalKeyObserver;
|
||||
|
||||
@@ -14,7 +15,7 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public class Pref {
|
||||
|
||||
private static final SharedPreferences DISPOSABLE_BOOLEAN = App.getApp().getSharedPreferences("DISPOSABLE_BOOLEAN", Context.MODE_PRIVATE);
|
||||
private static final SharedPreferences DISPOSABLE_BOOLEAN = GlobalAppContext.get().getSharedPreferences("DISPOSABLE_BOOLEAN", Context.MODE_PRIVATE);
|
||||
private static final String KEY_SERVER_ADDRESS = "Still love you...17.5.14";
|
||||
private static final String KEY_SHOULD_SHOW_ANNUNCIATION = "Sing about all the things you forgot, things you are not";
|
||||
private static final String KEY_FIRST_SHOW_AD = "En, Today is 17.7.7, but, I'm still love you so....";
|
||||
@@ -40,7 +41,7 @@ public class Pref {
|
||||
}
|
||||
|
||||
private static SharedPreferences def() {
|
||||
return PreferenceManager.getDefaultSharedPreferences(App.getApp());
|
||||
return PreferenceManager.getDefaultSharedPreferences(GlobalAppContext.get());
|
||||
}
|
||||
|
||||
private static boolean getDisposableBoolean(String key, boolean defaultValue) {
|
||||
@@ -68,7 +69,7 @@ public class Pref {
|
||||
}
|
||||
|
||||
private static String getString(int id) {
|
||||
return App.getApp().getString(id);
|
||||
return GlobalAppContext.getString(id);
|
||||
}
|
||||
|
||||
public static boolean isFirstUsing() {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.stardust.scriptdroid.autojs;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.core.console.GlobalStardustConsole;
|
||||
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||
import com.stardust.autojs.runtime.accessibility.AccessibilityConfig;
|
||||
@@ -33,13 +34,13 @@ public class AutoJs extends com.stardust.autojs.AutoJs {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static void initInstance(Context context) {
|
||||
instance = new AutoJs(context);
|
||||
public static void initInstance(Application application) {
|
||||
instance = new AutoJs(application);
|
||||
}
|
||||
|
||||
|
||||
private AutoJs(final Context context) {
|
||||
super(context);
|
||||
private AutoJs(final Application application) {
|
||||
super(application);
|
||||
getScriptEngineService().registerGlobalScriptExecutionListener(new ScriptExecutionGlobalListener());
|
||||
}
|
||||
|
||||
@@ -60,15 +61,15 @@ public class AutoJs extends com.stardust.autojs.AutoJs {
|
||||
return;
|
||||
}
|
||||
String errorMessage = null;
|
||||
if (AccessibilityServiceTool.isAccessibilityServiceEnabled(App.getApp())) {
|
||||
errorMessage = App.getApp().getString(R.string.text_auto_operate_service_enabled_but_not_running);
|
||||
if (AccessibilityServiceTool.isAccessibilityServiceEnabled(GlobalAppContext.get())) {
|
||||
errorMessage = GlobalAppContext.getString(R.string.text_auto_operate_service_enabled_but_not_running);
|
||||
} else {
|
||||
if (Pref.shouldEnableAccessibilityServiceByRoot()) {
|
||||
if (!AccessibilityServiceTool.enableAccessibilityServiceByRootAndWaitFor(2000)) {
|
||||
errorMessage = App.getApp().getString(R.string.text_enable_accessibility_service_by_root_timeout);
|
||||
errorMessage = GlobalAppContext.getString(R.string.text_enable_accessibility_service_by_root_timeout);
|
||||
}
|
||||
} else {
|
||||
errorMessage = App.getApp().getString(R.string.text_no_accessibility_permission);
|
||||
errorMessage = GlobalAppContext.getString(R.string.text_no_accessibility_permission);
|
||||
}
|
||||
}
|
||||
if (errorMessage != null) {
|
||||
@@ -83,15 +84,15 @@ public class AutoJs extends com.stardust.autojs.AutoJs {
|
||||
return;
|
||||
}
|
||||
String errorMessage = null;
|
||||
if (AccessibilityServiceTool.isAccessibilityServiceEnabled(App.getApp())) {
|
||||
errorMessage = App.getApp().getString(R.string.text_auto_operate_service_enabled_but_not_running);
|
||||
if (AccessibilityServiceTool.isAccessibilityServiceEnabled(GlobalAppContext.get())) {
|
||||
errorMessage = GlobalAppContext.getString(R.string.text_auto_operate_service_enabled_but_not_running);
|
||||
} else {
|
||||
if (Pref.shouldEnableAccessibilityServiceByRoot()) {
|
||||
if (!AccessibilityServiceTool.enableAccessibilityServiceByRootAndWaitFor(2000)) {
|
||||
errorMessage = App.getApp().getString(R.string.text_enable_accessibility_service_by_root_timeout);
|
||||
errorMessage = GlobalAppContext.getString(R.string.text_enable_accessibility_service_by_root_timeout);
|
||||
}
|
||||
} else {
|
||||
errorMessage = App.getApp().getString(R.string.text_no_accessibility_permission);
|
||||
errorMessage = GlobalAppContext.getString(R.string.text_no_accessibility_permission);
|
||||
}
|
||||
}
|
||||
if (errorMessage != null) {
|
||||
@@ -111,11 +112,6 @@ public class AutoJs extends com.stardust.autojs.AutoJs {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Application getApplication() {
|
||||
return App.getApp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ScriptRuntime createRuntime() {
|
||||
ScriptRuntime runtime = super.createRuntime();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.stardust.scriptdroid.autojs;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.engine.JavaScriptEngine;
|
||||
import com.stardust.autojs.execution.ScriptExecution;
|
||||
import com.stardust.autojs.execution.ScriptExecutionListener;
|
||||
@@ -29,7 +30,7 @@ public class ScriptExecutionGlobalListener implements ScriptExecutionListener {
|
||||
return;
|
||||
double seconds = (System.currentTimeMillis() - millis) / 1000.0;
|
||||
AutoJs.getInstance().getScriptEngineService().getGlobalConsole()
|
||||
.verbose(App.getApp().getString(R.string.text_execution_finished), execution.getSource().toString(), seconds);
|
||||
.verbose(GlobalAppContext.getString(R.string.text_execution_finished), execution.getSource().toString(), seconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.stardust.scriptdroid.autojs.build;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.apkbuilder.ApkBuilder;
|
||||
import com.stardust.autojs.apkbuilder.ManifestEditor;
|
||||
import com.stardust.autojs.apkbuilder.util.StreamUtils;
|
||||
@@ -98,7 +99,7 @@ public class AutoJsApkBuilder extends ApkBuilder {
|
||||
@Override
|
||||
public AutoJsApkBuilder prepare() throws IOException {
|
||||
if (mProgressCallback != null) {
|
||||
App.getApp().getUiHandler().post(() -> mProgressCallback.onPrepare(AutoJsApkBuilder.this));
|
||||
GlobalAppContext.post(() -> mProgressCallback.onPrepare(AutoJsApkBuilder.this));
|
||||
}
|
||||
return (AutoJsApkBuilder) super.prepare();
|
||||
}
|
||||
@@ -179,7 +180,7 @@ public class AutoJsApkBuilder extends ApkBuilder {
|
||||
@Override
|
||||
public AutoJsApkBuilder build() throws IOException {
|
||||
if (mProgressCallback != null) {
|
||||
App.getApp().getUiHandler().post(() -> mProgressCallback.onBuild(AutoJsApkBuilder.this));
|
||||
GlobalAppContext.post(() -> mProgressCallback.onBuild(AutoJsApkBuilder.this));
|
||||
}
|
||||
mManifestEditor.commit();
|
||||
if (mAppConfig.icon != null) {
|
||||
@@ -196,7 +197,7 @@ public class AutoJsApkBuilder extends ApkBuilder {
|
||||
@Override
|
||||
public AutoJsApkBuilder sign() throws Exception {
|
||||
if (mProgressCallback != null) {
|
||||
App.getApp().getUiHandler().post(() -> mProgressCallback.onSign(AutoJsApkBuilder.this));
|
||||
GlobalAppContext.post(() -> mProgressCallback.onSign(AutoJsApkBuilder.this));
|
||||
}
|
||||
return (AutoJsApkBuilder) super.sign();
|
||||
}
|
||||
@@ -204,7 +205,7 @@ public class AutoJsApkBuilder extends ApkBuilder {
|
||||
@Override
|
||||
public AutoJsApkBuilder cleanWorkspace() {
|
||||
if (mProgressCallback != null) {
|
||||
App.getApp().getUiHandler().post(() -> mProgressCallback.onClean(AutoJsApkBuilder.this));
|
||||
GlobalAppContext.post(() -> mProgressCallback.onClean(AutoJsApkBuilder.this));
|
||||
}
|
||||
return (AutoJsApkBuilder) super.cleanWorkspace();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.view.ContextThemeWrapper;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.app.DialogUtils;
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.core.record.Recorder;
|
||||
import com.stardust.autojs.core.record.inputevent.InputEventRecorder;
|
||||
import com.stardust.autojs.core.record.inputevent.InputEventToAutoFileRecorder;
|
||||
@@ -106,7 +107,7 @@ public class GlobalActionRecorder implements Recorder.OnStateChangedListener {
|
||||
@Override
|
||||
public void onStart() {
|
||||
if (Pref.isRecordToastEnabled())
|
||||
App.getApp().getUiHandler().toast(R.string.text_start_record);
|
||||
GlobalAppContext.toast(R.string.text_start_record);
|
||||
for (Recorder.OnStateChangedListener listener : mOnStateChangedListeners) {
|
||||
listener.onStart();
|
||||
}
|
||||
@@ -150,13 +151,13 @@ public class GlobalActionRecorder implements Recorder.OnStateChangedListener {
|
||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
showRecordHandleDialog(script);
|
||||
} else {
|
||||
App.getApp().getUiHandler().post(() -> showRecordHandleDialog(script));
|
||||
GlobalAppContext.post(() -> showRecordHandleDialog(script));
|
||||
}
|
||||
}
|
||||
|
||||
private void handleRecordedFile(final String path) {
|
||||
if (Looper.myLooper() != Looper.getMainLooper()) {
|
||||
App.getApp().getUiHandler().post(() -> handleRecordedFile(path));
|
||||
GlobalAppContext.post(() -> handleRecordedFile(path));
|
||||
return;
|
||||
}
|
||||
new ScriptOperations(mContext, null)
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.scriptdroid.App;
|
||||
|
||||
import java.util.HashSet;
|
||||
@@ -22,7 +23,7 @@ public class ScriptWidgets {
|
||||
|
||||
|
||||
private static final String LOG_TAG = "ScriptWidgets";
|
||||
private static SharedPreferences widgets = App.getApp().getSharedPreferences("ScriptWidgets", Context.MODE_PRIVATE);
|
||||
private static SharedPreferences widgets = GlobalAppContext.get().getSharedPreferences("ScriptWidgets", Context.MODE_PRIVATE);
|
||||
private static final Pattern ID_PATTERN = Pattern.compile("[a-zA-Z]+_([0-9])+");
|
||||
|
||||
static String getPathForAppWidgetId(int id) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.execution.ExecutionConfig;
|
||||
import com.stardust.autojs.execution.ScriptExecution;
|
||||
import com.stardust.autojs.execution.ScriptExecutionListener;
|
||||
@@ -39,7 +40,7 @@ public class Scripts {
|
||||
|
||||
@Override
|
||||
public void onSuccess(ScriptExecution execution, Object result) {
|
||||
App.getApp().sendBroadcast(new Intent(ACTION_ON_EXECUTION_FINISHED));
|
||||
GlobalAppContext.get().sendBroadcast(new Intent(ACTION_ON_EXECUTION_FINISHED));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,11 +52,11 @@ public class Scripts {
|
||||
col = rhinoException.columnNumber();
|
||||
}
|
||||
if (ScriptInterruptedException.causedByInterrupted(e)) {
|
||||
App.getApp().sendBroadcast(new Intent(ACTION_ON_EXECUTION_FINISHED)
|
||||
GlobalAppContext.get().sendBroadcast(new Intent(ACTION_ON_EXECUTION_FINISHED)
|
||||
.putExtra(EXTRA_EXCEPTION_LINE_NUMBER, line)
|
||||
.putExtra(EXTRA_EXCEPTION_COLUMN_NUMBER, col));
|
||||
} else {
|
||||
App.getApp().sendBroadcast(new Intent(ACTION_ON_EXECUTION_FINISHED)
|
||||
GlobalAppContext.get().sendBroadcast(new Intent(ACTION_ON_EXECUTION_FINISHED)
|
||||
.putExtra(EXTRA_EXCEPTION_MESSAGE, e.getMessage())
|
||||
.putExtra(EXTRA_EXCEPTION_LINE_NUMBER, line)
|
||||
.putExtra(EXTRA_EXCEPTION_COLUMN_NUMBER, col));
|
||||
@@ -67,7 +68,7 @@ public class Scripts {
|
||||
|
||||
public static void openByOtherApps(String path) {
|
||||
Uri uri = Uri.parse("file://" + path);
|
||||
App.getApp().startActivity(new Intent(Intent.ACTION_VIEW).setDataAndType(uri, "text/plain").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
GlobalAppContext.get().startActivity(new Intent(Intent.ACTION_VIEW).setDataAndType(uri, "text/plain").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
public static void openByOtherApps(File file) {
|
||||
@@ -75,7 +76,7 @@ public class Scripts {
|
||||
}
|
||||
|
||||
public static void createShortcut(ScriptFile scriptFile) {
|
||||
new Shortcut(App.getApp()).name(scriptFile.getSimplifiedName())
|
||||
new Shortcut(GlobalAppContext.get()).name(scriptFile.getSimplifiedName())
|
||||
.targetClass(ShortcutActivity.class)
|
||||
.iconRes(R.drawable.ic_node_js_black)
|
||||
.extras(new Intent().putExtra(ScriptIntents.EXTRA_KEY_PATH, scriptFile.getPath()))
|
||||
@@ -84,7 +85,7 @@ public class Scripts {
|
||||
|
||||
|
||||
public static void edit(ScriptFile file) {
|
||||
EditActivity.editFile(App.getApp(), file.getSimplifiedName(), file.getPath());
|
||||
EditActivity.editFile(GlobalAppContext.get(), file.getSimplifiedName(), file.getPath());
|
||||
}
|
||||
|
||||
public static void edit(String path) {
|
||||
@@ -128,10 +129,10 @@ public class Scripts {
|
||||
}
|
||||
|
||||
public static void send(ScriptFile file) {
|
||||
App.getApp().startActivity(Intent.createChooser(new Intent(Intent.ACTION_SEND)
|
||||
GlobalAppContext.get().startActivity(Intent.createChooser(new Intent(Intent.ACTION_SEND)
|
||||
.setType("text/plain")
|
||||
.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)),
|
||||
App.getApp().getString(R.string.text_send)
|
||||
GlobalAppContext.getString(R.string.text_send)
|
||||
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.text.TextUtils;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.execution.ScriptExecution;
|
||||
import com.stardust.autojs.script.StringScriptSource;
|
||||
import com.stardust.pio.PFiles;
|
||||
@@ -100,6 +101,6 @@ public class DevPluginResponseHandler implements Handler {
|
||||
name = "<remote>" + name;
|
||||
}
|
||||
PFiles.write(StorageFileProvider.DEFAULT_DIRECTORY_PATH + name, script);
|
||||
App.getApp().getUiHandler().toast(R.string.text_script_save_successfully);
|
||||
GlobalAppContext.toast(R.string.text_script_save_successfully);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.stardust.scriptdroid.storage.file;
|
||||
|
||||
import android.os.Environment;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.pio.PFile;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.R;
|
||||
@@ -27,7 +28,7 @@ public class StorageFileProvider {
|
||||
public static final int CREATE = 1;
|
||||
public static final int CHANGE = 2;
|
||||
public static final int ALL = 3;
|
||||
public static final String DEFAULT_DIRECTORY_PATH = Environment.getExternalStorageDirectory() + App.getApp().getString(R.string.folder_name);
|
||||
public static final String DEFAULT_DIRECTORY_PATH = Environment.getExternalStorageDirectory() + GlobalAppContext.getString(R.string.folder_name);
|
||||
public static final PFile DEFAULT_DIRECTORY = new PFile(DEFAULT_DIRECTORY_PATH);
|
||||
public static final FileFilter SCRIPT_FILTER = file ->
|
||||
file.isDirectory() || file.getName().endsWith(".js") || file.getName().endsWith(".auto");
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.raizlabs.android.dbflow.rx2.language.RXSQLite;
|
||||
import com.raizlabs.android.dbflow.sql.language.SQLite;
|
||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||
import com.raizlabs.android.dbflow.structure.ModelAdapter;
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.storage.database.ModelChange;
|
||||
import com.stardust.scriptdroid.storage.database.TimedTaskDatabase;
|
||||
@@ -37,7 +38,7 @@ public class TimedTaskManager {
|
||||
|
||||
public static TimedTaskManager getInstance() {
|
||||
if (sInstance == null) {
|
||||
sInstance = new TimedTaskManager(App.getApp());
|
||||
sInstance = new TimedTaskManager(GlobalAppContext.get());
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.scriptdroid.Pref;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.R;
|
||||
@@ -32,14 +33,14 @@ public class AccessibilityServiceTool {
|
||||
}
|
||||
|
||||
public static void goToAccessibilitySetting() {
|
||||
Context context = App.getApp();
|
||||
Context context = GlobalAppContext.get();
|
||||
if (Pref.isFirstGoToAccessibilitySetting()) {
|
||||
App.getApp().getUiHandler().toast(context.getString(R.string.text_please_choose) + context.getString(R.string._app_name));
|
||||
GlobalAppContext.toast(context.getString(R.string.text_please_choose) + context.getString(R.string._app_name));
|
||||
}
|
||||
try {
|
||||
AccessibilityServiceUtils.goToAccessibilitySetting(context);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
App.getApp().getUiHandler().toast(context.getString(R.string.go_to_accessibility_settings) + context.getString(R.string._app_name));
|
||||
GlobalAppContext.toast(context.getString(R.string.go_to_accessibility_settings) + context.getString(R.string._app_name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +56,7 @@ public class AccessibilityServiceTool {
|
||||
"settings put secure accessibility_enabled 1";
|
||||
|
||||
public static boolean enableAccessibilityServiceByRoot(Class<? extends android.accessibilityservice.AccessibilityService> accessibilityService) {
|
||||
String serviceName = App.getApp().getPackageName() + "/" + accessibilityService.getName();
|
||||
String serviceName = GlobalAppContext.get().getPackageName() + "/" + accessibilityService.getName();
|
||||
try {
|
||||
return TextUtils.isEmpty(ProcessShell.execCommand(String.format(Locale.getDefault(), cmd, serviceName), true).error);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import android.util.Log;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.BuildConfig;
|
||||
import com.stardust.scriptdroid.R;
|
||||
@@ -48,14 +49,14 @@ public class CrashHandler implements UncaughtExceptionHandler {
|
||||
return;
|
||||
}
|
||||
if (causedByBadWindowToken(ex)) {
|
||||
Toast.makeText(App.getApp(), R.string.text_no_floating_window_permission, Toast.LENGTH_SHORT).show();
|
||||
IntentUtil.goToAppDetailSettings(App.getApp());
|
||||
Toast.makeText(GlobalAppContext.get(), R.string.text_no_floating_window_permission, Toast.LENGTH_SHORT).show();
|
||||
IntentUtil.goToAppDetailSettings(GlobalAppContext.get());
|
||||
} else {
|
||||
try {
|
||||
Log.e(TAG, "Uncaught Exception", ex);
|
||||
if (crashTooManyTimes())
|
||||
return;
|
||||
String msg = App.getApp().getString(R.string.sorry_for_crash) + ex.toString();
|
||||
String msg = GlobalAppContext.getString(R.string.sorry_for_crash) + ex.toString();
|
||||
startErrorReportActivity(msg, throwableToString(ex));
|
||||
System.exit(1);
|
||||
} catch (Throwable throwable) {
|
||||
@@ -75,11 +76,11 @@ public class CrashHandler implements UncaughtExceptionHandler {
|
||||
}
|
||||
|
||||
private void startErrorReportActivity(String msg, String detail) {
|
||||
Intent intent = new Intent(App.getApp(), this.mErrorReportClass);
|
||||
Intent intent = new Intent(GlobalAppContext.get(), this.mErrorReportClass);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
intent.putExtra("message", msg);
|
||||
intent.putExtra("error", detail);
|
||||
App.getApp().startActivity(intent);
|
||||
GlobalAppContext.get().startActivity(intent);
|
||||
}
|
||||
|
||||
private boolean crashTooManyTimes() {
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.view.Window;
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.app.DialogUtils;
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.model.script.ScriptFile;
|
||||
@@ -60,7 +61,7 @@ public class ScriptLoopDialog {
|
||||
float loopDelay = Float.parseFloat(mLoopDelay.getText().toString());
|
||||
Scripts.runRepeatedly(mScriptFile, loopTimes, (long) (1000L * loopDelay), (long) (loopInterval * 1000L));
|
||||
} catch (NumberFormatException e) {
|
||||
App.getApp().getUiHandler().toast(R.string.text_number_format_error);
|
||||
GlobalAppContext.toast(R.string.text_number_format_error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import android.widget.Toast;
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.app.DialogUtils;
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.pio.PFile;
|
||||
import com.stardust.pio.PFiles;
|
||||
import com.stardust.pio.UncheckedIOException;
|
||||
@@ -159,7 +160,7 @@ public class ScriptOperations {
|
||||
showMessageWithoutThreadSwitch(resId);
|
||||
}
|
||||
//switch to ui thread to show message
|
||||
App.getApp().getUiHandler().post(() -> showMessageWithoutThreadSwitch(resId));
|
||||
GlobalAppContext.post(() -> showMessageWithoutThreadSwitch(resId));
|
||||
}
|
||||
|
||||
private void showMessageWithoutThreadSwitch(int resId) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.util.FloatingPermission;
|
||||
import com.stardust.enhancedfloaty.FloatyService;
|
||||
import com.stardust.enhancedfloaty.FloatyWindow;
|
||||
@@ -53,13 +54,13 @@ public class FloatyWindowManger {
|
||||
}
|
||||
|
||||
public static boolean showCircularMenu() {
|
||||
if (!SettingsCompat.canDrawOverlays(App.getApp())) {
|
||||
Toast.makeText(App.getApp(), R.string.text_no_floating_window_permission, Toast.LENGTH_SHORT).show();
|
||||
manageDrawOverlays(App.getApp());
|
||||
if (!SettingsCompat.canDrawOverlays(GlobalAppContext.get())) {
|
||||
Toast.makeText(GlobalAppContext.get(), R.string.text_no_floating_window_permission, Toast.LENGTH_SHORT).show();
|
||||
manageDrawOverlays(GlobalAppContext.get());
|
||||
return false;
|
||||
} else {
|
||||
App.getApp().startService(new Intent(App.getApp(), FloatyService.class));
|
||||
CircularMenu menu = new CircularMenu(App.getApp());
|
||||
GlobalAppContext.get().startService(new Intent(GlobalAppContext.get(), FloatyService.class));
|
||||
CircularMenu menu = new CircularMenu(GlobalAppContext.get());
|
||||
sCircularMenu = new WeakReference<>(menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.notification.NotificationListenerService;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.Pref;
|
||||
@@ -276,7 +277,7 @@ public class DrawerFragment extends android.support.v4.app.Fragment {
|
||||
new UpdateInfoDialogBuilder(getActivity(), versionInfo)
|
||||
.show();
|
||||
} else {
|
||||
Toast.makeText(App.getApp(), R.string.text_is_latest_version, Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(GlobalAppContext.get(), R.string.text_is_latest_version, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
setProgress(mCheckForUpdatesItem, false);
|
||||
}
|
||||
@@ -284,7 +285,7 @@ public class DrawerFragment extends android.support.v4.app.Fragment {
|
||||
@Override
|
||||
public void onError(@io.reactivex.annotations.NonNull Throwable e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(App.getApp(), R.string.text_check_update_error, Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(GlobalAppContext.get(), R.string.text_check_update_error, Toast.LENGTH_SHORT).show();
|
||||
setProgress(mCheckForUpdatesItem, false);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.stardust.scriptdroid.ui.main.task;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.engine.JavaScriptEngine;
|
||||
import com.stardust.autojs.engine.ScriptEngine;
|
||||
import com.stardust.autojs.engine.ScriptEngineFactory;
|
||||
@@ -22,7 +23,7 @@ import org.joda.time.format.DateTimeFormat;
|
||||
* Created by Stardust on 2017/11/28.
|
||||
*/
|
||||
|
||||
public abstract class Task implements Parcelable {
|
||||
public abstract class Task {
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
@@ -32,16 +33,6 @@ public abstract class Task implements Parcelable {
|
||||
|
||||
public abstract String getEngineName();
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
|
||||
}
|
||||
|
||||
public static class PendingTask extends Task {
|
||||
|
||||
private TimedTask mTimedTask;
|
||||
@@ -63,7 +54,7 @@ public abstract class Task implements Parcelable {
|
||||
@Override
|
||||
public String getDesc() {
|
||||
long nextTime = mTimedTask.getNextTime();
|
||||
return App.getApp().getString(R.string.text_next_run_time) + ": " +
|
||||
return GlobalAppContext.getString(R.string.text_next_run_time) + ": " +
|
||||
DateTimeFormat.shortDateTime().print(nextTime);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.network.VersionService;
|
||||
@@ -42,7 +43,7 @@ public class UpdateCheckDialog {
|
||||
new UpdateInfoDialogBuilder(mContext, versionInfo)
|
||||
.show();
|
||||
} else {
|
||||
Toast.makeText(App.getApp(), R.string.text_is_latest_version, Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(GlobalAppContext.get(), R.string.text_is_latest_version, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +51,7 @@ public class UpdateCheckDialog {
|
||||
public void onError(@NonNull Throwable e) {
|
||||
e.printStackTrace();
|
||||
mProgress.dismiss();
|
||||
Toast.makeText(App.getApp(), R.string.text_check_update_error, Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(GlobalAppContext.get(), R.string.text_check_update_error, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.stardust.theme;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.scriptdroid.*;
|
||||
import com.stardust.scriptdroid.R;
|
||||
|
||||
@@ -12,7 +13,7 @@ public class ThemeColorManagerCompat {
|
||||
public static int getColorPrimary() {
|
||||
int color = ThemeColorManager.getColorPrimary();
|
||||
if (color == 0) {
|
||||
return App.getApp().getResources().getColor(R.color.colorPrimary);
|
||||
return GlobalAppContext.get().getResources().getColor(R.color.colorPrimary);
|
||||
} else {
|
||||
return color;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user