From 2e80ba72598546c8f80ab50d2395e70e0d9e66a0 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期三, 24 六月 2020 15:15:13 +0800
Subject: [PATCH] 2020-06-24 1.修改添加场景方法,需要指定回路号

---
 app/src/main/java/com/hdl/sdk/hdl_sdk/activity/MainActivity.java |  103 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 100 insertions(+), 3 deletions(-)

diff --git a/app/src/main/java/com/hdl/sdk/hdl_sdk/activity/MainActivity.java b/app/src/main/java/com/hdl/sdk/hdl_sdk/activity/MainActivity.java
index 6c3e53b..cb5db34 100644
--- a/app/src/main/java/com/hdl/sdk/hdl_sdk/activity/MainActivity.java
+++ b/app/src/main/java/com/hdl/sdk/hdl_sdk/activity/MainActivity.java
@@ -19,11 +19,16 @@
 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_sdk.R;
+import com.hdl.sdk.hdl_sdk.utlis.HDLLog;
 
 import org.greenrobot.eventbus.EventBus;
 import org.greenrobot.eventbus.Subscribe;
@@ -37,7 +42,8 @@
 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 Button btn_setting;
     private TextView tv;
     private EditText editText;
     private List<DevicesData> devicesDatas;
@@ -51,7 +57,18 @@
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
-        HDLCommand.init(this);
+        NetWorkUtil.setIsGetWifiBroadCast(true);
+        HDLSDK.init(this);
+        //鎺у埗BUS璁惧妯″紡
+        HDLSDK.startHomeMode(this);
+
+//        //鎺у埗RCU璁惧妯″紡
+//        HDLSDK.startRcuMode(this,"192.168.10.111");
+
+//
+//        HDLCommand.init(this);
+//        HDLCommand.startHomeMode(this);
+
 //        /**閰嶇疆鏄惁寮�鍚疭DK鎵撳嵃鏃ュ織锛岄粯璁や负鎵撳紑*/
 //        HDLCommand.setHDLLogOpen(false);//
 
@@ -72,7 +89,11 @@
         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");
@@ -142,8 +163,84 @@
                 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() {

--
Gitblit v1.8.0