@@ -0,0 +1,8 @@ | |||
*.iml | |||
.gradle | |||
/local.properties | |||
/.idea | |||
.DS_Store | |||
/build | |||
/captures | |||
.externalNativeBuild |
@@ -0,0 +1,391 @@ | |||
# AILink SDK Instructions - Android | |||
[aar package download address](https://github.com/elinkthings/AILinkSdkDemoAndroid/releases) | |||
[key registered address](http://sdk.aicare.net.cn) | |||
[中文文档](README_CN.md) | |||
This document is to guide Android developers to integrate AILink-SDK-Android in Android 4.4 and above systems, and it is mainly for some key usage examples. | |||
## 1. Conditions of use: | |||
1. Android SDK minimum version android4.4 (API 19). | |||
2. The Bluetooth version used by the device needs 4.0 and above. | |||
3.Configure java1.8 | |||
4. The project depends on the androidx library | |||
## 二, import SDK | |||
``` | |||
repositories { | |||
flatDir { | |||
dirs 'libs' | |||
} | |||
} | |||
1. Add the JitPack repository to your build file | |||
Add this to the root build.gradle at the end of the repository: | |||
allprojects { | |||
repositories { | |||
... | |||
maven { url 'https://jitpack.io' } | |||
} | |||
} | |||
2. Add dependencies | |||
dependencies { | |||
... | |||
implementation 'com.github.elinkthings:AILinkSDKRepositoryAndroid:1.2.9'//Bluetooth library | |||
implementation 'com.github.elinkthings:AILinkSDKParsingLibraryAndroid:1.2.9'//Parsing library | |||
} | |||
3.Configure java1.8 in gradle | |||
android { | |||
... | |||
compileOptions { | |||
sourceCompatibility 1.8 | |||
targetCompatibility 1.8 | |||
} | |||
} | |||
You can also use the aar package dependency. Please download it to the project's libs yourself. | |||
The download address is at the top of the document. | |||
``` | |||
## 二、Permission settings | |||
``` | |||
<!--In most cases, you need to ensure that the device supports BLE.--> | |||
<uses-feature | |||
android:name="android.hardware.bluetooth_le" | |||
android:required="true"/> | |||
<uses-permission android:name="android.permission.BLUETOOTH"/> | |||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> | |||
<!--Android 6.0 and above. Bluetooth scanning requires one of the following two permissions. You need to apply at run time.--> | |||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> | |||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> | |||
<!--Optional. If your app need dfu function.--> | |||
<uses-permission android:name="android.permission.INTERNET"/> | |||
``` | |||
> 6.0 and above systems must locate permissions, and need to obtain permissions manually | |||
## 三, start integration | |||
> Add below AndroidManifest.xml application tag | |||
``` | |||
<application> | |||
... | |||
<service android:name="com.pingwang.bluetoothlib.server.ELinkBleServer"/> | |||
</application> | |||
``` | |||
> > Initialize [key registered address](http://sdk.aicare.net.cn) | |||
``` | |||
// Call in application | |||
AILinkSDK.getInstance().init(this, key, secret); | |||
``` | |||
> You can use the BleBeseActivity class provided in the library, | |||
and inherit the implementation method | |||
### 1, Bind service: | |||
``` | |||
ps:Bind services where you need to handle Bluetooth, get Bluetooth device objects to handle, or comprehensively handle them in one place. | |||
private void bindService() { | |||
if (bindIntent == null) { | |||
bindIntent = new Intent(this, ELinkBleServer.class); | |||
if (mFhrSCon != null) | |||
this.bindService(bindIntent, mFhrSCon, Context.BIND_AUTO_CREATE); | |||
} | |||
} | |||
private ServiceConnection mFhrSCon = new ServiceConnection() { | |||
@Override | |||
public void onServiceConnected(ComponentName name, IBinder service) { | |||
//Establish a connection with the service | |||
mBluetoothService = ((ELinkBleServer.BluetoothBinder) service).getService(); | |||
onServiceSuccess(); | |||
} | |||
@Override | |||
public void onServiceDisconnected(ComponentName name) { | |||
//Disconnect from the service | |||
mBluetoothService = null; | |||
onServiceErr(); | |||
} | |||
}; | |||
``` | |||
### 2, Set the mBluetoothService.setOnCallback (); | |||
``` | |||
Implement OnCallbackBle interface to get search, connect, disconnect status and data | |||
/ ** | |||
* Bluetooth search, connection and other operating interfaces | |||
* / | |||
public interface OnCallbackBle extends OnCallback { | |||
/ ** | |||
* Start scanning device | |||
* / | |||
default void onStartScan () () | |||
/ ** | |||
* Called back every time a device is scanned | |||
* / | |||
default void onScanning (BleValueBean data) () | |||
/ ** | |||
* Scan timeout (completed) | |||
* / | |||
default void onScanTimeOut () () | |||
/ ** | |||
* connecting | |||
* / | |||
default void onConnecting (String mac) () | |||
/ ** | |||
* Connection disconnected in UI thread | |||
* / | |||
default void onDisConnected (String mac, int code) {} | |||
/ ** | |||
* Successful connection (discover service), in UI thread | |||
* / | |||
default void onServicesDiscovered (String mac) {} | |||
/ ** | |||
* Bluetooth is turned on, triggering thread | |||
* / | |||
default void bleOpen () {} | |||
/ ** | |||
* Bluetooth is not turned on, triggering thread | |||
* / | |||
default void bleClose () {} | |||
} | |||
``` | |||
### 3, search for mBluetoothService.scanLeDevice (long timeOut);//timeOut milliseconds | |||
``` | |||
/ ** | |||
* Search device | |||
* Scanning too often will cause scanning to fail | |||
* Need to ensure that the total duration of 5 scans exceeds 30s | |||
* @param timeOut timeout time, milliseconds (how long to search to get data, 0 means always searching) | |||
* / | |||
scanLeDevice (long timeOut) | |||
/ ** | |||
* Search device | |||
* Scanning too often will cause scanning to fail | |||
* Need to ensure that the total duration of 5 scans exceeds 30s | |||
* @param timeOut timeout time, milliseconds (how long to search to get data, 0 means always searching) | |||
* @param scanUUID filtered UUID (empty / null code does not filter) | |||
* / | |||
scanLeDevice (long timeOut, UUID scanUUID) | |||
The discovered device will be returned in onScanning (BleValueBean data) in the OnCallbackBle interface | |||
``` | |||
### 4, connect mBluetoothService.connectDevice (String mAddress); | |||
``` | |||
Note: It is recommended to stop searching for mBluetoothService.stopScan () before connecting, | |||
so the connection process will be more stable After the connection is successful and the service is successfully obtained, | |||
it will be returned in onServicesDiscovered (String mac) in the OnCallbackBle interface | |||
``` | |||
### 5,Disconnect | |||
``` | |||
Disconnect all connections mBluetoothService.disconnectAll (), | |||
since this library supports multiple connections, only the method of disconnecting the device is provided in the service | |||
``` | |||
### 6, Get connected device object | |||
``` | |||
BleDevice bleDevice = mBluetoothService.getBleDevice (mAddress); | |||
The BleDevice object has all operations on this device, including operations such as disconnecting, sending instructions, receiving instructions, etc. | |||
BleDevice.disconnect (); // Disconnect | |||
BleDevice.sendData (SendDataBean sendDataBean) // Send instructions, the content needs to be encapsulated with SendDataBean | |||
/ ** | |||
* @param hex content | |||
* @param uuid feature uuid to operate | |||
* @param type operation type (1 = read, 2 = write, 3 = signal strength) {@link BleConfig} | |||
* @param uuidService service uuid (Generally, no setting is needed, just use the default one) | |||
* / | |||
public SendDataBean (byte [] hex, UUID uuid, int type, UUID uuidService) { | |||
this.hex = hex; | |||
this.uuid = uuid; | |||
this.type = type; | |||
if (uuidService! = null) | |||
this.uuidService = uuidService; | |||
} | |||
Under normal circumstances, you can use a subclass of SendDataBean; | |||
Since there is a sending queue for sending data, the SendDataBean object is not recommended to be reused to avoid data overwriting; | |||
SendBleBean is used to interact with the Bluetooth module; | |||
SendMcuBean is used to interact with MCU; | |||
If there is a need for custom transparent data transmission, please inherit SendDataBean or send it using SendDataBean object. | |||
``` | |||
## 四, more commonly used interface introduction | |||
### 1, setOnBleVersionListener (OnBleVersionListener bleVersionListener) in BleDevice // device version number, unit interface | |||
``` | |||
public interface OnBleVersionListener { | |||
/ ** | |||
* BM module software and hardware version number | |||
* / | |||
default void onBmVersion (String version) () | |||
/ ** | |||
* mcu supported units (all are supported by default) | |||
* @param list null or empty means support all | |||
* / | |||
default void onSupportUnit (List <SupportUnitBean> list) {} | |||
} | |||
``` | |||
### 2, setOnMcuParameterListener (OnMcuParameterListener mcuParameterListener) in BleDevice // Power, time interface | |||
``` | |||
public interface OnMcuParameterListener { | |||
/ ** | |||
* mcu battery status | |||
* @param status current battery status (0 = no charge, 1 = charging, 2 = full charge, 3 = charging abnormality) | |||
* @param battery current battery percentage (0 ~ 100), default: 0xFFFF | |||
* / | |||
default void onMcuBatteryStatus (int status, int battery) () | |||
/ ** | |||
* system time | |||
* @param status time status (0 = invalid, 1 = valid) | |||
* @param times time array (year, month, day, hour, minute, second) | |||
* / | |||
default void onSysTime (int status, int [] times) {} | |||
} | |||
``` | |||
### 3, setOnBleOtherDataListener (OnBleOtherDataListener onBleOtherDataListener) in BleDevice // Transparent data interface, if the data format does not conform to the protocol, this interface will return data | |||
``` | |||
public interface OnBleOtherDataListener { | |||
/ ** | |||
* Transparent data | |||
* @param data does not support protocol transparent data | |||
* / | |||
void onNotifyOtherData (byte [] data); | |||
} | |||
``` | |||
## 五, matters needing attention | |||
#### 1.The Bluetooth library only provides data, and analyzes some ble data. The data connected to the MCU module is not parsed. | |||
#### 2, Please use the AILinkBleParsingAndroid library for module data analysis, which provides analysis templates for each module | |||
#### 3, AILinkBleParsingAndroid library needs to rely on AILinkSDKRepositoryAndroid library, it is not recommended to use it alone | |||
#### 4, The BaseBleDeviceData object is the base class object of the module device. It is recommended to inherit the implementation operation. For more details, please refer to the template in the AILinkBleParsingAndroid library. | |||
#### 5, AILinkBleParsingAndroid library has source code provided, you can find start on github | |||
#### 6, For more operations, please refer to the demo, you can clone this project | |||
## 六, AILinkBleParsingAndroid library overview | |||
#### 1, baby scale | |||
``` | |||
BabyDeviceData parsing class | |||
BabyBleConfig directive configuration class | |||
``` | |||
#### 2, height gauge | |||
``` | |||
HeightDeviceData Parsing Class | |||
HeightBleConfig directive configuration class | |||
``` | |||
#### 3, sphygmomanometer | |||
``` | |||
SphyDeviceData parsing class | |||
SphyBleConfig instruction configuration class | |||
``` | |||
#### 4, thermometer | |||
``` | |||
TempDeviceData parsing class | |||
TempBleConfig instruction configuration class | |||
``` | |||
#### 5, forehead gun | |||
``` | |||
TempGunDeviceData parsing class | |||
TempGunBleConfig instruction configuration class | |||
``` | |||
#### 6, TPMS (Smart Tire Pressure) | |||
``` | |||
TPMS transfer board: | |||
TpmsDeviceData Parsing Class | |||
TpmsBleConfig directive configuration class | |||
``` | |||
#### 7, electronic lock | |||
``` | |||
Electronic locks: | |||
TempGunDeviceData parsing class | |||
TempGunBleConfig instruction configuration class | |||
LockKeyBean electronic lock (user) key information | |||
public class LockKeyBean implements Serializable { | |||
/ ** | |||
* Key type (password, remote control, fingerprint ...) | |||
* / | |||
@ LockBleConfig.KeyType | |||
private int mKeyType; | |||
/ ** | |||
* User id (key id) | |||
* / | |||
private int mUserId; | |||
/ ** | |||
* Password (6 digits), 0 means not supported | |||
* / | |||
private int mPassword = 0; | |||
/ ** | |||
* Validity Type | |||
* / | |||
@ LockBleConfig.Time | |||
private int mValidTimeType; | |||
/ ** | |||
* 0 means not supported | |||
* Year, month, day, hour, minute, second <br> | |||
* Validity start time (permanent time is 0,0,0,0,0) <br> | |||
* If it is a babysitter password, the format is: hour, minute <br> | |||
* / | |||
private long mStartTime = 0; | |||
/ ** | |||
* 0 means not supported | |||
* Year, month, day, hour, minute, second <br> | |||
* Validity end time (permanent time is -1, -1, -1, -1, -1) <br> | |||
* If it is a babysitter password, the format is: hour, minute <br> | |||
* / | |||
private long mStopTime = 0; | |||
/ ** | |||
* 0 means not supported | |||
* Nanny lock repeat effective way, day, week, month | |||
* / | |||
@ LockBleConfig.Repeat | |||
private int mRepeat = 0; | |||
/ ** | |||
* Repeat time, days of the week, days of the month | |||
* / | |||
private List <Integer> mRepeatList = new ArrayList <> (); | |||
} | |||
Electronic lock remote control: | |||
LockRemoteControlDeviceData parsing class | |||
LockRemoteControlBleConfig instruction configuration class | |||
``` | |||
#### 8, Body Fat Scale | |||
``` | |||
BodyFatBleUtilsData Body Fat Scale Object | |||
BodyFatDataUtil Body fat scale analysis and instruction configuration class | |||
BodyFatRecord Body Fat Record Object (Measured Return) | |||
McuHistoryRecordBean history object | |||
User user information object | |||
``` |
@@ -0,0 +1,387 @@ | |||
# AILink SDK使用说明 - Android | |||
[aar包下载地址](https://github.com/elinkthings/AILinkSdkDemoAndroid/releases) | |||
[key注册地址](http://sdk.aicare.net.cn) | |||
[English documentation](README.md) | |||
该文档为指导Android开发人员在Android 4.4及以上系统中集成AILink-SDK-Android,主要为一些关键的使用示例 | |||
## 一、使用条件: | |||
1.Android SDK最低版本android4.4(API 19)。 | |||
2.设备所使用蓝牙版本需要4.0及以上。 | |||
3.配置java1.8 | |||
4.项目依赖androidx库 | |||
## 二、导入SDK | |||
``` | |||
repositories { | |||
flatDir { | |||
dirs 'libs' | |||
} | |||
} | |||
1.将JitPack存储库添加到您的构建文件中 | |||
将其添加到存储库末尾的root build.gradle中: | |||
allprojects { | |||
repositories { | |||
... | |||
maven { url 'https://jitpack.io' } | |||
} | |||
} | |||
2.添加依赖项 | |||
dependencies { | |||
implementation 'com.github.elinkthings:AILinkSDKRepositoryAndroid:1.2.9'//蓝牙库 | |||
implementation 'com.github.elinkthings:AILinkSDKParsingLibraryAndroid:1.2.9'//解析库 | |||
} | |||
3.在gradle中配置java1.8 | |||
android { | |||
... | |||
compileOptions { | |||
sourceCompatibility 1.8 | |||
targetCompatibility 1.8 | |||
} | |||
} | |||
也可以使用aar包依赖,请自行下载放到项目的libs中,下载地址在文档顶部 | |||
``` | |||
## 二、权限设置 | |||
``` | |||
<!--In most cases, you need to ensure that the device supports BLE.--> | |||
<uses-feature | |||
android:name="android.hardware.bluetooth_le" | |||
android:required="true"/> | |||
<uses-permission android:name="android.permission.BLUETOOTH"/> | |||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> | |||
<!--Android 6.0 and above. Bluetooth scanning requires one of the following two permissions. You need to apply at run time.--> | |||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> | |||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> | |||
<!--Optional. If your app need dfu function.--> | |||
<uses-permission android:name="android.permission.INTERNET"/> | |||
``` | |||
> 6.0及以上系统必须要定位权限,且需要手动获取权限 | |||
## 三、开始集成 | |||
> 在AndroidManifest.xml application标签下面增加 | |||
``` | |||
<application> | |||
... | |||
<service android:name="com.pingwang.bluetoothlib.server.ELinkBleServer"/> | |||
</application> | |||
``` | |||
> 初始化 [key注册地址](http://sdk.aicare.net.cn) | |||
``` | |||
//在application中调用 | |||
AILinkSDK.getInstance().init(this, key, secret); | |||
``` | |||
> 注:可使用库中提供的BleBeseActivity类,继承实现方法, | |||
里面有绑定服务判断权限等相关操作,详细可参考demo | |||
### 1,绑定服务: | |||
``` | |||
ps:在需要处理蓝牙的地方绑定服务,拿到蓝牙设备对象来处理,也可在一个地方综合处理. | |||
private void bindService() { | |||
if (bindIntent == null) { | |||
bindIntent = new Intent(this, ELinkBleServer.class); | |||
if (mFhrSCon != null) | |||
this.bindService(bindIntent, mFhrSCon, Context.BIND_AUTO_CREATE); | |||
} | |||
} | |||
private ServiceConnection mFhrSCon = new ServiceConnection() { | |||
@Override | |||
public void onServiceConnected(ComponentName name, IBinder service) { | |||
//与服务建立连接 | |||
mBluetoothService = ((ELinkBleServer.BluetoothBinder) service).getService(); | |||
onServiceSuccess(); | |||
} | |||
@Override | |||
public void onServiceDisconnected(ComponentName name) { | |||
//与服务断开连接 | |||
mBluetoothService = null; | |||
onServiceErr(); | |||
} | |||
}; | |||
``` | |||
### 2,绑定服务成功后设置监听mBluetoothService.setOnCallback(); | |||
``` | |||
实现OnCallbackBle接口可以获取搜索,连接,断开等状态和数据 | |||
/** | |||
* 蓝牙搜索,连接等操作接口 | |||
*/ | |||
public interface OnCallbackBle extends OnCallback { | |||
/** | |||
* 开始扫描设备 | |||
*/ | |||
default void onStartScan(){} | |||
/** | |||
* 每扫描到一个设备就会回调一次 | |||
*/ | |||
default void onScanning(BleValueBean data){} | |||
/** | |||
* 扫描超时(完成) | |||
*/ | |||
default void onScanTimeOut(){} | |||
/** | |||
* 正在连接 | |||
*/ | |||
default void onConnecting(String mac){} | |||
/** | |||
* 连接断开,在UI线程 | |||
*/ | |||
default void onDisConnected(String mac, int code){} | |||
/** | |||
* 连接成功(发现服务),在UI线程 | |||
*/ | |||
default void onServicesDiscovered(String mac){} | |||
/** | |||
* 已开启蓝牙,在触发线程 | |||
*/ | |||
default void bleOpen(){} | |||
/** | |||
* 未开启蓝牙,在触发线程 | |||
*/ | |||
default void bleClose(){} | |||
} | |||
``` | |||
### 3,搜索 mBluetoothService.scanLeDevice(long timeOut);//timeOut毫秒 | |||
``` | |||
/** | |||
* 搜索设备 | |||
* 扫描过于频繁会导致扫描失败 | |||
* 需要保证5次扫描总时长超过30s | |||
* @param timeOut 超时时间,毫秒(搜索多久去取数据,0代表一直搜索) | |||
*/ | |||
scanLeDevice(long timeOut) | |||
/** | |||
* 搜索设备 | |||
* 扫描过于频繁会导致扫描失败 | |||
* 需要保证5次扫描总时长超过30s | |||
* @param timeOut 超时时间,毫秒(搜索多久去取数据,0代表一直搜索) | |||
* @param scanUUID 过滤的UUID(空/null代码不过滤) | |||
*/ | |||
scanLeDevice(long timeOut, UUID scanUUID) | |||
搜索到的设备会在OnCallbackBle接口中的onScanning(BleValueBean data)返回 | |||
``` | |||
### 4,连接mBluetoothService.connectDevice(String mAddress); | |||
``` | |||
注:连接之前建议停止搜索mBluetoothService.stopScan(),这样连接过程会更稳定 | |||
连接成功并获取服务成功后会在OnCallbackBle接口中的onServicesDiscovered(String mac)返回 | |||
``` | |||
### 5,断开连接 | |||
``` | |||
mBluetoothService.disconnectAll()断开所有连接,由于此库支持多连接, | |||
所以service中只提供断开设备的方法,可在BleDevice.disconnect();断开连接 | |||
``` | |||
### 6,获取连接的设备对象 | |||
``` | |||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | |||
BleDevice对象拥有对此设备的所有操作,包括断开连接,发送指令,接收指令等操作 | |||
BleDevice.disconnect();//断开连接 | |||
BleDevice.sendData(SendDataBean sendDataBean)//发送指令,内容需要用SendDataBean装载 | |||
/** | |||
* @param hex 发送的内容 | |||
* @param uuid 需要操作的特征uuid | |||
* @param type 操作类型(1=读,2=写,3=信号强度) {@link BleConfig} | |||
* @param uuidService 服务uuid(一般情况下不需要设置,使用默认的即可) | |||
*/ | |||
public SendDataBean(byte[] hex, UUID uuid, int type, UUID uuidService) { | |||
this.hex = hex; | |||
this.uuid = uuid; | |||
this.type = type; | |||
if (uuidService != null) | |||
this.uuidService = uuidService; | |||
} | |||
正常情况下,使用SendDataBean的子类即可; | |||
由于发送数据存在发送队列,SendDataBean对象不建议复用,避免数据给覆盖; | |||
SendBleBean用于与蓝牙模块交互; | |||
SendMcuBean用于与mcu交互; | |||
如果有自定义透传数据需求,请自行继承SendDataBean或者使用SendDataBean对象发送即可. | |||
``` | |||
## 四、较常用的接口介绍 | |||
### 1,BleDevice 中的setOnBleVersionListener(OnBleVersionListener bleVersionListener)//设备版本号,单位接口 | |||
``` | |||
public interface OnBleVersionListener { | |||
/** | |||
* BM 模块软、硬件版本号 | |||
*/ | |||
default void onBmVersion(String version){} | |||
/** | |||
* mcu 支持的单位(默认支持所有) | |||
* @param list null或者空代表支持所有 | |||
*/ | |||
default void onSupportUnit(List<SupportUnitBean> list) {} | |||
} | |||
``` | |||
### 2,BleDevice 中的setOnMcuParameterListener(OnMcuParameterListener mcuParameterListener)//电量,时间接口 | |||
``` | |||
public interface OnMcuParameterListener { | |||
/** | |||
* mcu电池状态 | |||
* @param status 当前电池状态(0=没充电,1=充电中,2=充满电,3=充电异常) | |||
* @param battery 当前电量百分比(0~100),默认为:0xFFFF | |||
*/ | |||
default void onMcuBatteryStatus(int status, int battery){} | |||
/** | |||
* 系统时间 | |||
* @param status 时间状态(0=无效,1=有效) | |||
* @param times 时间数组(年,月,日,时,分,秒) | |||
*/ | |||
default void onSysTime(int status, int[] times){} | |||
} | |||
``` | |||
### 3,BleDevice 中的setOnBleOtherDataListener(OnBleOtherDataListener onBleOtherDataListener) //透传数据接口,数据格式不符合协议的才会走此接口返回数据 | |||
``` | |||
public interface OnBleOtherDataListener { | |||
/** | |||
* 透传数据 | |||
* @param data 不支持协议的透传数据 | |||
*/ | |||
void onNotifyOtherData(byte[] data); | |||
} | |||
``` | |||
## 五、注意事项 | |||
#### 1,蓝牙库只提供数据,解析部分ble数据,mcu模块对接的数据不解析 | |||
#### 2,模块数据解析请使用AILinkBleParsingAndroid 库,里面有提供各模块的解析模板 | |||
#### 3,AILinkBleParsingAndroid库需要依赖AILinkSDKRepositoryAndroid库,不建议单独使用 | |||
#### 4,BaseBleDeviceData对象为模块设备的基类对象,建议继承实现操作,更多请参考AILinkBleParsingAndroid库中的模板 | |||
#### 5,AILinkBleParsingAndroid库有源码提供,可在github上查找start | |||
#### 6,更多操作请参考demo,将此项目clone下来即可 | |||
## 六、AILinkBleParsingAndroid库概述 | |||
#### 1,婴儿秤 | |||
``` | |||
BabyDeviceData解析类 | |||
BabyBleConfig 指令配置类 | |||
``` | |||
#### 2,身高仪 | |||
``` | |||
HeightDeviceData解析类 | |||
HeightBleConfig指令配置类 | |||
``` | |||
#### 3,血压计 | |||
``` | |||
SphyDeviceData解析类 | |||
SphyBleConfig指令配置类 | |||
``` | |||
#### 4,体温计 | |||
``` | |||
TempDeviceData解析类 | |||
TempBleConfig指令配置类 | |||
``` | |||
#### 5,额温枪 | |||
``` | |||
TempGunDeviceData解析类 | |||
TempGunBleConfig指令配置类 | |||
``` | |||
#### 6,TPMS(智能胎压) | |||
``` | |||
TPMS转接板: | |||
TpmsDeviceData解析类 | |||
TpmsBleConfig指令配置类 | |||
``` | |||
#### 7,电子锁 | |||
``` | |||
电子锁: | |||
TempGunDeviceData解析类 | |||
TempGunBleConfig指令配置类 | |||
LockKeyBean电子锁(用户)钥匙信息 | |||
public class LockKeyBean implements Serializable { | |||
/** | |||
* 钥匙类型(密码,遥控,指纹...) | |||
*/ | |||
@LockBleConfig.KeyType | |||
private int mKeyType; | |||
/** | |||
* 用户id(钥匙id) | |||
*/ | |||
private int mUserId; | |||
/** | |||
* 密码(6位数字),0代表不支持 | |||
*/ | |||
private int mPassword = 0; | |||
/** | |||
* 有效期类型 | |||
*/ | |||
@LockBleConfig.Time | |||
private int mValidTimeType; | |||
/** | |||
* 0代表不支持 | |||
* 年,月,日,时,分,秒<br> | |||
* 有效期开始时间(永久时间为0,0,0,0,0)<br> | |||
* 如果是保姆密码,格式:时,分<br> | |||
*/ | |||
private long mStartTime = 0; | |||
/** | |||
* 0代表不支持 | |||
* 年,月,日,时,分,秒<br> | |||
* 有效期结束时间(永久时间为-1,-1,-1,-1,-1)<br> | |||
* 如果是保姆密码,格式:时,分<br> | |||
*/ | |||
private long mStopTime = 0; | |||
/** | |||
* 0代表不支持 | |||
* 保姆锁重复有效方式,天,周,月 | |||
*/ | |||
@LockBleConfig.Repeat | |||
private int mRepeat = 0; | |||
/** | |||
* 重复时间,周中的那几天,月中的那几天 | |||
*/ | |||
private List<Integer> mRepeatList = new ArrayList<>(); | |||
} | |||
电子锁遥控器: | |||
LockRemoteControlDeviceData解析类 | |||
LockRemoteControlBleConfig指令配置类 | |||
``` | |||
#### 8,体脂秤 | |||
``` | |||
BodyFatBleUtilsData 体脂秤对象 | |||
BodyFatDataUtil 体脂秤解析和指令配置类 | |||
BodyFatRecord 体脂记录对象(测量返回) | |||
McuHistoryRecordBean 历史记录对象 | |||
User 用户信息对象 | |||
``` |
@@ -0,0 +1 @@ | |||
/build |
@@ -0,0 +1,36 @@ | |||
apply plugin: 'com.android.application' | |||
android { | |||
compileSdkVersion 29 | |||
buildToolsVersion "29.0.2" | |||
defaultConfig { | |||
applicationId "aicare.net.cn.sdk.ailinksdkdemoandroid" | |||
minSdkVersion 19 | |||
targetSdkVersion 29 | |||
versionCode 2 | |||
versionName "1.2.9" | |||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | |||
} | |||
buildTypes { | |||
release { | |||
minifyEnabled false | |||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | |||
} | |||
} | |||
compileOptions { | |||
sourceCompatibility 1.8 | |||
targetCompatibility 1.8 | |||
} | |||
} | |||
dependencies { | |||
implementation fileTree(dir: 'libs', include: ['*.jar']) | |||
implementation 'androidx.appcompat:appcompat:1.1.0' | |||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | |||
testImplementation 'junit:junit:4.12' | |||
implementation 'com.github.elinkthings:AILinkSDKRepositoryAndroid:1.2.9' | |||
implementation 'com.github.elinkthings:AILinkSDKParsingLibraryAndroid:1.2.9' | |||
} |
@@ -0,0 +1,21 @@ | |||
# Add project specific ProGuard rules here. | |||
# You can control the set of applied configuration files using the | |||
# proguardFiles setting in build.gradle. | |||
# | |||
# For more details, see | |||
# http://developer.android.com/guide/developing/tools/proguard.html | |||
# If your project uses WebView with JS, uncomment the following | |||
# and specify the fully qualified class name to the JavaScript interface | |||
# class: | |||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | |||
# public *; | |||
#} | |||
# Uncomment this to preserve the line number information for | |||
# debugging stack traces. | |||
#-keepattributes SourceFile,LineNumberTable | |||
# If you keep the line number information, uncomment this to | |||
# hide the original source file name. | |||
#-renamesourcefileattribute SourceFile |
@@ -0,0 +1,51 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<manifest package="aicare.net.cn.sdk.ailinksdkdemoandroid" | |||
xmlns:android="http://schemas.android.com/apk/res/android"> | |||
<!--兼容6.0以上的手机Ble--> | |||
<uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION"/> | |||
<uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION"/> | |||
<uses-permission android:name="android.permission.BLUETOOTH"/> | |||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> | |||
<uses-feature | |||
android:name="android.hardware.bluetooth_le" | |||
android:required="true"/> | |||
<application | |||
android:allowBackup="true" | |||
android:icon="@mipmap/ic_launcher" | |||
android:label="@string/app_name" | |||
android:roundIcon="@mipmap/ic_launcher_round" | |||
android:supportsRtl="true" | |||
android:theme="@style/AppTheme"> | |||
<activity android:name=".MainActivity"> | |||
<intent-filter> | |||
<action android:name="android.intent.action.VIEW"/> | |||
<action android:name="android.intent.action.MAIN"/> | |||
<category android:name="android.intent.category.LAUNCHER"/> | |||
</intent-filter> | |||
</activity> | |||
<activity android:name=".ShowBleActivity"/> | |||
<activity android:name=".BabyCmdActivity"/> | |||
<activity android:name=".TempGunCmdActivity"/> | |||
<activity android:name=".SphyCmdActivity"/> | |||
<activity android:name=".TempCmdActivity"/> | |||
<activity android:name=".HeightCmdActivity"/> | |||
<activity android:name=".BleCmdActivityDataData"/> | |||
<activity android:name=".TpmsConnectCmdActivity" /> | |||
<activity android:name=".ADWeightScaleCmdActivity"/> | |||
<activity android:name=".ADWeightScaleUserActivity" | |||
android:theme="@style/Theme.AppCompat.Light.NoActionBar" | |||
/> | |||
<activity android:name=".WeightScaleWifiBle" | |||
android:theme="@style/Theme.AppCompat.Light.NoActionBar" | |||
/> | |||
<service android:name="com.pingwang.bluetoothlib.server.ELinkBleServer"/> | |||
</application> | |||
</manifest> |
@@ -0,0 +1,666 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.annotation.SuppressLint; | |||
import android.app.Activity; | |||
import android.content.Context; | |||
import android.content.Intent; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import android.os.Message; | |||
import android.view.View; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.ListView; | |||
import android.widget.RadioButton; | |||
import android.widget.RadioGroup; | |||
import android.widget.TextView; | |||
import com.pingwang.bluetoothlib.bean.BleValueBean; | |||
import com.pingwang.bluetoothlib.config.CmdConfig; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | |||
import com.pingwang.bluetoothlib.device.SendBleBean; | |||
import com.pingwang.bluetoothlib.listener.OnBleCompanyListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleSettingListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleVersionListener; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | |||
import com.pingwang.bluetoothlib.listener.OnMcuParameterListener; | |||
import com.pingwang.bluetoothlib.utils.BleDensityUtil; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import cn.net.aicare.modulelibrary.module.ADWeight.ADWeightScaleBleConfig; | |||
import cn.net.aicare.modulelibrary.module.ADWeight.ADWeightScaleBodyFatData; | |||
import cn.net.aicare.modulelibrary.module.ADWeight.ADWeightScaleBodyFatDataRecord; | |||
import cn.net.aicare.modulelibrary.module.ADWeight.ADWeightScaleDeviceData; | |||
import cn.net.aicare.modulelibrary.module.ADWeight.ADWeightScaleUserData; | |||
/** | |||
* xing<br> | |||
* 2019/7/12<br> | |||
* 显示数据 | |||
*/ | |||
public class ADWeightScaleCmdActivity extends BleBaseActivity implements OnCallbackBle, OnBleVersionListener, OnMcuParameterListener, OnBleCompanyListener, OnBleSettingListener, | |||
ADWeightScaleDeviceData.onNotifyData, View.OnClickListener, RadioGroup.OnCheckedChangeListener { | |||
private static String TAG = ADWeightScaleCmdActivity.class.getName(); | |||
private final int REFRESH_DATA = 3; | |||
private TextView user_id_tv, user_sex_tv, user_age_tv, user_height_tv, user_weight_tv, | |||
user_adc_tv; | |||
private List<String> mList; | |||
private ArrayAdapter listAdapter; | |||
private Context mContext; | |||
private ADWeightScaleDeviceData mDevice; | |||
private String mAddress; | |||
private BleSendCmdUtil mBleSendCmdUtil; | |||
private int type; | |||
private int weightUnit = 0; | |||
private RadioGroup radio_weight; | |||
private RadioButton mRadioButtonKg, mRadioButtonLb, mRadioButtonStLb, mRadioButtonJin; | |||
private List<RadioButton> mListWeight; | |||
/** | |||
* 去衣模式状态 | |||
*/ | |||
private boolean mUndressing = false; | |||
/** | |||
* 阻抗值开关 | |||
*/ | |||
private boolean mImpedance = false; | |||
public static List<ADWeightScaleUserData> sADWeightScaleUserDataList; | |||
private ADWeightScaleUserData mADWeightScaleUserData; | |||
public static int sCheckedUserId = 1; | |||
public static int mUserId = 1; | |||
private Handler mHandler = new Handler(Looper.getMainLooper()) { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
switch (msg.what) { | |||
case REFRESH_DATA: | |||
if (listAdapter != null) | |||
listAdapter.notifyDataSetChanged(); | |||
break; | |||
} | |||
} | |||
}; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_ad_weight_scale_cmd); | |||
mContext = this; | |||
mAddress = getIntent().getStringExtra("mac"); | |||
type = getIntent().getIntExtra("type", -1); | |||
mBleSendCmdUtil = BleSendCmdUtil.getInstance(); | |||
init(); | |||
} | |||
private void init() { | |||
mList = new ArrayList<>(); | |||
ListView listView = findViewById(R.id.listview); | |||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | |||
listView.setAdapter(listAdapter); | |||
findViewById(R.id.user).setOnClickListener(this); | |||
findViewById(R.id.btnVersion).setOnClickListener(this); | |||
findViewById(R.id.Undressing).setOnClickListener(this); | |||
findViewById(R.id.clear).setOnClickListener(this); | |||
findViewById(R.id.getRecord).setOnClickListener(this); | |||
findViewById(R.id.synUserAll).setOnClickListener(this); | |||
findViewById(R.id.synUser).setOnClickListener(this); | |||
findViewById(R.id.Impedance).setOnClickListener(this); | |||
findViewById(R.id.synTime).setOnClickListener(this); | |||
findViewById(R.id.btnDis).setOnClickListener(this); | |||
findViewById(R.id.btnConnect).setOnClickListener(this); | |||
((RadioGroup) findViewById(R.id.radio_weight)).setOnCheckedChangeListener(this); | |||
user_id_tv = findViewById(R.id.user_id_tv); | |||
user_sex_tv = findViewById(R.id.user_sex_tv); | |||
user_age_tv = findViewById(R.id.user_age_tv); | |||
user_height_tv = findViewById(R.id.user_height_tv); | |||
user_weight_tv = findViewById(R.id.user_weight_tv); | |||
user_adc_tv = findViewById(R.id.user_adc_tv); | |||
mListWeight = new ArrayList<>(); | |||
radio_weight = findViewById(R.id.radio_weight); | |||
mRadioButtonKg = findViewById(R.id.radio_weight_kg); | |||
mRadioButtonJin = findViewById(R.id.radio_weight_jin); | |||
mRadioButtonStLb = findViewById(R.id.radio_weight_st_lb); | |||
mRadioButtonLb = findViewById(R.id.radio_weight_lb_lb); | |||
mListWeight.add(mRadioButtonKg); | |||
mListWeight.add(mRadioButtonLb); | |||
mListWeight.add(mRadioButtonStLb); | |||
mListWeight.add(mRadioButtonJin); | |||
if (sADWeightScaleUserDataList == null) { | |||
sADWeightScaleUserDataList = new ArrayList<>(); | |||
ADWeightScaleUserData adWeightScaleUserData = new ADWeightScaleUserData(); | |||
adWeightScaleUserData.setUserId(1); | |||
adWeightScaleUserData.setSex(ADWeightScaleBleConfig.SEX.MALE); | |||
adWeightScaleUserData.setAge(20); | |||
adWeightScaleUserData.setHeight(170); | |||
adWeightScaleUserData.setWeight(50); | |||
adWeightScaleUserData.setAdc(500); | |||
sADWeightScaleUserDataList.add(adWeightScaleUserData); | |||
} | |||
mADWeightScaleUserData = sADWeightScaleUserDataList.get(0); | |||
initUserData(mADWeightScaleUserData); | |||
} | |||
@SuppressLint("SetTextI18n") | |||
private void initUserData(ADWeightScaleUserData adWeightScaleUserData) { | |||
user_id_tv.setText("用户ID:" + adWeightScaleUserData.getUserId()); | |||
user_sex_tv.setText("性别:" + (adWeightScaleUserData.getSex() == ADWeightScaleBleConfig.SEX.MALE ? "男" : "女")); | |||
user_age_tv.setText("年龄:" + adWeightScaleUserData.getAge()); | |||
user_height_tv.setText("身高:" + adWeightScaleUserData.getHeight()); | |||
user_weight_tv.setText("体重:" + adWeightScaleUserData.getWeight()); | |||
user_adc_tv.setText("阻抗:" + adWeightScaleUserData.getAdc()); | |||
} | |||
@Override | |||
public void onCheckedChanged(RadioGroup group, int checkedId) { | |||
if (checkedId == -1) | |||
return;//不是人为点击不触发 | |||
switch (group.getCheckedRadioButtonId()) { | |||
case R.id.radio_weight_kg: | |||
weightUnit = ADWeightScaleBleConfig.WEIGHT_KG; | |||
break; | |||
case R.id.radio_weight_lb_lb: | |||
weightUnit = ADWeightScaleBleConfig.WEIGHT_LB_LB; | |||
break; | |||
case R.id.radio_weight_st_lb: | |||
weightUnit = ADWeightScaleBleConfig.WEIGHT_ST; | |||
break; | |||
case R.id.radio_weight_jin: | |||
weightUnit = ADWeightScaleBleConfig.WEIGHT_JIN; | |||
break; | |||
} | |||
BleLog.i(TAG, "weightUnit:" + weightUnit); | |||
mDevice.setUnit(weightUnit); | |||
} | |||
private void showWeightUnit(int unit) { | |||
switch (unit) { | |||
case ADWeightScaleBleConfig.WEIGHT_KG: | |||
mRadioButtonKg.setChecked(true); | |||
break; | |||
case ADWeightScaleBleConfig.WEIGHT_LB: | |||
mRadioButtonLb.setChecked(true); | |||
break; | |||
case ADWeightScaleBleConfig.WEIGHT_ST: | |||
mRadioButtonStLb.setChecked(true); | |||
break; | |||
case ADWeightScaleBleConfig.WEIGHT_JIN: | |||
mRadioButtonJin.setChecked(true); | |||
break; | |||
} | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
SendBleBean sendBleBean = new SendBleBean(); | |||
switch (v.getId()) { | |||
case R.id.btnVersion: | |||
sendBleBean.setHex(mBleSendCmdUtil.getBleVersion()); | |||
mDevice.sendData(sendBleBean); | |||
break; | |||
case R.id.Undressing: | |||
mUndressing = !mUndressing; | |||
mDevice.setUndressing(mUndressing); | |||
break; | |||
case R.id.Impedance: | |||
mImpedance = !mImpedance; | |||
mDevice.setBleImpedanceDiscern(mImpedance, 50); | |||
break; | |||
case R.id.clear: | |||
if (mList != null) | |||
mList.clear(); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
break; | |||
case R.id.getRecord: | |||
List<Integer> list = new ArrayList<>(); | |||
for (ADWeightScaleUserData adWeightScaleUserData : sADWeightScaleUserDataList) { | |||
list.add(adWeightScaleUserData.getUserId()); | |||
} | |||
mDevice.setBleSynUserHistoryRecord(list); | |||
break; | |||
case R.id.synUserAll: | |||
synUserAll(); | |||
break; | |||
case R.id.synUser: | |||
mDevice.setBleUpdateUser(mADWeightScaleUserData); | |||
break; | |||
case R.id.user: | |||
startActivityForResult(new Intent(mContext, ADWeightScaleUserActivity.class), 1); | |||
break; | |||
case R.id.synTime: | |||
if (mDevice != null) { | |||
mDevice.setSynTime(); | |||
mList.add(TimeUtils.getTime() + "同步时间"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
break; | |||
case R.id.btnDis: | |||
if (mDevice != null) { | |||
mDevice.disconnect(); | |||
} | |||
break; | |||
case R.id.btnConnect: | |||
startScanBle(0); | |||
break; | |||
} | |||
} | |||
/** | |||
* 同步用户 | |||
*/ | |||
private void synUserAll() { | |||
mList.add(TimeUtils.getTime() + "开始同步用户列表"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
for (ADWeightScaleUserData adWeightScaleUserData : sADWeightScaleUserDataList) { | |||
mDevice.setBleSynUser(adWeightScaleUserData); | |||
} | |||
mDevice.setBleSynUserSuccess(); | |||
} | |||
@Override | |||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | |||
super.onActivityResult(requestCode, resultCode, data); | |||
if (requestCode == 1 && resultCode == Activity.RESULT_OK) { | |||
for (ADWeightScaleUserData adWeightScaleUserData : sADWeightScaleUserDataList) { | |||
if (adWeightScaleUserData.getUserId() == sCheckedUserId) { | |||
mADWeightScaleUserData = adWeightScaleUserData; | |||
initUserData(mADWeightScaleUserData); | |||
} | |||
} | |||
} | |||
} | |||
//---------------------------------服务--------------------------------------------------- | |||
@Override | |||
public void onServiceSuccess() { | |||
BleLog.i(TAG, "服务与界面建立连接成功"); | |||
//与服务建立连接 | |||
if (mBluetoothService != null) { | |||
mBluetoothService.setOnCallback(this); | |||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | |||
if (bleDevice != null) { | |||
mDevice = ADWeightScaleDeviceData.getInstance(bleDevice); | |||
mDevice.setOnNotifyData(this); | |||
mDevice.setOnBleVersionListener(ADWeightScaleCmdActivity.this); | |||
mDevice.setOnMcuParameterListener(ADWeightScaleCmdActivity.this); | |||
mDevice.setOnCompanyListener(ADWeightScaleCmdActivity.this); | |||
mDevice.setOnBleSettingListener(ADWeightScaleCmdActivity.this); | |||
} | |||
} | |||
} | |||
@Override | |||
public void onServiceErr() { | |||
BleLog.i(TAG, "服务与界面连接断开"); | |||
//与服务断开连接 | |||
mBluetoothService = null; | |||
} | |||
@Override | |||
public void unbindServices() { | |||
if (mDevice != null) { | |||
mDevice.disconnect(); | |||
mDevice.clear(); | |||
mDevice = null; | |||
} | |||
} | |||
//-----------------状态------------------- | |||
@Override | |||
public void onScanning(BleValueBean data) { | |||
if (data.getMac().equals(mAddress)) { | |||
connectBle(mAddress); | |||
mList.add(TimeUtils.getTime() + "开始连接"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
} | |||
@Override | |||
public void onConnecting(@NonNull String mac) { | |||
//TODO 连接中 | |||
BleLog.i(TAG, "连接中"); | |||
mList.add(TimeUtils.getTime() + "连接中"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onDisConnected(@NonNull String mac, int code) { | |||
//TODO 连接断开 | |||
BleLog.i(TAG, "连接断开"); | |||
mList.add(TimeUtils.getTime() + "连接断开"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onServicesDiscovered(@NonNull String mac) { | |||
//TODO 连接成功(获取服务成功) | |||
BleLog.i(TAG, "连接成功(获取服务成功)"); | |||
mList.add(TimeUtils.getTime() + "连接成功"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
onServiceSuccess(); | |||
} | |||
@Override | |||
public void bleOpen() { | |||
mList.add(TimeUtils.getTime() + "蓝牙打开"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void bleClose() { | |||
BleLog.i(TAG, "蓝牙未开启,可请求开启"); | |||
mList.add(TimeUtils.getTime() + "蓝牙关闭"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
//-----------------通知------------------- | |||
@Override | |||
public void onData(byte[] hex, int type) { | |||
String data = ""; | |||
if (hex != null) | |||
data = BleStrUtils.byte2HexStr(hex); | |||
if (type == 100) { | |||
mList.add(TimeUtils.getTime() + "send->" + data); | |||
} else { | |||
mList.add(TimeUtils.getTime() + "notify->" + data); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getWeight(int weight, int decimal, int unit) { | |||
String weightStr = BleDensityUtil.getInstance().holdNumber(weight, decimal); | |||
mList.add(TimeUtils.getTime() + "稳定体重=" + weightStr + ";小数位=" + decimal + ";单位=" + unit); | |||
if (weightUnit != unit) { | |||
weightUnit = unit; | |||
showWeightUnit(weightUnit); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getWeightNow(int weight, int decimal, int unit) { | |||
String weightStr = BleDensityUtil.getInstance().holdNumber(weight, decimal); | |||
mList.add(TimeUtils.getTime() + "实时体重=" + weightStr + ";小数位=" + decimal + ";单位=" + unit); | |||
//10.00,2,0 | |||
if (weightUnit != unit) { | |||
weightUnit = unit; | |||
showWeightUnit(weightUnit); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getTemperature(double temp) { | |||
} | |||
@Override | |||
public void getImpedance(int status, double impedance) { | |||
switch (status) { | |||
//测阻抗中 | |||
case ADWeightScaleBleConfig.GET_IMPEDANCE_ING: | |||
BleLog.i(TAG, "测阻抗中"); | |||
mList.add(TimeUtils.getTime() + "测阻抗中,阻抗值:" + impedance); | |||
break; | |||
//测阻抗成功,带上阻抗数据 | |||
case ADWeightScaleBleConfig.GET_IMPEDANCE_SUCCESS: | |||
BleLog.i(TAG, "测阻抗成功"); | |||
mList.add(TimeUtils.getTime() + "测阻抗成功,阻抗值:" + impedance); | |||
break; | |||
//测阻抗失败 | |||
case ADWeightScaleBleConfig.GET_IMPEDANCE_FAILURE: | |||
BleLog.i(TAG, "测阻抗失败"); | |||
mList.add(TimeUtils.getTime() + "测阻抗失败,阻抗值:" + impedance); | |||
break; | |||
//测阻抗成功,带上阻抗数据,并使用 APP 算法,APP 会根据 VID,PID 来识别对应算法 | |||
case ADWeightScaleBleConfig.GET_IMPEDANCE_SUCCESS_APP: | |||
BleLog.i(TAG, "测阻抗成功,使用app算法"); | |||
mList.add(TimeUtils.getTime() + "测阻抗成功,使用app算法,阻抗值:" + impedance); | |||
break; | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getUnit(int status) { | |||
String msg = ""; | |||
switch (status) { | |||
case CmdConfig.SETTING_SUCCESS: | |||
msg = "设置单位成功"; | |||
break; | |||
case CmdConfig.SETTING_FAILURE: | |||
msg = "设置单位失败"; | |||
break; | |||
case CmdConfig.SETTING_ERR: | |||
msg = "设置单位错误"; | |||
break; | |||
} | |||
mList.add(TimeUtils.getTime() + msg); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getUndressing(int status) { | |||
switch (status) { | |||
case 0: | |||
mList.add(TimeUtils.getTime() + "去衣设置成功:" + mUndressing); | |||
break; | |||
case 1: | |||
mList.add(TimeUtils.getTime() + "去衣设置失败" + status); | |||
break; | |||
case 2: | |||
mList.add(TimeUtils.getTime() + "去衣不支持设置" + status); | |||
break; | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getImpedance(int status) { | |||
switch (status) { | |||
case 0: | |||
mList.add(TimeUtils.getTime() + "阻抗设置成功:" + mImpedance); | |||
break; | |||
case 1: | |||
mList.add(TimeUtils.getTime() + "阻抗设置失败" + status); | |||
break; | |||
case 2: | |||
mList.add(TimeUtils.getTime() + "阻抗不支持设置" + status); | |||
break; | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void requestSynUser() { | |||
mList.add(TimeUtils.getTime() + "请求同步用户"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
mDevice.setSynUserData(mADWeightScaleUserData); | |||
} | |||
@Override | |||
public void getSynUser(boolean status) { | |||
mList.add(TimeUtils.getTime() + "同步用户:" + status); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getBodyFatData(ADWeightScaleBodyFatData adWeightScaleBodyFatData) { | |||
if (adWeightScaleBodyFatData == null) { | |||
mList.add(TimeUtils.getTime() + "没有体脂数据"); | |||
} else { | |||
mList.add(TimeUtils.getTime() + "体脂数据:" + adWeightScaleBodyFatData.toString()); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getBodyFatDataRecord(ADWeightScaleBodyFatDataRecord adWeightScaleBodyFatDataRecord) { | |||
if (adWeightScaleBodyFatDataRecord != null) { | |||
mList.add(TimeUtils.getTime() + "历史数据:" + adWeightScaleBodyFatDataRecord.toString()); | |||
} else { | |||
mList.add(TimeUtils.getTime() + "历史数据:null"); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getBodyFatDataRecordResult(int status) { | |||
switch (status) { | |||
case 0: | |||
mList.add(TimeUtils.getTime() + "无历史记录"); | |||
break; | |||
case 1: | |||
mList.add(TimeUtils.getTime() + "开始发送历史记录"); | |||
break; | |||
case 2: | |||
mList.add(TimeUtils.getTime() + "结束发送历史记录"); | |||
break; | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getErr(byte status) { | |||
mList.add(TimeUtils.getTime() + "错误指令:" + status); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getAppUpdateUser(int status) { | |||
//00:更新列表成功 | |||
//01:更新个人用户成功 | |||
//02:更新列表失败 | |||
//03:更新个人用户失败 | |||
switch (status) { | |||
case 0: | |||
mList.add(TimeUtils.getTime() + "更新列表成功"); | |||
break; | |||
case 1: | |||
mList.add(TimeUtils.getTime() + "更新个人用户成功"); | |||
break; | |||
case 2: | |||
mList.add(TimeUtils.getTime() + "更新列表失败"); | |||
break; | |||
case 3: | |||
mList.add(TimeUtils.getTime() + "更新个人用户失败"); | |||
break; | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onBmVersion(String version) { | |||
mList.add(TimeUtils.getTime() + "版本号:" + version); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void OnDID(int cid, int vid, int pid) { | |||
String didStr = "cid:" + cid + "||vid:" + vid + "||pid:" + pid; | |||
mList.add(TimeUtils.getTime() + "ID:" + didStr); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onMcuBatteryStatus(int status, int battery) { | |||
mList.add(TimeUtils.getTime() + "电量:" + battery + "%"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onSysTime(int status, int[] times) { | |||
String time = | |||
times[0] + "-" + times[1] + "-" + times[2] + " " + times[3] + ":" + times[4] + | |||
":" + times[5]; | |||
mList.add(TimeUtils.getTime() + "系统时间:" + time); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void OnSettingReturn(byte cmdType, byte cmdData) { | |||
String msg = ""; | |||
switch (cmdType) { | |||
case CmdConfig.SET_SYS_TIME://设置系统当前时间返回 | |||
msg = "设置系统当前时间"; | |||
break; | |||
case CmdConfig.SET_DEVICE_TIME://同步时间返回 | |||
msg = "同步时间"; | |||
break; | |||
} | |||
String cmdDataMsg=""; | |||
switch (cmdData){ | |||
case 0: | |||
cmdDataMsg="设置成功"; | |||
break; | |||
case 1: | |||
cmdDataMsg="设置失败"; | |||
break; | |||
case 2: | |||
cmdDataMsg="不支持设置"; | |||
break; | |||
} | |||
if (msg.isEmpty()) | |||
mList.add(TimeUtils.getTime() + "设置指令:" + cmdType + ";" + cmdDataMsg + ";"); | |||
else | |||
mList.add(TimeUtils.getTime() + "设置指令:" + cmdType + ";" + cmdDataMsg + ";" + msg); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
protected void onDestroy() { | |||
super.onDestroy(); | |||
BleLog.i(TAG, "onDestroy"); | |||
} | |||
} |
@@ -0,0 +1,325 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.annotation.SuppressLint; | |||
import android.app.Activity; | |||
import android.app.AlertDialog; | |||
import android.content.Context; | |||
import android.os.Bundle; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import android.widget.BaseAdapter; | |||
import android.widget.CheckedTextView; | |||
import android.widget.ListView; | |||
import android.widget.RadioButton; | |||
import android.widget.RadioGroup; | |||
import android.widget.SeekBar; | |||
import android.widget.TextView; | |||
import android.widget.Toast; | |||
import androidx.annotation.Nullable; | |||
import androidx.appcompat.app.AppCompatActivity; | |||
import cn.net.aicare.modulelibrary.module.ADWeight.ADWeightScaleBleConfig; | |||
import cn.net.aicare.modulelibrary.module.ADWeight.ADWeightScaleUserData; | |||
/** | |||
* xing<br> | |||
* 2019/11/14<br> | |||
* java类作用描述 | |||
*/ | |||
public class ADWeightScaleUserActivity extends AppCompatActivity implements View.OnClickListener { | |||
private ListView listView; | |||
private Context mContext; | |||
private UserAdapter mAdapter; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setResult(Activity.RESULT_OK); | |||
setContentView(R.layout.activity_ad_weight_scale_user); | |||
findViewById(R.id.back_btn).setOnClickListener(this); | |||
findViewById(R.id.add_user_btn).setOnClickListener(this); | |||
listView = findViewById(R.id.listView); | |||
mContext = this; | |||
mAdapter = new UserAdapter(); | |||
listView.setAdapter(mAdapter); | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
switch (v.getId()) { | |||
case R.id.back_btn: | |||
finish(); | |||
break; | |||
case R.id.add_user_btn: | |||
if (ADWeightScaleCmdActivity.sADWeightScaleUserDataList.size() < 8) { | |||
ADWeightScaleCmdActivity.mUserId++; | |||
ADWeightScaleUserData adWeightScaleUserData = new ADWeightScaleUserData(); | |||
adWeightScaleUserData.setUserId(ADWeightScaleCmdActivity.mUserId); | |||
adWeightScaleUserData.setSex(ADWeightScaleBleConfig.SEX.MALE); | |||
adWeightScaleUserData.setAge(20); | |||
adWeightScaleUserData.setHeight(170); | |||
adWeightScaleUserData.setWeight(50); | |||
adWeightScaleUserData.setAdc(500); | |||
ADWeightScaleCmdActivity.sADWeightScaleUserDataList.add(adWeightScaleUserData); | |||
mAdapter.notifyDataSetChanged(); | |||
} else { | |||
Toast.makeText(mContext, "最多只允许添加8个用户", Toast.LENGTH_SHORT).show(); | |||
} | |||
break; | |||
} | |||
} | |||
private class UserAdapter extends BaseAdapter implements View.OnClickListener, | |||
RadioGroup.OnCheckedChangeListener { | |||
@Override | |||
public int getCount() { | |||
return ADWeightScaleCmdActivity.sADWeightScaleUserDataList.size(); | |||
} | |||
@Override | |||
public Object getItem(int position) { | |||
return ADWeightScaleCmdActivity.sADWeightScaleUserDataList.get(position); | |||
} | |||
@Override | |||
public long getItemId(int position) { | |||
return position; | |||
} | |||
@SuppressLint("SetTextI18n") | |||
@Override | |||
public View getView(int position, View convertView, ViewGroup parent) { | |||
ViewHolder viewHolder; | |||
if (convertView == null || convertView.getTag() == null) { | |||
convertView = LayoutInflater.from(mContext) | |||
.inflate(R.layout.item_ad_weight_scale, parent, false); | |||
viewHolder = new ViewHolder(convertView); | |||
convertView.setTag(viewHolder); | |||
} else { | |||
viewHolder = (ViewHolder) convertView.getTag(); | |||
} | |||
ADWeightScaleUserData adWeightScaleUserData = | |||
ADWeightScaleCmdActivity.sADWeightScaleUserDataList | |||
.get(position); | |||
viewHolder.user_id_ctv.setText(adWeightScaleUserData.getUserId() + ""); | |||
viewHolder.user_id_ctv.setChecked(adWeightScaleUserData.getUserId() == ADWeightScaleCmdActivity.sCheckedUserId); | |||
viewHolder.user_id_ctv.setOnClickListener(this); | |||
viewHolder.user_id_ctv.setTag(position); | |||
int sex = adWeightScaleUserData.getSex(); | |||
viewHolder.sex_radioGroup.check(sex == ADWeightScaleBleConfig.SEX.MALE ? | |||
R.id.man_radioButton : R.id.female_radioButton); | |||
viewHolder.sex_radioGroup.setTag(position); | |||
viewHolder.sex_radioGroup.setOnCheckedChangeListener(this); | |||
viewHolder.tv_item_age.setText(adWeightScaleUserData.getAge() + ""); | |||
viewHolder.tv_item_height.setText(adWeightScaleUserData.getHeight() + ""); | |||
viewHolder.tv_item_weight.setText(adWeightScaleUserData.getWeight() + ""); | |||
viewHolder.tv_item_adc.setText(adWeightScaleUserData.getAdc() + ""); | |||
viewHolder.sb_item_age.setProgress(adWeightScaleUserData.getAge()); | |||
viewHolder.sb_item_age.setTag(position); | |||
viewHolder.sb_item_age.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { | |||
@Override | |||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { | |||
refreshSeekBar(seekBar,progress,viewHolder.tv_item_age); | |||
} | |||
@Override | |||
public void onStartTrackingTouch(SeekBar seekBar) { | |||
} | |||
@Override | |||
public void onStopTrackingTouch(SeekBar seekBar) { | |||
notifyDataSetChanged(); | |||
} | |||
}); | |||
viewHolder.sb_item_height.setProgress(adWeightScaleUserData.getHeight()); | |||
viewHolder.sb_item_height.setTag(position); | |||
viewHolder.sb_item_height.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { | |||
@Override | |||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { | |||
refreshSeekBar(seekBar,progress,viewHolder.tv_item_height); | |||
} | |||
@Override | |||
public void onStartTrackingTouch(SeekBar seekBar) { | |||
} | |||
@Override | |||
public void onStopTrackingTouch(SeekBar seekBar) { | |||
notifyDataSetChanged(); | |||
} | |||
}); | |||
viewHolder.sb_item_weight.setProgress(adWeightScaleUserData.getWeight()); | |||
viewHolder.sb_item_weight.setTag(position); | |||
viewHolder.sb_item_weight.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { | |||
@Override | |||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { | |||
refreshSeekBar(seekBar,progress,viewHolder.tv_item_weight); | |||
} | |||
@Override | |||
public void onStartTrackingTouch(SeekBar seekBar) { | |||
} | |||
@Override | |||
public void onStopTrackingTouch(SeekBar seekBar) { | |||
notifyDataSetChanged(); | |||
} | |||
}); | |||
viewHolder.sb_item_adc.setProgress(adWeightScaleUserData.getAdc()); | |||
viewHolder.sb_item_adc.setTag(position); | |||
viewHolder.sb_item_adc.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { | |||
@Override | |||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { | |||
refreshSeekBar(seekBar,progress,viewHolder.tv_item_adc); | |||
} | |||
@Override | |||
public void onStartTrackingTouch(SeekBar seekBar) { | |||
} | |||
@Override | |||
public void onStopTrackingTouch(SeekBar seekBar) { | |||
notifyDataSetChanged(); | |||
} | |||
}); | |||
convertView.setOnLongClickListener(v -> { | |||
{ | |||
new AlertDialog.Builder(mContext).setMessage("确定删除?") | |||
.setPositiveButton("确定", (dialog, which) -> { | |||
ADWeightScaleUserData adWeightScaleUserData1 = | |||
ADWeightScaleCmdActivity.sADWeightScaleUserDataList | |||
.get(position); | |||
if (ADWeightScaleCmdActivity.sCheckedUserId != adWeightScaleUserData1 | |||
.getUserId()) { | |||
ADWeightScaleCmdActivity.sADWeightScaleUserDataList.remove(position); | |||
notifyDataSetChanged(); | |||
} else { | |||
Toast.makeText(mContext, "选中不可删除", Toast.LENGTH_SHORT).show(); | |||
} | |||
}) | |||
.setNegativeButton("取消", (dialog, which) -> dialog.dismiss()) | |||
.create() | |||
.show(); | |||
} | |||
return true; | |||
}); | |||
return convertView; | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
if (v.getTag() == null) { | |||
return; | |||
} | |||
if (v.getId() == R.id.user_id_ctv) { | |||
int po = (int) v.getTag(); | |||
ADWeightScaleUserData adWeightScaleUserData = | |||
ADWeightScaleCmdActivity.sADWeightScaleUserDataList | |||
.get(po); | |||
if (adWeightScaleUserData.getUserId() == ADWeightScaleCmdActivity.sCheckedUserId) | |||
return; | |||
ADWeightScaleCmdActivity.sCheckedUserId = adWeightScaleUserData.getUserId(); | |||
notifyDataSetChanged(); | |||
} | |||
} | |||
@Override | |||
public void onCheckedChanged(RadioGroup group, int checkedId) { | |||
if (group.getTag() == null) { | |||
return; | |||
} | |||
int po = (int) group.getTag(); | |||
if (po == -1) | |||
return; | |||
ADWeightScaleCmdActivity.sADWeightScaleUserDataList.get(po) | |||
.setSex((group.getCheckedRadioButtonId() == R.id.man_radioButton) ? | |||
ADWeightScaleBleConfig.SEX.MALE : ADWeightScaleBleConfig.SEX.FEMALE); | |||
} | |||
private void refreshSeekBar(SeekBar seekBar, int progress, TextView textView) { | |||
if (seekBar.getTag() == null) { | |||
return; | |||
} | |||
int po = (int) seekBar.getTag(); | |||
if (po == -1) | |||
return; | |||
ADWeightScaleUserData adWeightScaleUserData = | |||
ADWeightScaleCmdActivity.sADWeightScaleUserDataList | |||
.get(po); | |||
switch (seekBar.getId()) { | |||
case R.id.sb_item_age: | |||
adWeightScaleUserData.setAge(progress); | |||
break; | |||
case R.id.sb_item_height: | |||
adWeightScaleUserData.setHeight(progress); | |||
break; | |||
case R.id.sb_item_weight: | |||
adWeightScaleUserData.setWeight(progress); | |||
break; | |||
case R.id.sb_item_adc: | |||
adWeightScaleUserData.setAdc(progress); | |||
break; | |||
} | |||
textView.setText(progress + ""); | |||
ADWeightScaleCmdActivity.sADWeightScaleUserDataList.set(po, adWeightScaleUserData); | |||
} | |||
class ViewHolder { | |||
CheckedTextView user_id_ctv; | |||
RadioGroup sex_radioGroup; | |||
RadioButton man_radioButton; | |||
RadioButton female_radioButton; | |||
TextView tv_item_age; | |||
TextView tv_item_height; | |||
TextView tv_item_weight; | |||
TextView tv_item_adc; | |||
SeekBar sb_item_age; | |||
SeekBar sb_item_height; | |||
SeekBar sb_item_weight; | |||
SeekBar sb_item_adc; | |||
public ViewHolder(View view) { | |||
user_id_ctv = view.findViewById(R.id.user_id_ctv); | |||
sex_radioGroup = view.findViewById(R.id.sex_radioGroup); | |||
man_radioButton = view.findViewById(R.id.man_radioButton); | |||
female_radioButton = view.findViewById(R.id.female_radioButton); | |||
tv_item_age = view.findViewById(R.id.tv_item_age); | |||
tv_item_height = view.findViewById(R.id.tv_item_height); | |||
tv_item_weight = view.findViewById(R.id.tv_item_weight); | |||
tv_item_adc = view.findViewById(R.id.tv_item_adc); | |||
sb_item_age = view.findViewById(R.id.sb_item_age); | |||
sb_item_height = view.findViewById(R.id.sb_item_height); | |||
sb_item_weight = view.findViewById(R.id.sb_item_weight); | |||
sb_item_adc = view.findViewById(R.id.sb_item_adc); | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,434 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.content.Context; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import android.os.Message; | |||
import android.view.View; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.ListView; | |||
import android.widget.RadioButton; | |||
import android.widget.RadioGroup; | |||
import android.widget.Toast; | |||
import com.pingwang.bluetoothlib.bean.SupportUnitBean; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | |||
import com.pingwang.bluetoothlib.device.SendBleBean; | |||
import com.pingwang.bluetoothlib.listener.OnBleCompanyListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleVersionListener; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackDis; | |||
import com.pingwang.bluetoothlib.listener.OnMcuParameterListener; | |||
import com.pingwang.bluetoothlib.utils.BleDensityUtil; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import cn.net.aicare.modulelibrary.module.babyscale.BabyBleConfig; | |||
import cn.net.aicare.modulelibrary.module.babyscale.BabyDeviceData; | |||
/** | |||
* xing<br> | |||
* 2019/4/25<br> | |||
* 显示数据 | |||
*/ | |||
public class BabyCmdActivity extends BleBaseActivity implements OnCallbackDis, OnBleVersionListener | |||
, OnMcuParameterListener, OnBleCompanyListener, View.OnClickListener, | |||
RadioGroup.OnCheckedChangeListener { | |||
private static String TAG = BabyCmdActivity.class.getName(); | |||
private final int REFRESH_DATA = 3; | |||
private List<String> mList; | |||
private ArrayAdapter listAdapter; | |||
private Context mContext; | |||
private BabyDeviceData babyDevice; | |||
private String mAddress; | |||
private BleSendCmdUtil mBleSendCmdUtil; | |||
private int type; | |||
private int weightUnit = 0, heightUnit = 0; | |||
private RadioButton mRadioButtonKg, mRadioButtonLb, mRadioButtonOz, mRadioButtonG, | |||
mRadioButtonLbLb, mRadioButtonCm, mRadioButtonFoot; | |||
private List<RadioButton> mListWeight, mListHeight; | |||
private Handler mHandler = new Handler(Looper.getMainLooper()) { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
switch (msg.what) { | |||
case REFRESH_DATA: | |||
if (listAdapter != null) | |||
listAdapter.notifyDataSetChanged(); | |||
break; | |||
} | |||
} | |||
}; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_baby_cmd); | |||
mContext = this; | |||
mAddress = getIntent().getStringExtra("mac"); | |||
type = getIntent().getIntExtra("type", -1); | |||
mBleSendCmdUtil = BleSendCmdUtil.getInstance(); | |||
init(); | |||
} | |||
private void init() { | |||
mList = new ArrayList<>(); | |||
ListView listView = findViewById(R.id.listview); | |||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | |||
listView.setAdapter(listAdapter); | |||
findViewById(R.id.btn_get_did).setOnClickListener(this); | |||
findViewById(R.id.btnVersion).setOnClickListener(this); | |||
findViewById(R.id.btnBattery).setOnClickListener(this); | |||
findViewById(R.id.clear).setOnClickListener(this); | |||
findViewById(R.id.clear).setOnClickListener(this); | |||
findViewById(R.id.btn_set_unit).setOnClickListener(this); | |||
findViewById(R.id.btn_set_tare).setOnClickListener(this); | |||
findViewById(R.id.btn_set_hold).setOnClickListener(this); | |||
findViewById(R.id.getUnit).setOnClickListener(this); | |||
((RadioGroup) findViewById(R.id.radio_weight)).setOnCheckedChangeListener(this); | |||
((RadioGroup) findViewById(R.id.radio_height)).setOnCheckedChangeListener(this); | |||
mListWeight = new ArrayList<>(); | |||
mListHeight = new ArrayList<>(); | |||
mRadioButtonKg = findViewById(R.id.radio_weight_kg); | |||
mRadioButtonLb = findViewById(R.id.radio_weight_lb); | |||
mRadioButtonOz = findViewById(R.id.radio_weight_oz); | |||
mRadioButtonG = findViewById(R.id.radio_weight_g); | |||
mRadioButtonLbLb = findViewById(R.id.radio_weight_lb_lb); | |||
mListWeight.add(mRadioButtonKg); | |||
mListWeight.add(mRadioButtonLb); | |||
mListWeight.add(mRadioButtonOz); | |||
mListWeight.add(mRadioButtonG); | |||
mListWeight.add(mRadioButtonLbLb); | |||
mRadioButtonCm = findViewById(R.id.radio_height_cm); | |||
mRadioButtonFoot = findViewById(R.id.radio_height_foot); | |||
mListHeight.add(mRadioButtonCm); | |||
mListHeight.add(mRadioButtonFoot); | |||
} | |||
@Override | |||
public void onCheckedChanged(RadioGroup group, int checkedId) { | |||
switch (group.getCheckedRadioButtonId()) { | |||
case R.id.radio_weight_kg: | |||
weightUnit = BabyBleConfig.BABY_KG; | |||
break; | |||
case R.id.radio_weight_lb: | |||
weightUnit = BabyBleConfig.BABY_LB; | |||
break; | |||
case R.id.radio_weight_lb_lb: | |||
weightUnit = BabyBleConfig.BABY_LB_LB; | |||
break; | |||
case R.id.radio_weight_oz: | |||
weightUnit = BabyBleConfig.BABY_OZ; | |||
break; | |||
case R.id.radio_weight_g: | |||
weightUnit = BabyBleConfig.BABY_G; | |||
break; | |||
case R.id.radio_height_cm: | |||
heightUnit = BabyBleConfig.BABY_CM; | |||
break; | |||
case R.id.radio_height_foot: | |||
heightUnit = BabyBleConfig.BABY_FEET; | |||
break; | |||
} | |||
} | |||
private void showWeightUnit(int unit) { | |||
for (RadioButton radioButton : mListWeight) { | |||
radioButton.setChecked(false); | |||
} | |||
switch (unit) { | |||
case BabyBleConfig.BABY_KG: | |||
mRadioButtonKg.setChecked(true); | |||
break; | |||
case BabyBleConfig.BABY_LB: | |||
mRadioButtonLb.setChecked(true); | |||
break; | |||
case BabyBleConfig.BABY_OZ: | |||
mRadioButtonOz.setChecked(true); | |||
break; | |||
case BabyBleConfig.BABY_G: | |||
mRadioButtonG.setChecked(true); | |||
break; | |||
case BabyBleConfig.BABY_LB_LB: | |||
mRadioButtonLbLb.setChecked(true); | |||
break; | |||
} | |||
} | |||
private void showHeightUnit(int unit) { | |||
for (RadioButton radioButton : mListHeight) { | |||
radioButton.setChecked(false); | |||
} | |||
switch (unit) { | |||
case BabyBleConfig.BABY_CM: | |||
mRadioButtonCm.setChecked(true); | |||
break; | |||
case BabyBleConfig.BABY_FEET: | |||
mRadioButtonFoot.setChecked(true); | |||
break; | |||
} | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
switch (v.getId()) { | |||
case R.id.btnVersion: | |||
babyDevice.sendData(new SendBleBean(BleSendCmdUtil.getInstance().getBleVersion())); | |||
break; | |||
case R.id.btnBattery: | |||
babyDevice.sendData(new SendBleBean(BleSendCmdUtil.getInstance().getMcuBatteryStatus())); | |||
break; | |||
case R.id.btn_get_did: | |||
babyDevice.sendData(new SendBleBean(BleSendCmdUtil.getInstance().getDid())); | |||
break; | |||
case R.id.clear: | |||
if (mList != null) | |||
mList.clear(); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
break; | |||
case R.id.btn_set_unit: | |||
//cm=0,inch=1 | |||
//kg=0,斤=1,lb=2,oz=3,st=4,g=5 | |||
babyDevice.setUnit(weightUnit, weightUnit); | |||
break; | |||
case R.id.btn_set_tare: | |||
babyDevice.setTare(); | |||
break; | |||
case R.id.btn_set_hold: | |||
babyDevice.setHold(); | |||
break; | |||
case R.id.getUnit: | |||
babyDevice.sendData(new SendBleBean(BleSendCmdUtil.getInstance().getSupportUnit())); | |||
break; | |||
} | |||
} | |||
//---------------------------------服务--------------------------------------------------- | |||
@Override | |||
public void onServiceSuccess() { | |||
BleLog.i(TAG, "服务与界面建立连接成功"); | |||
//与服务建立连接 | |||
if (mBluetoothService != null) { | |||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | |||
if (bleDevice != null) { | |||
babyDevice = BabyDeviceData.getInstance(bleDevice); | |||
babyDevice.setOnNotifyData(new babyNotifyData()); | |||
babyDevice.setOnBleVersionListener(BabyCmdActivity.this); | |||
babyDevice.setOnMcuParameterListener(BabyCmdActivity.this); | |||
babyDevice.setOnCompanyListener(BabyCmdActivity.this); | |||
} | |||
} | |||
} | |||
@Override | |||
public void onServiceErr() { | |||
BleLog.i(TAG, "服务与界面连接断开"); | |||
//与服务断开连接 | |||
mBluetoothService = null; | |||
} | |||
@Override | |||
public void unbindServices() { | |||
if (babyDevice != null) { | |||
babyDevice.disconnect(); | |||
babyDevice.clear(); | |||
babyDevice = null; | |||
} | |||
} | |||
//-----------------状态------------------- | |||
@Override | |||
public void onConnecting(@NonNull String mac) { | |||
//TODO 连接中 | |||
BleLog.i(TAG, "连接中"); | |||
} | |||
@Override | |||
public void onDisConnected(@NonNull String mac, int code) { | |||
//TODO 连接断开 | |||
BleLog.i(TAG, "连接断开"); | |||
finish(); | |||
Toast.makeText(mContext, "连接断开", Toast.LENGTH_SHORT).show(); | |||
} | |||
@Override | |||
public void onServicesDiscovered(@NonNull String mac) { | |||
//TODO 连接成功(获取服务成功) | |||
BleLog.i(TAG, "连接成功(获取服务成功)"); | |||
} | |||
@Override | |||
public void bleOpen() { | |||
} | |||
@Override | |||
public void bleClose() { | |||
BleLog.i(TAG, "蓝牙未开启,可请求开启"); | |||
} | |||
//-----------------通知------------------- | |||
private class babyNotifyData implements BabyDeviceData.onNotifyData { | |||
@Override | |||
public void onData(byte[] hex, int type) { | |||
String data = ""; | |||
if (hex != null) | |||
data = BleStrUtils.byte2HexStr(hex); | |||
if (type == 100) { | |||
mList.add(TimeUtils.getTime() + "send->" + data); | |||
} else { | |||
mList.add(TimeUtils.getTime() + "notify->" + data); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getWeight(int weight, int decimal, byte unit) { | |||
String weightStr = BleDensityUtil.getInstance().holdNumber(weight, decimal); | |||
String showStr="稳定体重:" + weightStr + "|小数:" + decimal + "|单位:" + unit; | |||
mList.add(TimeUtils.getTime() + showStr); | |||
if (weightUnit != unit) { | |||
weightUnit = unit; | |||
showWeightUnit(weightUnit); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getWeightNow(int weight, int decimal, byte unit) { | |||
String weightStr = BleDensityUtil.getInstance().holdNumber(weight, decimal); | |||
mList.add(TimeUtils.getTime() + "实时体重:" + weightStr + "|小数:" + decimal + "|单位:" + unit);//10.00,2,0 | |||
if (weightUnit != unit) { | |||
weightUnit = unit; | |||
showWeightUnit(weightUnit); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getHeight(int height, int decimal, byte unit) { | |||
String heightStr = BleDensityUtil.getInstance().holdNumber(height, decimal); | |||
mList.add(TimeUtils.getTime() + "稳定身高:" + heightStr + "|小数:" + decimal + "|单位:" + unit); | |||
if (heightUnit != unit) { | |||
heightUnit = unit; | |||
showHeightUnit(heightUnit); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getUnit(byte status) { | |||
mList.add(TimeUtils.getTime() + "单位结果:" + status); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getTare(byte status) { | |||
mList.add(TimeUtils.getTime() + "去皮:" + status); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getHold(byte status) { | |||
mList.add(TimeUtils.getTime() + "锁定:" + status); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getErr(byte status) { | |||
mList.add(TimeUtils.getTime() + "错误指令:" + status); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
} | |||
@Override | |||
public void onBmVersion(String version) { | |||
mList.add(TimeUtils.getTime() + "版本号:" + version); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void OnDID(int cid, int vid, int pid) { | |||
String didStr = "cid:" + cid + "||vid:" + vid + "||pid:" + pid; | |||
mList.add(TimeUtils.getTime() + "ID:" + didStr); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onMcuBatteryStatus(int status, int battery) { | |||
mList.add(TimeUtils.getTime() + "电量:" + battery + "%"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onSysTime(int status, int[] times) { | |||
String time = | |||
times[0] + "-" + times[1] + "-" + times[2] + " " + times[3] + ":" + times[4] + | |||
":" + times[5]; | |||
mList.add(TimeUtils.getTime() + "系统时间:" + time); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onSupportUnit(List<SupportUnitBean> list) { | |||
StringBuilder unitStr = new StringBuilder(); | |||
unitStr.append(TimeUtils.getTime()); | |||
for (SupportUnitBean supportUnitBean : list) { | |||
unitStr.append("单位类型:").append(supportUnitBean.getType()); | |||
StringBuilder units = new StringBuilder(); | |||
units.append("["); | |||
for (Integer integer1 : supportUnitBean.getSupportUnit()) { | |||
units.append(integer1).append(","); | |||
} | |||
units.append("]"); | |||
unitStr.append("单位列表:").append(units); | |||
unitStr.append("\n"); | |||
} | |||
mList.add(unitStr.toString()); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
protected void onDestroy() { | |||
super.onDestroy(); | |||
BleLog.i(TAG, "onDestroy"); | |||
} | |||
} |
@@ -0,0 +1,155 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.content.ComponentName; | |||
import android.content.Context; | |||
import android.content.Intent; | |||
import android.content.ServiceConnection; | |||
import android.os.Bundle; | |||
import android.os.IBinder; | |||
import com.pingwang.bluetoothlib.bean.BleValueBean; | |||
import com.pingwang.bluetoothlib.config.BleConfig; | |||
import com.pingwang.bluetoothlib.server.ELinkBleServer; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import androidx.annotation.Nullable; | |||
import androidx.appcompat.app.AppCompatActivity; | |||
/** | |||
* xing<br> | |||
* 2019/4/25<br> | |||
* 显示数据 | |||
*/ | |||
public abstract class BleBaseActivity extends AppCompatActivity { | |||
private static String TAG = BleBaseActivity.class.getName(); | |||
protected ELinkBleServer mBluetoothService; | |||
/** | |||
* 服务Intent | |||
*/ | |||
private Intent bindIntent; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
init(); | |||
} | |||
private void init() { | |||
bindService(); | |||
} | |||
/** | |||
* 搜索蓝牙(默认通过uuid过滤) | |||
* @param timeOut 超时,小于等于0代表永不超时 | |||
*/ | |||
protected void startScanBle(long timeOut){ | |||
if (mBluetoothService!=null){ | |||
mBluetoothService.scanLeDevice(timeOut, BleConfig.SERVER_UUID); | |||
} | |||
} | |||
/** | |||
* 主动停止搜索 | |||
*/ | |||
protected void stopScanBle(){ | |||
if (mBluetoothService!=null){ | |||
mBluetoothService.stopScan(); | |||
} | |||
} | |||
/** | |||
* 连接设备 | |||
* @param bleValueBean 搜索到的地址 | |||
*/ | |||
protected void connectBle(BleValueBean bleValueBean){ | |||
if (mBluetoothService!=null){ | |||
mBluetoothService.stopScan(); | |||
mBluetoothService.connectDevice(bleValueBean.getMac()); | |||
} | |||
} | |||
/** | |||
* 连接设备 | |||
* @param mac 设备的地址 | |||
*/ | |||
protected void connectBle(String mac){ | |||
if (mBluetoothService!=null){ | |||
mBluetoothService.stopScan(); | |||
mBluetoothService.connectDevice(mac); | |||
} | |||
} | |||
//---------------------------------服务--------------------------------------------------- | |||
private void bindService() { | |||
BleLog.i(TAG, "绑定服务"); | |||
if (bindIntent == null) { | |||
bindIntent = new Intent(this, ELinkBleServer.class); | |||
if (mFhrSCon != null) | |||
this.bindService(bindIntent, mFhrSCon, Context.BIND_AUTO_CREATE); | |||
} | |||
} | |||
private void unbindService() { | |||
unbindServices(); | |||
if (mFhrSCon != null) | |||
this.unbindService(mFhrSCon); | |||
bindIntent = null; | |||
} | |||
/** | |||
* 服务连接与界面的连接 | |||
*/ | |||
private ServiceConnection mFhrSCon = new ServiceConnection() { | |||
@Override | |||
public void onServiceConnected(ComponentName name, IBinder service) { | |||
BleLog.i(TAG, "服务与界面建立连接成功"); | |||
//与服务建立连接 | |||
mBluetoothService = ((ELinkBleServer.BluetoothBinder) service).getService(); | |||
onServiceSuccess(); | |||
} | |||
@Override | |||
public void onServiceDisconnected(ComponentName name) { | |||
BleLog.e(TAG, "服务与界面连接断开"); | |||
//与服务断开连接 | |||
mBluetoothService = null; | |||
onServiceErr(); | |||
} | |||
}; | |||
/** | |||
* 绑定服务成功 | |||
*/ | |||
public abstract void onServiceSuccess(); | |||
/** | |||
* 绑定服务失败 | |||
*/ | |||
public abstract void onServiceErr(); | |||
/** | |||
* 解绑服务,去掉与服务相关的操作,接口等 | |||
*/ | |||
public abstract void unbindServices(); | |||
@Override | |||
protected void onDestroy() { | |||
super.onDestroy(); | |||
BleLog.i(TAG, "onDestroy"); | |||
unbindService(); | |||
} | |||
} |
@@ -0,0 +1,500 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.content.Context; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import android.os.Message; | |||
import android.view.View; | |||
import android.view.WindowManager; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.EditText; | |||
import android.widget.ListView; | |||
import android.widget.Toast; | |||
import com.pingwang.bluetoothlib.bean.SupportUnitBean; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | |||
import com.pingwang.bluetoothlib.device.SendBleBean; | |||
import com.pingwang.bluetoothlib.listener.CallbackDisIm; | |||
import com.pingwang.bluetoothlib.listener.OnBleCompanyListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleDeviceDataListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleErrListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleHandshakeListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleInfoListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleOtherDataListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleParameterListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleSettingListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleVersionListener; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackDis; | |||
import com.pingwang.bluetoothlib.listener.OnMcuParameterListener; | |||
import com.pingwang.bluetoothlib.utils.BleDataUtils; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.Locale; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
/** | |||
* xing<br> | |||
* 2019/4/25<br> | |||
* 基础指令信息数据显示 | |||
*/ | |||
public class BleCmdActivityDataData extends BleBaseActivity implements OnCallbackDis, OnBleDeviceDataListener, OnBleVersionListener, OnMcuParameterListener, OnBleErrListener, OnBleInfoListener, OnBleParameterListener, OnBleCompanyListener, OnBleSettingListener, OnBleHandshakeListener,View.OnClickListener , OnBleOtherDataListener { | |||
private static String TAG = BleCmdActivityDataData.class.getName(); | |||
private final int REFRESH_DATA = 3; | |||
private List<String> mList; | |||
private ArrayAdapter listAdapter; | |||
private EditText etName, etMacType, etDid, etBroadcastTime, etMcuType; | |||
private Context mContext; | |||
private String mAddress; | |||
private BleSendCmdUtil mBleSendCmdUtil; | |||
private BleDataUtils bleDataUtils; | |||
private BleDevice mBleDevice; | |||
private int type; | |||
private Handler mHandler = new Handler(Looper.getMainLooper()) { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
switch (msg.what) { | |||
case REFRESH_DATA: | |||
if (listAdapter != null) | |||
listAdapter.notifyDataSetChanged(); | |||
break; | |||
} | |||
} | |||
}; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_ble); | |||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); | |||
mContext = this; | |||
mAddress = getIntent().getStringExtra("mac"); | |||
type = getIntent().getIntExtra("type", -1); | |||
mBleSendCmdUtil = BleSendCmdUtil.getInstance(); | |||
init(); | |||
} | |||
private void init() { | |||
mList = new ArrayList<>(); | |||
ListView listView = findViewById(R.id.listview); | |||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | |||
listView.setAdapter(listAdapter); | |||
bleDataUtils = BleDataUtils.getInstance(); | |||
findViewById(R.id.btnClear).setOnClickListener(this); | |||
findViewById(R.id.btnHandshake).setOnClickListener(this); | |||
findViewById(R.id.btnVersion).setOnClickListener(this); | |||
findViewById(R.id.btnBattery).setOnClickListener(this); | |||
findViewById(R.id.btnTimeRead).setOnClickListener(this); | |||
findViewById(R.id.btnTimeWrite).setOnClickListener(this); | |||
findViewById(R.id.btnNameRead).setOnClickListener(this); | |||
findViewById(R.id.btnMacRead).setOnClickListener(this); | |||
findViewById(R.id.btnMacTypeRead).setOnClickListener(this); | |||
findViewById(R.id.btnNameWrite).setOnClickListener(this); | |||
findViewById(R.id.btnMacTypeWrite).setOnClickListener(this); | |||
findViewById(R.id.btnDidWrite).setOnClickListener(this); | |||
findViewById(R.id.btnDidRead).setOnClickListener(this); | |||
findViewById(R.id.btnBroadcastTimeWrite).setOnClickListener(this); | |||
findViewById(R.id.btnBroadcastTimeRead).setOnClickListener(this); | |||
findViewById(R.id.btnBmRestart).setOnClickListener(this); | |||
findViewById(R.id.btnBmReset).setOnClickListener(this); | |||
findViewById(R.id.btnMcuType).setOnClickListener(this); | |||
findViewById(R.id.btnUnits).setOnClickListener(this); | |||
etName = findViewById(R.id.etName); | |||
etMacType = findViewById(R.id.etMacType); | |||
etDid = findViewById(R.id.etDid); | |||
etBroadcastTime = findViewById(R.id.etBroadcastTime); | |||
etMcuType = findViewById(R.id.etMcuType); | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
SendBleBean sendBleBean; | |||
switch (v.getId()) { | |||
case R.id.btnClear: | |||
if (mList != null) | |||
mList.clear(); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
break; | |||
case R.id.btnHandshake: | |||
if (mBleDevice != null) | |||
mBleDevice.sendHandshake(); | |||
break; | |||
case R.id.btnVersion: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.getBleVersion()); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnBattery: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.getMcuBatteryStatus()); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnTimeRead: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.getSysTime()); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnTimeWrite: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.setSysTime(bleDataUtils.getCurrentTime(),true)); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnNameRead: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.getBleName()); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnMacRead: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.getBleMac()); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnMacTypeRead: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.getBroadcastDataType()); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnMacTypeWrite: | |||
byte macType = Byte.valueOf(etMacType.getText().toString().trim()); | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.setBroadcastDataType(macType)); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnNameWrite: | |||
byte[] names = bleDataUtils.getBleName(etName.getText().toString().trim()); | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.setBleName(names)); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnBroadcastTimeRead: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.getBleBroadcastTime()); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnBroadcastTimeWrite: | |||
int time = Integer.parseInt(etBroadcastTime.getText().toString().trim()); | |||
byte[] broadcastTime = bleDataUtils.getBroadcastTime(time); | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.setBleBroadcastTime(broadcastTime)); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnDidWrite: | |||
String didStr = etDid.getText().toString().trim().toLowerCase(Locale.US); | |||
if (didStr.contains(",")) { | |||
String[] didStrS = didStr.split(","); | |||
if (didStrS.length > 5) { | |||
int cidS = Integer.parseInt(didStrS[0]); | |||
int vidS = Integer.parseInt(didStrS[1]); | |||
int pidS = Integer.parseInt(didStrS[2]); | |||
int cid = Integer.parseInt(didStrS[3]); | |||
int vid = Integer.parseInt(didStrS[4]); | |||
int pid = Integer.parseInt(didStrS[5]); | |||
byte[] did = bleDataUtils.getDid(cidS, vidS, pidS, cid, vid, pid); | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.setDid(did)); | |||
sendData(sendBleBean); | |||
} | |||
} | |||
break; | |||
case R.id.btnDidRead: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.getDid()); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnBmRestart: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.setBleRestart()); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnBmReset: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.setBleReset()); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnMcuType: | |||
byte mode=(byte)Integer.parseInt(etMcuType.getText().toString().trim()); | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.setPortI2cSpiMode(mode)); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnUnits: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.getSupportUnit()); | |||
sendData(sendBleBean); | |||
break; | |||
} | |||
} | |||
private void sendData(SendBleBean sendBleBean) { | |||
if (mBleDevice != null) { | |||
mBleDevice.sendData(sendBleBean); | |||
} | |||
} | |||
//---------------------------------服务--------------------------------------------------- | |||
@Override | |||
public void onServiceSuccess() { | |||
mList.add(TimeUtils.getTime() + "服务与界面建立连接成功"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
CallbackDisIm.getInstance().addListListener(this); | |||
if (mBluetoothService != null) { | |||
mBleDevice = mBluetoothService.getBleDevice(mAddress); | |||
if (mBleDevice == null) { | |||
finish(); | |||
BleLog.i(TAG, "mBleDevice==null"); | |||
} | |||
mBleDevice.setOnBleVersionListener(this); | |||
// mBleDevice.setOnBleDeviceDataListener(this); | |||
mBleDevice.setOnBleErrListener(this); | |||
mBleDevice.setOnBleInfoListener(this); | |||
mBleDevice.setOnMcuParameterListener(this); | |||
mBleDevice.setOnBleSettingListener(this); | |||
mBleDevice.setOnBleCompanyListener(this); | |||
mBleDevice.setOnBleParameterListener(this); | |||
mBleDevice.setOnBleHandshakeListener(this); | |||
mBleDevice.setOnBleOtherDataListener(this); | |||
} | |||
} | |||
@Override | |||
public void onServiceErr() { | |||
mList.add(TimeUtils.getTime() + "服务与界面连接断开"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
mHandler.postDelayed(new Runnable() { | |||
@Override | |||
public void run() { | |||
finish(); | |||
} | |||
}, 3000); | |||
//与服务断开连接 | |||
mBluetoothService = null; | |||
} | |||
@Override | |||
public void unbindServices() { | |||
CallbackDisIm.getInstance().removeListener(this); | |||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | |||
if (bleDevice != null) { | |||
BleLog.i(TAG, "unbindService,断开连接"); | |||
bleDevice.disconnect(); | |||
} | |||
} | |||
//-----------------状态------------------- | |||
@Override | |||
public void onConnecting(@NonNull String mac) { | |||
//TODO 连接中 | |||
BleLog.i(TAG, "连接中"); | |||
} | |||
@Override | |||
public void onDisConnected(@NonNull String mac, int code) { | |||
//TODO 连接断开 | |||
BleLog.i(TAG, "连接断开"); | |||
if (mAddress.equals(mac)) { | |||
Toast.makeText(mContext, "连接断开:" + code, Toast.LENGTH_SHORT).show(); | |||
finish(); | |||
} | |||
} | |||
@Override | |||
public void onServicesDiscovered(@NonNull String mac) { | |||
//TODO 连接成功(获取服务成功) | |||
BleLog.i(TAG, "连接成功(获取服务成功)"); | |||
} | |||
@Override | |||
public void bleOpen() { | |||
} | |||
@Override | |||
public void bleClose() { | |||
BleLog.i(TAG, "蓝牙未开启,可请求开启"); | |||
} | |||
//--------------------------------- | |||
@Override | |||
public void onNotifyOtherData(byte[] data) { | |||
mList.add(TimeUtils.getTime() + "透传数据:" + BleStrUtils.byte2HexStr(data)); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onNotifyData(byte[] hex, int type) { | |||
String data = ""; | |||
if (hex != null) | |||
data = BleStrUtils.byte2HexStr(hex); | |||
if (type == 100) { | |||
mList.add(TimeUtils.getTime() + "send->" + data); | |||
} else { | |||
mList.add(TimeUtils.getTime() + "notify->" + data); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onHandshake(boolean status) { | |||
mList.add(TimeUtils.getTime() + "握手:" + status); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onBmVersion(String version) { | |||
mList.add(TimeUtils.getTime() + "版本号:" + version); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onSupportUnit(List<SupportUnitBean> list) { | |||
StringBuilder unitStr=new StringBuilder(); | |||
unitStr.append(TimeUtils.getTime()); | |||
for (SupportUnitBean supportUnitBean : list) { | |||
unitStr.append("单位类型:").append(supportUnitBean.getType()); | |||
StringBuilder units= new StringBuilder(); | |||
units.append("["); | |||
for (Integer integer1 : supportUnitBean.getSupportUnit()) { | |||
units.append(integer1).append(","); | |||
} | |||
units.append("]"); | |||
unitStr.append("单位列表:").append(units); | |||
unitStr.append("\n"); | |||
} | |||
mList.add(unitStr.toString()); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onMcuBatteryStatus(int status, int battery) { | |||
mList.add(TimeUtils.getTime() + "电量:" + battery + "%" + "||状态:" + status); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onSysTime(int status, int[] times) { | |||
String timeStr = | |||
times[0] + "-" + times[1] + "-" + times[2] + " " + times[3] + ":" + times[4] + | |||
":" + times[5]; | |||
mList.add(TimeUtils.getTime() + "时间:" + timeStr + "||是否有效:" + status); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onErr(int cmdType) { | |||
mList.add(TimeUtils.getTime() + "错误:" + cmdType); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void OnSettingReturn(byte cmdType, byte cmdData) { | |||
mList.add(TimeUtils.getTime() + "设置指令:" + cmdType + "||结果:" + cmdData); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onBleName(String name) { | |||
mList.add(TimeUtils.getTime() + "名称:" + name); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onBleMac(String mac) { | |||
mList.add(TimeUtils.getTime() + "Mac:" + mac); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onNoConnectSleep(int sleepSwitch, int sleepTime, int sleepBroadcastSwitch, | |||
int sleepBroadcastTime) { | |||
mList.add(TimeUtils.getTime() + "sleepSwitch:" + sleepSwitch + "||sleepTime:" + sleepTime + "||sleepBroadcastSwitch:" + sleepBroadcastSwitch + "||sleepBroadcastTime:" + sleepBroadcastTime); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void OnDID(int cid, int vid, int pid) { | |||
mList.add(TimeUtils.getTime() + "cid:" + cid + "||vid:" + vid + "||pid:" + pid); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onBleBroadcastTime(int time) { | |||
mList.add(TimeUtils.getTime() + "广播间隔:" + time); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onConnectTime(int time, int status, int timeOut) { | |||
mList.add(TimeUtils.getTime() + "连接:time:" + time + "||status:" + status + "||timeOut:" + timeOut); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onBlePower(int power) { | |||
mList.add(TimeUtils.getTime() + "功率:" + power); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onPortRate(int rate) { | |||
mList.add(TimeUtils.getTime() + "串口波特率:" + rate); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onBroadcastDataType(int type) { | |||
mList.add(TimeUtils.getTime() + "广播大小端:" + type); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onModuleUUID(int length, String serverUUID, String featureUUID1, | |||
String featureUUID2) { | |||
mList.add(TimeUtils.getTime() + "UUID:length:" + length + "||serverUUID:" + serverUUID + | |||
"||featureUUID1:" + featureUUID1 + "||featureUUID2" + featureUUID2); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onBleMode(int mode) { | |||
mList.add(TimeUtils.getTime() + "模式:" + mode); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
protected void onDestroy() { | |||
super.onDestroy(); | |||
BleLog.i(TAG, "onDestroy"); | |||
} | |||
} |
@@ -0,0 +1,293 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.content.Context; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import android.os.Message; | |||
import android.view.View; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.Button; | |||
import android.widget.EditText; | |||
import android.widget.ListView; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | |||
import com.pingwang.bluetoothlib.device.SendBleBean; | |||
import com.pingwang.bluetoothlib.device.SendMcuBean; | |||
import com.pingwang.bluetoothlib.listener.CallbackDisIm; | |||
import com.pingwang.bluetoothlib.listener.OnBleCompanyListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleVersionListener; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackDis; | |||
import com.pingwang.bluetoothlib.listener.OnMcuParameterListener; | |||
import com.pingwang.bluetoothlib.utils.BleDensityUtil; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import cn.net.aicare.modulelibrary.module.height.HeightDeviceData; | |||
/** | |||
* xing<br> | |||
* 2019/4/25<br> | |||
* 显示数据 | |||
*/ | |||
public class HeightCmdActivity extends BleBaseActivity implements OnCallbackDis, | |||
HeightDeviceData.onNotifyData, OnBleVersionListener, OnMcuParameterListener, OnBleCompanyListener, View.OnClickListener { | |||
private static String TAG = HeightCmdActivity.class.getName(); | |||
private final int REFRESH_DATA = 3; | |||
private List<String> mList; | |||
private ArrayAdapter listAdapter; | |||
/** | |||
* 服务Intent | |||
*/ | |||
private Context mContext; | |||
private EditText et_type; | |||
private HeightDeviceData mBleDevice; | |||
private String mAddress; | |||
private BleSendCmdUtil mBleSendCmdUtil; | |||
private int type; | |||
private Handler mHandler = new Handler(Looper.getMainLooper()) { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
switch (msg.what) { | |||
case REFRESH_DATA: | |||
if (listAdapter != null) | |||
listAdapter.notifyDataSetChanged(); | |||
break; | |||
} | |||
} | |||
}; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_height); | |||
mContext = this; | |||
mAddress = getIntent().getStringExtra("mac"); | |||
type = getIntent().getIntExtra("type", -1); | |||
mBleSendCmdUtil = BleSendCmdUtil.getInstance(); | |||
init(); | |||
} | |||
private void init() { | |||
mList = new ArrayList<>(); | |||
ListView listView = findViewById(R.id.listview); | |||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | |||
listView.setAdapter(listAdapter); | |||
findViewById(R.id.clear).setOnClickListener(this); | |||
findViewById(R.id.btn1).setOnClickListener(this); | |||
findViewById(R.id.btnVersion).setOnClickListener(this); | |||
findViewById(R.id.btnBattery).setOnClickListener(this); | |||
findViewById(R.id.btn_get_did).setOnClickListener(this); | |||
et_type = findViewById(R.id.et_type); | |||
cmdBtn(); | |||
} | |||
private void cmdBtn() { | |||
EditText et_unit_weight = findViewById(R.id.et_unit_weight); | |||
EditText et_unit_height = findViewById(R.id.et_unit_height); | |||
Button btn_set_unit = findViewById(R.id.btn_set_unit); | |||
btn_set_unit.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
String weightStr = et_unit_weight.getText().toString(); | |||
String heightStr = et_unit_height.getText().toString(); | |||
if (!weightStr.equals("") && !heightStr.equals("")) { | |||
int weight = Integer.valueOf(weightStr); | |||
int height = Integer.valueOf(heightStr); | |||
mBleDevice.setUnit((byte) height, (byte) weight); | |||
} | |||
} | |||
}); | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
SendBleBean sendBleBean = new SendBleBean(); | |||
switch (v.getId()){ | |||
case R.id.btnVersion: | |||
sendBleBean.setHex(mBleSendCmdUtil.getBleVersion()); | |||
mBleDevice.sendData(sendBleBean); | |||
break; | |||
case R.id.btnBattery: | |||
sendBleBean.setHex(mBleSendCmdUtil.getMcuBatteryStatus()); | |||
mBleDevice.sendData(sendBleBean); | |||
break; | |||
case R.id.btn_get_did: | |||
sendBleBean.setHex(mBleSendCmdUtil.getDid()); | |||
mBleDevice.sendData(sendBleBean); | |||
break; | |||
case R.id.btn1: | |||
String cmd = et_type.getText().toString().trim(); | |||
SendMcuBean sendDataBean = new SendMcuBean(); | |||
sendDataBean.setHex(type,cmd.getBytes()); | |||
mBleDevice.sendData(sendDataBean); | |||
break; | |||
case R.id.clear: | |||
if (mList != null) | |||
mList.clear(); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
break; | |||
} | |||
} | |||
//---------------------------------服务--------------------------------------------------- | |||
@Override | |||
public void onServiceSuccess() { | |||
BleLog.i(TAG, "服务与界面建立连接成功"); | |||
CallbackDisIm.getInstance().addListListener(this); | |||
if (mBluetoothService != null) { | |||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | |||
if (bleDevice != null) { | |||
mBleDevice = HeightDeviceData.getInstance(bleDevice); | |||
mBleDevice.setOnNotifyData(HeightCmdActivity.this); | |||
mBleDevice.setOnBleVersionListener(HeightCmdActivity.this); | |||
mBleDevice.setOnMcuParameterListener(HeightCmdActivity.this); | |||
mBleDevice.setOnCompanyListener(HeightCmdActivity.this); | |||
} | |||
} | |||
} | |||
@Override | |||
public void onServiceErr() { | |||
BleLog.i(TAG, "服务与界面连接断开"); | |||
//与服务断开连接 | |||
mBluetoothService = null; | |||
} | |||
@Override | |||
public void unbindServices() { | |||
CallbackDisIm.getInstance().removeListener(this); | |||
if (mBleDevice!=null) { | |||
mBleDevice.disconnect(); | |||
mBleDevice.clear(); | |||
mBleDevice=null; | |||
} | |||
} | |||
//-----------------状态------------------- | |||
@Override | |||
public void onConnecting(@NonNull String mac) { | |||
//TODO 连接中 | |||
BleLog.i(TAG, "连接中"); | |||
} | |||
@Override | |||
public void onDisConnected(@NonNull String mac, int code) { | |||
//TODO 连接断开 | |||
BleLog.i(TAG, "连接断开"); | |||
finish(); | |||
} | |||
@Override | |||
public void onServicesDiscovered(@NonNull String mac) { | |||
//TODO 连接成功(获取服务成功) | |||
BleLog.i(TAG, "连接成功(获取服务成功)"); | |||
} | |||
@Override | |||
public void bleOpen() { | |||
} | |||
@Override | |||
public void bleClose() { | |||
BleLog.i(TAG, "蓝牙未开启,可请求开启"); | |||
finish(); | |||
} | |||
//-----------------通知------------------- | |||
@Override | |||
public void onData(byte[] status,int type) { | |||
String data = ""; | |||
if (status != null) | |||
data = BleStrUtils.byte2HexStr(status); | |||
if (type == 100) { | |||
mList.add(TimeUtils.getTime() + "send->" + data); | |||
} else { | |||
mList.add(TimeUtils.getTime() + "notify->" + data); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void height(int height, int decimalHeight, byte heightUnit, int weight, | |||
int decimalWeight, byte weightUnit) { | |||
String heightStr= BleDensityUtil.getInstance().holdDecimals(height,decimalHeight); | |||
String weightStr= BleDensityUtil.getInstance().holdDecimals(weight,decimalWeight); | |||
mList.add(TimeUtils.getTime() + "身高:" + heightStr + "|" + heightUnit + "体重:" + weightStr + "|" + weightUnit); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getUnit(byte status) { | |||
mList.add(TimeUtils.getTime() + "单位结果:" + status); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getErr(byte status) { | |||
mList.add(TimeUtils.getTime() + "错误:" + status); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onBmVersion(String version) { | |||
mList.add(TimeUtils.getTime() + "版本号:" + version); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void OnDID(int cid, int vid, int pid) { | |||
String didStr = "cid:" + cid + "||vid:" + vid + "||pid:" + pid; | |||
mList.add(TimeUtils.getTime() + "ID:" + didStr); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onMcuBatteryStatus(int status, int battery) { | |||
mList.add(TimeUtils.getTime() + "电量:" + battery + "%"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onSysTime(int status, int[] times) { | |||
String time = | |||
times[0] + "-" + times[1] + "-" + times[2] + " " + times[3] + ":" + times[4] + | |||
":" + times[5]; | |||
mList.add(TimeUtils.getTime() + "系统时间:" + time); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
protected void onDestroy() { | |||
super.onDestroy(); | |||
BleLog.i(TAG, "onDestroy"); | |||
} | |||
} |
@@ -0,0 +1,144 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.app.Dialog; | |||
import android.content.DialogInterface; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import android.os.Message; | |||
import android.view.KeyEvent; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import androidx.fragment.app.DialogFragment; | |||
import androidx.fragment.app.FragmentManager; | |||
import androidx.fragment.app.FragmentTransaction; | |||
/** | |||
* elink-android<br> | |||
* LoadingIosDialogFragment<br> | |||
* xing<br> | |||
* 2019/2/26 16:07<br> | |||
* 加载提示框 | |||
*/ | |||
public class LoadingIosDialogFragment extends DialogFragment { | |||
private static String TAG = LoadingIosDialogFragment.class.getName(); | |||
private final static int DISMISS_OUT = 1; | |||
/** | |||
* 默认超时时间 | |||
*/ | |||
private int timeOut = 30; | |||
private boolean show = false; | |||
public boolean isShow() { | |||
return show; | |||
} | |||
private Handler mHandler = new Handler(Looper.getMainLooper()) { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
switch (msg.what) { | |||
case DISMISS_OUT: | |||
LoadingIosDialogFragment.this.dismiss(); | |||
break; | |||
} | |||
} | |||
}; | |||
@Override | |||
public void dismiss() { | |||
try { | |||
mHandler.removeMessages(DISMISS_OUT); | |||
if (getFragmentManager() != null) | |||
super.dismiss(); | |||
show = false; | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
public int getTimeOut() { | |||
return timeOut; | |||
} | |||
public void setTimeOut(int timeOut) { | |||
this.timeOut = timeOut; | |||
} | |||
public void show(@NonNull FragmentManager manager) { | |||
this.show(manager, "LoadingIosDialogFragment"); | |||
} | |||
@Override | |||
public void show(@NonNull FragmentManager manager, @Nullable String tag) { | |||
try { | |||
super.show(manager, tag); | |||
show = true; | |||
} catch (Exception e) { | |||
show = false; | |||
e.printStackTrace(); | |||
} | |||
mHandler.sendEmptyMessageDelayed(DISMISS_OUT, timeOut * 1000); | |||
} | |||
@Override | |||
public int show(@NonNull FragmentTransaction transaction, @Nullable String tag) { | |||
return super.show(transaction, tag); | |||
} | |||
@Override | |||
public void onActivityCreated(@Nullable Bundle savedInstanceState) { | |||
super.onActivityCreated(savedInstanceState); | |||
if (getDialog() != null) { | |||
getDialog().setOnShowListener(null); | |||
getDialog().setOnCancelListener(null); | |||
getDialog().setOnDismissListener(null); | |||
} | |||
} | |||
@Nullable | |||
@Override | |||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |||
return super.onCreateView(inflater, container, savedInstanceState); | |||
} | |||
@NonNull | |||
@Override | |||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { | |||
LayoutInflater inflater = LayoutInflater.from(requireContext()); | |||
View v = inflater.inflate(R.layout.dialog_loading_ios, null);// 得到加载view | |||
Dialog loadingDialog = new Dialog(requireContext(), R.style.MyDialog);// 创建自定义样式dialog | |||
loadingDialog.setCancelable(false);//设置点击空白处是否可以取消 | |||
//按返回键是否可以取消 | |||
loadingDialog.setCanceledOnTouchOutside(false); | |||
loadingDialog.setContentView(v);// 设置布局 | |||
loadingDialog.setOnKeyListener(new DialogInterface.OnKeyListener() { | |||
@Override | |||
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { | |||
//返回不关闭 | |||
return keyCode == KeyEvent.KEYCODE_BACK; | |||
} | |||
}); | |||
return loadingDialog; | |||
} | |||
@Override | |||
public void onDestroyView() { | |||
super.onDestroyView(); | |||
if (mHandler != null) { | |||
mHandler.removeCallbacksAndMessages(null); | |||
} | |||
} | |||
} |
@@ -0,0 +1,198 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.Manifest; | |||
import android.app.AlertDialog; | |||
import android.content.DialogInterface; | |||
import android.content.Intent; | |||
import android.content.pm.PackageManager; | |||
import android.net.Uri; | |||
import android.os.Build; | |||
import android.os.Bundle; | |||
import android.provider.Settings; | |||
import android.view.View; | |||
import android.widget.Button; | |||
import android.widget.TextView; | |||
import com.pingwang.bluetoothlib.AILinkSDK; | |||
import com.pingwang.bluetoothlib.config.BleDeviceConfig; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import androidx.annotation.NonNull; | |||
import androidx.appcompat.app.AppCompatActivity; | |||
import androidx.core.app.ActivityCompat; | |||
public class MainActivity extends AppCompatActivity { | |||
private static String TAG = MainActivity.class.getName(); | |||
@Override | |||
protected void onCreate(Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
AILinkSDK.getInstance().init(this,"",""); | |||
setContentView(R.layout.activity_main); | |||
BleLog.init("", "", BuildConfig.DEBUG); | |||
String version=getString(R.string.version)+":"+BuildConfig.VERSION_NAME; | |||
((TextView)findViewById(R.id.tv_app_version)).setText(version); | |||
init(); | |||
initPermissions(); | |||
} | |||
private void init() { | |||
MyListener listener = new MyListener(); | |||
Button btn_shpy = findViewById(R.id.btn_sphy); | |||
Button btn_tempgun = findViewById(R.id.btn_tempgun); | |||
Button btn_temp = findViewById(R.id.btn_temp); | |||
Button btn_baby = findViewById(R.id.btn_baby); | |||
Button btn_height = findViewById(R.id.btn_height); | |||
Button btn_ble = findViewById(R.id.btn_ble); | |||
findViewById(R.id.btn_ad_weight).setOnClickListener(listener); | |||
btn_shpy.setOnClickListener(listener); | |||
btn_tempgun.setOnClickListener(listener); | |||
btn_temp.setOnClickListener(listener); | |||
btn_baby.setOnClickListener(listener); | |||
btn_height.setOnClickListener(listener); | |||
btn_ble.setOnClickListener(listener); | |||
findViewById(R.id.btn_wifi_ble_weight).setOnClickListener(listener); | |||
} | |||
private class MyListener implements View.OnClickListener { | |||
@Override | |||
public void onClick(View v) { | |||
// boolean onClick= initPermissions(); | |||
// if (!onClick){ | |||
// return; | |||
// } | |||
int type = 0; | |||
switch (v.getId()) { | |||
case R.id.btn_sphy: | |||
type = BleDeviceConfig.BLOOD_PRESSURE; | |||
break; | |||
case R.id.btn_tempgun: | |||
type = BleDeviceConfig.INFRARED_THERMOMETER; | |||
break; | |||
case R.id.btn_temp: | |||
type = BleDeviceConfig.THERMOMETER; | |||
break; | |||
case R.id.btn_baby: | |||
type = BleDeviceConfig.BABY_SCALE; | |||
break; | |||
case R.id.btn_height: | |||
type = BleDeviceConfig.HEIGHT_METER; | |||
break; | |||
case R.id.btn_ad_weight: | |||
type = BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_AD; | |||
break; | |||
case R.id.btn_wifi_ble_weight: | |||
type= BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_WIFI_BLE; | |||
break; | |||
case R.id.btn_ble: | |||
type = 0; | |||
break; | |||
} | |||
startActivity(type); | |||
} | |||
} | |||
/** | |||
* 初始化请求权限 | |||
*/ | |||
private void initPermissions() { | |||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | |||
ActivityCompat.requestPermissions(this, | |||
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, 1); | |||
} | |||
} | |||
@Override | |||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, | |||
@NonNull int[] grantResults) { | |||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | |||
if (requestCode != 1) { | |||
return; | |||
} | |||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | |||
} else { | |||
if (ActivityCompat.shouldShowRequestPermissionRationale(this, permissions[0])) { | |||
//权限请求失败,但未选中“不再提示”选项 | |||
new AlertDialog.Builder(this).setTitle("提示") | |||
.setMessage("请求使用定位权限搜索蓝牙设备") | |||
.setPositiveButton("确定", new DialogInterface.OnClickListener() { | |||
@Override | |||
public void onClick(DialogInterface dialog, int which) { | |||
//引导用户至设置页手动授权 | |||
Intent intent = | |||
new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); | |||
Uri uri = Uri.fromParts("package", | |||
getApplicationContext().getPackageName(), null); | |||
intent.setData(uri); | |||
startActivity(intent); | |||
} | |||
}) | |||
.setNegativeButton("取消", new DialogInterface.OnClickListener() { | |||
@Override | |||
public void onClick(DialogInterface dialog, int which) { | |||
if (dialog != null) { | |||
dialog.cancel(); | |||
} | |||
} | |||
}) | |||
.show(); | |||
} else { | |||
//权限请求失败,选中“不再提示”选项 | |||
// T.showShort(MainActivity.this, "获取权限失败"); | |||
new AlertDialog.Builder(this).setTitle("提示") | |||
.setMessage("请求使用定位权限搜索蓝牙设备") | |||
.setPositiveButton("确定", new DialogInterface.OnClickListener() { | |||
@Override | |||
public void onClick(DialogInterface dialog, int which) { | |||
//引导用户至设置页手动授权 | |||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); | |||
Uri uri = Uri.fromParts("package", getApplicationContext().getPackageName(), null); | |||
intent.setData(uri); | |||
startActivity(intent); | |||
} | |||
}) | |||
.setNegativeButton("取消", new DialogInterface.OnClickListener() { | |||
@Override | |||
public void onClick(DialogInterface dialog, int which) { | |||
if (dialog != null) { | |||
dialog.cancel(); | |||
} | |||
} | |||
}) | |||
.show(); | |||
} | |||
} | |||
} | |||
private void startActivity(int tyep) { | |||
Intent intent = new Intent(this, ShowBleActivity.class); | |||
intent.putExtra("type", tyep); | |||
startActivity(intent); | |||
} | |||
@Override | |||
protected void onResume() { | |||
super.onResume(); | |||
} | |||
@Override | |||
protected void onDestroy() { | |||
super.onDestroy(); | |||
BleLog.quit(); | |||
} | |||
} |
@@ -0,0 +1,383 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.content.ComponentName; | |||
import android.content.Context; | |||
import android.content.Intent; | |||
import android.content.ServiceConnection; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.IBinder; | |||
import android.os.Looper; | |||
import android.os.Message; | |||
import android.view.View; | |||
import android.widget.AdapterView; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.Button; | |||
import android.widget.ListView; | |||
import android.widget.Toast; | |||
import com.pingwang.bluetoothlib.bean.BleValueBean; | |||
import com.pingwang.bluetoothlib.config.BleConfig; | |||
import com.pingwang.bluetoothlib.config.BleDeviceConfig; | |||
import com.pingwang.bluetoothlib.listener.CallbackDisIm; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | |||
import com.pingwang.bluetoothlib.listener.OnScanFilterListener; | |||
import com.pingwang.bluetoothlib.server.ELinkBleServer; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import androidx.appcompat.app.AppCompatActivity; | |||
/** | |||
* xing<br> | |||
* 2019/3/6<br> | |||
* java类作用描述 | |||
*/ | |||
public class ShowBleActivity extends AppCompatActivity implements OnCallbackBle, OnScanFilterListener { | |||
private static String TAG = ShowBleActivity.class.getName(); | |||
private final int BIND_SERVER_OK = 1; | |||
private final int BIND_SERVER_ERR = 2; | |||
private final int REFRESH_DATA = 3; | |||
private List<String> mList; | |||
private ArrayAdapter listAdapter; | |||
private ELinkBleServer mBluetoothService; | |||
/** | |||
* 服务Intent | |||
*/ | |||
private Intent bindIntent; | |||
private Context mContext; | |||
private int mType; | |||
private boolean mFilter = true; | |||
private Handler mHandler = new Handler(Looper.getMainLooper()) { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
switch (msg.what) { | |||
case BIND_SERVER_OK: | |||
break; | |||
case REFRESH_DATA: | |||
listAdapter.notifyDataSetChanged(); | |||
break; | |||
} | |||
} | |||
}; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_show_ble); | |||
Intent mUserService = new Intent(this.getApplicationContext(), ELinkBleServer.class); | |||
//核心用户服务 | |||
startService(mUserService); | |||
mContext = this; | |||
mType = getIntent().getIntExtra("type", -1); | |||
if (-1 == mType) { | |||
finish(); | |||
return; | |||
} | |||
init(); | |||
initData(); | |||
} | |||
private void initData() { | |||
bindService(); | |||
} | |||
private void init() { | |||
mList = new ArrayList<>(); | |||
ListView listView = findViewById(R.id.listview); | |||
Button btn = findViewById(R.id.btn); | |||
Button btn1 = findViewById(R.id.btn1); | |||
Button clear = findViewById(R.id.clear); | |||
final Button filter = findViewById(R.id.filter); | |||
filter.setTag(true); | |||
btn.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
if (mBluetoothService != null) { | |||
BleLog.i(TAG, "搜索设备"); | |||
mBluetoothService.scanLeDevice(0, BleConfig.SERVER_UUID); | |||
mList.clear(); | |||
listAdapter.notifyDataSetChanged(); | |||
} | |||
} | |||
}); | |||
btn1.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
if (mBluetoothService != null) { | |||
mBluetoothService.stopScan(); | |||
} | |||
} | |||
}); | |||
clear.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
if (mBluetoothService != null) { | |||
mList.clear(); | |||
listAdapter.notifyDataSetChanged(); | |||
} | |||
} | |||
}); | |||
filter.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
boolean m = (Boolean) filter.getTag(); | |||
filter.setTag(!m); | |||
mFilter = !m; | |||
filter.setText("过滤:" + mFilter); | |||
} | |||
}); | |||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | |||
listView.setAdapter(listAdapter); | |||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { | |||
@Override | |||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | |||
String itemStr = mList.get(position); | |||
String mac = itemStr.split("=")[0]; | |||
if (mBluetoothService != null) { | |||
mBluetoothService.stopScan(); | |||
mBluetoothService.connectDevice(mac); | |||
showLoading(); | |||
} | |||
} | |||
}); | |||
findViewById(R.id.跳过).setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
Toast.makeText(mContext, "跳过", Toast.LENGTH_SHORT).show(); | |||
} | |||
}); | |||
} | |||
//---------------------------------服务--------------------------------------------------- | |||
private void bindService() { | |||
BleLog.i(TAG, "绑定服务"); | |||
if (bindIntent == null) { | |||
bindIntent = new Intent(mContext, ELinkBleServer.class); | |||
if (mFhrSCon != null) | |||
this.bindService(bindIntent, mFhrSCon, Context.BIND_AUTO_CREATE); | |||
} | |||
} | |||
private void unbindService() { | |||
CallbackDisIm.getInstance().removeListener(this); | |||
if (mFhrSCon != null) | |||
this.unbindService(mFhrSCon); | |||
bindIntent = null; | |||
} | |||
/** | |||
* 服务连接与界面的连接 | |||
*/ | |||
private ServiceConnection mFhrSCon = new ServiceConnection() { | |||
@Override | |||
public void onServiceConnected(ComponentName name, IBinder service) { | |||
BleLog.i(TAG, "服务与界面建立连接成功"); | |||
//与服务建立连接 | |||
mBluetoothService = ((ELinkBleServer.BluetoothBinder) service).getService(); | |||
if (mBluetoothService != null) { | |||
mBluetoothService.setOnCallback(ShowBleActivity.this); | |||
mBluetoothService.setOnScanFilterListener(ShowBleActivity.this); | |||
mHandler.sendEmptyMessage(BIND_SERVER_OK); | |||
} | |||
} | |||
@Override | |||
public void onServiceDisconnected(ComponentName name) { | |||
BleLog.i(TAG, "服务与界面连接断开"); | |||
//与服务断开连接 | |||
mBluetoothService = null; | |||
} | |||
}; | |||
@Override | |||
public void onStartScan() { | |||
} | |||
@Override | |||
public void onScanning(@NonNull BleValueBean data) { | |||
String mAddress = data.getMac(); | |||
if (!mList.contains(mAddress + "=" + data.getName())) { | |||
String data1 = BleStrUtils.byte2HexStr(data.getScanRecord()); | |||
BleLog.i(TAG, "设备地址+广播数据:" + mAddress + "||" + data1); | |||
mList.add(mAddress + "=" + data.getName()); | |||
listAdapter.notifyDataSetChanged(); | |||
} | |||
} | |||
@Override | |||
public void onConnecting(@NonNull String mac) { | |||
} | |||
@Override | |||
public void onDisConnected(@NonNull String mac, int code) { | |||
dismissLoading(); | |||
Toast.makeText(mContext, "连接断开:" + code, Toast.LENGTH_SHORT).show(); | |||
} | |||
@Override | |||
public void onServicesDiscovered(@NonNull String mac) { | |||
dismissLoading(); | |||
Intent intent = new Intent(); | |||
int type = mType;//默认婴儿秤 | |||
switch (type) { | |||
case BleDeviceConfig.BABY_SCALE: | |||
intent.setClass(ShowBleActivity.this, BabyCmdActivity.class); | |||
break; | |||
case BleDeviceConfig.INFRARED_THERMOMETER: | |||
intent.setClass(ShowBleActivity.this, TempGunCmdActivity.class); | |||
break; | |||
case BleDeviceConfig.BLOOD_PRESSURE: | |||
intent.setClass(ShowBleActivity.this, SphyCmdActivity.class); | |||
break; | |||
case BleDeviceConfig.THERMOMETER: | |||
intent.setClass(ShowBleActivity.this, TempCmdActivity.class); | |||
break; | |||
case BleDeviceConfig.HEIGHT_METER: | |||
intent.setClass(ShowBleActivity.this, HeightCmdActivity.class); | |||
break; | |||
case BleDeviceConfig.WEIGHT_BODY_FAT_SCALE: | |||
break; | |||
case BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_AD: | |||
intent.setClass(ShowBleActivity.this, ADWeightScaleCmdActivity.class); | |||
break; | |||
case BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_WIFI_BLE: | |||
intent.setClass(ShowBleActivity.this,WeightScaleWifiBle.class); | |||
break; | |||
case 0: | |||
intent.setClass(ShowBleActivity.this, BleCmdActivityDataData.class); | |||
break; | |||
} | |||
intent.putExtra("type", type); | |||
intent.putExtra("mac", mac); | |||
startActivity(intent); | |||
} | |||
@Override | |||
public void bleOpen() { | |||
} | |||
@Override | |||
public void bleClose() { | |||
} | |||
@Override | |||
public boolean onFilter(BleValueBean bleValueBean) { | |||
byte[] CID = bleValueBean.getCID(); | |||
int cid = ((CID[0] & 0xff) << 8) + (CID[1]); | |||
BleLog.i(TAG, "绑定设备广播类型:" + cid + "||添加的类型:" + mType); | |||
if (mType == 0 || mType == 100) | |||
return true; | |||
else | |||
return mType == cid; | |||
// byte[] CID = new byte[2]; | |||
// CID[0] = 0x0a; | |||
// CID[1] = 0x45; | |||
// byte[] data = bleValueBean.getScanRecord(); | |||
// byte[] datas=new byte[13]; | |||
// BleLog.i(TAG, "原始数据1:"+BleStrUtils.byte2HexStr(data)); | |||
// System.arraycopy(data,9,datas,0,datas.length); | |||
// byte size=0; | |||
// for (int i = 1; i < datas.length-2; i++) { | |||
// size+=datas[i]; | |||
// } | |||
// | |||
// BleLog.i(TAG, "校验和:"+BleStrUtils.getHexString((size&0xff)).toUpperCase()); | |||
// BleLog.i(TAG, "原始数据2:"+BleStrUtils.byte2HexStr(datas).toUpperCase()); | |||
// byte[] dataEncrypt=new byte[datas.length-4]; | |||
// System.arraycopy(datas,2,dataEncrypt,0,dataEncrypt.length); | |||
// byte[] newData = AiLinkBleCheckUtil.mcuEncrypt(CID, dataEncrypt, bleValueBean.getMac()); | |||
// BleLog.i(TAG,"解密:"+BleStrUtils.byte2HexStr(newData).toUpperCase()); | |||
// return false; | |||
} | |||
@Override | |||
public void onScanRecord(BleValueBean mBle) { | |||
//TODO 过滤后的设备 | |||
} | |||
//--------------------------start Loading-------------------------- | |||
private LoadingIosDialogFragment mDialogFragment; | |||
/** | |||
* 显示加载 | |||
*/ | |||
private void showLoading() { | |||
if (mDialogFragment == null) | |||
mDialogFragment = new LoadingIosDialogFragment(); | |||
mDialogFragment.show(getSupportFragmentManager()); | |||
} | |||
/** | |||
* 关闭加载 | |||
*/ | |||
private void dismissLoading() { | |||
if (mDialogFragment != null) | |||
mDialogFragment.dismiss(); | |||
} | |||
//--------------------------end Loading-------------------------- | |||
@Override | |||
protected void onResume() { | |||
super.onResume(); | |||
if (mBluetoothService != null) { | |||
mBluetoothService.setOnCallback(ShowBleActivity.this); | |||
mBluetoothService.setOnScanFilterListener(ShowBleActivity.this); | |||
} | |||
} | |||
@Override | |||
protected void onDestroy() { | |||
super.onDestroy(); | |||
unbindService(); | |||
} | |||
} |
@@ -0,0 +1,346 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.content.Context; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import android.os.Message; | |||
import android.view.View; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.Button; | |||
import android.widget.EditText; | |||
import android.widget.ListView; | |||
import com.pingwang.bluetoothlib.config.CmdConfig; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | |||
import com.pingwang.bluetoothlib.device.SendBleBean; | |||
import com.pingwang.bluetoothlib.device.SendMcuBean; | |||
import com.pingwang.bluetoothlib.listener.CallbackDisIm; | |||
import com.pingwang.bluetoothlib.listener.OnBleCompanyListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleVersionListener; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackDis; | |||
import com.pingwang.bluetoothlib.listener.OnMcuParameterListener; | |||
import com.pingwang.bluetoothlib.utils.BleDensityUtil; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import cn.net.aicare.modulelibrary.module.sphygmomanometer.SphyDeviceData; | |||
/** | |||
* xing<br> | |||
* 2019/4/25<br> | |||
* 显示数据 | |||
*/ | |||
public class SphyCmdActivity extends BleBaseActivity implements OnCallbackDis, OnBleVersionListener | |||
, OnMcuParameterListener, OnBleCompanyListener, View.OnClickListener { | |||
private static String TAG = SphyCmdActivity.class.getName(); | |||
private final int REFRESH_DATA = 3; | |||
private List<String> mList; | |||
private ArrayAdapter listAdapter; | |||
private Context mContext; | |||
private EditText et_type; | |||
private SphyDeviceData mBleDevice; | |||
private String mAddress; | |||
private BleSendCmdUtil mBleSendCmdUtil; | |||
private int type; | |||
private byte unit = 0; | |||
private Handler mHandler = new Handler(Looper.getMainLooper()) { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
switch (msg.what) { | |||
case REFRESH_DATA: | |||
if (listAdapter != null) | |||
listAdapter.notifyDataSetChanged(); | |||
break; | |||
} | |||
} | |||
}; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_sphy); | |||
mContext = this; | |||
mAddress = getIntent().getStringExtra("mac"); | |||
type = getIntent().getIntExtra("type", -1); | |||
mBleSendCmdUtil = BleSendCmdUtil.getInstance(); | |||
init(); | |||
} | |||
private void init() { | |||
mList = new ArrayList<>(); | |||
ListView listView = findViewById(R.id.listview); | |||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | |||
listView.setAdapter(listAdapter); | |||
Button clear = findViewById(R.id.clear); | |||
clear.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
if (mList != null) | |||
mList.clear(); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
}); | |||
findViewById(R.id.btn1).setOnClickListener(this); | |||
findViewById(R.id.btnVersion).setOnClickListener(this); | |||
findViewById(R.id.btnBattery).setOnClickListener(this); | |||
findViewById(R.id.btn_get_did).setOnClickListener(this); | |||
findViewById(R.id.clear).setOnClickListener(this); | |||
et_type = findViewById(R.id.et_type); | |||
cmdBtn(); | |||
} | |||
private void cmdBtn() { | |||
Button btn_set_unit = findViewById(R.id.btn_set_unit); | |||
btn_set_unit.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
if (unit == 0) { | |||
mBleDevice.setUnit((byte) 1); | |||
unit = 1; | |||
} else { | |||
mBleDevice.setUnit((byte) 0); | |||
unit = 0; | |||
} | |||
} | |||
}); | |||
Button btn_start = findViewById(R.id.btn_start); | |||
btn_start.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
mBleDevice.startMeasuring(); | |||
} | |||
}); | |||
Button btn_stop = findViewById(R.id.btn_stop); | |||
btn_stop.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
mBleDevice.stopMeasuring(); | |||
} | |||
}); | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
SendBleBean sendBleBean = new SendBleBean(); | |||
switch (v.getId()) { | |||
case R.id.btnVersion: | |||
sendBleBean.setHex(mBleSendCmdUtil.getBleVersion()); | |||
mBleDevice.sendData(sendBleBean); | |||
break; | |||
case R.id.btnBattery: | |||
sendBleBean.setHex(mBleSendCmdUtil.getMcuBatteryStatus()); | |||
mBleDevice.sendData(sendBleBean); | |||
break; | |||
case R.id.btn_get_did: | |||
sendBleBean.setHex(mBleSendCmdUtil.getDid()); | |||
mBleDevice.sendData(sendBleBean); | |||
break; | |||
case R.id.btn1: | |||
String cmd = et_type.getText().toString().trim(); | |||
SendMcuBean sendDataBean = new SendMcuBean(); | |||
sendDataBean.setHex(type,cmd.getBytes()); | |||
mBleDevice.sendData(sendDataBean); | |||
break; | |||
case R.id.clear: | |||
if (mList != null) | |||
mList.clear(); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
break; | |||
} | |||
} | |||
//---------------------------------服务--------------------------------------------------- | |||
@Override | |||
public void onServiceSuccess() { | |||
CallbackDisIm.getInstance().addListListener(this); | |||
BleLog.i(TAG, "服务与界面建立连接成功"); | |||
//与服务建立连接 | |||
if (mBluetoothService != null) { | |||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | |||
if (bleDevice != null) { | |||
mBleDevice = SphyDeviceData.getInstance(bleDevice); | |||
mBleDevice.setOnNotifyData(new NotifyData()); | |||
mBleDevice.setOnBleVersionListener(SphyCmdActivity.this); | |||
mBleDevice.setOnMcuParameterListener(SphyCmdActivity.this); | |||
mBleDevice.setOnCompanyListener(SphyCmdActivity.this); | |||
} | |||
} | |||
} | |||
@Override | |||
public void onServiceErr() { | |||
BleLog.i(TAG, "服务与界面连接断开"); | |||
//与服务断开连接 | |||
mBluetoothService = null; | |||
} | |||
@Override | |||
public void unbindServices() { | |||
CallbackDisIm.getInstance().removeListener(this); | |||
if (mBleDevice != null) { | |||
mBleDevice.disconnect(); | |||
mBleDevice.clear(); | |||
mBleDevice = null; | |||
} | |||
} | |||
//-----------------状态------------------- | |||
@Override | |||
public void onConnecting(@NonNull String mac) { | |||
//TODO 连接中 | |||
if (mAddress.equals(mac)) | |||
BleLog.i(TAG, "连接中"); | |||
} | |||
@Override | |||
public void onDisConnected(@NonNull String mac, int code) { | |||
//TODO 连接断开 | |||
if (mAddress.equals(mac)) | |||
BleLog.i(TAG, "连接断开"); | |||
} | |||
@Override | |||
public void onServicesDiscovered(@NonNull String mac) { | |||
//TODO 连接成功(获取服务成功) | |||
if (mAddress.equals(mac)) | |||
BleLog.i(TAG, "连接成功(获取服务成功)"); | |||
} | |||
@Override | |||
public void bleOpen() { | |||
} | |||
@Override | |||
public void bleClose() { | |||
BleLog.i(TAG, "蓝牙未开启,可请求开启"); | |||
} | |||
//-----------------通知------------------- | |||
private class NotifyData implements SphyDeviceData.onNotifyData { | |||
@Override | |||
public void onData(byte[] status, int type) { | |||
String data = ""; | |||
if (status != null) | |||
data = BleStrUtils.byte2HexStr(status); | |||
if (type == 100) { | |||
mList.add(TimeUtils.getTime() + "send->" + data); | |||
} else { | |||
mList.add(TimeUtils.getTime() + "notify->" + data); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getSphyCmd(byte cmd) { | |||
mList.add(TimeUtils.getTime() + "指令:" + cmd); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void sphyDataNow(int dia, int sys, int decimal, int pul, int unit) { | |||
String diaStr = BleDensityUtil.getInstance().holdDecimals(dia, decimal); | |||
String sysStr = BleDensityUtil.getInstance().holdDecimals(sys, decimal); | |||
mList.add(TimeUtils.getTime() + "实时:dia=" + diaStr + "sys=" + sysStr + "pul=" + pul + "unit" + "=" + unit); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void sphyData(int dia, int sys, int decimal, int pul, int unit) { | |||
String diaStr = BleDensityUtil.getInstance().holdDecimals(dia, decimal); | |||
String sysStr = BleDensityUtil.getInstance().holdDecimals(sys, decimal); | |||
mList.add(TimeUtils.getTime() + "稳定:dia=" + diaStr + "sys=" + sysStr + "pul=" + pul + "unit" + "=" + unit); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getUnit(int unit) { | |||
String showData = ""; | |||
switch (unit) { | |||
case CmdConfig.SETTING_SUCCESS: | |||
showData = "设置单位成功"; | |||
break; | |||
case CmdConfig.SETTING_FAILURE: | |||
showData = "设置单位失败"; | |||
break; | |||
case CmdConfig.SETTING_ERR: | |||
showData = "设置单位错误"; | |||
break; | |||
} | |||
mList.add(TimeUtils.getTime() + showData); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getErr(byte status) { | |||
mList.add(TimeUtils.getTime() + "错误:" + status); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
} | |||
@Override | |||
public void onBmVersion(String version) { | |||
mList.add(TimeUtils.getTime() + "版本号:" + version); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void OnDID(int cid, int vid, int pid) { | |||
String didStr = "cid:" + cid + "||vid:" + vid + "||pid:" + pid; | |||
mList.add(TimeUtils.getTime() + "ID:" + didStr); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onMcuBatteryStatus(int status, int battery) { | |||
mList.add(TimeUtils.getTime() + "电量:" + battery + "%"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onSysTime(int status, int[] times) { | |||
String time = | |||
times[0] + "-" + times[1] + "-" + times[2] + " " + times[3] + ":" + times[4] + | |||
":" + times[5]; | |||
mList.add(TimeUtils.getTime() + "系统时间:" + time); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
protected void onDestroy() { | |||
super.onDestroy(); | |||
BleLog.i(TAG, "onDestroy"); | |||
} | |||
} |
@@ -0,0 +1,297 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.content.Context; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import android.os.Message; | |||
import android.view.View; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.Button; | |||
import android.widget.EditText; | |||
import android.widget.ListView; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | |||
import com.pingwang.bluetoothlib.device.SendBleBean; | |||
import com.pingwang.bluetoothlib.device.SendMcuBean; | |||
import com.pingwang.bluetoothlib.listener.CallbackDisIm; | |||
import com.pingwang.bluetoothlib.listener.OnBleCompanyListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleVersionListener; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackDis; | |||
import com.pingwang.bluetoothlib.listener.OnMcuParameterListener; | |||
import com.pingwang.bluetoothlib.utils.BleDensityUtil; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import cn.net.aicare.modulelibrary.module.thermometer.TempDeviceData; | |||
/** | |||
* xing<br> | |||
* 2019/4/25<br> | |||
* 显示数据 | |||
*/ | |||
public class TempCmdActivity extends BleBaseActivity implements OnCallbackDis, OnBleVersionListener, OnMcuParameterListener, OnBleCompanyListener, View.OnClickListener { | |||
private static String TAG = TempCmdActivity.class.getName(); | |||
private final int REFRESH_DATA = 3; | |||
private List<String> mList; | |||
private ArrayAdapter listAdapter; | |||
/** | |||
* 服务Intent | |||
*/ | |||
private Context mContext; | |||
private EditText et_type; | |||
private TempDeviceData mBleDevice; | |||
private String mAddress; | |||
private BleSendCmdUtil mBleSendCmdUtil; | |||
private int type; | |||
private byte unit = 0; | |||
private Handler mHandler = new Handler(Looper.getMainLooper()) { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
switch (msg.what) { | |||
case REFRESH_DATA: | |||
if (listAdapter != null) | |||
listAdapter.notifyDataSetChanged(); | |||
break; | |||
} | |||
} | |||
}; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_temp_gun); | |||
mContext = this; | |||
mAddress = getIntent().getStringExtra("mac"); | |||
type = getIntent().getIntExtra("type", -1); | |||
mBleSendCmdUtil = BleSendCmdUtil.getInstance(); | |||
init(); | |||
} | |||
private void init() { | |||
mList = new ArrayList<>(); | |||
ListView listView = findViewById(R.id.listview); | |||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | |||
listView.setAdapter(listAdapter); | |||
findViewById(R.id.btn1).setOnClickListener(this); | |||
findViewById(R.id.btnVersion).setOnClickListener(this); | |||
findViewById(R.id.btnBattery).setOnClickListener(this); | |||
findViewById(R.id.btn_get_did).setOnClickListener(this); | |||
findViewById(R.id.clear).setOnClickListener(this); | |||
et_type = findViewById(R.id.et_type); | |||
cmdBtn(); | |||
} | |||
private void cmdBtn() { | |||
Button btn_set_unit = findViewById(R.id.btn_set_unit); | |||
btn_set_unit.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
if (unit == 0) { | |||
unit=1; | |||
mBleDevice.setUnit((byte) 1); | |||
} else { | |||
unit=0; | |||
mBleDevice.setUnit((byte) 0); | |||
} | |||
} | |||
}); | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
SendBleBean sendBleBean = new SendBleBean(); | |||
switch (v.getId()){ | |||
case R.id.btnVersion: | |||
sendBleBean.setHex(mBleSendCmdUtil.getBleVersion()); | |||
mBleDevice.sendData(sendBleBean); | |||
break; | |||
case R.id.btnBattery: | |||
sendBleBean.setHex(mBleSendCmdUtil.getMcuBatteryStatus()); | |||
mBleDevice.sendData(sendBleBean); | |||
break; | |||
case R.id.btn_get_did: | |||
sendBleBean.setHex(mBleSendCmdUtil.getDid()); | |||
mBleDevice.sendData(sendBleBean); | |||
break; | |||
case R.id.btn1: | |||
String cmd = et_type.getText().toString().trim(); | |||
SendMcuBean sendDataBean = new SendMcuBean(); | |||
sendDataBean.setHex(type,cmd.getBytes()); | |||
mBleDevice.sendData(sendDataBean); | |||
break; | |||
case R.id.clear: | |||
if (mList != null) | |||
mList.clear(); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
break; | |||
} | |||
} | |||
//---------------------------------服务--------------------------------------------------- | |||
@Override | |||
public void onServiceSuccess() { | |||
BleLog.i(TAG, "服务与界面建立连接成功"); | |||
CallbackDisIm.getInstance().addListListener(this); | |||
if (mBluetoothService != null) { | |||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | |||
if (bleDevice != null) { | |||
mBleDevice = TempDeviceData.getInstance(bleDevice); | |||
mBleDevice.setOnNotifyData(new NotifyData()); | |||
mBleDevice.setOnBleVersionListener(TempCmdActivity.this); | |||
mBleDevice.setOnMcuParameterListener(TempCmdActivity.this); | |||
mBleDevice.setOnCompanyListener(TempCmdActivity.this); | |||
} | |||
} | |||
} | |||
@Override | |||
public void onServiceErr() { | |||
BleLog.i(TAG, "服务与界面连接断开"); | |||
//与服务断开连接 | |||
mBluetoothService = null; | |||
} | |||
@Override | |||
public void unbindServices() { | |||
CallbackDisIm.getInstance().removeListener(this); | |||
if (mBleDevice!=null){ | |||
mBleDevice.disconnect(); | |||
mBleDevice.clear(); | |||
mBleDevice=null; | |||
} | |||
} | |||
//-----------------状态------------------- | |||
@Override | |||
public void onConnecting(@NonNull String mac) { | |||
//TODO 连接中 | |||
BleLog.i(TAG, "连接中"); | |||
} | |||
@Override | |||
public void onDisConnected(@NonNull String mac, int code) { | |||
//TODO 连接断开 | |||
BleLog.i(TAG, "连接断开"); | |||
finish(); | |||
} | |||
@Override | |||
public void onServicesDiscovered(@NonNull String mac) { | |||
//TODO 连接成功(获取服务成功) | |||
BleLog.i(TAG, "连接成功(获取服务成功)"); | |||
} | |||
@Override | |||
public void bleOpen() { | |||
} | |||
@Override | |||
public void bleClose() { | |||
BleLog.i(TAG, "蓝牙未开启,可请求开启"); | |||
finish(); | |||
} | |||
//-----------------通知------------------- | |||
private class NotifyData implements TempDeviceData.onNotifyData { | |||
@Override | |||
public void onData(byte[] status,int type) { | |||
String data = ""; | |||
if (status != null) | |||
data = BleStrUtils.byte2HexStr(status); | |||
if (type == 100) { | |||
mList.add(TimeUtils.getTime() + "send->" + data); | |||
} else { | |||
mList.add(TimeUtils.getTime() + "notify->" + data); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void temp(int temp, int decimal, byte tempUnit) { | |||
String tempStr= BleDensityUtil.getInstance().holdDecimals(temp,decimal); | |||
mList.add(TimeUtils.getTime() + "稳定:TEMP=" + tempStr + "tempUnit=" + tempUnit); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void tempNow(int temp, int decimal, byte tempUnit) { | |||
String tempStr= BleDensityUtil.getInstance().holdDecimals(temp,decimal); | |||
mList.add(TimeUtils.getTime() + "实时:TEMP=" + tempStr + "tempUnit=" + tempUnit); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getUnit(byte status) { | |||
mList.add(TimeUtils.getTime() + "单位:" + status); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getErr(byte status) { | |||
mList.add(TimeUtils.getTime() + "错误:" + status); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
} | |||
@Override | |||
public void onBmVersion(String version) { | |||
mList.add(TimeUtils.getTime() + "版本号:" + version); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void OnDID(int cid, int vid, int pid) { | |||
String didStr = "cid:" + cid + "||vid:" + vid + "||pid:" + pid; | |||
mList.add(TimeUtils.getTime() + "ID:" + didStr); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onMcuBatteryStatus(int status, int battery) { | |||
mList.add(TimeUtils.getTime() + "电量:" + battery + "%"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onSysTime(int status, int[] times) { | |||
String time = | |||
times[0] + "-" + times[1] + "-" + times[2] + " " + times[3] + ":" + times[4] + | |||
":" + times[5]; | |||
mList.add(TimeUtils.getTime() + "系统时间:" + time); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
protected void onDestroy() { | |||
super.onDestroy(); | |||
BleLog.i(TAG, "onDestroy"); | |||
} | |||
} |
@@ -0,0 +1,343 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.content.Context; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import android.os.Message; | |||
import android.view.View; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.Button; | |||
import android.widget.EditText; | |||
import android.widget.ListView; | |||
import android.widget.Toast; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | |||
import com.pingwang.bluetoothlib.device.SendBleBean; | |||
import com.pingwang.bluetoothlib.device.SendMcuBean; | |||
import com.pingwang.bluetoothlib.listener.CallbackDisIm; | |||
import com.pingwang.bluetoothlib.listener.OnBleCompanyListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleVersionListener; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackDis; | |||
import com.pingwang.bluetoothlib.listener.OnMcuParameterListener; | |||
import com.pingwang.bluetoothlib.utils.BleDensityUtil; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import cn.net.aicare.modulelibrary.module.foreheadgun.TempGunDeviceData; | |||
/** | |||
* xing<br> | |||
* 2019/4/25<br> | |||
* 显示数据 | |||
*/ | |||
public class TempGunCmdActivity extends BleBaseActivity implements OnCallbackDis, OnBleVersionListener, TempGunDeviceData.onNotifyData , OnBleCompanyListener, OnMcuParameterListener, View.OnClickListener { | |||
private static String TAG = TempGunCmdActivity.class.getName(); | |||
private final int REFRESH_DATA = 3; | |||
private List<String> mList; | |||
private ArrayAdapter listAdapter; | |||
/** | |||
* 服务Intent | |||
*/ | |||
private Context mContext; | |||
private EditText et_type; | |||
private TempGunDeviceData mBleDevice; | |||
private String mAddress; | |||
private BleSendCmdUtil mBleSendCmdUtil; | |||
private int type; | |||
private byte unit = 0; | |||
private Handler mHandler = new Handler(Looper.getMainLooper()) { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
switch (msg.what) { | |||
case REFRESH_DATA: | |||
if (listAdapter != null) | |||
listAdapter.notifyDataSetChanged(); | |||
break; | |||
} | |||
} | |||
}; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_temp_gun); | |||
mContext = this; | |||
mAddress = getIntent().getStringExtra("mac"); | |||
type = getIntent().getIntExtra("type", -1); | |||
mBleSendCmdUtil = BleSendCmdUtil.getInstance(); | |||
init(); | |||
} | |||
private void init() { | |||
mList = new ArrayList<>(); | |||
ListView listView = findViewById(R.id.listview); | |||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | |||
listView.setAdapter(listAdapter); | |||
findViewById(R.id.btn1).setOnClickListener(this); | |||
findViewById(R.id.btnVersion).setOnClickListener(this); | |||
findViewById(R.id.btnBattery).setOnClickListener(this); | |||
findViewById(R.id.btn_get_did).setOnClickListener(this); | |||
findViewById(R.id.clear).setOnClickListener(this); | |||
et_type = findViewById(R.id.et_type); | |||
cmdBtn(); | |||
} | |||
private void cmdBtn() { | |||
Button btn_set_unit = findViewById(R.id.btn_set_unit); | |||
btn_set_unit.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
if (mBleDevice != null) { | |||
if (unit == 0) { | |||
unit=1; | |||
mBleDevice.setUnit((byte) 1); | |||
} else { | |||
unit=0; | |||
mBleDevice.setUnit((byte) 0); | |||
} | |||
} | |||
} | |||
}); | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
SendBleBean sendBleBean = new SendBleBean(); | |||
switch (v.getId()){ | |||
case R.id.btnVersion: | |||
sendBleBean.setHex(mBleSendCmdUtil.getBleVersion()); | |||
mBleDevice.sendData(sendBleBean); | |||
break; | |||
case R.id.btnBattery: | |||
sendBleBean.setHex(mBleSendCmdUtil.getMcuBatteryStatus()); | |||
mBleDevice.sendData(sendBleBean); | |||
break; | |||
case R.id.btn_get_did: | |||
sendBleBean.setHex(mBleSendCmdUtil.getDid()); | |||
mBleDevice.sendData(sendBleBean); | |||
break; | |||
case R.id.btn1: | |||
String cmd = et_type.getText().toString().trim(); | |||
SendMcuBean sendDataBean = new SendMcuBean(); | |||
sendDataBean.setHex(type,cmd.getBytes()); | |||
mBleDevice.sendData(sendDataBean); | |||
break; | |||
case R.id.clear: | |||
if (mList != null) | |||
mList.clear(); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
break; | |||
} | |||
} | |||
//---------------------------------服务--------------------------------------------------- | |||
@Override | |||
public void onServiceSuccess() { | |||
BleLog.i(TAG, "服务与界面建立连接成功"); | |||
CallbackDisIm.getInstance().addListListener(this); | |||
if (mBluetoothService != null) { | |||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | |||
if (bleDevice != null) { | |||
mBleDevice = TempGunDeviceData.getInstance(bleDevice); | |||
mBleDevice.setOnNotifyData(TempGunCmdActivity.this); | |||
mBleDevice.setOnBleVersionListener(TempGunCmdActivity.this); | |||
mBleDevice.setOnMcuParameterListener(TempGunCmdActivity.this); | |||
mBleDevice.setOnCompanyListener(TempGunCmdActivity.this); | |||
} else { | |||
finish(); | |||
Toast.makeText(mContext, "连接获取对象失败", Toast.LENGTH_SHORT).show(); | |||
} | |||
} | |||
} | |||
@Override | |||
public void onServiceErr() { | |||
BleLog.i(TAG, "服务与界面连接断开"); | |||
//与服务断开连接 | |||
mBluetoothService = null; | |||
} | |||
@Override | |||
public void unbindServices() { | |||
CallbackDisIm.getInstance().removeListener(this); | |||
if (mBleDevice != null) { | |||
mBleDevice.disconnect(); | |||
mBleDevice.clear(); | |||
mBleDevice = null; | |||
} | |||
} | |||
//-----------------状态------------------- | |||
@Override | |||
public void onConnecting(@NonNull String mac) { | |||
//TODO 连接中 | |||
if (mAddress.equals(mac)) | |||
BleLog.i(TAG, "连接中"); | |||
} | |||
@Override | |||
public void onDisConnected(@NonNull String mac, int code) { | |||
//TODO 连接断开 | |||
BleLog.i(TAG, "连接断开"); | |||
finish(); | |||
} | |||
@Override | |||
public void onServicesDiscovered(@NonNull String mac) { | |||
//TODO 连接成功(获取服务成功) | |||
BleLog.i(TAG, "连接成功(获取服务成功)"); | |||
} | |||
@Override | |||
public void bleOpen() { | |||
} | |||
@Override | |||
public void bleClose() { | |||
BleLog.i(TAG, "蓝牙未开启,可请求开启"); | |||
finish(); | |||
} | |||
//-----------------通知------------------- | |||
@Override | |||
public void onBmVersion(String version) { | |||
mList.add(TimeUtils.getTime() + "版本号:" + version); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onData(byte[] status,int type) { | |||
String data = ""; | |||
if (status != null) | |||
data = BleStrUtils.byte2HexStr(status); | |||
if (type == 100) { | |||
mList.add(TimeUtils.getTime() + "send->" + data); | |||
} else { | |||
mList.add(TimeUtils.getTime() + "notify->" + data); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void tempNow(int temp, int decimal, byte unit) { | |||
String tempStr= BleDensityUtil.getInstance().holdDecimals(temp,decimal); | |||
mList.add(TimeUtils.getTime() + "实时温度:" + tempStr + "||unit:" + unit); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void tempEar(int temp, int decimal, byte unit) { | |||
String tempStr= BleDensityUtil.getInstance().holdDecimals(temp,decimal); | |||
mList.add(TimeUtils.getTime() + "稳定耳温:" + tempStr + "||unit:" + unit); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void tempEarNow(int temp, int decimal, byte unit) { | |||
String tempStr= BleDensityUtil.getInstance().holdDecimals(temp,decimal); | |||
mList.add(TimeUtils.getTime() + "实时耳温:" + tempStr + "||unit:" + unit); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void tempSurrounding(int temp, int decimal, byte unit) { | |||
String tempStr= BleDensityUtil.getInstance().holdDecimals(temp,decimal); | |||
mList.add(TimeUtils.getTime() + "稳定环境温:" + tempStr + "||unit:" + unit); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void tempSurroundingNow(int temp, int decimal, byte unit) { | |||
String tempStr= BleDensityUtil.getInstance().holdDecimals(temp,decimal); | |||
mList.add(TimeUtils.getTime() + "实时环境温:" + tempStr + "||unit:" + unit); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void tempBody(int temp, int decimal, byte unit) { | |||
String tempStr= BleDensityUtil.getInstance().holdDecimals(temp,decimal); | |||
mList.add(TimeUtils.getTime() + "稳定物温:" + tempStr + "||unit:" + unit); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void tempBodyNow(int temp, int decimal, byte unit) { | |||
String tempStr= BleDensityUtil.getInstance().holdDecimals(temp,decimal); | |||
mList.add(TimeUtils.getTime() + "实时物温:" + tempStr + "||unit:" + unit); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getErr(byte status) { | |||
mList.add(TimeUtils.getTime() + "错误:" + status); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getUnit(byte status) { | |||
mList.add(TimeUtils.getTime() + "单位结果:" + status); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void temp(int temp, int decimal, byte unit) { | |||
String tempStr= BleDensityUtil.getInstance().holdDecimals(temp,decimal); | |||
mList.add(TimeUtils.getTime() + "稳定温度:" + tempStr + "||unit:" + unit); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void OnDID(int cid, int vid, int pid) { | |||
String didStr = "cid:" + cid + "||vid:" + vid + "||pid:" + pid; | |||
mList.add(TimeUtils.getTime() + "ID:" + didStr); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onMcuBatteryStatus(int status, int battery) { | |||
mList.add(TimeUtils.getTime() + "电量:" + battery + "%"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onSysTime(int status, int[] times) { | |||
String time = | |||
times[0] + "-" + times[1] + "-" + times[2] + " " + times[3] + ":" + times[4] + | |||
":" + times[5]; | |||
mList.add(TimeUtils.getTime() + "系统时间:" + time); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
protected void onDestroy() { | |||
super.onDestroy(); | |||
BleLog.i(TAG, "onDestroy"); | |||
} | |||
} |
@@ -0,0 +1,18 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import java.text.SimpleDateFormat; | |||
import java.util.Locale; | |||
/** | |||
* xing<br> | |||
* 2019/5/25<br> | |||
* java类作用描述 | |||
*/ | |||
public class TimeUtils { | |||
public static String getTime(){ | |||
SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss", Locale.US); | |||
return format.format(System.currentTimeMillis())+":\n"; | |||
} | |||
} |
@@ -0,0 +1,293 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.content.Context; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import android.os.Message; | |||
import android.view.View; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.Button; | |||
import android.widget.EditText; | |||
import android.widget.ListView; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | |||
import com.pingwang.bluetoothlib.device.SendBleBean; | |||
import com.pingwang.bluetoothlib.device.SendMcuBean; | |||
import com.pingwang.bluetoothlib.listener.CallbackDisIm; | |||
import com.pingwang.bluetoothlib.listener.OnBleCompanyListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleVersionListener; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackDis; | |||
import com.pingwang.bluetoothlib.listener.OnMcuParameterListener; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import cn.net.aicare.modulelibrary.module.tpms.TpmsDeviceData; | |||
/** | |||
* xing<br> | |||
* 2019/9/2<br> | |||
* 显示数据 | |||
*/ | |||
public class TpmsConnectCmdActivity extends BleBaseActivity implements OnCallbackDis, | |||
TpmsDeviceData.onNotifyData, TpmsDeviceData.onTpmsSetting, TpmsDeviceData.onTpmsInfo, OnBleVersionListener, OnMcuParameterListener, OnBleCompanyListener, View.OnClickListener { | |||
private static String TAG = TpmsConnectCmdActivity.class.getName(); | |||
private final int REFRESH_DATA = 3; | |||
private List<String> mList; | |||
private ArrayAdapter listAdapter; | |||
/** | |||
* 服务Intent | |||
*/ | |||
private Context mContext; | |||
private EditText et_type; | |||
private TpmsDeviceData mBleDevice; | |||
private String mAddress; | |||
private BleSendCmdUtil mBleSendCmdUtil; | |||
private int type; | |||
private Handler mHandler = new Handler(Looper.getMainLooper()) { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
switch (msg.what) { | |||
case REFRESH_DATA: | |||
if (listAdapter != null) | |||
listAdapter.notifyDataSetChanged(); | |||
break; | |||
} | |||
} | |||
}; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_height); | |||
mContext = this; | |||
mAddress = getIntent().getStringExtra("mac"); | |||
type = getIntent().getIntExtra("type", -1); | |||
mBleSendCmdUtil = BleSendCmdUtil.getInstance(); | |||
init(); | |||
} | |||
private void init() { | |||
mList = new ArrayList<>(); | |||
ListView listView = findViewById(R.id.listview); | |||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | |||
listView.setAdapter(listAdapter); | |||
findViewById(R.id.clear).setOnClickListener(this); | |||
findViewById(R.id.btn1).setOnClickListener(this); | |||
findViewById(R.id.btnVersion).setOnClickListener(this); | |||
findViewById(R.id.btnBattery).setOnClickListener(this); | |||
findViewById(R.id.btn_get_did).setOnClickListener(this); | |||
et_type = findViewById(R.id.et_type); | |||
cmdBtn(); | |||
} | |||
private void cmdBtn() { | |||
EditText et_unit_weight = findViewById(R.id.et_unit_weight); | |||
EditText et_unit_height = findViewById(R.id.et_unit_height); | |||
Button btn_set_unit = findViewById(R.id.btn_set_unit); | |||
btn_set_unit.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
String weightStr = et_unit_weight.getText().toString(); | |||
String heightStr = et_unit_height.getText().toString(); | |||
if (!weightStr.equals("") && !heightStr.equals("")) { | |||
int weight = Integer.valueOf(weightStr); | |||
int height = Integer.valueOf(heightStr); | |||
mBleDevice.setUnit((byte) height, (byte) weight); | |||
} | |||
} | |||
}); | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
SendBleBean sendBleBean = new SendBleBean(); | |||
switch (v.getId()) { | |||
case R.id.btnVersion: | |||
sendBleBean.setHex(mBleSendCmdUtil.getBleVersion()); | |||
mBleDevice.sendData(sendBleBean); | |||
break; | |||
case R.id.btnBattery: | |||
sendBleBean.setHex(mBleSendCmdUtil.getMcuBatteryStatus()); | |||
mBleDevice.sendData(sendBleBean); | |||
break; | |||
case R.id.btn_get_did: | |||
sendBleBean.setHex(mBleSendCmdUtil.getDid()); | |||
mBleDevice.sendData(sendBleBean); | |||
break; | |||
case R.id.btn1: | |||
String cmd = et_type.getText().toString().trim(); | |||
SendMcuBean sendDataBean = new SendMcuBean(); | |||
sendDataBean.setHex(type,cmd.getBytes()); | |||
mBleDevice.sendData(sendDataBean); | |||
break; | |||
case R.id.clear: | |||
if (mList != null) | |||
mList.clear(); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
break; | |||
} | |||
} | |||
//---------------------------------服务--------------------------------------------------- | |||
@Override | |||
public void onServiceSuccess() { | |||
BleLog.i(TAG, "服务与界面建立连接成功"); | |||
CallbackDisIm.getInstance().addListListener(this); | |||
if (mBluetoothService != null) { | |||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | |||
if (bleDevice != null) { | |||
mBleDevice = TpmsDeviceData.getInstance(bleDevice); | |||
mBleDevice.setOnNotifyData(TpmsConnectCmdActivity.this); | |||
mBleDevice.setOnBleVersionListener(TpmsConnectCmdActivity.this); | |||
mBleDevice.setOnMcuParameterListener(TpmsConnectCmdActivity.this); | |||
mBleDevice.setOnCompanyListener(TpmsConnectCmdActivity.this); | |||
mBleDevice.setOnTpmsSetting(TpmsConnectCmdActivity.this); | |||
} | |||
} | |||
} | |||
@Override | |||
public void onServiceErr() { | |||
BleLog.i(TAG, "服务与界面连接断开"); | |||
//与服务断开连接 | |||
mBluetoothService = null; | |||
} | |||
@Override | |||
public void unbindServices() { | |||
CallbackDisIm.getInstance().removeListener(this); | |||
if (mBleDevice != null) { | |||
mBleDevice.disconnect(); | |||
mBleDevice.clear(); | |||
mBleDevice = null; | |||
} | |||
} | |||
//-----------------状态------------------- | |||
@Override | |||
public void onConnecting(@NonNull String mac) { | |||
//TODO 连接中 | |||
BleLog.i(TAG, "连接中"); | |||
} | |||
@Override | |||
public void onDisConnected(@NonNull String mac, int code) { | |||
//TODO 连接断开 | |||
BleLog.i(TAG, "连接断开"); | |||
finish(); | |||
} | |||
@Override | |||
public void onServicesDiscovered(@NonNull String mac) { | |||
//TODO 连接成功(获取服务成功) | |||
BleLog.i(TAG, "连接成功(获取服务成功)"); | |||
} | |||
@Override | |||
public void bleOpen() { | |||
} | |||
@Override | |||
public void bleClose() { | |||
BleLog.i(TAG, "蓝牙未开启,可请求开启"); | |||
finish(); | |||
} | |||
//-----------------通知------------------- | |||
@Override | |||
public void onData(byte[] status, int type) { | |||
String data = ""; | |||
if (status != null) | |||
data = BleStrUtils.byte2HexStr(status); | |||
if (type == 100) { | |||
mList.add(TimeUtils.getTime() + "send->" + data); | |||
} else { | |||
mList.add(TimeUtils.getTime() + "notify->" + data); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onTpmsData(int index, int pressure, int pressureUnit, int pressureDecimal, | |||
float battery, int tem, int temUnit, int temDecimal, int status) { | |||
} | |||
@Override | |||
public void onTpmsType(int type) { | |||
} | |||
@Override | |||
public void getUnit(byte status) { | |||
mList.add(TimeUtils.getTime() + "单位结果:" + status); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getErr(byte status) { | |||
mList.add(TimeUtils.getTime() + "错误:" + status); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onBmVersion(String version) { | |||
mList.add(TimeUtils.getTime() + "版本号:" + version); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void OnDID(int cid, int vid, int pid) { | |||
String didStr = "cid:" + cid + "||vid:" + vid + "||pid:" + pid; | |||
mList.add(TimeUtils.getTime() + "ID:" + didStr); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onMcuBatteryStatus(int status, int battery) { | |||
mList.add(TimeUtils.getTime() + "电量:" + battery + "%"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onSysTime(int status, int[] times) { | |||
String time = | |||
times[0] + "-" + times[1] + "-" + times[2] + " " + times[3] + ":" + times[4] + | |||
":" + times[5]; | |||
mList.add(TimeUtils.getTime() + "系统时间:" + time); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
protected void onDestroy() { | |||
super.onDestroy(); | |||
BleLog.i(TAG, "onDestroy"); | |||
} | |||
} |
@@ -0,0 +1,553 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Message; | |||
import android.view.View; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.CompoundButton; | |||
import android.widget.EditText; | |||
import android.widget.ListView; | |||
import android.widget.RadioButton; | |||
import android.widget.Toast; | |||
import com.pingwang.bluetoothlib.bean.BleValueBean; | |||
import com.pingwang.bluetoothlib.config.BleDeviceConfig; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import java.lang.ref.WeakReference; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import androidx.annotation.Nullable; | |||
import cn.net.aicare.modulelibrary.module.BodyFatScale.AppHistoryRecordBean; | |||
import cn.net.aicare.modulelibrary.module.BodyFatScale.BodyFatBleUtilsData; | |||
import cn.net.aicare.modulelibrary.module.BodyFatScale.BodyFatDataUtil; | |||
import cn.net.aicare.modulelibrary.module.BodyFatScale.BodyFatRecord; | |||
import cn.net.aicare.modulelibrary.module.BodyFatScale.McuHistoryRecordBean; | |||
public class WeightScaleWifiBle extends BleBaseActivity implements View.OnClickListener, OnCallbackBle, BodyFatBleUtilsData.BleBodyFatCallback, BodyFatBleUtilsData.BleBodyFatWiFiCallback { | |||
private String TAG = WeightScaleWifiBle.class.getName(); | |||
private String mAddress; | |||
private List<String> mList; | |||
private ArrayAdapter listAdapter; | |||
// private Button wifiStatus_btn; | |||
private BodyFatBleUtilsData bodyFatBleUtilsData; | |||
private MHandler mMHandler; | |||
private EditText mEditText; | |||
private RadioButton kg,jing,stlb,lb; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_weight_scale_wifi_ble); | |||
findViewById(R.id.wifistatus).setOnClickListener(this); | |||
findViewById(R.id.sn).setOnClickListener(this); | |||
findViewById(R.id.scan_wifi).setOnClickListener(this); | |||
findViewById(R.id.connect_wifi).setOnClickListener(this); | |||
findViewById(R.id.disconnect).setOnClickListener(this); | |||
findViewById(R.id.setedname).setOnClickListener(this); | |||
findViewById(R.id.setedpaw).setOnClickListener(this); | |||
findViewById(R.id.setedmac).setOnClickListener(this); | |||
mEditText = findViewById(R.id.select_wifi_et); | |||
kg=findViewById(R.id.kg); | |||
jing=findViewById(R.id.jin); | |||
stlb=findViewById(R.id.st_lb); | |||
lb=findViewById(R.id.lb); | |||
kg.setChecked(true); | |||
mAddress = getIntent().getStringExtra("mac"); | |||
mList = new ArrayList<>(); | |||
ListView listView = findViewById(R.id.log_list); | |||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | |||
listView.setAdapter(listAdapter); | |||
WeakReference weakReference = new WeakReference(new MHandler()); | |||
mMHandler = (MHandler) weakReference.get(); | |||
kg.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked){ | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil | |||
.getInstance().setWeightUnit(0, BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_WIFI_BLE)); | |||
} | |||
} | |||
}); | |||
jing.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked){ | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil | |||
.getInstance().setWeightUnit(1, BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_WIFI_BLE)); | |||
} | |||
} | |||
}); | |||
stlb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked){ | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil | |||
.getInstance().setWeightUnit(4, BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_WIFI_BLE)); | |||
} | |||
} | |||
}); | |||
lb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked){ | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil | |||
.getInstance().setWeightUnit(6, BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_WIFI_BLE)); | |||
} | |||
} | |||
}); | |||
} | |||
@Override | |||
public void onServiceSuccess() { | |||
BleLog.i(TAG, "服务与界面建立连接成功"); | |||
//与服务建立连接 | |||
if (mBluetoothService != null) { | |||
mBluetoothService.setOnCallback(this); | |||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | |||
if (bleDevice != null) { | |||
BodyFatBleUtilsData.init(bleDevice, this, this); | |||
bodyFatBleUtilsData = BodyFatBleUtilsData.getInstance(); | |||
} | |||
} | |||
} | |||
@Override | |||
public void onServiceErr() { | |||
} | |||
@Override | |||
public void unbindServices() { | |||
} | |||
@Override | |||
public void onStartScan() { | |||
} | |||
@Override | |||
public void onScanning(BleValueBean data) { | |||
} | |||
@Override | |||
public void onScanTimeOut() { | |||
} | |||
@Override | |||
public void onConnecting(String mac) { | |||
} | |||
@Override | |||
public void onDisConnected(String mac, int code) { | |||
} | |||
@Override | |||
public void onServicesDiscovered(String mac) { | |||
} | |||
@Override | |||
public void bleOpen() { | |||
} | |||
@Override | |||
public void bleClose() { | |||
} | |||
@Override | |||
public void onWeightData(int status, float weight, int weightUnit, int decimals) { | |||
mList.add(0, "体重数据类型:" + status + " 体重: " + weight + " 单位:" + weightUnit + " 小数点位: " + decimals); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onStatus(int status) { | |||
switch (status){ | |||
case BodyFatDataUtil.WEIGHT_TESTING: | |||
mList.add(0, "测量状态:" + status+" 测量实时体重"); | |||
break; | |||
case BodyFatDataUtil.WEIGHT_RESULT: | |||
mList.add(0, "测量状态:" + status+" 稳定体重"); | |||
break; | |||
case BodyFatDataUtil.IMPEDANCE_TESTING: | |||
mList.add(0, "测量状态:" + status+" 阻抗测量中"); | |||
break; | |||
case BodyFatDataUtil.IMPEDANCE_SUCCESS_DATA: | |||
case BodyFatDataUtil.IMPEDANCE_SUCCESS: | |||
mList.add(0, "测量状态:" + status+" 阻抗测量成功"); | |||
break; | |||
case BodyFatDataUtil.IMPEDANCE_FAIL: | |||
mList.add(0, "测量状态:" + status+" 阻抗测量失败"); | |||
break; | |||
case BodyFatDataUtil.HEART_TESTING: | |||
mList.add(0, "测量状态:" + status+" 心率测量中"); | |||
break; | |||
case BodyFatDataUtil.HEART_SUCCESS: | |||
mList.add(0, "测量状态:" + status+" 心率测量成功"); | |||
break; | |||
case BodyFatDataUtil.HEART_FAIL: | |||
mList.add(0, "测量状态:" + status+" 心率测量失败"); | |||
break; | |||
case BodyFatDataUtil.TEST_FINISH: | |||
mList.add(0, "测量状态:" + status+" 测量完成"); | |||
break; | |||
case BodyFatDataUtil.MUC_REQUEST_USER_INFO: | |||
mList.add(0,"测量状态:" + status+"请求用户信息"); | |||
break; | |||
default: | |||
mList.add(0, "测量状态:" + status); | |||
} | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onAdc(int adc, int algorithmic) { | |||
mList.add(0, "阻抗:" + adc + " 算法位:" + algorithmic); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onHeartRate(int heartrate) { | |||
mList.add(0, "心率:" + heartrate); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onBodyFat(BodyFatRecord bodyFatRecord) { | |||
mList.add(0, "体脂数:" + bodyFatRecord.toString()); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onError(int code) { | |||
mList.add(0, "历史记录Mcu:" + code); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onHistoryMcu(McuHistoryRecordBean mcuHistoryRecordBean) { | |||
mList.add(0, "历史记录Mcu:" + mcuHistoryRecordBean.toString()); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onHistoryApp(AppHistoryRecordBean appHistoryRecordBean) { | |||
mList.add(0, "历史记录app:" + appHistoryRecordBean.toString()); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onVersion(String version) { | |||
mList.add(0, "版本号:" + version); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onMcuBatteryStatus(int status, int battery) { | |||
mList.add(0,"电量状态"+status+" 电量:"+battery); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onSysTime(int status, int[] times) { | |||
mList.add(0,"时间状态"+status); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void requestSynTime() { | |||
mList.add(0,"请求同步时间"); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void setTimeCallback(int type, int status) { | |||
mList.add(0,"设置时间回调"); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void requestSynHistoryCallback(int status) { | |||
if (status==0) { | |||
mList.add(0, "" + status+" 无历史记录"); | |||
}else if (status==1){ | |||
mList.add(0, "请求历史记录" + status+" 开始发送历史记录"); | |||
}else { | |||
mList.add(0, "请求历史记录" + status+" 发送历史记录结束"); | |||
} | |||
} | |||
@Override | |||
public void updateUserCallback(int status) { | |||
if (status==0) { | |||
mList.add(0, "更新用户或列表回调" + status+" 更新列表成功"); | |||
}else if (status==1){ | |||
mList.add(0, "更新用户或列表回调" + status+" 更新个人用户成功"); | |||
}else if (status==2){ | |||
mList.add(0, "更新用户或列表回调" + status+" 更新列表失败"); | |||
}else { | |||
mList.add(0, "更新用户或列表回调" + status+" 更新个人用户失败"); | |||
} | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void setUnitCallback(int status) { | |||
if (status==0) { | |||
mList.add(0, "下发单位回调" + status + " 成功"); | |||
}else if (status==1){ | |||
mList.add(0, "下发单位回调" + status + " 失败"); | |||
}else { | |||
mList.add(0, "下发单位回调" + status + " 不支持"); | |||
} | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void requestUserData(int status) { | |||
if (status==0x01){ | |||
mList.add(0,"下发用户信息 "+status); | |||
}else if (status==0x03){ | |||
mList.add(0,"下发用户信息成功 "+status); | |||
}else { | |||
mList.add(0,"下发用户信息失败 "+status); | |||
} | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void OnBleAndWifiStatus(int blestatus, int wifistatus, int workstatus) { | |||
BleLog.e(TAG, "蓝牙状态:" + blestatus + " wifi状态:" + " 工作状态:" + workstatus); | |||
mList.add(0, "蓝牙状态:" + blestatus + " wifi状态:" + wifistatus + " 工作状态:" + workstatus); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void OnWifiScanStatus(int Status) { | |||
mList.add(0, "扫描wifi状态: " + Status); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
private HashMap<Integer, String> mHashMap = new HashMap(); | |||
@Override | |||
public void OnWifiListName(int no, String name) { | |||
// mList.add(0,"WIFI序号: "+no+" WIFI名称: "+name); | |||
mHashMap.put(no, name); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
private HashMap<Integer, String> wifimacMap = new HashMap(); | |||
@Override | |||
public void OnWifiListInfo(int no, String mac, int db, int type, int wifistatus) { | |||
wifimacMap.put(no, mac); | |||
mList.add(0, "WIFI序号: " + no + " WIFI名称:" + mHashMap.get(no) + " WIFImac: " + mac + " db: " + db + " type: " + type + " wifistata" + wifistatus); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void OnWifiCurrentConnect(String name) { | |||
mList.add(0, "当前连接wifi名称: " + name); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void OnWifiScanFinish(int wifiNum) { | |||
mList.add(0, "扫描结束 扫描的wifi个数 " + wifiNum); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
private boolean issetMac=false; | |||
@Override | |||
public void OnSetWifiNameOrPwdOrConnectCallback(int type, int status) { | |||
if (type== BodyFatDataUtil.SET_WIFI_MAC){ | |||
mList.add(0, "获取到设置的mac地址状态 " +status); | |||
if (status== BodyFatDataUtil.STATUS_SUCCESS)issetMac=true; | |||
// bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().getSelectWifiMac()); | |||
} | |||
if (type== BodyFatDataUtil.SET_WIFI_PAW){ | |||
mList.add(0, "获取到设置的密码状态 " +status); | |||
// bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().getSelectWifiPwd()); | |||
if (issetMac)mMHandler.sendEmptyMessage(ConnectWifi); | |||
} | |||
if (type== BodyFatDataUtil.DIS_OR_CON_WIFI){ | |||
mList.add(0, "发起连接 " +status); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
} | |||
@Override | |||
public void getSelectWifiMac(String mac) { | |||
mList.add(0, "获取到设置的wifi的mac地址 " + mac); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void getSelectWifiPaw(String paw) { | |||
mList.add(0, "获取到设置的wifi的密码 " + paw); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void getDid(long did) { | |||
mList.add(0, "did: " + did); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
int id = v.getId(); | |||
switch (id) { | |||
case R.id.wifistatus: | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().queryBleStatus()); | |||
break; | |||
case R.id.sn: | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().getSnDeviceDid()); | |||
break; | |||
case R.id.scan_wifi: | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().scanWifi()); | |||
break; | |||
case R.id.connect_wifi: | |||
try { | |||
int selectWifi = Integer.valueOf(mEditText.getText().toString().trim()); | |||
WifiDialog.newInstance().setTitle(mHashMap.get(selectWifi),wifimacMap.get(selectWifi)).setOnDialogListener(new WifiDialog.OnDialogListener() { | |||
@Override | |||
public void tvCancelListener(View v) { | |||
} | |||
@Override | |||
public void tvSucceedListener(View v, String data) { | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().setWifiMac(wifimacMap.get(selectWifi))); | |||
if (data.equals("") || data.length() > 8) { | |||
setPaw(data); | |||
} else { | |||
Toast.makeText(WeightScaleWifiBle.this, "密码格式不对", Toast.LENGTH_SHORT).show(); | |||
} | |||
} | |||
@Override | |||
public void etModifyName(EditText v) { | |||
} | |||
}).show(getSupportFragmentManager()); | |||
} catch (NumberFormatException e) { | |||
e.printStackTrace(); | |||
mMHandler.sendEmptyMessage(ConnectWifi); | |||
} | |||
break; | |||
case R.id.setedmac: | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().getSelectWifiMac()); | |||
break; | |||
case R.id.setedpaw: | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().getSelectWifiPwd()); | |||
break; | |||
case R.id.setedname: | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().getConnectWifiName()); | |||
break; | |||
case R.id.disconnect: | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().disconnectWifi()); | |||
break; | |||
} | |||
} | |||
private final int ToRefreUi = 300; | |||
private final int ConnectWifi=400; | |||
private class MHandler extends Handler { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
super.handleMessage(msg); | |||
switch (msg.what) { | |||
case ToRefreUi: | |||
if (listAdapter != null) { | |||
listAdapter.notifyDataSetChanged(); | |||
} | |||
break; | |||
case ConnectWifi: | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().connectWifi()); | |||
break; | |||
} | |||
} | |||
} | |||
private void setPaw(String paw) { | |||
if (paw.isEmpty()) { | |||
byte[] bytes = new byte[0]; | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().setWifiPwd(0, bytes)); | |||
} else { | |||
byte[] password = BleStrUtils.stringToBytes(paw); | |||
if (password != null) { | |||
if (password.length < 14) | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().setWifiPwd(0, password)); | |||
else { | |||
boolean isend = false; | |||
int i = 0; | |||
byte[] byte1 = password; | |||
while (!isend) { | |||
if (byte1.length > 14) { | |||
byte[] bytes = new byte[14]; | |||
System.arraycopy(password, i, bytes, 0, bytes.length); | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().setWifiPwd(1, bytes)); | |||
i = i + 14; | |||
byte1 = Arrays.copyOf(password, password.length - i); | |||
} else { | |||
isend = true; | |||
byte[] bytes = new byte[password.length - i]; | |||
System.arraycopy(password, i, bytes, 0, bytes.length); | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().setWifiPwd(0, bytes)); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,218 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.app.Dialog; | |||
import android.content.Context; | |||
import android.content.DialogInterface; | |||
import android.content.Intent; | |||
import android.os.Bundle; | |||
import android.view.KeyEvent; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import android.widget.EditText; | |||
import android.widget.TextView; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import androidx.fragment.app.DialogFragment; | |||
import androidx.fragment.app.FragmentManager; | |||
public class WifiDialog extends DialogFragment implements View.OnClickListener { | |||
/** | |||
* 是否显示 | |||
*/ | |||
private EditText mEtName; | |||
private TextView mTvCancel, mTvSucceed, mTvTitle, mTvTitleHint; | |||
private boolean mShow; | |||
private boolean mCancelBlank; | |||
private Context mContext; | |||
private CharSequence mTitle = ""; | |||
private CharSequence mTitleHint; | |||
private CharSequence mContent = ""; | |||
private CharSequence mContentHint = ""; | |||
private CharSequence mCancel = ""; | |||
private OnDialogListener mOnDialogListener; | |||
public static WifiDialog newInstance() { | |||
return new WifiDialog(); | |||
} | |||
@NonNull | |||
@Override | |||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { | |||
Dialog dialogView = new Dialog(requireContext(), R.style.MyDialog);// 创建自定义样式dialog | |||
dialogView.setCancelable(false);//设置是否可以关闭 | |||
dialogView.setCanceledOnTouchOutside(mCancelBlank);//设置点击空白处是否可以取消 | |||
dialogView.setOnKeyListener((dialog, keyCode, event) -> { | |||
if (mCancelBlank) { | |||
return false; | |||
} else { | |||
//返回不关闭 | |||
return keyCode == KeyEvent.KEYCODE_BACK; | |||
} | |||
}); | |||
return dialogView; | |||
// return super.onCreateDialog(savedInstanceState); | |||
} | |||
@Nullable | |||
@Override | |||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |||
return inflater.inflate(R.layout.dialog_move_data, container); | |||
} | |||
@Override | |||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { | |||
super.onViewCreated(view, savedInstanceState); | |||
mContext = view.getContext(); | |||
init(view); | |||
initData(mTitle, mTitleHint); | |||
} | |||
@Override | |||
public void onActivityResult(int requestCode, int resultCode, Intent data) { | |||
super.onActivityResult(requestCode, resultCode, data); | |||
} | |||
private void init(View view) { | |||
mEtName = view.findViewById(R.id.et_move_data_context); | |||
mTvCancel = view.findViewById(R.id.tv_move_data_cancel); | |||
mTvSucceed = view.findViewById(R.id.tv_move_data_ok); | |||
mTvTitle = view.findViewById(R.id.tv_move_data_title); | |||
mTvTitleHint = view.findViewById(R.id.tv_move_data_title_hint); | |||
mTvCancel.setOnClickListener(this); | |||
mTvSucceed.setOnClickListener(this); | |||
} | |||
private void initData(CharSequence title, CharSequence titleHint) { | |||
setTitle(title, titleHint); | |||
setCancel(""); | |||
setOk(""); | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
int i = v.getId(); | |||
if (i == R.id.tv_move_data_cancel) { | |||
if (mOnDialogListener != null) | |||
mOnDialogListener.tvCancelListener(v); | |||
dismiss(); | |||
} else if (i == R.id.tv_move_data_ok) { | |||
if (mOnDialogListener != null) { | |||
String data = mEtName.getText().toString().trim(); | |||
mOnDialogListener.tvSucceedListener(v, data); | |||
} | |||
dismiss(); | |||
} | |||
} | |||
public WifiDialog setTitle(CharSequence title, CharSequence titleHint) { | |||
this.mTitle=title; | |||
this.mTitleHint=titleHint; | |||
if (mTvTitle != null && !title.equals("")) | |||
mTvTitle.setText(title); | |||
if (mTvTitleHint != null && !titleHint.equals("")) | |||
mTvTitleHint.setText(titleHint); | |||
return this; | |||
} | |||
public WifiDialog setCancel(CharSequence name) { | |||
if (mTvCancel != null && !name.equals("")) | |||
mTvCancel.setText(name); | |||
return this; | |||
} | |||
public WifiDialog setOk(CharSequence name){ | |||
if (mTvSucceed != null && !name.equals("")) | |||
mTvSucceed.setText(name); | |||
return this; | |||
} | |||
public WifiDialog setOnDialogListener(OnDialogListener onDialogListener) { | |||
mOnDialogListener = onDialogListener; | |||
return this; | |||
} | |||
/** | |||
* 当前是否显示 | |||
*/ | |||
public boolean isShow() { | |||
return mShow; | |||
} | |||
@Override | |||
public void show(@NonNull FragmentManager manager, @Nullable String tag) { | |||
try { | |||
if (!mShow) { | |||
super.show(manager, tag); | |||
mShow = true; | |||
} | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
public void show(@NonNull FragmentManager manager) { | |||
this.show(manager, "DialogFragment"); | |||
} | |||
@Override | |||
public void onDismiss(@NonNull DialogInterface dialog) { | |||
super.onDismiss(dialog); | |||
mShow = false; | |||
} | |||
@Override | |||
public void dismiss() { | |||
try { | |||
mShow = false; | |||
super.dismiss(); | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
public interface OnDialogListener { | |||
/** | |||
* 取消的点击事件 | |||
*/ | |||
default void tvCancelListener(View v) { | |||
} | |||
/** | |||
* 成功的点击事件 | |||
*/ | |||
default void tvSucceedListener(View v, String data) { | |||
} | |||
/** | |||
* 修改名称的控件 | |||
*/ | |||
default void etModifyName(EditText v) { | |||
} | |||
} | |||
@Override | |||
public void onDestroyView() { | |||
super.onDestroyView(); | |||
mShow = false; | |||
} | |||
} |
@@ -0,0 +1,34 @@ | |||
<vector xmlns:aapt="http://schemas.android.com/aapt" | |||
xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:width="108dp" | |||
android:height="108dp" | |||
android:viewportHeight="108" | |||
android:viewportWidth="108"> | |||
<path | |||
android:fillType="evenOdd" | |||
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z" | |||
android:strokeColor="#00000000" | |||
android:strokeWidth="1"> | |||
<aapt:attr name="android:fillColor"> | |||
<gradient | |||
android:endX="78.5885" | |||
android:endY="90.9159" | |||
android:startX="48.7653" | |||
android:startY="61.0927" | |||
android:type="linear"> | |||
<item | |||
android:color="#44000000" | |||
android:offset="0.0"/> | |||
<item | |||
android:color="#00000000" | |||
android:offset="1.0"/> | |||
</gradient> | |||
</aapt:attr> | |||
</path> | |||
<path | |||
android:fillColor="#FFFFFF" | |||
android:fillType="nonZero" | |||
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z" | |||
android:strokeColor="#00000000" | |||
android:strokeWidth="1"/> | |||
</vector> |
@@ -0,0 +1,7 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |||
<item android:state_checked="true" android:drawable="@mipmap/choose_room_on"/> | |||
<item android:state_checked="false" android:drawable="@mipmap/choose_room"/> | |||
</selector> |
@@ -0,0 +1,6 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:drawable="@drawable/dialog_loading_img" | |||
android:pivotX="50%" | |||
android:pivotY="50%" /> | |||
@@ -0,0 +1,171 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<vector | |||
xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:width="108dp" | |||
android:height="108dp" | |||
android:viewportHeight="108" | |||
android:viewportWidth="108"> | |||
<path | |||
android:fillColor="#008577" | |||
android:pathData="M0,0h108v108h-108z"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M9,0L9,108" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M19,0L19,108" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M29,0L29,108" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M39,0L39,108" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M49,0L49,108" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M59,0L59,108" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M69,0L69,108" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M79,0L79,108" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M89,0L89,108" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M99,0L99,108" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M0,9L108,9" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M0,19L108,19" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M0,29L108,29" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M0,39L108,39" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M0,49L108,49" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M0,59L108,59" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M0,69L108,69" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M0,79L108,79" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M0,89L108,89" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M0,99L108,99" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M19,29L89,29" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M19,39L89,39" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M19,49L89,49" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M19,59L89,59" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M19,69L89,69" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M19,79L89,79" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M29,19L29,89" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M39,19L39,89" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M49,19L49,89" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M59,19L59,89" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M69,19L69,89" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
<path | |||
android:fillColor="#00000000" | |||
android:pathData="M79,19L79,89" | |||
android:strokeColor="#33FFFFFF" | |||
android:strokeWidth="0.8"/> | |||
</vector> |
@@ -0,0 +1,267 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical"> | |||
<ScrollView | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="vertical" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/user" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="用户" | |||
android:textAllCaps="false" | |||
/> | |||
<Button | |||
android:id="@+id/btnVersion" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="版本号" | |||
android:textAllCaps="false" | |||
/> | |||
<Button | |||
android:id="@+id/btnDis" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="断开" | |||
android:textAllCaps="false" | |||
/> | |||
<Button | |||
android:id="@+id/btnConnect" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="连接" | |||
android:textAllCaps="false" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_marginTop="6dp" | |||
android:orientation="horizontal" | |||
android:paddingEnd="12dp" | |||
android:paddingStart="24dp"> | |||
<TextView | |||
android:id="@+id/user_id_tv" | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:textSize="16sp"/> | |||
<TextView | |||
android:id="@+id/user_sex_tv" | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:textSize="16sp"/> | |||
<TextView | |||
android:id="@+id/user_age_tv" | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:textSize="16sp"/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
android:paddingEnd="12dp" | |||
android:paddingStart="24dp"> | |||
<TextView | |||
android:id="@+id/user_height_tv" | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:textSize="16sp"/> | |||
<TextView | |||
android:id="@+id/user_weight_tv" | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:textSize="16sp"/> | |||
<TextView | |||
android:id="@+id/user_adc_tv" | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:textSize="16sp"/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:gravity="center_vertical" | |||
android:padding="10dp"> | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Weight:" | |||
/> | |||
<RadioGroup | |||
android:id="@+id/radio_weight" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
> | |||
<RadioButton | |||
android:id="@+id/radio_weight_kg" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:checked="true" | |||
android:text="kg" | |||
/> | |||
<RadioButton | |||
android:id="@+id/radio_weight_lb_lb" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="lb" | |||
/> | |||
<RadioButton | |||
android:id="@+id/radio_weight_st_lb" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="st:lb" | |||
/> | |||
<RadioButton | |||
android:id="@+id/radio_weight_jin" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="jin" | |||
/> | |||
</RadioGroup> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/getRecord" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="读取记录" | |||
android:textAllCaps="false" | |||
/> | |||
<Button | |||
android:id="@+id/synUserAll" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="同步所有用户" | |||
android:textAllCaps="false" | |||
/> | |||
<Button | |||
android:id="@+id/synUser" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="同步当前用户" | |||
android:textAllCaps="false" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/Undressing" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="去衣模式" | |||
android:textAllCaps="false" | |||
/> | |||
<Button | |||
android:id="@+id/Impedance" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="阻抗识别用户" | |||
android:textAllCaps="false" | |||
/> | |||
<Button | |||
android:id="@+id/synTime" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="同步时间" | |||
android:textAllCaps="false" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/clear" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="@string/clear" | |||
android:textAllCaps="false" | |||
/> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</ScrollView> | |||
<ListView | |||
android:id="@+id/listview" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
android:padding="10dp" | |||
android:stackFromBottom="true" | |||
android:transcriptMode="alwaysScroll" | |||
> | |||
</ListView> | |||
</LinearLayout> |
@@ -0,0 +1,48 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical"> | |||
<FrameLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="50dp" | |||
android:background="@color/colorPrimary"> | |||
<ImageButton | |||
android:id="@+id/back_btn" | |||
android:layout_width="50dp" | |||
android:layout_height="match_parent" | |||
android:background="@android:color/transparent" | |||
android:src="@mipmap/back_white"/> | |||
<TextView | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:gravity="center" | |||
android:text="User List" | |||
android:textColor="@android:color/white" | |||
android:textSize="16sp"/> | |||
</FrameLayout> | |||
<ListView | |||
android:id="@+id/listView" | |||
android:layout_width="match_parent" | |||
android:overScrollMode="never" | |||
android:scrollbars="vertical" | |||
android:layout_height="0dp" | |||
android:layout_weight="1"/> | |||
<Button android:id="@+id/add_user_btn" | |||
android:layout_width="match_parent" | |||
android:layout_height="50dp" | |||
android:background="@android:color/white" | |||
android:textColor="@color/colorPrimary" | |||
android:textSize="18sp" | |||
android:text="Add User" | |||
android:textAllCaps="false"/> | |||
</LinearLayout> |
@@ -0,0 +1,208 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical"> | |||
<ScrollView | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="vertical" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/clear" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="clear" | |||
/> | |||
<Button | |||
android:id="@+id/getUnit" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="getUnit" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/btn_get_did" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="CVPID" | |||
/> | |||
<Button | |||
android:id="@+id/btnBattery" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Battery" | |||
/> | |||
<Button | |||
android:id="@+id/btn_set_tare" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Tare" | |||
/> | |||
<Button | |||
android:id="@+id/btn_set_hold" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Hold" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:gravity="center_vertical" | |||
android:padding="10dp"> | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Weight:" | |||
/> | |||
<RadioGroup | |||
android:id="@+id/radio_weight" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
> | |||
<RadioButton | |||
android:id="@+id/radio_weight_kg" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:checked="true" | |||
android:text="kg" | |||
/> | |||
<RadioButton | |||
android:id="@+id/radio_weight_lb" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="lb:oz" | |||
/> | |||
<RadioButton | |||
android:id="@+id/radio_weight_oz" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="oz" | |||
/> | |||
<RadioButton | |||
android:id="@+id/radio_weight_g" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="g" | |||
/> | |||
<RadioButton | |||
android:id="@+id/radio_weight_lb_lb" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="lb" | |||
/> | |||
</RadioGroup> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:gravity="center_vertical" | |||
android:padding="10dp"> | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Height:" | |||
/> | |||
<RadioGroup | |||
android:id="@+id/radio_height" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
> | |||
<RadioButton | |||
android:id="@+id/radio_height_cm" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:checked="true" | |||
android:text="cm" | |||
/> | |||
<RadioButton | |||
android:id="@+id/radio_height_foot" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="foot" | |||
/> | |||
</RadioGroup> | |||
<Button | |||
android:id="@+id/btn_set_unit" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_marginStart="10dp" | |||
android:text="set_unit" | |||
/> | |||
<Button | |||
android:id="@+id/btnVersion" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="version" | |||
android:layout_marginStart="10dp" | |||
/> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</ScrollView> | |||
<ListView | |||
android:id="@+id/listview" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
android:padding="10dp" | |||
android:stackFromBottom="true" | |||
android:transcriptMode="alwaysScroll" | |||
> | |||
</ListView> | |||
</LinearLayout> |
@@ -0,0 +1,271 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical" | |||
android:focusable="true" | |||
android:focusableInTouchMode="true" | |||
> | |||
<ScrollView | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="vertical" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
> | |||
<Button | |||
android:id="@+id/btnClear" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="@string/clear" | |||
/> | |||
<Button | |||
android:id="@+id/btnHandshake" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="@string/handshake" | |||
/> | |||
<Button | |||
android:id="@+id/btnVersion" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="读版本" | |||
/> | |||
<Button | |||
android:id="@+id/btnBattery" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="读电量" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
android:padding="5dp" | |||
> | |||
<Button | |||
android:id="@+id/btnTimeRead" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="读时间" | |||
/> | |||
<Button | |||
android:id="@+id/btnTimeWrite" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="写时间" | |||
/> | |||
<Button | |||
android:id="@+id/btnMacRead" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="读mac" | |||
/> | |||
<Button | |||
android:id="@+id/btnBmRestart" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="重启模块" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
android:padding="5dp" | |||
> | |||
<EditText | |||
android:id="@+id/etMcuType" | |||
android:layout_width="100dp" | |||
android:layout_height="wrap_content" | |||
android:hint="串口,i2c,spi" | |||
android:text="1" | |||
/> | |||
<Button | |||
android:id="@+id/btnMcuType" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="设置模式" | |||
/> | |||
<Button | |||
android:id="@+id/btnBmReset" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="出厂设置" | |||
/> | |||
<Button | |||
android:id="@+id/btnUnits" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="读单位" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
android:padding="5dp" | |||
> | |||
<EditText | |||
android:id="@+id/etDid" | |||
android:layout_width="200dp" | |||
android:layout_height="wrap_content" | |||
android:hint="cidS,vidS,pidS,cid,vid,pid" | |||
android:text="1,1,1,1,2,3" | |||
/> | |||
<Button | |||
android:id="@+id/btnDidWrite" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="写DID" | |||
/> | |||
<Button | |||
android:id="@+id/btnDidRead" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="读DID" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
android:padding="5dp" | |||
> | |||
<EditText | |||
android:id="@+id/etName" | |||
android:layout_width="100dp" | |||
android:layout_height="wrap_content" | |||
android:maxLength="13" | |||
/> | |||
<Button | |||
android:id="@+id/btnNameWrite" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="写名称" | |||
/> | |||
<Button | |||
android:id="@+id/btnNameRead" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="读名称" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
android:padding="5dp" | |||
> | |||
<EditText | |||
android:id="@+id/etMacType" | |||
android:layout_width="100dp" | |||
android:layout_height="wrap_content" | |||
android:maxLength="1" | |||
android:digits="0987654321" | |||
/> | |||
<Button | |||
android:id="@+id/btnMacTypeWrite" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="写Mac大小端" | |||
/> | |||
<Button | |||
android:id="@+id/btnMacTypeRead" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="读Mac大小端" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
android:padding="5dp" | |||
> | |||
<EditText | |||
android:id="@+id/etBroadcastTime" | |||
android:layout_width="100dp" | |||
android:layout_height="wrap_content" | |||
android:digits="0987654321" | |||
/> | |||
<Button | |||
android:id="@+id/btnBroadcastTimeWrite" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="写广播间隔" | |||
/> | |||
<Button | |||
android:id="@+id/btnBroadcastTimeRead" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="读广播间隔" | |||
/> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</ScrollView> | |||
<ListView | |||
android:id="@+id/listview" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
android:padding="10dp" | |||
android:stackFromBottom="true" | |||
android:transcriptMode="alwaysScroll" | |||
> | |||
</ListView> | |||
</LinearLayout> |
@@ -0,0 +1,132 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:focusable="true" | |||
android:focusableInTouchMode="true" | |||
android:orientation="vertical" | |||
> | |||
<ScrollView | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="vertical" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<EditText | |||
android:id="@+id/et_type" | |||
android:layout_width="200dp" | |||
android:layout_height="wrap_content" | |||
android:hint="透传数据" | |||
android:text="4" | |||
/> | |||
<Button | |||
android:id="@+id/btn1" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="发送" | |||
/> | |||
<Button | |||
android:id="@+id/clear" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="清空" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<EditText | |||
android:id="@+id/et_unit_weight" | |||
android:layout_width="100dp" | |||
android:layout_height="wrap_content" | |||
android:digits="0123456789" | |||
android:hint="weight" | |||
android:maxLength="1" | |||
android:text="0" | |||
/> | |||
<EditText | |||
android:id="@+id/et_unit_height" | |||
android:layout_width="100dp" | |||
android:layout_height="wrap_content" | |||
android:digits="0123456789" | |||
android:hint="height" | |||
android:maxLength="1" | |||
android:text="0" | |||
/> | |||
<Button | |||
android:id="@+id/btn_set_unit" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="set_unit" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/btn_get_did" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="get_did" | |||
/> | |||
<Button | |||
android:id="@+id/btnVersion" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="version" | |||
/> | |||
<Button | |||
android:id="@+id/btnBattery" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Battery" | |||
/> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</ScrollView> | |||
<ListView | |||
android:id="@+id/listview" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="2" | |||
android:padding="10dp" | |||
android:stackFromBottom="true" | |||
android:transcriptMode="alwaysScroll" | |||
> | |||
</ListView> | |||
</LinearLayout> |
@@ -0,0 +1,106 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout | |||
xmlns:android="http://schemas.android.com/apk/res/android" | |||
xmlns:app="http://schemas.android.com/apk/res-auto" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical" | |||
> | |||
<TextView | |||
android:id="@+id/tv_app_version" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:text="@string/version" | |||
android:padding="10dp" | |||
/> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_margin="10dp" | |||
> | |||
<Button | |||
android:id="@+id/btn_sphy" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="血压计" | |||
/> | |||
<Button | |||
android:id="@+id/btn_tempgun" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="额温枪" | |||
/> | |||
<Button | |||
android:id="@+id/btn_temp" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="体温计" | |||
/> | |||
<Button | |||
android:id="@+id/btn_baby" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="婴儿秤" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_margin="10dp" | |||
> | |||
<Button | |||
android:id="@+id/btn_height" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="身高仪" | |||
/> | |||
<Button | |||
android:id="@+id/btn_ad_weight" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="艾迪体脂秤" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_margin="10dp" | |||
android:layout_height="wrap_content"> | |||
<Button | |||
android:id="@+id/btn_wifi_ble_weight" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="WiFi+Ble体脂秤" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_margin="10dp" | |||
> | |||
<Button | |||
android:id="@+id/btn_ble" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Ble通用设置" | |||
/> | |||
</LinearLayout> | |||
</LinearLayout> |
@@ -0,0 +1,74 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:orientation="vertical" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:focusable="true" | |||
android:focusableInTouchMode="true" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/btn" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="搜索" | |||
/> | |||
<Button | |||
android:id="@+id/btn1" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="停止" | |||
/> | |||
<Button | |||
android:id="@+id/clear" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="清空" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/filter" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="过滤:true" | |||
/> | |||
<Button | |||
android:id="@+id/跳过" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="跳过" | |||
/> | |||
</LinearLayout> | |||
<ListView | |||
android:id="@+id/listview" | |||
android:layout_width="match_parent" | |||
android:padding="10dp" | |||
android:layout_height="match_parent" | |||
> | |||
</ListView> | |||
</LinearLayout> |
@@ -0,0 +1,123 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical" | |||
android:focusable="true" | |||
android:focusableInTouchMode="true" | |||
> | |||
<ScrollView | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="vertical" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<EditText | |||
android:id="@+id/et_type" | |||
android:layout_width="200dp" | |||
android:layout_height="wrap_content" | |||
android:hint="透传数据" | |||
android:text="4" | |||
/> | |||
<Button | |||
android:id="@+id/btn1" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="发送" | |||
/> | |||
<Button | |||
android:id="@+id/clear" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="清空" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/btn_set_unit" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="set_unit" | |||
/> | |||
<Button | |||
android:id="@+id/btn_start" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="start" | |||
/> | |||
<Button | |||
android:id="@+id/btn_stop" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="stop" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/btn_get_did" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="get_did" | |||
/> | |||
<Button | |||
android:id="@+id/btnVersion" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="version" | |||
/> | |||
<Button | |||
android:id="@+id/btnBattery" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Battery" | |||
/> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</ScrollView> | |||
<ListView | |||
android:id="@+id/listview" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="2" | |||
android:padding="10dp" | |||
android:stackFromBottom="true" | |||
android:transcriptMode="alwaysScroll" | |||
> | |||
</ListView> | |||
</LinearLayout> |
@@ -0,0 +1,87 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical" | |||
android:focusable="true" | |||
android:focusableInTouchMode="true" | |||
> | |||
<ScrollView | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="vertical" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<EditText | |||
android:id="@+id/et_type" | |||
android:layout_width="200dp" | |||
android:layout_height="wrap_content" | |||
android:hint="透传数据" | |||
android:text="4" | |||
/> | |||
<Button | |||
android:id="@+id/btn1" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="发送" | |||
/> | |||
<Button | |||
android:id="@+id/clear" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="清空" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/btn_get_did" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="get_did" | |||
/> | |||
<Button | |||
android:id="@+id/btn_set_unit" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="set_unit" | |||
/> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</ScrollView> | |||
<ListView | |||
android:id="@+id/listview" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="2.5" | |||
android:padding="10dp" | |||
android:stackFromBottom="true" | |||
android:transcriptMode="alwaysScroll" | |||
> | |||
</ListView> | |||
</LinearLayout> |
@@ -0,0 +1,104 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:focusable="true" | |||
android:focusableInTouchMode="true" | |||
android:orientation="vertical" | |||
> | |||
<ScrollView | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="vertical" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<EditText | |||
android:id="@+id/et_type" | |||
android:layout_width="200dp" | |||
android:layout_height="wrap_content" | |||
android:hint="透传数据" | |||
android:text="4" | |||
/> | |||
<Button | |||
android:id="@+id/btn1" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="发送" | |||
/> | |||
<Button | |||
android:id="@+id/clear" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="清空" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/btn_get_did" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="get_did" | |||
/> | |||
<Button | |||
android:id="@+id/btn_set_unit" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="set_unit" | |||
/> | |||
<Button | |||
android:id="@+id/btnVersion" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="version" | |||
/> | |||
<Button | |||
android:id="@+id/btnBattery" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Battery" | |||
/> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</ScrollView> | |||
<ListView | |||
android:id="@+id/listview" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="2" | |||
android:padding="10dp" | |||
android:stackFromBottom="true" | |||
android:transcriptMode="alwaysScroll" | |||
> | |||
</ListView> | |||
</LinearLayout> |
@@ -0,0 +1,132 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:focusable="true" | |||
android:focusableInTouchMode="true" | |||
android:orientation="vertical" | |||
> | |||
<ScrollView | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="vertical" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<EditText | |||
android:id="@+id/et_type" | |||
android:layout_width="200dp" | |||
android:layout_height="wrap_content" | |||
android:hint="透传数据" | |||
android:text="4" | |||
/> | |||
<Button | |||
android:id="@+id/btn1" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="发送" | |||
/> | |||
<Button | |||
android:id="@+id/clear" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="清空" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<EditText | |||
android:id="@+id/et_unit_weight" | |||
android:layout_width="100dp" | |||
android:layout_height="wrap_content" | |||
android:digits="0123456789" | |||
android:hint="weight" | |||
android:maxLength="1" | |||
android:text="0" | |||
/> | |||
<EditText | |||
android:id="@+id/et_unit_height" | |||
android:layout_width="100dp" | |||
android:layout_height="wrap_content" | |||
android:digits="0123456789" | |||
android:hint="height" | |||
android:maxLength="1" | |||
android:text="0" | |||
/> | |||
<Button | |||
android:id="@+id/btn_set_unit" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="set_unit" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/btn_get_did" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="get_did" | |||
/> | |||
<Button | |||
android:id="@+id/btnVersion" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="version" | |||
/> | |||
<Button | |||
android:id="@+id/btnBattery" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Battery" | |||
/> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</ScrollView> | |||
<ListView | |||
android:id="@+id/listview" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="2" | |||
android:padding="10dp" | |||
android:stackFromBottom="true" | |||
android:transcriptMode="alwaysScroll" | |||
> | |||
</ListView> | |||
</LinearLayout> |
@@ -0,0 +1,214 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical"> | |||
<ScrollView | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="vertical" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<EditText | |||
android:id="@+id/et_type" | |||
android:layout_width="200dp" | |||
android:layout_height="wrap_content" | |||
android:hint="透传数据" | |||
/> | |||
<Button | |||
android:id="@+id/btn1" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="发送" | |||
/> | |||
<Button | |||
android:id="@+id/clear" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="清空" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/btn_get_did" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="CVPID" | |||
/> | |||
<Button | |||
android:id="@+id/btnBattery" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Battery" | |||
/> | |||
<Button | |||
android:id="@+id/btn_set_tare" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Tare" | |||
/> | |||
<Button | |||
android:id="@+id/btn_set_hold" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Hold" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:gravity="center_vertical" | |||
android:padding="10dp"> | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Weight:" | |||
/> | |||
<RadioGroup | |||
android:id="@+id/radio_weight" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
> | |||
<RadioButton | |||
android:id="@+id/radio_weight_kg" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:checked="true" | |||
android:text="kg" | |||
/> | |||
<RadioButton | |||
android:id="@+id/radio_weight_lb" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="lb:oz" | |||
/> | |||
<RadioButton | |||
android:id="@+id/radio_weight_oz" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="oz" | |||
/> | |||
<RadioButton | |||
android:id="@+id/radio_weight_g" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="g" | |||
/> | |||
<RadioButton | |||
android:id="@+id/radio_weight_lb_lb" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="lb" | |||
/> | |||
</RadioGroup> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:gravity="center_vertical" | |||
android:padding="10dp"> | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Height:" | |||
/> | |||
<RadioGroup | |||
android:id="@+id/radio_height" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
> | |||
<RadioButton | |||
android:id="@+id/radio_height_cm" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:checked="true" | |||
android:text="cm" | |||
/> | |||
<RadioButton | |||
android:id="@+id/radio_height_foot" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="foot" | |||
/> | |||
</RadioGroup> | |||
<Button | |||
android:id="@+id/btn_set_unit" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_marginStart="10dp" | |||
android:text="set_unit" | |||
/> | |||
<Button | |||
android:id="@+id/btnVersion" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="version" | |||
android:layout_marginStart="10dp" | |||
/> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</ScrollView> | |||
<ListView | |||
android:id="@+id/listview" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
android:padding="10dp" | |||
android:stackFromBottom="true" | |||
android:transcriptMode="alwaysScroll" | |||
> | |||
</ListView> | |||
</LinearLayout> |
@@ -0,0 +1,129 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<RelativeLayout | |||
xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical"> | |||
<Button | |||
android:id="@+id/wifistatus" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="查看wifi状态" /> | |||
<Button | |||
android:id="@+id/scan_wifi" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_marginStart="12dp" | |||
android:layout_toEndOf="@+id/wifistatus" | |||
android:text="搜索wifi热点" /> | |||
<Button | |||
android:id="@+id/sn" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_below="@+id/scan_wifi" | |||
android:layout_marginTop="8dp" | |||
android:text="查看设备did号" /> | |||
<EditText | |||
android:id="@+id/select_wifi_et" | |||
android:layout_width="90dp" | |||
android:layout_height="wrap_content" | |||
android:layout_marginStart="22dp" | |||
android:layout_toEndOf="@+id/scan_wifi" | |||
android:hint="选择wifi序号" | |||
android:inputType="number" | |||
android:textSize="14dp" /> | |||
<Button | |||
android:id="@+id/connect_wifi" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_below="@+id/select_wifi_et" | |||
android:layout_marginStart="13dp" | |||
android:layout_marginTop="11dp" | |||
android:layout_toEndOf="@+id/disconnect" | |||
android:text="发起连接" /> | |||
<Button | |||
android:id="@+id/disconnect" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_below="@+id/scan_wifi" | |||
android:layout_marginStart="9dp" | |||
android:layout_marginTop="5dp" | |||
android:layout_toEndOf="@+id/sn" | |||
android:text="断开连接" /> | |||
<Button | |||
android:id="@+id/setedmac" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_below="@+id/sn" | |||
android:layout_marginStart="9dp" | |||
android:layout_marginTop="5dp" | |||
android:text="获取希望设置的MAC" /> | |||
<Button | |||
android:id="@+id/setedpaw" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_below="@+id/sn" | |||
android:layout_toEndOf="@id/setedmac" | |||
android:layout_marginStart="9dp" | |||
android:layout_marginTop="5dp" | |||
android:text="获取希望设置的密码" /> | |||
<Button | |||
android:id="@+id/setedname" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_below="@+id/setedmac" | |||
android:layout_marginStart="9dp" | |||
android:layout_marginTop="5dp" | |||
android:text="获取当前连接wifi名称" /> | |||
<RadioGroup | |||
android:id="@+id/unit" | |||
android:layout_below="@+id/setedname" | |||
android:layout_width="match_parent" | |||
android:orientation="horizontal" | |||
android:layout_height="wrap_content"> | |||
<RadioButton | |||
android:id="@+id/kg" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:text="kg"/> | |||
<RadioButton | |||
android:id="@+id/jin" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:text="斤"/> | |||
<RadioButton | |||
android:id="@+id/st_lb" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:text="st:lb"/> | |||
<RadioButton | |||
android:id="@+id/lb" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:text="lb"/> | |||
</RadioGroup> | |||
<ListView | |||
android:id="@+id/log_list" | |||
android:layout_marginTop="20dp" | |||
android:layout_below="@id/unit" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent"> | |||
</ListView> | |||
</RelativeLayout> |
@@ -0,0 +1,19 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout | |||
xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="200dp" | |||
android:layout_height="110dp" | |||
android:background="@drawable/bg_dialog_loading" | |||
android:gravity="center" | |||
android:orientation="vertical"> | |||
<ProgressBar | |||
android:id="@+id/progressBar1" | |||
android:layout_width="35dp" | |||
android:layout_height="35dp" | |||
android:layout_gravity="center_horizontal" | |||
android:indeterminateBehavior="repeat" | |||
android:indeterminateDrawable="@drawable/dialog_loading" | |||
android:indeterminateOnly="true"/> | |||
</LinearLayout> |
@@ -0,0 +1,87 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:background="#ffffff" | |||
android:orientation="vertical"> | |||
<TextView | |||
android:id="@+id/tv_move_data_title" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:gravity="center" | |||
android:padding="10dp" | |||
android:text="title" | |||
android:textColor="#000000" | |||
android:textSize="20dp" | |||
/> | |||
<TextView | |||
android:id="@+id/tv_move_data_title_hint" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_marginTop="10dp" | |||
android:gravity="center" | |||
android:padding="10dp" | |||
android:text="title_2" | |||
android:textColor="#000000" | |||
android:textSize="18dp" | |||
/> | |||
<EditText | |||
android:id="@+id/et_move_data_context" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_marginEnd="25dp" | |||
android:layout_marginStart="25dp" | |||
android:layout_marginTop="20dp" | |||
android:padding="8dp" | |||
android:singleLine="true" | |||
android:textColor="#000000" | |||
android:textSize="18dp" | |||
android:focusable="true" | |||
/> | |||
<TextView | |||
android:id="@+id/tv_move_data_ok" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_marginEnd="25dp" | |||
android:layout_marginStart="25dp" | |||
android:layout_marginTop="40dp" | |||
android:background="#2878ce" | |||
android:gravity="center" | |||
android:padding="10dp" | |||
android:text="确认" | |||
android:textColor="#ffffff" | |||
android:textSize="18dp" | |||
/> | |||
<TextView | |||
android:id="@+id/tv_move_data_cancel" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_marginEnd="25dp" | |||
android:layout_marginStart="25dp" | |||
android:layout_marginTop="10dp" | |||
android:gravity="center" | |||
android:padding="10dp" | |||
android:text="取消" | |||
android:textSize="15dp" | |||
/> | |||
<View | |||
android:layout_width="match_parent" | |||
android:layout_height="20dp"/> | |||
</LinearLayout> |
@@ -0,0 +1,181 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout | |||
xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="horizontal"> | |||
<LinearLayout | |||
android:layout_width="68dp" | |||
android:layout_height="wrap_content" | |||
android:layout_marginStart="12dp" | |||
android:orientation="vertical"> | |||
<TextView | |||
android:layout_width="80dp" | |||
android:layout_height="40dp" | |||
android:gravity="center_vertical" | |||
android:text="ID: " | |||
android:textSize="16sp" | |||
/> | |||
<TextView | |||
android:layout_width="80dp" | |||
android:layout_height="40dp" | |||
android:gravity="center_vertical" | |||
android:text="sex: " | |||
android:textSize="16sp" | |||
/> | |||
<TextView | |||
android:layout_width="80dp" | |||
android:layout_height="40dp" | |||
android:gravity="center_vertical" | |||
android:text="age: " | |||
android:textSize="16sp" | |||
/> | |||
<TextView | |||
android:layout_width="80dp" | |||
android:layout_height="40dp" | |||
android:gravity="center_vertical" | |||
android:text="height(cm): " | |||
android:textSize="12sp" | |||
/> | |||
<TextView | |||
android:layout_width="80dp" | |||
android:layout_height="40dp" | |||
android:gravity="center_vertical" | |||
android:text="weight(kg): " | |||
android:textSize="12sp" | |||
/> | |||
<TextView | |||
android:layout_width="80dp" | |||
android:layout_height="40dp" | |||
android:gravity="center_vertical" | |||
android:text="adc: " | |||
android:textSize="16sp" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:layout_marginEnd="12dp" | |||
android:layout_weight="1" | |||
android:orientation="vertical"> | |||
<CheckedTextView | |||
android:id="@+id/user_id_ctv" | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:checkMark="@drawable/checkbox_button" | |||
android:gravity="center_vertical" | |||
android:textSize="16sp"/> | |||
<RadioGroup | |||
android:id="@+id/sex_radioGroup" | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:gravity="center_vertical" | |||
android:orientation="horizontal"> | |||
<RadioButton | |||
android:id="@+id/man_radioButton" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_marginEnd="20dp" | |||
android:checked="true" | |||
android:text="Man"/> | |||
<RadioButton | |||
android:id="@+id/female_radioButton" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Female"/> | |||
</RadioGroup> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
> | |||
<LinearLayout | |||
android:layout_width="60dp" | |||
android:layout_height="wrap_content" | |||
android:orientation="vertical" | |||
> | |||
<TextView | |||
android:id="@+id/tv_item_age" | |||
android:layout_width="wrap_content" | |||
android:layout_height="40dp"/> | |||
<TextView | |||
android:id="@+id/tv_item_height" | |||
android:layout_width="wrap_content" | |||
android:layout_height="40dp"/> | |||
<TextView | |||
android:id="@+id/tv_item_weight" | |||
android:layout_width="wrap_content" | |||
android:layout_height="40dp"/> | |||
<TextView | |||
android:id="@+id/tv_item_adc" | |||
android:layout_width="wrap_content" | |||
android:layout_height="40dp"/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="vertical" | |||
> | |||
<SeekBar | |||
android:id="@+id/sb_item_age" | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:max="100" | |||
/> | |||
<SeekBar | |||
android:id="@+id/sb_item_height" | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:max="250" | |||
/> | |||
<SeekBar | |||
android:id="@+id/sb_item_weight" | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:max="180" | |||
/> | |||
<SeekBar | |||
android:id="@+id/sb_item_adc" | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:max="1000" | |||
/> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</LinearLayout> |
@@ -0,0 +1,5 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> | |||
<background android:drawable="@drawable/ic_launcher_background"/> | |||
<foreground android:drawable="@drawable/ic_launcher_foreground"/> | |||
</adaptive-icon> |
@@ -0,0 +1,5 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> | |||
<background android:drawable="@drawable/ic_launcher_background"/> | |||
<foreground android:drawable="@drawable/ic_launcher_foreground"/> | |||
</adaptive-icon> |
@@ -0,0 +1,6 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<resources> | |||
<color name="colorPrimary">#008577</color> | |||
<color name="colorPrimaryDark">#00574B</color> | |||
<color name="colorAccent">#D81B60</color> | |||
</resources> |
@@ -0,0 +1,7 @@ | |||
<resources> | |||
<string name="app_name">AILinkSdkDemoAndroid</string> | |||
<string name="clear">清空</string> | |||
<string name="handshake">握手</string> | |||
<string name="version">版本</string> | |||
<string name="time">时间</string> | |||
</resources> |
@@ -0,0 +1,23 @@ | |||
<resources> | |||
<!-- Base application theme. --> | |||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | |||
<!-- Customize your theme here. --> | |||
<item name="colorPrimary">@color/colorPrimary</item> | |||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | |||
<item name="colorAccent">@color/colorAccent</item> | |||
</style> | |||
<!--Dialog样式--> | |||
<style name="MyDialog" parent="android:style/Theme.Dialog"> | |||
<item name="android:windowNoTitle">true</item> | |||
<item name="android:background">@android:color/transparent</item> | |||
<item name="android:windowBackground">@android:color/transparent</item> | |||
<item name="android:windowIsFloating">true</item> | |||
<!-- 无边框设置 --> | |||
<item name="android:windowFrame">@null</item> | |||
<!--是否有阴影--> | |||
<item name="android:backgroundDimEnabled">true</item> | |||
</style> | |||
</resources> |
@@ -0,0 +1,17 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import org.junit.Test; | |||
import static org.junit.Assert.*; | |||
/** | |||
* Example local unit test, which will execute on the development machine (host). | |||
* | |||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | |||
*/ | |||
public class ExampleUnitTest { | |||
@Test | |||
public void addition_isCorrect() { | |||
assertEquals(4, 2 + 2); | |||
} | |||
} |
@@ -0,0 +1,27 @@ | |||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | |||
buildscript { | |||
repositories { | |||
google() | |||
jcenter() | |||
} | |||
dependencies { | |||
classpath 'com.android.tools.build:gradle:3.4.0' | |||
// NOTE: Do not place your application dependencies here; they belong | |||
// in the individual module build.gradle files | |||
} | |||
} | |||
allprojects { | |||
repositories { | |||
google() | |||
jcenter() | |||
maven { url 'https://jitpack.io' } | |||
} | |||
} | |||
task clean(type: Delete) { | |||
delete rootProject.buildDir | |||
} |
@@ -0,0 +1,20 @@ | |||
# Project-wide Gradle settings. | |||
# IDE (e.g. Android Studio) users: | |||
# Gradle settings configured through the IDE *will override* | |||
# any settings specified in this file. | |||
# For more details on how to configure your build environment visit | |||
# http://www.gradle.org/docs/current/userguide/build_environment.html | |||
# Specifies the JVM arguments used for the daemon process. | |||
# The setting is particularly useful for tweaking memory settings. | |||
org.gradle.jvmargs=-Xmx1536m | |||
# When configured, Gradle will run in incubating parallel mode. | |||
# This option should only be used with decoupled projects. More details, visit | |||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects | |||
# org.gradle.parallel=true | |||
# AndroidX package structure to make it clearer which packages are bundled with the | |||
# Android operating system, and which are packaged with your app's APK | |||
# https://developer.android.com/topic/libraries/support-library/androidx-rn | |||
android.useAndroidX=true | |||
# Automatically convert third-party libraries to use AndroidX | |||
android.enableJetifier=true | |||
@@ -0,0 +1,6 @@ | |||
#Thu Mar 26 17:17:50 CST 2020 | |||
distributionBase=GRADLE_USER_HOME | |||
distributionPath=wrapper/dists | |||
zipStoreBase=GRADLE_USER_HOME | |||
zipStorePath=wrapper/dists | |||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip |
@@ -0,0 +1,172 @@ | |||
#!/usr/bin/env sh | |||
############################################################################## | |||
## | |||
## Gradle start up script for UN*X | |||
## | |||
############################################################################## | |||
# Attempt to set APP_HOME | |||
# Resolve links: $0 may be a link | |||
PRG="$0" | |||
# Need this for relative symlinks. | |||
while [ -h "$PRG" ] ; do | |||
ls=`ls -ld "$PRG"` | |||
link=`expr "$ls" : '.*-> \(.*\)$'` | |||
if expr "$link" : '/.*' > /dev/null; then | |||
PRG="$link" | |||
else | |||
PRG=`dirname "$PRG"`"/$link" | |||
fi | |||
done | |||
SAVED="`pwd`" | |||
cd "`dirname \"$PRG\"`/" >/dev/null | |||
APP_HOME="`pwd -P`" | |||
cd "$SAVED" >/dev/null | |||
APP_NAME="Gradle" | |||
APP_BASE_NAME=`basename "$0"` | |||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. | |||
DEFAULT_JVM_OPTS="" | |||
# Use the maximum available, or set MAX_FD != -1 to use that value. | |||
MAX_FD="maximum" | |||
warn () { | |||
echo "$*" | |||
} | |||
die () { | |||
echo | |||
echo "$*" | |||
echo | |||
exit 1 | |||
} | |||
# OS specific support (must be 'true' or 'false'). | |||
cygwin=false | |||
msys=false | |||
darwin=false | |||
nonstop=false | |||
case "`uname`" in | |||
CYGWIN* ) | |||
cygwin=true | |||
;; | |||
Darwin* ) | |||
darwin=true | |||
;; | |||
MINGW* ) | |||
msys=true | |||
;; | |||
NONSTOP* ) | |||
nonstop=true | |||
;; | |||
esac | |||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar | |||
# Determine the Java command to use to start the JVM. | |||
if [ -n "$JAVA_HOME" ] ; then | |||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then | |||
# IBM's JDK on AIX uses strange locations for the executables | |||
JAVACMD="$JAVA_HOME/jre/sh/java" | |||
else | |||
JAVACMD="$JAVA_HOME/bin/java" | |||
fi | |||
if [ ! -x "$JAVACMD" ] ; then | |||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME | |||
Please set the JAVA_HOME variable in your environment to match the | |||
location of your Java installation." | |||
fi | |||
else | |||
JAVACMD="java" | |||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. | |||
Please set the JAVA_HOME variable in your environment to match the | |||
location of your Java installation." | |||
fi | |||
# Increase the maximum file descriptors if we can. | |||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then | |||
MAX_FD_LIMIT=`ulimit -H -n` | |||
if [ $? -eq 0 ] ; then | |||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then | |||
MAX_FD="$MAX_FD_LIMIT" | |||
fi | |||
ulimit -n $MAX_FD | |||
if [ $? -ne 0 ] ; then | |||
warn "Could not set maximum file descriptor limit: $MAX_FD" | |||
fi | |||
else | |||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" | |||
fi | |||
fi | |||
# For Darwin, add options to specify how the application appears in the dock | |||
if $darwin; then | |||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" | |||
fi | |||
# For Cygwin, switch paths to Windows format before running java | |||
if $cygwin ; then | |||
APP_HOME=`cygpath --path --mixed "$APP_HOME"` | |||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` | |||
JAVACMD=`cygpath --unix "$JAVACMD"` | |||
# We build the pattern for arguments to be converted via cygpath | |||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` | |||
SEP="" | |||
for dir in $ROOTDIRSRAW ; do | |||
ROOTDIRS="$ROOTDIRS$SEP$dir" | |||
SEP="|" | |||
done | |||
OURCYGPATTERN="(^($ROOTDIRS))" | |||
# Add a user-defined pattern to the cygpath arguments | |||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then | |||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" | |||
fi | |||
# Now convert the arguments - kludge to limit ourselves to /bin/sh | |||
i=0 | |||
for arg in "$@" ; do | |||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` | |||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option | |||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition | |||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` | |||
else | |||
eval `echo args$i`="\"$arg\"" | |||
fi | |||
i=$((i+1)) | |||
done | |||
case $i in | |||
(0) set -- ;; | |||
(1) set -- "$args0" ;; | |||
(2) set -- "$args0" "$args1" ;; | |||
(3) set -- "$args0" "$args1" "$args2" ;; | |||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;; | |||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; | |||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; | |||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; | |||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; | |||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; | |||
esac | |||
fi | |||
# Escape application args | |||
save () { | |||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done | |||
echo " " | |||
} | |||
APP_ARGS=$(save "$@") | |||
# Collect all arguments for the java command, following the shell quoting and substitution rules | |||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" | |||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong | |||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then | |||
cd "$(dirname "$0")" | |||
fi | |||
exec "$JAVACMD" "$@" |
@@ -0,0 +1,84 @@ | |||
@if "%DEBUG%" == "" @echo off | |||
@rem ########################################################################## | |||
@rem | |||
@rem Gradle startup script for Windows | |||
@rem | |||
@rem ########################################################################## | |||
@rem Set local scope for the variables with windows NT shell | |||
if "%OS%"=="Windows_NT" setlocal | |||
set DIRNAME=%~dp0 | |||
if "%DIRNAME%" == "" set DIRNAME=. | |||
set APP_BASE_NAME=%~n0 | |||
set APP_HOME=%DIRNAME% | |||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. | |||
set DEFAULT_JVM_OPTS= | |||
@rem Find java.exe | |||
if defined JAVA_HOME goto findJavaFromJavaHome | |||
set JAVA_EXE=java.exe | |||
%JAVA_EXE% -version >NUL 2>&1 | |||
if "%ERRORLEVEL%" == "0" goto init | |||
echo. | |||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. | |||
echo. | |||
echo Please set the JAVA_HOME variable in your environment to match the | |||
echo location of your Java installation. | |||
goto fail | |||
:findJavaFromJavaHome | |||
set JAVA_HOME=%JAVA_HOME:"=% | |||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe | |||
if exist "%JAVA_EXE%" goto init | |||
echo. | |||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% | |||
echo. | |||
echo Please set the JAVA_HOME variable in your environment to match the | |||
echo location of your Java installation. | |||
goto fail | |||
:init | |||
@rem Get command-line arguments, handling Windows variants | |||
if not "%OS%" == "Windows_NT" goto win9xME_args | |||
:win9xME_args | |||
@rem Slurp the command line arguments. | |||
set CMD_LINE_ARGS= | |||
set _SKIP=2 | |||
:win9xME_args_slurp | |||
if "x%~1" == "x" goto execute | |||
set CMD_LINE_ARGS=%* | |||
:execute | |||
@rem Setup the command line | |||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar | |||
@rem Execute Gradle | |||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% | |||
:end | |||
@rem End local scope for the variables with windows NT shell | |||
if "%ERRORLEVEL%"=="0" goto mainEnd | |||
:fail | |||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of | |||
rem the _cmd.exe /c_ return code! | |||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 | |||
exit /b 1 | |||
:mainEnd | |||
if "%OS%"=="Windows_NT" endlocal | |||
:omega |
@@ -0,0 +1 @@ | |||
include ':app' |