| | |
| | | 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.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 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 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); |
| | | setContentView(R.layout.activity_main); |
| | | HDLCommand.init(this); |
| | | // /**配置是否开启SDK打印日志,默认为打开*/ |
| | | // HDLCommand.setHDLLogOpen(false);// |
| | |
| | | initView(); |
| | | setOnClick(); |
| | | |
| | | |
| | | // 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); |
| | | |
| | | 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); |
| | | } |
| | | }); |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | 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(); |
| | | } |
| | | } |