mirror of
https://github.com/TonyJiangWJ/Auto.js.git
synced 2026-06-21 21:01:43 +08:00
Added: setClip
This commit is contained in:
parent
8e3db7c7c3
commit
6ec0601373
Binary file not shown.
@ -7,8 +7,8 @@ android {
|
||||
applicationId "com.stardust.scriptdroid"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 23
|
||||
versionCode 31
|
||||
versionName "1.17.0221"
|
||||
versionCode 34
|
||||
versionName "1.17.0223"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
|
||||
@ -90,9 +90,9 @@
|
||||
<service android:name=".service.VolumeChangeListenService"/>
|
||||
|
||||
<activity
|
||||
android:name=".ui.edit.EditAndRunIntentActivity"
|
||||
android:name=".external.open.EditIntentActivity"
|
||||
android:icon="@drawable/ic_edit_green_48dp"
|
||||
android:label="编辑与运行脚本">
|
||||
android:label="编辑脚本">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
@ -129,7 +129,47 @@
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ui.edit.ImportIntentActivity"
|
||||
android:name=".external.open.RunIntentActivity"
|
||||
android:icon="@drawable/ic_play_green"
|
||||
android:label="运行脚本">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<action android:name="android.intent.action.EDIT"/>
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
|
||||
<data android:scheme="file"/>
|
||||
<data android:scheme="content"/>
|
||||
<data android:mimeType="application/x-*"/>
|
||||
<data android:mimeType="application/postscript"/>
|
||||
<data android:mimeType="application/plain"/>
|
||||
<data android:mimeType="application/x-javascript"/>
|
||||
<data android:mimeType="text/*"/>
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND"/>
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
|
||||
<data android:mimeType="text/*"/>
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEARCH"/>
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="com.googlecode.android_scripting.action.EDIT_SCRIPT"/>
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
|
||||
<activity
|
||||
android:name=".external.open.ImportIntentActivity"
|
||||
android:icon="@drawable/ic_folder_open_outline_green"
|
||||
android:label="导入脚本文件">
|
||||
|
||||
|
||||
@ -132,4 +132,8 @@ var getPackageName = function(){
|
||||
|
||||
var getActivityName = function(){
|
||||
return droid.getActivityName();
|
||||
}
|
||||
|
||||
var setClip = function(text){
|
||||
droid.setClip(text);
|
||||
}
|
||||
@ -1,5 +1,8 @@
|
||||
package com.stardust.scriptdroid.droid.runtime;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
@ -145,6 +148,15 @@ public class DroidRuntime implements IDroidRuntime {
|
||||
return performAction(target.createAction(AccessibilityNodeInfo.ACTION_SET_TEXT, text));
|
||||
}
|
||||
|
||||
public void setClip(final String text) {
|
||||
mUIHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
((ClipboardManager) App.getApp().getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText(TAG, text));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean paste(ActionTarget target) {
|
||||
return performAction(target.createAction(AccessibilityNodeInfo.ACTION_PASTE));
|
||||
|
||||
@ -73,12 +73,14 @@ public class ActionPerformAccessibilityDelegate implements AccessibilityDelegate
|
||||
if (latestPackage == null)
|
||||
return;
|
||||
ActionPerformAccessibilityDelegate.latestPackage = latestPackage.toString();
|
||||
ComponentName componentName = new ComponentName(latestPackage.toString(), latestClass == null ? null : latestClass.toString());
|
||||
if(latestClass == null)
|
||||
return;
|
||||
try {
|
||||
ComponentName componentName = new ComponentName(latestPackage.toString(), latestClass.toString());
|
||||
ActivityInfo activityInfo = App.getApp().getPackageManager().getActivityInfo(componentName, 0);
|
||||
ActionPerformAccessibilityDelegate.latestActivity = activityInfo.name;
|
||||
} catch (PackageManager.NameNotFoundException ignored) {
|
||||
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.stardust.scriptdroid.ui.edit;
|
||||
package com.stardust.scriptdroid.external.open;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
@ -8,12 +8,13 @@ import android.widget.Toast;
|
||||
|
||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.ui.edit.EditActivity;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/2/2.
|
||||
*/
|
||||
|
||||
public class EditAndRunIntentActivity extends BaseActivity {
|
||||
public class EditIntentActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@ -24,6 +25,7 @@ public class EditAndRunIntentActivity extends BaseActivity {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(this, R.string.edit_and_run_handle_intent_error, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
private void handleIntent() {
|
||||
@ -1,10 +1,11 @@
|
||||
package com.stardust.scriptdroid.ui.edit;
|
||||
package com.stardust.scriptdroid.external.open;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||
@ -24,7 +25,13 @@ public class ImportIntentActivity extends BaseActivity {
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
handleIntent();
|
||||
try {
|
||||
handleIntent();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(this, R.string.edit_and_run_handle_intent_error, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
private void handleIntent() {
|
||||
40
app/src/main/java/com/stardust/scriptdroid/external/open/RunIntentActivity.java
vendored
Normal file
40
app/src/main/java/com/stardust/scriptdroid/external/open/RunIntentActivity.java
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
package com.stardust.scriptdroid.external.open;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.external.shortcut.ShortcutActivity;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/2/22.
|
||||
*/
|
||||
|
||||
public class RunIntentActivity extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
try {
|
||||
handleIntent();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(this, R.string.edit_and_run_handle_intent_error, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
private void handleIntent() {
|
||||
Intent intent = getIntent();
|
||||
String path = intent.getData().getPath();
|
||||
if (!TextUtils.isEmpty(path)) {
|
||||
startActivity(new Intent(this, ShortcutActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra("path", path));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -198,4 +198,17 @@ public class FileUtils {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static String generateNotExistingPath(String path, String extension) {
|
||||
if (!new File(path + extension).exists())
|
||||
return path + extension;
|
||||
int i = 0;
|
||||
while (true) {
|
||||
String pathI = path + "(" + i + ")" + extension;
|
||||
if (!new File(pathI).exists())
|
||||
return pathI;
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -47,7 +47,7 @@ public class CodeCompletion implements TextWatcher {
|
||||
}
|
||||
|
||||
interface OnCodeCompletionChangeListener {
|
||||
void OnCodeCompletionChange(Collection<CodeCompletionItem> list);
|
||||
void OnCodeCompletionChange(Collection<CodeCompletionItem>... list);
|
||||
}
|
||||
|
||||
private static final String TAG = "CodeCompletion";
|
||||
@ -101,14 +101,14 @@ public class CodeCompletion implements TextWatcher {
|
||||
|
||||
private static final String[] KEYWORDS = {"arguments", "break", "case", "catch", "class", "continue", "default", "do", "else", "eval", "export", "false", "for", "function", "if", "import", "in", "int", "new", "null", "package", "return", "switch", "this", "throw", "throws", "true", "try", "typeof", "var", "volatile", "while", "with", "Array", "Date", "hasOwnProperty", "Infinity", "isFinite", "isNaN", "isPrototypeOf", "length", "Math", "NaN", "name", "Number", "Object", "prototype", "String", "toString", "undefined", "valueOf"};
|
||||
private static final int KEY_WORD_LENGTH_MAX = 15;
|
||||
private static final String[] FUNCTIONS = {"toast", "launchPackage", "launch", "launchApp", "click", "longClick", "scrollUp", "scrollDown", "select", "focus", "paste", "input", "sleep", "isStopped", "notStopped", "log", "err", "openConsole", "clearConsole", "shell", "getTexts", "getPackageName", "getActivityName"};
|
||||
private static final String[] FUNCTIONS = {"toast", "launchPackage", "launch", "launchApp", "click", "longClick", "scrollUp", "scrollDown", "select", "focus", "paste", "input", "sleep", "isStopped", "notStopped", "log", "err", "openConsole", "clearConsole", "shell", "getTexts", "getPackageName", "getActivityName", "setClip"};
|
||||
|
||||
private boolean searchCodeCompletion(String str) {
|
||||
Collection<CodeCompletionItem> c = searchWordCompletion(str);
|
||||
c.addAll(searchCodeCompletion(str, FUNCTIONS));
|
||||
c.addAll(searchKeyWordCompletion(str));
|
||||
if (c.size() > 0) {
|
||||
mOnCodeCompletionChangeListener.OnCodeCompletionChange(c);
|
||||
mOnCodeCompletionChangeListener.OnCodeCompletionChange(c, DEFAULT_CODE_COMPLETION_LIST);
|
||||
return true;
|
||||
} else {
|
||||
mOnCodeCompletionChangeListener.OnCodeCompletionChange(DEFAULT_CODE_COMPLETION_LIST);
|
||||
|
||||
@ -68,9 +68,11 @@ public class InputMethodEnhanceBar extends RecyclerView implements CodeCompletio
|
||||
}
|
||||
|
||||
@Override
|
||||
public void OnCodeCompletionChange(Collection<CodeCompletion.CodeCompletionItem> list) {
|
||||
public void OnCodeCompletionChange(Collection<CodeCompletion.CodeCompletionItem>... lists) {
|
||||
mCodeCompletionList.clear();
|
||||
mCodeCompletionList.addAll(list);
|
||||
for (Collection<CodeCompletion.CodeCompletionItem> list : lists) {
|
||||
mCodeCompletionList.addAll(list);
|
||||
}
|
||||
getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
@ -25,7 +25,6 @@ public class IssueReportActivity extends IssueReporterActivity {
|
||||
private boolean mCrash = false;
|
||||
private Method mReportIssue, mValidateInput;
|
||||
private boolean mReportFailed = false;
|
||||
private String token = "d";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -129,7 +128,7 @@ public class IssueReportActivity extends IssueReporterActivity {
|
||||
@Override
|
||||
protected String getGuestToken() {
|
||||
//绕过github安全检查
|
||||
return decode("NDlkZDU3NjRiYTk3NzVmZDkxOTA3MDQ4YTdmNzQ1ZDY5NjcyNzEyNA==");
|
||||
return decode("MzA5MWJhNWI0NDM2NWYzOGRmNDA4ZWRhM2Y5MTUxN2ZlNDVlZDBhZQ==");
|
||||
}
|
||||
|
||||
public static String decode(String str) {
|
||||
|
||||
@ -163,10 +163,11 @@ public class MainActivity extends BaseActivity implements FileChooserDialog.File
|
||||
.input(getString(R.string.text_please_input_name), "", new MaterialDialog.InputCallback() {
|
||||
@Override
|
||||
public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
|
||||
String path = ScriptFile.DEFAULT_FOLDER + input + ".js";
|
||||
String path = FileUtils.generateNotExistingPath(ScriptFile.DEFAULT_FOLDER + input, ".js");
|
||||
MainActivity.this.createScriptFile(input.toString(), path, script);
|
||||
}
|
||||
}).show();
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
private void createScriptFile(String name, String path, String script) {
|
||||
|
||||
@ -28,6 +28,7 @@
|
||||
* `getTexts()` 获取屏幕上的文字列表, 返回一个java.util.List<String>。例如:
|
||||
* `getPackageName` 获取正在运行的应用包名
|
||||
* `getActivityName` 获取正在运行的Activity名称
|
||||
* `setClip(text)` 设置剪贴板文本
|
||||
```
|
||||
launchApp("微信");
|
||||
while(!click("通讯录"));
|
||||
|
||||
@ -124,4 +124,5 @@
|
||||
<string name="text_edit">编辑</string>
|
||||
<string name="key_max_length_for_code_completion">key_max_length_for_code_completion</string>
|
||||
<string name="text_max_length_for_code_completion">代码补全最大文件长度</string>
|
||||
<string name="text_file_exists">文件已存在</string>
|
||||
</resources>
|
||||
|
||||
@ -14,26 +14,6 @@ public class ExampleUnitTest {
|
||||
@Test
|
||||
public void testSync() throws Exception {
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
synchronized (this) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
synchronized (this) {
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user