Commit d7ea7ebe1e100547a01a38961c54dfa0af14a52e

Authored by wugian
1 parent 257e4689

volley gradle update,switch basic use in fangtang

Showing 58 changed files with 3483 additions and 92 deletions
@@ -157,10 +157,11 @@ dependencies { @@ -157,10 +157,11 @@ dependencies {
157 compile project(':pinying') 157 compile project(':pinying')
158 compile project(':debug-db') 158 compile project(':debug-db')
159 compile project(':BluetoothLightLib') 159 compile project(':BluetoothLightLib')
  160 + compile project(':switchcontrollib')
160 161
161 // compile group: 'com.android.support', name: 'support-v4', version: '25.2.0' 162 // compile group: 'com.android.support', name: 'support-v4', version: '25.2.0'
162 // compile group: 'com.android.support', name: 'support-compat', version: '25.2.0' 163 // compile group: 'com.android.support', name: 'support-compat', version: '25.2.0'
163 - compile group: 'com.android.support', name: 'recyclerview-v7', version: '25.2.0' 164 +// compile group: 'com.android.support', name: 'recyclerview-v7', version: '25.2.0'
164 compile group: 'com.squareup.okhttp', name: 'okhttp', version: '2.7.5' 165 compile group: 'com.squareup.okhttp', name: 'okhttp', version: '2.7.5'
165 compile group: 'com.google.code.gson', name: 'gson', version: '2.7' 166 compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
166 compile group: 'com.google.zxing', name: 'core', version: '3.3.0' 167 compile group: 'com.google.zxing', name: 'core', version: '3.3.0'
@@ -169,7 +170,7 @@ dependencies { @@ -169,7 +170,7 @@ dependencies {
169 compile group: 'com.squareup.retrofit2', name: 'retrofit', version: '2.0.2' 170 compile group: 'com.squareup.retrofit2', name: 'retrofit', version: '2.0.2'
170 compile group: 'com.squareup.retrofit2', name: 'converter-gson', version: '2.0.2' 171 compile group: 'com.squareup.retrofit2', name: 'converter-gson', version: '2.0.2'
171 compile 'org.greenrobot:eventbus:3.0.0' 172 compile 'org.greenrobot:eventbus:3.0.0'
172 - compile 'com.android.support:support-v4:25.2.0' 173 +// compile 'com.android.support:support-v4:25.2.0'
173 } 174 }
174 175
175 def getPwd(modifyPwd) { 176 def getPwd(modifyPwd) {
@@ -29,7 +29,7 @@ @@ -29,7 +29,7 @@
29 android:name=".application.FangTangApplication" 29 android:name=".application.FangTangApplication"
30 android:allowBackup="true" 30 android:allowBackup="true"
31 android:hardwareAccelerated="true" 31 android:hardwareAccelerated="true"
32 - android:icon="${icon}" 32 + android:icon="@drawable/ic_launcher"
33 android:label="@string/app_name" 33 android:label="@string/app_name"
34 android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> 34 android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
35 <meta-data 35 <meta-data
@@ -32,6 +32,7 @@ public class AdsPreVideoPlayerActivity extends BaseActivity { @@ -32,6 +32,7 @@ public class AdsPreVideoPlayerActivity extends BaseActivity {
32 private int duration; 32 private int duration;
33 33
34 private Handler handler = new Handler(); 34 private Handler handler = new Handler();
  35 + String leaveTimeFormat = "广告还有 %s s";
35 36
36 @Override 37 @Override
37 protected void onCreate(Bundle savedInstanceState) { 38 protected void onCreate(Bundle savedInstanceState) {
@@ -69,7 +70,7 @@ public class AdsPreVideoPlayerActivity extends BaseActivity { @@ -69,7 +70,7 @@ public class AdsPreVideoPlayerActivity extends BaseActivity {
69 } 70 }
70 duration = (videoView.getDuration() + 500) / 1000 * playCount; 71 duration = (videoView.getDuration() + 500) / 1000 * playCount;
71 timeCount.setVisibility(View.VISIBLE); 72 timeCount.setVisibility(View.VISIBLE);
72 - timeCount.setText(String.format("%s s", String.valueOf(duration))); 73 + timeCount.setText(String.format(leaveTimeFormat, String.valueOf(duration)));
73 try { 74 try {
74 videoView.start(); 75 videoView.start();
75 handler.postDelayed(timeCountRunnable, 1000); 76 handler.postDelayed(timeCountRunnable, 1000);
@@ -88,7 +89,7 @@ public class AdsPreVideoPlayerActivity extends BaseActivity { @@ -88,7 +89,7 @@ public class AdsPreVideoPlayerActivity extends BaseActivity {
88 @Override 89 @Override
89 public void run() { 90 public void run() {
90 handler.postDelayed(this, 1000); 91 handler.postDelayed(this, 1000);
91 - timeCount.setText(String.format("%s s", String.valueOf(--duration >= 0 ? duration : 0))); 92 + timeCount.setText(String.format(leaveTimeFormat, String.valueOf(--duration >= 0 ? duration : 0)));
92 } 93 }
93 }; 94 };
94 95
@@ -42,6 +42,10 @@ import android.widget.ImageView; @@ -42,6 +42,10 @@ import android.widget.ImageView;
42 import android.widget.RelativeLayout; 42 import android.widget.RelativeLayout;
43 import android.widget.ScrollView; 43 import android.widget.ScrollView;
44 import android.widget.Toast; 44 import android.widget.Toast;
  45 +import com.adroplat.fist_switch.jni.Device;
  46 +import com.adroplat.fist_switch.jni.FistJni;
  47 +import com.adroplat.fist_switch.jni.SubDevice;
  48 +import com.adroplat.fist_switch.utils.protocol.one.FistProtocol;
45 import com.bluetoothle.BLEBroadcastReceiver; 49 import com.bluetoothle.BLEBroadcastReceiver;
46 import com.bluetoothle.BLEOpenRecord; 50 import com.bluetoothle.BLEOpenRecord;
47 import com.bluetoothle.GREENBluetoothLeService; 51 import com.bluetoothle.GREENBluetoothLeService;
@@ -59,10 +63,12 @@ import com.gimi.common.cinema.utils.M1905Utils; @@ -59,10 +63,12 @@ import com.gimi.common.cinema.utils.M1905Utils;
59 import com.gimi.common.cinema.utils.OpenMMUtils; 63 import com.gimi.common.cinema.utils.OpenMMUtils;
60 import com.gimi.common.cinema.utils.ScreenUtils; 64 import com.gimi.common.cinema.utils.ScreenUtils;
61 import com.gimi.common.cinema.utils.SystemUtils; 65 import com.gimi.common.cinema.utils.SystemUtils;
  66 +import com.google.gson.Gson;
62 import com.qnbar.smc.model.Light; 67 import com.qnbar.smc.model.Light;
63 import com.qnbar.smc.model.Lights; 68 import com.qnbar.smc.model.Lights;
64 import com.qnbar.smc.service.SocketService; 69 import com.qnbar.smc.service.SocketService;
65 import com.qnbar.smc.service.TelinkLightService; 70 import com.qnbar.smc.service.TelinkLightService;
  71 +import com.qnbar.switchcontrol.model.SwitchMessageEvent;
66 import com.telink.bluetooth.LeBluetooth; 72 import com.telink.bluetooth.LeBluetooth;
67 import com.telink.bluetooth.TelinkLog; 73 import com.telink.bluetooth.TelinkLog;
68 import com.telink.bluetooth.event.DeviceEvent; 74 import com.telink.bluetooth.event.DeviceEvent;
@@ -98,11 +104,14 @@ import java.util.Date; @@ -98,11 +104,14 @@ import java.util.Date;
98 import java.util.List; 104 import java.util.List;
99 import java.util.Locale; 105 import java.util.Locale;
100 106
  107 +import static com.qnbar.smc.service.SocketService.OPEN_DOOR_CMD;
  108 +
101 /** 109 /**
102 * Created by wugian on 2016/9/23 110 * Created by wugian on 2016/9/23
103 */ 111 */
104 public class MainActivity extends BaseActivity implements IMainView, EventListener<String> { 112 public class MainActivity extends BaseActivity implements IMainView, EventListener<String> {
105 - 113 + private long switchNum = 4294967151L;
  114 + private String deviceNum = "FF:FF:FF:FF:00:FF";
106 private static final String TAG = "MainActivity"; 115 private static final String TAG = "MainActivity";
107 private Context context; 116 private Context context;
108 117
@@ -365,21 +374,22 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen @@ -365,21 +374,22 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
365 } 374 }
366 375
367 if (!LeBluetooth.getInstance().isEnabled()) { 376 if (!LeBluetooth.getInstance().isEnabled()) {
368 - AlertDialog.Builder builder = new AlertDialog.Builder(this);  
369 - builder.setMessage("开启蓝牙,体验智能灯!");  
370 - builder.setNeutralButton("cancel", new DialogInterface.OnClickListener() {  
371 - @Override  
372 - public void onClick(DialogInterface dialog, int which) {  
373 - finish();  
374 - }  
375 - });  
376 - builder.setNegativeButton("enable", new DialogInterface.OnClickListener() {  
377 - @Override  
378 - public void onClick(DialogInterface dialog, int which) {  
379 - LeBluetooth.getInstance().enable(getApplicationContext());  
380 - }  
381 - });  
382 - builder.show(); 377 +// AlertDialog.Builder builder = new AlertDialog.Builder(this);
  378 +// builder.setMessage("开启蓝牙,体验智能灯!");
  379 +// builder.setNeutralButton("cancel", new DialogInterface.OnClickListener() {
  380 +// @Override
  381 +// public void onClick(DialogInterface dialog, int which) {
  382 +// finish();
  383 +// }
  384 +// });
  385 +// builder.setNegativeButton("enable", new DialogInterface.OnClickListener() {
  386 +// @Override
  387 +// public void onClick(DialogInterface dialog, int which) {
  388 + LeBluetooth.getInstance().enable(getApplicationContext());
  389 + Log.d(TAG, "开启蓝牙,体验智能灯!");
  390 +// }
  391 +// });
  392 +// builder.show();
383 } 393 }
384 394
385 DeviceInfo deviceInfo = mApplication.getConnectDevice(); 395 DeviceInfo deviceInfo = mApplication.getConnectDevice();
@@ -389,10 +399,21 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen @@ -389,10 +399,21 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
389 } else { 399 } else {
390 autoConnect(); 400 autoConnect();
391 } 401 }
  402 + if (findCount++ < 5) {
  403 + if (!findHub || !findSwitch) {
  404 + initSwitch();
  405 + Log.d(TAG, "re init switch");
  406 + }
  407 + } else {
  408 + Log.d(TAG, "find switch more than 5 times ,there may not exist right switch");
  409 + }
  410 +
392 411
393 Log.d(TAG, "onResume"); 412 Log.d(TAG, "onResume");
394 } 413 }
395 414
  415 + int findCount = 0;
  416 +
396 @Override 417 @Override
397 public boolean onGenericMotionEvent(MotionEvent event) { 418 public boolean onGenericMotionEvent(MotionEvent event) {
398 return super.onGenericMotionEvent(event); 419 return super.onGenericMotionEvent(event);
@@ -634,7 +655,7 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen @@ -634,7 +655,7 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
634 655
635 BLEOpenRecord bleOpenRecord = new BLEOpenRecord(); 656 BLEOpenRecord bleOpenRecord = new BLEOpenRecord();
636 bleOpenRecord.setLockmac("DC:F6:70:C1:AA:D6"); 657 bleOpenRecord.setLockmac("DC:F6:70:C1:AA:D6");
637 - bleOpenRecord.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US).format(new Date())); 658 + bleOpenRecord.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US).leaveTimeFormat(new Date()));
638 Intent intent = new Intent(); 659 Intent intent = new Intent();
639 intent.setAction(GREENBluetoothLeService.ACTION_OPEN_SUCCESS); 660 intent.setAction(GREENBluetoothLeService.ACTION_OPEN_SUCCESS);
640 intent.putExtra("openrecord", bleOpenRecord); 661 intent.putExtra("openrecord", bleOpenRecord);
@@ -851,10 +872,46 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen @@ -851,10 +872,46 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
851 @Subscribe(threadMode = ThreadMode.MAIN) 872 @Subscribe(threadMode = ThreadMode.MAIN)
852 public void onMoonEvent(MessageEvent messageEvent) { 873 public void onMoonEvent(MessageEvent messageEvent) {
853 switch (messageEvent.getEventId()) { 874 switch (messageEvent.getEventId()) {
854 - case SocketService.OPEN_DOOR_CMD: 875 + case OPEN_DOOR_CMD:
855 openDoor(); 876 openDoor();
856 Log.d("event bus", messageEvent.getMessage()); 877 Log.d("event bus", messageEvent.getMessage());
857 Log.d("event bus", "open door"); 878 Log.d("event bus", "open door");
  879 + MessageEvent msgEvent = new MessageEvent();
  880 + msgEvent.setEventId(0x19910);
  881 + msgEvent.setMessage("open_switch");
  882 + EventBus.getDefault().post(msgEvent);
  883 + break;
  884 +
  885 + case 0x19910:
  886 + if (findHub && findSwitch) {
  887 + Device device = null;
  888 + for (Device deviceCur : FistJni.getHubs()) {
  889 + if (deviceCur.getStringDeviceNum().equals(deviceNum)) {
  890 + device = deviceCur;
  891 + break;
  892 + }
  893 + }
  894 + if (device == null) {
  895 +// toast("当前控制口令出错,请重新选择控制主机按menu设置");
  896 + return;
  897 + }
  898 + SubDevice curSubDevice = null;
  899 + for (SubDevice subDevice : FistJni.getSubDevices()) {
  900 + if (subDevice.getSubDeviceNum() == switchNum) {
  901 + curSubDevice = subDevice;
  902 + break;
  903 + }
  904 + }
  905 + if (curSubDevice == null) {
  906 + return;
  907 + }
  908 + curSubDevice.setSubDeviceStatus("close_switch".equals(messageEvent.getMessage()) ? 0 : 1);
  909 + ArrayList<SubDevice> subDevices = new ArrayList<>();
  910 + subDevices.add(curSubDevice);
  911 + device.setSubDevices(subDevices);
  912 + FistJni.getInstance().normalC(new Gson().toJson(device));
  913 + Log.d(TAG, "open door and smart switch");
  914 + }
858 break; 915 break;
859 } 916 }
860 } 917 }
@@ -889,4 +946,57 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen @@ -889,4 +946,57 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
889 OpenMMUtils.openMMWithAds(this, localMovieMessages.get(0).getPlayPath(), null); 946 OpenMMUtils.openMMWithAds(this, localMovieMessages.get(0).getPlayPath(), null);
890 } 947 }
891 } 948 }
  949 +
  950 + //---------------------------about switch-----------------------------------
  951 + private boolean findHub = false;
  952 + private boolean findSwitch = false;
  953 +
  954 + void initSwitch() {
  955 + FistJni fistJni = FistJni.getInstance();
  956 + fistJni.startSdk();
  957 + fistJni.searchLocalDevice();
  958 + }
  959 +
  960 + @Subscribe(threadMode = ThreadMode.MAIN)
  961 + public void onMoonEvent(SwitchMessageEvent switchMessageEvent) {
  962 + switch (switchMessageEvent.getEventId()) {
  963 + case FistJni.DEVICE_HUBS_ONLINE_NOTIFY:
  964 + case FistProtocol.CommondType.CMD_TYPE_SEARCH_RESPONSE:
  965 + Log.d("qnbar_switch", switchMessageEvent.getMessage());
  966 + for (Device device : FistJni.getHubs()) {
  967 + if (device.getStringDeviceNum().equals(deviceNum)) {
  968 + findHub = true;
  969 + FistJni fistJni = FistJni.getInstance();
  970 + fistJni.query(new Gson().toJson(device));
  971 + break;
  972 + }
  973 + }
  974 +// hubAdapter.notifyDataSetChanged();
  975 + break;
  976 + case FistJni.DEVICE_SWITCH_ONLINE_NOTIFY:
  977 + case FistProtocol.CommondType.CMD_TYPE_QUERY_RESPONSE:
  978 + Log.d("qnbar_switch", switchMessageEvent.getMessage());
  979 + for (SubDevice subDevice : FistJni.getSubDevices()) {
  980 + if (subDevice.getSubDeviceNum() == switchNum) {
  981 + findSwitch = true;
  982 + break;
  983 + }
  984 + }
  985 +// switchAdapter.notifyDataSetChanged();
  986 + break;
  987 + case FistJni.DEVICE_SWITCH_ADD_OVER:
  988 + case FistProtocol.CommondType.CMD_TYPE_ADD_OVER:
  989 + Log.d("qnbar_switch", switchMessageEvent.getMessage());
  990 +// toast("设备添加完成");
  991 + break;
  992 + case FistProtocol.CommondType.CMD_TYPE_ADD_OVER_RESPONSE:
  993 + Log.d("qnbar_switch", switchMessageEvent.getMessage());
  994 +// toast("子设备有变动");
  995 + break;
  996 + default:
  997 + Log.d("qnbar_switch", "default:" + switchMessageEvent.getMessage() + "," + switchMessageEvent.getEventId());
  998 + break;
  999 + }
  1000 + }
  1001 + //---------------------------about switch-----------------------------------
892 } 1002 }
@@ -23,6 +23,7 @@ import android.widget.Toast; @@ -23,6 +23,7 @@ import android.widget.Toast;
23 import com.gimi.common.cinema.model.SambaMsg; 23 import com.gimi.common.cinema.model.SambaMsg;
24 import com.gimi.common.cinema.utils.T; 24 import com.gimi.common.cinema.utils.T;
25 import com.gimi.common.cinema.utils.WifiApManger; 25 import com.gimi.common.cinema.utils.WifiApManger;
  26 +import com.qnbar.switchcontrol.SwitchControlActivity;
26 import com.xgimi.gimicinema.BuildConfig; 27 import com.xgimi.gimicinema.BuildConfig;
27 import com.xgimi.gimicinema.R; 28 import com.xgimi.gimicinema.R;
28 import com.xgimi.gimicinema.mview.ISettingView; 29 import com.xgimi.gimicinema.mview.ISettingView;
@@ -320,4 +321,9 @@ public class SettingActivity extends BaseActivity implements ISettingView { @@ -320,4 +321,9 @@ public class SettingActivity extends BaseActivity implements ISettingView {
320 Intent intent = new Intent(this, com.qnbar.smc.MainActivity.class); 321 Intent intent = new Intent(this, com.qnbar.smc.MainActivity.class);
321 startActivity(intent); 322 startActivity(intent);
322 } 323 }
  324 +
  325 + public void setSmartSwitch(View view) {
  326 + Intent intent = new Intent(this, SwitchControlActivity.class);
  327 + startActivity(intent);
  328 + }
323 } 329 }
@@ -80,7 +80,11 @@ public class SambaModelImpl implements ISambaModel { @@ -80,7 +80,11 @@ public class SambaModelImpl implements ISambaModel {
80 @Override 80 @Override
81 public void doSomeThing() { 81 public void doSomeThing() {
82 CinemaConfig.BASIC_ROOT = msg.getRootPath(); 82 CinemaConfig.BASIC_ROOT = msg.getRootPath();
83 - sambaUtil.mount(ctx, msg); 83 + try {
  84 + sambaUtil.mount(ctx, msg);
  85 + } catch (Exception ex){
  86 + ex.printStackTrace();
  87 + }
84 } 88 }
85 }); 89 });
86 } 90 }
@@ -23,6 +23,7 @@ import android.os.Handler; @@ -23,6 +23,7 @@ import android.os.Handler;
23 import android.os.IBinder; 23 import android.os.IBinder;
24 import android.os.RemoteException; 24 import android.os.RemoteException;
25 import android.util.Log; 25 import android.util.Log;
  26 +import com.gimi.common.cinema.model.MessageEvent;
26 import com.gimi.common.cinema.utils.Utils; 27 import com.gimi.common.cinema.utils.Utils;
27 import com.qnbar.smc.model.Light; 28 import com.qnbar.smc.model.Light;
28 import com.qnbar.smc.model.Lights; 29 import com.qnbar.smc.model.Lights;
@@ -31,6 +32,7 @@ import com.telink.bluetooth.light.ConnectionStatus; @@ -31,6 +32,7 @@ import com.telink.bluetooth.light.ConnectionStatus;
31 import com.telink.bluetooth.light.DeviceInfo; 32 import com.telink.bluetooth.light.DeviceInfo;
32 import com.xgimi.gimicinema.ICinemaControl; 33 import com.xgimi.gimicinema.ICinemaControl;
33 import com.xgimi.gimicinema.application.FangTangApplication; 34 import com.xgimi.gimicinema.application.FangTangApplication;
  35 +import org.greenrobot.eventbus.EventBus;
34 36
35 import java.util.ArrayList; 37 import java.util.ArrayList;
36 import java.util.List; 38 import java.util.List;
@@ -92,6 +94,10 @@ public class CinemaControlService extends Service { @@ -92,6 +94,10 @@ public class CinemaControlService extends Service {
92 switch (state) { 94 switch (state) {
93 case 0://空闲 95 case 0://空闲
94 fadeIn(); 96 fadeIn();
  97 + MessageEvent msgEvent = new MessageEvent();
  98 + msgEvent.setEventId(0x19910);
  99 + msgEvent.setMessage("close_switch");
  100 + EventBus.getDefault().post(msgEvent);
95 break; 101 break;
96 case 1://播放 102 case 1://播放
97 fadeOut(); 103 fadeOut();
@@ -36,6 +36,8 @@ @@ -36,6 +36,8 @@
36 android:id="@+id/promoteTv" 36 android:id="@+id/promoteTv"
37 android:visibility="visible" 37 android:visibility="visible"
38 android:padding="5dp" 38 android:padding="5dp"
  39 + android:paddingStart="10dp"
  40 + android:paddingEnd="10dp"
39 android:gravity="center" 41 android:gravity="center"
40 android:background="@color/dark_background" 42 android:background="@color/dark_background"
41 android:layout_gravity="right"/> 43 android:layout_gravity="right"/>
@@ -188,6 +188,12 @@ @@ -188,6 +188,12 @@
188 android:text="@string/set_sm_light"/> 188 android:text="@string/set_sm_light"/>
189 189
190 <Button style="@style/GeneralTextViewTheme" 190 <Button style="@style/GeneralTextViewTheme"
  191 + android:onClick="setSmartSwitch"
  192 + android:visibility="visible"
  193 + android:textColor="@color/black"
  194 + android:text="设置智能开关"/>
  195 +
  196 + <Button style="@style/GeneralTextViewTheme"
191 android:onClick="update1905Movies" 197 android:onClick="update1905Movies"
192 android:visibility="invisible" 198 android:visibility="invisible"
193 android:textColor="@color/black" 199 android:textColor="@color/black"
1 -include ':transitionhelper', ':uil', ':volley', ':pinying', ':debug-db' 1 +include ':transitionhelper', ':uil', ':volley', ':pinying', ':debug-db', ':switchcontrollib'
2 include ':BluetoothLightLib' 2 include ':BluetoothLightLib'
3 include ':gimiCinema' 3 include ':gimiCinema'
4 include ':switchcontrol' 4 include ':switchcontrol'
1 -<?xml version="1.0" encoding="utf-8"?>  
2 -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
3 - xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main"  
4 - android:layout_width="match_parent" android:layout_height="match_parent"  
5 - android:paddingBottom="@dimen/activity_vertical_margin"  
6 - android:paddingLeft="@dimen/activity_horizontal_margin"  
7 - android:paddingRight="@dimen/activity_horizontal_margin"  
8 - android:paddingTop="@dimen/activity_vertical_margin"  
9 - android:orientation="vertical"  
10 - tools:context="com.qnbar.switchcontrol.MainActivity">  
11 -  
12 - <TextView android:layout_width="wrap_content"  
13 - android:layout_height="wrap_content"  
14 - android:text="Hello World!" />  
15 -  
16 - <Button  
17 - android:layout_width="wrap_content"  
18 - android:layout_height="wrap_content"  
19 - android:onClick="startSdk"  
20 - android:text="startSdk"/>  
21 -  
22 - <Button  
23 - android:layout_width="wrap_content"  
24 - android:layout_height="wrap_content"  
25 - android:onClick="startFist"  
26 - android:text="FindSubDevice"/>  
27 -  
28 - <Button  
29 - android:layout_width="wrap_content"  
30 - android:layout_height="wrap_content"  
31 - android:onClick="searchLocalDevice"  
32 - android:text="searchLocalDevice"/>  
33 -  
34 - <Button  
35 - android:layout_width="wrap_content"  
36 - android:layout_height="wrap_content"  
37 - android:onClick="normalC1"  
38 - android:text="Open Connect Switch"/>  
39 -  
40 - <Button  
41 - android:layout_width="wrap_content"  
42 - android:layout_height="wrap_content"  
43 - android:onClick="normalC"  
44 - android:text="Close Connect Switch"/>  
45 -  
46 -</LinearLayout>  
1 -<?xml version="1.0" encoding="utf-8"?>  
2 -<LinearLayout  
3 - xmlns:android="http://schemas.android.com/apk/res/android"  
4 - xmlns:tools="http://schemas.android.com/tools"  
5 - xmlns:app="http://schemas.android.com/apk/res-auto"  
6 - android:layout_width="match_parent"  
7 - android:layout_height="match_parent"  
8 - android:padding="16dp"  
9 - app:layout_behavior="@string/appbar_scrolling_view_behavior"  
10 - tools:showIn="@layout/activity_switch_control"  
11 - tools:context="com.qnbar.switchcontrol.SwitchControlActivity">  
12 -  
13 - <android.support.v7.widget.RecyclerView  
14 - android:id="@+id/hubsRv"  
15 - android:layout_width="match_parent"  
16 - android:layout_height="wrap_content"  
17 - android:layout_alignParentStart="true"  
18 - android:layout_below="@+id/button" />  
19 -  
20 -</LinearLayout>  
  1 +apply plugin: 'com.android.library'
  2 +apply plugin: 'realm-android'
  3 +
  4 +android {
  5 + compileSdkVersion 25
  6 + buildToolsVersion "25.0.2"
  7 +
  8 + defaultConfig {
  9 + minSdkVersion 18
  10 + targetSdkVersion 25
  11 + versionCode 1
  12 + versionName "1.0"
  13 +
  14 + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  15 +
  16 + }
  17 +
  18 + sourceSets {
  19 + main {
  20 + jniLibs.srcDirs = ['libs']
  21 + }
  22 + }
  23 +
  24 + buildTypes {
  25 + release {
  26 + minifyEnabled false
  27 + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  28 + }
  29 + }
  30 +}
  31 +
  32 +dependencies {
  33 + compile fileTree(dir: 'libs', include: ['*.jar'])
  34 + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
  35 + exclude group: 'com.android.support', module: 'support-annotations'
  36 + })
  37 + compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
  38 + compile 'com.android.support:appcompat-v7:25.2.0'
  39 + compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha4'
  40 + compile 'com.android.support:design:25.2.0'
  41 + compile 'org.greenrobot:eventbus:3.0.0'
  42 + testCompile 'junit:junit:4.12'
  43 +}
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
  1 +# Add project specific ProGuard rules here.
  2 +# By default, the flags in this file are appended to flags specified
  3 +# in /Users/wugian/Documents/android-sdk-macosx/tools/proguard/proguard-android.txt
  4 +# You can edit the include path and order by changing the proguardFiles
  5 +# directive in build.gradle.
  6 +#
  7 +# For more details, see
  8 +# http://developer.android.com/guide/developing/tools/proguard.html
  9 +
  10 +# Add any project specific keep options here:
  11 +
  12 +# If your project uses WebView with JS, uncomment the following
  13 +# and specify the fully qualified class name to the JavaScript interface
  14 +# class:
  15 +#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
  16 +# public *;
  17 +#}
  1 +package com.qnbar.switchcontrol;
  2 +
  3 +import android.content.Context;
  4 +import android.support.test.InstrumentationRegistry;
  5 +import android.support.test.runner.AndroidJUnit4;
  6 +
  7 +import org.junit.Test;
  8 +import org.junit.runner.RunWith;
  9 +
  10 +import static org.junit.Assert.*;
  11 +
  12 +/**
  13 + * Instrumentation test, which will execute on an Android device.
  14 + *
  15 + * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
  16 + */
  17 +@RunWith(AndroidJUnit4.class)
  18 +public class ExampleInstrumentedTest {
  19 + @Test
  20 + public void useAppContext() throws Exception {
  21 + // Context of the app under test.
  22 + Context appContext = InstrumentationRegistry.getTargetContext();
  23 +
  24 + assertEquals("com.qnbar.switchcontrol", appContext.getPackageName());
  25 + }
  26 +}
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3 + package="com.qnbar.switchcontrol">
  4 +
  5 + <uses-permission android:name="android.permission.INTERNET"/>
  6 +
  7 + <application
  8 + android:allowBackup="true"
  9 + android:label="@string/app_name"
  10 + android:supportsRtl="true">
  11 + <activity
  12 + android:name=".SwitchControlActivity"
  13 + android:theme="@style/AppTheme.NoActionBar">
  14 +
  15 + </activity>
  16 + </application>
  17 +
  18 +</manifest>
  1 +package com.adroplat.fist_switch.config;
  2 +
  3 +import android.util.Log;
  4 +
  5 +/**
  6 + * Created by wugian on 2017/3/8.
  7 + */
  8 +
  9 +public class GlobalVar {
  10 + public static final String CHARSET_UTF8 = "utf-8";
  11 + public static final int MAX_BYTE = 0xFF;
  12 + static GlobalVar globalVar = new GlobalVar();
  13 +
  14 +
  15 + public static GlobalVar getLogUtils() {
  16 + return globalVar;
  17 + }
  18 +
  19 + public void i(String s) {
  20 + Log.d("GlobalVar", s);
  21 + }
  22 +}
  1 +package com.adroplat.fist_switch.jni;
  2 +
  3 +
  4 +import com.adroplat.fist_switch.config.GlobalVar;
  5 +import com.adroplat.fist_switch.utils.ByteUtils;
  6 +
  7 +import java.io.Serializable;
  8 +import java.io.UnsupportedEncodingException;
  9 +import java.util.ArrayList;
  10 +
  11 +/**
  12 + * Created by WLJ on 16-3-8.
  13 + */
  14 +public class Device implements Serializable, Cloneable {
  15 + private static final long serialVersionUID = -1055014034866886590L;
  16 +
  17 + private static Device instance;
  18 +
  19 + private Device() {
  20 + }
  21 +
  22 + public static Device getInstance() {
  23 + if (null == instance) {
  24 + instance = new Device();
  25 + }
  26 + Device hub;
  27 + try {
  28 + hub = (Device) instance.clone();
  29 + } catch (CloneNotSupportedException e) {
  30 + hub = new Device();
  31 + }
  32 + return hub;
  33 + }
  34 +
  35 + /**
  36 + * 控制ID
  37 + */
  38 + private long ControllerId;
  39 + /**
  40 + * 命令类型
  41 + */
  42 + private int CmdType;
  43 + /**
  44 + * 错误码
  45 + */
  46 + private byte ErrorCode;
  47 + /**
  48 + * 设备IP
  49 + */
  50 + private byte[] DeviceIp;
  51 + /**
  52 + * 设备端口
  53 + */
  54 + private int DevicePort;
  55 + /**
  56 + * 设备公网IP
  57 + */
  58 + private byte[] MappedIp;
  59 + /**
  60 + * 设备公网端口
  61 + */
  62 + private int MappedPort;
  63 + /**
  64 + * 设备号
  65 + */
  66 + private byte[] DeviceNum;
  67 + /**
  68 + * 设备口令
  69 + */
  70 + private byte[] DeviceKey;
  71 + /**
  72 + * 是否是广域网控制
  73 + */
  74 + private boolean IsWan;
  75 + /**
  76 + * 子设备
  77 + */
  78 + private ArrayList<SubDevice> SubDevices;
  79 +
  80 + public long getControllerId() {
  81 + return ControllerId;
  82 + }
  83 +
  84 + public void setControllerId(long controllerId) {
  85 + ControllerId = controllerId;
  86 + }
  87 +
  88 + public int getCmdType() {
  89 + return CmdType;
  90 + }
  91 +
  92 + public void setCmdType(int cmdType) {
  93 + CmdType = cmdType;
  94 + }
  95 +
  96 + public byte getErrorCode() {
  97 + return ErrorCode;
  98 + }
  99 +
  100 + public void setErrorCode(byte errorCode) {
  101 + ErrorCode = errorCode;
  102 + }
  103 +
  104 + public byte[] getDeviceIp() {
  105 + return DeviceIp;
  106 + }
  107 +
  108 + public String getStringDeviceIp() {
  109 + String strIp = "null";
  110 + if (null != DeviceIp) {
  111 + char point = '.';
  112 + StringBuilder builder = new StringBuilder();
  113 + for (byte b : DeviceIp) {
  114 + builder.append((b & GlobalVar.MAX_BYTE)).append(point);
  115 + }
  116 + builder.deleteCharAt(builder.length() - 1);
  117 + strIp = builder.toString();
  118 + }
  119 + return strIp;
  120 + }
  121 +
  122 + public void setDeviceIp(byte[] deviceIp) {
  123 + DeviceIp = deviceIp;
  124 + }
  125 +
  126 + public int getDevicePort() {
  127 + return DevicePort;
  128 + }
  129 +
  130 + public void setDevicePort(int devicePort) {
  131 + DevicePort = devicePort;
  132 + }
  133 +
  134 + public byte[] getMappedIp() {
  135 + return MappedIp;
  136 + }
  137 +
  138 + public void setMappedIp(byte[] mappedIp) {
  139 + MappedIp = mappedIp;
  140 + }
  141 +
  142 + public int getMappedPort() {
  143 + return MappedPort;
  144 + }
  145 +
  146 + public void setMappedPort(int mappedPort) {
  147 + MappedPort = mappedPort;
  148 + }
  149 +
  150 + public byte[] getDeviceNum() {
  151 + return DeviceNum;
  152 + }
  153 +
  154 + //添加 转化成16进制显示 17.03.23
  155 + public String getStringDeviceNum() {
  156 + String strIp = "null";
  157 + if (null != DeviceNum) {
  158 + char point = ':';
  159 + StringBuilder builder = new StringBuilder();
  160 + for (byte b : DeviceNum) {
  161 + builder.append(decimal2hex(b & GlobalVar.MAX_BYTE)).append(point);
  162 + }
  163 + builder.deleteCharAt(builder.length() - 1);
  164 + strIp = builder.toString();
  165 + }
  166 + return strIp;
  167 + }
  168 + // precondition: d is a nonnegative integer
  169 + public static String decimal2hex(int d) {
  170 + String digits = "0123456789ABCDEF";
  171 + if (d <= 0) return "00";
  172 + int base = 16; // flexible to change in any base under 16
  173 + String hex = "";
  174 + while (d > 0) {
  175 + int digit = d % base; // rightmost digit
  176 + hex = digits.charAt(digit) + hex; // string concatenation
  177 + d = d / base;
  178 + }
  179 + return hex;
  180 + }
  181 +
  182 + public void setDeviceNum(byte[] deviceNum) {
  183 + DeviceNum = deviceNum;
  184 + }
  185 +
  186 + public byte[] getDeviceKey() {
  187 + return DeviceKey;
  188 + }
  189 +
  190 + public String getDeviceStrKey() {
  191 + String strKey = "";
  192 + try {
  193 + strKey = new String(DeviceKey, GlobalVar.CHARSET_UTF8);
  194 + } catch (UnsupportedEncodingException e) {
  195 + e.printStackTrace();
  196 + }
  197 + return strKey;
  198 + }
  199 +
  200 + public void setDeviceKey(byte[] deviceKey) {
  201 + DeviceKey = deviceKey;
  202 + }
  203 +
  204 + public boolean isWan() {
  205 + return IsWan;
  206 + }
  207 +
  208 + public void setWan(boolean wan) {
  209 + IsWan = wan;
  210 + }
  211 +
  212 + public ArrayList<SubDevice> getSubDevices() {
  213 + return SubDevices;
  214 + }
  215 +
  216 + public void setSubDevices(ArrayList<SubDevice> subDevices) {
  217 + this.SubDevices = subDevices;
  218 + }
  219 +
  220 + /**
  221 + * DeviceNum转换成long
  222 + *
  223 + * @return
  224 + */
  225 + public long getLongDeviceNum() {
  226 + return ByteUtils.macArrayToLong(DeviceNum);
  227 + }
  228 +
  229 + /**
  230 + * DeviceKey转换成long
  231 + *
  232 + * @return
  233 + */
  234 + public long getLongDeviceKey() {
  235 + return ByteUtils.macArrayToLong(DeviceKey);
  236 + }
  237 +
  238 + /**
  239 + * MappedIp转换成int
  240 + *
  241 + * @return
  242 + */
  243 + public int getIntMappedIp() {
  244 + return ByteUtils.byteArrayToInt(MappedIp);
  245 + }
  246 +
  247 + /**
  248 + * DeviceIp转换成int
  249 + *
  250 + * @return
  251 + */
  252 + public int getIntDeviceIp() {
  253 + return ByteUtils.byteArrayToInt(DeviceIp);
  254 + }
  255 +}
  1 +package com.adroplat.fist_switch.jni;
  2 +
  3 +import java.util.List;
  4 +
  5 +/**
  6 + * Created by wugian on 2017/3/22
  7 + */
  8 +public class Device1 {
  9 + /**
  10 + * CmdType : 17
  11 + * ErrorCode : 0
  12 + * DeviceIp : [192,168,31,163]
  13 + * DeviceNum : [255,255,255,255,0,255]
  14 + * DeviceKey : [120,56,53,98,97,117]
  15 + * DevicePort : 9000
  16 + * MappedIp : [0,0,0,0]
  17 + * MappedPort : 0
  18 + * SubDevices : [{"SubDeviceNum":4294967151,"SubDeviceType":33,"SubDeviceStatus":0,"SubDeviceOnlineStatus":0,"SubDeviceBit":0}]
  19 + */
  20 +
  21 + private int CmdType;
  22 + private int ErrorCode;
  23 + private int DevicePort;
  24 + private int MappedPort;
  25 + private List<Integer> DeviceIp;
  26 + private List<Integer> DeviceNum;
  27 + private List<Integer> DeviceKey;
  28 + private List<Integer> MappedIp;
  29 + private List<SubDevicesEntity> SubDevices;
  30 +
  31 + public int getCmdType() {
  32 + return CmdType;
  33 + }
  34 +
  35 + public void setCmdType(int CmdType) {
  36 + this.CmdType = CmdType;
  37 + }
  38 +
  39 + public int getErrorCode() {
  40 + return ErrorCode;
  41 + }
  42 +
  43 + public void setErrorCode(int ErrorCode) {
  44 + this.ErrorCode = ErrorCode;
  45 + }
  46 +
  47 + public int getDevicePort() {
  48 + return DevicePort;
  49 + }
  50 +
  51 + public void setDevicePort(int DevicePort) {
  52 + this.DevicePort = DevicePort;
  53 + }
  54 +
  55 + public int getMappedPort() {
  56 + return MappedPort;
  57 + }
  58 +
  59 + public void setMappedPort(int MappedPort) {
  60 + this.MappedPort = MappedPort;
  61 + }
  62 +
  63 + public List<Integer> getDeviceIp() {
  64 + return DeviceIp;
  65 + }
  66 +
  67 + public void setDeviceIp(List<Integer> DeviceIp) {
  68 + this.DeviceIp = DeviceIp;
  69 + }
  70 +
  71 + public List<Integer> getDeviceNum() {
  72 + return DeviceNum;
  73 + }
  74 +
  75 + public void setDeviceNum(List<Integer> DeviceNum) {
  76 + this.DeviceNum = DeviceNum;
  77 + }
  78 +
  79 + public List<Integer> getDeviceKey() {
  80 + return DeviceKey;
  81 + }
  82 +
  83 + public void setDeviceKey(List<Integer> DeviceKey) {
  84 + this.DeviceKey = DeviceKey;
  85 + }
  86 +
  87 + public List<Integer> getMappedIp() {
  88 + return MappedIp;
  89 + }
  90 +
  91 + public void setMappedIp(List<Integer> MappedIp) {
  92 + this.MappedIp = MappedIp;
  93 + }
  94 +
  95 + public List<SubDevicesEntity> getSubDevices() {
  96 + return SubDevices;
  97 + }
  98 +
  99 + public void setSubDevices(List<SubDevicesEntity> SubDevices) {
  100 + this.SubDevices = SubDevices;
  101 + }
  102 +
  103 + public static class SubDevicesEntity {
  104 + /**
  105 + * SubDeviceNum : 4294967151
  106 + * SubDeviceType : 33
  107 + * SubDeviceStatus : 0
  108 + * SubDeviceOnlineStatus : 0
  109 + * SubDeviceBit : 0
  110 + */
  111 + private long SubDeviceNum;
  112 + private int SubDeviceType;
  113 + private int SubDeviceStatus;
  114 + private int SubDeviceOnlineStatus;
  115 + private int SubDeviceBit;
  116 +
  117 + public long getSubDeviceNum() {
  118 + return SubDeviceNum;
  119 + }
  120 +
  121 + public void setSubDeviceNum(long SubDeviceNum) {
  122 + this.SubDeviceNum = SubDeviceNum;
  123 + }
  124 +
  125 + public int getSubDeviceType() {
  126 + return SubDeviceType;
  127 + }
  128 +
  129 + public void setSubDeviceType(int SubDeviceType) {
  130 + this.SubDeviceType = SubDeviceType;
  131 + }
  132 +
  133 + public int getSubDeviceStatus() {
  134 + return SubDeviceStatus;
  135 + }
  136 +
  137 + public void setSubDeviceStatus(int SubDeviceStatus) {
  138 + this.SubDeviceStatus = SubDeviceStatus;
  139 + }
  140 +
  141 + public int getSubDeviceOnlineStatus() {
  142 + return SubDeviceOnlineStatus;
  143 + }
  144 +
  145 + public void setSubDeviceOnlineStatus(int SubDeviceOnlineStatus) {
  146 + this.SubDeviceOnlineStatus = SubDeviceOnlineStatus;
  147 + }
  148 +
  149 + public int getSubDeviceBit() {
  150 + return SubDeviceBit;
  151 + }
  152 +
  153 + public void setSubDeviceBit(int SubDeviceBit) {
  154 + this.SubDeviceBit = SubDeviceBit;
  155 + }
  156 + }
  157 +}
  1 +package com.adroplat.fist_switch.jni;
  2 +
  3 +import android.content.Intent;
  4 +import android.os.AsyncTask;
  5 +import android.text.TextUtils;
  6 +import android.util.Log;
  7 +import com.adroplat.fist_switch.config.GlobalVar;
  8 +import com.adroplat.fist_switch.utils.ToastUtils;
  9 +import com.adroplat.fist_switch.utils.WifiUtils;
  10 +import com.adroplat.fist_switch.utils.protocol.one.FistProtocol;
  11 +import com.google.gson.Gson;
  12 +import com.qnbar.switchcontrol.model.SwitchMessageEvent;
  13 +import io.realm.Realm;
  14 +import org.greenrobot.eventbus.EventBus;
  15 +
  16 +import java.util.ArrayList;
  17 +import java.util.Arrays;
  18 +
  19 +/**
  20 + * Created by WLJ on 2016/1/14.
  21 + */
  22 +public class FistJni {
  23 + private static final String TAG = FistJni.class.getSimpleName();
  24 +
  25 + public static final int DEVICE_HUBS_ONLINE_NOTIFY = 0x7101;
  26 + private static final String DEVICE_HUBS_ONLINE_NOTIFY_STR = "DEVICE_HUBS_ONLINE_NOTIFY_STR";
  27 + public static final int DEVICE_SWITCH_ONLINE_NOTIFY = 0x7102;
  28 + private static final String DEVICE_SWITCH_ONLINE_NOTIFY_STR = "DEVICE_SWITCH_ONLINE_NOTIFY_STR";
  29 +
  30 + public static final int DEVICE_SWITCH_ADD_OVER = 0x7103;
  31 + private static final String DEVICE_SWITCH_ADD_OVER_STR = "DEVICE_SWITCH_ADD_OVER_STR";
  32 +
  33 + static {
  34 + System.loadLibrary("fist_ndk");
  35 + }
  36 +
  37 + private static FistJni instance;
  38 +
  39 + private FistJni() {
  40 + }
  41 +
  42 + public static FistJni getInstance() {
  43 + if (null == instance) {
  44 + instance = new FistJni();
  45 + }
  46 + return instance;
  47 + }
  48 +
  49 + private static Intent intent;
  50 +
  51 + public static Intent getIntent() {
  52 + intent = new Intent();
  53 + return intent;
  54 + }
  55 +
  56 + public static final String CONFIG_DONE = "CONFIG_DONE";
  57 + public static final String SEARCH_RESPONSE = "SEARCH_RESPONSE";
  58 + public static final String LINK_STATUS_RESPONSE = "LINK_STATUS_RESPONSE";
  59 + public static final String LINK_RESPONSE = "LINK_RESPONSE";
  60 + public static final String CTRL_PWD_RESPONSE = "CTRL_PWD_RESPONSE";
  61 + public static final String START_ADD = "START_ADD";
  62 + public static final String STOP_ADD = "STOP_ADD";
  63 + public static final String ADD_DONE = "ADD_DONE";
  64 + public static final String CONTROL_REQUEST_TIMEOUT = "CONTROL_REQUEST_TIMEOUT";
  65 + public static final String CONTROL_RESPONSE = "CONTROL_RESPONSE";
  66 + public static final String CONTROL_DONE = "CONTROL_DONE";
  67 + public static final String CONTROL_OVER = "CONTROL_OVER";
  68 + public static final String BYTE_ERROR_CODE = "BYTE_ERROR_CODE";
  69 + public static final String JSON_DEVICE = "JSON_DEVICE";
  70 +
  71 + private static void configDone(Device device) {
  72 +// sendJsonDevice(CONFIG_DONE, device);
  73 + }
  74 +
  75 + private static ArrayList<Device> hubs;
  76 +
  77 + public static ArrayList<Device> getHubs() {
  78 + if (hubs == null) {
  79 + hubs = new ArrayList<>();
  80 + }
  81 + return hubs;
  82 + }
  83 +
  84 + private static ArrayList<SubDevice> subDevices;
  85 +
  86 + public static ArrayList<SubDevice> getSubDevices() {
  87 + if (subDevices == null) {
  88 + subDevices = new ArrayList<>();
  89 + }
  90 + return subDevices;
  91 + }
  92 +
  93 + private static void online(Device device, String jsonDevice) {
  94 +// boolean hasAdded = false;
  95 + for (Device device1 : getHubs()) {
  96 + if (Arrays.equals(device1.getDeviceIp(), device.getDeviceIp())) {
  97 +// hasAdded = true;
  98 + getHubs().remove(device1);
  99 + break;
  100 + }
  101 + }
  102 +// if (!hasAdded) {
  103 + getHubs().add(device);
  104 +// }
  105 +// sendMessage(DEVICE_HUBS_ONLINE_NOTIFY, DEVICE_HUBS_ONLINE_NOTIFY_STR);
  106 + }
  107 +
  108 + private static void sendMessage(int type, String typeStr) {
  109 + SwitchMessageEvent switchMessageEvent = new SwitchMessageEvent();
  110 + switchMessageEvent.setEventId(type);
  111 + switchMessageEvent.setMessage(typeStr);
  112 + EventBus.getDefault().post(switchMessageEvent);
  113 + }
  114 +
  115 + private static void saveRemote(Device device) {
  116 + if (null == device) return;
  117 + Realm realm = Realm.getDefaultInstance();
  118 +// Hub host = realm.where(Hub.class)
  119 +// .equalTo(Hub.Companion.getDEVICE_NUM(), device.getLongDeviceNum()).findFirst();
  120 +// if (null != host) {//已存储,更新IP,查询子设备
  121 +// realm.beginTransaction();
  122 +// host.setMapIp(device.getIntMappedIp());
  123 +// host.setMapPort(device.getMappedPort());
  124 +// host.setPeerIp(device.getIntDeviceIp());
  125 +// host.setPeerPort(device.getDevicePort());
  126 +// host.setLAN(false);
  127 +// host.setAlreadyHaveRemoteIP(true);
  128 +// realm.commitTransaction();
  129 +// }
  130 + realm.close();
  131 + }
  132 +
  133 + private static Gson gson;
  134 +
  135 + public static Gson getGson() {
  136 + if (null == gson) {
  137 + gson = new Gson();
  138 + }
  139 + return gson;
  140 + }
  141 +
  142 +// /**
  143 +// * 发送广播
  144 +// *
  145 +// * @param action
  146 +// * @param device
  147 +// */
  148 +// private static void sendJsonDevice(String action, Device device) {
  149 +// if (null == action || action.isEmpty() || null == device) return;
  150 +// Context context = SwitchApplication.getAppContext();
  151 +// if (null == context) return;
  152 +// Intent intent = getIntent();
  153 +// intent.setAction(action);
  154 +// intent.putExtra(JSON_DEVICE, device);
  155 +// LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
  156 +// }
  157 +
  158 + /**
  159 + * 发送消息
  160 + *
  161 + * @param type
  162 + * @param msg
  163 + */
  164 + private static void sendJsonDevice(int type, String msg) {
  165 + if (TextUtils.isEmpty(msg)) {
  166 + return;
  167 + }
  168 + sendMessage(type, msg);
  169 + }
  170 +
  171 + public static void fistListener(String jsonDevice) {
  172 + if (null == jsonDevice || jsonDevice.isEmpty()) return;
  173 + Log.d(TAG, jsonDevice);
  174 + Gson gson = getGson();
  175 + Device device = gson.fromJson(jsonDevice, Device.class);
  176 + char cmdTpye = (char) device.getCmdType();
  177 +// qnbar_switch
  178 + Log.d("qnbar_switch", "cmdType:" + device.getCmdType() + "");
  179 + if (FistProtocol.CommondType.CMD_TYPE_SEARCH_RESPONSE == cmdTpye) {//查询响应
  180 + removeId(device);
  181 + online(device, jsonDevice);
  182 +// sendJsonDevice(SEARCH_RESPONSE, device);
  183 + sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_SEARCH_RESPONSE, SEARCH_RESPONSE);
  184 + } else if (FistProtocol.CommondType.CMD_TYPE_CONFIG_DONE == cmdTpye) {//配置完成处理
  185 +// configDone(device);
  186 + sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_CONFIG_DONE, CONFIG_DONE);
  187 +
  188 + } else if (FistProtocol.CommondType.CMD_TYPE_ONLINE == cmdTpye) {//上线通知
  189 + removeId(device);
  190 + online(device, jsonDevice);
  191 +// configDone(device);
  192 + sendMessage(FistProtocol.CommondType.CMD_TYPE_CONFIG_DONE, CONFIG_DONE);
  193 + } else if (FistProtocol.CommondType.CMD_TYPE_QUERY_RESPONSE == cmdTpye) {
  194 +// sendJsonDevice(ADD_DONE, device);
  195 + ArrayList<SubDevice> subDevices = device.getSubDevices();
  196 + if (!subDevices.isEmpty()) {//查询结果不为空
  197 + subDeviceOnline(subDevices);
  198 +// getSubDevices().addAll(subDevices);
  199 +// sendMessage(DEVICE_SWITCH_ONLINE_NOTIFY, DEVICE_SWITCH_ONLINE_NOTIFY_STR);
  200 + }
  201 +// sendJsonDevice(LightingGroupAdapter.REFRESH, device);
  202 + sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_QUERY_RESPONSE, DEVICE_SWITCH_ONLINE_NOTIFY_STR);
  203 +
  204 + } else if (FistProtocol.CommondType.CMD_TYPE_ADD_RESPONSE == cmdTpye) {
  205 +// sendJsonDevice(START_ADD, device);
  206 +// FistJni.stopAddSubDevice(jsonDevice);
  207 + device.setCmdType(49);
  208 + getInstance().query(gson.toJson(device));
  209 +// getInstance().query(gson.toJson(device));
  210 +
  211 + FistJni.stopAddSubDevice(jsonDevice);
  212 + sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_ADD_RESPONSE, START_ADD);
  213 +
  214 + } else if (FistProtocol.CommondType.CMD_TYPE_ADD_OVER == cmdTpye) {//子设备结束入网
  215 + if (0 == device.getIntDeviceIp()) return;
  216 + device.setCmdType(49);
  217 +// getInstance().query(gson.toJson(device));
  218 + getInstance().query(gson.toJson(device));
  219 + FistJni.stopAddSubDevice(jsonDevice);
  220 +// sendMessage(DEVICE_SWITCH_ADD_OVER, DEVICE_SWITCH_ADD_OVER_STR);
  221 + sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_ADD_OVER, ADD_DONE);
  222 +
  223 +// getInstance().query(jsonDevice);
  224 + } else if (FistProtocol.CommondType.CMD_TYPE_ADD_OVER_RESPONSE == cmdTpye) {
  225 +// sendJsonDevice(CONTROL_REQUEST_TIMEOUT, device);
  226 + sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_ADD_OVER_RESPONSE, "CMD_TYPE_ADD_OVER_RESPONSE");
  227 +
  228 + }else if (FistProtocol.CommondType.CMD_TYPE_CONTROL == cmdTpye) {//控制超时
  229 +// sendJsonDevice(CONTROL_REQUEST_TIMEOUT, device);
  230 + sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_CONTROL, CONTROL_REQUEST_TIMEOUT);
  231 +
  232 + } else if (FistProtocol.CommondType.CMD_TYPE_CONTROL_RESPONSE == cmdTpye) {//控制应答
  233 +// sendJsonDevice(CONTROL_RESPONSE, device);
  234 + sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_CONTROL_RESPONSE, CONTROL_RESPONSE);
  235 +
  236 + } else if (FistProtocol.CommondType.CMD_TYPE_CONTROL_DONE_RESPONSE == cmdTpye) {//单个控制结果
  237 +// sendJsonDevice(CONTROL_DONE, device);
  238 + getInstance().query(getGson().toJson(getHubs().get(0)));
  239 + sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_CONTROL_RESPONSE, CONFIG_DONE);
  240 +// ArrayList<SubDevice> subDevices = device.getSubDevices();
  241 +// if (!subDevices.isEmpty()) {//查询结果不为空
  242 +// subDeviceOnline(subDevices);
  243 +//// getSubDevices().addAll(subDevices);
  244 +//// sendMessage(DEVICE_SWITCH_ONLINE_NOTIFY, DEVICE_SWITCH_ONLINE_NOTIFY_STR);
  245 +// }
  246 + } else if (FistProtocol.CommondType.CMD_TYPE_CONTROL_OVER == cmdTpye) {
  247 +// sendJsonDevice(CONTROL_OVER, device);
  248 + sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_CONTROL_OVER, CONTROL_OVER);
  249 +// GlobalVar.getLogUtils().i("CONTROL_OVER");
  250 + } else if (FistProtocol.CommondType.CMD_NET_LINK_STATUS_RESPONSE == cmdTpye) {
  251 + sendJsonDevice(FistProtocol.CommondType.CMD_NET_LINK_STATUS_RESPONSE, LINK_STATUS_RESPONSE);
  252 +// sendJsonDevice(LINK_STATUS_RESPONSE, device);
  253 +
  254 + } else if (FistProtocol.CommondType.CMD_LINK_RESPONSE == cmdTpye) {
  255 + sendJsonDevice(FistProtocol.CommondType.CMD_LINK_RESPONSE, LINK_RESPONSE);
  256 +// sendJsonDevice(LINK_RESPONSE, device);
  257 +
  258 + } else if (FistProtocol.CommondType.CMD_MODIFY_CTRL_PWD_RESPONSE == cmdTpye) {
  259 +// GlobalVar.getLogUtils().i("FistProtocol.CommondType.CMD_MODIFY_CTRL_PWD_RESPONSE");
  260 + sendJsonDevice(FistProtocol.CommondType.CMD_MODIFY_CTRL_PWD_RESPONSE, CTRL_PWD_RESPONSE);
  261 +// sendJsonDevice(CTRL_PWD_RESPONSE, device);
  262 +
  263 + } /*else if (RemoteProtocol.MsgType.SET_SUCCESS == cmdTpye) {//密码设置成功
  264 + GlobalVar.getLogUtils().i("SET_SUCCESS jsonDevice =" + jsonDevice);
  265 + long deviceNum = device.getLongDeviceNum();
  266 + Realm realm = Realm.getDefaultInstance();
  267 + Hub host = realm.where(Hub.class).equalTo(Hub.Companion.getDEVICE_NUM(), deviceNum).findFirst();
  268 + if (null != host) {
  269 + realm.beginTransaction();
  270 + host.setWanState(WanState.ON);
  271 + realm.commitTransaction();
  272 + }
  273 + realm.close();
  274 + } else if (RemoteProtocol.MsgType.SET_FAILED == cmdTpye) {//密码设置失败
  275 + GlobalVar.getLogUtils().i("SET_FAILED jsonDevice =" + jsonDevice);
  276 +
  277 + } else if (RemoteProtocol.MsgType.QUERY_SUCCESS == cmdTpye) {//查询对端成功
  278 + final long deviceNum = device.getLongDeviceNum();
  279 + ArrayList<Long> ids = HeService.getLocIds();
  280 + for (long id : ids) {
  281 + if (deviceNum == id) {
  282 + saveRemote(device);
  283 + device.setWan(true);
  284 + jsonDevice = gson.toJson(device);
  285 + querySubDevice(jsonDevice);
  286 + break;
  287 + }
  288 + }
  289 + removeId(device);
  290 +
  291 + } else if (RemoteProtocol.MsgType.QUERY_FAILED == cmdTpye) {//查询对端失败
  292 +
  293 + }*/
  294 + }
  295 +
  296 + private static void subDeviceOnline(ArrayList<SubDevice> subDevices) {
  297 + for (SubDevice subDevice : subDevices) {
  298 +// boolean hasAdd = false;
  299 + for (SubDevice subDevice1 : getSubDevices()) {
  300 + if (subDevice.getSubDeviceNum() == subDevice1.getSubDeviceNum()) {
  301 +// hasAdd = true;
  302 + getSubDevices().remove(subDevice1);
  303 + break;
  304 + }
  305 + }
  306 +// if (!hasAdd) {
  307 + getSubDevices().add(subDevice);
  308 +// sendMessage(DEVICE_SWITCH_ONLINE_NOTIFY, DEVICE_SWITCH_ONLINE_NOTIFY_STR);
  309 +// }
  310 + }
  311 + }
  312 +
  313 + /**
  314 + * 开始
  315 + */
  316 + public static native void start();
  317 +
  318 + /**
  319 + * 启动SKD
  320 + */
  321 + public void startSdk() {
  322 + new AsyncTask<Void, Void, Void>() {
  323 + @Override
  324 + protected Void doInBackground(Void... params) {
  325 + start();
  326 + Log.d(TAG, "start sdk");
  327 + return null;
  328 + }
  329 + }.execute();
  330 + }
  331 +
  332 + /**
  333 + * 移除查询到的主机ID
  334 + *
  335 + * @param device
  336 + */
  337 + private static void removeId(Device device) {
  338 +// ArrayList<Long> ids = HeService.getLocIds();
  339 +// final long deviceNum = device.getLongDeviceNum();
  340 +// for (long id : ids) {
  341 +// if (deviceNum == id) {
  342 +// ids.remove(id);
  343 +// break;
  344 +// }
  345 +// }
  346 + }
  347 +
  348 + /**
  349 + * 搜索设备
  350 + */
  351 + public static native void searchDevice();
  352 +
  353 + /**
  354 + * 查询子设备
  355 + */
  356 + public static native void querySubDevice(String jsonDevice);
  357 +
  358 + public void query(final String jsonDevice) {
  359 +// if (!HeService.isConn()) {
  360 +// return;
  361 +// }
  362 + new AsyncTask<Void, Void, Void>() {
  363 + @Override
  364 + protected Void doInBackground(Void... params) {
  365 + querySubDevice(jsonDevice);
  366 + return null;
  367 + }
  368 + }.execute();
  369 + }
  370 +
  371 + /**
  372 + * 开始添加子设备
  373 + */
  374 + public static native void startAddSubDevice(String jsonDevice);
  375 +
  376 + public void startAdd(final String jsonDevice) {
  377 + if (!(WifiUtils.isWifiConnected())) {
  378 + ToastUtils.toastShort("网络未连接");
  379 + return;
  380 + }
  381 + new AsyncTask<Void, Void, Void>() {
  382 + @Override
  383 + protected Void doInBackground(Void... params) {
  384 + startAddSubDevice(jsonDevice);
  385 + return null;
  386 + }
  387 + }.execute();
  388 + }
  389 +
  390 + /**
  391 + * 停止添加子设备
  392 + */
  393 + public static native void stopAddSubDevice(String jsonDevice);
  394 +
  395 + public void stopAdd(final String jsonDevice) {
  396 + if (!(WifiUtils.isWifiConnected())) {
  397 + ToastUtils.toastShort("网络未连接");
  398 + return;
  399 + }
  400 + new AsyncTask<Void, Void, Void>() {
  401 + @Override
  402 + protected Void doInBackground(Void... params) {
  403 + stopAddSubDevice(jsonDevice);
  404 + return null;
  405 + }
  406 + }.execute();
  407 + }
  408 +
  409 + /**
  410 + * 删除子设备
  411 + */
  412 + public static native void deleteSubDevices(String jsonDevice);
  413 +
  414 + public void delSub(final String jsonDevice) {
  415 +// if (!HeService.isConn()) {
  416 +// ToastUtils.toastShort("网络未连接");
  417 +// return;
  418 +// }
  419 + new AsyncTask<Void, Void, Void>() {
  420 + @Override
  421 + protected Void doInBackground(Void... params) {
  422 + deleteSubDevices(jsonDevice);
  423 + return null;
  424 + }
  425 + }.execute();
  426 + }
  427 +
  428 + /**
  429 + * 查询软件版本
  430 + */
  431 + public static native void querySoftwareVer(String jsonDevice);
  432 +
  433 + /**
  434 + * 查询工作模式
  435 + */
  436 + public static native void queryModel(String jsonDevice);
  437 +
  438 + public void sceneC(final String jsonDevice) {
  439 + if (!(WifiUtils.isWifiConnected())) {
  440 + ToastUtils.toastShort("网络未连接");
  441 + return;
  442 + }
  443 + new AsyncTask<Void, Void, Void>() {
  444 + @Override
  445 + protected Void doInBackground(Void... params) {
  446 + GlobalVar.getLogUtils().i("sceneC jsonDevice =" + jsonDevice);
  447 + sceneControl(jsonDevice);
  448 + return null;
  449 + }
  450 + }.execute();
  451 + }
  452 +
  453 + /**
  454 + * 情景控制
  455 + */
  456 + public static native void sceneControl(String jsonDevice);
  457 +
  458 + public void normalC(final String jsonDevice) {
  459 + if (!(WifiUtils.isWifiConnected())) {
  460 + ToastUtils.toastShort("网络未连接");
  461 + return;
  462 + }
  463 + new AsyncTask<Void, Void, Void>() {
  464 + @Override
  465 + protected Void doInBackground(Void... params) {
  466 + GlobalVar.getLogUtils().i("normalC jsonDevice =" + jsonDevice);
  467 + normalControl(jsonDevice);
  468 + return null;
  469 + }
  470 + }.execute();
  471 + }
  472 +
  473 + /**
  474 + * 普通控制
  475 + */
  476 + private static native void normalControl(String jsonDevice);
  477 +
  478 +
  479 + /**
  480 + * 设置远程密码
  481 + *
  482 + * @param jsonDevice
  483 + * @param pwd
  484 + */
  485 + private static native void setRemotePwd(String jsonDevice, String pwd);
  486 +
  487 + public void setPwd(final String jsonDevice, final String pwd) {
  488 + if (!(WifiUtils.isWifiConnected())) {
  489 + ToastUtils.toastShort("网络未连接");
  490 + return;
  491 + }
  492 + new AsyncTask<Void, Void, Void>() {
  493 + @Override
  494 + protected Void doInBackground(Void... params) {
  495 + setRemotePwd(jsonDevice, pwd);
  496 + return null;
  497 + }
  498 + }.execute();
  499 + }
  500 +
  501 + private static native void getRemoteCtrlIp(String jsonDevice, String random, String pwd);
  502 +
  503 + public void searchRecordDevice() {
  504 +// final ArrayList<Long> ids = HeService.getLocIds();
  505 +// if (ids.isEmpty()) return;
  506 +// new AsyncTask<Void, Void, Void>() {
  507 +//
  508 +// @Override
  509 +// protected Void doInBackground(Void... params) {
  510 +// searchDevice();
  511 +// Realm realm = Realm.getDefaultInstance();
  512 +// for (long id : ids) {
  513 +// Hub host = realm.where(Hub.class).equalTo(Hub.Companion.getDEVICE_NUM(), id).findFirst();
  514 +// if (null != host) {
  515 +// if (WanState.ON == host.getWanState()) {
  516 +// realm.beginTransaction();
  517 +// host.setAlreadyHaveRemoteIP(false);
  518 +// realm.commitTransaction();
  519 +// Device device = Device.getInstance();
  520 +// device.setDeviceNum(ByteUtils.longToMacArray(id));
  521 +// device.setDeviceKey(host.getWanPwd().getBytes());
  522 +// Gson gson = getGson();
  523 +// String jsonDevice = gson.toJson(device);
  524 +// GlobalVar.getLogUtils().i("searchRecordDevice = " + jsonDevice);
  525 +// String strRandom = RandomUtil.getRandomStr();
  526 +// String strPwd = host.getWanPwd();
  527 +// getRemoteCtrlIp(jsonDevice, strRandom, strPwd);
  528 +// }
  529 +// }
  530 +// }
  531 +// realm.close();
  532 +// return null;
  533 +// }
  534 +// }.execute();
  535 + }
  536 +
  537 + public void searchLocalDevice() {
  538 + new AsyncTask<Void, Void, Void>() {
  539 +
  540 + @Override
  541 + protected Void doInBackground(Void... params) {
  542 + searchDevice();
  543 + Log.d(TAG, "search local device");
  544 + return null;
  545 + }
  546 + }.execute();
  547 + }
  548 +
  549 + /**
  550 + * 链接路由
  551 + *
  552 + * @param jsonDevice
  553 + * @param ssid
  554 + * @param pwd
  555 + */
  556 + public static native void linkRouter(String jsonDevice, String ssid, String pwd);
  557 +
  558 + public void getlinkRouter(final String jsonDevice, final String ssid, final String pwd) {
  559 + if (!(WifiUtils.isWifiConnected())) {
  560 + ToastUtils.toastShort("网络未连接");
  561 + return;
  562 + }
  563 + new AsyncTask<Void, Void, Void>() {
  564 + @Override
  565 + protected Void doInBackground(Void... params) {
  566 + GlobalVar.getLogUtils().i("getlinkRouter jsonDevice =" + jsonDevice);
  567 + linkRouter(jsonDevice, ssid, pwd);
  568 + return null;
  569 + }
  570 + }.execute();
  571 + }
  572 +
  573 + /**
  574 + * 修改密码或SSID
  575 + *
  576 + * @param jsonDevice
  577 + * @param ssid
  578 + * @param pwd
  579 + */
  580 + public static native void modifyAp(String jsonDevice, String ssid, String pwd);
  581 +
  582 + /**
  583 + * 链接状态
  584 + *
  585 + * @param jsonDevice
  586 + */
  587 + public static native void linkStatus(String jsonDevice);
  588 +
  589 + public void getLinkStatus(final String jsonDevice) {
  590 + if (!(WifiUtils.isWifiConnected())) {
  591 + ToastUtils.toastShort("网络未连接");
  592 + return;
  593 + }
  594 + new AsyncTask<Void, Void, Void>() {
  595 + @Override
  596 + protected Void doInBackground(Void... params) {
  597 + GlobalVar.getLogUtils().i("getLinkStatus jsonDevice =" + jsonDevice);
  598 + linkStatus(jsonDevice);
  599 + return null;
  600 + }
  601 + }.execute();
  602 + }
  603 +
  604 +
  605 + /**
  606 + * 修改控制密码
  607 + *
  608 + * @param jsonDevice
  609 + * @param pwd
  610 + */
  611 + public static native void modifyCtrlPWd(String jsonDevice, String pwd);
  612 +
  613 + public void modifyPwd(final String jsonDevice, final String pwd) {
  614 + if (!(WifiUtils.isWifiConnected())) {
  615 + ToastUtils.toastShort("网络未连接");
  616 + return;
  617 + }
  618 + new AsyncTask<Void, Void, Void>() {
  619 + @Override
  620 + protected Void doInBackground(Void... params) {
  621 + GlobalVar.getLogUtils().i("modifyPwd jsonDevice =" + jsonDevice);
  622 + modifyCtrlPWd(jsonDevice, pwd);
  623 + return null;
  624 + }
  625 + }.execute();
  626 + }
  627 +}
  1 +//package com.adroplat.fist_switch.jni;
  2 +//
  3 +//import android.content.Context;
  4 +//import android.content.Intent;
  5 +//import android.os.AsyncTask;
  6 +//import android.support.v4.content.LocalBroadcastManager;
  7 +//
  8 +//import com.adroplat.fist_switch.adapter.LightingGroupAdapter;
  9 +//import com.adroplat.fist_switch.config.GlobalVar;
  10 +//import com.adroplat.fist_switch.service.HeService;
  11 +//import com.adroplat.fist_switch.sqlite.Hub;
  12 +//import com.adroplat.fist_switch.sqlite.SwSubDev;
  13 +//import com.adroplat.fist_switch.sqlite.SyncState;
  14 +//import com.adroplat.fist_switch.sqlite.Transform;
  15 +//import com.adroplat.fist_switch.sqlite.WanState;
  16 +//import com.adroplat.fist_switch.ui.SwitchApp;
  17 +//import com.adroplat.fist_switch.utils.ByteUtils;
  18 +//import com.adroplat.fist_switch.utils.RandomUtil;
  19 +//import com.adroplat.fist_switch.utils.ToastUtils;
  20 +//import com.adroplat.fist_switch.utils.WifiUtils;
  21 +//import com.adroplat.fist_switch.utils.protocol.one.FistProtocol;
  22 +//import com.adroplat.fist_switch.utils.protocol.remote.RemoteProtocol;
  23 +//import com.google.gson.Gson;
  24 +//
  25 +//import java.util.ArrayList;
  26 +//
  27 +//import io.realm.Realm;
  28 +//import io.realm.RealmResults;
  29 +//
  30 +///**
  31 +// * Created by WLJ on 2016/1/14.
  32 +// */
  33 +//public class FistJni_back {
  34 +// static {
  35 +// System.loadLibrary("fist_ndk");
  36 +// }
  37 +//
  38 +// private static FistJni_back instance;
  39 +//
  40 +// private FistJni_back() {
  41 +// }
  42 +//
  43 +// public static FistJni_back getInstance() {
  44 +// if (null == instance) {
  45 +// instance = new FistJni_back();
  46 +// }
  47 +// return instance;
  48 +// }
  49 +//
  50 +// private static Intent intent;
  51 +//
  52 +// public static Intent getIntent() {
  53 +// intent = new Intent();
  54 +// return intent;
  55 +// }
  56 +//
  57 +// public static final String CONFIG_DONE = "CONFIG_DONE";
  58 +// public static final String SEARCH_RESPONSE = "SEARCH_RESPONSE";
  59 +// public static final String LINK_STATUS_RESPONSE = "LINK_STATUS_RESPONSE";
  60 +// public static final String LINK_RESPONSE = "LINK_RESPONSE";
  61 +// public static final String CTRL_PWD_RESPONSE = "CTRL_PWD_RESPONSE";
  62 +// public static final String START_ADD = "START_ADD";
  63 +// public static final String STOP_ADD = "STOP_ADD";
  64 +// public static final String ADD_DONE = "ADD_DONE";
  65 +// public static final String CONTROL_REQUEST_TIMEOUT = "CONTROL_REQUEST_TIMEOUT";
  66 +// public static final String CONTROL_RESPONSE = "CONTROL_RESPONSE";
  67 +// public static final String CONTROL_DONE = "CONTROL_DONE";
  68 +// public static final String CONTROL_OVER = "CONTROL_OVER";
  69 +// public static final String BYTE_ERROR_CODE = "BYTE_ERROR_CODE";
  70 +// public static final String JSON_DEVICE = "JSON_DEVICE";
  71 +//
  72 +// private static void configDone(Device device) {
  73 +// sendJsonDevice(CONFIG_DONE, device);
  74 +// }
  75 +//
  76 +// private static void online(Device device, String jsonDevice) {
  77 +// Realm realm = Realm.getDefaultInstance();
  78 +// Hub host = realm.where(Hub.class)
  79 +// .equalTo(Hub.Companion.getDEVICE_NUM(), device.getLongDeviceNum()).findFirst();
  80 +// if (null != host) {//已存储,更新IP,查询子设备
  81 +// realm.beginTransaction();
  82 +// host.setIp(device.getIntDeviceIp());
  83 +// host.setLAN(true);
  84 +// realm.commitTransaction();
  85 +// FistJni_back.getInstance().query(jsonDevice);
  86 +// }
  87 +// realm.close();
  88 +// }
  89 +//
  90 +// private static void saveRemote(Device device) {
  91 +// if (null == device) return;
  92 +// Realm realm = Realm.getDefaultInstance();
  93 +// Hub host = realm.where(Hub.class)
  94 +// .equalTo(Hub.Companion.getDEVICE_NUM(), device.getLongDeviceNum()).findFirst();
  95 +// if (null != host) {//已存储,更新IP,查询子设备
  96 +// realm.beginTransaction();
  97 +// host.setMapIp(device.getIntMappedIp());
  98 +// host.setMapPort(device.getMappedPort());
  99 +// host.setPeerIp(device.getIntDeviceIp());
  100 +// host.setPeerPort(device.getDevicePort());
  101 +// host.setLAN(false);
  102 +// host.setAlreadyHaveRemoteIP(true);
  103 +// realm.commitTransaction();
  104 +// }
  105 +// realm.close();
  106 +// }
  107 +//
  108 +// private static Gson gson;
  109 +//
  110 +// public static Gson getGson() {
  111 +// if (null == gson) {
  112 +// gson = new Gson();
  113 +// }
  114 +// return gson;
  115 +// }
  116 +//
  117 +// /**
  118 +// * 发送广播
  119 +// *
  120 +// * @param action
  121 +// * @param device
  122 +// */
  123 +// private static void sendJsonDevice(String action, Device device) {
  124 +// if (null == action || action.isEmpty() || null == device) return;
  125 +// Context context = SwitchApp.getAppContext();
  126 +// if (null == context) return;
  127 +// Intent intent = getIntent();
  128 +// intent.setAction(action);
  129 +// intent.putExtra(JSON_DEVICE, device);
  130 +// LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
  131 +// }
  132 +//
  133 +// public static void fistListener(String jsonDevice) {
  134 +// if (null == jsonDevice || jsonDevice.isEmpty()) return;
  135 +// GlobalVar.getLogUtils().i("fistListener jsonDevice =" + jsonDevice);
  136 +// Gson gson = getGson();
  137 +// Device device = gson.fromJson(jsonDevice, Device.class);
  138 +// char cmdTpye = (char) device.getCmdType();
  139 +//
  140 +// if (FistProtocol.CommondType.CMD_TYPE_SEARCH_RESPONSE == cmdTpye) {//查询响应
  141 +// removeId(device);
  142 +// online(device, jsonDevice);
  143 +// sendJsonDevice(SEARCH_RESPONSE, device);
  144 +//
  145 +// } else if (FistProtocol.CommondType.CMD_TYPE_CONFIG_DONE == cmdTpye) {//配置完成处理
  146 +// configDone(device);
  147 +//
  148 +// } else if (FistProtocol.CommondType.CMD_TYPE_ONLINE == cmdTpye) {//上线通知
  149 +// removeId(device);
  150 +// online(device, jsonDevice);
  151 +// configDone(device);
  152 +//
  153 +// } else if (FistProtocol.CommondType.CMD_TYPE_QUERY_RESPONSE == cmdTpye) {
  154 +// sendJsonDevice(ADD_DONE, device);
  155 +// ArrayList<SubDevice> subDevices = device.getSubDevices();
  156 +// if (!subDevices.isEmpty()) {//查询结果不为空
  157 +// Realm realm = Realm.getDefaultInstance();
  158 +// long hostNum = device.getLongDeviceNum();
  159 +// RealmResults<Hub> hubs = realm.where(Hub.class)
  160 +// .equalTo(Hub.Companion.getDEVICE_NUM(), hostNum)
  161 +// .notEqualTo(Transform.Companion.getSYNC_CODE(), SyncState.DELETE.ordinal()).findAll();
  162 +// if (!hubs.isEmpty()) {
  163 +// int subSize = subDevices.size();
  164 +// for (int i = 0; i < subSize; i++) {
  165 +// SubDevice subDevice = subDevices.get(i);
  166 +// long subDeviceNum = subDevice.getSubDeviceNum();
  167 +// RealmResults<SwSubDev> swSubDevs = realm.where(SwSubDev.class)
  168 +// .equalTo(SwSubDev.Companion.getHOST_NUM(), hostNum)
  169 +// .equalTo(SwSubDev.Companion.getPARENT_NUM(), subDeviceNum)
  170 +// .findAll();
  171 +// if (!swSubDevs.isEmpty()) {//数据库已存储
  172 +// int lightingSize = swSubDevs.size();
  173 +// byte lingtingState = (byte) subDevice.getSubDeviceStatus();
  174 +// for (int j = 0; j < lightingSize; j++) {//更新开关状态
  175 +// SwSubDev lighting = swSubDevs.get(j);
  176 +// realm.beginTransaction();
  177 +// byte currentState = (byte) (lingtingState >> lighting.getDeviceNum() & 1);
  178 +// if (0 == currentState) {
  179 +// lighting.setOn(false);
  180 +// } else {
  181 +// lighting.setOn(true);
  182 +// }
  183 +// realm.commitTransaction();
  184 +// }
  185 +// }
  186 +// }
  187 +// }
  188 +//
  189 +// realm.close();
  190 +// }
  191 +// sendJsonDevice(LightingGroupAdapter.REFRESH, device);
  192 +//
  193 +// } else if (FistProtocol.CommondType.CMD_TYPE_ADD_RESPONSE == cmdTpye) {
  194 +// sendJsonDevice(START_ADD, device);
  195 +//
  196 +// } else if (FistProtocol.CommondType.CMD_TYPE_ADD_OVER == cmdTpye) {//子设备结束入网
  197 +//// if (0 == device.getIntDeviceIp()) return;
  198 +//// FistJni.stopAddSubDevice(jsonDevice);
  199 +//
  200 +// } else if (FistProtocol.CommondType.CMD_TYPE_CONTROL == cmdTpye) {//控制超时
  201 +// sendJsonDevice(CONTROL_REQUEST_TIMEOUT, device);
  202 +//
  203 +// } else if (FistProtocol.CommondType.CMD_TYPE_CONTROL_RESPONSE == cmdTpye) {//控制应答
  204 +// sendJsonDevice(CONTROL_RESPONSE, device);
  205 +//
  206 +// } else if (FistProtocol.CommondType.CMD_TYPE_CONTROL_DONE_RESPONSE == cmdTpye) {//单个控制结果
  207 +// sendJsonDevice(CONTROL_DONE, device);
  208 +//
  209 +// } else if (FistProtocol.CommondType.CMD_TYPE_CONTROL_OVER == cmdTpye) {
  210 +// sendJsonDevice(CONTROL_OVER, device);
  211 +// GlobalVar.getLogUtils().i("CONTROL_OVER");
  212 +// } else if (FistProtocol.CommondType.CMD_NET_LINK_STATUS_RESPONSE == cmdTpye) {
  213 +// sendJsonDevice(LINK_STATUS_RESPONSE, device);
  214 +//
  215 +// } else if (FistProtocol.CommondType.CMD_LINK_RESPONSE == cmdTpye) {
  216 +// sendJsonDevice(LINK_RESPONSE, device);
  217 +//
  218 +// } else if (FistProtocol.CommondType.CMD_MODIFY_CTRL_PWD_RESPONSE == cmdTpye) {
  219 +// GlobalVar.getLogUtils().i("FistProtocol.CommondType.CMD_MODIFY_CTRL_PWD_RESPONSE");
  220 +// sendJsonDevice(CTRL_PWD_RESPONSE, device);
  221 +//
  222 +// } else if (RemoteProtocol.MsgType.SET_SUCCESS == cmdTpye) {//密码设置成功
  223 +// GlobalVar.getLogUtils().i("SET_SUCCESS jsonDevice =" + jsonDevice);
  224 +// long deviceNum = device.getLongDeviceNum();
  225 +// Realm realm = Realm.getDefaultInstance();
  226 +// Hub host = realm.where(Hub.class).equalTo(Hub.Companion.getDEVICE_NUM(), deviceNum).findFirst();
  227 +// if (null != host) {
  228 +// realm.beginTransaction();
  229 +// host.setWanState(WanState.ON);
  230 +// realm.commitTransaction();
  231 +// }
  232 +// realm.close();
  233 +// } else if (RemoteProtocol.MsgType.SET_FAILED == cmdTpye) {//密码设置失败
  234 +// GlobalVar.getLogUtils().i("SET_FAILED jsonDevice =" + jsonDevice);
  235 +//
  236 +// } else if (RemoteProtocol.MsgType.QUERY_SUCCESS == cmdTpye) {//查询对端成功
  237 +// final long deviceNum = device.getLongDeviceNum();
  238 +// ArrayList<Long> ids = HeService.getLocIds();
  239 +// for (long id : ids) {
  240 +// if (deviceNum == id) {
  241 +// saveRemote(device);
  242 +// device.setWan(true);
  243 +// jsonDevice = gson.toJson(device);
  244 +// querySubDevice(jsonDevice);
  245 +// break;
  246 +// }
  247 +// }
  248 +// removeId(device);
  249 +//
  250 +// } else if (RemoteProtocol.MsgType.QUERY_FAILED == cmdTpye) {//查询对端失败
  251 +//
  252 +// }
  253 +// }
  254 +//
  255 +// /**
  256 +// * 开始
  257 +// */
  258 +// public static native void start();
  259 +//
  260 +// /**
  261 +// * 启动SKD
  262 +// */
  263 +// public void startSdk() {
  264 +// new AsyncTask<Void, Void, Void>() {
  265 +// @Override
  266 +// protected Void doInBackground(Void... params) {
  267 +// start();
  268 +// return null;
  269 +// }
  270 +// }.execute();
  271 +// }
  272 +//
  273 +// /**
  274 +// * 移除查询到的主机ID
  275 +// *
  276 +// * @param device
  277 +// */
  278 +// private static void removeId(Device device) {
  279 +// ArrayList<Long> ids = HeService.getLocIds();
  280 +// final long deviceNum = device.getLongDeviceNum();
  281 +// for (long id : ids) {
  282 +// if (deviceNum == id) {
  283 +// ids.remove(id);
  284 +// break;
  285 +// }
  286 +// }
  287 +// }
  288 +//
  289 +// /**
  290 +// * 搜索设备
  291 +// */
  292 +// public static native void searchDevice();
  293 +//
  294 +// /**
  295 +// * 查询子设备
  296 +// */
  297 +// public static native void querySubDevice(String jsonDevice);
  298 +//
  299 +// public void query(final String jsonDevice) {
  300 +// if (!HeService.isConn()) {
  301 +// return;
  302 +// }
  303 +// new AsyncTask<Void, Void, Void>() {
  304 +// @Override
  305 +// protected Void doInBackground(Void... params) {
  306 +// querySubDevice(jsonDevice);
  307 +// return null;
  308 +// }
  309 +// }.execute();
  310 +// }
  311 +//
  312 +// /**
  313 +// * 开始添加子设备
  314 +// */
  315 +// public static native void startAddSubDevice(String jsonDevice);
  316 +//
  317 +// public void startAdd(final String jsonDevice) {
  318 +// if (!(WifiUtils.isWifiConnected())) {
  319 +// ToastUtils.toastShort("网络未连接");
  320 +// return;
  321 +// }
  322 +// new AsyncTask<Void, Void, Void>() {
  323 +// @Override
  324 +// protected Void doInBackground(Void... params) {
  325 +// startAddSubDevice(jsonDevice);
  326 +// return null;
  327 +// }
  328 +// }.execute();
  329 +// }
  330 +//
  331 +// /**
  332 +// * 停止添加子设备
  333 +// */
  334 +// public static native void stopAddSubDevice(String jsonDevice);
  335 +//
  336 +// public void stopAdd(final String jsonDevice) {
  337 +// if (!(WifiUtils.isWifiConnected())) {
  338 +// ToastUtils.toastShort("网络未连接");
  339 +// return;
  340 +// }
  341 +// new AsyncTask<Void, Void, Void>() {
  342 +// @Override
  343 +// protected Void doInBackground(Void... params) {
  344 +// stopAddSubDevice(jsonDevice);
  345 +// return null;
  346 +// }
  347 +// }.execute();
  348 +// }
  349 +//
  350 +// /**
  351 +// * 删除子设备
  352 +// */
  353 +// public static native void deleteSubDevices(String jsonDevice);
  354 +//
  355 +// public void delSub(final String jsonDevice) {
  356 +// if (!HeService.isConn()) {
  357 +// ToastUtils.toastShort("网络未连接");
  358 +// return;
  359 +// }
  360 +// new AsyncTask<Void, Void, Void>() {
  361 +// @Override
  362 +// protected Void doInBackground(Void... params) {
  363 +// deleteSubDevices(jsonDevice);
  364 +// return null;
  365 +// }
  366 +// }.execute();
  367 +// }
  368 +//
  369 +// /**
  370 +// * 查询软件版本
  371 +// */
  372 +// public static native void querySoftwareVer(String jsonDevice);
  373 +//
  374 +// /**
  375 +// * 查询工作模式
  376 +// */
  377 +// public static native void queryModel(String jsonDevice);
  378 +//
  379 +// public void sceneC(final String jsonDevice) {
  380 +// if (!(WifiUtils.isWifiConnected())) {
  381 +// ToastUtils.toastShort("网络未连接");
  382 +// return;
  383 +// }
  384 +// new AsyncTask<Void, Void, Void>() {
  385 +// @Override
  386 +// protected Void doInBackground(Void... params) {
  387 +// GlobalVar.getLogUtils().i("sceneC jsonDevice =" + jsonDevice);
  388 +// sceneControl(jsonDevice);
  389 +// return null;
  390 +// }
  391 +// }.execute();
  392 +// }
  393 +//
  394 +// /**
  395 +// * 情景控制
  396 +// */
  397 +// public static native void sceneControl(String jsonDevice);
  398 +//
  399 +// public void normalC(final String jsonDevice) {
  400 +// if (!(WifiUtils.isWifiConnected())) {
  401 +// ToastUtils.toastShort("网络未连接");
  402 +// return;
  403 +// }
  404 +// new AsyncTask<Void, Void, Void>() {
  405 +// @Override
  406 +// protected Void doInBackground(Void... params) {
  407 +// GlobalVar.getLogUtils().i("normalC jsonDevice =" + jsonDevice);
  408 +// normalControl(jsonDevice);
  409 +// return null;
  410 +// }
  411 +// }.execute();
  412 +// }
  413 +//
  414 +// /**
  415 +// * 普通控制
  416 +// */
  417 +// private static native void normalControl(String jsonDevice);
  418 +//
  419 +//
  420 +// /**
  421 +// * 设置远程密码
  422 +// *
  423 +// * @param jsonDevice
  424 +// * @param pwd
  425 +// */
  426 +// private static native void setRemotePwd(String jsonDevice, String pwd);
  427 +//
  428 +// public void setPwd(final String jsonDevice, final String pwd) {
  429 +// if (!(WifiUtils.isWifiConnected())) {
  430 +// ToastUtils.toastShort("网络未连接");
  431 +// return;
  432 +// }
  433 +// new AsyncTask<Void, Void, Void>() {
  434 +// @Override
  435 +// protected Void doInBackground(Void... params) {
  436 +// setRemotePwd(jsonDevice, pwd);
  437 +// return null;
  438 +// }
  439 +// }.execute();
  440 +// }
  441 +//
  442 +// private static native void getRemoteCtrlIp(String jsonDevice, String random, String pwd);
  443 +//
  444 +// public void searchRecordDevice() {
  445 +// final ArrayList<Long> ids = HeService.getLocIds();
  446 +// if (ids.isEmpty()) return;
  447 +// new AsyncTask<Void, Void, Void>() {
  448 +//
  449 +// @Override
  450 +// protected Void doInBackground(Void... params) {
  451 +// searchDevice();
  452 +// Realm realm = Realm.getDefaultInstance();
  453 +// for (long id : ids) {
  454 +// Hub host = realm.where(Hub.class).equalTo(Hub.Companion.getDEVICE_NUM(), id).findFirst();
  455 +// if (null != host) {
  456 +// if (WanState.ON == host.getWanState()) {
  457 +// realm.beginTransaction();
  458 +// host.setAlreadyHaveRemoteIP(false);
  459 +// realm.commitTransaction();
  460 +// Device device = Device.getInstance();
  461 +// device.setDeviceNum(ByteUtils.longToMacArray(id));
  462 +// device.setDeviceKey(host.getWanPwd().getBytes());
  463 +// Gson gson = getGson();
  464 +// String jsonDevice = gson.toJson(device);
  465 +// GlobalVar.getLogUtils().i("searchRecordDevice = " + jsonDevice);
  466 +// String strRandom = RandomUtil.getRandomStr();
  467 +// String strPwd = host.getWanPwd();
  468 +// getRemoteCtrlIp(jsonDevice, strRandom, strPwd);
  469 +// }
  470 +// }
  471 +// }
  472 +// realm.close();
  473 +// return null;
  474 +// }
  475 +// }.execute();
  476 +// }
  477 +//
  478 +// public void searchLocalDevice() {
  479 +// new AsyncTask<Void, Void, Void>() {
  480 +//
  481 +// @Override
  482 +// protected Void doInBackground(Void... params) {
  483 +// searchDevice();
  484 +// return null;
  485 +// }
  486 +// }.execute();
  487 +// }
  488 +//
  489 +// /**
  490 +// * 链接路由
  491 +// *
  492 +// * @param jsonDevice
  493 +// * @param ssid
  494 +// * @param pwd
  495 +// */
  496 +// public static native void linkRouter(String jsonDevice, String ssid, String pwd);
  497 +//
  498 +// public void getlinkRouter(final String jsonDevice, final String ssid, final String pwd) {
  499 +// if (!(WifiUtils.isWifiConnected())) {
  500 +// ToastUtils.toastShort("网络未连接");
  501 +// return;
  502 +// }
  503 +// new AsyncTask<Void, Void, Void>() {
  504 +// @Override
  505 +// protected Void doInBackground(Void... params) {
  506 +// GlobalVar.getLogUtils().i("getlinkRouter jsonDevice =" + jsonDevice);
  507 +// linkRouter(jsonDevice, ssid, pwd);
  508 +// return null;
  509 +// }
  510 +// }.execute();
  511 +// }
  512 +//
  513 +// /**
  514 +// * 修改密码或SSID
  515 +// *
  516 +// * @param jsonDevice
  517 +// * @param ssid
  518 +// * @param pwd
  519 +// */
  520 +// public static native void modifyAp(String jsonDevice, String ssid, String pwd);
  521 +//
  522 +// /**
  523 +// * 链接状态
  524 +// *
  525 +// * @param jsonDevice
  526 +// */
  527 +// public static native void linkStatus(String jsonDevice);
  528 +//
  529 +// public void getLinkStatus(final String jsonDevice) {
  530 +// if (!(WifiUtils.isWifiConnected())) {
  531 +// ToastUtils.toastShort("网络未连接");
  532 +// return;
  533 +// }
  534 +// new AsyncTask<Void, Void, Void>() {
  535 +// @Override
  536 +// protected Void doInBackground(Void... params) {
  537 +// GlobalVar.getLogUtils().i("getLinkStatus jsonDevice =" + jsonDevice);
  538 +// linkStatus(jsonDevice);
  539 +// return null;
  540 +// }
  541 +// }.execute();
  542 +// }
  543 +//
  544 +//
  545 +// /**
  546 +// * 修改控制密码
  547 +// *
  548 +// * @param jsonDevice
  549 +// * @param pwd
  550 +// */
  551 +// public static native void modifyCtrlPWd(String jsonDevice, String pwd);
  552 +//
  553 +// public void modifyPwd(final String jsonDevice, final String pwd) {
  554 +// if (!(WifiUtils.isWifiConnected())) {
  555 +// ToastUtils.toastShort("网络未连接");
  556 +// return;
  557 +// }
  558 +// new AsyncTask<Void, Void, Void>() {
  559 +// @Override
  560 +// protected Void doInBackground(Void... params) {
  561 +// GlobalVar.getLogUtils().i("modifyPwd jsonDevice =" + jsonDevice);
  562 +// modifyCtrlPWd(jsonDevice, pwd);
  563 +// return null;
  564 +// }
  565 +// }.execute();
  566 +// }
  567 +//}
  1 +package com.adroplat.fist_switch.jni;
  2 +
  3 +/**
  4 + * Created by yikuyiliao on 16-3-8.
  5 + */
  6 +public class SubDevice implements Cloneable {
  7 +
  8 + private static SubDevice instance;
  9 +
  10 + private SubDevice() {
  11 + }
  12 +
  13 + public static SubDevice getInstance() {
  14 + if (null == instance) {
  15 + instance = new SubDevice();
  16 + }
  17 + SubDevice subDevice = null;
  18 + try {
  19 + subDevice = (SubDevice) instance.clone();
  20 + } catch (CloneNotSupportedException e) {
  21 + e.printStackTrace();
  22 + }
  23 + if (null == subDevice) {
  24 + subDevice = new SubDevice();
  25 + }
  26 + return subDevice;
  27 + }
  28 +
  29 + private long SubDeviceNum;
  30 + private int SubDeviceType;
  31 + private int SubDeviceStatus;
  32 + private int SubDeviceOnlineStatus;
  33 + private int SubDeviceBit;
  34 +
  35 +
  36 + public long getSubDeviceNum() {
  37 +
  38 + return SubDeviceNum;
  39 + }
  40 +
  41 + public void setSubDeviceNum(long subDeviceNum) {
  42 +
  43 + SubDeviceNum = subDeviceNum;
  44 + }
  45 +
  46 + public int getSubDeviceType() {
  47 + return SubDeviceType;
  48 + }
  49 +
  50 + public void setSubDeviceType(int subDeviceType) {
  51 +
  52 + SubDeviceType = subDeviceType;
  53 + }
  54 +
  55 + public int getSubDeviceStatus() {
  56 + return SubDeviceStatus;
  57 + }
  58 +
  59 + public void setSubDeviceStatus(int subDeviceStatus) {
  60 +
  61 + SubDeviceStatus = subDeviceStatus;
  62 + }
  63 +
  64 + public int getSubDeviceOnlineStatus() {
  65 + return SubDeviceOnlineStatus;
  66 + }
  67 +
  68 + public void setSubDeviceOnlineStatus(int subDeviceOnlineStatus) {
  69 + SubDeviceOnlineStatus = subDeviceOnlineStatus;
  70 + }
  71 +
  72 + public int getSubDeviceBit() {
  73 + return SubDeviceBit;
  74 + }
  75 +
  76 + public void setSubDeviceBit(int subDeviceBit) {
  77 + SubDeviceBit = subDeviceBit;
  78 + }
  79 +}
  1 +package com.adroplat.fist_switch.utils;
  2 +
  3 +import java.nio.ByteBuffer;
  4 +import java.util.Arrays;
  5 +
  6 +//import com.adroplat.fist_switch.utils.protocol.remote.RemoteHead;
  7 +
  8 +/**
  9 + * byte转换工具类
  10 + * Created by WLJ on 2015/10/10.
  11 + */
  12 +public class ByteUtils {
  13 +
  14 +
  15 + /**
  16 + * byte数组转int
  17 + *
  18 + * @param byteArray
  19 + * @return
  20 + */
  21 + public static int byteArrayToInt(byte[] byteArray) {
  22 + int value = 0;
  23 + if (null == byteArray || 4 != byteArray.length) {
  24 +
  25 + } else {
  26 + int len = byteArray.length;
  27 + for (int i = 0; i < len; i++) {
  28 + value += (byteArray[i] & 0xff) << (8 * (3 - i));
  29 + }
  30 + }
  31 + return value;
  32 + }
  33 +
  34 + /**
  35 + * int转byte数组
  36 + *
  37 + * @param value
  38 + * @return
  39 + */
  40 + public static byte[] intToByteArrays(int value) {
  41 + byte[] byteArray = new byte[4];
  42 + int len = byteArray.length;
  43 + for (int i = 0; i < len; i++) {
  44 + byteArray[i] = (byte) ((value >> (8 * (3 - i))) & 0xff);
  45 + }
  46 + return byteArray;
  47 + }
  48 +
  49 + public static String intToIp(int ipInt) {
  50 + StringBuilder builder = new StringBuilder();
  51 + builder.delete(0, builder.length());
  52 + char c = '.';
  53 + return builder.append(((ipInt >> 24) & 0xff)).append(c)
  54 + .append((ipInt >> 16) & 0xff).append(c)
  55 + .append((ipInt >> 8) & 0xff).append(c)
  56 + .append((ipInt & 0xff))
  57 + .toString();
  58 + }
  59 +
  60 + public static byte[] intToLend(int value) {
  61 + byte[] byteArray = new byte[4];
  62 + int len = byteArray.length;
  63 + for (int i = 0; i < len; i++) {
  64 + byteArray[i] = (byte) ((value >> (8 * i)) & 0xff);
  65 + }
  66 + return byteArray;
  67 + }
  68 +
  69 + /**
  70 + * byte数组转long
  71 + *
  72 + * @param macArray
  73 + * @return
  74 + */
  75 + public static long macArrayToLong(byte[] macArray) {
  76 + long value = 0;
  77 + if (null == macArray || 8 < macArray.length) {
  78 +
  79 + } else {
  80 + int len = macArray.length;
  81 + for (int i = 0; i < len; i++) {
  82 + value |= (long) (macArray[i] & 0xff) << (8 * (len - i - 1));
  83 + }
  84 + }
  85 + return value;
  86 + }
  87 +
  88 + /**
  89 + * long转byte数组
  90 + *
  91 + * @param value
  92 + * @return
  93 + */
  94 + public static byte[] longToMacArray(long value) {
  95 + byte[] lAray = longToBytes(value);
  96 + return Arrays.copyOfRange(lAray, 2, lAray.length);
  97 + }
  98 +
  99 +
  100 + /**
  101 + * long转16进制String
  102 + *
  103 + * @param value
  104 + * @return
  105 + */
  106 + public static String longToHexString(long value) {
  107 + byte[] array = longToMacArray(value);
  108 + int offset = 0;
  109 + int len = array.length;
  110 + for (int i = 0; i < len; i++) {
  111 + if (0 != array[i]) {
  112 + offset = i;
  113 + break;
  114 + }
  115 + }
  116 + array = Arrays.copyOfRange(array, offset, len);
  117 + return byteArayToHexString(array).trim();
  118 + }
  119 +
  120 + /**
  121 + * 16进制String转long
  122 + *
  123 + * @param hex
  124 + * @return
  125 + */
  126 + public static long hexStringToLong(String hex) {
  127 + byte[] array = hexStringToByteAray(hex);
  128 + return macArrayToLong(array);
  129 + }
  130 +
  131 + /**
  132 + * byte数组转16进制String
  133 + *
  134 + * @param array
  135 + * @return
  136 + */
  137 + public static String byteArayToHexString(byte[] array) {
  138 + String strHex = null;
  139 + if (null == array || 0 == array.length) {
  140 + } else {
  141 + StringBuilder builder = new StringBuilder();
  142 + for (byte b : array) {
  143 + String str = Integer.toHexString(b & 0xff);
  144 + if (1 == str.length()) {
  145 + str = '0' + str;
  146 + }
  147 + builder.append(str);
  148 + }
  149 + strHex = builder.toString();
  150 + }
  151 + return strHex;
  152 + }
  153 +
  154 + /**
  155 + * byte数组转16进制MAC
  156 + *
  157 + * @param array
  158 + * @return
  159 + */
  160 + public static String byteArayToMacStr(byte[] array) {
  161 + String strHex = null;
  162 + if (null == array || 0 == array.length) {
  163 + } else {
  164 + StringBuilder builder = new StringBuilder();
  165 + for (byte b : array) {
  166 + String str = Integer.toHexString(b & 0xff);
  167 + if (1 == str.length()) {
  168 + str = '0' + str;
  169 + }
  170 + builder.append(str + ":");
  171 + }
  172 + strHex = builder.deleteCharAt(builder.length() - 1).toString().toUpperCase();
  173 + }
  174 + return strHex;
  175 + }
  176 +
  177 + /**
  178 + * 16进制String转byte数组
  179 + *
  180 + * @param hex
  181 + * @return
  182 + */
  183 + public static byte[] hexStringToByteAray(String hex) {
  184 + if (hex == null || hex.equals("")) {
  185 + return null;
  186 + }
  187 + hex = hex.toUpperCase();
  188 + char[] hexChars = hex.toCharArray();
  189 + int len = hexChars.length / 2;
  190 + byte[] d = new byte[len];
  191 + for (int i = 0; i < len; i++) {
  192 + int pos = i * 2;
  193 + d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
  194 + }
  195 + return d;
  196 + }
  197 +
  198 + /**
  199 + * Convert char to byte
  200 + *
  201 + * @param c char
  202 + * @return byte
  203 + */
  204 + private static byte charToByte(char c) {
  205 + return (byte) "0123456789ABCDEF".indexOf(c);
  206 + }
  207 +
  208 + /**
  209 + * int转char
  210 + *
  211 + * @param value
  212 + * @return
  213 + */
  214 + public static char intToChar(int value) {
  215 + byte[] byteArray = intToByteArrays(value);
  216 +// return (char) ((byteArray[2] & 0xff) << 8 | byteArray[3] & 0xff);
  217 + return bytesToChar(byteArray);
  218 + }
  219 +
  220 +
  221 + /**
  222 + * char转byte[]
  223 + */
  224 + public static byte[] charToBytes(char c) {
  225 + byte[] bytes = new byte[2];
  226 +// final char DIGIT = RemoteHead.DIGIT;
  227 +// bytes[0] = (byte) ((c >> 8) & DIGIT);
  228 +// bytes[1] = (byte) (c & DIGIT);
  229 + return bytes;
  230 + }
  231 +
  232 + /**
  233 + * byte[]转char
  234 + */
  235 + public static char bytesToChar(byte[] bytes) {
  236 + char c = 0;
  237 + if (null != bytes) {
  238 + int size = bytes.length;
  239 + if (size >= 2) {
  240 + c = (char) ((bytes[size - 2] & 0xff) << 8 | bytes[size - 1] & 0xff);
  241 + } else if (1 == size) {
  242 + c = (char) (bytes[0]);
  243 + }
  244 + }
  245 + return c;
  246 + }
  247 +
  248 + /**
  249 + * 转化CRON需要的星期
  250 + *
  251 + * @param weekCode
  252 + * @return
  253 + */
  254 + public static String byteToDayWeek(byte weekCode, String weekDay[]) {
  255 + StringBuilder sb = new StringBuilder();
  256 + if (null != weekDay) {
  257 + final int size = weekDay.length;
  258 + for (int i = 0; i < size; i++) {
  259 + if (0 != (weekCode >> i) % 2) {
  260 + sb.append(weekDay[i]).append(",");
  261 + }
  262 + }
  263 + int len = sb.length();
  264 + if (len > 0) {
  265 + sb.deleteCharAt(len - 1);
  266 + }
  267 + }
  268 + return sb.toString();
  269 + }
  270 +
  271 + public static byte[] longToBytes(long value) {
  272 + ByteBuffer buffer = ByteBuffer.allocate(8);
  273 + buffer.putLong(0, value);
  274 + return buffer.array();
  275 + }
  276 +
  277 + public static long bytesToLong(byte[] value) {
  278 + long result = 0;
  279 + if (null != value) {
  280 + for (int i = 0; i < value.length; i++) {
  281 + value[i] &= 0xff;
  282 + }
  283 + ByteBuffer buffer = ByteBuffer.allocate(8);
  284 + buffer.put(value, 0, value.length);
  285 + buffer.flip();//need flip
  286 + result = buffer.getLong();
  287 + }
  288 + return result;
  289 + }
  290 +
  291 +}
  1 +package com.adroplat.fist_switch.utils;
  2 +
  3 +import android.util.Log;
  4 +
  5 +/**
  6 + * Created by wugian on 2017/3/8.
  7 + */
  8 +
  9 +public class ToastUtils {
  10 + public static void toastShort(String s){
  11 + Log.d("ToastUtils", s);
  12 + }
  13 +}
  1 +package com.adroplat.fist_switch.utils;
  2 +
  3 +/**
  4 + * Created by wugian on 2017/3/8.
  5 + */
  6 +
  7 +public class WifiUtils {
  8 + public static boolean isWifiConnected() {
  9 + return true;
  10 + }
  11 +}
  1 +package com.adroplat.fist_switch.utils.protocol.one;
  2 +
  3 +
  4 +/**
  5 + * 协议类
  6 + * Created by WLJ on 2015/11/13.
  7 + */
  8 +public class FistProtocol {
  9 + /**
  10 + * 包头
  11 + */
  12 + public static final byte[] COMMOND_PACKAGE_HEADER = {(byte) 0x83, (byte) 0xb3, (byte) 0xa9};
  13 + /**
  14 + * 协议版本
  15 + */
  16 + public static final byte[] COMMOND_PROTOCOL_VERSION = {0x01, 0x00, 0x00, 0x00};
  17 + /**
  18 + * 版本角标
  19 + */
  20 + public static final int INDEXT_OF_VERSION = COMMOND_PACKAGE_HEADER.length;
  21 + /**
  22 + * 命令类型角标
  23 + */
  24 + public static final int INDEXT_OF_CMD = COMMOND_PACKAGE_HEADER.length + COMMOND_PROTOCOL_VERSION.length;
  25 + /**
  26 + * 命令类型长度
  27 + */
  28 + public static final int LENGTH_OF_CMD = 1;
  29 + /**
  30 + * 包长角标
  31 + */
  32 + public static final int INDEXT_OF_PACKAGE_LENGTH = INDEXT_OF_CMD + LENGTH_OF_CMD;
  33 + /**
  34 + * 包长长度
  35 + */
  36 + public static final int LENGTH_OF_PACKAGE_LENGTH = 2;
  37 + /**
  38 + * 随机数角标
  39 + */
  40 + public static final int INDEXT_OF_RANDOM = INDEXT_OF_PACKAGE_LENGTH + LENGTH_OF_PACKAGE_LENGTH;
  41 +
  42 + /**
  43 + * 随机数长度
  44 + */
  45 + public static final int LENGTH_OF_RANDOM = 2;
  46 + /**
  47 + * 设备类型长度
  48 + */
  49 + public static final int LENGTH_OF_DEVICE_TYPE = 2;
  50 + /**
  51 + * 设备号角标
  52 + */
  53 + public static final int INDEXT_OF_DEVICE_NUM = INDEXT_OF_RANDOM + LENGTH_OF_RANDOM + LENGTH_OF_DEVICE_TYPE;
  54 + /**
  55 + * 设备号长度
  56 + */
  57 + public static final int LENGTH_OF_DEVICE_NUM = 6;
  58 + /**
  59 + * 设备ip角标
  60 + */
  61 + public static final int INDEXT_OF_DEVICE_IP = INDEXT_OF_DEVICE_NUM + LENGTH_OF_DEVICE_NUM;
  62 + /**
  63 + * 设备IP长度
  64 + */
  65 + public static final int LENGTH_OF_DEVICE_IP = 4;
  66 +
  67 + /**
  68 + * UDP搜索响应包长
  69 + */
  70 + public static final byte COMMOND_UDP_QUERY_RESPONSE_DATA_LENGTH = 0x18;
  71 + /**
  72 + * 超时
  73 + */
  74 + public static final byte ERROR_CODE_TIMEOUT = (byte) 0xFE;
  75 +
  76 + /**
  77 + * 在线状态
  78 + */
  79 +
  80 + public class OnlineState {
  81 + /**
  82 + * 未知
  83 + */
  84 + public static final int UNKNOW = 0;
  85 + /**
  86 + * 掉线
  87 + */
  88 + public static final int OFFLINE = 0x1;
  89 + /**
  90 + * 在线
  91 + */
  92 + public static final int ONLINE = 0x2;
  93 + /**
  94 + * 不存在
  95 + */
  96 + public static final int NOTHINGNESS = 0x20;
  97 + }
  98 +
  99 + /**
  100 + * 命令类型
  101 + */
  102 + public class CommondType {
  103 + /**
  104 + * 查询
  105 + */
  106 + public static final byte CMD_TYPE_QUERY = 0x10;
  107 + /**
  108 + * 查询反馈
  109 + */
  110 + public static final byte CMD_TYPE_QUERY_RESPONSE = 0x11;
  111 + /**
  112 + * 控制
  113 + */
  114 + public static final byte CMD_TYPE_CONTROL = 0x20;
  115 + /**
  116 + * 控制响应
  117 + */
  118 + public static final byte CMD_TYPE_CONTROL_RESPONSE = 0x21;
  119 + /**
  120 + * 子设备控制完毕响应包
  121 + */
  122 + public static final byte CMD_TYPE_CONTROL_DONE_RESPONSE = 0x22;
  123 + /**
  124 + * 命令控制完毕响应包:
  125 + */
  126 + public static final byte CMD_TYPE_CONTROL_OVER = 0x23;
  127 + /**
  128 + * UDP搜索
  129 + */
  130 + public static final byte CMD_TYPE_SEARCH = 0x30;
  131 + /**
  132 + * UDP搜索响应
  133 + */
  134 + public static final byte CMD_TYPE_SEARCH_RESPONSE = 0x31;
  135 + /**
  136 + * 配置完成通知
  137 + */
  138 + public static final byte CMD_TYPE_CONFIG_DONE = 0x32;
  139 + /**
  140 + * 设备启动、网络重连通知包
  141 + */
  142 + public static final byte CMD_TYPE_ONLINE = 0x33;
  143 +
  144 + /**
  145 + * 子设备入网申请
  146 + */
  147 + public static final byte CMD_TYPE_ADD = 0x40;
  148 + /**
  149 + * 子设备入网申请响应
  150 + */
  151 + public static final byte CMD_TYPE_ADD_RESPONSE = 0x41;
  152 + /**
  153 + * 子设备入网结束
  154 + */
  155 + public static final byte CMD_TYPE_ADD_OVER = 0x42;
  156 + /**
  157 + * 子设备入网结束响应
  158 + */
  159 + public static final byte CMD_TYPE_ADD_OVER_RESPONSE = 0x43;
  160 + /**
  161 + * 开关删除
  162 + */
  163 + public static final byte CMD_TYPE_DELETE = 0x50;
  164 + /**
  165 + * 开关删除响应
  166 + */
  167 + public static final byte CMD_TYPE_DELETE_RESPONSE = 0x51;
  168 + /**
  169 + * 网关工作模式查询包命令类型
  170 + */
  171 + public static final byte CMD_DEVICE_MODEL_REQUEST = 0x60;
  172 + /**
  173 + * 网关工作模式响应包命令类型
  174 + */
  175 + public static final byte CMD_DEVICE_MODEL_RESPONSE = 0x61;
  176 + /**
  177 + * 软件版本查询包命令类型
  178 + */
  179 + public static final byte CMD_SOFTWARE_VER_REQUEST = 0x70;
  180 + /**
  181 + * 软件版本响应包命令类型
  182 + */
  183 + public static final byte CMD_SOFTWARE_VER_RESPONSE = 0x71;
  184 + /**
  185 + * 链接路由器包命令类型
  186 + */
  187 + public static final byte CMD_LINK_REQUEST = (byte) 0x80;
  188 + /**
  189 + * 链接路由器响应包命令类型
  190 + */
  191 + public static final char CMD_LINK_RESPONSE = 0x81;
  192 + /**
  193 + * 修改SSID和密码包命令类型
  194 + */
  195 + public static final byte CMD_MODIFY_SSID_AND_PWD_REQUEST = (byte) 0x90;
  196 + /**
  197 + * 修改SSID和密码响应包命令类型
  198 + */
  199 + public static final char CMD_MODIFY_SSID_AND_PWD_RESPONSE = 0x91;
  200 + /**
  201 + * 修改控制密码包命令类型
  202 + */
  203 + public static final byte CMD_MODIFY_CTRL_AND_PWD_REQUEST = (byte) 0x92;
  204 + /**
  205 + * 修改控制密码响应包命令类型
  206 + */
  207 + public static final char CMD_MODIFY_CTRL_PWD_RESPONSE = 0x93;
  208 + /**
  209 + * 获取主机联网状态命令类型
  210 + */
  211 + public static final byte CMD_NET_LINK_STATUS = (byte) 0xA0;
  212 + /**
  213 + * 获取主机联网状态响应包命令类型
  214 + */
  215 + public static final char CMD_NET_LINK_STATUS_RESPONSE = 0xA1;
  216 + /**
  217 + * 获取主机联网状态命令类型
  218 + */
  219 + public static final byte CMD_ROUTER_LIST_REQUEST = (byte) 0xB0;
  220 + /**
  221 + * 获取主机联网状态响应包命令类型
  222 + */
  223 + public static final char CMD_ROUTER_LIST_RESPONSE = 0xB1;
  224 + }
  225 +}
  1 +package com.qnbar.switchcontrol;
  2 +
  3 +import android.graphics.Rect;
  4 +import android.os.Bundle;
  5 +import android.support.v7.app.AppCompatActivity;
  6 +import android.support.v7.widget.GridLayoutManager;
  7 +import android.support.v7.widget.RecyclerView;
  8 +import android.util.Log;
  9 +import android.view.View;
  10 +import android.widget.Toast;
  11 +import com.adroplat.fist_switch.jni.Device;
  12 +import com.adroplat.fist_switch.jni.FistJni;
  13 +import com.adroplat.fist_switch.jni.SubDevice;
  14 +import com.adroplat.fist_switch.utils.protocol.one.FistProtocol;
  15 +import com.google.gson.Gson;
  16 +import com.qnbar.switchcontrol.adapter.DeviceListAdapter;
  17 +import com.qnbar.switchcontrol.adapter.SwitchListAdapter;
  18 +import com.qnbar.switchcontrol.model.SwitchMessageEvent;
  19 +import org.greenrobot.eventbus.EventBus;
  20 +import org.greenrobot.eventbus.Subscribe;
  21 +import org.greenrobot.eventbus.ThreadMode;
  22 +
  23 +import java.util.ArrayList;
  24 +
  25 +public class SwitchControlActivity extends AppCompatActivity {
  26 + private String deviceStrKey = "123456";
  27 +
  28 + @Override
  29 + protected void onCreate(Bundle savedInstanceState) {
  30 + super.onCreate(savedInstanceState);
  31 + setContentView(R.layout.content_main);
  32 +// Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  33 +// setSupportActionBar(toolbar);
  34 +// if (getSupportActionBar() != null) {
  35 +// getSupportActionBar().setTitle("智能开关设置");
  36 +// }
  37 + EventBus.getDefault().register(this);
  38 + //EventBus,List of Hub,List of Lights
  39 + //TODO save DeviceNum,SubDeviceNum
  40 + initList();
  41 + FistJni fistJni = FistJni.getInstance();
  42 + fistJni.startSdk();
  43 + searchLocalDevice();
  44 + }
  45 +
  46 + public void searchLocalDevice() {
  47 + FistJni fistJni = FistJni.getInstance();
  48 + fistJni.searchLocalDevice();
  49 + }
  50 +
  51 + DeviceListAdapter hubAdapter;
  52 + SwitchListAdapter switchAdapter;
  53 + RecyclerView hubRv;
  54 + RecyclerView switchRv;
  55 +
  56 + void initList() {
  57 + hubRv = (RecyclerView) findViewById(R.id.hubsRv);
  58 + hubAdapter = new DeviceListAdapter();
  59 +
  60 + GridLayoutManager layoutManager = new /*Focus*/GridLayoutManager(this, 5);
  61 + GridLayoutManager layoutManager2 = new /*Focus*/GridLayoutManager(this, 5);
  62 + hubRv.setLayoutManager(layoutManager);
  63 + hubRv.addItemDecoration(new MovieItemDecoration());
  64 + hubAdapter.setListener(new DeviceListAdapter.OnRecyclerViewItemClickListener() {
  65 + @Override
  66 + public void onItemClick(Device light, int position) {
  67 + Device device = null;
  68 + for (Device deviceCur : FistJni.getHubs()) {
  69 + if (deviceCur.getDeviceStrKey().equals(deviceStrKey)) {
  70 + device = deviceCur;
  71 + }
  72 + }
  73 + if (device == null) {
  74 + toast("没有发现当前配置主机");
  75 + return;
  76 + }
  77 + FistJni.getInstance().query(new Gson().toJson(light));
  78 + }
  79 +
  80 + @Override
  81 + public void onLongClick(Device light, int position) {
  82 +
  83 + }
  84 +
  85 + @Override
  86 + public void onMenuClick(View v, int position) {
  87 + deviceStrKey = FistJni.getHubs().get(position).getDeviceStrKey();
  88 + toast("重设控制口令");
  89 + Log.d("menu", "reset control hub:" + deviceStrKey);
  90 + }
  91 + });
  92 + hubRv.setAdapter(hubAdapter);
  93 + hubRv.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
  94 +
  95 +
  96 + switchAdapter = new SwitchListAdapter();
  97 + switchRv = (RecyclerView) findViewById(R.id.switchRv);
  98 +
  99 + switchRv.setLayoutManager(layoutManager2);
  100 + switchRv.addItemDecoration(new MovieItemDecoration());
  101 + switchAdapter.setListener(new SwitchListAdapter.OnRecyclerViewItemClickListener() {
  102 + @Override
  103 + public void onItemClick(SubDevice light, int position) {
  104 + Device device = null;
  105 + for (Device deviceCur : FistJni.getHubs()) {
  106 + if (deviceCur.getDeviceStrKey().equals(deviceStrKey)) {
  107 + device = deviceCur;
  108 + }
  109 + }
  110 + if (device == null) {
  111 + toast("当前控制口令出错,请重新选择控制主机按menu设置");
  112 + return;
  113 + }
  114 + if (light.getSubDeviceStatus() == 0) {
  115 + light.setSubDeviceStatus(1);
  116 + } else {
  117 + light.setSubDeviceStatus(0);
  118 + }
  119 + ArrayList<SubDevice> subDevices = new ArrayList<>();
  120 + subDevices.add(light);
  121 + device.setSubDevices(subDevices);
  122 + FistJni.getInstance().normalC(new Gson().toJson(device));
  123 + }
  124 +
  125 +
  126 + @Override
  127 + public void onLongClick(SubDevice light, int position) {
  128 +
  129 + }
  130 +
  131 + @Override
  132 + public void onMenuClick(View v, int position) {
  133 + Device device = null;
  134 + for (Device deviceCur : FistJni.getHubs()) {
  135 + if (deviceCur.getDeviceStrKey().equals(deviceStrKey)) {
  136 + device = deviceCur;
  137 + }
  138 + }
  139 + if (device == null) {
  140 + toast("当前控制口令出错,请重新选择控制主机按menu设置");
  141 + return;
  142 + }
  143 +
  144 + ArrayList<SubDevice> subDevices = new ArrayList<>();
  145 + subDevices.add(FistJni.getSubDevices().get(position));
  146 + device.setSubDevices(subDevices);
  147 + FistJni.getInstance().delSub(new Gson().toJson(device));
  148 + FistJni.getSubDevices().clear();
  149 + switchAdapter.notifyDataSetChanged();
  150 + }
  151 + });
  152 + switchRv.setAdapter(switchAdapter);
  153 + switchRv.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
  154 + }
  155 +
  156 + public void startAdd(View view) {
  157 + FistJni fistJni = FistJni.getInstance();
  158 + final Device device = FistJni.getHubs().get(0);
  159 + fistJni.startAdd(new Gson().toJson(device));
  160 + }
  161 +
  162 + public void stopAdd(View view) {
  163 + FistJni fistJni = FistJni.getInstance();
  164 +
  165 + final Device device = FistJni.getHubs().get(0);
  166 + fistJni.stopAdd(new Gson().toJson(device));
  167 + }
  168 +
  169 + public void resetPwd(View view) {
  170 + FistJni fistJni = FistJni.getInstance();
  171 + Device device = FistJni.getHubs().get(0);
  172 + fistJni.modifyPwd(new Gson().toJson(device), "123456");
  173 + }
  174 +
  175 + public void getLinkStatus(View view) {
  176 + FistJni fistJni = FistJni.getInstance();
  177 + Device device = FistJni.getHubs().get(0);
  178 + fistJni.getLinkStatus(new Gson().toJson(device));
  179 + }
  180 +
  181 + public void setLinkMsg(View view) {
  182 + FistJni fistJni = FistJni.getInstance();
  183 + Device device = FistJni.getHubs().get(0);
  184 +// fistJni.getlinkRouter(new Gson().toJson(device),"Xiaomi123","88888888");
  185 + fistJni.getlinkRouter(new Gson().toJson(device), "LEMOMOFFICE2.4G", "88888888");
  186 + }
  187 +
  188 + public void scanHubs(View view) {
  189 + searchLocalDevice();
  190 + }
  191 +
  192 + public void openSdk(View view) {
  193 + FistJni fistJni = FistJni.getInstance();
  194 + fistJni.startSdk();
  195 + }
  196 +
  197 + public class MovieItemDecoration extends RecyclerView.ItemDecoration {
  198 + @Override
  199 + public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
  200 + RecyclerView.State state) {
  201 + outRect.top = 40;
  202 + outRect.left = 15;
  203 + outRect.right = 15;
  204 + outRect.bottom = 40;
  205 + }
  206 + }
  207 +
  208 + @Subscribe(threadMode = ThreadMode.MAIN)
  209 + public void onMoonEvent(SwitchMessageEvent switchMessageEvent) {
  210 + switch (switchMessageEvent.getEventId()) {
  211 + case FistJni.DEVICE_HUBS_ONLINE_NOTIFY:
  212 + case FistProtocol.CommondType.CMD_TYPE_SEARCH_RESPONSE:
  213 + Log.d("qnbar_switch", switchMessageEvent.getMessage());
  214 + hubAdapter.notifyDataSetChanged();
  215 + break;
  216 + case FistJni.DEVICE_SWITCH_ONLINE_NOTIFY:
  217 + case FistProtocol.CommondType.CMD_TYPE_QUERY_RESPONSE:
  218 + Log.d("qnbar_switch", switchMessageEvent.getMessage());
  219 + switchAdapter.notifyDataSetChanged();
  220 + break;
  221 + case FistJni.DEVICE_SWITCH_ADD_OVER:
  222 + case FistProtocol.CommondType.CMD_TYPE_ADD_OVER:
  223 + Log.d("qnbar_switch", switchMessageEvent.getMessage());
  224 + toast("设备添加完成");
  225 + break;
  226 + case FistProtocol.CommondType.CMD_TYPE_ADD_OVER_RESPONSE:
  227 + Log.d("qnbar_switch", switchMessageEvent.getMessage());
  228 + toast("子设备有变动");
  229 + break;
  230 + default:
  231 + Log.d("qnbar_switch", "default:" + switchMessageEvent.getMessage() + "," + switchMessageEvent.getEventId());
  232 + break;
  233 + }
  234 + }
  235 +
  236 + private void toast(String msg) {
  237 + Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
  238 + }
  239 +
  240 + @Override
  241 + protected void onDestroy() {
  242 + super.onDestroy();
  243 + EventBus.getDefault().unregister(this);
  244 + }
  245 +}
  1 +package com.qnbar.switchcontrol;
  2 +
  3 +import android.util.Log;
  4 +
  5 +import java.io.IOException;
  6 +import java.net.DatagramPacket;
  7 +import java.net.DatagramSocket;
  8 +import java.net.InetAddress;
  9 +import java.net.SocketException;
  10 +/**
  11 + * UdpHelper帮助类
  12 + *
  13 + */
  14 +public class UdpHelper{
  15 + public Boolean IsThreadDisable = false;//指示监听线程是否终止
  16 + InetAddress mInetAddress;
  17 +
  18 + public void StartListen() {
  19 + // UDP服务器监听的端口
  20 + Integer port = 9000;
  21 + // 接收的字节大小,客户端发送的数据不能超过这个大小
  22 + byte[] message = new byte[4096];
  23 + try {
  24 + // 建立Socket连接
  25 + DatagramSocket datagramSocket = new DatagramSocket(port);
  26 + datagramSocket.setBroadcast(true);
  27 + try {
  28 + while (!IsThreadDisable) {
  29 + // 准备接收数据
  30 + Log.d("UDP_Demo", "准备接受");
  31 +
  32 + DatagramPacket datagramPacket = new DatagramPacket(message,
  33 + message.length);
  34 + datagramSocket.receive(datagramPacket);
  35 + String strMsg=new String(datagramPacket.getData()).trim();
  36 + Log.d("UDP_Demo", datagramPacket.getAddress().getHostAddress()
  37 + + ":" +strMsg );
  38 + }
  39 + } catch (IOException e) {//IOException
  40 + e.printStackTrace();
  41 + }
  42 + } catch (SocketException e) {
  43 + e.printStackTrace();
  44 + }
  45 + }
  46 + /* public static void send(String message) {
  47 + message = (message == null ? “Hello IdeasAndroid!” : message);
  48 + int server_port = 8904;
  49 + Log.d(“UDP Demo”, “UDP发送数据:”+message);
  50 + DatagramSocket s = null;
  51 + try {
  52 + s = new DatagramSocket();
  53 + } catch (SocketException e) {
  54 + e.printStackTrace();
  55 + }
  56 + InetAddress local = null;
  57 + try {
  58 + local = InetAddress.getByName(“255.255.255.255”);
  59 + } catch (UnknownHostException e) {
  60 + e.printStackTrace();
  61 + }
  62 + int msg_length = message.length();
  63 + byte[] messageByte = message.getBytes();
  64 + DatagramPacket p = new DatagramPacket(messageByte, msg_length, local,
  65 + server_port);
  66 + try {
  67 + s.send(p);
  68 + s.close();
  69 +
  70 + } catch (IOException e) {
  71 + e.printStackTrace();
  72 + }
  73 + }*/
  74 +}
  1 +package com.qnbar.switchcontrol;
  2 +
  3 +import android.os.Handler;
  4 +import android.os.Message;
  5 +import android.text.TextUtils;
  6 +import android.util.Log;
  7 +
  8 +import java.net.DatagramPacket;
  9 +import java.net.DatagramSocket;
  10 +import java.net.InetAddress;
  11 +import java.net.InetSocketAddress;
  12 +import java.net.UnknownHostException;
  13 +
  14 +/**
  15 + * UDP通信接口类,采用单例模式,用ip和通信端口初始化
  16 + */
  17 +public class UdpPostSender extends Thread {
  18 +
  19 + public static final int MSG_What = 0x100;
  20 + protected static final int MSG_PARSE_DATA = 0x100;
  21 + private static final String TAG = "UdpPostSender";
  22 +
  23 + private boolean isThreadDisable = false;// 指示监听线程是否终止
  24 + private Handler mHandler;
  25 + private DatagramSocket udpSocket = null;
  26 + private DatagramPacket dataPacket = null;
  27 + private InetAddress broadcastAddr = null;
  28 + private int defaultPort;
  29 + private int remotePort;
  30 + private String ip;
  31 + private String remoteIp;
  32 +
  33 + public UdpPostSender(String iP, int defaultPort, int remotePort,
  34 + Handler handler) {
  35 + this.ip = iP;
  36 + this.defaultPort = defaultPort;
  37 + this.remotePort = remotePort;
  38 + this.mHandler = handler;
  39 +
  40 + initData();
  41 +
  42 + if (handler != null) {// 不需要接收恢复信息的udp
  43 + this.start();
  44 + }
  45 + }
  46 +
  47 + public String getRemoteIp() {
  48 + return remoteIp;
  49 + }
  50 +
  51 + @Override
  52 + public void run() {
  53 + startListen();
  54 + }
  55 +
  56 + private void initData() {
  57 + try {
  58 + if (udpSocket == null) {
  59 + udpSocket = new DatagramSocket(null);
  60 + udpSocket.setReuseAddress(true);
  61 + // udpSocket.setSoTimeout(5000);
  62 + udpSocket.bind(new InetSocketAddress(defaultPort));
  63 + }
  64 + Log.i("info", "ip----" + ip);
  65 + broadcastAddr = InetAddress.getByName(ip);
  66 +
  67 + } catch (Exception e) {
  68 + Log.i("info", e.getMessage());
  69 + }
  70 + }
  71 +
  72 + public void sendUDPmsg(final String command) {
  73 + byte out[] = command.getBytes();
  74 + dataPacket = new DatagramPacket(out, out.length);
  75 + dataPacket.setPort(remotePort);
  76 + try {
  77 + dataPacket.setAddress(InetAddress.getByName(remoteIp));
  78 + } catch (UnknownHostException e) {
  79 + Log.i("info", e.getMessage());
  80 + e.printStackTrace();
  81 + }
  82 + Log.e(TAG, "cmd" + command + broadcastAddr.toString());
  83 + new Thread() {
  84 + public void run() {
  85 + try {
  86 + udpSocket.send(dataPacket);
  87 + } catch (Exception e) {
  88 + e.printStackTrace();
  89 + }
  90 + }
  91 + }.start();
  92 + }
  93 +
  94 + public void startListen() {
  95 + while (!isThreadDisable) {
  96 + try {
  97 + // 准备接收数据
  98 + byte[] buf = new byte[4 * 1024];
  99 + DatagramPacket packet = new DatagramPacket(buf, buf.length);
  100 + initData();
  101 +// udpSocket.setSoTimeout(2 * 1000);
  102 + udpSocket.receive(packet);
  103 + Log.d("lovely_switch", "success");
  104 +// String ip = packet.getAddress().getHostAddress();
  105 + String cmd = new String(packet.getData(), 0, packet.getLength());
  106 + if (!TextUtils.isEmpty(cmd)) {
  107 + remoteIp = packet.getAddress().toString().replace("/", "");
  108 + }
  109 + Message m = Message.obtain();
  110 + m.what = MSG_PARSE_DATA;
  111 + m.obj = cmd;
  112 + mHandler.sendMessage(m);
  113 + } catch (Exception e) {
  114 + e.printStackTrace();
  115 + }
  116 + }
  117 + }
  118 +
  119 + public void stopListen() {
  120 + isThreadDisable = true;
  121 + }
  122 +}
  1 +/*
  2 + * Copyright 2017 wugian
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +
  17 +package com.qnbar.switchcontrol.adapter;
  18 +
  19 +import android.graphics.Color;
  20 +import android.support.v7.widget.RecyclerView;
  21 +import android.util.Log;
  22 +import android.view.KeyEvent;
  23 +import android.view.LayoutInflater;
  24 +import android.view.View;
  25 +import android.view.ViewGroup;
  26 +import android.widget.TextView;
  27 +import com.adroplat.fist_switch.jni.Device;
  28 +import com.adroplat.fist_switch.jni.FistJni;
  29 +import com.qnbar.switchcontrol.R;
  30 +
  31 +public class DeviceListAdapter extends RecyclerView.Adapter<DeviceListAdapter.DeviceHolder>
  32 + implements View.OnClickListener, View.OnLongClickListener {
  33 +
  34 + OnRecyclerViewItemClickListener listener;
  35 +
  36 + public void setListener(OnRecyclerViewItemClickListener listener) {
  37 + this.listener = listener;
  38 + }
  39 +
  40 + @Override
  41 + public DeviceHolder onCreateViewHolder(ViewGroup parent,
  42 + int viewType) {
  43 + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.hub_item, parent, false);
  44 + view.setFocusable(true);
  45 + view.setFocusableInTouchMode(true);
  46 + view.setOnClickListener(this);
  47 + view.setOnLongClickListener(this);
  48 + view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
  49 + @Override
  50 + public void onFocusChange(View v, boolean hasFocus) {
  51 + if (hasFocus) {
  52 + v.setBackgroundColor(Color.GRAY);
  53 + } else {
  54 + v.setBackgroundColor(Color.TRANSPARENT);
  55 + }
  56 + }
  57 + });
  58 + view.setOnKeyListener(new View.OnKeyListener() {
  59 + @Override
  60 + public boolean onKey(View view, int keycode, KeyEvent keyEvent) {
  61 + if (keycode == KeyEvent.KEYCODE_MENU && keyEvent.getAction() == KeyEvent.ACTION_UP) {
  62 + Log.d("menu", "onKey: key menu");
  63 + if (listener != null) {
  64 + listener.onMenuClick(view, (Integer) view.getTag());
  65 + }
  66 + return true;
  67 + }
  68 + return false;
  69 + }
  70 + });
  71 + return new DeviceHolder(view);
  72 + }
  73 +
  74 + @Override
  75 + public void onBindViewHolder(DeviceHolder holder, int position) {
  76 + int size = FistJni.getHubs().size();
  77 + if (position > size - 1 && size != 0) {
  78 + position = 0;
  79 + }
  80 + holder.itemView.setTag(position);
  81 + Device light = FistJni.getHubs().get(position);
  82 + holder.render(light);
  83 +// RelativeLayout item = (RelativeLayout)
  84 +// holder.itemView.findViewById(R.id.root);
  85 +// ViewGroup.LayoutParams layoutParams = item.getLayoutParams();
  86 +// layoutParams.width = itemWidth;
  87 +// layoutParams.height = itemHeight;
  88 +// item.setLayoutParams(layoutParams);
  89 + }
  90 +
  91 + @Override
  92 + public int getItemCount() {
  93 + return FistJni.getHubs().size()/* == 0 ? 0 : Lights.getInstance().size() + 2*/;
  94 + }
  95 +
  96 + @Override
  97 + public long getItemId(int position) {
  98 + return position;
  99 + }
  100 +
  101 +
  102 + @Override
  103 + public void onClick(View v) {
  104 + if (listener != null) {
  105 + Integer tag = (Integer) v.getTag();
  106 + listener.onItemClick(FistJni.getHubs().get(tag), tag);
  107 + }
  108 + }
  109 +
  110 + @Override
  111 + public boolean onLongClick(View v) {
  112 + if (listener != null) {
  113 + Integer tag = (Integer) v.getTag();
  114 + listener.onLongClick(FistJni.getHubs().get(tag), tag);
  115 + return true;
  116 + }
  117 + return false;
  118 + }
  119 +
  120 + class DeviceHolder extends RecyclerView.ViewHolder {
  121 +
  122 + TextView deviceNumTv;
  123 + TextView deviceIp;
  124 + TextView deviceKey;
  125 +
  126 + DeviceHolder(View v) {
  127 + super(v);
  128 + deviceNumTv = (TextView) v.findViewById(R.id.deviceNumTv);
  129 + deviceIp = (TextView) v.findViewById(R.id.deviceIp);
  130 + deviceKey = (TextView) v.findViewById(R.id.deviceKey);
  131 + }
  132 +
  133 + void render(Device light) {
  134 + deviceNumTv.setText("设备号:" + light.getStringDeviceNum() + "");
  135 + deviceIp.setText("IP:" + light.getStringDeviceIp());
  136 + deviceKey.setText("控制口令:" + light.getDeviceStrKey());
  137 + }
  138 + }
  139 +
  140 + public interface OnRecyclerViewItemClickListener {
  141 + void onItemClick(Device light, int position);
  142 +
  143 + void onLongClick(Device light, int position);
  144 +
  145 + void onMenuClick(View v, int position);
  146 + }
  147 +}
  1 +/*
  2 + * Copyright 2017 wugian
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +
  17 +package com.qnbar.switchcontrol.adapter;
  18 +
  19 +import android.graphics.Color;
  20 +import android.support.v7.widget.RecyclerView;
  21 +import android.util.Log;
  22 +import android.view.KeyEvent;
  23 +import android.view.LayoutInflater;
  24 +import android.view.View;
  25 +import android.view.ViewGroup;
  26 +import android.widget.TextView;
  27 +import com.adroplat.fist_switch.jni.FistJni;
  28 +import com.adroplat.fist_switch.jni.SubDevice;
  29 +import com.qnbar.switchcontrol.R;
  30 +
  31 +public class SwitchListAdapter extends RecyclerView.Adapter<SwitchListAdapter.DeviceHolder>
  32 + implements View.OnClickListener, View.OnLongClickListener {
  33 +
  34 + OnRecyclerViewItemClickListener listener;
  35 +
  36 + public void setListener(OnRecyclerViewItemClickListener listener) {
  37 + this.listener = listener;
  38 + }
  39 +
  40 + @Override
  41 + public DeviceHolder onCreateViewHolder(ViewGroup parent,
  42 + int viewType) {
  43 + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.switch_item, parent, false);
  44 + view.setFocusable(true);
  45 + view.setFocusableInTouchMode(true);
  46 + view.setOnClickListener(this);
  47 + view.setOnLongClickListener(this);
  48 + view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
  49 + @Override
  50 + public void onFocusChange(View v, boolean hasFocus) {
  51 + if (hasFocus) {
  52 + v.setBackgroundColor(Color.GRAY);
  53 + } else {
  54 + v.setBackgroundColor(Color.TRANSPARENT);
  55 + }
  56 + }
  57 + });
  58 + view.setOnKeyListener(new View.OnKeyListener() {
  59 + @Override
  60 + public boolean onKey(View view, int keycode, KeyEvent keyEvent) {
  61 + if (keycode == KeyEvent.KEYCODE_MENU && keyEvent.getAction() == KeyEvent.ACTION_UP) {
  62 + Log.d("menu", "onKey: key menu");
  63 + if (listener != null) {
  64 + listener.onMenuClick(view, (Integer) view.getTag());
  65 + }
  66 + return true;
  67 + }
  68 + return false;
  69 + }
  70 + });
  71 + return new DeviceHolder(view);
  72 + }
  73 +
  74 + @Override
  75 + public void onBindViewHolder(DeviceHolder holder, int position) {
  76 +// int size = FistJni.getSubDevices().size();
  77 +// if (position > size - 1 && size != 0) {
  78 +// position = 0;
  79 +// }
  80 + holder.itemView.setTag(position);
  81 + SubDevice light = FistJni.getSubDevices().get(position);
  82 + holder.render(light);
  83 +// RelativeLayout item = (RelativeLayout)
  84 +// holder.itemView.findViewById(R.id.root);
  85 +// ViewGroup.LayoutParams layoutParams = item.getLayoutParams();
  86 +// layoutParams.width = itemWidth;
  87 +// layoutParams.height = itemHeight;
  88 +// item.setLayoutParams(layoutParams);
  89 + }
  90 +
  91 + @Override
  92 + public int getItemCount() {
  93 + return FistJni.getSubDevices().size()/* == 0 ? 0 : Lights.getInstance().size() + 2*/;
  94 + }
  95 +
  96 + @Override
  97 + public long getItemId(int position) {
  98 + return position;
  99 + }
  100 +
  101 +
  102 + @Override
  103 + public void onClick(View v) {
  104 + if (listener != null) {
  105 + Integer tag = (Integer) v.getTag();
  106 + listener.onItemClick(FistJni.getSubDevices().get(tag), tag);
  107 + }
  108 + }
  109 +
  110 + @Override
  111 + public boolean onLongClick(View v) {
  112 + if (listener != null) {
  113 + Integer tag = (Integer) v.getTag();
  114 + listener.onLongClick(FistJni.getSubDevices().get(tag), tag);
  115 + return true;
  116 + }
  117 + return false;
  118 + }
  119 +
  120 + class DeviceHolder extends RecyclerView.ViewHolder {
  121 +
  122 + TextView subDeviceNum;
  123 + TextView subDeviceStatus;
  124 +
  125 + DeviceHolder(View v) {
  126 + super(v);
  127 + subDeviceNum = (TextView) v.findViewById(R.id.subDeviceNum);
  128 + subDeviceStatus = (TextView) v.findViewById(R.id.subDeviceStatus);
  129 + }
  130 +
  131 + void render(SubDevice light) {
  132 + subDeviceNum.setText("设备号:" + light.getSubDeviceNum() + "");
  133 + String statusStr = light.getSubDeviceStatus() == 1 ? "状态:开" : "状态:关";
  134 + this.subDeviceStatus.setText(statusStr);
  135 + }
  136 + }
  137 +
  138 + public interface OnRecyclerViewItemClickListener {
  139 + void onItemClick(SubDevice light, int position);
  140 +
  141 + void onLongClick(SubDevice light, int position);
  142 +
  143 + void onMenuClick(View v, int position);
  144 + }
  145 +}
  1 +package com.qnbar.switchcontrol.model;
  2 +
  3 +public class SwitchMessageEvent {
  4 + private int eventId;
  5 + private String message;
  6 +
  7 + public int getEventId() {
  8 + return eventId;
  9 + }
  10 +
  11 + public void setEventId(int eventId) {
  12 + this.eventId = eventId;
  13 + }
  14 +
  15 + public String getMessage() {
  16 + return message;
  17 + }
  18 +
  19 + public void setMessage(String message) {
  20 + this.message = message;
  21 + }
  22 +}
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<android.support.design.widget.CoordinatorLayout
  3 + xmlns:android="http://schemas.android.com/apk/res/android"
  4 + xmlns:app="http://schemas.android.com/apk/res-auto"
  5 + android:layout_width="match_parent"
  6 + android:layout_height="match_parent">
  7 +
  8 + <android.support.design.widget.AppBarLayout
  9 + android:layout_height="wrap_content"
  10 + android:layout_width="match_parent"
  11 + android:theme="@style/AppTheme.AppBarOverlay">
  12 +
  13 + <android.support.v7.widget.Toolbar
  14 + android:id="@+id/toolbar"
  15 + android:layout_width="match_parent"
  16 + android:layout_height="?attr/actionBarSize"
  17 + android:background="?attr/colorPrimary"
  18 + app:popupTheme="@style/AppTheme.PopupOverlay"/>
  19 +
  20 + </android.support.design.widget.AppBarLayout>
  21 +
  22 + <include layout="@layout/content_main"/>
  23 +
  24 + <android.support.design.widget.FloatingActionButton
  25 + android:id="@+id/fab"
  26 + android:layout_width="wrap_content"
  27 + android:layout_height="wrap_content"
  28 + android:layout_gravity="bottom|end"
  29 + android:layout_margin="@dimen/fab_margin"
  30 + app:srcCompat="@android:drawable/ic_dialog_email"/>
  31 +
  32 +</android.support.design.widget.CoordinatorLayout>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<LinearLayout
  3 + xmlns:android="http://schemas.android.com/apk/res/android"
  4 + xmlns:tools="http://schemas.android.com/tools"
  5 + xmlns:app="http://schemas.android.com/apk/res-auto"
  6 + android:background="#ac0097ca"
  7 + android:layout_width="match_parent"
  8 + android:layout_height="match_parent"
  9 + android:padding="16dp"
  10 + android:orientation="vertical"
  11 + app:layout_behavior="@string/appbar_scrolling_view_behavior"
  12 + tools:showIn="@layout/activity_switch_control"
  13 + tools:context="com.qnbar.switchcontrol.SwitchControlActivity">
  14 +
  15 + <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal">
  16 +
  17 + <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="扫描主机"
  18 + android:onClick="scanHubs"/>
  19 +
  20 + <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="开始添加"
  21 + android:onClick="startAdd"/>
  22 +
  23 + <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="结束添加"
  24 + android:onClick="stopAdd"/>
  25 +
  26 + <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="重设置密码"
  27 + android:onClick="resetPwd"/>
  28 +
  29 + <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="设置路由信息"
  30 + android:onClick="setLinkMsg"/>
  31 +
  32 + <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="获取路由信息"
  33 + android:onClick="getLinkStatus"/>
  34 +
  35 +
  36 + </LinearLayout>
  37 + <TextView android:layout_width="wrap_content"
  38 + android:layout_height="wrap_content"
  39 + android:text="控制主机"
  40 + android:textSize="20sp"/>
  41 +
  42 + <android.support.v7.widget.RecyclerView
  43 + android:id="@+id/hubsRv"
  44 + android:layout_marginTop="15dp"
  45 + android:layout_width="match_parent"
  46 + android:layout_height="wrap_content"
  47 + android:layout_alignParentStart="true"
  48 + android:layout_below="@+id/button"/>
  49 +
  50 + <TextView android:layout_width="wrap_content"
  51 + android:layout_height="wrap_content"
  52 + android:layout_marginTop="30dp"
  53 + android:text="开关"
  54 + android:textSize="20sp"/>
  55 +
  56 + <android.support.v7.widget.RecyclerView
  57 + android:id="@+id/switchRv"
  58 + android:layout_marginTop="15dp"
  59 + android:layout_width="match_parent"
  60 + android:layout_height="wrap_content"
  61 + android:layout_alignParentStart="true"
  62 + android:layout_below="@+id/button"/>
  63 +
  64 +</LinearLayout>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="match_parent"
  4 + android:padding="5dp"
  5 + android:layout_height="wrap_content"
  6 + android:gravity="center"
  7 + android:orientation="vertical"
  8 +>
  9 + <ImageView android:layout_width="80dp" android:layout_height="80dp"
  10 + android:background="@mipmap/host"/>
  11 + <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
  12 + android:id="@+id/deviceNumTv"
  13 + android:textSize="16sp"
  14 + android:visibility="visible"
  15 + android:textColor="@android:color/black"
  16 + android:text="device num"
  17 + />
  18 +
  19 + <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
  20 + android:id="@+id/deviceIp"
  21 + android:text="device ip"
  22 + android:textSize="16sp"
  23 + android:textColor="@android:color/black"
  24 + android:layout_marginTop="4dp"
  25 + />
  26 +
  27 + <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
  28 + android:id="@+id/deviceKey"
  29 + android:layout_marginTop="4dp"
  30 + android:textSize="16sp"
  31 + android:textColor="@android:color/black"
  32 + android:text="device key"
  33 + />
  34 +
  35 +</LinearLayout>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="match_parent"
  4 + android:padding="5dp"
  5 + android:gravity="center"
  6 + android:layout_height="wrap_content"
  7 + android:orientation="vertical"
  8 +>
  9 + <ImageView android:layout_width="80dp" android:layout_height="80dp"
  10 + android:background="@mipmap/equipment_switch"/>
  11 +
  12 + <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
  13 + android:id="@+id/subDeviceNum"
  14 + android:textSize="16sp"
  15 + android:textColor="@android:color/black"
  16 + android:text="SubDeviceNum"
  17 + />
  18 + <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
  19 + android:id="@+id/subDeviceStatus"
  20 + android:textSize="16sp"
  21 + android:layout_marginTop="4dp"
  22 + android:textColor="@android:color/black"
  23 + android:text="SubDeviceStatus"
  24 + />
  25 +
  26 +
  27 +</LinearLayout>
  1 +<resources>
  2 + <!-- Example customization of dimensions originally defined in res/values/dimens.xml
  3 + (such as screen margins) for screens with more than 820dp of available width. This
  4 + would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
  5 + <dimen name="activity_horizontal_margin">64dp</dimen>
  6 +</resources>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<resources>
  3 + <color name="colorPrimary">#3F51B5</color>
  4 + <color name="colorPrimaryDark">#303F9F</color>
  5 + <color name="colorAccent">#FF4081</color>
  6 +</resources>
  1 +<resources>
  2 + <!-- Default screen margins, per the Android Design guidelines. -->
  3 + <dimen name="activity_horizontal_margin">16dp</dimen>
  4 + <dimen name="activity_vertical_margin">16dp</dimen>
  5 + <dimen name="fab_margin">16dp</dimen>
  6 +</resources>
  1 +<resources>
  2 + <string name="app_name">SwitchControl</string>
  3 + <string name="title_activity_switch_control">SwitchControlActivity</string>
  4 +</resources>
  1 +<resources>
  2 +
  3 + <!-- Base application theme. -->
  4 + <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
  5 + <!-- Customize your theme here. -->
  6 + <item name="colorPrimary">@color/colorPrimary</item>
  7 + <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
  8 + <item name="colorAccent">@color/colorAccent</item>
  9 + </style>
  10 + <style name="AppTheme.NoActionBar">
  11 + <item name="windowActionBar">false</item>
  12 + <item name="windowNoTitle">true</item>
  13 + </style>
  14 + <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
  15 + <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
  16 +
  17 +</resources>
  1 +package com.qnbar.switchcontrol;
  2 +
  3 +import org.junit.Test;
  4 +
  5 +import static org.junit.Assert.*;
  6 +
  7 +/**
  8 + * Example local unit test, which will execute on the development machine (host).
  9 + *
  10 + * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
  11 + */
  12 +public class ExampleUnitTest {
  13 + @Test
  14 + public void addition_isCorrect() throws Exception {
  15 + assertEquals(4, 2 + 2);
  16 + }
  17 +}
@@ -44,5 +44,5 @@ android { @@ -44,5 +44,5 @@ android {
44 44
45 dependencies { 45 dependencies {
46 compile fileTree(include: ['*.jar'], dir: 'libs') 46 compile fileTree(include: ['*.jar'], dir: 'libs')
47 - provided 'com.google.code.gson:gson:2.4' 47 + provided 'com.google.code.gson:gson:2.7'
48 } 48 }
Please register or login to post a comment