package com.hdl.sdk.ttl_sdk.activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.RelativeLayout; import android.widget.TextView; import com.hdl.sdk.ttl.HDLAppliances.Config.HDLApConfig; import com.hdl.sdk.ttl.HDLDeviceManger.Bean.AppliancesInfo; import com.hdl.sdk.ttl.HDLDeviceManger.Core.HDLCommand; import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.LogicFeedBackEvent; 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; /** * Created by JLChen on 2019/7/4 * 逻辑类模块控制页面 */ public class CtrlLogicActivity extends BaseActivity { /**Topbar*/ private RelativeLayout topBarBack; private TextView topBarTitle; private Button logicBtn; private TextView logicText; private AppliancesInfo appliancesInfo; /** * 复写isRegisterEventBus() 要注册使用EventBus,这里要设置返回true * * @return true */ @Override protected boolean isRegisterEventBus() { return true; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ctrl_logic); initToolbar(); initcurState(); initView(); initOnClick(); displayStateView(); } /** * 初始化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() { logicBtn = findViewById(R.id.logicbtn); logicText = findViewById(R.id.logicText); } private void initOnClick() { logicBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { HDLCommand.logicCtrl(appliancesInfo); } }); } private void displayStateView(){ switch (appliancesInfo.getDeviceType()) { case HDLApConfig.TYPE_LOGIC_MODULE: case HDLApConfig.TYPE_GLOBAL_LOGIC_MODULE: break; default: finish();//设备类型不对结束页面 break; } /**根据需求是否发送一次获取刷新状态请求*/ } /** * 逻辑模块控制回调Event * * @param event */ @Subscribe(threadMode = ThreadMode.MAIN) public void onLogicFeedBackInfoEventMain(LogicFeedBackEvent event) { // 先判断是否超时 if (event.getLogicCtrlBackInfo().getAppliancesInfo().getDeviceDeviceID() == appliancesInfo.getDeviceDeviceID() && event.getLogicCtrlBackInfo().getAppliancesInfo().getDeviceSubnetID() == appliancesInfo.getDeviceSubnetID() && event.getLogicCtrlBackInfo().getAppliancesInfo().getChannelNum() == appliancesInfo.getChannelNum() ) { if (!event.isSuccess()) { showToast("场景控制超时,请重新再试"); return; } showToast("场景控制成功"); } } }