mirror of
https://github.com/niushuai233/DevControl.git
synced 2024-10-27 22:43:20 +08:00
feat: 开关添加页面
This commit is contained in:
@@ -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);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user