Skip to content

Commit

Permalink
add: 增加zMOPS 童锁/led开关
Browse files Browse the repository at this point in the history
add: 增加zA1 童锁功能
  • Loading branch information
a2633063 committed Nov 22, 2020
1 parent 9e207bc commit b5387c7
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/zyc/zcontrol/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

if (deviceData.size() < 1) {
deviceData.add(new DeviceClock("演示设备", "000000000000"));
deviceData.add(new DeviceTC1("演示设备", "000000000000"));
}
//endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.SwitchPreference;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
Expand Down Expand Up @@ -45,6 +46,7 @@ public class A1SettingFragment extends SettingFragment {
Preference regetdata;
EditTextPreference name_preference;
CheckBoxPreference led_state;
SwitchPreference child_lock;


DeviceA1 device;
Expand Down Expand Up @@ -154,7 +156,7 @@ public void onClick(DialogInterface dialog, int which) {
//region 发送请求数据
case 3:
Send("{\"mac\":\"" + device.getMac()
+ "\",\"version\":null,\"lock\":null,\"ssid\":null,\"led_state\":null,\"filter_time\":null}");
+ "\",\"version\":null,\"lock\":null,\"child_lock\":null,\"ssid\":null,\"led_state\":null,\"filter_time\":null}");
break;
//endregion
}
Expand Down Expand Up @@ -184,6 +186,7 @@ public void onCreate(Bundle savedInstanceState) {
regetdata = findPreference("regetdata");
name_preference = (EditTextPreference) findPreference("name");
led_state = (CheckBoxPreference) findPreference("led_state");
child_lock = (SwitchPreference) findPreference("child_lock");


name_preference.setSummary(device.getName());
Expand Down Expand Up @@ -215,6 +218,20 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
}
});
//endregion
//region 童锁
child_lock.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
child_lock.setChecked(!child_lock.isChecked());
if (!child_lock.isChecked()) {
Send("{\"mac\":\"" + device.getMac() + "\",\"child_lock\":1}");
} else {
Send("{\"mac\":\"" + device.getMac() + "\",\"child_lock\":0}");
}
return true;
}
});
//endregion
//region led状态
led_state.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
Expand Down Expand Up @@ -526,6 +543,12 @@ public void Receive(String ip, int port, String topic, String message) {
fw_version.setSummary(version);
}
//endregion
//region 童锁
if (jsonObject.has("child_lock")) {
int child_lock_val = jsonObject.getInt("child_lock");
child_lock.setChecked(child_lock_val != 0);
}
//endregion
//region led状态
if (jsonObject.has("led_state")) {
int led = jsonObject.optInt("led_state");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.os.Message;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.SwitchPreference;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
Expand All @@ -37,6 +38,8 @@ public class MOPSSettingFragment extends SettingFragment {

Preference regetdata;
EditTextPreference name_preference;
SwitchPreference child_lock;
SwitchPreference led_lock;

DeviceMOPS device;

Expand Down Expand Up @@ -169,6 +172,8 @@ public void onCreate(Bundle savedInstanceState) {

regetdata = findPreference("regetdata");
name_preference = (EditTextPreference) findPreference("name");
child_lock = (SwitchPreference) findPreference("child_lock");
led_lock = (SwitchPreference) findPreference("led_lock");


name_preference.setSummary(device.getName());
Expand Down Expand Up @@ -201,7 +206,35 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
});
//endregion

//region 夜间模式 led锁
led_lock.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
led_lock.setChecked(!led_lock.isChecked());
if (!led_lock.isChecked()) {
Send("{\"mac\":\"" + device.getMac() + "\",\"led_lock\":1}");
} else {
Send("{\"mac\":\"" + device.getMac() + "\",\"led_lock\":0}");
}
return true;
}
});
//endregion

//region 童锁
child_lock.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
child_lock.setChecked(!child_lock.isChecked());
if (!child_lock.isChecked()) {
Send("{\"mac\":\"" + device.getMac() + "\",\"child_lock\":1}");
} else {
Send("{\"mac\":\"" + device.getMac() + "\",\"child_lock\":0}");
}
return true;
}
});
//endregion
//region 版本
fw_version.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
Expand Down Expand Up @@ -337,7 +370,18 @@ public void Receive(String ip, int port, String topic, String message) {
name_preference.setText(device.getName());
}
//endregion

//region 夜间模式 led锁
if (jsonObject.has("led_lock")) {
int led_lock_val = jsonObject.getInt("led_lock");
led_lock.setChecked(led_lock_val != 0);
}
//endregion
//region 童锁
if (jsonObject.has("child_lock")) {
int child_lock_val = jsonObject.getInt("child_lock");
child_lock.setChecked(child_lock_val != 0);
}
//endregion
//region 获取版本号
if (jsonObject.has("version")) {
String version = jsonObject.getString("version");
Expand Down
11 changes: 8 additions & 3 deletions app/src/main/res/xml/a1_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
android:title="总是通过UDP发送数据" />
<Preference
android:key="ssid"
android:title="连接的热点"/>
android:title="连接的热点" />
<Preference
android:key="fw_version"
android:title="当前版本(点击检查新版本)" />
Expand All @@ -30,9 +30,14 @@
<CheckBoxPreference
android:defaultValue="false"
android:key="led_state"
android:title="风速指示灯常亮"
android:persistent="false"
android:summary="勾选后启动设备后led灯不会熄灭" />
android:summary="勾选后启动设备后led灯不会熄灭"
android:title="风速指示灯常亮" />
<SwitchPreference
android:defaultValue="false"
android:key="child_lock"
android:summary="开启后按键无效.重启后自动关闭童锁."
android:title="按键锁定(童锁)" />
<Preference
android:key="filter_time"
android:title="滤芯启用日期" />
Expand Down
15 changes: 12 additions & 3 deletions app/src/main/res/xml/mops_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@
<Preference
android:key="fw_version"
android:title="当前版本(点击检查新版本)" />

<SwitchPreference
android:defaultValue="false"
android:key="led_lock"
android:summary="开启后led会熄灭.重启后自动关闭夜间模式."
android:title="夜间模式" />
<SwitchPreference
android:defaultValue="false"
android:key="child_lock"
android:summary="开启后按键无效.重启后自动关闭童锁."
android:title="按键锁定(童锁)" />
<Preference
android:key="regetdata"
android:title="重新获取数据"
android:summary="获取版本/激活状态失败时点此重试"/>
android:summary="获取版本/激活状态失败时点此重试"
android:title="重新获取数据" />

</PreferenceCategory>

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/xml/tc1_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
<SwitchPreference
android:defaultValue="false"
android:key="child_lock"
android:title="童锁"
android:summary="开启按键无效.重启后自动关闭童锁."/>
android:summary="开启后按键无效.重启后自动关闭童锁."
android:title="按键锁定(童锁)" />
<Preference
android:key="fw_version"
android:title="当前版本(点击检查新版本)"/>
Expand Down

0 comments on commit b5387c7

Please sign in to comment.