1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
package com.ihealth.ihealthlibrary;
import android.text.TextUtils;
import android.util.Log;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.module.annotations.ReactModule;
import com.ihealth.communication.control.HS6Control;
import com.ihealth.communication.manager.iHealthDeviceHs6Callback;
import com.ihealth.communication.manager.iHealthDevicesManager;
import java.util.HashMap;
import java.util.Map;
/**
* Created by lixuesong on 16/10/20.
*/
@ReactModule(name = "HS6Module")
public class HS6Module extends iHealthBaseModule {
private static final String modelName = "HS6Module";
private static final String TAG = "HS6Module";
private static final String EVENT_NOTIFY = "event_notify_hs6";
private ReactApplicationContext mContext;
private HS6Control mHS6control;
public HS6Module(ReactApplicationContext reactContext) {
super(TAG, reactContext);
this.mContext = reactContext;
}
@Override
public String getName() {
return modelName;
}
@Override
public Map<String, Object> getConstants() {
Map<String, Object> map = new HashMap<>();
map.put("Event_Notify", EVENT_NOTIFY);
return map;
}
@ReactMethod
public void init(String userName) {
mHS6control = new HS6Control(userName, mContext, iHealthDevicesManager.TYPE_HS6, mIHealthDeviceHs6Callback);
}
@ReactMethod
public void setWifi(String ssid, String password) {
if (mHS6control != null) {
mHS6control.setWifi(ssid, password);
} else {
Log.e(TAG, "Please call init(String username) method first");
}
}
@ReactMethod
public void bindDeviceHS6(String birthday, float weight, int height, int isSporter, int gender, String serialNumber) {
if (mHS6control != null) {
mHS6control.bindDeviceHS6(birthday, weight, height, isSporter, gender, serialNumber);
} else {
Log.e(TAG, "Please call init(String username) method first");
}
}
@ReactMethod
public void unBindDeviceHS6(String serialNumber) {
if (mHS6control != null) {
mHS6control.unBindDeviceHS6(serialNumber);
} else {
Log.e(TAG, "Please call init(String username) method first");
}
}
@ReactMethod
public void getToken(String clientId, String clientSecret, String username, String clientPara) {
if (mHS6control != null) {
mHS6control.getToken(clientId, clientSecret, username, clientPara);
} else {
Log.e(TAG, "Please call init(String username) method first");
}
}
@ReactMethod
public void setUnit(String username, int unitType) {
if (mHS6control != null) {
mHS6control.setUnit(username, unitType);
} else {
Log.e(TAG, "Please call init(String username) method first");
}
}
@ReactMethod
public void getCloudData(String clientId, String clientSecret, String username, double downloadTS, double pageSize) {
if (mHS6control != null) {
mHS6control.getDataByMeasuretimeFromCloud(clientId, clientSecret, username, (long) downloadTS, (long) pageSize);
} else {
Log.e(TAG, "Please call init(String username) method first");
}
}
@Override
public void handleNotify(String mac, String deviceType, String action, String message) {
WritableMap params = Arguments.createMap();
params.putString("action", action);
params.putString("mac", mac);
params.putString("type", deviceType);
if (!TextUtils.isEmpty(message)) {
Utils.jsonToMap(message, params);
}
sendEvent(EVENT_NOTIFY, params);
}
private iHealthDeviceHs6Callback mIHealthDeviceHs6Callback = new iHealthDeviceHs6Callback() {
public void setWifiNotify(String deviceType, String action, String message) {
WritableMap params = Arguments.createMap();
params.putString("action", action);
params.putString("deviceType", deviceType);
if (!TextUtils.isEmpty(message)) {
Utils.jsonToMap(message, params);
}
sendEvent(EVENT_NOTIFY, params);
}
public void onNotify(String mac, String deviceType, String action, String message) {
handleNotify(mac, deviceType, action, message);
}
};
}
|