改进Termux应用调用函数,添加TermuxWorkSpaces按钮响应。
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Thu Apr 30 02:12:23 GMT 2026
|
#Thu Apr 30 02:41:13 GMT 2026
|
||||||
stageCount=26
|
stageCount=26
|
||||||
libraryProject=
|
libraryProject=
|
||||||
baseVersion=15.11
|
baseVersion=15.11
|
||||||
publishVersion=15.11.25
|
publishVersion=15.11.25
|
||||||
buildCount=46
|
buildCount=54
|
||||||
baseBetaVersion=15.11.26
|
baseBetaVersion=15.11.26
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ public class MyTermuxActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private Toolbar mToolbar;
|
private Toolbar mToolbar;
|
||||||
private Button mTermuxButton;
|
private Button mTermuxButton;
|
||||||
|
private Button mTermuxWorkSpacesButton;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -24,7 +25,7 @@ public class MyTermuxActivity extends AppCompatActivity {
|
|||||||
// 初始化工具栏
|
// 初始化工具栏
|
||||||
initToolbar();
|
initToolbar();
|
||||||
// 初始化按钮
|
// 初始化按钮
|
||||||
initTermuxButton();
|
initView();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initToolbar() {
|
private void initToolbar() {
|
||||||
@@ -33,38 +34,40 @@ public class MyTermuxActivity extends AppCompatActivity {
|
|||||||
setSupportActionBar(mToolbar);
|
setSupportActionBar(mToolbar);
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
LogUtils.d(TAG, "点击返回按钮");
|
LogUtils.d(TAG, "点击返回按钮");
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
LogUtils.d(TAG, "工具栏初始化完成");
|
LogUtils.d(TAG, "工具栏初始化完成");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initTermuxButton() {
|
private void initView() {
|
||||||
mTermuxButton = findViewById(R.id.btn_termux);
|
mTermuxButton = findViewById(R.id.btn_termux);
|
||||||
if (mTermuxButton != null) {
|
if (mTermuxButton != null) {
|
||||||
mTermuxButton.setOnClickListener(new View.OnClickListener() {
|
mTermuxButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
LogUtils.d(TAG, "点击 Termux 按钮");
|
LogUtils.d(TAG, "点击 Termux 按钮");
|
||||||
executeSampleCommand();
|
TermuxCommandExecutor.openTermuxBash(MyTermuxActivity.this, "cd ~");
|
||||||
}
|
//TermuxCommandExecutor.openTermuxBash(MyTermuxActivity.this, "cd ~/TermuxWorkSpaces", "./TermuxWorkSpaces");
|
||||||
});
|
}
|
||||||
|
});
|
||||||
LogUtils.d(TAG, "Termux 按钮初始化完成");
|
LogUtils.d(TAG, "Termux 按钮初始化完成");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void executeSampleCommand() {
|
mTermuxWorkSpacesButton = findViewById(R.id.btn_termuxworkspaces);
|
||||||
if (isTermuxAvailable()) {
|
if (mTermuxWorkSpacesButton != null) {
|
||||||
boolean success = TermuxCommandExecutor.openTermuxBash(this, "ls -la ./");
|
mTermuxWorkSpacesButton.setOnClickListener(new View.OnClickListener() {
|
||||||
if (success) {
|
@Override
|
||||||
LogUtils.i(TAG, "命令执行成功");
|
public void onClick(View v) {
|
||||||
} else {
|
LogUtils.d(TAG, "点击 TermuxWorkSpaces 按钮");
|
||||||
LogUtils.e(TAG, "命令执行失败");
|
TermuxCommandExecutor.openTermuxBash(MyTermuxActivity.this, "cd ~/TermuxWorkSpaces", "./TermuxWorkSpaces");
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
LogUtils.d(TAG, "TermuxWorkSpaces 按钮初始化完成");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ public class TermuxCommandExecutor {
|
|||||||
context,
|
context,
|
||||||
"/data/data/com.termux/files/usr/bin/bash", // Termux 默认 bash 路径(正确)
|
"/data/data/com.termux/files/usr/bin/bash", // Termux 默认 bash 路径(正确)
|
||||||
args,
|
args,
|
||||||
"/data/data/com.termux/files/home", // 默认工作目录
|
TERMUX_HOME_PATH, // 默认工作目录
|
||||||
false, // 终端会话执行(可见)
|
false, // 终端会话执行(可见)
|
||||||
null // 不输出到文件
|
null // 不输出到文件
|
||||||
);
|
);
|
||||||
@@ -176,6 +176,10 @@ public class TermuxCommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean openTermuxBash(Context context, String command) {
|
public static boolean openTermuxBash(Context context, String command) {
|
||||||
|
return openTermuxBash(context, command, "~");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean openTermuxBash(Context context, String command, String workDir) {
|
||||||
LogUtils.d(TAG, "openTermuxBash() 按钮点击,执行Gradle命令(实时输出)");
|
LogUtils.d(TAG, "openTermuxBash() 按钮点击,执行Gradle命令(实时输出)");
|
||||||
|
|
||||||
// 1. 校验Termux是否安装
|
// 1. 校验Termux是否安装
|
||||||
@@ -185,7 +189,10 @@ public class TermuxCommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. 定义核心路径(确保路径与Termux中一致)
|
// 2. 定义核心路径(确保路径与Termux中一致)
|
||||||
String projectPath = TERMUX_HOME_PATH + "/"; // 项目目录
|
String projectPath = TERMUX_HOME_PATH;
|
||||||
|
if (workDir.startsWith("~") || workDir.startsWith(".")) {
|
||||||
|
projectPath = TERMUX_HOME_PATH + "/" + workDir.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
// 3. 构造命令(核心:用stdbuf禁用缓冲,实现实时输出)
|
// 3. 构造命令(核心:用stdbuf禁用缓冲,实现实时输出)
|
||||||
String targetCmd = "";
|
String targetCmd = "";
|
||||||
|
|||||||
Reference in New Issue
Block a user