| | |
| | | import android.widget.TextView; |
| | | import android.widget.Toast; |
| | | |
| | | import com.hdl.sdk.hdl_core.Config.Configuration; |
| | | import com.hdl.sdk.hdl_core.HDLAppliances.HDLAirCondition.Parser.AirCtrlParser; |
| | | 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.HDLSDK; |
| | | 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_core.Util.NetUtil.NetWorkUtil; |
| | | import com.hdl.sdk.hdl_core.Util.TransformUtil.HDLUtlis; |
| | | 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,btn_getlocal,btn_getlocal_add; |
| | | private Button btn_setting; |
| | | private TextView tv; |
| | | private EditText editText; |
| | | private List<DevicesData> devicesDatas; |
| | |
| | | private ArrayAdapter<String> adapter; |
| | | private ProgressDialog proDia; |
| | | private ListView listView; |
| | | |
| | | private List<AppliancesInfo> airList = new ArrayList<>(); |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | setContentView(com.hdl.sdk.hdl_sdk.R.layout.activity_main); |
| | | HDLCommand.init(this); |
| | | setContentView(R.layout.activity_main); |
| | | NetWorkUtil.setIsGetWifiBroadCast(true); |
| | | HDLSDK.init(this); |
| | | //控制BUS设备模式 |
| | | HDLSDK.startHomeMode(this); |
| | | |
| | | // //控制RCU设备模式 |
| | | // HDLSDK.startRcuMode(this,"192.168.10.111"); |
| | | |
| | | // |
| | | // HDLCommand.init(this); |
| | | // HDLCommand.startHomeMode(this); |
| | | |
| | | // /**配置是否开启SDK打印日志,默认为打开*/ |
| | | // HDLCommand.setHDLLogOpen(false);// |
| | | |
| | |
| | | initView(); |
| | | setOnClick(); |
| | | |
| | | // String str = "#Z018TYPE0010,music121"; |
| | | // String result = str.substring(4, 5); |
| | | // HDLLog.I("result:"+result); |
| | | |
| | | // hideTestButton(); |
| | | |
| | | } |
| | | |
| | | private void initView() { |
| | | btn = findViewById(com.hdl.sdk.hdl_sdk.R.id.btn); |
| | | btn2 = findViewById(com.hdl.sdk.hdl_sdk.R.id.get); |
| | | tv = findViewById(com.hdl.sdk.hdl_sdk.R.id.tv); |
| | | editText = findViewById(com.hdl.sdk.hdl_sdk.R.id.edt); |
| | | btn = findViewById(R.id.btn); |
| | | btn2 = findViewById(R.id.get); |
| | | |
| | | 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); |
| | | |
| | | btn_setting = findViewById(R.id.btn_setting); |
| | | tv = findViewById(R.id.tv); |
| | | editText = findViewById(R.id.edt); |
| | | editText.setText("172.168.188.100"); |
| | | adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, listString); |
| | | listView = findViewById(com.hdl.sdk.hdl_sdk.R.id.listView1); |
| | | listView = findViewById(R.id.listView1); |
| | | proDia = new ProgressDialog(MainActivity.this); |
| | | proDia.setTitle("正在获取数据..."); |
| | | proDia.setMessage("请耐心等待"); |
| | |
| | | HDLCommand.getHomeDevices(MainActivity.this); |
| | | proDia.show(); |
| | | |
| | | |
| | | } |
| | | }); |
| | | |
| | |
| | | |
| | | } |
| | | }); |
| | | |
| | | btn_get_all.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | getAllAirList(); |
| | | } |
| | | }); |
| | | |
| | | btn_on_all.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | sendAll(true); |
| | | } |
| | | }); |
| | | |
| | | btn_off_all.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | 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(AddDevicesActivity.class); |
| | | |
| | | } |
| | | }); |
| | | |
| | | btn_setting.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | startActivity(SettingActivity.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() { |
| | |
| | | } |
| | | |
| | | |
| | | private void hideTestButton(){ |
| | | btn_get_all.setVisibility(View.GONE); |
| | | btn_on_all.setVisibility(View.GONE); |
| | | btn_off_all.setVisibility(View.GONE); |
| | | } |
| | | |
| | | private void getAllAirList(){ |
| | | airList.clear(); |
| | | if(devicesDatas == null || devicesDatas.size() == 0) { |
| | | showToast("没有设备"); |
| | | return; |
| | | } |
| | | for (int j = 0; j < devicesDatas.size(); j++) { |
| | | DevicesData mDevicesData = devicesDatas.get(j); |
| | | List<AppliancesInfo> appliancesInfos = mDevicesData.getAppliancesInfoList(); |
| | | for (int i = 0; i < appliancesInfos.size(); i++) { |
| | | if (appliancesInfos.get(i).getBigType() == Configuration.AIR_BIG_TYPE) { |
| | | airList.add(appliancesInfos.get(i)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | String mes = "共获得:" + airList.size() + " 台空调"; |
| | | showToast(mes); |
| | | } |
| | | |
| | | private void sendAll(Boolean bOn){ |
| | | if(airList == null || airList.size() == 0) { |
| | | showToast("没有设备"); |
| | | return; |
| | | } |
| | | for (int j = 0; j < airList.size(); j++) { |
| | | AppliancesInfo info = airList.get(j); |
| | | if(bOn){ |
| | | HDLCommand.airCtrl(info, AirCtrlParser.airSwich, AirCtrlParser.airOn); |
| | | }else { |
| | | HDLCommand.airCtrl(info, AirCtrlParser.airSwich, AirCtrlParser.airOff); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | private void showToast(String text) { |
| | | Toast.makeText(this, text, Toast.LENGTH_SHORT).show(); |
| | | } |
| | | } |