@@ -9,8 +9,8 @@ android {
|
|||||||
applicationId "com.stardust.scriptdroid"
|
applicationId "com.stardust.scriptdroid"
|
||||||
minSdkVersion 19
|
minSdkVersion 19
|
||||||
targetSdkVersion 23
|
targetSdkVersion 23
|
||||||
versionCode 140
|
versionCode 141
|
||||||
versionName "2.0.13 Alpha3"
|
versionName "2.0.13 Beta"
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
ndk {
|
ndk {
|
||||||
|
|||||||
@@ -38,10 +38,11 @@
|
|||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".external.shortcut.ShortcutActivity"
|
android:name=".external.shortcut.ShortcutActivity"
|
||||||
android:theme="@style/AppTheme.NoActionBar">
|
android:taskAffinity="com.stardust.scriptdroid.external.shortcut.ShortcutActivity"
|
||||||
|
android:theme="@android:style/Theme.NoDisplay">
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.example.Project.Action"/>
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
@@ -78,6 +79,7 @@
|
|||||||
android:name=".ui.error.IssueReporterActivity"
|
android:name=".ui.error.IssueReporterActivity"
|
||||||
android:theme="@style/IssueReporterTheme"/>
|
android:theme="@style/IssueReporterTheme"/>
|
||||||
|
|
||||||
|
|
||||||
<service android:name="com.stardust.scriptdroid.external.ScriptExecutionIntentService"/>
|
<service android:name="com.stardust.scriptdroid.external.ScriptExecutionIntentService"/>
|
||||||
<service android:name="com.stardust.scriptdroid.external.floatingwindow.menu.HoverMenuService"/>
|
<service android:name="com.stardust.scriptdroid.external.floatingwindow.menu.HoverMenuService"/>
|
||||||
|
|
||||||
@@ -151,7 +153,9 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name=".external.open.RunIntentActivity"
|
android:name=".external.open.RunIntentActivity"
|
||||||
android:icon="@drawable/ic_ali_run"
|
android:icon="@drawable/ic_ali_run"
|
||||||
android:label="运行脚本">
|
android:label="运行脚本"
|
||||||
|
android:taskAffinity="com.stardust.scriptdroid.external.open.RunIntentActivity"
|
||||||
|
android:theme="@android:style/Theme.NoDisplay">
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW"/>
|
<action android:name="android.intent.action.VIEW"/>
|
||||||
|
|||||||
@@ -3,23 +3,23 @@ shell命令是通过shell函数运行的命令。等同于"adb shell"。shell函
|
|||||||
* cmd \<String\> 要执行的命令
|
* cmd \<String\> 要执行的命令
|
||||||
* root \<Boolean\> 是否以root权限运行,默认为false。
|
* root \<Boolean\> 是否以root权限运行,默认为false。
|
||||||
返回运行一个执行结果。该返回值一般不会用到,其属性如下:
|
返回运行一个执行结果。该返回值一般不会用到,其属性如下:
|
||||||
* code \<Number\> 返回码。执行成功时为1,失败时为非1的数字,一般为0。
|
* code \<Number\> 返回码。执行成功时为0,失败时为非0的数字。
|
||||||
* result \<String\> 运行结果。
|
* result \<String\> 运行结果。
|
||||||
* error \<String\> 运行的错误信息。例如执行需要root权限的命令但没有授予root权限会返回错误信息"Permission denied"。
|
* error \<String\> 运行的错误信息。例如执行需要root权限的命令但没有授予root权限会返回错误信息"Permission denied"。
|
||||||
|
|
||||||
示例(强制停止微信) :
|
示例(强制停止微信) :
|
||||||
```
|
```
|
||||||
var result = shell("am force-stop com.tencent.mm", true);
|
var result = shell("am force-stop com.tencent.mm", true);
|
||||||
if(result.code == 1){
|
log(result);
|
||||||
|
openConsole();
|
||||||
|
if(result.code == 0){
|
||||||
toast("执行成功");
|
toast("执行成功");
|
||||||
}else{
|
}else{
|
||||||
toast("执行失败!请到控制台查看错误信息");
|
toast("执行失败!请到控制台查看错误信息");
|
||||||
err(result.error);
|
|
||||||
openConsole();
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
以下关于shell命令的资料来自[AndroidStudio用户指南:Sehll命令](https://developer.android.com/studio/command-line/adb.html#shellcommands)。
|
以下关于shell命令的资料来自[AndroidStudio用户指南:Shell命令](https://developer.android.com/studio/command-line/adb.html#shellcommands)。
|
||||||
|
|
||||||
目录:
|
目录:
|
||||||
* [am命令](#am命令)
|
* [am命令](#am命令)
|
||||||
@@ -367,31 +367,19 @@ log(shell("ls /system/bin"));
|
|||||||
|
|
||||||
Shell类的构造函数。
|
Shell类的构造函数。
|
||||||
|
|
||||||
### Shell.execute(cmd)
|
### Shell.exec(cmd)
|
||||||
* cmd \<String\> 要执行的命令
|
* cmd \<String\> 要执行的命令
|
||||||
|
|
||||||
|
该命令没有返回值。
|
||||||
|
|
||||||
执行命令cmd,例如:
|
执行命令cmd,例如:
|
||||||
```
|
```
|
||||||
var sh = Shell(true);
|
var sh = new Shell(true);
|
||||||
sh.execute("rm /sdcard/1.txt"); //删除SD卡上的1.txt文件
|
sh.exec("rm -f /sdcard/1.txt"); //删除SD卡上的1.txt文件
|
||||||
```
|
```
|
||||||
|
|
||||||
### Shell.exitAndWaitFor()
|
|
||||||
退出Shell,并等待所有命令执行完成。
|
|
||||||
一个完整的例子如下:
|
|
||||||
```
|
|
||||||
var sh = Shell(true);
|
|
||||||
sh.execute("rm /sdcard/1.txt");
|
|
||||||
sh.execute("input keyevent 26");
|
|
||||||
sh.exitAndWaitFor();
|
|
||||||
```
|
|
||||||
|
|
||||||
### Shell.waitFor()
|
|
||||||
等待当前所有命令执行完成。返回一个整数作为返回码,1为执行成功,其他数字为错误。
|
|
||||||
|
|
||||||
### Shell.exit()
|
### Shell.exit()
|
||||||
退出Shell。调用该函数后再执行的命令无效。
|
退出Shell。调用该函数后再执行的命令无效。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
除以上命令之外, Shell也包含自动操作的命令,例如Shell.Tap,参见《需要Root权限的自动操作函数》。
|
除以上命令之外, Shell也包含自动操作的命令,例如Shell.Tap,参见《需要Root权限的自动操作函数》。
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
### requestScreenCapture(\[width, height\])
|
### requestScreenCapture(\[width, height\])
|
||||||
|
|
||||||
参数width和height用于指定截图的分辨率,默认为屏幕宽高。
|
参数width和height用于指定截图的分辨率,默认为屏幕宽高。
|
||||||
|
|
||||||
|
未完待续。
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
控制台通常用来输出一些调试信息和运算结果。
|
控制台通常用来输出一些调试信息和运算结果。
|
||||||
而Toast是安卓上一种显示信息的机制,即使应用在后台运行也能显示。
|
|
||||||
|
|
||||||
### openConsole()
|
### openConsole()
|
||||||
显示控制台。
|
显示控制台。
|
||||||
@@ -30,4 +29,4 @@ try{
|
|||||||
### toast(message)
|
### toast(message)
|
||||||
* message \<String\> | \<Object\> 要显示的信息
|
* message \<String\> | \<Object\> 要显示的信息
|
||||||
|
|
||||||
以灰色的方框显示信息message几秒。(具体时间取决于安卓系统)
|
以气泡显示信息message几秒。(具体时间取决于安卓系统)
|
||||||
@@ -33,7 +33,6 @@ public class CommonUtils {
|
|||||||
String directoryPath = null;
|
String directoryPath = null;
|
||||||
String script = intent.getStringExtra(CommonUtils.EXTRA_KEY_PRE_EXECUTE_SCRIPT);
|
String script = intent.getStringExtra(CommonUtils.EXTRA_KEY_PRE_EXECUTE_SCRIPT);
|
||||||
ScriptSource source = null;
|
ScriptSource source = null;
|
||||||
Toast.makeText(context, path, Toast.LENGTH_SHORT).show();
|
|
||||||
if (path == null && script != null) {
|
if (path == null && script != null) {
|
||||||
source = new StringScriptSource(script);
|
source = new StringScriptSource(script);
|
||||||
} else if (path != null && new PathChecker(context).checkAndToastError(path)) {
|
} else if (path != null && new PathChecker(context).checkAndToastError(path)) {
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package com.stardust.scriptdroid.external.floatingwindow.menu.layout_inspector;
|
package com.stardust.scriptdroid.external.floatingwindow.menu.layout_inspector;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
import android.view.accessibility.AccessibilityNodeInfo;
|
import android.view.accessibility.AccessibilityNodeInfo;
|
||||||
|
|
||||||
import com.stardust.view.accessibility.AccessibilityService;
|
import com.stardust.view.accessibility.AccessibilityService;
|
||||||
import com.stardust.util.UnderuseExecutors;
|
import com.stardust.util.UnderuseExecutors;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/3/10.
|
* Created by Stardust on 2017/3/10.
|
||||||
@@ -13,16 +15,19 @@ import java.util.concurrent.Executor;
|
|||||||
|
|
||||||
public class LayoutInspector {
|
public class LayoutInspector {
|
||||||
|
|
||||||
|
private static final String LOG_TAG = LayoutInspector.class.getSimpleName();
|
||||||
private volatile NodeInfo mCapture;
|
private volatile NodeInfo mCapture;
|
||||||
private volatile boolean mDumping = false;
|
private volatile boolean mDumping = false;
|
||||||
private Executor mExecutor = UnderuseExecutors.getExecutor();
|
private Executor mExecutor = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
public void captureCurrentWindow() {
|
public void captureCurrentWindow() {
|
||||||
AccessibilityService service = AccessibilityService.getInstance();
|
AccessibilityService service = AccessibilityService.getInstance();
|
||||||
if (service == null) {
|
if (service == null) {
|
||||||
|
Log.d(LOG_TAG, "captureCurrentWindow: service = null");
|
||||||
mCapture = null;
|
mCapture = null;
|
||||||
} else {
|
} else {
|
||||||
final AccessibilityNodeInfo root = service.getRootInActiveWindow();
|
final AccessibilityNodeInfo root = service.getRootInActiveWindow();
|
||||||
|
Log.d(LOG_TAG, "captureCurrentWindow: root = null");
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
mCapture = null;
|
mCapture = null;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.stardust.scriptdroid.external.shortcut;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -23,10 +23,6 @@ public class ShortcutActivity extends Activity {
|
|||||||
if (new PathChecker(this).checkAndToastError(path)) {
|
if (new PathChecker(this).checkAndToastError(path)) {
|
||||||
runScriptFile(path);
|
runScriptFile(path);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void onStart() {
|
|
||||||
super.onStart();
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import com.stardust.scriptdroid.ui.edit.EditActivity;
|
|||||||
import com.stardust.scriptdroid.ui.edit.completion.InputMethodEnhanceBar;
|
import com.stardust.scriptdroid.ui.edit.completion.InputMethodEnhanceBar;
|
||||||
import com.stardust.scriptdroid.ui.edit.editor920.Editor920Activity;
|
import com.stardust.scriptdroid.ui.edit.editor920.Editor920Activity;
|
||||||
import com.stardust.scriptdroid.ui.edit.editor920.Editor920Utils;
|
import com.stardust.scriptdroid.ui.edit.editor920.Editor920Utils;
|
||||||
|
import com.stardust.theme.ThemeColorManager;
|
||||||
|
import com.stardust.theme.ThemeColorManagerCompat;
|
||||||
import com.stardust.view.ViewBinder;
|
import com.stardust.view.ViewBinder;
|
||||||
import com.stardust.view.ViewBinding;
|
import com.stardust.view.ViewBinding;
|
||||||
import com.stardust.widget.ToolbarMenuItem;
|
import com.stardust.widget.ToolbarMenuItem;
|
||||||
@@ -56,6 +58,7 @@ public class TaskerScriptEditActivity extends Editor920Activity {
|
|||||||
((TextView) findViewById(R.id.summary)).setText(mSummary);
|
((TextView) findViewById(R.id.summary)).setText(mSummary);
|
||||||
mRedo = (ToolbarMenuItem) findViewById(R.id.redo);
|
mRedo = (ToolbarMenuItem) findViewById(R.id.redo);
|
||||||
mUndo = (ToolbarMenuItem) findViewById(R.id.undo);
|
mUndo = (ToolbarMenuItem) findViewById(R.id.undo);
|
||||||
|
ThemeColorManager.addActivityStatusBar(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleIntent(Intent intent) {
|
private void handleIntent(Intent intent) {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class ScriptFile extends File {
|
|||||||
if (isDirectory())
|
if (isDirectory())
|
||||||
return renameTo(new File(getParent(), newName));
|
return renameTo(new File(getParent(), newName));
|
||||||
else
|
else
|
||||||
return renameTo(new File(getParent(), newName + getExtension()));
|
return renameTo(new File(getParent(), newName + "." + getExtension()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getExtension() {
|
private String getExtension() {
|
||||||
|
|||||||
@@ -30,8 +30,6 @@ public class VersionInfo {
|
|||||||
|
|
||||||
private boolean mDeprecated = false;
|
private boolean mDeprecated = false;
|
||||||
private UpdateChecker.UpdateInfo mUpdateInfo;
|
private UpdateChecker.UpdateInfo mUpdateInfo;
|
||||||
private final int mReconnectTimes = 2;
|
|
||||||
private int mReconnectCount = 0;
|
|
||||||
private OnReceiveUpdateResultCallback mOnReceiveUpdateResultCallback;
|
private OnReceiveUpdateResultCallback mOnReceiveUpdateResultCallback;
|
||||||
private SharedPreferences mSharedPreferences;
|
private SharedPreferences mSharedPreferences;
|
||||||
|
|
||||||
@@ -87,28 +85,22 @@ public class VersionInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void checkUpdate(Context context) {
|
public void checkUpdate(Context context) {
|
||||||
mReconnectCount = 0;
|
|
||||||
checkUpdateInner(context);
|
checkUpdateInner(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkUpdateInner(final Context context) {
|
private void checkUpdateInner(final Context context) {
|
||||||
mReconnectCount++;
|
|
||||||
new UpdateChecker(context).check(new UpdateChecker.Callback() {
|
new UpdateChecker(context).check(new UpdateChecker.Callback() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(UpdateChecker.UpdateInfo result) {
|
public void onSuccess(UpdateChecker.UpdateInfo result) {
|
||||||
if (result.isValid()) {
|
if (result.isValid()) {
|
||||||
setUpdateInfo(result);
|
setUpdateInfo(result);
|
||||||
} else if (mReconnectCount < mReconnectTimes) {
|
|
||||||
checkUpdate(context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Exception exception) {
|
public void onError(Exception exception) {
|
||||||
if (mReconnectCount < mReconnectTimes) {
|
exception.printStackTrace();
|
||||||
checkUpdate(context);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,6 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
checkPermissions();
|
checkPermissions();
|
||||||
registerBackPressHandlers();
|
|
||||||
mIntentToHandle = getIntent();
|
mIntentToHandle = getIntent();
|
||||||
EventBus.getDefault().register(this);
|
EventBus.getDefault().register(this);
|
||||||
mVersionGuard = new VersionGuard(this);
|
mVersionGuard = new VersionGuard(this);
|
||||||
@@ -113,7 +112,7 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
|||||||
setUpDrawerHeader();
|
setUpDrawerHeader();
|
||||||
setUpFragment();
|
setUpFragment();
|
||||||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
||||||
|
registerBackPressHandlers();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showAnnunciationIfNeeded() {
|
private void showAnnunciationIfNeeded() {
|
||||||
|
|||||||
@@ -55,12 +55,6 @@ public class MyScriptListFragment extends Fragment {
|
|||||||
private MaterialDialog.InputCallback mDirectoryNameInputCallback = new InputCallback(true);
|
private MaterialDialog.InputCallback mDirectoryNameInputCallback = new InputCallback(true);
|
||||||
private String mFilePathToImport;
|
private String mFilePathToImport;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View createView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View createView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
|
|||||||
@@ -4,14 +4,12 @@
|
|||||||
>
|
>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:label="@string/app_name"
|
android:label="@string/_app_name"
|
||||||
>
|
>
|
||||||
<activity android:name=".execution.ScriptExecuteActivity"/>
|
<activity android:name=".execution.ScriptExecuteActivity"/>
|
||||||
<service
|
<service
|
||||||
android:name="com.stardust.view.accessibility.AccessibilityService"
|
android:name="com.stardust.view.accessibility.AccessibilityService"
|
||||||
android:enabled="true"
|
android:label="@string/_app_name"
|
||||||
android:exported="true"
|
|
||||||
android:label="@string/app_name"
|
|
||||||
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
|
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.accessibilityservice.AccessibilityService"/>
|
<action android:name="android.accessibilityservice.AccessibilityService"/>
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ import android.content.pm.ApplicationInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.webkit.MimeTypeMap;
|
||||||
|
|
||||||
import com.stardust.autojs.runtime.ScriptInterface;
|
import com.stardust.autojs.runtime.ScriptInterface;
|
||||||
import com.stardust.util.IntentUtil;
|
import com.stardust.util.IntentUtil;
|
||||||
@@ -15,6 +17,8 @@ import com.stardust.util.IntentUtil;
|
|||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.stardust.pio.PFile.getExtension;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/4/2.
|
* Created by Stardust on 2017/4/2.
|
||||||
*/
|
*/
|
||||||
@@ -55,7 +59,7 @@ public class AppUtils {
|
|||||||
return applicationInfo.processName;
|
return applicationInfo.processName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ScriptInterface
|
@ScriptInterface
|
||||||
@@ -75,6 +79,40 @@ public class AppUtils {
|
|||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ScriptInterface
|
||||||
|
public void viewFile(String path) {
|
||||||
|
if (path == null)
|
||||||
|
throw new NullPointerException("path == null");
|
||||||
|
path = "file://" + path;
|
||||||
|
String ext = getExtension(path);
|
||||||
|
String mimeType = TextUtils.isEmpty(ext) ? "*/*" : MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
|
||||||
|
mContext.startActivity(new Intent(Intent.ACTION_VIEW)
|
||||||
|
.setDataAndType(Uri.parse(path), mimeType)
|
||||||
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ScriptInterface
|
||||||
|
public void editFile(String path) {
|
||||||
|
if (path == null)
|
||||||
|
throw new NullPointerException("path == null");
|
||||||
|
path = "file://" + path;
|
||||||
|
String ext = getExtension(path);
|
||||||
|
String mimeType = TextUtils.isEmpty(ext) ? "*/*" : MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
|
||||||
|
mContext.startActivity(new Intent(Intent.ACTION_EDIT)
|
||||||
|
.setDataAndType(Uri.parse(path), mimeType)
|
||||||
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ScriptInterface
|
||||||
|
public void openUrl(String url) {
|
||||||
|
if (!url.startsWith("http://") || !url.startsWith("https://")) {
|
||||||
|
url = "http://" + url;
|
||||||
|
}
|
||||||
|
mContext.startActivity(new Intent(Intent.ACTION_VIEW)
|
||||||
|
.setData(Uri.parse(url))
|
||||||
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||||
|
}
|
||||||
|
|
||||||
public void setCurrentActivity(Activity currentActivity) {
|
public void setCurrentActivity(Activity currentActivity) {
|
||||||
mCurrentActivity = new WeakReference<>(currentActivity);
|
mCurrentActivity = new WeakReference<>(currentActivity);
|
||||||
Log.d("App", "setCurrentActivity: " + currentActivity);
|
Log.d("App", "setCurrentActivity: " + currentActivity);
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class Shell extends AbstractShell implements AutoCloseable {
|
|||||||
|
|
||||||
private static final String TAG = "Shell";
|
private static final String TAG = "Shell";
|
||||||
|
|
||||||
private TermSession mTermSession;
|
private volatile TermSession mTermSession;
|
||||||
private final Object mInitLock = new Object();
|
private final Object mInitLock = new Object();
|
||||||
private final Object mExitLock = new Object();
|
private final Object mExitLock = new Object();
|
||||||
private volatile RuntimeException mInitException;
|
private volatile RuntimeException mInitException;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
<string name="text_console">控制台</string>
|
<string name="text_console">控制台</string>
|
||||||
<string name="text_no_floating_window_permission">没有悬浮窗权限</string>
|
<string name="text_no_floating_window_permission">没有悬浮窗权限</string>
|
||||||
<string name="text_accessibility_service_description">使脚本自动操作(点击、长按、滑动等)所需,若关闭则只能执行不涉及自动操作的脚本。</string>
|
<string name="text_accessibility_service_description">使脚本自动操作(点击、长按、滑动等)所需,若关闭则只能执行不涉及自动操作的脚本。</string>
|
||||||
|
<string name="_app_name">AutoJs</string>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -171,16 +171,16 @@ public class PFile {
|
|||||||
|
|
||||||
public static String renameWithoutExtension(String path, String newName) {
|
public static String renameWithoutExtension(String path, String newName) {
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
File newFile = new File(file.getParent(), newName + getExtension(file.getName()));
|
File newFile = new File(file.getParent(), newName + "." + getExtension(file.getName()));
|
||||||
file.renameTo(newFile);
|
file.renameTo(newFile);
|
||||||
return newFile.getAbsolutePath();
|
return newFile.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getExtension(String fileName) {
|
public static String getExtension(String fileName) {
|
||||||
int i = fileName.lastIndexOf('.');
|
int i = fileName.lastIndexOf('.');
|
||||||
if (i < 0 || i == fileName.length() - 1)
|
if (i < 0 || i + 1 >= fileName.length() - 1)
|
||||||
return "";
|
return "";
|
||||||
return fileName.substring(i);
|
return fileName.substring(i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean write(String path, String text) {
|
public static boolean write(String path, String text) {
|
||||||
@@ -233,7 +233,7 @@ public class PFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static File copyAssetToTmpFile(Context context, String path) {
|
public static File copyAssetToTmpFile(Context context, String path) {
|
||||||
String extension = getExtension(path);
|
String extension = "." + getExtension(path);
|
||||||
String name = getNameWithoutExtension(path);
|
String name = getNameWithoutExtension(path);
|
||||||
if (name.length() < 5) {
|
if (name.length() < 5) {
|
||||||
name += name.hashCode();
|
name += name.hashCode();
|
||||||
|
|||||||
Reference in New Issue
Block a user