applicationId "aicare.net.cn.sdk.ailinksdkdemoandroid" | applicationId "aicare.net.cn.sdk.ailinksdkdemoandroid" | ||||
minSdkVersion 19 | minSdkVersion 19 | ||||
targetSdkVersion 31 | targetSdkVersion 31 | ||||
versionCode 17 | |||||
versionName "1.10.59" | |||||
versionName "1.11.9" | |||||
versionCode getVersionCodeNumber(versionName) | |||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||||
} | } | ||||
buildTypes { | buildTypes { | ||||
} | } | ||||
} | } | ||||
static def getVersionCodeNumber(String versionName) { | |||||
//1.49.13_beta05 | |||||
int code=0 | |||||
if (versionName!=null){ | |||||
String versionCodeStr=versionName+"80" | |||||
if (versionName.contains("_")){ | |||||
String[] versionStr=versionName.split("_") | |||||
versionCodeStr=versionStr[0]+"."+versionStr[1].substring(4) | |||||
} | |||||
String[] versionCodes=versionCodeStr.split("\\.") | |||||
for(int i=0;i<versionCodes.length;i++){ | |||||
String version=versionCodes[i] | |||||
if (version.length()<=1){ | |||||
version="0"+version; | |||||
} | |||||
versionCodes[i]=version | |||||
} | |||||
String versionAllStr="" | |||||
for (String version:versionCodes){ | |||||
versionAllStr+=version | |||||
} | |||||
code= (versionAllStr).toInteger() | |||||
} | |||||
return code | |||||
} | |||||
dependencies { | dependencies { | ||||
implementation fileTree(dir: 'libs', include: ['*.jar']) | implementation fileTree(dir: 'libs', include: ['*.jar']) |
<uses-permission android:name="android.permission.INTERNET" /> | <uses-permission android:name="android.permission.INTERNET" /> | ||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | |||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | |||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" | |||||
android:maxSdkVersion="30"/> | |||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" | |||||
android:maxSdkVersion="30"/> | |||||
<!--OTA需要读写文件--> | <!--OTA需要读写文件--> | ||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||||
<!--兼容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" | |||||
android:maxSdkVersion="30" /> | |||||
<uses-permission | |||||
android:name="android.permission.BLUETOOTH_ADMIN" | |||||
android:maxSdkVersion="30" /> | |||||
<!--android12还需要增加如下权限,也需求动态申请--> | |||||
<uses-permission | |||||
android:name="android.permission.BLUETOOTH_SCAN" | |||||
android:usesPermissionFlags="neverForLocation" | |||||
tools:targetApi="s" /> | |||||
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" /> | |||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> | |||||
<!--android10,11需要后台扫描的,需要添加如下权限--> | |||||
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> | |||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> | |||||
<uses-feature | |||||
android:name="android.hardware.bluetooth_le" | |||||
android:required="false" /> | |||||
<uses-feature | |||||
android:name="android.hardware.bluetooth" | |||||
android:required="false" /> | |||||
<application | <application | ||||
android:name=".base.MyApplication" | android:name=".base.MyApplication" | ||||
android:allowBackup="true" | android:allowBackup="true" | ||||
android:theme="@style/AppTheme" | android:theme="@style/AppTheme" | ||||
android:usesCleartextTraffic="true" | android:usesCleartextTraffic="true" | ||||
tools:targetApi="q"> | tools:targetApi="q"> | ||||
<activity android:name=".ClearShakeHandsActivity" /> | |||||
<activity android:name=".MainActivity" | <activity android:name=".MainActivity" | ||||
android:exported="true"> | android:exported="true"> | ||||
<intent-filter> | <intent-filter> | ||||
<activity android:name=".HeightWeightScaleActivity" /> | <activity android:name=".HeightWeightScaleActivity" /> | ||||
<activity android:name=".find.FindDeviceActivity" /> | <activity android:name=".find.FindDeviceActivity" /> | ||||
<activity android:name=".TempHumidityActivity" /> | <activity android:name=".TempHumidityActivity" /> | ||||
<activity android:name=".RopeSkippingActivity" /> | |||||
<activity android:name=".modules.ropeskipping.RopeSkippingActivity" /> | |||||
<activity android:name=".modules.airdetector.AirDetectorActivity" /> | <activity android:name=".modules.airdetector.AirDetectorActivity" /> | ||||
<activity android:name=".modules.airdetector_test.AirDetectorActivityTest" /> | <activity android:name=".modules.airdetector_test.AirDetectorActivityTest" /> | ||||
<activity | <activity | ||||
<activity android:name=".modules.leaone_broadcast.LeaOneBroadcastActivity" /> | <activity android:name=".modules.leaone_broadcast.LeaOneBroadcastActivity" /> | ||||
<activity android:name=".modules.fascia_gun.FasciaGunActivity" /> | <activity android:name=".modules.fascia_gun.FasciaGunActivity" /> | ||||
<activity android:name=".modules.blood_pressure_tc.BloodPressureTcActivity" /> | <activity android:name=".modules.blood_pressure_tc.BloodPressureTcActivity" /> | ||||
<activity android:name=".RopeSkippingSetActivity" /> | |||||
<activity android:name=".modules.ropeskipping.RopeSkippingSetActivity" /> | |||||
<activity android:name=".modules.body_scale_4g.BodyScale4GActivity" /> | <activity android:name=".modules.body_scale_4g.BodyScale4GActivity" /> | ||||
<activity android:name=".AiLinkScooterActivity" /> | <activity android:name=".AiLinkScooterActivity" /> | ||||
<activity android:name=".modules.TempInstrument.TempInstrumentActivity" /> | <activity android:name=".modules.TempInstrument.TempInstrumentActivity" /> | ||||
<activity android:name=".AboutActivity" /> | <activity android:name=".AboutActivity" /> | ||||
<activity android:name=".PublicBleNetworkCmdActivity" /> | |||||
<activity android:name=".modules.PublicBleNetworkCmdActivity" /> | |||||
<activity android:name=".modules.noise_meter.WifiBleNoiseMeterActivity" /> | <activity android:name=".modules.noise_meter.WifiBleNoiseMeterActivity" /> | ||||
<activity android:name=".modules.noise_meter.BleNoiseMeterActivity" /> | <activity android:name=".modules.noise_meter.BleNoiseMeterActivity" /> | ||||
<activity | |||||
android:name=".modules.meat_probe_charger.MeatProbeChargerActivity" | |||||
android:screenOrientation="portrait" /> | |||||
<activity | |||||
android:name=".modules.meat_probe.MeatProbeActivity" | |||||
android:screenOrientation="portrait" /> | |||||
<activity | <activity | ||||
android:name=".modules.weight_scale.WeightScaleActivity" | android:name=".modules.weight_scale.WeightScaleActivity" | ||||
android:screenOrientation="portrait" /> | android:screenOrientation="portrait" /> | ||||
android:name="android.support.FILE_PROVIDER_PATHS" | android:name="android.support.FILE_PROVIDER_PATHS" | ||||
android:resource="@xml/file_paths" /> | android:resource="@xml/file_paths" /> | ||||
</provider> | </provider> | ||||
<service android:name="com.pingwang.bluetoothlib.server.ELinkBleServer"/> | |||||
</application> | </application> | ||||
</manifest> | </manifest> |
import android.widget.RadioGroup; | import android.widget.RadioGroup; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import com.pingwang.bluetoothlib.config.CmdConfig; | import com.pingwang.bluetoothlib.config.CmdConfig; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.utils.BleDensityUtil; | import com.pingwang.bluetoothlib.utils.BleDensityUtil; | ||||
import com.pingwang.bluetoothlib.utils.BleLog; | import com.pingwang.bluetoothlib.utils.BleLog; | ||||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | import com.pingwang.bluetoothlib.utils.BleStrUtils; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.List; | import java.util.List; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.ADWeight.ADWeightScaleBleConfig; | import cn.net.aicare.modulelibrary.module.ADWeight.ADWeightScaleBleConfig; | ||||
import cn.net.aicare.modulelibrary.module.ADWeight.ADWeightScaleBodyFatData; | import cn.net.aicare.modulelibrary.module.ADWeight.ADWeightScaleBodyFatData; | ||||
import cn.net.aicare.modulelibrary.module.ADWeight.ADWeightScaleBodyFatDataRecord; | import cn.net.aicare.modulelibrary.module.ADWeight.ADWeightScaleBodyFatDataRecord; | ||||
import cn.net.aicare.modulelibrary.module.ADWeight.ADWeightScaleUserData; | import cn.net.aicare.modulelibrary.module.ADWeight.ADWeightScaleUserData; | ||||
/** | /** | ||||
* xing<br> | * xing<br> | ||||
* 2019/7/12<br> | * 2019/7/12<br> | ||||
* 显示数据 | * 显示数据 | ||||
*/ | */ | ||||
public class ADWeightScaleCmdActivity extends BleBaseActivity implements OnCallbackBle, OnBleVersionListener, OnMcuParameterListener, OnBleCompanyListener, OnBleSettingListener, | |||||
ADWeightScaleDeviceData.onNotifyData, View.OnClickListener, RadioGroup.OnCheckedChangeListener { | |||||
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 static String TAG = ADWeightScaleCmdActivity.class.getName(); | ||||
private final int REFRESH_DATA = 3; | 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 TextView user_id_tv, user_sex_tv, user_age_tv, user_height_tv, user_weight_tv, user_adc_tv; | |||||
private List<String> mList; | private List<String> mList; | ||||
private ArrayAdapter listAdapter; | private ArrayAdapter listAdapter; | ||||
private Context mContext; | private Context mContext; | ||||
BleLog.i(TAG, "服务与界面建立连接成功"); | BleLog.i(TAG, "服务与界面建立连接成功"); | ||||
//与服务建立连接 | //与服务建立连接 | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | ||||
if (bleDevice != null) { | if (bleDevice != null) { | ||||
mDevice = ADWeightScaleDeviceData.getInstance(bleDevice); | mDevice = ADWeightScaleDeviceData.getInstance(bleDevice); | ||||
mDevice.clear(); | mDevice.clear(); | ||||
mDevice = null; | mDevice = null; | ||||
} | } | ||||
if (mBluetoothService != null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | } | ||||
//-----------------状态------------------- | //-----------------状态------------------- | ||||
@Override | @Override | ||||
public void getAppUpdateUser(int status) { | public void getAppUpdateUser(int status) { | ||||
//00:更新列表成功 | |||||
//00:更新列表成功 | |||||
//01:更新个人用户成功 | //01:更新个人用户成功 | ||||
//02:更新列表失败 | //02:更新列表失败 | ||||
//03:更新个人用户失败 | //03:更新个人用户失败 | ||||
@Override | @Override | ||||
public void onSysTime(int status, int[] times) { | public void onSysTime(int status, int[] times) { | ||||
String time = | |||||
times[0] + "-" + times[1] + "-" + times[2] + " " + times[3] + ":" + times[4] + | |||||
":" + times[5]; | |||||
String time = times[0] + "-" + times[1] + "-" + times[2] + " " + times[3] + ":" + times[4] + ":" + times[5]; | |||||
mList.add(TimeUtils.getTime() + "系统时间:" + time); | mList.add(TimeUtils.getTime() + "系统时间:" + time); | ||||
mHandler.sendEmptyMessage(REFRESH_DATA); | mHandler.sendEmptyMessage(REFRESH_DATA); | ||||
} | } | ||||
msg = "同步时间"; | msg = "同步时间"; | ||||
break; | break; | ||||
} | } | ||||
String cmdDataMsg=""; | |||||
switch (cmdData){ | |||||
String cmdDataMsg = ""; | |||||
switch (cmdData) { | |||||
case 0: | case 0: | ||||
cmdDataMsg="设置成功"; | |||||
cmdDataMsg = "设置成功"; | |||||
break; | break; | ||||
case 1: | case 1: | ||||
cmdDataMsg="设置失败"; | |||||
cmdDataMsg = "设置失败"; | |||||
break; | break; | ||||
case 2: | case 2: | ||||
cmdDataMsg="不支持设置"; | |||||
cmdDataMsg = "不支持设置"; | |||||
break; | break; | ||||
} | } |
import androidx.annotation.Nullable; | import androidx.annotation.Nullable; | ||||
import androidx.appcompat.app.AppCompatActivity; | import androidx.appcompat.app.AppCompatActivity; | ||||
import cn.net.aicare.modulelibrary.module.ADWeight.ADWeightScaleBleConfig; | import cn.net.aicare.modulelibrary.module.ADWeight.ADWeightScaleBleConfig; | ||||
import cn.net.aicare.modulelibrary.module.ADWeight.ADWeightScaleUserData; | import cn.net.aicare.modulelibrary.module.ADWeight.ADWeightScaleUserData; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.AppBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.AppBaseActivity; | ||||
/** | /** | ||||
* xing<br> | * xing<br> | ||||
* 2022/4/6<br> | * 2022/4/6<br> |
import android.widget.EditText; | import android.widget.EditText; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | import com.pingwang.bluetoothlib.listener.OnCallbackBle; | ||||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | import com.pingwang.bluetoothlib.utils.BleStrUtils; | ||||
import java.util.List; | import java.util.List; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.ailinkScooter.AilinkScooterBleData; | import cn.net.aicare.modulelibrary.module.ailinkScooter.AilinkScooterBleData; | ||||
public class AiLinkScooterActivity extends BleBaseActivity implements View.OnClickListener, OnCallbackBle, AilinkScooterBleData.ScooterListener { | public class AiLinkScooterActivity extends BleBaseActivity implements View.OnClickListener, OnCallbackBle, AilinkScooterBleData.ScooterListener { | ||||
@Override | @Override | ||||
public void onServiceSuccess() { | public void onServiceSuccess() { | ||||
mBluetoothService.setOnCallback(this); | |||||
logList.add(0,"绑定服务成功"); | logList.add(0,"绑定服务成功"); | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | ||||
if (bleDevice != null) { | if (bleDevice != null) { | ||||
AilinkScooterBleData.init(bleDevice); | AilinkScooterBleData.init(bleDevice); | ||||
@Override | @Override | ||||
public void unbindServices() { | public void unbindServices() { | ||||
if (mBluetoothService!=null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | } | ||||
@Override | @Override |
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.RadioButton; | import android.widget.RadioButton; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import com.pingwang.bluetoothlib.bean.SupportUnitBean; | import com.pingwang.bluetoothlib.bean.SupportUnitBean; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import java.util.List; | import java.util.List; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.BLDBodyfatScale.BLDBodyFatBleUtilsData; | import cn.net.aicare.modulelibrary.module.BLDBodyfatScale.BLDBodyFatBleUtilsData; | ||||
import cn.net.aicare.modulelibrary.module.BLDBodyfatScale.BLDBodyFatDataUtil; | import cn.net.aicare.modulelibrary.module.BLDBodyfatScale.BLDBodyFatDataUtil; | ||||
import cn.net.aicare.modulelibrary.module.BLDBodyfatScale.BLDUser; | import cn.net.aicare.modulelibrary.module.BLDBodyfatScale.BLDUser; | ||||
// BleLog.i(TAG, "服务与界面建立连接成功"); | // BleLog.i(TAG, "服务与界面建立连接成功"); | ||||
//与服务建立连接 | //与服务建立连接 | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | ||||
if (bleDevice != null) { | if (bleDevice != null) { | ||||
BLDBodyFatBleUtilsData.init(bleDevice, this); | BLDBodyFatBleUtilsData.init(bleDevice, this); | ||||
public void unbindServices() { | public void unbindServices() { | ||||
mlogList.add(0, "服务与界面建立断开连接成功"); | mlogList.add(0, "服务与界面建立断开连接成功"); | ||||
mMHandler.sendEmptyMessage(ToRefreUi); | mMHandler.sendEmptyMessage(ToRefreUi); | ||||
if (mBluetoothService!=null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | } | ||||
@Override | @Override |
import android.widget.RadioGroup; | import android.widget.RadioGroup; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import com.pingwang.bluetoothlib.config.CmdConfig; | import com.pingwang.bluetoothlib.config.CmdConfig; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.babyBodyFat.BabyBodyFatBleConfig; | import cn.net.aicare.modulelibrary.module.babyBodyFat.BabyBodyFatBleConfig; | ||||
import cn.net.aicare.modulelibrary.module.babyBodyFat.BabyBodyFatDeviceData; | import cn.net.aicare.modulelibrary.module.babyBodyFat.BabyBodyFatDeviceData; | ||||
import cn.net.aicare.modulelibrary.module.babyscale.BabyBleConfig; | import cn.net.aicare.modulelibrary.module.babyscale.BabyBleConfig; | ||||
BleLog.i(TAG, "服务与界面建立连接成功"); | BleLog.i(TAG, "服务与界面建立连接成功"); | ||||
//与服务建立连接 | //与服务建立连接 | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | ||||
if (bleDevice != null) { | if (bleDevice != null) { | ||||
mDevice = BabyBodyFatDeviceData.getInstance(bleDevice); | mDevice = BabyBodyFatDeviceData.getInstance(bleDevice); | ||||
mDevice.clear(); | mDevice.clear(); | ||||
mDevice = null; | mDevice = null; | ||||
} | } | ||||
if (mBluetoothService!=null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | } | ||||
//-----------------状态------------------- | //-----------------状态------------------- |
import android.widget.RadioGroup; | import android.widget.RadioGroup; | ||||
import android.widget.Toast; | import android.widget.Toast; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.bean.SupportUnitBean; | import com.pingwang.bluetoothlib.bean.SupportUnitBean; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.babyscale.BabyBleConfig; | import cn.net.aicare.modulelibrary.module.babyscale.BabyBleConfig; | ||||
import cn.net.aicare.modulelibrary.module.babyscale.BabyDeviceData; | import cn.net.aicare.modulelibrary.module.babyscale.BabyDeviceData; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.Toast; | import android.widget.Toast; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.bean.SupportUnitBean; | import com.pingwang.bluetoothlib.bean.SupportUnitBean; | ||||
import com.pingwang.bluetoothlib.config.CmdConfig; | import com.pingwang.bluetoothlib.config.CmdConfig; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
/** | /** | ||||
* 2019/4/25<br> | * 2019/4/25<br> | ||||
* 基础指令信息数据显示 | * 基础指令信息数据显示 | ||||
*/ | */ | ||||
public class BleCmdActivity extends BleBaseActivity implements OnCallbackBle, OnBleDeviceDataListener, OnBleVersionListener, OnMcuParameterListener, OnBleErrListener, OnBleInfoListener, | |||||
OnBleParameterListener, OnBleCompanyListener, OnBleSettingListener, OnBleHandshakeListener, View.OnClickListener, OnBleOtherDataListener, OnBleRssiListener { | |||||
public class BleCmdActivity extends BleBaseActivity implements OnCallbackBle, OnBleDeviceDataListener, OnBleVersionListener, OnMcuParameterListener, OnBleErrListener, OnBleInfoListener, OnBleParameterListener, OnBleCompanyListener, OnBleSettingListener, OnBleHandshakeListener, View.OnClickListener, OnBleOtherDataListener, OnBleRssiListener { | |||||
private static String TAG = BleCmdActivity.class.getName(); | private static String TAG = BleCmdActivity.class.getName(); | ||||
private final int REFRESH_DATA = 3; | private final int REFRESH_DATA = 3; | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
private int mId = 0; | |||||
private void addShowData(String data) { | |||||
mId++; | |||||
mList.add("ID:" +mId+" " + TimeUtils.getTimeSSS() + data); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
} | |||||
@Override | @Override | ||||
protected void onCreate(@Nullable Bundle savedInstanceState) { | protected void onCreate(@Nullable Bundle savedInstanceState) { | ||||
if (mBleDevice != null) { | if (mBleDevice != null) { | ||||
mBleDevice.disconnect(); | mBleDevice.disconnect(); | ||||
} | } | ||||
mList.add(TimeUtils.getTime() + "断开连接"); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("断开连接"); | |||||
break; | break; | ||||
case R.id.btnConnect: | case R.id.btnConnect: | ||||
mBluetoothService.connectDevice(mAddress); | mBluetoothService.connectDevice(mAddress); | ||||
mList.add(TimeUtils.getTime() + "连接设备"); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("连接设备"); | |||||
break; | break; | ||||
case R.id.btnClear: | case R.id.btnClear: | ||||
if (mList != null) | if (mList != null) | ||||
case R.id.btnHandshake: | case R.id.btnHandshake: | ||||
if (mBleDevice != null) { | if (mBleDevice != null) { | ||||
mBleDevice.setHandshake(true); | mBleDevice.setHandshake(true); | ||||
// mBleDevice.sendHandshake(); | |||||
mList.add(TimeUtils.getTime() + "发送握手"); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
// mBleDevice.sendHandshake(); | |||||
addShowData("发送握手"); | |||||
} | } | ||||
break; | break; | ||||
case R.id.btnVersion: | case R.id.btnVersion: | ||||
sendBleBean = new SendBleBean(); | sendBleBean = new SendBleBean(); | ||||
sendBleBean.setHex(mBleSendCmdUtil.getBleVersion()); | sendBleBean.setHex(mBleSendCmdUtil.getBleVersion()); | ||||
sendData(sendBleBean); | sendData(sendBleBean); | ||||
mList.add(TimeUtils.getTime() + "正在获取版本号."); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("正在获取版本号."); | |||||
return; | return; | ||||
} | } | ||||
mList.add(TimeUtils.getTime() + "版本号:" + version); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("版本号:" + version); | |||||
} | } | ||||
break; | break; | ||||
case R.id.btnBattery: | case R.id.btnBattery: | ||||
sendBleBean = new SendBleBean(); | |||||
sendBleBean.setHex(mBleSendCmdUtil.getMcuBatteryStatus()); | |||||
sendData(sendBleBean); | |||||
for (int i = 0; i < 10; i++) { | |||||
sendBleBean = new SendBleBean(); | |||||
sendBleBean.setHex(mBleSendCmdUtil.getMcuBatteryStatus()); | |||||
sendData(sendBleBean); | |||||
} | |||||
addShowData("读取电量"); | |||||
break; | break; | ||||
case R.id.btnTimeRead: | case R.id.btnTimeRead: | ||||
sendBleBean = new SendBleBean(); | sendBleBean = new SendBleBean(); | ||||
sendBleBean = new SendBleBean(); | sendBleBean = new SendBleBean(); | ||||
sendBleBean.setHex(mBleSendCmdUtil.setDeviceInfo(data)); | sendBleBean.setHex(mBleSendCmdUtil.setDeviceInfo(data)); | ||||
sendData(sendBleBean); | sendData(sendBleBean); | ||||
mList.add(TimeUtils.getTime() + "设置设备信息:" + BleStrUtils.byte2HexStr(data)); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("设置设备信息:" + BleStrUtils.byte2HexStr(data)); | |||||
break; | break; | ||||
case R.id.btn_get_device: | case R.id.btn_get_device: | ||||
// 获取设备信息 | // 获取设备信息 | ||||
sendBleBean = new SendBleBean(); | sendBleBean = new SendBleBean(); | ||||
sendBleBean.setHex(mBleSendCmdUtil.getDeviceInfo()); | sendBleBean.setHex(mBleSendCmdUtil.getDeviceInfo()); | ||||
sendData(sendBleBean); | sendData(sendBleBean); | ||||
mList.add(TimeUtils.getTime() + "读取设备信息"); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("读取设备信息"); | |||||
break; | break; | ||||
case R.id.btnSnRead: | case R.id.btnSnRead: | ||||
// 获取设备信息 | // 获取设备信息 | ||||
sendData[0] = (byte) 0x95; | sendData[0] = (byte) 0x95; | ||||
sendBleBean.setHex(sendData); | sendBleBean.setHex(sendData); | ||||
sendData(sendBleBean); | sendData(sendBleBean); | ||||
mList.add(TimeUtils.getTime() + "读取SN号"); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("读取SN号"); | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
private void sendDataNow(SendBleBean sendBleBean) { | |||||
if (mBleDevice != null) { | |||||
mBleDevice.sendDataNow(sendBleBean); | |||||
} | |||||
} | |||||
//---------------------------------服务--------------------------------------------------- | //---------------------------------服务--------------------------------------------------- | ||||
@Override | @Override | ||||
public void onServiceSuccess() { | public void onServiceSuccess() { | ||||
mList.add(TimeUtils.getTime() + "服务与界面建立连接成功"); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("服务与界面建立连接成功"); | |||||
CallbackDisIm.getInstance().addListListener(this); | CallbackDisIm.getInstance().addListListener(this); | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
mBluetoothService.deviceConnectListener(mAddress, true); | mBluetoothService.deviceConnectListener(mAddress, true); | ||||
connectSuccess(); | connectSuccess(); | ||||
} | } | ||||
@Override | @Override | ||||
public void onServiceErr() { | public void onServiceErr() { | ||||
mList.add(TimeUtils.getTime() + "服务与界面连接断开"); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("服务与界面连接断开"); | |||||
mHandler.postDelayed(new Runnable() { | mHandler.postDelayed(new Runnable() { | ||||
@Override | @Override | ||||
public void run() { | public void run() { | ||||
public void unbindServices() { | public void unbindServices() { | ||||
CallbackDisIm.getInstance().removeListener(this); | CallbackDisIm.getInstance().removeListener(this); | ||||
mBluetoothService.disconnectAll(); | mBluetoothService.disconnectAll(); | ||||
if (mBluetoothService!=null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | } | ||||
if (mAddress.equals(mac)) { | if (mAddress.equals(mac)) { | ||||
Toast.makeText(mContext, "连接断开:" + code, Toast.LENGTH_SHORT).show(); | Toast.makeText(mContext, "连接断开:" + code, Toast.LENGTH_SHORT).show(); | ||||
mBleDevice = null; | mBleDevice = null; | ||||
addShowData("连接断开:" + code); | |||||
} | } | ||||
} | } | ||||
if (mPauseShowCmd) { | if (mPauseShowCmd) { | ||||
return; | return; | ||||
} | } | ||||
mList.add(TimeUtils.getTime() + "透传数据:" + BleStrUtils.byte2HexStr(data)); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("透传数据:" + BleStrUtils.byte2HexStr(data)); | |||||
} | } | ||||
@Override | @Override | ||||
switch (hex[0]) { | switch (hex[0]) { | ||||
case CmdConfig.SET_DEVICE_INFO: { | case CmdConfig.SET_DEVICE_INFO: { | ||||
// 设置设备信息 | // 设置设备信息 | ||||
mList.add(TimeUtils.getTime() + "设置设备信息:结果:" + hex[1]); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("设置设备信息:结果:" + hex[1]); | |||||
} | } | ||||
break; | break; | ||||
case CmdConfig.GET_DEVICE_INFO: { | case CmdConfig.GET_DEVICE_INFO: { | ||||
// 读取设备信息 | // 读取设备信息 | ||||
byte[] data = new byte[hex.length - 1]; | byte[] data = new byte[hex.length - 1]; | ||||
System.arraycopy(hex, 1, data, 0, data.length); | System.arraycopy(hex, 1, data, 0, data.length); | ||||
mList.add(TimeUtils.getTime() + "读取设备信息:结果:" + BleStrUtils.byte2HexStr(data)); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("读取设备信息:结果:" + BleStrUtils.byte2HexStr(data)); | |||||
} | } | ||||
break; | break; | ||||
case (byte) 0x95: { | case (byte) 0x95: { | ||||
// 读取设备信息 | // 读取设备信息 | ||||
byte[] dataSn = new byte[hex.length - 1]; | byte[] dataSn = new byte[hex.length - 1]; | ||||
System.arraycopy(hex, 1, dataSn, 0, dataSn.length); | System.arraycopy(hex, 1, dataSn, 0, dataSn.length); | ||||
mList.add(TimeUtils.getTime() + "读取SN:结果:" + BleStrUtils.byte2HexStr(dataSn)); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("读取SN:结果:" + BleStrUtils.byte2HexStr(dataSn)); | |||||
} | } | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
@Override | @Override | ||||
public void onNotifyData(byte[] hex, int type) { | |||||
public void onNotifyData(String uuid, byte[] hex, int type) { | |||||
if (mPauseShowCmd) { | if (mPauseShowCmd) { | ||||
return; | return; | ||||
} | } | ||||
if (hex != null) | if (hex != null) | ||||
data = BleStrUtils.byte2HexStr(hex); | data = BleStrUtils.byte2HexStr(hex); | ||||
if (type == 100) { | if (type == 100) { | ||||
mList.add(TimeUtils.getTime() + "cid=" + type + "\nsend->" + data); | |||||
addShowData("cid=" + type + "\nsend->" + data); | |||||
} else { | } else { | ||||
mList.add(TimeUtils.getTime() + "cid=" + type + "\nnotify->" + data); | |||||
addShowData("cid=" + type + "\nnotify->" + data); | |||||
} | } | ||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
} | } | ||||
@Override | @Override | ||||
public void onHandshake(boolean status) { | public void onHandshake(boolean status) { | ||||
mList.add(TimeUtils.getTime() + "握手:" + status); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("握手:" + status); | |||||
} | } | ||||
@Override | @Override | ||||
public void onBmVersion(String version) { | public void onBmVersion(String version) { | ||||
mList.add(TimeUtils.getTime() + "版本号:" + version); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("版本号:" + version); | |||||
} | } | ||||
@Override | @Override | ||||
public void onSupportUnit(List<SupportUnitBean> list) { | public void onSupportUnit(List<SupportUnitBean> list) { | ||||
StringBuilder unitStr = new StringBuilder(); | StringBuilder unitStr = new StringBuilder(); | ||||
unitStr.append(TimeUtils.getTime()); | |||||
unitStr.append(TimeUtils.getTimeSSS()); | |||||
for (SupportUnitBean supportUnitBean : list) { | for (SupportUnitBean supportUnitBean : list) { | ||||
unitStr.append("单位类型:").append(supportUnitBean.getType()); | unitStr.append("单位类型:").append(supportUnitBean.getType()); | ||||
mList.add(unitStr.toString()); | mList.add(unitStr.toString()); | ||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
} | } | ||||
@Override | @Override | ||||
public void onMcuBatteryStatus(int status, int battery) { | public void onMcuBatteryStatus(int status, int battery) { | ||||
mList.add(TimeUtils.getTime() + "电量:" + battery + "%" + "||状态:" + status); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("电量:" + battery + "%" + "||状态:" + status); | |||||
BleLog.i("当前电量:" + battery); | |||||
} | } | ||||
@Override | @Override | ||||
public void onSysTime(int status, int[] times) { | public void onSysTime(int status, int[] times) { | ||||
String timeStr = times[0] + "-" + times[1] + "-" + times[2] + " " + times[3] + ":" + times[4] + ":" + times[5]; | String timeStr = times[0] + "-" + times[1] + "-" + times[2] + " " + times[3] + ":" + times[4] + ":" + times[5]; | ||||
mList.add(TimeUtils.getTime() + "时间:" + timeStr + "||是否有效:" + status); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("时间:" + timeStr + "||是否有效:" + status); | |||||
} | } | ||||
@Override | @Override | ||||
public void onErr(int cmdType) { | public void onErr(int cmdType) { | ||||
mList.add(TimeUtils.getTime() + "错误:" + cmdType); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("错误:" + cmdType); | |||||
} | } | ||||
@Override | @Override | ||||
if (CmdConfig.SET_TO_SLEEP == cmdType && cmdData == CmdConfig.SETTING_SUCCESS) { | if (CmdConfig.SET_TO_SLEEP == cmdType && cmdData == CmdConfig.SETTING_SUCCESS) { | ||||
//进入睡眠 | //进入睡眠 | ||||
} | } | ||||
mList.add(TimeUtils.getTime() + "设置指令:" + cmdType + "||结果:" + cmdData); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("设置指令:" + cmdType + "||结果:" + cmdData); | |||||
} | } | ||||
@Override | @Override | ||||
public void onBleName(String name) { | public void onBleName(String name) { | ||||
mList.add(TimeUtils.getTime() + "名称:" + name); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("名称:" + name); | |||||
} | } | ||||
@Override | @Override | ||||
public void onBleMac(String mac) { | public void onBleMac(String mac) { | ||||
mList.add(TimeUtils.getTime() + "Mac:" + mac); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("Mac:" + mac); | |||||
} | } | ||||
@Override | @Override | ||||
public void onNoConnectSleep(int sleepSwitch, int sleepTime, int sleepBroadcastSwitch, int sleepBroadcastTime) { | 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); | |||||
addShowData("sleepSwitch:" + sleepSwitch + " ||sleepTime:" + sleepTime + " ||sleepBroadcastSwitch:" + sleepBroadcastSwitch + " ||sleepBroadcastTime:" + sleepBroadcastTime); | |||||
} | } | ||||
@Override | @Override | ||||
public void OnDID(int cid, int vid, int pid) { | public void OnDID(int cid, int vid, int pid) { | ||||
mList.add(TimeUtils.getTime() + "cid:" + cid + "||vid:" + vid + "||pid:" + pid); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("cid:" + cid + "||vid:" + vid + "||pid:" + pid); | |||||
} | } | ||||
@Override | @Override | ||||
public void onBleBroadcastTime(int time) { | public void onBleBroadcastTime(int time) { | ||||
mList.add(TimeUtils.getTime() + "广播间隔:" + time); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("广播间隔:" + time); | |||||
} | } | ||||
@Override | @Override | ||||
public void onConnectTime(int time, int status, int timeOut) { | public void onConnectTime(int time, int status, int timeOut) { | ||||
mList.add(TimeUtils.getTime() + "连接:time:" + time + "||status:" + status + "||timeOut:" + timeOut); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("连接:time:" + time + "||status:" + status + "||timeOut:" + timeOut); | |||||
} | } | ||||
@Override | @Override | ||||
public void onBlePower(int power) { | public void onBlePower(int power) { | ||||
mList.add(TimeUtils.getTime() + "功率:" + power); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("功率:" + power); | |||||
} | } | ||||
@Override | @Override | ||||
public void onPortRate(int rate) { | public void onPortRate(int rate) { | ||||
mList.add(TimeUtils.getTime() + "串口波特率:" + rate); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("串口波特率:" + rate); | |||||
} | } | ||||
@Override | @Override | ||||
public void onBroadcastDataType(int type) { | public void onBroadcastDataType(int type) { | ||||
mList.add(TimeUtils.getTime() + "广播大小端:" + type); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("广播大小端:" + type); | |||||
} | } | ||||
@Override | @Override | ||||
public void onModuleUUID(int length, String serverUUID, String featureUUID1, String featureUUID2) { | 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); | |||||
addShowData("UUID:length:" + length + "||serverUUID:" + serverUUID + "||featureUUID1:" + featureUUID1 + "||featureUUID2" + featureUUID2); | |||||
} | } | ||||
@Override | @Override | ||||
public void onBleMode(int mode) { | public void onBleMode(int mode) { | ||||
mList.add(TimeUtils.getTime() + "模式:" + mode); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("模式:" + mode); | |||||
} | } | ||||
@Override | @Override | ||||
if (mBleDevice != null) { | if (mBleDevice != null) { | ||||
name = mBleDevice.getName(); | name = mBleDevice.getName(); | ||||
} | } | ||||
mList.add(TimeUtils.getTime() + "名称:" + name + " ,||信号:" + rssi); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||||
addShowData("名称:" + name + " ,||信号:" + rssi); | |||||
} | } | ||||
@Override | @Override |
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.RadioButton; | import android.widget.RadioButton; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.bean.SupportUnitBean; | import com.pingwang.bluetoothlib.bean.SupportUnitBean; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | import com.pingwang.bluetoothlib.listener.OnCallbackBle; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.List; | import java.util.List; | ||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.BloodGlucose.BloodGlucoseBleDeviceData; | import cn.net.aicare.modulelibrary.module.BloodGlucose.BloodGlucoseBleDeviceData; | ||||
import cn.net.aicare.modulelibrary.module.BloodGlucose.BloodGlucoseUtil; | import cn.net.aicare.modulelibrary.module.BloodGlucose.BloodGlucoseUtil; | ||||
mLogList.add(0, "绑定服务成功"); | mLogList.add(0, "绑定服务成功"); | ||||
listAdapter.notifyDataSetChanged(); | listAdapter.notifyDataSetChanged(); | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | ||||
if (bleDevice != null) { | if (bleDevice != null) { | ||||
mBloodGlucoseBleDeviceData = new BloodGlucoseBleDeviceData(bleDevice); | mBloodGlucoseBleDeviceData = new BloodGlucoseBleDeviceData(bleDevice); |
import android.widget.TextView; | import android.widget.TextView; | ||||
import android.widget.Toast; | import android.widget.Toast; | ||||
import androidx.annotation.Nullable; | |||||
import androidx.appcompat.widget.AppCompatSeekBar; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | import com.pingwang.bluetoothlib.listener.OnCallbackBle; | ||||
import java.util.List; | import java.util.List; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.Nullable; | |||||
import androidx.appcompat.widget.AppCompatSeekBar; | |||||
import cn.net.aicare.modulelibrary.module.BloodOxygen.BleBloodOxygenBleConfig; | import cn.net.aicare.modulelibrary.module.BloodOxygen.BleBloodOxygenBleConfig; | ||||
import cn.net.aicare.modulelibrary.module.BloodOxygen.BleBloodOxygenDeviceData; | import cn.net.aicare.modulelibrary.module.BloodOxygen.BleBloodOxygenDeviceData; | ||||
@Override | @Override | ||||
public void onServiceSuccess() { | public void onServiceSuccess() { | ||||
loglist.add(0, "连接设备成功"); | loglist.add(0, "连接设备成功"); | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | ||||
BleBloodOxygenDeviceData.init(bleDevice, this); | BleBloodOxygenDeviceData.init(bleDevice, this); | ||||
mBleBloodOxygenDeviceData = BleBloodOxygenDeviceData.getInstance(); | mBleBloodOxygenDeviceData = BleBloodOxygenDeviceData.getInstance(); | ||||
@Override | @Override | ||||
public void unbindServices() { | public void unbindServices() { | ||||
if (mBluetoothService!=null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | } | ||||
@Override | @Override |
import android.widget.EditText; | import android.widget.EditText; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import androidx.annotation.Nullable; | |||||
import androidx.appcompat.app.AppCompatActivity; | |||||
import org.json.JSONArray; | import org.json.JSONArray; | ||||
import org.json.JSONException; | import org.json.JSONException; | ||||
import org.json.JSONObject; | import org.json.JSONObject; | ||||
import java.util.Locale; | import java.util.Locale; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.Nullable; | |||||
import androidx.appcompat.app.AppCompatActivity; | |||||
/** | /** | ||||
* 4G血糖仪 | * 4G血糖仪 |
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import com.pingwang.bluetoothlib.config.BleConfig; | import com.pingwang.bluetoothlib.config.BleConfig; | ||||
import com.pingwang.bluetoothlib.listener.OnCallbackDis; | import com.pingwang.bluetoothlib.listener.OnCallbackDis; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.BloodOxygen.BroadcastBloodOxygenBleConfig; | import cn.net.aicare.modulelibrary.module.BloodOxygen.BroadcastBloodOxygenBleConfig; | ||||
import cn.net.aicare.modulelibrary.module.BloodOxygen.BroadcastBloodOxygenDeviceData; | import cn.net.aicare.modulelibrary.module.BloodOxygen.BroadcastBloodOxygenDeviceData; | ||||
break; | break; | ||||
case R.id.open: | case R.id.open: | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.scanLeDevice(0, UUID.fromString("0000F0A0-0000-1000-8000-00805F9B34FB")); | |||||
mBluetoothService.startScan(0, UUID.fromString("0000F0A0-0000-1000-8000-00805F9B34FB")); | |||||
} | } | ||||
break; | break; | ||||
case R.id.stop: | case R.id.stop: | ||||
mDevice = BroadcastBloodOxygenDeviceData.getInstance(); | mDevice = BroadcastBloodOxygenDeviceData.getInstance(); | ||||
mDevice.setOnNotifyData(this); | mDevice.setOnNotifyData(this); | ||||
mBluetoothService.setOnScanFilterListener(this); | mBluetoothService.setOnScanFilterListener(this); | ||||
mBluetoothService.scanLeDevice(0, BleConfig.UUID_SERVER_BROADCAST_AILINK); | |||||
mBluetoothService.startScan(0, BleConfig.UUID_SERVER_BROADCAST_AILINK); | |||||
} | } | ||||
} | } | ||||
import android.widget.RadioGroup; | import android.widget.RadioGroup; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.AILinkBleManager; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import com.pingwang.bluetoothlib.config.BleConfig; | import com.pingwang.bluetoothlib.config.BleConfig; | ||||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | ||||
import com.pingwang.bluetoothlib.listener.OnBleBroadcastDataListener; | |||||
import com.pingwang.bluetoothlib.listener.OnCallbackDis; | import com.pingwang.bluetoothlib.listener.OnCallbackDis; | ||||
import com.pingwang.bluetoothlib.listener.OnScanFilterListener; | |||||
import com.pingwang.bluetoothlib.utils.BleDensityUtil; | import com.pingwang.bluetoothlib.utils.BleDensityUtil; | ||||
import com.pingwang.bluetoothlib.utils.BleLog; | import com.pingwang.bluetoothlib.utils.BleLog; | ||||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | import com.pingwang.bluetoothlib.utils.BleStrUtils; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.UUID; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleNewBaseActivity; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.BroadcastScale.BroadcastScaleBleConfig; | import cn.net.aicare.modulelibrary.module.BroadcastScale.BroadcastScaleBleConfig; | ||||
import cn.net.aicare.modulelibrary.module.BroadcastScale.BroadcastScaleDeviceData; | import cn.net.aicare.modulelibrary.module.BroadcastScale.BroadcastScaleDeviceData; | ||||
import cn.net.aicare.modulelibrary.module.babyscale.BabyBleConfig; | import cn.net.aicare.modulelibrary.module.babyscale.BabyBleConfig; | ||||
/** | /** | ||||
* xing<br> | * xing<br> | ||||
* 2020/08/10<br> | * 2020/08/10<br> | ||||
* 广播秤 | * 广播秤 | ||||
*/ | */ | ||||
public class BroadcastScaleActivity extends BleBaseActivity implements OnCallbackDis, BroadcastScaleDeviceData.onNotifyData, OnScanFilterListener, View.OnClickListener, | |||||
RadioGroup.OnCheckedChangeListener { | |||||
public class BroadcastScaleActivity extends BleNewBaseActivity implements OnCallbackDis, BroadcastScaleDeviceData.onNotifyData, OnBleBroadcastDataListener, View.OnClickListener, RadioGroup.OnCheckedChangeListener { | |||||
private static String TAG = BroadcastScaleActivity.class.getName(); | private static String TAG = BroadcastScaleActivity.class.getName(); | ||||
private final int REFRESH_DATA = 3; | private final int REFRESH_DATA = 3; | ||||
private RadioButton mRadioButtonKg, mRadioButtonLb, mRadioButtonLbLb, mRadioButtonG, mRadioButtonOz, mRadioButtonStLb, mRadioButtonJin; | private RadioButton mRadioButtonKg, mRadioButtonLb, mRadioButtonLbLb, mRadioButtonG, mRadioButtonOz, mRadioButtonStLb, mRadioButtonJin; | ||||
private TextView tv_broadcast_temp, tv_broadcast_mac,tv_broadcast_did; | |||||
private TextView tv_broadcast_temp, tv_broadcast_mac, tv_broadcast_did; | |||||
private List<String> mList; | private List<String> mList; | ||||
private ArrayAdapter listAdapter; | private ArrayAdapter listAdapter; | ||||
super.onCreate(savedInstanceState); | super.onCreate(savedInstanceState); | ||||
setContentView(R.layout.activity_broadcast_scale); | setContentView(R.layout.activity_broadcast_scale); | ||||
mContext = this; | mContext = this; | ||||
// mAddress = getIntent().getStringExtra("mac"); | |||||
// mAddress = getIntent().getStringExtra("mac"); | |||||
mBleSendCmdUtil = BleSendCmdUtil.getInstance(); | mBleSendCmdUtil = BleSendCmdUtil.getInstance(); | ||||
init(); | init(); | ||||
} | } | ||||
private void init() { | private void init() { | ||||
mHandler.sendEmptyMessage(REFRESH_DATA); | mHandler.sendEmptyMessage(REFRESH_DATA); | ||||
break; | break; | ||||
case R.id.open: | case R.id.open: | ||||
if (mBluetoothService != null) { | |||||
mBluetoothService.scanLeDevice(0, UUID.fromString("0000F0A0-0000-1000-8000-00805F9B34FB")); | |||||
} | |||||
AILinkBleManager.getInstance().startScan(0, BleConfig.UUID_SERVER_BROADCAST_AILINK); | |||||
break; | break; | ||||
case R.id.stop: | case R.id.stop: | ||||
if (mBluetoothService != null) { | |||||
mBluetoothService.stopScan(); | |||||
} | |||||
AILinkBleManager.getInstance().stopScan(); | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
public void onServiceSuccess() { | public void onServiceSuccess() { | ||||
BleLog.i(TAG, "服务与界面建立连接成功"); | BleLog.i(TAG, "服务与界面建立连接成功"); | ||||
//与服务建立连接 | //与服务建立连接 | ||||
if (mBluetoothService != null) { | |||||
mDevice = BroadcastScaleDeviceData.getInstance(); | |||||
mDevice.setOnNotifyData(this); | |||||
mBluetoothService.setOnScanFilterListener(this); | |||||
mBluetoothService.scanLeDevice(0, BleConfig.UUID_SERVER_BROADCAST_AILINK); | |||||
} | |||||
mDevice = BroadcastScaleDeviceData.getInstance(); | |||||
mDevice.setOnNotifyData(this); | |||||
AILinkBleManager.getInstance().setOnBleBroadcastDataListener(this); | |||||
AILinkBleManager.getInstance().startScan(0, BleConfig.UUID_SERVER_BROADCAST_AILINK); | |||||
} | } | ||||
@Override | @Override | ||||
public void onServiceErr() { | public void onServiceErr() { | ||||
BleLog.i(TAG, "服务与界面连接断开"); | BleLog.i(TAG, "服务与界面连接断开"); | ||||
//与服务断开连接 | //与服务断开连接 | ||||
mBluetoothService = null; | |||||
} | } | ||||
@Override | @Override | ||||
//-----------------通知------------------- | //-----------------通知------------------- | ||||
private String mOldData=""; | |||||
private String mOldData = ""; | |||||
@Override | @Override | ||||
public void onData(byte[] dataOriginal,byte[] hex, int type) { | |||||
public void onData(byte[] dataOriginal, byte[] hex, int type) { | |||||
String data = ""; | String data = ""; | ||||
if (hex != null) | if (hex != null) | ||||
data = BleStrUtils.byte2HexStr(hex); | data = BleStrUtils.byte2HexStr(hex); | ||||
if (mOldData.equals(data)){ | |||||
if (mOldData.equals(data)) { | |||||
return; | return; | ||||
} | } | ||||
mOldData=data; | |||||
mList.add(TimeUtils.getTime() + "数据ID" + type+" ,||解密数据:"+data+" ,||原始数据:"+BleStrUtils.byte2HexStr(dataOriginal)); | |||||
mOldData = data; | |||||
mList.add(TimeUtils.getTime() + "数据ID" + type + " ,||解密数据:" + data + " ,||原始数据:" + BleStrUtils.byte2HexStr(dataOriginal)); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | mHandler.sendEmptyMessage(REFRESH_DATA); | ||||
} | } | ||||
statusStr += "测阻抗中"; | statusStr += "测阻抗中"; | ||||
break; | break; | ||||
case BroadcastScaleBleConfig.GET_IMPEDANCE_SUCCESS: | case BroadcastScaleBleConfig.GET_IMPEDANCE_SUCCESS: | ||||
statusStr+= "测阻抗成功"; | |||||
statusStr += "测阻抗成功"; | |||||
break; | break; | ||||
case BroadcastScaleBleConfig.GET_IMPEDANCE_FAIL: | case BroadcastScaleBleConfig.GET_IMPEDANCE_FAIL: | ||||
statusStr += "测阻抗失败"; | statusStr += "测阻抗失败"; | ||||
statusStr += "测量完成"; | statusStr += "测量完成"; | ||||
break; | break; | ||||
default: | default: | ||||
statusStr+=Integer.toHexString(status); | |||||
statusStr += Integer.toHexString(status); | |||||
break; | break; | ||||
} | } | ||||
@Override | @Override | ||||
public void OnDID(int cid, int vid, int pid) { | public void OnDID(int cid, int vid, int pid) { | ||||
String didStr = "cid:" + cid + "||vid:" + vid + "||pid:" + pid; | String didStr = "cid:" + cid + "||vid:" + vid + "||pid:" + pid; | ||||
if (tv_broadcast_did!=null){ | |||||
if (tv_broadcast_did != null) { | |||||
tv_broadcast_did.setText(didStr); | tv_broadcast_did.setText(didStr); | ||||
} | } | ||||
} | } | ||||
@Override | @Override | ||||
public boolean onFilter(BleValueBean bleValueBean) { | |||||
return true; | |||||
} | |||||
@Override | |||||
public void onScanRecord(BleValueBean bleValueBean) { | |||||
public void onBleBroadcastData(BleValueBean bleValueBean, byte[] payload) { | |||||
if (TextUtils.isEmpty(mAddress) && bleValueBean.isBroadcastModule()) { | if (TextUtils.isEmpty(mAddress) && bleValueBean.isBroadcastModule()) { | ||||
mAddress = bleValueBean.getMac(); | mAddress = bleValueBean.getMac(); | ||||
if (tv_broadcast_mac != null) { | if (tv_broadcast_mac != null) { | ||||
int cid = bleValueBean.getCid(); | int cid = bleValueBean.getCid(); | ||||
int vid = bleValueBean.getVid(); | int vid = bleValueBean.getVid(); | ||||
int pid = bleValueBean.getPid(); | int pid = bleValueBean.getPid(); | ||||
if (mDevice != null) | |||||
mDevice.onNotifyData(manufacturerData, cid, vid, pid); | |||||
if (mDevice != null) { | |||||
mDevice.onNotifyData( manufacturerData, cid, vid, pid); | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } |
import android.widget.EditText; | import android.widget.EditText; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | ||||
import com.pingwang.bluetoothlib.device.SendBleBean; | import com.pingwang.bluetoothlib.device.SendBleBean; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.sphygmomanometer.SphyBleConfig; | import cn.net.aicare.modulelibrary.module.sphygmomanometer.SphyBleConfig; | ||||
@Override | @Override | ||||
public void onNotifyData(byte[] hex, int type) { | |||||
public void onNotifyData(String uuid, byte[] hex, int type) { | |||||
mList.add(TimeUtils.getTime() + "notify->" + BleStrUtils.byte2HexStr(hex)); | mList.add(TimeUtils.getTime() + "notify->" + BleStrUtils.byte2HexStr(hex)); | ||||
mHandler.sendEmptyMessage(REFRESH_DATA); | mHandler.sendEmptyMessage(REFRESH_DATA); | ||||
} | } |
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.Toast; | import android.widget.Toast; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import androidx.appcompat.app.AppCompatActivity; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import com.pingwang.bluetoothlib.listener.CallbackDisIm; | import com.pingwang.bluetoothlib.listener.CallbackDisIm; | ||||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | import com.pingwang.bluetoothlib.listener.OnCallbackBle; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.LoadingIosDialogFragment; | import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.LoadingIosDialogFragment; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import androidx.appcompat.app.AppCompatActivity; | |||||
/** | /** |
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||||
import com.holtek.libHTBodyfat.HTBodyBasicInfo; | |||||
import com.holtek.libHTBodyfat.HTBodyResultAllBody; | |||||
import java.util.Locale; | |||||
public class EightBodyFatAlgorithms { | |||||
public EightBodyFatAlgorithms() { | |||||
} | |||||
private static class AlgorithmsHolder { | |||||
private static EightBodyFatAlgorithms algorithmsUnit = new EightBodyFatAlgorithms(); | |||||
} | |||||
public static EightBodyFatAlgorithms getInstance() { | |||||
return AlgorithmsHolder.algorithmsUnit; | |||||
} | |||||
public EightBodyFatBean getAlgorithmsData(int algorithms, int sex, int height, float weight_kg, int age, EightBodyfatAdc eightBodyfatAdc) { | |||||
EightBodyFatBean eightBodyFatBean = new EightBodyFatBean(); | |||||
switch (algorithms) { | |||||
//和泰算法 | |||||
case 1: | |||||
default: | |||||
HTBodyBasicInfo basicInfo = new HTBodyBasicInfo(sex, height, weight_kg, age); | |||||
basicInfo.htZAllBodyImpedance = eightBodyfatAdc.getAdcRightBody(); | |||||
basicInfo.htZLeftLegImpedance = eightBodyfatAdc.getAdcLeftFoot(); | |||||
basicInfo.htZRightLegImpedance = eightBodyfatAdc.getAdcRightFoot(); | |||||
basicInfo.htZLeftArmImpedance = eightBodyfatAdc.getAdcLeftHand(); | |||||
basicInfo.htZRightArmImpedance = eightBodyfatAdc.getAdcRightHand(); | |||||
basicInfo.htTwoLegsImpedance = eightBodyfatAdc.getAdcFoot(); | |||||
basicInfo.htTwoArmsImpedance = eightBodyfatAdc.getAdcHand(); | |||||
HTBodyResultAllBody resultTwoLegs = new HTBodyResultAllBody(); | |||||
int errorType = resultTwoLegs.getBodyfatWithBasicInfo(basicInfo); | |||||
if (errorType == HTBodyBasicInfo.ErrorNone) { | |||||
eightBodyFatBean.setBmi(Adecimal(resultTwoLegs.htBMI)); | |||||
eightBodyFatBean.setBmr((float) resultTwoLegs.htBMR); | |||||
eightBodyFatBean.setUvi((float) resultTwoLegs.htVFAL); | |||||
eightBodyFatBean.setBm(String.valueOf((float) resultTwoLegs.htBoneKg)); | |||||
eightBodyFatBean.setBfr(Adecimal(resultTwoLegs.htBodyfatPercentage)); | |||||
eightBodyFatBean.setVwc(Adecimal(resultTwoLegs.htWaterPercentage)); | |||||
eightBodyFatBean.setRom(Adecimal(resultTwoLegs.htMusclePercentage)); | |||||
eightBodyFatBean.setBodyAge(resultTwoLegs.htBodyAge); | |||||
eightBodyFatBean.setPp(Adecimal(resultTwoLegs.htProteinPercentage)); | |||||
eightBodyFatBean.setSfr(Adecimal(resultTwoLegs.htBodyfatSubcut)); | |||||
eightBodyFatBean.setFatMassBody(String.valueOf(resultTwoLegs.htBodyfatKgTrunk)); | |||||
eightBodyFatBean.setFatMassLeftTop(String.valueOf(resultTwoLegs.htBodyfatKgLeftArm)); | |||||
eightBodyFatBean.setFatMassLeftBottom(String.valueOf(resultTwoLegs.htBodyfatKgLeftLeg)); | |||||
eightBodyFatBean.setFatMassRightTop(String.valueOf(resultTwoLegs.htBodyfatKgRightArm)); | |||||
eightBodyFatBean.setFatMassRightBottom(String.valueOf(resultTwoLegs.htBodyfatKgRightLeg)); | |||||
// eightBodyFatBean.setFatMass(resultTwoLegs.htBodyfatKg); | |||||
eightBodyFatBean.setMuscleMassBody(String.valueOf(resultTwoLegs.htMuscleKgTrunk)); | |||||
eightBodyFatBean.setMuscleMassLeftTop(String.valueOf(resultTwoLegs.htMuscleKgLeftArm)); | |||||
eightBodyFatBean.setMuscleMassLeftBottom(String.valueOf(resultTwoLegs.htMuscleKgLeftLeg)); | |||||
eightBodyFatBean.setMuscleMassRightTop(String.valueOf(resultTwoLegs.htMuscleKgRightArm)); | |||||
eightBodyFatBean.setMuscleMassRightBottom(String.valueOf(resultTwoLegs.htMuscleKgRightLeg)); | |||||
// eightBodyFatBean.setMusleMass(resultTwoLegs.htMuscleKg); | |||||
// eightBodyFatBean.setStandardWeight(resultTwoLegs.htIdealWeightKg); | |||||
// eightBodyFatBean.setWeightWithoutFat(resultTwoLegs.htBodyfatFreeMass); | |||||
// eightBodyFatBean.setWeightControl((weight_kg - resultTwoLegs.htIdealWeightKg)); | |||||
// eightBodyFatBean.setFatLevel(HealthyStatusUtil.ObesitylevelsStatus(weight_kg, (float) resultTwoLegs.htIdealWeightKg)); | |||||
// double muscle = (resultTwoLegs.htMuscleKgLeftArm + resultTwoLegs.htMuscleKgLeftLeg + resultTwoLegs.htMuscleKgRightArm + resultTwoLegs.htMuscleKgRightLeg); | |||||
// eightBodyFatBean.setMusleMassLimbs(Adecimal(muscle / (height * height) * 10000)); | |||||
eightBodyFatBean.setAdcFoot((resultTwoLegs.htZLeftLeg + resultTwoLegs.htZRightLeg)); | |||||
eightBodyFatBean.setAdcHand((resultTwoLegs.htZLeftArm + resultTwoLegs.htZRightArm)); | |||||
eightBodyFatBean.setAdcLeftHand(resultTwoLegs.htZLeftArm); | |||||
eightBodyFatBean.setAdcRightHand(resultTwoLegs.htZRightArm); | |||||
eightBodyFatBean.setAdcLeftFoot(resultTwoLegs.htZLeftLeg); | |||||
eightBodyFatBean.setAdcRightFoot(resultTwoLegs.htZRightLeg); | |||||
eightBodyFatBean.setAdcLeftBody(resultTwoLegs.htZAllBody); | |||||
eightBodyFatBean.setAdcRightBody(resultTwoLegs.htZAllBody); | |||||
eightBodyFatBean.setAdcRightHandLeftFoot((resultTwoLegs.htZRightArm + resultTwoLegs.htZLeftLeg)); | |||||
eightBodyFatBean.setAdcLeftHandRightFoot((resultTwoLegs.htZLeftArm + resultTwoLegs.htZRightLeg)); | |||||
eightBodyFatBean.setAdcBody(resultTwoLegs.htZAllBody); | |||||
} | |||||
} | |||||
return eightBodyFatBean; | |||||
} | |||||
private float Adecimal(double data) { | |||||
return Float.parseFloat(String.format(Locale.US, "%.1f", data)); | |||||
} | |||||
} |
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||||
public class EightBodyFatBean { | |||||
private String weight; //体重, | |||||
private float bmi; //体质指数, | |||||
private float bfr; //体脂率, | |||||
private float sfr; //皮下脂肪率, | |||||
private float uvi; //内脏脂肪率, | |||||
private float rom; //肌肉率, | |||||
private float bmr; //基础代谢率, | |||||
private String bm; //骨骼质量, | |||||
private float vwc; //水含量, | |||||
private int bodyAge; //身体年龄, | |||||
private float pp; //蛋白率, | |||||
private double adcFoot; //双脚阻抗, | |||||
private double adcHand;//双手阻抗 | |||||
private double adcLeftHand; //左手阻抗 | |||||
private double adcRightHand; //右手阻抗 | |||||
private double adcLeftFoot; //左脚阻抗 | |||||
private double adcRightFoot; //右脚阻抗 | |||||
private double adcLeftBody; | |||||
private double adcRightBody; | |||||
private double adcRightHandLeftFoot; | |||||
private double adcLeftHandRightFoot; | |||||
private double adcBody; | |||||
private int arithmetic; | |||||
private int heartRate; | |||||
private String fatMassRightTop; //体脂-右上 | |||||
private String fatMassRightBottom; //体脂-右下 | |||||
private String fatMassLeftTop; //体脂-左上 | |||||
private String fatMassLeftBottom; //体脂-左下 | |||||
private String fatMassBody; //体脂-躯干 | |||||
private String muscleMassRightTop; //肌肉-右上 | |||||
private String muscleMassRightBottom; //肌肉-右下 | |||||
private String muscleMassLeftTop; //肌肉-左上 | |||||
private String muscleMassLeftBottom; //肌肉-左下 | |||||
private String muscleMassBody; //肌肉-躯干 | |||||
private String testAdc; | |||||
public String getTestAdc() { | |||||
return testAdc; | |||||
} | |||||
public void setTestAdc(String testAdc) { | |||||
this.testAdc = testAdc; | |||||
} | |||||
public String getWeight() { | |||||
return weight; | |||||
} | |||||
public void setWeight(String weight) { | |||||
this.weight = weight; | |||||
} | |||||
public float getBmi() { | |||||
return bmi; | |||||
} | |||||
public void setBmi(float bmi) { | |||||
this.bmi = bmi; | |||||
} | |||||
public float getBfr() { | |||||
return bfr; | |||||
} | |||||
public void setBfr(float bfr) { | |||||
this.bfr = bfr; | |||||
} | |||||
public float getSfr() { | |||||
return sfr; | |||||
} | |||||
public void setSfr(float sfr) { | |||||
this.sfr = sfr; | |||||
} | |||||
public float getUvi() { | |||||
return uvi; | |||||
} | |||||
public void setUvi(float uvi) { | |||||
this.uvi = uvi; | |||||
} | |||||
public float getRom() { | |||||
return rom; | |||||
} | |||||
public void setRom(float rom) { | |||||
this.rom = rom; | |||||
} | |||||
public float getBmr() { | |||||
return bmr; | |||||
} | |||||
public void setBmr(float bmr) { | |||||
this.bmr = bmr; | |||||
} | |||||
public String getBm() { | |||||
return bm; | |||||
} | |||||
public void setBm(String bm) { | |||||
this.bm = bm; | |||||
} | |||||
public float getVwc() { | |||||
return vwc; | |||||
} | |||||
public void setVwc(float vwc) { | |||||
this.vwc = vwc; | |||||
} | |||||
public int getBodyAge() { | |||||
return bodyAge; | |||||
} | |||||
public void setBodyAge(int bodyAge) { | |||||
this.bodyAge = bodyAge; | |||||
} | |||||
public float getPp() { | |||||
return pp; | |||||
} | |||||
public void setPp(float pp) { | |||||
this.pp = pp; | |||||
} | |||||
public double getAdcFoot() { | |||||
return adcFoot; | |||||
} | |||||
public void setAdcFoot(double adcFoot) { | |||||
this.adcFoot = adcFoot; | |||||
} | |||||
public double getAdcHand() { | |||||
return adcHand; | |||||
} | |||||
public void setAdcHand(double adcHand) { | |||||
this.adcHand = adcHand; | |||||
} | |||||
public double getAdcLeftHand() { | |||||
return adcLeftHand; | |||||
} | |||||
public void setAdcLeftHand(double adcLeftHand) { | |||||
this.adcLeftHand = adcLeftHand; | |||||
} | |||||
public double getAdcRightHand() { | |||||
return adcRightHand; | |||||
} | |||||
public void setAdcRightHand(double adcRightHand) { | |||||
this.adcRightHand = adcRightHand; | |||||
} | |||||
public double getAdcLeftFoot() { | |||||
return adcLeftFoot; | |||||
} | |||||
public void setAdcLeftFoot(double adcLeftFoot) { | |||||
this.adcLeftFoot = adcLeftFoot; | |||||
} | |||||
public double getAdcRightFoot() { | |||||
return adcRightFoot; | |||||
} | |||||
public void setAdcRightFoot(double adcRightFoot) { | |||||
this.adcRightFoot = adcRightFoot; | |||||
} | |||||
public double getAdcLeftBody() { | |||||
return adcLeftBody; | |||||
} | |||||
public void setAdcLeftBody(double adcLeftBody) { | |||||
this.adcLeftBody = adcLeftBody; | |||||
} | |||||
public double getAdcRightBody() { | |||||
return adcRightBody; | |||||
} | |||||
public void setAdcRightBody(double adcRightBody) { | |||||
this.adcRightBody = adcRightBody; | |||||
} | |||||
public double getAdcRightHandLeftFoot() { | |||||
return adcRightHandLeftFoot; | |||||
} | |||||
public void setAdcRightHandLeftFoot(double adcRightHandLeftFoot) { | |||||
this.adcRightHandLeftFoot = adcRightHandLeftFoot; | |||||
} | |||||
public double getAdcLeftHandRightFoot() { | |||||
return adcLeftHandRightFoot; | |||||
} | |||||
public void setAdcLeftHandRightFoot(double adcLeftHandRightFoot) { | |||||
this.adcLeftHandRightFoot = adcLeftHandRightFoot; | |||||
} | |||||
public double getAdcBody() { | |||||
return adcBody; | |||||
} | |||||
public void setAdcBody(double adcBody) { | |||||
this.adcBody = adcBody; | |||||
} | |||||
public String getFatMassRightTop() { | |||||
return fatMassRightTop; | |||||
} | |||||
public void setFatMassRightTop(String fatMassRightTop) { | |||||
this.fatMassRightTop = fatMassRightTop; | |||||
} | |||||
public String getFatMassRightBottom() { | |||||
return fatMassRightBottom; | |||||
} | |||||
public void setFatMassRightBottom(String fatMassRightBottom) { | |||||
this.fatMassRightBottom = fatMassRightBottom; | |||||
} | |||||
public String getFatMassLeftTop() { | |||||
return fatMassLeftTop; | |||||
} | |||||
public void setFatMassLeftTop(String fatMassLeftTop) { | |||||
this.fatMassLeftTop = fatMassLeftTop; | |||||
} | |||||
public String getFatMassLeftBottom() { | |||||
return fatMassLeftBottom; | |||||
} | |||||
public void setFatMassLeftBottom(String fatMassLeftBottom) { | |||||
this.fatMassLeftBottom = fatMassLeftBottom; | |||||
} | |||||
public String getFatMassBody() { | |||||
return fatMassBody; | |||||
} | |||||
public void setFatMassBody(String fatMassBody) { | |||||
this.fatMassBody = fatMassBody; | |||||
} | |||||
public String getMuscleMassRightTop() { | |||||
return muscleMassRightTop; | |||||
} | |||||
public void setMuscleMassRightTop(String muscleMassRightTop) { | |||||
this.muscleMassRightTop = muscleMassRightTop; | |||||
} | |||||
public String getMuscleMassRightBottom() { | |||||
return muscleMassRightBottom; | |||||
} | |||||
public void setMuscleMassRightBottom(String muscleMassRightBottom) { | |||||
this.muscleMassRightBottom = muscleMassRightBottom; | |||||
} | |||||
public String getMuscleMassLeftTop() { | |||||
return muscleMassLeftTop; | |||||
} | |||||
public void setMuscleMassLeftTop(String muscleMassLeftTop) { | |||||
this.muscleMassLeftTop = muscleMassLeftTop; | |||||
} | |||||
public String getMuscleMassLeftBottom() { | |||||
return muscleMassLeftBottom; | |||||
} | |||||
public void setMuscleMassLeftBottom(String muscleMassLeftBottom) { | |||||
this.muscleMassLeftBottom = muscleMassLeftBottom; | |||||
} | |||||
public String getMuscleMassBody() { | |||||
return muscleMassBody; | |||||
} | |||||
public void setMuscleMassBody(String muscleMassBody) { | |||||
this.muscleMassBody = muscleMassBody; | |||||
} | |||||
public int getArithmetic() { | |||||
return arithmetic; | |||||
} | |||||
public void setArithmetic(int arithmetic) { | |||||
this.arithmetic = arithmetic; | |||||
} | |||||
public void setHeartRate(int heartRate) { | |||||
this.heartRate = heartRate; | |||||
} | |||||
public int getHeartRate() { | |||||
return heartRate; | |||||
} | |||||
@Override | |||||
public String toString() { | |||||
return "EightBodyFatBean{" + "weight='" + weight + '\'' + ", bmi=" + bmi + ", bfr=" + bfr + ", sfr=" + sfr + ", uvi=" + uvi + ", rom=" + rom + ", bmr=" + bmr + ", bm='" + bm + '\'' + ", " + | |||||
"vwc=" + vwc + ", bodyAge=" + bodyAge + ", pp=" + pp + ", adcFoot=" + adcFoot + ", adcHand=" + adcHand + ", adcLeftHand=" + adcLeftHand + ", adcRightHand=" + adcRightHand + ", " + | |||||
"adcLeftFoot=" + adcLeftFoot + ", adcRightFoot=" + adcRightFoot + ", adcLeftBody=" + adcLeftBody + ", adcRightBody=" + adcRightBody + ", adcRightHandLeftFoot=" + adcRightHandLeftFoot + ", adcLeftHandRightFoot=" + adcLeftHandRightFoot + ", adcBody=" + adcBody + ", arithmetic=" + arithmetic + ", heartRate=" + heartRate + ", fatMassRightTop='" + fatMassRightTop + '\'' + ", fatMassRightBottom='" + fatMassRightBottom + '\'' + ", fatMassLeftTop='" + fatMassLeftTop + '\'' + ", fatMassLeftBottom='" + fatMassLeftBottom + '\'' + ", fatMassBody='" + fatMassBody + '\'' + ", muscleMassRightTop='" + muscleMassRightTop + '\'' + ", muscleMassRightBottom='" + muscleMassRightBottom + '\'' + ", muscleMassLeftTop='" + muscleMassLeftTop + '\'' + ", muscleMassLeftBottom='" + muscleMassLeftBottom + '\'' + ", muscleMassBody='" + muscleMassBody + '\'' + ", testAdc='" + testAdc + '\'' + '}'; | |||||
} | |||||
} |
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.RadioButton; | import android.widget.RadioButton; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.bean.SupportUnitBean; | import com.pingwang.bluetoothlib.bean.SupportUnitBean; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | import com.pingwang.bluetoothlib.listener.OnCallbackBle; | ||||
import java.util.List; | import java.util.List; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.Nullable; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.EightBodyFatAlgorithms; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.EightBodyFatBean; | |||||
import cn.net.aicare.modulelibrary.module.EightBodyfatscale.EightBodyFatBleDeviceData; | import cn.net.aicare.modulelibrary.module.EightBodyfatscale.EightBodyFatBleDeviceData; | ||||
import cn.net.aicare.modulelibrary.module.EightBodyfatscale.EightBodyFatUtil; | import cn.net.aicare.modulelibrary.module.EightBodyfatscale.EightBodyFatUtil; | ||||
public void onServiceSuccess() { | public void onServiceSuccess() { | ||||
loglist.add(0, "绑定服务成功"); | loglist.add(0, "绑定服务成功"); | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | ||||
if (bleDevice != null) { | if (bleDevice != null) { | ||||
mEightBodyFatBleDeviceData = new EightBodyFatBleDeviceData(bleDevice); | mEightBodyFatBleDeviceData = new EightBodyFatBleDeviceData(bleDevice); | ||||
@Override | @Override | ||||
public void unbindServices() { | public void unbindServices() { | ||||
if (mBluetoothService!=null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | } | ||||
@Override | @Override |
import android.widget.EditText; | import android.widget.EditText; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | ||||
import com.pingwang.bluetoothlib.device.SendBleBean; | import com.pingwang.bluetoothlib.device.SendBleBean; | ||||
import com.pingwang.bluetoothlib.utils.BleDensityUtil; | import com.pingwang.bluetoothlib.utils.BleDensityUtil; | ||||
import com.pingwang.bluetoothlib.utils.BleLog; | import com.pingwang.bluetoothlib.utils.BleLog; | ||||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | import com.pingwang.bluetoothlib.utils.BleStrUtils; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.List; | import java.util.List; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | |||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.height.HeightDeviceData; | import cn.net.aicare.modulelibrary.module.height.HeightDeviceData; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import com.pingwang.bluetoothlib.bean.SupportUnitBean; | import com.pingwang.bluetoothlib.bean.SupportUnitBean; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | import com.pingwang.bluetoothlib.listener.OnCallbackBle; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.AllUnitUtils; | |||||
import java.lang.ref.WeakReference; | import java.lang.ref.WeakReference; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.List; | import java.util.List; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | |||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.algorithmutil.AlgorithmUtil; | |||||
import cn.net.aicare.algorithmutil.BodyFatData; | |||||
import cn.net.aicare.modulelibrary.module.HeightWeightScale.HeightBodyFatBleData; | import cn.net.aicare.modulelibrary.module.HeightWeightScale.HeightBodyFatBleData; | ||||
import cn.net.aicare.modulelibrary.module.HeightWeightScale.HeightBodyFatBleUntils; | import cn.net.aicare.modulelibrary.module.HeightWeightScale.HeightBodyFatBleUntils; | ||||
import cn.net.aicare.modulelibrary.module.HeightWeightScale.HeightBodyFatUser; | |||||
import cn.net.aicare.modulelibrary.module.utils.AicareBleConfig; | |||||
/** | /** | ||||
* 身高体脂秤 | * 身高体脂秤 | ||||
private int currentVoice = 1; | private int currentVoice = 1; | ||||
private int selectVoice = 1; | private int selectVoice = 1; | ||||
private HeightBodyFatUser mHeightBodyFatUser; | |||||
@Override | @Override | ||||
public void onServiceSuccess() { | public void onServiceSuccess() { | ||||
mBluetoothService.setOnCallback(this); | |||||
logList.add(0, "绑定服务成功"); | logList.add(0, "绑定服务成功"); | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | ||||
if (bleDevice != null) { | if (bleDevice != null) { | ||||
HeightBodyFatBleData.init(bleDevice); | HeightBodyFatBleData.init(bleDevice); | ||||
@Override | @Override | ||||
public void unbindServices() { | public void unbindServices() { | ||||
if (mBluetoothService!=null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | } | ||||
logList.add(0, "设置声音结果:" + resultStr); | logList.add(0, "设置声音结果:" + resultStr); | ||||
break; | break; | ||||
default:break; | |||||
} | } | ||||
listAdapter.notifyDataSetChanged(); | listAdapter.notifyDataSetChanged(); | ||||
mMHandler.removeMessages(FINISH); | mMHandler.removeMessages(FINISH); | ||||
mMHandler.sendEmptyMessageDelayed(FINISH, 40000); | mMHandler.sendEmptyMessageDelayed(FINISH, 40000); | ||||
} | } | ||||
if (mHeightBodyFatUser!=null) { | |||||
mHeightBodyFatUser.setWeight(weight); | |||||
mHeightBodyFatUser.setDecimals(decimals); | |||||
mHeightBodyFatUser.setUnit(unit); | |||||
} | |||||
} | } | ||||
mMHandler.removeMessages(ADC); | mMHandler.removeMessages(ADC); | ||||
logList.add(0, "阻抗数据 模式:" + workMode + " 测量状态: " + status + "\n 阻抗类型: " + adcType | logList.add(0, "阻抗数据 模式:" + workMode + " 测量状态: " + status + "\n 阻抗类型: " + adcType | ||||
+ " 阻抗: " + adc + " 算法位: " + arithmetic); | + " 阻抗: " + adc + " 算法位: " + arithmetic); | ||||
// arithmetic | |||||
if (mHeightBodyFatUser != null && arithmetic != 0) { | |||||
int sex = mHeightBodyFatUser.getSex(); | |||||
if (sex == 0) { | |||||
sex = 2; | |||||
} | |||||
String weightToKg = AllUnitUtils.getWeightToKg(mHeightBodyFatUser.getUnit(), String.valueOf(mHeightBodyFatUser.getWeight()), mHeightBodyFatUser.getDecimals()); | |||||
BodyFatData bodyFatData = AicareBleConfig.getBodyFatData(AlgorithmUtil.AlgorithmType.TYPE_AICARE, sex, mHeightBodyFatUser.getAge(), Double.parseDouble(weightToKg), | |||||
mHeightBodyFatUser.getHeight(), mHeightBodyFatUser.getAdc()); | |||||
logList.add( "体脂数据:" + "\n 体脂率: " + bodyFatData.getBfr() + " 皮下脂肪: " + bodyFatData.getSfr() + | |||||
"\n 内脏脂肪: " + bodyFatData.getUvi() + " 肌肉率: " + bodyFatData.getRom() + | |||||
"\n 基础代谢率: " + bodyFatData.getBmr() + " 身体年龄:" + bodyFatData.getBodyAge()+ | |||||
"\n 水分: " + bodyFatData.getVwc() + " 蛋白率:" + bodyFatData.getPp()+ | |||||
"\n BMI: " + bodyFatData.getBmi() + " 骨量:" + bodyFatData.getBm() | |||||
); | |||||
} | |||||
listAdapter.notifyDataSetChanged(); | listAdapter.notifyDataSetChanged(); | ||||
case R.id.girl: | case R.id.girl: | ||||
logList.add(0, "下用户 女 18岁 165cm :" + selectWUnit); | logList.add(0, "下用户 女 18岁 165cm :" + selectWUnit); | ||||
listAdapter.notifyDataSetChanged(); | listAdapter.notifyDataSetChanged(); | ||||
HeightBodyFatBleData.getInstance().sendData(HeightBodyFatBleUntils.setUser(0, 18, 165)); | |||||
mHeightBodyFatUser=new HeightBodyFatUser(0,18,165,0,0); | |||||
HeightBodyFatBleData.getInstance().sendData(HeightBodyFatBleUntils.setUser(mHeightBodyFatUser.getSex(), mHeightBodyFatUser.getAge(), mHeightBodyFatUser.getHeight())); | |||||
mMHandler.removeMessages(SETUSER); | mMHandler.removeMessages(SETUSER); | ||||
mMHandler.sendEmptyMessageDelayed(SETUSER, 3000); | mMHandler.sendEmptyMessageDelayed(SETUSER, 3000); | ||||
break; | break; | ||||
case R.id.man: | case R.id.man: | ||||
logList.add(0, "下用户 男 28岁 170cm :" + selectWUnit); | logList.add(0, "下用户 男 28岁 170cm :" + selectWUnit); | ||||
listAdapter.notifyDataSetChanged(); | listAdapter.notifyDataSetChanged(); | ||||
HeightBodyFatBleData.getInstance().sendData(HeightBodyFatBleUntils.setUser(1, 28, 170)); | |||||
mHeightBodyFatUser=new HeightBodyFatUser(1,28,170,0,0); | |||||
HeightBodyFatBleData.getInstance().sendData(HeightBodyFatBleUntils.setUser(mHeightBodyFatUser.getSex(), mHeightBodyFatUser.getAge(), mHeightBodyFatUser.getHeight())); | |||||
mMHandler.removeMessages(SETUSER); | mMHandler.removeMessages(SETUSER); | ||||
mMHandler.sendEmptyMessageDelayed(SETUSER, 3000); | mMHandler.sendEmptyMessageDelayed(SETUSER, 3000); | ||||
import android.view.View; | import android.view.View; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import androidx.appcompat.app.ActionBar; | |||||
import androidx.appcompat.app.AppCompatActivity; | |||||
import androidx.core.app.ActivityCompat; | |||||
import androidx.core.content.ContextCompat; | |||||
import com.besthealth.bhBodyComposition120.BhBodyComposition; | import com.besthealth.bhBodyComposition120.BhBodyComposition; | ||||
import com.pingwang.bluetoothlib.AILinkBleManager; | |||||
import com.pingwang.bluetoothlib.AILinkSDK; | |||||
import com.pingwang.bluetoothlib.bean.AilinkLicenseBean; | |||||
import com.pingwang.bluetoothlib.utils.BleLog; | import com.pingwang.bluetoothlib.utils.BleLog; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.broadcast_nutrition.BroadNutritionActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.broadcast_nutrition.BroadNutritionActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.broadcast_weight_sacle.BroadcastWeightScaleActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.broadcast_weight_sacle.BroadcastWeightScaleActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.leaone_broadcast.LeaOneBroadcastActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.leaone_broadcast.LeaOneBroadcastActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.ropeskipping.RopeSkippingSetActivity; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.AppStart; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.AppStart; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.L; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.L; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.SP; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.SP; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import androidx.appcompat.app.ActionBar; | |||||
import androidx.appcompat.app.AppCompatActivity; | |||||
import androidx.core.app.ActivityCompat; | |||||
import androidx.core.content.ContextCompat; | |||||
public class MainActivity extends AppCompatActivity { | public class MainActivity extends AppCompatActivity { | ||||
int bodyComposition = new BhBodyComposition().getBodyComposition(); | int bodyComposition = new BhBodyComposition().getBodyComposition(); | ||||
L.i("bodyComposition:" + bodyComposition); | L.i("bodyComposition:" + bodyComposition); | ||||
// Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:10086")); | |||||
// Method setDefaultSim = null; | |||||
// try { | |||||
// setDefaultSim = TelephonyManager.class.getDeclaredMethod("setDefaultSim", Context.class, int.class, int.class); | |||||
// setDefaultSim.invoke(null, this, 0, 0); | |||||
// } catch (NoSuchMethodException e) { | |||||
// e.printStackTrace(); | |||||
// } catch (IllegalAccessException e) { | |||||
// e.printStackTrace(); | |||||
// } catch (InvocationTargetException e) { | |||||
// e.printStackTrace(); | |||||
// } | |||||
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |||||
// startActivity(intent); | |||||
// Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:10086")); | |||||
// Method setDefaultSim = null; | |||||
// try { | |||||
// setDefaultSim = TelephonyManager.class.getDeclaredMethod("setDefaultSim", Context.class, int.class, int.class); | |||||
// setDefaultSim.invoke(null, this, 0, 0); | |||||
// } catch (NoSuchMethodException e) { | |||||
// e.printStackTrace(); | |||||
// } catch (IllegalAccessException e) { | |||||
// e.printStackTrace(); | |||||
// } catch (InvocationTargetException e) { | |||||
// e.printStackTrace(); | |||||
// } | |||||
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |||||
// startActivity(intent); | |||||
} | } | ||||
MyListener listener = new MyListener(); | 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); | |||||
// Button btn_weightScale = findViewById(R.id.btn_lock); | |||||
// Button btn_ble_test = findViewById(R.id.btn_ble_test); | |||||
// Button btnConnectTest = findViewById(R.id.btnConnectTest); | |||||
// Button btn_ad_weight = findViewById(R.id.btn_ad_weight); | |||||
// Button btn_ble_weight = findViewById(R.id.btn_ble_weight); | |||||
// Button btn_wifi_ble_tooth = findViewById(R.id.btn_wifi_ble_tooth); | |||||
// Button wifi_config = findViewById(R.id.wifi_config); | |||||
// Button eight_scale = findViewById(R.id.eight_scale); | |||||
// Button btn_ota = findViewById(R.id.btn_ota); | |||||
// Button btn_wristband = findViewById(R.id.btn_wristband); | |||||
// Button glucometer = findViewById(R.id.glucometer); | |||||
// Button btn_broadcast_scale = findViewById(R.id.btn_broadcast_scale); | |||||
// Button btn_broadcast_blood_oxygen = findViewById(R.id.btn_broadcast_blood_oxygen); | |||||
// Button btn_smart_mask = findViewById(R.id.btn_smart_mask); | |||||
// Button btn_bld = findViewById(R.id.btn_bld); | |||||
// Button btn_bleBo = findViewById(R.id.btn_bleBo); | |||||
// Button btn_coffeeScale = findViewById(R.id.btn_coffeeScale); | |||||
// Button btn_scooter = findViewById(R.id.btn_scooter); | |||||
// Button btn_shareCharger = findViewById(R.id.btn_shareCharger); | |||||
// Button btn_transmission = findViewById(R.id.btn_transmission); | |||||
// Button btn_wifi_ble_weight = findViewById(R.id.btn_wifi_ble_weight); | |||||
// Button btn_baby_body_fat = findViewById(R.id.btn_baby_body_fat); | |||||
// 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); | |||||
// Button btn_weightScale = findViewById(R.id.btn_lock); | |||||
// Button btn_ble_test = findViewById(R.id.btn_ble_test); | |||||
// Button btnConnectTest = findViewById(R.id.btnConnectTest); | |||||
// Button btn_ad_weight = findViewById(R.id.btn_ad_weight); | |||||
// Button btn_ble_weight = findViewById(R.id.btn_ble_weight); | |||||
// Button btn_wifi_ble_tooth = findViewById(R.id.btn_wifi_ble_tooth); | |||||
// Button wifi_config = findViewById(R.id.wifi_config); | |||||
// Button eight_scale = findViewById(R.id.eight_scale); | |||||
// Button btn_ota = findViewById(R.id.btn_ota); | |||||
// Button btn_wristband = findViewById(R.id.btn_wristband); | |||||
// Button glucometer = findViewById(R.id.glucometer); | |||||
// Button btn_broadcast_scale = findViewById(R.id.btn_broadcast_scale); | |||||
// Button btn_broadcast_blood_oxygen = findViewById(R.id.btn_broadcast_blood_oxygen); | |||||
// Button btn_smart_mask = findViewById(R.id.btn_smart_mask); | |||||
// Button btn_bld = findViewById(R.id.btn_bld); | |||||
// Button btn_bleBo = findViewById(R.id.btn_bleBo); | |||||
// Button btn_coffeeScale = findViewById(R.id.btn_coffeeScale); | |||||
// Button btn_scooter = findViewById(R.id.btn_scooter); | |||||
// Button btn_shareCharger = findViewById(R.id.btn_shareCharger); | |||||
// Button btn_transmission = findViewById(R.id.btn_transmission); | |||||
// Button btn_wifi_ble_weight = findViewById(R.id.btn_wifi_ble_weight); | |||||
// Button btn_baby_body_fat = findViewById(R.id.btn_baby_body_fat); | |||||
mList.add(findViewById(R.id.btn_sphy)); | mList.add(findViewById(R.id.btn_sphy)); | ||||
mList.add(findViewById(R.id.btn_tempgun)); | mList.add(findViewById(R.id.btn_tempgun)); | ||||
mList.add(findViewById(R.id.btn_temp)); | mList.add(findViewById(R.id.btn_temp)); | ||||
mList.add(findViewById(R.id.btn_baby)); | mList.add(findViewById(R.id.btn_baby)); | ||||
mList.add(findViewById(R.id.btn_height)); | mList.add(findViewById(R.id.btn_height)); | ||||
mList.add(findViewById(R.id.btn_ble)); | mList.add(findViewById(R.id.btn_ble)); | ||||
// mList.add(findViewById(R.id.btn_lock)); | |||||
// mList.add(findViewById(R.id.btn_lock)); | |||||
mList.add(findViewById(R.id.btn_ble_test)); | mList.add(findViewById(R.id.btn_ble_test)); | ||||
mList.add(findViewById(R.id.btnConnectTest)); | mList.add(findViewById(R.id.btnConnectTest)); | ||||
mList.add(findViewById(R.id.btn_ad_weight)); | mList.add(findViewById(R.id.btn_ad_weight)); | ||||
mList.add(findViewById(R.id.btn_body_scale_4g)); | mList.add(findViewById(R.id.btn_body_scale_4g)); | ||||
mList.add(findViewById(R.id.btn_scooter_cm02)); | mList.add(findViewById(R.id.btn_scooter_cm02)); | ||||
mList.add(findViewById(R.id.btn_temp_instrument)); | mList.add(findViewById(R.id.btn_temp_instrument)); | ||||
mList.add(findViewById(R.id.btn_leap_watch)); | |||||
mList.add(findViewById(R.id.btn_public_ble_network)); | mList.add(findViewById(R.id.btn_public_ble_network)); | ||||
mList.add(findViewById(R.id.btn_rope_skipping_set_mode)); | mList.add(findViewById(R.id.btn_rope_skipping_set_mode)); | ||||
mList.add(findViewById(R.id.btn_air_detector)); | mList.add(findViewById(R.id.btn_air_detector)); | ||||
mList.add(findViewById(R.id.btn_meat_probe_charger)); | mList.add(findViewById(R.id.btn_meat_probe_charger)); | ||||
mList.add(findViewById(R.id.btn_weight_scale)); | mList.add(findViewById(R.id.btn_weight_scale)); | ||||
mList.add(findViewById(R.id.btn_broadcast_scale_weight)); | mList.add(findViewById(R.id.btn_broadcast_scale_weight)); | ||||
mList.add(findViewById(R.id.btn_meat_probe)); | |||||
for (View view : mList) { | for (View view : mList) { | ||||
view.setOnClickListener(listener); | view.setOnClickListener(listener); | ||||
} | } | ||||
startActivity(new Intent(mContext, RopeSkippingSetActivity.class)); | startActivity(new Intent(mContext, RopeSkippingSetActivity.class)); | ||||
// Intent intent = new Intent(); | |||||
// intent.setAction("android.media.action.STILL_IMAGE_CAMERA"); | |||||
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |||||
// startActivity(intent); | |||||
// | |||||
// mHandler.postDelayed(new Runnable() { | |||||
// @Override | |||||
// public void run() { | |||||
// try { | |||||
// L.i("按下音量+ start"); | |||||
// String keyCommand = "input keyevent " + KeyEvent.KEYCODE_VOLUME_UP; | |||||
// Runtime runtime = Runtime.getRuntime(); | |||||
// Process proc = runtime.exec(keyCommand); | |||||
// L.i("按下音量+ stop"+proc.toString()); | |||||
// } catch (IOException e) { | |||||
// e.printStackTrace(); | |||||
// } | |||||
// | |||||
// } | |||||
// }, 5000); | |||||
// Intent intent = new Intent(); | |||||
// intent.setAction("android.media.action.STILL_IMAGE_CAMERA"); | |||||
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |||||
// startActivity(intent); | |||||
// | |||||
// mHandler.postDelayed(new Runnable() { | |||||
// @Override | |||||
// public void run() { | |||||
// try { | |||||
// L.i("按下音量+ start"); | |||||
// String keyCommand = "input keyevent " + KeyEvent.KEYCODE_VOLUME_UP; | |||||
// Runtime runtime = Runtime.getRuntime(); | |||||
// Process proc = runtime.exec(keyCommand); | |||||
// L.i("按下音量+ stop"+proc.toString()); | |||||
// } catch (IOException e) { | |||||
// e.printStackTrace(); | |||||
// } | |||||
// | |||||
// } | |||||
// }, 5000); | |||||
} | } | ||||
}); | }); | ||||
// AILinkBleManager.getInstance().init(mContext, new AILinkBleManager.onInitListener() { | |||||
// @Override | |||||
// public void onInitSuccess() { | |||||
// L.i("初始化成功"); | |||||
// AILinkBleManager.getInstance().startScan(1000); | |||||
// AILinkBleManager.getInstance().setOnCallbackBle(new OnCallbackBle() { | |||||
// @Override | |||||
// public void onScanning(BleValueBean data) { | |||||
// L.i("当前搜索到的设备:"+data.getName()+" mac="+data.getMac()); | |||||
// AILinkBleManager.getInstance().stopScan(); | |||||
// AILinkBleManager.getInstance().connectDevice(data); | |||||
// } | |||||
// | |||||
// @Override | |||||
// public void onServicesDiscovered(String mac) { | |||||
// L.i("连接成功:"+mac); | |||||
// } | |||||
// }); | |||||
// | |||||
// } | |||||
// | |||||
// @Override | |||||
// public void onInitFailure() { | |||||
// L.i("初始化失败"); | |||||
// } | |||||
// }); | |||||
// AILinkBleManager.getInstance().init(mContext, new AILinkBleManager.onInitListener() { | |||||
// @Override | |||||
// public void onInitSuccess() { | |||||
// L.i("初始化成功"); | |||||
// AILinkBleManager.getInstance().startScan(1000); | |||||
// AILinkBleManager.getInstance().setOnCallbackBle(new OnCallbackBle() { | |||||
// @Override | |||||
// public void onScanning(BleValueBean data) { | |||||
// L.i("当前搜索到的设备:"+data.getName()+" mac="+data.getMac()); | |||||
// AILinkBleManager.getInstance().stopScan(); | |||||
// AILinkBleManager.getInstance().connectDevice(data); | |||||
// } | |||||
// | |||||
// @Override | |||||
// public void onServicesDiscovered(String mac) { | |||||
// L.i("连接成功:"+mac); | |||||
// } | |||||
// }); | |||||
// | |||||
// } | |||||
// | |||||
// @Override | |||||
// public void onInitFailure() { | |||||
// L.i("初始化失败"); | |||||
// } | |||||
// }); | |||||
} | } | ||||
protected void initData() { | protected void initData() { | ||||
initPermissions(); | initPermissions(); | ||||
List<AilinkLicenseBean> list = new ArrayList<>(); | |||||
list.add(new AilinkLicenseBean(0x2F, 0x03, 0x09)); | |||||
AILinkSDK.getInstance().initLicense(list); | |||||
} | } | ||||
protected void initView() { | protected void initView() { | ||||
BleLog.init("", "", true); | |||||
BleLog.init(true); | |||||
//connectDevice(BleValueBean bleValueBean);连接的时候需要传广播对象,否则返回的cid,vid,pid始终都是0 | //connectDevice(BleValueBean bleValueBean);连接的时候需要传广播对象,否则返回的cid,vid,pid始终都是0 | ||||
// AILinkSDK.getInstance().init(getApplication(), new AILinkSDK.OnNewKeyListener() { | |||||
// @Override | |||||
// public boolean onNewKey(int cid, int vid, int pid) { | |||||
// if (vid == 1) { | |||||
// return true; | |||||
// } | |||||
// return false; | |||||
// } | |||||
// }); | |||||
//每次连接之前都要设置一次,设置一次之后就一直有效 | |||||
//sdk | //sdk | ||||
// AILinkBleManager.getInstance().init(mContext, new AILinkBleManager.onInitListener() { | |||||
// @Override | |||||
// public void onInitSuccess() { | |||||
// AILinkBleManager.getInstance().startScan(0); | |||||
// } | |||||
// | |||||
// @Override | |||||
// public void onInitFailure() { | |||||
// | |||||
// } | |||||
// }); | |||||
// BleConfig.addVendorID(0xac05); | |||||
AILinkSDK.getInstance().init(mContext); | |||||
AILinkBleManager.getInstance().init(mContext, new AILinkBleManager.onInitListener() { | |||||
@Override | |||||
public void onInitSuccess() { | |||||
AILinkBleManager.getInstance().startScan(0); | |||||
} | |||||
@Override | |||||
public void onInitFailure() { | |||||
} | |||||
}); | |||||
SP.init(this); | SP.init(this); | ||||
} | } | ||||
private class MyListener implements View.OnClickListener { | private class MyListener implements View.OnClickListener { | ||||
@Override | @Override | ||||
public void onClick(View v) { | public void onClick(View v) { | ||||
// boolean onClick= initPermissions(); | |||||
// if (!onClick){ | |||||
// return; | |||||
// } | |||||
// boolean onClick= initPermissions(); | |||||
// if (!onClick){ | |||||
// return; | |||||
// } | |||||
int type = 0; | int type = 0; | ||||
switch (v.getId()) { | switch (v.getId()) { | ||||
case R.id.btn_height: | case R.id.btn_height: | ||||
type = BleDeviceConfig.HEIGHT_METER; | type = BleDeviceConfig.HEIGHT_METER; | ||||
break; | break; | ||||
case R.id.btn_lock: | |||||
type = BleDeviceConfig.SMART_LOCK; | |||||
break; | |||||
case R.id.btn_ad_weight: | case R.id.btn_ad_weight: | ||||
type = BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_AD; | type = BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_AD; | ||||
break; | break; | ||||
case R.id.btn_bleBo: | case R.id.btn_bleBo: | ||||
type = BleDeviceConfig.BLE_BOOLD_OXYGEN; | type = BleDeviceConfig.BLE_BOOLD_OXYGEN; | ||||
break; | break; | ||||
// case R.id.btn_bld: | |||||
// type = BleDeviceConfig.BLD_WEIGHT; | |||||
// break; | |||||
// case R.id.btn_bld: | |||||
// type = BleDeviceConfig.BLD_WEIGHT; | |||||
// break; | |||||
case R.id.btn_ble: | case R.id.btn_ble: | ||||
type = -1; | type = -1; | ||||
break; | break; | ||||
Intent bodyScaleIntent = new Intent(MainActivity.this, BodyScale4GActivity.class); | Intent bodyScaleIntent = new Intent(MainActivity.this, BodyScale4GActivity.class); | ||||
startActivity(bodyScaleIntent); | startActivity(bodyScaleIntent); | ||||
return; | return; | ||||
case R.id.btn_leap_watch: | |||||
// 芯一代手表 | |||||
type = BleDeviceConfig.LEAP_WATCH; | |||||
break; | |||||
case R.id.btn_public_ble_network: | case R.id.btn_public_ble_network: | ||||
// BLE通用配网 | // BLE通用配网 | ||||
type = BleDeviceConfig.PUBLIC_BLE_NETWORK; | type = BleDeviceConfig.PUBLIC_BLE_NETWORK; | ||||
//体重秤 | //体重秤 | ||||
type = BleDeviceConfig.WEIGHT_SCALE; | type = BleDeviceConfig.WEIGHT_SCALE; | ||||
break; | break; | ||||
case R.id.btn_meat_probe: | |||||
// 食物探针 | |||||
type = BleDeviceConfig.MEAT_PROBE; | |||||
break; | |||||
case R.id.btn_mqtt: | case R.id.btn_mqtt: | ||||
return; | return; | ||||
} | } | ||||
//-----------------------权限---------------------------------------- | |||||
//-----------------------权限---------------------------------------- | |||||
/** | /** | ||||
* 需要申请的权限 | * 需要申请的权限 | ||||
*/ | */ | ||||
private String[] LOCATION_PERMISSION = new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE}; | private String[] LOCATION_PERMISSION = new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE}; | ||||
private final static String[] BLUETOOTH_PERMISSION = new String[]{Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_ADVERTISE, Manifest.permission.BLUETOOTH_CONNECT}; | |||||
/** | /** | ||||
* 权限请求返回 | * 权限请求返回 | ||||
*/ | */ | ||||
onPermissionsOk(); | onPermissionsOk(); | ||||
return; | return; | ||||
} | } | ||||
if (ContextCompat.checkSelfPermission(this, LOCATION_PERMISSION[0]) != PackageManager.PERMISSION_GRANTED) { | |||||
ActivityCompat.requestPermissions(this, LOCATION_PERMISSION, PERMISSION); | |||||
} else { | |||||
boolean bleStatus = AppStart.isLocServiceEnable(mContext); | |||||
if (!bleStatus) { | |||||
//没有开启定位服务 | |||||
mHintDataDialog = HintDataDialogFragment.newInstance().setTitle("提示", 0).setCancel("取消", 0).setOk("确定", 0).setContent("请求开启定位服务", true) | |||||
.setOnDialogListener(new HintDataDialogFragment.onDialogListener() { | |||||
@Override | |||||
public void onSucceedListener(View v) { | |||||
startLocationActivity(); | |||||
} | |||||
}); | |||||
mHintDataDialog.show(getSupportFragmentManager()); | |||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { | |||||
if (ContextCompat.checkSelfPermission(this, LOCATION_PERMISSION[0]) != PackageManager.PERMISSION_GRANTED) { | |||||
ActivityCompat.requestPermissions(this, LOCATION_PERMISSION, PERMISSION); | |||||
} else { | } else { | ||||
onPermissionsOk(); | |||||
boolean bleStatus = AppStart.isLocServiceEnable(mContext); | |||||
if (!bleStatus) { | |||||
//没有开启定位服务 | |||||
mHintDataDialog = HintDataDialogFragment.newInstance().setTitle("提示", 0).setCancel("取消", 0).setOk("确定", 0).setContent("请求开启定位服务", true).setOnDialogListener(new HintDataDialogFragment.onDialogListener() { | |||||
@Override | |||||
public void onSucceedListener(View v) { | |||||
startLocationActivity(); | |||||
} | |||||
}); | |||||
mHintDataDialog.show(getSupportFragmentManager()); | |||||
} else { | |||||
onPermissionsOk(); | |||||
} | |||||
} | |||||
} else { | |||||
if (ContextCompat.checkSelfPermission(this, BLUETOOTH_PERMISSION[0]) != PackageManager.PERMISSION_GRANTED) { | |||||
ActivityCompat.requestPermissions(this, BLUETOOTH_PERMISSION, PERMISSION); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
//请求权限被拒绝 | //请求权限被拒绝 | ||||
if (requestCode != PERMISSION) | if (requestCode != PERMISSION) | ||||
return; | return; | ||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | |||||
initPermissions(); | |||||
} else { | |||||
if (ActivityCompat.shouldShowRequestPermissionRationale(this, LOCATION_PERMISSION[0])) { | |||||
//权限请求失败,但未选中“不再提示”选项,再次请求 | |||||
ActivityCompat.requestPermissions(this, LOCATION_PERMISSION, PERMISSION); | |||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { | |||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | |||||
initPermissions(); | |||||
} else { | } else { | ||||
//权限请求失败,选中“不再提示”选项 | |||||
mHintDataDialog = HintDataDialogFragment.newInstance().setTitle("提示", 0).setCancel("取消", 0).setOk("确定", 0).setContent("请求开启定位权限", true) | |||||
.setOnDialogListener(new HintDataDialogFragment.onDialogListener() { | |||||
@Override | |||||
public void onSucceedListener(View v) { | |||||
AppStart.startUseSetActivity(mContext); | |||||
} | |||||
}); | |||||
mHintDataDialog.show(getSupportFragmentManager()); | |||||
if (ActivityCompat.shouldShowRequestPermissionRationale(this, LOCATION_PERMISSION[0])) { | |||||
//权限请求失败,但未选中“不再提示”选项,再次请求 | |||||
ActivityCompat.requestPermissions(this, LOCATION_PERMISSION, PERMISSION); | |||||
} else { | |||||
//权限请求失败,选中“不再提示”选项 | |||||
mHintDataDialog = HintDataDialogFragment.newInstance().setTitle("提示", 0).setCancel("取消", 0).setOk("确定", 0).setContent("请求开启定位权限", true).setOnDialogListener(new HintDataDialogFragment.onDialogListener() { | |||||
@Override | |||||
public void onSucceedListener(View v) { | |||||
AppStart.startUseSetActivity(mContext); | |||||
} | |||||
}); | |||||
mHintDataDialog.show(getSupportFragmentManager()); | |||||
} | |||||
} | } | ||||
} else { | |||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | |||||
initPermissions(); | |||||
} | |||||
} | } | ||||
} | } | ||||
import android.app.Activity; | import android.app.Activity; | ||||
import android.app.AlertDialog; | import android.app.AlertDialog; | ||||
import android.bluetooth.BluetoothAdapter; | import android.bluetooth.BluetoothAdapter; | ||||
import android.bluetooth.BluetoothDevice; | |||||
import android.content.ComponentName; | |||||
import android.content.Context; | import android.content.Context; | ||||
import android.content.Intent; | import android.content.Intent; | ||||
import android.content.ServiceConnection; | |||||
import android.content.pm.PackageManager; | import android.content.pm.PackageManager; | ||||
import android.location.LocationManager; | import android.location.LocationManager; | ||||
import android.os.Build; | |||||
import android.os.Bundle; | import android.os.Bundle; | ||||
import android.os.Handler; | import android.os.Handler; | ||||
import android.os.IBinder; | |||||
import android.os.Looper; | import android.os.Looper; | ||||
import android.os.Message; | import android.os.Message; | ||||
import android.os.ParcelUuid; | import android.os.ParcelUuid; | ||||
import android.widget.EditText; | import android.widget.EditText; | ||||
import android.widget.Toast; | import android.widget.Toast; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import androidx.appcompat.app.ActionBar; | |||||
import androidx.core.app.ActivityCompat; | |||||
import androidx.recyclerview.widget.LinearLayoutManager; | |||||
import androidx.recyclerview.widget.RecyclerView; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import com.pingwang.bluetoothlib.config.BleConfig; | import com.pingwang.bluetoothlib.config.BleConfig; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.listener.CallbackDisIm; | |||||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | import com.pingwang.bluetoothlib.listener.OnCallbackBle; | ||||
import com.pingwang.bluetoothlib.listener.OnScanFilterListener; | import com.pingwang.bluetoothlib.listener.OnScanFilterListener; | ||||
import com.pingwang.bluetoothlib.server.ELinkBleServer; | import com.pingwang.bluetoothlib.server.ELinkBleServer; | ||||
import java.util.UUID; | import java.util.UUID; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.adapter.StringAdapter; | import aicare.net.cn.sdk.ailinksdkdemoandroid.adapter.StringAdapter; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.config.BleDeviceConfig; | import aicare.net.cn.sdk.ailinksdkdemoandroid.config.BleDeviceConfig; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.HintDataDialogFragment; | import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.HintDataDialogFragment; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.LoadingIosDialogFragment; | import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.LoadingIosDialogFragment; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.find.FindDeviceNewActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.find.FindDeviceNewActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.PublicBleNetworkCmdActivity; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.TempInstrument.TempInstrumentActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.TempInstrument.TempInstrumentActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.airdetector.AirDetectorActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.airdetector.AirDetectorActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.ble_nutrition.BleNutritionActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.ble_nutrition.BleNutritionActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.coffee_scale.CoffeeScaleActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.coffee_scale.CoffeeScaleActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.fascia_gun.FasciaGunActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.fascia_gun.FasciaGunActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.food_temp.FoodTempActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.food_temp.FoodTempActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.meat_probe.MeatProbeActivity; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.meat_probe_charger.MeatProbeChargerActivity; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.noise_meter.BleNoiseMeterActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.noise_meter.BleNoiseMeterActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.noise_meter.WifiBleNoiseMeterActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.noise_meter.WifiBleNoiseMeterActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.ropeskipping.RopeSkippingActivity; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.share_charger.ShareChargerActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.share_charger.ShareChargerActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.share_condom.ShareCondomActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.share_condom.ShareCondomActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.share_socket.ShareSocketActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.share_socket.ShareSocketActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.toothbrush.ToothBrushWifiBleActivity; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.toothbrush_test.ToothbrushTestActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.toothbrush_test.ToothbrushTestActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.weight_scale.WeightScaleActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.weight_scale.WeightScaleActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.CheckPermissionUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.CheckPermissionUtils; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.view.MyItemDecoration; | import aicare.net.cn.sdk.ailinksdkdemoandroid.view.MyItemDecoration; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import androidx.appcompat.app.ActionBar; | |||||
import androidx.appcompat.app.AppCompatActivity; | |||||
import androidx.core.app.ActivityCompat; | |||||
import androidx.recyclerview.widget.LinearLayoutManager; | |||||
import androidx.recyclerview.widget.RecyclerView; | |||||
import cn.net.aicare.modulelibrary.module.RopeSkipping.RopeSkippingBleData; | import cn.net.aicare.modulelibrary.module.RopeSkipping.RopeSkippingBleData; | ||||
import cn.net.aicare.modulelibrary.module.scooter.SkateboardBleConfig; | import cn.net.aicare.modulelibrary.module.scooter.SkateboardBleConfig; | ||||
/** | /** | ||||
* xing<br> | * xing<br> | ||||
* 2019/3/6<br> | * 2019/3/6<br> | ||||
* java类作用描述 | |||||
* 扫描蓝牙设备界面 | |||||
*/ | */ | ||||
public class ShowBleActivity extends AppCompatActivity implements OnCallbackBle, OnScanFilterListener { | |||||
public class ShowBleActivity extends BleBaseActivity implements OnCallbackBle, OnScanFilterListener { | |||||
public static final int REQUEST_PERMISSION_CODE = 1500; | public static final int REQUEST_PERMISSION_CODE = 1500; | ||||
private EditText et_cid; | private EditText et_cid; | ||||
private List<BleValueBean> mBleValueList; | private List<BleValueBean> mBleValueList; | ||||
private StringAdapter listAdapter; | private StringAdapter listAdapter; | ||||
private ELinkBleServer mBluetoothService; | |||||
/** | |||||
* 服务Intent | |||||
*/ | |||||
private Intent bindIntent; | |||||
private Context mContext; | private Context mContext; | ||||
private int mType; | private int mType; | ||||
private String mNoEncryptionMac = ""; | private String mNoEncryptionMac = ""; | ||||
} | } | ||||
} | } | ||||
private void initData() { | private void initData() { | ||||
bindService(); | |||||
} | } | ||||
if (mType == BleDeviceConfig.SMART_SCOOTER) { | if (mType == BleDeviceConfig.SMART_SCOOTER) { | ||||
Map<String, String> map = new HashMap<>(); | Map<String, String> map = new HashMap<>(); | ||||
map.put(SkateboardBleConfig.UUID_BROADCAST.toString(), "37,3,1");//37=0x0025=电滑板的cid | map.put(SkateboardBleConfig.UUID_BROADCAST.toString(), "37,3,1");//37=0x0025=电滑板的cid | ||||
mBluetoothService.scanLeDevice(30 * 1000, map, BleConfig.UUID_SERVER_AILINK, SkateboardBleConfig.UUID_BROADCAST); | |||||
mBluetoothService.startScan(30 * 1000, map, BleConfig.UUID_SERVER_AILINK, SkateboardBleConfig.UUID_BROADCAST); | |||||
} else { | } else { | ||||
//0000FEE7=手表 | //0000FEE7=手表 | ||||
mBluetoothService.scanLeDevice(1000, BleConfig.UUID_SERVER_AILINK, UUID.fromString("0000FEE7-0000-1000-8000-00805F9B34FB"), SkateboardBleConfig.UUID_BROADCAST); | |||||
mBluetoothService.startScan(1000, BleConfig.UUID_SERVER_AILINK, UUID.fromString("0000FEE7-0000-1000-8000-00805F9B34FB"), SkateboardBleConfig.UUID_BROADCAST); | |||||
} | } | ||||
mBleValueList.clear(); | mBleValueList.clear(); | ||||
listAdapter.notifyDataSetChanged(); | listAdapter.notifyDataSetChanged(); | ||||
BleConfig.setHandshakeStatus(mac, false); | BleConfig.setHandshakeStatus(mac, false); | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.stopScan(); | mBluetoothService.stopScan(); | ||||
mBluetoothService.connectDevice(mac); | |||||
mBluetoothService.connectDevice(new BleValueBean(mac, mCid, mVid, mPid)); | |||||
showLoading(); | showLoading(); | ||||
} | } | ||||
} else if (BleDeviceConfig.TOOTHBRUSH_WIFI_BLE == mType) { | } else if (BleDeviceConfig.TOOTHBRUSH_WIFI_BLE == mType) { | ||||
//要加密要握手。别人家的东西 | //要加密要握手。别人家的东西 | ||||
if (mVid == 0x0027 && mPid == 0x0001) { | if (mVid == 0x0027 && mPid == 0x0001) { | ||||
BleConfig.setHandshakeStatus(RopeSkippingBleData.LongXiang, mac, true); | BleConfig.setHandshakeStatus(RopeSkippingBleData.LongXiang, mac, true); | ||||
} else if (mVid == 0x0003 && mPid == 0x0009) { | |||||
//设置A7不加密 | |||||
mNoEncryptionMac = mac; | |||||
} | } | ||||
} else if (mCid == BleDeviceConfig.LEAP_WATCH) { | |||||
// 手表不握手 | |||||
BleConfig.setHandshakeStatus(mac, false); | |||||
} else if (mCid == BleDeviceConfig.MEAT_PROBE_CHARGER) { | |||||
//探针充电盒握手 | |||||
BleConfig.setHandshakeStatus(mac, true, mCid, mVid, mPid); | |||||
mNoEncryptionMac = mac; | |||||
} | } | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.stopScan(); | mBluetoothService.stopScan(); | ||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | |||||
mBluetoothService.connectDevice(mac, BluetoothDevice.TRANSPORT_LE); | |||||
} else { | |||||
mBluetoothService.connectDevice(mac); | |||||
} | |||||
mBluetoothService.connectDevice(new BleValueBean(mac, mCid, mVid, mPid)); | |||||
showLoading(); | showLoading(); | ||||
} | } | ||||
} | } | ||||
//---------------------------------服务--------------------------------------------------- | //---------------------------------服务--------------------------------------------------- | ||||
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() { | |||||
if (mBluetoothService != null) { | |||||
mBluetoothService.stopForeground();//停止前台服务 | |||||
} | |||||
CallbackDisIm.getInstance().removeListener(this); | |||||
if (mFhrSCon != null) { | |||||
BleLog.i(TAG, "解绑服务"); | |||||
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); | |||||
mBluetoothService.initForegroundService(1, R.mipmap.ic_launcher, "前台服务", MainActivity.class); | |||||
mBluetoothService.startForeground();//启动前台服务 | |||||
mHandler.sendEmptyMessage(BIND_SERVER_OK); | |||||
} | |||||
} | |||||
@Override | |||||
public void onServiceDisconnected(ComponentName name) { | |||||
BleLog.i(TAG, "服务与界面连接断开"); | |||||
//与服务断开连接 | |||||
mBluetoothService = null; | |||||
} | |||||
}; | |||||
@Override | @Override | ||||
public void onStartScan() { | public void onStartScan() { | ||||
public void onScanning(@NonNull BleValueBean data) { | public void onScanning(@NonNull BleValueBean data) { | ||||
String mAddress = data.getMac(); | String mAddress = data.getMac(); | ||||
BleLog.i(TAG, "MAC=" + mAddress + "||CID=" + data.getCid() + "||VID=" + data.getVid() + "||PID=" + data.getPid()); | BleLog.i(TAG, "MAC=" + mAddress + "||CID=" + data.getCid() + "||VID=" + data.getVid() + "||PID=" + data.getPid()); | ||||
boolean oldData = false; | boolean oldData = false; | ||||
for (int i = 0; i < mBleValueList.size(); i++) { | for (int i = 0; i < mBleValueList.size(); i++) { | ||||
BleValueBean bleValueBean = mBleValueList.get(i); | BleValueBean bleValueBean = mBleValueList.get(i); | ||||
mBleValueList.add(data); | mBleValueList.add(data); | ||||
listAdapter.notifyDataSetChanged(); | listAdapter.notifyDataSetChanged(); | ||||
} else { | } else { | ||||
// if (System.currentTimeMillis()-mOldRefreshTime>500){ | |||||
// mOldRefreshTime=System.currentTimeMillis(); | |||||
// listAdapter.notifyDataSetChanged(); | |||||
// } | |||||
// if (System.currentTimeMillis()-mOldRefreshTime>500){ | |||||
// mOldRefreshTime=System.currentTimeMillis(); | |||||
// listAdapter.notifyDataSetChanged(); | |||||
// } | |||||
} | } | ||||
// String data1 = BleStrUtils.byte2HexStr(data.getScanRecord()); | |||||
// String data2 = BleStrUtils.byte2HexStr(data.getManufacturerData()); | |||||
// BleLog.i(TAG, "设备地址+广播数据:" + mAddress + "||" + data1 + "||" + data2); | |||||
// String data1 = BleStrUtils.byte2HexStr(data.getScanRecord()); | |||||
// String data2 = BleStrUtils.byte2HexStr(data.getManufacturerData()); | |||||
// BleLog.i(TAG, "设备地址+广播数据:" + mAddress + "||" + data1 + "||" + data2); | |||||
} | } | ||||
bleDevice.setA7Encryption(false); | bleDevice.setA7Encryption(false); | ||||
mNoEncryptionMac = ""; | mNoEncryptionMac = ""; | ||||
} | } | ||||
dismissLoading(); | dismissLoading(); | ||||
Intent intent = new Intent(); | Intent intent = new Intent(); | ||||
case BleDeviceConfig.WEIGHT_BODY_FAT_SCALE: | case BleDeviceConfig.WEIGHT_BODY_FAT_SCALE: | ||||
intent.setClass(ShowBleActivity.this, WeightScaleBleActivity.class); | intent.setClass(ShowBleActivity.this, WeightScaleBleActivity.class); | ||||
break; | break; | ||||
case BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_AD: | case BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_AD: | ||||
intent.setClass(ShowBleActivity.this, ADWeightScaleCmdActivity.class); | intent.setClass(ShowBleActivity.this, ADWeightScaleCmdActivity.class); | ||||
break; | break; | ||||
break; | break; | ||||
case BleDeviceConfig.FIND_DEVICE: | case BleDeviceConfig.FIND_DEVICE: | ||||
// 寻物器 | // 寻物器 | ||||
// intent.setClass(ShowBleActivity.this, FindDeviceActivity.class); | |||||
// intent.setClass(ShowBleActivity.this, FindDeviceActivity.class); | |||||
intent.setClass(ShowBleActivity.this, FindDeviceNewActivity.class); | intent.setClass(ShowBleActivity.this, FindDeviceNewActivity.class); | ||||
BleConfig.setHandshakeStatus(mac, false); | BleConfig.setHandshakeStatus(mac, false); | ||||
break; | break; | ||||
case BleDeviceConfig.BLE_NOISE_METER: | case BleDeviceConfig.BLE_NOISE_METER: | ||||
intent.setClass(ShowBleActivity.this, BleNoiseMeterActivity.class); | intent.setClass(ShowBleActivity.this, BleNoiseMeterActivity.class); | ||||
break; | break; | ||||
//探针充电盒 | |||||
case BleDeviceConfig.MEAT_PROBE_CHARGER: | |||||
intent.setClass(ShowBleActivity.this, MeatProbeChargerActivity.class); | |||||
break; | |||||
//体脂秤 | //体脂秤 | ||||
case BleDeviceConfig.WEIGHT_SCALE: | case BleDeviceConfig.WEIGHT_SCALE: | ||||
intent.setClass(ShowBleActivity.this, WeightScaleActivity.class); | intent.setClass(ShowBleActivity.this, WeightScaleActivity.class); | ||||
break; | break; | ||||
// case BleDeviceConfig.BLD_WEIGHT: | |||||
// intent.setClass(ShowBleActivity.this, BLDWeightScaleBle.class); | |||||
// break; | |||||
// case BleDeviceConfig.BLD_WEIGHT: | |||||
// intent.setClass(ShowBleActivity.this, BLDWeightScaleBle.class); | |||||
// break; | |||||
case -1: | case -1: | ||||
intent.setClass(ShowBleActivity.this, BleCmdActivity.class); | intent.setClass(ShowBleActivity.this, BleCmdActivity.class); | ||||
break; | break; | ||||
//验证不握手不加密的界面 | //验证不握手不加密的界面 | ||||
intent.setClass(ShowBleActivity.this, ClearShakeHandsActivity.class); | intent.setClass(ShowBleActivity.this, ClearShakeHandsActivity.class); | ||||
break; | break; | ||||
//食物探针 | |||||
case BleDeviceConfig.MEAT_PROBE: | |||||
intent.setClass(ShowBleActivity.this, MeatProbeActivity.class); | |||||
break; | |||||
default: | default: | ||||
} | } | ||||
} | } | ||||
@Override | |||||
public void onServiceSuccess() { | |||||
if (mBluetoothService != null) { | |||||
mBluetoothService.setOnCallbackBle(ShowBleActivity.this); | |||||
mBluetoothService.setOnScanFilterListener(ShowBleActivity.this); | |||||
mBluetoothService.initForegroundService(1, R.mipmap.ic_launcher, "前台服务", MainActivity.class); | |||||
mBluetoothService.startForegroundService();//启动前台服务 | |||||
mHandler.sendEmptyMessage(BIND_SERVER_OK); | |||||
} | |||||
} | |||||
@Override | |||||
public void onServiceErr() { | |||||
} | |||||
@Override | |||||
public void unbindServices() { | |||||
if (mBluetoothService != null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | |||||
//--------------------------start Loading-------------------------- | //--------------------------start Loading-------------------------- | ||||
private LoadingIosDialogFragment mDialogFragment; | private LoadingIosDialogFragment mDialogFragment; | ||||
protected void onResume() { | protected void onResume() { | ||||
super.onResume(); | super.onResume(); | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.setOnCallback(ShowBleActivity.this); | |||||
mBluetoothService.setOnCallbackBle(ShowBleActivity.this); | |||||
mBluetoothService.setOnScanFilterListener(ShowBleActivity.this); | mBluetoothService.setOnScanFilterListener(ShowBleActivity.this); | ||||
} | } | ||||
} | } | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.stopScan(); | mBluetoothService.stopScan(); | ||||
} | } | ||||
unbindService(); | |||||
} | } | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.listener.OnBleHandshakeListener; | import com.pingwang.bluetoothlib.listener.OnBleHandshakeListener; | ||||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | import com.pingwang.bluetoothlib.listener.OnCallbackBle; | ||||
import com.realsil.sdk.dfu.DfuConstants; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.List; | import java.util.List; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleAppBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleAppBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.DialogStringImageAdapter; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.DialogStringImageBean; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.ShowListDialogFragment; | import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.ShowListDialogFragment; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.FileUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.FileUtils; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.L; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.L; | ||||
* 滑板车界面 | * 滑板车界面 | ||||
*/ | */ | ||||
public class SkateboardDataActivity extends BleAppBaseActivity implements OnCallbackBle, View.OnClickListener, SkateboardDevice.onNotifyData, | public class SkateboardDataActivity extends BleAppBaseActivity implements OnCallbackBle, View.OnClickListener, SkateboardDevice.onNotifyData, | ||||
RtkOtaManager.OnRtkOtaInfoListener, ShowListDialogFragment.onDialogListener, OnBleHandshakeListener , OnScooterBleOTAListener { | |||||
RtkOtaManager.OnRtkOtaInfoListener, ShowListDialogFragment.onDialogListener, OnBleHandshakeListener, OnScooterBleOTAListener { | |||||
private final int REFRESH_DATA = 1; | private final int REFRESH_DATA = 1; | ||||
private SkateboardDevice mDevice; | private SkateboardDevice mDevice; | ||||
private int mOtaUpdateStatus; | private int mOtaUpdateStatus; | ||||
private ArrayList<DialogStringImageAdapter.DialogStringImageBean> mDialogList; | |||||
private ArrayList<DialogStringImageBean> mDialogList; | |||||
/** | /** | ||||
* OTA类型,0=BOOTLOADER,1=APP,2=FLASH,3=ble | * OTA类型,0=BOOTLOADER,1=APP,2=FLASH,3=ble | ||||
*/ | */ | ||||
* rtk升级方式 | * rtk升级方式 | ||||
* 默认静默升级 | * 默认静默升级 | ||||
*/ | */ | ||||
// private int mRtkOtaType = RtkOtaManager.OTA_MODE_SILENT_FUNCTION; | |||||
private int mRtkOtaType = DfuConstants.OTA_MODE_NORMAL_FUNCTION; | |||||
/** | /** | ||||
* ota作用域 | * ota作用域 | ||||
*/ | */ | ||||
case R.id.btn_ble: | case R.id.btn_ble: | ||||
mDialogList.clear(); | mDialogList.clear(); | ||||
for (String s : FileUtils.list()) { | for (String s : FileUtils.list()) { | ||||
mDialogList.add(new DialogStringImageAdapter.DialogStringImageBean(s, 0)); | |||||
mDialogList.add(new DialogStringImageBean(s, 0)); | |||||
} | } | ||||
//btn_ble | //btn_ble | ||||
mOTAType = 3; | mOTAType = 3; | ||||
break; | break; | ||||
//OTA类型 | //OTA类型 | ||||
case R.id.btn_ota_type: | case R.id.btn_ota_type: | ||||
List<DialogStringImageAdapter.DialogStringImageBean> list = new ArrayList<>(); | |||||
// list.add(new DialogStringImageAdapter.DialogStringImageBean("静默升级", RtkOtaManager.OTA_MODE_SILENT_FUNCTION)); | |||||
// list.add(new DialogStringImageAdapter.DialogStringImageBean("普通升级", RtkOtaManager.OTA_MODE_NORMAL_FUNCTION)); | |||||
List<DialogStringImageBean> list = new ArrayList<>(); | |||||
list.add(new DialogStringImageBean("静默升级", DfuConstants.OTA_MODE_SILENT_FUNCTION)); | |||||
list.add(new DialogStringImageBean("普通升级", DfuConstants.OTA_MODE_NORMAL_FUNCTION)); | |||||
ShowListDialogFragment.newInstance().setTitle("").setCancel("", 0).setCancelBlank(true).setBackground(true).setBottom(false) | ShowListDialogFragment.newInstance().setTitle("").setCancel("", 0).setCancelBlank(true).setBackground(true).setBottom(false) | ||||
.setList(list).setOnDialogListener(new ShowListDialogFragment.onDialogListener() { | .setList(list).setOnDialogListener(new ShowListDialogFragment.onDialogListener() { | ||||
@Override | @Override | ||||
public void onItemListener(int position) { | public void onItemListener(int position) { | ||||
DialogStringImageAdapter.DialogStringImageBean dialogStringImageBean = list.get(position); | |||||
// mRtkOtaType = (int) dialogStringImageBean.getType(); | |||||
DialogStringImageBean dialogStringImageBean = list.get(position); | |||||
mRtkOtaType = (int) dialogStringImageBean.getType(); | |||||
btn_ota_type.setText(dialogStringImageBean.getName()); | btn_ota_type.setText(dialogStringImageBean.getName()); | ||||
} | } | ||||
}).show(getSupportFragmentManager()); | }).show(getSupportFragmentManager()); | ||||
private void selectOta(int OTAType, int OTAScope) { | private void selectOta(int OTAType, int OTAScope) { | ||||
mDialogList.clear(); | mDialogList.clear(); | ||||
for (String s : FileUtils.list()) { | for (String s : FileUtils.list()) { | ||||
mDialogList.add(new DialogStringImageAdapter.DialogStringImageBean(s, 0)); | |||||
mDialogList.add(new DialogStringImageBean(s, 0)); | |||||
} | } | ||||
mOTAType = OTAType; | mOTAType = OTAType; | ||||
mOTAScope = OTAScope; | mOTAScope = OTAScope; | ||||
private RtkOtaManager mRtkOtaManager; | private RtkOtaManager mRtkOtaManager; | ||||
@Override | |||||
public void onCancelListener(View v) { | |||||
} | |||||
@Override | @Override | ||||
public void onItemListener(int position) { | public void onItemListener(int position) { | ||||
if (mDialogList.size() > position) { | if (mDialogList.size() > position) { | ||||
DialogStringImageAdapter.DialogStringImageBean dialogStringImageBean = mDialogList.get(position); | |||||
DialogStringImageBean dialogStringImageBean = mDialogList.get(position); | |||||
String name = dialogStringImageBean.getName(); | String name = dialogStringImageBean.getName(); | ||||
String byFileName = FileUtils.getByFileName() + name; | String byFileName = FileUtils.getByFileName() + name; | ||||
if (mOTAType == 3) { | if (mOTAType == 3) { | ||||
mList.add("OTA包中包含:" + stepSize + "个小包\n现在升级" + ((step >= 0) ? step + "包" : "全部包")); | mList.add("OTA包中包含:" + stepSize + "个小包\n现在升级" + ((step >= 0) ? step + "包" : "全部包")); | ||||
mHandler.sendEmptyMessage(REFRESH_DATA); | mHandler.sendEmptyMessage(REFRESH_DATA); | ||||
// mRtkOtaManager.startOta(mRtkOtaType, step); | |||||
mRtkOtaManager.startOta(mRtkOtaType, step); | |||||
} else if (mDevice != null) { | } else if (mDevice != null) { | ||||
mDevice.setOnScooterBleOTAListener(SkateboardDataActivity.this); | mDevice.setOnScooterBleOTAListener(SkateboardDataActivity.this); | ||||
@Override | @Override | ||||
public void onServiceSuccess() { | public void onServiceSuccess() { | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
mBluetoothService.setOnScanFilterListener(null); | mBluetoothService.setOnScanFilterListener(null); | ||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mMac); | BleDevice bleDevice = mBluetoothService.getBleDevice(mMac); | ||||
if (bleDevice == null) { | if (bleDevice == null) { | ||||
mBluetoothService.scanLeDevice(0, SkateboardBleConfig.UUID_BROADCAST, BleConfig.UUID_SERVER_AILINK); | |||||
mBluetoothService.startScan(0, SkateboardBleConfig.UUID_BROADCAST, BleConfig.UUID_SERVER_AILINK); | |||||
} else { | } else { | ||||
onServicesDiscovered(mMac); | onServicesDiscovered(mMac); | ||||
} | } | ||||
@Override | @Override | ||||
public void unbindServices() { | public void unbindServices() { | ||||
if (mBluetoothService!=null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | } | ||||
@Override | @Override | ||||
} | } | ||||
@Override | |||||
public void onScanErr(long time) { | |||||
} | |||||
@Override | |||||
public void onConnecting(String mac) { | |||||
} | |||||
@Override | @Override | ||||
public void bleClose() { | public void bleClose() { | ||||
mDevice = null; | mDevice = null; | ||||
} | } | ||||
@Override | |||||
public void onConnectionSuccess(String mac) { | |||||
} | |||||
@Override | @Override | ||||
public void bleOpen() { | public void bleOpen() { | ||||
mList.add("蓝牙已开启"); | mList.add("蓝牙已开启"); | ||||
mHandler.sendEmptyMessage(REFRESH_DATA); | mHandler.sendEmptyMessage(REFRESH_DATA); | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.scanLeDevice(0, SkateboardBleConfig.UUID_BROADCAST, BleConfig.UUID_SERVER_AILINK); | |||||
mBluetoothService.startScan(0, SkateboardBleConfig.UUID_BROADCAST, BleConfig.UUID_SERVER_AILINK); | |||||
} | } | ||||
} | } | ||||
mHandler.sendEmptyMessage(REFRESH_DATA); | mHandler.sendEmptyMessage(REFRESH_DATA); | ||||
} | } | ||||
@Override | |||||
public void onReconnect(String mac) { | |||||
} | |||||
public static int getProgressStateResId(int var0) { | public static int getProgressStateResId(int var0) { | ||||
if (var0 != 527) { | if (var0 != 527) { | ||||
} | } | ||||
} | } |
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.Toast; | import android.widget.Toast; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | ||||
import com.pingwang.bluetoothlib.device.SendBleBean; | import com.pingwang.bluetoothlib.device.SendBleBean; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import butterknife.BindView; | import butterknife.BindView; | ||||
import butterknife.ButterKnife; | import butterknife.ButterKnife; | ||||
import cn.net.aicare.modulelibrary.module.SmartMask.SmartMaskBleConfig; | import cn.net.aicare.modulelibrary.module.SmartMask.SmartMaskBleConfig; |
import android.widget.EditText; | import android.widget.EditText; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.config.CmdConfig; | import com.pingwang.bluetoothlib.config.CmdConfig; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.sphygmomanometer.SphyBleConfig; | import cn.net.aicare.modulelibrary.module.sphygmomanometer.SphyBleConfig; | ||||
import cn.net.aicare.modulelibrary.module.sphygmomanometer.SphyDeviceData; | import cn.net.aicare.modulelibrary.module.sphygmomanometer.SphyDeviceData; | ||||
import android.widget.RadioButton; | import android.widget.RadioButton; | ||||
import android.widget.Toast; | import android.widget.Toast; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | ||||
import com.pingwang.bluetoothlib.device.SendBleBean; | import com.pingwang.bluetoothlib.device.SendBleBean; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.thermometer.TempDeviceData; | import cn.net.aicare.modulelibrary.module.thermometer.TempDeviceData; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.Toast; | import android.widget.Toast; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | ||||
import com.pingwang.bluetoothlib.device.SendBleBean; | import com.pingwang.bluetoothlib.device.SendBleBean; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.foreheadgun.TempGunDeviceData; | import cn.net.aicare.modulelibrary.module.foreheadgun.TempGunDeviceData; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | import com.pingwang.bluetoothlib.listener.OnCallbackBle; | ||||
import java.util.List; | import java.util.List; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.TempHumidity.TempHumidityBleUtils; | import cn.net.aicare.modulelibrary.module.TempHumidity.TempHumidityBleUtils; | ||||
/** | /** | ||||
@Override | @Override | ||||
public void onServiceSuccess() { | public void onServiceSuccess() { | ||||
mBluetoothService.setOnCallback(this); | |||||
logList.add(0, "绑定服务成功"); | logList.add(0, "绑定服务成功"); | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
mBluetoothService.deviceConnectListener(mAddress, true); | mBluetoothService.deviceConnectListener(mAddress, true); | ||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | ||||
if (bleDevice != null) { | if (bleDevice != null) { | ||||
@Override | @Override | ||||
public void unbindServices() { | public void unbindServices() { | ||||
if (mBluetoothService!=null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | } | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.config.BleConfig; | import com.pingwang.bluetoothlib.config.BleConfig; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.device.SendDataBean; | import com.pingwang.bluetoothlib.device.SendDataBean; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
/** | /** | ||||
private ArrayAdapter listAdapter; | private ArrayAdapter listAdapter; | ||||
private Context mContext; | private Context mContext; | ||||
private EditText et_cmd, et_uuid, et_uuid_server, et_time, et_notify; | private EditText et_cmd, et_uuid, et_uuid_server, et_time, et_notify; | ||||
private BleDevice bleDevice; | |||||
private BleDevice mBleDevice; | |||||
private String mAddress; | private String mAddress; | ||||
private int sendTime = 1000; | private int sendTime = 1000; | ||||
private UUID sendUuid = null; | private UUID sendUuid = null; | ||||
private long mSendNumber = 0; | private long mSendNumber = 0; | ||||
private long mReceiveNumber = 0; | private long mReceiveNumber = 0; | ||||
private boolean mShowLog = true; | private boolean mShowLog = true; | ||||
private int mNum = 1; | |||||
private Handler mHandler = new Handler(Looper.getMainLooper()) { | private Handler mHandler = new Handler(Looper.getMainLooper()) { | ||||
@Override | @Override | ||||
public void handleMessage(Message msg) { | public void handleMessage(Message msg) { | ||||
case SEND_DATA: | case SEND_DATA: | ||||
if (sendUuid != null && sendUuidServer != null) { | if (sendUuid != null && sendUuidServer != null) { | ||||
SendDataBean sendDataBean = new SendDataBean(sendCmd.getBytes(), sendUuid, BleConfig.WRITE_DATA, sendUuidServer); | |||||
bleDevice.sendData(sendDataBean); | |||||
mNum++; | |||||
SendDataBean sendDataBean = new SendDataBean(String.valueOf(mNum).getBytes(), sendUuid, BleConfig.WRITE_DATA, sendUuidServer); | |||||
mBleDevice.sendData(sendDataBean); | |||||
if (sendTime > 0) { | if (sendTime > 0) { | ||||
mHandler.sendEmptyMessageDelayed(SEND_DATA, sendTime); | mHandler.sendEmptyMessageDelayed(SEND_DATA, sendTime); | ||||
} | } | ||||
case R.id.clear: | case R.id.clear: | ||||
if (mList != null) | if (mList != null) | ||||
mList.clear(); | mList.clear(); | ||||
mSendNumber=0; | |||||
mSendNumber = 0; | |||||
mReceiveNumber = 0; | mReceiveNumber = 0; | ||||
tv_receive_number.setText("0"); | tv_receive_number.setText("0"); | ||||
tv_send_number.setText("0"); | tv_send_number.setText("0"); | ||||
*/ | */ | ||||
private void readNotify(String notify, boolean notifyOpen) { | private void readNotify(String notify, boolean notifyOpen) { | ||||
UUID uuidNotify = UuidUtils.getUuid(notify); | UUID uuidNotify = UuidUtils.getUuid(notify); | ||||
if (bleDevice != null && sendUuidServer != null) { | |||||
if (mBleDevice != null && sendUuidServer != null) { | |||||
if (notifyOpen) { | if (notifyOpen) { | ||||
bleDevice.setNotify(sendUuidServer, uuidNotify); | |||||
mBleDevice.setNotify(sendUuidServer, uuidNotify); | |||||
} else { | } else { | ||||
bleDevice.setCloseNotify(sendUuidServer, uuidNotify); | |||||
mBleDevice.setCloseNotify(sendUuidServer, uuidNotify); | |||||
} | } | ||||
} else { | } else { | ||||
BleLog.i(TAG, "服务与界面建立连接成功"); | BleLog.i(TAG, "服务与界面建立连接成功"); | ||||
//与服务建立连接 | //与服务建立连接 | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
bleDevice = mBluetoothService.getBleDevice(mAddress); | |||||
mBleDevice = mBluetoothService.getBleDevice(mAddress); | |||||
CallbackDisIm.getInstance().addListListener(this); | CallbackDisIm.getInstance().addListListener(this); | ||||
if (bleDevice != null) { | |||||
bleDevice.setOnBleOtherDataListener(this); | |||||
bleDevice.setOnBleDeviceDataListener(this); | |||||
if (mBleDevice != null) { | |||||
mBleDevice.setOnBleOtherDataListener(this); | |||||
mBleDevice.setOnBleDeviceDataListener(this); | |||||
} | } | ||||
} | } | ||||
@Override | @Override | ||||
public void unbindServices() { | public void unbindServices() { | ||||
CallbackDisIm.getInstance().removeListener(this); | CallbackDisIm.getInstance().removeListener(this); | ||||
if (bleDevice != null) { | |||||
bleDevice.disconnect(); | |||||
bleDevice = null; | |||||
if (mBleDevice != null) { | |||||
mBleDevice.disconnect(); | |||||
mBleDevice = null; | |||||
} | } | ||||
} | } | ||||
//-----------------通知------------------- | //-----------------通知------------------- | ||||
@Override | @Override | ||||
public void onNotifyData(byte[] hex, int type) { | |||||
public void onNotifyData(String uuid, byte[] hex, int type) { | |||||
if (!mShowLog) { | if (!mShowLog) { | ||||
return; | return; | ||||
} | } | ||||
if (type == 100) { | if (type == 100) { | ||||
mList.add(TimeUtils.getTime() + "send->" + data); | mList.add(TimeUtils.getTime() + "send->" + data); | ||||
} else { | } else { | ||||
mList.add(TimeUtils.getTime() + "notify->" + data); | |||||
mList.add(TimeUtils.getTime() + "notify1->" + data); | |||||
mReceiveNumber += hex.length; | mReceiveNumber += hex.length; | ||||
tv_receive_number.setText(String.valueOf(mReceiveNumber)); | tv_receive_number.setText(String.valueOf(mReceiveNumber)); | ||||
} | } | ||||
mHandler.sendEmptyMessage(REFRESH_DATA); | mHandler.sendEmptyMessage(REFRESH_DATA); | ||||
} | } | ||||
@Override | @Override | ||||
public void onNotifyOtherData(byte[] hex) { | |||||
public void onNotifyOtherData(String uuid, byte[] hex) { | |||||
if (mBleDevice != null) { | |||||
hex[0]= (byte) (hex[0]+1); | |||||
SendDataBean sendDataBean = new SendDataBean(hex,BleConfig.UUID_WRITE_AILINK,BleConfig.WRITE_DATA,BleConfig.UUID_SERVER_AILINK); | |||||
mBleDevice.sendDataNow(sendDataBean); | |||||
} | |||||
if (mShowLog) { | if (mShowLog) { | ||||
String data = ""; | String data = ""; | ||||
if (hex != null) | if (hex != null) | ||||
data = BleStrUtils.byte2HexStr(hex); | data = BleStrUtils.byte2HexStr(hex); | ||||
mList.add(TimeUtils.getTime() + "notify->" + data); | |||||
mList.add(TimeUtils.getTime() + "notify2->" + data); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | mHandler.sendEmptyMessage(REFRESH_DATA); | ||||
} | } | ||||
mReceiveNumber += hex.length; | mReceiveNumber += hex.length; |
import android.widget.TextView; | import android.widget.TextView; | ||||
import android.widget.Toast; | import android.widget.Toast; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import androidx.core.app.ActivityCompat; | |||||
import com.elinkthings.bleotalibrary.dialog.DialogOtaManager; | import com.elinkthings.bleotalibrary.dialog.DialogOtaManager; | ||||
import com.elinkthings.bleotalibrary.listener.OnBleOTAListener; | import com.elinkthings.bleotalibrary.listener.OnBleOTAListener; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import java.util.List; | import java.util.List; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.DialogStringImageAdapter; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.DialogStringImageBean; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.ShowListDialogFragment; | import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.ShowListDialogFragment; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.FileUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.FileUtils; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.SP; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.SP; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import androidx.core.app.ActivityCompat; | |||||
/** | /** | ||||
private BleDevice mBleDevice; | private BleDevice mBleDevice; | ||||
private String mAddress; | private String mAddress; | ||||
private ArrayList<DialogStringImageAdapter.DialogStringImageBean> mDialogList; | |||||
private ArrayList<DialogStringImageBean> mDialogList; | |||||
private String mOTAFileName; | private String mOTAFileName; | ||||
private DialogOtaManager mDialogOtaManager; | private DialogOtaManager mDialogOtaManager; | ||||
private Handler mHandler = new Handler(Looper.getMainLooper()) { | private Handler mHandler = new Handler(Looper.getMainLooper()) { | ||||
@Override | @Override | ||||
public void onItemListener(int position) { | public void onItemListener(int position) { | ||||
if (mDialogList.size() > position) { | if (mDialogList.size() > position) { | ||||
DialogStringImageAdapter.DialogStringImageBean dialogStringImageBean = mDialogList.get(position); | |||||
DialogStringImageBean dialogStringImageBean = mDialogList.get(position); | |||||
String name = dialogStringImageBean.getName(); | String name = dialogStringImageBean.getName(); | ||||
mOTAFileName = name; | mOTAFileName = name; | ||||
SP.getInstance().putOtaFileName(name); | SP.getInstance().putOtaFileName(name); | ||||
mDialogList.clear(); | mDialogList.clear(); | ||||
ArrayList<String> list = FileUtils.list(); | ArrayList<String> list = FileUtils.list(); | ||||
for (String s : list) { | for (String s : list) { | ||||
mDialogList.add(new DialogStringImageAdapter.DialogStringImageBean(s, 0)); | |||||
mDialogList.add(new DialogStringImageBean(s, 0)); | |||||
} | } | ||||
ShowListDialogFragment.newInstance().setTitle("").setCancel("", 0).setCancelBlank(true).setBackground(true).setBottom(false).setList(mDialogList).setOnDialogListener(this) | ShowListDialogFragment.newInstance().setTitle("").setCancel("", 0).setCancelBlank(true).setBackground(true).setBottom(false).setList(mDialogList).setOnDialogListener(this) | ||||
//与服务建立连接 | //与服务建立连接 | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBleDevice = mBluetoothService.getBleDevice(mAddress); | mBleDevice = mBluetoothService.getBleDevice(mAddress); | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
if (mDialogOtaManager != null) { | if (mDialogOtaManager != null) { | ||||
mDialogOtaManager.setOnBleOTAListener(this); | mDialogOtaManager.setOnBleOTAListener(this); | ||||
} | } | ||||
@Override | @Override | ||||
public void unbindServices() { | public void unbindServices() { | ||||
if (mBluetoothService!=null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
if (mBleDevice != null) { | if (mBleDevice != null) { | ||||
mBleDevice.disconnect(); | mBleDevice.disconnect(); | ||||
mBleDevice = null; | mBleDevice = null; |
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||||
import android.content.Intent; | |||||
import android.content.pm.ActivityInfo; | |||||
import android.os.Bundle; | |||||
import android.os.Handler; | |||||
import android.os.Message; | |||||
import android.util.Log; | |||||
import android.view.View; | |||||
import android.widget.ArrayAdapter; | |||||
import android.widget.EditText; | |||||
import android.widget.ListView; | |||||
import android.widget.Toast; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | |||||
import com.pingwang.bluetoothlib.device.BleDevice; | |||||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | |||||
import com.pingwang.bluetoothlib.utils.BleLog; | |||||
import java.lang.ref.WeakReference; | |||||
import java.util.ArrayList; | |||||
import java.util.Arrays; | |||||
import java.util.List; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.config.BleDeviceConfig; | |||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.ToothBrush.ToothBrushBleCmd; | |||||
/** | |||||
* ble 牙刷 | |||||
*/ | |||||
public class ToothBrushBleActivity extends BleBaseActivity implements View.OnClickListener, OnCallbackBle,ToothBrushBleUtilsData.BleToothBrushCallback { | |||||
private String TAG = ToothBrushBleActivity.class.getName(); | |||||
private String mAddress; | |||||
private int type; | |||||
private List<String> mList; | |||||
private ArrayAdapter listAdapter; | |||||
private MHandler mMHandler; | |||||
private EditText select_gears_et; | |||||
private ToothBrushBleUtilsData mToothBrushBleUtilsData; | |||||
@Override | |||||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||||
super.onCreate(savedInstanceState); | |||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//禁止横屏 | |||||
setContentView(R.layout.activity_tooth_brush_ble); | |||||
findViewById(R.id.support_unit).setOnClickListener(this); | |||||
findViewById(R.id.default_try_out).setOnClickListener(this); | |||||
findViewById(R.id.default_time_mode).setOnClickListener(this); | |||||
findViewById(R.id.default_mode).setOnClickListener(this); | |||||
select_gears_et = findViewById(R.id.select_gears_et); | |||||
mAddress = getIntent().getStringExtra("mac"); | |||||
type = getIntent().getIntExtra("type", BleDeviceConfig.TOOTHBRUSH_TEST); | |||||
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(); | |||||
} | |||||
@Override | |||||
protected void onNewIntent(Intent intent) { | |||||
super.onNewIntent(intent); | |||||
setIntent(intent); | |||||
} | |||||
@Override | |||||
public void onServiceSuccess() { | |||||
//与服务建立连接 | |||||
mList.add(0, "服务与界面建立连接成功"); | |||||
// mList.add(0, "搜索设备"); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.scanLeDevice(30 * 1000); | |||||
} | |||||
@Override | |||||
public void onServiceErr() { | |||||
} | |||||
@Override | |||||
public void unbindServices() { | |||||
} | |||||
@Override | |||||
public void onStartScan() { | |||||
} | |||||
@Override | |||||
public void onScanning(BleValueBean data) { | |||||
BleLog.i(TAG, "MAC=" + mAddress + "||CID=" + data.getCid() + "||VID=" + data.getVid() + "||PID=" + data.getPid()); | |||||
if (data.getMac().equalsIgnoreCase(mAddress)) { | |||||
mBluetoothService.stopScan(); | |||||
mBluetoothService.connectDevice(data.getMac()); | |||||
} | |||||
} | |||||
@Override | |||||
public void onScanTimeOut() { | |||||
} | |||||
@Override | |||||
public void onConnecting(String mac) { | |||||
} | |||||
@Override | |||||
public void onDisConnected(String mac, int code) { | |||||
mList.add(0, "蓝牙已断开"); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onServicesDiscovered(String mac) { | |||||
mList.add(0, "蓝牙已连接"); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
stopScanBle(); | |||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | |||||
if (bleDevice != null) { | |||||
ToothBrushBleUtilsData.init(bleDevice,this); | |||||
mToothBrushBleUtilsData =ToothBrushBleUtilsData.getInstance(); | |||||
mMHandler.sendEmptyMessageDelayed(ToRequestToken, 600); | |||||
mMHandler.sendEmptyMessageDelayed(GETBATTERY, 800); | |||||
} | |||||
} | |||||
@Override | |||||
public void bleOpen() { | |||||
} | |||||
@Override | |||||
public void bleClose() { | |||||
} | |||||
@Override | |||||
public void onClick(View v) { | |||||
int id = v.getId(); | |||||
if (mToothBrushBleUtilsData != null) | |||||
switch (id) { | |||||
case R.id.support_unit: | |||||
mToothBrushBleUtilsData.getSupportGears(); | |||||
break; | |||||
case R.id.default_mode: | |||||
String gear = select_gears_et.getText().toString().trim(); | |||||
if (!gear.isEmpty()) { | |||||
String[] gears = null; | |||||
if (gear.contains(",")) { | |||||
gears = gear.split(","); | |||||
} else if (gear.contains(",")) { | |||||
gears = gear.split(","); | |||||
} else { | |||||
Toast.makeText(this, "请输入时长,档位,档位级别(数字加符号)", Toast.LENGTH_SHORT).show(); | |||||
} | |||||
if (gears != null) { | |||||
try { | |||||
mToothBrushBleUtilsData.setDefault(Integer.parseInt(gears[0]), Integer.parseInt(gears[1]), Integer.parseInt(gears[2])); | |||||
} catch (Exception e) { | |||||
e.printStackTrace(); | |||||
Toast.makeText(this, "请输入时长,档位,档位级别(数字加符号)", Toast.LENGTH_SHORT).show(); | |||||
} | |||||
} | |||||
} | |||||
break; | |||||
case R.id.default_try_out: | |||||
String gear1 = select_gears_et.getText().toString().trim(); | |||||
if (!gear1.isEmpty()) { | |||||
String[] gears = null; | |||||
if (gear1.contains(",")) { | |||||
gears = gear1.split(","); | |||||
} else if (gear1.contains(",")) { | |||||
gears = gear1.split(","); | |||||
} else { | |||||
Toast.makeText(this, "请输入时长,档位,档位级别(数字加符号)", Toast.LENGTH_SHORT).show(); | |||||
} | |||||
if (gears != null) { | |||||
try { | |||||
mToothBrushBleUtilsData.setTryOut(Integer.parseInt(gears[1]), Integer.parseInt(gears[2]), 0, 0); | |||||
} catch (Exception e) { | |||||
e.printStackTrace(); | |||||
Toast.makeText(this, "请输入时长,档位,档位级别(数字加符号)", Toast.LENGTH_SHORT).show(); | |||||
} | |||||
} | |||||
} | |||||
break; | |||||
case R.id.default_time_mode: | |||||
mToothBrushBleUtilsData.getdefaultGearAndDuration(); | |||||
break; | |||||
} | |||||
} | |||||
private final int ToRefreUi = 300; | |||||
private final int ConnectWifi = 400; | |||||
private final int ToRequestToken = 500; | |||||
private final int GETBATTERY = 600; | |||||
@Override | |||||
public void onVersion(String version) { | |||||
mList.add(0, "版本号:" + version); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onGetSupportGears(List<Integer> staif, List<Integer> secondLevel) { | |||||
mList.add(0, "牙刷支持的一级档位:" + Arrays.toString(staif.toArray()) + " 二级档位:" + Arrays.toString(secondLevel.toArray())); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onGetBattery(int batteryStatus, int batteryQuantity) { | |||||
mList.add(0, "电池状态:" + batteryStatus + " 电量:" + batteryQuantity); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onGetDefaultGearAndDuration(int time, int gear, int gearFrom) { | |||||
mList.add(0, "获得到默认的刷牙档位和时长:" + time + " 档位:" + gear + " 档位级别" + gearFrom); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onGetTokenResult(int result) { | |||||
String s = ""; | |||||
if (result == ToothBrushBleCmd.NO_TOKEN) { | |||||
s = "没有"; | |||||
} else if (result == ToothBrushBleCmd.HAS_TOKEN) { | |||||
s = "已经授权"; | |||||
} else if (result == ToothBrushBleCmd.WITHOUT_TOKEN) { | |||||
s = "不需要授权"; | |||||
} else if (result == ToothBrushBleCmd.SUCCESSTOKEN) { | |||||
s = "授权成功"; | |||||
} | |||||
mList.add(0, "请求授权结果" + result + " " + s); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onGetManualParameter(int time, int hz, int duty) { | |||||
mList.add(0, " 获取手动档位的参数: 时长" + time + " 频率" + hz + " 占空比" + duty); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onSetDefaultModeAndManualModeResult(byte type, int result) { | |||||
String s = ""; | |||||
if (result == 0) { | |||||
s = "设置成功"; | |||||
} else if (result == 1) { | |||||
s = "设置失败"; | |||||
} else if (result == 2) { | |||||
s = "不支持设置"; | |||||
} | |||||
if (type == ToothBrushBleCmd.SET_TOOTHBRUSH_TIME_GEARS) { | |||||
mList.add(0, " 设置默认刷牙时长和工作档位: 结果" + result + " " + s); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} else { | |||||
mList.add(0, " 设置手动设置(自定义)档位: 结果" + result + " " + s); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
} | |||||
@Override | |||||
public void onTestFinish(int totalTime, int leftTime, int rightTime, int mode, int battery) { | |||||
mList.add(0, "刷牙完成: 总时长:" + totalTime + " 左时长:" + leftTime + " 右时长:" + rightTime + " 模式:" + mode + " 电量:" + battery); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onTryOutResult(int result) { | |||||
mList.add(0, "设置使用结果:" + result + " ( 0:设置成功 1:设置失败,原因未知 2:不支持设置)"); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onTwoLevelModeDefault(int mode) { | |||||
mList.add(0, "获取二级档位默认值:" + mode); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onShowData(String data) { | |||||
Log.e("蓝牙牙刷",data); | |||||
} | |||||
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 ToRequestToken: | |||||
mList.add(0, "请求授权"); | |||||
mToothBrushBleUtilsData.requestToken(System.currentTimeMillis()); | |||||
if (listAdapter != null) { | |||||
listAdapter.notifyDataSetChanged(); | |||||
} | |||||
break; | |||||
case GETBATTERY: | |||||
mToothBrushBleUtilsData.getBattery(); | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
} |
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||||
import com.pingwang.bluetoothlib.device.BaseBleDeviceData; | |||||
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.OnBleOtherDataListener; | |||||
import com.pingwang.bluetoothlib.listener.OnBleVersionListener; | |||||
import com.pingwang.bluetoothlib.listener.OnMcuParameterListener; | |||||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||||
import java.lang.ref.WeakReference; | |||||
import java.util.ArrayList; | |||||
import java.util.List; | |||||
import cn.net.aicare.modulelibrary.module.ToothBrush.ToothBrushBleCmd; | |||||
/** | |||||
* 如果在解析包中。找不到这个类。可以直接把代码复制过去 | |||||
* 如果有这个类。这个类只演示用 | |||||
*/ | |||||
public class ToothBrushBleUtilsData extends BaseBleDeviceData { | |||||
public final static int TOOTHBRUSH_BLE = 0x2d; | |||||
private BleDevice mBleDevice = null; | |||||
private volatile static ToothBrushBleUtilsData toothBrushBleUtilsData = null; | |||||
private ToothBrushBleUtilsData(BleDevice bleDevice, BleToothBrushCallback bleToothBrushCallback) { | |||||
super(bleDevice); | |||||
mBleDevice = bleDevice; | |||||
this.bleToothBrushCallback = bleToothBrushCallback; | |||||
mBleDevice.setOnBleVersionListener(new OnBleVersionListener() { | |||||
@Override | |||||
public void onBmVersion(String version) { | |||||
//蓝牙版本号 | |||||
if (bleToothBrushCallback != null) { | |||||
bleToothBrushCallback.onVersion(version); | |||||
} | |||||
} | |||||
}); | |||||
bleDevice.setOnMcuParameterListener(new OnMcuParameterListener() { | |||||
@Override | |||||
public void onMcuBatteryStatus(int status, int battery) { | |||||
if (bleToothBrushCallback != null) { | |||||
bleToothBrushCallback.onGetBattery(status, battery); | |||||
} | |||||
} | |||||
}); | |||||
mBleDevice.setOnBleOtherDataListener(new OnBleOtherDataListener() { | |||||
@Override | |||||
public void onNotifyOtherData(byte[] data) { | |||||
} | |||||
}); | |||||
} | |||||
public static ToothBrushBleUtilsData getInstance() { | |||||
return toothBrushBleUtilsData; | |||||
} | |||||
/** | |||||
* 初始化话 | |||||
* | |||||
* @param bleDevice 蓝牙操作类 | |||||
* @param bleCallback 蓝牙基础回调接口 | |||||
*/ | |||||
public static void init(BleDevice bleDevice, BleToothBrushCallback bleCallback) { | |||||
toothBrushBleUtilsData=null; | |||||
toothBrushBleUtilsData=new ToothBrushBleUtilsData(bleDevice,bleCallback); | |||||
} | |||||
/** | |||||
* 获取到蓝牙设备对象 | |||||
* | |||||
* @return 蓝牙设备 | |||||
*/ | |||||
public BleDevice getBleDevice() { | |||||
WeakReference weakReference = new WeakReference(mBleDevice); | |||||
return (BleDevice) weakReference.get(); | |||||
} | |||||
@Override | |||||
public void onNotifyData(byte[] bytes, int type) { | |||||
if (bleToothBrushCallback != null) { | |||||
bleToothBrushCallback.onShowData("蓝牙返回的A7: " + BleStrUtils.byte2HexStr(bytes)); | |||||
} | |||||
switch (bytes[0]) { | |||||
case ToothBrushBleCmd.GET_TOOTHBRUSH_TIME_GEARS: | |||||
if (bytes.length >= 5) { | |||||
int highTime = (bytes[1] & 0xff) << 8; | |||||
int lowTime = bytes[2] & 0xff; | |||||
int gears = bytes[3] & 0xff; | |||||
int gearsfrom = bytes[4] & 0xff; | |||||
if (bleToothBrushCallback != null) | |||||
bleToothBrushCallback.onGetDefaultGearAndDuration(highTime + lowTime, gears, gearsfrom); | |||||
} | |||||
break; | |||||
case ToothBrushBleCmd.SET_TOOTHBRUSH_TIME_GEARS: | |||||
case ToothBrushBleCmd.SET_MANUAL_MODE: | |||||
if (bytes.length >= 2) { | |||||
if (bleToothBrushCallback != null) | |||||
bleToothBrushCallback.onSetDefaultModeAndManualModeResult(bytes[0], bytes[1] & 0xff); | |||||
} | |||||
break; | |||||
case ToothBrushBleCmd.GET_MANUAL_MODE: | |||||
if (bytes.length >= 7) { | |||||
int hzH = (bytes[2] & 0xff) << 8; | |||||
int hzl = bytes[3] & 0xff; | |||||
int duty = bytes[4] & 0xff; | |||||
int timeH = (bytes[5] & 0xff) << 8; | |||||
int timeL = bytes[6] & 0xff; | |||||
if (bleToothBrushCallback != null) { | |||||
bleToothBrushCallback.onGetManualParameter(timeH + timeL, hzH + hzl, duty); | |||||
} | |||||
} | |||||
break; | |||||
case (byte) ToothBrushBleCmd.BRUSH_TEETH_TO_COMPLETE: | |||||
if (bytes.length >= 9) { | |||||
int mode = bytes[1] & 0xff; | |||||
int timeH = (bytes[2] & 0xff) << 8; | |||||
int timeL = bytes[3] & 0xff; | |||||
int lTimeH = (bytes[4] & 0xff) << 8; | |||||
int lTimeL = bytes[5] & 0xff; | |||||
int rTimeH = (bytes[6] & 0xff) << 8; | |||||
int rTimeL = bytes[7] & 0xff; | |||||
int battery = bytes[8] & 0xff; | |||||
if (bleToothBrushCallback != null) { | |||||
bleToothBrushCallback.onTestFinish(timeH + timeL, lTimeH + lTimeL, rTimeH + rTimeL, mode, battery); | |||||
} | |||||
} | |||||
break; | |||||
case ToothBrushBleCmd.THE_TRIAL_ORDER: | |||||
//试用指令 | |||||
if (bytes.length >= 2) | |||||
if (bleToothBrushCallback != null) { | |||||
bleToothBrushCallback.onTryOutResult(bytes[1] & 0xff); | |||||
} | |||||
break; | |||||
case ToothBrushBleCmd.GET_SECOND_GEARS: | |||||
if (bytes.length >= 2) | |||||
if (bleToothBrushCallback != null) { | |||||
bleToothBrushCallback.onTwoLevelModeDefault(bytes[1] & 0xff); | |||||
} | |||||
} | |||||
} | |||||
@Override | |||||
public void onNotifyDataA6(byte[] hex) { | |||||
if (bleToothBrushCallback != null) { | |||||
bleToothBrushCallback.onShowData("蓝牙返回的A6: " + BleStrUtils.byte2HexStr(hex)); | |||||
} | |||||
switch (hex[0]) { | |||||
case (byte) ToothBrushBleCmd.GET_TOOTHBRUSH_GEARS: | |||||
disposeSupportGears(hex); | |||||
break; | |||||
case ToothBrushBleCmd.REQUEST_TOKEN: | |||||
int result = hex[1] & 0xff; | |||||
if (bleToothBrushCallback != null) { | |||||
bleToothBrushCallback.onGetTokenResult(result); | |||||
} | |||||
break; | |||||
} | |||||
} | |||||
private void disposeSupportGears(byte[] hex) { | |||||
if (hex.length > 4 && hex[1] == 0x01) { | |||||
int stair = hex[2] & 0xff; | |||||
int secondLevel = hex[3] & 0xff; | |||||
List<Integer> stairs = new ArrayList<>(); | |||||
List<Integer> secondLevels = new ArrayList<>(); | |||||
if (hex.length >= 4 + stair) { | |||||
for (int i = 0; i < stair; i++) { | |||||
stairs.add((int) hex[i + 4] & 0xff); | |||||
} | |||||
} | |||||
if (hex.length >= 4 + stair + secondLevel) { | |||||
for (int i = 0; i < secondLevel; i++) { | |||||
secondLevels.add((int) hex[i + 4 + stair] & 0xff); | |||||
} | |||||
} | |||||
if (bleToothBrushCallback != null) { | |||||
bleToothBrushCallback.onGetSupportGears(stairs, secondLevels); | |||||
} | |||||
} | |||||
} | |||||
private BleToothBrushCallback bleToothBrushCallback; | |||||
public interface BleToothBrushCallback { | |||||
/** | |||||
* 版本号 | |||||
* version number | |||||
* | |||||
* @param Version | |||||
*/ | |||||
void onVersion(String Version); | |||||
/** | |||||
* 牙刷支持的档位 | |||||
* Gear supported by toothbrush | |||||
* | |||||
* @param staif 一级档位 First gear | |||||
* @param secondLevel 二级档位 Second gear | |||||
*/ | |||||
void onGetSupportGears(List<Integer> staif, List<Integer> secondLevel); | |||||
/** | |||||
* 获取电量 | |||||
* Get battery | |||||
* | |||||
* @param batteryStatus 电池充电状态 Battery charging status | |||||
* 0x00:没有充电(默认) 0x00: No charging (default) | |||||
* 0x01:充电中 0x01: Charging | |||||
* 0x02:充满电 0x02: Fully charged | |||||
* 0x03:充电异常 0x03: abnormal charging | |||||
* @param batteryQuantity 电池电量百分比 (0—100) Battery power percentage (0-100) | |||||
*/ | |||||
void onGetBattery(int batteryStatus, int batteryQuantity); | |||||
/** | |||||
* 获得到默认的刷牙档位和时长 | |||||
* Get the default brushing position and duration | |||||
* | |||||
* @param time 刷牙时长 Brushing time | |||||
* @param gear 刷牙档位 Brushing gear | |||||
* @param gearFrom 刷牙档位级别 Brushing gear level | |||||
*/ | |||||
void onGetDefaultGearAndDuration(int time, int gear, int gearFrom); | |||||
/** | |||||
* 请求授权的回调 | |||||
* Callback to request authorization | |||||
* | |||||
* @param result 0:没有 1:已经授权 2:不需要授权 3:授权成功 {@link ToothBrushBleCmd#NO_TOKEN} | |||||
*/ | |||||
void onGetTokenResult(int result); | |||||
/** | |||||
* 获取手动档位的参数 | |||||
* Get the parameters of manual gear | |||||
* | |||||
* @param time 时长 duration | |||||
* @param hz 频率 frequency | |||||
* @param duty 占空比 Duty cycle | |||||
*/ | |||||
void onGetManualParameter(int time, int hz, int duty); | |||||
/** | |||||
* 设置默认档位和手动模式结果回调 | |||||
* | |||||
* @param type 类型 {@link ToothBrushBleCmd#SET_TOOTHBRUSH_TIME_GEARS, ToothBrushBleCmd#Set_Manual_Mode} | |||||
* @param result 0:设置成功 1:设置失败 2:不支持设置 | |||||
*/ | |||||
void onSetDefaultModeAndManualModeResult(byte type, int result); | |||||
/** | |||||
* 刷牙完成 | |||||
* Brushing is done | |||||
* | |||||
* @param totalTime 刷牙总时长 Total brushing time | |||||
* @param leftTime 左边刷牙时间 Brushing time on the left | |||||
* @param rightTime 右边刷牙时间 Brushing time on the right | |||||
* @param mode 刷牙模式 Brushing mode | |||||
* @param battery 电量 Power | |||||
*/ | |||||
void onTestFinish(int totalTime, int leftTime, int rightTime, int mode, int battery); | |||||
/** | |||||
* 试用回调 | |||||
* Trial callback | |||||
* | |||||
* @param result 0:设置成功 0: Setting is successful | |||||
* 1:设置失败,原因未知 1: Setting fails, the reason is unknown | |||||
* 2:不支持设置 2: Setting is not supported | |||||
*/ | |||||
void onTryOutResult(int result); | |||||
/** | |||||
* 获取二级档位默认值 | |||||
* Get the default value of the second gear | |||||
* | |||||
* @param mode 0x00:不支持 0x00: not supported | |||||
* 0x01-0xfe:工作档位编号 0x01-0xfe: working gear number | |||||
* 0xFF:手动设置档位 0xFF: manual setting of gear | |||||
*/ | |||||
void onTwoLevelModeDefault(int mode); | |||||
/** | |||||
* 蓝牙返回的数据 | |||||
* Data returned by Bluetooth | |||||
* | |||||
* @param data | |||||
*/ | |||||
void onShowData(String data); | |||||
} | |||||
/** | |||||
* 获取支持的单位 A6指令 | |||||
* Supported unit | |||||
*/ | |||||
public void getSupportGears() { | |||||
byte[] bytes = new byte[2]; | |||||
bytes[0] = ToothBrushBleCmd.GET_TOOTHBRUSH_GEARS; | |||||
bytes[1] = 0x01; | |||||
sendA6(bytes); | |||||
} | |||||
/** | |||||
* 获取到电量 | |||||
* Get power | |||||
*/ | |||||
public void getBattery() { | |||||
sendA6(BleSendCmdUtil.getInstance().getMcuBatteryStatus()); | |||||
} | |||||
/** | |||||
* 获取默认模式和时长 | |||||
* Get the default mode and duration | |||||
*/ | |||||
public void getdefaultGearAndDuration() { | |||||
byte[] bytes = new byte[1]; | |||||
bytes[0] = ToothBrushBleCmd.GET_TOOTHBRUSH_TIME_GEARS; | |||||
sendA7(bytes); | |||||
} | |||||
public void setOta() { | |||||
// 91 01 | |||||
byte[] bytes = new byte[2]; | |||||
bytes[0] = (byte) 0x91; | |||||
bytes[1] = 0x01; | |||||
sendA6(bytes); | |||||
} | |||||
/** | |||||
* 发起连接 | |||||
* Initiate connection | |||||
* | |||||
* @return | |||||
*/ | |||||
public void connectWifi() { | |||||
byte[] bytes = new byte[2]; | |||||
bytes[0] = (byte) 0x88; | |||||
bytes[1] = 0x01; | |||||
sendA6(bytes); | |||||
} | |||||
/** | |||||
* 设置试用 | |||||
* Set up trial | |||||
*/ | |||||
public void setTryOut(int id, int level, int hz, int duty) { | |||||
byte[] bytes = new byte[14]; | |||||
bytes[0] = ToothBrushBleCmd.THE_TRIAL_ORDER; | |||||
bytes[1] = (byte) id; | |||||
bytes[2] = (byte) level; | |||||
bytes[3] = (byte) 0xff; | |||||
bytes[4] = (byte) (hz >> 8); | |||||
bytes[5] = (byte) hz; | |||||
bytes[6] = (byte) duty; | |||||
bytes[7] = (byte) 0; | |||||
bytes[8] = (byte) 0; | |||||
bytes[9] = (byte) 0; | |||||
bytes[10] = (byte) 0; | |||||
bytes[11] = (byte) 0; | |||||
bytes[12] = (byte) 0; | |||||
bytes[13] = (byte) 0; | |||||
sendA7(bytes); | |||||
} | |||||
/** | |||||
* 设置默认 | |||||
* Set the default | |||||
*/ | |||||
public void setDefault(int time, int mode, int level) { | |||||
byte[] bytes = new byte[5]; | |||||
bytes[0] = ToothBrushBleCmd.SET_TOOTHBRUSH_TIME_GEARS; | |||||
bytes[1] = (byte) (time >> 8); | |||||
bytes[2] = (byte) time; | |||||
bytes[3] = (byte) mode; | |||||
bytes[4] = (byte) level; | |||||
sendA7(bytes); | |||||
} | |||||
/** | |||||
* 下发数据上报成功 | |||||
* Successfully sent data and reported | |||||
*/ | |||||
public void testFinishSuccess() { | |||||
byte[] bytes = new byte[2]; | |||||
bytes[0] = (byte) ToothBrushBleCmd.Issue_Data_Report_Completed; | |||||
bytes[1] = 0x01; | |||||
sendA7(bytes); | |||||
} | |||||
/** | |||||
* APP 设置二级档位默认值 | |||||
* Set the default value of the second gear | |||||
*/ | |||||
public void setTwoLevelDefault(int modeId) { | |||||
byte[] bytes = new byte[2]; | |||||
bytes[0] = ToothBrushBleCmd.Set_Second_GEARS; | |||||
bytes[1] = (byte) modeId; | |||||
sendA7(bytes); | |||||
} | |||||
/** | |||||
* APP 获取二级档位默认值 | |||||
*/ | |||||
public void getTwoLevelDefault() { | |||||
byte[] bytes = new byte[1]; | |||||
bytes[0] = ToothBrushBleCmd.GET_SECOND_GEARS; | |||||
sendA7(bytes); | |||||
} | |||||
/** | |||||
* 开始刷牙 | |||||
* Get the default value of the second gear | |||||
*/ | |||||
public void starTooth() { | |||||
byte[] bytes = new byte[1]; | |||||
bytes[0] = ToothBrushBleCmd.Start_Close_ToothBrush; | |||||
sendA7(bytes); | |||||
} | |||||
/** | |||||
* 设置手动模式的参数 | |||||
* Set the parameters of manual mode | |||||
*/ | |||||
public void setManualParameter(int hz, int duty, int time) { | |||||
byte[] bytes = new byte[7]; | |||||
bytes[0] = ToothBrushBleCmd.SET_MANUAL_MODE; | |||||
bytes[1] = 0x00; | |||||
bytes[2] = (byte) (hz >> 8); | |||||
bytes[3] = (byte) hz; | |||||
bytes[4] = (byte) duty; | |||||
bytes[5] = (byte) (time >> 8); | |||||
bytes[6] = (byte) time; | |||||
sendA7(bytes); | |||||
} | |||||
/** | |||||
* 获取手动模式的参数 | |||||
* Get the parameters of manual mode | |||||
*/ | |||||
public void getManualParameter() { | |||||
byte[] bytes = new byte[1]; | |||||
bytes[0] = ToothBrushBleCmd.GET_MANUAL_MODE; | |||||
sendA7(bytes); | |||||
} | |||||
/** | |||||
* APP 请求授权 Payload | |||||
* Request authorization | |||||
* | |||||
* @param toothbrushId 时间搓 | |||||
*/ | |||||
public void requestToken(long toothbrushId) { | |||||
byte[] timebyte = long2Bytes(toothbrushId); //long 长度8 byte 时间搓是6个byte 所以去后面6位 | |||||
byte[] bytes = new byte[7]; | |||||
bytes[0] = ToothBrushBleCmd.REQUEST_TOKEN; | |||||
bytes[1] = timebyte[2]; | |||||
bytes[2] = timebyte[3]; | |||||
bytes[3] = timebyte[4]; | |||||
bytes[4] = timebyte[5]; | |||||
bytes[5] = timebyte[6]; | |||||
bytes[6] = timebyte[7]; | |||||
sendA6(bytes); | |||||
} | |||||
private byte[] long2Bytes(long num) { | |||||
byte[] byteNum = new byte[8]; | |||||
for (int ix = 0; ix < 8; ++ix) { | |||||
int offset = 64 - (ix + 1) * 8; | |||||
byteNum[ix] = (byte) ((num >> offset) & 0xff); | |||||
} | |||||
return byteNum; | |||||
} | |||||
private SendBleBean sendBleBean; | |||||
/** | |||||
* 发送A6指令 | |||||
* | |||||
* @param bytes | |||||
*/ | |||||
public void sendA6(byte[] bytes) { | |||||
if (sendBleBean == null) { | |||||
sendBleBean = new SendBleBean(); | |||||
} | |||||
sendBleBean.setHex(bytes); | |||||
sendData(sendBleBean); | |||||
} | |||||
/** | |||||
* 断开连接 | |||||
* Disconnect | |||||
* | |||||
* @return SendBleBean | |||||
*/ | |||||
public void disconnectWifi() { | |||||
byte[] bytes = new byte[2]; | |||||
bytes[0] = (byte) 0x88; | |||||
bytes[1] = 0x00; | |||||
sendA6(bytes); | |||||
} | |||||
/** | |||||
* 发送A7指令 | |||||
* | |||||
* @param bytes | |||||
*/ | |||||
public void sendA7(byte[] bytes) { | |||||
SendMcuBean sendMcuBean = new SendMcuBean(); | |||||
sendMcuBean.setHex(TOOTHBRUSH_BLE, bytes); | |||||
sendData(sendMcuBean); | |||||
} | |||||
} |
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||||
import android.content.Intent; | |||||
import android.content.pm.ActivityInfo; | |||||
import android.os.Bundle; | |||||
import android.os.Handler; | |||||
import android.os.Message; | |||||
import android.view.View; | |||||
import android.widget.ArrayAdapter; | |||||
import android.widget.EditText; | |||||
import android.widget.ListView; | |||||
import android.widget.Toast; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | |||||
import com.pingwang.bluetoothlib.config.CmdConfig; | |||||
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 aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.WifiDialog; | |||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.ToothBrush.ToothBrushBleCmd; | |||||
import cn.net.aicare.modulelibrary.module.ToothBrush.ToothBrushWiFiBleUtilsData; | |||||
/** | |||||
* Wifi+ble 牙刷 | |||||
*/ | |||||
public class ToothBrushWifiBleActivity extends BleBaseActivity implements View.OnClickListener, OnCallbackBle, ToothBrushWiFiBleUtilsData.BleToothBrushWiFiCallback, ToothBrushWiFiBleUtilsData.BleToothBrushCallback { | |||||
private String TAG = ToothBrushWifiBleActivity.class.getName(); | |||||
private String mAddress; | |||||
private List<String> mList; | |||||
private ArrayAdapter listAdapter; | |||||
private ToothBrushWiFiBleUtilsData mToothBrushWiFiBleUtilsData; | |||||
private MHandler mMHandler; | |||||
private EditText mEditText, select_gears_et; | |||||
private String dataPaw; | |||||
@Override | |||||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||||
super.onCreate(savedInstanceState); | |||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//禁止横屏 | |||||
setContentView(R.layout.activity_tooth_brush_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.support_unit).setOnClickListener(this); | |||||
findViewById(R.id.default_try_out).setOnClickListener(this); | |||||
findViewById(R.id.default_time_mode).setOnClickListener(this); | |||||
findViewById(R.id.default_mode).setOnClickListener(this); | |||||
findViewById(R.id.ota).setOnClickListener(this); | |||||
mEditText = findViewById(R.id.select_wifi_et); | |||||
select_gears_et = findViewById(R.id.select_gears_et); | |||||
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(); | |||||
} | |||||
@Override | |||||
protected void onNewIntent(Intent intent) { | |||||
super.onNewIntent(intent); | |||||
setIntent(intent); | |||||
} | |||||
@Override | |||||
public void onServiceSuccess() { | |||||
//与服务建立连接 | |||||
mList.add(0, "服务与界面建立连接成功"); | |||||
// mList.add(0, "搜索设备"); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.scanLeDevice(30 * 1000); | |||||
} | |||||
@Override | |||||
public void onServiceErr() { | |||||
} | |||||
@Override | |||||
public void unbindServices() { | |||||
} | |||||
@Override | |||||
public void onStartScan() { | |||||
} | |||||
@Override | |||||
public void onScanning(BleValueBean data) { | |||||
BleLog.i(TAG, "MAC=" + mAddress + "||CID=" + data.getCid() + "||VID=" + data.getVid() + "||PID=" + data.getPid()); | |||||
if (data.getMac().equalsIgnoreCase(mAddress)) { | |||||
mBluetoothService.connectDevice(data.getMac()); | |||||
} | |||||
} | |||||
@Override | |||||
public void onScanTimeOut() { | |||||
} | |||||
@Override | |||||
public void onConnecting(String mac) { | |||||
} | |||||
@Override | |||||
public void onDisConnected(String mac, int code) { | |||||
mList.add(0, "蓝牙已断开"); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onServicesDiscovered(String mac) { | |||||
mList.add(0, "蓝牙已连接"); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
mBluetoothService.setOnCallback(this); | |||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | |||||
if (bleDevice != null) { | |||||
ToothBrushWiFiBleUtilsData.init(bleDevice, this, this); | |||||
mToothBrushWiFiBleUtilsData = ToothBrushWiFiBleUtilsData.getInstance(); | |||||
mMHandler.sendEmptyMessageDelayed(ToRequestToken, 600); | |||||
mMHandler.sendEmptyMessageDelayed(GETBATTERY, 800); | |||||
} | |||||
} | |||||
@Override | |||||
public void bleOpen() { | |||||
} | |||||
@Override | |||||
public void bleClose() { | |||||
} | |||||
@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) { | |||||
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; | |||||
/** | |||||
* @param type {@link CmdConfig#SET_WIFI_MAC} | |||||
* @param status {@link ToothBrushBleCmd#STATUS_SUCCESS} | |||||
*/ | |||||
@Override | |||||
public void OnSetWifiNameOrPwdOrConnectCallback(int type, int status) { | |||||
if (type == CmdConfig.SET_WIFI_MAC) { | |||||
mList.add(0, "获取到设置的mac地址状态 " + status); | |||||
if (status == ToothBrushBleCmd.STATUS_SUCCESS) { | |||||
issetMac = true; | |||||
setPaw(dataPaw); | |||||
} | |||||
} | |||||
if (type == CmdConfig.SET_WIFI_PWD) { | |||||
mList.add(0, "获取到设置的密码状态 " + status); | |||||
if (status == ToothBrushBleCmd.STATUS_SUCCESS && issetMac) { | |||||
mMHandler.sendEmptyMessage(ConnectWifi); | |||||
} | |||||
} | |||||
if (type == CmdConfig.DISCONNECT_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 sn) { | |||||
mList.add(0, "sn: " + sn); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onClick(View v) { | |||||
int id = v.getId(); | |||||
if (mToothBrushWiFiBleUtilsData != null) | |||||
switch (id) { | |||||
case R.id.wifistatus: | |||||
mToothBrushWiFiBleUtilsData.queryBleStatus(); | |||||
break; | |||||
case R.id.sn: | |||||
mToothBrushWiFiBleUtilsData.getDevicedid(); | |||||
break; | |||||
case R.id.scan_wifi: | |||||
mToothBrushWiFiBleUtilsData.scanWifi(); | |||||
break; | |||||
case R.id.connect_wifi: | |||||
try { | |||||
int selectWifi = Integer.valueOf(mEditText.getText().toString().trim()); | |||||
if (mHashMap.get(selectWifi) != null && wifimacMap.get(selectWifi) != null) { | |||||
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) { | |||||
if (data.equals("") || data.length() > 8) { | |||||
dataPaw = data.trim(); | |||||
mToothBrushWiFiBleUtilsData.setWifimac(wifimacMap.get(selectWifi)); | |||||
} else { | |||||
Toast.makeText(ToothBrushWifiBleActivity.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.setedname: | |||||
mToothBrushWiFiBleUtilsData.getConnectWifiName(); | |||||
break; | |||||
case R.id.disconnect: | |||||
mToothBrushWiFiBleUtilsData.disconnectWifi(); | |||||
break; | |||||
case R.id.support_unit: | |||||
mToothBrushWiFiBleUtilsData.getSupportGears(); | |||||
break; | |||||
case R.id.default_mode: | |||||
String gear = select_gears_et.getText().toString().trim(); | |||||
if (!gear.isEmpty()) { | |||||
String[] gears = null; | |||||
if (gear.contains(",")) { | |||||
gears = gear.split(","); | |||||
} else if (gear.contains(",")) { | |||||
gears = gear.split(","); | |||||
} else { | |||||
Toast.makeText(this, "请输入时长,档位,档位级别(数字加符号)", Toast.LENGTH_SHORT).show(); | |||||
} | |||||
if (gears != null) { | |||||
try { | |||||
mToothBrushWiFiBleUtilsData.setDefault(Integer.parseInt(gears[0]), Integer.parseInt(gears[1]), Integer.parseInt(gears[2])); | |||||
} catch (NumberFormatException e) { | |||||
e.printStackTrace(); | |||||
Toast.makeText(this, "请输入时长,档位,档位级别(数字加符号)", Toast.LENGTH_SHORT).show(); | |||||
} | |||||
} | |||||
} | |||||
break; | |||||
case R.id.default_try_out: | |||||
String gear1 = select_gears_et.getText().toString().trim(); | |||||
if (!gear1.isEmpty()) { | |||||
String[] gears = null; | |||||
if (gear1.contains(",")) { | |||||
gears = gear1.split(","); | |||||
} else if (gear1.contains(",")) { | |||||
gears = gear1.split(","); | |||||
} else { | |||||
Toast.makeText(this, "请输入时长,档位,档位级别(数字加符号)", Toast.LENGTH_SHORT).show(); | |||||
} | |||||
if (gears != null) { | |||||
try { | |||||
mToothBrushWiFiBleUtilsData.setTryOut(Integer.parseInt(gears[1]), Integer.parseInt(gears[2]), 0, 0); | |||||
} catch (Exception e) { | |||||
e.printStackTrace(); | |||||
Toast.makeText(this, "请输入时长,档位,档位级别(数字加符号)", Toast.LENGTH_SHORT).show(); | |||||
} | |||||
} | |||||
} | |||||
break; | |||||
case R.id.default_time_mode: | |||||
mToothBrushWiFiBleUtilsData.getDefaultGearAndDuration(); | |||||
break; | |||||
case R.id.ota: | |||||
mToothBrushWiFiBleUtilsData.setOta(); | |||||
break; | |||||
} | |||||
} | |||||
private final int ToRefreUi = 300; | |||||
private final int ConnectWifi = 400; | |||||
private final int ToRequestToken = 500; | |||||
private final int GETBATTERY = 600; | |||||
@Override | |||||
public void onVersion(String version) { | |||||
mList.add(0, "版本号:" + version); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onGetSupportGears(List<Integer> staif, List<Integer> secondLevel) { | |||||
mList.add(0, "牙刷支持的一级档位:" + Arrays.toString(staif.toArray()) + " 二级档位:" + Arrays.toString(secondLevel.toArray())); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onGetBattery(int batteryStatus, int batteryQuantity) { | |||||
mList.add(0, "电池状态:" + batteryStatus + " 电量:" + batteryQuantity); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onGetDefaultGearAndDuration(int time, int gear, int gearFrom) { | |||||
mList.add(0, "获得到默认的刷牙档位和时长:" + time + " 档位:" + gear + " 档位级别" + gearFrom); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onGetTokenResult(int result) { | |||||
String s = ""; | |||||
if (result == ToothBrushBleCmd.NO_TOKEN) { | |||||
s = "没有"; | |||||
} else if (result == ToothBrushBleCmd.HAS_TOKEN) { | |||||
s = "已经授权"; | |||||
} else if (result == ToothBrushBleCmd.WITHOUT_TOKEN) { | |||||
s = "不需要授权"; | |||||
} else if (result == ToothBrushBleCmd.SUCCESSTOKEN) { | |||||
s = "授权成功"; | |||||
} | |||||
mList.add(0, "请求授权结果" + result + " " + s); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onGetManualParameter(int time, int hz, int duty) { | |||||
mList.add(0, " 获取手动档位的参数: 时长" + time + " 频率" + hz + " 占空比" + duty); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onSetDefaultModeAndManualModeResult(byte type, int result) { | |||||
String s = ""; | |||||
if (result == 0) { | |||||
s = "设置成功"; | |||||
} else if (result == 1) { | |||||
s = "设置失败"; | |||||
} else if (result == 2) { | |||||
s = "不支持设置"; | |||||
} | |||||
if (type == ToothBrushBleCmd.SET_TOOTHBRUSH_TIME_GEARS) { | |||||
mList.add(0, " 设置默认刷牙时长和工作档位: 结果" + result + " " + s); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} else { | |||||
mList.add(0, " 设置手动设置(自定义)档位: 结果" + result + " " + s); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
} | |||||
@Override | |||||
public void onTestFinish(int totalTime, int leftTime, int rightTime, int mode, int battery) { | |||||
mList.add(0, "刷牙完成: 总时长:" + totalTime + " 左时长:" + leftTime + " 右时长:" + rightTime + " 模式:" + mode + " 电量:" + battery); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onTryOutResult(int result) { | |||||
mList.add(0, "设置使用结果:" + result + " ( 0:设置成功 1:设置失败,原因未知 2:不支持设置)"); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onTwoLevelModeDefault(int mode) { | |||||
mList.add(0, "获取二级档位默认值:" + mode); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onOTA(int status) { | |||||
String s = " "; | |||||
switch (status) { | |||||
case 0x00: | |||||
s = "wifiOTA 成功"; | |||||
break; | |||||
case 0x01: | |||||
s = "wifiOTA 失败"; | |||||
break; | |||||
case 0x02: | |||||
s = "不支持 wifiOTA"; | |||||
break; | |||||
case 0x03: | |||||
s = "模块主动开始 wifiOTA(MCU 收到该指 令后不能断电,需要等待 OTA 成功或者失败)"; | |||||
break; | |||||
} | |||||
mList.add(0, s); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | |||||
@Override | |||||
public void onShowData(String data) { | |||||
} | |||||
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: | |||||
mToothBrushWiFiBleUtilsData.connectWifi(); | |||||
break; | |||||
case ToRequestToken: | |||||
mList.add(0, "请求授权"); | |||||
mToothBrushWiFiBleUtilsData.requestToken(System.currentTimeMillis()); | |||||
if (listAdapter != null) { | |||||
listAdapter.notifyDataSetChanged(); | |||||
} | |||||
break; | |||||
case GETBATTERY: | |||||
mToothBrushWiFiBleUtilsData.getBattery(); | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* wifi密码一次只能传14个byte | |||||
* 如果密码长度超过14个byte 就需要分包传送 | |||||
* subpackage 为0 时,表示后面还有数据 | |||||
* subpackage 为1 时,表示数据小于或等于14个byte,后面没有数据 | |||||
* | |||||
* @param paw | |||||
*/ | |||||
private void setPaw(String paw) { | |||||
if (paw.isEmpty()) { | |||||
byte[] bytes = new byte[0]; | |||||
mToothBrushWiFiBleUtilsData.setWifiPwd(0, bytes); | |||||
} else { | |||||
byte[] password = BleStrUtils.stringToBytes(paw); | |||||
if (password != null) { | |||||
if (password.length < 14) | |||||
mToothBrushWiFiBleUtilsData.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); | |||||
mToothBrushWiFiBleUtilsData.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); | |||||
mToothBrushWiFiBleUtilsData.setWifiPwd(1, bytes); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} |
import android.widget.EditText; | import android.widget.EditText; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | ||||
import com.pingwang.bluetoothlib.device.SendBleBean; | import com.pingwang.bluetoothlib.device.SendBleBean; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.tpms.TpmsDeviceData; | import cn.net.aicare.modulelibrary.module.tpms.TpmsDeviceData; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.bean.SupportUnitBean; | import com.pingwang.bluetoothlib.bean.SupportUnitBean; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.Transmission.TransmissionDeviceData; | import cn.net.aicare.modulelibrary.module.Transmission.TransmissionDeviceData; | ||||
/** | /** | ||||
// BleLog.i(TAG, "服务与界面建立连接成功"); | // BleLog.i(TAG, "服务与界面建立连接成功"); | ||||
//与服务建立连接 | //与服务建立连接 | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | ||||
if (bleDevice != null) { | if (bleDevice != null) { | ||||
if (tv_device_info!=null) { | if (tv_device_info!=null) { | ||||
@Override | @Override | ||||
public void unbindServices() { | public void unbindServices() { | ||||
if (mBluetoothService!=null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | } | ||||
@Override | @Override | ||||
public void showData(String data, int type) { | public void showData(String data, int type) { | ||||
mlogList.add(0, "收 payload数据" + TimeUtils.getTime() +"cid=" + type + "\n" + data); | |||||
mlogList.add(0, "收 payload数据" + TimeUtils.getTimeSSS() +"cid=" + type + "\n" + data); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | mMHandler.sendEmptyMessage(ToRefreUi); | ||||
} | } | ||||
@Override | @Override | ||||
public void sendData(String data) { | public void sendData(String data) { | ||||
mlogList.add(0, "发 " + TimeUtils.getTime() + data); | |||||
mlogList.add(0, "发 " + TimeUtils.getTimeSSS() + data); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | mMHandler.sendEmptyMessage(ToRefreUi); | ||||
} | } | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.RadioButton; | import android.widget.RadioButton; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import com.pingwang.bluetoothlib.config.CmdConfig; | import com.pingwang.bluetoothlib.config.CmdConfig; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.config.BleDeviceConfig; | import aicare.net.cn.sdk.ailinksdkdemoandroid.config.BleDeviceConfig; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.AddUserDialog; | import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.AddUserDialog; | ||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.BodyFatScale.AppHistoryRecordBean; | import cn.net.aicare.modulelibrary.module.BodyFatScale.AppHistoryRecordBean; | ||||
import cn.net.aicare.modulelibrary.module.BodyFatScale.BodyFatBleUtilsData; | import cn.net.aicare.modulelibrary.module.BodyFatScale.BodyFatBleUtilsData; | ||||
import cn.net.aicare.modulelibrary.module.BodyFatScale.BodyFatDataUtil; | import cn.net.aicare.modulelibrary.module.BodyFatScale.BodyFatDataUtil; | ||||
// BleLog.i(TAG, "服务与界面建立连接成功"); | // BleLog.i(TAG, "服务与界面建立连接成功"); | ||||
//与服务建立连接 | //与服务建立连接 | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | ||||
if (bleDevice != null) { | if (bleDevice != null) { | ||||
BodyFatBleUtilsData.init(bleDevice, this, null); | BodyFatBleUtilsData.init(bleDevice, this, null); | ||||
public void unbindServices() { | public void unbindServices() { | ||||
mlogList.add(0, "服务与界面建立断开连接成功"); | mlogList.add(0, "服务与界面建立断开连接成功"); | ||||
mMHandler.sendEmptyMessage(ToRefreUi); | mMHandler.sendEmptyMessage(ToRefreUi); | ||||
if (mBluetoothService!=null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | } | ||||
@Override | @Override | ||||
mMHandler.sendEmptyMessage(ToRefreUi); | mMHandler.sendEmptyMessage(ToRefreUi); | ||||
} | } | ||||
private String mOldData = ""; | |||||
@Override | @Override | ||||
public void onWeightData(int status, float weight, int weightUnit, int decimals) { | public void onWeightData(int status, float weight, int weightUnit, int decimals) { | ||||
mlogList.add(0, "体重数据类型:" + status + " 体重: " + weight + " 单位:" + weightUnit + " 小数点位: " + decimals); | |||||
String data = "体重数据类型:" + (status==BodyFatDataUtil.WEIGHT_TESTING?"实时":"稳定") + "\n体重: " + weight + " 单位:" + weightUnit + " 小数点位: " + decimals; | |||||
if (mOldData.equals(data)) { | |||||
return; | |||||
} | |||||
mOldData = data; | |||||
mlogList.add(0, data); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | mMHandler.sendEmptyMessage(ToRefreUi); | ||||
} | } | ||||
private int mOldStatus = -1; | |||||
@Override | @Override | ||||
public void onStatus(int status) { | public void onStatus(int status) { | ||||
if (mOldStatus == status) { | |||||
return; | |||||
} | |||||
mOldStatus = status; | |||||
switch (status) { | switch (status) { | ||||
case BodyFatDataUtil.WEIGHT_TESTING: | case BodyFatDataUtil.WEIGHT_TESTING: |
import android.content.Intent; | import android.content.Intent; | ||||
import android.content.pm.ActivityInfo; | import android.content.pm.ActivityInfo; | ||||
import android.net.Uri; | import android.net.Uri; | ||||
import android.os.Build; | |||||
import android.os.Bundle; | import android.os.Bundle; | ||||
import android.os.Environment; | |||||
import android.os.Handler; | import android.os.Handler; | ||||
import android.os.Message; | import android.os.Message; | ||||
import android.text.TextUtils; | |||||
import android.view.View; | import android.view.View; | ||||
import android.widget.ArrayAdapter; | import android.widget.ArrayAdapter; | ||||
import android.widget.CompoundButton; | import android.widget.CompoundButton; | ||||
import android.widget.EditText; | import android.widget.EditText; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.RadioButton; | import android.widget.RadioButton; | ||||
import android.widget.TextView; | |||||
import android.widget.Toast; | import android.widget.Toast; | ||||
import com.elinkthings.bleotalibrary.listener.OnBleOTAListener; | |||||
import com.elinkthings.bleotalibrary.netstrap.OPLOtaManager; | |||||
import androidx.activity.result.ActivityResultLauncher; | |||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import com.pingwang.bluetoothlib.config.CmdConfig; | import com.pingwang.bluetoothlib.config.CmdConfig; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.utils.BleLog; | import com.pingwang.bluetoothlib.utils.BleLog; | ||||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | import com.pingwang.bluetoothlib.utils.BleStrUtils; | ||||
import java.io.File; | |||||
import java.lang.ref.WeakReference; | import java.lang.ref.WeakReference; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.config.BleDeviceConfig; | import aicare.net.cn.sdk.ailinksdkdemoandroid.config.BleDeviceConfig; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.DialogStringImageBean; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.ShowListDialogFragment; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.WifiDialog; | import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.WifiDialog; | ||||
import androidx.annotation.Nullable; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.FileUtils; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.ResultContact; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.SP; | |||||
import cn.net.aicare.modulelibrary.module.BodyFatScale.AppHistoryRecordBean; | import cn.net.aicare.modulelibrary.module.BodyFatScale.AppHistoryRecordBean; | ||||
import cn.net.aicare.modulelibrary.module.BodyFatScale.BodyFatBleUtilsData; | import cn.net.aicare.modulelibrary.module.BodyFatScale.BodyFatBleUtilsData; | ||||
import cn.net.aicare.modulelibrary.module.BodyFatScale.BodyFatDataUtil; | import cn.net.aicare.modulelibrary.module.BodyFatScale.BodyFatDataUtil; | ||||
private RadioButton kg, jing, stlb, lb; | private RadioButton kg, jing, stlb, lb; | ||||
private EditText et_ip, et_url, et_port; | private EditText et_ip, et_url, et_port; | ||||
private TextView tv_path; | |||||
private byte[] testIp = new byte[]{0x74, 0x65, 0x73, 0x74, 0x2e, 0x61, 0x69, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, 0x72, 0x65, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x61, 0x69, 0x63, 0x61, 0x72, 0x65, 0x2e, | |||||
0x6e, 0x65, 0x74, 0x2e, 0x63, 0x6e}; | |||||
private byte[] testIp = new byte[]{0x74, 0x65, 0x73, 0x74, 0x2e, 0x61, 0x69, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, 0x72, 0x65, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x61, 0x69, 0x63, 0x61, 0x72, 0x65, 0x2e, 0x6e, 0x65, 0x74, 0x2e, 0x63, 0x6e}; | |||||
private byte[] productIp = new byte[]{0x61, 0x69, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, 0x69, 0x6f, 0x74, 0x2e, 0x61, 0x69, 0x63, 0x61, 0x72, 0x65, 0x2e, 0x6e, 0x65, 0x74, 0x2e, 0x63, 0x6e}; | private byte[] productIp = new byte[]{0x61, 0x69, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, 0x69, 0x6f, 0x74, 0x2e, 0x61, 0x69, 0x63, 0x61, 0x72, 0x65, 0x2e, 0x6e, 0x65, 0x74, 0x2e, 0x63, 0x6e}; | ||||
private byte[] IpUrl = new byte[]{0x2f, 0x64, 0x65, 0x76, 0x69, 0x76, 0x63, 0x64, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x64, 0x72, 0x52, 0x65, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x2f}; | private byte[] IpUrl = new byte[]{0x2f, 0x64, 0x65, 0x76, 0x69, 0x76, 0x63, 0x64, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x64, 0x72, 0x52, 0x65, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x2f}; | ||||
private boolean isTest = false; | private boolean isTest = false; | ||||
private ArrayList<DialogStringImageBean> mDialogList; | |||||
private ActivityResultLauncher<Boolean> launcher; | |||||
@Override | @Override | ||||
protected void onCreate(@Nullable Bundle savedInstanceState) { | protected void onCreate(@Nullable Bundle savedInstanceState) { | ||||
findViewById(R.id.check_ip).setOnClickListener(this); | findViewById(R.id.check_ip).setOnClickListener(this); | ||||
findViewById(R.id.check_port).setOnClickListener(this); | findViewById(R.id.check_port).setOnClickListener(this); | ||||
findViewById(R.id.check_url).setOnClickListener(this); | findViewById(R.id.check_url).setOnClickListener(this); | ||||
findViewById(R.id.reset).setOnClickListener(this); | |||||
findViewById(R.id.btn_select_file).setOnClickListener(this); | |||||
et_ip = findViewById(R.id.et_ip); | et_ip = findViewById(R.id.et_ip); | ||||
et_port = findViewById(R.id.et_port); | et_port = findViewById(R.id.et_port); | ||||
ListView listView = findViewById(R.id.log_list); | ListView listView = findViewById(R.id.log_list); | ||||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | ||||
listView.setAdapter(listAdapter); | listView.setAdapter(listAdapter); | ||||
tv_path = findViewById(R.id.tv_path); | |||||
tv_path.setText("文件路径:手机" + File.separator + Environment.DIRECTORY_DOCUMENTS + File.separator + FileUtils.FILE_DIR); | |||||
WeakReference weakReference = new WeakReference(new MHandler()); | WeakReference weakReference = new WeakReference(new MHandler()); | ||||
mMHandler = (MHandler) weakReference.get(); | mMHandler = (MHandler) weakReference.get(); | ||||
kg.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | kg.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | ||||
} | } | ||||
}); | }); | ||||
FileUtils.init(); | |||||
mDialogList = new ArrayList<>(); | |||||
initLauncher(); | |||||
} | } | ||||
private void initLauncher() { | |||||
launcher = registerForActivityResult(new ResultContact(), result -> { | |||||
if (!TextUtils.isEmpty(result)) { | |||||
SP.getInstance().putOtaFileName(result); | |||||
mList.add(0, "选择文件:" + result); | |||||
listAdapter.notifyDataSetChanged(); | |||||
} | |||||
}); | |||||
} | |||||
@Override | @Override | ||||
public void onServiceSuccess() { | public void onServiceSuccess() { | ||||
BleLog.i(TAG, "服务与界面建立连接成功"); | BleLog.i(TAG, "服务与界面建立连接成功"); | ||||
//与服务建立连接 | //与服务建立连接 | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | ||||
if (bleDevice != null) { | if (bleDevice != null) { | ||||
BodyFatBleUtilsData.init(bleDevice, this, this); | BodyFatBleUtilsData.init(bleDevice, this, this); | ||||
@Override | @Override | ||||
public void unbindServices() { | public void unbindServices() { | ||||
if (mBluetoothService != null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | } | ||||
@Override | @Override | ||||
} | } | ||||
private String mOldData = ""; | |||||
@Override | @Override | ||||
public void onWeightData(int status, float weight, int weightUnit, int decimals) { | public void onWeightData(int status, float weight, int weightUnit, int decimals) { | ||||
mList.add(0, "体重数据类型:" + status + " 体重: " + weight + " 单位:" + weightUnit + " 小数点位: " + decimals); | |||||
String data = "体重数据类型:" + (status==BodyFatDataUtil.WEIGHT_TESTING?"实时":"稳定") + "\n体重: " + weight + " 单位:" + weightUnit + " 小数点位: " + decimals; | |||||
if (mOldData.equals(data)) { | |||||
return; | |||||
} | |||||
mOldData = data; | |||||
mList.add(0, mOldData); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | mMHandler.sendEmptyMessage(ToRefreUi); | ||||
} | } | ||||
private int mOldStatus = -1; | |||||
@Override | @Override | ||||
public void onStatus(int status) { | public void onStatus(int status) { | ||||
if (mOldStatus == status) { | |||||
return; | |||||
} | |||||
mOldStatus = status; | |||||
switch (status) { | switch (status) { | ||||
case BodyFatDataUtil.WEIGHT_TESTING: | case BodyFatDataUtil.WEIGHT_TESTING: | ||||
public void onHistoryMcu(McuHistoryRecordBean mcuHistoryRecordBean) { | public void onHistoryMcu(McuHistoryRecordBean mcuHistoryRecordBean) { | ||||
mList.add(0, "历史记录Mcu:" + mcuHistoryRecordBean.toString()); | mList.add(0, "历史记录Mcu:" + mcuHistoryRecordBean.toString()); | ||||
mMHandler.sendEmptyMessage(ToRefreUi); | mMHandler.sendEmptyMessage(ToRefreUi); | ||||
// mMHandler.sendEmptyMessage(ToRefreUi); | |||||
// mMHandler.sendEmptyMessage(ToRefreUi); | |||||
} | } | ||||
@Override | @Override | ||||
@Override | @Override | ||||
public void OnWifiListName(int no, String name) { | public void OnWifiListName(int no, String name) { | ||||
// mList.add(0,"WIFI序号: "+no+" WIFI名称: "+name); | |||||
// mList.add(0,"WIFI序号: "+no+" WIFI名称: "+name); | |||||
mHashMap.put(no, name); | mHashMap.put(no, name); | ||||
mMHandler.sendEmptyMessage(ToRefreUi); | mMHandler.sendEmptyMessage(ToRefreUi); | ||||
} | } | ||||
@Override | @Override | ||||
public void onSetIpStatus(int status) { | public void onSetIpStatus(int status) { | ||||
// if (status == 0) { | |||||
// if (isTest) { | |||||
// mList.add(0, "设置环境IP为生产环境成功"); | |||||
// mList.add(0, "设置环境路径为生产环境"); | |||||
// } else { | |||||
// mList.add(0, "设置环境IP为测试环境成功"); | |||||
// mList.add(0, "设置环境路径为测试环境"); | |||||
// } | |||||
// setIpUrl(IpUrl); | |||||
// } else { | |||||
// mList.add(0, "设置环境IP失败"); | |||||
// } | |||||
// listAdapter.notifyDataSetChanged(); | |||||
// if (status == 0) { | |||||
// if (isTest) { | |||||
// mList.add(0, "设置环境IP为生产环境成功"); | |||||
// mList.add(0, "设置环境路径为生产环境"); | |||||
// } else { | |||||
// mList.add(0, "设置环境IP为测试环境成功"); | |||||
// mList.add(0, "设置环境路径为测试环境"); | |||||
// } | |||||
// setIpUrl(IpUrl); | |||||
// } else { | |||||
// mList.add(0, "设置环境IP失败"); | |||||
// } | |||||
// listAdapter.notifyDataSetChanged(); | |||||
if (status == 0) { | if (status == 0) { | ||||
mList.add(0, "设置环境IP成功"); | mList.add(0, "设置环境IP成功"); | ||||
int port = Integer.parseInt(et_port.getText().toString()); | int port = Integer.parseInt(et_port.getText().toString()); | ||||
@Override | @Override | ||||
public void onSetIpUrlStatus(int status) { | public void onSetIpUrlStatus(int status) { | ||||
// if (status == 0) { | |||||
// if (isTest) { | |||||
// mList.add(0, "设置环境路径为生产环境成功"); | |||||
// isTest = false; | |||||
// | |||||
// } else { | |||||
// mList.add(0, "设置环境路径为测试环境成功"); | |||||
// isTest = true; | |||||
// | |||||
// } | |||||
// } else { | |||||
// mList.add(0, "设置环境路径失败"); | |||||
// } | |||||
// listAdapter.notifyDataSetChanged(); | |||||
// if (status == 0) { | |||||
// if (isTest) { | |||||
// mList.add(0, "设置环境路径为生产环境成功"); | |||||
// isTest = false; | |||||
// | |||||
// } else { | |||||
// mList.add(0, "设置环境路径为测试环境成功"); | |||||
// isTest = true; | |||||
// | |||||
// } | |||||
// } else { | |||||
// mList.add(0, "设置环境路径失败"); | |||||
// } | |||||
// listAdapter.notifyDataSetChanged(); | |||||
if (status == 0) { | if (status == 0) { | ||||
mList.add(0, "设置环境url成功"); | mList.add(0, "设置环境url成功"); | ||||
} else { | } else { | ||||
public void onClick(View v) { | public void onClick(View v) { | ||||
int id = v.getId(); | int id = v.getId(); | ||||
switch (id) { | switch (id) { | ||||
case R.id.reset: | |||||
mList.add(0, "恢复出厂设置"); | |||||
listAdapter.notifyDataSetChanged(); | |||||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().reset()); | |||||
break; | |||||
case R.id.wifistatus: | case R.id.wifistatus: | ||||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().queryBleStatus()); | bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().queryBleStatus()); | ||||
break; | break; | ||||
showFileChooser(); | showFileChooser(); | ||||
break; | break; | ||||
case R.id.surroundings: | case R.id.surroundings: | ||||
// if (isTest) { | |||||
// setIp(productIp); | |||||
// mList.add(0, "设置环境IP为生产环境"); | |||||
// | |||||
// } else { | |||||
// setIp(testIp); | |||||
// mList.add(0, "设置环境IP为测试环境"); | |||||
// | |||||
// | |||||
// } | |||||
String ipStr = et_ip.getText().toString(); | String ipStr = et_ip.getText().toString(); | ||||
setIp(convertToASCII(ipStr)); | setIp(convertToASCII(ipStr)); | ||||
mList.add(0, "设置环境IP为:" + ipStr); | mList.add(0, "设置环境IP为:" + ipStr); | ||||
listAdapter.notifyDataSetChanged(); | listAdapter.notifyDataSetChanged(); | ||||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().checkUrl()); | bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().checkUrl()); | ||||
break; | break; | ||||
case R.id.btn_select_file: | |||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { | |||||
launcher.launch(true); | |||||
} else { | |||||
mDialogList.clear(); | |||||
ArrayList<String> list = FileUtils.list(); | |||||
for (String s : list) { | |||||
mDialogList.add(new DialogStringImageBean(s, 0)); | |||||
} | |||||
ShowListDialogFragment.newInstance().setTitle("").setCancel("", 0).setCancelBlank(true).setBackground(true).setBottom(false).setList(mDialogList).setOnDialogListener(new ShowListDialogFragment.onDialogListener() { | |||||
@Override | |||||
public void onItemListener(int position) { | |||||
if (mDialogList.size() > position) { | |||||
DialogStringImageBean dialogStringImageBean = mDialogList.get(position); | |||||
String name = dialogStringImageBean.getName(); | |||||
SP.getInstance().putOtaFileName(name); | |||||
} | |||||
} | |||||
}).show(getSupportFragmentManager()); | |||||
} | |||||
break; | |||||
} | } | ||||
} | } | ||||
private byte[] convertToASCII(String string) { | private byte[] convertToASCII(String string) { | ||||
char[] ch = string.toCharArray(); | char[] ch = string.toCharArray(); | ||||
byte[] tmp = new byte[ch.length]; | byte[] tmp = new byte[ch.length]; | ||||
private void setIp(byte[] ips) { | private void setIp(byte[] ips) { | ||||
if (ips.length <= 14) { | |||||
if (ips.length <= 14) | |||||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().environmentIp(0, ips)); | bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().environmentIp(0, ips)); | ||||
} else { | |||||
else { | |||||
boolean isend = false; | boolean isend = false; | ||||
int i = 0; | int i = 0; | ||||
byte[] byte1 = ips; | byte[] byte1 = ips; | ||||
} | } | ||||
private void setIpUrl(byte[] setIpUrl) { | private void setIpUrl(byte[] setIpUrl) { | ||||
if (setIpUrl.length <= 14) { | |||||
if (setIpUrl.length <= 14) | |||||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().environmentUrl(0, setIpUrl)); | bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().environmentUrl(0, setIpUrl)); | ||||
} else { | |||||
else { | |||||
boolean isend = false; | boolean isend = false; | ||||
int i = 0; | int i = 0; | ||||
byte[] byte1 = setIpUrl; | byte[] byte1 = setIpUrl; | ||||
} else { | } else { | ||||
byte[] password = BleStrUtils.stringToBytes(paw); | byte[] password = BleStrUtils.stringToBytes(paw); | ||||
if (password != null) { | if (password != null) { | ||||
if (password.length < 14) { | |||||
if (password.length < 14) | |||||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().setWifiPwd(0, password)); | bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().setWifiPwd(0, password)); | ||||
} else { | |||||
else { | |||||
boolean isend = false; | boolean isend = false; | ||||
int i = 0; | int i = 0; | ||||
byte[] byte1 = password; | byte[] byte1 = password; | ||||
if (resultCode == RESULT_OK) { | if (resultCode == RESULT_OK) { | ||||
Uri uri = data.getData(); | Uri uri = data.getData(); | ||||
String path = uri.getPath(); | String path = uri.getPath(); | ||||
mList.add(0, "ota准备就绪,请勿操作"); | |||||
SP.getInstance().put("WIFI_BLE_OTA_FILE_PATH", path); | |||||
mList.add(0, "选择文件:" + path); | |||||
listAdapter.notifyDataSetChanged(); | listAdapter.notifyDataSetChanged(); | ||||
OPLOtaManager build = OPLOtaManager.newBuilder(this).setFilePath(uri).setOnBleOTAListener(new OnBleOTAListener() { | |||||
@Override | |||||
public void onOtaSuccess() { | |||||
mList.add(0, "ota成功"); | |||||
listAdapter.notifyDataSetChanged(); | |||||
} | |||||
@Override | |||||
public void onOtaFailure(int cmd, String err) { | |||||
mList.add(0, "失败"); | |||||
listAdapter.notifyDataSetChanged(); | |||||
} | |||||
private int mOldProgress = -1; | |||||
} else { | |||||
@Override | |||||
public void onOtaProgress(float progress, int currentCount, int maxCount) { | |||||
if (mOldProgress != progress) { | |||||
mOldProgress = (int) progress; | |||||
mList.add(0, "otaProgress:" + progress); | |||||
listAdapter.notifyDataSetChanged(); | |||||
} | |||||
} | |||||
}).build(bodyFatBleUtilsData.getBleDevice()); | |||||
build.startOta(); | |||||
} | } | ||||
} | } | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.RadioButton; | import android.widget.RadioButton; | ||||
import androidx.annotation.Nullable; | |||||
import androidx.appcompat.app.AppCompatActivity; | |||||
import androidx.core.app.ActivityCompat; | |||||
import androidx.core.content.ContextCompat; | |||||
import org.json.JSONArray; | import org.json.JSONArray; | ||||
import org.json.JSONException; | import org.json.JSONException; | ||||
import org.json.JSONObject; | import org.json.JSONObject; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Locale; | import java.util.Locale; | ||||
import androidx.annotation.Nullable; | |||||
import androidx.appcompat.app.AppCompatActivity; | |||||
import androidx.core.app.ActivityCompat; | |||||
import androidx.core.content.ContextCompat; | |||||
import cn.net.aicare.modulelibrary.module.wifi.WifiConfig; | import cn.net.aicare.modulelibrary.module.wifi.WifiConfig; | ||||
import cn.net.aicare.modulelibrary.module.wifi.WifiUtils; | import cn.net.aicare.modulelibrary.module.wifi.WifiUtils; | ||||
import android.view.ViewGroup; | import android.view.ViewGroup; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.recyclerview.widget.RecyclerView; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import java.util.List; | import java.util.List; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.recyclerview.widget.RecyclerView; | |||||
/** | /** | ||||
* xing<br> | * xing<br> | ||||
} | } | ||||
public static class DialogStringImageBean{ | |||||
String mName; | |||||
long mType; | |||||
public DialogStringImageBean(String name, long type) { | |||||
mName = name; | |||||
mType = type; | |||||
} | |||||
public String getName() { | |||||
return mName; | |||||
} | |||||
public void setName(String name) { | |||||
mName = name; | |||||
} | |||||
public long getType() { | |||||
return mType; | |||||
} | |||||
public void setType(long type) { | |||||
mType = type; | |||||
} | |||||
} | |||||
} | } |
import android.view.View; | import android.view.View; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import java.lang.ref.WeakReference; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.BuildConfig; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.HintDataDialogFragment; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.AppStart; | |||||
import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||
import androidx.annotation.Nullable; | import androidx.annotation.Nullable; | ||||
import androidx.appcompat.app.ActionBar; | import androidx.appcompat.app.ActionBar; | ||||
import androidx.appcompat.widget.Toolbar; | import androidx.appcompat.widget.Toolbar; | ||||
import androidx.core.app.ActivityCompat; | import androidx.core.app.ActivityCompat; | ||||
import androidx.core.content.ContextCompat; | import androidx.core.content.ContextCompat; | ||||
import java.lang.ref.WeakReference; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.BuildConfig; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.HintDataDialogFragment; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.AppStart; | |||||
import butterknife.ButterKnife; | import butterknife.ButterKnife; | ||||
import butterknife.Unbinder; | import butterknife.Unbinder; | ||||
import android.view.View; | import android.view.View; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import java.lang.ref.WeakReference; | |||||
import androidx.annotation.Nullable; | |||||
import androidx.appcompat.widget.Toolbar; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.HintDataDialogFragment; | import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.HintDataDialogFragment; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.CheckPermissionUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.CheckPermissionUtils; | ||||
import androidx.annotation.Nullable; | |||||
import androidx.appcompat.widget.Toolbar; | |||||
import java.lang.ref.WeakReference; | |||||
import butterknife.ButterKnife; | import butterknife.ButterKnife; | ||||
import butterknife.Unbinder; | import butterknife.Unbinder; | ||||
package aicare.net.cn.sdk.ailinksdkdemoandroid.base; | package aicare.net.cn.sdk.ailinksdkdemoandroid.base; | ||||
import android.content.ComponentName; | |||||
import android.content.Context; | |||||
import android.content.Intent; | |||||
import android.content.ServiceConnection; | |||||
import android.os.Bundle; | import android.os.Bundle; | ||||
import android.os.IBinder; | |||||
import android.os.Handler; | |||||
import android.os.Looper; | |||||
import androidx.annotation.Nullable; | |||||
import androidx.appcompat.app.ActionBar; | |||||
import androidx.appcompat.app.AppCompatActivity; | |||||
import com.pingwang.bluetoothlib.AILinkBleManager; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import com.pingwang.bluetoothlib.config.BleConfig; | import com.pingwang.bluetoothlib.config.BleConfig; | ||||
import com.pingwang.bluetoothlib.server.ELinkBleServer; | |||||
import com.pingwang.bluetoothlib.utils.BleLog; | import com.pingwang.bluetoothlib.utils.BleLog; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.BuildConfig; | import aicare.net.cn.sdk.ailinksdkdemoandroid.BuildConfig; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import androidx.annotation.Nullable; | |||||
import androidx.appcompat.app.ActionBar; | |||||
import androidx.appcompat.app.AppCompatActivity; | |||||
/** | /** | ||||
* xing<br> | * xing<br> | ||||
public abstract class BleBaseActivity extends AppCompatActivity { | public abstract class BleBaseActivity extends AppCompatActivity { | ||||
private static String TAG = BleBaseActivity.class.getName(); | private static String TAG = BleBaseActivity.class.getName(); | ||||
protected ELinkBleServer mBluetoothService; | |||||
/** | |||||
* 服务Intent | |||||
*/ | |||||
private Intent bindIntent; | |||||
protected AILinkBleManager mBluetoothService; | |||||
private Handler mHandler = new Handler(Looper.getMainLooper()); | |||||
@Override | @Override | ||||
protected void onCreate(@Nullable Bundle savedInstanceState) { | protected void onCreate(@Nullable Bundle savedInstanceState) { | ||||
* @param timeOut 超时,小于等于0代表永不超时 | * @param timeOut 超时,小于等于0代表永不超时 | ||||
*/ | */ | ||||
protected void startScanBle(long timeOut){ | protected void startScanBle(long timeOut){ | ||||
if (mBluetoothService!=null){ | |||||
mBluetoothService.scanLeDevice(timeOut,BleConfig.UUID_SERVER_AILINK); | |||||
if (AILinkBleManager.getInstance().isInitOk()){ | |||||
AILinkBleManager.getInstance().startScan(timeOut,BleConfig.UUID_SERVER_AILINK); | |||||
} | } | ||||
} | } | ||||
* 主动停止搜索 | * 主动停止搜索 | ||||
*/ | */ | ||||
protected void stopScanBle(){ | protected void stopScanBle(){ | ||||
if (mBluetoothService!=null){ | |||||
mBluetoothService.stopScan(); | |||||
if (AILinkBleManager.getInstance().isInitOk()){ | |||||
AILinkBleManager.getInstance().stopScan(); | |||||
} | } | ||||
} | } | ||||
* @param bleValueBean 搜索到的地址 | * @param bleValueBean 搜索到的地址 | ||||
*/ | */ | ||||
protected void connectBle(BleValueBean bleValueBean){ | protected void connectBle(BleValueBean bleValueBean){ | ||||
if (mBluetoothService!=null){ | |||||
mBluetoothService.stopScan(); | |||||
mBluetoothService.connectDevice(bleValueBean.getMac()); | |||||
if (AILinkBleManager.getInstance().isInitOk()){ | |||||
AILinkBleManager.getInstance().stopScan(); | |||||
AILinkBleManager.getInstance().connectDevice(bleValueBean); | |||||
} | } | ||||
} | } | ||||
* @param mac 设备的地址 | * @param mac 设备的地址 | ||||
*/ | */ | ||||
protected void connectBle(String mac){ | protected void connectBle(String mac){ | ||||
if (mBluetoothService!=null){ | |||||
mBluetoothService.stopScan(); | |||||
mBluetoothService.connectDevice(mac); | |||||
if (AILinkBleManager.getInstance().isInitOk()){ | |||||
AILinkBleManager.getInstance().stopScan(); | |||||
AILinkBleManager.getInstance().connectDevice(mac); | |||||
} | } | ||||
} | } | ||||
private void bindService() { | private void bindService() { | ||||
BleLog.i(TAG, "绑定服务"); | BleLog.i(TAG, "绑定服务"); | ||||
if (bindIntent == null) { | |||||
bindIntent = new Intent(this, ELinkBleServer.class); | |||||
if (mFhrSCon != null) | |||||
this.bindService(bindIntent, mFhrSCon, Context.BIND_AUTO_CREATE); | |||||
if (!AILinkBleManager.getInstance().isInitOk()) { | |||||
AILinkBleManager.getInstance().init(this, new AILinkBleManager.onInitListener() { | |||||
@Override | |||||
public void onInitSuccess() { | |||||
mBluetoothService = AILinkBleManager.getInstance(); | |||||
onServiceSuccess(); | |||||
} | |||||
@Override | |||||
public void onInitFailure() { | |||||
AILinkBleManager.getInstance().clear(); | |||||
mBluetoothService = null; | |||||
onServiceErr(); | |||||
} | |||||
}); | |||||
}else { | |||||
mHandler.postDelayed(()->{ | |||||
mBluetoothService = AILinkBleManager.getInstance(); | |||||
onServiceSuccess(); | |||||
},500); | |||||
} | } | ||||
} | } | ||||
private void unbindService() { | private void unbindService() { | ||||
unbindServices(); | 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(); | |||||
} | |||||
}; | |||||
/** | /** | ||||
* 绑定服务成功 | * 绑定服务成功 | ||||
*/ | */ |
package aicare.net.cn.sdk.ailinksdkdemoandroid.base; | |||||
import android.os.Bundle; | |||||
import androidx.annotation.Nullable; | |||||
import androidx.appcompat.app.ActionBar; | |||||
import androidx.appcompat.app.AppCompatActivity; | |||||
import com.pingwang.bluetoothlib.AILinkBleManager; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | |||||
import com.pingwang.bluetoothlib.config.BleConfig; | |||||
import com.pingwang.bluetoothlib.utils.BleLog; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.BuildConfig; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
/** | |||||
* xing<br> | |||||
* 2019/4/25<br> | |||||
* 显示数据 | |||||
*/ | |||||
public abstract class BleNewBaseActivity extends AppCompatActivity { | |||||
private static String TAG = BleNewBaseActivity.class.getName(); | |||||
@Override | |||||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||||
super.onCreate(savedInstanceState); | |||||
ActionBar supportActionBar = getSupportActionBar(); | |||||
if (supportActionBar != null) | |||||
supportActionBar.setTitle(getString(R.string.app_name) + BuildConfig.VERSION_NAME); | |||||
init(); | |||||
} | |||||
private void init() { | |||||
bindService(); | |||||
} | |||||
/** | |||||
* 搜索蓝牙(默认通过uuid过滤) | |||||
* @param timeOut 超时,小于等于0代表永不超时 | |||||
*/ | |||||
protected void startScanBle(long timeOut){ | |||||
if (AILinkBleManager.getInstance()!=null){ | |||||
AILinkBleManager.getInstance().startScan(timeOut,BleConfig.UUID_SERVER_AILINK); | |||||
} | |||||
} | |||||
/** | |||||
* 主动停止搜索 | |||||
*/ | |||||
protected void stopScanBle(){ | |||||
if (AILinkBleManager.getInstance()!=null){ | |||||
AILinkBleManager.getInstance().stopScan(); | |||||
} | |||||
} | |||||
/** | |||||
* 连接设备 | |||||
* @param bleValueBean 搜索到的地址 | |||||
*/ | |||||
protected void connectBle(BleValueBean bleValueBean){ | |||||
if (AILinkBleManager.getInstance()!=null){ | |||||
AILinkBleManager.getInstance().stopScan(); | |||||
AILinkBleManager.getInstance().connectDevice(bleValueBean.getMac()); | |||||
} | |||||
} | |||||
/** | |||||
* 连接设备 | |||||
* @param mac 设备的地址 | |||||
*/ | |||||
protected void connectBle(String mac){ | |||||
if (AILinkBleManager.getInstance()!=null){ | |||||
AILinkBleManager.getInstance().stopScan(); | |||||
AILinkBleManager.getInstance().connectDevice(mac); | |||||
} | |||||
} | |||||
//---------------------------------服务--------------------------------------------------- | |||||
private void bindService() { | |||||
if (!AILinkBleManager.getInstance().isInitOk()) { | |||||
AILinkBleManager.getInstance().init(this, new AILinkBleManager.onInitListener() { | |||||
@Override | |||||
public void onInitSuccess() { | |||||
onServiceSuccess(); | |||||
} | |||||
@Override | |||||
public void onInitFailure() { | |||||
onServiceErr(); | |||||
} | |||||
}); | |||||
}else { | |||||
onServiceSuccess(); | |||||
} | |||||
} | |||||
private void unbindService() { | |||||
unbindServices(); | |||||
} | |||||
/** | |||||
* 绑定服务成功 | |||||
*/ | |||||
public abstract void onServiceSuccess(); | |||||
/** | |||||
* 绑定服务失败 | |||||
*/ | |||||
public abstract void onServiceErr(); | |||||
/** | |||||
* 解绑服务,去掉与服务相关的操作,接口等 | |||||
*/ | |||||
public abstract void unbindServices(); | |||||
@Override | |||||
protected void onDestroy() { | |||||
super.onDestroy(); | |||||
BleLog.i(TAG, "onDestroy"); | |||||
unbindService(); | |||||
} | |||||
} |
*/ | */ | ||||
public final static int TEMP_INSTRUMENT = 0x003D; | public final static int TEMP_INSTRUMENT = 0x003D; | ||||
/** | |||||
* 芯一代手表 | |||||
*/ | |||||
public final static int LEAP_WATCH = 0x003E; | |||||
/** | /** | ||||
*/ | */ | ||||
public final static int WEIGHT_SCALE = 0X0056; | public final static int WEIGHT_SCALE = 0X0056; | ||||
/** | |||||
* 食物探针 | |||||
*/ | |||||
public final static int MEAT_PROBE = 0X003F; | |||||
/** | |||||
* 气压温湿度计 | |||||
*/ | |||||
public static final int BAROMETRIC_TEMP_HUMIDITY = 0x005C; | |||||
//------------------特殊 | //------------------特殊 | ||||
package aicare.net.cn.sdk.ailinksdkdemoandroid.config; | |||||
/** | |||||
* xing<br> | |||||
* 2019/7/26<br> | |||||
* java类作用描述 | |||||
*/ | |||||
public class UserUnitConfig { | |||||
//-------重量 | |||||
public final static int USER_UNIT_KG = 0; | |||||
public final static int USER_UNIT_FG = 1;//斤 | |||||
public final static int USER_UNIT_LB = 2; | |||||
public final static int USER_UNIT_OZ = 3; | |||||
public final static int USER_UNIT_ST = 4; | |||||
public final static int USER_UNIT_G = 5; | |||||
public final static int USER_UNIT_LB_LB = 6; | |||||
//-------身高 | |||||
public final static int USER_UNIT_CM = 0; | |||||
public final static int USER_UNIT_INCH = 1; | |||||
public final static int USER_UNIT_FEET = 2; | |||||
public final static int USER_UNIT_M = 3; | |||||
//-------温度 | |||||
public final static int USER_UNIT_C = 0; | |||||
public final static int USER_UNIT_F = 1; | |||||
//-------压力 | |||||
public final static int USER_UNIT_MMHG = 0; | |||||
public final static int USER_UNIT_KPA = 1; | |||||
/** | |||||
* 热量卡 | |||||
*/ | |||||
public final static int USER_UNIT_CAL = 0; | |||||
/** | |||||
* 秒 | |||||
*/ | |||||
public final static int USER_UNIT_S = 0; | |||||
} |
import android.widget.SeekBar; | import android.widget.SeekBar; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||
import androidx.annotation.Nullable; | import androidx.annotation.Nullable; | ||||
import androidx.fragment.app.DialogFragment; | import androidx.fragment.app.DialogFragment; | ||||
import androidx.fragment.app.FragmentManager; | import androidx.fragment.app.FragmentManager; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
import cn.net.aicare.modulelibrary.module.BodyFatScale.BodyFatDataUtil; | import cn.net.aicare.modulelibrary.module.BodyFatScale.BodyFatDataUtil; | ||||
import cn.net.aicare.modulelibrary.module.BodyFatScale.User; | import cn.net.aicare.modulelibrary.module.BodyFatScale.User; | ||||
import android.view.ViewGroup; | import android.view.ViewGroup; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.recyclerview.widget.RecyclerView; | |||||
import java.util.List; | import java.util.List; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.recyclerview.widget.RecyclerView; | |||||
/** | /** | ||||
* xing<br> | * xing<br> | ||||
} | } | ||||
public static class DialogStringImageBean{ | |||||
String mName; | |||||
long mType; | |||||
public DialogStringImageBean(String name, long type) { | |||||
mName = name; | |||||
mType = type; | |||||
} | |||||
public String getName() { | |||||
return mName; | |||||
} | |||||
public void setName(String name) { | |||||
mName = name; | |||||
} | |||||
public long getType() { | |||||
return mType; | |||||
} | |||||
public void setType(long type) { | |||||
mType = type; | |||||
} | |||||
} | |||||
} | } |
package aicare.net.cn.sdk.ailinksdkdemoandroid.dialog; | |||||
/** | |||||
* 对话框字符串bean | |||||
* | |||||
* @author xing | |||||
* @date 2023/07/21 | |||||
*/ | |||||
public class DialogStringImageBean { | |||||
private String mName; | |||||
private long mType; | |||||
public DialogStringImageBean(String name, long type) { | |||||
mName = name; | |||||
mType = type; | |||||
} | |||||
public String getName() { | |||||
return mName; | |||||
} | |||||
public void setName(String name) { | |||||
mName = name; | |||||
} | |||||
public long getType() { | |||||
return mType; | |||||
} | |||||
public void setType(long type) { | |||||
mType = type; | |||||
} | |||||
@Override | |||||
public String toString() { | |||||
return "DialogStringImageBean{" + "mName='" + mName + '\'' + ", mType=" + mType + '}'; | |||||
} | |||||
} |
import android.view.WindowManager; | import android.view.WindowManager; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.L; | |||||
import androidx.annotation.ColorInt; | import androidx.annotation.ColorInt; | ||||
import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||
import androidx.annotation.Nullable; | import androidx.annotation.Nullable; | ||||
import androidx.fragment.app.DialogFragment; | import androidx.fragment.app.DialogFragment; | ||||
import androidx.fragment.app.FragmentManager; | import androidx.fragment.app.FragmentManager; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
/** | /** | ||||
* 显示信息的弹框 | * 显示信息的弹框 | ||||
* 是否居中 | * 是否居中 | ||||
*/ | */ | ||||
private boolean isCenter = false; | private boolean isCenter = false; | ||||
private CharSequence mCancel; | |||||
private CharSequence mCancel = ""; | |||||
@ColorInt | @ColorInt | ||||
private int mCancelColor = 0; | private int mCancelColor = 0; | ||||
private CharSequence mOkStr; | |||||
private CharSequence mOkStr = ""; | |||||
@ColorInt | @ColorInt | ||||
private int mOkColor = 0; | private int mOkColor = 0; | ||||
@ColorInt | @ColorInt | ||||
@NonNull | @NonNull | ||||
@Override | @Override | ||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { | public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { | ||||
L.i(TAG, "onCreateDialog"); | |||||
Dialog dialogView = new Dialog(requireContext(), R.style.MyDialog);// 创建自定义样式dialog | Dialog dialogView = new Dialog(requireContext(), R.style.MyDialog);// 创建自定义样式dialog | ||||
dialogView.setCancelable(false);//设置是否可以关闭 | dialogView.setCancelable(false);//设置是否可以关闭 | ||||
dialogView.setCanceledOnTouchOutside(mCancelBlank);//设置点击空白处是否可以取消 | dialogView.setCanceledOnTouchOutside(mCancelBlank);//设置点击空白处是否可以取消 | ||||
@Override | @Override | ||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, | ||||
@Nullable Bundle savedInstanceState) { | @Nullable Bundle savedInstanceState) { | ||||
L.i(TAG, "onCreateView"); | |||||
return inflater.inflate(R.layout.dialog_hint_data, container);// 得到加载view | return inflater.inflate(R.layout.dialog_hint_data, container);// 得到加载view | ||||
@Override | @Override | ||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) { | public void onActivityCreated(@Nullable Bundle savedInstanceState) { | ||||
super.onActivityCreated(savedInstanceState); | super.onActivityCreated(savedInstanceState); | ||||
L.i(TAG, "onActivityCreated"); | |||||
Dialog dialog = getDialog(); | Dialog dialog = getDialog(); | ||||
if (dialog != null) { | if (dialog != null) { | ||||
getDialog().setOnShowListener(null); | getDialog().setOnShowListener(null); | ||||
public HintDataDialogFragment initColor(@ColorInt int cancelColor, @ColorInt int okColor) { | public HintDataDialogFragment initColor(@ColorInt int cancelColor, @ColorInt int okColor) { | ||||
this.mCancelColor = cancelColor; | this.mCancelColor = cancelColor; | ||||
this.mOkColor = okColor; | this.mOkColor = okColor; | ||||
if (mTvCancel != null && mCancelColor != 0) | |||||
if (mTvCancel != null && mCancelColor != 0) { | |||||
mTvCancel.setTextColor(mCancelColor); | mTvCancel.setTextColor(mCancelColor); | ||||
if (mTvSucceed != null && mOkColor != 0) | |||||
} | |||||
if (mTvSucceed != null && mOkColor != 0) { | |||||
mTvSucceed.setTextColor(mOkColor); | mTvSucceed.setTextColor(mOkColor); | ||||
} | |||||
return this; | return this; | ||||
} | } | ||||
} else if (mContent == null) { | } else if (mContent == null) { | ||||
mTvContent.setVisibility(View.GONE); | mTvContent.setVisibility(View.GONE); | ||||
} | } | ||||
if (isCenter) | |||||
if (isCenter) { | |||||
mTvContent.setGravity(Gravity.CENTER); | mTvContent.setGravity(Gravity.CENTER); | ||||
else | |||||
} else { | |||||
mTvContent.setGravity(Gravity.CENTER_VERTICAL); | mTvContent.setGravity(Gravity.CENTER_VERTICAL); | ||||
} | |||||
} | } | ||||
return this; | return this; | ||||
} | } | ||||
} else if (mOkStr == null) { | } else if (mOkStr == null) { | ||||
mTvSucceed.setVisibility(View.GONE); | mTvSucceed.setVisibility(View.GONE); | ||||
} | } | ||||
if (mOkColor != 0) | |||||
if (mOkColor != 0) { | |||||
mTvSucceed.setTextColor(mOkColor); | mTvSucceed.setTextColor(mOkColor); | ||||
} | |||||
} | } | ||||
return this; | return this; | ||||
} | } | ||||
if (getActivity() != null) { | if (getActivity() != null) { | ||||
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); | getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); | ||||
if (dialog.getWindow() != null) | if (dialog.getWindow() != null) | ||||
{ | |||||
//设置宽度为80% | //设置宽度为80% | ||||
dialog.getWindow() | dialog.getWindow() | ||||
.setLayout((int) (dm.widthPixels * 0.9), | .setLayout((int) (dm.widthPixels * 0.9), | ||||
ViewGroup.LayoutParams.WRAP_CONTENT); | ViewGroup.LayoutParams.WRAP_CONTENT); | ||||
} | |||||
} | } | ||||
} | } | ||||
} | } | ||||
mShow = true; | mShow = true; | ||||
} | } | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
L.e(TAG, "显示异常"); | |||||
e.printStackTrace(); | e.printStackTrace(); | ||||
} | } | ||||
} | } | ||||
mShow = false; | mShow = false; | ||||
super.dismiss(); | super.dismiss(); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
L.e(TAG, "关闭异常"); | |||||
e.printStackTrace(); | e.printStackTrace(); | ||||
} | } | ||||
} | } |
import android.view.View; | import android.view.View; | ||||
import android.view.ViewGroup; | import android.view.ViewGroup; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||
import androidx.annotation.Nullable; | import androidx.annotation.Nullable; | ||||
import androidx.fragment.app.DialogFragment; | import androidx.fragment.app.DialogFragment; | ||||
import androidx.fragment.app.FragmentManager; | import androidx.fragment.app.FragmentManager; | ||||
import androidx.fragment.app.FragmentTransaction; | import androidx.fragment.app.FragmentTransaction; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
/** | /** | ||||
* elink-android<br> | * elink-android<br> | ||||
/** | /** | ||||
* 默认超时时间 | * 默认超时时间 | ||||
*/ | */ | ||||
private int timeOut = 30; | |||||
private int timeOut = 10; | |||||
private boolean show = false; | private boolean show = false; | ||||
public boolean isShow() { | public boolean isShow() { |
import android.view.WindowManager; | import android.view.WindowManager; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import java.util.ArrayList; | |||||
import java.util.List; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.L; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.view.MyItemDecoration; | |||||
import androidx.annotation.ColorInt; | import androidx.annotation.ColorInt; | ||||
import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||
import androidx.annotation.Nullable; | import androidx.annotation.Nullable; | ||||
import androidx.recyclerview.widget.LinearLayoutManager; | import androidx.recyclerview.widget.LinearLayoutManager; | ||||
import androidx.recyclerview.widget.RecyclerView; | import androidx.recyclerview.widget.RecyclerView; | ||||
import java.util.ArrayList; | |||||
import java.util.List; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.L; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.view.MyItemDecoration; | |||||
/** | /** | ||||
* 列表显示的dialog | * 列表显示的dialog | ||||
*/ | */ | ||||
private int mCancelColor; | private int mCancelColor; | ||||
private CharSequence mCancel; | private CharSequence mCancel; | ||||
private CharSequence mTitle; | private CharSequence mTitle; | ||||
private ArrayList<DialogStringImageAdapter.DialogStringImageBean> mList; | |||||
private ArrayList<DialogStringImageBean> mList; | |||||
private boolean mBottom; | private boolean mBottom; | ||||
/** | /** | ||||
* 是否显示灰色背景 | * 是否显示灰色背景 | ||||
/** | /** | ||||
* 初始化数据 | * 初始化数据 | ||||
*/ | */ | ||||
private void initData(ArrayList<DialogStringImageAdapter.DialogStringImageBean> list, CharSequence title, CharSequence cancel, int cancelColor) { | |||||
private void initData(ArrayList<DialogStringImageBean> list, CharSequence title, CharSequence cancel, int cancelColor) { | |||||
if (mList == null) | if (mList == null) | ||||
mList = new ArrayList<>(); | mList = new ArrayList<>(); | ||||
/** | /** | ||||
* 修改列表中的内容 | * 修改列表中的内容 | ||||
*/ | */ | ||||
public ShowListDialogFragment setList(List<DialogStringImageAdapter.DialogStringImageBean> list) { | |||||
public ShowListDialogFragment setList(List<DialogStringImageBean> list) { | |||||
if (mList == null) { | if (mList == null) { | ||||
mList = new ArrayList<>(); | mList = new ArrayList<>(); | ||||
mList.addAll(list); | mList.addAll(list); |
import android.widget.EditText; | import android.widget.EditText; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||
import androidx.annotation.Nullable; | import androidx.annotation.Nullable; | ||||
import androidx.fragment.app.DialogFragment; | import androidx.fragment.app.DialogFragment; | ||||
import androidx.fragment.app.FragmentManager; | import androidx.fragment.app.FragmentManager; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
public class WifiDialog extends DialogFragment implements View.OnClickListener { | public class WifiDialog extends DialogFragment implements View.OnClickListener { | ||||
/** | /** |
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.Toast; | import android.widget.Toast; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.findDevice.FindConnectDeviceInfoBean; | import cn.net.aicare.modulelibrary.module.findDevice.FindConnectDeviceInfoBean; | ||||
import cn.net.aicare.modulelibrary.module.findDevice.FindDeviceData; | import cn.net.aicare.modulelibrary.module.findDevice.FindDeviceData; | ||||
import android.view.ViewGroup; | import android.view.ViewGroup; | ||||
import android.widget.Button; | import android.widget.Button; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.recyclerview.widget.RecyclerView; | |||||
import java.util.List; | import java.util.List; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.recyclerview.widget.RecyclerView; | |||||
/** | /** | ||||
* xing<br> | * xing<br> |
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import androidx.recyclerview.widget.GridLayoutManager; | |||||
import androidx.recyclerview.widget.LinearLayoutManager; | |||||
import androidx.recyclerview.widget.RecyclerView; | |||||
import com.pingwang.bluetoothlib.AILinkSDK; | import com.pingwang.bluetoothlib.AILinkSDK; | ||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import com.pingwang.bluetoothlib.config.BleConfig; | import com.pingwang.bluetoothlib.config.BleConfig; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleAppBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleAppBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.SP; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.SP; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.view.MyItemDecoration; | import aicare.net.cn.sdk.ailinksdkdemoandroid.view.MyItemDecoration; | ||||
import androidx.recyclerview.widget.GridLayoutManager; | |||||
import androidx.recyclerview.widget.LinearLayoutManager; | |||||
import androidx.recyclerview.widget.RecyclerView; | |||||
import cn.net.aicare.modulelibrary.module.findDevice.FindDeviceData; | import cn.net.aicare.modulelibrary.module.findDevice.FindDeviceData; | ||||
public class FindDeviceNewActivity extends BleAppBaseActivity implements View.OnClickListener, OnCallbackBle, FindDeviceData.onNotifyData, OnScanFilterListener, FindDeviceAdapter.OnItemClickListener { | public class FindDeviceNewActivity extends BleAppBaseActivity implements View.OnClickListener, OnCallbackBle, FindDeviceData.onNotifyData, OnScanFilterListener, FindDeviceAdapter.OnItemClickListener { | ||||
mFindDeviceAdapter.notifyDataSetChanged(); | mFindDeviceAdapter.notifyDataSetChanged(); | ||||
} | } | ||||
mFindDeviceData.getConnectInfoList(); | mFindDeviceData.getConnectInfoList(); | ||||
mBluetoothService.scanLeDevice(30 * 1000); | |||||
mBluetoothService.startScan(30 * 1000); | |||||
} | } | ||||
break; | break; | ||||
@Override | @Override | ||||
protected void onPermissionsOk() { | protected void onPermissionsOk() { | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
mBleDevice = mBluetoothService.getBleDevice(mMac); | mBleDevice = mBluetoothService.getBleDevice(mMac); | ||||
mBluetoothService.setOnScanFilterListener(this); | mBluetoothService.setOnScanFilterListener(this); | ||||
if (mBleDevice != null) { | if (mBleDevice != null) { | ||||
BleConfig.setHandshakeStatus(mMac, false); | BleConfig.setHandshakeStatus(mMac, false); | ||||
mBluetoothService.stopScan(); | mBluetoothService.stopScan(); | ||||
mBluetoothService.connectDevice(mMac); | mBluetoothService.connectDevice(mMac); | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
} else if (bleValueBean.getName() == null || !bleValueBean.getName().trim().toUpperCase().startsWith(BLE_NAME_START.toUpperCase())) { | } else if (bleValueBean.getName() == null || !bleValueBean.getName().trim().toUpperCase().startsWith(BLE_NAME_START.toUpperCase())) { | ||||
onNearbyDeviceInfo(bleValueBean.getMac(), bleValueBean.getRssi(), bleValueBean.getManufacturerData()); | onNearbyDeviceInfo(bleValueBean.getMac(), bleValueBean.getRssi(), bleValueBean.getManufacturerData()); | ||||
} | } | ||||
if (tv_status != null) | if (tv_status != null) | ||||
tv_status.setText("正在连接..."); | tv_status.setText("正在连接..."); | ||||
mHandler.sendEmptyMessage(REFRESH_DATA); | mHandler.sendEmptyMessage(REFRESH_DATA); | ||||
mBluetoothService.scanLeDevice(0, BleConfig.UUID_SERVER_AILINK); | |||||
mBluetoothService.startScan(0, BleConfig.UUID_SERVER_AILINK); | |||||
} | } | ||||
} | } |
import android.widget.ArrayAdapter; | import android.widget.ArrayAdapter; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import androidx.annotation.Nullable; | |||||
import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.List; | import java.util.List; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.Nullable; | |||||
/** | /** | ||||
* 噪音计(ble) | * 噪音计(ble) | ||||
* | * | ||||
* @author xing | * @author xing | ||||
*/ | */ | ||||
public class BleDemoActivity extends BleBaseActivity { | |||||
public class BleDemoActivity extends BleBaseActivity { | |||||
private ListView list_view; | private ListView list_view; | ||||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||||
package aicare.net.cn.sdk.ailinksdkdemoandroid.modules; | |||||
import android.content.Context; | import android.content.Context; | ||||
import android.os.Bundle; | import android.os.Bundle; | ||||
import android.widget.EditText; | import android.widget.EditText; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.config.CmdConfig; | import com.pingwang.bluetoothlib.config.CmdConfig; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
import java.util.List; | import java.util.List; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.WifiDialog; | import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.WifiDialog; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.BodyFatScale.BodyFatDataUtil; | import cn.net.aicare.modulelibrary.module.BodyFatScale.BodyFatDataUtil; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.Toast; | import android.widget.Toast; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | ||||
import com.pingwang.bluetoothlib.device.SendBleBean; | import com.pingwang.bluetoothlib.device.SendBleBean; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.TempInstrument.TempInstrumentBleConfig; | import cn.net.aicare.modulelibrary.module.TempInstrument.TempInstrumentBleConfig; | ||||
import cn.net.aicare.modulelibrary.module.TempInstrument.TempInstrumentDeviceData; | import cn.net.aicare.modulelibrary.module.TempInstrument.TempInstrumentDeviceData; | ||||
public void onServiceSuccess() { | public void onServiceSuccess() { | ||||
mAddress = getIntent().getStringExtra("mac"); | mAddress = getIntent().getStringExtra("mac"); | ||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
if (mAirDetectorWifeBleData == null) { | if (mAirDetectorWifeBleData == null) { | ||||
AirDetectorWifeBleData.init(bleDevice); | AirDetectorWifeBleData.init(bleDevice); | ||||
mAirDetectorWifeBleData = AirDetectorWifeBleData.getInstance(); | mAirDetectorWifeBleData = AirDetectorWifeBleData.getInstance(); | ||||
@Override | @Override | ||||
public void unbindServices() { | public void unbindServices() { | ||||
if (mBluetoothService!=null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | } | ||||
@Override | @Override | ||||
String valueMin = ed_min.getText().toString().trim(); | String valueMin = ed_min.getText().toString().trim(); | ||||
float myValueMax = valueMax.contains("\\.") ? Float.parseFloat(valueMax) : Integer.parseInt(valueMax); | float myValueMax = valueMax.contains("\\.") ? Float.parseFloat(valueMax) : Integer.parseInt(valueMax); | ||||
float myValueMin = valueMin.contains("\\.") ? Float.parseFloat(valueMin) : Integer.parseInt(valueMin); | float myValueMin = valueMin.contains("\\.") ? Float.parseFloat(valueMin) : Integer.parseInt(valueMin); | ||||
sendDataBean = AirSendUtil.setWarmTemp(supportBean.getPoint(), supportBean.getUnit(), myValueMax, myValueMin,1); | |||||
int warmStateTemp = Integer.parseInt(ed_warm_state.getText().toString().trim()); | |||||
sendDataBean = AirSendUtil.setWarmTemp(supportBean.getPoint(), | |||||
supportBean.getUnit(), myValueMax, myValueMin, warmStateTemp); | |||||
break; | break; | ||||
case AirConst.AIR_TYPE_HUMIDITY: | case AirConst.AIR_TYPE_HUMIDITY: | ||||
valueMax = ed_max.getText().toString().trim(); | valueMax = ed_max.getText().toString().trim(); | ||||
valueMin = ed_min.getText().toString().trim(); | valueMin = ed_min.getText().toString().trim(); | ||||
myValueMax = valueMax.contains("\\.") ? Float.parseFloat(valueMax) : Integer.parseInt(valueMax); | myValueMax = valueMax.contains("\\.") ? Float.parseFloat(valueMax) : Integer.parseInt(valueMax); | ||||
myValueMin = valueMin.contains("\\.") ? Float.parseFloat(valueMin) : Integer.parseInt(valueMin); | myValueMin = valueMin.contains("\\.") ? Float.parseFloat(valueMin) : Integer.parseInt(valueMin); | ||||
int warmStateHumi = Integer.parseInt(ed_warm_state.getText().toString().trim()); | |||||
sendDataBean = AirSendUtil.setWarmHumidity(supportBean.getPoint(), | sendDataBean = AirSendUtil.setWarmHumidity(supportBean.getPoint(), | ||||
myValueMax, myValueMin,1); | |||||
myValueMax, myValueMin, warmStateHumi); | |||||
break; | break; | ||||
case AirConst.AIR_SETTING_VOICE: | case AirConst.AIR_SETTING_VOICE: | ||||
warmState = Integer.parseInt(ed_warm_state.getText().toString().trim()); | warmState = Integer.parseInt(ed_warm_state.getText().toString().trim()); |
builder.append("max : ").append(bean.getMax()).append(", min: ").append(bean.getMin()).append(", 小数点:").append(bean.getPoint()); | builder.append("max : ").append(bean.getMax()).append(", min: ").append(bean.getMin()).append(", 小数点:").append(bean.getPoint()); | ||||
break; | break; | ||||
case AirConst.AIR_SETTING_WARM: | case AirConst.AIR_SETTING_WARM: | ||||
builder.append("数值:").append(bean.getCurValue()).append(", ").append(AirUtil.dealWarnSwitch((int) bean.getCurValue())); | |||||
break; | |||||
case AirConst.AIR_SETTING_DEVICE_ERROR: | case AirConst.AIR_SETTING_DEVICE_ERROR: | ||||
case AirConst.AIR_SETTING_DEVICE_SELF_TEST: | case AirConst.AIR_SETTING_DEVICE_SELF_TEST: | ||||
case AirConst.AIR_RESTORE_FACTORY_SETTINGS: | case AirConst.AIR_RESTORE_FACTORY_SETTINGS: | ||||
AlarmClockStatement alarmClockStatement = (AlarmClockStatement) bean.getExtentObject(); | AlarmClockStatement alarmClockStatement = (AlarmClockStatement) bean.getExtentObject(); | ||||
String alarmShow = "闹钟显示:" + alarmClockStatement.isShowIcon(); | String alarmShow = "闹钟显示:" + alarmClockStatement.isShowIcon(); | ||||
String alarmCount = ", 闹钟数量:" + alarmClockStatement.getAlarmCount(); | String alarmCount = ", 闹钟数量:" + alarmClockStatement.getAlarmCount(); | ||||
String supportDelete = ", 支持添加删除闹钟:" + alarmClockStatement.isSupportDelete(); | |||||
String mode0 = ", 模式 0:一次性,当天有效:" + alarmClockStatement.isMode0(); | String mode0 = ", 模式 0:一次性,当天有效:" + alarmClockStatement.isMode0(); | ||||
String mode1 = ", 模式 1:每天都响:" + alarmClockStatement.isMode1(); | String mode1 = ", 模式 1:每天都响:" + alarmClockStatement.isMode1(); | ||||
String mode2 = ", 模式 2:周一至周五:" + alarmClockStatement.isMode2(); | String mode2 = ", 模式 2:周一至周五:" + alarmClockStatement.isMode2(); | ||||
String mode3 = ", 模式 3:周一至周六:" + alarmClockStatement.isMode3(); | String mode3 = ", 模式 3:周一至周六:" + alarmClockStatement.isMode3(); | ||||
String mode4 = ", 模式 4:自定义:" + alarmClockStatement.isMode4(); | String mode4 = ", 模式 4:自定义:" + alarmClockStatement.isMode4(); | ||||
builder.append(alarmShow).append(alarmCount).append(mode0).append(mode1).append(mode2).append(mode3).append(mode4); | |||||
builder.append(alarmShow).append(alarmCount).append(supportDelete).append(mode0).append(mode1).append(mode2).append(mode3).append(mode4); | |||||
break; | break; | ||||
case AirConst.AIR_KEY_SOUND: | case AirConst.AIR_KEY_SOUND: | ||||
case AirConst.AIR_ALARM_SOUND_EFFECT: | case AirConst.AIR_ALARM_SOUND_EFFECT: | ||||
case AirConst.AIR_SETTING_SWITCH_TEMP_UNIT: | case AirConst.AIR_SETTING_SWITCH_TEMP_UNIT: | ||||
builder.append("温度: ").append(bean.getCurValue() == 1 ? "1 - 支持" : "0 - 不支持"); | builder.append("温度: ").append(bean.getCurValue() == 1 ? "1 - 支持" : "0 - 不支持"); | ||||
break; | break; | ||||
case AirConst.AIR_PROTOCOL_VERSION: | |||||
builder.append(bean.getCurValue()); | |||||
break; | |||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
case AirConst.AIR_MONITORING_DISPLAY_DATA: | case AirConst.AIR_MONITORING_DISPLAY_DATA: | ||||
builder.append(AirUtil.getSwitchStatus(statusBean.isOpen())); | builder.append(AirUtil.getSwitchStatus(statusBean.isOpen())); | ||||
break; | break; | ||||
case AirConst.AIR_SETTING_SWITCH_TEMP_UNIT: | |||||
builder.append("可忽略,不处理"); | |||||
break; | |||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
int hPow = (int) Math.pow(10, supportBean.getPoint()); | int hPow = (int) Math.pow(10, supportBean.getPoint()); | ||||
String humpStr = "下限值:" + settingBean.getWarmMin() / hPow + ", 上限值: " + settingBean.getWarmMax() / hPow; | String humpStr = "下限值:" + settingBean.getWarmMin() / hPow + ", 上限值: " + settingBean.getWarmMax() / hPow; | ||||
builder.append(humpStr); | builder.append(humpStr); | ||||
builder.append(", 子开关:").append(AirUtil.getSwitchStatus(settingBean.isOpen())); | |||||
break; | break; | ||||
case AirConst.AIR_TYPE_TEMP: | case AirConst.AIR_TYPE_TEMP: | ||||
String tempStr = "下限值:" + settingBean.getWarmMin() + ", 上限值: " + settingBean.getWarmMax(); | String tempStr = "下限值:" + settingBean.getWarmMin() + ", 上限值: " + settingBean.getWarmMax(); | ||||
builder.append(tempStr); | builder.append(tempStr); | ||||
builder.append(", 子开关:").append(AirUtil.getSwitchStatus(settingBean.isOpen())); | |||||
break; | |||||
case AirConst.AIR_SETTING_WARM: | |||||
builder.append(", 总开关:").append(AirUtil.getSwitchStatus(settingBean.isOpen())); | |||||
break; | break; | ||||
case AirConst.AIR_SETTING_VOICE: | case AirConst.AIR_SETTING_VOICE: | ||||
builder.append("开关:").append(AirUtil.getSwitchStatus(settingBean.isOpen())).append(", Level: ").append(settingBean.getValue()); | builder.append("开关:").append(AirUtil.getSwitchStatus(settingBean.isOpen())).append(", Level: ").append(settingBean.getValue()); |
typeNameArray.append(AirConst.AIR_ICON_DISPLAY, "图标显示"); | typeNameArray.append(AirConst.AIR_ICON_DISPLAY, "图标显示"); | ||||
typeNameArray.append(AirConst.AIR_MONITORING_DISPLAY_DATA, "监控显示数据"); | typeNameArray.append(AirConst.AIR_MONITORING_DISPLAY_DATA, "监控显示数据"); | ||||
typeNameArray.append(AirConst.AIR_DATA_DISPLAY_MODE, "数据显示模式"); | typeNameArray.append(AirConst.AIR_DATA_DISPLAY_MODE, "数据显示模式"); | ||||
typeNameArray.append(AirConst.AIR_PROTOCOL_VERSION, "协议版本"); | |||||
} | } | ||||
} | } | ||||
StringBuilder builder = new StringBuilder(); | StringBuilder builder = new StringBuilder(); | ||||
for (AlarmClockInfoList.AlarmInfo bean : list) { | for (AlarmClockInfoList.AlarmInfo bean : list) { | ||||
builder.append(getSwitchStatus(bean.getSwitchStatus() == 1)); | |||||
builder.append("编号:").append(bean.getId()); | |||||
builder.append(", " + getSwitchStatus(bean.getSwitchStatus() == 1)); | |||||
builder.append(", 删除:").append(bean.isDeleted()); | builder.append(", 删除:").append(bean.isDeleted()); | ||||
builder.append(", 编号:").append(bean.getId()); | |||||
builder.append(", 模式:").append(bean.getMode()); | builder.append(", 模式:").append(bean.getMode()); | ||||
builder.append(", 闹钟时间:").append(bean.getHour()).append(":").append(bean.getMinute()); | |||||
builder.append(", 闹钟时间:").append(dealTime(bean.getHour())).append(":").append(dealTime(bean.getMinute())); | |||||
builder.append(", 闹钟周期:").append(dealAlarmDay(bean.getAlarmDays())); | builder.append(", 闹钟周期:").append(dealAlarmDay(bean.getAlarmDays())); | ||||
builder.append("\n"); | builder.append("\n"); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
private static String dealTime(int num){ | |||||
if (num < 10) { | |||||
return "0" + num; | |||||
} | |||||
return num + ""; | |||||
} | |||||
private static String dealAlarmDay(int[] days){ | private static String dealAlarmDay(int[] days){ | ||||
if (days == null) { | if (days == null) { | ||||
return ""; | return ""; | ||||
builder.append("]"); | builder.append("]"); | ||||
return builder.toString(); | return builder.toString(); | ||||
} | } | ||||
public static int[] getAlarmClockDayByMode(int mode){ | |||||
switch (mode){ | |||||
case 1: | |||||
return new int[]{0,1,1,1,1,1,1,1}; | |||||
case 2: | |||||
return new int[]{0,1,1,1,1,1,0,0}; | |||||
case 3: | |||||
return new int[]{0,1,1,1,1,1,1,0}; | |||||
case 4: | |||||
return new int[]{0,1,1,0,1,1,0,1}; | |||||
case 0: | |||||
default: | |||||
return new int[]{0,0,0,0,0,0,0,0}; | |||||
} | |||||
} | |||||
public static String dealWarnSwitch(int val){ | |||||
if (val == 1) { | |||||
return "各报警功能可单独设置开关"; | |||||
} else if(val == 2){ | |||||
return "报警功能只支持总开关"; | |||||
} | |||||
return "未知"; | |||||
} | |||||
} | } |
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleAppBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleAppBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.airdetector.AirUtil; | |||||
import cn.net.aicare.modulelibrary.module.airDetector.AirConst; | import cn.net.aicare.modulelibrary.module.airDetector.AirConst; | ||||
import cn.net.aicare.modulelibrary.module.airDetector.AirDetectorWifeBleData; | import cn.net.aicare.modulelibrary.module.airDetector.AirDetectorWifeBleData; | ||||
import cn.net.aicare.modulelibrary.module.airDetector.AirSendUtil; | import cn.net.aicare.modulelibrary.module.airDetector.AirSendUtil; | ||||
import cn.net.aicare.modulelibrary.module.airDetector.AlarmClockStatement; | |||||
import cn.net.aicare.modulelibrary.module.airDetector.StatusBean; | import cn.net.aicare.modulelibrary.module.airDetector.StatusBean; | ||||
import cn.net.aicare.modulelibrary.module.airDetector.SupportBean; | import cn.net.aicare.modulelibrary.module.airDetector.SupportBean; | ||||
private static final int STEP_CAL_TVOC = 36; // TVOC校准 | private static final int STEP_CAL_TVOC = 36; // TVOC校准 | ||||
private static final int STEP_CAL_CO = 37; // CO校准 | private static final int STEP_CAL_CO = 37; // CO校准 | ||||
private static final int STEP_SETTING_ALARM = 38; // 闹钟 | private static final int STEP_SETTING_ALARM = 38; // 闹钟 | ||||
private static final int STEP_SETTING_WARN_SWITCH = 39; // 报警总开关 | |||||
// private static final int STEP_DEVICE_SELF_TEST = 18; // 设备自检 | // private static final int STEP_DEVICE_SELF_TEST = 18; // 设备自检 | ||||
// private static final int STEP_DEVICE_BIND = 18; // 设备绑定 | // private static final int STEP_DEVICE_BIND = 18; // 设备绑定 | ||||
// private static final int STEP_RESTORE_FACTORY_SETTINGS = 18; // 恢复出厂设置 | // private static final int STEP_RESTORE_FACTORY_SETTINGS = 18; // 恢复出厂设置 | ||||
private static final int STEP_DONE = 39;// 结束 | |||||
private static final int STEP_DONE = 40;// 结束 | |||||
private static final int RESULT_NULL = 0; | private static final int RESULT_NULL = 0; | ||||
private static final int RESULT_SUCCESS = 1; | private static final int RESULT_SUCCESS = 1; | ||||
finish(); | finish(); | ||||
return; | return; | ||||
} | } | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
if (mAirDetectorWifeBleData == null) { | if (mAirDetectorWifeBleData == null) { | ||||
// AirDetectorWifeBleData.init(bleDevice); | // AirDetectorWifeBleData.init(bleDevice); | ||||
mAirDetectorWifeBleData = AirDetectorWifeBleData.getInstance(); | mAirDetectorWifeBleData = AirDetectorWifeBleData.getInstance(); | ||||
@Override | @Override | ||||
public void unbindServices() { | public void unbindServices() { | ||||
Log.i(TAG, "unbindServices"); | Log.i(TAG, "unbindServices"); | ||||
if (mBluetoothService!=null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | } | ||||
@Override | @Override | ||||
public void onStatusList(SparseArray<StatusBean> statusList) { | public void onStatusList(SparseArray<StatusBean> statusList) { | ||||
if (mStep == STEP_REALTIME_STATUS) { | if (mStep == STEP_REALTIME_STATUS) { | ||||
stepSuccess(AirDetectorTestShowUtil.showTextStatus(statusList, deviceSupportList)); | stepSuccess(AirDetectorTestShowUtil.showTextStatus(statusList, deviceSupportList)); | ||||
} else if (mStep == STEP_CAL_HCHO || mStep == STEP_CAL_TEMP || mStep == STEP_CAL_HUMIDITY || mStep == STEP_CAL_PM2_5 | |||||
|| mStep == STEP_CAL_PM1_0 || mStep == STEP_CAL_VOC || mStep == STEP_CAL_CO2 || mStep == STEP_CAL_AQI | |||||
|| mStep == STEP_CAL_TVOC || mStep == STEP_CAL_CO) { | |||||
if (statusList.get(AirConst.AIR_CALIBRATION_PARAMETERS) != null) { | |||||
stepSuccess(AirDetectorTestShowUtil.showCalSettingAfterTextStatus(statusList, deviceSupportList)); | |||||
} | |||||
} | } | ||||
} | } | ||||
type = AirConst.AIR_TYPE_FORMALDEHYDE; | type = AirConst.AIR_TYPE_FORMALDEHYDE; | ||||
if (isSupportWarmType(type)) { | if (isSupportWarmType(type)) { | ||||
addTest("设置甲醛报警"); | addTest("设置甲醛报警"); | ||||
mAirDetectorWifeBleData.sendData(AirSendUtil.setWarmMaxByType(type, switchOpenFlag, 0.08f, deviceSupportList.get(type).getPoint())); | |||||
mAirDetectorWifeBleData.sendData(AirSendUtil.setWarmMaxByType(type, switchOpenFlag, 0.10f, deviceSupportList.get(type).getPoint())); | |||||
} | } | ||||
break; | break; | ||||
case STEP_WARM_TEMP: | case STEP_WARM_TEMP: | ||||
type = AirConst.AIR_TYPE_TEMP; | type = AirConst.AIR_TYPE_TEMP; | ||||
if (isSupportWarmType(type)) { | if (isSupportWarmType(type)) { | ||||
addTest("设置温度报警"); | addTest("设置温度报警"); | ||||
mAirDetectorWifeBleData.sendData(AirSendUtil.setWarmTemp(0, AirConst.UNIT_C, 30f, 0f,1)); | |||||
mAirDetectorWifeBleData.sendData(AirSendUtil.setWarmTemp(0, AirConst.UNIT_C, 30f, 0f, 1)); | |||||
} | } | ||||
break; | break; | ||||
case STEP_WARM_HUMIDITY: | case STEP_WARM_HUMIDITY: | ||||
type = AirConst.AIR_TYPE_HUMIDITY; | type = AirConst.AIR_TYPE_HUMIDITY; | ||||
if (isSupportWarmType(type)) { | if (isSupportWarmType(type)) { | ||||
addTest("设置湿度报警"); | addTest("设置湿度报警"); | ||||
mAirDetectorWifeBleData.sendData(AirSendUtil.setWarmHumidity(0, 60f, 7f,1)); | |||||
mAirDetectorWifeBleData.sendData(AirSendUtil.setWarmHumidity(0, 60f, 7f, 1)); | |||||
} | } | ||||
break; | break; | ||||
case STEP_WARM_PM2_5: | case STEP_WARM_PM2_5: | ||||
case STEP_CAL_HCHO: | case STEP_CAL_HCHO: | ||||
type = AirConst.AIR_TYPE_FORMALDEHYDE; | type = AirConst.AIR_TYPE_FORMALDEHYDE; | ||||
if (isSupportCalType(type)) { | if (isSupportCalType(type)) { | ||||
addTest("设置甲醛校准"); | |||||
addTest("设置甲醛校准, 单位校准值加1"); | |||||
mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | ||||
} | } | ||||
break; | break; | ||||
case STEP_CAL_TEMP: | case STEP_CAL_TEMP: | ||||
type = AirConst.AIR_TYPE_TEMP; | type = AirConst.AIR_TYPE_TEMP; | ||||
if (isSupportCalType(type)) { | if (isSupportCalType(type)) { | ||||
addTest("设置温度校准"); | |||||
addTest("设置温度校准, 单位校准值加1"); | |||||
mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | ||||
} | } | ||||
break; | break; | ||||
case STEP_CAL_HUMIDITY: | case STEP_CAL_HUMIDITY: | ||||
type = AirConst.AIR_TYPE_HUMIDITY; | type = AirConst.AIR_TYPE_HUMIDITY; | ||||
if (isSupportCalType(type)) { | if (isSupportCalType(type)) { | ||||
addTest("设置湿度校准"); | |||||
addTest("设置湿度校准, 单位校准值加1"); | |||||
mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | ||||
} | } | ||||
break; | break; | ||||
case STEP_CAL_PM2_5: | case STEP_CAL_PM2_5: | ||||
type = AirConst.AIR_TYPE_PM_2_5; | type = AirConst.AIR_TYPE_PM_2_5; | ||||
if (isSupportCalType(type)) { | if (isSupportCalType(type)) { | ||||
addTest("设置PM2.5校准"); | |||||
addTest("设置PM2.5校准, 单位校准值加1"); | |||||
mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | ||||
} | } | ||||
break; | break; | ||||
case STEP_CAL_PM1_0: | case STEP_CAL_PM1_0: | ||||
type = AirConst.AIR_TYPE_PM_1; | type = AirConst.AIR_TYPE_PM_1; | ||||
if (isSupportCalType(type)) { | if (isSupportCalType(type)) { | ||||
addTest("设置PM1.0校准"); | |||||
addTest("设置PM1.0校准, 单位校准值加1"); | |||||
mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | ||||
} | } | ||||
break; | break; | ||||
case STEP_CAL_PM10: | case STEP_CAL_PM10: | ||||
type = AirConst.AIR_TYPE_PM_10; | type = AirConst.AIR_TYPE_PM_10; | ||||
if (isSupportCalType(type)) { | if (isSupportCalType(type)) { | ||||
addTest("设置PM10校准"); | |||||
addTest("设置PM10校准, 单位校准值加1"); | |||||
mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | ||||
} | } | ||||
break; | break; | ||||
case STEP_CAL_VOC: | case STEP_CAL_VOC: | ||||
type = AirConst.AIR_TYPE_VOC; | type = AirConst.AIR_TYPE_VOC; | ||||
if (isSupportCalType(type)) { | if (isSupportCalType(type)) { | ||||
addTest("设置VOC校准"); | |||||
addTest("设置VOC校准, 单位校准值加1"); | |||||
mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | ||||
} | } | ||||
break; | break; | ||||
case STEP_CAL_CO2: | case STEP_CAL_CO2: | ||||
type = AirConst.AIR_TYPE_CO2; | type = AirConst.AIR_TYPE_CO2; | ||||
if (isSupportCalType(type)) { | if (isSupportCalType(type)) { | ||||
addTest("设置二氧化碳校准"); | |||||
addTest("设置二氧化碳校准, 单位校准值加1"); | |||||
mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | ||||
} | } | ||||
break; | break; | ||||
case STEP_CAL_AQI: | case STEP_CAL_AQI: | ||||
type = AirConst.AIR_TYPE_AQI; | type = AirConst.AIR_TYPE_AQI; | ||||
if (isSupportCalType(type)) { | if (isSupportCalType(type)) { | ||||
addTest("设置空气质量校准"); | |||||
addTest("设置空气质量校准, 单位校准值加1"); | |||||
mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | ||||
} | } | ||||
break; | break; | ||||
case STEP_CAL_TVOC: | case STEP_CAL_TVOC: | ||||
type = AirConst.AIR_TYPE_TVOC; | type = AirConst.AIR_TYPE_TVOC; | ||||
if (isSupportCalType(type)) { | if (isSupportCalType(type)) { | ||||
addTest("设置TVOC校准"); | |||||
addTest("设置TVOC校准, 单位校准值加1"); | |||||
mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | ||||
} | } | ||||
break; | break; | ||||
case STEP_CAL_CO: | case STEP_CAL_CO: | ||||
type = AirConst.AIR_TYPE_CO; | type = AirConst.AIR_TYPE_CO; | ||||
if (isSupportCalType(type)) { | if (isSupportCalType(type)) { | ||||
addTest("设置一氧化碳校准"); | |||||
addTest("设置一氧化碳校准, 单位校准值加1"); | |||||
mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | mAirDetectorWifeBleData.sendData(AirSendUtil.setCalibrationParam(type, 0)); | ||||
} | } | ||||
break; | break; | ||||
type = AirConst.AIR_ALARM_CLOCK; | type = AirConst.AIR_ALARM_CLOCK; | ||||
if (isSupportType(type)) { | if (isSupportType(type)) { | ||||
addTest("设置闹钟"); | addTest("设置闹钟"); | ||||
int[] days = {0,1,1,1,1,1,1,0}; | |||||
mAirDetectorWifeBleData.sendData(AirSendUtil.setAlarm(1, 14, 30, days, 4, 0, false)); | |||||
SupportBean supportBean = deviceSupportList.get(AirConst.AIR_ALARM_CLOCK); | |||||
if (supportBean.getExtentObject() != null) { | |||||
AlarmClockStatement alarmClockStatement = (AlarmClockStatement) supportBean.getExtentObject(); | |||||
int mode = 0; | |||||
if (alarmClockStatement.isMode4()) { | |||||
mode = 4; | |||||
} else if (alarmClockStatement.isMode0()) { | |||||
mode = 0; | |||||
} else if (alarmClockStatement.isMode1()) { | |||||
mode = 1; | |||||
} else if (alarmClockStatement.isMode2()) { | |||||
mode = 2; | |||||
} else if (alarmClockStatement.isMode3()) { | |||||
mode = 3; | |||||
} | |||||
int[] days = AirUtil.getAlarmClockDayByMode(mode); | |||||
mAirDetectorWifeBleData.sendData(AirSendUtil.setAlarm(1, 14, 30, days, 4, 0, false)); | |||||
} | |||||
} | |||||
break; | |||||
case STEP_SETTING_WARN_SWITCH: | |||||
type = AirConst.AIR_SETTING_WARM; | |||||
if (isSupportType(type) && deviceSupportList.get(type).getCurValue() == 0x02) { | |||||
addTest("设置指标报警总开关"); | |||||
mAirDetectorWifeBleData.sendData(AirSendUtil.setMasterWarnSwitch(1)); | |||||
} else { | |||||
mStep = getNextStep(); | |||||
test(); | |||||
} | } | ||||
break; | break; | ||||
case STEP_DONE: | case STEP_DONE: | ||||
} | } | ||||
} | } | ||||
@Override | |||||
public void onResultMasterWarnSwitch(String content) { | |||||
if (mStep == STEP_SETTING_WARN_SWITCH) { | |||||
stepSuccess(content); | |||||
} | |||||
} | |||||
@Override | @Override | ||||
public void onCalResultHCHO(String content) { | public void onCalResultHCHO(String content) { | ||||
if (mStep == STEP_CAL_HCHO) { | if (mStep == STEP_CAL_HCHO) { |
import android.view.ViewGroup; | import android.view.ViewGroup; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import java.util.List; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||
import androidx.core.content.ContextCompat; | import androidx.core.content.ContextCompat; | ||||
import androidx.recyclerview.widget.RecyclerView; | import androidx.recyclerview.widget.RecyclerView; | ||||
import java.util.List; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
public class AirDetectorTestAdapter extends RecyclerView.Adapter<AirDetectorTestAdapter.ViewHolder> { | public class AirDetectorTestAdapter extends RecyclerView.Adapter<AirDetectorTestAdapter.ViewHolder> { | ||||
private Context mContext; | private Context mContext; |
import android.util.SparseArray; | import android.util.SparseArray; | ||||
import androidx.annotation.NonNull; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.airdetector.AirUtil; | import aicare.net.cn.sdk.ailinksdkdemoandroid.modules.airdetector.AirUtil; | ||||
import androidx.annotation.NonNull; | |||||
import cn.net.aicare.modulelibrary.module.airDetector.AirConst; | import cn.net.aicare.modulelibrary.module.airDetector.AirConst; | ||||
import cn.net.aicare.modulelibrary.module.airDetector.CalibrationListBean; | import cn.net.aicare.modulelibrary.module.airDetector.CalibrationListBean; | ||||
import cn.net.aicare.modulelibrary.module.airDetector.StatusBean; | import cn.net.aicare.modulelibrary.module.airDetector.StatusBean; | ||||
return builder.toString(); | return builder.toString(); | ||||
} | } | ||||
/** | |||||
* 参数校准后,实时状态返回 | |||||
* | |||||
* @param statusList | |||||
* @param supportList | |||||
* @return | |||||
*/ | |||||
public static String showCalSettingAfterTextStatus(SparseArray<StatusBean> statusList, SparseArray<SupportBean> supportList) { | |||||
StringBuilder builder = new StringBuilder(); | |||||
StatusBean statusBean = statusList.get(AirConst.AIR_CALIBRATION_PARAMETERS); | |||||
// 支持列表不包含,添加空字符串 | |||||
SupportBean supportBean = supportList.get(AirConst.AIR_CALIBRATION_PARAMETERS); | |||||
if (supportBean != null) { | |||||
builder.append(AirUtil.dealCalResultAllStatus(statusBean, supportList)); | |||||
} | |||||
return builder.toString(); | |||||
} | |||||
/** | /** | ||||
* 设置指令返回 | * 设置指令返回 | ||||
* | * | ||||
* @param settingList | * @param settingList | ||||
* @param supportList | * @param supportList | ||||
* @Param resultInterface | |||||
* @return | * @return | ||||
* @Param resultInterface | |||||
*/ | */ | ||||
public static String showGetResultSettings(SparseArray<StatusBean> settingList, SparseArray<SupportBean> supportList){ | |||||
public static String showGetResultSettings(SparseArray<StatusBean> settingList, SparseArray<SupportBean> supportList) { | |||||
StringBuilder builder = new StringBuilder(); | StringBuilder builder = new StringBuilder(); | ||||
for (int i = 0; i < settingList.size(); i++) { | for (int i = 0; i < settingList.size(); i++) { | ||||
int type = settingList.keyAt(i); | int type = settingList.keyAt(i); | ||||
break; | break; | ||||
case AirConst.AIR_TYPE_HUMIDITY: | case AirConst.AIR_TYPE_HUMIDITY: | ||||
int hPow = (int) Math.pow(10, supportBean.getPoint()); | int hPow = (int) Math.pow(10, supportBean.getPoint()); | ||||
String humpStr = "下限值:" + settingBean.getWarmMin() / hPow + ", 上限值: "+ settingBean.getWarmMax() / hPow; | |||||
String humpStr = "下限值:" + settingBean.getWarmMin() / hPow + ", 上限值: " + settingBean.getWarmMax() / hPow; | |||||
builder.append(humpStr); | builder.append(humpStr); | ||||
break; | break; | ||||
case AirConst.AIR_TYPE_TEMP: | case AirConst.AIR_TYPE_TEMP: | ||||
String tempStr = "下限值:" + settingBean.getWarmMin() + ", 上限值: "+ settingBean.getWarmMax(); | |||||
String tempStr = "下限值:" + settingBean.getWarmMin() + ", 上限值: " + settingBean.getWarmMax(); | |||||
builder.append(tempStr); | builder.append(tempStr); | ||||
break; | break; | ||||
case AirConst.AIR_SETTING_VOICE: | case AirConst.AIR_SETTING_VOICE: | ||||
resultInterface.onWarmResultCO(AirUtil.getWarmResultStr(supportBean, resultBean)); | resultInterface.onWarmResultCO(AirUtil.getWarmResultStr(supportBean, resultBean)); | ||||
break; | break; | ||||
case AirConst.AIR_TYPE_HUMIDITY: | case AirConst.AIR_TYPE_HUMIDITY: | ||||
String humpStr = "下限值:" + resultBean.getWarmMin() + ", 上限值: "+ resultBean.getWarmMax(); | |||||
String humpStr = "下限值:" + resultBean.getWarmMin() + ", 上限值: " + resultBean.getWarmMax(); | |||||
resultInterface.onWarmResultHumidity(humpStr); | resultInterface.onWarmResultHumidity(humpStr); | ||||
break; | break; | ||||
case AirConst.AIR_TYPE_TEMP: | case AirConst.AIR_TYPE_TEMP: | ||||
String tempStr = "下限值:" + resultBean.getWarmMin() + ", 上限值: "+ resultBean.getWarmMax(); | |||||
String tempStr = "下限值:" + resultBean.getWarmMin() + ", 上限值: " + resultBean.getWarmMax(); | |||||
resultInterface.onWarmResultTemp(tempStr); | resultInterface.onWarmResultTemp(tempStr); | ||||
break; | break; | ||||
case AirConst.AIR_SETTING_VOICE: | case AirConst.AIR_SETTING_VOICE: | ||||
resultInterface.onResultVoice("开关:" + AirUtil.getSwitchStatus(resultBean.isOpen()) + ", Level: "+ resultBean.getValue()); | |||||
resultInterface.onResultVoice("开关:" + AirUtil.getSwitchStatus(resultBean.isOpen()) + ", Level: " + resultBean.getValue()); | |||||
break; | break; | ||||
case AirConst.AIR_SETTING_WARM_DURATION: | case AirConst.AIR_SETTING_WARM_DURATION: | ||||
resultInterface.onResultWarmDuration("时长:" + resultBean.getValue() + " S"); | resultInterface.onResultWarmDuration("时长:" + resultBean.getValue() + " S"); | ||||
case AirConst.AIR_MONITORING_DISPLAY_DATA: | case AirConst.AIR_MONITORING_DISPLAY_DATA: | ||||
resultInterface.onResultMonitoringDisplayData("监测显示数据开关:" + AirUtil.getSwitchStatus(resultBean.isOpen())); | resultInterface.onResultMonitoringDisplayData("监测显示数据开关:" + AirUtil.getSwitchStatus(resultBean.isOpen())); | ||||
break; | break; | ||||
case AirConst.AIR_SETTING_WARM: | |||||
resultInterface.onResultMasterWarnSwitch("指标报警总开关:" + AirUtil.getSwitchStatus(resultBean.isOpen())); | |||||
break; | |||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
for (CalibrationListBean.CalibrationBean bean : list) { | for (CalibrationListBean.CalibrationBean bean : list) { | ||||
String resultStr = AirUtil.getOperateStr(bean.getCalOperate()); | String resultStr = AirUtil.getOperateStr(bean.getCalOperate()); | ||||
switch (bean.getCalType()){ | |||||
switch (bean.getCalType()) { | |||||
case AirConst.AIR_TYPE_FORMALDEHYDE: | case AirConst.AIR_TYPE_FORMALDEHYDE: | ||||
resultInterface.onCalResultHCHO(resultStr); | resultInterface.onCalResultHCHO(resultStr); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } |
* @param content | * @param content | ||||
*/ | */ | ||||
public void onResultDataDisplayMode(String content); | public void onResultDataDisplayMode(String content); | ||||
/** | |||||
* 报警总开关设置 | |||||
* @param content | |||||
*/ | |||||
public void onResultMasterWarnSwitch(String content); | |||||
/** | /** | ||||
* 甲醛校准 | * 甲醛校准 | ||||
* @param content | * @param content |
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.RadioButton; | import android.widget.RadioButton; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.bean.SupportUnitBean; | import com.pingwang.bluetoothlib.bean.SupportUnitBean; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.BleNutrition.BleNutritionData; | import cn.net.aicare.modulelibrary.module.BleNutrition.BleNutritionData; | ||||
public class BleNutritionActivity extends BleBaseActivity implements View.OnClickListener, BleNutritionData.BleNutritionCallback { | public class BleNutritionActivity extends BleBaseActivity implements View.OnClickListener, BleNutritionData.BleNutritionCallback { |
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.RadioButton; | import android.widget.RadioButton; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.bean.SupportUnitBean; | import com.pingwang.bluetoothlib.bean.SupportUnitBean; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | import com.pingwang.bluetoothlib.listener.OnCallbackBle; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.BloodGlucose.BloodGlucoseBleDeviceData; | import cn.net.aicare.modulelibrary.module.BloodGlucose.BloodGlucoseBleDeviceData; | ||||
import cn.net.aicare.modulelibrary.module.BloodGlucose.BloodGlucoseUtil; | import cn.net.aicare.modulelibrary.module.BloodGlucose.BloodGlucoseUtil; | ||||
mLogList.add(0, "绑定服务成功"); | mLogList.add(0, "绑定服务成功"); | ||||
listAdapter.notifyDataSetChanged(); | listAdapter.notifyDataSetChanged(); | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | ||||
if (bleDevice != null) { | if (bleDevice != null) { | ||||
mBloodGlucoseBleDeviceData = new BloodGlucoseBleDeviceData(bleDevice); | mBloodGlucoseBleDeviceData = new BloodGlucoseBleDeviceData(bleDevice); | ||||
@Override | @Override | ||||
public void unbindServices() { | public void unbindServices() { | ||||
if (mBluetoothService!=null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | } | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.Toast; | import android.widget.Toast; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.bean.SupportUnitBean; | import com.pingwang.bluetoothlib.bean.SupportUnitBean; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.listener.OnBleCompanyListener; | import com.pingwang.bluetoothlib.listener.OnBleCompanyListener; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.BloodGlucose.BloodGlucoseBleDeviceData; | import cn.net.aicare.modulelibrary.module.BloodGlucose.BloodGlucoseBleDeviceData; | ||||
import cn.net.aicare.modulelibrary.module.BloodGlucose.BloodGlucoseUtil; | import cn.net.aicare.modulelibrary.module.BloodGlucose.BloodGlucoseUtil; | ||||
@Override | @Override | ||||
public void onServiceSuccess() { | public void onServiceSuccess() { | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | ||||
if (bleDevice != null) { | if (bleDevice != null) { | ||||
mBleDevice = new BloodGlucoseBleDeviceData(bleDevice); | mBleDevice = new BloodGlucoseBleDeviceData(bleDevice); | ||||
@Override | @Override | ||||
public void unbindServices() { | public void unbindServices() { | ||||
if (mBluetoothService!=null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | } | ||||
@Override | @Override |
import android.widget.ArrayAdapter; | import android.widget.ArrayAdapter; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.bean.SupportUnitBean; | import com.pingwang.bluetoothlib.bean.SupportUnitBean; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.Transmission.TransmissionDeviceData; | import cn.net.aicare.modulelibrary.module.Transmission.TransmissionDeviceData; | ||||
/** | /** |
import android.widget.SeekBar; | import android.widget.SeekBar; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import androidx.annotation.Nullable; | |||||
import androidx.appcompat.app.AppCompatActivity; | |||||
import org.json.JSONArray; | import org.json.JSONArray; | ||||
import org.json.JSONException; | import org.json.JSONException; | ||||
import org.json.JSONObject; | import org.json.JSONObject; | ||||
import java.util.Locale; | import java.util.Locale; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import androidx.annotation.Nullable; | |||||
import androidx.appcompat.app.AppCompatActivity; | |||||
import cn.net.aicare.algorithmutil.AlgorithmUtil; | import cn.net.aicare.algorithmutil.AlgorithmUtil; | ||||
import cn.net.aicare.algorithmutil.BodyFatData; | import cn.net.aicare.algorithmutil.BodyFatData; | ||||
import android.widget.ArrayAdapter; | import android.widget.ArrayAdapter; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import androidx.core.app.ActivityCompat; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import com.pingwang.bluetoothlib.config.BleConfig; | import com.pingwang.bluetoothlib.config.BleConfig; | ||||
import com.pingwang.bluetoothlib.listener.OnCallbackDis; | import com.pingwang.bluetoothlib.listener.OnCallbackDis; | ||||
import com.pingwang.bluetoothlib.listener.OnScanFilterListener; | import com.pingwang.bluetoothlib.listener.OnScanFilterListener; | ||||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | import com.pingwang.bluetoothlib.utils.BleStrUtils; | ||||
import com.pinwang.ailinkble.AiLinkPwdUtil; | |||||
import java.math.BigDecimal; | import java.math.BigDecimal; | ||||
import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import androidx.core.app.ActivityCompat; | |||||
import cn.net.aicare.modulelibrary.module.BroadcastScale.BroadcastScaleBleConfig; | |||||
import cn.net.aicare.modulelibrary.module.broadcastheight.BroadCastHeightConfig; | |||||
import cn.net.aicare.modulelibrary.module.broadcastheight.BroadCastHeightDeviceData; | |||||
public class BroadcastHeightActivity extends BleBaseActivity implements OnCallbackDis, OnScanFilterListener { | |||||
public class BroadcastHeightActivity extends BleBaseActivity implements OnCallbackDis, OnScanFilterListener,BroadCastHeightDeviceData.OnNotifyHeightData { | |||||
private Context mContext; | private Context mContext; | ||||
private ArrayAdapter mListAdapter; | private ArrayAdapter mListAdapter; | ||||
private String mMac; | private String mMac; | ||||
private String mac; | |||||
private BroadCastHeightDeviceData mBroadCastHeightDeviceData; | |||||
@Override | @Override | ||||
protected void onCreate(@Nullable Bundle savedInstanceState) { | protected void onCreate(@Nullable Bundle savedInstanceState) { | ||||
@Override | @Override | ||||
public void unbindServices() { | public void unbindServices() { | ||||
if (mBroadCastHeightDeviceData != null) { | |||||
mBroadCastHeightDeviceData.clear(); | |||||
mBroadCastHeightDeviceData = null; | |||||
} | |||||
} | } | ||||
@Override | @Override | ||||
public void onScanRecord(BleValueBean bleValueBean) { | public void onScanRecord(BleValueBean bleValueBean) { | ||||
if (TextUtils.isEmpty(mMac) && bleValueBean.isBroadcastModule()) { | if (TextUtils.isEmpty(mMac) && bleValueBean.isBroadcastModule()) { | ||||
// 是广播模块 | // 是广播模块 | ||||
if (bleValueBean.getCid() == 0x03) { | |||||
if (bleValueBean.getCid() == BroadCastHeightConfig.BROAD_CAST_HEIGHT) { | |||||
// 是身高仪,进行数据解析 | // 是身高仪,进行数据解析 | ||||
notifyData(bleValueBean.getManufacturerData(), bleValueBean.getCid(), bleValueBean.getVid(), bleValueBean.getPid(), bleValueBean.getMac()); | |||||
mac = bleValueBean.getMac(); | |||||
mBroadCastHeightDeviceData.onNotifyData(bleValueBean.getManufacturerData(), bleValueBean.getCid(), bleValueBean.getVid(), bleValueBean.getPid()); | |||||
// notifyData(bleValueBean.getManufacturerData(), bleValueBean.getCid(), bleValueBean.getVid(), bleValueBean.getPid(), bleValueBean.getMac()); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | |||||
* @param manufacturerData 自定义厂商数据0xFF后面的数据 | |||||
* @param cid cid 设备类型 | |||||
* @param vid vid | |||||
* @param pid pid | |||||
*/ | |||||
private void notifyData(byte[] manufacturerData, int cid, int vid, int pid, String mac) { | |||||
if (manufacturerData == null) { | |||||
addText("接收到的数据:null"); | |||||
return; | |||||
} | |||||
if (manufacturerData.length >= 20) { | |||||
byte sum = manufacturerData[9]; | |||||
byte[] data = new byte[10]; | |||||
System.arraycopy(manufacturerData, 10, data, 0, data.length); | |||||
byte newSum = cmdSum(data); | |||||
if (newSum == sum) { | |||||
// addText("接收到的数据:原始数据:" + BleStrUtils.byte2HexStr(data)); | |||||
byte[] bytes; | |||||
byte[] dataOriginal = data.clone(); | |||||
if (cid != 0 || vid != 0 || pid != 0) { | |||||
//数据需要解密 | |||||
if (cid == BroadcastScaleBleConfig.BROADCAST_SCALE_LING_YANG_CID) { | |||||
bytes = AiLinkPwdUtil.decryptLingYang(data); | |||||
} else { | |||||
bytes = AiLinkPwdUtil.decryptBroadcast(cid, vid, pid, data); | |||||
} | |||||
} else { | |||||
bytes = data; | |||||
} | |||||
// addText("接收到的数据:" + BleStrUtils.byte2HexStr(bytes)); | |||||
checkData(bytes, cid, vid, pid, mac); | |||||
} else { | |||||
addText("校验和错误"); | |||||
} | |||||
} | |||||
} | |||||
// 上一次的流水号 | |||||
private int mLastSerialNum = -1; | |||||
/** | |||||
* 解析数据 | |||||
* | |||||
* @param hex 解密后的数据 | |||||
* @param cid cid | |||||
* @param vid vid | |||||
* @param pid pid | |||||
*/ | |||||
private void checkData(byte[] hex, int cid, int vid, int pid, String mac) { | |||||
// 流水号 | |||||
int serialNum = hex[0]; | |||||
if (serialNum == mLastSerialNum) { | |||||
return; | |||||
} | |||||
mLastSerialNum = serialNum; | |||||
// 测量标识 | |||||
int flag = hex[1] & 0xff; | |||||
// 身高原始数据 | |||||
int heightOrigin = (hex[2] & 0xff) << 8 | (hex[3] & 0xff); | |||||
// 身高单位 0:cm;1:inch;2:ft-in | |||||
int heightUnit = (hex[4] & 0xff) & 0x0f; | |||||
// 身高小数点 | |||||
int heightDecimal = ((hex[4] & 0xff) & 0xf0) >> 4; | |||||
// 体重原始数据 | |||||
int weightOrigin = (hex[5] & 0xff) << 8 | (hex[6] & 0xff); | |||||
// 体重单位 0:kg;1:斤;2:lb:oz;3:oz;4:st:lb;5:g;6:lb | |||||
int weightUnit = (hex[7] & 0xff) & 0x0f; | |||||
// 体重正负号 | |||||
int weightSymbol = ((hex[7] & 0xff) & 0x10) >> 4; | |||||
// 体重小数点 | |||||
int weightDecimal = ((hex[7] & 0xff) & 0xe0) >> 5; | |||||
// 电量 | |||||
int battery = hex[8] & 0xff; | |||||
// 输出 | |||||
String text = ""; | |||||
text += "MAC地址:" + mac; | |||||
text += "\n数据解析:" + BleStrUtils.byte2HexStr(hex); | |||||
text += "\n测量标识:" + flag + ":" + getFlagStr(flag); | |||||
text += "\n身高原始数据:" + heightOrigin; | |||||
text += "\n身高单位:" + heightUnit; | |||||
text += "\n身高小数点:" + heightDecimal; | |||||
text += "\n身高最终值:" + getHeightStr(heightOrigin, heightUnit, heightDecimal); | |||||
if (weightOrigin != 0xffff) { | |||||
text += "\n体重原始数据:" + weightOrigin; | |||||
text += "\n体重单位:" + weightUnit; | |||||
text += "\n体重正负号:" + weightSymbol; | |||||
text += "\n体重小数点:" + weightDecimal; | |||||
text += "\n体重最终值:" + getWeightStr(weightOrigin, weightUnit, weightDecimal, weightSymbol); | |||||
} else { | |||||
text += "\n体重:" + "不支持"; | |||||
} | |||||
if (battery != 0xff) { | |||||
text += "\n电量:" + battery; | |||||
} else { | |||||
text += "\n电量:" + "不支持"; | |||||
} | |||||
addText(text); | |||||
} | |||||
// /** | |||||
// * @param manufacturerData 自定义厂商数据0xFF后面的数据 | |||||
// * @param cid cid 设备类型 | |||||
// * @param vid vid | |||||
// * @param pid pid | |||||
// */ | |||||
// private void notifyData(byte[] manufacturerData, int cid, int vid, int pid, String mac) { | |||||
// if (manufacturerData == null) { | |||||
// addText("接收到的数据:null"); | |||||
// return; | |||||
// } | |||||
// if (manufacturerData.length >= 20) { | |||||
// byte sum = manufacturerData[9]; | |||||
// byte[] data = new byte[10]; | |||||
// System.arraycopy(manufacturerData, 10, data, 0, data.length); | |||||
// byte newSum = cmdSum(data); | |||||
// if (newSum == sum) { | |||||
//// addText("接收到的数据:原始数据:" + BleStrUtils.byte2HexStr(data)); | |||||
// byte[] bytes; | |||||
// if (cid != 0 || vid != 0 || pid != 0) { | |||||
// //数据需要解密 | |||||
// if (cid == BroadcastScaleBleConfig.BROADCAST_SCALE_LING_YANG_CID) { | |||||
// bytes = AiLinkPwdUtil.decryptLingYang(data); | |||||
// } else { | |||||
// bytes = AiLinkPwdUtil.decryptBroadcast(cid, vid, pid, data); | |||||
// } | |||||
// } else { | |||||
// bytes = data; | |||||
// } | |||||
// | |||||
//// addText("接收到的数据:" + BleStrUtils.byte2HexStr(bytes)); | |||||
// checkData(bytes, cid, vid, pid, mac); | |||||
// } else { | |||||
// addText("校验和错误"); | |||||
// } | |||||
// } | |||||
// } | |||||
// | |||||
// // 上一次的流水号 | |||||
// private int mLastSerialNum = -1; | |||||
// | |||||
// /** | |||||
// * 解析数据 | |||||
// * | |||||
// * @param hex 解密后的数据 | |||||
// * @param cid cid | |||||
// * @param vid vid | |||||
// * @param pid pid | |||||
// */ | |||||
// private void checkData(byte[] hex, int cid, int vid, int pid, String mac) { | |||||
// // 流水号 | |||||
// int serialNum = hex[0]; | |||||
// if (serialNum == mLastSerialNum) { | |||||
// return; | |||||
// } | |||||
// mLastSerialNum = serialNum; | |||||
// | |||||
// // 测量标识 | |||||
// int flag = hex[1] & 0xff; | |||||
// // 身高原始数据 | |||||
// int heightOrigin = (hex[2] & 0xff) << 8 | (hex[3] & 0xff); | |||||
// // 身高单位 0:cm;1:inch;2:ft-in | |||||
// int heightUnit = (hex[4] & 0xff) & 0x0f; | |||||
// // 身高小数点 | |||||
// int heightDecimal = ((hex[4] & 0xff) & 0xf0) >> 4; | |||||
// // 体重原始数据 | |||||
// int weightOrigin = (hex[5] & 0xff) << 8 | (hex[6] & 0xff); | |||||
// // 体重单位 0:kg;1:斤;2:lb:oz;3:oz;4:st:lb;5:g;6:lb | |||||
// int weightUnit = (hex[7] & 0xff) & 0x0f; | |||||
// // 体重正负号 | |||||
// int weightSymbol = ((hex[7] & 0xff) & 0x10) >> 4; | |||||
// // 体重小数点 | |||||
// int weightDecimal = ((hex[7] & 0xff) & 0xe0) >> 5; | |||||
// // 电量 | |||||
// int battery = hex[8] & 0xff; | |||||
// | |||||
// // 输出 | |||||
// String text = ""; | |||||
// text += "MAC地址:" + mac; | |||||
// text += "\n数据解析:" + BleStrUtils.byte2HexStr(hex); | |||||
// text += "\n测量标识:" + flag + ":" + getFlagStr(flag); | |||||
// text += "\n身高原始数据:" + heightOrigin; | |||||
// text += "\n身高单位:" + heightUnit; | |||||
// text += "\n身高小数点:" + heightDecimal; | |||||
// text += "\n身高最终值:" + getHeightStr(heightOrigin, heightUnit, heightDecimal); | |||||
// | |||||
// if (weightOrigin != 0xffff) { | |||||
// text += "\n体重原始数据:" + weightOrigin; | |||||
// text += "\n体重单位:" + weightUnit; | |||||
// text += "\n体重正负号:" + weightSymbol; | |||||
// text += "\n体重小数点:" + weightDecimal; | |||||
// text += "\n体重最终值:" + getWeightStr(weightOrigin, weightUnit, weightDecimal, weightSymbol); | |||||
// } else { | |||||
// text += "\n体重:" + "不支持"; | |||||
// } | |||||
// if (battery != 0xff) { | |||||
// text += "\n电量:" + battery; | |||||
// } else { | |||||
// text += "\n电量:" + "不支持"; | |||||
// } | |||||
// addText(text); | |||||
// } | |||||
private String getFlagStr(int flag) { | private String getFlagStr(int flag) { | ||||
String str = ""; | String str = ""; | ||||
switch (flag) { | switch (flag) { | ||||
case 0: | |||||
case BroadCastHeightConfig.MEASURING: | |||||
str = "正在测量"; | str = "正在测量"; | ||||
break; | break; | ||||
case 1: | |||||
case BroadCastHeightConfig.MEASURING_STABLE: | |||||
str = "稳定身高体重"; | str = "稳定身高体重"; | ||||
break; | break; | ||||
case 0xff: | |||||
case BroadCastHeightConfig.MEASURING_FAILED: | |||||
str = "测量失败"; | str = "测量失败"; | ||||
break; | break; | ||||
} | } | ||||
str += getPreFloatStr((float) (heightOrigin * 1.0f / Math.pow(10, heightDecimal)), heightDecimal, 0); | str += getPreFloatStr((float) (heightOrigin * 1.0f / Math.pow(10, heightDecimal)), heightDecimal, 0); | ||||
switch (heightUnit) { | switch (heightUnit) { | ||||
case 0: | |||||
case BroadCastHeightConfig.UNIT_CM: | |||||
str += "cm"; | str += "cm"; | ||||
break; | break; | ||||
case 1: | |||||
case BroadCastHeightConfig.UNIT_INCH: | |||||
str += "inch"; | str += "inch"; | ||||
break; | break; | ||||
case 2: | |||||
case BroadCastHeightConfig.UNIT_FT_IN: | |||||
try { | try { | ||||
int ft = Integer.parseInt(str); | |||||
int f = ft / 12; | |||||
int i = ft - f * 12; | |||||
str = f + "'" + i + "\""; | |||||
float inchSize = Float.parseFloat(str); | |||||
int feet = (int) (inchSize / 12); | |||||
float inch = (inchSize % 12f); | |||||
String decimalStr = "%." + heightDecimal + "f"; | |||||
inch = Float.parseFloat(String.format(Locale.US, decimalStr, inch)); | |||||
str = feet + "'" + inch + "\""; | |||||
} catch (Exception e) { | } catch (Exception e) { | ||||
str = "解析异常,原始值不是int型"; | |||||
str = "解析异常"; | |||||
} | } | ||||
break; | break; | ||||
} | } | ||||
str += getPreFloatStr((float) (weightOrigin * 1.0f / Math.pow(10, weightDecimal)) * (weightSymbol == 1 ? -1 : 1), weightDecimal, 0); | str += getPreFloatStr((float) (weightOrigin * 1.0f / Math.pow(10, weightDecimal)) * (weightSymbol == 1 ? -1 : 1), weightDecimal, 0); | ||||
switch (weightUnit) { | switch (weightUnit) { | ||||
case 0: | |||||
case BroadCastHeightConfig.UNIT_KG: | |||||
str += "kg"; | str += "kg"; | ||||
break; | break; | ||||
case 1: | |||||
case BroadCastHeightConfig.UNIT_JIN: | |||||
str += "斤"; | str += "斤"; | ||||
break; | break; | ||||
case 2: | |||||
case BroadCastHeightConfig.UNIT_LB_OZ: | |||||
str += "lb:oz"; | str += "lb:oz"; | ||||
break; | break; | ||||
case 3: | |||||
case BroadCastHeightConfig.UNIT_OZ: | |||||
str += "oz"; | str += "oz"; | ||||
break; | break; | ||||
case 4: | |||||
case BroadCastHeightConfig.UNIT_ST_LB: | |||||
str += "st:lb"; | str += "st:lb"; | ||||
break; | break; | ||||
case 5: | |||||
case BroadCastHeightConfig.UNIT_G: | |||||
str += "g"; | str += "g"; | ||||
break; | break; | ||||
case 6: | |||||
case BroadCastHeightConfig.UNIT_LB: | |||||
str += "lb"; | str += "lb"; | ||||
break; | break; | ||||
} | } | ||||
// 权限都有了,OK | // 权限都有了,OK | ||||
addText("权限都有,开始接收广播数据"); | addText("权限都有,开始接收广播数据"); | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBroadCastHeightDeviceData = BroadCastHeightDeviceData.getInstance(); | |||||
mBroadCastHeightDeviceData.setOnNotifyHeightData(this); | |||||
mBluetoothService.setOnScanFilterListener(this); | mBluetoothService.setOnScanFilterListener(this); | ||||
mBluetoothService.scanLeDevice(0, BleConfig.UUID_SERVER_BROADCAST_AILINK); | |||||
mBluetoothService.startScan(0, BleConfig.UUID_SERVER_BROADCAST_AILINK); | |||||
} | } | ||||
} | } | ||||
mListAdapter.notifyDataSetChanged(); | mListAdapter.notifyDataSetChanged(); | ||||
list_view.smoothScrollToPosition(mList.size() - 1); | list_view.smoothScrollToPosition(mList.size() - 1); | ||||
} | } | ||||
/** | |||||
* | |||||
* @param hex 解析后的数据 | |||||
* @param flag 测量标识 | |||||
* @param heightOrigin 身高原始数据 | |||||
* @param heightUnit 身高单位 | |||||
* @param heightDecimal 身高小数点 | |||||
* @param weightOrigin 体重原始数据 | |||||
* @param weightUnit 体重单位 | |||||
* @param weightSymbol 体重正负号 | |||||
* @param weightDecimal 体重小数点 | |||||
* @param battery 体重最终值 | |||||
*/ | |||||
@Override | |||||
public void notifyData(byte[] hex, int flag, int heightOrigin, int heightUnit, int heightDecimal, | |||||
int weightOrigin, int weightUnit, int weightSymbol, int weightDecimal, int battery) { | |||||
if (heightOrigin == 0){ | |||||
return; | |||||
} | |||||
// 输出 | |||||
String text = ""; | |||||
text += "MAC地址:" + mac; | |||||
text += "\n数据解析:" + BleStrUtils.byte2HexStr(hex); | |||||
text += "\n测量标识:" + flag + ":" + getFlagStr(flag); | |||||
text += "\n身高原始数据:" + heightOrigin; | |||||
text += "\n身高单位:" + heightUnit; | |||||
text += "\n身高小数点:" + heightDecimal; | |||||
text += "\n身高最终值:" + getHeightStr(heightOrigin, heightUnit, heightDecimal); | |||||
if (weightOrigin != 0xffff) { | |||||
text += "\n体重原始数据:" + weightOrigin; | |||||
text += "\n体重单位:" + weightUnit; | |||||
text += "\n体重正负号:" + weightSymbol; | |||||
text += "\n体重小数点:" + weightDecimal; | |||||
text += "\n体重最终值:" + getWeightStr(weightOrigin, weightUnit, weightDecimal, weightSymbol); | |||||
} else { | |||||
text += "\n体重:" + "不支持"; | |||||
} | |||||
if (battery != 0xff) { | |||||
text += "\n电量:" + battery; | |||||
} else { | |||||
text += "\n电量:" + "不支持"; | |||||
} | |||||
addText(text); | |||||
} | |||||
} | } |
import android.widget.Button; | import android.widget.Button; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import com.pingwang.bluetoothlib.config.BleConfig; | import com.pingwang.bluetoothlib.config.BleConfig; | ||||
import com.pingwang.bluetoothlib.listener.OnScanFilterListener; | import com.pingwang.bluetoothlib.listener.OnScanFilterListener; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.Nullable; | |||||
public class BroadNutritionActivity extends BleBaseActivity implements View.OnClickListener, OnScanFilterListener { | public class BroadNutritionActivity extends BleBaseActivity implements View.OnClickListener, OnScanFilterListener { | ||||
public void onClick(View v) { | public void onClick(View v) { | ||||
int id = v.getId(); | int id = v.getId(); | ||||
if (id == R.id.btn_start) { | if (id == R.id.btn_start) { | ||||
mBluetoothService.scanLeDevice(0, BleConfig.UUID_SERVER_BROADCAST_AILINK); | |||||
mBluetoothService.startScan(0, BleConfig.UUID_SERVER_BROADCAST_AILINK); | |||||
} else if (id == R.id.btn_stop) { | } else if (id == R.id.btn_stop) { | ||||
mBluetoothService.stopScan(); | mBluetoothService.stopScan(); | ||||
} else if (id == R.id.btn_clear) { | } else if (id == R.id.btn_clear) { | ||||
public void onScanRecord(BleValueBean bleValueBean) { | public void onScanRecord(BleValueBean bleValueBean) { | ||||
byte[] manufacturerData = bleValueBean.getManufacturerData(); | byte[] manufacturerData = bleValueBean.getManufacturerData(); | ||||
mMac = bleValueBean.getMac(); | mMac = bleValueBean.getMac(); | ||||
onNotifyData(manufacturerData, bleValueBean.getCid(), bleValueBean.getVid(), bleValueBean.getPid()); | |||||
onNotifyData("",manufacturerData, bleValueBean.getCid(), bleValueBean.getVid(), bleValueBean.getPid()); | |||||
} | } | ||||
private SimpleDateFormat mSdf; | private SimpleDateFormat mSdf; | ||||
* @param vid vid | * @param vid vid | ||||
* @param pid pid | * @param pid pid | ||||
*/ | */ | ||||
public void onNotifyData(byte[] manufacturerData, int cid, int vid, int pid) { | |||||
public void onNotifyData(String uuid, byte[] manufacturerData, int cid, int vid, int pid) { | |||||
if (manufacturerData == null) { | if (manufacturerData == null) { | ||||
BleLog.i("Tag1", "接收到的数据:null"); | BleLog.i("Tag1", "接收到的数据:null"); | ||||
return; | return; | ||||
int symbol = (hex[5] & 0xff) >> 7; | int symbol = (hex[5] & 0xff) >> 7; | ||||
int battery = hex[6] & 0xff; | int battery = hex[6] & 0xff; | ||||
int err = hex[7] & 0xff; | int err = hex[7] & 0xff; | ||||
float weightValue = weight; | float weightValue = weight; | ||||
if (symbol == 1) { | if (symbol == 1) { | ||||
weightValue *= -1; | weightValue *= -1; | ||||
} | } | ||||
weightValue /= Math.pow(10, decimal); | weightValue /= Math.pow(10, decimal); | ||||
String weightStr = getPreFloatStr(weightValue, decimal); | String weightStr = getPreFloatStr(weightValue, decimal); | ||||
switch (unit) { | |||||
default: | |||||
case 0: | |||||
weightStr += "g"; | |||||
break; | |||||
case 1: | |||||
weightStr += "ml"; | |||||
break; | |||||
} | |||||
addText("Mac:" + mMac + "\n流水号:" + no + "\n测量标识符:" + type + "\n原始重量:" + weight + ",单位:" + unit + ",小数点:" + decimal + ",正负:" + symbol + "\n重量:" + weightStr + "\n电量:" + battery + "\n异常标志位:" + err); | addText("Mac:" + mMac + "\n流水号:" + no + "\n测量标识符:" + type + "\n原始重量:" + weight + ",单位:" + unit + ",小数点:" + decimal + ",正负:" + symbol + "\n重量:" + weightStr + "\n电量:" + battery + "\n异常标志位:" + err); | ||||
} | } | ||||
} | } |
import android.widget.RadioGroup; | import android.widget.RadioGroup; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.AILinkBleManager; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import com.pingwang.bluetoothlib.config.BleConfig; | import com.pingwang.bluetoothlib.config.BleConfig; | ||||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | ||||
import com.pingwang.bluetoothlib.listener.OnBleBroadcastDataListener; | |||||
import com.pingwang.bluetoothlib.listener.OnCallbackDis; | import com.pingwang.bluetoothlib.listener.OnCallbackDis; | ||||
import com.pingwang.bluetoothlib.listener.OnScanFilterListener; | |||||
import com.pingwang.bluetoothlib.utils.BleDensityUtil; | import com.pingwang.bluetoothlib.utils.BleDensityUtil; | ||||
import com.pingwang.bluetoothlib.utils.BleLog; | import com.pingwang.bluetoothlib.utils.BleLog; | ||||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | import com.pingwang.bluetoothlib.utils.BleStrUtils; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.BroadcastScaleActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.BroadcastScaleActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleNewBaseActivity; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.broadcastweightscale.BroadcastWeightScaleBleConfig; | import cn.net.aicare.modulelibrary.module.broadcastweightscale.BroadcastWeightScaleBleConfig; | ||||
import cn.net.aicare.modulelibrary.module.broadcastweightscale.BroadcastWeightScaleDeviceData; | import cn.net.aicare.modulelibrary.module.broadcastweightscale.BroadcastWeightScaleDeviceData; | ||||
/** | /** | ||||
* 广播体重秤 | |||||
* @auther ljl | * @auther ljl | ||||
* on 2023/3/10 | * on 2023/3/10 | ||||
*/ | */ | ||||
public class BroadcastWeightScaleActivity extends BleBaseActivity implements OnCallbackDis, BroadcastWeightScaleDeviceData.OnNotifyData, OnScanFilterListener, View.OnClickListener, | |||||
public class BroadcastWeightScaleActivity extends BleNewBaseActivity implements OnCallbackDis, BroadcastWeightScaleDeviceData.OnNotifyData, OnBleBroadcastDataListener, View.OnClickListener, | |||||
RadioGroup.OnCheckedChangeListener { | RadioGroup.OnCheckedChangeListener { | ||||
private static String TAG = BroadcastScaleActivity.class.getName(); | private static String TAG = BroadcastScaleActivity.class.getName(); | ||||
mHandler.sendEmptyMessage(REFRESH_DATA); | mHandler.sendEmptyMessage(REFRESH_DATA); | ||||
break; | break; | ||||
case R.id.open_weight: | case R.id.open_weight: | ||||
if (mBluetoothService != null) { | |||||
mBluetoothService.scanLeDevice(0, UUID.fromString("0000F0A0-0000-1000-8000-00805F9B34FB")); | |||||
if (AILinkBleManager.getInstance() != null) { | |||||
AILinkBleManager.getInstance().startScan(0, UUID.fromString("0000F0A0-0000-1000-8000-00805F9B34FB")); | |||||
} | } | ||||
break; | break; | ||||
case R.id.stop_weight: | case R.id.stop_weight: | ||||
if (mBluetoothService != null) { | |||||
mBluetoothService.stopScan(); | |||||
if (AILinkBleManager.getInstance() != null) { | |||||
AILinkBleManager.getInstance().stopScan(); | |||||
} | } | ||||
break; | break; | ||||
default: | default: | ||||
public void onServiceSuccess() { | public void onServiceSuccess() { | ||||
BleLog.i("ljl", "服务与界面建立连接成功"); | BleLog.i("ljl", "服务与界面建立连接成功"); | ||||
//与服务建立连接 | //与服务建立连接 | ||||
if (mBluetoothService != null) { | |||||
if (AILinkBleManager.getInstance() != null) { | |||||
mDevice = BroadcastWeightScaleDeviceData.getInstance(); | mDevice = BroadcastWeightScaleDeviceData.getInstance(); | ||||
mDevice.setOnNotifyData(this); | mDevice.setOnNotifyData(this); | ||||
mBluetoothService.setOnScanFilterListener(this); | |||||
mBluetoothService.scanLeDevice(0, BleConfig.UUID_SERVER_BROADCAST_AILINK); | |||||
AILinkBleManager.getInstance().setOnBleBroadcastDataListener(this); | |||||
AILinkBleManager.getInstance().startScan(0, BleConfig.UUID_SERVER_BROADCAST_AILINK); | |||||
} | } | ||||
} | } | ||||
public void onServiceErr() { | public void onServiceErr() { | ||||
BleLog.i("ljl", "服务与界面连接断开"); | BleLog.i("ljl", "服务与界面连接断开"); | ||||
//与服务断开连接 | //与服务断开连接 | ||||
mBluetoothService = null; | |||||
AILinkBleManager.getInstance().setOnBleBroadcastDataListener(null); | |||||
} | } | ||||
@Override | @Override | ||||
mDevice.clear(); | mDevice.clear(); | ||||
mDevice = null; | mDevice = null; | ||||
} | } | ||||
} | } | ||||
//-----------------状态------------------- | //-----------------状态------------------- | ||||
return; | return; | ||||
} | } | ||||
mOldData = data; | mOldData = data; | ||||
mList.add(TimeUtils.getTime() + "数据ID" + type + " ,||解密数据:" + data + " ,||原始数据:" + BleStrUtils.byte2HexStr(dataOriginal)); | |||||
mList.add(TimeUtils.getTime() + "数据ID" + type + " ,||解密payload数据:" + data + " ,||原始厂商数据:" + BleStrUtils.byte2HexStr(dataOriginal)); | |||||
mHandler.sendEmptyMessage(REFRESH_DATA); | mHandler.sendEmptyMessage(REFRESH_DATA); | ||||
} | } | ||||
@Override | @Override | ||||
public boolean onFilter(BleValueBean bleValueBean) { | |||||
return true; | |||||
} | |||||
@Override | |||||
public void onScanRecord(BleValueBean bleValueBean) { | |||||
public void onBleBroadcastData(BleValueBean bleValueBean, byte[] payload) { | |||||
if (TextUtils.isEmpty(mAddress) && bleValueBean.isBroadcastModule()) { | if (TextUtils.isEmpty(mAddress) && bleValueBean.isBroadcastModule()) { | ||||
mAddress = bleValueBean.getMac(); | mAddress = bleValueBean.getMac(); | ||||
if (tv_broadcast_mac != null) { | if (tv_broadcast_mac != null) { | ||||
//地址相同,并且是广播秤 | //地址相同,并且是广播秤 | ||||
if (mAddress.equalsIgnoreCase(bleValueBean.getMac()) && bleValueBean.isBroadcastModule()) { | if (mAddress.equalsIgnoreCase(bleValueBean.getMac()) && bleValueBean.isBroadcastModule()) { | ||||
byte[] manufacturerData = bleValueBean.getManufacturerData(); | |||||
int cid = bleValueBean.getCid(); | int cid = bleValueBean.getCid(); | ||||
int vid = bleValueBean.getVid(); | int vid = bleValueBean.getVid(); | ||||
int pid = bleValueBean.getPid(); | int pid = bleValueBean.getPid(); | ||||
if (mDevice != null) { | if (mDevice != null) { | ||||
mDevice.onNotifyData(manufacturerData, cid, vid, pid); | |||||
mDevice.onNotifyData(bleValueBean.getManufacturerData(), cid, vid, pid); | |||||
} | } | ||||
} | } | ||||
} | } |
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.RadioButton; | import android.widget.RadioButton; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.bean.SupportUnitBean; | import com.pingwang.bluetoothlib.bean.SupportUnitBean; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.CoffeeScale.CoffeeScaleData; | import cn.net.aicare.modulelibrary.module.CoffeeScale.CoffeeScaleData; | ||||
public class CoffeeScaleActivity extends BleBaseActivity implements View.OnClickListener, CoffeeScaleData.CoffeeScaleCallback { | public class CoffeeScaleActivity extends BleBaseActivity implements View.OnClickListener, CoffeeScaleData.CoffeeScaleCallback { |
import android.widget.RadioButton; | import android.widget.RadioButton; | ||||
import android.widget.Spinner; | import android.widget.Spinner; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.FasciaGun.FasciaGunData; | import cn.net.aicare.modulelibrary.module.FasciaGun.FasciaGunData; | ||||
/** | /** |
import android.widget.Spinner; | import android.widget.Spinner; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | ||||
import com.pingwang.bluetoothlib.device.SendBleBean; | import com.pingwang.bluetoothlib.device.SendBleBean; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.FoodTemp.FoodTempData; | import cn.net.aicare.modulelibrary.module.FoodTemp.FoodTempData; | ||||
/** | /** |
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import com.pingwang.bluetoothlib.listener.OnScanFilterListener; | import com.pingwang.bluetoothlib.listener.OnScanFilterListener; | ||||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | import com.pingwang.bluetoothlib.utils.BleStrUtils; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.Nullable; | |||||
public class LeaOneBroadcastActivity extends BleBaseActivity implements View.OnClickListener, OnScanFilterListener { | public class LeaOneBroadcastActivity extends BleBaseActivity implements View.OnClickListener, OnScanFilterListener { | ||||
public void onClick(View v) { | public void onClick(View v) { | ||||
int id = v.getId(); | int id = v.getId(); | ||||
if (id == R.id.btn_start) { | if (id == R.id.btn_start) { | ||||
mBluetoothService.scanLeDevice(0); | |||||
mBluetoothService.startScan(0); | |||||
} else if (id == R.id.btn_stop) { | } else if (id == R.id.btn_stop) { | ||||
mBluetoothService.stopScan(); | mBluetoothService.stopScan(); | ||||
} else if (id == R.id.btn_clear) { | } else if (id == R.id.btn_clear) { |
package aicare.net.cn.sdk.ailinksdkdemoandroid.modules.meat_probe; | |||||
public class FoodConfig { | |||||
/** | |||||
* 摄氏度 | |||||
*/ | |||||
public static final int UNIT_C = 0; | |||||
/** | |||||
* 华氏度 | |||||
*/ | |||||
public static final int UNIT_F = 1; | |||||
/** | |||||
* 牛肉 | |||||
*/ | |||||
public static final int FOOD_TYPE_BEEF = 0; | |||||
/** | |||||
* 小牛肉 | |||||
*/ | |||||
public static final int FOOD_TYPE_VEAL = 1; | |||||
/** | |||||
* 羊肉 | |||||
*/ | |||||
public static final int FOOD_TYPE_LAMB = 2; | |||||
/** | |||||
* 猪肉 | |||||
*/ | |||||
public static final int FOOD_TYPE_PORK = 3; | |||||
/** | |||||
* 鸡肉 | |||||
*/ | |||||
public static final int FOOD_TYPE_CHICKEN = 4; | |||||
/** | |||||
* 火鸡肉 | |||||
*/ | |||||
public static final int FOOD_TYPE_TURKEY = 5; | |||||
/** | |||||
* 鱼肉 | |||||
*/ | |||||
public static final int FOOD_TYPE_FISH = 6; | |||||
/** | |||||
* 汉堡 | |||||
*/ | |||||
public static final int FOOD_TYPE_HAMBURGER = 7; | |||||
/** | |||||
* 其它 | |||||
*/ | |||||
public static final int FOOD_TYPE_OTHER = 8; | |||||
/** | |||||
* 食物类型未设置 | |||||
*/ | |||||
public static final int FOOD_TYPE_NO_SETTING = 9; | |||||
/** | |||||
* 食品成熟度 DIY | |||||
*/ | |||||
public static final int FOOD_DEGREE_DIY = 4; | |||||
/** | |||||
* 三分熟 | |||||
*/ | |||||
public static final int FOOD_DEGREE_MRATE = 0; | |||||
/** | |||||
* 五分熟 | |||||
*/ | |||||
public static final int FOOD_DEGREE_MEDIUM = 1; | |||||
/** | |||||
* 七分熟 | |||||
*/ | |||||
public static final int FOOD_DEGREE_MWELL = 2; | |||||
/** | |||||
* 全熟 | |||||
*/ | |||||
public static final int FOOD_DEGREE_WELL = 3; | |||||
/** | |||||
* 报警 铃声 | |||||
*/ | |||||
public static final int ALERT_TYPE_RING = 0; | |||||
/** | |||||
* 报警 震动 | |||||
*/ | |||||
public static final int ALERT_TYPE_SHOCK = 1; | |||||
/** | |||||
* 报警 铃声和震动 | |||||
*/ | |||||
public static final int ALERT_TYPE_RING_AND_SHOCK = 2; | |||||
/** | |||||
* 烧烤模式 烤炉 | |||||
*/ | |||||
public static final int FOOD_COOK_MODE_OVEN = 0; | |||||
/** | |||||
* 烧烤 | |||||
*/ | |||||
public static final int FOOD_COOK_MODE_BARBECUE = 1; | |||||
/** | |||||
* 正常状态 | |||||
*/ | |||||
public static final int BATTERY_STATE_NORMAL = 0; | |||||
/** | |||||
* 充电中 | |||||
*/ | |||||
public static final int BATTERY_STATE_CHARGING = 1; | |||||
/** | |||||
* 设备低电 | |||||
*/ | |||||
public static final int BATTERY_STATE_LOW = 2; | |||||
/** | |||||
* 设置温度单位 | |||||
*/ | |||||
public static final String BROADCAST_SET_TEMP_UNIT = "BROADCAST_SET_TEMP_UNIT"; | |||||
/** | |||||
* 温度为这个值就不处理,-16383为0xFFFF的前13个bit | |||||
*/ | |||||
public static final int DISABLE_TEMP = 0xFFFF; | |||||
/** | |||||
* 设备高温警告(摄氏度) | |||||
*/ | |||||
public static final int DEVICE_HIGH_TEMP_C = 85; | |||||
/** | |||||
* 设备高温警告(华氏度) | |||||
*/ | |||||
public static final int DEVICE_HIGH_TEMP_F = 185; | |||||
/** | |||||
* 设备超高温警告(摄氏度) | |||||
*/ | |||||
public static final int DEVICE_SUPER_HIGH_TEMP_C = 100; | |||||
/** | |||||
* 设备超高温警告(华氏度) | |||||
*/ | |||||
public static final int DEVICE_SUPER_HIGH_TEMP_F = 212; | |||||
} | |||||
package aicare.net.cn.sdk.ailinksdkdemoandroid.modules.meat_probe; | |||||
import android.os.Bundle; | |||||
import android.util.Log; | |||||
import android.view.View; | |||||
import android.widget.ArrayAdapter; | |||||
import android.widget.Button; | |||||
import android.widget.ListView; | |||||
import android.widget.TextView; | |||||
import android.widget.Toast; | |||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.device.BleDevice; | |||||
import com.pingwang.bluetoothlib.listener.CallbackDisIm; | |||||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | |||||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||||
import java.text.SimpleDateFormat; | |||||
import java.util.ArrayList; | |||||
import java.util.List; | |||||
import java.util.Locale; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | |||||
import cn.net.aicare.modulelibrary.module.meatprobe.MeatProbeBleData; | |||||
import cn.net.aicare.modulelibrary.module.meatprobe.MeatProbeSendCmdUtil; | |||||
import cn.net.aicare.modulelibrary.module.meatprobe.OnMeatProbeDataListener; | |||||
import cn.net.aicare.modulelibrary.module.meatprobe.ProbeBean; | |||||
import cn.net.aicare.modulelibrary.module.meatprobe.ProbeNowBean; | |||||
/** | |||||
* @author ljl | |||||
* on 2023/6/6 | |||||
*/ | |||||
public class MeatProbeActivity extends BleBaseActivity implements OnCallbackBle, OnMeatProbeDataListener, View.OnClickListener { | |||||
private Button btn_meat_probe_connect, btn_meat_probe_disconnect; | |||||
private Button btn_meat_probe_version, btn_meat_probe_battery; | |||||
private Button btn_meat_probe_switch_unit, btn_meat_probe_get_info; | |||||
private Button btn_meat_probe_start, btn_meat_probe_end; | |||||
private TextView tv_meat_probe_ambient, tv_meat_probe_internal, tv_meat_probe_target; | |||||
private TextView tv_meat_probe_battery, tv_meat_probe_version; | |||||
private TextView tv_meat_probe_ambient_unit, tv_meat_probe_internal_unit, tv_meat_probe_target_unit; | |||||
ListView list_view_meat_probe; | |||||
private List<String> mList; | |||||
private ArrayAdapter mListAdapter; | |||||
private String mMac; | |||||
private int mCid; | |||||
private int mVid; | |||||
private int mPid; | |||||
private BleDevice mBleDevice; | |||||
private MeatProbeBleData mMeatProbeBleData; | |||||
private long mCookingId; | |||||
private double percent = 0.8; | |||||
private int foodType = 0; | |||||
private int foodRawness = 2; | |||||
private int unit = 0; | |||||
private ProbeBean mProbeBean; | |||||
@Override | |||||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||||
super.onCreate(savedInstanceState); | |||||
setContentView(R.layout.activity_meat_probe); | |||||
initView(); | |||||
initData(); | |||||
} | |||||
/** | |||||
* 初始化控件 | |||||
*/ | |||||
private void initView() { | |||||
btn_meat_probe_connect = findViewById(R.id.btn_meat_probe_connect); | |||||
btn_meat_probe_disconnect = findViewById(R.id.btn_meat_probe_disconnect); | |||||
btn_meat_probe_version = findViewById(R.id.btn_meat_probe_version); | |||||
btn_meat_probe_battery = findViewById(R.id.btn_meat_probe_battery); | |||||
btn_meat_probe_switch_unit = findViewById(R.id.btn_meat_probe_switch_unit); | |||||
btn_meat_probe_get_info = findViewById(R.id.btn_meat_probe_get_info); | |||||
btn_meat_probe_start = findViewById(R.id.btn_meat_probe_start); | |||||
btn_meat_probe_end = findViewById(R.id.btn_meat_probe_end); | |||||
tv_meat_probe_ambient = findViewById(R.id.tv_meat_probe_ambient); | |||||
tv_meat_probe_internal = findViewById(R.id.tv_meat_probe_internal); | |||||
tv_meat_probe_battery = findViewById(R.id.tv_meat_probe_battery); | |||||
tv_meat_probe_version = findViewById(R.id.tv_meat_probe_version); | |||||
tv_meat_probe_target = findViewById(R.id.tv_meat_probe_target); | |||||
tv_meat_probe_ambient_unit = findViewById(R.id.tv_meat_probe_ambient_unit); | |||||
tv_meat_probe_internal_unit = findViewById(R.id.tv_meat_probe_internal_unit); | |||||
tv_meat_probe_target_unit = findViewById(R.id.tv_meat_probe_target_unit); | |||||
list_view_meat_probe = findViewById(R.id.list_view_meat_probe); | |||||
} | |||||
/** | |||||
* 初始化数据 | |||||
*/ | |||||
private void initData() { | |||||
if (getIntent() != null) { | |||||
mMac = getIntent().getStringExtra("mac"); | |||||
mCid = getIntent().getIntExtra("type", 0); | |||||
mVid = getIntent().getIntExtra("vid", 0); | |||||
mPid = getIntent().getIntExtra("pid", 0); | |||||
} | |||||
CallbackDisIm.getInstance().addListListener(this); | |||||
btn_meat_probe_connect.setOnClickListener(this); | |||||
btn_meat_probe_disconnect.setOnClickListener(this); | |||||
btn_meat_probe_version.setOnClickListener(this); | |||||
btn_meat_probe_battery.setOnClickListener(this); | |||||
btn_meat_probe_switch_unit.setOnClickListener(this); | |||||
btn_meat_probe_get_info.setOnClickListener(this); | |||||
btn_meat_probe_start.setOnClickListener(this); | |||||
btn_meat_probe_end.setOnClickListener(this); | |||||
mProbeBean = new ProbeBean(mMac); | |||||
mProbeBean.setAlarmTemperaturePercent(0.8); | |||||
mProbeBean.setFoodType(foodType); | |||||
mProbeBean.setFoodRawness(foodRawness); | |||||
mProbeBean.setTargetTemperature_C(65); | |||||
mProbeBean.setTargetTemperature_F(149); | |||||
mProbeBean.setAmbientMinTemperature_C(0); | |||||
mProbeBean.setAmbientMinTemperature_F(32); | |||||
mProbeBean.setAmbientMaxTemperature_C(100); | |||||
mProbeBean.setAmbientMaxTemperature_F(212); | |||||
mProbeBean.setTimerStart(0); | |||||
mProbeBean.setTimerEnd(0); | |||||
//初始化列表 | |||||
mList = new ArrayList<>(); | |||||
mListAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | |||||
list_view_meat_probe.setAdapter(mListAdapter); | |||||
} | |||||
/** | |||||
* 添加一条文本 | |||||
* | |||||
* @param text 文本 | |||||
*/ | |||||
private void addText(String text) { | |||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss", Locale.US); | |||||
mList.add(sdf.format(System.currentTimeMillis()) + ":\n" + text); | |||||
if (mListAdapter != null) { | |||||
mListAdapter.notifyDataSetChanged(); | |||||
} | |||||
if (list_view_meat_probe != null) { | |||||
list_view_meat_probe.smoothScrollToPosition(mList.size() - 1); | |||||
} | |||||
} | |||||
@Override | |||||
public void onServiceSuccess() { | |||||
if (mBluetoothService != null) { | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mMac); | |||||
MeatProbeBleData.init(bleDevice); | |||||
mMeatProbeBleData = MeatProbeBleData.getInstance(); | |||||
mMeatProbeBleData.addOnMeatProbeDataListener(this); | |||||
MeatProbeSendCmdUtil.getInstance().setListeners(this); | |||||
} | |||||
} | |||||
@Override | |||||
public void onServiceErr() { | |||||
} | |||||
@Override | |||||
public void unbindServices() { | |||||
if (mBluetoothService!=null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | |||||
@Override | |||||
public void onServicesDiscovered(String mac) { | |||||
//连接成功 | |||||
Log.e("ljl", "onServicesDiscovered: mac is " + mac); | |||||
if (mBluetoothService != null) { | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mMac); | |||||
MeatProbeBleData.init(bleDevice); | |||||
mMeatProbeBleData = MeatProbeBleData.getInstance(); | |||||
mMeatProbeBleData.addOnMeatProbeDataListener(this); | |||||
MeatProbeSendCmdUtil.getInstance().setListeners(this); | |||||
} | |||||
} | |||||
@Override | |||||
public void onDisConnected(String mac, int code) { | |||||
//断开连接 | |||||
Toast.makeText(this, "断开连接", Toast.LENGTH_SHORT).show(); | |||||
} | |||||
@Override | |||||
public void onClick(View v) { | |||||
switch (v.getId()) { | |||||
case R.id.btn_meat_probe_connect: | |||||
if (mBluetoothService != null) { | |||||
mBluetoothService.connectDevice(mMac); | |||||
} | |||||
break; | |||||
case R.id.btn_meat_probe_disconnect: | |||||
if (mBluetoothService != null) { | |||||
mBluetoothService.disconnect(mMac); | |||||
} | |||||
break; | |||||
case R.id.btn_meat_probe_version: | |||||
if (mMeatProbeBleData != null) { | |||||
mMeatProbeBleData.getVersionInfo(); | |||||
} | |||||
break; | |||||
case R.id.btn_meat_probe_battery: | |||||
if (mMeatProbeBleData != null) { | |||||
mMeatProbeBleData.getBattery(); | |||||
} | |||||
break; | |||||
case R.id.btn_meat_probe_switch_unit: | |||||
if (mMeatProbeBleData != null) { | |||||
//0-摄氏度 1-华氏度 | |||||
if (unit == 0) { | |||||
mMeatProbeBleData.sendSwitchUnit(1); | |||||
} else { | |||||
mMeatProbeBleData.sendSwitchUnit(0); | |||||
} | |||||
} | |||||
break; | |||||
case R.id.btn_meat_probe_get_info: | |||||
if (mMeatProbeBleData != null) { | |||||
mMeatProbeBleData.appGetDeviceInfo(); | |||||
} | |||||
break; | |||||
case R.id.btn_meat_probe_start: | |||||
if (mMeatProbeBleData != null) { | |||||
mProbeBean.setCookingId(System.currentTimeMillis()); | |||||
mProbeBean.setCurrentUnit(unit); | |||||
mMeatProbeBleData.appSetDeviceInfo(mProbeBean); | |||||
} | |||||
break; | |||||
case R.id.btn_meat_probe_end: | |||||
if (mMeatProbeBleData != null) { | |||||
mMeatProbeBleData.endWork(); | |||||
} | |||||
break; | |||||
default: | |||||
break; | |||||
} | |||||
} | |||||
@Override | |||||
protected void onDestroy() { | |||||
super.onDestroy(); | |||||
if (mBluetoothService != null) { | |||||
mBluetoothService.disconnect(mMac); | |||||
} | |||||
} | |||||
@Override | |||||
public void onBleNowData(String mac, ProbeNowBean probeNowBean) { | |||||
//当前单位取实时温度的单位 | |||||
unit = probeNowBean.getRealTimeUnit(); | |||||
//环境温度 | |||||
tv_meat_probe_ambient.setText("环境温度:" + (probeNowBean.getAmbientPositive() == 0 ? probeNowBean.getAmbientTemp() : -probeNowBean.getAmbientTemp())); | |||||
//食物温度 | |||||
tv_meat_probe_internal.setText("食物温度:" + (probeNowBean.getRealTimePositive() == 0 ? probeNowBean.getRealTimeTemp() : -probeNowBean.getRealTimeTemp())); | |||||
//环境温度单位 | |||||
tv_meat_probe_ambient_unit.setText("环境温度单位:" + (probeNowBean.getAmbientUnit() == 0 ? "0(℃)" : "1(℉)")); | |||||
//食物温度单位 | |||||
tv_meat_probe_internal_unit.setText("食物温度单位:" + (probeNowBean.getRealTimeUnit() == 0 ? "0(℃)" : "1(℉)")); | |||||
// addText("环境温度:" + (probeNowBean.getAmbientPositive() == 0 ? probeNowBean.getAmbientTemp() : -probeNowBean.getAmbientTemp()) + | |||||
// "食物温度:" + (probeNowBean.getRealTimePositive() == 0 ? probeNowBean.getRealTimeTemp() : -probeNowBean.getRealTimeTemp()) + | |||||
// "目标温度:" + (probeNowBean.getTargetPositive() == 0 ? probeNowBean.getTargetTemp() : -probeNowBean.getTargetTemp()) + | |||||
// "环境温度单位:" + (probeNowBean.getAmbientUnit() == 0 ? "0(℃)" : "1(℉)") + | |||||
// "食物温度单位:" + (probeNowBean.getRealTimeUnit() == 0 ? "0(℃)" : "1(℉)") + | |||||
// "目标温度单位:" + (probeNowBean.getTargetUnit() == 0 ? "0(℃)" : "1(℉)")); | |||||
} | |||||
@Override | |||||
public void onBatteryState(String mac, int status, int battery) { | |||||
Log.e("ljl", "onBatteryState: mac is " + mac + " status is " + status + " battery is " + battery); | |||||
//当前电量 | |||||
tv_meat_probe_battery.setText("当前电量:" + battery); | |||||
addText("当前电量:" + battery); | |||||
} | |||||
@Override | |||||
public void onMcuVersionInfo(String mac, String versionInfo) { | |||||
Log.e("ljl", "onMcuVersionInfo: mac is " + mac + " versionInfo is " + versionInfo); | |||||
//版本号 | |||||
tv_meat_probe_version.setText("模块版本号:" + versionInfo); | |||||
addText("模块版本号:" + versionInfo); | |||||
} | |||||
@Override | |||||
public void getDeviceInfo(String mac, ProbeBean probeBean) { | |||||
//目标温度 | |||||
tv_meat_probe_target.setText("目标温度:" + probeBean.getTargetTemperature_C()); | |||||
//目标温度单位 | |||||
tv_meat_probe_target_unit.setText("目标温度单位:" + (probeBean.getCurrentUnit() == 0 ? "0(℃)" : "1(℉)")); | |||||
} | |||||
@Override | |||||
public void getInfoFailed(String mac) { | |||||
Log.e("ljl", "getInfoFailed: mac is " + mac); | |||||
} | |||||
@Override | |||||
public void getInfoSuccess(String mac) { | |||||
Log.e("ljl", "getInfoSuccess: mac is " + mac); | |||||
} | |||||
@Override | |||||
public void onDataNotifyA7(String mac, byte[] dataA7) { | |||||
//接收到的A7 payload数据 | |||||
addText("接收的A7 payload[" + BleStrUtils.byte2HexStr(dataA7) + "]"); | |||||
} | |||||
@Override | |||||
public void onDataNotifyA6(String mac, byte[] dataA6) { | |||||
//接收到的A6 payload数据 | |||||
addText("接收的A6 payload[" + BleStrUtils.byte2HexStr(dataA6) + "]"); | |||||
} | |||||
@Override | |||||
public void onDataA6(byte[] dataA6) { | |||||
//发出的A6 payload数据 | |||||
addText("发送的A6 payload[" + BleStrUtils.byte2HexStr(dataA6) + "]"); | |||||
} | |||||
@Override | |||||
public void onDataA7(byte[] dataA7) { | |||||
//发出的A7 payload数据 | |||||
addText("发送的A7 payload[" + BleStrUtils.byte2HexStr(dataA7) + "]"); | |||||
} | |||||
} |
package aicare.net.cn.sdk.ailinksdkdemoandroid.modules.meat_probe_charger; | |||||
import android.os.Bundle; | |||||
import android.text.InputType; | |||||
import android.text.TextUtils; | |||||
import android.util.Log; | |||||
import android.view.View; | |||||
import android.widget.ArrayAdapter; | |||||
import android.widget.Button; | |||||
import android.widget.EditText; | |||||
import android.widget.ListView; | |||||
import android.widget.TextView; | |||||
import android.widget.Toast; | |||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.config.BleConfig; | |||||
import com.pingwang.bluetoothlib.device.BleDevice; | |||||
import java.text.SimpleDateFormat; | |||||
import java.util.ArrayList; | |||||
import java.util.List; | |||||
import java.util.Locale; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.DialogStringImageBean; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.ShowListDialogFragment; | |||||
import cn.net.aicare.modulelibrary.module.meatprobecharger.ChargerProbeBean; | |||||
import cn.net.aicare.modulelibrary.module.meatprobecharger.MeatProbeChargerBleDevice; | |||||
/** | |||||
* @auther ljl | |||||
* 食物探针充电盒ble | |||||
* on 2023/2/24 | |||||
*/ | |||||
public class MeatProbeChargerActivity extends BleBaseActivity implements View.OnClickListener, MeatProbeChargerBleDevice.OnMeatProbeChargerDataListener { | |||||
private String mMac; | |||||
private int mVid; | |||||
private BleDevice mBleDevice; | |||||
private ListView list_view; | |||||
private List<String> mList; | |||||
private ArrayAdapter mListAdapter; | |||||
private List<String> mMacList; | |||||
private List<DialogStringImageBean> mDialogMacList; | |||||
private MeatProbeChargerBleDevice mMeatProbeChargerBleDevice; | |||||
private Button btn_probe_version, btn_probe_sync_time, btn_probe_info, btn_probe_clear; | |||||
private Button btn_probe_set, btn_probe_get, btn_probe_unit, btn_probe_set_alarm; | |||||
private Button btn_probe_clear_alarm, btn_probe_set_hand; | |||||
private EditText et_probe_set_hand; | |||||
private TextView tv_version, tv_other; | |||||
private List<ChargerProbeBean> mChargerProbeBeanList; | |||||
@Override | |||||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||||
super.onCreate(savedInstanceState); | |||||
setContentView(R.layout.activity_meat_probe_charger); | |||||
initView(); | |||||
mMac = getIntent().getStringExtra("mac"); | |||||
mVid = getIntent().getIntExtra("vid", 0); | |||||
// 初始化列表 | |||||
mList = new ArrayList<>(); | |||||
mMacList = new ArrayList<>(); | |||||
// mMacList.add("44:33:22:11:10:10"); | |||||
// mMacList.add("44:33:22:11:10:09"); | |||||
// mMacList.add("44:33:22:11:10:08"); | |||||
// mMacList.add("44:33:22:11:10:07"); | |||||
mDialogMacList = new ArrayList<>(); | |||||
// mDialogMacList.add(new DialogStringImageBean("44:33:22:11:10:10", 0)); | |||||
// mDialogMacList.add(new DialogStringImageBean("44:33:22:11:10:09", 0)); | |||||
// mDialogMacList.add(new DialogStringImageBean("44:33:22:11:10:08", 0)); | |||||
// mDialogMacList.add(new DialogStringImageBean("44:33:22:11:10:07", 0)); | |||||
mListAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | |||||
list_view.setAdapter(mListAdapter); | |||||
} | |||||
private void initView() { | |||||
list_view = findViewById(R.id.list_view); | |||||
btn_probe_version = findViewById(R.id.btn_probe_version); | |||||
btn_probe_sync_time = findViewById(R.id.btn_probe_sync_time); | |||||
btn_probe_info = findViewById(R.id.btn_probe_info); | |||||
btn_probe_set = findViewById(R.id.btn_probe_set); | |||||
btn_probe_get = findViewById(R.id.btn_probe_get); | |||||
btn_probe_unit = findViewById(R.id.btn_probe_unit); | |||||
btn_probe_set_alarm = findViewById(R.id.btn_probe_set_alarm); | |||||
btn_probe_clear = findViewById(R.id.btn_probe_clear); | |||||
btn_probe_clear_alarm = findViewById(R.id.btn_probe_clear_alarm); | |||||
btn_probe_set_hand = findViewById(R.id.btn_probe_set_hand); | |||||
et_probe_set_hand = findViewById(R.id.et_probe_set_hand); | |||||
btn_probe_version.setOnClickListener(this); | |||||
btn_probe_sync_time.setOnClickListener(this); | |||||
btn_probe_info.setOnClickListener(this); | |||||
btn_probe_set.setOnClickListener(this); | |||||
btn_probe_get.setOnClickListener(this); | |||||
btn_probe_unit.setOnClickListener(this); | |||||
btn_probe_set_alarm.setOnClickListener(this); | |||||
btn_probe_clear.setOnClickListener(this); | |||||
btn_probe_clear_alarm.setOnClickListener(this); | |||||
btn_probe_set_hand.setOnClickListener(this); | |||||
tv_version = findViewById(R.id.tv_probe_version); | |||||
tv_other = findViewById(R.id.tv_probe_other); | |||||
et_probe_set_hand.setInputType(InputType.TYPE_CLASS_NUMBER); | |||||
} | |||||
@Override | |||||
public void onClick(View view) { | |||||
switch (view.getId()) { | |||||
case R.id.btn_probe_version: | |||||
//获取版本号 | |||||
mMeatProbeChargerBleDevice.getVersion(); | |||||
break; | |||||
case R.id.btn_probe_sync_time: | |||||
//同步时间 | |||||
mMeatProbeChargerBleDevice.appSyncTime(); | |||||
break; | |||||
case R.id.btn_probe_info: | |||||
//获取设备状态 | |||||
mMeatProbeChargerBleDevice.getDeviceInfo(); | |||||
break; | |||||
case R.id.btn_probe_set: | |||||
//设置探针参数,需要选择探针 | |||||
if (mDialogMacList.size() > 0) { | |||||
setProbeDataDialog(); | |||||
} else { | |||||
Toast.makeText(MeatProbeChargerActivity.this, "请确认充电盒当前是否有连接的探针,点击获取设备状态按钮试试", Toast.LENGTH_SHORT).show(); | |||||
} | |||||
break; | |||||
case R.id.btn_probe_get: | |||||
//获取探针参数,先判断是否有探针再选择探针获取数据,需要选择探针 | |||||
if (mDialogMacList.size() > 0) { | |||||
getProbeDataDialog(); | |||||
} else { | |||||
Toast.makeText(MeatProbeChargerActivity.this, "请确认充电盒当前是否有连接的探针,点击获取设备状态按钮试试", Toast.LENGTH_SHORT).show(); | |||||
} | |||||
break; | |||||
case R.id.btn_probe_clear: | |||||
//清除探针数据,需要选择探针 | |||||
if (mDialogMacList.size() > 0) { | |||||
clearProbeDataDialog(); | |||||
} else { | |||||
Toast.makeText(MeatProbeChargerActivity.this, "请确认充电盒当前是否有连接的探针,点击获取设备状态按钮试试", Toast.LENGTH_SHORT).show(); | |||||
} | |||||
break; | |||||
case R.id.btn_probe_unit: | |||||
//切换盒子单位 | |||||
if (("切换成℃").equals(btn_probe_unit.getText().toString())) { | |||||
btn_probe_unit.setText("切换成℉"); | |||||
mMeatProbeChargerBleDevice.switchUnit(true); | |||||
} else { | |||||
btn_probe_unit.setText("切换成℃"); | |||||
mMeatProbeChargerBleDevice.switchUnit(false); | |||||
} | |||||
break; | |||||
case R.id.btn_probe_set_alarm: | |||||
//发送报警设置,需要选择探针 | |||||
if (mDialogMacList.size() > 0) { | |||||
setAlarmDialog(); | |||||
} else { | |||||
Toast.makeText(MeatProbeChargerActivity.this, "请确认充电盒当前是否有连接的探针,点击获取设备状态按钮试试", Toast.LENGTH_SHORT).show(); | |||||
} | |||||
break; | |||||
case R.id.btn_probe_clear_alarm: | |||||
//清除报警设置,需要选择探针 | |||||
if (mDialogMacList.size() > 0) { | |||||
cancelDialog(); | |||||
} else { | |||||
Toast.makeText(MeatProbeChargerActivity.this, "请确认充电盒当前是否有连接的探针,点击获取设备状态按钮试试", Toast.LENGTH_SHORT).show(); | |||||
} | |||||
break; | |||||
case R.id.btn_probe_set_hand: | |||||
//发送握手命令进行握手 | |||||
if (!TextUtils.isEmpty(et_probe_set_hand.getText().toString())) { | |||||
String cidvidpid = et_probe_set_hand.getText().toString().replaceAll(",", ","); | |||||
if (cidvidpid.contains(",")) { | |||||
String[] split = cidvidpid.split(","); | |||||
int cid = 0, vid = 0, pid = 0; | |||||
cid = Integer.parseInt(split[0], 16); | |||||
if (split.length > 1) { | |||||
vid = Integer.parseInt(split[1], 16); | |||||
} | |||||
if (split.length > 2) { | |||||
pid = Integer.parseInt(split[2], 16); | |||||
} | |||||
BleConfig.setHandshakeStatus(mMac, true, cid, vid, pid); | |||||
} | |||||
} else { | |||||
Toast.makeText(MeatProbeChargerActivity.this, "请先输入CID,VID,PID", Toast.LENGTH_SHORT).show(); | |||||
} | |||||
break; | |||||
default: | |||||
break; | |||||
} | |||||
} | |||||
/** | |||||
* 取消报警 | |||||
*/ | |||||
private void cancelDialog() { | |||||
ShowListDialogFragment.newInstance().setTitle("选择探针").setCancel("取消", 0).setCancelBlank(true).setBackground(true).setBottom(false).setList(mDialogMacList) | |||||
.setOnDialogListener(new ShowListDialogFragment.onDialogListener() { | |||||
@Override | |||||
public void onItemListener(int position) { | |||||
Toast.makeText(MeatProbeChargerActivity.this, mDialogMacList.get(position).getName() + "设置该指令", Toast.LENGTH_SHORT).show(); | |||||
mMeatProbeChargerBleDevice.cancelAlarm(mDialogMacList.get(position).getName()); | |||||
} | |||||
}).show(getSupportFragmentManager()); | |||||
} | |||||
/** | |||||
* 发送报警设置 | |||||
*/ | |||||
private void setAlarmDialog() { | |||||
ShowListDialogFragment.newInstance().setTitle("选择探针").setCancel("取消", 0).setCancelBlank(true).setBackground(true).setBottom(false).setList(mDialogMacList) | |||||
.setOnDialogListener(new ShowListDialogFragment.onDialogListener() { | |||||
@Override | |||||
public void onItemListener(int position) { | |||||
Toast.makeText(MeatProbeChargerActivity.this, mDialogMacList.get(position).getName() + "设置该指令", Toast.LENGTH_SHORT).show(); | |||||
mMeatProbeChargerBleDevice.setAlarmInfo(mDialogMacList.get(position).getName(), true, true, true); | |||||
} | |||||
}).show(getSupportFragmentManager()); | |||||
} | |||||
/** | |||||
* 清除探针数据 | |||||
*/ | |||||
private void clearProbeDataDialog() { | |||||
ShowListDialogFragment.newInstance().setTitle("选择探针").setCancel("取消", 0).setCancelBlank(true).setBackground(true).setBottom(false).setList(mDialogMacList) | |||||
.setOnDialogListener(new ShowListDialogFragment.onDialogListener() { | |||||
@Override | |||||
public void onItemListener(int position) { | |||||
Toast.makeText(MeatProbeChargerActivity.this, mDialogMacList.get(position).getName() + "设置该指令", Toast.LENGTH_SHORT).show(); | |||||
mMeatProbeChargerBleDevice.setProbeData(0, mDialogMacList.get(position).getName()); | |||||
} | |||||
}).show(getSupportFragmentManager()); | |||||
} | |||||
/** | |||||
* 获取探针数据指令 | |||||
*/ | |||||
private void getProbeDataDialog() { | |||||
ShowListDialogFragment.newInstance().setTitle("选择探针").setCancel("取消", 0).setCancelBlank(true).setBackground(true).setBottom(false).setList(mDialogMacList) | |||||
.setOnDialogListener(new ShowListDialogFragment.onDialogListener() { | |||||
@Override | |||||
public void onItemListener(int position) { | |||||
Toast.makeText(MeatProbeChargerActivity.this, mDialogMacList.get(position).getName() + "设置该指令", Toast.LENGTH_SHORT).show(); | |||||
mMeatProbeChargerBleDevice.setProbeData(2, mDialogMacList.get(position).getName()); | |||||
} | |||||
}).show(getSupportFragmentManager()); | |||||
} | |||||
/** | |||||
* 设置探针数据 | |||||
*/ | |||||
private void setProbeDataDialog() { | |||||
ShowListDialogFragment.newInstance().setTitle("选择探针").setCancel("取消", 0).setCancelBlank(true).setBackground(true).setBottom(false).setList(mDialogMacList) | |||||
.setOnDialogListener(new ShowListDialogFragment.onDialogListener() { | |||||
@Override | |||||
public void onItemListener(int position) { | |||||
Toast.makeText(MeatProbeChargerActivity.this, mDialogMacList.get(position).getName() + "设置该指令", Toast.LENGTH_SHORT).show(); | |||||
mMeatProbeChargerBleDevice.setProbeData(mDialogMacList.get(position).getName(), 2, System.currentTimeMillis(), 0, 0, -15, 5, 0, 0, 0, 0, 0.8, 0, 0, 0, -15, 5); | |||||
} | |||||
}).show(getSupportFragmentManager()); | |||||
} | |||||
@Override | |||||
public void onServiceSuccess() { | |||||
mBleDevice = mBluetoothService.getBleDevice(mMac); | |||||
if (mBleDevice != null) { | |||||
if (mMeatProbeChargerBleDevice == null) { | |||||
Log.e("ljl", "onServiceSuccess: 绑定设备,设置监听"); | |||||
MeatProbeChargerBleDevice.init(mBleDevice); | |||||
mMeatProbeChargerBleDevice = MeatProbeChargerBleDevice.getInstance(); | |||||
mMeatProbeChargerBleDevice.setOnMeatProbeChargerDataListener(this); | |||||
if (btn_probe_version != null) { | |||||
btn_probe_version.postDelayed(new Runnable() { | |||||
@Override | |||||
public void run() { | |||||
mBleDevice.setMtu(247); | |||||
} | |||||
}, 200); | |||||
} | |||||
} | |||||
} | |||||
addText("连接成功,充电盒Mac地址为:" + mMac); | |||||
} | |||||
@Override | |||||
public void onServiceErr() { | |||||
} | |||||
@Override | |||||
public void unbindServices() { | |||||
} | |||||
/** | |||||
* 添加一条文本 | |||||
* | |||||
* @param text 文本 | |||||
*/ | |||||
private void addText(String text) { | |||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss", Locale.US); | |||||
mList.add(sdf.format(System.currentTimeMillis()) + ":\n" + text); | |||||
if (mListAdapter != null) { | |||||
mListAdapter.notifyDataSetChanged(); | |||||
} | |||||
if (list_view != null) { | |||||
list_view.smoothScrollToPosition(mList.size() - 1); | |||||
} | |||||
} | |||||
@Override | |||||
protected void onDestroy() { | |||||
if (mMeatProbeChargerBleDevice != null) { | |||||
mMeatProbeChargerBleDevice = null; | |||||
} | |||||
if (mBluetoothService != null) { | |||||
mBluetoothService.disconnectAll(); | |||||
} | |||||
super.onDestroy(); | |||||
} | |||||
@Override | |||||
public void setVersion() { | |||||
if (mMeatProbeChargerBleDevice != null) { | |||||
mMeatProbeChargerBleDevice.getVersion(); | |||||
} | |||||
} | |||||
/** | |||||
* 设置mtu成功后可以设置设备信息 | |||||
*/ | |||||
@Override | |||||
public void setDeviceInfo() { | |||||
} | |||||
@Override | |||||
public void onVersionInfo(String version) { | |||||
tv_version.setText("固件版本号:" + version); | |||||
} | |||||
@Override | |||||
public void appSyncTimeResult(int result) { | |||||
addText("同步时间状态码:" + result); | |||||
} | |||||
@Override | |||||
public void switchUnitResult(int result) { | |||||
addText("切换单位状态码:" + result); | |||||
} | |||||
@Override | |||||
public void setAlarmresult(String mac, int alarmResult) { | |||||
addText("设置警报->探针Mac地址" + mac + " 状态码:" + alarmResult); | |||||
} | |||||
@Override | |||||
public void cancelAlarmresult(String mac, int alarmResult) { | |||||
addText("取消警报->探针Mac地址" + mac + " 状态码:" + alarmResult); | |||||
} | |||||
private int index = 0; | |||||
@Override | |||||
public void onDeviceInfo(int supportNum, int currentNum, int chargerState, int battery, int boxUnit, List<ChargerProbeBean> chargerProbeBeanList) { | |||||
addText("设备支持探针数:" + supportNum + " 当前连接探针数:" + currentNum + " 充电状态:" + chargerState + " 电池电量:" + battery + " 充电盒单位:" + boxUnit); | |||||
if (mChargerProbeBeanList == null) { | |||||
mChargerProbeBeanList = new ArrayList<>(); | |||||
mChargerProbeBeanList.addAll(chargerProbeBeanList); | |||||
} else { | |||||
mChargerProbeBeanList.clear(); | |||||
mChargerProbeBeanList.addAll(chargerProbeBeanList); | |||||
} | |||||
if (mMacList.size() > 0) { | |||||
mMacList.clear(); | |||||
} | |||||
if (mDialogMacList.size() > 0) { | |||||
index = 0; | |||||
mDialogMacList.clear(); | |||||
} | |||||
for (ChargerProbeBean chargerProbeBean : chargerProbeBeanList) { | |||||
mMacList.add(chargerProbeBean.getMac()); | |||||
mDialogMacList.add(new DialogStringImageBean(chargerProbeBean.getMac(), ++index)); | |||||
addText("探针编号:" + chargerProbeBean.getNum() + " 探针mac地址:" + chargerProbeBean.getMac() + " 食物温度单位: " + chargerProbeBean.getFoodUnit() + " 正负: " + chargerProbeBean.getFoodPositive() + " " + "温度绝对值: " + chargerProbeBean.getFoodTemp() + " 环境温度单位: " + chargerProbeBean.getAmbientUnit() + " 正负: " + chargerProbeBean.getAmbientPositive() + " 温度绝对值: " + chargerProbeBean.getAmbientTemp() + " 探针充电状态:" + chargerProbeBean.getChargerState() + " 电量: " + chargerProbeBean.getBattery() + " 插入食物状态: " + chargerProbeBean.getInsertState()); | |||||
} | |||||
} | |||||
@Override | |||||
public void onNoDeviceInfo(int supportNum, int currentNum, int chargingState, int battery, int boxUnit) { | |||||
addText("设备支持探针数:" + supportNum + " 当前连接探针数:" + currentNum + " 充电状态:" + chargingState + " 电池电量:" + battery + " 充电盒单位:" + boxUnit); | |||||
} | |||||
@Override | |||||
public void onBatteryStatus(int status, int battery) { | |||||
if (btn_probe_version != null) { | |||||
btn_probe_version.postDelayed(new Runnable() { | |||||
@Override | |||||
public void run() { | |||||
if (mBleDevice != null) { | |||||
mBleDevice.setMtu(247); | |||||
} | |||||
} | |||||
}, 200); | |||||
} | |||||
} | |||||
@Override | |||||
public void onOtherData(String hexStr) { | |||||
//其他数据 | |||||
addText("其他数据:[" + hexStr + "]"); | |||||
} | |||||
@Override | |||||
public void onDataStrA6(String hexStrA6) { | |||||
addText("收到A6数据:[" + hexStrA6 + "]"); | |||||
} | |||||
@Override | |||||
public void onDataStrA7(String hexStrA7) { | |||||
addText("收到A7数据:[" + hexStrA7 + "]"); | |||||
} | |||||
@Override | |||||
public void sendDataA6(String hexStrA6) { | |||||
addText("发送A6数据:[" + hexStrA6 + "]"); | |||||
} | |||||
@Override | |||||
public void sendDataA7(String hexStrA7) { | |||||
addText("发送A7数据:[" + hexStrA7 + "]"); | |||||
} | |||||
@Override | |||||
public void onHand(boolean status) { | |||||
addText("握手" + (status ? "成功" : "失败")); | |||||
if (!status) { | |||||
Toast.makeText(MeatProbeChargerActivity.this, "握手失败,请退出界面重新搜索蓝牙连接设备", Toast.LENGTH_SHORT).show(); | |||||
} | |||||
} | |||||
} |
import android.widget.Button; | import android.widget.Button; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.NoiseMeter.NoiseMeterBleDevice; | import cn.net.aicare.modulelibrary.module.NoiseMeter.NoiseMeterBleDevice; | ||||
/** | /** |
import android.widget.ArrayAdapter; | import android.widget.ArrayAdapter; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.listener.OnBleOtherDataListener; | import com.pingwang.bluetoothlib.listener.OnBleOtherDataListener; | ||||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | import com.pingwang.bluetoothlib.utils.BleStrUtils; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.NoiseMeter.BleNoiseTLVBean; | import cn.net.aicare.modulelibrary.module.NoiseMeter.BleNoiseTLVBean; | ||||
import cn.net.aicare.modulelibrary.module.NoiseMeter.NoiseMeterHistoryBean; | import cn.net.aicare.modulelibrary.module.NoiseMeter.NoiseMeterHistoryBean; | ||||
import cn.net.aicare.modulelibrary.module.NoiseMeter.NoiseMeterWifiBleDevice; | import cn.net.aicare.modulelibrary.module.NoiseMeter.NoiseMeterWifiBleDevice; |
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||||
package aicare.net.cn.sdk.ailinksdkdemoandroid.modules.ropeskipping; | |||||
import android.os.Bundle; | import android.os.Bundle; | ||||
import android.view.View; | import android.view.View; | ||||
import android.widget.ArrayAdapter; | import android.widget.ArrayAdapter; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import androidx.annotation.Nullable; | |||||
import com.google.gson.Gson; | import com.google.gson.Gson; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | import com.pingwang.bluetoothlib.listener.OnCallbackBle; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.List; | import java.util.List; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.RopeSkipping.OnRopeSkipCallBack; | import cn.net.aicare.modulelibrary.module.RopeSkipping.OnRopeSkipCallBack; | ||||
import cn.net.aicare.modulelibrary.module.RopeSkipping.RopeSkipRecord; | import cn.net.aicare.modulelibrary.module.RopeSkipping.RopeSkipRecord; | ||||
import cn.net.aicare.modulelibrary.module.RopeSkipping.RopeSkippingBleData; | import cn.net.aicare.modulelibrary.module.RopeSkipping.RopeSkippingBleData; | ||||
@Override | @Override | ||||
public void onServiceSuccess() { | public void onServiceSuccess() { | ||||
mBluetoothService.setOnCallback(this); | |||||
logList.add("绑定服务成功"); | logList.add("绑定服务成功"); | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | ||||
if (bleDevice != null) { | if (bleDevice != null) { | ||||
RopeSkippingBleData.init(bleDevice); | RopeSkippingBleData.init(bleDevice); | ||||
if (mArrayAdapter != null && logList != null) { | if (mArrayAdapter != null && logList != null) { | ||||
refreshLog("解除绑定服务"); | refreshLog("解除绑定服务"); | ||||
} | } | ||||
if (mBluetoothService!=null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | } | ||||
} else if (v.getId() == R.id.btn_clear_log) { | } else if (v.getId() == R.id.btn_clear_log) { | ||||
if (!isPauseLog) { | if (!isPauseLog) { | ||||
isPauseLog = true; | isPauseLog = true; | ||||
}else { | |||||
} else { | |||||
isPauseLog = false; | isPauseLog = false; | ||||
} | } | ||||
@Override | @Override | ||||
public void onFinish(RopeSkipRecord ropeSkipBean) { | public void onFinish(RopeSkipRecord ropeSkipBean) { | ||||
refreshLog("跳绳结束"+"\n"+ropeSkipBean.toString() + " \n绊绳=" + new Gson().toJson(ropeSkipBean.getStopDetail())); | |||||
refreshLog("跳绳结束" + "\n" + ropeSkipBean.toString() + " \n绊绳=" + new Gson().toJson(ropeSkipBean.getStopDetail())); | |||||
} | } | ||||
@Override | @Override | ||||
} | } | ||||
private String mOldData = ""; | |||||
private int mId = 0; | |||||
@Override | @Override | ||||
public void onCurrentData(int status, int mode, int defaultValue, int currentJumpNum, int currentJumpTime, int batter) { | public void onCurrentData(int status, int mode, int defaultValue, int currentJumpNum, int currentJumpTime, int batter) { | ||||
refreshLog("实时数据 \n" + "状态: " + status + " ( 0:准备 1:进行中 2:完成) \n" + "模式: " | |||||
+ mode + " (1:自由 2:倒计时 3:倒计数) \n" | |||||
+ "默认值: " + defaultValue + " 电量 " + batter + "\n 当前个数: " + currentJumpNum + " 时间 " + currentJumpTime); | |||||
String data = "实时数据 \n" + "状态: " + status + " ( 0:准备 1:进行中 2:完成) \n" + "模式: " + mode + " (1:自由 2:倒计时 3:倒计数) \n" + "默认值: " + defaultValue + " 电量 " + batter + "\n 当前个数: " + currentJumpNum + | |||||
" 时间 " + currentJumpTime; | |||||
mId++; | |||||
if (mOldData.equals(data)) { | |||||
return; | |||||
} | |||||
mOldData = data; | |||||
refreshLog(mId+data); | |||||
} | } | ||||
@Override | @Override | ||||
refreshLog("没有离线记录"); | refreshLog("没有离线记录"); | ||||
} else { | } else { | ||||
refreshLog("离线记录:\n"+new Gson().toJson(list)); | |||||
refreshLog("离线记录:\n" + new Gson().toJson(list)); | |||||
} | } | ||||
} | } | ||||
@Override | @Override | ||||
public void finish() { | public void finish() { | ||||
super.finish(); | super.finish(); | ||||
if (mBluetoothService != null) | |||||
if (mBluetoothService != null){ | |||||
mBluetoothService.disconnectAll(); | mBluetoothService.disconnectAll(); | ||||
} | |||||
} | } | ||||
} | } |
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||||
package aicare.net.cn.sdk.ailinksdkdemoandroid.modules.ropeskipping; | |||||
import android.os.Bundle; | import android.os.Bundle; | ||||
import android.os.Handler; | import android.os.Handler; | ||||
import android.widget.EditText; | import android.widget.EditText; | ||||
import android.widget.ListView; | import android.widget.ListView; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import androidx.collection.ArraySet; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import com.pingwang.bluetoothlib.config.BleConfig; | import com.pingwang.bluetoothlib.config.BleConfig; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Set; | import java.util.Set; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import androidx.collection.ArraySet; | |||||
/** | /** | ||||
* 跳绳设置模式 | * 跳绳设置模式 | ||||
case 1: | case 1: | ||||
refreshLog("正在设置下一个..."); | refreshLog("正在设置下一个..."); | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.scanLeDevice(0, BleConfig.UUID_BROADCAST_AILINK); | |||||
mBluetoothService.startScan(0, BleConfig.UUID_BROADCAST_AILINK); | |||||
} | } | ||||
break; | break; | ||||
@Override | @Override | ||||
public void onServiceSuccess() { | public void onServiceSuccess() { | ||||
mBluetoothService.setOnCallback(this); | |||||
refreshLog("绑定服务成功"); | refreshLog("绑定服务成功"); | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
} | } | ||||
if (mArrayAdapter != null && logList != null) { | if (mArrayAdapter != null && logList != null) { | ||||
refreshLog("解除绑定服务"); | refreshLog("解除绑定服务"); | ||||
} | } | ||||
if (mBluetoothService!=null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | } | ||||
et_rssi.setEnabled(false); | et_rssi.setEnabled(false); | ||||
mSetMode = true; | mSetMode = true; | ||||
if (mBluetoothService != null) { | if (mBluetoothService != null) { | ||||
mBluetoothService.scanLeDevice(0, BleConfig.UUID_BROADCAST_AILINK); | |||||
mBluetoothService.startScan(0, BleConfig.UUID_BROADCAST_AILINK); | |||||
} | } | ||||
} else if (v.getId() == R.id.btn_start_read) { | } else if (v.getId() == R.id.btn_start_read) { | ||||
//开始读取 | //开始读取 | ||||
private void refreshLog(String content) { | private void refreshLog(String content) { | ||||
if (!isPauseLog) { | if (!isPauseLog) { | ||||
content= TimeUtils.getTime(System.currentTimeMillis())+content; | |||||
content=TimeUtils.getTime(System.currentTimeMillis())+content; | |||||
logList.add( content); | logList.add( content); | ||||
mArrayAdapter.notifyDataSetChanged(); | mArrayAdapter.notifyDataSetChanged(); | ||||
} | } | ||||
} | } | ||||
@Override | @Override | ||||
public void onNotifyData(byte[] hex, int type) { | |||||
public void onNotifyData(String uuid, byte[] hex, int type) { | |||||
if (type == 0x002F) { | if (type == 0x002F) { | ||||
if ((hex[0] & 0xFF) == 0x40) { | if ((hex[0] & 0xFF) == 0x40) { | ||||
@Override | @Override | ||||
public void finish() { | public void finish() { | ||||
super.finish(); | super.finish(); | ||||
if (mBluetoothService != null) | |||||
if (mBluetoothService!=null) { | |||||
mBluetoothService.disconnectAll(); | mBluetoothService.disconnectAll(); | ||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | } | ||||
} | } |
import android.widget.SeekBar; | import android.widget.SeekBar; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.ShareCharger.ShareChargerData; | import cn.net.aicare.modulelibrary.module.ShareCharger.ShareChargerData; | ||||
public class ShareChargerActivity extends BleBaseActivity implements View.OnClickListener, ShareChargerData.ShareChargerCallback { | public class ShareChargerActivity extends BleBaseActivity implements View.OnClickListener, ShareChargerData.ShareChargerCallback { |
import android.widget.SeekBar; | import android.widget.SeekBar; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.ShareCondom.ShareCondomData; | import cn.net.aicare.modulelibrary.module.ShareCondom.ShareCondomData; | ||||
public class ShareCondomActivity extends BleBaseActivity implements View.OnClickListener, ShareCondomData.ShareCondomCallback { | public class ShareCondomActivity extends BleBaseActivity implements View.OnClickListener, ShareCondomData.ShareCondomCallback { |
import android.widget.Spinner; | import android.widget.Spinner; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | import com.pingwang.bluetoothlib.listener.OnCallbackBle; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.ShareSocket.ShareSocketData; | import cn.net.aicare.modulelibrary.module.ShareSocket.ShareSocketData; | ||||
public class ShareSocketActivity extends BleBaseActivity implements View.OnClickListener, ShareSocketData.ShareSocketCallback, OnCallbackBle, OnScanFilterListener { | public class ShareSocketActivity extends BleBaseActivity implements View.OnClickListener, ShareSocketData.ShareSocketCallback, OnCallbackBle, OnScanFilterListener { | ||||
case MSG_TEST_START_SCAN: | case MSG_TEST_START_SCAN: | ||||
// 开始扫描设备 | // 开始扫描设备 | ||||
addText("准备重连,开始扫描设备:" + mMac); | addText("准备重连,开始扫描设备:" + mMac); | ||||
mBluetoothService.scanLeDevice(0); | |||||
mBluetoothService.startScan(0); | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
@Override | @Override | ||||
public void onServiceSuccess() { | public void onServiceSuccess() { | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
mBluetoothService.setOnScanFilterListener(this); | mBluetoothService.setOnScanFilterListener(this); | ||||
mBleDevice = mBluetoothService.getBleDevice(mMac); | mBleDevice = mBluetoothService.getBleDevice(mMac); | ||||
if (mBleDevice != null) { | if (mBleDevice != null) { | ||||
@Override | @Override | ||||
public void unbindServices() { | public void unbindServices() { | ||||
if (mBluetoothService!=null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
} | |||||
} | } | ||||
@Override | @Override |
import android.widget.ListView; | import android.widget.ListView; | ||||
import android.widget.Toast; | import android.widget.Toast; | ||||
import androidx.annotation.Nullable; | |||||
import com.elinkthings.bleotalibrary.listener.OnBleOTAListener; | import com.elinkthings.bleotalibrary.listener.OnBleOTAListener; | ||||
import com.elinkthings.bleotalibrary.netstrap.OPLOtaManager; | import com.elinkthings.bleotalibrary.netstrap.OPLOtaManager; | ||||
import com.pingwang.bluetoothlib.bean.BleValueBean; | import com.pingwang.bluetoothlib.bean.BleValueBean; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.WifiDialog; | import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.WifiDialog; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.L; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.L; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.ToothBrushUtils; | import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.ToothBrushUtils; | ||||
import androidx.annotation.Nullable; | |||||
import cn.net.aicare.modulelibrary.module.ToothBrush.ToothBrushBleCmd; | import cn.net.aicare.modulelibrary.module.ToothBrush.ToothBrushBleCmd; | ||||
import cn.net.aicare.modulelibrary.module.ToothBrush.ToothBrushWiFiBleUtilsData; | import cn.net.aicare.modulelibrary.module.ToothBrush.ToothBrushWiFiBleUtilsData; | ||||
/** | /** | ||||
* Wifi+ble 牙刷 | * Wifi+ble 牙刷 | ||||
*/ | */ | ||||
public class ToothBrushWifiBleActivity extends BleBaseActivity implements View.OnClickListener, OnCallbackBle, ToothBrushWiFiBleUtilsData.BleToothBrushWiFiCallback, | |||||
ToothBrushWiFiBleUtilsData.BleToothBrushCallback { | |||||
public class ToothBrushWifiBleActivity extends BleBaseActivity implements View.OnClickListener, OnCallbackBle, ToothBrushWiFiBleUtilsData.BleToothBrushWiFiCallback, ToothBrushWiFiBleUtilsData.BleToothBrushCallback { | |||||
private String TAG = ToothBrushWifiBleActivity.class.getName(); | private String TAG = ToothBrushWifiBleActivity.class.getName(); | ||||
private String mAddress; | private String mAddress; | ||||
private List<String> mList; | private List<String> mList; | ||||
//与服务建立连接 | //与服务建立连接 | ||||
mList.add(0, "服务与界面建立连接成功"); | mList.add(0, "服务与界面建立连接成功"); | ||||
// mList.add(0, "搜索设备"); | |||||
// mList.add(0, "搜索设备"); | |||||
mMHandler.sendEmptyMessage(ToRefreUi); | mMHandler.sendEmptyMessage(ToRefreUi); | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.scanLeDevice(30 * 1000); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
mBluetoothService.startScan(30 * 1000); | |||||
} | } | ||||
@Override | @Override | ||||
public void unbindServices() { | public void unbindServices() { | ||||
if (mBluetoothService!=null) { | |||||
if (mBluetoothService != null) { | |||||
mBluetoothService.removeOnCallbackBle(this); | |||||
mBluetoothService.disconnectAll(); | mBluetoothService.disconnectAll(); | ||||
} | } | ||||
} | } | ||||
public void onScanning(BleValueBean data) { | public void onScanning(BleValueBean data) { | ||||
BleLog.i(TAG, "MAC=" + mAddress + "||CID=" + data.getCid() + "||VID=" + data.getVid() + "||PID=" + data.getPid()); | BleLog.i(TAG, "MAC=" + mAddress + "||CID=" + data.getCid() + "||VID=" + data.getVid() + "||PID=" + data.getPid()); | ||||
if (data.getMac().equalsIgnoreCase(mAddress)) { | if (data.getMac().equalsIgnoreCase(mAddress)) { | ||||
if (mBluetoothService!=null) { | |||||
if (mBluetoothService != null) { | |||||
mBluetoothService.stopScan(); | mBluetoothService.stopScan(); | ||||
mBluetoothService.connectDevice(data.getMac()); | mBluetoothService.connectDevice(data.getMac()); | ||||
} | } | ||||
public void onServicesDiscovered(String mac) { | public void onServicesDiscovered(String mac) { | ||||
mList.add(0, "蓝牙已连接"); | mList.add(0, "蓝牙已连接"); | ||||
mMHandler.sendEmptyMessage(ToRefreUi); | mMHandler.sendEmptyMessage(ToRefreUi); | ||||
mBluetoothService.setOnCallback(this); | |||||
mBluetoothService.setOnCallbackBle(this); | |||||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | ||||
if (bleDevice != null) { | if (bleDevice != null) { | ||||
ToothBrushWiFiBleUtilsData.init(bleDevice, this, this); | ToothBrushWiFiBleUtilsData.init(bleDevice, this, this); | ||||
case R.id.ota: | case R.id.ota: | ||||
showFileChooser(); | showFileChooser(); | ||||
// mToothBrushWiFiBleUtilsData.setOta(); | |||||
// mToothBrushWiFiBleUtilsData.setOta(); | |||||
break; | break; | ||||
import android.os.Looper; | import android.os.Looper; | ||||
import android.os.Message; | import android.os.Message; | ||||
import android.text.TextUtils; | import android.text.TextUtils; | ||||
import android.widget.Button; | |||||
import android.widget.TextView; | |||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import androidx.recyclerview.widget.LinearLayoutManager; | |||||
import androidx.recyclerview.widget.RecyclerView; | |||||
import com.pingwang.bluetoothlib.device.BleDevice; | import com.pingwang.bluetoothlib.device.BleDevice; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.BleBaseActivity; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import androidx.recyclerview.widget.LinearLayoutManager; | |||||
import androidx.recyclerview.widget.RecyclerView; | |||||
import cn.net.aicare.modulelibrary.module.BleToothbrush.ToothbrushTestData; | import cn.net.aicare.modulelibrary.module.BleToothbrush.ToothbrushTestData; | ||||
import cn.net.aicare.modulelibrary.module.ToothBrush.ToothBrushBleUtilsData; | |||||
public class ToothbrushTestActivity extends BleBaseActivity implements ToothbrushTestData.BleToothbrushCallback, ToothbrushTestAdapter.OnSelectListener { | public class ToothbrushTestActivity extends BleBaseActivity implements ToothbrushTestData.BleToothbrushCallback, ToothbrushTestAdapter.OnSelectListener { | ||||
private static final int MSG_NEXT = 101;// 下一步 | private static final int MSG_NEXT = 101;// 下一步 | ||||
private RecyclerView recycler_view; | private RecyclerView recycler_view; | ||||
private Button btn_toothbrush_prevent_splash, btn_toothbrush_prevent_splash_test; | |||||
private TextView tv_toothbrush_status; | |||||
private List<ToothbrushTestBean> mList; | private List<ToothbrushTestBean> mList; | ||||
private ToothbrushTestAdapter mAdapter; | private ToothbrushTestAdapter mAdapter; | ||||
private String mMac; | private String mMac; | ||||
private BleDevice mBleDevice; | private BleDevice mBleDevice; | ||||
private ToothbrushTestData mToothbrushTestData; | private ToothbrushTestData mToothbrushTestData; | ||||
private ToothBrushBleUtilsData mToothBrushBleUtilsData; | |||||
private int mStep;// 当前正在进行哪个步骤 | private int mStep;// 当前正在进行哪个步骤 | ||||
private int mSupportMode;// 支持的模式 | private int mSupportMode;// 支持的模式 | ||||
/** | /** | ||||
* 添加测试项标题 | * 添加测试项标题 | ||||
* | |||||
* @param type 1:自动测试;2:手动测试 | * @param type 1:自动测试;2:手动测试 | ||||
*/ | */ | ||||
private void addTestTitle(int type) { | private void addTestTitle(int type) { | ||||
* @param str str | * @param str str | ||||
*/ | */ | ||||
private void showNgDialog(String str) { | private void showNgDialog(String str) { | ||||
new AlertDialog.Builder(this) | |||||
.setTitle("请按照协议回复:") | |||||
.setMessage("\n" + str) | |||||
.setPositiveButton("确认", null) | |||||
.show(); | |||||
new AlertDialog.Builder(this).setTitle("请按照协议回复:").setMessage("\n" + str).setPositiveButton("确认", null).show(); | |||||
} | } | ||||
} | } |
import android.view.ViewGroup; | import android.view.ViewGroup; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import java.util.List; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||
import androidx.core.content.ContextCompat; | import androidx.core.content.ContextCompat; | ||||
import androidx.recyclerview.widget.RecyclerView; | import androidx.recyclerview.widget.RecyclerView; | ||||
import java.util.List; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||||
public class ToothbrushTestAdapter extends RecyclerView.Adapter<ToothbrushTestAdapter.ViewHolder> { | public class ToothbrushTestAdapter extends RecyclerView.Adapter<ToothbrushTestAdapter.ViewHolder> { | ||||
private Context mContext; | private Context mContext; |
public static float[] LbToSt(float lbSize) { | public static float[] LbToSt(float lbSize) { | ||||
float[] lbFloatS = new float[2]; | float[] lbFloatS = new float[2]; | ||||
int st = (int) lbSize / 14; | int st = (int) lbSize / 14; | ||||
float lb = lbSize % 14f; | |||||
String str = String.valueOf(lbSize); | |||||
float lb = (float) (Double.parseDouble(str) - (st * 14)); | |||||
lbFloatS[0] = st; | lbFloatS[0] = st; | ||||
lbFloatS[1] = lb; | lbFloatS[1] = lb; | ||||
return lbFloatS; | return lbFloatS; | ||||
@Override | @Override | ||||
public void onSupportUnit(List<SupportUnitBean> list) { | public void onSupportUnit(List<SupportUnitBean> list) { | ||||
//支持的单位列表 | |||||
for (SupportUnitBean supportUnitBean : list) { | |||||
addText("支持的单位列表:[" + supportUnitBean.toString() + "]"); | |||||
} | |||||
} | } | ||||
addText("版本号:" + version); | addText("版本号:" + version); | ||||
} | } | ||||
/** | |||||
* 请求同步时间 | |||||
* | |||||
* @param quest 1-请求同步时间 | |||||
*/ | |||||
// @Override | |||||
// public void onSyncTime(int quest) { | |||||
// if (quest == 1) { | |||||
// if (mWeightScaleDevice != null) { | |||||
// mWeightScaleDevice.appSyncTime(); | |||||
// } | |||||
// } | |||||
// } | |||||
@Override | @Override | ||||
public void onBattery(int status, int battery) { | public void onBattery(int status, int battery) { |
package aicare.net.cn.sdk.ailinksdkdemoandroid.utils; | |||||
import android.text.TextUtils; | |||||
import java.text.DecimalFormat; | |||||
import java.util.Locale; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.config.UserUnitConfig; | |||||
/** | |||||
* 总的单位换算工具类 | |||||
*/ | |||||
public class AllUnitUtils { | |||||
public final static String LB_SPLIT = ":"; | |||||
public final static String NO_DATA = "-1"; | |||||
public final static String INCH_SPLIT_ONE = "′"; | |||||
public final static String INCH_SPLIT_ONE_1 = "'"; | |||||
public final static String INCH_SPLIT_TWO = "″"; | |||||
public final static String INCH_SPLIT_TWO_1 = "\""; | |||||
public static String getHeightToUnit(int unit, int newUnit, String data, int decimal) { | |||||
String height = ""; | |||||
if (TextUtils.isEmpty(data) || NO_DATA.equalsIgnoreCase(data)) { | |||||
return NO_DATA; | |||||
} | |||||
if (unit == newUnit) { | |||||
height = data; | |||||
} | |||||
switch (newUnit) { | |||||
case UserUnitConfig.USER_UNIT_CM: | |||||
height = getHeightToCm(unit, data, decimal); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_FEET: | |||||
height = getHeightToFeetFeet(unit, data, decimal); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_INCH: | |||||
height = getHeightToInch(unit, data, decimal); | |||||
break; | |||||
} | |||||
return height; | |||||
} | |||||
public static String getHeightToFeetFeet(int unit, String data, int decimal) { | |||||
String height = ""; | |||||
float inch; | |||||
float cm; | |||||
if (TextUtils.isEmpty(data) || NO_DATA.equalsIgnoreCase(data)) { | |||||
return NO_DATA; | |||||
} | |||||
if (unit == UserUnitConfig.USER_UNIT_FEET) {//单位相同直接返回 | |||||
height = data; | |||||
} | |||||
switch (unit) { | |||||
case UserUnitConfig.USER_UNIT_CM: | |||||
inch = UnitUtils.cmToInch(Float.parseFloat(data)); | |||||
height = getHeightInchToFeet(inch, decimal); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_INCH: | |||||
height = getHeightInchToFeet(Float.parseFloat(data), decimal); | |||||
break; | |||||
} | |||||
return height; | |||||
} | |||||
private static String getHeightInchToFeet(float heightStr, int decimal) { | |||||
String inch; | |||||
float[] feetS = UnitUtils.inchToFeet(heightStr); | |||||
String decimalStr = "%." + decimal + "f"; | |||||
inch = String.format(Locale.US, decimalStr, feetS[1]); | |||||
return ((int) feetS[0]) + INCH_SPLIT_ONE + inch + INCH_SPLIT_TWO; | |||||
} | |||||
/** | |||||
* 服务器返回(数据库读取) | |||||
* | |||||
* @param unit 当前的单位 | |||||
* @param data 数据 | |||||
* @param decimal 小数位 | |||||
* @return 返回指定单位显示 | |||||
*/ | |||||
public static String getHeightToCm(int unit, String data, int decimal) { | |||||
double height = -1.0; | |||||
float inch; | |||||
if (TextUtils.isEmpty(data) || NO_DATA.equalsIgnoreCase(data)) { | |||||
return NO_DATA; | |||||
} | |||||
if (unit == UserUnitConfig.USER_UNIT_CM) {//单位相同直接返回 | |||||
height = Float.parseFloat(data); | |||||
} | |||||
switch (unit) { | |||||
case UserUnitConfig.USER_UNIT_INCH: | |||||
if (data.contains(INCH_SPLIT_ONE)) { | |||||
return NO_DATA; | |||||
} | |||||
height = UnitUtils.inchToCm(Float.parseFloat(data)); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_FEET: | |||||
inch = getHeightFeetToInch(data); | |||||
height = UnitUtils.inchToCm(inch); | |||||
break; | |||||
} | |||||
return getHoldDecimal(decimal, (float) height); | |||||
} | |||||
/** | |||||
* 服务器返回(数据库读取) | |||||
* | |||||
* @param unit 当前的单位 | |||||
* @param data 数据 | |||||
* @param decimal 小数位 | |||||
* @return 返回指定单位显示 | |||||
*/ | |||||
public static String getHeightToInch(int unit, String data, int decimal) { | |||||
float height = -1f; | |||||
float inch; | |||||
if (TextUtils.isEmpty(data) || NO_DATA.equalsIgnoreCase(data)) { | |||||
return NO_DATA; | |||||
} | |||||
if (unit == UserUnitConfig.USER_UNIT_INCH) {//单位相同直接返回 | |||||
height = Float.parseFloat(data); | |||||
} | |||||
switch (unit) { | |||||
case UserUnitConfig.USER_UNIT_CM: | |||||
height = UnitUtils.cmToInch(Float.parseFloat(data)); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_FEET: | |||||
height = getHeightFeetToInch(data); | |||||
break; | |||||
} | |||||
return getHoldDecimal(decimal, height); | |||||
} | |||||
/** | |||||
* Feet:Inch转Inch | |||||
*/ | |||||
private static float getHeightFeetToInch(String feetStr) { | |||||
float feet = 0; | |||||
float inch = 0; | |||||
if (feetStr.contains(INCH_SPLIT_ONE) && feetStr.contains(INCH_SPLIT_TWO)) { | |||||
String[] strings = feetStr.split(INCH_SPLIT_ONE); | |||||
feet = Float.parseFloat(strings[0]); | |||||
inch = Float.parseFloat(strings[1].substring(0, strings[1].length() - 1)); | |||||
} else if (feetStr.contains(INCH_SPLIT_ONE_1) && feetStr.contains(INCH_SPLIT_TWO_1)) { | |||||
String[] strings = feetStr.split(INCH_SPLIT_ONE_1); | |||||
feet = Float.parseFloat(strings[0]); | |||||
inch = Float.parseFloat(strings[1].substring(0, strings[1].length() - 1)); | |||||
} | |||||
return UnitUtils.feetToInch(feet) + inch; | |||||
} | |||||
/** | |||||
* 服务器返回(数据库读取) | |||||
* | |||||
* @param unit 当前的单位 | |||||
* @param data 数据 | |||||
* @param decimal 小数位 | |||||
* @return 返回指定单位显示 | |||||
*/ | |||||
public static String getWeightToKg(int unit, String data, int decimal) { | |||||
float weight = -1f; | |||||
float g; | |||||
float oz; | |||||
if (TextUtils.isEmpty(data) || NO_DATA.equalsIgnoreCase(data)) { | |||||
return NO_DATA; | |||||
} | |||||
if (unit == UserUnitConfig.USER_UNIT_KG) {//单位相同直接返回 | |||||
weight = Float.parseFloat(String.format(Locale.US, data)); | |||||
} | |||||
switch (unit) { | |||||
case UserUnitConfig.USER_UNIT_FG: | |||||
weight = UnitUtils.fgToKG(Float.parseFloat(data)); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_OZ: | |||||
g = UnitUtils.ozToG(Float.parseFloat(data)); | |||||
weight = UnitUtils.gToKG(g); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_LB: | |||||
oz = getWeightLbToOz(data); | |||||
g = UnitUtils.ozToG(oz); | |||||
weight = UnitUtils.gToKG(g); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_G: | |||||
weight = UnitUtils.gToKG(Float.parseFloat(data)); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_LB_LB: | |||||
oz = UnitUtils.lbToOz(Float.parseFloat(data)); | |||||
g = UnitUtils.ozToG(oz); | |||||
weight = UnitUtils.gToKG(g); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_ST: | |||||
String[] weightStlb = null; | |||||
if (data.contains(":")) weightStlb = data.split(":"); | |||||
if (weightStlb != null && weightStlb.length >= 2) { | |||||
oz = UnitUtils.lbToOz(UnitUtils.stToLb(Float.parseFloat(weightStlb[0])) + Float.parseFloat(weightStlb[1])); | |||||
g = UnitUtils.ozToG(oz); | |||||
weight = UnitUtils.gToKG(g); | |||||
} | |||||
break; | |||||
} | |||||
return getHoldDecimal(decimal, weight); | |||||
} | |||||
public static String getWeightToFg(int unit, String data, int decimal) { | |||||
float weight = -1f; | |||||
float g; | |||||
float oz; | |||||
if (TextUtils.isEmpty(data) || NO_DATA.equalsIgnoreCase(data)) { | |||||
return NO_DATA; | |||||
} | |||||
if (unit == UserUnitConfig.USER_UNIT_FG) {//单位相同直接返回 | |||||
weight = Float.parseFloat(data); | |||||
} | |||||
switch (unit) { | |||||
case UserUnitConfig.USER_UNIT_KG: | |||||
weight = UnitUtils.gToFG(UnitUtils.kgToG(Float.parseFloat(data))); | |||||
// KgTo(Float.valueOf(data)); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_OZ: | |||||
g = UnitUtils.ozToG(Float.parseFloat(data)); | |||||
weight = UnitUtils.gToFG(g); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_LB: | |||||
oz = getWeightLbToOz(data); | |||||
g = UnitUtils.ozToG(oz); | |||||
weight = UnitUtils.gToFG(g); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_G: | |||||
weight = UnitUtils.gToFG(Float.parseFloat(data)); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_LB_LB: | |||||
oz = UnitUtils.lbToOz(Float.parseFloat(data)); | |||||
g = UnitUtils.ozToG(oz); | |||||
weight = UnitUtils.gToFG(g); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_ST: | |||||
String[] weightStlb = null; | |||||
if (data.contains(":")) weightStlb = data.split(":"); | |||||
if (weightStlb != null && weightStlb.length >= 2) { | |||||
oz = UnitUtils.lbToOz(UnitUtils.stToLb(Float.parseFloat(weightStlb[0])) + Float.parseFloat(weightStlb[1])); | |||||
g = UnitUtils.ozToG(oz); | |||||
weight = UnitUtils.gToFG(g); | |||||
} | |||||
break; | |||||
} | |||||
return getHoldDecimal(decimal, weight); | |||||
} | |||||
/** | |||||
* lb:oz转Oz | |||||
*/ | |||||
private static float getWeightLbToOz(String lbStr) { | |||||
float lb = 0; | |||||
float oz = 0; | |||||
if (lbStr.contains(LB_SPLIT)) { | |||||
String[] lbOzS = lbStr.split(LB_SPLIT); | |||||
lb = Float.parseFloat(lbOzS[0]); | |||||
oz = Float.parseFloat(lbOzS[1]); | |||||
} else { | |||||
lb = Float.parseFloat(lbStr); | |||||
} | |||||
float ozSize = UnitUtils.lbToOz(lb) + oz; | |||||
return ozSize; | |||||
} | |||||
public static int getWeightToG(int unit, String data, int decimal) { | |||||
int weightg = 0; | |||||
try { | |||||
weightg = (int) (Float.parseFloat(getWeightToKg(unit, data, decimal).trim()) * 1000); | |||||
} catch (Exception e) { | |||||
e.printStackTrace(); | |||||
} | |||||
return weightg; | |||||
} | |||||
public static String getWeightToUnit(int unit, int newUnit, String data, int decimal) { | |||||
String weight = ""; | |||||
if (TextUtils.isEmpty(data) || NO_DATA.equalsIgnoreCase(data)) { | |||||
return NO_DATA; | |||||
} | |||||
if (unit == newUnit) { | |||||
weight = data; | |||||
} | |||||
switch (newUnit) { | |||||
case UserUnitConfig.USER_UNIT_KG: | |||||
weight = getWeightToKg(unit, data, decimal); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_LB_LB: | |||||
weight = getWeightToLbLb(unit, data, decimal); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_ST: | |||||
weight = getWeightToStLb(unit, data, decimal); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_FG: | |||||
weight = getWeightToFg(unit, data, decimal); | |||||
break; | |||||
} | |||||
return weight; | |||||
} | |||||
public static String getWeightKgToOther(int goalUnit, String data, int decimal) { | |||||
return getWeightToUnit(UserUnitConfig.USER_UNIT_KG, goalUnit, data, decimal); | |||||
} | |||||
private static String getWeightToLbLb(int unit, String data, int decimal) { | |||||
float weight = -1f; | |||||
float g; | |||||
float oz; | |||||
if (TextUtils.isEmpty(data) || NO_DATA.equalsIgnoreCase(data)) { | |||||
return NO_DATA; | |||||
} | |||||
if (unit == UserUnitConfig.USER_UNIT_LB_LB) {//单位相同直接返回 | |||||
weight = Float.parseFloat(data); | |||||
} | |||||
switch (unit) { | |||||
case UserUnitConfig.USER_UNIT_FG: | |||||
g = UnitUtils.fgToG(Float.parseFloat(data)); | |||||
oz = UnitUtils.gToOz(g); | |||||
weight = UnitUtils.ozToLbLb(oz); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_KG: | |||||
g = UnitUtils.kgToG(Float.parseFloat(data)); | |||||
oz = UnitUtils.gToOz(g); | |||||
weight = UnitUtils.ozToLbLb(oz); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_OZ: | |||||
weight = UnitUtils.ozToLbLb(Float.parseFloat(data)); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_LB: | |||||
oz = getWeightLbToOz(data); | |||||
weight = UnitUtils.ozToLbLb(oz); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_G: | |||||
oz = UnitUtils.gToOz(Float.parseFloat(data)); | |||||
weight = UnitUtils.ozToLbLb(oz); | |||||
break; | |||||
} | |||||
return getHoldDecimal(decimal, weight); | |||||
} | |||||
private static String getWeightToStLb(int unit, String data, int decimal) { | |||||
String stlb_str = "0:0.0"; | |||||
float weight = -1f; | |||||
float g; | |||||
float oz; | |||||
if (TextUtils.isEmpty(data) || NO_DATA.equalsIgnoreCase(data)) { | |||||
return NO_DATA; | |||||
} | |||||
if (unit == UserUnitConfig.USER_UNIT_ST) {//单位相同直接返回 | |||||
return data; | |||||
} | |||||
switch (unit) { | |||||
case UserUnitConfig.USER_UNIT_FG: | |||||
g = UnitUtils.fgToG(Float.parseFloat(data)); | |||||
oz = UnitUtils.gToOz(g); | |||||
weight = UnitUtils.ozToLbLb(oz); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_KG: | |||||
g = UnitUtils.kgToG(Float.parseFloat(data)); | |||||
oz = UnitUtils.gToOz(g); | |||||
weight = UnitUtils.ozToLbLb(oz); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_OZ: | |||||
weight = UnitUtils.ozToLbLb(Float.parseFloat(data)); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_LB: | |||||
oz = getWeightLbToOz(data); | |||||
weight = UnitUtils.ozToLbLb(oz); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_G: | |||||
oz = UnitUtils.gToOz(Float.parseFloat(data)); | |||||
weight = UnitUtils.ozToLbLb(oz); | |||||
break; | |||||
} | |||||
float[] stlb = UnitUtils.LbToSt(weight); | |||||
stlb_str = (int) stlb[0] + ":" + Math.round(stlb[1] * 10) / 10f; | |||||
return stlb_str; | |||||
} | |||||
public static int getToMmhg(float kpa, int decimal, int unit) { | |||||
float mmhg = 0; | |||||
switch (unit) { | |||||
case UserUnitConfig.USER_UNIT_KPA: | |||||
float data = UnitUtils.kpaToMmhg(kpa); | |||||
mmhg = Float.parseFloat(getHoldDecimal(decimal, data)); | |||||
break; | |||||
case UserUnitConfig.USER_UNIT_MMHG: | |||||
mmhg = kpa; | |||||
break; | |||||
} | |||||
return (int) mmhg; | |||||
} | |||||
public static int getToMmhg(String kpa, int decimal, int unit) { | |||||
return getToMmhg(Float.parseFloat(kpa), decimal, unit); | |||||
} | |||||
public static int getC(String temperature, int decimal, int unit) { | |||||
float c = 0f; | |||||
try { | |||||
if (unit == UserUnitConfig.USER_UNIT_F) { | |||||
c = Float.parseFloat(getHoldDecimal(decimal, UnitUtils.FToC(Float.parseFloat(temperature)))) * 100f; | |||||
} else if (unit == UserUnitConfig.USER_UNIT_C) { | |||||
c = Float.parseFloat(temperature) * 100f; | |||||
} | |||||
} catch (NumberFormatException e) { | |||||
e.printStackTrace(); | |||||
} | |||||
return (int) c; | |||||
} | |||||
/** | |||||
* 保留小数位,不足后面补0 | |||||
* | |||||
* @param decimal 保留几位小数,后面补0 | |||||
* @param value 原始小数 | |||||
* @return 保留后的数据 | |||||
*/ | |||||
public static String getHoldDecimal(int decimal, float value) { | |||||
if (decimal > 0) { | |||||
StringBuilder decimalStr = new StringBuilder("0."); | |||||
for (int i = 0; i < decimal; i++) { | |||||
decimalStr.append("0"); | |||||
} | |||||
DecimalFormat df = new DecimalFormat(decimalStr.toString()); | |||||
return df.format(value).replace(",", "."); | |||||
} | |||||
String s = String.format(Locale.US, "%."+decimal+"f", value); | |||||
return s; | |||||
} | |||||
} |
package aicare.net.cn.sdk.ailinksdkdemoandroid.utils; | package aicare.net.cn.sdk.ailinksdkdemoandroid.utils; | ||||
import android.Manifest; | import android.Manifest; | ||||
import android.app.Activity; | |||||
import android.content.Context; | import android.content.Context; | ||||
import android.content.Intent; | import android.content.Intent; | ||||
import android.content.pm.PackageManager; | import android.content.pm.PackageManager; | ||||
import android.provider.Settings; | import android.provider.Settings; | ||||
import android.view.View; | import android.view.View; | ||||
import java.lang.ref.WeakReference; | |||||
import java.util.Map; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.HintDataDialogFragment; | |||||
import androidx.activity.result.ActivityResult; | |||||
import androidx.activity.result.ActivityResultCallback; | import androidx.activity.result.ActivityResultCallback; | ||||
import androidx.activity.result.ActivityResultLauncher; | import androidx.activity.result.ActivityResultLauncher; | ||||
import androidx.activity.result.contract.ActivityResultContracts; | import androidx.activity.result.contract.ActivityResultContracts; | ||||
import androidx.fragment.app.Fragment; | import androidx.fragment.app.Fragment; | ||||
import androidx.fragment.app.FragmentManager; | import androidx.fragment.app.FragmentManager; | ||||
import java.lang.ref.WeakReference; | |||||
import java.util.Map; | |||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.HintDataDialogFragment; | |||||
/** | /** | ||||
* @author xing<br> | * @author xing<br> | ||||
* @date 2022/11/24<br> | * @date 2022/11/24<br> | ||||
public CheckPermissionUtils(AppCompatActivity activity) { | public CheckPermissionUtils(AppCompatActivity activity) { | ||||
mPermissionRequestFragment = new PermissionRequestFragment(); | mPermissionRequestFragment = new PermissionRequestFragment(); | ||||
WeakReference<AppCompatActivity> mActivity = new WeakReference<>(activity);; | |||||
WeakReference<AppCompatActivity> mActivity = new WeakReference<>(activity); | |||||
mPermissionRequestFragment.setActivity(mActivity.get()); | mPermissionRequestFragment.setActivity(mActivity.get()); | ||||
} | } | ||||
private String[] LOCATION_PERMISSION = new String[]{Manifest.permission.ACCESS_FINE_LOCATION}; | private String[] LOCATION_PERMISSION = new String[]{Manifest.permission.ACCESS_FINE_LOCATION}; | ||||
private String[] BLUETOOTH_PERMISSION = new String[]{Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_ADVERTISE, Manifest.permission.BLUETOOTH_CONNECT}; | private String[] BLUETOOTH_PERMISSION = new String[]{Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_ADVERTISE, Manifest.permission.BLUETOOTH_CONNECT}; | ||||
private ActivityResultLauncher<String[]> mActivityResultLauncher; | private ActivityResultLauncher<String[]> mActivityResultLauncher; | ||||
private ActivityResultLauncher<Intent> mActivityResultIntentLauncher; | |||||
private int mErrNumber; | private int mErrNumber; | ||||
private FragmentManager mFragmentManager; | private FragmentManager mFragmentManager; | ||||
public void onCreate(@Nullable Bundle savedInstanceState) { | public void onCreate(@Nullable Bundle savedInstanceState) { | ||||
super.onCreate(savedInstanceState); | super.onCreate(savedInstanceState); | ||||
initPermissions(); | initPermissions(); | ||||
initLocationActivity(); | |||||
} | } | ||||
protected void initPermissions() { | protected void initPermissions() { | ||||
} | } | ||||
return; | return; | ||||
} | } | ||||
if (mContext==null||mActivity==null) { | |||||
if (mContext == null || mActivity == null) { | |||||
return; | return; | ||||
} | } | ||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | ||||
boolean bleStatus = isLocServiceEnable(mContext); | boolean bleStatus = isLocServiceEnable(mContext); | ||||
if (!bleStatus) { | if (!bleStatus) { | ||||
//没有开启定位服务 | //没有开启定位服务 | ||||
HintDataDialogFragment.newInstance().setTitle("提示",0) | |||||
.setContent("请求打开定位权限", true) | |||||
.setOnDialogListener(new HintDataDialogFragment.onDialogListener() { | |||||
@Override | |||||
public void onCancelListener(View v) { | |||||
} | |||||
@Override | |||||
public void onSucceedListener(View v) { | |||||
startLocationActivity(); | |||||
} | |||||
}).show(mActivity.getSupportFragmentManager()); | |||||
HintDataDialogFragment.newInstance().setTitle("提示", 0).setContent("请求开启定位服务", true).setOnDialogListener(new HintDataDialogFragment.onDialogListener() { | |||||
@Override | |||||
public void onCancelListener(View v) { | |||||
} | |||||
@Override | |||||
public void onSucceedListener(View v) { | |||||
startLocationActivity(); | |||||
} | |||||
}).show(mActivity.getSupportFragmentManager()); | |||||
} else { | } else { | ||||
onPermissionsOk(); | onPermissionsOk(); | ||||
} | } | ||||
} | } | ||||
/** | |||||
* 检查蓝牙权限 | |||||
* | |||||
* @return boolean | |||||
*/ | |||||
private boolean checkBluetoothPermission() { | private boolean checkBluetoothPermission() { | ||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { | ||||
return true; | return true; | ||||
onPermissionsOk(); | onPermissionsOk(); | ||||
} else { | } else { | ||||
//请求的权限有一个或者多个被拒绝 | //请求的权限有一个或者多个被拒绝 | ||||
HintDataDialogFragment.newInstance().setTitle("提示",0).setContent("请求蓝牙权限", true) | |||||
.setOnDialogListener(new HintDataDialogFragment.onDialogListener() { | |||||
@Override | |||||
public void onCancelListener(View v) { | |||||
} | |||||
@Override | |||||
public void onSucceedListener(View v) { | |||||
mErrNumber++; | |||||
if (mErrNumber >= 3) { | |||||
startUseSetActivity(mContext); | |||||
} else { | |||||
mActivityResultLauncher.launch(BLUETOOTH_PERMISSION); | |||||
} | |||||
} | |||||
}).show(mActivity.getSupportFragmentManager()); | |||||
HintDataDialogFragment.newInstance().setTitle("提示", 0).setContent("请求蓝牙权限", true).setOnDialogListener(new HintDataDialogFragment.onDialogListener() { | |||||
@Override | |||||
public void onCancelListener(View v) { | |||||
} | |||||
@Override | |||||
public void onSucceedListener(View v) { | |||||
mErrNumber++; | |||||
if (mErrNumber >= 3) { | |||||
startUseSetActivity(mContext); | |||||
} else { | |||||
mActivityResultLauncher.launch(BLUETOOTH_PERMISSION); | |||||
} | |||||
} | |||||
}).show(mActivity.getSupportFragmentManager()); | |||||
} | } | ||||
boolean bleStatus = isLocServiceEnable(mContext); | boolean bleStatus = isLocServiceEnable(mContext); | ||||
if (!bleStatus) { | if (!bleStatus) { | ||||
//没有开启定位服务 | //没有开启定位服务 | ||||
HintDataDialogFragment.newInstance().setTitle("提示",0).setContent("请求位置权限", true) | |||||
.setOnDialogListener(new HintDataDialogFragment.onDialogListener() { | |||||
@Override | |||||
public void onCancelListener(View v) { | |||||
} | |||||
@Override | |||||
public void onSucceedListener(View v) { | |||||
startLocationActivity(); | |||||
} | |||||
}).show(mActivity.getSupportFragmentManager()); | |||||
HintDataDialogFragment.newInstance().setTitle("提示", 0).setContent("请求位置权限", true).setOnDialogListener(new HintDataDialogFragment.onDialogListener() { | |||||
@Override | |||||
public void onCancelListener(View v) { | |||||
} | |||||
@Override | |||||
public void onSucceedListener(View v) { | |||||
startLocationActivity(); | |||||
} | |||||
}).show(mActivity.getSupportFragmentManager()); | |||||
} else { | } else { | ||||
onPermissionsOk(); | onPermissionsOk(); | ||||
} | } | ||||
} else { | } else { | ||||
//请求的权限有一个或者多个被拒绝 | //请求的权限有一个或者多个被拒绝 | ||||
HintDataDialogFragment.newInstance().setTitle("提示",0).setContent("请求定位权限", true) | |||||
.setOnDialogListener(new HintDataDialogFragment.onDialogListener() { | |||||
@Override | |||||
public void onCancelListener(View v) { | |||||
HintDataDialogFragment.newInstance().setTitle("提示", 0).setContent("请求定位权限", true).setOnDialogListener(new HintDataDialogFragment.onDialogListener() { | |||||
@Override | |||||
public void onCancelListener(View v) { | |||||
} | |||||
} | |||||
@Override | |||||
public void onSucceedListener(View v) { | |||||
mErrNumber++; | |||||
if (mErrNumber >= 3) { | |||||
startUseSetActivity(mContext); | |||||
} else { | |||||
mActivityResultLauncher.launch(LOCATION_PERMISSION); | |||||
} | |||||
} | |||||
}).show(mActivity.getSupportFragmentManager()); | |||||
@Override | |||||
public void onSucceedListener(View v) { | |||||
mErrNumber++; | |||||
if (mErrNumber >= 3) { | |||||
startUseSetActivity(mContext); | |||||
} else { | |||||
mActivityResultLauncher.launch(LOCATION_PERMISSION); | |||||
} | |||||
} | |||||
}).show(mActivity.getSupportFragmentManager()); | |||||
} | } | ||||
mActivityResultLauncher.launch(LOCATION_PERMISSION); | mActivityResultLauncher.launch(LOCATION_PERMISSION); | ||||
} | } | ||||
/** | |||||
* 初始化位置活动 | |||||
*/ | |||||
private void initLocationActivity() { | |||||
mActivityResultIntentLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> { | |||||
//定位服务页面返回 | |||||
boolean bleStatus = isLocServiceEnable(mContext); | |||||
if (!bleStatus) { | |||||
//没有开启定位服务 | |||||
HintDataDialogFragment.newInstance().setTitle("提示", 0).setContent("请求开启定位服务", true).setOnDialogListener(new HintDataDialogFragment.onDialogListener() { | |||||
@Override | |||||
public void onCancelListener(View v) { | |||||
} | |||||
@Override | |||||
public void onSucceedListener(View v) { | |||||
startLocationActivity(); | |||||
} | |||||
}).show(mActivity.getSupportFragmentManager()); | |||||
} else { | |||||
onPermissionsOk(); | |||||
} | |||||
}); | |||||
} | |||||
/** | /** | ||||
* 启动去设置定位服务 | * 启动去设置定位服务 | ||||
*/ | */ | ||||
protected void startLocationActivity() { | |||||
Intent localIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); | |||||
if (mActivity.getPackageManager().resolveActivity(localIntent, PackageManager.MATCH_DEFAULT_ONLY) != null) { | |||||
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() { | |||||
@Override | |||||
public void onActivityResult(ActivityResult result) { | |||||
if (result.getResultCode() == Activity.RESULT_OK) { | |||||
//定位服务页面返回 | |||||
boolean bleStatus = isLocServiceEnable(mContext); | |||||
if (!bleStatus) { | |||||
//没有开启定位服务 | |||||
HintDataDialogFragment.newInstance().setTitle("提示",0).setContent("请求位置权限", true) | |||||
.setOnDialogListener(new HintDataDialogFragment.onDialogListener() { | |||||
@Override | |||||
public void onCancelListener(View v) { | |||||
} | |||||
@Override | |||||
public void onSucceedListener(View v) { | |||||
startLocationActivity(); | |||||
} | |||||
}).show(mActivity.getSupportFragmentManager()); | |||||
} else { | |||||
onPermissionsOk(); | |||||
} | |||||
} | |||||
} | |||||
}).launch(localIntent); | |||||
private void startLocationActivity() { | |||||
try { | |||||
if (mActivityResultIntentLauncher != null) { | |||||
Intent localIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); | |||||
mActivityResultIntentLauncher.launch(localIntent); | |||||
} | |||||
} catch (Exception e) { | |||||
e.printStackTrace(); | |||||
} | } | ||||
} | } | ||||
* 权限ok | * 权限ok | ||||
*/ | */ | ||||
private void onPermissionsOk() { | private void onPermissionsOk() { | ||||
if (!isDetached()&&!isRemoving()) { | |||||
if (!isDetached() && !isRemoving()) { | |||||
mFragmentManager.beginTransaction().detach(this).commit(); | mFragmentManager.beginTransaction().detach(this).commit(); | ||||
} | } | ||||
import android.net.Uri; | import android.net.Uri; | ||||
import android.os.Build; | import android.os.Build; | ||||
import java.io.File; | |||||
import androidx.core.content.FileProvider; | import androidx.core.content.FileProvider; | ||||
import java.io.File; | |||||
/** | /** | ||||
* 兼容android 7.0以上获取uri异常的工具类 | * 兼容android 7.0以上获取uri异常的工具类 | ||||
*/ | */ |
import android.provider.OpenableColumns; | import android.provider.OpenableColumns; | ||||
import android.util.Log; | import android.util.Log; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import java.io.ByteArrayOutputStream; | import java.io.ByteArrayOutputStream; | ||||
import java.io.File; | import java.io.File; | ||||
import java.io.FileOutputStream; | import java.io.FileOutputStream; | ||||
import java.util.Comparator; | import java.util.Comparator; | ||||
import aicare.net.cn.sdk.ailinksdkdemoandroid.base.MyApplication; | import aicare.net.cn.sdk.ailinksdkdemoandroid.base.MyApplication; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
public class FileUtils { | public class FileUtils { |
import android.util.Log; | import android.util.Log; | ||||
import androidx.annotation.NonNull; | |||||
import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||
import java.util.Date; | import java.util.Date; | ||||
import java.util.Locale; | import java.util.Locale; | ||||
import androidx.annotation.NonNull; | |||||
/** | /** | ||||
* 打印日志工具 | * 打印日志工具 | ||||
*/ | */ |
package aicare.net.cn.sdk.ailinksdkdemoandroid.utils; | |||||
import java.math.RoundingMode; | |||||
import java.text.DecimalFormat; | |||||
import java.util.Locale; | |||||
/** | |||||
* xing<br> | |||||
* 2019/4/29<br> | |||||
* 单位转换工具类 | |||||
*/ | |||||
public class UnitUtils { | |||||
//-------------重量------------ | |||||
/** | |||||
* st转lb | |||||
*/ | |||||
public static float stToLb(float st) { | |||||
float lb = st * 14; | |||||
return lb; | |||||
} | |||||
// public static float LbToSt(float lb) { | |||||
// float st = lb / 14; | |||||
// return st; | |||||
// } | |||||
/** | |||||
* lb转oz | |||||
*/ | |||||
public static float lbToOz(float lb) { | |||||
float oz = lb * 16; | |||||
return oz; | |||||
} | |||||
/** | |||||
* oz转lb:oz | |||||
*/ | |||||
public static float[] ozToLb(float ozSize) { | |||||
float[] ozFloatS = new float[2]; | |||||
int lb = (int) ozSize / 16; | |||||
float oz = ozSize % 16f; | |||||
ozFloatS[0] = lb; | |||||
ozFloatS[1] = oz; | |||||
return ozFloatS; | |||||
} | |||||
/** | |||||
* oz转lb | |||||
*/ | |||||
public static float ozToLbLb(float ozSize) { | |||||
return ozSize / 16f; | |||||
} | |||||
/** | |||||
* lb转st:lb | |||||
*/ | |||||
public static float[] LbToSt(float lbSize) { | |||||
float[] lbFloatS = new float[2]; | |||||
int st = (int) lbSize / 14; | |||||
float lb = lbSize % 14f; | |||||
lbFloatS[0] = st; | |||||
lbFloatS[1] = lb; | |||||
return lbFloatS; | |||||
} | |||||
/** | |||||
* lb转st | |||||
*/ | |||||
public static float LbToStSt(float lbSize) { | |||||
return lbSize / 14f; | |||||
} | |||||
/** | |||||
* oz转g | |||||
*/ | |||||
public static float ozToG(float oz) { | |||||
float g = oz * 28.3495F; | |||||
return g; | |||||
} | |||||
public static float gToOz(float g) { | |||||
return g / 28.3495F; | |||||
} | |||||
/** | |||||
* 千克转克 | |||||
*/ | |||||
public static float kgToG(float kg) { | |||||
return kg * 1000; | |||||
} | |||||
public static float gToKG(float g) { | |||||
return g / 1000; | |||||
} | |||||
/** | |||||
* 斤转克 | |||||
*/ | |||||
public static float fgToG(float fg) { | |||||
return fg * 500; | |||||
} | |||||
public static float gToFG(float g) { | |||||
return g / 500; | |||||
} | |||||
/** | |||||
* 斤转Kg | |||||
*/ | |||||
public static float fgToKG(float fg) { | |||||
return fg / 2; | |||||
} | |||||
//-----------温度------------- | |||||
/** | |||||
* 摄氏度转华氏度,可能会出现小数点精度问题,例:xx.99999999 | |||||
*/ | |||||
public static float CToF(float c) { | |||||
float f = c * 1.8F + 32; | |||||
return f; | |||||
} | |||||
public static float CToFOne(float c) { | |||||
float f = c * 1.8F + 32; | |||||
return Math.round(f * 10) / 10f; | |||||
} | |||||
/** | |||||
* 华氏度转摄氏度 | |||||
*/ | |||||
public static float FToC(float f) { | |||||
float c = (f - 32) / 1.8f; | |||||
return c; | |||||
} | |||||
/** | |||||
* 华氏度转度 | |||||
*/ | |||||
public static float FToCOne(float f) { | |||||
float c = (f - 32) / 1.8f; | |||||
return Math.round(c * 10) / 10f; | |||||
} | |||||
//------------压力----------------------- | |||||
/** | |||||
* 千帕转毫米汞柱 | |||||
*/ | |||||
public static float kpaToMmhg(float kpa) { | |||||
float mmhg = (kpa * 7.50f); | |||||
return mmhg; | |||||
} | |||||
/** | |||||
* 毫米汞柱转千帕 | |||||
*/ | |||||
public static float mmhgToKpa(float mmhg) { | |||||
float kpa = (mmhg / 7.50f); | |||||
return kpa; | |||||
} | |||||
//-----------长度-------------------- | |||||
public static float feetToInch(float feet) { | |||||
float inch = (feet * 12f); | |||||
return inch; | |||||
} | |||||
/** | |||||
* Inch转Feet:Inch | |||||
*/ | |||||
public static float[] inchToFeet(float inchSize) { | |||||
float[] feetS = new float[2]; | |||||
int feet = (int) (inchSize / 12); | |||||
float inch = (inchSize % 12f); | |||||
feetS[0] = feet; | |||||
feetS[1] = inch; | |||||
return feetS; | |||||
} | |||||
/** | |||||
* Inch转Feet | |||||
*/ | |||||
public static float inchToFeetFeet(float inchSize) { | |||||
return inchSize / 12f; | |||||
} | |||||
public static float inchToCm(float inch) { | |||||
float cm = (inch * 2.54f); | |||||
return cm; | |||||
} | |||||
public static float cmToInch(float cm) { | |||||
return cm / 2.54F; | |||||
} | |||||
/** | |||||
* 米转码 | |||||
*/ | |||||
public static float mToYard(float m) { | |||||
return m * 1.0936133F; | |||||
} | |||||
/** | |||||
* 码转英里 | |||||
*/ | |||||
public static float yardToMi(float yard) { | |||||
return yard / 1760F; | |||||
} | |||||
//----------转换用---------- | |||||
/** | |||||
* 保留小数位,不足后面补0 | |||||
* | |||||
* @param decimal 保留几位小数,后面补0 | |||||
* @param value 原始小数 | |||||
* @return 保留后的数据 | |||||
*/ | |||||
public static String getHoldDecimal(int decimal, float value) { | |||||
if (decimal > 0) { | |||||
StringBuilder decimalStr = new StringBuilder("0."); | |||||
for (int i = 0; i < decimal; i++) { | |||||
decimalStr.append("0"); | |||||
} | |||||
DecimalFormat df = new DecimalFormat(decimalStr.toString()); | |||||
return df.format(value).replace(",", "."); | |||||
} | |||||
String s = String.format(Locale.US, "%."+decimal+"f", value); | |||||
return s; | |||||
} | |||||
/** | |||||
* 保留小数位,不足后面补0 | |||||
* | |||||
* @param decimal 保留几位小数,后面补0 | |||||
* @param value 原始小数 | |||||
* @return 保留后的数据 | |||||
*/ | |||||
public static String getHoldDecimalNotRounding(int decimal, double value) { | |||||
if (decimal > 0) { | |||||
StringBuilder decimalStr = new StringBuilder("0."); | |||||
for (int i = 0; i < decimal; i++) { | |||||
decimalStr.append("0"); | |||||
} | |||||
DecimalFormat df = new DecimalFormat(decimalStr.toString()); | |||||
df.setRoundingMode(RoundingMode.DOWN);//向下取,丢掉后面的 | |||||
return df.format(value).replace(",", "."); | |||||
} | |||||
return String.valueOf((int) value); | |||||
} | |||||
} |