| | |
| | | import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.AppliancesInfo; |
| | | import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.DevicesData; |
| | | import com.hdl.sdk.hdl_core.HDLDeviceManger.Core.HDLCommand; |
| | | import com.hdl.sdk.hdl_core.HDLDeviceManger.Core.HDLDeviceManager; |
| | | import com.hdl.sdk.hdl_core.HDLDeviceManger.Core.HandleSearch; |
| | | import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.BgmInfoEvent; |
| | | import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.DevicesInfoEvent; |
| | | import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.ThirdPartyBgmInfoEvent; |
| | | import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.WarningInfoEvent; |
| | | import com.hdl.sdk.hdl_sdk.R; |
| | | import com.hdl.sdk.hdl_sdk.utlis.HDLLog; |
| | | |
| | | import org.greenrobot.eventbus.EventBus; |
| | | import org.greenrobot.eventbus.Subscribe; |
| | |
| | | public class MainActivity extends AppCompatActivity { |
| | | |
| | | private Button btn, btn2; |
| | | private Button btn_get_all,btn_on_all, btn_off_all; |
| | | private Button btn_get_all,btn_on_all, btn_off_all,btn_getlocal,btn_getlocal_add; |
| | | private TextView tv; |
| | | private EditText editText; |
| | | private List<DevicesData> devicesDatas; |
| | |
| | | btn_get_all = findViewById(R.id.btn_get_all); |
| | | btn_on_all = findViewById(R.id.btn_on_all); |
| | | btn_off_all = findViewById(R.id.btn_off_all); |
| | | |
| | | btn_getlocal = findViewById(R.id.btn_getlocal); |
| | | |
| | | btn_getlocal_add = findViewById(R.id.btn_getlocal_add); |
| | | |
| | | tv = findViewById(R.id.tv); |
| | | editText = findViewById(R.id.edt); |
| | | editText.setText("172.168.188.100"); |
| | |
| | | sendAll(false); |
| | | } |
| | | }); |
| | | |
| | | |
| | | btn_getlocal.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | |
| | | clearListView(); |
| | | getLocalDevicesDataList(); |
| | | } |
| | | }); |
| | | |
| | | |
| | | |
| | | |
| | | btn_getlocal_add.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | startActivity(AddDevicesManuallyActivity.class); |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | public void startActivity(Class<?> clazz) { |
| | | Intent intent = new Intent(this, clazz); |
| | | startActivity(intent); |
| | | } |
| | | /** |
| | | * 读取和加载本地数据 |
| | | */ |
| | | private void getLocalDevicesDataList() { |
| | | devicesDatas = HDLDeviceManager.getLocalDevicesDataList(); |
| | | if (devicesDatas.size() > 0) { |
| | | updateDeviceListView(); |
| | | HandleSearch.refreshAllDevicesStateAndRemarks();//如果本地有数据,可以调用该方法,遍历发送指令,刷新所有设备的备注和状态 |
| | | } else { |
| | | showToast("本地数据为空"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 刷新设备列表数据 |
| | | */ |
| | | private void updateDeviceListView() { |
| | | int countAll = 0; |
| | | for (DevicesData devicesData : devicesDatas) { |
| | | countAll += devicesData.getAppliancesInfoList().size(); |
| | | } |
| | | tv.setText("总共模块数:" + devicesDatas.size() + " 总共回路数:" + countAll); |
| | | HDLLog.I("获取数据成功:总共模块数:" + devicesDatas.size() + " 总共回路数:" + countAll); |
| | | |
| | | for (int i = 0; i < devicesDatas.size(); i++) { |
| | | if (TextUtils.isEmpty(devicesDatas.get(i).getRemark())) { |
| | | listString.add("暂无备注"); |
| | | } else { |
| | | listString.add(devicesDatas.get(i).getRemark()); |
| | | } |
| | | } |
| | | adapter.notifyDataSetChanged(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 清空数据并刷新列表 |
| | | */ |
| | | private void clearListView() { |
| | | if (devicesDatas != null) devicesDatas.clear(); |
| | | if (listString != null) listString.clear(); |
| | | |
| | | adapter.notifyDataSetChanged(); |
| | | } |
| | | |
| | | @Override |
| | | protected void onDestroy() { |