6.1.1 - 新增应用更新功能 修复编辑器页面/安卓10存储权限 异常消息资源化
This commit is contained in:
1 parent
f68ad1c993
commit
069932c8d3
93 files changed
+2094
-680
No files matched your search
@@ -2,7 +2,7 @@
|
||||
|
||||
<div align="center">
|
||||
<p>
|
||||
<img alt="AF_Banner" src="https://github.com/SuperMonster002/Hello-Sockpuppet/raw/master/auto.js-banner_800×224_transparent.png"/>
|
||||
<img alt="AF_Banner" src="https://raw.githubusercontent.com/SuperMonster002/Hello-Sockpuppet/master/auto.js-banner_800%C3%97224_transparent.png"/>
|
||||
</p>
|
||||
|
||||
<p>Android 平台支持无障碍服务的 JavaScript 自动化工具</p>
|
||||
@@ -16,7 +16,7 @@
|
||||
<a href="https://github.com/mozilla/rhino"><img alt="Rhino" src="https://img.shields.io/badge/rhino-1.7.15--snapshot-F06292"/></a>
|
||||
<a href="https://developer.android.com/studio/archive"><img alt="Android Studio" src="https://img.shields.io/badge/android%20studio-bumblebee%202021.1.1-B64FC8"/></a>
|
||||
<br>
|
||||
<a href="https://github.com/SuperMonster003/AutoJs6/commit/ce88d3acb797b180c3f1f15bf77dbba5e934393c"><img alt="Created" src="https://img.shields.io/date/1636632233?color=2e7d32&label=created"/></a>
|
||||
<a href="https://github.com/SuperMonster003/AutoJs6/commit/99a1d8490fac5b6d55f6f183db59ad833a2064ed"><img alt="Created" src="https://img.shields.io/date/1636632233?color=2e7d32&label=created"/></a>
|
||||
<a href="https://github.com/SuperMonster003/AutoJs6/find/master"><img alt="GitHub Code Size" src="https://img.shields.io/github/languages/code-size/SuperMonster003/AutoJs6?color=795548"/></a>
|
||||
<a href="https://github.com/SuperMonster003/AutoJs6/blob/master/LICENSE"><img alt="GitHub License" src="https://img.shields.io/github/license/SuperMonster003/AutoJs6?color=534BAE"/></a>
|
||||
</p>
|
||||
@@ -104,6 +104,19 @@
|
||||
|
||||
[comment]: <> "Version history only shows last 3 versions"
|
||||
|
||||
# v6.1.1
|
||||
|
||||
###### 2022/05/31
|
||||
|
||||
* `新增` 检查更新/下载更新/更新提示功能 (参阅 设置页面) (暂不支持安卓 7.x 系统)
|
||||
* `修复` 应用在安卓 10 系统无法读写外部存储的问题 _[`issue #17`](https://github.com/SuperMonster003/AutoJs6/issues/17)_
|
||||
* `修复` 编辑器页面长按时可能导致应用崩溃的问题 _[`issue #18`](https://github.com/SuperMonster003/AutoJs6/issues/18)_
|
||||
* `修复` 编辑器页面长按菜单 "删除行" 和 "复制行" 功能无效的问题
|
||||
* `修复` 编辑器页面选项菜单中 "粘贴" 功能缺失的问题
|
||||
* `优化` 部分异常消息字符串资源化 (en / zh)
|
||||
* `优化` 调整内容未保存对话框的按钮布局并增加颜色区分
|
||||
* `优化` 部分依赖或本地库版本调整 _[`CHANGELOG.md`](https://github.com/SuperMonster003/AutoJs6/blob/master/app/src/main/assets/doc/CHANGELOG.md#v611)_
|
||||
|
||||
# v6.1.0
|
||||
|
||||
###### 2022/05/26 - 包名变更 谨慎升级
|
||||
@@ -150,7 +163,7 @@
|
||||
* `优化` 保存 ImageWrapper 所有实例弱引用并在脚本结束时自动回收 (实验性)
|
||||
* `优化` 附加 CircleImageView 版本 3.1.0
|
||||
* `优化` 升级 Rhino 引擎版本 1.7.14 -> 1.7.15-snapshot
|
||||
* `优化` 部分依赖或本地库版本调整 (详见 [`CHANGELOG.md`](https://github.com/SuperMonster003/AutoJs6/blob/master/app/src/main/assets/doc/CHANGELOG.md#v610))
|
||||
* `优化` 部分依赖或本地库版本调整 _[`CHANGELOG.md`](https://github.com/SuperMonster003/AutoJs6/blob/master/app/src/main/assets/doc/CHANGELOG.md#v610)_
|
||||
|
||||
# v6.0.3
|
||||
|
||||
@@ -169,28 +182,13 @@
|
||||
* `优化` 主页抽屉增加前台服务状态开关的同步
|
||||
* `优化` 主页抽屉展开时立即按需同步开关状态
|
||||
* `优化` 显示指针位置增加状态检测及结果提示
|
||||
* `优化` 支持 64 位操作系统 (Ref to TonyJiangWJ)
|
||||
* `优化` 支持 64 位操作系统 (Ref to [TonyJiangWJ](https://github.com/TonyJiangWJ))
|
||||
* `优化` 悬浮窗初始化时同时应用透明度设置 (无需点击后再应用透明度)
|
||||
* `优化` 重置文件内容时增加是否为示例代码文件的检测并增加结果提示
|
||||
* `优化` 转移打包插件下载地址 GitHub -> JsDelivr
|
||||
* `优化` 附加 Zeugma Solutions LocaleHelper 版本 1.5.1
|
||||
* `优化` 降级 Android Material 版本 1.6.0-alpha02 -> 1.5.0
|
||||
* `优化` 部分依赖或本地库版本调整 (详见 [`CHANGELOG.md`](https://github.com/SuperMonster003/AutoJs6/blob/master/app/src/main/assets/doc/CHANGELOG.md#v603))
|
||||
|
||||
# v6.0.2
|
||||
|
||||
###### 2022/02/05
|
||||
|
||||
* `新增` images.bilateralFilter() 双边滤波图像处理方法
|
||||
* `修复` 多次调用 toast 只生效最后一次调用的问题
|
||||
* `修复` toast.dismiss() 可能无效的问题
|
||||
* `修复` 客户端模式及服务端模式开关可能无法正常工作的问题
|
||||
* `修复` 客户端模式及服务端模式开关状态不能正常刷新的问题
|
||||
* `修复` Android 7 解析 UI 模式 text 元素异常 (Ref to TonyJiangWJ) _[`issue #4`](https://github.com/SuperMonster003/AutoJs6/issues/4)_ _[`#9`](https://github.com/SuperMonster003/AutoJs6/issues/9)_
|
||||
* `优化` 忽略 sleep() 的 ScriptInterruptedException 异常
|
||||
* `优化` 附加 Androidx AppCompat (Legacy) 版本 1.0.2
|
||||
* `优化` 升级 Rhino 引擎版本 1.7.14-snapshot -> 1.7.14
|
||||
* `优化` 部分依赖或本地库版本调整 (详见 [`CHANGELOG.md`](https://github.com/SuperMonster003/AutoJs6/blob/master/app/src/main/assets/doc/CHANGELOG.md#v602))
|
||||
* `优化` 部分依赖或本地库版本调整 _[`CHANGELOG.md`](https://github.com/SuperMonster003/AutoJs6/blob/master/app/src/main/assets/doc/CHANGELOG.md#v603)_
|
||||
|
||||
##### 更多版本历史可参阅
|
||||
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ dependencies {
|
||||
// Retrofit
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
|
||||
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
|
||||
implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
|
||||
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.9.0'
|
||||
implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
|
||||
|
||||
// Glide
|
||||
|
||||
@@ -2,10 +2,25 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="org.autojs.autojs">
|
||||
|
||||
<!--
|
||||
@Hint by SuperMonster003 on May 27, 2022.
|
||||
! WRT: android.permission.WRITE_EXTERNAL_STORAGE
|
||||
! MSV<API>: android:maxSdkVersion="API"
|
||||
! LGC: android:requestLegacyExternalStorage="true" (since API 29)
|
||||
! MAN: android.permission.MANAGE_EXTERNAL_STORAGE (since API 30)
|
||||
!
|
||||
! Storage permission requirement on different API targets.
|
||||
! [ XXX ] means optional but recommended.
|
||||
!
|
||||
! Target API == 28: WRT
|
||||
! Target API == 29: WRT + [ MSV<29> ] / WRT + [ MSV<28> ] + LGC
|
||||
! Target API >= 30: WRT + [ MSV<29> ] + LGC + MAN
|
||||
-->
|
||||
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission
|
||||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||
android:maxSdkVersion="28" />
|
||||
android:maxSdkVersion="29" />
|
||||
<uses-permission
|
||||
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
|
||||
tools:ignore="ScopedStorage" />
|
||||
@@ -42,6 +57,7 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
android:usesCleartextTraffic="true"
|
||||
android:requestLegacyExternalStorage="true"
|
||||
tools:replace="android:label, android:allowBackup"
|
||||
tools:ignore="DataExtractionRules">
|
||||
|
||||
|
||||
@@ -4,6 +4,20 @@
|
||||
|
||||
******
|
||||
|
||||
# v6.1.1
|
||||
|
||||
###### 2022/05/31
|
||||
|
||||
* `新增` 检查更新/下载更新/更新提示功能 (参阅 设置页面) (暂不支持安卓 7.x 系统)
|
||||
* `修复` 应用在安卓 10 系统无法读写外部存储的问题 _[`issue #17`](https://github.com/SuperMonster003/AutoJs6/issues/17)_
|
||||
* `修复` 编辑器页面长按时可能导致应用崩溃的问题 _[`issue #18`](https://github.com/SuperMonster003/AutoJs6/issues/18)_
|
||||
* `修复` 编辑器页面长按菜单 "删除行" 和 "复制行" 功能无效的问题
|
||||
* `修复` 编辑器页面选项菜单中 "粘贴" 功能缺失的问题
|
||||
* `优化` 部分异常消息字符串资源化 (en / zh)
|
||||
* `优化` 调整内容未保存对话框的按钮布局并增加颜色区分
|
||||
* `优化` 附加 github-api 版本 1.306
|
||||
* `优化` 替换 retrofit2-rxjava2-adapter 版本 1.0.0 为 adapter-rxjava2 版本 2.9.0
|
||||
|
||||
# v6.1.0
|
||||
|
||||
###### 2022/05/26 - 包名变更 谨慎升级
|
||||
@@ -82,14 +96,14 @@
|
||||
* `优化` 主页抽屉增加前台服务状态开关的同步
|
||||
* `优化` 主页抽屉展开时立即按需同步开关状态
|
||||
* `优化` 显示指针位置增加状态检测及结果提示
|
||||
* `优化` 支持 64 位操作系统 (Ref to TonyJiangWJ)
|
||||
* `优化` 支持 64 位操作系统 (Ref to [TonyJiangWJ](https://github.com/TonyJiangWJ))
|
||||
* `优化` 悬浮窗初始化时同时应用透明度设置 (无需点击后再应用透明度)
|
||||
* `优化` 重置文件内容时增加是否为示例代码文件的检测并增加结果提示
|
||||
* `优化` 转移打包插件下载地址 GitHub -> JsDelivr
|
||||
* `优化` 附加 Zeugma Solutions LocaleHelper 版本 1.5.1
|
||||
* `优化` 降级 Android Material 版本 1.6.0-alpha02 -> 1.5.0
|
||||
* `优化` 升级 Kotlinx Coroutines 版本 1.6.0-native-mt -> 1.6.0
|
||||
* `优化` 升级 OpenCV 版本 3.4.3 -> 4.5.4 -> 4.5.5 (Ref to TonyJiangWJ)
|
||||
* `优化` 升级 OpenCV 版本 3.4.3 -> 4.5.4 -> 4.5.5 (Ref to [TonyJiangWJ](https://github.com/TonyJiangWJ))
|
||||
* `优化` 升级 Okhttp3 版本 3.10.0 -> 5.0.0-alpha.4 -> 5.0.0-alpha.6
|
||||
* `优化` 升级 Android Gradle 插件版本 7.2.0-beta01 -> 7.3.0-alpha06
|
||||
* `优化` 升级 Auto.js-ApkBuilder 版本 1.0.1 -> 1.0.3
|
||||
@@ -107,7 +121,7 @@
|
||||
* `修复` toast.dismiss() 可能无效的问题
|
||||
* `修复` 客户端模式及服务端模式开关可能无法正常工作的问题
|
||||
* `修复` 客户端模式及服务端模式开关状态不能正常刷新的问题
|
||||
* `修复` Android 7 解析 UI 模式 text 元素异常 (Ref to TonyJiangWJ) _[`issue #4`](https://github.com/SuperMonster003/AutoJs6/issues/4)_ _[`#9`](https://github.com/SuperMonster003/AutoJs6/issues/9)_
|
||||
* `修复` Android 7 解析 UI 模式 text 元素异常 (Ref to [TonyJiangWJ](https://github.com/TonyJiangWJ)) _[`issue #4`](https://github.com/SuperMonster003/AutoJs6/issues/4)_ _[`#9`](https://github.com/SuperMonster003/AutoJs6/issues/9)_
|
||||
* `优化` 忽略 sleep() 的 ScriptInterruptedException 异常
|
||||
* `优化` 附加 Androidx AppCompat (Legacy) 版本 1.0.2
|
||||
* `优化` 升级 Androidx AppCompat 版本 1.4.0 -> 1.4.1
|
||||
@@ -122,8 +136,8 @@
|
||||
|
||||
###### 2022/01/01
|
||||
|
||||
* `新增` 连接 VSCode 插件支持客户端 (LAN) 及服务端 (LAN/ADB) 方式 (Ref to Auto.js Pro)
|
||||
* `新增` 内置 base64 模块 (Ref to Auto.js Pro)
|
||||
* `新增` 连接 VSCode 插件支持客户端 (LAN) 及服务端 (LAN/ADB) 方式 (Ref to [Auto.js Pro](https://g.pro.autojs.org/))
|
||||
* `新增` 内置 base64 模块 (Ref to [Auto.js Pro](https://g.pro.autojs.org/))
|
||||
* `新增` 增加 isInteger/isNullish/isPlainObject/isPrimitive/isReference 全局方法
|
||||
* `新增` 增加 polyfill (Object.getOwnPropertyDescriptors)
|
||||
* `新增` 增加 polyfill (Array.prototype.flat)
|
||||
@@ -159,7 +173,7 @@
|
||||
* `优化` 升级 JSON 模块至 2017-06-12 版本并整合 cycle.js
|
||||
* `优化` 移除 Activity 前置时的自动检查更新功能并移除检查更新相关按钮
|
||||
* `优化` AppOpsKt#isOpPermissionGranted 内部代码逻辑
|
||||
* `优化` ResourceMonitor 使用 ReentrantLock 增强安全性 (Ref to TonyJiangWJ)
|
||||
* `优化` ResourceMonitor 使用 ReentrantLock 增强安全性 (Ref to [TonyJiangWJ](https://github.com/TonyJiangWJ))
|
||||
* `优化` 使用 Maven Central 等仓库替换 JCenter 仓库
|
||||
* `优化` 抽离并移除重复的本地库文件
|
||||
* `优化` 本地化 CrashReport 版本 2.6.6
|
||||
|
||||
@@ -17,7 +17,7 @@ console.log('code: ' + morse.code);
|
||||
console.log('pattern: ' + morse.pattern);
|
||||
|
||||
// Call vibrate() if you need your device play this morse code by vibration.
|
||||
// zh-CN: Call vibrate() if you need your device play this morse code by vibration.
|
||||
// zh-CN: 可调用 vibrate() 方法使设备按摩斯电码模式震动.
|
||||
|
||||
// morse.vibrate();
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.stardust.theme.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
@@ -54,8 +55,10 @@ public class ThemeColorPreferenceCategory extends PreferenceCategory implements
|
||||
public View onCreateView(ViewGroup parent) {
|
||||
View view = super.onCreateView(parent);
|
||||
mTitleTextView = view.findViewById(android.R.id.title);
|
||||
if (mColor != Color.TRANSPARENT)
|
||||
if (mColor != Color.TRANSPARENT) {
|
||||
mTitleTextView.setTextColor(mColor);
|
||||
}
|
||||
mTitleTextView.setTypeface(null, Typeface.BOLD);
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.autojs.autojs;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Environment;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
@@ -10,6 +11,9 @@ import com.stardust.autojs.runtime.accessibility.AccessibilityConfig;
|
||||
|
||||
import org.autojs.autojs.autojs.key.GlobalKeyObserver;
|
||||
import org.autojs.autojs6.R;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
@@ -21,6 +25,7 @@ public class Pref {
|
||||
|
||||
private static final String KEY_SERVER_ADDRESS = "KEY_SERVER_ADDRESS";
|
||||
private static final String KEY_FLOATING_MENU_SHOWN = "KEY_FLOATING_MENU_SHOWN";
|
||||
private static final String KEY_LAST_UPDATED_CHECKED = "KEY_LAST_UPDATED_CHECKED";
|
||||
private static final String KEY_APP_LANG_INDEX = "KEY_APP_LANG_INDEX";
|
||||
private static final String KEY_EDITOR_THEME = "editor.theme";
|
||||
private static final String KEY_EDITOR_TEXT_SIZE = "editor.textSize";
|
||||
@@ -51,6 +56,29 @@ public class Pref {
|
||||
return def().getBoolean(getString(R.string.key_use_volume_control_running), true);
|
||||
}
|
||||
|
||||
public static boolean isAutoCheckForUpdatesEnabled() {
|
||||
return def().getBoolean(getString(R.string.key_auto_check_for_updates), true);
|
||||
}
|
||||
|
||||
public static void refreshLastUpdatesCheckedTimestamp() {
|
||||
def().edit().putLong(KEY_LAST_UPDATED_CHECKED, System.currentTimeMillis()).apply();
|
||||
}
|
||||
|
||||
public static long getLastUpdatesCheckedTimestamp() {
|
||||
return def().getLong(KEY_LAST_UPDATED_CHECKED, -1);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getLastUpdatesCheckedTimeString() {
|
||||
long ts = getLastUpdatesCheckedTimestamp();
|
||||
if (ts < 0) {
|
||||
return null;
|
||||
}
|
||||
DateTime dt = new DateTime(ts);
|
||||
DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy/MM/dd HH:mm");
|
||||
return fmt.print(dt);
|
||||
}
|
||||
|
||||
private static String getString(int id) {
|
||||
return GlobalAppContext.getString(id);
|
||||
}
|
||||
|
||||
@@ -39,10 +39,10 @@ public class TinySign {
|
||||
private static void doDir(String prefix, File dir, ZipOutputStream zos, DigestOutputStream dos, Manifest m) throws IOException {
|
||||
zos.putNextEntry(new ZipEntry(prefix));
|
||||
zos.closeEntry();
|
||||
File[] arr$ = dir.listFiles();
|
||||
File[] files = dir.listFiles();
|
||||
|
||||
if (arr$ != null) {
|
||||
for (File f : arr$) {
|
||||
if (files != null) {
|
||||
for (File f : files) {
|
||||
if (f.isFile()) {
|
||||
doFile(prefix + f.getName(), f, zos, dos, m);
|
||||
} else {
|
||||
@@ -72,13 +72,8 @@ public class TinySign {
|
||||
private static Manifest generateSF(Manifest manifest) throws NoSuchAlgorithmException, UnsupportedEncodingException {
|
||||
MessageDigest md = MessageDigest.getInstance("SHA1");
|
||||
PrintStream print = new PrintStream(new DigestOutputStream(new OutputStream() {
|
||||
public void write(byte[] arg0) {
|
||||
}
|
||||
|
||||
public void write(byte[] arg0, int arg1, int arg2) {
|
||||
}
|
||||
|
||||
public void write(int arg0) {
|
||||
@Override
|
||||
public void write(int b) {
|
||||
}
|
||||
}, md), true, "UTF-8");
|
||||
Manifest sf = new Manifest();
|
||||
@@ -164,10 +159,10 @@ public class TinySign {
|
||||
}
|
||||
|
||||
private static void zipAndSha1(File dir, ZipOutputStream zos, DigestOutputStream dos, Manifest m) throws IOException {
|
||||
File[] arr$ = dir.listFiles();
|
||||
File[] files = dir.listFiles();
|
||||
|
||||
if (arr$ != null) {
|
||||
for (File f : arr$) {
|
||||
if (files != null) {
|
||||
for (File f : files) {
|
||||
if (!f.getName().startsWith("META-INF")) {
|
||||
if (f.isFile()) {
|
||||
doFile(f.getName(), f, zos, dos, m);
|
||||
@@ -191,8 +186,8 @@ public class TinySign {
|
||||
public void write(byte[] buffer) throws IOException {
|
||||
try {
|
||||
this.mSignature.update(buffer);
|
||||
} catch (SignatureException var3) {
|
||||
throw new IOException("SignatureException: " + var3);
|
||||
} catch (SignatureException e) {
|
||||
throw new IOException("SignatureException: " + e);
|
||||
}
|
||||
|
||||
this.out.write(buffer);
|
||||
@@ -201,8 +196,8 @@ public class TinySign {
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
try {
|
||||
this.mSignature.update(b, off, len);
|
||||
} catch (SignatureException var5) {
|
||||
throw new IOException("SignatureException: " + var5);
|
||||
} catch (SignatureException e) {
|
||||
throw new IOException("SignatureException: " + e);
|
||||
}
|
||||
|
||||
this.out.write(b, off, len);
|
||||
@@ -211,8 +206,8 @@ public class TinySign {
|
||||
public void write(int b) throws IOException {
|
||||
try {
|
||||
this.mSignature.update((byte) b);
|
||||
} catch (SignatureException var3) {
|
||||
throw new IOException("SignatureException: " + var3);
|
||||
} catch (SignatureException e) {
|
||||
throw new IOException("SignatureException: " + e);
|
||||
}
|
||||
|
||||
this.out.write(b);
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.autojs.autojs.tool.BitmapTool;
|
||||
import org.autojs.autojs6.R;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/1/20.
|
||||
@@ -54,7 +55,7 @@ public class Shortcut {
|
||||
|
||||
public Shortcut iconRes(Intent.ShortcutIconResource icon) {
|
||||
if (mIcon != null) {
|
||||
throw new IllegalStateException("Cannot set both iconRes and icon");
|
||||
throw new IllegalStateException(mContext.getString(R.string.error_set_both_icon_res_and_icon));
|
||||
}
|
||||
mIconRes = icon;
|
||||
return this;
|
||||
@@ -67,7 +68,7 @@ public class Shortcut {
|
||||
|
||||
public Shortcut icon(Bitmap icon) {
|
||||
if (mIconRes != null) {
|
||||
throw new IllegalStateException("Cannot set both iconRes and icon");
|
||||
throw new IllegalStateException(mContext.getString(R.string.error_set_both_icon_res_and_icon));
|
||||
}
|
||||
if (icon.getByteCount() > 1024 * 500) {
|
||||
mIcon = BitmapTool.scaleBitmap(icon, 200, 200);
|
||||
|
||||
@@ -2,6 +2,10 @@ package org.autojs.autojs.model.explorer;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
|
||||
import org.autojs.autojs6.R;
|
||||
|
||||
public class ExplorerChangeEvent {
|
||||
|
||||
|
||||
@@ -73,6 +77,6 @@ public class ExplorerChangeEvent {
|
||||
case CHILDREN_CHANGE:
|
||||
return "CHILDREN_CHANGE";
|
||||
}
|
||||
throw new IllegalArgumentException("action = " + action);
|
||||
throw new IllegalArgumentException(GlobalAppContext.getString(R.string.error_illegal_argument, "action", action));
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,12 @@ package org.autojs.autojs.model.explorer;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.pio.PFile;
|
||||
import com.stardust.util.ObjectHelper;
|
||||
import com.stardust.util.Objects;
|
||||
|
||||
import org.autojs.autojs.model.script.ScriptFile;
|
||||
import org.autojs.autojs6.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
@@ -24,7 +25,11 @@ public class ExplorerFileItem implements ExplorerItem {
|
||||
private final ExplorerPage mParent;
|
||||
|
||||
public ExplorerFileItem(PFile file, ExplorerPage parent) {
|
||||
ObjectHelper.requireNonNull(file, "file");
|
||||
if (file == null) {
|
||||
throw new NullPointerException(GlobalAppContext
|
||||
.getString(R.string.error_method_called_with_null_argument,
|
||||
"ExplorerFileItem.constructor", "file"));
|
||||
}
|
||||
mFile = file;
|
||||
mParent = parent;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,597 @@
|
||||
package org.autojs.autojs.network;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.afollestad.materialdialogs.internal.MDButton;
|
||||
import com.google.android.material.snackbar.BaseTransientBottomBar;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.core.ui.widget.CustomSnackbar;
|
||||
import com.stardust.util.IntentUtil;
|
||||
|
||||
import org.autojs.autojs.Pref;
|
||||
import org.autojs.autojs.external.fileprovider.AppFileProvider;
|
||||
import org.autojs.autojs.network.api.UpdateCheckerApi;
|
||||
import org.autojs.autojs.network.download.DownloadManager;
|
||||
import org.autojs.autojs.network.entity.VersionInfo;
|
||||
import org.autojs.autojs.tool.SimpleObserver;
|
||||
import org.autojs.autojs6.R;
|
||||
import org.kohsuke.github.GHAsset;
|
||||
import org.kohsuke.github.GHRelease;
|
||||
import org.kohsuke.github.GHRepository;
|
||||
import org.kohsuke.github.GHUser;
|
||||
import org.kohsuke.github.GitHub;
|
||||
import org.kohsuke.github.MarkdownMode;
|
||||
import org.kohsuke.github.PagedIterable;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.Reader;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/9/20.
|
||||
* Modified by SuperMonster003 as of Feb 26, 2022.
|
||||
*/
|
||||
|
||||
public class UpdateChecker {
|
||||
|
||||
private MaterialDialog mUpdateDialog;
|
||||
private MaterialDialog mPendingDialog;
|
||||
|
||||
public enum PromptMode {NONE, DIALOG, SNACKBAR}
|
||||
|
||||
private static final String TAG = UpdateChecker.class.getSimpleName();
|
||||
private final Handler mHandler = new Handler(Looper.getMainLooper());
|
||||
private final Context mContext;
|
||||
private final View mView;
|
||||
private final String mBaseUrl;
|
||||
private final String mUrl;
|
||||
private final PromptMode mPromptMode;
|
||||
private final SimpleObserver<ResponseBody> mCallback;
|
||||
private final Executor mGitHubExecutor = Executors.newSingleThreadExecutor();
|
||||
|
||||
private GitHub mGitHubConnection;
|
||||
private UpdateCheckerApi checkerApi;
|
||||
|
||||
private UpdateChecker(Context context, View view, String baseUrl, String url, PromptMode promptMode, SimpleObserver<ResponseBody> callback) {
|
||||
mContext = context;
|
||||
mView = view;
|
||||
mBaseUrl = baseUrl;
|
||||
mUrl = url;
|
||||
mPromptMode = promptMode;
|
||||
mCallback = callback;
|
||||
}
|
||||
|
||||
public void checkNow() {
|
||||
mPendingDialog = getPendingDialog(mContext, R.string.text_checking_update);
|
||||
|
||||
if (mPromptMode == PromptMode.DIALOG) {
|
||||
mPendingDialog.show();
|
||||
}
|
||||
|
||||
getCheckerApi()
|
||||
.checkForUpdates(mUrl)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new SimpleObserver<>() {
|
||||
@Override
|
||||
public void onNext(ResponseBody responseBody) {
|
||||
if (mPendingDialog.isShowing()) {
|
||||
mPendingDialog.dismiss();
|
||||
}
|
||||
Pref.refreshLastUpdatesCheckedTimestamp();
|
||||
|
||||
if (mCallback != null) {
|
||||
mCallback.onNext(responseBody);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Properties prop = new Properties();
|
||||
prop.load(responseBody.byteStream());
|
||||
|
||||
String versionNameKey = mContext.getString(R.string.key_app_property_version_name);
|
||||
String versionName = prop.getProperty(versionNameKey);
|
||||
|
||||
String versionCodeKey = mContext.getString(R.string.key_app_property_version_code);
|
||||
int versionCode = Integer.parseInt(prop.getProperty(versionCodeKey));
|
||||
|
||||
VersionInfo versionInfo = new VersionInfo(versionName, versionCode);
|
||||
|
||||
switch (mPromptMode) {
|
||||
case DIALOG -> {
|
||||
if (versionInfo.isNewer()) {
|
||||
showDialog(versionInfo);
|
||||
} else {
|
||||
GlobalAppContext.toast(R.string.text_is_latest_version);
|
||||
}
|
||||
}
|
||||
case SNACKBAR -> {
|
||||
if (versionInfo.isNewer()) {
|
||||
showSnackBar(versionInfo);
|
||||
}
|
||||
}
|
||||
default -> throw new IllegalStateException(mContext.getString(
|
||||
R.string.error_illegal_argument,
|
||||
"promptMode", mPromptMode));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
GlobalAppContext.toast(mContext.getString(R.string.error_failed_to_parse_version_info));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
e.printStackTrace();
|
||||
|
||||
if (mPendingDialog.isShowing()) {
|
||||
mPendingDialog.dismiss();
|
||||
}
|
||||
|
||||
if (mCallback != null) {
|
||||
mCallback.onError(e);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mPromptMode == PromptMode.DIALOG) {
|
||||
new MaterialDialog.Builder(mContext)
|
||||
.title(R.string.error_check_for_update)
|
||||
.content(e.toString())
|
||||
.positiveText(R.string.text_cancel)
|
||||
.canceledOnTouchOutside(false)
|
||||
.build()
|
||||
.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showDialog(@NonNull VersionInfo versionInfo) {
|
||||
showDialog(versionInfo, null);
|
||||
}
|
||||
|
||||
private void showDialog(@NonNull VersionInfo versionInfo, Context context) {
|
||||
// TODO by SuperMonster003 on May 30, 2022.
|
||||
// ! A. Updates ignorance (and settings).
|
||||
// ! B. VersionInfo: *.properties / *.json.
|
||||
|
||||
Context ctx = context != null ? context : mContext;
|
||||
|
||||
String propVersion = versionInfo.getVersionName();
|
||||
if (propVersion == null) {
|
||||
new MaterialDialog.Builder(ctx)
|
||||
.title(R.string.error_check_for_update)
|
||||
.content(R.string.error_parse_version_info)
|
||||
.positiveText(R.string.dialog_button_back)
|
||||
.build()
|
||||
.show();
|
||||
return;
|
||||
}
|
||||
|
||||
mUpdateDialog = new MaterialDialog.Builder(ctx)
|
||||
.title(propVersion)
|
||||
.content(R.string.text_getting_release_notes)
|
||||
.neutralText(R.string.dialog_button_ignore_current_update)
|
||||
.neutralColor(ctx.getColor(R.color.dialog_button_warn))
|
||||
.negativeText(R.string.dialog_button_back)
|
||||
.negativeColor(ctx.getColor(R.color.dialog_button_default))
|
||||
.positiveText(R.string.dialog_button_update_now)
|
||||
.positiveColor(ctx.getColor(R.color.dialog_button_unavailable))
|
||||
.autoDismiss(false)
|
||||
.cancelable(false)
|
||||
.build();
|
||||
|
||||
mPendingDialog = getPendingDialog(ctx, R.string.text_preparing);
|
||||
|
||||
MDButton neutralButton = mUpdateDialog.getActionButton(DialogAction.NEUTRAL);
|
||||
neutralButton.setOnClickListener(v -> {
|
||||
// TODO by SuperMonster003 on May 30, 2022.
|
||||
// ! Updates ignorance.
|
||||
|
||||
new MaterialDialog.Builder(ctx)
|
||||
.title(R.string.text_prompt)
|
||||
.content(R.string.text_under_development_content)
|
||||
.positiveText(R.string.dialog_button_back)
|
||||
.build()
|
||||
.show();
|
||||
});
|
||||
|
||||
MDButton negativeButton = mUpdateDialog.getActionButton(DialogAction.NEGATIVE);
|
||||
negativeButton.setOnClickListener(v -> mUpdateDialog.dismiss());
|
||||
|
||||
MDButton positiveButton = mUpdateDialog.getActionButton(DialogAction.POSITIVE);
|
||||
positiveButton.setOnClickListener(null);
|
||||
|
||||
mUpdateDialog.show();
|
||||
|
||||
// TODO by SuperMonster003 on May 31, 2022.
|
||||
// ! Android 7.x (N and N_MR1) compatibility.
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
mUpdateDialog.dismiss();
|
||||
new MaterialDialog.Builder(ctx)
|
||||
.title(R.string.error_check_for_update)
|
||||
.content(R.string.error_sdk_lower_than_o_not_supported_yet)
|
||||
.positiveText(R.string.text_cancel)
|
||||
.cancelable(false)
|
||||
.build()
|
||||
.show();
|
||||
return;
|
||||
}
|
||||
|
||||
mGitHubExecutor.execute(() -> {
|
||||
GitHub github = connectToGitHubIfNeeded();
|
||||
if (github == null) {
|
||||
setDialogContent(mUpdateDialog, R.string.error_cannot_connect_to_github);
|
||||
return;
|
||||
}
|
||||
|
||||
String userName = ctx.getString(R.string.developer_full_name);
|
||||
String repoName = ctx.getString(R.string.app_name);
|
||||
GHRepository repo = getGitHubRepo(github, userName, repoName);
|
||||
if (repo == null) {
|
||||
setDialogContent(mUpdateDialog, ctx.getString(R.string.error_invalid_github_repo, repoName));
|
||||
return;
|
||||
}
|
||||
|
||||
GHRelease release = getGitHubRelease(repo);
|
||||
if (release == null) {
|
||||
setDialogContent(mUpdateDialog, R.string.error_get_github_latest_release);
|
||||
return;
|
||||
}
|
||||
|
||||
String releaseTag = release.getTagName();
|
||||
if (!checkReleaseTagMatchesProp(releaseTag, propVersion)) {
|
||||
setDialogContent(mUpdateDialog, R.string.error_corresponding_github_release_may_not_published);
|
||||
return;
|
||||
}
|
||||
|
||||
String rawHtmlContent = getRawHtmlFromRelease(repo, release);
|
||||
Spanned htmlContent = Html.fromHtml(rawHtmlContent, Html.FROM_HTML_MODE_COMPACT);
|
||||
if (htmlContent.toString().isEmpty()) {
|
||||
setDialogContent(mUpdateDialog, R.string.text_empty_release_note);
|
||||
} else {
|
||||
setDialogContent(mUpdateDialog, htmlContent);
|
||||
}
|
||||
|
||||
PagedIterable<GHAsset> assets = getGitHubAssets(release);
|
||||
if (assets == null) {
|
||||
setDialogContent(mUpdateDialog, R.string.error_empty_github_release_assets);
|
||||
return;
|
||||
}
|
||||
|
||||
setDialogUpdateButton(ctx, assets, versionInfo);
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PagedIterable<GHAsset> getGitHubAssets(GHRelease release) {
|
||||
try {
|
||||
PagedIterable<GHAsset> assets = release.listAssets();
|
||||
if (assets.toArray().length > 0) {
|
||||
return assets;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
@SuppressLint("CheckResult")
|
||||
private void download(Context ctx, String downloadUrl, String fileName, VersionInfo versionInfo) {
|
||||
File downloadDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
|
||||
final String path = new File(downloadDir, fileName).getPath();
|
||||
|
||||
Consumer<File> onNext = file -> {
|
||||
mUpdateDialog = null;
|
||||
IntentUtil.installApkOrToast(ctx, file.getPath(), AppFileProvider.AUTHORITY);
|
||||
};
|
||||
|
||||
Consumer<Throwable> onError = e -> {
|
||||
Log.d(TAG, "onError: printing stack trace");
|
||||
e.printStackTrace();
|
||||
|
||||
String msg = e.getMessage();
|
||||
|
||||
MaterialDialog d = new MaterialDialog.Builder(ctx)
|
||||
.title(R.string.text_download_failed)
|
||||
.content(msg == null ? ctx.getString(R.string.error_unknown) : msg)
|
||||
.negativeText(R.string.text_cancel)
|
||||
.negativeColor(ctx.getColor(R.color.dialog_button_default))
|
||||
.onNegative((dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
mUpdateDialog = null;
|
||||
})
|
||||
.positiveText("")
|
||||
.positiveColor(ctx.getColor(R.color.dialog_button_failure))
|
||||
.autoDismiss(false)
|
||||
.cancelable(false)
|
||||
.build();
|
||||
|
||||
if (mPendingDialog != null) {
|
||||
mPendingDialog.dismiss();
|
||||
}
|
||||
|
||||
if (mUpdateDialog != null) {
|
||||
d.getActionButton(DialogAction.NEGATIVE).setText(R.string.dialog_button_quit);
|
||||
d.getActionButton(DialogAction.NEGATIVE).setTextColor(ctx.getColor(R.color.dialog_button_caution));
|
||||
d.getActionButton(DialogAction.POSITIVE).setText(R.string.dialog_button_retry);
|
||||
d.getActionButton(DialogAction.POSITIVE).setOnClickListener(v -> {
|
||||
d.dismiss();
|
||||
mUpdateDialog.show();
|
||||
});
|
||||
}
|
||||
|
||||
d.show();
|
||||
};
|
||||
|
||||
DownloadManager.getInstance().downloadWithProgress(ctx, downloadUrl, path, versionInfo)
|
||||
.subscribeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(onNext, onError);
|
||||
}
|
||||
|
||||
private void setDialogUpdateButton(@NonNull Context ctx, PagedIterable<GHAsset> ghAssets, VersionInfo versionInfo) {
|
||||
MDButton positiveButton = mUpdateDialog.getActionButton(DialogAction.POSITIVE);
|
||||
positiveButton.setTextColor(ctx.getColor(R.color.dialog_button_attraction));
|
||||
positiveButton.setOnClickListener(v -> {
|
||||
if (!mUpdateDialog.isShowing()) {
|
||||
return;
|
||||
}
|
||||
mUpdateDialog.dismiss();
|
||||
mPendingDialog.show();
|
||||
|
||||
mGitHubExecutor.execute(() -> {
|
||||
String[] abiList = Build.SUPPORTED_ABIS;
|
||||
String abiBackup = "universal";
|
||||
|
||||
String url = null;
|
||||
String urlBackup = null;
|
||||
String fileName = null;
|
||||
String fileNameBackup = null;
|
||||
|
||||
try {
|
||||
assets:
|
||||
for (GHAsset ghAsset : ghAssets) {
|
||||
String assetName = ghAsset.getName();
|
||||
String assetUrl = ghAsset.getBrowserDownloadUrl();
|
||||
for (String abi : abiList) {
|
||||
String regex = ".*\\b" + abi + "\\b.*";
|
||||
if (assetName.matches(regex)) {
|
||||
url = assetUrl;
|
||||
fileName = assetName;
|
||||
break assets;
|
||||
}
|
||||
}
|
||||
if (assetName.contains(abiBackup)) {
|
||||
urlBackup = assetUrl;
|
||||
fileNameBackup = assetName;
|
||||
}
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
// Ignored.
|
||||
}
|
||||
|
||||
mPendingDialog.dismiss();
|
||||
|
||||
if (url == null && urlBackup == null) {
|
||||
mHandler.post(() -> new MaterialDialog.Builder(ctx)
|
||||
.content(R.string.error_cannot_get_download_url)
|
||||
.positiveText(R.string.text_cancel)
|
||||
.positiveColor(ctx.getColor(R.color.dialog_button_default))
|
||||
.canceledOnTouchOutside(false)
|
||||
.build()
|
||||
.show());
|
||||
return;
|
||||
}
|
||||
|
||||
if (url != null) {
|
||||
downloadWithHandler(ctx, url, fileName, versionInfo);
|
||||
} else {
|
||||
GlobalAppContext.toast(R.string.text_github_backup_url_used, Toast.LENGTH_LONG);
|
||||
downloadWithHandler(ctx, urlBackup, fileNameBackup, versionInfo);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private void downloadWithHandler(Context ctx, String url, String fileName, VersionInfo versionInfo) {
|
||||
mHandler.post(() -> download(ctx, url, fileName, versionInfo));
|
||||
}
|
||||
|
||||
private String getRawHtmlFromRelease(GHRepository repo, GHRelease release) {
|
||||
Reader reader;
|
||||
try {
|
||||
reader = repo.renderMarkdown(release.getBody(), MarkdownMode.MARKDOWN);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
StringBuilder textBuilder = new StringBuilder();
|
||||
try (Reader r = new BufferedReader(reader)) {
|
||||
int c;
|
||||
while ((c = r.read()) != -1) {
|
||||
textBuilder.append((char) c);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return textBuilder.toString();
|
||||
}
|
||||
|
||||
private GHRelease getGitHubRelease(GHRepository repo) {
|
||||
try {
|
||||
return repo.getLatestRelease();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private GHRepository getGitHubRepo(GitHub github, String userName, String repoName) {
|
||||
try {
|
||||
GHUser user = github.getUser(userName);
|
||||
return user.getRepository(repoName);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkReleaseTagMatchesProp(String releaseTag, String propVersion) {
|
||||
return releaseTag.endsWith(propVersion);
|
||||
}
|
||||
|
||||
private void setDialogContent(MaterialDialog dialog, String content) {
|
||||
mHandler.post(() -> dialog.setContent(content));
|
||||
}
|
||||
|
||||
private void setDialogContent(MaterialDialog dialog, Spanned content) {
|
||||
mHandler.post(() -> dialog.setContent(content));
|
||||
}
|
||||
|
||||
private void setDialogContent(MaterialDialog dialog, int resId) {
|
||||
mHandler.post(() -> dialog.setContent(resId));
|
||||
}
|
||||
|
||||
private GitHub connectToGitHubIfNeeded() {
|
||||
try {
|
||||
if (mGitHubConnection == null) {
|
||||
// FIXME by SuperMonster003 on May 31, 2022.
|
||||
// ! Given that java.time package was added only in Android O (API 26),
|
||||
// ! API 24 and 25 will throw an java.lang.NoClassDefFoundError here.
|
||||
mGitHubConnection = GitHub.connectAnonymously();
|
||||
}
|
||||
return mGitHubConnection;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void showSnackBar(@NonNull VersionInfo versionInfo) {
|
||||
String content = mContext.getString(R.string.text_new_version_found) + ": " + versionInfo.getVersionName();
|
||||
|
||||
CustomSnackbar snackbar = CustomSnackbar.make(mView, content, BaseTransientBottomBar.LENGTH_INDEFINITE);
|
||||
snackbar.setAnimationMode(BaseTransientBottomBar.ANIMATION_MODE_SLIDE)
|
||||
.setActionOne(R.string.text_updates_snack_bar_act_view, v -> showDialog(versionInfo, mView.getContext()))
|
||||
.setActionTwo(R.string.text_updates_snack_bar_act_later, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
private MaterialDialog getPendingDialog(Context context, int content) {
|
||||
// TODO by SuperMonster003 on May 29, 2022.
|
||||
// ! Add a "CANCEL" button for interruption.
|
||||
// ! Concurrent programming may be needed.
|
||||
|
||||
return new MaterialDialog.Builder(context)
|
||||
.content(content)
|
||||
.autoDismiss(false)
|
||||
.cancelable(false)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final Context mContext;
|
||||
|
||||
private View mView;
|
||||
private String mBaseUrl;
|
||||
private String mUrl;
|
||||
private PromptMode mPromptMode = PromptMode.NONE;
|
||||
private SimpleObserver<ResponseBody> mCallback;
|
||||
|
||||
public Builder() {
|
||||
this(GlobalAppContext.get());
|
||||
}
|
||||
|
||||
public Builder(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public Builder(View view) {
|
||||
this();
|
||||
mView = view;
|
||||
}
|
||||
|
||||
public Builder setBaseUrl(String baseUrl) {
|
||||
this.mBaseUrl = baseUrl;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setUrl(String url) {
|
||||
this.mUrl = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setPromptMode(PromptMode promptMode) {
|
||||
this.mPromptMode = promptMode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setCallback(SimpleObserver<ResponseBody> callback) {
|
||||
this.mCallback = callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UpdateChecker build() {
|
||||
ensureUrl();
|
||||
return new UpdateChecker(mContext, mView, mBaseUrl, mUrl, mPromptMode, mCallback);
|
||||
}
|
||||
|
||||
private void ensureUrl() {
|
||||
String regexUrl = "^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]";
|
||||
if (mBaseUrl != null) {
|
||||
if (!mBaseUrl.matches(regexUrl)) {
|
||||
System.out.println("Base URL: " + mBaseUrl);
|
||||
throw new IllegalArgumentException(mContext.getString(R.string.error_illegal_url_argument));
|
||||
}
|
||||
} else {
|
||||
if (!mUrl.matches(regexUrl)) {
|
||||
System.out.println("URL: " + mUrl);
|
||||
throw new IllegalArgumentException(mContext.getString(R.string.error_illegal_relative_url_argument_without_base));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private UpdateCheckerApi getCheckerApi() {
|
||||
if (checkerApi == null) {
|
||||
checkerApi = new Retrofit.Builder()
|
||||
.baseUrl(mBaseUrl)
|
||||
.addConverterFactory(GsonConverterFactory.create(new GsonBuilder().setLenient().create()))
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.build()
|
||||
.create(UpdateCheckerApi.class);
|
||||
}
|
||||
return checkerApi;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package org.autojs.autojs.network;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
|
||||
import org.autojs.autojs.network.api.UpdateCheckApi;
|
||||
import org.autojs.autojs.network.entity.VersionInfo;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/9/20.
|
||||
* Modified by SuperMonster003 as of Feb 26, 2022.
|
||||
*/
|
||||
public class VersionService {
|
||||
|
||||
private static final String baseUrl = "https://raw.githubusercontent.com/";
|
||||
|
||||
private static Retrofit mRetrofit;
|
||||
|
||||
public static Observable<VersionInfo> checkForUpdates() {
|
||||
Retrofit mRetrofit = getRetrofit();
|
||||
return mRetrofit.create(UpdateCheckApi.class)
|
||||
.checkForUpdates()
|
||||
.subscribeOn(Schedulers.io());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static Retrofit getRetrofit() {
|
||||
if (mRetrofit == null) {
|
||||
mRetrofit = new Retrofit.Builder()
|
||||
.baseUrl(baseUrl)
|
||||
.addConverterFactory(GsonConverterFactory.create(new GsonBuilder().setLenient().create()))
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.build();
|
||||
}
|
||||
return mRetrofit;
|
||||
}
|
||||
|
||||
}
|
||||
+8
-4
@@ -1,19 +1,23 @@
|
||||
package org.autojs.autojs.network.api;
|
||||
|
||||
import org.autojs.autojs.network.entity.VersionInfo;
|
||||
import java.io.InputStream;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Headers;
|
||||
import retrofit2.http.Streaming;
|
||||
import retrofit2.http.Url;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/9/20.
|
||||
* Modified by SuperMonster003 as of Feb 28, 2022.
|
||||
*/
|
||||
public interface UpdateCheckApi {
|
||||
public interface UpdateCheckerApi {
|
||||
|
||||
@GET("/SuperMonster003/AutoJs6/master/project-versions.json")
|
||||
@Streaming
|
||||
@GET()
|
||||
@Headers("Cache-Control: no-cache")
|
||||
Observable<VersionInfo> checkForUpdates();
|
||||
Observable<ResponseBody> checkForUpdates(@Url String url);
|
||||
|
||||
}
|
||||
@@ -1,19 +1,25 @@
|
||||
package org.autojs.autojs.network.download;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.util.Log;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
import com.afollestad.materialdialogs.internal.MDButton;
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.concurrent.VolatileBox;
|
||||
import com.stardust.pio.PFiles;
|
||||
|
||||
import org.autojs.autojs6.R;
|
||||
import org.autojs.autojs.network.api.DownloadApi;
|
||||
import org.autojs.autojs.network.entity.VersionInfo;
|
||||
import org.autojs.autojs.tool.SimpleObserver;
|
||||
import org.autojs.autojs.tool.UpdateUtils;
|
||||
import org.autojs.autojs6.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -21,17 +27,21 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import io.reactivex.subjects.PublishSubject;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/10/20.
|
||||
@@ -40,32 +50,38 @@ public class DownloadManager {
|
||||
|
||||
private static final String LOG_TAG = "DownloadManager";
|
||||
private static DownloadManager sInstance;
|
||||
|
||||
private static final int RETRY_COUNT = 3;
|
||||
|
||||
private final DownloadApi mDownloadApi;
|
||||
private final ConcurrentHashMap<String, VolatileBox<Boolean>> mDownloadStatuses = new ConcurrentHashMap<>();
|
||||
|
||||
private Disposable mDisposable;
|
||||
|
||||
public DownloadManager() {
|
||||
Retrofit mRetrofit = new Retrofit.Builder()
|
||||
.baseUrl("https://www.autojs.org")
|
||||
.baseUrl(UpdateUtils.BASE_URL)
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.client(new OkHttpClient.Builder()
|
||||
.addInterceptor(chain -> {
|
||||
Request request = chain.request();
|
||||
Response response = chain.proceed(request);
|
||||
int tryCount = 0;
|
||||
while (!response.isSuccessful() && tryCount < RETRY_COUNT) {
|
||||
tryCount++;
|
||||
response = chain.proceed(request);
|
||||
}
|
||||
return response;
|
||||
})
|
||||
.build()
|
||||
)
|
||||
.client(getOkHttpClient())
|
||||
.build();
|
||||
|
||||
mDownloadApi = mRetrofit.create(DownloadApi.class);
|
||||
}
|
||||
|
||||
private OkHttpClient getOkHttpClient() {
|
||||
Interceptor interceptor = chain -> {
|
||||
Request request = chain.request();
|
||||
Response response = chain.proceed(request);
|
||||
int tryCount = 0;
|
||||
while (!response.isSuccessful() && tryCount < RETRY_COUNT) {
|
||||
tryCount++;
|
||||
response = chain.proceed(request);
|
||||
}
|
||||
return response;
|
||||
};
|
||||
return new OkHttpClient.Builder()
|
||||
.addInterceptor(interceptor)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static DownloadManager getInstance() {
|
||||
if (sInstance == null) {
|
||||
@@ -74,6 +90,11 @@ public class DownloadManager {
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public void disposeIfNeeded() {
|
||||
if (mDisposable != null) {
|
||||
mDisposable.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static String parseFileNameLocally(String url) {
|
||||
int i = url.lastIndexOf('-');
|
||||
@@ -89,7 +110,7 @@ public class DownloadManager {
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
@SuppressLint("CheckResult")
|
||||
public Observable<Integer> download(String url, String path) {
|
||||
public Observable<ProgressInfo> download(String url, String path) {
|
||||
DownloadTask task = new DownloadTask(url, path);
|
||||
mDownloadApi.download(url)
|
||||
.subscribeOn(Schedulers.io())
|
||||
@@ -98,26 +119,73 @@ public class DownloadManager {
|
||||
}
|
||||
|
||||
public Observable<File> downloadWithProgress(Context context, String url, String path) {
|
||||
String fileName = DownloadManager.parseFileNameLocally(url);
|
||||
return download(url, path, createDownloadProgressDialog(context, url, fileName));
|
||||
String content = context.getString(R.string.text_file_name) + ": " + DownloadManager.parseFileNameLocally(url);
|
||||
return downloadWithProgress(context, url, path, content);
|
||||
}
|
||||
|
||||
private MaterialDialog createDownloadProgressDialog(Context context, String url, String fileName) {
|
||||
return new MaterialDialog.Builder(context)
|
||||
.progress(false, 100)
|
||||
.title(fileName)
|
||||
public Observable<File> downloadWithProgress(Context context, String url, String path, VersionInfo versionInfo) {
|
||||
return download(context, url, path, createDownloadProgressDialog(context, url, versionInfo, null));
|
||||
}
|
||||
|
||||
public Observable<File> downloadWithProgress(Context context, String url, String path, String content) {
|
||||
return download(context, url, path, createDownloadProgressDialog(context, url, null, content));
|
||||
}
|
||||
|
||||
private MaterialDialog createDownloadProgressDialog(Context context, String url, @Nullable VersionInfo versionInfo, @Nullable String content) {
|
||||
MaterialDialog d = new MaterialDialog.Builder(context)
|
||||
.title(context.getString(R.string.text_downloading))
|
||||
.positiveText(R.string.dialog_button_cancel_download)
|
||||
.onPositive((dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
DownloadManager.getInstance().cancelDownload(url);
|
||||
})
|
||||
.progress(false, 100, true)
|
||||
.cancelable(false)
|
||||
.positiveText(R.string.text_cancel_download)
|
||||
.onPositive((dialog, which) -> DownloadManager.getInstance().cancelDownload(url))
|
||||
.autoDismiss(false)
|
||||
.show();
|
||||
|
||||
String contentText = versionInfo != null ? versionInfo.toString() : content;
|
||||
if (contentText != null) {
|
||||
d.setContent(contentText);
|
||||
}
|
||||
|
||||
d.setProgressNumberFormat(context.getString(R.string.text_half_ellipsis));
|
||||
|
||||
ProgressBar progressBar = d.getProgressBar();
|
||||
progressBar.setProgressTintList(ColorStateList.valueOf(context.getColor(R.color.dialog_progress_download_tint)));
|
||||
progressBar.setProgressBackgroundTintList(ColorStateList.valueOf(context.getColor(R.color.dialog_progress_download_bg_tint)));
|
||||
|
||||
MDButton positiveButton = d.getActionButton(DialogAction.POSITIVE);
|
||||
positiveButton.setTextColor(context.getColor(R.color.dialog_progress_download_act_btn));
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
private Observable<File> download(String url, String path, MaterialDialog progressDialog) {
|
||||
private Observable<File> download(Context context, String url, String path, MaterialDialog progressDialog) {
|
||||
PublishSubject<File> subject = PublishSubject.create();
|
||||
DownloadManager.getInstance().download(url, path)
|
||||
DownloadManager downloadMgr = DownloadManager.getInstance();
|
||||
downloadMgr.download(url, path)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnNext(progressDialog::setProgress)
|
||||
.doOnNext(o -> {
|
||||
// 10,000 KB (around but less than 10 MB)
|
||||
int megaThreshold = 10000 * (1 << 10);
|
||||
if (o.getTotalBytes() > megaThreshold) {
|
||||
progressDialog.setProgressNumberFormat(String.format(Locale.getDefault(),
|
||||
context.getString(R.string.format_dialog_progress_number_format_mega_bytes),
|
||||
o.getReadMegaBytes(), o.getTotalMegaBytes()));
|
||||
} else {
|
||||
progressDialog.setProgressNumberFormat(String.format(Locale.getDefault(),
|
||||
context.getString(R.string.format_dialog_progress_number_format_kilo_bytes),
|
||||
o.getReadKiloBytes(), o.getTotalKiloBytes()));
|
||||
}
|
||||
progressDialog.setProgress(o.getProgress());
|
||||
})
|
||||
.subscribe(new SimpleObserver<>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable disposable) {
|
||||
mDisposable = disposable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
progressDialog.dismiss();
|
||||
@@ -129,6 +197,8 @@ public class DownloadManager {
|
||||
public void onError(Throwable error) {
|
||||
Log.e(LOG_TAG, "Download failed", error);
|
||||
progressDialog.dismiss();
|
||||
disposeIfNeeded();
|
||||
getOkHttpClient().dispatcher().cancelAll();
|
||||
subject.onError(error);
|
||||
}
|
||||
});
|
||||
@@ -142,6 +212,11 @@ public class DownloadManager {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCancelled(String url) {
|
||||
VolatileBox<Boolean> status = mDownloadStatuses.get(url);
|
||||
return status != null && !status.get();
|
||||
}
|
||||
|
||||
private class DownloadTask {
|
||||
|
||||
private final String mUrl;
|
||||
@@ -149,24 +224,27 @@ public class DownloadManager {
|
||||
private final VolatileBox<Boolean> mStatus;
|
||||
private InputStream mInputStream;
|
||||
private FileOutputStream mFileOutputStream;
|
||||
private final PublishSubject<Integer> mProgress;
|
||||
private final PublishSubject<ProgressInfo> mProgress;
|
||||
|
||||
public DownloadTask(String url, String path) {
|
||||
mUrl = url;
|
||||
mPath = path;
|
||||
mStatus = new VolatileBox<>(true);
|
||||
VolatileBox<Boolean> previous = mDownloadStatuses.put(mUrl, mStatus);
|
||||
if (previous != null)
|
||||
if (previous != null) {
|
||||
previous.set(false);
|
||||
}
|
||||
mProgress = PublishSubject.create();
|
||||
}
|
||||
|
||||
private void startImpl(ResponseBody body) throws IOException {
|
||||
private void startImpl(ResponseBody body) throws Exception {
|
||||
byte[] buffer = new byte[4096];
|
||||
mFileOutputStream = new FileOutputStream(mPath);
|
||||
mInputStream = body.byteStream();
|
||||
long total = body.contentLength();
|
||||
long read = 0;
|
||||
|
||||
ProgressInfo o = new ProgressInfo(total);
|
||||
|
||||
while (true) {
|
||||
if (!mStatus.get()) {
|
||||
onCancel();
|
||||
@@ -176,52 +254,51 @@ public class DownloadManager {
|
||||
if (len == -1) {
|
||||
break;
|
||||
}
|
||||
read += len;
|
||||
o.incrementRead(len);
|
||||
mFileOutputStream.write(buffer, 0, len);
|
||||
if (total > 0) {
|
||||
mProgress.onNext((int) (100 * read / total));
|
||||
if (o.getTotalBytes() > 0) {
|
||||
mProgress.onNext(o);
|
||||
}
|
||||
}
|
||||
mProgress.onComplete();
|
||||
recycle();
|
||||
}
|
||||
|
||||
public void start(ResponseBody body) {
|
||||
try {
|
||||
PFiles.ensureDir(mPath);
|
||||
startImpl(body);
|
||||
} catch (Exception e) {
|
||||
mProgress.onError(e);
|
||||
}
|
||||
public void start(ResponseBody body) throws Exception {
|
||||
PFiles.ensureDir(mPath);
|
||||
startImpl(body);
|
||||
}
|
||||
|
||||
private void onCancel() {
|
||||
GlobalAppContext.toast(R.string.text_download_cancelled);
|
||||
recycle();
|
||||
// TODO: 2017/12/6 notify?
|
||||
}
|
||||
|
||||
public void recycle() {
|
||||
// FIXME by SuperMonster003 on May 31, 2022.
|
||||
// ! Seems like none of the ways below could stop the downloading process.
|
||||
// ! Even worse, progress may stuck at around 99% and suspend.
|
||||
// disposeIfNeeded();
|
||||
// getOkHttpClient().dispatcher().cancelAll();
|
||||
// body.close();
|
||||
|
||||
mDownloadStatuses.remove(mUrl);
|
||||
if (mInputStream != null) {
|
||||
try {
|
||||
mInputStream.close();
|
||||
} catch (IOException ignored) {
|
||||
|
||||
}
|
||||
try {
|
||||
mInputStream.close();
|
||||
} catch (IOException ignored) {
|
||||
// Ignored.
|
||||
}
|
||||
if (mFileOutputStream != null) {
|
||||
try {
|
||||
mFileOutputStream.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
try {
|
||||
mFileOutputStream.close();
|
||||
} catch (IOException ignored) {
|
||||
// Ignored.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public PublishSubject<Integer> progress() {
|
||||
public PublishSubject<ProgressInfo> progress() {
|
||||
return mProgress;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package org.autojs.autojs.network.download;
|
||||
|
||||
/**
|
||||
* Created by SuperMonster003 on May 30, 2022.
|
||||
*/
|
||||
|
||||
public class ProgressInfo {
|
||||
private long mRead = 0;
|
||||
private long mTotal;
|
||||
|
||||
public ProgressInfo(long contentLength) {
|
||||
mTotal = contentLength;
|
||||
}
|
||||
|
||||
public long getTotalBytes() {
|
||||
return mTotal;
|
||||
}
|
||||
|
||||
public float getTotalKiloBytes() {
|
||||
return (float) (mTotal / Math.pow(2, 10));
|
||||
}
|
||||
|
||||
public float getTotalMegaBytes() {
|
||||
return (float) (mTotal / Math.pow(2, 20));
|
||||
}
|
||||
|
||||
public void setTotal(long total) {
|
||||
mTotal = total;
|
||||
}
|
||||
|
||||
public void incrementTotal(long i) {
|
||||
mTotal += i;
|
||||
}
|
||||
|
||||
public long getReadBytes() {
|
||||
return mRead;
|
||||
}
|
||||
|
||||
public float getReadKiloBytes() {
|
||||
return (float) (mRead / Math.pow(2, 10));
|
||||
}
|
||||
|
||||
public float getReadMegaBytes() {
|
||||
return (float) (mRead / Math.pow(2, 20));
|
||||
}
|
||||
|
||||
public void setRead(long read) {
|
||||
mRead = read;
|
||||
}
|
||||
|
||||
public void incrementRead(long i) {
|
||||
mRead += i;
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
return (int) (mRead * 100 / mTotal);
|
||||
}
|
||||
}
|
||||
@@ -2,27 +2,63 @@ package org.autojs.autojs.network.entity;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
|
||||
import org.autojs.autojs6.BuildConfig;
|
||||
import org.autojs.autojs6.R;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/9/20.
|
||||
* Modified by SuperMonster003 as of May 29, 2022.
|
||||
*/
|
||||
public class VersionInfo {
|
||||
|
||||
public int appVersionCode;
|
||||
public String appVersionName;
|
||||
private String mVersionName;
|
||||
private int mVersionCode;
|
||||
|
||||
public VersionInfo(@NonNull String propertiesFileRawString) {
|
||||
String regexVersionName = "VERSION_NAME=.+";
|
||||
String regexVersionCode = "VERSION_BUILD=.+";
|
||||
for (String string : propertiesFileRawString.split("\n")) {
|
||||
if (string.matches(regexVersionName)) {
|
||||
mVersionName = string.split("=")[1];
|
||||
} else if (string.matches(regexVersionCode)) {
|
||||
mVersionCode = Integer.parseInt(string.split("=")[1]);
|
||||
}
|
||||
if (mVersionName != null && mVersionCode > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public VersionInfo(@NonNull String versionName, int versionCode) {
|
||||
mVersionName = versionName;
|
||||
mVersionCode = versionCode;
|
||||
}
|
||||
|
||||
public boolean isNewer() {
|
||||
return appVersionCode > BuildConfig.VERSION_CODE;
|
||||
return mVersionCode > BuildConfig.VERSION_CODE;
|
||||
}
|
||||
|
||||
public boolean isNotIgnored() {
|
||||
// TODO by SuperMonster003 on May 30, 2022.
|
||||
return true;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UpdateInfo{" +
|
||||
"appVersionCode=" + appVersionCode +
|
||||
", appVersionName='" + appVersionName + '\'' +
|
||||
'}';
|
||||
return MessageFormat.format("{0}: {1} ({2})", GlobalAppContext.getString(R.string.text_version), mVersionName, mVersionCode);
|
||||
}
|
||||
|
||||
public String getVersionName() {
|
||||
return mVersionName;
|
||||
}
|
||||
|
||||
public int getVersionCode() {
|
||||
return mVersionCode;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import com.stardust.autojs.runtime.api.Device;
|
||||
import com.stardust.util.MapBuilder;
|
||||
|
||||
import org.autojs.autojs6.BuildConfig;
|
||||
import org.autojs.autojs6.R;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
@@ -167,7 +168,7 @@ abstract public class JsonSocket extends Socket {
|
||||
} else if (value instanceof JsonElement) {
|
||||
data.add(key, (JsonElement) value);
|
||||
} else {
|
||||
throw new IllegalArgumentException("cannot put value " + value + " into json");
|
||||
throw new IllegalArgumentException(GlobalAppContext.getString(R.string.error_put_value_into_json, value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,12 @@ import android.content.Intent;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.execution.ExecutionConfig;
|
||||
|
||||
import org.autojs.autojs.external.ScriptIntents;
|
||||
import org.autojs.autojs.storage.database.BaseModel;
|
||||
import org.autojs.autojs6.R;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeConstants;
|
||||
import org.joda.time.LocalDateTime;
|
||||
@@ -100,7 +102,7 @@ public class TimedTask extends BaseModel {
|
||||
dayOfWeek++;
|
||||
nextTimeMillis += TimeUnit.DAYS.toMillis(1);
|
||||
}
|
||||
throw new IllegalStateException("Should not happen! timeFlag = " + mTimeFlag + ", dayOfWeek = " + DateTime.now().getDayOfWeek());
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static long getDayOfWeekTimeFlag(int dayOfWeek) {
|
||||
@@ -127,7 +129,7 @@ public class TimedTask extends BaseModel {
|
||||
return FLAG_FRIDAY;
|
||||
|
||||
}
|
||||
throw new IllegalArgumentException("dayOfWeek = " + dayOfWeek);
|
||||
throw new IllegalArgumentException(GlobalAppContext.getString(R.string.error_illegal_argument, "dayOfWeek", dayOfWeek));
|
||||
}
|
||||
|
||||
public long getMillis() {
|
||||
|
||||
@@ -8,10 +8,16 @@ import org.autojs.autojs.ui.log.LogActivity_;
|
||||
|
||||
public class ConsoleTool {
|
||||
|
||||
public static void launch() {
|
||||
LogActivity_.intent(GlobalAppContext.get())
|
||||
.flags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.start();
|
||||
public static boolean launch() {
|
||||
try {
|
||||
LogActivity_.intent(GlobalAppContext.get())
|
||||
.flags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.start();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package org.autojs.autojs.tool;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
import com.stardust.autojs.annotation.ScriptInterface;
|
||||
|
||||
import org.autojs.autojs.network.UpdateChecker;
|
||||
import org.autojs.autojs.network.UpdateChecker.PromptMode;
|
||||
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
/**
|
||||
* Created by SuperMonster003 on May 29, 2022.
|
||||
*/
|
||||
|
||||
public class UpdateUtils {
|
||||
|
||||
public static String BASE_URL = "https://raw.githubusercontent.com/";
|
||||
public static String RELATIVE_URL = "/SuperMonster003/AutoJs6/master/version.properties";
|
||||
public static String URL = BASE_URL + RELATIVE_URL.substring(1);
|
||||
|
||||
@ScriptInterface
|
||||
public static UpdateChecker getDialogChecker(Context context, String url, SimpleObserver<ResponseBody> callback) {
|
||||
return getBuilder(context, url, callback)
|
||||
.setPromptMode(PromptMode.DIALOG)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static UpdateChecker getDialogChecker(Context context) {
|
||||
return getDialogChecker(context, null, null);
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
public static UpdateChecker getSnackbarChecker(View view, String url, SimpleObserver<ResponseBody> callback) {
|
||||
return getBuilder(view, url, callback)
|
||||
.setPromptMode(PromptMode.SNACKBAR)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static UpdateChecker getSnackbarChecker(View view) {
|
||||
return getSnackbarChecker(view, null, null);
|
||||
}
|
||||
|
||||
private static UpdateChecker.Builder getBuilder(Context context, String url, SimpleObserver<ResponseBody> callback) {
|
||||
return new UpdateChecker.Builder(context)
|
||||
.setBaseUrl(BASE_URL)
|
||||
.setUrl(url != null ? url : RELATIVE_URL)
|
||||
.setCallback(callback);
|
||||
}
|
||||
|
||||
private static UpdateChecker.Builder getBuilder(View view, String url, SimpleObserver<ResponseBody> callback) {
|
||||
return new UpdateChecker.Builder(view)
|
||||
.setBaseUrl(BASE_URL)
|
||||
.setUrl(url != null ? url : RELATIVE_URL)
|
||||
.setCallback(callback);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,12 +29,12 @@ import com.stardust.pio.PFiles;
|
||||
import org.androidannotations.annotations.AfterViews;
|
||||
import org.androidannotations.annotations.EActivity;
|
||||
import org.androidannotations.annotations.ViewById;
|
||||
import org.autojs.autojs6.R;
|
||||
import org.autojs.autojs.storage.file.TmpScriptFiles;
|
||||
import org.autojs.autojs.theme.dialog.ThemeColorMaterialDialogBuilder;
|
||||
import org.autojs.autojs.tool.Observers;
|
||||
import org.autojs.autojs.ui.BaseActivity;
|
||||
import org.autojs.autojs.ui.main.MainActivity_;
|
||||
import org.autojs.autojs6.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -158,11 +158,29 @@ public class EditActivity extends BaseActivity implements OnActivityResultDelega
|
||||
Log.d(LOG_TAG, "onActionModeStarted: " + mode);
|
||||
Menu menu = mode.getMenu();
|
||||
MenuItem item = menu.getItem(menu.size() - 1);
|
||||
menu.add(item.getGroupId(), R.id.action_delete_line, 10000, R.string.text_delete_line);
|
||||
menu.add(item.getGroupId(), R.id.action_copy_line, 20000, R.string.text_copy_line);
|
||||
addMenuItem(menu, item.getGroupId(), R.id.action_delete_line, 10000, R.string.text_delete_line, () -> mEditorMenu.deleteLine());
|
||||
addMenuItem(menu, item.getGroupId(), R.id.action_copy_line, 20000, R.string.text_copy_line, () -> mEditorMenu.copyLine());
|
||||
super.onActionModeStarted(mode);
|
||||
}
|
||||
|
||||
private void addMenuItem(Menu menu, int groupId, int itemId, int order, int titleRes, Runnable runnable) {
|
||||
try {
|
||||
menu.add(groupId, itemId, order, titleRes).setOnMenuItemClickListener(item -> {
|
||||
try {
|
||||
runnable.run();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
// @Example android.content.res.Resources.NotFoundException
|
||||
// ! on MIUI devices (maybe more)
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSupportActionModeStarted(@NonNull androidx.appcompat.view.ActionMode mode) {
|
||||
Log.d(LOG_TAG, "onSupportActionModeStarted: mode = " + mode);
|
||||
@@ -215,14 +233,17 @@ public class EditActivity extends BaseActivity implements OnActivityResultDelega
|
||||
new ThemeColorMaterialDialogBuilder(this)
|
||||
.title(R.string.text_prompt)
|
||||
.content(R.string.edit_exit_without_save_warn)
|
||||
.positiveText(R.string.text_cancel)
|
||||
.negativeText(R.string.text_save_and_exit)
|
||||
.neutralText(R.string.text_exit_directly)
|
||||
.onNegative((dialog, which) -> {
|
||||
.neutralText(R.string.text_back)
|
||||
.neutralColor(getColor(R.color.dialog_button_default))
|
||||
.negativeText(R.string.text_exit_directly)
|
||||
.negativeColor(getColor(R.color.dialog_button_caution))
|
||||
.positiveText(R.string.text_save_and_exit)
|
||||
.positiveColor(getColor(R.color.dialog_button_hint))
|
||||
.onNegative((dialog, which) -> finishAndRemoveFromRecents())
|
||||
.onPositive((dialog, which) -> {
|
||||
mEditorView.saveFile();
|
||||
finishAndRemoveFromRecents();
|
||||
})
|
||||
.onNeutral((dialog, which) -> finishAndRemoveFromRecents())
|
||||
.show();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.autojs.script.JavaScriptSource;
|
||||
import com.stardust.pio.PFiles;
|
||||
|
||||
import org.autojs.autojs.tool.ConsoleTool;
|
||||
import org.autojs.autojs6.R;
|
||||
import org.autojs.autojs.model.indices.AndroidClass;
|
||||
import org.autojs.autojs.model.indices.ClassSearchingItem;
|
||||
@@ -23,7 +24,6 @@ import org.autojs.autojs.ui.project.BuildActivity;
|
||||
import org.autojs.autojs.ui.project.BuildActivity_;
|
||||
import org.autojs.autojs.ui.common.NotAskAgainDialog;
|
||||
import org.autojs.autojs.ui.edit.editor.CodeEditor;
|
||||
import org.autojs.autojs.ui.log.LogActivity_;
|
||||
import org.autojs.autojs.theme.dialog.ThemeColorMaterialDialogBuilder;
|
||||
|
||||
import com.stardust.util.ClipboardUtil;
|
||||
@@ -54,12 +54,10 @@ public class EditorMenu {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.action_log) {
|
||||
showLog();
|
||||
return true;
|
||||
return ConsoleTool.launch();
|
||||
}
|
||||
if (itemId == R.id.action_force_stop) {
|
||||
forceStop();
|
||||
return true;
|
||||
return tryDoing(mEditorView::forceStop);
|
||||
}
|
||||
return onEditOptionsSelected(item)
|
||||
|| onJumpOptionsSelected(item)
|
||||
@@ -79,8 +77,7 @@ public class EditorMenu {
|
||||
.content(R.string.hint_long_click_run_to_debug)
|
||||
.positiveText(R.string.text_ok)
|
||||
.show();
|
||||
mEditorView.debug();
|
||||
return true;
|
||||
return tryDoing(mEditorView::debug);
|
||||
}
|
||||
if (itemId == R.id.action_remove_all_breakpoints) {
|
||||
mEditor.removeAllBreakpoints();
|
||||
@@ -118,24 +115,20 @@ public class EditorMenu {
|
||||
private boolean onMoreOptionsSelected(MenuItem item) {
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.action_console) {
|
||||
showConsole();
|
||||
return true;
|
||||
return tryDoing(mEditorView::showConsole);
|
||||
}
|
||||
if (itemId == R.id.action_import_java_class) {
|
||||
importJavaPackageOrClass();
|
||||
return true;
|
||||
}
|
||||
if (itemId == R.id.action_editor_text_size) {
|
||||
mEditorView.selectTextSize();
|
||||
return true;
|
||||
return tryDoing(mEditorView::selectTextSize);
|
||||
}
|
||||
if (itemId == R.id.action_editor_theme) {
|
||||
mEditorView.selectEditorTheme();
|
||||
return true;
|
||||
return tryDoing(mEditorView::selectEditorTheme);
|
||||
}
|
||||
if (itemId == R.id.action_open_by_other_apps) {
|
||||
openByOtherApps();
|
||||
return true;
|
||||
return tryDoing(mEditorView::openByOtherApps);
|
||||
}
|
||||
if (itemId == R.id.action_info) {
|
||||
showInfo();
|
||||
@@ -212,20 +205,19 @@ public class EditorMenu {
|
||||
return true;
|
||||
}
|
||||
if (itemId == R.id.action_copy_line) {
|
||||
copyLine();
|
||||
return true;
|
||||
return copyLine();
|
||||
}
|
||||
if (itemId == R.id.action_delete_line) {
|
||||
deleteLine();
|
||||
return true;
|
||||
return deleteLine();
|
||||
}
|
||||
if (itemId == R.id.action_paste) {
|
||||
return paste();
|
||||
}
|
||||
if (itemId == R.id.action_clear) {
|
||||
mEditor.setText("");
|
||||
return true;
|
||||
return tryDoing(() -> mEditor.setText(""));
|
||||
}
|
||||
if (itemId == R.id.action_beautify) {
|
||||
beautifyCode();
|
||||
return true;
|
||||
return tryDoing(mEditorView::beautifyCode);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -255,11 +247,12 @@ public class EditorMenu {
|
||||
}
|
||||
|
||||
private void showInfo() {
|
||||
Observable.zip(Observable.just(mEditor.getText()), mEditor.getLineCount(), (text, lineCount) -> {
|
||||
String size = PFiles.getHumanReadableSize(text.length());
|
||||
return String.format(Locale.getDefault(), mContext.getString(R.string.format_editor_info),
|
||||
text.length(), lineCount, size);
|
||||
})
|
||||
Observable
|
||||
.zip(Observable.just(mEditor.getText()), mEditor.getLineCount(), (text, lineCount) -> {
|
||||
String size = PFiles.getHumanReadableSize(text.length());
|
||||
return String.format(Locale.getDefault(), mContext.getString(R.string.format_editor_info),
|
||||
text.length(), lineCount, size);
|
||||
})
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::showInfo);
|
||||
|
||||
@@ -272,20 +265,21 @@ public class EditorMenu {
|
||||
.show();
|
||||
}
|
||||
|
||||
private void copyLine() {
|
||||
mEditor.copyLine();
|
||||
protected boolean copyLine() {
|
||||
return tryDoing(mEditor::copyLine);
|
||||
}
|
||||
|
||||
|
||||
private void deleteLine() {
|
||||
mEditor.deleteLine();
|
||||
protected boolean deleteLine() {
|
||||
return tryDoing(mEditor::deleteLine);
|
||||
}
|
||||
|
||||
private void paste() {
|
||||
CharSequence clip = getClip();
|
||||
if (clip != null) {
|
||||
mEditor.insert(clip.toString());
|
||||
}
|
||||
protected boolean paste() {
|
||||
return tryDoing(() -> {
|
||||
CharSequence clip = getClip();
|
||||
if (clip != null) {
|
||||
mEditor.insert(clip.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -309,25 +303,14 @@ public class EditorMenu {
|
||||
Snackbar.make(mEditorView, R.string.text_already_copied_to_clip, Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
|
||||
private void showLog() {
|
||||
LogActivity_.intent(mContext).start();
|
||||
}
|
||||
|
||||
private void showConsole() {
|
||||
mEditorView.showConsole();
|
||||
}
|
||||
|
||||
private void forceStop() {
|
||||
mEditorView.forceStop();
|
||||
}
|
||||
|
||||
private void openByOtherApps() {
|
||||
mEditorView.openByOtherApps();
|
||||
}
|
||||
|
||||
private void beautifyCode() {
|
||||
mEditorView.beautifyCode();
|
||||
private boolean tryDoing(Runnable callable) {
|
||||
try {
|
||||
callable.run();
|
||||
return true;
|
||||
} catch (Exception ignore) {
|
||||
// Ignored.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,6 +15,8 @@ import android.view.animation.AnimationUtils;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.Scroller;
|
||||
|
||||
import org.autojs.autojs6.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -194,40 +196,34 @@ public class HVScrollView extends FrameLayout {
|
||||
|
||||
@Override
|
||||
public void addView(View child) {
|
||||
if (getChildCount() > 0) {
|
||||
throw new IllegalStateException("ScrollView can host only one direct child");
|
||||
}
|
||||
|
||||
ensureNotMoreThanOneChild();
|
||||
super.addView(child);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addView(View child, int index) {
|
||||
if (getChildCount() > 0) {
|
||||
throw new IllegalStateException("ScrollView can host only one direct child");
|
||||
}
|
||||
|
||||
ensureNotMoreThanOneChild();
|
||||
super.addView(child, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addView(View child, ViewGroup.LayoutParams params) {
|
||||
if (getChildCount() > 0) {
|
||||
throw new IllegalStateException("ScrollView can host only one direct child");
|
||||
}
|
||||
|
||||
ensureNotMoreThanOneChild();
|
||||
super.addView(child, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addView(View child, int index, ViewGroup.LayoutParams params) {
|
||||
if (getChildCount() > 0) {
|
||||
throw new IllegalStateException("ScrollView can host only one direct child");
|
||||
}
|
||||
|
||||
ensureNotMoreThanOneChild();
|
||||
super.addView(child, index, params);
|
||||
}
|
||||
|
||||
private void ensureNotMoreThanOneChild() {
|
||||
if (getChildCount() > 0) {
|
||||
throw new IllegalStateException(getContext().getString(R.string.error_only_one_child_for_scroll_view));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns true this ScrollView can be scrolled
|
||||
*/
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class JavaScriptHighlighter implements SimpleTextWatcher.AfterTextChangedListener {
|
||||
|
||||
|
||||
public static class HighlightTokens {
|
||||
|
||||
public final int[] colors;
|
||||
@@ -90,7 +89,6 @@ public class JavaScriptHighlighter implements SimpleTextWatcher.AfterTextChanged
|
||||
updateTokens(s.toString());
|
||||
}
|
||||
|
||||
|
||||
public void setTheme(Theme theme) {
|
||||
mTheme = theme;
|
||||
}
|
||||
@@ -112,7 +110,6 @@ public class JavaScriptHighlighter implements SimpleTextWatcher.AfterTextChanged
|
||||
} catch (IOException neverHappen) {
|
||||
throw new UncheckedIOException(neverHappen);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package org.autojs.autojs.ui.edit.toolbar;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
@@ -69,7 +71,7 @@ public class DebugToolbarFragment extends ToolbarFragment implements DebugCallba
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
mEditorView = findEditorView(view);
|
||||
mDebugger = DebuggerSingleton.get();
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.autojs.autojs.ui.edit.toolbar;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import android.view.View;
|
||||
@@ -17,9 +19,12 @@ public class SearchToolbarFragment extends ToolbarFragment {
|
||||
public static final String ARGUMENT_SHOW_REPLACE_ITEM = "show_replace_item";
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
boolean showReplaceItem = getArguments().getBoolean(ARGUMENT_SHOW_REPLACE_ITEM, false);
|
||||
boolean showReplaceItem = false;
|
||||
if (getArguments() != null) {
|
||||
showReplaceItem = getArguments().getBoolean(ARGUMENT_SHOW_REPLACE_ITEM, false);
|
||||
}
|
||||
view.findViewById(R.id.replace).setVisibility(showReplaceItem ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import androidx.fragment.app.Fragment;
|
||||
import android.view.View;
|
||||
|
||||
import org.autojs.autojs.ui.edit.EditorView;
|
||||
import org.autojs.autojs6.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -48,7 +49,7 @@ public abstract class ToolbarFragment extends Fragment implements View.OnClickLi
|
||||
view = (View) view.getParent();
|
||||
}
|
||||
if (!(view instanceof EditorView)) {
|
||||
throw new IllegalStateException("cannot find EditorView from child: " + view);
|
||||
throw new IllegalStateException(getString(R.string.error_cannot_find_editor_view_from_child_view, view));
|
||||
}
|
||||
return (EditorView) view;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.heinrichreimersoftware.androidissuereporter.model.github.GithubLogin;
|
||||
import com.heinrichreimersoftware.androidissuereporter.model.github.GithubTarget;
|
||||
import com.heinrichreimersoftware.androidissuereporter.util.ColorUtils;
|
||||
import com.heinrichreimersoftware.androidissuereporter.util.ThemeUtils;
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.theme.ThemeColorManager;
|
||||
|
||||
import org.autojs.autojs6.BuildConfig;
|
||||
@@ -235,7 +236,8 @@ public abstract class AbstractIssueReporterActivity extends BaseActivity {
|
||||
sendBugReport(new GithubLogin(username, password), null);
|
||||
} else {
|
||||
if (TextUtils.isEmpty(token))
|
||||
throw new IllegalStateException("You must provide a GitHub API Token.");
|
||||
throw new IllegalStateException(GlobalAppContext
|
||||
.getString(org.autojs.autojs6.R.string.error_github_api_token_needed));
|
||||
|
||||
String email = null;
|
||||
if (!TextUtils.isEmpty(inputEmail.getText()) &&
|
||||
|
||||
@@ -48,9 +48,12 @@ import org.androidannotations.annotations.AfterViews;
|
||||
import org.androidannotations.annotations.Click;
|
||||
import org.androidannotations.annotations.EActivity;
|
||||
import org.androidannotations.annotations.ViewById;
|
||||
import org.autojs.autojs.Pref;
|
||||
import org.autojs.autojs.autojs.AutoJs;
|
||||
import org.autojs.autojs.external.foreground.MainActivityForegroundService;
|
||||
import org.autojs.autojs.model.explorer.Explorers;
|
||||
import org.autojs.autojs.network.UpdateChecker;
|
||||
import org.autojs.autojs.tool.UpdateUtils;
|
||||
import org.autojs.autojs.ui.BaseActivity;
|
||||
import org.autojs.autojs.ui.common.NotAskAgainDialog;
|
||||
import org.autojs.autojs.ui.doc.DocsFragment_;
|
||||
@@ -101,6 +104,7 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
@Override
|
||||
protected void onPostResume() {
|
||||
restartIfNeeded();
|
||||
autoCheckForUpdatesIfNeeded();
|
||||
super.onPostResume();
|
||||
}
|
||||
|
||||
@@ -111,6 +115,19 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
}
|
||||
}
|
||||
|
||||
private void autoCheckForUpdatesIfNeeded() {
|
||||
if (Pref.isAutoCheckForUpdatesEnabled()) {
|
||||
long minCheckedInterval = 2 * 60 * 60 * 1000; // 2 hours
|
||||
long lastChecked = Pref.getLastUpdatesCheckedTimestamp();
|
||||
|
||||
if (System.currentTimeMillis() - lastChecked > minCheckedInterval) {
|
||||
View rootView = findViewById(android.R.id.content);
|
||||
UpdateChecker checker = UpdateUtils.getSnackbarChecker(rootView);
|
||||
checker.checkNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void applyThemeColor() {
|
||||
if (ThemeColor.fromPreferences(PreferenceManager.getDefaultSharedPreferences(this), null) == null) {
|
||||
ThemeColor defaultThemeColor = new ThemeColor(
|
||||
|
||||
@@ -189,7 +189,10 @@ public class DrawerFragment extends androidx.fragment.app.Fragment {
|
||||
|
||||
new DrawerMenuGroup(R.string.text_appearance),
|
||||
new DrawerMenuItem(R.drawable.ic_night_mode, R.string.text_night_mode, R.string.key_night_mode, this::toggleNightMode),
|
||||
new DrawerMenuItem(R.drawable.ic_personalize, R.string.text_theme_color, this::openThemeColorSettings)
|
||||
new DrawerMenuItem(R.drawable.ic_personalize, R.string.text_theme_color, this::launchThemeColorSettings),
|
||||
|
||||
new DrawerMenuGroup(R.string.text_about),
|
||||
new DrawerMenuItem(R.drawable.ic_about, R.string.text_about_app_and_developer, this::launchAboutAppAndDeveloper)
|
||||
)));
|
||||
mDrawerMenu.setAdapter(mDrawerMenuAdapter);
|
||||
mDrawerMenu.setLayoutManager(new LinearLayoutManager(mContext));
|
||||
@@ -266,7 +269,6 @@ public class DrawerFragment extends androidx.fragment.app.Fragment {
|
||||
syncForegroundServiceState();
|
||||
})
|
||||
.onPositive((dialog, which) -> MainActivityForegroundService.start(mContext))
|
||||
.canceledOnTouchOutside(false)
|
||||
.cancelable(false)
|
||||
.show();
|
||||
}
|
||||
@@ -307,7 +309,6 @@ public class DrawerFragment extends androidx.fragment.app.Fragment {
|
||||
syncUsageStatsPermissionState();
|
||||
})
|
||||
.onPositive((dialog, which) -> requestAppUsagePermission())
|
||||
.canceledOnTouchOutside(false)
|
||||
.cancelable(false)
|
||||
.show();
|
||||
}
|
||||
@@ -350,10 +351,14 @@ public class DrawerFragment extends androidx.fragment.app.Fragment {
|
||||
return ((PowerManager) mContext.getSystemService(Context.POWER_SERVICE)).isIgnoringBatteryOptimizations(mPackageName);
|
||||
}
|
||||
|
||||
public void openThemeColorSettings(DrawerMenuItemViewHolder holder) {
|
||||
public void launchThemeColorSettings(DrawerMenuItemViewHolder holder) {
|
||||
SettingsActivity.selectThemeColor(getActivity());
|
||||
}
|
||||
|
||||
public void launchAboutAppAndDeveloper(DrawerMenuItemViewHolder holder) {
|
||||
SettingsActivity.launchAboutAppAndDeveloper(requireActivity());
|
||||
}
|
||||
|
||||
public void toggleNightMode(@NonNull DrawerMenuItemViewHolder holder) {
|
||||
((BaseActivity) requireActivity()).setNightModeEnabled(holder.getSwitchCompat().isChecked());
|
||||
}
|
||||
@@ -402,7 +407,6 @@ public class DrawerFragment extends androidx.fragment.app.Fragment {
|
||||
syncWriteSecuritySettingsState();
|
||||
})
|
||||
.onPositive((dialog, which) -> grantWriteSecureSettingsAccess())
|
||||
.canceledOnTouchOutside(false)
|
||||
.cancelable(false)
|
||||
.show();
|
||||
}
|
||||
@@ -430,7 +434,6 @@ public class DrawerFragment extends androidx.fragment.app.Fragment {
|
||||
syncProjectMediaAccessState();
|
||||
})
|
||||
.onPositive((dialog, which) -> grantProjectMediaAccess())
|
||||
.canceledOnTouchOutside(false)
|
||||
.cancelable(false)
|
||||
.show();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.autojs.autojs.ui.main.task;
|
||||
import android.content.Context;
|
||||
|
||||
import com.bignerdranch.expandablerecyclerview.model.Parent;
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.execution.ScriptExecution;
|
||||
|
||||
import org.autojs.autojs6.R;
|
||||
@@ -69,7 +70,7 @@ public abstract class TaskGroup implements Parent<Task> {
|
||||
} else if (task instanceof IntentTask) {
|
||||
mTasks.add(new Task.PendingTask((IntentTask) task));
|
||||
} else {
|
||||
throw new IllegalArgumentException("task = " + task);
|
||||
throw new IllegalArgumentException(GlobalAppContext.getString(R.string.error_illegal_argument, "task", task));
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
@@ -100,7 +101,7 @@ public abstract class TaskGroup implements Parent<Task> {
|
||||
} else if (task instanceof IntentTask) {
|
||||
((Task.PendingTask) mTasks.get(i)).setIntentTask((IntentTask) task);
|
||||
} else {
|
||||
throw new IllegalArgumentException("task = " + task);
|
||||
throw new IllegalArgumentException(GlobalAppContext.getString(R.string.error_illegal_argument, "task", task));
|
||||
}
|
||||
}
|
||||
return i;
|
||||
|
||||
@@ -126,7 +126,7 @@ public class BuildActivity extends BaseActivity implements ApkBuilder.ProgressCa
|
||||
}
|
||||
|
||||
private void downloadPlugin() {
|
||||
IntentUtil.browse(this, "https://cdn.jsdelivr.net/gh/SuperMonster002/Hello-Sockpuppet@master/" +
|
||||
IntentUtil.browse(this, "https://raw.githubusercontent.com/SuperMonster002/Hello-Sockpuppet/master/" +
|
||||
"%5B" + "auto.js" + "%5D" +
|
||||
"%5B" + "apk_builder_plugin_4.1.1_alpha2" + "%5D" +
|
||||
"%5B" + "arm-v7a" + "%5D" +
|
||||
|
||||
@@ -11,11 +11,11 @@ import org.androidannotations.annotations.AfterViews;
|
||||
import org.androidannotations.annotations.Click;
|
||||
import org.androidannotations.annotations.EActivity;
|
||||
import org.androidannotations.annotations.ViewById;
|
||||
import org.autojs.autojs.tool.UpdateUtils;
|
||||
import org.autojs.autojs6.BuildConfig;
|
||||
import org.autojs.autojs6.R;
|
||||
import org.autojs.autojs.ui.BaseActivity;
|
||||
import org.autojs.autojs.ui.error.IssueReporterActivity;
|
||||
import org.autojs.autojs.ui.update.UpdateCheckDialog;
|
||||
|
||||
import de.psdev.licensesdialog.LicenseResolver;
|
||||
import de.psdev.licensesdialog.LicensesDialog;
|
||||
@@ -113,8 +113,8 @@ public class AboutActivity extends BaseActivity {
|
||||
|
||||
@SuppressLint("NonConstantResourceId")
|
||||
@Click(R.id.about_functions_button_update)
|
||||
void checkForUpdated() {
|
||||
new UpdateCheckDialog(this).show();
|
||||
void checkForUpdates() {
|
||||
UpdateUtils.getDialogChecker(this).checkNow();
|
||||
}
|
||||
|
||||
@SuppressLint("NonConstantResourceId")
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package org.autojs.autojs.ui.settings;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.Preference;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import org.autojs.autojs.Pref;
|
||||
import org.autojs.autojs6.R;
|
||||
|
||||
/**
|
||||
* Created by SuperMonster003 on May 31, 2022.
|
||||
*/
|
||||
|
||||
public class CheckForUpdatesPreference extends Preference implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
public CheckForUpdatesPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init();
|
||||
}
|
||||
|
||||
public CheckForUpdatesPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
mSharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
public CheckForUpdatesPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public CheckForUpdatesPreference(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToActivity() {
|
||||
setSummaryIfNeeded();
|
||||
super.onAttachedToActivity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
setSummaryIfNeeded();
|
||||
}
|
||||
|
||||
private void setSummaryIfNeeded() {
|
||||
String lastChecked = Pref.getLastUpdatesCheckedTimeString();
|
||||
if (lastChecked != null) {
|
||||
setSummary(getContext().getString(R.string.text_last_updates_checked_time, lastChecked));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.autojs.autojs.ui.settings;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
@@ -23,10 +24,10 @@ import com.stardust.util.MapBuilder;
|
||||
import org.androidannotations.annotations.AfterViews;
|
||||
import org.androidannotations.annotations.EActivity;
|
||||
import org.autojs.autojs.Pref;
|
||||
import org.autojs.autojs.tool.UpdateUtils;
|
||||
import org.autojs.autojs6.R;
|
||||
import org.autojs.autojs.ui.BaseActivity;
|
||||
import org.autojs.autojs.ui.common.NotAskAgainDialog;
|
||||
import org.autojs.autojs.ui.update.UpdateCheckDialog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -66,70 +67,6 @@ public class SettingsActivity extends BaseActivity {
|
||||
.add(new Pair<>(R.color.theme_color_default, R.string.theme_color_default))
|
||||
.list();
|
||||
|
||||
public static void selectThemeColor(Context context) {
|
||||
List<ColorSelectActivity.ColorItem> colorItems = new ArrayList<>(COLOR_ITEMS.size());
|
||||
for (Pair<Integer, Integer> item : COLOR_ITEMS) {
|
||||
colorItems.add(new ColorSelectActivity.ColorItem(context.getString(item.second), ContextCompat.getColor(context, item.first)));
|
||||
}
|
||||
ColorSelectActivity.startColorSelect(context, context.getString(R.string.mt_color_picker_title), colorItems);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static LinkedHashMap<String, Runnable> getAvailableLanguages(@NonNull Context context) {
|
||||
LinkedHashMap<String, Runnable> map = new LinkedHashMap<>();
|
||||
map.put(context.getString(R.string.text_app_language_follow_system),
|
||||
((BaseActivity) context)::setLocaleFollowSystem);
|
||||
map.put(context.getString(R.string.text_app_language_simplified_chinese),
|
||||
() -> ((BaseActivity) context).updateLocale(Locale.SIMPLIFIED_CHINESE));
|
||||
map.put(context.getString(R.string.text_app_language_english),
|
||||
() -> ((BaseActivity) context).updateLocale(Locale.ENGLISH));
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void selectAppLanguage(Context context) {
|
||||
LinkedHashMap<String, Runnable> languagesMap = getAvailableLanguages(context);
|
||||
Set<String> languagesKey = languagesMap.keySet();
|
||||
Collection<Runnable> languagesRunnable = languagesMap.values();
|
||||
|
||||
new MaterialDialog.Builder(context)
|
||||
.title(R.string.text_app_language)
|
||||
.items(languagesKey)
|
||||
.itemsCallbackSingleChoice(Pref.getAppLanguageIndex(), (dialog, itemView, position, text) -> true)
|
||||
.positiveText(R.string.text_ok)
|
||||
.onPositive((dialog, which) -> {
|
||||
int index = dialog.getSelectedIndex();
|
||||
Runnable run = (Runnable) languagesRunnable.toArray()[index];
|
||||
if (run != null) {
|
||||
Pref.setAppLanguageIndex(index);
|
||||
GlobalAppContext.post(run);
|
||||
}
|
||||
dialog.dismiss();
|
||||
})
|
||||
.negativeText(R.string.text_cancel)
|
||||
.onNegative((dialog, which) -> dialog.dismiss())
|
||||
.neutralText(R.string.text_dialog_button_go_to_settings)
|
||||
.onNeutral((dialog, which) -> {
|
||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||
intent.setClassName("com.android.settings", "com.android.settings.LanguageSettings");
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
})
|
||||
.autoDismiss(false)
|
||||
.show();
|
||||
|
||||
showImperfectHint(context);
|
||||
}
|
||||
|
||||
private static void showImperfectHint(Context context) {
|
||||
new NotAskAgainDialog.Builder(context, "SettingsActivity.select_app_language_imperfect_hint")
|
||||
.title(R.string.text_notice)
|
||||
.content(R.string.text_imperfect_hint_for_app_language)
|
||||
.positiveText(R.string.text_ok)
|
||||
.onPositive((dialog, which) -> dialog.dismiss())
|
||||
.autoDismiss(false)
|
||||
.show();
|
||||
}
|
||||
|
||||
@AfterViews
|
||||
void setUpUI() {
|
||||
setUpToolbar();
|
||||
@@ -163,14 +100,28 @@ public class SettingsActivity extends BaseActivity {
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
Activity mActivity = getActivity();
|
||||
ACTION_MAP = new MapBuilder<String, Runnable>()
|
||||
.put(getString(R.string.text_theme_color), () -> selectThemeColor(getActivity()))
|
||||
.put(getString(R.string.text_check_for_updates), () -> new UpdateCheckDialog(getActivity()).show())
|
||||
.put(getString(R.string.text_about_app_and_developer), () -> startActivity(new Intent(getActivity(), AboutActivity_.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)))
|
||||
.put(getString(R.string.text_app_language), () -> selectAppLanguage(getActivity()))
|
||||
.put(getString(R.string.text_theme_color), () -> selectThemeColor(mActivity))
|
||||
.put(getString(R.string.text_about_app_and_developer), () -> launchAboutAppAndDeveloper(mActivity))
|
||||
.put(getString(R.string.text_app_language), () -> selectAppLanguage(mActivity))
|
||||
.put(getString(R.string.text_check_for_updates), () -> checkForUpdates(mActivity))
|
||||
.put(getString(R.string.text_manage_ignored_updates), () -> manageIgnoredUpdates(mActivity))
|
||||
.build();
|
||||
}
|
||||
|
||||
private void manageIgnoredUpdates(Activity mActivity) {
|
||||
// TODO by SuperMonster003 on May 31, 2022.
|
||||
// ! Updates ignorance.
|
||||
|
||||
new MaterialDialog.Builder(mActivity)
|
||||
.title(R.string.text_prompt)
|
||||
.content(R.string.text_under_development_content)
|
||||
.positiveText(R.string.dialog_button_back)
|
||||
.build()
|
||||
.show();
|
||||
}
|
||||
|
||||
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
||||
CharSequence title = preference.getTitle();
|
||||
if (title != null) {
|
||||
@@ -185,4 +136,76 @@ public class SettingsActivity extends BaseActivity {
|
||||
|
||||
}
|
||||
|
||||
public static void checkForUpdates(Context context) {
|
||||
UpdateUtils.getDialogChecker(context).checkNow();
|
||||
}
|
||||
|
||||
public static void selectThemeColor(Context context) {
|
||||
List<ColorSelectActivity.ColorItem> colorItems = new ArrayList<>(COLOR_ITEMS.size());
|
||||
for (Pair<Integer, Integer> item : COLOR_ITEMS) {
|
||||
colorItems.add(new ColorSelectActivity.ColorItem(context.getString(item.second), ContextCompat.getColor(context, item.first)));
|
||||
}
|
||||
ColorSelectActivity.startColorSelect(context, context.getString(R.string.mt_color_picker_title), colorItems);
|
||||
}
|
||||
|
||||
public static void selectAppLanguage(Context context) {
|
||||
LinkedHashMap<String, Runnable> languagesMap = getAvailableLanguages(context);
|
||||
Set<String> languagesKey = languagesMap.keySet();
|
||||
Collection<Runnable> languagesRunnable = languagesMap.values();
|
||||
|
||||
new MaterialDialog.Builder(context)
|
||||
.title(R.string.text_app_language)
|
||||
.items(languagesKey)
|
||||
.itemsCallbackSingleChoice(Pref.getAppLanguageIndex(), (dialog, itemView, position, text) -> true)
|
||||
.positiveText(R.string.text_ok)
|
||||
.onPositive((dialog, which) -> {
|
||||
int index = dialog.getSelectedIndex();
|
||||
Runnable run = (Runnable) languagesRunnable.toArray()[index];
|
||||
if (run != null) {
|
||||
Pref.setAppLanguageIndex(index);
|
||||
GlobalAppContext.post(run);
|
||||
}
|
||||
dialog.dismiss();
|
||||
})
|
||||
.negativeText(R.string.text_cancel)
|
||||
.onNegative((dialog, which) -> dialog.dismiss())
|
||||
.neutralText(R.string.dialog_button_go_to_settings)
|
||||
.onNeutral((dialog, which) -> {
|
||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||
intent.setClassName("com.android.settings", "com.android.settings.LanguageSettings");
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
})
|
||||
.autoDismiss(false)
|
||||
.show();
|
||||
|
||||
showImperfectHint(context);
|
||||
}
|
||||
|
||||
public static void launchAboutAppAndDeveloper(@NonNull Context context) {
|
||||
context.startActivity(new Intent(context, AboutActivity_.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static LinkedHashMap<String, Runnable> getAvailableLanguages(@NonNull Context context) {
|
||||
LinkedHashMap<String, Runnable> map = new LinkedHashMap<>();
|
||||
map.put(context.getString(R.string.text_app_language_follow_system),
|
||||
((BaseActivity) context)::setLocaleFollowSystem);
|
||||
map.put(context.getString(R.string.text_app_language_simplified_chinese),
|
||||
() -> ((BaseActivity) context).updateLocale(Locale.SIMPLIFIED_CHINESE));
|
||||
map.put(context.getString(R.string.text_app_language_english),
|
||||
() -> ((BaseActivity) context).updateLocale(Locale.ENGLISH));
|
||||
return map;
|
||||
}
|
||||
|
||||
private static void showImperfectHint(Context context) {
|
||||
new NotAskAgainDialog.Builder(context, "SettingsActivity.select_app_language_imperfect_hint")
|
||||
.title(R.string.text_notice)
|
||||
.content(R.string.text_imperfect_hint_for_app_language)
|
||||
.positiveText(R.string.text_ok)
|
||||
.onPositive((dialog, which) -> dialog.dismiss())
|
||||
.autoDismiss(false)
|
||||
.show();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package org.autojs.autojs.ui.update;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
|
||||
import org.autojs.autojs6.R;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/9/20.
|
||||
*/
|
||||
public class UpdateCheckDialog {
|
||||
|
||||
private final MaterialDialog mProgress;
|
||||
private final Context mContext;
|
||||
|
||||
public UpdateCheckDialog(Context context) {
|
||||
mContext = context;
|
||||
mProgress = new MaterialDialog.Builder(context)
|
||||
.title(R.string.text_under_development_title)
|
||||
.content(R.string.text_under_development_content)
|
||||
.positiveText(R.string.text_ok)
|
||||
.build();
|
||||
// mProgress = new MaterialDialog.Builder(context)
|
||||
// .progress(true, 0)
|
||||
// .content(R.string.text_checking_update)
|
||||
// .build();
|
||||
}
|
||||
|
||||
public void show() {
|
||||
mProgress.show();
|
||||
// VersionService.checkForUpdates()
|
||||
// .observeOn(AndroidSchedulers.mainThread())
|
||||
// .subscribe(new SimpleObserver<>() {
|
||||
// @Override
|
||||
// public void onNext(@NonNull VersionInfo versionInfo) {
|
||||
// mProgress.dismiss();
|
||||
// if (versionInfo.isNewer()) {
|
||||
// new UpdateInfoDialogBuilder(mContext, versionInfo).show();
|
||||
// } else {
|
||||
// GlobalAppContext.toast(R.string.text_is_latest_version);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(@NonNull Throwable e) {
|
||||
// e.printStackTrace();
|
||||
// mProgress.dismiss();
|
||||
// GlobalAppContext.toast(R.string.text_check_update_error);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package org.autojs.autojs.ui.update;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.util.IntentUtil;
|
||||
|
||||
import org.autojs.autojs.Pref;
|
||||
import org.autojs.autojs6.R;
|
||||
import org.autojs.autojs.external.fileprovider.AppFileProvider;
|
||||
import org.autojs.autojs.network.download.DownloadManager;
|
||||
import org.autojs.autojs.network.entity.VersionInfo;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/9.
|
||||
*/
|
||||
public class UpdateInfoDialogBuilder extends MaterialDialog.Builder {
|
||||
|
||||
private static final String KEY_IGNORED_VERSION_PREFIX = "Ignored version: ";
|
||||
private final SharedPreferences mSharedPreferences;
|
||||
private VersionInfo mVersionInfo;
|
||||
|
||||
public UpdateInfoDialogBuilder(@NonNull Context context, VersionInfo info) {
|
||||
super(context);
|
||||
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
updateInfo(info);
|
||||
}
|
||||
|
||||
public void updateInfo(VersionInfo info) {
|
||||
mVersionInfo = info;
|
||||
title(GlobalAppContext.getString(R.string.text_new_version_found));
|
||||
content(info.appVersionName + "\n" + info.appVersionCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialDialog show() {
|
||||
if (mSharedPreferences.getBoolean(KEY_IGNORED_VERSION_PREFIX + mVersionInfo.appVersionCode, false)) {
|
||||
return null;
|
||||
}
|
||||
return super.show();
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
@SuppressLint("CheckResult")
|
||||
private void directlyDownload(String downloadUrl) {
|
||||
final String path = new File(Pref.getScriptDirPath(), "autojs6-latest.apk").getPath();
|
||||
DownloadManager.getInstance().downloadWithProgress(getContext(), downloadUrl, path)
|
||||
.subscribeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(file -> IntentUtil.installApkOrToast(getContext(), file.getPath(), AppFileProvider.AUTHORITY),
|
||||
error -> {
|
||||
error.printStackTrace();
|
||||
GlobalAppContext.toast(R.string.text_download_failed);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,9 +2,12 @@ package org.autojs.autojs.ui.viewmodel;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
|
||||
import org.autojs.autojs.model.explorer.ExplorerItem;
|
||||
import org.autojs.autojs.model.explorer.ExplorerPage;
|
||||
import org.autojs.autojs.model.explorer.ExplorerSorter;
|
||||
import org.autojs.autojs6.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
@@ -118,7 +121,7 @@ public class ExplorerItemList {
|
||||
case SORT_TYPE_TYPE:
|
||||
return ExplorerSorter.TYPE;
|
||||
}
|
||||
throw new IllegalArgumentException("unknown type " + sortType);
|
||||
throw new IllegalArgumentException(GlobalAppContext.getString(R.string.error_illegal_argument, "sortType", sortType));
|
||||
}
|
||||
|
||||
public int groupCount() {
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
@@ -30,5 +30,5 @@
|
||||
android:scrollbars="vertical"
|
||||
android:textColor="@android:color/secondary_text_light"
|
||||
android:textSize="16sp"
|
||||
tools:text="错误"/>
|
||||
tools:text="@string/text_error"/>
|
||||
</LinearLayout>
|
||||
@@ -26,7 +26,7 @@
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:theme="@style/ToolBarStyle"
|
||||
android:title="@string/app_name"
|
||||
app:layout_scrollFlags="scroll|enterAlways"
|
||||
app:layout_scrollFlags="enterAlways"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
|
||||
@@ -1,149 +1,154 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_force_stop"
|
||||
android:title="@string/text_force_stop"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_force_stop"
|
||||
android:title="@string/text_force_stop"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item android:title="@string/text_edit">
|
||||
|
||||
<menu>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_find_or_replace"
|
||||
android:title="@string/text_find_or_replace"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_find_or_replace"
|
||||
android:title="@string/text_find_or_replace"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_copy_all"
|
||||
android:title="@string/text_copy_all"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_copy_all"
|
||||
android:title="@string/text_copy_all"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_copy_line"
|
||||
android:title="@string/text_copy_line"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_copy_line"
|
||||
android:title="@string/text_copy_line"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_delete_line"
|
||||
android:title="@string/text_delete_line"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_paste"
|
||||
android:title="@string/text_paste"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_clear"
|
||||
android:title="@string/text_clear"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_delete_line"
|
||||
android:title="@string/text_delete_line"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_beautify"
|
||||
android:title="@string/text_code_beautify"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_clear"
|
||||
android:title="@string/text_clear"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_beautify"
|
||||
android:title="@string/text_code_beautify"
|
||||
app:showAsAction="never" />
|
||||
|
||||
</menu>
|
||||
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:title="@string/text_jump"
|
||||
app:showAsAction="never">
|
||||
android:title="@string/text_jump"
|
||||
app:showAsAction="never">
|
||||
|
||||
<menu>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_jump_to_line"
|
||||
android:title="@string/text_jump_to_line"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_jump_to_line"
|
||||
android:title="@string/text_jump_to_line"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_jump_to_start"
|
||||
android:title="@string/text_jump_to_start"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_jump_to_start"
|
||||
android:title="@string/text_jump_to_start"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_jump_to_end"
|
||||
android:title="@string/text_jump_to_end"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_jump_to_end"
|
||||
android:title="@string/text_jump_to_end"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_jump_to_line_start"
|
||||
android:title="@string/text_jump_to_line_start"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_jump_to_line_start"
|
||||
android:title="@string/text_jump_to_line_start"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_jump_to_line_end"
|
||||
android:title="@string/text_jump_to_line_end"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_jump_to_line_end"
|
||||
android:title="@string/text_jump_to_line_end"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
||||
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:title="@string/text_debug"
|
||||
app:showAsAction="never">
|
||||
android:title="@string/text_debug"
|
||||
app:showAsAction="never">
|
||||
|
||||
<menu>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_breakpoint"
|
||||
android:title="@string/text_set_breakpoint"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_breakpoint"
|
||||
android:title="@string/text_set_breakpoint"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_launch_debugger"
|
||||
android:title="@string/text_launch_debugger"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_launch_debugger"
|
||||
android:title="@string/text_launch_debugger"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_remove_all_breakpoints"
|
||||
android:title="@string/text_remove_all_breakpoints"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_remove_all_breakpoints"
|
||||
android:title="@string/text_remove_all_breakpoints"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
||||
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_build_apk"
|
||||
android:title="@string/text_build_apk"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_build_apk"
|
||||
android:title="@string/text_build_apk"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_log"
|
||||
android:title="@string/text_log"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_log"
|
||||
android:title="@string/text_log"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item android:title="@string/text_more">
|
||||
<menu>
|
||||
<item
|
||||
android:id="@+id/action_console"
|
||||
android:title="@string/text_console"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_console"
|
||||
android:title="@string/text_console"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_import_java_class"
|
||||
android:title="@string/text_find_java_classes"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_import_java_class"
|
||||
android:title="@string/text_find_java_classes"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_info"
|
||||
android:title="@string/text_info"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_info"
|
||||
android:title="@string/text_info"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_editor_text_size"
|
||||
android:title="@string/text_text_size"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_editor_text_size"
|
||||
android:title="@string/text_text_size"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_editor_theme"
|
||||
android:title="@string/text_editor_theme"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_editor_theme"
|
||||
android:title="@string/text_editor_theme"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_open_by_other_apps"
|
||||
android:title="@string/text_open_by_other_apps"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/action_open_by_other_apps"
|
||||
android:title="@string/text_open_by_other_apps"
|
||||
app:showAsAction="never" />
|
||||
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
@@ -77,12 +77,12 @@
|
||||
<string name="text_build_failed">Build failed</string>
|
||||
<string name="text_build_successfully">Build succeeded</string>
|
||||
<string name="text_cancel">Cancel</string>
|
||||
<string name="text_cancel_download">Cancel downloading</string>
|
||||
<string name="dialog_button_cancel_download">Cancel</string>
|
||||
<string name="text_cannot_read_file">Can\'t read file</string>
|
||||
<string name="text_change_working_dir">Change working directory</string>
|
||||
<string name="text_checking_update">Checking for updates</string>
|
||||
<string name="text_checking_update" tools:ignore="TypographyEllipsis">Checking for updates...</string>
|
||||
<string name="text_check_for_updates">Check for updates</string>
|
||||
<string name="text_check_update_error">Check for updates failed</string>
|
||||
<string name="error_check_for_update">Checking for updates failed</string>
|
||||
<string name="text_class_or_package_name">Class / Package name</string>
|
||||
<string name="text_clear">Clear</string>
|
||||
<string name="text_clear_file_selection">Clear file selection</string>
|
||||
@@ -102,6 +102,7 @@
|
||||
<string name="text_copy_command">Copy cmd</string>
|
||||
<string name="text_copy_debug_info">Copy debugging log</string>
|
||||
<string name="text_copy_line">Copy line</string>
|
||||
<string name="text_paste">Paste</string>
|
||||
<string name="text_copy_to_clip">Copy to clipboard</string>
|
||||
<string name="text_copy_value">Copy value</string>
|
||||
<string name="text_create_fail">Create failed</string>
|
||||
@@ -123,7 +124,7 @@
|
||||
<string name="text_delete_line">Delete line</string>
|
||||
<string name="text_detail">Details</string>
|
||||
<string name="text_developer_details_under_development">Developer details is under development</string>
|
||||
<string name="text_dialog_button_go_to_settings">System Settings</string>
|
||||
<string name="dialog_button_go_to_settings">System Settings</string>
|
||||
<string name="text_directly_download">Download now</string>
|
||||
<string name="text_directory">Directory</string>
|
||||
<string name="text_display_over_other_app">Display over other apps</string>
|
||||
@@ -365,7 +366,7 @@
|
||||
<string name="text_under_development_content">The feature will be ready to use in the next few updates</string>
|
||||
<string name="text_under_development_title">Under development</string>
|
||||
<string name="text_undo">Undo</string>
|
||||
<string name="text_update">Update</string>
|
||||
<string name="text_updates">Updates</string>
|
||||
<string name="text_usage_stats_permission">Usage stats access</string>
|
||||
<string name="text_usage_stats_permission_description">Provides access to device usage history and statistics which results in currentPackage() a more accurate result</string>
|
||||
<string name="text_username">Username</string>
|
||||
@@ -406,6 +407,42 @@
|
||||
<string name="theme_color_yellow">Yellow</string>
|
||||
<string name="theme_color_yellow_green">Yellow green</string>
|
||||
<string name="text_refresh_explorer_may_needed">An explorer page swipe-to-refresh may be needed</string>
|
||||
<string name="error_set_both_icon_res_and_icon">Can\'t set both iconRes and icon</string>
|
||||
<string name="error_only_one_child_for_scroll_view">ScrollView can host only one direct child</string>
|
||||
<string name="error_illegal_url_argument">URL must starts with a protocol like \"https://\" and so forth</string>
|
||||
<string name="error_illegal_relative_url_argument_without_base">Relative URL can\'t be used without base URL</string>
|
||||
<string name="dialog_button_ignore_current_update">Ignore</string>
|
||||
<string name="dialog_button_back">@string/text_back</string>
|
||||
<string name="dialog_button_update_now">Update</string>
|
||||
<string name="text_getting_release_notes" tools:ignore="TypographyEllipsis">Retrieving release notes...</string>
|
||||
<string name="error_cannot_connect_to_github">Can\'t connect to GitHub</string>
|
||||
<string name="error_invalid_github_repo">Invalid GitHub repository: %s</string>
|
||||
<string name="error_get_github_latest_release">Can\'t get latest GitHub release</string>
|
||||
<string name="error_corresponding_github_release_may_not_published">Corresponding GitHub release may have not been published yet</string>
|
||||
<string name="error_parse_version_info">Can\'t parse version information</string>
|
||||
<string name="text_empty_release_note">No release note</string>
|
||||
<string name="error_cannot_get_download_url">Can\'t get downloading URL</string>
|
||||
<string name="error_empty_github_release_assets">No GitHub release assets to download</string>
|
||||
<string name="text_github_backup_url_used">Backup URL has been used</string>
|
||||
<string name="error_unknown">Unknown error</string>
|
||||
<string name="text_downloading">Downloading</string>
|
||||
<string name="text_file_name">File name</string>
|
||||
<string name="text_version">Version</string>
|
||||
<string name="dialog_button_quit">Quit</string>
|
||||
<string name="dialog_button_retry">Retry</string>
|
||||
<string name="text_preparing" tools:ignore="TypographyEllipsis">Preparing...</string>
|
||||
<string name="error_download_interrupted">Download interrupted</string>
|
||||
<string name="text_download_cancelled">Download cancelled</string>
|
||||
<string name="text_manage_ignored_updates">Manage ignored updates</string>
|
||||
<string name="text_auto_check_for_updates_and_show_snackbar">Check for updates automatically and show a snackbar on homepage</string>
|
||||
<string name="text_auto_check_for_updates">Auto check for updates</string>
|
||||
<string name="text_last_updates_checked_time">Last checked: %s</string>
|
||||
<string name="error_failed_to_parse_version_info">Failed to parse version info</string>
|
||||
<string name="error_put_value_into_json">Can\'t put value %s into JSON</string>
|
||||
<string name="error_github_api_token_needed">You must provide a GitHub API Token</string>
|
||||
<string name="error_cannot_find_editor_view_from_child_view">Cann\'t find EditorView from child view: %s</string>
|
||||
<string name="error_unknown_type">Unknown type: %s</string>
|
||||
<string name="error_sdk_lower_than_o_not_supported_yet">Current function is not supported by Android SDK versions lower than 26 (Android 8.0) yet</string>
|
||||
<plurals name="air_error_short_description" key="air_error_short_description">
|
||||
<item quantity="one">The description must have at least %d character</item>
|
||||
<item quantity="other">The description must have at least %d characters</item>
|
||||
|
||||
@@ -77,12 +77,12 @@
|
||||
<string name="text_build_failed">打包失败</string>
|
||||
<string name="text_build_successfully">打包成功</string>
|
||||
<string name="text_cancel">取消</string>
|
||||
<string name="text_cancel_download">取消下载</string>
|
||||
<string name="dialog_button_cancel_download">取消下载</string>
|
||||
<string name="text_cannot_read_file">无法读取文件</string>
|
||||
<string name="text_change_working_dir">更改工作路径 (脚本文件夹)</string>
|
||||
<string name="text_checking_update">正在检查更新</string>
|
||||
<string name="text_checking_update" tools:ignore="TypographyEllipsis">正在检查更新...</string>
|
||||
<string name="text_check_for_updates">检查更新</string>
|
||||
<string name="text_check_update_error">检查更新失败</string>
|
||||
<string name="error_check_for_update">检查更新失败</string>
|
||||
<string name="text_class_or_package_name">类/包名</string>
|
||||
<string name="text_clear">清空</string>
|
||||
<string name="text_clear_file_selection">清空文件选择</string>
|
||||
@@ -102,6 +102,7 @@
|
||||
<string name="text_copy_command">复制指令</string>
|
||||
<string name="text_copy_debug_info">复制调试信息</string>
|
||||
<string name="text_copy_line">复制行</string>
|
||||
<string name="text_paste">粘贴</string>
|
||||
<string name="text_copy_to_clip">复制到剪贴板</string>
|
||||
<string name="text_copy_value">复制值</string>
|
||||
<string name="text_create_fail">创建失败</string>
|
||||
@@ -123,7 +124,7 @@
|
||||
<string name="text_delete_line">删除行</string>
|
||||
<string name="text_detail">详情</string>
|
||||
<string name="text_developer_details_under_development" tools:ignore="TypographyEllipsis">\"开发者详情\" 正在开发中...</string>
|
||||
<string name="text_dialog_button_go_to_settings">系统设置</string>
|
||||
<string name="dialog_button_go_to_settings">系统设置</string>
|
||||
<string name="text_directly_download">直接下载</string>
|
||||
<string name="text_directory">文件夹</string>
|
||||
<string name="text_display_over_other_app">显示在其他应用上层</string>
|
||||
@@ -193,7 +194,7 @@
|
||||
<string name="text_invalid_project">无效项目</string>
|
||||
<string name="text_in_progress">处理中</string>
|
||||
<string name="text_issue_report">问题反馈</string>
|
||||
<string name="text_is_latest_version">暂无更新版本</string>
|
||||
<string name="text_is_latest_version">已是最新版本</string>
|
||||
<string name="text_js_file">*.js 文件</string>
|
||||
<string name="text_jump">跳转</string>
|
||||
<string name="text_jump_to_end">跳转到文件末尾</string>
|
||||
@@ -365,7 +366,7 @@
|
||||
<string name="text_under_development_content">将在后续版本实现当前功能</string>
|
||||
<string name="text_under_development_title">开发中</string>
|
||||
<string name="text_undo">撤销</string>
|
||||
<string name="text_update">更新</string>
|
||||
<string name="text_updates">更新</string>
|
||||
<string name="text_usage_stats_permission">查看使用情况权限</string>
|
||||
<string name="text_usage_stats_permission_description">\"查看使用情况\" 权限可获取本设备过去使用应用的情况,从而使 \"获取当前应用\" (currentPackage) 结果更准确</string>
|
||||
<string name="text_username">用户名</string>
|
||||
@@ -406,6 +407,42 @@
|
||||
<string name="theme_color_yellow">黄色</string>
|
||||
<string name="theme_color_yellow_green">黄绿</string>
|
||||
<string name="text_refresh_explorer_may_needed">可能需要下拉刷新文件浏览器页面</string>
|
||||
<string name="error_set_both_icon_res_and_icon">不支持同时设置 iconRes 与 icon</string>
|
||||
<string name="error_only_one_child_for_scroll_view">ScrollView 只能拥有至多一个直接子控件</string>
|
||||
<string name="error_illegal_url_argument">URL 需以协议标识开头 (如 "https://" 等)</string>
|
||||
<string name="error_illegal_relative_url_argument_without_base">使用相对 URL 时必须指定 Base URL</string>
|
||||
<string name="dialog_button_ignore_current_update">忽略此版本</string>
|
||||
<string name="dialog_button_back">@string/text_back</string>
|
||||
<string name="dialog_button_update_now">立即更新</string>
|
||||
<string name="text_getting_release_notes" tools:ignore="TypographyEllipsis">正在获取版本信息...</string>
|
||||
<string name="error_cannot_connect_to_github">无法连接到 GitHub</string>
|
||||
<string name="error_invalid_github_repo">无效的 GitHub 仓库: %s</string>
|
||||
<string name="error_get_github_latest_release">无法获取最新的 GitHub 发行版</string>
|
||||
<string name="error_corresponding_github_release_may_not_published">对应的 GitHub 发行版可能还未发布</string>
|
||||
<string name="error_parse_version_info">无法解析版本信息</string>
|
||||
<string name="text_empty_release_note">无版本信息</string>
|
||||
<string name="error_cannot_get_download_url">无法获取下载链接</string>
|
||||
<string name="error_empty_github_release_assets">无可供下载的 GitHub 发行版资源</string>
|
||||
<string name="text_github_backup_url_used">备用 URL 已使用</string>
|
||||
<string name="error_unknown">未知错误</string>
|
||||
<string name="text_downloading">下载中</string>
|
||||
<string name="text_file_name">文件名</string>
|
||||
<string name="text_version">版本</string>
|
||||
<string name="dialog_button_quit">放弃</string>
|
||||
<string name="dialog_button_retry">重试</string>
|
||||
<string name="text_preparing" tools:ignore="TypographyEllipsis">准备中...</string>
|
||||
<string name="error_download_interrupted">下载中断</string>
|
||||
<string name="text_download_cancelled">下载已取消</string>
|
||||
<string name="text_manage_ignored_updates">管理已忽略更新</string>
|
||||
<string name="text_auto_check_for_updates_and_show_snackbar">自动检查更新并在首页下方显示通知条</string>
|
||||
<string name="text_auto_check_for_updates">自动检查更新</string>
|
||||
<string name="text_last_updates_checked_time">上次检查: %s</string>
|
||||
<string name="error_failed_to_parse_version_info">无法解析版本信息</string>
|
||||
<string name="error_put_value_into_json">无法将值 %s 存入 JSON</string>
|
||||
<string name="error_github_api_token_needed">需要提供 GitHub API 令牌</string>
|
||||
<string name="error_cannot_find_editor_view_from_child_view">无法在子控件 %s 中找到 EditorView</string>
|
||||
<string name="error_unknown_type">未知类型: %s</string>
|
||||
<string name="error_sdk_lower_than_o_not_supported_yet">当前功能暂不支持安卓 SDK 版本低于 26 (Android 8.0) 的系统</string>
|
||||
<plurals name="air_error_short_description" key="air_error_short_description" tools:ignore="UnusedQuantity">
|
||||
<item quantity="one">描述至少需要 %d 个字</item>
|
||||
<item quantity="other">描述至少需要 %d 个字</item>
|
||||
|
||||
@@ -36,6 +36,46 @@
|
||||
<color name="github_color_fg_muted">#57606A</color>
|
||||
<color name="tint_1st_developer_identifier">#2B7A85</color>
|
||||
<color name="tint_2nd_developer_identifier">#CC7A34</color>
|
||||
<color name="title_material_toolbar">#ffffff</color>
|
||||
|
||||
<color name="dialog_button_default">#03A9F4</color>
|
||||
<color name="dialog_button_caution">#FF3D00</color>
|
||||
<color name="dialog_button_warn">#F57C00</color>
|
||||
<color name="dialog_button_attraction">#7B1FA2</color>
|
||||
<color name="dialog_button_hint">#0DA798</color>
|
||||
<color name="dialog_button_reset">#A1887F</color>
|
||||
<color name="dialog_button_unavailable">#BDBDBD</color>
|
||||
<color name="dialog_button_finish">#009624</color>
|
||||
<color name="dialog_button_success">@color/dialog_button_finish</color>
|
||||
<color name="dialog_button_error">#003C8F</color>
|
||||
<color name="dialog_button_failure">@color/dialog_button_error</color>
|
||||
|
||||
<color name="dialog_progress_download_tint">#FF6F00</color>
|
||||
<color name="dialog_progress_download_bg_tint">#FFECB3</color>
|
||||
<color name="dialog_progress_download_act_btn">#C43E00</color>
|
||||
<color name="dialog_progress_files_tint">#F9A825</color>
|
||||
<color name="dialog_progress_files_bg_tint">#FFF59D</color>
|
||||
<color name="dialog_progress_files_act_btn">#C17900</color>
|
||||
<color name="dialog_progress_backup_tint">#455A64</color>
|
||||
<color name="dialog_progress_backup_bg_tint">#ECEFF1</color>
|
||||
<color name="dialog_progress_backup_act_btn">#1C313A</color>
|
||||
<color name="dialog_progress_restore_tint">#AB47BC</color>
|
||||
<color name="dialog_progress_restore_bg_tint">#F3E5F5</color>
|
||||
<color name="dialog_progress_restore_act_btn">#790E8B</color>
|
||||
<color name="dialog_progress_indeterminate_tint">#00897B</color>
|
||||
<color name="dialog_progress_indeterminate_bg_tint">#B2DFDB</color>
|
||||
<color name="dialog_progress_indeterminate_act_btn">#005B4F</color>
|
||||
<color name="dialog_progress_finish_tint">#00C853</color>
|
||||
<color name="dialog_progress_finish_bg_tint">#DCEDC8</color>
|
||||
<color name="dialog_progress_finish_act_btn">#009624</color>
|
||||
<color name="dialog_progress_success_tint">#00C853</color>
|
||||
<color name="dialog_progress_success_bg_tint">#DCEDC8</color>
|
||||
<color name="dialog_progress_success_act_btn">#009624</color>
|
||||
<color name="dialog_progress_error_tint">#1565C0</color>
|
||||
<color name="dialog_progress_error_bg_tint">#BBDEFB</color>
|
||||
<color name="dialog_progress_error_act_btn">#003C8F</color>
|
||||
<color name="dialog_progress_failure_tint">#1565C0</color>
|
||||
<color name="dialog_progress_failure_bg_tint">#BBDEFB</color>
|
||||
<color name="dialog_progress_failure_act_btn">#003C8F</color>
|
||||
|
||||
</resources>
|
||||
@@ -105,12 +105,12 @@
|
||||
<string name="text_build_failed">Build failed</string>
|
||||
<string name="text_build_successfully">Build succeeded</string>
|
||||
<string name="text_cancel">Cancel</string>
|
||||
<string name="text_cancel_download">Cancel downloading</string>
|
||||
<string name="dialog_button_cancel_download">Cancel</string>
|
||||
<string name="text_cannot_read_file">Can\'t read file</string>
|
||||
<string name="text_change_working_dir">Change working directory</string>
|
||||
<string name="text_checking_update">Checking for updates</string>
|
||||
<string name="text_checking_update" tools:ignore="TypographyEllipsis">Checking for updates...</string>
|
||||
<string name="text_check_for_updates">Check for updates</string>
|
||||
<string name="text_check_update_error">Check for updates failed</string>
|
||||
<string name="error_check_for_update">Checking for updates failed</string>
|
||||
<string name="text_class_or_package_name">Class / Package name</string>
|
||||
<string name="text_clear">Clear</string>
|
||||
<string name="text_clear_file_selection">Clear file selection</string>
|
||||
@@ -130,6 +130,7 @@
|
||||
<string name="text_copy_command">Copy cmd</string>
|
||||
<string name="text_copy_debug_info">Copy debugging log</string>
|
||||
<string name="text_copy_line">Copy line</string>
|
||||
<string name="text_paste">Paste</string>
|
||||
<string name="text_copy_to_clip">Copy to clipboard</string>
|
||||
<string name="text_copy_value">Copy value</string>
|
||||
<string name="text_create_fail">Create failed</string>
|
||||
@@ -151,7 +152,7 @@
|
||||
<string name="text_delete_line">Delete line</string>
|
||||
<string name="text_detail">Details</string>
|
||||
<string name="text_developer_details_under_development">Developer details is under development</string>
|
||||
<string name="text_dialog_button_go_to_settings">System Settings</string>
|
||||
<string name="dialog_button_go_to_settings">System Settings</string>
|
||||
<string name="text_directly_download">Download now</string>
|
||||
<string name="text_directory">Directory</string>
|
||||
<string name="text_display_over_other_app">Display over other apps</string>
|
||||
@@ -400,7 +401,7 @@
|
||||
<string name="text_under_development_content">The feature will be ready to use in the next few updates</string>
|
||||
<string name="text_under_development_title">Under development</string>
|
||||
<string name="text_undo">Undo</string>
|
||||
<string name="text_update">Update</string>
|
||||
<string name="text_updates">Updates</string>
|
||||
<string name="text_usage_stats_permission">Usage stats access</string>
|
||||
<string name="text_usage_stats_permission_description">Provides access to device usage history and statistics which results in currentPackage() a more accurate result</string>
|
||||
<string name="text_username">Username</string>
|
||||
@@ -421,6 +422,47 @@
|
||||
<string name="text_write_secure_settings_description">Secure system settings, containing system preferences that applications can read but are not allowed to write.\nThese are for preferences that the user must explicitly modify through the UI of a system app.\nWith secure system settings permission, normal applications can directly modify the secure settings (such as accessibility service).</string>
|
||||
<string name="text_write_system_settings">Write system settings</string>
|
||||
<string name="text_refresh_explorer_may_needed">An explorer page swipe-to-refresh may be needed</string>
|
||||
<string name="error_set_both_icon_res_and_icon">Can\'t set both iconRes and icon</string>
|
||||
<string name="error_only_one_child_for_scroll_view">ScrollView can host only one direct child</string>
|
||||
<string name="error_illegal_url_argument">URL must starts with a protocol like \"https://\" and so forth</string>
|
||||
<string name="error_illegal_relative_url_argument_without_base">Relative URL can\'t be used without base URL</string>
|
||||
<string name="dialog_button_ignore_current_update">Ignore</string>
|
||||
<string name="dialog_button_back">@string/text_back</string>
|
||||
<string name="dialog_button_update_now">Update</string>
|
||||
<string name="text_getting_release_notes" tools:ignore="TypographyEllipsis">Retrieving release notes...</string>
|
||||
<string name="error_cannot_connect_to_github">Can\'t connect to GitHub</string>
|
||||
<string name="error_invalid_github_repo">Invalid GitHub repository: %s</string>
|
||||
<string name="error_get_github_latest_release">Can\'t get latest GitHub release</string>
|
||||
<string name="error_corresponding_github_release_may_not_published">Corresponding GitHub release may have not been published yet</string>
|
||||
<string name="error_parse_version_info">Can\'t parse version information</string>
|
||||
<string name="text_empty_release_note">No release note</string>
|
||||
<string name="error_cannot_get_download_url">Can\'t get downloading URL</string>
|
||||
<string name="error_empty_github_release_assets">No GitHub release assets to download</string>
|
||||
<string name="text_github_backup_url_used">Backup URL has been used</string>
|
||||
<string name="error_unknown">Unknown error</string>
|
||||
<string name="text_downloading">Downloading</string>
|
||||
<string name="text_file_name">File name</string>
|
||||
<string name="text_version">Version</string>
|
||||
<string name="dialog_button_quit">Quit</string>
|
||||
<string name="dialog_button_retry">Retry</string>
|
||||
<string name="text_half_ellipsis" translatable="false" formatted="true">...</string>
|
||||
<string name="text_preparing" tools:ignore="TypographyEllipsis">Preparing...</string>
|
||||
<string name="error_download_interrupted">Download interrupted</string>
|
||||
<string name="text_download_cancelled">Download cancelled</string>
|
||||
<string name="format_dialog_progress_number_format_mega_bytes" translatable="false">%.2fMB/%.2fMB</string>
|
||||
<string name="format_dialog_progress_number_format_kilo_bytes" translatable="false">%.1fKB/%.1fKB</string>
|
||||
<string name="text_manage_ignored_updates">Manage ignored updates</string>
|
||||
<string name="text_auto_check_for_updates">Auto check for updates</string>
|
||||
<string name="text_last_updates_checked_time">Last checked: %s</string>
|
||||
<string name="key_app_property_version_name" translatable="false">VERSION_NAME</string>
|
||||
<string name="key_app_property_version_code" translatable="false">VERSION_BUILD</string>
|
||||
<string name="error_failed_to_parse_version_info">Failed to parse version info</string>
|
||||
<string name="error_put_value_into_json">Can\'t put value %s into JSON</string>
|
||||
<string name="error_github_api_token_needed">You must provide a GitHub API Token</string>
|
||||
<string name="text_auto_check_for_updates_and_show_snackbar">Check for updates automatically and show a snackbar on homepage</string>
|
||||
<string name="error_cannot_find_editor_view_from_child_view">Cann\'t find EditorView from child view: %s</string>
|
||||
<string name="error_unknown_type">Unknown type: %s</string>
|
||||
<string name="error_sdk_lower_than_o_not_supported_yet">Current function is not supported by Android SDK versions lower than 26 (Android 8.0) yet</string>
|
||||
<plurals name="air_error_short_description" key="air_error_short_description">
|
||||
<item quantity="one">The description must have at least %d character</item>
|
||||
<item quantity="other">The description must have at least %d characters</item>
|
||||
|
||||
@@ -79,4 +79,7 @@
|
||||
<style name="MtAppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.ActionBar">
|
||||
<item name="android:textColorPrimary">#212121</item>
|
||||
</style>
|
||||
|
||||
<style name="TextAppearance.Design.Snackbar.Message" parent="android:TextAppearance" />
|
||||
|
||||
</resources>
|
||||
@@ -41,7 +41,7 @@
|
||||
android:key="@string/key_root_mode"
|
||||
android:layout="@layout/preference_custom"
|
||||
android:dialogMessage="@string/text_root_mode_description"
|
||||
android:title="@string/text_root_mode_title"/>
|
||||
android:title="@string/text_root_mode_title" />
|
||||
|
||||
<org.autojs.autojs.ui.settings.SetHiddenFilesPreference
|
||||
android:defaultValue="@string/value_hidden_files_default"
|
||||
@@ -50,7 +50,7 @@
|
||||
android:key="@string/key_hidden_files"
|
||||
android:layout="@layout/preference_custom"
|
||||
android:dialogMessage="@string/text_hidden_files_description"
|
||||
android:title="@string/text_hidden_files_title"/>
|
||||
android:title="@string/text_hidden_files_title" />
|
||||
|
||||
</com.stardust.theme.preference.ThemeColorPreferenceCategory>
|
||||
|
||||
@@ -130,11 +130,28 @@
|
||||
|
||||
<com.stardust.theme.preference.ThemeColorPreferenceCategory
|
||||
android:layout="@layout/preference_category_custom"
|
||||
android:title="@string/text_about">
|
||||
android:title="@string/text_updates">
|
||||
|
||||
<org.autojs.autojs.ui.settings.CheckForUpdatesPreference
|
||||
android:layout="@layout/preference_custom"
|
||||
android:title="@string/text_check_for_updates" />
|
||||
|
||||
<com.stardust.theme.preference.ThemeColorSwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="@string/key_auto_check_for_updates"
|
||||
android:layout="@layout/preference_custom"
|
||||
android:title="@string/text_auto_check_for_updates"
|
||||
android:summary="@string/text_auto_check_for_updates_and_show_snackbar" />
|
||||
|
||||
<Preference
|
||||
android:layout="@layout/preference_custom"
|
||||
android:title="@string/text_check_for_updates" />
|
||||
android:title="@string/text_manage_ignored_updates" />
|
||||
|
||||
</com.stardust.theme.preference.ThemeColorPreferenceCategory>
|
||||
|
||||
<com.stardust.theme.preference.ThemeColorPreferenceCategory
|
||||
android:layout="@layout/preference_category_custom"
|
||||
android:title="@string/text_about">
|
||||
|
||||
<Preference
|
||||
android:layout="@layout/preference_custom"
|
||||
|
||||
@@ -1,30 +1,5 @@
|
||||
package com.stardust.autojs.core.accessibility;
|
||||
|
||||
import android.os.Looper;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
import com.stardust.autojs.BuildConfig;
|
||||
import com.stardust.autojs.annotation.ScriptInterface;
|
||||
import com.stardust.autojs.rhino.continuation.Continuation;
|
||||
import com.stardust.autojs.runtime.exception.ScriptInterruptedException;
|
||||
import com.stardust.automator.ActionArgument;
|
||||
import com.stardust.automator.UiGlobalSelector;
|
||||
import com.stardust.automator.UiObject;
|
||||
import com.stardust.automator.UiObjectCollection;
|
||||
import com.stardust.automator.filter.Filter;
|
||||
import com.stardust.concurrent.VolatileBox;
|
||||
import com.stardust.view.accessibility.AccessibilityNodeInfoAllocator;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static androidx.core.view.accessibility.AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS;
|
||||
import static androidx.core.view.accessibility.AccessibilityNodeInfoCompat.ACTION_ARGUMENT_COLUMN_INT;
|
||||
import static androidx.core.view.accessibility.AccessibilityNodeInfoCompat.ACTION_ARGUMENT_PROGRESS_VALUE;
|
||||
@@ -57,6 +32,31 @@ import static androidx.core.view.accessibility.AccessibilityNodeInfoCompat.Acces
|
||||
import static androidx.core.view.accessibility.AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_SET_PROGRESS;
|
||||
import static androidx.core.view.accessibility.AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_SHOW_ON_SCREEN;
|
||||
|
||||
import android.os.Looper;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.BuildConfig;
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.autojs.annotation.ScriptInterface;
|
||||
import com.stardust.autojs.runtime.exception.ScriptInterruptedException;
|
||||
import com.stardust.automator.ActionArgument;
|
||||
import com.stardust.automator.UiGlobalSelector;
|
||||
import com.stardust.automator.UiObject;
|
||||
import com.stardust.automator.UiObjectCollection;
|
||||
import com.stardust.automator.filter.Filter;
|
||||
import com.stardust.concurrent.VolatileBox;
|
||||
import com.stardust.view.accessibility.AccessibilityNodeInfoAllocator;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/3/9.
|
||||
*/
|
||||
@@ -168,8 +168,7 @@ public class UiSelector extends UiGlobalSelector {
|
||||
@NonNull
|
||||
public UiObjectCollection untilFind() {
|
||||
if (isUiThread()) {
|
||||
// TODO: 2018/11/1 配置字符串
|
||||
throw new IllegalThreadStateException("不能在ui线程执行阻塞操作, 请在子线程或子脚本执行untilFind()");
|
||||
throw new IllegalThreadStateException(GlobalAppContext.getString(R.string.error_function_called_in_ui_thread, "untilFind"));
|
||||
}
|
||||
UiObjectCollection uiObjectCollection = find();
|
||||
while (uiObjectCollection.empty()) {
|
||||
@@ -189,8 +188,7 @@ public class UiSelector extends UiGlobalSelector {
|
||||
@ScriptInterface
|
||||
public UiObject findOne(long timeout) {
|
||||
if (isUiThread()) {
|
||||
// TODO: 2018/11/1 配置字符串
|
||||
throw new IllegalThreadStateException("不能在ui线程执行阻塞操作, 请在子线程或子脚本执行findOne()");
|
||||
throw new IllegalThreadStateException(GlobalAppContext.getString(R.string.error_function_called_in_ui_thread, "findOne"));
|
||||
}
|
||||
UiObjectCollection uiObjectCollection = find(1);
|
||||
long start = SystemClock.uptimeMillis();
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.stardust.autojs.core.console;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.util.UiHandler;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
@@ -49,7 +51,7 @@ public class GlobalConsole extends ConsoleImpl {
|
||||
case android.util.Log.ASSERT:
|
||||
return Level.FATAL;
|
||||
}
|
||||
throw new IllegalArgumentException("invalid level = " + level);
|
||||
throw new IllegalArgumentException(GlobalAppContext.getString(R.string.error_illegal_argument, "level", level));
|
||||
}
|
||||
|
||||
private String getLevelChar(int level) {
|
||||
|
||||
@@ -2,6 +2,9 @@ package com.stardust.autojs.core.database;
|
||||
|
||||
import android.database.Cursor;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.R;
|
||||
|
||||
public class CursorHelper {
|
||||
|
||||
|
||||
@@ -12,7 +15,8 @@ public class CursorHelper {
|
||||
case Cursor.FIELD_TYPE_INTEGER -> cursor.getInt(column);
|
||||
case Cursor.FIELD_TYPE_NULL -> null;
|
||||
case Cursor.FIELD_TYPE_BLOB -> cursor.getBlob(column);
|
||||
default -> throw new IllegalArgumentException("unknown type");
|
||||
default -> throw new IllegalArgumentException(GlobalAppContext
|
||||
.getString(R.string.error_illegal_argument, "column", column));
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package com.stardust.autojs.core.eventloop;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.autojs.core.looper.Timer;
|
||||
import com.stardust.autojs.runtime.ScriptBridges;
|
||||
import com.stardust.autojs.runtime.exception.ScriptException;
|
||||
@@ -40,7 +42,8 @@ public class EventEmitter {
|
||||
|
||||
private void ensureListenersNotAtLimit() {
|
||||
if (mMaxListeners != 0 && mListenerWrappers.size() >= mMaxListeners) {
|
||||
throw new ScriptException(new TooManyListenersException("max = " + mMaxListeners));
|
||||
throw new ScriptException(new TooManyListenersException(GlobalAppContext
|
||||
.getString(R.string.error_max_listeners_exceeded, mMaxListeners)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import android.media.Image;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.autojs.core.opencv.Mat;
|
||||
import com.stardust.autojs.core.opencv.OpenCVHelper;
|
||||
import com.stardust.pio.UncheckedIOException;
|
||||
@@ -85,7 +87,7 @@ public class ImageWrapper implements Recyclable {
|
||||
mHeight = bitmap.getHeight();
|
||||
} else {
|
||||
if (mat == null) {
|
||||
throw new Error("Both bitmap and mat are null");
|
||||
throw new Error(GlobalAppContext.getString(R.string.error_both_bitmap_and_mat_are_null));
|
||||
}
|
||||
mWidth = mat.cols();
|
||||
mHeight = mat.rows();
|
||||
@@ -204,7 +206,7 @@ public class ImageWrapper implements Recyclable {
|
||||
|
||||
public void ensureNotRecycled() {
|
||||
if (isRecycled()) {
|
||||
throw new IllegalStateException("Image has been recycled");
|
||||
throw new IllegalStateException(GlobalAppContext.getString(R.string.error_image_has_been_recycled));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import androidx.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.autojs.core.record.inputevent.EventFormatException;
|
||||
import com.stardust.autojs.core.util.Shell;
|
||||
|
||||
@@ -91,7 +92,9 @@ public class InputEventObserver {
|
||||
|
||||
public void observe() {
|
||||
if (mShell != null)
|
||||
throw new IllegalStateException("observe() should be called only once");
|
||||
throw new IllegalStateException(mContext
|
||||
.getString(R.string.error_function_called_more_than_once,
|
||||
"InputEventObserver.observe"));
|
||||
mShell = new Shell(mContext, true);
|
||||
mShell.setCallback(new Shell.SimpleCallback() {
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.stardust.autojs.core.internal;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.R;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/7/19.
|
||||
*/
|
||||
@@ -18,7 +21,8 @@ public class Functions {
|
||||
} else if (func instanceof Func4) {
|
||||
return ((Func4) func).call(args[0], args[1], args[2], args[3]);
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown func: " + func);
|
||||
throw new IllegalArgumentException(GlobalAppContext
|
||||
.getString(R.string.error_illegal_argument, "func", func));
|
||||
}
|
||||
|
||||
public interface Func {
|
||||
|
||||
@@ -5,6 +5,8 @@ import android.os.Looper;
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.autojs.engine.RhinoJavaScriptEngine;
|
||||
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||
import com.stardust.autojs.runtime.exception.ScriptInterruptedException;
|
||||
@@ -88,7 +90,7 @@ public class TimerThread extends ThreadCompat {
|
||||
|
||||
public Timer getTimer() {
|
||||
if (mTimer == null) {
|
||||
throw new IllegalStateException("thread is not alive");
|
||||
throw new IllegalStateException(GlobalAppContext.getString(R.string.error_thread_is_not_alive));
|
||||
}
|
||||
return mTimer;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.UiThread;
|
||||
@@ -39,6 +40,7 @@ import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.afollestad.materialdialogs.internal.MDButton;
|
||||
import com.stardust.app.DialogUtils;
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.autojs.core.eventloop.EventEmitter;
|
||||
import com.stardust.util.UiHandler;
|
||||
|
||||
@@ -78,7 +80,7 @@ public class JsDialog {
|
||||
Context context = mDialog.getContext();
|
||||
if (!DialogUtils.isActivityContext(context)) {
|
||||
Window window = mDialog.getWindow();
|
||||
if (window != null){
|
||||
if (window != null) {
|
||||
int type;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
||||
@@ -95,7 +97,8 @@ public class JsDialog {
|
||||
case "positive" -> DialogAction.POSITIVE;
|
||||
case "negative" -> DialogAction.NEGATIVE;
|
||||
case "neutral" -> DialogAction.NEUTRAL;
|
||||
default -> throw new IllegalArgumentException("unknown action " + action);
|
||||
default -> throw new IllegalArgumentException(getContext()
|
||||
.getString(R.string.error_illegal_argument, "action", action));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -325,7 +325,7 @@ public class DynamicLayoutInflater {
|
||||
} else if (attr.length == 2) {
|
||||
applyAttribute(context, setter, view, attr[0], attr[1], entry.getValue(), parent, attrs);
|
||||
} else {
|
||||
throw new InflateException("illegal attr name: " + entry.getKey());
|
||||
throw new InflateException("Illegal attr name: " + entry.getKey());
|
||||
}
|
||||
}
|
||||
setter.applyPendingAttributes(view, parent);
|
||||
|
||||
+9
-5
@@ -4,6 +4,8 @@ import android.view.InflateException;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.autojs.core.ui.inflater.ResourceParser;
|
||||
import com.stardust.autojs.core.ui.inflater.util.Colors;
|
||||
import com.stardust.autojs.core.ui.inflater.util.Dimensions;
|
||||
@@ -44,7 +46,7 @@ public class ImageViewInflater<V extends ImageView> extends BaseViewInflater<V>
|
||||
view.setMaxWidth(Dimensions.parseToIntPixel(value, view));
|
||||
break;
|
||||
case "path":
|
||||
getDrawables().setupWithImage(view, wrapAsPath(value));
|
||||
getDrawables().setupWithImage(view, wrapAsPath(value));
|
||||
break;
|
||||
case "scaleType":
|
||||
view.setScaleType(parseScaleType(value));
|
||||
@@ -59,13 +61,14 @@ public class ImageViewInflater<V extends ImageView> extends BaseViewInflater<V>
|
||||
view.setImageTintMode(TINT_MODES.get(value));
|
||||
break;
|
||||
case "url":
|
||||
getDrawables().setupWithImage(view, wrapAsUrl(value));
|
||||
getDrawables().setupWithImage(view, wrapAsUrl(value));
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private String wrapAsPath(String value) {
|
||||
if (!value.startsWith("file://")) {
|
||||
return "file://" + value;
|
||||
@@ -80,8 +83,8 @@ public class ImageViewInflater<V extends ImageView> extends BaseViewInflater<V>
|
||||
return value;
|
||||
}
|
||||
|
||||
private ImageView.ScaleType parseScaleType(String value) {
|
||||
switch (value.toLowerCase()) {
|
||||
private ImageView.ScaleType parseScaleType(String scaleType) {
|
||||
switch (scaleType.toLowerCase()) {
|
||||
case "center":
|
||||
return ImageView.ScaleType.CENTER;
|
||||
case "center_crop":
|
||||
@@ -99,6 +102,7 @@ public class ImageViewInflater<V extends ImageView> extends BaseViewInflater<V>
|
||||
case "matrix":
|
||||
return ImageView.ScaleType.MATRIX;
|
||||
}
|
||||
throw new InflateException("unknown scale type: " + value);
|
||||
throw new InflateException(GlobalAppContext
|
||||
.getString(R.string.error_illegal_argument, "scaleType", scaleType));
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import android.view.InflateException;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.stardust.autojs.R;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -56,7 +58,7 @@ public class Dimensions {
|
||||
}
|
||||
Matcher m = DIMENSION_PATTERN.matcher(dimension);
|
||||
if (!m.matches()) {
|
||||
throw new InflateException("dimension cannot be resolved: " + dimension);
|
||||
throw new InflateException(context.getString(R.string.error_illegal_argument, "dimension", dimension));
|
||||
}
|
||||
int unit = m.groupCount() == 2 ? UNITS.get(m.group(2), TypedValue.COMPLEX_UNIT_DIP) : TypedValue.COMPLEX_UNIT_DIP;
|
||||
float value = Integer.parseInt(m.group(1));
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ValueMapper<V> {
|
||||
public V get(String key) {
|
||||
V v = mHashMap.get(key);
|
||||
if (v == null) {
|
||||
throw new InflateException(String.format("unknown value for %s: %s", mAttrName, key));
|
||||
throw new InflateException(String.format("Unknown value for %s: %s", mAttrName, key));
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
package com.stardust.autojs.core.ui.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
import android.widget.Button;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
|
||||
import com.google.android.material.snackbar.BaseTransientBottomBar;
|
||||
import com.stardust.autojs.R;
|
||||
|
||||
/**
|
||||
* Created by SuperMonster003 on May 30, 2022.
|
||||
*/
|
||||
|
||||
public class CustomSnackbar extends BaseTransientBottomBar<CustomSnackbar> {
|
||||
|
||||
private final View mContent;
|
||||
|
||||
protected CustomSnackbar(@NonNull Context context, @NonNull ViewGroup parent, @NonNull View content, @NonNull com.google.android.material.snackbar.ContentViewCallback contentViewCallback) {
|
||||
super(context, parent, content, contentViewCallback);
|
||||
mContent = content;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static CustomSnackbar make(@NonNull View view, @NonNull CharSequence text, @Duration int duration) {
|
||||
return makeInternal(/* context= */ null, view, text, duration);
|
||||
}
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private static CustomSnackbar makeInternal(@Nullable Context context, @NonNull View view, @NonNull CharSequence text, @Duration int duration) {
|
||||
final ViewGroup parent = findSuitableParent(view);
|
||||
if (parent == null) {
|
||||
throw new IllegalArgumentException("No suitable parent found from the given view. Please provide a valid view.");
|
||||
}
|
||||
|
||||
if (context == null) {
|
||||
context = parent.getContext();
|
||||
}
|
||||
|
||||
final LayoutInflater inflater = LayoutInflater.from(context);
|
||||
final CustomSnackbarContentLayout content = (CustomSnackbarContentLayout) inflater.inflate(R.layout.snackbar_custom, parent, false);
|
||||
final CustomSnackbar snackbar = new CustomSnackbar(context, parent, content, content);
|
||||
|
||||
snackbar.setText(text);
|
||||
snackbar.setDuration(duration);
|
||||
|
||||
return snackbar;
|
||||
}
|
||||
|
||||
// @Copied by SuperMonster003 on May 30, 2022.
|
||||
// ! From: com.stardust.autojs.core.ui.widget.CustomSnackbar.findSuitableParent
|
||||
@Nullable
|
||||
private static ViewGroup findSuitableParent(View view) {
|
||||
ViewGroup fallback = null;
|
||||
do {
|
||||
if (view instanceof CoordinatorLayout) {
|
||||
// We've found a CoordinatorLayout, use it
|
||||
return (ViewGroup) view;
|
||||
} else if (view instanceof FrameLayout) {
|
||||
if (view.getId() == android.R.id.content) {
|
||||
// If we've hit the decor content view, then we didn't find a CoL in the
|
||||
// hierarchy, so use it.
|
||||
return (ViewGroup) view;
|
||||
} else {
|
||||
// It's not the content view but we'll use it as our fallback
|
||||
fallback = (ViewGroup) view;
|
||||
}
|
||||
}
|
||||
|
||||
if (view != null) {
|
||||
// Else, we will loop and crawl up the view hierarchy and try to find a parent
|
||||
final ViewParent parent = view.getParent();
|
||||
view = parent instanceof View ? (View) parent : null;
|
||||
}
|
||||
} while (view != null);
|
||||
|
||||
// If we reach here then we didn't find a CoL or a suitable content view so we'll fallback
|
||||
return fallback;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public CustomSnackbar setText(@NonNull CharSequence message) {
|
||||
((CustomSnackbarContentLayout) mContent).getCustomTextView().setText(message);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CustomSnackbar setActionOne(@StringRes int resId, View.OnClickListener listener) {
|
||||
return setActionOne(getContext().getText(resId), listener);
|
||||
}
|
||||
|
||||
public CustomSnackbar setActionTwo(@StringRes int resId, View.OnClickListener listener) {
|
||||
return setActionTwo(getContext().getText(resId), listener);
|
||||
}
|
||||
|
||||
public CustomSnackbar setActionOne(@Nullable CharSequence text, @Nullable final View.OnClickListener listener) {
|
||||
return setAction(text, listener, ((CustomSnackbarContentLayout) mContent).getActionOneView());
|
||||
}
|
||||
|
||||
public CustomSnackbar setActionTwo(@Nullable CharSequence text, @Nullable final View.OnClickListener listener) {
|
||||
return setAction(text, listener, ((CustomSnackbarContentLayout) mContent).getActionTwoView());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public CustomSnackbar setAction(@StringRes int resId, View.OnClickListener listener, Button view) {
|
||||
return setAction(getContext().getText(resId), listener, view);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public CustomSnackbar setAction(@Nullable CharSequence text, @Nullable final View.OnClickListener listener, Button view) {
|
||||
if (TextUtils.isEmpty(text)) {
|
||||
view.setVisibility(View.GONE);
|
||||
} else {
|
||||
view.setVisibility(View.VISIBLE);
|
||||
view.setText(text);
|
||||
}
|
||||
view.setOnClickListener(v -> {
|
||||
if (listener != null) {
|
||||
listener.onClick(v);
|
||||
}
|
||||
// Now dismiss the Snackbar
|
||||
dispatchDismiss(BaseCallback.DISMISS_EVENT_ACTION);
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package com.stardust.autojs.core.ui.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.android.material.snackbar.ContentViewCallback;
|
||||
import com.stardust.autojs.R;
|
||||
|
||||
/**
|
||||
* Created by SuperMonster003 on May 30, 2022.
|
||||
*/
|
||||
|
||||
public class CustomSnackbarContentLayout extends LinearLayout implements ContentViewCallback {
|
||||
|
||||
public CustomSnackbarContentLayout(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public CustomSnackbarContentLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public Button getActionOneView() {
|
||||
return findViewById(R.id.snackbar_action_one);
|
||||
}
|
||||
|
||||
public Button getActionTwoView() {
|
||||
return findViewById(R.id.snackbar_action_two);
|
||||
}
|
||||
|
||||
public TextView getCustomTextView() {
|
||||
return findViewById(R.id.snackbar_text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void animateContentIn(int delay, int duration) {
|
||||
TextView mTextView = getCustomTextView();
|
||||
Button mActionOneView = getActionOneView();
|
||||
Button mActionTwoView = getActionTwoView();
|
||||
|
||||
mTextView.setAlpha(0f);
|
||||
mTextView.animate().alpha(1f).setDuration(duration).setStartDelay(delay).start();
|
||||
|
||||
if (mActionOneView.getVisibility() == VISIBLE) {
|
||||
mActionOneView.setAlpha(0f);
|
||||
mActionOneView.animate().alpha(1f).setDuration(duration).setStartDelay(delay).start();
|
||||
}
|
||||
|
||||
if (mActionTwoView.getVisibility() == VISIBLE) {
|
||||
mActionTwoView.setAlpha(0f);
|
||||
mActionTwoView.animate().alpha(1f).setDuration(duration).setStartDelay(delay).start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void animateContentOut(int delay, int duration) {
|
||||
TextView mTextView = getCustomTextView();
|
||||
Button mActionOneView = getActionOneView();
|
||||
Button mActionTwoView = getActionTwoView();
|
||||
|
||||
mTextView.setAlpha(1f);
|
||||
mTextView.animate().alpha(0f).setDuration(duration).setStartDelay(delay).start();
|
||||
|
||||
if (mActionOneView.getVisibility() == VISIBLE) {
|
||||
mActionOneView.setAlpha(1f);
|
||||
mActionOneView.animate().alpha(0f).setDuration(duration).setStartDelay(delay).start();
|
||||
}
|
||||
|
||||
if (mActionTwoView.getVisibility() == VISIBLE) {
|
||||
mActionTwoView.setAlpha(1f);
|
||||
mActionTwoView.animate().alpha(0f).setDuration(duration).setStartDelay(delay).start();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package com.stardust.autojs.core.util;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.autojs.runtime.api.AbstractShell;
|
||||
import com.stardust.autojs.util.ProcessUtils;
|
||||
import com.stardust.pio.UncheckedIOException;
|
||||
@@ -178,7 +180,7 @@ public class ProcessShell extends AbstractShell {
|
||||
public static Result execCommand(String[] commands, boolean isRoot) {
|
||||
Result commandResult = new Result();
|
||||
if (commands == null || commands.length == 0)
|
||||
throw new IllegalArgumentException("command is empty");
|
||||
throw new IllegalArgumentException(GlobalAppContext.getString(R.string.error_empty_shell_command));
|
||||
Process process = null;
|
||||
DataOutputStream os = null;
|
||||
try {
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.stardust.autojs.engine;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||
import com.stardust.autojs.script.JavaScriptSource;
|
||||
import com.stardust.autojs.script.ScriptSource;
|
||||
@@ -29,7 +31,7 @@ public abstract class JavaScriptEngine extends ScriptEngine.AbstractScriptEngine
|
||||
|
||||
public void setRuntime(ScriptRuntime runtime) {
|
||||
if (mRuntime != null) {
|
||||
throw new IllegalStateException("a runtime has been set");
|
||||
throw new IllegalStateException(GlobalAppContext.getString(R.string.error_a_runtime_has_been_set));
|
||||
}
|
||||
mRuntime = runtime;
|
||||
mRuntime.engines.setCurrentEngine(this);
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.stardust.autojs.engine;
|
||||
|
||||
import androidx.annotation.CallSuper;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.autojs.execution.ScriptExecution;
|
||||
import com.stardust.autojs.script.ScriptSource;
|
||||
|
||||
@@ -105,8 +107,10 @@ public interface ScriptEngine<S extends ScriptSource> {
|
||||
}
|
||||
|
||||
public void setOnDestroyListener(OnDestroyListener onDestroyListener) {
|
||||
if (mOnDestroyListener != null)
|
||||
throw new SecurityException("setOnDestroyListener can be called only once");
|
||||
if (mOnDestroyListener != null) {
|
||||
throw new SecurityException(GlobalAppContext.getString(R.string.error_function_called_more_than_once,
|
||||
"AbstractScriptEngine.setOnDestroyListener"));
|
||||
}
|
||||
mOnDestroyListener = onDestroyListener;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.stardust.autojs.engine;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.autojs.script.ScriptSource;
|
||||
import com.stardust.util.Supplier;
|
||||
|
||||
@@ -64,16 +66,18 @@ public class ScriptEngineFactory {
|
||||
@NonNull
|
||||
public ScriptEngine createEngineByNameOrThrow(String name) {
|
||||
ScriptEngine engine = createEngine(name);
|
||||
if (engine == null)
|
||||
throw new EngineNotFoundException("name: " + name);
|
||||
if (engine == null) {
|
||||
throw new EngineNotFoundException(GlobalAppContext.getString(R.string.error_illegal_argument, "name", name));
|
||||
}
|
||||
return engine;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ScriptEngine createEngineOfSourceOrThrow(ScriptSource source) {
|
||||
ScriptEngine engine = createEngineOfSource(source);
|
||||
if (engine == null)
|
||||
throw new EngineNotFoundException("source: " + source);
|
||||
if (engine == null) {
|
||||
throw new EngineNotFoundException(GlobalAppContext.getString(R.string.error_illegal_argument, "source", source));
|
||||
}
|
||||
return engine;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.stardust.autojs.rhino;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.dx.command.dexer.Main;
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.pio.PFiles;
|
||||
import com.stardust.util.MD5;
|
||||
|
||||
@@ -94,7 +96,7 @@ public class AndroidClassLoader extends ClassLoader implements GeneratedClassLoa
|
||||
public void loadJar(File jar) throws IOException {
|
||||
Log.d(LOG_TAG, "loadJar: jar = " + jar);
|
||||
if (!jar.exists() || !jar.canRead()) {
|
||||
throw new FileNotFoundException("File does not exist or readable: " + jar.getPath());
|
||||
throw new FileNotFoundException(GlobalAppContext.getString(R.string.file_not_exist_or_readable, jar.getPath()));
|
||||
}
|
||||
File dexFile = new File(mCacheDir, generateDexFileName(jar));
|
||||
if (dexFile.exists()) {
|
||||
|
||||
@@ -36,7 +36,7 @@ public class ScriptBridges {
|
||||
|
||||
private void checkBridges() {
|
||||
if (mBridges == null)
|
||||
throw new IllegalStateException("no bridges set");
|
||||
throw new IllegalStateException("No bridges have been set");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -227,8 +227,9 @@ public class ScriptRuntime {
|
||||
}
|
||||
|
||||
public void init() {
|
||||
if (loopers != null)
|
||||
throw new IllegalStateException("already initialized");
|
||||
if (loopers != null) {
|
||||
throw new IllegalStateException("Already initialized");
|
||||
}
|
||||
threads = new Threads(this);
|
||||
timers = new Timers(this);
|
||||
loopers = new Loopers(this);
|
||||
@@ -243,7 +244,7 @@ public class ScriptRuntime {
|
||||
|
||||
public void setTopLevelScope(TopLevelScope topLevelScope) {
|
||||
if (mTopLevelScope != null) {
|
||||
throw new IllegalStateException("top level has already exists");
|
||||
throw new IllegalStateException("Top level has already exists");
|
||||
}
|
||||
mTopLevelScope = topLevelScope;
|
||||
}
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ public class AccessibilityConfig {
|
||||
|
||||
public void addWhiteList(String packageName) {
|
||||
if (mSealed)
|
||||
throw new IllegalStateException("sealed");
|
||||
throw new IllegalStateException("Sealed");
|
||||
mWhiteList.add(packageName);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,11 +6,13 @@ import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.autojs.annotation.ScriptInterface;
|
||||
import com.stardust.util.IntentUtil;
|
||||
|
||||
@@ -110,15 +112,21 @@ public class AppUtils {
|
||||
|
||||
@ScriptInterface
|
||||
public void viewFile(String path) {
|
||||
if (path == null)
|
||||
throw new NullPointerException("path == null");
|
||||
if (path == null) {
|
||||
throw new NullPointerException(mContext
|
||||
.getString(R.string.error_method_called_with_null_argument,
|
||||
"AppUtils.viewFile", "path"));
|
||||
}
|
||||
IntentUtil.viewFile(mContext, path, mFileProviderAuthority);
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
public void editFile(String path) {
|
||||
if (path == null)
|
||||
throw new NullPointerException("path == null");
|
||||
if (path == null) {
|
||||
throw new NullPointerException(mContext
|
||||
.getString(R.string.error_method_called_with_null_argument,
|
||||
"AppUtils.editFile", "path"));
|
||||
}
|
||||
IntentUtil.editFile(mContext, path, mFileProviderAuthority);
|
||||
}
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ public class Device {
|
||||
public boolean isCharging() {
|
||||
Intent intent = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||
if (intent == null) {
|
||||
throw new ScriptException("Cannot retrieve the battery state");
|
||||
throw new ScriptException(mContext.getString(R.string.error_cannot_retrieve_battery_state));
|
||||
}
|
||||
int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
|
||||
return plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB;
|
||||
@@ -310,7 +310,7 @@ public class Device {
|
||||
private <T> T getSystemService(String service) {
|
||||
Object systemService = mContext.getSystemService(service);
|
||||
if (systemService == null) {
|
||||
throw new RuntimeException("should never happen..." + service);
|
||||
throw new RuntimeException("Should never happen... " + service);
|
||||
}
|
||||
return (T) systemService;
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ public class Events extends EventEmitter implements OnKeyListener, TouchObserver
|
||||
mScriptRuntime.ensureAccessibilityServiceEnabled();
|
||||
AccessibilityService service = mAccessibilityBridge.getService();
|
||||
if (service == null)
|
||||
throw new ScriptException("AccessibilityService = null");
|
||||
throw new ScriptException(mContext.getString(R.string.error_no_accessibility_service));
|
||||
return service;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,10 @@ import android.util.Base64;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.autojs.annotation.ScriptVariable;
|
||||
import com.stardust.autojs.core.image.ColorFinder;
|
||||
import com.stardust.autojs.core.image.ImageWrapper;
|
||||
@@ -99,7 +103,7 @@ public class Images {
|
||||
|
||||
public synchronized ImageWrapper captureScreen() {
|
||||
if (mScreenCapturer == null) {
|
||||
throw new SecurityException("No screen capture permission");
|
||||
throw new SecurityException(mContext.getString(R.string.error_no_screen_capture_permission));
|
||||
}
|
||||
Image capture = mScreenCapturer.capture();
|
||||
if (capture == mPreCapture && mPreCaptureImage != null) {
|
||||
@@ -123,15 +127,12 @@ public class Images {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ImageWrapper copy(ImageWrapper image) {
|
||||
public ImageWrapper copy(@NonNull ImageWrapper image) {
|
||||
return image.clone();
|
||||
}
|
||||
|
||||
public boolean save(ImageWrapper image, String path, String format, int quality) throws IOException {
|
||||
public boolean save(@NonNull ImageWrapper image, String path, String format, int quality) throws IOException {
|
||||
Bitmap.CompressFormat compressFormat = parseImageFormat(format);
|
||||
if (compressFormat == null) {
|
||||
throw new IllegalArgumentException("unknown format " + format);
|
||||
}
|
||||
Bitmap bitmap = image.getBitmap();
|
||||
FileOutputStream outputStream = new FileOutputStream(mScriptRuntime.files.path(path));
|
||||
return bitmap.compress(compressFormat, quality, outputStream);
|
||||
@@ -139,14 +140,17 @@ public class Images {
|
||||
|
||||
public static int pixel(ImageWrapper image, int x, int y) {
|
||||
if (image == null) {
|
||||
throw new NullPointerException("image = null");
|
||||
throw new NullPointerException(GlobalAppContext
|
||||
.getString(R.string.error_method_called_with_null_argument, "Images.pixel", "image"));
|
||||
}
|
||||
return image.pixel(x, y);
|
||||
}
|
||||
|
||||
public static ImageWrapper concat(ImageWrapper img1, ImageWrapper img2, int direction) {
|
||||
if (!Arrays.asList(Gravity.START, Gravity.END, Gravity.TOP, Gravity.BOTTOM).contains(direction)) {
|
||||
throw new IllegalArgumentException("unknown direction " + direction);
|
||||
throw new IllegalArgumentException(GlobalAppContext
|
||||
.getString(R.string.error_illegal_argument,
|
||||
"direction", direction));
|
||||
}
|
||||
int width;
|
||||
int height;
|
||||
@@ -175,13 +179,13 @@ public class Images {
|
||||
return ImageWrapper.ofBitmap(bitmap);
|
||||
}
|
||||
|
||||
public ImageWrapper rotate(ImageWrapper img, float x, float y, float degree) {
|
||||
public ImageWrapper rotate(@NonNull ImageWrapper img, float x, float y, float degree) {
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postRotate(degree, x, y);
|
||||
return ImageWrapper.ofBitmap(Bitmap.createBitmap(img.getBitmap(), 0, 0, img.getWidth(), img.getHeight(), matrix, true));
|
||||
}
|
||||
|
||||
public ImageWrapper clip(ImageWrapper img, int x, int y, int w, int h) {
|
||||
public ImageWrapper clip(@NonNull ImageWrapper img, int x, int y, int w, int h) {
|
||||
return ImageWrapper.ofBitmap(Bitmap.createBitmap(img.getBitmap(), x, y, w, h));
|
||||
}
|
||||
|
||||
@@ -199,11 +203,8 @@ public class Images {
|
||||
return Base64.encodeToString(toBytes(wrapper, format, quality), Base64.NO_WRAP);
|
||||
}
|
||||
|
||||
public byte[] toBytes(ImageWrapper wrapper, String format, int quality) {
|
||||
public byte[] toBytes(@NonNull ImageWrapper wrapper, String format, int quality) {
|
||||
Bitmap.CompressFormat compressFormat = parseImageFormat(format);
|
||||
if (compressFormat == null) {
|
||||
throw new IllegalArgumentException("Unknown format " + format);
|
||||
}
|
||||
Bitmap bitmap = wrapper.getBitmap();
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
bitmap.compress(compressFormat, quality, outputStream);
|
||||
@@ -219,7 +220,8 @@ public class Images {
|
||||
case "png" -> Bitmap.CompressFormat.PNG;
|
||||
case "jpeg", "jpg" -> Bitmap.CompressFormat.JPEG;
|
||||
case "webp" -> Bitmap.CompressFormat.WEBP;
|
||||
default -> null;
|
||||
default -> throw new IllegalArgumentException(GlobalAppContext
|
||||
.getString(R.string.error_illegal_argument, "format", format));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -237,7 +239,7 @@ public class Images {
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveBitmap(Bitmap bitmap, String path) {
|
||||
public static void saveBitmap(@NonNull Bitmap bitmap, String path) {
|
||||
try {
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream(path));
|
||||
} catch (FileNotFoundException e) {
|
||||
@@ -279,10 +281,14 @@ public class Images {
|
||||
public Point findImage(ImageWrapper image, ImageWrapper template, float weakThreshold, float threshold, Rect rect, int maxLevel) {
|
||||
initOpenCvIfNeeded();
|
||||
if (image == null) {
|
||||
throw new NullPointerException("Param image is null");
|
||||
throw new NullPointerException(GlobalAppContext
|
||||
.getString(R.string.error_method_called_with_null_argument,
|
||||
"Images.findImage", "image"));
|
||||
}
|
||||
if (template == null) {
|
||||
throw new NullPointerException("Param template is null");
|
||||
throw new NullPointerException(GlobalAppContext
|
||||
.getString(R.string.error_method_called_with_null_argument,
|
||||
"Images.findImage", "template"));
|
||||
}
|
||||
Mat src = image.getMat();
|
||||
if (rect != null) {
|
||||
@@ -307,10 +313,14 @@ public class Images {
|
||||
public List<TemplateMatching.Match> matchTemplate(ImageWrapper image, ImageWrapper template, float weakThreshold, float threshold, Rect rect, int maxLevel, int limit) {
|
||||
initOpenCvIfNeeded();
|
||||
if (image == null) {
|
||||
throw new NullPointerException("Param image is null");
|
||||
throw new NullPointerException(GlobalAppContext
|
||||
.getString(R.string.error_method_called_with_null_argument,
|
||||
"Images.matchTemplate", "image"));
|
||||
}
|
||||
if (template == null) {
|
||||
throw new NullPointerException("Param template is null");
|
||||
throw new NullPointerException(GlobalAppContext
|
||||
.getString(R.string.error_method_called_with_null_argument,
|
||||
"Images.matchTemplate", "template"));
|
||||
}
|
||||
Mat src = image.getMat();
|
||||
if (rect != null) {
|
||||
|
||||
@@ -8,6 +8,8 @@ import android.hardware.SensorManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.autojs.core.eventloop.EventEmitter;
|
||||
import com.stardust.autojs.core.looper.Loopers;
|
||||
import com.stardust.autojs.runtime.ScriptBridges;
|
||||
@@ -98,7 +100,9 @@ public class Sensors extends EventEmitter implements Loopers.LooperQuitHandler {
|
||||
|
||||
public SensorEventEmitter register(String sensorName, int delay) {
|
||||
if (sensorName == null) {
|
||||
throw new NullPointerException("sensorName = null");
|
||||
throw new NullPointerException(GlobalAppContext
|
||||
.getString(R.string.error_method_called_with_null_argument,
|
||||
"Sensors.register", "sensorName"));
|
||||
}
|
||||
Sensor sensor = getSensor(sensorName);
|
||||
if (sensor == null) {
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.stardust.autojs.runtime.api;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.stardust.app.GlobalAppContext;
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.autojs.core.looper.MainThreadProxy;
|
||||
import com.stardust.autojs.core.looper.TimerThread;
|
||||
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||
@@ -45,7 +47,7 @@ public class Threads {
|
||||
TimerThread thread = createThread(runnable);
|
||||
synchronized (mThreads) {
|
||||
if (mExit) {
|
||||
throw new IllegalStateException("Script is on exiting");
|
||||
throw new IllegalStateException(GlobalAppContext.getString(R.string.error_script_is_on_exiting));
|
||||
}
|
||||
mThreads.add(thread);
|
||||
thread.setName(mMainThread.getName() + " (Spawn-" + mSpawnCount + ")");
|
||||
|
||||
@@ -56,7 +56,9 @@ public class RootTool {
|
||||
if (key.equals(AUTO_DETECT.key)) {
|
||||
return AUTO_DETECT;
|
||||
}
|
||||
throw new Error("Unknown RootMode number");
|
||||
throw new IllegalArgumentException(GlobalAppContext
|
||||
.getString(R.string.error_illegal_argument,
|
||||
"RootMode", key));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<view xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
class="com.stardust.autojs.core.ui.widget.CustomSnackbarContentLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:theme="@style/Theme.Holo">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/snackbar_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="center_vertical|start"
|
||||
android:paddingTop="@dimen/snackbar_padding_vertical"
|
||||
android:paddingBottom="@dimen/snackbar_padding_vertical"
|
||||
android:paddingLeft="@dimen/snackbar_padding_horizontal"
|
||||
android:paddingRight="@dimen/snackbar_padding_horizontal"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="@integer/snackbar_text_max_lines"
|
||||
android:textSize="@dimen/snackbar_text_size"
|
||||
android:textAlignment="viewStart"
|
||||
android:textAppearance="@style/TextAppearance.Design.Snackbar.Message"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/snackbar_action_two"
|
||||
style="@style/Widget.AppCompat.Button.Borderless"
|
||||
android:textSize="@dimen/snackbar_text_size"
|
||||
android:textAllCaps="false"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/snackbar_extra_spacing_horizontal"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
android:minWidth="@dimen/snackbar_min_width"
|
||||
android:textColor="@color/colorAccent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/snackbar_action_one"
|
||||
style="@style/Widget.AppCompat.Button.Borderless"
|
||||
android:textSize="@dimen/snackbar_text_size"
|
||||
android:textAllCaps="false"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/snackbar_extra_spacing_horizontal"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
android:minWidth="@dimen/snackbar_min_width"
|
||||
android:textColor="@color/colorAccent"/>
|
||||
</view>
|
||||
@@ -36,4 +36,20 @@
|
||||
<string name="text_start_running">Running</string>
|
||||
<string name="text_root_mode_description">If you have exotic root or abnormal state for root access, you can force set root to root or non-root.</string>
|
||||
<string name="text_hidden_files_description">Whether the hidden files and folders show or not in file explorer. A file or folder is considered to be hidden if its name begins with a period character (\".\").</string>
|
||||
<string name="text_updates_snack_bar_act_view">View</string>
|
||||
<string name="text_updates_snack_bar_act_later">Later</string>
|
||||
<string name="error_function_called_in_ui_thread">UI thread can\'t be blocked. Try running %s() in sub-thread or sub-script</string>
|
||||
<string name="error_max_listeners_exceeded">Max listeners exceeded: %d</string>
|
||||
<string name="error_both_bitmap_and_mat_are_null">Both bitmap and mat are null</string>
|
||||
<string name="error_image_has_been_recycled">Image has been recycled</string>
|
||||
<string name="error_function_called_more_than_once">%s() called more than once</string>
|
||||
<string name="error_thread_is_not_alive">Thread is not alive</string>
|
||||
<string name="error_empty_shell_command">Command is empty</string>
|
||||
<string name="error_a_runtime_has_been_set">A runtime has been set</string>
|
||||
<string name="file_not_exist_or_readable">File doesn\'t exist or readable: %s</string>
|
||||
<string name="error_cannot_retrieve_battery_state">Can\'t retrieve the battery state</string>
|
||||
<string name="error_no_screen_capture_permission">No screen capture permission</string>
|
||||
<string name="error_no_accessibility_service">No accessibility service</string>
|
||||
<string name="error_method_called_with_null_argument">%s() called with null argument: %s</string>
|
||||
<string name="error_script_is_on_exiting">Script is on exiting</string>
|
||||
</resources>
|
||||
@@ -37,4 +37,20 @@
|
||||
<string name="entry_hidden_files_show">显示隐藏文件和文件夹</string>
|
||||
<string name="text_root_mode_description">如果设备使用非常规 Root 方式或 Root 权限检测异常, 可设置强制 Root 或 强制非 Root 模式.</string>
|
||||
<string name="text_hidden_files_description">设置是否在文件浏览器页面显示隐藏文件和文件夹 (文件名以 \".\" 开头)</string>
|
||||
<string name="text_updates_snack_bar_act_view">查看更新</string>
|
||||
<string name="text_updates_snack_bar_act_later">稍后提示</string>
|
||||
<string name="error_function_called_in_ui_thread">UI 线程内无法执行阻塞操作. 可尝试在子线程或子脚本中执行 %s()</string>
|
||||
<string name="error_max_listeners_exceeded">超出最大监听器数量限制: %d</string>
|
||||
<string name="error_both_bitmap_and_mat_are_null">Bitmap 与 Mat 不能同时为 null</string>
|
||||
<string name="error_image_has_been_recycled">图像资源已被回收</string>
|
||||
<string name="error_function_called_more_than_once">%s() 调用不能超过一次</string>
|
||||
<string name="error_thread_is_not_alive">线程处于非活动状态</string>
|
||||
<string name="error_empty_shell_command">命令为空</string>
|
||||
<string name="error_a_runtime_has_been_set">运行时已存在</string>
|
||||
<string name="file_not_exist_or_readable">文件不存在或不可读: %s</string>
|
||||
<string name="error_cannot_retrieve_battery_state">无法获取设备电池状态</string>
|
||||
<string name="error_no_screen_capture_permission">缺少屏幕捕获权限</string>
|
||||
<string name="error_no_accessibility_service">没有无障碍服务</string>
|
||||
<string name="error_method_called_with_null_argument">%s() 传入的 %s 参数为空</string>
|
||||
<string name="error_script_is_on_exiting">脚本正在退出中</string>
|
||||
</resources>
|
||||
@@ -1,4 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<dimen name="floaty_window_offset">12dp</dimen>
|
||||
<dimen name="snackbar_padding_vertical">14dp</dimen>
|
||||
<dimen name="snackbar_padding_horizontal">12dp</dimen>
|
||||
<integer name="snackbar_text_max_lines">2</integer>
|
||||
<dimen name="snackbar_extra_spacing_horizontal">0dp</dimen>
|
||||
<dimen name="snackbar_min_width">48dp</dimen>
|
||||
<dimen name="snackbar_text_size">14sp</dimen>
|
||||
</resources>
|
||||
@@ -56,4 +56,20 @@
|
||||
<string name="key_gesture_observing" translatable="false">key_gesture_observing</string>
|
||||
<string name="text_root_mode_description">If you have exotic root or abnormal state for root access, you can force set root to root or non-root.</string>
|
||||
<string name="text_hidden_files_description">Whether the hidden files and folders show or not in file explorer. A file or folder is considered to be hidden if its name begins with a period character (\".\").</string>
|
||||
<string name="text_updates_snack_bar_act_view">View</string>
|
||||
<string name="text_updates_snack_bar_act_later">Later</string>
|
||||
<string name="error_function_called_in_ui_thread">UI thread can\'t be blocked. Try running %s() in sub-thread or sub-script</string>
|
||||
<string name="error_max_listeners_exceeded">Max listeners exceeded: %d</string>
|
||||
<string name="error_both_bitmap_and_mat_are_null">Both bitmap and mat are null</string>
|
||||
<string name="error_image_has_been_recycled">Image has been recycled</string>
|
||||
<string name="error_function_called_more_than_once">%s() called more than once</string>
|
||||
<string name="error_thread_is_not_alive">Thread is not alive</string>
|
||||
<string name="error_empty_shell_command">Command is empty</string>
|
||||
<string name="error_a_runtime_has_been_set">A runtime has been set</string>
|
||||
<string name="file_not_exist_or_readable">File doesn\'t exist or readable: %s</string>
|
||||
<string name="error_cannot_retrieve_battery_state">Can\'t retrieve the battery state</string>
|
||||
<string name="error_no_screen_capture_permission">No screen capture permission</string>
|
||||
<string name="error_no_accessibility_service">No accessibility service</string>
|
||||
<string name="error_method_called_with_null_argument">%s() called with null argument: %s</string>
|
||||
<string name="error_script_is_on_exiting">Script is on exiting</string>
|
||||
</resources>
|
||||
@@ -58,6 +58,8 @@ dependencies {
|
||||
// AppCompat
|
||||
api 'androidx.appcompat:appcompat:1.4.1'
|
||||
|
||||
api 'org.kohsuke:github-api:1.306'
|
||||
|
||||
// AppCompat for legacy views (such as JsTextViewLegacy)
|
||||
api project(':libs:androidx.appcompat-1.0.2')
|
||||
|
||||
|
||||
@@ -22,11 +22,16 @@ public class GlobalAppContext {
|
||||
}
|
||||
|
||||
public static Context get() {
|
||||
if (sApplicationContext == null)
|
||||
if (sApplicationContext == null) {
|
||||
throw new IllegalStateException("Call GlobalAppContext.set() to set a application context");
|
||||
}
|
||||
return sApplicationContext;
|
||||
}
|
||||
|
||||
public static String getString(int resId, Object... formatArgs) {
|
||||
return get().getString(resId, formatArgs);
|
||||
}
|
||||
|
||||
public static String getString(int resId) {
|
||||
return get().getString(resId);
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ public class PFiles {
|
||||
list = manager.list(assetsDir);
|
||||
}
|
||||
if (list == null)
|
||||
throw new IOException("not a directory: " + assetsDir);
|
||||
throw new IOException("Not a directory: " + assetsDir);
|
||||
for (String file : list) {
|
||||
if (TextUtils.isEmpty(file)) {
|
||||
continue;
|
||||
@@ -398,7 +398,7 @@ public class PFiles {
|
||||
|
||||
public static boolean deleteFilesOfDir(File dir) {
|
||||
if (!dir.isDirectory())
|
||||
throw new IllegalArgumentException("not a directory: " + dir);
|
||||
throw new IllegalArgumentException("Not a directory: " + dir);
|
||||
File[] children = dir.listFiles();
|
||||
if (children != null) {
|
||||
for (File child : children) {
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.stardust.util;
|
||||
|
||||
public class ObjectHelper {
|
||||
|
||||
public static void requireNonNull(Object obj, String name){
|
||||
if(obj == null){
|
||||
throw new NullPointerException(name + " should not be null");
|
||||
}
|
||||
}
|
||||
|
||||
public static void requireNonNull(Object obj){
|
||||
if(obj == null){
|
||||
throw new NullPointerException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -45,4 +45,5 @@
|
||||
<string name="text_script_running">Script running</string>
|
||||
<string name="text_stable_mode">Stable mode</string>
|
||||
<string name="text_use_volume_to_stop_running">Use volume up key to stop all running scripts</string>
|
||||
<string name="error_illegal_argument">Illegal argument %s: %s</string>
|
||||
</resources>
|
||||
@@ -46,4 +46,5 @@
|
||||
<string name="text_script_running">脚本运行</string>
|
||||
<string name="text_stable_mode">稳定模式</string>
|
||||
<string name="text_use_volume_to_stop_running">使用 \"音量加\" 键停止所有运行的脚本</string>
|
||||
<string name="error_illegal_argument">不合法的参数 %s: %s</string>
|
||||
</resources>
|
||||
@@ -30,6 +30,7 @@
|
||||
<string name="key_enable_a11y_service_with_secure_settings" translatable="false">key_enable_a11y_service_with_secure_settings</string>
|
||||
<string name="key_stable_mode" translatable="false">key_stable_mode</string>
|
||||
<string name="key_use_volume_control_running" translatable="false">key_use_volume_control_running</string>
|
||||
<string name="key_auto_check_for_updates" translatable="false">key_auto_check_for_updates</string>
|
||||
<string name="summary_enable_a11y_service_with_root_access">Enable accessibility service with root access automatically when needed</string>
|
||||
<string name="summary_enable_a11y_service_with_secure_settings">Enable accessibility service with secure settings automatically when needed</string>
|
||||
<string name="summary_stable_mode">More stable layout analysis but worse code compatibility (a11y service restarting needed)</string>
|
||||
@@ -51,4 +52,5 @@
|
||||
<string name="text_script_running">Script running</string>
|
||||
<string name="text_stable_mode">Stable mode</string>
|
||||
<string name="text_use_volume_to_stop_running">Use volume up key to stop all running scripts</string>
|
||||
<string name="error_illegal_argument">Illegal argument %s: %s</string>
|
||||
</resources>
|
||||
@@ -6,7 +6,7 @@
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission
|
||||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||
android:maxSdkVersion="28" />
|
||||
android:maxSdkVersion="29" />
|
||||
<uses-permission
|
||||
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
|
||||
tools:ignore="ScopedStorage" />
|
||||
@@ -42,6 +42,7 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/ScriptTheme"
|
||||
android:usesCleartextTraffic="true"
|
||||
android:requestLegacyExternalStorage="true"
|
||||
tools:replace="android:label, android:allowBackup"
|
||||
tools:targetApi="m"
|
||||
tools:ignore="DataExtractionRules">
|
||||
|
||||
+4
-4
@@ -1,8 +1,8 @@
|
||||
#Thu May 26 18:59:04 CST 2022
|
||||
BUILD_TIME=1653562744879
|
||||
#Tue May 31 21:03:12 CST 2022
|
||||
BUILD_TIME=1654002192465
|
||||
COMPILE_SDK_VERSION=32
|
||||
JAVA_VERSION=17
|
||||
MIN_SDK_VERSION=24
|
||||
TARGET_SDK_VERSION=32
|
||||
VERSION_BUILD=886
|
||||
VERSION_NAME=6.1.0
|
||||
VERSION_BUILD=914
|
||||
VERSION_NAME=6.1.1
|
||||
Reference in new issue
Block a user