From 59a9e0ee459806b1f0594b1a46f6b829e19f451f Mon Sep 17 00:00:00 2001 From: ZhanGSKen Date: Thu, 30 Apr 2026 11:48:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0TermuxButton=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E6=8E=A7=E4=BB=B6=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- winboll/build.properties | 4 +- .../winboll/models/TermuxButtonModel.java | 92 ++++++++++---- .../studio/winboll/views/TermuxButton.java | 119 ++++++++++++++++++ .../main/res/layout/activity_my_termux.xml | 74 +++++++---- winboll/src/main/res/values/attrs.xml | 9 ++ 5 files changed, 250 insertions(+), 48 deletions(-) create mode 100644 winboll/src/main/java/cc/winboll/studio/winboll/views/TermuxButton.java diff --git a/winboll/build.properties b/winboll/build.properties index 9f3d12c..88515cf 100644 --- a/winboll/build.properties +++ b/winboll/build.properties @@ -1,8 +1,8 @@ #Created by .winboll/winboll_app_build.gradle -#Thu Apr 30 02:41:13 GMT 2026 +#Thu Apr 30 03:47:19 GMT 2026 stageCount=26 libraryProject= baseVersion=15.11 publishVersion=15.11.25 -buildCount=54 +buildCount=60 baseBetaVersion=15.11.26 diff --git a/winboll/src/main/java/cc/winboll/studio/winboll/models/TermuxButtonModel.java b/winboll/src/main/java/cc/winboll/studio/winboll/models/TermuxButtonModel.java index 726a964..9d7400c 100644 --- a/winboll/src/main/java/cc/winboll/studio/winboll/models/TermuxButtonModel.java +++ b/winboll/src/main/java/cc/winboll/studio/winboll/models/TermuxButtonModel.java @@ -17,39 +17,74 @@ public class TermuxButtonModel extends BaseBean { String exeCommand; String workDir; + // 新增属性 + boolean isCommit; + String commitTitle; + String commitInfo; + public TermuxButtonModel() { this.buttonName = ""; this.exeCommand = ""; this.workDir = ""; + // 新增属性默认初始化 + this.isCommit = false; + this.commitTitle = ""; + this.commitInfo = ""; } - public void setButtonName(String buttonName) { - this.buttonName = buttonName; - } + public void setButtonName(String buttonName) { + this.buttonName = buttonName; + } - public String getButtonName() { - return buttonName; - } + public String getButtonName() { + return buttonName; + } - public void setExeCommand(String exeCommand) { - this.exeCommand = exeCommand; - } + public void setExeCommand(String exeCommand) { + this.exeCommand = exeCommand; + } - public String getExeCommand() { - return exeCommand; - } + public String getExeCommand() { + return exeCommand; + } - public void setWorkDir(String workDir) { - this.workDir = workDir; - } + public void setWorkDir(String workDir) { + this.workDir = workDir; + } - public String getWorkDir() { - return workDir; - } + public String getWorkDir() { + return workDir; + } + // ========== 新增属性 Get & Set ========== + public boolean isCommit() { + return isCommit; + } + + public void setCommit(boolean commit) { + isCommit = commit; + } + + public String getCommitTitle() { + return commitTitle; + } + + public void setCommitTitle(String commitTitle) { + this.commitTitle = commitTitle; + } + + public String getCommitInfo() { + return commitInfo; + } + + public void setCommitInfo(String commitInfo) { + this.commitInfo = commitInfo; + } + + // 修复原来错误的返回类名 @Override public String getName() { - return UserInfoModel.class.getName(); + return TermuxButtonModel.class.getName(); } @Override @@ -58,17 +93,32 @@ public class TermuxButtonModel extends BaseBean { jsonWriter.name("buttonName").value(getButtonName()); jsonWriter.name("exeCommand").value(getExeCommand()); jsonWriter.name("workDir").value(getWorkDir()); + + // 新增字段写入JSON + jsonWriter.name("isCommit").value(isCommit()); + jsonWriter.name("commitTitle").value(getCommitTitle()); + jsonWriter.name("commitInfo").value(getCommitInfo()); } @Override public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException { - if (super.initObjectsFromJsonReader(jsonReader, name)) { return true; } else { + if (super.initObjectsFromJsonReader(jsonReader, name)) { + return true; + } else { if (name.equals("buttonName")) { setButtonName(jsonReader.nextString()); } else if (name.equals("exeCommand")) { setExeCommand(jsonReader.nextString()); } else if (name.equals("workDir")) { setWorkDir(jsonReader.nextString()); + } + // 新增字段解析读取 + else if (name.equals("isCommit")) { + setCommit(jsonReader.nextBoolean()); + } else if (name.equals("commitTitle")) { + setCommitTitle(jsonReader.nextString()); + } else if (name.equals("commitInfo")) { + setCommitInfo(jsonReader.nextString()); } else { return false; } @@ -85,8 +135,8 @@ public class TermuxButtonModel extends BaseBean { jsonReader.skipValue(); } } - // 结束 JSON 对象 jsonReader.endObject(); return this; } } + diff --git a/winboll/src/main/java/cc/winboll/studio/winboll/views/TermuxButton.java b/winboll/src/main/java/cc/winboll/studio/winboll/views/TermuxButton.java new file mode 100644 index 0000000..9d6d5ab --- /dev/null +++ b/winboll/src/main/java/cc/winboll/studio/winboll/views/TermuxButton.java @@ -0,0 +1,119 @@ +package cc.winboll.studio.winboll.views; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.Button; +import cc.winboll.studio.winboll.models.TermuxButtonModel; + +/** + * @Author 豆包&ZhanGSKen + * @Date 2026/04/30 10:57 + */ +public class TermuxButton extends Button { + + public static final String TAG = "TermuxButton"; + + // 绑定实体Model + private TermuxButtonModel buttonModel; + + // 原生基础构造 + public TermuxButton(Context context) { + super(context); + initView(null, null); + } + + // XML布局引用构造 解析属性 + public TermuxButton(Context context, AttributeSet attrs) { + super(context, attrs); + initView(attrs, null); + } + + public TermuxButton(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + initView(attrs, null); + } + + public TermuxButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + initView(attrs, null); + } + + // 代码动态创建 直接传入Model构造 + public TermuxButton(Context context, TermuxButtonModel model) { + super(context); + initView(null, model); + } + + /** + * 统一初始化 + */ + private void initView(AttributeSet attrs, TermuxButtonModel model) { + this.buttonModel = model; + + // 基础按钮默认配置 + setClickable(true); + setFocusable(true); + + // 解析XML自定义属性 + if (attrs != null) { + parseXmlCustomAttr(attrs); + } + + // 用model的buttonName同步按钮文字 + refreshButtonText(); + } + + /** + * 解析XML属性 + * 改用原生 android:text 给 buttonName 赋值 + */ + private void parseXmlCustomAttr(AttributeSet attrs) { + if (buttonModel == null) { + buttonModel = new TermuxButtonModel(); + } + + // 核心:读取原生 android:text 作为 buttonName + String androidText = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "text"); + + // 读取其他自定义属性 + String cmd = attrs.getAttributeValue("http://schemas.android.com/apk/res-auto", "exeCommand"); + String dir = attrs.getAttributeValue("http://schemas.android.com/apk/res-auto", "workDir"); + String isCommitStr = attrs.getAttributeValue("http://schemas.android.com/apk/res-auto", "isCommit"); + String cTitle = attrs.getAttributeValue("http://schemas.android.com/apk/res-auto", "commitTitle"); + String cInfo = attrs.getAttributeValue("http://schemas.android.com/apk/res-auto", "commitInfo"); + + // 把 android:text 赋值给 model 的 buttonName + if (androidText != null) { + buttonModel.setButtonName(androidText); + } + + // 其余属性正常赋值 + if (cmd != null) buttonModel.setExeCommand(cmd); + if (dir != null) buttonModel.setWorkDir(dir); + if (isCommitStr != null) buttonModel.setCommit(Boolean.parseBoolean(isCommitStr)); + if (cTitle != null) buttonModel.setCommitTitle(cTitle); + if (cInfo != null) buttonModel.setCommitInfo(cInfo); + } + + /** + * 统一同步:buttonName 同步到按钮 android:text + */ + private void refreshButtonText() { + if (buttonModel != null) { + setText(buttonModel.getButtonName()); + } + } + + // Model Getter & Setter + public TermuxButtonModel getButtonModel() { + return buttonModel; + } + + public void setButtonModel(TermuxButtonModel buttonModel) { + this.buttonModel = buttonModel; + // 赋值model自动刷新按钮文字 + refreshButtonText(); + } + +} + diff --git a/winboll/src/main/res/layout/activity_my_termux.xml b/winboll/src/main/res/layout/activity_my_termux.xml index 5252dd1..9b7ba45 100644 --- a/winboll/src/main/res/layout/activity_my_termux.xml +++ b/winboll/src/main/res/layout/activity_my_termux.xml @@ -27,36 +27,60 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - - + + + + + + + + + + + +