Add input handling and execution flow for proxy automation
Introduced input field and button in `MainActivity` and updated layout to enable dynamic iteration of proxy operations based on user input. Implemented logic to handle input validation and sequential proxy processing using predefined proxy names.
This commit is contained in:
parent
c27ca64a8d
commit
74e77acdd0
|
@ -12,6 +12,7 @@ import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
@ -37,6 +38,24 @@ public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private static final int ALLOW_ALL_FILES_ACCESS_PERMISSION_CODE = 1001;
|
private static final int ALLOW_ALL_FILES_ACCESS_PERMISSION_CODE = 1001;
|
||||||
|
|
||||||
|
// 假设我们从配置文件中提取出了以下 name 项数据(仅为部分示例数据)
|
||||||
|
private final String[] proxyNames = {
|
||||||
|
"mr", "sr", "bq", "ml", "ht", "ga", "mk", "by", "pr", "hr", "hu",
|
||||||
|
"in", "gt", "at", "kh", "bn", "mg", "kr", "ca", "gh", "ma", "md",
|
||||||
|
"je", "pa", "ba", "mm", "ir", "gy", "mt", "ae", "es", "ng", "ls",
|
||||||
|
"ag", "pk", "bd", "kn", "mw", "ve", "hk", "cv", "hn", "tm", "us",
|
||||||
|
"cz", "ly", "gb", "kz", "it", "bh", "sn", "fi", "co", "sx", "bm",
|
||||||
|
"fj", "cw", "st", "bw", "fr", "bb", "tg", "ci", "gd", "ne", "bj",
|
||||||
|
"nz", "rs", "do", "cl", "lb", "nl", "re", "aw", "ug", "sv", "ar",
|
||||||
|
"jo", "bg", "jp", "rw", "py", "mn", "ec", "uz", "ro", "cu", "gu",
|
||||||
|
"xk", "sy", "so", "zm", "tz", "ni", "sc", "my", "gf", "na", "zw",
|
||||||
|
"la", "et", "ao", "ua", "om", "np", "mx", "mz", "dm", "ye", "gi",
|
||||||
|
"cr", "cm", "ph", "am", "th", "ch", "br", "sd", "ie", "bo", "bs",
|
||||||
|
"tc", "vg", "pe", "sa", "dk", "tn", "ee", "jm", "lc", "pt", "qa",
|
||||||
|
"ge", "ps"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -116,19 +135,50 @@ public class MainActivity extends AppCompatActivity {
|
||||||
Toast.makeText(this, "resetDeviceInfo button not found", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "resetDeviceInfo button not found", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
// try {
|
// 获取输入框和按钮
|
||||||
// if (!ClashUtil.checkProxy(this)) {
|
EditText inputNumber = findViewById(R.id.input_number);
|
||||||
// startProxyVpn(this);
|
Button executeButton = findViewById(R.id.execute_button);
|
||||||
// }else {
|
|
||||||
// ClashUtil.switchProxyGroup("GLOBAL","us", "127.0.0.1:6170");
|
// 设置按钮的点击事件
|
||||||
// };
|
executeButton.setOnClickListener(v -> executeLogic(inputNumber) );
|
||||||
// ChangeDeviceInfoUtil.changeDeviceInfo(getPackageName(), this);
|
|
||||||
// AutoJsUtil.runAutojsScript(this);
|
|
||||||
// } catch (InterruptedException e) {
|
|
||||||
// throw new RuntimeException(e);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 提取的独立方法
|
||||||
|
private void executeLogic(EditText inputNumber) {
|
||||||
|
String numberText = inputNumber.getText().toString(); // 获取输入框内容
|
||||||
|
|
||||||
|
if (numberText.isEmpty()) {
|
||||||
|
Toast.makeText(this, "请输入一个数字", Toast.LENGTH_SHORT).show();
|
||||||
|
return; // 退出执行
|
||||||
|
}
|
||||||
|
|
||||||
|
int number;
|
||||||
|
try {
|
||||||
|
number = Integer.parseInt(numberText); // 将输入内容转换为整数
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
Toast.makeText(this, "请输入有效的数字", Toast.LENGTH_SHORT).show();
|
||||||
|
return; // 输入无效的退出
|
||||||
|
}
|
||||||
|
|
||||||
|
// 循环执行逻辑代码
|
||||||
|
for (int i = 0; i < number; i++) {
|
||||||
|
// 假设这里是您需要选中的代码逻辑
|
||||||
|
try {
|
||||||
|
if (!ClashUtil.checkProxy(this)) {
|
||||||
|
startProxyVpn(this);
|
||||||
|
} else {
|
||||||
|
ClashUtil.switchProxyGroup("GLOBAL", proxyNames[i], "127.0.0.1:6170");
|
||||||
|
}
|
||||||
|
ChangeDeviceInfoUtil.changeDeviceInfo(getPackageName(), this);
|
||||||
|
AutoJsUtil.runAutojsScript(this);
|
||||||
|
Toast.makeText(this, "第 " + (i + 1) + " 次执行完成", Toast.LENGTH_SHORT).show();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void startProxyVpn(Context context) {
|
private void startProxyVpn(Context context) {
|
||||||
if (!isNetworkAvailable(context)) {
|
if (!isNetworkAvailable(context)) {
|
||||||
Toast.makeText(context, "Network is not available", Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, "Network is not available", Toast.LENGTH_SHORT).show();
|
||||||
|
|
|
@ -11,50 +11,84 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:gravity="center"
|
android:padding="16dp"
|
||||||
android:padding="16dp">
|
android:gravity="center">
|
||||||
|
|
||||||
|
<!-- 分组:VPN 按钮 -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="VPN 操作"
|
||||||
|
android:paddingBottom="8dp"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/run_script_button"
|
android:id="@+id/run_script_button"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="开始运行脚本"
|
android:text="运行 脚本" />
|
||||||
android:contentDescription="运行脚本按钮,用于启动自动化脚本" />
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/connectVpnButton"
|
android:id="@+id/connectVpnButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="开启 VPN"
|
android:text="开启 VPN" />
|
||||||
android:contentDescription="开启 VPN 按钮,用于连接到指定 VPN 服务" />
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/disconnectVpnButton"
|
android:id="@+id/disconnectVpnButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="断开 VPN"
|
android:text="断开 VPN" />
|
||||||
android:contentDescription="断开 VPN 按钮,用于断开当前连接的 VPN" />
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/switchVpnButton"
|
android:id="@+id/switchVpnButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="切换 VPN"
|
android:text="切换 VPN" />
|
||||||
android:contentDescription="切换 VPN 按钮,用于从一个 VPN 切换到另一个 VPN" />
|
|
||||||
|
<!-- 分组:设备信息 -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="设备信息操作"
|
||||||
|
android:paddingTop="16dp"
|
||||||
|
android:paddingBottom="8dp"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/modifyDeviceInfoButton"
|
android:id="@+id/modifyDeviceInfoButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="修改设备信息"
|
android:text="修改设备信息" />
|
||||||
android:contentDescription="修改设备信息按钮,用于编辑和更改设备信息" />
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/resetDeviceInfoButton"
|
android:id="@+id/resetDeviceInfoButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="重置设备信息"
|
android:text="重置设备信息" />
|
||||||
android:contentDescription="重置设备信息按钮,用于恢复到默认的设备信息" />
|
|
||||||
|
|
||||||
|
<!-- 添加输入框和执行按钮 -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="输入操作"
|
||||||
|
android:paddingTop="16dp"
|
||||||
|
android:paddingBottom="8dp"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/input_number"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="请输入数字"
|
||||||
|
android:inputType="number" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/execute_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="执行代码"
|
||||||
|
android:layout_gravity="center" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
Loading…
Reference in New Issue