package com.hdl.sdk.ttl_sdk.activity;
|
|
|
import android.app.ProgressDialog;
|
import android.os.Bundle;
|
import android.text.TextUtils;
|
import android.view.View;
|
import android.widget.Button;
|
import android.widget.EditText;
|
import android.widget.RelativeLayout;
|
import android.widget.TextView;
|
|
import com.hdl.sdk.ttl.HDLAppliances.Config.HDLApConfig;
|
import com.hdl.sdk.ttl.HDLAppliances.HDLGeothermal.GeothermalBackInfo;
|
import com.hdl.sdk.ttl.HDLAppliances.HDLGeothermal.Parser.GeothermalParser;
|
import com.hdl.sdk.ttl.HDLDeviceManger.Bean.AppliancesInfo;
|
import com.hdl.sdk.ttl.HDLDeviceManger.Core.HDLCommand;
|
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.DeviceStateEvent;
|
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.EventCode;
|
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.GeothermalFeedBackEvent;
|
import com.hdl.sdk.ttl.Utils.LogUtils.HDLLog;
|
import com.hdl.sdk.ttl_sdk.R;
|
import com.hdl.sdk.ttl_sdk.base.BaseActivity;
|
|
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.ThreadMode;
|
|
/**
|
* 地热模块控制界面
|
*/
|
public class GeothermalActivity extends BaseActivity {
|
/**Topbar*/
|
private RelativeLayout topBarBack;
|
private TextView topBarTitle;
|
|
private Button btn_switch, btn_mode, btn_temp;
|
private TextView mTextView;
|
private EditText tempEditText;
|
private AppliancesInfo appliancesInfo;
|
|
private int gSwitchState;//Demo仅以此作为演示,实际请根据需求开发设计
|
private int gModeState;
|
//
|
private ProgressDialog proDialog;
|
/**
|
* 要注册使用EventBus,这里要设置返回true
|
*
|
* @return true
|
*/
|
@Override
|
protected boolean isRegisterEventBus() {
|
return true;
|
}
|
|
@Override
|
protected void onCreate(Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
setContentView(R.layout.activity_geothermal);
|
initToolbar();
|
initcurState();
|
initView();
|
initClickOnEvent();
|
showStateView();
|
|
HDLCommand.getGeothermalStateFromNetwork(appliancesInfo);
|
}
|
|
@Override
|
protected void onDestroy() {
|
super.onDestroy();
|
proDialog.dismiss();
|
HDLLog.I("onDestroy: GeothermalActivity");
|
}
|
|
/**
|
* 初始化Toolbar
|
*/
|
private void initToolbar() {
|
topBarBack = findViewById(R.id.ll_top_b_left);
|
setViewVisible(topBarBack);
|
topBarTitle = findViewById(R.id.tv_top_b_header_title);
|
topBarBack.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View view) {
|
finish();
|
}
|
});
|
}
|
|
|
private void initcurState() {
|
appliancesInfo = (AppliancesInfo) getIntent().getSerializableExtra("hdl");
|
String titleStr = appliancesInfo.getRemarks();
|
topBarTitle.setText(titleStr);
|
}
|
|
private void initView() {
|
mTextView = findViewById(R.id.tv_geothermal);
|
btn_switch = findViewById(R.id.btn_switch);
|
btn_mode = findViewById(R.id.btn_mode);
|
btn_temp = findViewById(R.id.btn_temp);
|
tempEditText = findViewById(R.id.et_temp);
|
|
proDialog = new ProgressDialog(this);
|
proDialog.setTitle("正在发送控制命令...");
|
proDialog.setMessage("请耐心等待");
|
proDialog.onStart();
|
}
|
|
private void initClickOnEvent() {
|
btn_switch.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View view) {
|
proDialog.show();
|
//演示当前状态为关,设置为开。开,设置为关。
|
if (gSwitchState == 0) {
|
//地热开
|
HDLCommand.geothermalCtrl(appliancesInfo, GeothermalParser.gSwich, GeothermalParser.gSwichOn);
|
} else {
|
//地热关
|
HDLCommand.geothermalCtrl(appliancesInfo, GeothermalParser.gSwich, GeothermalParser.gSwichOff);
|
}
|
}
|
});
|
|
|
// 0手动,1 自动,2 智能,3 定时
|
btn_mode.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View view) {
|
proDialog.show();
|
switch (gModeState) {
|
case 1:
|
//若当前模式为普通,则点击按钮设置为白天模式
|
HDLCommand.geothermalCtrl(appliancesInfo, GeothermalParser.gMode, GeothermalParser.gModeDay);
|
break;
|
case 2:
|
//若当前模式白天,则点击按钮设置为夜间模式
|
HDLCommand.geothermalCtrl(appliancesInfo, GeothermalParser.gMode, GeothermalParser.gModeNight);
|
break;
|
case 3:
|
//若当前模式夜间,则点击按钮设置为离开模式
|
HDLCommand.geothermalCtrl(appliancesInfo, GeothermalParser.gMode, GeothermalParser.gModeLeave);
|
break;
|
case 4:
|
//若当前模式离开,则点击按钮设置为自动模式
|
HDLCommand.geothermalCtrl(appliancesInfo, GeothermalParser.gMode, GeothermalParser.gModeAuto);
|
break;
|
case 5:
|
//若当前模式自动模式,则点击按钮设置为普通模式
|
HDLCommand.geothermalCtrl(appliancesInfo, GeothermalParser.gMode, GeothermalParser.gModeNormal);
|
break;
|
default:
|
// 普通模式
|
HDLCommand.geothermalCtrl(appliancesInfo, GeothermalParser.gMode, GeothermalParser.gModeNormal);
|
break;
|
|
}
|
|
|
|
}
|
});
|
|
|
btn_temp.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View view) {
|
|
String tempStr = tempEditText.getText().toString();
|
if (TextUtils.isEmpty(tempStr)) {
|
showToast("设置的温度不能为空");
|
return;
|
}
|
int tempInt = Integer.parseInt(tempStr);
|
|
if (tempInt < 16 || tempInt > 35) {
|
showToast("温度设置范围为:16~35摄氏度(℃)");
|
return;
|
}
|
proDialog.show();
|
// HDLCommand.geothermalCtrlTemp(appliancesInfo, tempInt);//自动根据当前模式设置当前模式的温度。
|
|
switch (gModeState) {
|
case 1:
|
case 2:
|
case 3:
|
case 4:
|
HDLCommand.geothermalCtrlTemp(appliancesInfo, tempInt);//自动根据当前模式设置当前模式的温度。
|
break;
|
case 5:
|
proDialog.dismiss();
|
//当前地热模式为自动
|
showToast("自动模式,不能控制温度");
|
break;
|
default:
|
proDialog.dismiss();
|
//当前地热模式为自动
|
showToast("未知模式,不能控制温度");
|
break;
|
|
}
|
|
}
|
});
|
|
|
}
|
|
private void showStateView() {
|
if (appliancesInfo.getArrCurState() != null) {
|
GeothermalBackInfo mGeothermalBackInfo = new GeothermalBackInfo(appliancesInfo, false);
|
|
String stringState = "";
|
if (mGeothermalBackInfo.getIsOn() == GeothermalParser.gSwichOff) {
|
stringState = "地热模块:关闭";
|
} else if (mGeothermalBackInfo.getIsOn() == GeothermalParser.gSwichOn) {
|
stringState = "地热模块:打开";
|
|
stringState += "\n" + getModeStateString(mGeothermalBackInfo.getgMode());
|
|
stringState += "\n室内温度:" + mGeothermalBackInfo.getgCurrentTemp();
|
|
stringState += "\n普通模式温度:" + mGeothermalBackInfo.getgNormalTemp();
|
|
stringState += "\n白天模式温度:" + mGeothermalBackInfo.getgDayTemp();
|
|
stringState += "\n夜间模式温度:" + mGeothermalBackInfo.getgNightTemp();
|
|
stringState += "\n离开模式温度:" + mGeothermalBackInfo.getgLeaveTemp();
|
} else {
|
stringState = "未知开关状态";
|
}
|
|
mTextView.setText(stringState);
|
} else {
|
mTextView.setText("未获取到地热模块状态");
|
}
|
|
}
|
|
|
/**
|
* getSwichStateString
|
*
|
* @param mState
|
* @return
|
*/
|
private String getSwichStateString(int mState) {
|
String mStrState = "未知";
|
gSwitchState = mState; //更新开关状态
|
switch (mState) {
|
case GeothermalParser.gSwichOn:
|
mStrState = "地热模块:打开";
|
break;
|
case GeothermalParser.gSwichOff:
|
mStrState = "地热模块:关闭";
|
break;
|
|
default:
|
mStrState = "未知状态";
|
break;
|
}
|
return mStrState;
|
}
|
|
|
/**
|
* getModeStateString
|
*
|
* @param mState
|
* @return
|
*/
|
private String getModeStateString(int mState) {
|
String mStrState = "未知";
|
gModeState = mState; //更新模式状态
|
switch (mState) {
|
case GeothermalParser.gModeNormal:
|
mStrState = "模式:普通";
|
break;
|
case GeothermalParser.gModeDay:
|
mStrState = "模式:白天";
|
break;
|
case GeothermalParser.gModeNight:
|
mStrState = "模式:夜间";
|
break;
|
case GeothermalParser.gModeLeave:
|
mStrState = "模式:离开";
|
break;
|
case GeothermalParser.gModeAuto:
|
mStrState = "模式:自动";
|
break;
|
|
default:
|
mStrState = "未知模式状态";
|
break;
|
}
|
return mStrState;
|
}
|
|
/**
|
* 地热控制回调Event
|
*
|
* @param event
|
*/
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
public void onGeothermalFeedBackEventMain(GeothermalFeedBackEvent event) {
|
proDialog.dismiss();
|
if (event.getGeothermalBackInfo().getAppliancesInfo().getDeviceDeviceID() == appliancesInfo.getDeviceDeviceID()
|
&& event.getGeothermalBackInfo().getAppliancesInfo().getDeviceSubnetID() == appliancesInfo.getDeviceSubnetID()
|
&& event.getGeothermalBackInfo().getAppliancesInfo().getChannelNum() == appliancesInfo.getChannelNum()
|
) {
|
//先判断是否超时
|
if (event.getStatusID() == EventCode.FAILURE_TIMEOUT) {
|
showToast("地热模块控制超时,请重新再试");
|
return;
|
}
|
|
if (event.getStatusID() == EventCode.FAILURE_DATA_ERROR) {
|
showToast("地热模块,返回数据为空");
|
return;
|
}
|
GeothermalBackInfo mGeothermalBackInfo = event.getGeothermalBackInfo();
|
showGeothermalBackInfo(mGeothermalBackInfo);
|
|
}
|
}
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
public void onDeviceStateEventMain(DeviceStateEvent event) {
|
proDialog.dismiss();
|
if (event.getAppliancesInfo().getDeviceSubnetID() == appliancesInfo.getDeviceSubnetID()
|
&& event.getAppliancesInfo().getDeviceDeviceID() == appliancesInfo.getDeviceDeviceID()
|
) {
|
//这个返回的信息是当前状态的
|
switch (event.getAppliancesInfo().getDeviceType()) {
|
case HDLApConfig.TYPE_GEOTHERMAL_MODULE:
|
case HDLApConfig.TYPE_GEOTHERMAL_JINMAO:
|
if (appliancesInfo.getChannelNum() == event.getAppliancesInfo().getChannelNum()) {
|
if (!event.isSuccess()) {
|
showToast("获取地热状态失败,请重新再试");
|
return;
|
}
|
String message = "";
|
GeothermalBackInfo mGeothermalBackInfo = new GeothermalBackInfo(event.appliancesInfo, false);
|
|
if (mGeothermalBackInfo == null) {
|
showToast("获取地热状态失败,请重新再试");
|
return;
|
}
|
|
showGeothermalBackInfo(mGeothermalBackInfo);
|
|
}
|
break;
|
}
|
}
|
}
|
|
/**
|
* showGeothermalBackInfo
|
* @param mGeothermalBackInfo
|
*/
|
private void showGeothermalBackInfo(GeothermalBackInfo mGeothermalBackInfo){
|
String message = "";
|
if(mGeothermalBackInfo.getIsOn() == GeothermalParser.gSwichOn) {
|
message = getSwichStateString(mGeothermalBackInfo.getIsOn());
|
|
message += "\n" + getModeStateString(mGeothermalBackInfo.getgMode());
|
message += "\n" + "普通模式温度:" + mGeothermalBackInfo.getgNormalTemp();
|
message += "\n" + "白天模式温度:" + mGeothermalBackInfo.getgDayTemp();
|
message += "\n" + "夜间模式温度:" + mGeothermalBackInfo.getgNightTemp();
|
message += "\n" + "离开模式温度:" + mGeothermalBackInfo.getgLeaveTemp();
|
}else {
|
message = getSwichStateString(mGeothermalBackInfo.getIsOn());
|
}
|
|
|
mTextView.setText(message);
|
showToast(message);
|
HDLLog.I(message);
|
}
|
}
|