feat: 开关添加页面
@ -56,12 +56,19 @@ public class DeviceInfo {
|
||||
private String commandPath;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 执行命令 参数
|
||||
* /文件夹/二进制文件 参数
|
||||
* </pre>
|
||||
* 开启参数
|
||||
*/
|
||||
private String commandArgs;
|
||||
private String commandOpen;
|
||||
|
||||
/**
|
||||
* 关闭参数
|
||||
*/
|
||||
private String commandClose;
|
||||
|
||||
/**
|
||||
* 扩展参数集合
|
||||
*/
|
||||
private List<String> 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<String> getCommandExtra() {
|
||||
return commandExtra;
|
||||
}
|
||||
|
||||
public void setCommandExtra(List<String> 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);
|
||||
|
@ -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);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,6 +16,16 @@ public class ActivityUtil {
|
||||
startActivity(sourceActivity, targetActivity, null);
|
||||
}
|
||||
|
||||
public static void startActivity(Activity sourceActivity, Class<? extends BaseActivity> targetActivity, String[] keys, String[] values) {
|
||||
|
||||
HashMap<String, String> 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<? extends BaseActivity> targetActivity,
|
||||
Map<String, String> withData) {
|
||||
Intent intent = new Intent(sourceActivity, targetActivity);
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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()});
|
||||
}
|
||||
}
|
12
app/src/main/res/drawable/ic_confrim_32.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="32dp"
|
||||
android:height="32dp"
|
||||
android:viewportWidth="1024"
|
||||
android:viewportHeight="1024">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M512,1024a512,512 0,1 1,512 -512,512.52 512.52,0 0,1 -512,512zM512,52.09a459.91,459.91 0,1 0,459.91 459.91A460.44,460.44 0,0 0,512 52.09z"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M421.11,710.71a27.34,27.34 0,0 1,-18.49 -8.07l-160.94,-169.28a26.04,26.04 0,1 1,37.76 -35.94l142.45,149.75 323.45,-326.05a26.04,26.04 0,0 1,36.98 0,26.04 26.04,0 0,1 0,36.72L439.6,703.15a26.04,26.04 0,0 1,-18.49 7.55z"/>
|
||||
</vector>
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
@ -11,7 +12,157 @@
|
||||
|
||||
<include layout="@layout/activity_common_title" />
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@id/activity_layout_title">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@id/device_add_ll_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="@string/power_switch_name"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<EditText
|
||||
android:id="@id/device_add_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="9"
|
||||
android:inputType="text" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@id/device_add_ll_select_icon"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_below="@id/device_add_ll_name"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="@string/device_add_select_icon"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="8" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@id/device_add_select_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
app:srcCompat="@drawable/ic_next_16" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@id/device_add_ll_program"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:layout_below="@id/device_add_ll_select_icon"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_marginBottom="10dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="@string/device_add_param_program"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<EditText
|
||||
android:id="@id/device_add_param_program"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="9"
|
||||
android:inputType="text" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@id/device_add_ll_open"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:layout_below="@id/device_add_ll_program"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_marginBottom="10dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="@string/device_add_param_open"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<EditText
|
||||
android:id="@id/device_add_param_open"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="9"
|
||||
android:inputType="text" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@id/device_add_ll_close"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:layout_below="@id/device_add_ll_open"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_marginBottom="10dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="@string/device_add_param_close"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<EditText
|
||||
android:id="@id/device_add_param_close"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="9"
|
||||
android:inputType="text" />
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
</ScrollView>
|
||||
</RelativeLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
21
app/src/main/res/values/ids_device_add.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<!--开关-->
|
||||
<item name="device_add_name" type="id"/>
|
||||
<item name="device_add_select_icon" type="id"/>
|
||||
<item name="device_add_param_open" type="id"/>
|
||||
<item name="device_add_param_close" type="id"/>
|
||||
<item name="device_add_param_program" type="id"/>
|
||||
|
||||
<!--layout-->
|
||||
<item name="device_add_ll_name" type="id"/>
|
||||
<item name="device_add_ll_select_icon" type="id"/>
|
||||
<item name="device_add_ll_program" type="id"/>
|
||||
<item name="device_add_ll_open" type="id"/>
|
||||
<item name="device_add_ll_close" type="id"/>
|
||||
|
||||
|
||||
|
||||
|
||||
</resources>
|
16
app/src/main/res/values/strings_device_add.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<!--common-->
|
||||
<string name="device_add_select_icon">选择图标</string>
|
||||
<string name="device_add_param_open">开启指令</string>
|
||||
<string name="device_add_param_close">关闭指令</string>
|
||||
<string name="device_add_param_program">关联程序</string>
|
||||
|
||||
<!--开关-->
|
||||
<string name="power_switch_add">添加开关设备</string>
|
||||
<string name="power_switch_name">开关名称</string>
|
||||
|
||||
|
||||
<!--自定义设备-->
|
||||
</resources>
|
Before Width: | Height: | Size: 576 B After Width: | Height: | Size: 576 B |
Before Width: | Height: | Size: 575 B After Width: | Height: | Size: 575 B |
Before Width: | Height: | Size: 825 B After Width: | Height: | Size: 825 B |
Before Width: | Height: | Size: 855 B After Width: | Height: | Size: 855 B |
Before Width: | Height: | Size: 855 B After Width: | Height: | Size: 855 B |
1
iconfront/operate/确定.svg
Normal file
@ -0,0 +1 @@
|
||||
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1666330319160" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9519" xmlns:xlink="http://www.w3.org/1999/xlink" width="32" height="32"><path d="M512 1024a512 512 0 1 1 512-512 512.520855 512.520855 0 0 1-512 512z m0-971.914547a459.914547 459.914547 0 1 0 459.914547 459.914547A460.435402 460.435402 0 0 0 512 52.085453z" p-id="9520"></path><path d="M421.110885 710.706002a27.344863 27.344863 0 0 1-18.490336-8.073245l-160.944048-169.277721a26.042726 26.042726 0 1 1 37.761953-35.938963l142.453713 149.745677 323.450661-326.054934a26.042726 26.042726 0 0 1 36.980671 0 26.042726 26.042726 0 0 1 0 36.720244L439.601221 703.153611a26.042726 26.042726 0 0 1-18.490336 7.552391z" p-id="9521"></path></svg>
|
After Width: | Height: | Size: 887 B |
Before Width: | Height: | Size: 987 B After Width: | Height: | Size: 987 B |