Commit c30c875335258965302d390d6f1f0fcbaa6d9921

Authored by wugian
1 parent eadf2d5d

swithc basic show change,basic opration promote

... ... @@ -91,15 +91,17 @@ public class FistJni {
91 91 }
92 92
93 93 private static void online(Device device, String jsonDevice) {
94   - boolean hasAdded = false;
  94 +// boolean hasAdded = false;
95 95 for (Device device1 : getHubs()) {
96 96 if (Arrays.equals(device1.getDeviceIp(), device.getDeviceIp())) {
97   - hasAdded = true;
  97 +// hasAdded = true;
  98 + getHubs().remove(device1);
  99 + break;
98 100 }
99 101 }
100   - if (!hasAdded) {
101   - getHubs().add(device);
102   - }
  102 +// if (!hasAdded) {
  103 + getHubs().add(device);
  104 +// }
103 105 sendMessage(DEVICE_HUBS_ONLINE_NOTIFY, DEVICE_HUBS_ONLINE_NOTIFY_STR);
104 106 }
105 107
... ... @@ -182,8 +184,9 @@ public class FistJni {
182 184 sendJsonDevice(ADD_DONE, device);
183 185 ArrayList<SubDevice> subDevices = device.getSubDevices();
184 186 if (!subDevices.isEmpty()) {//查询结果不为空
185   - getSubDevices().addAll(subDevices);
186   - sendMessage(DEVICE_SWITCH_ONLINE_NOTIFY, DEVICE_SWITCH_ONLINE_NOTIFY_STR);
  187 + subDeviceOnline(subDevices);
  188 +// getSubDevices().addAll(subDevices);
  189 +// sendMessage(DEVICE_SWITCH_ONLINE_NOTIFY, DEVICE_SWITCH_ONLINE_NOTIFY_STR);
187 190 }
188 191 // sendJsonDevice(LightingGroupAdapter.REFRESH, device);
189 192
... ... @@ -202,7 +205,13 @@ public class FistJni {
202 205
203 206 } else if (FistProtocol.CommondType.CMD_TYPE_CONTROL_DONE_RESPONSE == cmdTpye) {//单个控制结果
204 207 sendJsonDevice(CONTROL_DONE, device);
205   -
  208 + getInstance().query(getGson().toJson(getHubs().get(0)));
  209 +// ArrayList<SubDevice> subDevices = device.getSubDevices();
  210 +// if (!subDevices.isEmpty()) {//查询结果不为空
  211 +// subDeviceOnline(subDevices);
  212 +//// getSubDevices().addAll(subDevices);
  213 +//// sendMessage(DEVICE_SWITCH_ONLINE_NOTIFY, DEVICE_SWITCH_ONLINE_NOTIFY_STR);
  214 +// }
206 215 } else if (FistProtocol.CommondType.CMD_TYPE_CONTROL_OVER == cmdTpye) {
207 216 sendJsonDevice(CONTROL_OVER, device);
208 217 GlobalVar.getLogUtils().i("CONTROL_OVER");
... ... @@ -249,6 +258,23 @@ public class FistJni {
249 258 }*/
250 259 }
251 260
  261 + private static void subDeviceOnline(ArrayList<SubDevice> subDevices) {
  262 + for (SubDevice subDevice : subDevices) {
  263 +// boolean hasAdd = false;
  264 + for (SubDevice subDevice1 : getSubDevices()) {
  265 + if (subDevice.getSubDeviceNum() == subDevice1.getSubDeviceNum()) {
  266 +// hasAdd = true;
  267 + getSubDevices().remove(subDevice1);
  268 + break;
  269 + }
  270 + }
  271 +// if (!hasAdd) {
  272 + getSubDevices().add(subDevice);
  273 + sendMessage(DEVICE_SWITCH_ONLINE_NOTIFY, DEVICE_SWITCH_ONLINE_NOTIFY_STR);
  274 +// }
  275 + }
  276 + }
  277 +
252 278 /**
253 279 * 开始
254 280 */
... ...
... ... @@ -7,6 +7,7 @@ import android.support.v7.widget.GridLayoutManager;
7 7 import android.support.v7.widget.RecyclerView;
8 8 import android.util.Log;
9 9 import android.view.View;
  10 +import android.widget.Toast;
10 11 import com.adroplat.fist_switch.jni.Device;
11 12 import com.adroplat.fist_switch.jni.FistJni;
12 13 import com.adroplat.fist_switch.jni.SubDevice;
... ... @@ -18,17 +19,17 @@ import org.greenrobot.eventbus.EventBus;
18 19 import org.greenrobot.eventbus.Subscribe;
19 20 import org.greenrobot.eventbus.ThreadMode;
20 21
  22 +import java.util.ArrayList;
  23 +
21 24 public class SwitchControlActivity extends AppCompatActivity {
  25 + private String deviceStrKey = "x85bau";
22 26
23 27 @Override
24 28 protected void onCreate(Bundle savedInstanceState) {
25 29 super.onCreate(savedInstanceState);
26 30 setContentView(R.layout.activity_switch_control);
27 31 EventBus.getDefault().register(this);
28   -
29 32 //TODO EventBus,List of Hub,List of Lights
30   -// Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
31   -// setSupportActionBar(toolbar);
32 33 initList();
33 34 FistJni fistJni = FistJni.getInstance();
34 35 fistJni.startSdk();
... ... @@ -36,15 +37,6 @@ public class SwitchControlActivity extends AppCompatActivity {
36 37 if (getSupportActionBar() != null) {
37 38 getSupportActionBar().setTitle("智能开关控制");
38 39 }
39   -
40   -// FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
41   -// fab.setOnClickListener(new View.OnClickListener() {
42   -// @Override
43   -// public void onClick(View view) {
44   -// Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
45   -// .setAction("Action", null).show();
46   -// }
47   -// });
48 40 }
49 41
50 42 public void searchLocalDevice() {
... ... @@ -94,7 +86,9 @@ public class SwitchControlActivity extends AppCompatActivity {
94 86
95 87 @Override
96 88 public void onMenuClick(View v, int position) {
97   -
  89 + deviceStrKey = FistJni.getHubs().get(position).getDeviceStrKey();
  90 + Toast.makeText(SwitchControlActivity.this, "重设控制口令", Toast.LENGTH_SHORT).show();
  91 + Log.d("menu", "reset control hub:" + deviceStrKey);
98 92 }
99 93 });
100 94 hubRv.setAdapter(hubAdapter);
... ... @@ -109,9 +103,28 @@ public class SwitchControlActivity extends AppCompatActivity {
109 103 switchAdapter.setListener(new SwitchListAdapter.OnRecyclerViewItemClickListener() {
110 104 @Override
111 105 public void onItemClick(SubDevice light, int position) {
112   -
  106 + Device device = null;
  107 + for (Device deviceCur : FistJni.getHubs()) {
  108 + if (deviceCur.getDeviceStrKey().equals(deviceStrKey)) {
  109 + device = deviceCur;
  110 + }
  111 + }
  112 + if (device == null) {
  113 + Toast.makeText(SwitchControlActivity.this, "当前控制口令出错,请重新选择控制主机按menu设置", Toast.LENGTH_SHORT).show();
  114 + return;
  115 + }
  116 + if (light.getSubDeviceStatus() == 0) {
  117 + light.setSubDeviceStatus(1);
  118 + } else {
  119 + light.setSubDeviceStatus(0);
  120 + }
  121 + final ArrayList<SubDevice> subDevices = new ArrayList<>();
  122 + subDevices.add(light);
  123 + device.setSubDevices(subDevices);
  124 + FistJni.getInstance().normalC(new Gson().toJson(device));
113 125 }
114 126
  127 +
115 128 @Override
116 129 public void onLongClick(SubDevice light, int position) {
117 130
... ...
... ... @@ -132,8 +132,8 @@ public class DeviceListAdapter extends RecyclerView.Adapter<DeviceListAdapter.De
132 132
133 133 void render(Device light) {
134 134 deviceNumTv.setText(light.getLongDeviceNum() + "");
135   - deviceIp.setText(light.getStringDeviceIp());
136   - deviceKey.setText(light.getDeviceStrKey());
  135 + deviceIp.setText("IP:" + light.getStringDeviceIp());
  136 + deviceKey.setText("控制口令:" + light.getDeviceStrKey());
137 137 }
138 138 }
139 139
... ...
... ... @@ -129,8 +129,9 @@ public class SwitchListAdapter extends RecyclerView.Adapter<SwitchListAdapter.De
129 129 }
130 130
131 131 void render(SubDevice light) {
132   - subDeviceNum.setText(light.getSubDeviceNum() + "");
133   - subDeviceStatus.setText(light.getSubDeviceOnlineStatus() + "");
  132 + subDeviceNum.setText("设备号:" + light.getSubDeviceNum() + "");
  133 + String statusStr = light.getSubDeviceStatus() == 1 ? "状态:开" : "状态:关";
  134 + this.subDeviceStatus.setText(statusStr);
134 135 }
135 136 }
136 137
... ...
... ... @@ -3,6 +3,7 @@
3 3 xmlns:android="http://schemas.android.com/apk/res/android"
4 4 xmlns:tools="http://schemas.android.com/tools"
5 5 xmlns:app="http://schemas.android.com/apk/res-auto"
  6 + android:background="#ac0097ca"
6 7 android:layout_width="match_parent"
7 8 android:layout_height="match_parent"
8 9 android:padding="16dp"
... ... @@ -11,8 +12,10 @@
11 12 tools:showIn="@layout/activity_switch_control"
12 13 tools:context="com.qnbar.switchcontrol.SwitchControlActivity">
13 14
14   - <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
15   - android:text="主机" android:textSize="20sp"/>
  15 + <TextView android:layout_width="wrap_content"
  16 + android:layout_height="wrap_content"
  17 + android:text="控制主机"
  18 + android:textSize="20sp"/>
16 19
17 20 <android.support.v7.widget.RecyclerView
18 21 android:id="@+id/hubsRv"
... ...
... ... @@ -2,12 +2,16 @@
2 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 3 android:layout_width="match_parent"
4 4 android:padding="5dp"
5   - android:layout_height="match_parent"
  5 + android:layout_height="wrap_content"
  6 + android:gravity="center"
6 7 android:orientation="vertical"
7 8 >
  9 + <ImageView android:layout_width="80dp" android:layout_height="80dp"
  10 + android:background="@mipmap/host"/>
8 11 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
9 12 android:id="@+id/deviceNumTv"
10 13 android:textSize="16sp"
  14 + android:visibility="gone"
11 15 android:textColor="@android:color/black"
12 16 android:text="device num"
13 17 />
... ...
... ... @@ -2,9 +2,13 @@
2 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 3 android:layout_width="match_parent"
4 4 android:padding="5dp"
5   - android:layout_height="match_parent"
  5 + android:gravity="center"
  6 + android:layout_height="wrap_content"
6 7 android:orientation="vertical"
7 8 >
  9 + <ImageView android:layout_width="80dp" android:layout_height="80dp"
  10 + android:background="@mipmap/equipment_switch"/>
  11 +
8 12 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
9 13 android:id="@+id/subDeviceNum"
10 14 android:textSize="16sp"
... ...
Please register or login to post a comment