diff --git a/app/src/main/java/org/autojs/autojs/ui/edit/editor/CodeEditText.java b/app/src/main/java/org/autojs/autojs/ui/edit/editor/CodeEditText.java index d9bfa6f4..8f27a861 100644 --- a/app/src/main/java/org/autojs/autojs/ui/edit/editor/CodeEditText.java +++ b/app/src/main/java/org/autojs/autojs/ui/edit/editor/CodeEditText.java @@ -190,14 +190,6 @@ public class CodeEditText extends AppCompatEditText { } } - @Override - public boolean onTextContextMenuItem(int id) { - if (id == android.R.id.paste) { - ClipboardUtil.setClip(getContext(), ClipboardUtil.getClip(getContext()).toString()); - } - return super.onTextContextMenuItem(id); - } - //该方法中内联了很多函数来提高效率 但是 这是必要的吗??? // 绘制文本着色 private void drawText(Canvas canvas) { diff --git a/autojs/src/main/assets/modules/__app__.js b/autojs/src/main/assets/modules/__app__.js index 1543d77f..57fb965b 100644 --- a/autojs/src/main/assets/modules/__app__.js +++ b/autojs/src/main/assets/modules/__app__.js @@ -62,7 +62,11 @@ module.exports = function (runtime, global) { throw new Error("class " + i + " not found"); } } - context.startActivity(app.intent(i).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); + if(i && i.root) { + shell("am start " + app.intentToShell(i), true); + }else{ + context.startActivity(app.intent(i).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); + } } app.sendBroadcast = function (i) { @@ -71,7 +75,19 @@ module.exports = function (runtime, global) { app.sendLocalBroadcastSync(app.intent({ action: runtime.getProperty("broadcast." + i) })); } } - context.sendBroadcast(app.intent(i)); + if(i && i.root) { + shell("am broadcast " + app.intentToShell(i), true); + }else{ + context.sendBroadcast(app.intent(i)); + } + } + + app.startService = function(i) { + if(i && i.root) { + shell("am startservice " + app.intentToShell(i), true); + }else{ + context.startService(app.intent(i)); + } } app.sendEmail = function (options) { @@ -139,6 +155,101 @@ module.exports = function (runtime, global) { versionName: org.autojs.autojs.BuildConfig.VERSION_NAME }; + app.intentToShell = function(i) { + var cmd = ""; + function quoteStr(str) { + return "'" + str.replace("'", "\\'") + "'"; + } + function isInt(value) { + return Bumber.isInteger(value) && value <= java.lang.Integer.MAX_VALUE && value >= java.lang.Integer.MIN_VALUE; + } + function typeChar(value){ + if(typeof(value) == 'boolean'){ + return 'z'; + } + if(typeof(value) == 'number'){ + if(Number.isInteger(value)){ + if(isInt(value)){ + return 'i'; + }else{ + return 'l'; + } + }else{ + return 'f'; + } + } + throw new TypeError("unknown type: " + value); + } + function addOption(option, param, quote) { + if(quote == undefined || quote === true){ + param = quoteStr(param); + } + cmd += " -" + option + " " + param; + } + if (i.className && i.packageName) { + addOption("n", i.packageName + "/" + i.className); + } + if (i.extras) { + for (var key in i.extras) { + let value = i.extras[key]; + if(typeof(value) == 'string'){ + addOption("-es", quoteStr(key) + ' ' + quoteStr(value), false); + }else if(Array.isArray(value)){ + if(value.length == 0){ + throw new Error('Empty array: ' + key); + } + var e = value[0]; + if(typeof(e) == 'string'){ + cmd += ' --esa ' + quoteStr(key) + ' '; + for(let str of value){ + cmd += quoteStr(str) + ','; + } + cmd = cmd.substring(0, cmd.length - 1); + }else{ + addOption('-e' + typeChar(e) + 'a', quoteStr(key) + ' ' + value, false); + } + }else { + addOption('-e' + typeChar(value), quoteStr(key) + ' ' + value, false); + } + } + } + if (i.category) { + if (i.category instanceof Array) { + for (var j = 0; i < i.category.length; j++) { + addOption('c', i.category[j], false); + } + } else { + addOption('c', i.category, false); + } + } + if (i.action) { + if (i.action.indexOf(".") == -1) { + i.action = "android.intent.action." + i.action; + } + addOption('a', i.action); + } + if (i.flags) { + let flags = 0; + if (Array.isArray(i.flags)) { + for (let j = 0; j < i.flags.length; j++) { + flags |= parseIntentFlag(i.flags[j]); + } + } else { + flags = parseIntentFlag(i.flags); + } + addOption('f', flags, false); + } + if (i.type) { + addOption('t', i.type, false); + } + if (i.data) { + addOption('d', i.data, false); + } + return cmd; + } + + + global.__asGlobal__(app, ['launchPackage', 'launch', 'launchApp', 'getPackageName', 'getAppName', 'openAppSetting']); function parseIntentFlag(flag) { diff --git a/common/release/output.json b/common/release/output.json index ea784926..cb815497 100644 --- a/common/release/output.json +++ b/common/release/output.json @@ -1 +1 @@ -[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":439,"versionName":"4.0.4 Alpha10","enabled":true,"outputFile":"commonRelease-4.0.4 Alpha10.apk","fullName":"commonRelease","baseName":"common-release"},"path":"commonRelease-4.0.4 Alpha10.apk","properties":{}}] \ No newline at end of file +[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":440,"versionName":"4.0.4 Alpha11","enabled":true,"outputFile":"commonRelease-4.0.4 Alpha11.apk","fullName":"commonRelease","baseName":"common-release"},"path":"commonRelease-4.0.4 Alpha11.apk","properties":{}}] \ No newline at end of file diff --git a/common/src/main/java/com/stardust/util/ClipboardUtil.java b/common/src/main/java/com/stardust/util/ClipboardUtil.java index 9165d1e9..751ab56e 100644 --- a/common/src/main/java/com/stardust/util/ClipboardUtil.java +++ b/common/src/main/java/com/stardust/util/ClipboardUtil.java @@ -3,6 +3,7 @@ package com.stardust.util; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; +import android.content.Intent; import android.support.annotation.NonNull;