feat: build apk from project(dir) support
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
<activity android:name=".SettingsActivity"/>
|
||||
|
||||
<service
|
||||
android:name=".rt.AccessibilityService"
|
||||
android:name=".autojs.AccessibilityService"
|
||||
android:label="inrt"
|
||||
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
|
||||
<intent-filter>
|
||||
|
||||
BIN
inrt/src/main/assets/project/auto.js.png
Normal file
BIN
inrt/src/main/assets/project/auto.js.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.8 KiB |
32
inrt/src/main/assets/project/main.js
Normal file
32
inrt/src/main/assets/project/main.js
Normal file
@@ -0,0 +1,32 @@
|
||||
"ui";
|
||||
|
||||
ui.layout(
|
||||
<scroll>
|
||||
<vertical bg="#707070" padding="16">
|
||||
<text text="网络图片" textColor="black" textSize="16sp" marginTop="16"/>
|
||||
<img src="file://auto.js.png"
|
||||
w="100" h="100"/>
|
||||
|
||||
<text text="带边框的图片" textColor="black" textSize="16sp" marginTop="16"/>
|
||||
<img src="http://www.autojs.org/assets/uploads/profile/1-profileavatar.jpeg"
|
||||
w="100" h="100" borderWidth="2dp" borderColor="#202020"/>
|
||||
|
||||
<text text="圆形图片" textColor="black" textSize="16sp" marginTop="16"/>
|
||||
<img src="http://www.autojs.org/assets/uploads/profile/1-profileavatar.jpeg"
|
||||
w="100" h="100" circle="true"/>
|
||||
|
||||
<text text="带边框的圆形图片" textColor="black" textSize="16sp" marginTop="16"/>
|
||||
<img src="http://www.autojs.org/assets/uploads/profile/1-profileavatar.jpeg"
|
||||
w="100" h="100" circle="true" borderWidth="2dp" borderColor="#202020"/>
|
||||
|
||||
<text text="圆角图片" textColor="black" textSize="16sp" marginTop="16"/>
|
||||
<img id="rounded_img" src="http://www.autojs.org/assets/uploads/profile/1-profileavatar.jpeg"
|
||||
w="100" h="100" radius="20dp" scaleType="fitXY"/>
|
||||
<button id="change_img" text="更改图片"/>
|
||||
</vertical>
|
||||
</scroll>
|
||||
);
|
||||
|
||||
ui.change_img.click(()=>{
|
||||
ui.rounded_img.setSource("http://www.autojs.org/assets/uploads/profile/1-profilecover.jpeg");
|
||||
});
|
||||
10
inrt/src/main/assets/project/project.json
Normal file
10
inrt/src/main/assets/project/project.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "Hello World",
|
||||
"versionName": "1.0.0",
|
||||
"versionCode": 1,
|
||||
"packageName": "org.autojs.example",
|
||||
"main": "main.js",
|
||||
"assets" : [
|
||||
"auto.js.png"
|
||||
]
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
auto();
|
||||
toast(files.read("/sdcard/1.txt"));
|
||||
@@ -1,10 +1,9 @@
|
||||
package com.stardust.auojs.inrt;
|
||||
|
||||
import android.app.Application;
|
||||
import android.app.Fragment;
|
||||
|
||||
import com.stardust.auojs.inrt.rt.AutoJs;
|
||||
import com.stardust.auojs.inrt.rt.GlobalKeyObserver;
|
||||
import com.stardust.auojs.inrt.autojs.AutoJs;
|
||||
import com.stardust.auojs.inrt.autojs.GlobalKeyObserver;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/7/1.
|
||||
|
||||
@@ -11,11 +11,10 @@ import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.stardust.auojs.inrt.rt.AutoJs;
|
||||
import com.stardust.auojs.inrt.autojs.AutoJs;
|
||||
import com.stardust.auojs.inrt.launch.AssetsProjectLauncher;
|
||||
import com.stardust.autojs.core.console.ConsoleView;
|
||||
import com.stardust.autojs.core.console.StardustConsole;
|
||||
import com.stardust.autojs.script.StringScriptSource;
|
||||
import com.stardust.pio.PFiles;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -46,15 +45,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
private void runScript() {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
String js = PFiles.read(getAssets().open("script.js"));
|
||||
StringScriptSource source = new StringScriptSource("main", js);
|
||||
AutoJs.getInstance().getScriptEngineService().execute(source);
|
||||
} catch (Exception e) {
|
||||
AutoJs.getInstance().getGlobalConsole().log(e);
|
||||
}
|
||||
}).start();
|
||||
new Thread(() -> new AssetsProjectLauncher("project", this).launch()).start();
|
||||
if (!Pref.shouldShowMainActivity()) {
|
||||
finish();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.stardust.auojs.inrt.rt;
|
||||
package com.stardust.auojs.inrt.autojs;
|
||||
|
||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.stardust.auojs.inrt.rt;
|
||||
package com.stardust.auojs.inrt.autojs;
|
||||
|
||||
import android.accessibilityservice.AccessibilityService;
|
||||
import android.content.Context;
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.stardust.auojs.inrt.rt;
|
||||
package com.stardust.auojs.inrt.autojs;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
|
||||
import com.stardust.auojs.inrt.App;
|
||||
import com.stardust.auojs.inrt.Pref;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.stardust.auojs.inrt.rt;
|
||||
package com.stardust.auojs.inrt.autojs;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.stardust.auojs.inrt.launch;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.stardust.auojs.inrt.autojs.AutoJs;
|
||||
import com.stardust.autojs.execution.ExecutionConfig;
|
||||
import com.stardust.autojs.project.ProjectConfig;
|
||||
import com.stardust.autojs.script.JavaScriptFileSource;
|
||||
import com.stardust.pio.PFiles;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2018/1/24.
|
||||
*/
|
||||
|
||||
public class AssetsProjectLauncher {
|
||||
|
||||
private String mAssetsProjectDir;
|
||||
private String mProjectDir;
|
||||
private File mMainScriptFile;
|
||||
private ProjectConfig mProjectConfig;
|
||||
private Context mContext;
|
||||
|
||||
public AssetsProjectLauncher(String projectDir, Context context) {
|
||||
mAssetsProjectDir = projectDir;
|
||||
mContext = context;
|
||||
mProjectDir = new File(context.getFilesDir(), "project/").getPath();
|
||||
mProjectConfig = ProjectConfig.fromAssets(context, ProjectConfig.configFileOfDir(mAssetsProjectDir));
|
||||
mMainScriptFile = new File(mProjectDir, mProjectConfig.getMainScriptFile());
|
||||
}
|
||||
|
||||
public void launch() {
|
||||
prepare();
|
||||
try {
|
||||
JavaScriptFileSource source = new JavaScriptFileSource(mMainScriptFile);
|
||||
AutoJs.getInstance().getScriptEngineService().execute(source, new ExecutionConfig()
|
||||
.executePath(mProjectDir));
|
||||
} catch (Exception e) {
|
||||
AutoJs.getInstance().getGlobalConsole().error(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void prepare() {
|
||||
if (mMainScriptFile.exists()) {
|
||||
return;
|
||||
}
|
||||
PFiles.copyAsset(mContext, PFiles.join(mAssetsProjectDir, mProjectConfig.getMainScriptFile()),
|
||||
mMainScriptFile.getPath());
|
||||
for (String asset : mProjectConfig.getAssets()) {
|
||||
PFiles.copyAsset(mContext, PFiles.join(mAssetsProjectDir, asset), PFiles.join(mProjectDir, asset));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user