mirror of
https://github.com/niushuai233/DevControl.git
synced 2024-10-27 22:43:20 +08:00
feat: 设备添加页面
This commit is contained in:
parent
8b1617ce45
commit
7e5035fb6b
@ -9,8 +9,10 @@
|
|||||||
android:roundIcon="@mipmap/app_launcher_round"
|
android:roundIcon="@mipmap/app_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.DevControl">
|
android:theme="@style/Theme.DevControl">
|
||||||
|
<activity
|
||||||
<!--主页面-->
|
android:name=".ui.deviceadd.DeviceAddPowerSwitchActivity"
|
||||||
|
android:exported="false" />
|
||||||
|
<!-- 主页面 -->
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
@ -19,29 +21,26 @@
|
|||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity> <!-- 开关操作 -->
|
||||||
|
|
||||||
<!--开关操作-->
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.powerswitch.PowerSwitchActivity"
|
android:name=".ui.powerswitch.PowerSwitchActivity"
|
||||||
android:exported="false">
|
android:exported="false">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity> <!-- 开关设置 -->
|
||||||
|
|
||||||
<!--开关设置-->
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.powerswitch.PowerSwitchSetActivity"
|
android:name=".ui.powerswitch.PowerSwitchSetActivity"
|
||||||
android:exported="false">
|
android:exported="false">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity> <!-- 开关参数设置 -->
|
||||||
<!--开关参数设置-->
|
<activity
|
||||||
<activity android:name=".ui.powerswitch.PowerSwitchSetParamActivity" android:exported="false">
|
android:name=".ui.powerswitch.PowerSwitchSetParamActivity"
|
||||||
|
android:exported="false">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
@ -148,7 +148,7 @@ public class DeviceInfo {
|
|||||||
device.setName("卧室灯开关" + (i + 1));
|
device.setName("卧室灯开关" + (i + 1));
|
||||||
device.setIconId(iconId);
|
device.setIconId(iconId);
|
||||||
device.setDescription("卧室灯开关-树莓派");
|
device.setDescription("卧室灯开关-树莓派");
|
||||||
device.setDeviceType(DeviceTypeEnum.Switch);
|
device.setDeviceType(DeviceTypeEnum.Power_Switch);
|
||||||
device.setOnOff(OnOffEnum.OFF);
|
device.setOnOff(OnOffEnum.OFF);
|
||||||
device.setCommandPath("/path/file");
|
device.setCommandPath("/path/file");
|
||||||
device.setCommandArgs("-c light -t 1");
|
device.setCommandArgs("-c light -t 1");
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package cc.niushuai.project.devcontrol.base.enums;
|
package cc.niushuai.project.devcontrol.base.enums;
|
||||||
|
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import cc.niushuai.project.devcontrol.R;
|
import cc.niushuai.project.devcontrol.R;
|
||||||
import cc.niushuai.project.devcontrol.base.ui.BaseActivity;
|
import cc.niushuai.project.devcontrol.base.ui.BaseActivity;
|
||||||
|
import cc.niushuai.project.devcontrol.ui.deviceadd.DeviceAddPowerSwitchActivity;
|
||||||
import cc.niushuai.project.devcontrol.ui.powerswitch.PowerSwitchActivity;
|
import cc.niushuai.project.devcontrol.ui.powerswitch.PowerSwitchActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -15,20 +18,34 @@ public enum DeviceTypeEnum {
|
|||||||
/**
|
/**
|
||||||
* 开关
|
* 开关
|
||||||
*/
|
*/
|
||||||
Switch("Switch", "开关", R.drawable.ic_device_type_switch, PowerSwitchActivity.class),
|
Power_Switch("Power_Switch", "开关", R.drawable.ic_device_type_switch, DeviceAddPowerSwitchActivity.class, PowerSwitchActivity.class),
|
||||||
Custom("Custom", "自定义设备", R.drawable.ic_device_type_custom, PowerSwitchActivity.class),
|
Custom("Custom", "自定义设备", R.drawable.ic_device_type_custom, DeviceAddPowerSwitchActivity.class, PowerSwitchActivity.class),
|
||||||
;
|
;
|
||||||
|
|
||||||
private String value;
|
private String value;
|
||||||
private String text;
|
private String text;
|
||||||
private int resId;
|
private int resId;
|
||||||
private Class<? extends BaseActivity> activity;
|
private Class<? extends BaseActivity> deviceAddActivity;
|
||||||
|
private Class<? extends BaseActivity> deviceOperateActivity;
|
||||||
|
|
||||||
DeviceTypeEnum(String value, String text, int resId, Class<? extends BaseActivity> activity) {
|
DeviceTypeEnum(String value, String text, int resId,
|
||||||
|
Class<? extends BaseActivity> deviceAddActivity,
|
||||||
|
Class<? extends BaseActivity> deviceOperateActivity) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.resId = resId;
|
this.resId = resId;
|
||||||
this.activity = activity;
|
this.deviceAddActivity = deviceAddActivity;
|
||||||
|
this.deviceOperateActivity = deviceOperateActivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DeviceTypeEnum matchByValue(String value) {
|
||||||
|
|
||||||
|
for (DeviceTypeEnum deviceTypeEnum : DeviceTypeEnum.values()) {
|
||||||
|
if (deviceTypeEnum.getValue().equals(value)) {
|
||||||
|
return deviceTypeEnum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
@ -55,11 +72,19 @@ public enum DeviceTypeEnum {
|
|||||||
this.resId = resId;
|
this.resId = resId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class<? extends BaseActivity> getActivity() {
|
public Class<? extends BaseActivity> getDeviceAddActivity() {
|
||||||
return activity;
|
return deviceAddActivity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setActivity(Class<? extends BaseActivity> activity) {
|
public void setDeviceAddActivity(Class<? extends BaseActivity> deviceAddActivity) {
|
||||||
this.activity = activity;
|
this.deviceAddActivity = deviceAddActivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<? extends BaseActivity> getDeviceOperateActivity() {
|
||||||
|
return deviceOperateActivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceOperateActivity(Class<? extends BaseActivity> deviceOperateActivity) {
|
||||||
|
this.deviceOperateActivity = deviceOperateActivity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,11 @@ public class GlobalVariables {
|
|||||||
*/
|
*/
|
||||||
public static final Map<String, DeviceInfo> DEVICE_INFO_MAP = new HashMap<>(16);
|
public static final Map<String, DeviceInfo> DEVICE_INFO_MAP = new HashMap<>(16);
|
||||||
|
|
||||||
|
public static Class<? extends BaseActivity> getDeviceAddActivity(String deviceId) {
|
||||||
|
return getDeviceInfo(deviceId).getDeviceType().getDeviceAddActivity();
|
||||||
|
}
|
||||||
public static Class<? extends BaseActivity> getDeviceOperateActivity(String deviceId) {
|
public static Class<? extends BaseActivity> getDeviceOperateActivity(String deviceId) {
|
||||||
return getDeviceInfo(deviceId).getDeviceType().getActivity();
|
return getDeviceInfo(deviceId).getDeviceType().getDeviceOperateActivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DeviceInfo getDeviceInfo(String deviceId) {
|
public static DeviceInfo getDeviceInfo(String deviceId) {
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package cc.niushuai.project.devcontrol.ui.deviceadd;
|
||||||
|
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import cc.niushuai.project.devcontrol.R;
|
||||||
|
import cc.niushuai.project.devcontrol.base.ui.BaseActivity;
|
||||||
|
|
||||||
|
public class DeviceAddPowerSwitchActivity extends BaseActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_device_add_power_switch);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.GridView;
|
import android.widget.GridView;
|
||||||
import android.widget.SimpleAdapter;
|
import android.widget.SimpleAdapter;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@ -18,6 +19,8 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
|
|
||||||
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -25,6 +28,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import cc.niushuai.project.devcontrol.R;
|
import cc.niushuai.project.devcontrol.R;
|
||||||
import cc.niushuai.project.devcontrol.base.enums.DeviceTypeEnum;
|
import cc.niushuai.project.devcontrol.base.enums.DeviceTypeEnum;
|
||||||
|
import cc.niushuai.project.devcontrol.base.util.ActivityUtil;
|
||||||
import cc.niushuai.project.devcontrol.databinding.DeviceAddBinding;
|
import cc.niushuai.project.devcontrol.databinding.DeviceAddBinding;
|
||||||
|
|
||||||
public class DeviceAddDialogFragment extends DialogFragment {
|
public class DeviceAddDialogFragment extends DialogFragment {
|
||||||
@ -88,7 +92,9 @@ public class DeviceAddDialogFragment extends DialogFragment {
|
|||||||
* @date: 2022/10/20 16:59
|
* @date: 2022/10/20 16:59
|
||||||
*/
|
*/
|
||||||
private void deviceTypeListItemClickListener(AdapterView<?> parent, View view, int position, long id) {
|
private void deviceTypeListItemClickListener(AdapterView<?> parent, View view, int position, long id) {
|
||||||
Toast.makeText(getActivity(), "xxx", Toast.LENGTH_SHORT).show();
|
TextView keyView = view.findViewById(R.id.device_type_list_key);
|
||||||
|
|
||||||
|
ActivityUtil.startActivity(getActivity(), DeviceTypeEnum.matchByValue(keyView.getText().toString()).getDeviceAddActivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
<?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"
|
||||||
|
tools:context=".ui.deviceadd.DeviceAddPowerSwitchActivity">
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -38,7 +38,6 @@
|
|||||||
<!--添加设备 end-->
|
<!--添加设备 end-->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!--开关设置页面 start-->
|
<!--开关设置页面 start-->
|
||||||
<string name="power_switch_set_iconChange">更换图标</string>
|
<string name="power_switch_set_iconChange">更换图标</string>
|
||||||
<string name="power_switch_set_paramSet">参数设置</string>
|
<string name="power_switch_set_paramSet">参数设置</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user