From 1c8968e1409fc286178699edbdc3437be40950da Mon Sep 17 00:00:00 2001 From: niushuai233 Date: Fri, 21 Oct 2022 14:53:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BC=80=E5=85=B3=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/entity/device/DeviceInfo.java | 43 +++-- .../devcontrol/base/ui/BaseActivity.java | 49 +++++- .../devcontrol/base/util/ActivityUtil.java | 10 ++ .../devcontrol/base/util/ToastUtil.java | 11 ++ .../DeviceAddPowerSwitchActivity.java | 59 +++++++ app/src/main/res/drawable/ic_confrim_32.xml | 12 ++ .../activity_device_add_power_switch.xml | 151 ++++++++++++++++++ app/src/main/res/values/ids_device_add.xml | 21 +++ .../main/res/values/strings_device_add.xml | 16 ++ iconfront/{ => operate}/215更多-横向.svg | 0 iconfront/{ => operate}/216更多-竖向.svg | 0 iconfront/{ => operate}/add.svg | 0 iconfront/{ => operate}/下一步.svg | 0 iconfront/{ => operate}/下一步_16.svg | 0 iconfront/operate/确定.svg | 1 + iconfront/{ => operate}/系统返回.svg | 0 16 files changed, 360 insertions(+), 13 deletions(-) create mode 100644 app/src/main/java/cc/niushuai/project/devcontrol/base/util/ToastUtil.java create mode 100644 app/src/main/res/drawable/ic_confrim_32.xml create mode 100644 app/src/main/res/values/ids_device_add.xml create mode 100644 app/src/main/res/values/strings_device_add.xml rename iconfront/{ => operate}/215更多-横向.svg (100%) rename iconfront/{ => operate}/216更多-竖向.svg (100%) rename iconfront/{ => operate}/add.svg (100%) rename iconfront/{ => operate}/下一步.svg (100%) rename iconfront/{ => operate}/下一步_16.svg (100%) create mode 100644 iconfront/operate/确定.svg rename iconfront/{ => operate}/系统返回.svg (100%) diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/entity/device/DeviceInfo.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/entity/device/DeviceInfo.java index fe1417f..2d900bc 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/base/entity/device/DeviceInfo.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/entity/device/DeviceInfo.java @@ -56,12 +56,19 @@ public class DeviceInfo { private String commandPath; /** - *
-     *  执行命令 参数
-     *  /文件夹/二进制文件 参数
-     * 
+ * 开启参数 */ - private String commandArgs; + private String commandOpen; + + /** + * 关闭参数 + */ + private String commandClose; + + /** + * 扩展参数集合 + */ + private List commandExtra; public String getId() { return id; @@ -119,18 +126,29 @@ public class DeviceInfo { this.commandPath = commandPath; } - public String getCommandArgs() { - return commandArgs; + public String getCommandOpen() { + return commandOpen; } - public void setCommandArgs(String commandArgs) { - this.commandArgs = commandArgs; + public void setCommandOpen(String commandOpen) { + this.commandOpen = commandOpen; } - public String getFullCommandArgs() { - return StrUtil.join(StrUtil.SPACE, this.getCommandPath(), StrUtil.SPACE, this.getCommandArgs()); + public String getCommandClose() { + return commandClose; } + public void setCommandClose(String commandClose) { + this.commandClose = commandClose; + } + + public List getCommandExtra() { + return commandExtra; + } + + public void setCommandExtra(List commandExtra) { + this.commandExtra = commandExtra; + } /** * mock 假数据 @@ -151,7 +169,8 @@ public class DeviceInfo { device.setDeviceType(DeviceTypeEnum.Power_Switch); device.setOnOff(OnOffEnum.OFF); device.setCommandPath("/path/file"); - device.setCommandArgs("-c light -t 1"); + device.setCommandOpen("-c light -t 1"); + device.setCommandClose("-c light -t 0"); list.add(device); GlobalVariables.DEVICE_INFO_MAP.put(device.getId(), device); diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/ui/BaseActivity.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/ui/BaseActivity.java index 6984268..20d0a39 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/base/ui/BaseActivity.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/ui/BaseActivity.java @@ -4,6 +4,7 @@ import android.view.View; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.AppCompatImageButton; import java.util.Map; @@ -43,9 +44,21 @@ public abstract class BaseActivity extends AppCompatActivity { * @date: 2022/10/20 10:13 */ protected void setTitle(String title, String subTitle) { + this.setTitle(null, title, subTitle, null); + } + + /** + * 设置title 同时修改icon + * + * @author niushuai + * @date: 2022/10/20 10:13 + */ + protected void setTitle(Integer backIconResId, String title, String subTitle, Integer moreSetIconResId) { // 标题名称 TextView titleTextView = findViewById(R.id.activity_title_name); - titleTextView.setText(title); + if (StrUtil.isNotEmpty(title)) { + titleTextView.setText(title); + } // 副标题名称 TextView descTextView = findViewById(R.id.activity_title_description); @@ -58,6 +71,18 @@ public abstract class BaseActivity extends AppCompatActivity { // 主标题 修改高度为50dp titleTextView.getLayoutParams().height = UiUtil.dip2px(this, 50); } + + // 修改back按钮的图片 + if (null != backIconResId) { + AppCompatImageButton btnBack = findViewById(R.id.activity_title_back); + btnBack.setImageResource(backIconResId); + } + + // 修改back按钮的图片 + if (null != moreSetIconResId) { + AppCompatImageButton btnMoreSet = findViewById(R.id.activity_title_more_set); + btnMoreSet.setImageResource(moreSetIconResId); + } } /** @@ -80,6 +105,17 @@ public abstract class BaseActivity extends AppCompatActivity { findViewById(R.id.activity_title_back).setOnClickListener(view -> activity.finish()); } + /** + * 自定义back的点击事件 + * + * @param onClickListener 点击事件 + * @author niushuai + * @date: 2022/10/21 14:19 + */ + protected void activityButtonBackClickListener(View.OnClickListener onClickListener) { + findViewById(R.id.activity_title_back).setOnClickListener(onClickListener); + } + /** * 更多设置 打开新的activity * @@ -99,4 +135,15 @@ public abstract class BaseActivity extends AppCompatActivity { moreSetView.setOnClickListener(view -> ActivityUtil.startActivity(activity, clazz, withData)); } + /** + * 自定义moreSet点击事件 + * + * @param onClickListener 点击事件 + * @author niushuai + * @date: 2022/10/21 14:18 + */ + protected void activityButtonMoreSetClickListener(View.OnClickListener onClickListener) { + findViewById(R.id.activity_title_more_set).setOnClickListener(onClickListener); + } + } diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/ActivityUtil.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/ActivityUtil.java index ff3ee7d..28595af 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/ActivityUtil.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/ActivityUtil.java @@ -16,6 +16,16 @@ public class ActivityUtil { startActivity(sourceActivity, targetActivity, null); } + public static void startActivity(Activity sourceActivity, Class targetActivity, String[] keys, String[] values) { + + HashMap map = new HashMap<>(); + for (int i = 0; i < keys.length; i++) { + map.put(keys[i], values[i]); + } + + startActivity(sourceActivity, targetActivity, map); + } + public static void startActivity(Activity sourceActivity, Class targetActivity, Map withData) { Intent intent = new Intent(sourceActivity, targetActivity); diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/ToastUtil.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/ToastUtil.java new file mode 100644 index 0000000..b0847e2 --- /dev/null +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/ToastUtil.java @@ -0,0 +1,11 @@ +package cc.niushuai.project.devcontrol.base.util; + +import android.app.Activity; +import android.widget.Toast; + +public class ToastUtil { + + public static void show(Activity activity, String msg) { + Toast.makeText(activity, msg, Toast.LENGTH_SHORT).show(); + } +} diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/ui/deviceadd/DeviceAddPowerSwitchActivity.java b/app/src/main/java/cc/niushuai/project/devcontrol/ui/deviceadd/DeviceAddPowerSwitchActivity.java index 7c7db48..98179ea 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/ui/deviceadd/DeviceAddPowerSwitchActivity.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/ui/deviceadd/DeviceAddPowerSwitchActivity.java @@ -2,9 +2,22 @@ package cc.niushuai.project.devcontrol.ui.deviceadd; import android.os.Bundle; +import android.view.View; +import android.widget.Toast; +import cc.niushuai.project.devcontrol.R; +import cc.niushuai.project.devcontrol.base.entity.device.DeviceInfo; +import cc.niushuai.project.devcontrol.base.enums.DeviceTypeEnum; +import cc.niushuai.project.devcontrol.base.enums.OnOffEnum; import cc.niushuai.project.devcontrol.base.ui.BaseActivity; +import cc.niushuai.project.devcontrol.base.util.ActivityUtil; +import cc.niushuai.project.devcontrol.base.util.GlobalVariables; +import cc.niushuai.project.devcontrol.base.util.Keys; +import cc.niushuai.project.devcontrol.base.util.ToastUtil; import cc.niushuai.project.devcontrol.databinding.ActivityDeviceAddPowerSwitchBinding; +import cc.niushuai.project.devcontrol.ui.powerswitch.PowerSwitchActivity; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; public class DeviceAddPowerSwitchActivity extends BaseActivity { @@ -24,5 +37,51 @@ public class DeviceAddPowerSwitchActivity extends BaseActivity { @Override protected void init() { + // 设置标题栏信息 + this.setTitle(null, getString(R.string.power_switch_add), null, R.drawable.ic_confrim_32); + + + } + + /** + * 监听器事件统一设置入口 + * + * @author niushuai + * @date: 2022/10/19 17:31 + */ + @Override + protected void addListener() { + + // 返回事件 + this.activityButtonBackClickListener(this); + // 保存设备信息事件 + this.activityButtonMoreSetClickListener(this::confirm4SaveDataClickListener); + } + + /** + * 保存设备数据 + * + * @param view + * @author niushuai + * @date: 2022/10/21 14:20 + */ + private void confirm4SaveDataClickListener(View view) { + DeviceInfo device = new DeviceInfo(); + + device.setId(IdUtil.nanoId()); + device.setIconId(R.drawable.ic_device_type_switch); + device.setDeviceType(DeviceTypeEnum.Power_Switch); + device.setOnOff(OnOffEnum.OFF); + device.setName(binding.deviceAddName.getText().toString()); + device.setDescription("默认设备"); + device.setCommandPath(binding.deviceAddParamProgram.getText().toString()); + device.setCommandOpen(binding.deviceAddParamOpen.getText().toString()); + device.setCommandClose(binding.deviceAddParamClose.getText().toString()); + + GlobalVariables.DEVICE_INFO_MAP.put(device.getId(), device); + + ToastUtil.show(this, StrUtil.format("设备: {} 已新增", device.getName())); + + ActivityUtil.startActivity(this, PowerSwitchActivity.class, new String[]{Keys.ID}, new String[]{device.getId()}); } } \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_confrim_32.xml b/app/src/main/res/drawable/ic_confrim_32.xml new file mode 100644 index 0000000..892553f --- /dev/null +++ b/app/src/main/res/drawable/ic_confrim_32.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/layout/activity_device_add_power_switch.xml b/app/src/main/res/layout/activity_device_add_power_switch.xml index b4676df..ace0d92 100644 --- a/app/src/main/res/layout/activity_device_add_power_switch.xml +++ b/app/src/main/res/layout/activity_device_add_power_switch.xml @@ -1,5 +1,6 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/ids_device_add.xml b/app/src/main/res/values/ids_device_add.xml new file mode 100644 index 0000000..623c4bf --- /dev/null +++ b/app/src/main/res/values/ids_device_add.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings_device_add.xml b/app/src/main/res/values/strings_device_add.xml new file mode 100644 index 0000000..1487ea0 --- /dev/null +++ b/app/src/main/res/values/strings_device_add.xml @@ -0,0 +1,16 @@ + + + + + 选择图标 + 开启指令 + 关闭指令 + 关联程序 + + + 添加开关设备 + 开关名称 + + + + \ No newline at end of file diff --git a/iconfront/215更多-横向.svg b/iconfront/operate/215更多-横向.svg similarity index 100% rename from iconfront/215更多-横向.svg rename to iconfront/operate/215更多-横向.svg diff --git a/iconfront/216更多-竖向.svg b/iconfront/operate/216更多-竖向.svg similarity index 100% rename from iconfront/216更多-竖向.svg rename to iconfront/operate/216更多-竖向.svg diff --git a/iconfront/add.svg b/iconfront/operate/add.svg similarity index 100% rename from iconfront/add.svg rename to iconfront/operate/add.svg diff --git a/iconfront/下一步.svg b/iconfront/operate/下一步.svg similarity index 100% rename from iconfront/下一步.svg rename to iconfront/operate/下一步.svg diff --git a/iconfront/下一步_16.svg b/iconfront/operate/下一步_16.svg similarity index 100% rename from iconfront/下一步_16.svg rename to iconfront/operate/下一步_16.svg diff --git a/iconfront/operate/确定.svg b/iconfront/operate/确定.svg new file mode 100644 index 0000000..ccbb5a0 --- /dev/null +++ b/iconfront/operate/确定.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/iconfront/系统返回.svg b/iconfront/operate/系统返回.svg similarity index 100% rename from iconfront/系统返回.svg rename to iconfront/operate/系统返回.svg