Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/hyb1996/NoRootScriptDroid in…
Browse files Browse the repository at this point in the history
…to dev

# Conflicts:
#	.idea/caches/build_file_checksums.ser
  • Loading branch information
hyb1996 committed Jan 22, 2019
2 parents d05b65b + cfe6f92 commit ce54478
Show file tree
Hide file tree
Showing 31 changed files with 443 additions and 330 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/Stardust.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":203},"path":"inrt-release.apk","properties":{"packageId":"com.stardust.auojs.inrt","split":"","minSdkVersion":"17"}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":253,"versionName":"4.1.0 Alpha3","enabled":true,"outputFile":"inrt-release.apk","fullName":"release","baseName":"release"},"path":"inrt-release.apk","properties":{}}]
6 changes: 4 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_SedTORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/>
Expand All @@ -15,7 +15,7 @@
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"/>


<!-- 非Auto.js运行必需,不会主动申请,某些脚本可以自行申请-->
Expand Down Expand Up @@ -85,6 +85,7 @@
android:name=".ui.edit.EditActivity_"
android:configChanges="orientation|screenSize"
android:multiprocess="true"
android:taskAffinity="org.autojs.autojs.edit"
android:theme="@style/EditorTheme">
</activity>
<activity android:name=".ui.settings.AboutActivity_"/>
Expand Down Expand Up @@ -275,6 +276,7 @@
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>

<service
android:name="com.stardust.notification.NotificationListenerService"
android:label="@string/app_name"
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/org/autojs/autojs/model/script/Scripts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,22 @@ object Scripts {
}


fun edit(file: ScriptFile) {
EditActivity.editFile(GlobalAppContext.get(), file.simplifiedName, file.path)
fun edit(context: Context, file: ScriptFile) {
EditActivity.editFile(context, file.simplifiedName, file.path)
}

fun edit(path: String) {
edit(ScriptFile(path))
fun edit(context: Context, path: String) {
edit(context, ScriptFile(path))
}

fun run(file: ScriptFile): ScriptExecution? {
try {
return AutoJs.getInstance().scriptEngineService.execute(file.toSource(),
return try {
AutoJs.getInstance().scriptEngineService.execute(file.toSource(),
ExecutionConfig(workingDirectory = file.parent))
} catch (e: Exception) {
e.printStackTrace()
Toast.makeText(GlobalAppContext.get(), e.message, Toast.LENGTH_LONG).show()
return null
null
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void createScriptFile(String path, String script, boolean edit) {
}
notifyFileCreated(mCurrentDirectory, new ScriptFile(path));
if (edit)
Scripts.INSTANCE.edit(path);
Scripts.INSTANCE.edit(mContext, path);
} else {
showMessage(R.string.text_create_fail);
}
Expand Down
18 changes: 15 additions & 3 deletions app/src/main/java/org/autojs/autojs/ui/edit/EditActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import android.util.Log;
import android.view.ActionMode;
import android.view.Menu;
Expand Down Expand Up @@ -195,7 +198,15 @@ public void finish() {
showExitConfirmDialog();
return;
}
super.finish();
finishAndRemoveFromRecents();
}

private void finishAndRemoveFromRecents() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
finishAndRemoveTask();
} else {
finish();
}
}

private void showExitConfirmDialog() {
Expand All @@ -207,9 +218,9 @@ private void showExitConfirmDialog() {
.neutralText(R.string.text_exit_directly)
.onNegative((dialog, which) -> {
mEditorView.saveFile();
EditActivity.super.finish();
finishAndRemoveFromRecents();
})
.onNeutral((dialog, which) -> EditActivity.super.finish())
.onNeutral((dialog, which) -> finishAndRemoveFromRecents())
.show();
}

Expand Down Expand Up @@ -294,4 +305,5 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
mRequestPermissionCallbacks.onRequestPermissionsResult(requestCode, permissions, grantResults);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ void run() {

@OnClick(R.id.edit)
void edit() {
Scripts.INSTANCE.edit(new ScriptFile(mExplorerItem.getPath()));
Scripts.INSTANCE.edit(getContext(), new ScriptFile(mExplorerItem.getPath()));
notifyOperated();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void save() {
.subscribe(file ->
Snackbar.make(CommunityWebView.this, getResources().getString(R.string.format_file_downloaded, file.getPath())
, Snackbar.LENGTH_LONG)
.setAction(R.string.text_open, v -> Scripts.INSTANCE.edit(file))
.setAction(R.string.text_open, v -> Scripts.INSTANCE.edit(getContext(), file))
.show(),
error -> {
error.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void setUpViews() {
mExplorerView.setExplorer(Explorers.workspace(), ExplorerDirPage.createRoot(Pref.getScriptDirPath()));
mExplorerView.setOnItemClickListener((view, item) -> {
if (item.isEditable()) {
Scripts.INSTANCE.edit(item.toScriptFile());
Scripts.INSTANCE.edit(getActivity(), item.toScriptFile());
} else {
IntentUtil.viewFile(GlobalAppContext.get(), item.getPath(), AppFileProvider.AUTHORITY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,25 @@
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import org.autojs.autojs.R;
import org.autojs.autojs.tool.BitmapTool;
import org.autojs.autojs.ui.BaseActivity;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
import org.autojs.autojs.R;
import org.autojs.autojs.tool.BitmapTool;
import org.autojs.autojs.ui.BaseActivity;
import org.autojs.autojs.workground.WrapContentGridLayoutManger;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.RecyclerView;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
Expand Down Expand Up @@ -93,7 +91,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
startActivityForResult(new Intent(Intent.ACTION_GET_CONTENT)
.setType("image/*"), 11209);
.setType("image/*"), 11234);
return true;
}

Expand Down
22 changes: 15 additions & 7 deletions autojs/src/main/assets/modules/__dialogs__.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,31 +155,31 @@ module.exports = function(__runtime__, scope){
builder.input(wrapNonNullString(properties.inputHint), wrapNonNullString(properties.inputPrefill),
function(dialog, input){
input = input.toString();
builder.emit("input_change", dialog, input);
builder.dialog.emit("input_change", builder.dialog, input);
})
.alwaysCallInputCallback();
}
if(properties.items != undefined){
var itemsSelectMode = properties.itemsSelectMode;
if(itemsSelectMode == undefined || itemsSelectMode == 'select'){
builder.itemsCallback(function(dialog, view, position, text){
dialog.emit("item_select", position, text.toString(), dialog);
builder.dialog.emit("item_select", position, text.toString(), builder.dialog);
});
}else if(itemsSelectMode == 'single'){
builder.itemsCallbackSingleChoice(properties.itemsSelectedIndex == undefined ? -1 : properties.itemsSelectedIndex,
function(dialog, view, which, text){
dialog.emit("single_choice", which, text.toString(), dialog);
builder.dialog.emit("single_choice", which, text.toString(), builder.dialog);
return true;
});
}else if(itemsSelectMode == 'multi'){
builder.itemsCallbackMultiChoice(properties.itemsSelectedIndex == undefined ? null : properties.itemsSelectedIndex,
function(dialog, view, indices, texts){
dialog.emit("multi_choice", toJsArray(indices, (l, i)=> parseInt(l.get(i)),
toJsArray(texts, (l, i)=> l.get(i).toString())), dialog);
builder.dialog.emit("multi_choice", toJsArray(indices, (l, i)=> parseInt(l.get(i)),
toJsArray(texts, (l, i)=> l.get(i).toString())), builder.dialog);
return true;
});
}else{
throw new Error("unknown itemsSelecteMode " + itemsSelectMode);
throw new Error("unknown itemsSelectMode " + itemsSelectMode);
}
}
if(properties.progress != undefined){
Expand All @@ -191,9 +191,17 @@ module.exports = function(__runtime__, scope){
if(properties.checkBoxPrompt != undefined || properties.checkBoxChecked != undefined){
builder.checkBoxPrompt(wrapNonNullString(properties.checkBoxPrompt), !!properties.checkBoxChecked,
function(view, checked){
builder.emit("check", checked, builder.getDialog());
builder.getDialog().emit("check", checked, builder.getDialog());
});
}
if(properties.customView != undefined) {
let customView = properties.customView;
if(typeof(customView) == 'xml' || typeof(customView) == 'string') {
customView = ui.run(() => ui.inflate(customView));
}
let wrapInScrollView = (properties.wrapInScrollView === undefined) ? true : properties.wrapInScrollView;
builder.customView(customView, wrapInScrollView);
}
}

function wrapNonNullString(str){
Expand Down
2 changes: 1 addition & 1 deletion autojs/src/main/assets/modules/__engines__.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = function(__runtime__, scope){
}
config.delay = c.delay || 0;
config.interval = c.interval || 0;
config.loopTimes = c.loopTimes || 1;
config.loopTimes = (c.loopTimes === undefined)? 1 : c.loopTimes;
if(c.arguments){
var arguments = c.arguments;
for(var key in arguments){
Expand Down
13 changes: 8 additions & 5 deletions autojs/src/main/assets/modules/__ui__.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = function (runtime, global) {
ui.__defineGetter__("emitter", ()=> activity ? activity.getEventEmitter() : null);

ui.layout = function (xml) {
if(!activity){
if(typeof(activity) == 'undefined'){
throw new Error("需要在ui模式下运行才能使用该函数");
}
runtime.ui.layoutInflater.setContext(activity);
Expand All @@ -24,15 +24,18 @@ module.exports = function (runtime, global) {
}

ui.inflate = function(xml, parent, attachToParent){
if(!activity){
throw new Error("需要在ui模式下运行才能使用该函数");
}
if(typeof(xml) == 'xml'){
xml = xml.toXMLString();
}
parent = parent || null;
attachToParent = !!attachToParent;
runtime.ui.layoutInflater.setContext(activity);
let ctx;
if(typeof(activity) == 'undefined') {
ctx = new android.view.ContextThemeWrapper(context, com.stardust.autojs.R.style.ScriptTheme);
} else {
ctx = activity;
}
runtime.ui.layoutInflater.setContext(ctx);
return runtime.ui.layoutInflater.inflate(xml.toString(), parent, attachToParent);
}

Expand Down
Loading

0 comments on commit ce54478

Please sign in to comment.