add samples, fix require()
This commit is contained in:
@@ -7,6 +7,7 @@ import android.os.Bundle;
|
||||
import android.support.annotation.Keep;
|
||||
import android.support.multidex.MultiDexApplication;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.iwebpp.node.NodeContext;
|
||||
import com.iwebpp.node.http.ClientRequest;
|
||||
@@ -16,6 +17,7 @@ import com.squareup.leakcanary.LeakCanary;
|
||||
import com.stardust.app.SimpleActivityLifecycleCallbacks;
|
||||
import com.stardust.app.VolumeChangeObserver;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.external.floating_window.OverlayPermissionChecker;
|
||||
import com.stardust.scriptdroid.service.AccessibilityWatchDogService;
|
||||
import com.stardust.scriptdroid.statics.ScriptStatics;
|
||||
import com.stardust.scriptdroid.tool.CrashHandler;
|
||||
|
||||
@@ -95,7 +95,6 @@ public class AutoJs implements AccessibilityBridge {
|
||||
|
||||
private NodeJsJavaScriptEngineManager createScriptEngineManager(Context context) {
|
||||
NodeJsJavaScriptEngineManager manager = new NodeJsJavaScriptEngineManager(context);
|
||||
manager.setRequirePath(StorageScriptProvider.DEFAULT_DIRECTORY_PATH);
|
||||
try {
|
||||
manager.setInitScript(PFile.read(context.getAssets().open(INIT_SCRIPT_PATH)));
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
package com.stardust.scriptdroid.external.floating_window;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.external.floating_window.menu.HoverMenuService;
|
||||
import com.stardust.util.IntentUtil;
|
||||
|
||||
@@ -15,9 +21,13 @@ import com.stardust.util.IntentUtil;
|
||||
|
||||
public class FloatingWindowManger {
|
||||
|
||||
private static final String KEY_FLOATING_WINDOW_PERMISSION = "May we go back..I...miss..you..Eating..17.5.9";
|
||||
private static final String TAG = "FloatingWindowManger";
|
||||
|
||||
public static void showHoverMenu() {
|
||||
if (!HoverMenuService.isServiceRunning()) {
|
||||
if (!hasFloatingWindowPermission()) {
|
||||
if (!hasFloatingWindowPermission(App.getApp())) {
|
||||
Toast.makeText(App.getApp(), R.string.text_no_floating_window_permission, Toast.LENGTH_SHORT).show();
|
||||
goToFloatingWindowPermissionSetting();
|
||||
} else {
|
||||
HoverMenuService.startService(App.getApp());
|
||||
@@ -26,33 +36,54 @@ public class FloatingWindowManger {
|
||||
}
|
||||
|
||||
public static void goToFloatingWindowPermissionSetting() {
|
||||
String packageName = App.getApp().getPackageName();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
try {
|
||||
App.getApp().startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
||||
Uri.parse("package:" + packageName))
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
} catch (Exception e) {
|
||||
IntentUtil.goToAppDetailSettings(App.getApp());
|
||||
}
|
||||
} else {
|
||||
IntentUtil.goToAppDetailSettings(App.getApp());
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
private static void goToOverlayPermissionSettings(Context context, String packageName) {
|
||||
try {
|
||||
App.getApp().startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
||||
Uri.parse("package:" + context))
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
} catch (Exception e) {
|
||||
IntentUtil.goToAppDetailSettings(App.getApp());
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasFloatingWindowPermission() {
|
||||
public static void checkPermission() {
|
||||
final OverlayPermissionChecker checker = new OverlayPermissionChecker(App.getApp());
|
||||
checker.setCallback(new OverlayPermissionChecker.Callback() {
|
||||
@Override
|
||||
public void onCheckResult(boolean granted) {
|
||||
checker.setCallback(null);
|
||||
Log.d(TAG, "onCheckResult:" + granted);
|
||||
setHasFloatingWindowPermission(App.getApp(), granted);
|
||||
}
|
||||
});
|
||||
checker.check(1500);
|
||||
}
|
||||
|
||||
public static boolean hasFloatingWindowPermission(Context context) {
|
||||
return hasOverlayPermission();
|
||||
}
|
||||
|
||||
private static void setHasFloatingWindowPermission(Context context, boolean has) {
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(KEY_FLOATING_WINDOW_PERMISSION, has).apply();
|
||||
}
|
||||
|
||||
private static boolean hasOverlayPermission() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
return Settings.canDrawOverlays(App.getApp());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isFloatingWindowShowing() {
|
||||
public static boolean isHoverMenuShowing() {
|
||||
return HoverMenuService.isServiceRunning();
|
||||
}
|
||||
|
||||
|
||||
public static void hideFloatingWindow() {
|
||||
public static void hideHoverMenu() {
|
||||
if (HoverMenuService.isServiceRunning())
|
||||
App.getApp().stopService(new Intent(App.getApp(), HoverMenuService.class));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,23 @@
|
||||
package com.stardust.scriptdroid.external.floating_window;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.stardust.enhancedfloaty.FloatyService;
|
||||
import com.stardust.enhancedfloaty.FloatyWindow;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.autojs.api.VolatileBox;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/9.
|
||||
@@ -11,41 +25,99 @@ import com.stardust.enhancedfloaty.FloatyWindow;
|
||||
|
||||
public class OverlayPermissionChecker {
|
||||
|
||||
|
||||
public static void addFloaty() {
|
||||
FloatyService.addWindow(new FloatyWindow() {
|
||||
@Override
|
||||
public void onCreate(FloatyService floatyService, WindowManager windowManager) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDestroy(FloatyService floatyService) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
}
|
||||
});
|
||||
public interface Callback {
|
||||
void onCheckResult(boolean granted);
|
||||
}
|
||||
|
||||
private static class OnePixelWindow implements FloatyWindow {
|
||||
private OnePixelWindow mOnePixelWindow = new OnePixelWindow();
|
||||
private Callback mCallback;
|
||||
private Context mContext;
|
||||
private Handler mHandler;
|
||||
private Boolean mCheckResult = null;
|
||||
|
||||
public OverlayPermissionChecker(Context context) {
|
||||
mContext = context;
|
||||
mHandler = new Handler(context.getMainLooper());
|
||||
}
|
||||
|
||||
public void check() {
|
||||
mCheckResult = null;
|
||||
try {
|
||||
FloatyService.addWindow(mOnePixelWindow);
|
||||
mContext.startService(new Intent(mContext, FloatyService.class));
|
||||
} catch (WindowManager.BadTokenException e) {
|
||||
onCheckResult(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void check(int timeOut) {
|
||||
check();
|
||||
mHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (mCheckResult == null) {
|
||||
onCheckResult(false);
|
||||
}
|
||||
}
|
||||
}, timeOut);
|
||||
}
|
||||
|
||||
public void setCallback(Callback callback) {
|
||||
mCallback = callback;
|
||||
}
|
||||
|
||||
private void onCheckResult(boolean b) {
|
||||
mCheckResult = b;
|
||||
if (mCallback != null) {
|
||||
mCallback.onCheckResult(b);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class OnePixelWindow implements FloatyWindow {
|
||||
|
||||
private View mOnePixelView;
|
||||
private WindowManager mWindowManager;
|
||||
|
||||
@Override
|
||||
public void onCreate(FloatyService floatyService, WindowManager windowManager) {
|
||||
|
||||
mWindowManager = windowManager;
|
||||
mOnePixelView = new View(floatyService) {
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
notifyWindowVisible();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onWindowVisibilityChanged(int visibility) {
|
||||
super.onWindowVisibilityChanged(visibility);
|
||||
}
|
||||
};
|
||||
mOnePixelView.setWillNotDraw(false);
|
||||
mOnePixelView.setBackgroundColor(Color.RED);
|
||||
WindowManager.LayoutParams params = new WindowManager.LayoutParams(10, 10,
|
||||
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
|
||||
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
|
||||
PixelFormat.TRANSLUCENT);
|
||||
params.gravity = Gravity.TOP | Gravity.START;
|
||||
windowManager.addView(mOnePixelView, params);
|
||||
}
|
||||
|
||||
private void notifyWindowVisible() {
|
||||
onCheckResult(true);
|
||||
//close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDestroy(FloatyService floatyService) {
|
||||
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
mWindowManager.removeView(mOnePixelView);
|
||||
FloatyService.removeWindow(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ import com.stardust.scriptdroid.external.CommonUtils;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.script.Scripts;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/2/22.
|
||||
*/
|
||||
@@ -35,6 +37,7 @@ public class RunIntentActivity extends Activity {
|
||||
|
||||
private void handleIntent(Intent intent) {
|
||||
String path = getPath(intent);
|
||||
String directoryPath = null;
|
||||
String script = intent.getStringExtra(CommonUtils.EXTRA_KEY_PRE_EXECUTE_SCRIPT);
|
||||
ScriptSource source = null;
|
||||
if (path == null && script != null) {
|
||||
@@ -42,9 +45,13 @@ public class RunIntentActivity extends Activity {
|
||||
} else if (path != null && new PathChecker(this).checkAndToastError(path)) {
|
||||
ScriptSource fileScriptSource = new FileScriptSource(path);
|
||||
source = new SequenceScriptSource(fileScriptSource.getName(), new StringScriptSource(script), fileScriptSource);
|
||||
directoryPath = new File(path).getParent();
|
||||
}
|
||||
if (source != null) {
|
||||
Scripts.run(source);
|
||||
if (directoryPath == null)
|
||||
Scripts.run(source);
|
||||
else
|
||||
Scripts.run(source, directoryPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.stardust.autojs.execution.ExecutionConfig;
|
||||
import com.stardust.autojs.execution.ScriptExecution;
|
||||
import com.stardust.autojs.execution.ScriptExecutionListener;
|
||||
import com.stardust.autojs.execution.SimpleScriptExecutionListener;
|
||||
@@ -81,15 +82,22 @@ public class Scripts {
|
||||
}
|
||||
|
||||
public static ScriptExecution run(ScriptFile file) {
|
||||
return run(new FileScriptSource(file));
|
||||
return run(new FileScriptSource(file), file.getParent());
|
||||
}
|
||||
|
||||
public static ScriptExecution run(ScriptSource source, String directoryPath) {
|
||||
return AutoJs.getInstance().getScriptEngineService().execute(source, new ExecutionConfig()
|
||||
.requirePath(directoryPath, StorageScriptProvider.DEFAULT_DIRECTORY_PATH));
|
||||
}
|
||||
|
||||
public static ScriptExecution run(ScriptSource source) {
|
||||
return AutoJs.getInstance().getScriptEngineService().execute(source);
|
||||
return AutoJs.getInstance().getScriptEngineService().execute(source, new ExecutionConfig()
|
||||
.requirePath(StorageScriptProvider.DEFAULT_DIRECTORY_PATH));
|
||||
}
|
||||
|
||||
public static ScriptExecution runWithBroadcastSender(ScriptSource scriptSource) {
|
||||
return AutoJs.getInstance().getScriptEngineService().execute(scriptSource, BROADCAST_SENDER_SCRIPT_EXECUTION_LISTENER);
|
||||
public static ScriptExecution runWithBroadcastSender(ScriptSource scriptSource, String directoryPath) {
|
||||
return AutoJs.getInstance().getScriptEngineService().execute(scriptSource, BROADCAST_SENDER_SCRIPT_EXECUTION_LISTENER,
|
||||
new ExecutionConfig().requirePath(directoryPath, StorageScriptProvider.DEFAULT_DIRECTORY_PATH));
|
||||
}
|
||||
|
||||
public static ScriptExecution run(Context context, Sample file) {
|
||||
@@ -97,4 +105,8 @@ public class Scripts {
|
||||
return AutoJs.getInstance().getScriptEngineService().execute(source);
|
||||
}
|
||||
|
||||
public static ScriptExecution runWithBroadcastSender(ScriptSource source) {
|
||||
return AutoJs.getInstance().getScriptEngineService().execute(source, BROADCAST_SENDER_SCRIPT_EXECUTION_LISTENER,
|
||||
new ExecutionConfig().requirePath(StorageScriptProvider.DEFAULT_DIRECTORY_PATH));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.stardust.enhancedfloaty.ResizableExpandableFloatyWindow;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.autojs.api.VolatileBox;
|
||||
import com.stardust.scriptdroid.external.floating_window.FloatingWindowManger;
|
||||
import com.stardust.util.UiHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -50,7 +51,6 @@ public class StardustConsole extends AbstractConsole {
|
||||
private ConsoleFloaty mConsoleFloaty;
|
||||
private LogListener mLogListener;
|
||||
private UiHandler mUiHandler;
|
||||
//private volatile VolatileBox<String> mInput = new VolatileBox<>("");
|
||||
private BlockingQueue<String> mInput = new ArrayBlockingQueue<>(1);
|
||||
private ConsoleView mConsoleView;
|
||||
private volatile boolean mShown = false;
|
||||
@@ -98,6 +98,10 @@ public class StardustConsole extends AbstractConsole {
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
if (!FloatingWindowManger.hasFloatingWindowPermission(mUiHandler.getContext())) {
|
||||
FloatingWindowManger.goToFloatingWindowPermissionSetting();
|
||||
mUiHandler.toast(R.string.text_no_floating_window_permission);
|
||||
}
|
||||
startFloatyService();
|
||||
mUiHandler.post(new Runnable() {
|
||||
@Override
|
||||
|
||||
@@ -206,11 +206,7 @@ public class EditActivity extends Editor920Activity {
|
||||
private void run() {
|
||||
Snackbar.make(mView, R.string.text_start_running, Snackbar.LENGTH_SHORT).show();
|
||||
setMenuStatus(R.id.run, MenuDef.STATUS_DISABLED);
|
||||
if (mFile != null) {
|
||||
mScriptExecution = Scripts.runWithBroadcastSender(new FileScriptSource(mName, mFile));
|
||||
} else {
|
||||
mScriptExecution = Scripts.runWithBroadcastSender(new StringScriptSource(mName, mEditorDelegate.getText()));
|
||||
}
|
||||
mScriptExecution = Scripts.runWithBroadcastSender(new FileScriptSource(mName, mFile), mFile.getParent());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ public class EditSideMenuFragment extends Fragment {
|
||||
}
|
||||
|
||||
private void syncSwitchState() {
|
||||
mFloatingWindowSwitch.setChecked(FloatingWindowManger.isFloatingWindowShowing());
|
||||
mFloatingWindowSwitch.setChecked(FloatingWindowManger.isHoverMenuShowing());
|
||||
}
|
||||
|
||||
private void setUpSwitchCompat() {
|
||||
@@ -97,10 +97,10 @@ public class EditSideMenuFragment extends Fragment {
|
||||
|
||||
@ViewBinding.Check(R.id.sw_floating_window)
|
||||
private void setFloatingWindowEnable(boolean enable) {
|
||||
if (enable && !FloatingWindowManger.isFloatingWindowShowing()) {
|
||||
if (enable && !FloatingWindowManger.isHoverMenuShowing()) {
|
||||
FloatingWindowManger.showHoverMenu();
|
||||
} else if (!enable && FloatingWindowManger.isFloatingWindowShowing()) {
|
||||
FloatingWindowManger.hideFloatingWindow();
|
||||
} else if (!enable && FloatingWindowManger.isHoverMenuShowing()) {
|
||||
FloatingWindowManger.hideHoverMenu();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.stardust.app.NotAskAgainDialog;
|
||||
import com.stardust.app.OnActivityResultDelegate;
|
||||
import com.stardust.scriptdroid.BuildConfig;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.external.floating_window.FloatingWindowManger;
|
||||
import com.stardust.scriptdroid.script.ScriptFile;
|
||||
import com.stardust.scriptdroid.script.StorageScriptProvider;
|
||||
import com.stardust.scriptdroid.script.sample.Sample;
|
||||
|
||||
@@ -88,7 +88,7 @@ public class SlideMenuFragment extends Fragment {
|
||||
});
|
||||
}
|
||||
}, 450);
|
||||
mFloatingWindowSwitch.setChecked(FloatingWindowManger.isFloatingWindowShowing());
|
||||
mFloatingWindowSwitch.setChecked(FloatingWindowManger.isHoverMenuShowing());
|
||||
}
|
||||
|
||||
private void setUpSwitchCompat() {
|
||||
@@ -123,10 +123,10 @@ public class SlideMenuFragment extends Fragment {
|
||||
|
||||
@ViewBinding.Check(R.id.sw_floating_window)
|
||||
private void setFloatingWindowEnable(boolean enable) {
|
||||
if (enable && !FloatingWindowManger.isFloatingWindowShowing()) {
|
||||
if (enable && !FloatingWindowManger.isHoverMenuShowing()) {
|
||||
FloatingWindowManger.showHoverMenu();
|
||||
} else if (!enable && FloatingWindowManger.isFloatingWindowShowing()) {
|
||||
FloatingWindowManger.hideFloatingWindow();
|
||||
} else if (!enable && FloatingWindowManger.isHoverMenuShowing()) {
|
||||
FloatingWindowManger.hideHoverMenu();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user