feat: 在 MyTermuxActivity 中添加 Termux 按钮功能
- 在 activity_my_termux.xml 布局中添加 Termux 按钮(底部居中) - 在 MyTermuxActivity.java 中实现按钮点击事件 - 调用 TermuxCommandExecutor 执行 Termux 命令 - 移除了空 FrameLayout,简化布局结构
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 08:55:04 CST 2026
|
#Thu Apr 30 09:29:52 CST 2026
|
||||||
stageCount=26
|
stageCount=26
|
||||||
libraryProject=
|
libraryProject=
|
||||||
baseVersion=15.11
|
baseVersion=15.11
|
||||||
publishVersion=15.11.25
|
publishVersion=15.11.25
|
||||||
buildCount=35
|
buildCount=38
|
||||||
baseBetaVersion=15.11.26
|
baseBetaVersion=15.11.26
|
||||||
|
|||||||
@@ -2,16 +2,19 @@ package cc.winboll.studio.winboll.applications;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import cc.winboll.studio.winboll.R;
|
import cc.winboll.studio.winboll.R;
|
||||||
|
import cc.winboll.studio.winboll.termux.TermuxCommandExecutor;
|
||||||
|
|
||||||
public class MyTermuxActivity extends AppCompatActivity {
|
public class MyTermuxActivity extends AppCompatActivity {
|
||||||
|
|
||||||
public static final String TAG = "MyTermuxActivity";
|
public static final String TAG = "MyTermuxActivity";
|
||||||
|
|
||||||
private Toolbar mToolbar;
|
private Toolbar mToolbar;
|
||||||
|
private Button mTermuxButton;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -20,6 +23,8 @@ public class MyTermuxActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
// 初始化工具栏
|
// 初始化工具栏
|
||||||
initToolbar();
|
initToolbar();
|
||||||
|
// 初始化按钮
|
||||||
|
initTermuxButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initToolbar() {
|
private void initToolbar() {
|
||||||
@@ -37,4 +42,33 @@ public class MyTermuxActivity extends AppCompatActivity {
|
|||||||
LogUtils.d(TAG, "工具栏初始化完成");
|
LogUtils.d(TAG, "工具栏初始化完成");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initTermuxButton() {
|
||||||
|
mTermuxButton = findViewById(R.id.btn_termux);
|
||||||
|
if (mTermuxButton != null) {
|
||||||
|
mTermuxButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
LogUtils.d(TAG, "点击 Termux 按钮");
|
||||||
|
executeSampleCommand();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
LogUtils.d(TAG, "Termux 按钮初始化完成");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void executeSampleCommand() {
|
||||||
|
if (isTermuxAvailable()) {
|
||||||
|
boolean success = TermuxCommandExecutor.executeTerminalCommand(this, "ls -la /data/data/com.termux/files/home");
|
||||||
|
if (success) {
|
||||||
|
LogUtils.i(TAG, "命令执行成功");
|
||||||
|
} else {
|
||||||
|
LogUtils.e(TAG, "命令执行失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isTermuxAvailable() {
|
||||||
|
return TermuxCommandExecutor.isTermuxInstalled(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -15,10 +15,15 @@
|
|||||||
app:titleTextColor="@android:color/white"
|
app:titleTextColor="@android:color/white"
|
||||||
app:subtitleTextColor="@android:color/white"/>
|
app:subtitleTextColor="@android:color/white"/>
|
||||||
|
|
||||||
<FrameLayout
|
<Button
|
||||||
android:layout_width="match_parent"
|
android:id="@+id/btn_termux"
|
||||||
android:layout_height="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_gravity="bottom"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"/>
|
android:layout_gravity="bottom|center_horizontal"
|
||||||
|
android:layout_margin="8dp"
|
||||||
|
android:text="Termux"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:backgroundTint="@android:color/holo_blue_dark"/>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
Reference in New Issue
Block a user