@@ -1,5 +1,5 @@ | |||
apply plugin: 'com.android.application' | |||
apply plugin: 'com.jakewharton.butterknife' | |||
android { | |||
compileSdkVersion 29 | |||
buildToolsVersion "29.0.2" | |||
@@ -7,8 +7,8 @@ android { | |||
applicationId "aicare.net.cn.sdk.ailinksdkdemoandroid" | |||
minSdkVersion 19 | |||
targetSdkVersion 29 | |||
versionCode 2 | |||
versionName "1.3.0" | |||
versionCode 3 | |||
versionName "1.5.2" | |||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | |||
} | |||
buildTypes { | |||
@@ -31,6 +31,9 @@ dependencies { | |||
implementation 'androidx.appcompat:appcompat:1.1.0' | |||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | |||
testImplementation 'junit:junit:4.12' | |||
implementation 'com.github.elinkthings:AILinkSDKRepositoryAndroid:1.4.5' | |||
implementation 'com.github.elinkthings:AILinkSDKParsingLibraryAndroid:1.3.0' | |||
implementation 'com.github.elinkthings:AILinkSDKRepositoryAndroid:1.5.1' | |||
implementation 'com.github.elinkthings:AILinkSDKParsingLibraryAndroid:1.5.2' | |||
implementation 'androidx.recyclerview:recyclerview:1.1.0' | |||
implementation 'com.jakewharton:butterknife:10.2.0' | |||
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.0' | |||
} |
@@ -1,13 +1,24 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<manifest package="aicare.net.cn.sdk.ailinksdkdemoandroid" | |||
xmlns:android="http://schemas.android.com/apk/res/android"> | |||
xmlns:android="http://schemas.android.com/apk/res/android" | |||
xmlns:tools="http://schemas.android.com/tools"> | |||
<!--兼容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-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.CHANGE_WIFI_MULTICAST_STATE" /> | |||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> | |||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> | |||
<uses-permission android:name="android.permission.INTERNET" /> | |||
<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_COARSE_LOCATION" /> | |||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | |||
<uses-permission android:name="android.permission.BLUETOOTH"/> | |||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> | |||
<!--OTA需要读写文件--> | |||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | |||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> | |||
<uses-feature | |||
android:name="android.hardware.bluetooth_le" | |||
android:required="true"/> | |||
@@ -17,34 +28,42 @@ | |||
android:icon="@mipmap/ic_launcher" | |||
android:label="@string/app_name" | |||
android:roundIcon="@mipmap/ic_launcher_round" | |||
android:requestLegacyExternalStorage="true" | |||
android:supportsRtl="true" | |||
android:theme="@style/AppTheme"> | |||
android:usesCleartextTraffic="true" | |||
android:theme="@style/AppTheme" | |||
tools:targetApi="q"> | |||
<activity android:name=".MainActivity"> | |||
<intent-filter> | |||
<action android:name="android.intent.action.VIEW"/> | |||
<action android:name="android.intent.action.MAIN"/> | |||
<category android:name="android.intent.category.LAUNCHER"/> | |||
<action android:name="android.intent.action.VIEW" /> | |||
<action android:name="android.intent.action.MAIN" /> | |||
<category android:name="android.intent.category.LAUNCHER" /> | |||
</intent-filter> | |||
</activity> | |||
<activity android:name=".ShowBleActivity"/> | |||
<activity android:name=".BabyCmdActivity"/> | |||
<activity android:name=".TempGunCmdActivity"/> | |||
<activity android:name=".SphyCmdActivity"/> | |||
<activity android:name=".TempCmdActivity"/> | |||
<activity android:name=".HeightCmdActivity"/> | |||
<activity android:name=".BleCmdActivityDataData"/> | |||
<activity android:name=".ShowBleActivity" /> | |||
<activity android:name=".BabyCmdActivity" /> | |||
<activity android:name=".TempGunCmdActivity" /> | |||
<activity android:name=".SphyCmdActivity" /> | |||
<activity android:name=".TempCmdActivity" /> | |||
<activity android:name=".HeightCmdActivity" /> | |||
<activity android:name=".BleCmdActivity" /> | |||
<activity android:name=".TestCmdActivity" /> | |||
<activity android:name=".TpmsConnectCmdActivity" /> | |||
<activity android:name=".BloodGlucoseActivity" /> | |||
<activity android:name=".ADWeightScaleCmdActivity"/> | |||
<activity android:name=".ADWeightScaleUserActivity" | |||
android:theme="@style/Theme.AppCompat.Light.NoActionBar" | |||
/> | |||
<activity android:name=".WeightScaleWifiBle" | |||
android:theme="@style/Theme.AppCompat.Light.NoActionBar" | |||
/> | |||
<activity android:name=".ConnectBleTestActivity" /> | |||
<activity android:name=".ADWeightScaleCmdActivity" /> | |||
<activity android:name=".ADWeightScaleUserActivity" /> | |||
<activity android:name=".WeightScaleWifiBle" /> | |||
<activity android:name=".WeightScaleBle"/> | |||
<activity android:name=".WifiConfigActivity"/> | |||
<activity android:name=".EightBodyfatActivity"/> | |||
<activity android:name=".TestOtaActivity"/> | |||
<activity android:name=".BloodGlucoseActivity"/> | |||
<activity android:name=".BabyBodyFatCmdActivity" /> | |||
<activity android:name=".BroadcastScaleActivity" /> | |||
<activity android:name=".TransmissionActivity"/> | |||
<activity android:name=".BroadcastBloodOxygenActivity" /> | |||
<activity android:name=".SmartMaskActivity" /> | |||
<activity android:name=".ToothBrushWifiBleActivity" /> | |||
<service android:name="com.pingwang.bluetoothlib.server.ELinkBleServer"/> | |||
</application> |
@@ -15,6 +15,7 @@ import android.widget.RadioButton; | |||
import android.widget.RadioGroup; | |||
import android.widget.TextView; | |||
import com.pingwang.bluetoothlib.BleBaseActivity; | |||
import com.pingwang.bluetoothlib.bean.BleValueBean; | |||
import com.pingwang.bluetoothlib.config.CmdConfig; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
@@ -28,6 +29,7 @@ import com.pingwang.bluetoothlib.listener.OnMcuParameterListener; | |||
import com.pingwang.bluetoothlib.utils.BleDensityUtil; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
@@ -41,6 +43,7 @@ import cn.net.aicare.modulelibrary.module.ADWeight.ADWeightScaleDeviceData; | |||
import cn.net.aicare.modulelibrary.module.ADWeight.ADWeightScaleUserData; | |||
/** | |||
* xing<br> | |||
* 2019/7/12<br> | |||
@@ -402,7 +405,7 @@ public class ADWeightScaleCmdActivity extends BleBaseActivity implements OnCallb | |||
@Override | |||
public void getWeight(int weight, int decimal, int unit) { | |||
String weightStr = BleDensityUtil.getInstance().holdNumber(weight, decimal); | |||
String weightStr = BleDensityUtil.getInstance().holdDecimals(weight, decimal); | |||
mList.add(TimeUtils.getTime() + "稳定体重=" + weightStr + ";小数位=" + decimal + ";单位=" + unit); | |||
if (weightUnit != unit) { | |||
@@ -414,7 +417,7 @@ public class ADWeightScaleCmdActivity extends BleBaseActivity implements OnCallb | |||
@Override | |||
public void getWeightNow(int weight, int decimal, int unit) { | |||
String weightStr = BleDensityUtil.getInstance().holdNumber(weight, decimal); | |||
String weightStr = BleDensityUtil.getInstance().holdDecimals(weight, decimal); | |||
mList.add(TimeUtils.getTime() + "实时体重=" + weightStr + ";小数位=" + decimal + ";单位=" + unit); | |||
//10.00,2,0 | |||
if (weightUnit != unit) { |
@@ -0,0 +1,212 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.app.Dialog; | |||
import android.content.DialogInterface; | |||
import android.content.IntentFilter; | |||
import android.os.Bundle; | |||
import android.view.KeyEvent; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import android.widget.RadioGroup; | |||
import android.widget.SeekBar; | |||
import android.widget.TextView; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import androidx.fragment.app.DialogFragment; | |||
import androidx.fragment.app.FragmentManager; | |||
import java.net.IDN; | |||
import cn.net.aicare.modulelibrary.module.BodyFatScale.BodyFatDataUtil; | |||
import cn.net.aicare.modulelibrary.module.BodyFatScale.User; | |||
public class AddUserDialog extends DialogFragment implements View.OnClickListener , SeekBar.OnSeekBarChangeListener, RadioGroup.OnCheckedChangeListener { | |||
private boolean mCancelBlank; | |||
private TextView id; | |||
private SeekBar agesb, heightsb, weightsb, adcsb; | |||
private RadioGroup sexRG, modeRG; | |||
private User user; | |||
private TextView tv_move_data_ok, tv_move_data_cancel; | |||
private OnDialogListener mOnDialogListener; | |||
public AddUserDialog( OnDialogListener onDialogListener) { | |||
user=new User(); | |||
user.setModeType(BodyFatDataUtil.MODE_ORDINARY); | |||
user.setSex(BodyFatDataUtil.SEX_MAN); | |||
user.setAge(0); | |||
user.setHeight(0); | |||
user.setAdc(0); | |||
user.setWeight(0); | |||
mOnDialogListener = onDialogListener; | |||
} | |||
@NonNull | |||
@Override | |||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { | |||
Dialog dialogView = new Dialog(requireContext(), R.style.MyDialog);// 创建自定义样式dialog | |||
dialogView.setCancelable(false);//设置是否可以关闭 | |||
dialogView.setCanceledOnTouchOutside(mCancelBlank);//设置点击空白处是否可以取消 | |||
dialogView.setOnKeyListener((dialog, keyCode, event) -> { | |||
if (mCancelBlank) { | |||
return false; | |||
} else { | |||
//返回不关闭 | |||
return keyCode == KeyEvent.KEYCODE_BACK; | |||
} | |||
}); | |||
return dialogView; | |||
} | |||
@Nullable | |||
@Override | |||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |||
return inflater.inflate(R.layout.item_user_info, container); | |||
} | |||
@Override | |||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { | |||
super.onViewCreated(view, savedInstanceState); | |||
agesb = view.findViewById(R.id.agesb); | |||
agesb.setOnSeekBarChangeListener(this); | |||
id = view.findViewById(R.id.id); | |||
tv_move_data_ok = view.findViewById(R.id.tv_move_data_ok); | |||
tv_move_data_cancel = view.findViewById(R.id.tv_move_data_cancel); | |||
tv_move_data_cancel.setOnClickListener(this); | |||
tv_move_data_ok.setOnClickListener(this); | |||
heightsb = view.findViewById(R.id.heightsb); | |||
heightsb.setOnSeekBarChangeListener(this); | |||
weightsb = view.findViewById(R.id.weightsb); | |||
weightsb.setOnSeekBarChangeListener(this); | |||
adcsb = view.findViewById(R.id.adcsb); | |||
adcsb.setOnSeekBarChangeListener(this); | |||
sexRG = view.findViewById(R.id.sexrg); | |||
modeRG = view.findViewById(R.id.moderg); | |||
sexRG.check(R.id.man); | |||
modeRG.check(R.id.ordinary); | |||
sexRG.setOnCheckedChangeListener(this); | |||
modeRG.setOnCheckedChangeListener(this); | |||
settext(); | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
if (v.getId() == R.id.tv_move_data_ok) { | |||
mOnDialogListener.tvSucceedListener(user); | |||
dismiss(); | |||
} else if (v.getId() == R.id.tv_move_data_cancel) { | |||
dismiss(); | |||
} | |||
} | |||
@Override | |||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { | |||
int id = seekBar.getId(); | |||
if (id == R.id.weightsb) { | |||
user.setWeight(progress); | |||
} else if (id == R.id.adcsb) { | |||
user.setAdc(progress); | |||
} else if (id == R.id.heightsb) { | |||
user.setHeight(progress); | |||
} else if (id == R.id.agesb) { | |||
user.setAge(progress); | |||
} | |||
settext(); | |||
} | |||
@Override | |||
public void onStartTrackingTouch(SeekBar seekBar) { | |||
} | |||
@Override | |||
public void onStopTrackingTouch(SeekBar seekBar) { | |||
} | |||
@Override | |||
public void onCheckedChanged(RadioGroup group, int checkedId) { | |||
if (checkedId == R.id.man) { | |||
user.setSex(BodyFatDataUtil.SEX_MAN); | |||
} else if (checkedId == R.id.female) { | |||
user.setSex(BodyFatDataUtil.SEX_FEMAN); | |||
} else if (checkedId == R.id.ordinary) { | |||
user.setModeType(BodyFatDataUtil.MODE_ORDINARY); | |||
} else if (checkedId == R.id.athlete) { | |||
user.setModeType(BodyFatDataUtil.MODE_ATHLETE); | |||
} else if (checkedId == R.id.pregnant) { | |||
user.setModeType(BodyFatDataUtil.MODE_PREGNANT); | |||
} | |||
settext(); | |||
} | |||
private void settext() { | |||
if (id != null) id.setText(user.toString()); | |||
} | |||
public interface OnDialogListener { | |||
/** | |||
* 取消的点击事件 | |||
*/ | |||
default void tvCancelListener() { | |||
} | |||
/** | |||
* 成功的点击事件 | |||
*/ | |||
default void tvSucceedListener(User user) { | |||
} | |||
} | |||
public void show(@NonNull FragmentManager manager) { | |||
this.show(manager, "DialogFragment"); | |||
} | |||
@Override | |||
public void onDismiss(@NonNull DialogInterface dialog) { | |||
super.onDismiss(dialog); | |||
mShow = false; | |||
} | |||
private boolean mShow=false; | |||
@Override | |||
public void show(@NonNull FragmentManager manager, @Nullable String tag) { | |||
try { | |||
if (!mShow) { | |||
super.show(manager, tag); | |||
mShow = true; | |||
} | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
@Override | |||
public void dismiss() { | |||
try { | |||
mShow = false; | |||
super.dismiss(); | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
} |
@@ -0,0 +1,557 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.content.Context; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import android.os.Message; | |||
import android.view.View; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.ListView; | |||
import android.widget.RadioButton; | |||
import android.widget.RadioGroup; | |||
import com.pingwang.bluetoothlib.BleBaseActivity; | |||
import com.pingwang.bluetoothlib.bean.BleValueBean; | |||
import com.pingwang.bluetoothlib.config.CmdConfig; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | |||
import com.pingwang.bluetoothlib.device.SendBleBean; | |||
import com.pingwang.bluetoothlib.listener.OnBleCompanyListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleVersionListener; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | |||
import com.pingwang.bluetoothlib.listener.OnMcuParameterListener; | |||
import com.pingwang.bluetoothlib.utils.BleDensityUtil; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import cn.net.aicare.modulelibrary.module.babyBodyFat.BabyBodyFatBleConfig; | |||
import cn.net.aicare.modulelibrary.module.babyBodyFat.BabyBodyFatDeviceData; | |||
import cn.net.aicare.modulelibrary.module.babyscale.BabyBleConfig; | |||
/** | |||
* xing<br> | |||
* 2020/08/10<br> | |||
* 显示数据 | |||
*/ | |||
public class BabyBodyFatCmdActivity extends BleBaseActivity implements OnCallbackBle, OnBleVersionListener, OnMcuParameterListener, OnBleCompanyListener, BabyBodyFatDeviceData.onNotifyData, | |||
View.OnClickListener, RadioGroup.OnCheckedChangeListener { | |||
private static String TAG = BabyBodyFatCmdActivity.class.getName(); | |||
private final int REFRESH_DATA = 3; | |||
private List<String> mList; | |||
private ArrayAdapter listAdapter; | |||
private Context mContext; | |||
private BabyBodyFatDeviceData mDevice; | |||
private String mAddress; | |||
private BleSendCmdUtil mBleSendCmdUtil; | |||
private int type; | |||
private int weightUnit = 0; | |||
private int heightUnit = 0; | |||
private RadioButton mRadioButtonKg, mRadioButtonLb, mRadioButtonLbLb, mRadioButtonG, mRadioButtonOz, mRadioButtonStLb, mRadioButtonJin; | |||
private RadioButton mRadioButtonCm, mRadioButtonInch, mRadioButtonFoot; | |||
private Handler mHandler = new Handler(Looper.getMainLooper()) { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
switch (msg.what) { | |||
case REFRESH_DATA: | |||
if (listAdapter != null) | |||
listAdapter.notifyDataSetChanged(); | |||
break; | |||
} | |||
} | |||
}; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_baby_body_fat_cmd); | |||
mContext = this; | |||
mAddress = getIntent().getStringExtra("mac"); | |||
type = getIntent().getIntExtra("type", -1); | |||
mBleSendCmdUtil = BleSendCmdUtil.getInstance(); | |||
init(); | |||
} | |||
private void init() { | |||
mList = new ArrayList<>(); | |||
ListView listView = findViewById(R.id.listview); | |||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | |||
listView.setAdapter(listAdapter); | |||
findViewById(R.id.btnVersion).setOnClickListener(this); | |||
findViewById(R.id.clear).setOnClickListener(this); | |||
findViewById(R.id.btnDis).setOnClickListener(this); | |||
findViewById(R.id.btnConnect).setOnClickListener(this); | |||
findViewById(R.id.btn_set_tare).setOnClickListener(this); | |||
findViewById(R.id.btn_set_hold).setOnClickListener(this); | |||
((RadioGroup) findViewById(R.id.radio_weight)).setOnCheckedChangeListener(this); | |||
((RadioGroup) findViewById(R.id.radio_height)).setOnCheckedChangeListener(this); | |||
mRadioButtonKg = findViewById(R.id.radio_weight_kg); | |||
mRadioButtonJin = findViewById(R.id.radio_weight_jin); | |||
mRadioButtonStLb = findViewById(R.id.radio_weight_st_lb); | |||
mRadioButtonLb = findViewById(R.id.radio_weight_lb); | |||
mRadioButtonOz = findViewById(R.id.radio_weight_oz); | |||
mRadioButtonG = findViewById(R.id.radio_weight_g); | |||
mRadioButtonLbLb = findViewById(R.id.radio_weight_lb_lb); | |||
mRadioButtonCm = findViewById(R.id.radio_height_cm); | |||
mRadioButtonInch = findViewById(R.id.radio_height_inch); | |||
mRadioButtonFoot = findViewById(R.id.radio_height_foot); | |||
} | |||
@Override | |||
public void onCheckedChanged(RadioGroup group, int checkedId) { | |||
if (checkedId == -1) | |||
return;//不是人为点击不触发 | |||
switch (group.getCheckedRadioButtonId()) { | |||
case R.id.radio_weight_kg: | |||
weightUnit = BabyBleConfig.BABY_KG; | |||
break; | |||
case R.id.radio_weight_jin: | |||
weightUnit = BabyBleConfig.BABY_FG; | |||
break; | |||
case R.id.radio_weight_lb: | |||
weightUnit = BabyBleConfig.BABY_LB; | |||
break; | |||
case R.id.radio_weight_oz: | |||
weightUnit = BabyBleConfig.BABY_OZ; | |||
break; | |||
case R.id.radio_weight_st_lb: | |||
weightUnit = BabyBleConfig.BABY_ST; | |||
break; | |||
case R.id.radio_weight_g: | |||
weightUnit = BabyBleConfig.BABY_G; | |||
break; | |||
case R.id.radio_weight_lb_lb: | |||
weightUnit = BabyBleConfig.BABY_LB_LB; | |||
break; | |||
case R.id.radio_height_cm: | |||
heightUnit = BabyBleConfig.BABY_CM; | |||
break; | |||
case R.id.radio_height_inch: | |||
heightUnit = BabyBleConfig.BABY_INCH; | |||
break; | |||
case R.id.radio_height_foot: | |||
heightUnit = BabyBleConfig.BABY_FEET; | |||
break; | |||
} | |||
BleLog.i(TAG, "weightUnit:" + weightUnit + " ,||heightUnit:" + heightUnit); | |||
mDevice.setUnit(weightUnit, heightUnit); | |||
} | |||
private void showWeightUnit(int unit) { | |||
switch (unit) { | |||
case BabyBleConfig.BABY_KG: | |||
mRadioButtonKg.setChecked(true); | |||
break; | |||
case BabyBleConfig.BABY_FG: | |||
mRadioButtonJin.setChecked(true); | |||
break; | |||
case BabyBleConfig.BABY_LB: | |||
mRadioButtonLb.setChecked(true); | |||
break; | |||
case BabyBleConfig.BABY_OZ: | |||
mRadioButtonOz.setChecked(true); | |||
break; | |||
case BabyBleConfig.BABY_ST: | |||
mRadioButtonStLb.setChecked(true); | |||
break; | |||
case BabyBleConfig.BABY_G: | |||
mRadioButtonG.setChecked(true); | |||
break; | |||
case BabyBleConfig.BABY_LB_LB: | |||
mRadioButtonLbLb.setChecked(true); | |||
break; | |||
} | |||
} | |||
private void showHeightUnit(int unit) { | |||
switch (unit) { | |||
case BabyBleConfig.BABY_CM: | |||
mRadioButtonCm.setChecked(true); | |||
break; | |||
case BabyBleConfig.BABY_INCH: | |||
mRadioButtonInch.setChecked(true); | |||
break; | |||
case BabyBleConfig.BABY_FEET: | |||
mRadioButtonFoot.setChecked(true); | |||
break; | |||
} | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
SendBleBean sendBleBean = new SendBleBean(); | |||
switch (v.getId()) { | |||
case R.id.btnVersion: | |||
sendBleBean.setHex(mBleSendCmdUtil.getBleVersion()); | |||
mDevice.sendData(sendBleBean); | |||
break; | |||
case R.id.clear: | |||
if (mList != null) | |||
mList.clear(); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
break; | |||
case R.id.btnDis: | |||
if (mDevice != null) { | |||
mDevice.disconnect(); | |||
} | |||
break; | |||
case R.id.btnConnect: | |||
startScanBle(0); | |||
break; | |||
case R.id.btn_set_tare: | |||
if (mDevice != null) { | |||
mDevice.setTare(); | |||
} | |||
break; | |||
case R.id.btn_set_hold: | |||
if (mDevice != null) { | |||
mDevice.setHold(); | |||
} | |||
break; | |||
} | |||
} | |||
//---------------------------------服务--------------------------------------------------- | |||
@Override | |||
public void onServiceSuccess() { | |||
BleLog.i(TAG, "服务与界面建立连接成功"); | |||
//与服务建立连接 | |||
if (mBluetoothService != null) { | |||
mBluetoothService.setOnCallback(this); | |||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | |||
if (bleDevice != null) { | |||
mDevice = BabyBodyFatDeviceData.getInstance(bleDevice); | |||
mDevice.setOnNotifyData(this); | |||
mDevice.setOnBleVersionListener(BabyBodyFatCmdActivity.this); | |||
mDevice.setOnMcuParameterListener(BabyBodyFatCmdActivity.this); | |||
mDevice.setOnCompanyListener(BabyBodyFatCmdActivity.this); | |||
} | |||
} | |||
} | |||
@Override | |||
public void onServiceErr() { | |||
BleLog.i(TAG, "服务与界面连接断开"); | |||
//与服务断开连接 | |||
mBluetoothService = null; | |||
} | |||
@Override | |||
public void unbindServices() { | |||
if (mDevice != null) { | |||
mDevice.disconnect(); | |||
mDevice.clear(); | |||
mDevice = null; | |||
} | |||
} | |||
//-----------------状态------------------- | |||
@Override | |||
public void onScanning(BleValueBean data) { | |||
if (data.getMac().equals(mAddress)) { | |||
connectBle(mAddress); | |||
mList.add(TimeUtils.getTime() + "开始连接"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
} | |||
@Override | |||
public void onConnecting(@NonNull String mac) { | |||
//TODO 连接中 | |||
BleLog.i(TAG, "连接中"); | |||
mList.add(TimeUtils.getTime() + "连接中"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onDisConnected(@NonNull String mac, int code) { | |||
//TODO 连接断开 | |||
BleLog.i(TAG, "连接断开"); | |||
mList.add(TimeUtils.getTime() + "连接断开"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onServicesDiscovered(@NonNull String mac) { | |||
//TODO 连接成功(获取服务成功) | |||
BleLog.i(TAG, "连接成功(获取服务成功)"); | |||
mList.add(TimeUtils.getTime() + "连接成功"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
onServiceSuccess(); | |||
} | |||
@Override | |||
public void bleOpen() { | |||
mList.add(TimeUtils.getTime() + "蓝牙打开"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void bleClose() { | |||
BleLog.i(TAG, "蓝牙未开启,可请求开启"); | |||
mList.add(TimeUtils.getTime() + "蓝牙关闭"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
//-----------------通知------------------- | |||
@Override | |||
public void onData(byte[] hex, int type) { | |||
String data = ""; | |||
if (hex != null) | |||
data = BleStrUtils.byte2HexStr(hex); | |||
if (type == 100) { | |||
mList.add(TimeUtils.getTime() + "send->" + data); | |||
} else { | |||
mList.add(TimeUtils.getTime() + "notify->" + data); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onWeight(int weight, int decimal, byte unit, boolean stableStatus) { | |||
String unitStr = "kg"; | |||
switch (unit) { | |||
case BabyBodyFatBleConfig.BABY_KG: | |||
unitStr = "kg"; | |||
break; | |||
case BabyBodyFatBleConfig.BABY_FG: | |||
unitStr = "斤"; | |||
break; | |||
case BabyBodyFatBleConfig.BABY_LB: | |||
unitStr = "lb:oz"; | |||
break; | |||
case BabyBodyFatBleConfig.BABY_OZ: | |||
unitStr = "oz"; | |||
break; | |||
case BabyBodyFatBleConfig.BABY_ST: | |||
unitStr = "st:lb"; | |||
break; | |||
case BabyBodyFatBleConfig.BABY_G: | |||
unitStr = "g"; | |||
break; | |||
case BabyBodyFatBleConfig.BABY_LB_LB: | |||
unitStr = "LB"; | |||
break; | |||
} | |||
String weightStr = BleDensityUtil.getInstance().holdDecimals(weight, decimal); | |||
if (stableStatus) { | |||
mList.add(TimeUtils.getTime() + "稳定体重=" + weightStr + ";小数位=" + decimal + ";单位=" + unit + ";" + unitStr); | |||
} else { | |||
mList.add(TimeUtils.getTime() + "实时体重=" + weightStr + ";小数位=" + decimal + ";单位=" + unit + ";" + unitStr); | |||
} | |||
if (weightUnit != unit) { | |||
weightUnit = unit; | |||
showWeightUnit(weightUnit); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onHeight(int height, int decimal, byte unit, boolean stableStatus) { | |||
String heightStr = BleDensityUtil.getInstance().holdDecimals(height, decimal); | |||
String unitStr = "cm"; | |||
switch (unit) { | |||
case BabyBodyFatBleConfig.BABY_CM: | |||
unitStr = "cm"; | |||
break; | |||
case BabyBodyFatBleConfig.BABY_INCH: | |||
unitStr = "inch"; | |||
break; | |||
case BabyBodyFatBleConfig.BABY_FEET: | |||
unitStr = "foot"; | |||
break; | |||
} | |||
if (stableStatus) { | |||
mList.add(TimeUtils.getTime() + "稳定身高=" + heightStr + ";小数位=" + decimal + ";单位=" + unit + ";" + unitStr); | |||
} else { | |||
mList.add(TimeUtils.getTime() + "实时身高=" + heightStr + ";小数位=" + decimal + ";单位=" + unit + ";" + unitStr); | |||
} | |||
if (heightUnit != unit) { | |||
heightUnit = unit; | |||
showHeightUnit(heightUnit); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onImpedanceTesting() { | |||
BleLog.i(TAG, "测阻抗中"); | |||
mList.add(TimeUtils.getTime() + "测阻抗中..."); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onImpedanceSuccess(boolean appAlgorithm,int adc, int algorithmId) { | |||
BleLog.i(TAG, "测阻抗成功"); | |||
mList.add(TimeUtils.getTime() + "测阻抗成功,阻抗值:" + adc + " ,算法ID:" + algorithmId+" ;"+(appAlgorithm?"使用app算法":"使用秤算法")); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onImpedanceFailure() { | |||
BleLog.i(TAG, "测阻抗失败"); | |||
mList.add(TimeUtils.getTime() + "测阻抗失败..."); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onMeasurementCompleted() { | |||
mList.add(TimeUtils.getTime() + "测量完成"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getTare(byte status) { | |||
String data = ""; | |||
switch (status) { | |||
case 0: | |||
data = "去皮成功"; | |||
break; | |||
case 1: | |||
data = "去皮失败"; | |||
break; | |||
case 2: | |||
data = "不支持"; | |||
break; | |||
} | |||
mList.add(TimeUtils.getTime() + data); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getHold(byte status) { | |||
String data = ""; | |||
switch (status) { | |||
case 0: | |||
data = "锁定成功"; | |||
break; | |||
case 1: | |||
data = "锁定失败"; | |||
break; | |||
case 2: | |||
data = "不支持"; | |||
break; | |||
} | |||
mList.add(TimeUtils.getTime() + data); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getUnit(byte status) { | |||
String msg = ""; | |||
switch (status) { | |||
case CmdConfig.SETTING_SUCCESS: | |||
msg = "设置单位成功"; | |||
break; | |||
case CmdConfig.SETTING_FAILURE: | |||
msg = "设置单位失败"; | |||
break; | |||
case CmdConfig.SETTING_ERR: | |||
msg = "设置单位错误"; | |||
break; | |||
} | |||
mList.add(TimeUtils.getTime() + msg); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getErr(byte status) { | |||
String statusStr = ""; | |||
if (status == 0) { | |||
statusStr = "超重"; | |||
} else if (status == 1) { | |||
statusStr = "称重期间,重量不稳定"; | |||
} else if (status == 2) { | |||
statusStr = "称重失败"; | |||
} | |||
mList.add(TimeUtils.getTime() + "错误指令:" + status+" ;"+statusStr); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onBmVersion(String version) { | |||
mList.add(TimeUtils.getTime() + "版本号:" + version); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void OnDID(int cid, int vid, int pid) { | |||
String didStr = "cid:" + cid + "||vid:" + vid + "||pid:" + pid; | |||
mList.add(TimeUtils.getTime() + "ID:" + didStr); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onMcuBatteryStatus(int status, int battery) { | |||
mList.add(TimeUtils.getTime() + "电量:" + battery + "%"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onSysTime(int status, int[] times) { | |||
String time = times[0] + "-" + times[1] + "-" + times[2] + " " + times[3] + ":" + times[4] + ":" + times[5]; | |||
mList.add(TimeUtils.getTime() + "系统时间:" + time); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
protected void onDestroy() { | |||
super.onDestroy(); | |||
BleLog.i(TAG, "onDestroy"); | |||
} | |||
} |
@@ -12,6 +12,7 @@ import android.widget.RadioButton; | |||
import android.widget.RadioGroup; | |||
import android.widget.Toast; | |||
import com.pingwang.bluetoothlib.BleBaseActivity; | |||
import com.pingwang.bluetoothlib.bean.SupportUnitBean; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | |||
@@ -23,6 +24,7 @@ import com.pingwang.bluetoothlib.listener.OnMcuParameterListener; | |||
import com.pingwang.bluetoothlib.utils.BleDensityUtil; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
@@ -33,6 +35,7 @@ import cn.net.aicare.modulelibrary.module.babyscale.BabyBleConfig; | |||
import cn.net.aicare.modulelibrary.module.babyscale.BabyDeviceData; | |||
/** | |||
* xing<br> | |||
* 2019/4/25<br> | |||
@@ -315,8 +318,8 @@ public class BabyCmdActivity extends BleBaseActivity implements OnCallbackDis, O | |||
@Override | |||
public void getWeight(int weight, int decimal, byte unit) { | |||
String weightStr = BleDensityUtil.getInstance().holdNumber(weight, decimal); | |||
String showStr="稳定体重:" + weightStr + "|小数:" + decimal + "|单位:" + unit; | |||
String weightStr = BleDensityUtil.getInstance().holdDecimals(weight, decimal); | |||
String showStr="稳定体重:" + weightStr + "|小数位:" + decimal + "|单位:" + unit; | |||
mList.add(TimeUtils.getTime() + showStr); | |||
if (weightUnit != unit) { | |||
weightUnit = unit; | |||
@@ -327,8 +330,8 @@ public class BabyCmdActivity extends BleBaseActivity implements OnCallbackDis, O | |||
@Override | |||
public void getWeightNow(int weight, int decimal, byte unit) { | |||
String weightStr = BleDensityUtil.getInstance().holdNumber(weight, decimal); | |||
mList.add(TimeUtils.getTime() + "实时体重:" + weightStr + "|小数:" + decimal + "|单位:" + unit);//10.00,2,0 | |||
String weightStr = BleDensityUtil.getInstance().holdDecimals(weight, decimal); | |||
mList.add(TimeUtils.getTime() + "实时体重:" + weightStr + "|单位:" + unit);//10.00,2,0 | |||
if (weightUnit != unit) { | |||
weightUnit = unit; | |||
showWeightUnit(weightUnit); | |||
@@ -338,8 +341,8 @@ public class BabyCmdActivity extends BleBaseActivity implements OnCallbackDis, O | |||
@Override | |||
public void getHeight(int height, int decimal, byte unit) { | |||
String heightStr = BleDensityUtil.getInstance().holdNumber(height, decimal); | |||
mList.add(TimeUtils.getTime() + "稳定身高:" + heightStr + "|小数:" + decimal + "|单位:" + unit); | |||
String heightStr = BleDensityUtil.getInstance().holdDecimals(height, decimal); | |||
mList.add(TimeUtils.getTime() + "稳定身高:" + heightStr + "|单位:" + unit); | |||
if (heightUnit != unit) { | |||
heightUnit = unit; | |||
showHeightUnit(heightUnit); |
@@ -0,0 +1,546 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.content.Context; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import android.os.Message; | |||
import android.view.View; | |||
import android.view.WindowManager; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.EditText; | |||
import android.widget.ListView; | |||
import android.widget.Toast; | |||
import com.pingwang.bluetoothlib.BleBaseActivity; | |||
import com.pingwang.bluetoothlib.bean.SupportUnitBean; | |||
import com.pingwang.bluetoothlib.config.CmdConfig; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | |||
import com.pingwang.bluetoothlib.device.SendBleBean; | |||
import com.pingwang.bluetoothlib.listener.CallbackDisIm; | |||
import com.pingwang.bluetoothlib.listener.OnBleCompanyListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleDeviceDataListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleErrListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleHandshakeListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleInfoListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleOtherDataListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleParameterListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleSettingListener; | |||
import com.pingwang.bluetoothlib.listener.OnBleVersionListener; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackDis; | |||
import com.pingwang.bluetoothlib.listener.OnMcuParameterListener; | |||
import com.pingwang.bluetoothlib.utils.BleDataUtils; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.Locale; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
/** | |||
* xing<br> | |||
* 2019/4/25<br> | |||
* 基础指令信息数据显示 | |||
*/ | |||
public class BleCmdActivity extends BleBaseActivity implements OnCallbackDis, OnBleDeviceDataListener, OnBleVersionListener, OnMcuParameterListener, OnBleErrListener, OnBleInfoListener, | |||
OnBleParameterListener, OnBleCompanyListener, OnBleSettingListener, OnBleHandshakeListener, View.OnClickListener, OnBleOtherDataListener { | |||
private static String TAG = BleCmdActivity.class.getName(); | |||
private final int REFRESH_DATA = 3; | |||
private List<String> mList; | |||
private ArrayAdapter listAdapter; | |||
private EditText etName, etMacType, etDid, etBroadcastTime, etMcuType, etSleepTime; | |||
private Context mContext; | |||
private String mAddress; | |||
private BleSendCmdUtil mBleSendCmdUtil; | |||
private BleDataUtils bleDataUtils; | |||
private BleDevice mBleDevice; | |||
private int type; | |||
/** | |||
* 是否暂停显示数据 | |||
*/ | |||
private boolean mPauseShowCmd=false; | |||
private Handler mHandler = new Handler(Looper.getMainLooper()) { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
switch (msg.what) { | |||
case REFRESH_DATA: | |||
if (listAdapter != null) | |||
listAdapter.notifyDataSetChanged(); | |||
break; | |||
} | |||
} | |||
}; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_ble); | |||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); | |||
mContext = this; | |||
mAddress = getIntent().getStringExtra("mac"); | |||
type = getIntent().getIntExtra("type", -1); | |||
mBleSendCmdUtil = BleSendCmdUtil.getInstance(); | |||
init(); | |||
} | |||
private void init() { | |||
mList = new ArrayList<>(); | |||
ListView listView = findViewById(R.id.listview); | |||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | |||
listView.setAdapter(listAdapter); | |||
bleDataUtils = BleDataUtils.getInstance(); | |||
findViewById(R.id.btnClear).setOnClickListener(this); | |||
findViewById(R.id.btnPause).setOnClickListener(this); | |||
findViewById(R.id.btnHandshake).setOnClickListener(this); | |||
findViewById(R.id.btnVersion).setOnClickListener(this); | |||
findViewById(R.id.btnBattery).setOnClickListener(this); | |||
findViewById(R.id.btnTimeRead).setOnClickListener(this); | |||
findViewById(R.id.btnTimeWrite).setOnClickListener(this); | |||
findViewById(R.id.btnNameRead).setOnClickListener(this); | |||
findViewById(R.id.btnMacRead).setOnClickListener(this); | |||
findViewById(R.id.btnMacTypeRead).setOnClickListener(this); | |||
findViewById(R.id.btnNameWrite).setOnClickListener(this); | |||
findViewById(R.id.btnMacTypeWrite).setOnClickListener(this); | |||
findViewById(R.id.btnDidWrite).setOnClickListener(this); | |||
findViewById(R.id.btnDidRead).setOnClickListener(this); | |||
findViewById(R.id.btnBroadcastTimeWrite).setOnClickListener(this); | |||
findViewById(R.id.btnBroadcastTimeRead).setOnClickListener(this); | |||
findViewById(R.id.btnBmRestart).setOnClickListener(this); | |||
findViewById(R.id.btnBmReset).setOnClickListener(this); | |||
findViewById(R.id.btnMcuType).setOnClickListener(this); | |||
findViewById(R.id.btnUnits).setOnClickListener(this); | |||
findViewById(R.id.btnSleepTimeWrite).setOnClickListener(this); | |||
findViewById(R.id.btnSleepTimeRead).setOnClickListener(this); | |||
findViewById(R.id.btn_start_ble).setOnClickListener(this); | |||
etName = findViewById(R.id.etName); | |||
etMacType = findViewById(R.id.etMacType); | |||
etDid = findViewById(R.id.etDid); | |||
etBroadcastTime = findViewById(R.id.etBroadcastTime); | |||
etMcuType = findViewById(R.id.etMcuType); | |||
etSleepTime = findViewById(R.id.etSleepTime); | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
SendBleBean sendBleBean; | |||
switch (v.getId()) { | |||
case R.id.btnClear: | |||
if (mList != null) | |||
mList.clear(); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
break; | |||
case R.id.btnPause: | |||
mPauseShowCmd=!mPauseShowCmd; | |||
break; | |||
case R.id.btnHandshake: | |||
if (mBleDevice != null) | |||
mBleDevice.sendHandshake(); | |||
break; | |||
case R.id.btnVersion: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.getBleVersion()); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnBattery: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.getMcuBatteryStatus()); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnTimeRead: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.getSysTime()); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnTimeWrite: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.setSysTime(bleDataUtils.getCurrentTime(), true)); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnNameRead: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.getBleName()); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnMacRead: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.getBleMac()); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnMacTypeRead: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.getBroadcastDataType()); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnMacTypeWrite: | |||
byte macType = Byte.valueOf(etMacType.getText().toString().trim()); | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.setBroadcastDataType(macType)); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnNameWrite: | |||
byte[] names = bleDataUtils.getBleName(etName.getText().toString().trim()); | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.setBleName(names)); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnBroadcastTimeRead: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.getBleBroadcastTime()); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnBroadcastTimeWrite: | |||
int time = Integer.parseInt(etBroadcastTime.getText().toString().trim()); | |||
byte[] broadcastTime = bleDataUtils.getBroadcastTime(time); | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.setBleBroadcastTime(broadcastTime)); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnDidWrite: | |||
String didStr = etDid.getText().toString().trim().toLowerCase(Locale.US); | |||
if (didStr.contains(",")) { | |||
String[] didStrS = didStr.split(","); | |||
if (didStrS.length > 5) { | |||
int cidS = Integer.parseInt(didStrS[0]); | |||
int vidS = Integer.parseInt(didStrS[1]); | |||
int pidS = Integer.parseInt(didStrS[2]); | |||
int cid = Integer.parseInt(didStrS[3]); | |||
int vid = Integer.parseInt(didStrS[4]); | |||
int pid = Integer.parseInt(didStrS[5]); | |||
byte[] did = bleDataUtils.getDid(cidS, vidS, pidS, cid, vid, pid); | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.setDid(did)); | |||
sendData(sendBleBean); | |||
} | |||
} | |||
break; | |||
case R.id.btnDidRead: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.getDid()); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnBmRestart: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.setBleRestart()); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnBmReset: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.setBleReset()); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnMcuType: | |||
byte mode = (byte) Integer.parseInt(etMcuType.getText().toString().trim()); | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.setPortI2cSpiMode(mode)); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btnUnits: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.getSupportUnit()); | |||
sendData(sendBleBean); | |||
break; | |||
//写自动休眠 | |||
case R.id.btnSleepTimeWrite: | |||
String sleepStr = etSleepTime.getText().toString().trim().toLowerCase(Locale.US); | |||
if (sleepStr.contains(",")) { | |||
String[] didStrS = sleepStr.split(","); | |||
if (didStrS.length > 3) { | |||
int switchStatus = Integer.parseInt(didStrS[0]); | |||
int toSleepTimeS = Integer.parseInt(didStrS[1]); | |||
int sleepSwitchCmd = Integer.parseInt(didStrS[2]); | |||
int broadcastTimeMS = Integer.parseInt(didStrS[3]); | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.setNoConnectSleep(switchStatus, toSleepTimeS, sleepSwitchCmd, broadcastTimeMS)); | |||
sendData(sendBleBean); | |||
} | |||
} | |||
break; | |||
case R.id.btnSleepTimeRead: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.getNoConnectSleep()); | |||
sendData(sendBleBean); | |||
break; | |||
case R.id.btn_start_ble: | |||
sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.setToWake()); | |||
sendData(sendBleBean); | |||
break; | |||
} | |||
} | |||
private void sendData(SendBleBean sendBleBean) { | |||
if (mBleDevice != null) { | |||
mBleDevice.sendData(sendBleBean); | |||
} | |||
} | |||
//---------------------------------服务--------------------------------------------------- | |||
@Override | |||
public void onServiceSuccess() { | |||
mList.add(TimeUtils.getTime() + "服务与界面建立连接成功"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
CallbackDisIm.getInstance().addListListener(this); | |||
if (mBluetoothService != null) { | |||
mBleDevice = mBluetoothService.getBleDevice(mAddress); | |||
if (mBleDevice == null) { | |||
finish(); | |||
BleLog.i(TAG, "mBleDevice==null"); | |||
} | |||
mBleDevice.setOnBleVersionListener(this); | |||
// mBleDevice.setOnBleDeviceDataListener(this); | |||
mBleDevice.setOnBleErrListener(this); | |||
mBleDevice.setOnBleInfoListener(this); | |||
mBleDevice.setOnMcuParameterListener(this); | |||
mBleDevice.setOnBleSettingListener(this); | |||
mBleDevice.setOnBleCompanyListener(this); | |||
mBleDevice.setOnBleParameterListener(this); | |||
mBleDevice.setOnBleHandshakeListener(this); | |||
mBleDevice.setOnBleOtherDataListener(this); | |||
} | |||
} | |||
@Override | |||
public void onServiceErr() { | |||
mList.add(TimeUtils.getTime() + "服务与界面连接断开"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
mHandler.postDelayed(new Runnable() { | |||
@Override | |||
public void run() { | |||
finish(); | |||
} | |||
}, 3000); | |||
//与服务断开连接 | |||
mBluetoothService = null; | |||
} | |||
@Override | |||
public void unbindServices() { | |||
CallbackDisIm.getInstance().removeListener(this); | |||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | |||
if (bleDevice != null) { | |||
BleLog.i(TAG, "unbindService,断开连接"); | |||
bleDevice.disconnect(); | |||
} | |||
} | |||
//-----------------状态------------------- | |||
@Override | |||
public void onConnecting(@NonNull String mac) { | |||
//TODO 连接中 | |||
BleLog.i(TAG, "连接中"); | |||
} | |||
@Override | |||
public void onDisConnected(@NonNull String mac, int code) { | |||
//TODO 连接断开 | |||
BleLog.i(TAG, "连接断开"); | |||
if (mAddress.equals(mac)) { | |||
Toast.makeText(mContext, "连接断开:" + code, Toast.LENGTH_SHORT).show(); | |||
finish(); | |||
} | |||
} | |||
@Override | |||
public void onServicesDiscovered(@NonNull String mac) { | |||
//TODO 连接成功(获取服务成功) | |||
BleLog.i(TAG, "连接成功(获取服务成功)"); | |||
} | |||
@Override | |||
public void bleOpen() { | |||
} | |||
@Override | |||
public void bleClose() { | |||
BleLog.i(TAG, "蓝牙未开启,可请求开启"); | |||
} | |||
//--------------------------------- | |||
@Override | |||
public void onNotifyOtherData(byte[] data) { | |||
if (mPauseShowCmd){ | |||
return; | |||
} | |||
mList.add(TimeUtils.getTime() + "透传数据:" + BleStrUtils.byte2HexStr(data)); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onNotifyData(byte[] hex, int type) { | |||
if (mPauseShowCmd){ | |||
return; | |||
} | |||
String data = ""; | |||
if (hex != null) | |||
data = BleStrUtils.byte2HexStr(hex); | |||
if (type == 100) { | |||
mList.add(TimeUtils.getTime() + "send->" + data); | |||
} else { | |||
mList.add(TimeUtils.getTime() + "notify->" + data); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onHandshake(boolean status) { | |||
mList.add(TimeUtils.getTime() + "握手:" + status); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onBmVersion(String version) { | |||
mList.add(TimeUtils.getTime() + "版本号:" + version); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onSupportUnit(List<SupportUnitBean> list) { | |||
StringBuilder unitStr = new StringBuilder(); | |||
unitStr.append(TimeUtils.getTime()); | |||
for (SupportUnitBean supportUnitBean : list) { | |||
unitStr.append("单位类型:").append(supportUnitBean.getType()); | |||
StringBuilder units = new StringBuilder(); | |||
units.append("["); | |||
for (Integer integer1 : supportUnitBean.getSupportUnit()) { | |||
units.append(integer1).append(","); | |||
} | |||
units.append("]"); | |||
unitStr.append("单位列表:").append(units); | |||
unitStr.append("\n"); | |||
} | |||
mList.add(unitStr.toString()); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onMcuBatteryStatus(int status, int battery) { | |||
mList.add(TimeUtils.getTime() + "电量:" + battery + "%" + "||状态:" + status); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onSysTime(int status, int[] times) { | |||
String timeStr = times[0] + "-" + times[1] + "-" + times[2] + " " + times[3] + ":" + times[4] + ":" + times[5]; | |||
mList.add(TimeUtils.getTime() + "时间:" + timeStr + "||是否有效:" + status); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onErr(int cmdType) { | |||
mList.add(TimeUtils.getTime() + "错误:" + cmdType); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void OnSettingReturn(byte cmdType, byte cmdData) { | |||
if (CmdConfig.SET_TO_SLEEP == cmdType && cmdData == CmdConfig.SETTING_SUCCESS) { | |||
//进入睡眠 | |||
} | |||
mList.add(TimeUtils.getTime() + "设置指令:" + cmdType + "||结果:" + cmdData); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onBleName(String name) { | |||
mList.add(TimeUtils.getTime() + "名称:" + name); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onBleMac(String mac) { | |||
mList.add(TimeUtils.getTime() + "Mac:" + mac); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onNoConnectSleep(int sleepSwitch, int sleepTime, int sleepBroadcastSwitch, int sleepBroadcastTime) { | |||
mList.add(TimeUtils.getTime() + "sleepSwitch:" + sleepSwitch + " ||sleepTime:" + sleepTime + " ||sleepBroadcastSwitch:" + sleepBroadcastSwitch + " ||sleepBroadcastTime:" + sleepBroadcastTime); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void OnDID(int cid, int vid, int pid) { | |||
mList.add(TimeUtils.getTime() + "cid:" + cid + "||vid:" + vid + "||pid:" + pid); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onBleBroadcastTime(int time) { | |||
mList.add(TimeUtils.getTime() + "广播间隔:" + time); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onConnectTime(int time, int status, int timeOut) { | |||
mList.add(TimeUtils.getTime() + "连接:time:" + time + "||status:" + status + "||timeOut:" + timeOut); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onBlePower(int power) { | |||
mList.add(TimeUtils.getTime() + "功率:" + power); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onPortRate(int rate) { | |||
mList.add(TimeUtils.getTime() + "串口波特率:" + rate); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onBroadcastDataType(int type) { | |||
mList.add(TimeUtils.getTime() + "广播大小端:" + type); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onModuleUUID(int length, String serverUUID, String featureUUID1, String featureUUID2) { | |||
mList.add(TimeUtils.getTime() + "UUID:length:" + length + "||serverUUID:" + serverUUID + "||featureUUID1:" + featureUUID1 + "||featureUUID2" + featureUUID2); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onBleMode(int mode) { | |||
mList.add(TimeUtils.getTime() + "模式:" + mode); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
protected void onDestroy() { | |||
super.onDestroy(); | |||
BleLog.i(TAG, "onDestroy"); | |||
} | |||
} |
@@ -21,7 +21,7 @@ import java.util.List; | |||
import cn.net.aicare.modulelibrary.module.BloodGlucose.BloodGlucoseBleDeviceData; | |||
import cn.net.aicare.modulelibrary.module.BloodGlucose.BloodGlucoseUtil; | |||
public class BloodGlucoseActivity extends BleBaseActivity implements OnCallbackBle, BloodGlucoseBleDeviceData.BloodGlucoseCallback{ | |||
public class BloodGlucoseActivity extends BleBaseActivity implements OnCallbackBle ,BloodGlucoseBleDeviceData.BloodGlucoseCallback{ | |||
private Button support_unit, quest_status,showdata; | |||
private RadioButton mmol, mg; |
@@ -0,0 +1,239 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.content.Context; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import android.os.Message; | |||
import android.text.TextUtils; | |||
import android.view.View; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.ListView; | |||
import android.widget.TextView; | |||
import com.pingwang.bluetoothlib.BleBaseActivity; | |||
import com.pingwang.bluetoothlib.bean.BleValueBean; | |||
import com.pingwang.bluetoothlib.config.BleConfig; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackDis; | |||
import com.pingwang.bluetoothlib.listener.OnScanFilterListener; | |||
import com.pingwang.bluetoothlib.utils.BleDensityUtil; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.UUID; | |||
import androidx.annotation.Nullable; | |||
import cn.net.aicare.modulelibrary.module.BloodOxygen.BroadcastBloodOxygenBleConfig; | |||
import cn.net.aicare.modulelibrary.module.BloodOxygen.BroadcastBloodOxygenDeviceData; | |||
/** | |||
* xing<br> | |||
* 2020/09/09<br> | |||
* 广播血氧仪 | |||
*/ | |||
public class BroadcastBloodOxygenActivity extends BleBaseActivity implements OnCallbackDis, BroadcastBloodOxygenDeviceData.onNotifyData, OnScanFilterListener, View.OnClickListener { | |||
private static String TAG = BroadcastBloodOxygenActivity.class.getName(); | |||
private final int REFRESH_DATA = 3; | |||
private TextView tv_broadcast_blood_oxygen, tv_broadcast_mac; | |||
private List<String> mList; | |||
private ArrayAdapter listAdapter; | |||
private Context mContext; | |||
private BroadcastBloodOxygenDeviceData mDevice; | |||
private String mAddress = ""; | |||
private Handler mHandler = new Handler(Looper.getMainLooper()) { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
switch (msg.what) { | |||
case REFRESH_DATA: | |||
if (listAdapter != null) | |||
listAdapter.notifyDataSetChanged(); | |||
break; | |||
} | |||
} | |||
}; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_broadcast_blood_oxygen); | |||
mContext = this; | |||
init(); | |||
} | |||
private void init() { | |||
mList = new ArrayList<>(); | |||
ListView listView = findViewById(R.id.listview); | |||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | |||
listView.setAdapter(listAdapter); | |||
findViewById(R.id.clear).setOnClickListener(this); | |||
findViewById(R.id.open).setOnClickListener(this); | |||
findViewById(R.id.stop).setOnClickListener(this); | |||
tv_broadcast_blood_oxygen = findViewById(R.id.tv_broadcast_blood_oxygen); | |||
tv_broadcast_mac = findViewById(R.id.tv_broadcast_mac); | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
switch (v.getId()) { | |||
case R.id.clear: | |||
if (mList != null) | |||
mList.clear(); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
break; | |||
case R.id.open: | |||
if (mBluetoothService != null) { | |||
mBluetoothService.scanLeDevice(0, UUID.fromString("0000F0A0-0000-1000-8000-00805F9B34FB")); | |||
} | |||
break; | |||
case R.id.stop: | |||
if (mBluetoothService != null) { | |||
mBluetoothService.stopScan(); | |||
} | |||
break; | |||
} | |||
} | |||
//---------------------------------服务--------------------------------------------------- | |||
@Override | |||
public void onServiceSuccess() { | |||
BleLog.i(TAG, "服务与界面建立连接成功"); | |||
//与服务建立连接 | |||
if (mBluetoothService != null) { | |||
mDevice = BroadcastBloodOxygenDeviceData.getInstance(); | |||
mDevice.setOnNotifyData(this); | |||
mBluetoothService.setOnScanFilterListener(this); | |||
mBluetoothService.scanLeDevice(0, BleConfig.UUID_SERVER_BROADCAST); | |||
} | |||
} | |||
@Override | |||
public void onServiceErr() { | |||
BleLog.i(TAG, "服务与界面连接断开"); | |||
//与服务断开连接 | |||
mBluetoothService = null; | |||
} | |||
@Override | |||
public void unbindServices() { | |||
if (mDevice != null) { | |||
mDevice.clear(); | |||
mDevice = null; | |||
} | |||
} | |||
//-----------------状态------------------- | |||
@Override | |||
public void bleOpen() { | |||
mList.add(TimeUtils.getTime() + "蓝牙打开"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void bleClose() { | |||
BleLog.i(TAG, "蓝牙未开启,可请求开启"); | |||
mList.add(TimeUtils.getTime() + "蓝牙关闭"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
//-----------------通知------------------- | |||
@Override | |||
public void getBloodOxygenData(int status, int bloodOxygen, int pulseRate, int plethysmogram, int power) { | |||
String statusStr = "状态="; | |||
switch (status) { | |||
case BroadcastBloodOxygenBleConfig.START_TESTING: | |||
statusStr += "开始测试"; | |||
break; | |||
case BroadcastBloodOxygenBleConfig.TESTING: | |||
statusStr += "正在测试"; | |||
break; | |||
case BroadcastBloodOxygenBleConfig.STOP_TESTING: | |||
statusStr += "测试完成"; | |||
break; | |||
} | |||
String bloodOxygenStr = "--%"; | |||
if (bloodOxygen != 0xFF) { | |||
bloodOxygenStr = bloodOxygen + "%"; | |||
} | |||
String pulseRateStr = "--%"; | |||
if (pulseRate != 0xFF) { | |||
pulseRateStr = pulseRate + "%"; | |||
} | |||
String plethysmogramStr = BleDensityUtil.getInstance().holdDecimals(plethysmogram, 1); | |||
String showData = TimeUtils.getTime(); | |||
showData += statusStr; | |||
showData += "\n血氧=" + bloodOxygenStr + ";脉率=" + pulseRateStr + ";PI=" + plethysmogramStr + ";电量=" + power + "%"; | |||
tv_broadcast_blood_oxygen.setText(bloodOxygenStr); | |||
mList.add(showData); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void OnDID(int cid, int vid, int pid) { | |||
String didStr = "cid:" + cid + "||vid:" + vid + "||pid:" + pid; | |||
mList.add(TimeUtils.getTime() + "ID:" + didStr); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
protected void onDestroy() { | |||
super.onDestroy(); | |||
BleLog.i(TAG, "onDestroy"); | |||
} | |||
@Override | |||
public boolean onFilter(BleValueBean bleValueBean) { | |||
return true; | |||
} | |||
@Override | |||
public void onScanRecord(BleValueBean bleValueBean) { | |||
if (TextUtils.isEmpty(mAddress) && bleValueBean.isBroadcastModule()) { | |||
mAddress = bleValueBean.getMac(); | |||
if (tv_broadcast_mac != null) { | |||
tv_broadcast_mac.setText(mAddress); | |||
} | |||
} | |||
//地址相同,并且是广播秤 | |||
if (mAddress.equalsIgnoreCase(bleValueBean.getMac()) && bleValueBean.isBroadcastModule()) { | |||
byte[] manufacturerData = bleValueBean.getManufacturerData(); | |||
int cid = bleValueBean.getCid(); | |||
int vid = bleValueBean.getVid(); | |||
int pid = bleValueBean.getPid(); | |||
if (mDevice != null) | |||
mDevice.onNotifyData(manufacturerData, cid, vid, pid); | |||
} | |||
} | |||
} |
@@ -0,0 +1,388 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.content.Context; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import android.os.Message; | |||
import android.text.TextUtils; | |||
import android.view.View; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.ListView; | |||
import android.widget.RadioButton; | |||
import android.widget.RadioGroup; | |||
import android.widget.TextView; | |||
import com.pingwang.bluetoothlib.BleBaseActivity; | |||
import com.pingwang.bluetoothlib.bean.BleValueBean; | |||
import com.pingwang.bluetoothlib.config.BleConfig; | |||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackDis; | |||
import com.pingwang.bluetoothlib.listener.OnScanFilterListener; | |||
import com.pingwang.bluetoothlib.utils.BleDensityUtil; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.UUID; | |||
import androidx.annotation.Nullable; | |||
import cn.net.aicare.modulelibrary.module.BroadcastScale.BroadcastScaleBleConfig; | |||
import cn.net.aicare.modulelibrary.module.BroadcastScale.BroadcastScaleDeviceData; | |||
import cn.net.aicare.modulelibrary.module.babyscale.BabyBleConfig; | |||
/** | |||
* xing<br> | |||
* 2020/08/10<br> | |||
* 广播秤 | |||
*/ | |||
public class BroadcastScaleActivity extends BleBaseActivity implements OnCallbackDis, BroadcastScaleDeviceData.onNotifyData, OnScanFilterListener, View.OnClickListener, | |||
RadioGroup.OnCheckedChangeListener { | |||
private static String TAG = BroadcastScaleActivity.class.getName(); | |||
private final int REFRESH_DATA = 3; | |||
private RadioButton mRadioButtonKg, mRadioButtonLb, mRadioButtonLbLb, mRadioButtonG, mRadioButtonOz, mRadioButtonStLb, mRadioButtonJin; | |||
private TextView tv_broadcast_temp, tv_broadcast_mac; | |||
private List<String> mList; | |||
private ArrayAdapter listAdapter; | |||
private Context mContext; | |||
private BroadcastScaleDeviceData mDevice; | |||
private String mAddress = ""; | |||
private BleSendCmdUtil mBleSendCmdUtil; | |||
private int type = BroadcastScaleBleConfig.BROADCAST_SCALE; | |||
private int mWeightUnit = 0; | |||
private int mTemp; | |||
private Handler mHandler = new Handler(Looper.getMainLooper()) { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
switch (msg.what) { | |||
case REFRESH_DATA: | |||
if (listAdapter != null) | |||
listAdapter.notifyDataSetChanged(); | |||
break; | |||
} | |||
} | |||
}; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_broadcast_scale); | |||
mContext = this; | |||
// mAddress = getIntent().getStringExtra("mac"); | |||
mBleSendCmdUtil = BleSendCmdUtil.getInstance(); | |||
init(); | |||
} | |||
private void init() { | |||
mList = new ArrayList<>(); | |||
ListView listView = findViewById(R.id.listview); | |||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | |||
listView.setAdapter(listAdapter); | |||
findViewById(R.id.clear).setOnClickListener(this); | |||
findViewById(R.id.open).setOnClickListener(this); | |||
findViewById(R.id.stop).setOnClickListener(this); | |||
((RadioGroup) findViewById(R.id.radio_weight)).setOnCheckedChangeListener(this); | |||
tv_broadcast_temp = findViewById(R.id.tv_broadcast_temp); | |||
mRadioButtonKg = findViewById(R.id.radio_weight_kg); | |||
mRadioButtonJin = findViewById(R.id.radio_weight_jin); | |||
mRadioButtonStLb = findViewById(R.id.radio_weight_st_lb); | |||
mRadioButtonLb = findViewById(R.id.radio_weight_lb); | |||
mRadioButtonOz = findViewById(R.id.radio_weight_oz); | |||
mRadioButtonG = findViewById(R.id.radio_weight_g); | |||
mRadioButtonLbLb = findViewById(R.id.radio_weight_lb_lb); | |||
tv_broadcast_mac = findViewById(R.id.tv_broadcast_mac); | |||
} | |||
@Override | |||
public void onCheckedChanged(RadioGroup group, int checkedId) { | |||
if (checkedId == -1) | |||
return;//不是人为点击不触发 | |||
switch (group.getCheckedRadioButtonId()) { | |||
case R.id.radio_weight_kg: | |||
mWeightUnit = BabyBleConfig.BABY_KG; | |||
break; | |||
case R.id.radio_weight_jin: | |||
mWeightUnit = BabyBleConfig.BABY_FG; | |||
break; | |||
case R.id.radio_weight_lb: | |||
mWeightUnit = BabyBleConfig.BABY_LB; | |||
break; | |||
case R.id.radio_weight_oz: | |||
mWeightUnit = BabyBleConfig.BABY_OZ; | |||
break; | |||
case R.id.radio_weight_st_lb: | |||
mWeightUnit = BabyBleConfig.BABY_ST; | |||
break; | |||
case R.id.radio_weight_g: | |||
mWeightUnit = BabyBleConfig.BABY_G; | |||
break; | |||
case R.id.radio_weight_lb_lb: | |||
mWeightUnit = BabyBleConfig.BABY_LB_LB; | |||
break; | |||
} | |||
BleLog.i(TAG, "weightUnit:" + mWeightUnit); | |||
} | |||
private void showWeightUnit(int unit) { | |||
switch (unit) { | |||
case BabyBleConfig.BABY_KG: | |||
mRadioButtonKg.setChecked(true); | |||
break; | |||
case BabyBleConfig.BABY_FG: | |||
mRadioButtonJin.setChecked(true); | |||
break; | |||
case BabyBleConfig.BABY_LB: | |||
mRadioButtonLb.setChecked(true); | |||
break; | |||
case BabyBleConfig.BABY_OZ: | |||
mRadioButtonOz.setChecked(true); | |||
break; | |||
case BabyBleConfig.BABY_ST: | |||
mRadioButtonStLb.setChecked(true); | |||
break; | |||
case BabyBleConfig.BABY_G: | |||
mRadioButtonG.setChecked(true); | |||
break; | |||
case BabyBleConfig.BABY_LB_LB: | |||
mRadioButtonLbLb.setChecked(true); | |||
break; | |||
} | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
switch (v.getId()) { | |||
case R.id.clear: | |||
if (mList != null) | |||
mList.clear(); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
break; | |||
case R.id.open: | |||
if (mBluetoothService != null) { | |||
mBluetoothService.scanLeDevice(0, UUID.fromString("0000F0A0-0000-1000-8000-00805F9B34FB")); | |||
} | |||
break; | |||
case R.id.stop: | |||
if (mBluetoothService != null) { | |||
mBluetoothService.stopScan(); | |||
} | |||
break; | |||
} | |||
} | |||
//---------------------------------服务--------------------------------------------------- | |||
@Override | |||
public void onServiceSuccess() { | |||
BleLog.i(TAG, "服务与界面建立连接成功"); | |||
//与服务建立连接 | |||
if (mBluetoothService != null) { | |||
mDevice = BroadcastScaleDeviceData.getInstance(); | |||
mDevice.setOnNotifyData(this); | |||
mBluetoothService.setOnScanFilterListener(this); | |||
mBluetoothService.scanLeDevice(0, BleConfig.UUID_SERVER_BROADCAST); | |||
} | |||
} | |||
@Override | |||
public void onServiceErr() { | |||
BleLog.i(TAG, "服务与界面连接断开"); | |||
//与服务断开连接 | |||
mBluetoothService = null; | |||
} | |||
@Override | |||
public void unbindServices() { | |||
if (mDevice != null) { | |||
mDevice.clear(); | |||
mDevice = null; | |||
} | |||
} | |||
//-----------------状态------------------- | |||
@Override | |||
public void bleOpen() { | |||
mList.add(TimeUtils.getTime() + "蓝牙打开"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void bleClose() { | |||
BleLog.i(TAG, "蓝牙未开启,可请求开启"); | |||
mList.add(TimeUtils.getTime() + "蓝牙关闭"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
//-----------------通知------------------- | |||
@Override | |||
public void onData(byte[] hex, int type) { | |||
String data = ""; | |||
if (hex != null) | |||
data = BleStrUtils.byte2HexStr(hex); | |||
if (type == 100) { | |||
mList.add(TimeUtils.getTime() + "send->" + data); | |||
} else { | |||
mList.add(TimeUtils.getTime() + "notify->" + data); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void getWeightData(int status, int tempUnit, int weightUnit, int weightDecimal, int weightStatus, int weightNegative, int weight, int adc, int algorithmId, int tempNegative, int temp) { | |||
String weightUnitStr = "kg"; | |||
switch (weightUnit) { | |||
case BroadcastScaleBleConfig.UNIT_KG: | |||
weightUnitStr = "kg"; | |||
break; | |||
case BroadcastScaleBleConfig.UNIT_FG: | |||
weightUnitStr = "斤"; | |||
break; | |||
case BroadcastScaleBleConfig.UNIT_LB: | |||
weightUnitStr = "lb:oz"; | |||
break; | |||
case BroadcastScaleBleConfig.UNIT_OZ: | |||
weightUnitStr = "oz"; | |||
break; | |||
case BroadcastScaleBleConfig.UNIT_ST: | |||
weightUnitStr = "st:lb"; | |||
break; | |||
case BroadcastScaleBleConfig.UNIT_G: | |||
weightUnitStr = "g"; | |||
break; | |||
case BroadcastScaleBleConfig.UNIT_LB_LB: | |||
weightUnitStr = "LB"; | |||
break; | |||
} | |||
String tempUnitStr = "℃";//℉ | |||
switch (tempUnit) { | |||
case BroadcastScaleBleConfig.UNIT_C: | |||
tempUnitStr = "℃"; | |||
break; | |||
case BroadcastScaleBleConfig.UNIT_F: | |||
tempUnitStr = "℉"; | |||
break; | |||
} | |||
String statusStr = "状态="; | |||
switch (status) { | |||
case BroadcastScaleBleConfig.GET_WEIGHT_TESTING: | |||
statusStr += "正在测量体重"; | |||
break; | |||
case BroadcastScaleBleConfig.GET_IMPEDANCE_TESTING: | |||
statusStr += "测阻抗中"; | |||
break; | |||
case BroadcastScaleBleConfig.GET_IMPEDANCE_SUCCESS: | |||
statusStr += "测阻抗成功"; | |||
break; | |||
case BroadcastScaleBleConfig.GET_IMPEDANCE_FAIL: | |||
statusStr += "测阻抗失败"; | |||
break; | |||
case BroadcastScaleBleConfig.GET_TEST_FINISH: | |||
statusStr += "测量完成"; | |||
break; | |||
} | |||
String weightStr = BleDensityUtil.getInstance().holdDecimals(weight, 1); | |||
if (weightNegative == 1) { | |||
weightStr = "-" + weightStr; | |||
} | |||
String showData = TimeUtils.getTime(); | |||
showData += statusStr; | |||
if (weightStatus == 1) { | |||
showData += "\n稳定体重=" + weightStr + ";小数位=" + weightDecimal + ";单位=" + weightUnit + ";" + weightUnitStr; | |||
} else { | |||
showData += "\n实时体重=" + weightStr + ";小数位=" + weightDecimal + ";单位=" + weightUnit + ";" + weightUnitStr; | |||
} | |||
showData += "\n阻抗=" + adc; | |||
if (tempNegative == 1) { | |||
showData += "\n温度=" + (-temp / 10F) + tempUnitStr; | |||
} else { | |||
showData += "\n温度=" + (temp / 10F) + tempUnitStr; | |||
} | |||
showData += "\n算法ID=" + algorithmId; | |||
if (mWeightUnit != weightUnit) { | |||
mWeightUnit = weightUnit; | |||
showWeightUnit(mWeightUnit); | |||
} | |||
if (mTemp != temp) { | |||
mTemp = temp; | |||
tv_broadcast_temp.setText((mTemp / 10F) + tempUnitStr); | |||
} | |||
mList.add(showData); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void OnDID(int cid, int vid, int pid) { | |||
String didStr = "cid:" + cid + "||vid:" + vid + "||pid:" + pid; | |||
mList.add(TimeUtils.getTime() + "ID:" + didStr); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
protected void onDestroy() { | |||
super.onDestroy(); | |||
BleLog.i(TAG, "onDestroy"); | |||
} | |||
@Override | |||
public boolean onFilter(BleValueBean bleValueBean) { | |||
return true; | |||
} | |||
@Override | |||
public void onScanRecord(BleValueBean bleValueBean) { | |||
if (TextUtils.isEmpty(mAddress)&&bleValueBean.isBroadcastModule()) { | |||
mAddress = bleValueBean.getMac(); | |||
if (tv_broadcast_mac != null) { | |||
tv_broadcast_mac.setText(mAddress); | |||
} | |||
} | |||
//地址相同,并且是广播秤 | |||
if (mAddress.equalsIgnoreCase(bleValueBean.getMac()) && bleValueBean.isBroadcastModule()) { | |||
byte[] manufacturerData = bleValueBean.getManufacturerData(); | |||
int cid = bleValueBean.getCid(); | |||
int vid = bleValueBean.getVid(); | |||
int pid = bleValueBean.getPid(); | |||
if (mDevice != null) | |||
mDevice.onNotifyData(manufacturerData, cid, vid, pid); | |||
} | |||
} | |||
} |
@@ -0,0 +1,300 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.content.ComponentName; | |||
import android.content.Context; | |||
import android.content.Intent; | |||
import android.content.ServiceConnection; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.IBinder; | |||
import android.os.Looper; | |||
import android.os.Message; | |||
import android.view.View; | |||
import android.widget.AdapterView; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.Button; | |||
import android.widget.ListView; | |||
import android.widget.Toast; | |||
import com.pingwang.bluetoothlib.bean.BleValueBean; | |||
import com.pingwang.bluetoothlib.listener.CallbackDisIm; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | |||
import com.pingwang.bluetoothlib.server.ELinkBleServer; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.LoadingIosDialogFragment; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import androidx.appcompat.app.AppCompatActivity; | |||
/** | |||
* xing<br> | |||
* 2019/3/6<br> | |||
* java类作用描述 | |||
*/ | |||
public class ConnectBleTestActivity extends AppCompatActivity implements OnCallbackBle { | |||
private static String TAG = ConnectBleTestActivity.class.getName(); | |||
private final int BIND_SERVER_OK = 1; | |||
private final int BIND_SERVER_ERR = 2; | |||
private final int REFRESH_LIST = 3; | |||
private final int REFRESH_DATA = 4; | |||
private List<String> mList; | |||
private List<String> mListData; | |||
private ArrayAdapter listAdapter; | |||
private ArrayAdapter listDataAdapter; | |||
private ELinkBleServer mBluetoothService; | |||
/** | |||
* 服务Intent | |||
*/ | |||
private Intent bindIntent; | |||
private Context mContext; | |||
private boolean mFilter = true; | |||
private long mConnectTime = 0; | |||
private Handler mHandler = new Handler(Looper.getMainLooper()) { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
switch (msg.what) { | |||
case BIND_SERVER_OK: | |||
break; | |||
case REFRESH_LIST: | |||
listAdapter.notifyDataSetChanged(); | |||
break; | |||
case REFRESH_DATA: | |||
listDataAdapter.notifyDataSetChanged(); | |||
break; | |||
} | |||
} | |||
}; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_connect_ble_test); | |||
Intent mUserService = new Intent(this.getApplicationContext(), ELinkBleServer.class); | |||
//核心用户服务 | |||
startService(mUserService); | |||
mContext = this; | |||
init(); | |||
initData(); | |||
} | |||
private void initData() { | |||
bindService(); | |||
} | |||
private void init() { | |||
mList = new ArrayList<>(); | |||
mListData = new ArrayList<>(); | |||
ListView listView = findViewById(R.id.listview); | |||
ListView listviewData = findViewById(R.id.listviewData); | |||
Button btn = findViewById(R.id.btn); | |||
Button btn1 = findViewById(R.id.btn1); | |||
Button clear = findViewById(R.id.clear); | |||
findViewById(R.id.clearData).setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
mListData.clear(); | |||
listDataAdapter.notifyDataSetChanged(); | |||
} | |||
}); | |||
final Button filter = findViewById(R.id.filter); | |||
filter.setTag(true); | |||
btn.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
if (mBluetoothService != null) { | |||
BleLog.i(TAG, "搜索设备"); | |||
mBluetoothService.scanLeDevice(30000); | |||
mList.clear(); | |||
listAdapter.notifyDataSetChanged(); | |||
} | |||
} | |||
}); | |||
btn1.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
if (mBluetoothService != null) { | |||
mBluetoothService.stopScan(); | |||
mBluetoothService.disconnectAll(); | |||
} | |||
} | |||
}); | |||
clear.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
if (mBluetoothService != null) { | |||
mList.clear(); | |||
listAdapter.notifyDataSetChanged(); | |||
} | |||
} | |||
}); | |||
filter.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
boolean m = (Boolean) filter.getTag(); | |||
filter.setTag(!m); | |||
mFilter = !m; | |||
filter.setText("过滤:" + mFilter); | |||
} | |||
}); | |||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | |||
listView.setAdapter(listAdapter); | |||
listDataAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mListData); | |||
listviewData.setAdapter(listDataAdapter); | |||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { | |||
@Override | |||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | |||
String itemStr = mList.get(position); | |||
String mac = itemStr.split("=")[0]; | |||
if (mBluetoothService != null) { | |||
mBluetoothService.stopScan(); | |||
mBluetoothService.disconnectAll(); | |||
mBluetoothService.connectDevice(mac); | |||
mConnectTime = System.currentTimeMillis(); | |||
showLoading(); | |||
} | |||
} | |||
}); | |||
findViewById(R.id.跳过).setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
Toast.makeText(mContext, "跳过", Toast.LENGTH_SHORT).show(); | |||
} | |||
}); | |||
} | |||
//---------------------------------服务--------------------------------------------------- | |||
private void bindService() { | |||
BleLog.i(TAG, "绑定服务"); | |||
if (bindIntent == null) { | |||
bindIntent = new Intent(mContext, ELinkBleServer.class); | |||
if (mFhrSCon != null) | |||
this.bindService(bindIntent, mFhrSCon, Context.BIND_AUTO_CREATE); | |||
} | |||
} | |||
private void unbindService() { | |||
CallbackDisIm.getInstance().removeListener(this); | |||
if (mFhrSCon != null) | |||
this.unbindService(mFhrSCon); | |||
bindIntent = null; | |||
} | |||
/** | |||
* 服务连接与界面的连接 | |||
*/ | |||
private ServiceConnection mFhrSCon = new ServiceConnection() { | |||
@Override | |||
public void onServiceConnected(ComponentName name, IBinder service) { | |||
BleLog.i(TAG, "服务与界面建立连接成功"); | |||
//与服务建立连接 | |||
mBluetoothService = ((ELinkBleServer.BluetoothBinder) service).getService(); | |||
if (mBluetoothService != null) { | |||
mBluetoothService.setOnCallback(ConnectBleTestActivity.this); | |||
mBluetoothService.setOnScanFilterListener(null); | |||
mHandler.sendEmptyMessage(BIND_SERVER_OK); | |||
} | |||
} | |||
@Override | |||
public void onServiceDisconnected(ComponentName name) { | |||
BleLog.i(TAG, "服务与界面连接断开"); | |||
//与服务断开连接 | |||
mBluetoothService = null; | |||
} | |||
}; | |||
@Override | |||
public void onStartScan() { | |||
} | |||
@Override | |||
public void onScanning(@NonNull BleValueBean data) { | |||
String mAddress = data.getMac(); | |||
if (!mList.contains(mAddress + "=" + data.getName())) { | |||
String data1 = BleStrUtils.byte2HexStr(data.getScanRecord()); | |||
BleLog.i(TAG, "设备地址+广播数据:" + mAddress + "||" + data1); | |||
mList.add(mAddress + "=" + data.getName()); | |||
listAdapter.notifyDataSetChanged(); | |||
} | |||
} | |||
@Override | |||
public void onConnecting(@NonNull String mac) { | |||
} | |||
@Override | |||
public void onDisConnected(@NonNull String mac, int code) { | |||
dismissLoading(); | |||
Toast.makeText(mContext, "连接断开:" + code, Toast.LENGTH_SHORT).show(); | |||
} | |||
@Override | |||
public void onServicesDiscovered(@NonNull String mac) { | |||
long time = System.currentTimeMillis() - mConnectTime; | |||
dismissLoading(); | |||
mListData.add(TimeUtils.getTime() + "连接成功获取服务成功:" + time); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void bleOpen() { | |||
} | |||
@Override | |||
public void bleClose() { | |||
} | |||
//--------------------------start Loading-------------------------- | |||
private LoadingIosDialogFragment mDialogFragment; | |||
/** | |||
* 显示加载 | |||
*/ | |||
private void showLoading() { | |||
if (mDialogFragment == null) | |||
mDialogFragment = new LoadingIosDialogFragment(); | |||
mDialogFragment.show(getSupportFragmentManager()); | |||
} | |||
/** | |||
* 关闭加载 | |||
*/ | |||
private void dismissLoading() { | |||
if (mDialogFragment != null) | |||
mDialogFragment.dismiss(); | |||
} | |||
//--------------------------end Loading-------------------------- | |||
@Override | |||
protected void onDestroy() { | |||
super.onDestroy(); | |||
unbindService(); | |||
} | |||
} |
@@ -0,0 +1,333 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.os.Bundle; | |||
import android.view.View; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.CompoundButton; | |||
import android.widget.ListView; | |||
import android.widget.RadioButton; | |||
import com.pingwang.bluetoothlib.BleBaseActivity; | |||
import com.pingwang.bluetoothlib.bean.SupportUnitBean; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import androidx.annotation.Nullable; | |||
import cn.net.aicare.modulelibrary.module.EightBodyfatscale.EightBodyFatBleDeviceData; | |||
import cn.net.aicare.modulelibrary.module.EightBodyfatscale.EightBodyfatUtil; | |||
public class EightBodyfatActivity extends BleBaseActivity implements View.OnClickListener, OnCallbackBle, EightBodyFatBleDeviceData.EightBodyFatCallback { | |||
private List<String> loglist; | |||
private ListView log_list; | |||
private ArrayAdapter listAdapter; | |||
private String mAddress; | |||
private EightBodyFatBleDeviceData mEightBodyFatBleDeviceData; | |||
private RadioButton kg, jing, stlb, lb, C, F; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_eight_body_fata); | |||
mAddress = getIntent().getStringExtra("mac"); | |||
init(); | |||
loglist = new ArrayList<>(); | |||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, loglist); | |||
log_list.setAdapter(listAdapter); | |||
} | |||
private void init() { | |||
log_list = findViewById(R.id.log_list); | |||
kg = findViewById(R.id.kg); | |||
jing = findViewById(R.id.jin); | |||
stlb = findViewById(R.id.st_lb); | |||
lb = findViewById(R.id.lb); | |||
C = findViewById(R.id.c); | |||
F = findViewById(R.id.f); | |||
findViewById(R.id.support_unit).setOnClickListener(this); | |||
kg.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked) { | |||
if (mEightBodyFatBleDeviceData != null) | |||
mEightBodyFatBleDeviceData.setWeightUnit(EightBodyfatUtil.KG); | |||
} | |||
} | |||
}); | |||
jing.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked) { | |||
if (mEightBodyFatBleDeviceData != null) | |||
mEightBodyFatBleDeviceData.setWeightUnit(EightBodyfatUtil.JIN); | |||
} | |||
} | |||
}); | |||
stlb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked) { | |||
if (mEightBodyFatBleDeviceData != null) | |||
mEightBodyFatBleDeviceData.setWeightUnit(EightBodyfatUtil.ST); | |||
} | |||
} | |||
}); | |||
lb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked) { | |||
if (mEightBodyFatBleDeviceData != null) | |||
mEightBodyFatBleDeviceData.setWeightUnit(EightBodyfatUtil.LB); | |||
} | |||
} | |||
}); | |||
C.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked) { | |||
if (mEightBodyFatBleDeviceData != null) | |||
mEightBodyFatBleDeviceData.setTempUnit(EightBodyfatUtil.C); | |||
} | |||
} | |||
}); | |||
F.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked) { | |||
if (mEightBodyFatBleDeviceData != null) | |||
mEightBodyFatBleDeviceData.setTempUnit(EightBodyfatUtil.F); | |||
} | |||
} | |||
}); | |||
kg.setChecked(true); | |||
C.setChecked(true); | |||
} | |||
@Override | |||
public void onServiceSuccess() { | |||
loglist.add(0, "绑定服务成功"); | |||
if (mBluetoothService != null) { | |||
mBluetoothService.setOnCallback(this); | |||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | |||
if (bleDevice != null) { | |||
mEightBodyFatBleDeviceData = new EightBodyFatBleDeviceData(bleDevice); | |||
mEightBodyFatBleDeviceData.setEightBodyFatCallback(this); | |||
} | |||
} | |||
} | |||
@Override | |||
public void onServiceErr() { | |||
} | |||
@Override | |||
public void unbindServices() { | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
if (v.getId() == R.id.support_unit) { | |||
if (mEightBodyFatBleDeviceData != null) | |||
mEightBodyFatBleDeviceData.getUnitList(); | |||
} | |||
} | |||
@Override | |||
public void onState(int type, int typeState, int result) { | |||
switch (type) { | |||
// case EightBodyfatUtil.WEIGHING: | |||
// switch (typeState) { | |||
// case EightBodyfatUtil.WEIGHT_REAL_TIME_WEIGH: | |||
// loglist.add(0, "实时体重"); | |||
// break; | |||
// case EightBodyfatUtil.WEIGHT_STABILIZATION_WEIGHT: | |||
// loglist.add(0, "稳定体重"); | |||
// } | |||
// break; | |||
case EightBodyfatUtil.IMPEDANCE: | |||
String adc = ""; | |||
switch (typeState) { | |||
case EightBodyfatUtil.IMPEDANCE_MEASUREMENT: | |||
adc = "阻抗测量中"; | |||
break; | |||
case EightBodyfatUtil.IMPEDANCE_SUCCESS: | |||
//阻抗测量成功 | |||
adc = "阻抗测量成功"; | |||
break; | |||
case EightBodyfatUtil.IMPEDANCE_FAILED: | |||
adc = "阻抗测量失败"; | |||
//阻抗测量失败 | |||
break; | |||
case EightBodyfatUtil.IMPEDANCE_FINISH: | |||
//阻抗测量完成 | |||
adc = "阻抗测量完成"; | |||
break; | |||
} | |||
switch (result) { | |||
case EightBodyfatUtil.IMPEDANCE_FOOT: | |||
adc = adc + "双脚阻抗"; | |||
break; | |||
case EightBodyfatUtil.IMPEDANCE_HAND: | |||
adc = adc + "双手阻抗"; | |||
break; | |||
case EightBodyfatUtil.IMPEDANCE_BODY: | |||
adc = adc + "躯干阻抗"; | |||
break; | |||
case EightBodyfatUtil.IMPEDANCE_L_HAND: | |||
adc = adc + "左手阻抗"; | |||
break; | |||
case EightBodyfatUtil.IMPEDANCE_R_HAND: | |||
adc = adc + "右手阻抗"; | |||
break; | |||
case EightBodyfatUtil.IMPEDANCE_L_FOOT: | |||
adc = adc + "左脚阻抗"; | |||
break; | |||
case EightBodyfatUtil.IMPEDANCE_R_FOOT: | |||
adc = adc + "右脚阻抗"; | |||
break; | |||
case EightBodyfatUtil.IMPEDANCE_L_BODY: | |||
adc = adc + "左驱干"; | |||
break; | |||
case EightBodyfatUtil.IMPEDANCE_R_BODY: | |||
adc = adc + "右躯干"; | |||
break; | |||
case EightBodyfatUtil.IMPEDANCE_R_HAND_L_FOOT: | |||
adc = adc + "右手左脚"; | |||
break; | |||
case EightBodyfatUtil.IMPEDANCE_L_HAND_R_FOOT: | |||
adc = adc + "左手右脚"; | |||
break; | |||
default: | |||
} | |||
loglist.add(0, adc); | |||
break; | |||
case EightBodyfatUtil.HEART_RATE: | |||
switch (typeState) { | |||
case EightBodyfatUtil.HEART_RATE_MEASUREMENT: | |||
//心率测量完成 | |||
loglist.add(0, "心率测量中"); | |||
break; | |||
case EightBodyfatUtil.HEART_RATE_SUCCESS: | |||
loglist.add(0, "心率测量成功"); | |||
//心率测量成功 | |||
break; | |||
case EightBodyfatUtil.HEART_RATE_FAILED: | |||
loglist.add(0, "心率测量失败"); | |||
//心率测量失败 | |||
break; | |||
} | |||
break; | |||
case EightBodyfatUtil.TEMP_MEASUREMENT: | |||
loglist.add(0, "测量温度"); | |||
break; | |||
case EightBodyfatUtil.MEASUREMENT_END: | |||
loglist.add(0, "测量完成"); | |||
//测量完成 | |||
break; | |||
case EightBodyfatUtil.MUC_CALL_BACK_RESULT: | |||
switch (typeState) { | |||
case EightBodyfatUtil.APP_CMD_CALIBRATION: | |||
//校验 | |||
if (result == EightBodyfatUtil.SUCCESS) { | |||
loglist.add(0, "校验成功"); | |||
} else if (result == EightBodyfatUtil.FAILED) { | |||
loglist.add(0, "校验失败"); | |||
} else { | |||
loglist.add(0, "校验中"); | |||
} | |||
break; | |||
case EightBodyfatUtil.APP_CMD_TEMP_UNIT: | |||
if (result == EightBodyfatUtil.SUCCESS) { | |||
loglist.add(0, "切换温度成功"); | |||
} else if (result == EightBodyfatUtil.FAILED) { | |||
loglist.add(0, "切换温度失败"); | |||
} else { | |||
loglist.add(0, "切换温度中"); | |||
} | |||
//切换温度 | |||
break; | |||
case EightBodyfatUtil.APP_CMD_WEIGHT_UNIT: | |||
if (result == EightBodyfatUtil.SUCCESS) { | |||
loglist.add(0, "切换体重单位成功"); | |||
} else if (result == EightBodyfatUtil.FAILED) { | |||
loglist.add(0, "切换体重单位失败"); | |||
} else { | |||
loglist.add(0, "切换体重单位中"); | |||
} | |||
//切换温度 | |||
break; | |||
} | |||
break; | |||
case EightBodyfatUtil.ERROR_CODE: | |||
loglist.add(0, "错误码" + typeState); | |||
break; | |||
} | |||
listAdapter.notifyDataSetChanged(); | |||
} | |||
@Override | |||
public void onWeight(int state, float weight, int unit, int decimal) { | |||
//测量状态 1实时体重 2稳定体重 | |||
String stateStr = ""; | |||
if (state == EightBodyfatUtil.WEIGHT_REAL_TIME_WEIGH) { | |||
stateStr = "实时体重"; | |||
} else if (state == EightBodyfatUtil.WEIGHT_STABILIZATION_WEIGHT) { | |||
stateStr = "稳定体重"; | |||
} | |||
if (unit == EightBodyfatUtil.ST) { | |||
loglist.add(0, "测量状态:" + state + stateStr + " 体重:" + EightBodyfatUtil.lbtostlb(weight) + " 体重单位:" + unit + " 小数点位" + decimal); | |||
} else { | |||
loglist.add(0, "测量状态:" + state + stateStr + " 体重:" + weight + " 体重单位:" + unit + " 小数点位" + decimal); | |||
} | |||
} | |||
@Override | |||
public void onImpedance(int adc, int part, int arithmetic) { | |||
loglist.add(0, "阻抗:" + adc + " 部位: " + part + " 算法" + arithmetic); | |||
} | |||
@Override | |||
public void onHeartRate(int heartRate) { | |||
loglist.add(0, " 心率" + heartRate); | |||
} | |||
@Override | |||
public void onTemp(int sign, float temp, int unit, int decimal) { | |||
loglist.add(0, " 温度 正负" + sign + " 温度:" + temp + " 单位: " + unit + " 小数位" + decimal); | |||
} | |||
@Override | |||
public void onVersion(String version) { | |||
loglist.add(0, "当前版本:" + version); | |||
listAdapter.notifyDataSetChanged(); | |||
} | |||
@Override | |||
public void onSupportUnit(List<SupportUnitBean> list) { | |||
loglist.add(0, "支持单位:"); | |||
for (SupportUnitBean supportUnitBean : list) { | |||
loglist.add(0, supportUnitBean.toString()); | |||
} | |||
listAdapter.notifyDataSetChanged(); | |||
} | |||
@Override | |||
public void showData(String data) { | |||
// loglist.add(0, data); | |||
} | |||
} |
@@ -11,6 +11,7 @@ import android.widget.Button; | |||
import android.widget.EditText; | |||
import android.widget.ListView; | |||
import com.pingwang.bluetoothlib.BleBaseActivity; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | |||
import com.pingwang.bluetoothlib.device.SendBleBean; | |||
@@ -23,6 +24,7 @@ import com.pingwang.bluetoothlib.listener.OnMcuParameterListener; | |||
import com.pingwang.bluetoothlib.utils.BleDensityUtil; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
@@ -32,13 +34,14 @@ import androidx.annotation.Nullable; | |||
import cn.net.aicare.modulelibrary.module.height.HeightDeviceData; | |||
/** | |||
* xing<br> | |||
* 2019/4/25<br> | |||
* 显示数据 | |||
*/ | |||
public class HeightCmdActivity extends BleBaseActivity implements OnCallbackDis, | |||
HeightDeviceData.onNotifyData, OnBleVersionListener, OnMcuParameterListener, OnBleCompanyListener, View.OnClickListener { | |||
HeightDeviceData.onNotifyData, OnBleVersionListener , OnMcuParameterListener, OnBleCompanyListener, View.OnClickListener { | |||
private static String TAG = HeightCmdActivity.class.getName(); | |||
private final int REFRESH_DATA = 3; |
@@ -14,9 +14,10 @@ import android.widget.Button; | |||
import android.widget.TextView; | |||
import com.pingwang.bluetoothlib.AILinkSDK; | |||
import com.pingwang.bluetoothlib.config.BleDeviceConfig; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.config.BleDeviceConfig; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.SP; | |||
import androidx.annotation.NonNull; | |||
import androidx.appcompat.app.AppCompatActivity; | |||
import androidx.core.app.ActivityCompat; | |||
@@ -36,6 +37,7 @@ public class MainActivity extends AppCompatActivity { | |||
((TextView) findViewById(R.id.tv_app_version)).setText(version); | |||
init(); | |||
initPermissions(); | |||
SP.init(this); | |||
} | |||
private void init() { | |||
@@ -46,17 +48,29 @@ public class MainActivity extends AppCompatActivity { | |||
Button btn_baby = findViewById(R.id.btn_baby); | |||
Button btn_height = findViewById(R.id.btn_height); | |||
Button btn_ble = findViewById(R.id.btn_ble); | |||
findViewById(R.id.btn_ble_test).setOnClickListener(listener); | |||
findViewById(R.id.btnConnectTest).setOnClickListener(listener); | |||
findViewById(R.id.btn_ad_weight).setOnClickListener(listener); | |||
findViewById(R.id.btn_bloodglucose).setOnClickListener(listener); | |||
findViewById(R.id.btn_ble_weight).setOnClickListener(listener); | |||
findViewById(R.id.btn_wifi_ble_tooth).setOnClickListener(listener); | |||
findViewById(R.id.wifi_config).setOnClickListener(listener); | |||
findViewById(R.id.eight_scale).setOnClickListener(listener); | |||
findViewById(R.id.btn_ota).setOnClickListener(listener); | |||
findViewById(R.id.btn_wristband).setOnClickListener(listener); | |||
findViewById(R.id.glucometer).setOnClickListener(listener); | |||
findViewById(R.id.btn_broadcast_scale).setOnClickListener(listener); | |||
findViewById(R.id.btn_broadcast_blood_oxygen).setOnClickListener(listener); | |||
findViewById(R.id.btn_smart_mask).setOnClickListener(listener); | |||
findViewById(R.id.btn_transmission).setOnClickListener(listener); | |||
btn_shpy.setOnClickListener(listener); | |||
btn_tempgun.setOnClickListener(listener); | |||
btn_temp.setOnClickListener(listener); | |||
btn_baby.setOnClickListener(listener); | |||
btn_height.setOnClickListener(listener); | |||
btn_ble.setOnClickListener(listener); | |||
findViewById(R.id.btn_wifi_ble_weight).setOnClickListener(listener); | |||
findViewById(R.id.btn_baby_body_fat).setOnClickListener(listener); | |||
} | |||
private class MyListener implements View.OnClickListener { | |||
@@ -83,19 +97,64 @@ public class MainActivity extends AppCompatActivity { | |||
case R.id.btn_height: | |||
type = BleDeviceConfig.HEIGHT_METER; | |||
break; | |||
case R.id.btn_ad_weight: | |||
type = BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_AD; | |||
break; | |||
case R.id.btn_wifi_ble_weight: | |||
type = BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_WIFI_BLE; | |||
break; | |||
case R.id.btn_bloodglucose: | |||
case R.id.btn_wifi_ble_tooth: | |||
type = BleDeviceConfig.TOOTHBRUSH_WIFI_BLE; | |||
break; | |||
case R.id.btn_ble_weight: | |||
type = BleDeviceConfig.WEIGHT_BODY_FAT_SCALE; | |||
break; | |||
case R.id.glucometer: | |||
type = BleDeviceConfig.BLOOD_GLUCOSE; | |||
break; | |||
case R.id.btn_baby_body_fat: | |||
type = BleDeviceConfig.BABY_BODY_FAT; | |||
break; | |||
case R.id.btn_broadcast_scale: | |||
Intent intentBroadcast = new Intent(MainActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.BroadcastScaleActivity.class); | |||
startActivity(intentBroadcast); | |||
return; | |||
case R.id.btn_broadcast_blood_oxygen: | |||
Intent intentBloodOxygen = new Intent(MainActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.BroadcastBloodOxygenActivity.class); | |||
startActivity(intentBloodOxygen); | |||
return; | |||
case R.id.btn_smart_mask: | |||
type = BleDeviceConfig.SMART_MASK; | |||
break; | |||
case R.id.btn_ble: | |||
type = 0; | |||
type = -1; | |||
break; | |||
case R.id.btn_ble_test: | |||
type = -2; | |||
break; | |||
case R.id.btn_ota: | |||
type = -3; | |||
break; | |||
case R.id.btn_wristband: | |||
type = 65536; | |||
break; | |||
case R.id.btn_transmission: | |||
type=-4; | |||
break; | |||
case R.id.eight_scale: | |||
type = BleDeviceConfig.EIGHT_BODY_FAT_SCALE; | |||
break; | |||
case R.id.btnConnectTest: | |||
Intent intent = new Intent(MainActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.ConnectBleTestActivity.class); | |||
startActivity(intent); | |||
return; | |||
case R.id.wifi_config: | |||
Intent intent1 = new Intent(MainActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.WifiConfigActivity.class); | |||
startActivity(intent1); | |||
return; | |||
} | |||
@@ -109,14 +168,14 @@ public class MainActivity extends AppCompatActivity { | |||
*/ | |||
private void initPermissions() { | |||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | |||
// ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, 1); | |||
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1); | |||
ActivityCompat | |||
.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.CHANGE_WIFI_MULTICAST_STATE, Manifest.permission.ACCESS_WIFI_STATE, | |||
Manifest.permission.CHANGE_WIFI_STATE}, 1); | |||
} | |||
} | |||
@Override | |||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, | |||
@NonNull int[] grantResults) { | |||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | |||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | |||
if (requestCode != 1) { | |||
return; | |||
@@ -125,55 +184,45 @@ public class MainActivity extends AppCompatActivity { | |||
} else { | |||
if (ActivityCompat.shouldShowRequestPermissionRationale(this, permissions[0])) { | |||
//权限请求失败,但未选中“不再提示”选项 | |||
new AlertDialog.Builder(this).setTitle("提示") | |||
.setMessage("请求使用定位权限搜索蓝牙设备") | |||
.setPositiveButton("确定", new DialogInterface.OnClickListener() { | |||
@Override | |||
public void onClick(DialogInterface dialog, int which) { | |||
//引导用户至设置页手动授权 | |||
Intent intent = | |||
new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); | |||
Uri uri = Uri.fromParts("package", | |||
getApplicationContext().getPackageName(), null); | |||
intent.setData(uri); | |||
startActivity(intent); | |||
} | |||
}) | |||
.setNegativeButton("取消", new DialogInterface.OnClickListener() { | |||
@Override | |||
public void onClick(DialogInterface dialog, int which) { | |||
if (dialog != null) { | |||
dialog.cancel(); | |||
} | |||
} | |||
}) | |||
.show(); | |||
new AlertDialog.Builder(this).setTitle("提示").setMessage("请求使用定位权限搜索蓝牙设备").setPositiveButton("确定", new DialogInterface.OnClickListener() { | |||
@Override | |||
public void onClick(DialogInterface dialog, int which) { | |||
//引导用户至设置页手动授权 | |||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); | |||
Uri uri = Uri.fromParts("package", getApplicationContext().getPackageName(), null); | |||
intent.setData(uri); | |||
startActivity(intent); | |||
} | |||
}).setNegativeButton("取消", new DialogInterface.OnClickListener() { | |||
@Override | |||
public void onClick(DialogInterface dialog, int which) { | |||
if (dialog != null) { | |||
dialog.cancel(); | |||
} | |||
} | |||
}).show(); | |||
} else { | |||
//权限请求失败,选中“不再提示”选项 | |||
// T.showShort(MainActivity.this, "获取权限失败"); | |||
new AlertDialog.Builder(this).setTitle("提示") | |||
.setMessage("请求使用定位权限搜索蓝牙设备") | |||
.setPositiveButton("确定", new DialogInterface.OnClickListener() { | |||
@Override | |||
public void onClick(DialogInterface dialog, int which) { | |||
//引导用户至设置页手动授权 | |||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); | |||
Uri uri = Uri.fromParts("package", getApplicationContext().getPackageName(), null); | |||
intent.setData(uri); | |||
startActivity(intent); | |||
} | |||
}) | |||
.setNegativeButton("取消", new DialogInterface.OnClickListener() { | |||
@Override | |||
public void onClick(DialogInterface dialog, int which) { | |||
if (dialog != null) { | |||
dialog.cancel(); | |||
} | |||
} | |||
}) | |||
.show(); | |||
new AlertDialog.Builder(this).setTitle("提示").setMessage("请求使用定位权限搜索蓝牙设备").setPositiveButton("确定", new DialogInterface.OnClickListener() { | |||
@Override | |||
public void onClick(DialogInterface dialog, int which) { | |||
//引导用户至设置页手动授权 | |||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); | |||
Uri uri = Uri.fromParts("package", getApplicationContext().getPackageName(), null); | |||
intent.setData(uri); | |||
startActivity(intent); | |||
} | |||
}).setNegativeButton("取消", new DialogInterface.OnClickListener() { | |||
@Override | |||
public void onClick(DialogInterface dialog, int which) { | |||
if (dialog != null) { | |||
dialog.cancel(); | |||
} | |||
} | |||
}).show(); | |||
} | |||
} | |||
@@ -182,7 +231,7 @@ public class MainActivity extends AppCompatActivity { | |||
private void startActivity(int tyep) { | |||
Intent intent = new Intent(this, ShowBleActivity.class); | |||
Intent intent = new Intent(this, aicare.net.cn.sdk.ailinksdkdemoandroid.ShowBleActivity.class); | |||
intent.putExtra("type", tyep); | |||
startActivity(intent); | |||
} | |||
@@ -198,4 +247,6 @@ public class MainActivity extends AppCompatActivity { | |||
super.onDestroy(); | |||
BleLog.quit(); | |||
} | |||
} |
@@ -18,7 +18,6 @@ import android.widget.Toast; | |||
import com.pingwang.bluetoothlib.bean.BleValueBean; | |||
import com.pingwang.bluetoothlib.config.BleConfig; | |||
import com.pingwang.bluetoothlib.config.BleDeviceConfig; | |||
import com.pingwang.bluetoothlib.listener.CallbackDisIm; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | |||
import com.pingwang.bluetoothlib.listener.OnScanFilterListener; | |||
@@ -28,7 +27,10 @@ import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.UUID; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.config.BleDeviceConfig; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.LoadingIosDialogFragment; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import androidx.appcompat.app.AppCompatActivity; | |||
@@ -81,8 +83,8 @@ public class ShowBleActivity extends AppCompatActivity implements OnCallbackBle, | |||
//核心用户服务 | |||
startService(mUserService); | |||
mContext = this; | |||
mType = getIntent().getIntExtra("type", -1); | |||
if (-1 == mType) { | |||
mType = getIntent().getIntExtra("type", 0); | |||
if (0 == mType) { | |||
finish(); | |||
return; | |||
} | |||
@@ -111,7 +113,15 @@ public class ShowBleActivity extends AppCompatActivity implements OnCallbackBle, | |||
public void onClick(View v) { | |||
if (mBluetoothService != null) { | |||
BleLog.i(TAG, "搜索设备"); | |||
mBluetoothService.scanLeDevice(0, BleConfig.UUID_SERVER); | |||
if (mType == -3) { | |||
mBluetoothService.scanLeDevice(0); | |||
} else { | |||
if (mFilter) | |||
mBluetoothService.scanLeDevice(0, BleConfig.UUID_SERVER, UUID.fromString("0000FEE7-0000-1000-8000-00805F9B34FB")); | |||
else | |||
mBluetoothService.scanLeDevice(0); | |||
} | |||
mList.clear(); | |||
listAdapter.notifyDataSetChanged(); | |||
} | |||
@@ -153,10 +163,20 @@ public class ShowBleActivity extends AppCompatActivity implements OnCallbackBle, | |||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | |||
String itemStr = mList.get(position); | |||
String mac = itemStr.split("=")[0]; | |||
if (mBluetoothService != null) { | |||
mBluetoothService.stopScan(); | |||
mBluetoothService.connectDevice(mac); | |||
showLoading(); | |||
if (BleDeviceConfig.TOOTHBRUSH_WIFI_BLE==mType){ | |||
Intent intent=new Intent(); | |||
intent.setClass(ShowBleActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.ToothBrushWifiBleActivity.class); | |||
intent.putExtra("type", mType); | |||
intent.putExtra("mac", mac); | |||
startActivity(intent); | |||
finish(); | |||
}else { | |||
if (mBluetoothService != null) { | |||
mBluetoothService.stopScan(); | |||
mBluetoothService.connectDevice(mac); | |||
showLoading(); | |||
} | |||
} | |||
} | |||
}); | |||
@@ -184,9 +204,13 @@ public class ShowBleActivity extends AppCompatActivity implements OnCallbackBle, | |||
private void unbindService() { | |||
if (mBluetoothService != null) | |||
mBluetoothService.stopForeground();//停止前台服务 | |||
CallbackDisIm.getInstance().removeListener(this); | |||
if (mFhrSCon != null) | |||
if (mFhrSCon != null) { | |||
BleLog.i(TAG, "解绑服务"); | |||
this.unbindService(mFhrSCon); | |||
} | |||
bindIntent = null; | |||
} | |||
@@ -203,6 +227,9 @@ public class ShowBleActivity extends AppCompatActivity implements OnCallbackBle, | |||
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); | |||
} | |||
} | |||
@@ -224,9 +251,11 @@ public class ShowBleActivity extends AppCompatActivity implements OnCallbackBle, | |||
@Override | |||
public void onScanning(@NonNull BleValueBean data) { | |||
String mAddress = data.getMac(); | |||
BleLog.i(TAG, "MAC=" + mAddress + "||CID=" + data.getCid() + "||VID=" + data.getVid() + "||PID=" + data.getPid()); | |||
if (!mList.contains(mAddress + "=" + data.getName())) { | |||
String data1 = BleStrUtils.byte2HexStr(data.getScanRecord()); | |||
BleLog.i(TAG, "设备地址+广播数据:" + mAddress + "||" + data1); | |||
String data2 = BleStrUtils.byte2HexStr(data.getManufacturerData()); | |||
BleLog.i(TAG, "设备地址+广播数据:" + mAddress + "||" + data1 + "||" + data2); | |||
mList.add(mAddress + "=" + data.getName()); | |||
listAdapter.notifyDataSetChanged(); | |||
} | |||
@@ -235,8 +264,6 @@ public class ShowBleActivity extends AppCompatActivity implements OnCallbackBle, | |||
} | |||
@Override | |||
public void onConnecting(@NonNull String mac) { | |||
@@ -256,39 +283,60 @@ public class ShowBleActivity extends AppCompatActivity implements OnCallbackBle, | |||
int type = mType;//默认婴儿秤 | |||
switch (type) { | |||
case BleDeviceConfig.BABY_SCALE: | |||
intent.setClass(ShowBleActivity.this, BabyCmdActivity.class); | |||
intent.setClass(ShowBleActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.BabyCmdActivity.class); | |||
break; | |||
case BleDeviceConfig.INFRARED_THERMOMETER: | |||
intent.setClass(ShowBleActivity.this, TempGunCmdActivity.class); | |||
intent.setClass(ShowBleActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.TempGunCmdActivity.class); | |||
break; | |||
case BleDeviceConfig.BLOOD_PRESSURE: | |||
intent.setClass(ShowBleActivity.this, SphyCmdActivity.class); | |||
intent.setClass(ShowBleActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.SphyCmdActivity.class); | |||
break; | |||
case BleDeviceConfig.THERMOMETER: | |||
intent.setClass(ShowBleActivity.this, TempCmdActivity.class); | |||
intent.setClass(ShowBleActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.TempCmdActivity.class); | |||
break; | |||
case BleDeviceConfig.HEIGHT_METER: | |||
intent.setClass(ShowBleActivity.this, HeightCmdActivity.class); | |||
intent.setClass(ShowBleActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.HeightCmdActivity.class); | |||
break; | |||
case BleDeviceConfig.WEIGHT_BODY_FAT_SCALE: | |||
intent.setClass(ShowBleActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.WeightScaleBle.class); | |||
break; | |||
case BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_AD: | |||
intent.setClass(ShowBleActivity.this, ADWeightScaleCmdActivity.class); | |||
intent.setClass(ShowBleActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.ADWeightScaleCmdActivity.class); | |||
break; | |||
case BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_WIFI_BLE: | |||
intent.setClass(ShowBleActivity.this,WeightScaleWifiBle.class); | |||
intent.setClass(ShowBleActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.WeightScaleWifiBle.class); | |||
break; | |||
case BleDeviceConfig.TOOTHBRUSH_WIFI_BLE: | |||
intent.setClass(ShowBleActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.ToothBrushWifiBleActivity.class); | |||
break; | |||
case BleDeviceConfig.EIGHT_BODY_FAT_SCALE: | |||
intent.setClass(ShowBleActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.EightBodyfatActivity.class); | |||
break; | |||
case BleDeviceConfig.BLOOD_GLUCOSE: | |||
intent.setClass(ShowBleActivity.this,BloodGlucoseActivity.class); | |||
intent.setClass(ShowBleActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.BloodGlucoseActivity.class); | |||
break; | |||
case 0: | |||
intent.setClass(ShowBleActivity.this, BleCmdActivityDataData.class); | |||
case BleDeviceConfig.BABY_BODY_FAT: | |||
intent.setClass(ShowBleActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.BabyBodyFatCmdActivity.class); | |||
break; | |||
case BleDeviceConfig.SMART_MASK: | |||
intent.setClass(ShowBleActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.SmartMaskActivity.class); | |||
break; | |||
case -1: | |||
intent.setClass(ShowBleActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.BleCmdActivity.class); | |||
break; | |||
case -2: | |||
intent.setClass(ShowBleActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.TestCmdActivity.class); | |||
break; | |||
case -3: | |||
intent.setClass(ShowBleActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.TestOtaActivity.class); | |||
break; | |||
case -4: | |||
intent.setClass(ShowBleActivity.this, aicare.net.cn.sdk.ailinksdkdemoandroid.TransmissionActivity.class); | |||
break; | |||
} | |||
intent.putExtra("type", type); | |||
intent.putExtra("mac", mac); | |||
startActivity(intent); | |||
@@ -308,36 +356,12 @@ public class ShowBleActivity extends AppCompatActivity implements OnCallbackBle, | |||
@Override | |||
public boolean onFilter(BleValueBean bleValueBean) { | |||
byte[] CID = bleValueBean.getCID(); | |||
int cid = ((CID[0] & 0xff) << 8) + (CID[1]); | |||
int cid = bleValueBean.getCid(); | |||
BleLog.i(TAG, "绑定设备广播类型:" + cid + "||添加的类型:" + mType); | |||
if (mType == 0 || mType == 100) | |||
if (mType < 0 || mType > 0xFF) | |||
return true; | |||
else | |||
return mType == cid; | |||
// byte[] CID = new byte[2]; | |||
// CID[0] = 0x0a; | |||
// CID[1] = 0x45; | |||
// byte[] data = bleValueBean.getScanRecord(); | |||
// byte[] datas=new byte[13]; | |||
// BleLog.i(TAG, "原始数据1:"+BleStrUtils.byte2HexStr(data)); | |||
// System.arraycopy(data,9,datas,0,datas.length); | |||
// byte size=0; | |||
// for (int i = 1; i < datas.length-2; i++) { | |||
// size+=datas[i]; | |||
// } | |||
// | |||
// BleLog.i(TAG, "校验和:"+BleStrUtils.getHexString((size&0xff)).toUpperCase()); | |||
// BleLog.i(TAG, "原始数据2:"+BleStrUtils.byte2HexStr(datas).toUpperCase()); | |||
// byte[] dataEncrypt=new byte[datas.length-4]; | |||
// System.arraycopy(datas,2,dataEncrypt,0,dataEncrypt.length); | |||
// byte[] newData = AiLinkBleCheckUtil.mcuEncrypt(CID, dataEncrypt, bleValueBean.getMac()); | |||
// BleLog.i(TAG,"解密:"+BleStrUtils.byte2HexStr(newData).toUpperCase()); | |||
// return false; | |||
} | |||
@Override |
@@ -0,0 +1,330 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.content.Context; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import android.os.Message; | |||
import android.view.View; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.Button; | |||
import android.widget.ListView; | |||
import android.widget.Toast; | |||
import com.pingwang.bluetoothlib.BleBaseActivity; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | |||
import com.pingwang.bluetoothlib.device.SendBleBean; | |||
import com.pingwang.bluetoothlib.listener.OnBleVersionListener; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackDis; | |||
import com.pingwang.bluetoothlib.listener.OnScanFilterListener; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import butterknife.BindView; | |||
import butterknife.ButterKnife; | |||
import cn.net.aicare.modulelibrary.module.SmartMask.SmartMaskBleConfig; | |||
import cn.net.aicare.modulelibrary.module.SmartMask.SmartMaskDeviceData; | |||
/** | |||
* xing<br> | |||
* 2020/09/15<br> | |||
* 智能口罩 | |||
*/ | |||
public class SmartMaskActivity extends BleBaseActivity implements OnCallbackDis, SmartMaskDeviceData.onNotifyData, OnBleVersionListener, OnScanFilterListener, View.OnClickListener { | |||
private static String TAG = SmartMaskActivity.class.getName(); | |||
private final int REFRESH_DATA = 3; | |||
@BindView(R.id.clear) | |||
Button mClear; | |||
@BindView(R.id.set_status) | |||
Button mSetStatus; | |||
@BindView(R.id.set_filter) | |||
Button mSetFilter; | |||
@BindView(R.id.set_fan) | |||
Button mSetFan; | |||
@BindView(R.id.listview) | |||
ListView mListview; | |||
@BindView(R.id.get_version) | |||
Button mGetVersion; | |||
private List<String> mList; | |||
private ArrayAdapter listAdapter; | |||
private Context mContext; | |||
private SmartMaskDeviceData mDevice; | |||
private String mAddress = ""; | |||
private BleSendCmdUtil mBleSendCmdUtil; | |||
private int type = SmartMaskBleConfig.SMART_MASK; | |||
private int mFanStatus = 0; | |||
private Handler mHandler = new Handler(Looper.getMainLooper()) { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
switch (msg.what) { | |||
case REFRESH_DATA: | |||
if (listAdapter != null) | |||
listAdapter.notifyDataSetChanged(); | |||
break; | |||
} | |||
} | |||
}; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_smart_mask); | |||
ButterKnife.bind(this); | |||
mContext = this; | |||
mAddress = getIntent().getStringExtra("mac"); | |||
type = getIntent().getIntExtra("type", -1); | |||
mBleSendCmdUtil = BleSendCmdUtil.getInstance(); | |||
init(); | |||
} | |||
private void init() { | |||
mList = new ArrayList<>(); | |||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | |||
mListview.setAdapter(listAdapter); | |||
mClear.setOnClickListener(this); | |||
mSetStatus.setOnClickListener(this); | |||
mSetFilter.setOnClickListener(this); | |||
mSetFan.setOnClickListener(this); | |||
mGetVersion.setOnClickListener(this); | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
switch (v.getId()) { | |||
case R.id.clear: | |||
if (mList != null) | |||
mList.clear(); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
break; | |||
case R.id.get_version: | |||
if (mDevice != null) { | |||
SendBleBean sendBleBean = new SendBleBean(); | |||
sendBleBean.setHex(mBleSendCmdUtil.getBleVersion()); | |||
mDevice.sendData(sendBleBean); | |||
} | |||
break; | |||
case R.id.set_status: | |||
if (mDevice != null) { | |||
mDevice.setStatus(); | |||
} | |||
break; | |||
case R.id.set_filter: | |||
if (mDevice != null) { | |||
mDevice.setReplaceFilter(); | |||
} | |||
break; | |||
case R.id.set_fan: | |||
if (mDevice != null) { | |||
if (mFanStatus < 2) { | |||
mFanStatus++; | |||
} else if (mFanStatus == 2) { | |||
mFanStatus = 0; | |||
} | |||
mDevice.setFanStatus(mFanStatus); | |||
} | |||
break; | |||
} | |||
} | |||
//---------------------------------服务--------------------------------------------------- | |||
@Override | |||
public void onServiceSuccess() { | |||
BleLog.i(TAG, "服务与界面建立连接成功"); | |||
//与服务建立连接 | |||
if (mBluetoothService != null) { | |||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | |||
if (bleDevice != null) { | |||
mDevice = SmartMaskDeviceData.getInstance(bleDevice); | |||
mDevice.setOnNotifyData(this); | |||
mDevice.setOnBleVersionListener(this); | |||
} | |||
} | |||
} | |||
@Override | |||
public void onServiceErr() { | |||
BleLog.i(TAG, "服务与界面连接断开"); | |||
//与服务断开连接 | |||
mBluetoothService = null; | |||
} | |||
@Override | |||
public void unbindServices() { | |||
if (mDevice != null) { | |||
mDevice.disconnect(); | |||
mDevice.clear(); | |||
mDevice = null; | |||
} | |||
} | |||
//-----------------通知------------------- | |||
@Override | |||
public void onData(byte[] hex, int type) { | |||
String data = ""; | |||
if (hex != null) | |||
data = BleStrUtils.byte2HexStr(hex); | |||
if (type == 100) { | |||
mList.add(TimeUtils.getTime() + "send->" + data); | |||
} else { | |||
mList.add(TimeUtils.getTime() + "notify->" + data); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onConnecting(@NonNull String mac) { | |||
//TODO 连接中 | |||
BleLog.i(TAG, "连接中"); | |||
} | |||
@Override | |||
public void onDisConnected(@NonNull String mac, int code) { | |||
//TODO 连接断开 | |||
BleLog.i(TAG, "连接断开"); | |||
finish(); | |||
Toast.makeText(mContext, "连接断开", Toast.LENGTH_SHORT).show(); | |||
} | |||
@Override | |||
public void onServicesDiscovered(@NonNull String mac) { | |||
//TODO 连接成功(获取服务成功) | |||
BleLog.i(TAG, "连接成功(获取服务成功)"); | |||
} | |||
@Override | |||
public void bleOpen() { | |||
} | |||
@Override | |||
public void bleClose() { | |||
BleLog.i(TAG, "蓝牙未开启,可请求开启"); | |||
} | |||
//-----------------通知------------------- | |||
@Override | |||
public void onStatus(int airIndex, int fanStatus, int power, int powerStatus, int batteryRemaining, int breathRate, int breathState, int filterDuration) { | |||
String data = "口罩状态:"; | |||
String fanStatusStr = "风扇状态:"; | |||
switch (fanStatus) { | |||
case 0: | |||
fanStatusStr += "关闭"; | |||
break; | |||
case 1: | |||
fanStatusStr += "1 档"; | |||
break; | |||
case 2: | |||
fanStatusStr += "2 档"; | |||
break; | |||
} | |||
String powerStatusStr = "电池状态:"; | |||
switch (powerStatus) { | |||
case 0: | |||
powerStatusStr += "充电"; | |||
break; | |||
case 1: | |||
powerStatusStr += "非充电"; | |||
break; | |||
} | |||
String breathStateStr = "呼吸状态:"; | |||
switch (breathState) { | |||
case 1: | |||
breathStateStr += "呼气"; | |||
break; | |||
case 2: | |||
breathStateStr += "吸气"; | |||
break; | |||
} | |||
data += "空气指数:" + airIndex + ";" + fanStatusStr + "\n"; | |||
data += "电量:" + power + "%;" + powerStatusStr + "\n"; | |||
data += "呼吸频率:" + breathRate + "次/min;" + breathStateStr + "\n"; | |||
data += "电池续航:" + batteryRemaining + "min;滤网的总工作时长:" + filterDuration; | |||
mList.add(TimeUtils.getTime() + data); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onFilter(int status) { | |||
String data = "更换滤网:"; | |||
switch (status) { | |||
case 0: | |||
data += "成功"; | |||
break; | |||
case 1: | |||
data += "失败"; | |||
break; | |||
} | |||
mList.add(TimeUtils.getTime() + data); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onFan(int status) { | |||
String data = ""; | |||
switch (status) { | |||
case 0: | |||
data = "关闭风扇"; | |||
break; | |||
case 1: | |||
data = "1 档风扇"; | |||
break; | |||
case 2: | |||
data = "2 档风扇"; | |||
break; | |||
} | |||
mList.add(TimeUtils.getTime() + data); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onBmVersion(String version) { | |||
mList.add(TimeUtils.getTime() + "版本号:" + version); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
protected void onDestroy() { | |||
super.onDestroy(); | |||
BleLog.i(TAG, "onDestroy"); | |||
} | |||
} |
@@ -11,6 +11,7 @@ import android.widget.Button; | |||
import android.widget.EditText; | |||
import android.widget.ListView; | |||
import com.pingwang.bluetoothlib.BleBaseActivity; | |||
import com.pingwang.bluetoothlib.config.CmdConfig; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | |||
@@ -24,12 +25,14 @@ import com.pingwang.bluetoothlib.listener.OnMcuParameterListener; | |||
import com.pingwang.bluetoothlib.utils.BleDensityUtil; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import cn.net.aicare.modulelibrary.module.sphygmomanometer.SphyBleConfig; | |||
import cn.net.aicare.modulelibrary.module.sphygmomanometer.SphyDeviceData; | |||
@@ -111,12 +114,12 @@ public class SphyCmdActivity extends BleBaseActivity implements OnCallbackDis, O | |||
btn_set_unit.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
if (unit == 0) { | |||
mBleDevice.setUnit((byte) 1); | |||
unit = 1; | |||
if (unit == SphyBleConfig.SPHY_UNIT_MMHG) { | |||
unit = SphyBleConfig.SPHY_UNIT_KPA; | |||
mBleDevice.setUnit(unit); | |||
} else { | |||
mBleDevice.setUnit((byte) 0); | |||
unit = 0; | |||
unit = SphyBleConfig.SPHY_UNIT_MMHG; | |||
mBleDevice.setUnit(unit); | |||
} | |||
} | |||
}); | |||
@@ -221,8 +224,10 @@ public class SphyCmdActivity extends BleBaseActivity implements OnCallbackDis, O | |||
@Override | |||
public void onDisConnected(@NonNull String mac, int code) { | |||
//TODO 连接断开 | |||
if (mAddress.equals(mac)) | |||
if (mAddress.equals(mac)){ | |||
BleLog.i(TAG, "连接断开"); | |||
finish(); | |||
} | |||
} | |||
@Override | |||
@@ -241,6 +246,7 @@ public class SphyCmdActivity extends BleBaseActivity implements OnCallbackDis, O | |||
@Override | |||
public void bleClose() { | |||
BleLog.i(TAG, "蓝牙未开启,可请求开启"); | |||
finish(); | |||
} | |||
@@ -11,6 +11,7 @@ import android.widget.Button; | |||
import android.widget.EditText; | |||
import android.widget.ListView; | |||
import com.pingwang.bluetoothlib.BleBaseActivity; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | |||
import com.pingwang.bluetoothlib.device.SendBleBean; | |||
@@ -23,6 +24,7 @@ import com.pingwang.bluetoothlib.listener.OnMcuParameterListener; | |||
import com.pingwang.bluetoothlib.utils.BleDensityUtil; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; |
@@ -12,6 +12,7 @@ import android.widget.EditText; | |||
import android.widget.ListView; | |||
import android.widget.Toast; | |||
import com.pingwang.bluetoothlib.BleBaseActivity; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | |||
import com.pingwang.bluetoothlib.device.SendBleBean; | |||
@@ -24,6 +25,7 @@ import com.pingwang.bluetoothlib.listener.OnMcuParameterListener; | |||
import com.pingwang.bluetoothlib.utils.BleDensityUtil; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
@@ -33,12 +35,14 @@ import androidx.annotation.Nullable; | |||
import cn.net.aicare.modulelibrary.module.foreheadgun.TempGunDeviceData; | |||
/** | |||
* xing<br> | |||
* 2019/4/25<br> | |||
* 显示数据 | |||
*/ | |||
public class TempGunCmdActivity extends BleBaseActivity implements OnCallbackDis, OnBleVersionListener, TempGunDeviceData.onNotifyData , OnBleCompanyListener, OnMcuParameterListener, View.OnClickListener { | |||
public class TempGunCmdActivity extends BleBaseActivity implements OnCallbackDis, | |||
OnBleVersionListener, TempGunDeviceData.onNotifyData , OnBleCompanyListener, OnMcuParameterListener, View.OnClickListener { | |||
private static String TAG = TempGunCmdActivity.class.getName(); | |||
private final int REFRESH_DATA = 3; |
@@ -0,0 +1,276 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.content.Context; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import android.os.Message; | |||
import android.view.View; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.Button; | |||
import android.widget.EditText; | |||
import android.widget.ListView; | |||
import com.pingwang.bluetoothlib.BleBaseActivity; | |||
import com.pingwang.bluetoothlib.config.BleConfig; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.device.SendDataBean; | |||
import com.pingwang.bluetoothlib.listener.CallbackDisIm; | |||
import com.pingwang.bluetoothlib.listener.OnBleDeviceDataListener; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackDis; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.Locale; | |||
import java.util.UUID; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
/** | |||
* xing<br> | |||
* 2019/4/25<br> | |||
* 显示数据 | |||
*/ | |||
public class TestCmdActivity extends BleBaseActivity implements OnCallbackDis, OnBleDeviceDataListener, | |||
View.OnClickListener { | |||
private static String TAG = TestCmdActivity.class.getName(); | |||
private final int REFRESH_DATA = 3; | |||
private final int SEND_DATA = 4; | |||
private List<String> mList; | |||
private ArrayAdapter listAdapter; | |||
private Context mContext; | |||
private EditText et_cmd, et_uuid, et_uuid_server, et_time, et_notify; | |||
private BleDevice bleDevice; | |||
private String mAddress; | |||
private int sendTime = 1000; | |||
private UUID sendUuid = null; | |||
private UUID sendUuidServer = null; | |||
private String uuidEnd = "-0000-1000-8000-00805F9B34FB"; | |||
private String sendCmd; | |||
private Handler mHandler = new Handler(Looper.getMainLooper()) { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
switch (msg.what) { | |||
case REFRESH_DATA: | |||
if (listAdapter != null) | |||
listAdapter.notifyDataSetChanged(); | |||
break; | |||
case SEND_DATA: | |||
if (sendUuid != null && sendUuidServer != null) { | |||
SendDataBean sendDataBean = new SendDataBean(sendCmd.getBytes(), sendUuid | |||
, BleConfig.WRITE_DATA, sendUuidServer); | |||
bleDevice.sendData(sendDataBean); | |||
mHandler.sendEmptyMessageDelayed(SEND_DATA, sendTime); | |||
} | |||
break; | |||
} | |||
} | |||
}; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_test_cmd); | |||
mContext = this; | |||
mAddress = getIntent().getStringExtra("mac"); | |||
init(); | |||
} | |||
private void init() { | |||
mList = new ArrayList<>(); | |||
ListView listView = findViewById(R.id.listview); | |||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | |||
listView.setAdapter(listAdapter); | |||
findViewById(R.id.clear).setOnClickListener(this); | |||
findViewById(R.id.btn1).setOnClickListener(this); | |||
findViewById(R.id.btn_uuid).setOnClickListener(this); | |||
findViewById(R.id.btn_time).setOnClickListener(this); | |||
findViewById(R.id.btn_stop).setOnClickListener(this); | |||
findViewById(R.id.btn_notify).setOnClickListener(this); | |||
findViewById(R.id.btn_notify_status).setOnClickListener(this); | |||
findViewById(R.id.btn_uuid_server).setOnClickListener(this); | |||
et_cmd = findViewById(R.id.et_cmd); | |||
et_uuid = findViewById(R.id.et_uuid); | |||
et_time = findViewById(R.id.et_time); | |||
et_notify = findViewById(R.id.et_notify); | |||
et_uuid_server = findViewById(R.id.et_uuid_server); | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
switch (v.getId()) { | |||
case R.id.btn1: | |||
sendCmd = et_cmd.getText().toString().trim(); | |||
mHandler.removeMessages(SEND_DATA); | |||
mHandler.sendEmptyMessage(SEND_DATA); | |||
break; | |||
case R.id.btn_stop: | |||
mHandler.removeMessages(SEND_DATA); | |||
break; | |||
case R.id.clear: | |||
if (mList != null) | |||
mList.clear(); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
break; | |||
case R.id.btn_uuid: | |||
String uuid = et_uuid.getText().toString().trim().toUpperCase(Locale.ENGLISH); | |||
if (uuid.length() == 8) { | |||
uuid += uuidEnd; | |||
} | |||
sendUuid = UUID.fromString(uuid); | |||
break; | |||
case R.id.btn_uuid_server: | |||
String uuidServer = | |||
et_uuid_server.getText().toString().trim().toUpperCase(Locale.ENGLISH); | |||
if (uuidServer.length() == 8) { | |||
uuidServer += uuidEnd; | |||
} | |||
sendUuidServer = UUID.fromString(uuidServer); | |||
break; | |||
case R.id.btn_time: | |||
String time = et_time.getText().toString().trim().toUpperCase(Locale.ENGLISH); | |||
sendTime = Integer.valueOf(time); | |||
break; | |||
case R.id.btn_notify: | |||
String notify = et_notify.getText().toString().trim().toUpperCase(Locale.ENGLISH); | |||
if (notify.length() == 8) { | |||
notify += uuidEnd; | |||
} | |||
readNotify(notify, mNotify); | |||
break; | |||
case R.id.btn_notify_status: | |||
mNotify = !mNotify; | |||
((Button) v).setText("" + mNotify); | |||
break; | |||
} | |||
} | |||
private boolean mNotify = true; | |||
/** | |||
* 设置通知 | |||
*/ | |||
private void readNotify(String notify, boolean notifyOpen) { | |||
UUID UUID_NOTIFY = UUID.fromString(notify); | |||
if (bleDevice != null && sendUuidServer != null) { | |||
// bleDevice.setNotify(notifyOpen); | |||
bleDevice.setOpenNotify(UUID_NOTIFY,sendUuidServer); | |||
} | |||
} | |||
//---------------------------------服务--------------------------------------------------- | |||
@Override | |||
public void onServiceSuccess() { | |||
BleLog.i(TAG, "服务与界面建立连接成功"); | |||
//与服务建立连接 | |||
if (mBluetoothService != null) { | |||
bleDevice = mBluetoothService.getBleDevice(mAddress); | |||
CallbackDisIm.getInstance().addListListener(this); | |||
if (bleDevice != null) { | |||
} | |||
} | |||
} | |||
@Override | |||
public void onServiceErr() { | |||
BleLog.i(TAG, "服务与界面连接断开"); | |||
//与服务断开连接 | |||
mBluetoothService = null; | |||
} | |||
@Override | |||
public void unbindServices() { | |||
CallbackDisIm.getInstance().removeListener(this); | |||
if (bleDevice != null) { | |||
bleDevice.disconnect(); | |||
bleDevice = null; | |||
} | |||
} | |||
//-----------------状态------------------- | |||
@Override | |||
public void onConnecting(@NonNull String mac) { | |||
//TODO 连接中 | |||
BleLog.i(TAG, "连接中"); | |||
} | |||
@Override | |||
public void onDisConnected(@NonNull String mac, int code) { | |||
//TODO 连接断开 | |||
BleLog.i(TAG, "连接断开"); | |||
mList.add(TimeUtils.getTime() + "连接断开"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
finish(); | |||
} | |||
@Override | |||
public void onServicesDiscovered(@NonNull String mac) { | |||
//TODO 连接成功(获取服务成功) | |||
BleLog.i(TAG, "连接成功(获取服务成功)"); | |||
} | |||
@Override | |||
public void bleOpen() { | |||
} | |||
@Override | |||
public void bleClose() { | |||
BleLog.i(TAG, "蓝牙未开启,可请求开启"); | |||
} | |||
//-----------------通知------------------- | |||
@Override | |||
public void onNotifyData(byte[] hex, int type) { | |||
String data = ""; | |||
if (hex != null) | |||
data = BleStrUtils.byte2HexStr(hex); | |||
if (type == 100) { | |||
mList.add(TimeUtils.getTime() + "send->" + data); | |||
} else { | |||
mList.add(TimeUtils.getTime() + "notify->" + data); | |||
} | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
protected void onDestroy() { | |||
super.onDestroy(); | |||
if (mHandler != null) { | |||
mHandler.removeCallbacksAndMessages(null); | |||
} | |||
BleLog.i(TAG, "onDestroy"); | |||
} | |||
} |
@@ -0,0 +1,359 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.Manifest; | |||
import android.app.AlertDialog; | |||
import android.content.Context; | |||
import android.content.DialogInterface; | |||
import android.content.Intent; | |||
import android.content.pm.PackageManager; | |||
import android.net.Uri; | |||
import android.os.Build; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import android.os.Message; | |||
import android.provider.Settings; | |||
import android.text.TextUtils; | |||
import android.view.View; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.ListView; | |||
import android.widget.TextView; | |||
import android.widget.Toast; | |||
import com.pingwang.bluetoothlib.BleBaseActivity; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.listener.OnBleDeviceDataListener; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | |||
import com.pingwang.bluetoothlib.listener.OnDialogOTAListener; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.DialogStringImageAdapter; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.ShowListDialogFragment; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.FileUtils; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.SP; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import androidx.core.app.ActivityCompat; | |||
/** | |||
* xing<br> | |||
* 2019/4/25<br> | |||
* 显示数据 | |||
*/ | |||
public class TestOtaActivity extends BleBaseActivity implements OnCallbackBle, | |||
OnBleDeviceDataListener, View.OnClickListener, OnDialogOTAListener, ShowListDialogFragment.onDialogListener { | |||
private static String TAG = TestOtaActivity.class.getName(); | |||
private final int REFRESH_DATA = 3; | |||
private final int SEND_DATA = 4; | |||
private TextView mTvVersion; | |||
private List<String> mList; | |||
private ArrayAdapter listAdapter; | |||
private Context mContext; | |||
private BleDevice mBleDevice; | |||
private String mAddress; | |||
private ArrayList<DialogStringImageAdapter.DialogStringImageBean> mDialogList; | |||
private String mOTAFileName; | |||
private Handler mHandler = new Handler(Looper.getMainLooper()) { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
switch (msg.what) { | |||
case REFRESH_DATA: | |||
if (listAdapter != null) | |||
listAdapter.notifyDataSetChanged(); | |||
break; | |||
case SEND_DATA: | |||
break; | |||
} | |||
} | |||
}; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_test_ota); | |||
mContext = this; | |||
mAddress = getIntent().getStringExtra("mac"); | |||
initPermissions(); | |||
init(); | |||
FileUtils.init(); | |||
} | |||
private void init() { | |||
mList = new ArrayList<>(); | |||
ListView listView = findViewById(R.id.listview); | |||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mList); | |||
listView.setAdapter(listAdapter); | |||
findViewById(R.id.btn_ota_connect).setOnClickListener(this); | |||
findViewById(R.id.btn_ota_dis).setOnClickListener(this); | |||
findViewById(R.id.btn_ota_file).setOnClickListener(this); | |||
findViewById(R.id.btn_ota_start).setOnClickListener(this); | |||
mTvVersion=findViewById(R.id.tv_version); | |||
mOTAFileName = SP.getInstance().getOtaFileName(); | |||
if (mOTAFileName.isEmpty()) | |||
mTvVersion.setText("xxxxxxxx"); | |||
else | |||
mTvVersion.setText(mOTAFileName); | |||
mDialogList=new ArrayList<>(); | |||
} | |||
@Override | |||
public void onItemListener(int position) { | |||
if (mDialogList.size() > position) { | |||
DialogStringImageAdapter.DialogStringImageBean dialogStringImageBean = mDialogList | |||
.get(position); | |||
String name = dialogStringImageBean.getName(); | |||
mOTAFileName = name; | |||
SP.getInstance().putOtaFileName(name); | |||
mTvVersion.setText(mOTAFileName); | |||
} | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
switch (v.getId()) { | |||
case R.id.btn_ota_connect: | |||
if (mBleDevice==null&&!TextUtils.isEmpty(mAddress)){ | |||
connectBle(mAddress); | |||
} | |||
break; | |||
case R.id.btn_ota_dis: | |||
if (mBleDevice!=null){ | |||
mBleDevice.disconnect(); | |||
mBleDevice=null; | |||
} | |||
break; | |||
case R.id.btn_ota_file: | |||
mDialogList.clear(); | |||
ArrayList<String> list = FileUtils.list(); | |||
for (String s : list) { | |||
mDialogList.add(new DialogStringImageAdapter.DialogStringImageBean(s, 0)); | |||
} | |||
ShowListDialogFragment.newInstance().setTitle("").setCancel("",0).setCancelBlank(true) | |||
.setBackground(true).setBottom(false).setList(mDialogList).setOnDialogListener(this) | |||
.show(getSupportFragmentManager()); | |||
break; | |||
case R.id.btn_ota_start: | |||
if (mOTAFileName.isEmpty()) { | |||
Toast.makeText(mContext, "请先选择文件", Toast.LENGTH_SHORT).show(); | |||
return; | |||
} | |||
String byFileName = FileUtils.getByFileName()+mOTAFileName; | |||
mList.add(TimeUtils.getTime() + "OTA已开始,请耐心等待"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
mBleDevice.setOnDialogOTAListener(this); | |||
mBleDevice.startDialogOta(byFileName); | |||
break; | |||
} | |||
} | |||
/** | |||
* 初始化请求权限 | |||
*/ | |||
private void initPermissions() { | |||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | |||
ActivityCompat | |||
.requestPermissions(this, | |||
new String[]{Manifest.permission.ACCESS_FINE_LOCATION, | |||
Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); | |||
} | |||
} | |||
@Override | |||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, | |||
@NonNull int[] grantResults) { | |||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | |||
if (requestCode != 1) { | |||
return; | |||
} | |||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | |||
} else { | |||
if (ActivityCompat.shouldShowRequestPermissionRationale(this, permissions[0])) { | |||
//权限请求失败,但未选中“不再提示”选项 | |||
new AlertDialog.Builder(this).setTitle("提示").setMessage("请求使用定位权限搜索蓝牙设备") | |||
.setPositiveButton("确定", new DialogInterface.OnClickListener() { | |||
@Override | |||
public void onClick(DialogInterface dialog, int which) { | |||
//引导用户至设置页手动授权 | |||
Intent intent = | |||
new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); | |||
Uri uri = Uri.fromParts("package", getApplicationContext() | |||
.getPackageName(), null); | |||
intent.setData(uri); | |||
startActivity(intent); | |||
} | |||
}).setNegativeButton("取消", new DialogInterface.OnClickListener() { | |||
@Override | |||
public void onClick(DialogInterface dialog, int which) { | |||
if (dialog != null) { | |||
dialog.cancel(); | |||
} | |||
} | |||
}).show(); | |||
} else { | |||
//权限请求失败,选中“不再提示”选项 | |||
// T.showShort(MainActivity.this, "获取权限失败"); | |||
new AlertDialog.Builder(this).setTitle("提示").setMessage("请求使用定位权限搜索蓝牙设备") | |||
.setPositiveButton("确定", new DialogInterface.OnClickListener() { | |||
@Override | |||
public void onClick(DialogInterface dialog, int which) { | |||
//引导用户至设置页手动授权 | |||
Intent intent = | |||
new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); | |||
Uri uri = Uri.fromParts("package", getApplicationContext() | |||
.getPackageName(), null); | |||
intent.setData(uri); | |||
startActivity(intent); | |||
} | |||
}).setNegativeButton("取消", new DialogInterface.OnClickListener() { | |||
@Override | |||
public void onClick(DialogInterface dialog, int which) { | |||
if (dialog != null) { | |||
dialog.cancel(); | |||
} | |||
} | |||
}).show(); | |||
} | |||
} | |||
} | |||
//---------------------------------服务--------------------------------------------------- | |||
@Override | |||
public void onServiceSuccess() { | |||
BleLog.i(TAG, "服务与界面建立连接成功"); | |||
//与服务建立连接 | |||
if (mBluetoothService != null) { | |||
mBleDevice = mBluetoothService.getBleDevice(mAddress); | |||
mBluetoothService.setOnCallback(this); | |||
if (mBleDevice != null) { | |||
mBleDevice.setOnDialogOTAListener(this); | |||
} | |||
} | |||
} | |||
@Override | |||
public void onServiceErr() { | |||
BleLog.i(TAG, "服务与界面连接断开"); | |||
//与服务断开连接 | |||
mBluetoothService = null; | |||
} | |||
@Override | |||
public void unbindServices() { | |||
if (mBleDevice != null) { | |||
mBleDevice.disconnect(); | |||
mBleDevice = null; | |||
} | |||
} | |||
//-----------------状态------------------- | |||
@Override | |||
public void onConnecting(@NonNull String mac) { | |||
//TODO 连接中 | |||
BleLog.i(TAG, "连接中"); | |||
mList.add(TimeUtils.getTime() + "连接中"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onDisConnected(@NonNull String mac, int code) { | |||
//TODO 连接断开 | |||
BleLog.i(TAG, "连接断开"); | |||
mList.add(TimeUtils.getTime() + "连接断开"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onServicesDiscovered(@NonNull String mac) { | |||
//TODO 连接成功(获取服务成功) | |||
BleLog.i(TAG, "连接成功(获取服务成功)"); | |||
mList.add(TimeUtils.getTime() + "连接成功"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
onServiceSuccess(); | |||
} | |||
@Override | |||
public void bleOpen() { | |||
} | |||
@Override | |||
public void bleClose() { | |||
BleLog.i(TAG, "蓝牙未开启,可请求开启"); | |||
} | |||
//-----------------通知------------------- | |||
@Override | |||
protected void onDestroy() { | |||
super.onDestroy(); | |||
if (mHandler != null) { | |||
mHandler.removeCallbacksAndMessages(null); | |||
} | |||
BleLog.i(TAG, "onDestroy"); | |||
} | |||
@Override | |||
public void onOtaSuccess() { | |||
mList.add(TimeUtils.getTime() + "OTA成功"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
@Override | |||
public void onOtaFailure(int cmd ,String err) { | |||
mList.add(TimeUtils.getTime() + "OTA失败:" + err); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
if (mBleDevice != null) { | |||
mBleDevice.disconnect(); | |||
} | |||
} | |||
private int progressOld; | |||
@Override | |||
public void onOtaProgress(float progress) { | |||
int progressInt = (int) progress; | |||
if (progressOld != progressInt) { | |||
progressOld = progressInt; | |||
mList.add(TimeUtils.getTime() + "OTA进度:" + progressInt + "%"); | |||
mHandler.sendEmptyMessage(REFRESH_DATA); | |||
} | |||
} | |||
} |
@@ -0,0 +1,522 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Message; | |||
import android.view.View; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.EditText; | |||
import android.widget.ListView; | |||
import android.widget.Toast; | |||
import com.pingwang.bluetoothlib.BleBaseActivity; | |||
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 androidx.annotation.Nullable; | |||
import cn.net.aicare.modulelibrary.module.ToothBrush.ToothBrushBleCmd; | |||
import cn.net.aicare.modulelibrary.module.ToothBrush.ToothBrushWiFiBleUtilsData; | |||
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); | |||
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); | |||
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 | |||
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.DISORCONNECTWIFI) { | |||
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 (NumberFormatException e) { | |||
e.printStackTrace(); | |||
Toast.makeText(this, "请输入时长,档位,档位级别(数字加符号)", Toast.LENGTH_SHORT).show(); | |||
} | |||
} | |||
} | |||
break; | |||
case R.id.default_time_mode: | |||
mToothBrushWiFiBleUtilsData.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) { | |||
} | |||
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); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} |
@@ -11,6 +11,7 @@ import android.widget.Button; | |||
import android.widget.EditText; | |||
import android.widget.ListView; | |||
import com.pingwang.bluetoothlib.BleBaseActivity; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.device.BleSendCmdUtil; | |||
import com.pingwang.bluetoothlib.device.SendBleBean; | |||
@@ -22,6 +23,7 @@ import com.pingwang.bluetoothlib.listener.OnCallbackDis; | |||
import com.pingwang.bluetoothlib.listener.OnMcuParameterListener; | |||
import com.pingwang.bluetoothlib.utils.BleLog; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
@@ -31,13 +33,15 @@ import androidx.annotation.Nullable; | |||
import cn.net.aicare.modulelibrary.module.tpms.TpmsDeviceData; | |||
/** | |||
* xing<br> | |||
* 2019/9/2<br> | |||
* 显示数据 | |||
*/ | |||
public class TpmsConnectCmdActivity extends BleBaseActivity implements OnCallbackDis, | |||
TpmsDeviceData.onNotifyData, TpmsDeviceData.onTpmsSetting, TpmsDeviceData.onTpmsInfo, OnBleVersionListener, OnMcuParameterListener, OnBleCompanyListener, View.OnClickListener { | |||
TpmsDeviceData.onNotifyData, TpmsDeviceData.onTpmsSetting, TpmsDeviceData.onTpmsInfo, OnBleVersionListener, | |||
OnMcuParameterListener, OnBleCompanyListener, View.OnClickListener { | |||
private static String TAG = TpmsConnectCmdActivity.class.getName(); | |||
private final int REFRESH_DATA = 3; |
@@ -0,0 +1,170 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Message; | |||
import android.view.View; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.Button; | |||
import android.widget.EditText; | |||
import android.widget.ListView; | |||
import androidx.annotation.Nullable; | |||
import com.pingwang.bluetoothlib.BleBaseActivity; | |||
import com.pingwang.bluetoothlib.bean.SupportUnitBean; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.TimeUtils; | |||
import java.lang.ref.WeakReference; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import cn.net.aicare.modulelibrary.module.Transmission.TransmissionDeviceData; | |||
public class TransmissionActivity extends BleBaseActivity implements View.OnClickListener, OnCallbackBle, TransmissionDeviceData.MyBleCallback { | |||
private EditText et, et_cid; | |||
private Button send, bt_clear, bt_clear_log,bt_cid; | |||
private ListView mListView; | |||
private List<String> mlogList; | |||
private final int ToRefreUi = 1; | |||
private MHandler mMHandler; | |||
private ArrayAdapter listAdapter; | |||
private String mAddress; | |||
private TransmissionDeviceData mTransmissionDeviceData; | |||
@Override | |||
public void onServiceSuccess() { | |||
mlogList.add(0, "服务与界面建立连接成功"); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
// BleLog.i(TAG, "服务与界面建立连接成功"); | |||
//与服务建立连接 | |||
if (mBluetoothService != null) { | |||
mBluetoothService.setOnCallback(this); | |||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | |||
if (bleDevice != null) { | |||
mTransmissionDeviceData = new TransmissionDeviceData(bleDevice); | |||
mTransmissionDeviceData.setMyBleCallback(this); | |||
} | |||
} | |||
} | |||
@Override | |||
public void onServiceErr() { | |||
} | |||
@Override | |||
public void unbindServices() { | |||
} | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_transmission); | |||
WeakReference weakReference = new WeakReference(new MHandler()); | |||
mMHandler = (MHandler) weakReference.get(); | |||
et = findViewById(R.id.et); | |||
et_cid = findViewById(R.id.et_cid); | |||
bt_cid = findViewById(R.id.bt_cid); | |||
send = findViewById(R.id.send); | |||
bt_clear = findViewById(R.id.bt_clear); | |||
bt_clear_log = findViewById(R.id.bt_clear_log); | |||
mListView = findViewById(R.id.listview); | |||
send.setOnClickListener(this); | |||
bt_clear.setOnClickListener(this); | |||
bt_cid.setOnClickListener(this); | |||
bt_clear_log.setOnClickListener(this); | |||
mAddress = getIntent().getStringExtra("mac"); | |||
mlogList = new ArrayList<>(); | |||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mlogList); | |||
mListView.setAdapter(listAdapter); | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
int id = v.getId(); | |||
if (id == R.id.send) { | |||
if (!et.getText().toString().isEmpty() && !et_cid.getText().toString().isEmpty()) { | |||
String hex=et.getText().toString().toUpperCase().trim(); | |||
byte[] hexStr = BleStrUtils.stringToByte(hex); | |||
String cid = et_cid.getText().toString().toUpperCase().trim(); | |||
int hexStrCid = Integer.parseInt(cid, 16); | |||
if (mTransmissionDeviceData != null) { | |||
mTransmissionDeviceData.setSendData(hexStrCid, hexStr); | |||
} | |||
} | |||
} else if (id == R.id.bt_clear) { | |||
et.setText(""); | |||
} else if (id == R.id.bt_clear_log) { | |||
mlogList.clear(); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
}else if (id==R.id.bt_cid){ | |||
if (mTransmissionDeviceData != null) { | |||
mTransmissionDeviceData.getCid(); | |||
} | |||
} | |||
} | |||
@Override | |||
public void onVersion(String version) { | |||
} | |||
@Override | |||
public void showdata(String data) { | |||
mlogList.add(0, "收 payload数据"+TimeUtils.getTime()+data); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onSupportUnit(List<SupportUnitBean> list) { | |||
} | |||
@Override | |||
public void onCid(int cid, int vid, int pid) { | |||
mlogList.add(0, "收"+TimeUtils.getTime() + "cid:" + cid + "||vid:" + vid + "||pid:" + pid); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void otherdata(String data) { | |||
mlogList.add(0, "收 透传数据"+TimeUtils.getTime()+data); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void sendData(String data) { | |||
mlogList.add(0, "发 "+TimeUtils.getTime()+data); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
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; | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,101 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.content.Context; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import android.widget.AdapterView; | |||
import android.widget.SeekBar; | |||
import android.widget.TextView; | |||
import androidx.annotation.NonNull; | |||
import androidx.recyclerview.widget.RecyclerView; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import cn.net.aicare.modulelibrary.module.BodyFatScale.User; | |||
public class UserAdapter extends RecyclerView.Adapter<UserAdapter.ViewHolder> { | |||
private List<User> mUser; | |||
private Context mContext; | |||
public UserAdapter(Context context, List<User> mUser) { | |||
this.mContext = context; | |||
this.mUser = mUser; | |||
} | |||
@NonNull | |||
@Override | |||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | |||
return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_user_info,parent)); | |||
} | |||
@Override | |||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) { | |||
} | |||
@Override | |||
public int getItemCount() { | |||
return mUser.size(); | |||
} | |||
class ViewHolder extends RecyclerView.ViewHolder implements SeekBar.OnSeekBarChangeListener { | |||
private TextView id; | |||
private SeekBar agesb, heightsb, weightsb, adcsb; | |||
public ViewHolder(@NonNull View itemView) { | |||
super(itemView); | |||
id = itemView.findViewById(R.id.id); | |||
agesb = itemView.findViewById(R.id.adcsb); | |||
agesb.setOnSeekBarChangeListener(this); | |||
heightsb = itemView.findViewById(R.id.heightsb); | |||
heightsb.setOnSeekBarChangeListener(this); | |||
weightsb = itemView.findViewById(R.id.weightsb); | |||
weightsb.setOnSeekBarChangeListener(this); | |||
adcsb = itemView.findViewById(R.id.adcsb); | |||
adcsb.setOnSeekBarChangeListener(this); | |||
} | |||
@Override | |||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { | |||
int id = seekBar.getId(); | |||
User user = mUser.get(getLayoutPosition()); | |||
if (id == R.id.weightsb) { | |||
user.setWeight(progress); | |||
} else if (id == R.id.adcsb) { | |||
user.setAdc(progress); | |||
} else if (id == R.id.heightsb) { | |||
user.setHeight(progress); | |||
} else if (id == R.id.age) { | |||
user.setAge(progress); | |||
} | |||
} | |||
@Override | |||
public void onStartTrackingTouch(SeekBar seekBar) { | |||
} | |||
@Override | |||
public void onStopTrackingTouch(SeekBar seekBar) { | |||
} | |||
} | |||
} |
@@ -0,0 +1,502 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
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.CompoundButton; | |||
import android.widget.EditText; | |||
import android.widget.ListView; | |||
import android.widget.RadioButton; | |||
import com.pingwang.bluetoothlib.BleBaseActivity; | |||
import com.pingwang.bluetoothlib.bean.BleValueBean; | |||
import com.pingwang.bluetoothlib.config.CmdConfig; | |||
import com.pingwang.bluetoothlib.device.BleDevice; | |||
import com.pingwang.bluetoothlib.device.SendBleBean; | |||
import com.pingwang.bluetoothlib.listener.OnCallbackBle; | |||
import com.pingwang.bluetoothlib.utils.BleStrUtils; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.config.BleDeviceConfig; | |||
import java.lang.ref.WeakReference; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import androidx.annotation.Nullable; | |||
import cn.net.aicare.modulelibrary.module.BodyFatScale.AppHistoryRecordBean; | |||
import cn.net.aicare.modulelibrary.module.BodyFatScale.BodyFatBleUtilsData; | |||
import cn.net.aicare.modulelibrary.module.BodyFatScale.BodyFatDataUtil; | |||
import cn.net.aicare.modulelibrary.module.BodyFatScale.BodyFatRecord; | |||
import cn.net.aicare.modulelibrary.module.BodyFatScale.McuHistoryRecordBean; | |||
import cn.net.aicare.modulelibrary.module.BodyFatScale.User; | |||
public class WeightScaleBle extends BleBaseActivity implements View.OnClickListener, OnCallbackBle, BodyFatBleUtilsData.BleBodyFatCallback { | |||
private String TAG = WeightScaleBle.class.getName(); | |||
private String mAddress; | |||
private List<String> mlogList; | |||
private List<String> mUserlogList; | |||
private ArrayAdapter listAdapter; | |||
private ArrayAdapter userAdapter; | |||
private BodyFatBleUtilsData bodyFatBleUtilsData; | |||
private MHandler mMHandler; | |||
private EditText mEditText; | |||
private RadioButton kg, jing, stlb, lb; | |||
private List<User> mUsers; | |||
private User selectUser; | |||
private int weighunit = BodyFatDataUtil.KG; | |||
private ListView loglistView; | |||
private ListView userlistView; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_weight_scale_ble); | |||
initView(); | |||
setUnitinit(); | |||
initdata(); | |||
} | |||
private void initView(){ | |||
findViewById(R.id.history).setOnClickListener(this); | |||
findViewById(R.id.userlist).setOnClickListener(this); | |||
findViewById(R.id.user).setOnClickListener(this); | |||
findViewById(R.id.adduser).setOnClickListener(this); | |||
findViewById(R.id.syntime).setOnClickListener(this); | |||
kg = findViewById(R.id.kg); | |||
jing = findViewById(R.id.jin); | |||
stlb = findViewById(R.id.st_lb); | |||
lb = findViewById(R.id.lb); | |||
mEditText = findViewById(R.id.edit_Userid); | |||
kg.setChecked(true); | |||
loglistView = findViewById(R.id.log_list); | |||
userlistView = findViewById(R.id.user_list); | |||
} | |||
private void initdata(){ | |||
mAddress = getIntent().getStringExtra("mac"); | |||
WeakReference weakReference = new WeakReference(new MHandler()); | |||
mMHandler = (MHandler) weakReference.get(); | |||
mlogList = new ArrayList<>(); | |||
listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mlogList); | |||
loglistView.setAdapter(listAdapter); | |||
User defaultUser=getdefault(); | |||
selectUser = defaultUser; | |||
mUsers = new ArrayList<>(); | |||
mUsers.add(defaultUser); | |||
mUserlogList = new ArrayList<>(); | |||
mUserlogList.add(defaultUser.toString()); | |||
userAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mUserlogList); | |||
userlistView.setAdapter(userAdapter); | |||
} | |||
private User getdefault(){ | |||
User user = new User(); | |||
user.setModeType(BodyFatDataUtil.MODE_ORDINARY); | |||
user.setSex(BodyFatDataUtil.SEX_MAN); | |||
user.setAge(18); | |||
user.setHeight(170); | |||
user.setAdc(560); | |||
user.setWeight(50); | |||
user.setId(1); | |||
return user; | |||
} | |||
private void setUnitinit() { | |||
kg.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked) { | |||
weighunit = BodyFatDataUtil.KG; | |||
if (bodyFatBleUtilsData != null) | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().setWeightUnit(BodyFatDataUtil.KG, BleDeviceConfig.WEIGHT_BODY_FAT_SCALE)); | |||
} | |||
} | |||
}); | |||
jing.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked) { | |||
weighunit = BodyFatDataUtil.JIN; | |||
if (bodyFatBleUtilsData != null) | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().setWeightUnit(BodyFatDataUtil.JIN, BleDeviceConfig.WEIGHT_BODY_FAT_SCALE)); | |||
} | |||
} | |||
}); | |||
stlb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked) { | |||
weighunit = BodyFatDataUtil.ST; | |||
if (bodyFatBleUtilsData != null) | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().setWeightUnit(BodyFatDataUtil.ST, BleDeviceConfig.WEIGHT_BODY_FAT_SCALE)); | |||
} | |||
} | |||
}); | |||
lb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked) { | |||
weighunit = BodyFatDataUtil.LB; | |||
if (bodyFatBleUtilsData != null) | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().setWeightUnit(BodyFatDataUtil.LB, BleDeviceConfig.WEIGHT_BODY_FAT_SCALE)); | |||
} | |||
} | |||
}); | |||
} | |||
@Override | |||
public void onServiceSuccess() { | |||
mlogList.add(0, "服务与界面建立连接成功"); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
// BleLog.i(TAG, "服务与界面建立连接成功"); | |||
//与服务建立连接 | |||
if (mBluetoothService != null) { | |||
mBluetoothService.setOnCallback(this); | |||
BleDevice bleDevice = mBluetoothService.getBleDevice(mAddress); | |||
if (bleDevice != null) { | |||
BodyFatBleUtilsData.init(bleDevice, this, null); | |||
bodyFatBleUtilsData = BodyFatBleUtilsData.getInstance(); | |||
if (bodyFatBleUtilsData != null) { | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().setWeightUnit(weighunit, BleDeviceConfig.WEIGHT_BODY_FAT_SCALE)); | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().synSysTime()); | |||
} | |||
} | |||
} | |||
} | |||
@Override | |||
public void onServiceErr() { | |||
mlogList.add(0, "服务与界面建立连接出错"); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void unbindServices() { | |||
mlogList.add(0, "服务与界面建立断开连接成功"); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onStartScan() { | |||
mlogList.add(0, "开始扫描"); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onScanning(BleValueBean data) { | |||
mlogList.add(0, "扫描中"); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onScanTimeOut() { | |||
mlogList.add(0, "扫描超时"); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onConnecting(String mac) { | |||
mlogList.add(0, "正在连接" + mac); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onDisConnected(String mac, int code) { | |||
mlogList.add(0, "断开连接" + mac); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onServicesDiscovered(String mac) { | |||
mlogList.add(0, "发现蓝牙服务" + mac); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void bleOpen() { | |||
mlogList.add(0, "蓝牙打开"); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void bleClose() { | |||
mlogList.add(0, "蓝牙关闭"); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onWeightData(int status, float weight, int weightUnit, int decimals) { | |||
mlogList.add(0, "体重数据类型:" + status + " 体重: " + weight + " 单位:" + weightUnit + " 小数点位: " + decimals); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onStatus(int status) { | |||
switch (status) { | |||
case BodyFatDataUtil.WEIGHT_TESTING: | |||
mlogList.add(0, "测量状态:" + status + " 测量实时体重"); | |||
break; | |||
case BodyFatDataUtil.WEIGHT_RESULT: | |||
mlogList.add(0, "测量状态:" + status + " 稳定体重"); | |||
break; | |||
case BodyFatDataUtil.IMPEDANCE_TESTING: | |||
mlogList.add(0, "测量状态:" + status + " 阻抗测量中"); | |||
break; | |||
case BodyFatDataUtil.IMPEDANCE_SUCCESS: | |||
case BodyFatDataUtil.IMPEDANCE_SUCCESS_DATA: | |||
mlogList.add(0, "测量状态:" + status + " 阻抗测量成功"); | |||
break; | |||
case BodyFatDataUtil.IMPEDANCE_FAIL: | |||
mlogList.add(0, "测量状态:" + status + " 阻抗测量失败"); | |||
break; | |||
case BodyFatDataUtil.HEART_TESTING: | |||
mlogList.add(0, "测量状态:" + status + " 心率测量中"); | |||
break; | |||
case BodyFatDataUtil.HEART_SUCCESS: | |||
mlogList.add(0, "测量状态:" + status + " 心率测量成功"); | |||
break; | |||
case BodyFatDataUtil.HEART_FAIL: | |||
mlogList.add(0, "测量状态:" + status + " 心率测量失败"); | |||
break; | |||
case BodyFatDataUtil.TEST_FINISH: | |||
mlogList.add(0, "测量状态:" + status + " 测量完成"); | |||
break; | |||
case BodyFatDataUtil.MUC_REQUEST_USER_INFO: | |||
mlogList.add(0, "测量状态:" + status + "请求用户信息"); | |||
if (bodyFatBleUtilsData != null) | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().setUserInfo(selectUser, BleDeviceConfig.WEIGHT_BODY_FAT_SCALE)); | |||
break; | |||
default: | |||
mlogList.add(0, "测量状态:" + status); | |||
} | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onAdc(int adc, int algorithmic) { | |||
mlogList.add(0, "阻抗:" + adc + " 算法位:" + algorithmic); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onHeartRate(int heartrate) { | |||
mlogList.add(0, "心率:" + heartrate); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onBodyFat(BodyFatRecord bodyFatRecord) { | |||
mlogList.add(0, "体脂数:" + bodyFatRecord.toString()); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onError(int code) { | |||
mlogList.add(0, "历史记录Mcu:" + code); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onHistoryMcu(McuHistoryRecordBean mcuHistoryRecordBean) { | |||
mlogList.add(0, "历史记录Mcu:" + mcuHistoryRecordBean.toString()); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onHistoryApp(AppHistoryRecordBean appHistoryRecordBean) { | |||
mlogList.add(0, "历史记录app:" + appHistoryRecordBean.toString()); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onVersion(String version) { | |||
mlogList.add(0, "版本号:" + version); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onMcuBatteryStatus(int status, int battery) { | |||
mlogList.add(0, "电量状态" + status + " 电量:" + battery); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onSysTime(int status, int[] times) { | |||
mlogList.add(0, "时间状态" + status); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void requestSynTime() { | |||
mlogList.add(0, "同步时间"); | |||
if (bodyFatBleUtilsData != null) | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().synTime()); | |||
} | |||
@Override | |||
public void setTimeCallback(int type, int status) { | |||
String msg = ""; | |||
if (type == CmdConfig.SET_SYS_TIME) { | |||
msg = "设置系统当前时间:"; | |||
} else if (type == CmdConfig.SET_DEVICE_TIME) { | |||
msg = "同步时间"; | |||
} | |||
if (status == BodyFatDataUtil.STATUS_SUCCESS) { | |||
msg = msg + status + " 成功"; | |||
} else if (status == BodyFatDataUtil.STATUS_FAIL) { | |||
msg = msg + status + " 失败"; | |||
} else if (status == BodyFatDataUtil.STATUS_NOSUPORT) { | |||
msg = msg + status + " 不支持"; | |||
} | |||
mlogList.add(0, msg); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void requestSynHistoryCallback(int status) { | |||
if (status == 0) { | |||
mlogList.add(0, "请求历史记录:" + status + " 无历史记录"); | |||
} else if (status == 1) { | |||
mlogList.add(0, "请求历史记录:" + status + " 开始发送历史记录"); | |||
} else { | |||
mlogList.add(0, "请求历史记录:" + status + " 发送历史记录结束"); | |||
} | |||
} | |||
@Override | |||
public void updateUserCallback(int status) { | |||
if (status == 0) { | |||
mlogList.add(0, "更新用户或列表回调" + status + " 更新列表成功"); | |||
} else if (status == 1) { | |||
mlogList.add(0, "更新用户或列表回调" + status + " 更新个人用户成功"); | |||
} else if (status == 2) { | |||
mlogList.add(0, "更新用户或列表回调" + status + " 更新列表失败"); | |||
} else { | |||
mlogList.add(0, "更新用户或列表回调" + status + " 更新个人用户失败"); | |||
} | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
/** | |||
* @param status {@link#Bod} | |||
*/ | |||
@Override | |||
public void setUnitCallback(int status) { | |||
if (status == 0) { | |||
mlogList.add(0, "下发单位回调" + status + " 成功"); | |||
} else if (status == 1) { | |||
mlogList.add(0, "下发单位回调" + status + " 失败"); | |||
} else { | |||
mlogList.add(0, "下发单位回调" + status + " 不支持"); | |||
} | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void requestUserData(int status) { | |||
if (status == 0x01) { | |||
mlogList.add(0, "下发用户信息 " + status); | |||
} else if (status == 0x03) { | |||
mlogList.add(0, "下发用户信息成功 " + status); | |||
} else { | |||
mlogList.add(0, "下发用户信息失败 " + status); | |||
} | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
int id = v.getId(); | |||
switch (id) { | |||
case R.id.history: | |||
if (bodyFatBleUtilsData != null) | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().requestSynHistory()); | |||
break; | |||
case R.id.user: | |||
if (!mEditText.getText().toString().trim().isEmpty()) { | |||
int userid = Integer.parseInt(mEditText.getText().toString().trim()); | |||
if (mUsers.size() >= userid) { | |||
selectUser = mUsers.get(userid - 1); | |||
if (bodyFatBleUtilsData != null) | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().updataPresentUser(selectUser)); | |||
} | |||
} | |||
break; | |||
case R.id.userlist: | |||
for (User mUser : mUsers) { | |||
if (bodyFatBleUtilsData != null) | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().setUserInfoList(mUser)); | |||
} | |||
if (bodyFatBleUtilsData != null) | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().updateUsersComplete()); | |||
break; | |||
case R.id.adduser: | |||
AddUserDialog addUserDialog = new AddUserDialog(new AddUserDialog.OnDialogListener() { | |||
@Override | |||
public void tvSucceedListener(User user) { | |||
user.setId(mUsers.size() + 1); | |||
mUsers.add(user); | |||
mUserlogList.add(user.toString()); | |||
userAdapter.notifyDataSetChanged(); | |||
} | |||
}); | |||
addUserDialog.show(getSupportFragmentManager()); | |||
break; | |||
case R.id.syntime: | |||
if (bodyFatBleUtilsData != null) { | |||
SendBleBean sendBleBean = BodyFatDataUtil.getInstance().synSysTime(); | |||
Log.e("time", BleStrUtils.byte2HexStr(sendBleBean.getHex())); | |||
bodyFatBleUtilsData.sendData(sendBleBean); | |||
} | |||
break; | |||
} | |||
} | |||
private final int ToRefreUi = 300; | |||
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; | |||
} | |||
} | |||
} | |||
} |
@@ -12,12 +12,14 @@ import android.widget.ListView; | |||
import android.widget.RadioButton; | |||
import android.widget.Toast; | |||
import com.pingwang.bluetoothlib.BleBaseActivity; | |||
import com.pingwang.bluetoothlib.bean.BleValueBean; | |||
import com.pingwang.bluetoothlib.config.BleDeviceConfig; | |||
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 aicare.net.cn.sdk.ailinksdkdemoandroid.config.BleDeviceConfig; | |||
import java.lang.ref.WeakReference; | |||
import java.util.ArrayList; | |||
@@ -41,7 +43,8 @@ public class WeightScaleWifiBle extends BleBaseActivity implements View.OnClickL | |||
private BodyFatBleUtilsData bodyFatBleUtilsData; | |||
private MHandler mMHandler; | |||
private EditText mEditText; | |||
private RadioButton kg,jing,stlb,lb; | |||
private RadioButton kg, jing, stlb, lb; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
@@ -55,10 +58,10 @@ public class WeightScaleWifiBle extends BleBaseActivity implements View.OnClickL | |||
findViewById(R.id.setedpaw).setOnClickListener(this); | |||
findViewById(R.id.setedmac).setOnClickListener(this); | |||
mEditText = findViewById(R.id.select_wifi_et); | |||
kg=findViewById(R.id.kg); | |||
jing=findViewById(R.id.jin); | |||
stlb=findViewById(R.id.st_lb); | |||
lb=findViewById(R.id.lb); | |||
kg = findViewById(R.id.kg); | |||
jing = findViewById(R.id.jin); | |||
stlb = findViewById(R.id.st_lb); | |||
lb = findViewById(R.id.lb); | |||
kg.setChecked(true); | |||
mAddress = getIntent().getStringExtra("mac"); | |||
mList = new ArrayList<>(); | |||
@@ -70,36 +73,32 @@ public class WeightScaleWifiBle extends BleBaseActivity implements View.OnClickL | |||
kg.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked){ | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil | |||
.getInstance().setWeightUnit(0, BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_WIFI_BLE)); | |||
if (isChecked) { | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().setWeightUnit(BodyFatDataUtil.KG, BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_WIFI_BLE)); | |||
} | |||
} | |||
}); | |||
jing.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
jing.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked){ | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil | |||
.getInstance().setWeightUnit(1, BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_WIFI_BLE)); | |||
if (isChecked) { | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().setWeightUnit(BodyFatDataUtil.JIN, BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_WIFI_BLE)); | |||
} | |||
} | |||
}); | |||
stlb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked){ | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil | |||
.getInstance().setWeightUnit(4, BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_WIFI_BLE)); | |||
if (isChecked) { | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().setWeightUnit(BodyFatDataUtil.ST, BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_WIFI_BLE)); | |||
} | |||
} | |||
}); | |||
lb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
lb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked){ | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil | |||
.getInstance().setWeightUnit(6, BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_WIFI_BLE)); | |||
if (isChecked) { | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().setWeightUnit(BodyFatDataUtil.LB, BleDeviceConfig.WEIGHT_BODY_FAT_SCALE_WIFI_BLE)); | |||
} | |||
} | |||
}); | |||
@@ -181,42 +180,42 @@ public class WeightScaleWifiBle extends BleBaseActivity implements View.OnClickL | |||
@Override | |||
public void onStatus(int status) { | |||
switch (status){ | |||
case BodyFatDataUtil.WEIGHT_TESTING: | |||
mList.add(0, "测量状态:" + status+" 测量实时体重"); | |||
break; | |||
case BodyFatDataUtil.WEIGHT_RESULT: | |||
mList.add(0, "测量状态:" + status+" 稳定体重"); | |||
break; | |||
case BodyFatDataUtil.IMPEDANCE_TESTING: | |||
mList.add(0, "测量状态:" + status+" 阻抗测量中"); | |||
break; | |||
case BodyFatDataUtil.IMPEDANCE_SUCCESS_DATA: | |||
case BodyFatDataUtil.IMPEDANCE_SUCCESS: | |||
mList.add(0, "测量状态:" + status+" 阻抗测量成功"); | |||
break; | |||
case BodyFatDataUtil.IMPEDANCE_FAIL: | |||
mList.add(0, "测量状态:" + status+" 阻抗测量失败"); | |||
break; | |||
case BodyFatDataUtil.HEART_TESTING: | |||
mList.add(0, "测量状态:" + status+" 心率测量中"); | |||
break; | |||
case BodyFatDataUtil.HEART_SUCCESS: | |||
mList.add(0, "测量状态:" + status+" 心率测量成功"); | |||
break; | |||
case BodyFatDataUtil.HEART_FAIL: | |||
mList.add(0, "测量状态:" + status+" 心率测量失败"); | |||
break; | |||
case BodyFatDataUtil.TEST_FINISH: | |||
mList.add(0, "测量状态:" + status+" 测量完成"); | |||
break; | |||
case BodyFatDataUtil.MUC_REQUEST_USER_INFO: | |||
mList.add(0,"测量状态:" + status+"请求用户信息"); | |||
break; | |||
default: | |||
mList.add(0, "测量状态:" + status); | |||
} | |||
switch (status) { | |||
case BodyFatDataUtil.WEIGHT_TESTING: | |||
mList.add(0, "测量状态:" + status + " 测量实时体重"); | |||
break; | |||
case BodyFatDataUtil.WEIGHT_RESULT: | |||
mList.add(0, "测量状态:" + status + " 稳定体重"); | |||
break; | |||
case BodyFatDataUtil.IMPEDANCE_TESTING: | |||
mList.add(0, "测量状态:" + status + " 阻抗测量中"); | |||
break; | |||
case BodyFatDataUtil.IMPEDANCE_SUCCESS_DATA: | |||
case BodyFatDataUtil.IMPEDANCE_SUCCESS: | |||
mList.add(0, "测量状态:" + status + " 阻抗测量成功"); | |||
break; | |||
case BodyFatDataUtil.IMPEDANCE_FAIL: | |||
mList.add(0, "测量状态:" + status + " 阻抗测量失败"); | |||
break; | |||
case BodyFatDataUtil.HEART_TESTING: | |||
mList.add(0, "测量状态:" + status + " 心率测量中"); | |||
break; | |||
case BodyFatDataUtil.HEART_SUCCESS: | |||
mList.add(0, "测量状态:" + status + " 心率测量成功"); | |||
break; | |||
case BodyFatDataUtil.HEART_FAIL: | |||
mList.add(0, "测量状态:" + status + " 心率测量失败"); | |||
break; | |||
case BodyFatDataUtil.TEST_FINISH: | |||
mList.add(0, "测量状态:" + status + " 测量完成"); | |||
break; | |||
case BodyFatDataUtil.MUC_REQUEST_USER_INFO: | |||
mList.add(0, "测量状态:" + status + "请求用户信息"); | |||
break; | |||
default: | |||
mList.add(0, "测量状态:" + status); | |||
} | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@@ -234,11 +233,10 @@ public class WeightScaleWifiBle extends BleBaseActivity implements View.OnClickL | |||
@Override | |||
public void onBodyFat(BodyFatRecord bodyFatRecord) { | |||
mList.add(0, "体脂数:" + bodyFatRecord.toString()); | |||
mList.add(0, "体脂数据:" + bodyFatRecord.toString()); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onError(int code) { | |||
mList.add(0, "历史记录Mcu:" + code); | |||
@@ -249,14 +247,14 @@ public class WeightScaleWifiBle extends BleBaseActivity implements View.OnClickL | |||
public void onHistoryMcu(McuHistoryRecordBean mcuHistoryRecordBean) { | |||
mList.add(0, "历史记录Mcu:" + mcuHistoryRecordBean.toString()); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
// mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onHistoryApp(AppHistoryRecordBean appHistoryRecordBean) { | |||
mList.add(0, "历史记录app:" + appHistoryRecordBean.toString()); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
@@ -268,63 +266,74 @@ public class WeightScaleWifiBle extends BleBaseActivity implements View.OnClickL | |||
@Override | |||
public void onMcuBatteryStatus(int status, int battery) { | |||
mList.add(0,"电量状态"+status+" 电量:"+battery); | |||
mList.add(0, "电量状态" + status + " 电量:" + battery); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onSysTime(int status, int[] times) { | |||
mList.add(0,"时间状态"+status); | |||
mList.add(0, "时间状态" + status); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void requestSynTime() { | |||
mList.add(0,"请求同步时间"); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
mList.add(0,"同步时间"); | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().synTime()); | |||
} | |||
@Override | |||
public void setTimeCallback(int type, int status) { | |||
mList.add(0,"设置时间回调"); | |||
public void setTimeCallback(int type,int status) { | |||
String msg = ""; | |||
if (type == CmdConfig.SET_SYS_TIME) { | |||
msg = "设置系统当前时间:"; | |||
} else if (type == CmdConfig.SET_DEVICE_TIME) { | |||
msg = "同步时间"; | |||
} | |||
if (status == BodyFatDataUtil.STATUS_SUCCESS) { | |||
msg = msg + status + " 成功"; | |||
} else if (status == BodyFatDataUtil.STATUS_FAIL) { | |||
msg = msg + status + " 失败"; | |||
} else if (status == BodyFatDataUtil.STATUS_NOSUPORT) { | |||
msg = msg + status + " 不支持"; | |||
} | |||
mList.add(0, msg); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void requestSynHistoryCallback(int status) { | |||
if (status==0) { | |||
mList.add(0, "" + status+" 无历史记录"); | |||
}else if (status==1){ | |||
mList.add(0, "请求历史记录" + status+" 开始发送历史记录"); | |||
}else { | |||
mList.add(0, "请求历史记录" + status+" 发送历史记录结束"); | |||
if (status == 0) { | |||
mList.add(0, "" + status + " 无历史记录"); | |||
} else if (status == 1) { | |||
mList.add(0, "请求历史记录" + status + " 开始发送历史记录"); | |||
} else { | |||
mList.add(0, "请求历史记录" + status + " 发送历史记录结束"); | |||
} | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void updateUserCallback(int status) { | |||
if (status==0) { | |||
mList.add(0, "更新用户或列表回调" + status+" 更新列表成功"); | |||
}else if (status==1){ | |||
mList.add(0, "更新用户或列表回调" + status+" 更新个人用户成功"); | |||
}else if (status==2){ | |||
mList.add(0, "更新用户或列表回调" + status+" 更新列表失败"); | |||
}else { | |||
mList.add(0, "更新用户或列表回调" + status+" 更新个人用户失败"); | |||
if (status == 0) { | |||
mList.add(0, "更新用户或列表回调" + status + " 更新列表成功"); | |||
} else if (status == 1) { | |||
mList.add(0, "更新用户或列表回调" + status + " 更新个人用户成功"); | |||
} else if (status == 2) { | |||
mList.add(0, "更新用户或列表回调" + status + " 更新列表失败"); | |||
} else { | |||
mList.add(0, "更新用户或列表回调" + status + " 更新个人用户失败"); | |||
} | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void setUnitCallback(int status) { | |||
if (status==0) { | |||
if (status == 0) { | |||
mList.add(0, "下发单位回调" + status + " 成功"); | |||
}else if (status==1){ | |||
} else if (status == 1) { | |||
mList.add(0, "下发单位回调" + status + " 失败"); | |||
}else { | |||
} else { | |||
mList.add(0, "下发单位回调" + status + " 不支持"); | |||
} | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
@@ -332,18 +341,17 @@ public class WeightScaleWifiBle extends BleBaseActivity implements View.OnClickL | |||
@Override | |||
public void requestUserData(int status) { | |||
if (status==0x01){ | |||
mList.add(0,"下发用户信息 "+status); | |||
}else if (status==0x03){ | |||
mList.add(0,"下发用户信息成功 "+status); | |||
}else { | |||
mList.add(0,"下发用户信息失败 "+status); | |||
if (status == 0x01) { | |||
mList.add(0, "下发用户信息 " + status); | |||
} else if (status == 0x03) { | |||
mList.add(0, "下发用户信息成功 " + status); | |||
} else { | |||
mList.add(0, "下发用户信息失败 " + status); | |||
} | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void OnBleAndWifiStatus(int blestatus, int wifistatus, int workstatus) { | |||
BleLog.e(TAG, "蓝牙状态:" + blestatus + " wifi状态:" + " 工作状态:" + workstatus); | |||
@@ -390,22 +398,34 @@ public class WeightScaleWifiBle extends BleBaseActivity implements View.OnClickL | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
private boolean issetMac=false; | |||
private boolean issetMac = false; | |||
/** | |||
* | |||
* @param type | |||
* @param status {@link BodyFatDataUtil#STATUS_SUCCESS} | |||
* | |||
*/ | |||
@Override | |||
public void OnSetWifiNameOrPwdOrConnectCallback(int type, int status) { | |||
if (type== BodyFatDataUtil.SET_WIFI_MAC){ | |||
mList.add(0, "获取到设置的mac地址状态 " +status); | |||
if (status== BodyFatDataUtil.STATUS_SUCCESS)issetMac=true; | |||
// bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().getSelectWifiMac()); | |||
if (type == BodyFatDataUtil.SET_WIFI_MAC) { | |||
mList.add(0, "获取到设置的mac地址状态 " + status); | |||
if (status == BodyFatDataUtil.STATUS_SUCCESS){ | |||
issetMac = true; | |||
}else { | |||
} | |||
} | |||
if (type== BodyFatDataUtil.SET_WIFI_PAW){ | |||
mList.add(0, "获取到设置的密码状态 " +status); | |||
// bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().getSelectWifiPwd()); | |||
if (issetMac)mMHandler.sendEmptyMessage(ConnectWifi); | |||
if (type == BodyFatDataUtil.SET_WIFI_PAW) { | |||
mList.add(0, "获取到设置的密码状态 " + status); | |||
if (status == BodyFatDataUtil.STATUS_SUCCESS && issetMac) { | |||
mMHandler.sendEmptyMessage(ConnectWifi); | |||
} | |||
} | |||
if (type== BodyFatDataUtil.DIS_OR_CON_WIFI){ | |||
mList.add(0, "发起连接 " +status); | |||
if (type == BodyFatDataUtil.DIS_OR_CON_WIFI) { | |||
mList.add(0, "发起连接 " + status); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@@ -423,14 +443,13 @@ public class WeightScaleWifiBle extends BleBaseActivity implements View.OnClickL | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void getDid(long did) { | |||
mList.add(0, "did: " + did); | |||
public void getDid(long sn) { | |||
mList.add(0, "sn: " + sn); | |||
mMHandler.sendEmptyMessage(ToRefreUi); | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
int id = v.getId(); | |||
@@ -447,31 +466,34 @@ public class WeightScaleWifiBle extends BleBaseActivity implements View.OnClickL | |||
case R.id.connect_wifi: | |||
try { | |||
int selectWifi = Integer.valueOf(mEditText.getText().toString().trim()); | |||
WifiDialog.newInstance().setTitle(mHashMap.get(selectWifi),wifimacMap.get(selectWifi)).setOnDialogListener(new WifiDialog.OnDialogListener() { | |||
@Override | |||
public void tvCancelListener(View v) { | |||
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) { | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().setWifiMac(wifimacMap.get(selectWifi))); | |||
if (data.equals("") || data.length() > 8) { | |||
setPaw(data); | |||
} else { | |||
Toast.makeText(WeightScaleWifiBle.this, "密码格式不对", Toast.LENGTH_SHORT).show(); | |||
@Override | |||
public void tvSucceedListener(View v, String data) { | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().setWifiMac(wifimacMap.get(selectWifi))); | |||
if (data.equals("") || data.length() > 8) { | |||
setPaw(data); | |||
} else { | |||
Toast.makeText(WeightScaleWifiBle.this, "密码格式不对", Toast.LENGTH_SHORT).show(); | |||
} | |||
} | |||
} | |||
@Override | |||
public void etModifyName(EditText v) { | |||
@Override | |||
public void etModifyName(EditText v) { | |||
} | |||
}).show(getSupportFragmentManager()); | |||
} | |||
}).show(getSupportFragmentManager()); | |||
} | |||
} catch (NumberFormatException e) { | |||
e.printStackTrace(); | |||
mMHandler.sendEmptyMessage(ConnectWifi); | |||
} | |||
break; | |||
case R.id.setedmac: | |||
bodyFatBleUtilsData.sendData(BodyFatDataUtil.getInstance().getSelectWifiMac()); | |||
@@ -492,7 +514,7 @@ public class WeightScaleWifiBle extends BleBaseActivity implements View.OnClickL | |||
} | |||
private final int ToRefreUi = 300; | |||
private final int ConnectWifi=400; | |||
private final int ConnectWifi = 400; | |||
private class MHandler extends Handler { | |||
@Override | |||
@@ -511,6 +533,15 @@ public class WeightScaleWifiBle extends BleBaseActivity implements View.OnClickL | |||
} | |||
} | |||
/** | |||
* 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]; | |||
@@ -549,5 +580,4 @@ public class WeightScaleWifiBle extends BleBaseActivity implements View.OnClickL | |||
} | |||
} |
@@ -0,0 +1,870 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid; | |||
import android.app.AlertDialog; | |||
import android.content.DialogInterface; | |||
import android.content.Intent; | |||
import android.content.pm.PackageManager; | |||
import android.location.LocationManager; | |||
import android.os.Build; | |||
import android.os.Bundle; | |||
import android.provider.Settings; | |||
import android.util.Log; | |||
import android.view.View; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.Button; | |||
import android.widget.CompoundButton; | |||
import android.widget.EditText; | |||
import android.widget.ListView; | |||
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.JSONException; | |||
import org.json.JSONObject; | |||
import java.io.ByteArrayOutputStream; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.net.HttpURLConnection; | |||
import java.net.URL; | |||
import java.text.SimpleDateFormat; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.Locale; | |||
import cn.net.aicare.modulelibrary.module.EightBodyfatscale.EightBodyfatUtil; | |||
import cn.net.aicare.modulelibrary.module.wifi.WifiConfig; | |||
import cn.net.aicare.modulelibrary.module.wifi.WifiUtils; | |||
public class WifiConfigActivity extends AppCompatActivity implements View.OnClickListener, WifiUtils.OnWifiEventListener { | |||
private String TAG = WifiConfigActivity.class.getName(); | |||
private EditText ssid, paw, key, sn, devicename; | |||
private ListView mListView; | |||
private ArrayAdapter logadapter; | |||
private List<String> loglist; | |||
private Button btn_connect; | |||
private Button btn_weight_result; | |||
private WifiUtils mWifiUtils; | |||
private Button btn_getdeviceid; | |||
private Button btn_login; | |||
private Button get_record; | |||
private String SN; | |||
private String myDeviceId; | |||
private String token; | |||
private long appid; | |||
private List<Long> bodyId; | |||
private RadioButton kg, jing, stlb, lb; | |||
private String mDeviceName; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_wifi_config); | |||
ssid = findViewById(R.id.ssid); | |||
paw = findViewById(R.id.password); | |||
key = findViewById(R.id.key); | |||
btn_getdeviceid = findViewById(R.id.deviceid); | |||
btn_weight_result = findViewById(R.id.weight_result); | |||
get_record = findViewById(R.id.get_record); | |||
mListView = findViewById(R.id.log_list); | |||
btn_connect = findViewById(R.id.btn_connect); | |||
btn_login = findViewById(R.id.btn_login); | |||
sn = findViewById(R.id.sn); | |||
devicename = findViewById(R.id.device_name); | |||
btn_login.setOnClickListener(this); | |||
btn_weight_result.setOnClickListener(this); | |||
btn_connect.setOnClickListener(this); | |||
btn_getdeviceid.setOnClickListener(this); | |||
get_record.setOnClickListener(this); | |||
findViewById(R.id.clear_log).setOnClickListener(this); | |||
findViewById(R.id.clear_record).setOnClickListener(this); | |||
loglist = new ArrayList<>(); | |||
logadapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, loglist); | |||
mListView.setAdapter(logadapter); | |||
mWifiUtils = new WifiUtils(this, this); | |||
mWifiUtils.setLoopSendEnable(false); | |||
mWifiUtils.setInterval(5); | |||
ssid.setText(mWifiUtils.getSsidstring() == null ? "Elink-wif" : mWifiUtils.getSsidstring().replace("\"", "")); | |||
paw.setText("elink1234567890"); | |||
key.setText("1234567812345678"); | |||
sn.setText("574d0868174f882078a5784b1f8d48"); | |||
devicename.setText("wifi秤"); | |||
bodyId = new ArrayList<>(); | |||
kg = findViewById(R.id.kg); | |||
jing = findViewById(R.id.jin); | |||
stlb = findViewById(R.id.st_lb); | |||
lb = findViewById(R.id.lb); | |||
kg.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked) { | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
setUnit(WifiConfig.KG); | |||
} catch (Throwable throwable) { | |||
throwable.printStackTrace(); | |||
} | |||
} | |||
}).start(); | |||
} | |||
} | |||
}); | |||
jing.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked) { | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
setUnit(WifiConfig.JIN); | |||
} catch (Throwable throwable) { | |||
throwable.printStackTrace(); | |||
} | |||
} | |||
}).start(); | |||
} | |||
} | |||
}); | |||
stlb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked) { | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
setUnit(WifiConfig.ST); | |||
} catch (Throwable throwable) { | |||
throwable.printStackTrace(); | |||
} | |||
} | |||
}).start(); | |||
} | |||
} | |||
}); | |||
lb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if (isChecked) { | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
setUnit(WifiConfig.LB); | |||
} catch (Throwable throwable) { | |||
throwable.printStackTrace(); | |||
} | |||
} | |||
}).start(); | |||
} | |||
} | |||
}); | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
if (v.getId() == R.id.btn_connect) { | |||
if (mWifiUtils.getRunning() == 0) { | |||
btn_connect.setText("停止"); | |||
mWifiUtils.startSendData(ssid.getText().toString().trim(), paw.getText().toString().trim(), key.getText().toString().trim()); | |||
} else { | |||
mWifiUtils.end(); | |||
btn_connect.setText("开始配网"); | |||
} | |||
} else if (v.getId() == R.id.deviceid) { | |||
SN = sn.getText().toString().trim(); | |||
mDeviceName = devicename.getText().toString().trim(); | |||
if (appid != 0 && token != null && !SN.isEmpty() && !mDeviceName.isEmpty()) { | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
getDeviceid(); | |||
} catch (Throwable throwable) { | |||
throwable.printStackTrace(); | |||
} | |||
} | |||
}).start(); | |||
} else { | |||
if (appid == 0 || token == null) { | |||
loglist.add(0, "未登录"); | |||
} | |||
if (SN.isEmpty()) { | |||
loglist.add(0, "没有SN号"); | |||
} | |||
if (mDeviceName.isEmpty()) { | |||
loglist.add(0, "没有设备名称"); | |||
} | |||
} | |||
logadapter.notifyDataSetChanged(); | |||
} else if (v.getId() == R.id.weight_result) { | |||
if (appid != 0 && token != null && myDeviceId != null) { | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
getWeight(appid, token, myDeviceId); | |||
} catch (Throwable throwable) { | |||
throwable.printStackTrace(); | |||
} | |||
} | |||
}).start(); | |||
} else { | |||
if (appid == 0 || token == null) { | |||
loglist.add(0, "未登录"); | |||
} | |||
if (myDeviceId == null) { | |||
loglist.add(0, "没有得到设备Id"); | |||
} | |||
} | |||
logadapter.notifyDataSetChanged(); | |||
} else if (v.getId() == R.id.btn_login) { | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
login(); | |||
} catch (Throwable throwable) { | |||
throwable.printStackTrace(); | |||
} | |||
} | |||
}).start(); | |||
} else if (v.getId() == R.id.clear_log) { | |||
loglist.clear(); | |||
logadapter.notifyDataSetChanged(); | |||
} else if (v.getId() == R.id.clear_record) { | |||
if (bodyId.size() != 0) { | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
for (int i = 0; i < bodyId.size(); i++) { | |||
try { | |||
delRecord(bodyId.get(i)); | |||
} catch (Throwable throwable) { | |||
throwable.printStackTrace(); | |||
} | |||
} | |||
} | |||
}).start(); | |||
} else { | |||
loglist.add(0, "没有BodyFatId"); | |||
logadapter.notifyDataSetChanged(); | |||
} | |||
} else if (v.getId() == R.id.get_record) { | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
getTestRecord(); | |||
} catch (Throwable throwable) { | |||
throwable.printStackTrace(); | |||
} | |||
} | |||
}).start(); | |||
} | |||
} | |||
@Override | |||
public void onEvent(int code) { | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
switch (code) { | |||
case WifiConfig.KEY_ILLEGAL: | |||
loglist.add(0, "加密key非法"); | |||
break; | |||
case WifiConfig.ERROR_EXCEPTIONAL: | |||
loglist.add(0, "异常"); | |||
break; | |||
case WifiConfig.INFORMATION_SUCCESSFUL: | |||
loglist.add(0, "生成数据类info 成功"); | |||
break; | |||
case WifiConfig.DEVICE_CONNECTION_SUCCESSFUL: | |||
mWifiUtils.end(); | |||
loglist.add(0, "设备联网成功成功"); | |||
btn_connect.setText("开始配网"); | |||
//调取登录 通过SN号去获取deviceId | |||
break; | |||
case WifiConfig.START_SEND_DATA: | |||
loglist.add(0, "开始发送加密包"); | |||
break; | |||
case WifiConfig.ERROR_START_SEND_DATA: | |||
loglist.add(0, "开始发送加密包,出错"); | |||
break; | |||
case WifiConfig.START_RECEIVE_DATA: | |||
loglist.add(0, "开始接收设备数据"); | |||
break; | |||
case WifiConfig.ERROR_START_RECEIVE_DATA: | |||
loglist.add(0, "开始接收设备数据,出错"); | |||
break; | |||
case WifiConfig.SSID_KEY_NULL: | |||
loglist.add(0, "ssid为空或key为空"); | |||
break; | |||
} | |||
logadapter.notifyDataSetChanged(); | |||
} | |||
}); | |||
} | |||
@Override | |||
protected void onDestroy() { | |||
super.onDestroy(); | |||
mWifiUtils.onDestory(); | |||
} | |||
public void login() throws Throwable { | |||
URL uri = new URL("http://test.ailink.app.aicare.net.cn/api/user/login?key=inet_elink&username=dhls@qq.com&password=dc483e80a7a0bd9ef71d8cf973673924"); | |||
HttpURLConnection httpURLConnection = (HttpURLConnection) uri.openConnection(); | |||
// Post请求必须设置允许输出 | |||
httpURLConnection.setDoOutput(true); | |||
// Post请求不能使用缓存 | |||
httpURLConnection.setUseCaches(false); | |||
// 设置为Post请求 | |||
httpURLConnection.setRequestMethod("POST"); | |||
httpURLConnection.setInstanceFollowRedirects(true); | |||
// 配置请求Content-Type | |||
httpURLConnection.setRequestProperty("Content-Type", | |||
"application/x-www-form-urlencode"); | |||
// 设置连接超时时间 | |||
httpURLConnection.setConnectTimeout(6 * 1000); | |||
// 开始连接 | |||
httpURLConnection.connect(); | |||
// DataOutputStream dos = new DataOutputStream(httpURLConnection.getOutputStream()); | |||
// dos.write(map.toString().getBytes()); | |||
// dos.flush(); | |||
// dos.close(); | |||
// 判断请求是否成功 | |||
if (httpURLConnection.getResponseCode() == 200) { | |||
// 获取返回的数据 | |||
byte[] data = readInputStream(httpURLConnection.getInputStream()); | |||
String result = new String(data, "UTF-8"); | |||
Log.i(TAG, result); | |||
JSONObject jsonObject = new JSONObject(result); | |||
JSONObject datajson = jsonObject.getJSONObject("data"); | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
token = jsonObject.getString("token"); | |||
appid = datajson.getLong("appUserId"); | |||
loglist.add(0, "登录成功"); | |||
logadapter.notifyDataSetChanged(); | |||
} catch (JSONException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
}); | |||
} else { | |||
Log.i(TAG, "Post方式请求失败"); | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
loglist.add(0, "登录失败"); | |||
} | |||
}); | |||
} | |||
} | |||
public void getWeight(long appid, String token, String deviceId) throws Throwable { | |||
StringBuilder stringBuilder = new StringBuilder(); | |||
stringBuilder.append("http://test.ailink.app.aicare.net.cn/api/BFScale/list?key=inet_elink&appUserId="); | |||
stringBuilder.append(appid); | |||
stringBuilder.append("&token="); | |||
stringBuilder.append(token); | |||
stringBuilder.append("&deviceId="); | |||
stringBuilder.append(deviceId); | |||
stringBuilder.append("&subUserId=1&maxId=0"); | |||
URL uri = new URL(stringBuilder.toString()); | |||
HttpURLConnection httpURLConnection = (HttpURLConnection) uri.openConnection(); | |||
// // Post请求必须设置允许输出 | |||
// httpURLConnection.setDoOutput(true); | |||
// // Post请求不能使用缓存 | |||
// httpURLConnection.setUseCaches(false); | |||
// 设置为Post请求 | |||
// httpURLConnection.setRequestMethod("GET"); | |||
// httpURLConnection.setInstanceFollowRedirects(true); | |||
// // 配置请求Content-Type | |||
// httpURLConnection.setRequestProperty("Content-Type", | |||
// "application/x-www-form-urlencode"); | |||
// 设置连接超时时间 | |||
httpURLConnection.setConnectTimeout(6 * 1000); | |||
// 开始连接 | |||
httpURLConnection.connect(); | |||
// DataOutputStream dos = new DataOutputStream(httpURLConnection.getOutputStream()); | |||
// dos.write(map.toString().getBytes()); | |||
// dos.flush(); | |||
// dos.close(); | |||
// 判断请求是否成功 | |||
if (httpURLConnection.getResponseCode() == 200) { | |||
// 获取返回的数据 | |||
byte[] data = readInputStream(httpURLConnection.getInputStream()); | |||
String result = new String(data, "UTF-8"); | |||
JSONObject jsonObject = new JSONObject(result); | |||
JSONArray datajson = jsonObject.getJSONArray("data"); | |||
bodyId.clear(); | |||
for (int i = 0; i < datajson.length(); i++) { | |||
bodyId.add(datajson.getJSONObject(i).getLong("bodyFatId")); | |||
} | |||
Log.i(TAG, result); | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
loglist.add(0, result); | |||
logadapter.notifyDataSetChanged(); | |||
loglist.add(0, "总共有:" + bodyId.size()); | |||
logadapter.notifyDataSetChanged(); | |||
} | |||
}); | |||
} else { | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
loglist.add(0, "请求失败"); | |||
logadapter.notifyDataSetChanged(); | |||
} | |||
}); | |||
} | |||
} | |||
public void getDeviceid() throws Throwable { | |||
StringBuilder stringBuilder = new StringBuilder(); | |||
stringBuilder.append("http://test.ailink.app.aicare.net.cn/api/device/getDeviceBySN?key=inet_elink&appUserId="); | |||
stringBuilder.append(appid); | |||
stringBuilder.append("&token="); | |||
stringBuilder.append(token); | |||
stringBuilder.append("&deviceSN="); | |||
stringBuilder.append(SN); | |||
Log.e(TAG, stringBuilder.toString()); | |||
URL uri = new URL(stringBuilder.toString()); | |||
HttpURLConnection httpURLConnection = (HttpURLConnection) uri.openConnection(); | |||
// Post请求必须设置允许输出 | |||
httpURLConnection.setDoOutput(true); | |||
// Post请求不能使用缓存 | |||
httpURLConnection.setUseCaches(false); | |||
// 设置为Post请求 | |||
httpURLConnection.setRequestMethod("POST"); | |||
httpURLConnection.setInstanceFollowRedirects(true); | |||
// 配置请求Content-Type | |||
httpURLConnection.setRequestProperty("Content-Type", | |||
"application/x-www-form-urlencode"); | |||
// 设置连接超时时间 | |||
httpURLConnection.setConnectTimeout(6 * 1000); | |||
// 开始连接 | |||
httpURLConnection.connect(); | |||
// DataOutputStream dos = new DataOutputStream(httpURLConnection.getOutputStream()); | |||
// dos.write(map.toString().getBytes()); | |||
// dos.flush(); | |||
// dos.close(); | |||
// 判断请求是否成功 | |||
if (httpURLConnection.getResponseCode() == 200) { | |||
// 获取返回的数据 | |||
byte[] data = readInputStream(httpURLConnection.getInputStream()); | |||
String result = new String(data, "UTF-8"); | |||
Log.i(TAG, result); | |||
JSONObject jsonObject = new JSONObject(result); | |||
JSONArray datajson = jsonObject.getJSONArray("data"); | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
if (datajson.length() > 0) | |||
myDeviceId = datajson.getJSONObject(0).getString("deviceId"); | |||
loglist.add(0, "设备信息" + result); | |||
logadapter.notifyDataSetChanged(); | |||
} catch (JSONException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
}); | |||
bindDevice(); | |||
} else { | |||
Log.i(TAG, "Post方式请求失败"); | |||
} | |||
} | |||
public void bindDevice() throws Throwable { | |||
StringBuilder stringBuilder = new StringBuilder(); | |||
stringBuilder.append("http://test.ailink.app.aicare.net.cn/api/device/update?key=inet_elink&appUserId="); | |||
stringBuilder.append(appid); | |||
stringBuilder.append("&token="); | |||
stringBuilder.append(token); | |||
stringBuilder.append("&deviceId="); | |||
stringBuilder.append(myDeviceId); | |||
stringBuilder.append("&roomId=4326&deviceName="); | |||
stringBuilder.append(mDeviceName); | |||
URL uri = new URL(stringBuilder.toString()); | |||
HttpURLConnection httpURLConnection = (HttpURLConnection) uri.openConnection(); | |||
// Post请求必须设置允许输出 | |||
httpURLConnection.setDoOutput(true); | |||
// Post请求不能使用缓存 | |||
httpURLConnection.setUseCaches(false); | |||
// 设置为Post请求 | |||
httpURLConnection.setRequestMethod("POST"); | |||
httpURLConnection.setInstanceFollowRedirects(true); | |||
// 配置请求Content-Type | |||
httpURLConnection.setRequestProperty("Content-Type", | |||
"application/x-www-form-urlencode"); | |||
// 设置连接超时时间 | |||
httpURLConnection.setConnectTimeout(6 * 1000); | |||
// 开始连接 | |||
httpURLConnection.connect(); | |||
// DataOutputStream dos = new DataOutputStream(httpURLConnection.getOutputStream()); | |||
// dos.write(map.toString().getBytes()); | |||
// dos.flush(); | |||
// dos.close(); | |||
// 判断请求是否成功 | |||
if (httpURLConnection.getResponseCode() == 200) { | |||
// 获取返回的数据 | |||
byte[] data = readInputStream(httpURLConnection.getInputStream()); | |||
String result = new String(data, "UTF-8"); | |||
Log.i(TAG, result); | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
loglist.add(0, "绑定设备" + result); | |||
logadapter.notifyDataSetChanged(); | |||
} | |||
}); | |||
} else { | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
loglist.add(0, "绑定设备失败"); | |||
logadapter.notifyDataSetChanged(); | |||
} | |||
}); | |||
} | |||
} | |||
public void delRecord(Long bodyid) throws Throwable { | |||
StringBuilder stringBuilder = new StringBuilder(); | |||
stringBuilder.append("http://test.ailink.app.aicare.net.cn/api/BFScale/delete?key=inet_elink&appUserId="); | |||
stringBuilder.append(appid); | |||
stringBuilder.append("&token="); | |||
stringBuilder.append(token); | |||
stringBuilder.append("&bodyFatId="); | |||
stringBuilder.append(bodyid); | |||
stringBuilder.append(""); | |||
URL uri = new URL(stringBuilder.toString()); | |||
HttpURLConnection httpURLConnection = (HttpURLConnection) uri.openConnection(); | |||
// Post请求必须设置允许输出 | |||
httpURLConnection.setDoOutput(true); | |||
// Post请求不能使用缓存 | |||
httpURLConnection.setUseCaches(false); | |||
// 设置为Post请求 | |||
httpURLConnection.setRequestMethod("POST"); | |||
httpURLConnection.setInstanceFollowRedirects(true); | |||
// 配置请求Content-Type | |||
httpURLConnection.setRequestProperty("Content-Type", | |||
"application/x-www-form-urlencode"); | |||
// 设置连接超时时间 | |||
httpURLConnection.setConnectTimeout(6 * 1000); | |||
// 开始连接 | |||
httpURLConnection.connect(); | |||
// DataOutputStream dos = new DataOutputStream(httpURLConnection.getOutputStream()); | |||
// dos.write(map.toString().getBytes()); | |||
// dos.flush(); | |||
// dos.close(); | |||
// 判断请求是否成功 | |||
if (httpURLConnection.getResponseCode() == 200) { | |||
// 获取返回的数据 | |||
byte[] data = readInputStream(httpURLConnection.getInputStream()); | |||
String result = new String(data, "UTF-8"); | |||
Log.i(TAG, result); | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
loglist.add(0, result); | |||
logadapter.notifyDataSetChanged(); | |||
} | |||
}); | |||
} else { | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
loglist.add(0, "请求失败"); | |||
logadapter.notifyDataSetChanged(); | |||
} | |||
}); | |||
} | |||
} | |||
public byte[] readInputStream(InputStream inputStream) throws IOException { | |||
byte[] buffer = new byte[1024]; | |||
int len = 0; | |||
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |||
while ((len = inputStream.read(buffer)) != -1) { | |||
bos.write(buffer, 0, len); | |||
} | |||
bos.close(); | |||
return bos.toByteArray(); | |||
} | |||
public void setUnit(int unit) throws Throwable { | |||
if (appid == 0 || token == null || SN == null || SN.isEmpty() || mDeviceName == null || mDeviceName.isEmpty()) { | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
loglist.add(0, "请先登录,然后获取设备id"); | |||
logadapter.notifyDataSetChanged(); | |||
} | |||
}); | |||
return; | |||
} | |||
StringBuilder stringBuilder = new StringBuilder(); | |||
// http://test.ailink.app.aicare.net.cn/api/device/update?key=inet_elink&appUserId=10429&token=57dce920-8521-42e9-9040-157d08c7d922&deviceId=3001&roomId=4326&deviceName=WIFI秤测试&deviceUnit=1 | |||
stringBuilder.append("http://test.ailink.app.aicare.net.cn/api/device/update?key=inet_elink&appUserId="); | |||
stringBuilder.append(appid); | |||
stringBuilder.append("&token="); | |||
stringBuilder.append(token); | |||
stringBuilder.append("&deviceId="); | |||
stringBuilder.append(myDeviceId); | |||
stringBuilder.append("&roomId=4326&deviceName="); | |||
stringBuilder.append(mDeviceName); | |||
stringBuilder.append("&deviceUnit="); | |||
stringBuilder.append(unit); | |||
Log.e("设置单位", stringBuilder.toString()); | |||
URL uri = new URL(stringBuilder.toString()); | |||
HttpURLConnection httpURLConnection = (HttpURLConnection) uri.openConnection(); | |||
// Post请求必须设置允许输出 | |||
httpURLConnection.setDoOutput(true); | |||
// Post请求不能使用缓存 | |||
httpURLConnection.setUseCaches(false); | |||
// 设置为Post请求 | |||
httpURLConnection.setRequestMethod("POST"); | |||
httpURLConnection.setInstanceFollowRedirects(true); | |||
// 配置请求Content-Type | |||
httpURLConnection.setRequestProperty("Content-Type", | |||
"application/x-www-form-urlencode"); | |||
// 设置连接超时时间 | |||
httpURLConnection.setConnectTimeout(6 * 1000); | |||
// 开始连接 | |||
httpURLConnection.connect(); | |||
// DataOutputStream dos = new DataOutputStream(httpURLConnection.getOutputStream()); | |||
// dos.write(map.toString().getBytes()); | |||
// dos.flush(); | |||
// dos.close(); | |||
// 判断请求是否成功 | |||
if (httpURLConnection.getResponseCode() == 200) { | |||
// 获取返回的数据 | |||
byte[] data = readInputStream(httpURLConnection.getInputStream()); | |||
String result = new String(data, "UTF-8"); | |||
Log.i(TAG, result); | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
loglist.add(0, result); | |||
logadapter.notifyDataSetChanged(); | |||
} | |||
}); | |||
} else { | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
loglist.add(0, "请求失败"); | |||
logadapter.notifyDataSetChanged(); | |||
} | |||
}); | |||
} | |||
} | |||
public void getTestRecord() throws Throwable { | |||
StringBuilder stringBuilder = new StringBuilder(); | |||
stringBuilder.append("http://test.ailink.app.aicare.net.cn/api/deDataTest/getDeDataTestPage?key=inet_elink&appUserId="); | |||
stringBuilder.append(appid); | |||
stringBuilder.append("&token="); | |||
stringBuilder.append(token); | |||
stringBuilder.append("&maxId=0"); | |||
stringBuilder.append("&sortColumns="); | |||
stringBuilder.append("id desc"); | |||
Log.e(TAG, stringBuilder.toString()); | |||
URL uri = new URL(stringBuilder.toString()); | |||
HttpURLConnection httpURLConnection = (HttpURLConnection) uri.openConnection(); | |||
// // Post请求必须设置允许输出 | |||
// httpURLConnection.setDoOutput(true); | |||
// // Post请求不能使用缓存 | |||
// httpURLConnection.setUseCaches(false); | |||
// // 设置为Post请求 | |||
// httpURLConnection.setRequestMethod("POST"); | |||
// httpURLConnection.setInstanceFollowRedirects(true); | |||
// // 配置请求Content-Type | |||
// httpURLConnection.setRequestProperty("Content-Type", | |||
// "application/x-www-form-urlencode"); | |||
// 设置连接超时时间 | |||
httpURLConnection.setConnectTimeout(6 * 1000); | |||
// 开始连接 | |||
httpURLConnection.connect(); | |||
// DataOutputStream dos = new DataOutputStream(httpURLConnection.getOutputStream()); | |||
// dos.write(map.toString().getBytes()); | |||
// dos.flush(); | |||
// dos.close(); | |||
// 判断请求是否成功 | |||
if (httpURLConnection.getResponseCode() == 200) { | |||
// 获取返回的数据 | |||
byte[] data = readInputStream(httpURLConnection.getInputStream()); | |||
String result = new String(data, "UTF-8"); | |||
Log.i(TAG, result); | |||
JSONObject jsonObject = new JSONObject(result); | |||
JSONObject datajson = jsonObject.getJSONObject("data"); | |||
JSONArray listjson = datajson.getJSONArray("list"); | |||
StringBuffer stringBuffer = new StringBuffer(); | |||
for (int i = 0; i < listjson.length(); i++) { | |||
long id = listjson.getJSONObject(i).getLong("id"); | |||
// String createTime="数据时间 "+getDateDefault(listjson.getJSONObject(i).getLong("createTime")); | |||
String encryptData = "请求的加密值: " + listjson.getJSONObject(i).getString("encryptData"); | |||
// String decryptData = "解密结果: " + listjson.getJSONObject(i).getString("decryptData"); | |||
stringBuffer.append("id: "); | |||
stringBuffer.append(id); | |||
stringBuffer.append("\n"); | |||
stringBuffer.append(encryptData); | |||
stringBuffer.append("\n=================\n"); | |||
} | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
loglist.add(0, "测试数据\n" + stringBuffer.toString()); | |||
logadapter.notifyDataSetChanged(); | |||
} | |||
}); | |||
} else { | |||
} | |||
} | |||
public static String getDateDefault(Long time) { | |||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US); | |||
return simpleDateFormat.format(time); | |||
} | |||
public void getPermission() { | |||
String[] permissions = {android.Manifest.permission.ACCESS_COARSE_LOCATION,}; | |||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | |||
//当前系统大于等于6.0 | |||
for (String perssion : permissions) { | |||
int isGranted = ContextCompat.checkSelfPermission(this, perssion); | |||
if (isGranted != PackageManager.PERMISSION_GRANTED) { | |||
ActivityCompat.requestPermissions(this, new String[]{perssion}, 1); | |||
} | |||
} | |||
LocationManager lm = (LocationManager) this.getSystemService(this.LOCATION_SERVICE); | |||
if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) { | |||
/*Toast.makeText(this, "检测到未开启GPS定位服务,需要开启才能扫描到附件WiFi信息,请开启", Toast.LENGTH_SHORT).show(); | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
Thread.sleep(3 * 1000); //sleep s | |||
} catch (InterruptedException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
}).start();*/ | |||
AlertDialog dialog = new AlertDialog.Builder(this) | |||
.setTitle("警告!") | |||
.setMessage("检测到未开启GPS定位服务,需要开启才能扫描到附件WiFi信息,请开启") | |||
.setPositiveButton("确定", new DialogInterface.OnClickListener() { | |||
@Override | |||
public void onClick(DialogInterface dialog, int which) { | |||
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); | |||
startActivityForResult(intent, 1); | |||
} | |||
}).show(); | |||
} | |||
} | |||
} | |||
@Override | |||
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { | |||
switch (requestCode) { | |||
case 1: { | |||
// If request is cancelled, the result arrays are empty. | |||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | |||
Log.d("Mainactivity", "onRequestPermissionsResult granted"); | |||
} else { | |||
Log.d("Mainactivity", "onRequestPermissionsResult denied"); | |||
AlertDialog dialog = new AlertDialog.Builder(this) | |||
.setTitle("警告!") | |||
.setMessage("需要授予定位权限才能扫描到附件WiFi信息") | |||
.setPositiveButton("确定", new DialogInterface.OnClickListener() { | |||
@Override | |||
public void onClick(DialogInterface dialog, int which) { | |||
//一般情况下如果用户不授权的话,功能是无法运行的,做退出处理 | |||
finish(); | |||
} | |||
}).show(); | |||
} | |||
break; | |||
} | |||
default: | |||
break; | |||
} | |||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | |||
} | |||
} |
@@ -0,0 +1,361 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid.base; | |||
import android.Manifest; | |||
import android.app.Activity; | |||
import android.content.Context; | |||
import android.content.Intent; | |||
import android.content.pm.ActivityInfo; | |||
import android.content.pm.PackageManager; | |||
import android.os.Build; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Message; | |||
import android.view.KeyEvent; | |||
import android.view.MenuItem; | |||
import android.view.MotionEvent; | |||
import android.view.View; | |||
import android.view.inputmethod.InputMethodManager; | |||
import android.widget.TextView; | |||
import com.pingwang.bluetoothlib.BleBaseActivity; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.dialog.HintDataDialogFragment; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.AppStart; | |||
import java.lang.ref.WeakReference; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import androidx.appcompat.widget.Toolbar; | |||
import androidx.core.app.ActivityCompat; | |||
import androidx.core.content.ContextCompat; | |||
import butterknife.ButterKnife; | |||
import butterknife.Unbinder; | |||
/** | |||
* 2019/4/16 11:55 | |||
* activity的基类, 共有的功能都可以写在这里 | |||
*/ | |||
public abstract class BleAppBaseActivity extends BleBaseActivity { | |||
/** | |||
* 上下文对象 | |||
*/ | |||
protected Context mContext; | |||
protected String TAG = this.getClass().getName(); | |||
protected Handler mHandler = new MyHandler(this); | |||
@Nullable | |||
protected TextView mTvTopTitle; | |||
@Nullable | |||
protected Toolbar mToolbar; | |||
private Unbinder bind; | |||
//--------------ble--------------- | |||
/** | |||
* 需要申请的权限 | |||
*/ | |||
private String[] LOCATION_PERMISSION = new String[]{Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.ACCESS_COARSE_LOCATION}; | |||
/** | |||
* 权限请求返回 | |||
*/ | |||
private final int PERMISSION = 101; | |||
/** | |||
* 定位服务返回 | |||
*/ | |||
protected final int LOCATION_SERVER = 102; | |||
private HintDataDialogFragment mHintDataDialog = null; | |||
@Override | |||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
if (getLayoutId() != 0) { | |||
initWindows(); | |||
setContentView(getLayoutId()); | |||
SaveActivityData(savedInstanceState); | |||
mContext = this; | |||
init(); | |||
} else if (getLayoutView() != null) { | |||
initWindows(); | |||
setContentView(getLayoutView()); | |||
SaveActivityData(savedInstanceState); | |||
mContext = this; | |||
init(); | |||
} | |||
} | |||
protected void SaveActivityData(Bundle savedInstanceState) { | |||
} | |||
/** | |||
* handler消息,使用弱引用,避免泄露问题 | |||
*/ | |||
private static class MyHandler extends Handler { | |||
private WeakReference<BleAppBaseActivity> mActivity; | |||
MyHandler(BleAppBaseActivity activity) { | |||
mActivity = new WeakReference<>(activity); | |||
} | |||
@Override | |||
public void handleMessage(Message msg) { | |||
if (mActivity.get() == null) { | |||
return; | |||
} | |||
mActivity.get().uiHandlerMessage(msg); | |||
} | |||
} | |||
/** | |||
* handler消息处理 | |||
*/ | |||
protected abstract void uiHandlerMessage(Message msg); | |||
/** | |||
* 在绑定布局前的操作(状态,任务栏等的设置) | |||
*/ | |||
protected void initWindows() { | |||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//禁止横屏 | |||
//设置状态栏文字为黑色 | |||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | |||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); | |||
} | |||
} | |||
/** | |||
* 获取当前activity的布局 | |||
* | |||
* @return int | |||
*/ | |||
protected abstract int getLayoutId(); | |||
/** | |||
* 获取当前activity的布局 | |||
* | |||
* @return View | |||
*/ | |||
protected View getLayoutView() { | |||
return null; | |||
} | |||
/** | |||
* 初始化 | |||
*/ | |||
protected final void init() { | |||
bind = ButterKnife.bind(this); | |||
addInit(); | |||
initView(); | |||
initData(); | |||
initListener(); | |||
} | |||
protected void addInit() { | |||
} | |||
//-----------------------权限---------------------------------------- | |||
protected void initPermissions() { | |||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { | |||
onPermissionsOk(); | |||
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) | |||
.setDialogListener(new HintDataDialogFragment.DialogListener() { | |||
@Override | |||
public void tvSucceedListener(View v) { | |||
startLocationActivity(); | |||
} | |||
}); | |||
mHintDataDialog.show(getSupportFragmentManager()); | |||
} else { | |||
onPermissionsOk(); | |||
} | |||
} | |||
} | |||
@Override | |||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, | |||
@NonNull int[] grantResults) { | |||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | |||
//请求权限被拒绝 | |||
if (requestCode != PERMISSION) | |||
return; | |||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | |||
initPermissions(); | |||
} else { | |||
if (ActivityCompat.shouldShowRequestPermissionRationale(BleAppBaseActivity.this, | |||
LOCATION_PERMISSION[0])) { | |||
//权限请求失败,但未选中“不再提示”选项,再次请求 | |||
ActivityCompat.requestPermissions(this, LOCATION_PERMISSION, PERMISSION); | |||
} else { | |||
//权限请求失败,选中“不再提示”选项 | |||
mHintDataDialog = HintDataDialogFragment.newInstance() | |||
.setTitle("提示", 0) | |||
.setCancel("取消",0) | |||
.setOk("确定",0) | |||
.setContent("请求开启定位权限", true) | |||
.setDialogListener(new HintDataDialogFragment.DialogListener() { | |||
@Override | |||
public void tvSucceedListener(View v) { | |||
AppStart.startUseSetActivity(mContext); | |||
} | |||
}); | |||
mHintDataDialog.show(getSupportFragmentManager()); | |||
} | |||
} | |||
} | |||
/** | |||
* 启动去设置定位服务 | |||
*/ | |||
protected void startLocationActivity() { | |||
AppStart.startLocationActivity(BleAppBaseActivity.this, LOCATION_SERVER); | |||
} | |||
/** | |||
* 权限ok | |||
*/ | |||
protected void onPermissionsOk() { | |||
} | |||
@Override | |||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | |||
super.onActivityResult(requestCode, resultCode, data); | |||
if (requestCode == LOCATION_SERVER) { | |||
//定位服务页面返回 | |||
initPermissions(); | |||
} | |||
} | |||
/** | |||
* 初始化事件 | |||
*/ | |||
protected abstract void initListener(); | |||
/** | |||
* 初始化数据 | |||
*/ | |||
protected abstract void initData(); | |||
/** | |||
* 初始化,绑定布局 | |||
*/ | |||
protected abstract void initView(); | |||
// @Override | |||
// public boolean onCreateOptionsMenu(Menu menu) { | |||
// getMenuInflater().inflate(R.menu.public_toolbar_menu, menu); | |||
// MenuItem item = menu.findItem(R.id.img_public_right); | |||
// if (item != null) { | |||
// item.setIcon(R.drawable.me_manssage); | |||
// } | |||
// return true; | |||
// } | |||
@Override | |||
public boolean onOptionsItemSelected(MenuItem item) { | |||
int i = item.getItemId(); | |||
if (i == android.R.id.home) { | |||
myFinish(); | |||
return true; | |||
} | |||
return super.onOptionsItemSelected(item); | |||
} | |||
/** | |||
* 返回键 | |||
*/ | |||
@Override | |||
public boolean onKeyDown(int keyCode, KeyEvent event) { | |||
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { | |||
myFinish(); | |||
return true; | |||
} | |||
return super.onKeyDown(keyCode, event); | |||
} | |||
/** | |||
* 返回 | |||
*/ | |||
protected void myFinish() { | |||
finish(); | |||
} | |||
protected void onClickRight() { | |||
} | |||
@Override | |||
protected void onStart() { | |||
super.onStart(); | |||
} | |||
@Override | |||
protected void onRestart() { | |||
super.onRestart(); | |||
} | |||
@Override | |||
protected void onResume() { | |||
super.onResume(); | |||
} | |||
@Override | |||
protected void onPause() { | |||
super.onPause(); | |||
} | |||
@Override | |||
protected void onStop() { | |||
super.onStop(); | |||
} | |||
@Override | |||
protected void onDestroy() { | |||
super.onDestroy(); | |||
if (mHandler != null) { | |||
mHandler.removeCallbacksAndMessages(null); | |||
} | |||
if (bind != null) | |||
bind.unbind(); | |||
} | |||
} |
@@ -0,0 +1,127 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid.config; | |||
/** | |||
* xing<br> | |||
* 2019/3/5<br> | |||
* 设备相关信息配置 | |||
*/ | |||
public class BleDeviceConfig { | |||
//--------------------设备类型----------------------- | |||
/** | |||
* 血压计(sphygmomanometer) | |||
* | |||
*/ | |||
public final static int BLOOD_PRESSURE =0x01; | |||
/** | |||
* 额温枪(Forehead gun) | |||
*/ | |||
public final static int INFRARED_THERMOMETER =0x02; | |||
/** | |||
* 体温计(thermometer) | |||
*/ | |||
public final static int THERMOMETER =0x03; | |||
/** | |||
* 婴儿秤(Baby scale) | |||
*/ | |||
public final static int BABY_SCALE =0x04; | |||
/** | |||
* 身高仪(Height gauge) | |||
*/ | |||
public final static int HEIGHT_METER =0x05; | |||
/** | |||
* 智能门锁(Smart door lock) | |||
*/ | |||
public final static int SMART_LOCK =0x0B; | |||
/** | |||
* 定制版遥控器(Customized remote control) | |||
*/ | |||
public final static int EL_REMOTE_CONTROL =0x0C; | |||
/** | |||
* 连接类型的TPMS(Connection type TPMS) | |||
*/ | |||
public final static int TPMS_CONN_DEVICE =0x0D; | |||
/** | |||
* 体重体脂称(Body fat scale) | |||
*/ | |||
public final static int WEIGHT_BODY_FAT_SCALE =0x0E; | |||
/** | |||
* 箱包锁(Luggage lock) | |||
*/ | |||
public final static int LUGGAGE_LOCK =0x0F; | |||
/** | |||
* 锁遥控器(Lock the remote control) | |||
*/ | |||
public final static int LOCK_REMOTE_CONTROL =0x10; | |||
/** | |||
* wifi+ble体脂秤(wifi + ble body fat scale) | |||
*/ | |||
public final static int WEIGHT_BODY_FAT_SCALE_WIFI_BLE=0x11; | |||
/** | |||
* wifi+ble牙刷(wifi + ble body fat scale) | |||
*/ | |||
public final static int TOOTHBRUSH_WIFI_BLE=0x12; | |||
/** | |||
* 八电极体脂秤 | |||
*/ | |||
public final static int EIGHT_BODY_FAT_SCALE =0x13; | |||
/** | |||
* 风速计 | |||
* cid 为0x14 | |||
*/ | |||
public final static int ANEMOMETER=0x14; | |||
/** | |||
* 钳表 | |||
* cid 为0x15 | |||
*/ | |||
public final static int CLAMP_TABLE=0x15; | |||
/** | |||
* 体重体脂称(Body fat scale)艾迪 | |||
*/ | |||
public final static int WEIGHT_BODY_FAT_SCALE_AD =0x100E; | |||
/** | |||
* 婴儿体脂两用秤 | |||
*/ | |||
public final static int BABY_BODY_FAT =0x1A; | |||
/** | |||
* 血糖仪 | |||
*/ | |||
public final static int BLOOD_GLUCOSE=0x1c; | |||
/** | |||
* 运动手表 华盛达手表 | |||
*/ | |||
public final static int SPORTS_WATCH_BLE = 0x1D; | |||
/** | |||
* 广播秤 | |||
*/ | |||
public final static int BROADCAST_SCALE =0x10001; | |||
/** | |||
* 智能口罩 | |||
*/ | |||
public final static int SMART_MASK =0x0022; | |||
} |
@@ -0,0 +1,102 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid.dialog; | |||
import android.content.Context; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import android.widget.TextView; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||
import java.util.List; | |||
import androidx.annotation.NonNull; | |||
import androidx.recyclerview.widget.RecyclerView; | |||
/** | |||
* xing<br> | |||
* 2019/8/24<br> | |||
* dialog列表<br> | |||
*/ | |||
public class DialogStringImageAdapter extends RecyclerView.Adapter<DialogStringImageAdapter.KeyViewHolder> { | |||
private List<DialogStringImageBean> mList; | |||
private OnItemClickListener listener; | |||
private Context mContext; | |||
public interface OnItemClickListener { | |||
void onItemClick(int position); | |||
} | |||
public DialogStringImageAdapter(Context context, List<DialogStringImageBean> list, OnItemClickListener listener) { | |||
mList = list; | |||
this.listener = listener; | |||
mContext = context; | |||
} | |||
@NonNull | |||
@Override | |||
public KeyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | |||
View view = LayoutInflater.from(mContext).inflate(R.layout.item_string_dialog_list, parent, false); | |||
return new KeyViewHolder(view, listener); | |||
} | |||
@Override | |||
public void onBindViewHolder(@NonNull KeyViewHolder holder, int position) { | |||
DialogStringImageBean bean = mList.get(position); | |||
holder.mTvTitle.setText(bean.getName()); | |||
} | |||
@Override | |||
public int getItemCount() { | |||
return mList.size(); | |||
} | |||
static class KeyViewHolder extends RecyclerView.ViewHolder { | |||
private TextView mTvTitle; | |||
KeyViewHolder(@NonNull View itemView, final OnItemClickListener listener) { | |||
super(itemView); | |||
mTvTitle = itemView.findViewById(R.id.tv_dialog_list_data); | |||
itemView.setOnClickListener(v -> { | |||
if (listener != null) | |||
listener.onItemClick(getLayoutPosition()); | |||
}); | |||
} | |||
} | |||
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; | |||
} | |||
} | |||
} |
@@ -0,0 +1,427 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid.dialog; | |||
import android.app.Dialog; | |||
import android.content.Context; | |||
import android.content.DialogInterface; | |||
import android.graphics.Color; | |||
import android.graphics.drawable.ColorDrawable; | |||
import android.os.Bundle; | |||
import android.util.DisplayMetrics; | |||
import android.view.Gravity; | |||
import android.view.KeyEvent; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import android.view.Window; | |||
import android.view.WindowManager; | |||
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.NonNull; | |||
import androidx.annotation.Nullable; | |||
import androidx.fragment.app.DialogFragment; | |||
import androidx.fragment.app.FragmentManager; | |||
/** | |||
* 显示信息的弹框 | |||
*/ | |||
public class HintDataDialogFragment extends DialogFragment { | |||
private static String TAG = HintDataDialogFragment.class.getName(); | |||
private Context mContext; | |||
private DialogListener mDialogListener; | |||
private TextView mTvTitle; | |||
private TextView mTvCancel, mTvSucceed, mTvContent; | |||
private View view_cancel_line; | |||
private CharSequence mTitle; | |||
private CharSequence mContent; | |||
/** | |||
* 是否居中 | |||
*/ | |||
private boolean isCenter = false; | |||
private CharSequence mCancel; | |||
@ColorInt | |||
private int mCancelColor = 0; | |||
private CharSequence mOkStr; | |||
@ColorInt | |||
private int mOkColor = 0; | |||
@ColorInt | |||
private int mTitleColor = 0; | |||
private boolean mBottom; | |||
/** | |||
* 是否显示灰色背景 | |||
*/ | |||
private boolean mBackground=true; | |||
/** | |||
* 点击空白区域是否关闭 | |||
*/ | |||
private boolean mCancelBlank; | |||
/** | |||
* 是否显示 | |||
*/ | |||
private boolean mShow; | |||
public static HintDataDialogFragment newInstance() { | |||
return new HintDataDialogFragment(); | |||
} | |||
private HintDataDialogFragment() { | |||
} | |||
@NonNull | |||
@Override | |||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { | |||
L.i(TAG, "onCreateDialog"); | |||
Dialog dialogView = new Dialog(requireContext(), R.style.MyDialog);// 创建自定义样式dialog | |||
dialogView.setCancelable(false);//设置是否可以关闭 | |||
dialogView.setCanceledOnTouchOutside(mCancelBlank);//设置点击空白处是否可以取消 | |||
dialogView.setOnKeyListener((dialog, keyCode, event) -> { | |||
if (mCancelBlank) { | |||
return false; | |||
} else { | |||
//返回不关闭 | |||
return keyCode == KeyEvent.KEYCODE_BACK; | |||
} | |||
}); | |||
return dialogView; | |||
} | |||
@Nullable | |||
@Override | |||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, | |||
@Nullable Bundle savedInstanceState) { | |||
L.i(TAG, "onCreateView"); | |||
return inflater.inflate(R.layout.dialog_hint_data, container);// 得到加载view | |||
} | |||
@Override | |||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { | |||
super.onViewCreated(view, savedInstanceState); | |||
mContext = view.getContext(); | |||
initView(view); | |||
initData(); | |||
} | |||
@Override | |||
public void onActivityCreated(@Nullable Bundle savedInstanceState) { | |||
super.onActivityCreated(savedInstanceState); | |||
L.i(TAG, "onActivityCreated"); | |||
Dialog dialog = getDialog(); | |||
if (dialog != null) { | |||
getDialog().setOnShowListener(null); | |||
getDialog().setOnCancelListener(null); | |||
getDialog().setOnDismissListener(null); | |||
Window window = dialog.getWindow(); | |||
if (window != null) { | |||
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); | |||
WindowManager.LayoutParams params = window.getAttributes(); | |||
if (mBackground) { | |||
params.dimAmount = 0.8f; | |||
} else { | |||
params.dimAmount = 0f; | |||
} | |||
if (mBottom) { | |||
params.y = 10;//设置Dialog距离底部的距离 | |||
params.gravity = Gravity.BOTTOM; | |||
} | |||
window.setAttributes(params); | |||
} | |||
} | |||
} | |||
/** | |||
* 初始化控件,数据 | |||
*/ | |||
private void initView(View mDialogView) { | |||
mTvTitle = mDialogView.findViewById(R.id.tv_hint_data_title); | |||
mTvCancel = mDialogView.findViewById(R.id.tv_hint_data_cancel); | |||
view_cancel_line = mDialogView.findViewById(R.id.view_cancel_line); | |||
mTvSucceed = mDialogView.findViewById(R.id.tv_hint_data_ok); | |||
mTvContent = mDialogView.findViewById(R.id.tv_hint_data_context); | |||
mTvCancel.setOnClickListener(v -> { | |||
if (mDialogListener != null) { | |||
mDialogListener.tvCancelListener(v); | |||
} | |||
this.dismiss(); | |||
}); | |||
mTvSucceed.setOnClickListener(v -> { | |||
if (mDialogListener != null) { | |||
mDialogListener.tvSucceedListener(v); | |||
} | |||
this.dismiss(); | |||
}); | |||
} | |||
private void initData() { | |||
this.initData(mTitle, mContent, isCenter, mCancel, mOkStr); | |||
this.initColor(mCancelColor, mOkColor); | |||
} | |||
/** | |||
* 设置取消,确定按钮颜色 | |||
* | |||
* @param cancelColor 取消的颜色 | |||
* @param okColor 确定的颜色 | |||
*/ | |||
public HintDataDialogFragment initColor(@ColorInt int cancelColor, @ColorInt int okColor) { | |||
this.mCancelColor = cancelColor; | |||
this.mOkColor = okColor; | |||
if (mTvCancel != null && mCancelColor != 0) | |||
mTvCancel.setTextColor(mCancelColor); | |||
if (mTvSucceed != null && mOkColor != 0) | |||
mTvSucceed.setTextColor(mOkColor); | |||
return this; | |||
} | |||
public HintDataDialogFragment setContent(CharSequence content, boolean center) { | |||
this.mContent = content; | |||
this.isCenter = center; | |||
if (mTvContent != null) { | |||
if (mContent != null && !mContent.equals("")) { | |||
mTvContent.setVisibility(View.VISIBLE); | |||
mTvContent.setText(mContent); | |||
} else if (mContent == null) { | |||
mTvContent.setVisibility(View.GONE); | |||
} | |||
if (isCenter) | |||
mTvContent.setGravity(Gravity.CENTER); | |||
else | |||
mTvContent.setGravity(Gravity.CENTER_VERTICAL); | |||
} | |||
return this; | |||
} | |||
public HintDataDialogFragment setTitle(CharSequence title, @ColorInt int titleColor) { | |||
this.mTitle = title; | |||
this.mTitleColor = titleColor; | |||
if (mTvTitle != null) { | |||
if (mTitle != null && !mTitle.equals("")) { | |||
mTvTitle.setVisibility(View.VISIBLE); | |||
mTvTitle.setText(mTitle); | |||
} else if (mTitle == null) { | |||
mTvTitle.setVisibility(View.GONE); | |||
} | |||
if (mTitleColor != 0) { | |||
mTvTitle.setTextColor(mTitleColor); | |||
} | |||
} | |||
return this; | |||
} | |||
public HintDataDialogFragment setCancel(CharSequence cancel, @ColorInt int cancelColor) { | |||
this.mCancel = cancel; | |||
this.mCancelColor = cancelColor; | |||
if (mTvCancel != null) { | |||
if (mCancel != null && !mCancel.equals("")) { | |||
mTvCancel.setVisibility(View.VISIBLE); | |||
view_cancel_line.setVisibility(View.VISIBLE); | |||
mTvCancel.setText(mCancel); | |||
} else if (mCancel == null) { | |||
mTvCancel.setVisibility(View.GONE); | |||
view_cancel_line.setVisibility(View.GONE); | |||
} | |||
if (mCancelColor != 0) { | |||
mTvCancel.setTextColor(mCancelColor); | |||
} | |||
} | |||
return this; | |||
} | |||
public HintDataDialogFragment setOk(CharSequence ok, @ColorInt int okColor) { | |||
this.mOkStr = ok; | |||
this.mOkColor = okColor; | |||
if (mTvSucceed != null) { | |||
if (mOkStr != null && !mOkStr.equals("")) { | |||
mTvSucceed.setVisibility(View.VISIBLE); | |||
mTvSucceed.setText(mOkStr); | |||
} else if (mOkStr == null) { | |||
mTvSucceed.setVisibility(View.GONE); | |||
} | |||
if (mOkColor != 0) | |||
mTvSucceed.setTextColor(mOkColor); | |||
} | |||
return this; | |||
} | |||
/** | |||
* 设置dialog是否在底部 | |||
*/ | |||
public HintDataDialogFragment setBottom(boolean bottom) { | |||
mBottom = bottom; | |||
return this; | |||
} | |||
/** | |||
* 设置dialog是否有灰色背景 | |||
*/ | |||
public HintDataDialogFragment setBackground(boolean background) { | |||
mBackground = background; | |||
return this; | |||
} | |||
/** | |||
* 设置点击空白区域是否可以关闭 | |||
*/ | |||
public HintDataDialogFragment setCancelBlank(boolean cancelable) { | |||
mCancelBlank = cancelable; | |||
return this; | |||
} | |||
/** | |||
* 当前是否显示 | |||
*/ | |||
public boolean isShow() { | |||
return mShow; | |||
} | |||
/** | |||
* 初始化数据 | |||
* | |||
* @param isCenter 显示的内容是否居中 | |||
*/ | |||
public HintDataDialogFragment initData(CharSequence title, CharSequence content, | |||
boolean isCenter, CharSequence cancel, CharSequence ok) { | |||
setTitle(title, mTitleColor); | |||
setContent(content, isCenter); | |||
setCancel(cancel, mCancelColor); | |||
setOk(ok, mOkColor); | |||
return this; | |||
} | |||
/** | |||
* 初始化数据 | |||
*/ | |||
public HintDataDialogFragment initData(CharSequence title, CharSequence content) { | |||
return this.initData(title, content, false, "", ""); | |||
} | |||
/** | |||
* 初始化数据 | |||
*/ | |||
public HintDataDialogFragment initData(CharSequence title, CharSequence content, | |||
CharSequence cancel, CharSequence ok) { | |||
return this.initData(title, content, false, cancel, ok); | |||
} | |||
@Override | |||
public void onStart() { | |||
super.onStart(); | |||
Dialog dialog = getDialog(); | |||
if (dialog != null) { | |||
dialog.setOnDismissListener(this); | |||
DisplayMetrics dm = new DisplayMetrics(); | |||
if (getActivity() != null) { | |||
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); | |||
if (dialog.getWindow() != null) | |||
//设置宽度为80% | |||
dialog.getWindow() | |||
.setLayout((int) (dm.widthPixels * 0.9), | |||
ViewGroup.LayoutParams.WRAP_CONTENT); | |||
} | |||
} | |||
} | |||
@Override | |||
public void show(@NonNull FragmentManager manager, @Nullable String tag) { | |||
try { | |||
if (!mShow) { | |||
super.show(manager, tag); | |||
mShow = true; | |||
} | |||
} catch (Exception e) { | |||
L.e(TAG, "显示异常"); | |||
e.printStackTrace(); | |||
} | |||
} | |||
public void show(@NonNull FragmentManager manager) { | |||
this.show(manager, "HintDataDialogFragment"); | |||
} | |||
@Override | |||
public void onDismiss(@NonNull DialogInterface dialog) { | |||
super.onDismiss(dialog); | |||
mShow = false; | |||
} | |||
@Override | |||
public void dismiss() { | |||
try { | |||
mShow = false; | |||
super.dismiss(); | |||
} catch (Exception e) { | |||
L.e(TAG, "关闭异常"); | |||
e.printStackTrace(); | |||
} | |||
} | |||
public interface DialogListener { | |||
/** | |||
* 取消的点击事件 | |||
* | |||
* @param v | |||
*/ | |||
default void tvCancelListener(View v) { | |||
} | |||
/** | |||
* 成功的点击事件 | |||
* | |||
* @param v | |||
*/ | |||
default void tvSucceedListener(View v) { | |||
} | |||
} | |||
public HintDataDialogFragment setDialogListener(DialogListener dialogListener) { | |||
mDialogListener = dialogListener; | |||
return this; | |||
} | |||
@Override | |||
public void onDetach() { | |||
super.onDetach(); | |||
} | |||
@Override | |||
public void onDestroy() { | |||
super.onDestroy(); | |||
} | |||
@Override | |||
public void onDestroyView() { | |||
super.onDestroyView(); | |||
mShow = false; | |||
} | |||
} |
@@ -0,0 +1,146 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid.dialog; | |||
import android.app.Dialog; | |||
import android.content.DialogInterface; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import android.os.Message; | |||
import android.view.KeyEvent; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import aicare.net.cn.sdk.ailinksdkdemoandroid.R; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import androidx.fragment.app.DialogFragment; | |||
import androidx.fragment.app.FragmentManager; | |||
import androidx.fragment.app.FragmentTransaction; | |||
/** | |||
* elink-android<br> | |||
* LoadingIosDialogFragment<br> | |||
* xing<br> | |||
* 2019/2/26 16:07<br> | |||
* 加载提示框 | |||
*/ | |||
public class LoadingIosDialogFragment extends DialogFragment { | |||
private static String TAG = LoadingIosDialogFragment.class.getName(); | |||
private final static int DISMISS_OUT = 1; | |||
/** | |||
* 默认超时时间 | |||
*/ | |||
private int timeOut = 30; | |||
private boolean show = false; | |||
public boolean isShow() { | |||
return show; | |||
} | |||
private Handler mHandler = new Handler(Looper.getMainLooper()) { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
switch (msg.what) { | |||
case DISMISS_OUT: | |||
LoadingIosDialogFragment.this.dismiss(); | |||
break; | |||
} | |||
} | |||
}; | |||
@Override | |||
public void dismiss() { | |||
try { | |||
mHandler.removeMessages(DISMISS_OUT); | |||
if (getFragmentManager() != null) | |||
super.dismiss(); | |||
show = false; | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
public int getTimeOut() { | |||
return timeOut; | |||
} | |||
public void setTimeOut(int timeOut) { | |||
this.timeOut = timeOut; | |||
} | |||
public void show(@NonNull FragmentManager manager) { | |||
this.show(manager, "LoadingIosDialogFragment"); | |||
} | |||
@Override | |||
public void show(@NonNull FragmentManager manager, @Nullable String tag) { | |||
try { | |||
super.show(manager, tag); | |||
show = true; | |||
} catch (Exception e) { | |||
show = false; | |||
e.printStackTrace(); | |||
} | |||
mHandler.sendEmptyMessageDelayed(DISMISS_OUT, timeOut * 1000); | |||
} | |||
@Override | |||
public int show(@NonNull FragmentTransaction transaction, @Nullable String tag) { | |||
return super.show(transaction, tag); | |||
} | |||
@Override | |||
public void onActivityCreated(@Nullable Bundle savedInstanceState) { | |||
super.onActivityCreated(savedInstanceState); | |||
if (getDialog() != null) { | |||
getDialog().setOnShowListener(null); | |||
getDialog().setOnCancelListener(null); | |||
getDialog().setOnDismissListener(null); | |||
} | |||
} | |||
@Nullable | |||
@Override | |||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |||
return super.onCreateView(inflater, container, savedInstanceState); | |||
} | |||
@NonNull | |||
@Override | |||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { | |||
LayoutInflater inflater = LayoutInflater.from(requireContext()); | |||
View v = inflater.inflate(R.layout.dialog_loading_ios, null);// 得到加载view | |||
Dialog loadingDialog = new Dialog(requireContext(), R.style.MyDialog);// 创建自定义样式dialog | |||
loadingDialog.setCancelable(false);//设置点击空白处是否可以取消 | |||
//按返回键是否可以取消 | |||
loadingDialog.setCanceledOnTouchOutside(false); | |||
loadingDialog.setContentView(v);// 设置布局 | |||
loadingDialog.setOnKeyListener(new DialogInterface.OnKeyListener() { | |||
@Override | |||
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { | |||
//返回不关闭 | |||
return keyCode == KeyEvent.KEYCODE_BACK; | |||
} | |||
}); | |||
return loadingDialog; | |||
} | |||
@Override | |||
public void onDestroyView() { | |||
super.onDestroyView(); | |||
if (mHandler != null) { | |||
mHandler.removeCallbacksAndMessages(null); | |||
} | |||
} | |||
} |
@@ -0,0 +1,311 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid.dialog; | |||
import android.app.Dialog; | |||
import android.content.Context; | |||
import android.content.DialogInterface; | |||
import android.graphics.Color; | |||
import android.graphics.drawable.ColorDrawable; | |||
import android.os.Bundle; | |||
import android.view.Gravity; | |||
import android.view.KeyEvent; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import android.view.Window; | |||
import android.view.WindowManager; | |||
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.NonNull; | |||
import androidx.annotation.Nullable; | |||
import androidx.fragment.app.DialogFragment; | |||
import androidx.fragment.app.FragmentManager; | |||
import androidx.recyclerview.widget.LinearLayoutManager; | |||
import androidx.recyclerview.widget.RecyclerView; | |||
/** | |||
* 列表显示的dialog | |||
*/ | |||
public class ShowListDialogFragment extends DialogFragment implements View.OnClickListener { | |||
private String TAG = ShowListDialogFragment.class.getName(); | |||
private Context mContext; | |||
private onDialogListener mOnDialogListener; | |||
private TextView mTvCancel, mTvTitle; | |||
private RecyclerView rv_dialog_list; | |||
private DialogStringImageAdapter mAdapter; | |||
private int mCancelColor; | |||
private CharSequence mCancel; | |||
private CharSequence mTitle; | |||
private ArrayList<DialogStringImageAdapter.DialogStringImageBean> mList; | |||
private boolean mBottom; | |||
/** | |||
* 是否显示灰色背景 | |||
*/ | |||
private boolean mBackground=true; | |||
/** | |||
* 点击空白区域是否关闭 | |||
*/ | |||
private boolean mCancelBlank; | |||
/** | |||
* 是否显示 | |||
*/ | |||
private boolean mShow; | |||
public static ShowListDialogFragment newInstance() { | |||
return new ShowListDialogFragment(); | |||
} | |||
@NonNull | |||
@Override | |||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { | |||
Dialog dialogView = new Dialog(requireContext(), R.style.MyDialog);// 创建自定义样式dialog | |||
dialogView.setCancelable(false);//设置是否可以关闭 | |||
dialogView.setCanceledOnTouchOutside(mCancelBlank);//设置点击空白处是否可以取消 | |||
dialogView.setOnKeyListener((dialog, keyCode, event) -> { | |||
if (mCancelBlank) { | |||
return false; | |||
} else { | |||
//返回不关闭 | |||
return keyCode == KeyEvent.KEYCODE_BACK; | |||
} | |||
}); | |||
return dialogView; | |||
} | |||
@Nullable | |||
@Override | |||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |||
return inflater.inflate(R.layout.dialog_list_data_fillet, container); | |||
} | |||
@Override | |||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { | |||
super.onViewCreated(view, savedInstanceState); | |||
mContext = view.getContext(); | |||
initView(view); | |||
initData(mList, mTitle, mCancel, mCancelColor); | |||
} | |||
@Override | |||
public void onActivityCreated(@Nullable Bundle savedInstanceState) { | |||
super.onActivityCreated(savedInstanceState); | |||
L.i(TAG,"onActivityCreated"); | |||
Dialog dialog = getDialog(); | |||
if (dialog != null) { | |||
Window window = dialog.getWindow(); | |||
if (window != null) { | |||
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); | |||
WindowManager.LayoutParams params = window.getAttributes(); | |||
if (mBackground) { | |||
params.dimAmount = 0.8f; | |||
} else { | |||
params.dimAmount = 0f; | |||
} | |||
if (mBottom) { | |||
params.y = 10;//设置Dialog距离底部的距离 | |||
params.gravity = Gravity.BOTTOM; | |||
} | |||
window.setAttributes(params); | |||
} | |||
} | |||
} | |||
/** | |||
* 初始化控件,数据 | |||
*/ | |||
private void initView(View view) { | |||
mTvTitle = view.findViewById(R.id.tv_dialog_list_data_title); | |||
mTvCancel = view.findViewById(R.id.tv_dialog_photo_cancel); | |||
rv_dialog_list = view.findViewById(R.id.rv_dialog_list); | |||
rv_dialog_list.setLayoutManager(new LinearLayoutManager(mContext)); | |||
rv_dialog_list.addItemDecoration(new MyItemDecoration(mContext, | |||
LinearLayoutManager.VERTICAL, 1, | |||
mContext.getResources().getColor(R.color.public_white))); | |||
} | |||
/** | |||
* 初始化数据 | |||
*/ | |||
private void initData(ArrayList<DialogStringImageAdapter.DialogStringImageBean> list, CharSequence title, CharSequence cancel, int cancelColor) { | |||
if (mList == null) | |||
mList = new ArrayList<>(); | |||
mAdapter = new DialogStringImageAdapter(mContext, mList, position -> { | |||
if (mOnDialogListener != null) { | |||
//item点击事件 | |||
mOnDialogListener.onItemListener(position); | |||
dismiss(); | |||
} | |||
}); | |||
rv_dialog_list.setAdapter(mAdapter); | |||
setList(list); | |||
setTitle(title); | |||
setCancel(cancel, cancelColor); | |||
mTvCancel.setOnClickListener(this); | |||
} | |||
public ShowListDialogFragment setTitle(CharSequence title) { | |||
this.mTitle = title; | |||
if (mTvTitle != null) { | |||
if (mTitle != null && !mTitle.equals("")) { | |||
mTvTitle.setVisibility(View.VISIBLE); | |||
mTvTitle.setText(mTitle); | |||
} else if (mTitle == null) { | |||
mTvTitle.setVisibility(View.GONE); | |||
} | |||
} | |||
return this; | |||
} | |||
public ShowListDialogFragment setCancel(CharSequence cancel, @ColorInt int cancelColor) { | |||
this.mCancel = cancel; | |||
this.mCancelColor = cancelColor; | |||
if (mTvCancel != null) { | |||
if (mCancel != null && !mCancel.equals("")) { | |||
mTvCancel.setVisibility(View.VISIBLE); | |||
mTvCancel.setText(mCancel); | |||
} else if (mCancel == null) { | |||
mTvCancel.setVisibility(View.GONE); | |||
} | |||
if (mCancelColor != 0) | |||
mTvCancel.setTextColor(mCancelColor); | |||
} | |||
return this; | |||
} | |||
/** | |||
* 修改列表中的内容 | |||
*/ | |||
public ShowListDialogFragment setList(List<DialogStringImageAdapter.DialogStringImageBean> list) { | |||
if (mList == null) { | |||
mList = new ArrayList<>(); | |||
mList.addAll(list); | |||
} | |||
if (mAdapter != null) | |||
mAdapter.notifyDataSetChanged(); | |||
return this; | |||
} | |||
public ShowListDialogFragment setOnDialogListener(onDialogListener onDialogListener) { | |||
mOnDialogListener = onDialogListener; | |||
return this; | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
int i = v.getId(); | |||
if (i == R.id.tv_dialog_photo_cancel) { | |||
if (mOnDialogListener != null) | |||
mOnDialogListener.onCancelListener(v); | |||
dismiss(); | |||
} | |||
} | |||
/** | |||
* 设置dialog是否在底部 | |||
*/ | |||
public ShowListDialogFragment setBottom(boolean bottom) { | |||
mBottom = bottom; | |||
return this; | |||
} | |||
/** | |||
* 设置dialog是否有灰色背景 | |||
*/ | |||
public ShowListDialogFragment setBackground(boolean background) { | |||
mBackground = background; | |||
return this; | |||
} | |||
/** | |||
* 设置点击空白区域是否可以关闭 | |||
*/ | |||
public ShowListDialogFragment setCancelBlank(boolean cancelable) { | |||
mCancelBlank = cancelable; | |||
return this; | |||
} | |||
/** | |||
* 当前是否显示 | |||
*/ | |||
public boolean isShow() { | |||
return mShow; | |||
} | |||
@Override | |||
public void show(@NonNull FragmentManager manager, @Nullable String tag) { | |||
try { | |||
if (!mShow) { | |||
super.show(manager, tag); | |||
mShow = true; | |||
} | |||
} catch (Exception e) { | |||
L.e(TAG, "显示异常"); | |||
e.printStackTrace(); | |||
} | |||
} | |||
public void show(@NonNull FragmentManager manager) { | |||
this.show(manager, "HintDataDialogFragment"); | |||
} | |||
@Override | |||
public void onDismiss(@NonNull DialogInterface dialog) { | |||
super.onDismiss(dialog); | |||
mShow = false; | |||
} | |||
@Override | |||
public void dismiss() { | |||
try { | |||
mShow = false; | |||
super.dismiss(); | |||
} catch (Exception e) { | |||
L.e(TAG, "关闭异常"); | |||
e.printStackTrace(); | |||
} | |||
} | |||
public interface onDialogListener { | |||
/** | |||
* 取消的点击事件 | |||
*/ | |||
default void onCancelListener(View v) { | |||
} | |||
/** | |||
* 打开点击事件 | |||
*/ | |||
void onItemListener(int position); | |||
} | |||
} |
@@ -0,0 +1,83 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid.utils; | |||
import android.app.Activity; | |||
import android.content.Context; | |||
import android.content.Intent; | |||
import android.content.pm.PackageManager; | |||
import android.location.LocationManager; | |||
import android.net.Uri; | |||
import android.provider.Settings; | |||
/** | |||
* xing<br> | |||
* 2019/4/22<br> | |||
* 路由跳转工具类 | |||
*/ | |||
public class AppStart { | |||
private static String TAG = AppStart.class.getName(); | |||
/** | |||
* 进入应用设置界面 | |||
* | |||
*/ | |||
public static void startUseSetActivity(Context context) { | |||
Intent localIntent = new Intent(); | |||
localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |||
localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS"); | |||
localIntent.setData(Uri.fromParts("package", context.getPackageName(), null)); | |||
context.startActivity(localIntent); | |||
} | |||
/** | |||
* 进入设置系统界面 | |||
* | |||
* @param context 上下文 | |||
*/ | |||
public static void startSetActivity(Context context) { | |||
Intent intent = new Intent(Settings.ACTION_SETTINGS); | |||
context.startActivity(intent); | |||
} | |||
/** | |||
* 手机是否开启位置服务 | |||
*/ | |||
public static boolean isLocServiceEnable(Context context) { | |||
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); | |||
boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); | |||
boolean network = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); | |||
if (gps || network) { | |||
return true; | |||
} | |||
return false; | |||
} | |||
/** | |||
* 进入定位服务 | |||
*/ | |||
public static void startLocationActivity(Activity activity, int code) { | |||
Intent localIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); | |||
if (activity.getPackageManager().resolveActivity(localIntent, | |||
PackageManager.MATCH_DEFAULT_ONLY) != null) { | |||
activity.startActivityForResult(localIntent, code); | |||
} | |||
} | |||
/** | |||
* 跳转到系统web | |||
*/ | |||
public static void startSysWeb(Context context, String url) { | |||
Intent intentWeb = new Intent(); | |||
intentWeb.setAction("android.intent.action.VIEW"); | |||
Uri content_url = Uri.parse("http://" + url); | |||
intentWeb.setData(content_url); | |||
context.startActivity(intentWeb); | |||
} | |||
} |
@@ -0,0 +1,64 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid.utils; | |||
import android.os.Environment; | |||
import java.io.File; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.Comparator; | |||
public class FileUtils { | |||
private static String TAG = FileUtils.class.getName(); | |||
private static String filesDir = Environment.getExternalStorageDirectory().getAbsolutePath(); | |||
public static String FILE_DIR="AiLinkBleDemo"; | |||
public static String FILE_NAME="updateName.img"; | |||
public static void init(){ | |||
filesDir = Environment.getExternalStorageDirectory().getAbsolutePath(); | |||
createFileDirectories(FILE_DIR); | |||
} | |||
public static String getByFileName(){ | |||
return filesDir + File.separator ; | |||
} | |||
/** | |||
* 创建文件夹 | |||
*/ | |||
private static void createFileDirectories(String directoryName) { | |||
filesDir = filesDir + File.separator + directoryName; | |||
File directory = new File(filesDir); | |||
if (!directory.exists()) { | |||
boolean mkdirs = directory.mkdirs(); | |||
L.i(TAG,"创建OTA文件:"+mkdirs); | |||
} | |||
} | |||
public static ArrayList<String> list() { | |||
File f = new File(filesDir); | |||
File file[] = f.listFiles(); | |||
if (file==null) | |||
return new ArrayList<>(); | |||
Arrays.sort(file, new Comparator<File>() { | |||
@Override | |||
public int compare(File lhs, File rhs) { | |||
return lhs.getPath().compareToIgnoreCase(rhs.getPath()); | |||
} | |||
}); | |||
L.d("Files", "Size: " + file.length); | |||
ArrayList<String> names = new ArrayList<String>(); | |||
for (int i = 0; i < file.length; i++) { | |||
L.d("Files", "FileName:" + file[i].getName()); | |||
names.add(file[i].getName()); | |||
} | |||
return names; | |||
} | |||
} |
@@ -0,0 +1,189 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid.utils; | |||
import android.util.Log; | |||
import java.text.SimpleDateFormat; | |||
import java.util.Date; | |||
import java.util.Locale; | |||
import androidx.annotation.NonNull; | |||
/** | |||
* 打印日志工具 | |||
*/ | |||
public class L { | |||
/** | |||
* 是否开启log日志 | |||
*/ | |||
private static boolean isLog = true; | |||
private static String TAG = "TagOther"; | |||
/** | |||
* 日志初始化 | |||
* | |||
* @param isShowLog 是否打印日志 | |||
*/ | |||
public static void init(boolean isShowLog) { | |||
isLog = isShowLog; | |||
} | |||
/** | |||
* 详细日志 | |||
*/ | |||
public static void v(String tag, String msg) { | |||
if (isLog) { | |||
logContent(tag, msg, 4); | |||
} | |||
} | |||
public static void v(String msg) { | |||
v(TAG, msg); | |||
} | |||
/** | |||
* 错误日志 | |||
*/ | |||
public static void e(String tag, String msg) { | |||
if (isLog) { | |||
logContent(tag, msg, 1); | |||
} | |||
} | |||
public static void e(String msg) { | |||
e(TAG, msg); | |||
} | |||
/** | |||
* 警告日志 | |||
*/ | |||
public static void w(String tag, String msg) { | |||
if (isLog) { | |||
logContent(tag, msg, 3); | |||
} | |||
} | |||
public static void w(String msg) { | |||
w(TAG, msg); | |||
} | |||
/** | |||
* 信息日志 | |||
*/ | |||
public static void i(String tag, String msg) { | |||
if (isLog) { | |||
logContent(tag, msg, 0); | |||
} | |||
} | |||
public static void i(String msg) { | |||
i(TAG, msg); | |||
} | |||
/** | |||
* 调试日志 | |||
*/ | |||
public static void d(String tag, String msg) { | |||
if (isLog) { | |||
logContent(tag, msg, 2); | |||
} | |||
} | |||
public static void d(String msg) { | |||
d(TAG, msg); | |||
} | |||
private static void logContent(String msg) { | |||
logContent("", msg, 0); | |||
} | |||
/** | |||
* @param tag tag | |||
* @param msg 内容 | |||
* @param level 0=i;1=e;2=d;3=w;其他=v; | |||
*/ | |||
private static void logContent(String tag, String msg, int level) { | |||
StackTraceElement[] trace = Thread.currentThread().getStackTrace(); | |||
int methodCount = 1; | |||
int stackOffset = getStackOffset(trace); | |||
if (methodCount + stackOffset > trace.length) { | |||
methodCount = trace.length - stackOffset - 1; | |||
} | |||
for (int i = methodCount; i > 0; i--) { | |||
int stackIndex = i + stackOffset; | |||
if (stackIndex >= trace.length) { | |||
continue; | |||
} | |||
StackTraceElement element = trace[stackIndex]; | |||
switch (level) { | |||
case 0: | |||
Log.i(tag, getLogContent(msg, element)); | |||
break; | |||
case 1: | |||
Log.e(tag, getLogContent(msg, element)); | |||
break; | |||
case 2: | |||
Log.d(tag, getLogContent(msg, element)); | |||
break; | |||
case 3: | |||
Log.w(tag, getLogContent(msg, element)); | |||
break; | |||
default: | |||
Log.v(tag, msg); | |||
break; | |||
} | |||
} | |||
} | |||
private static String getLogContent(String msg, StackTraceElement element) { | |||
StringBuilder builder = new StringBuilder(); | |||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); | |||
String time = sdf.format(new Date()); | |||
builder.append("\n") | |||
.append("-------------------------------------------------------\n") | |||
.append("|") | |||
.append(time) | |||
.append("\n") | |||
.append("|") | |||
.append(getSimpleClassName(element.getClassName())) | |||
.append(".") | |||
.append(element.getMethodName()) | |||
.append(" ") | |||
.append(" (") | |||
.append(element.getFileName()) | |||
.append(":") | |||
.append(element.getLineNumber()) | |||
.append(")") | |||
.append("\n") | |||
.append("||==>") | |||
.append(msg) | |||
.append("\n") | |||
.append("-------------------------------------------------------\n"); | |||
return builder.toString(); | |||
} | |||
private static int getStackOffset(StackTraceElement[] trace) { | |||
for (int i = 2; i < trace.length; i++) { | |||
StackTraceElement e = trace[i]; | |||
String name = e.getClassName(); | |||
String l = L.class.getName(); | |||
if (!name.equals(l)) { | |||
return --i; | |||
} | |||
} | |||
return -1; | |||
} | |||
private static String getSimpleClassName(@NonNull String name) { | |||
int lastIndex = name.lastIndexOf("."); | |||
return name.substring(lastIndex + 1); | |||
} | |||
} |
@@ -0,0 +1,160 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid.utils; | |||
import android.content.Context; | |||
import android.content.SharedPreferences; | |||
import java.util.Map; | |||
public class SP { | |||
public static final int INT_DEFAULT = 0; | |||
public static final String STR_DEFAULT = ""; | |||
private static SP instance; | |||
private SharedPreferences sp; | |||
/** | |||
* 保存在手机里面的文件名 | |||
*/ | |||
private static final String FILE_NAME = "app_data"; | |||
public static String OTA_FILE_NAME = "OTA_FILE_NAME"; | |||
//------------------------------------- | |||
private SP(Context context) { | |||
sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); | |||
} | |||
public static SP getInstance() { | |||
return instance; | |||
} | |||
public static void init(Context context) { | |||
if (instance == null) { | |||
synchronized (SP.class) { | |||
if (instance == null) { | |||
instance = new SP(context); | |||
} | |||
} | |||
} | |||
} | |||
public String getOtaFileName() { | |||
return sp.getString(OTA_FILE_NAME, STR_DEFAULT); | |||
} | |||
public void putOtaFileName(String name) { | |||
SharedPreferences.Editor editor = sp.edit(); | |||
editor.putString(OTA_FILE_NAME, name); | |||
apply(editor); | |||
} | |||
/** | |||
* 移除某个key值已经对应的值 | |||
*/ | |||
public void remove(String key) { | |||
SharedPreferences.Editor editor = sp.edit(); | |||
editor.remove(key); | |||
apply(editor); | |||
} | |||
/** | |||
* 清除用户相关的所有数据 | |||
*/ | |||
public void clear() { | |||
SharedPreferences.Editor editor = sp.edit(); | |||
editor.remove(OTA_FILE_NAME); | |||
apply(editor); | |||
} | |||
/** | |||
* 清除所有数据 | |||
*/ | |||
public void clearAll() { | |||
SharedPreferences.Editor editor = sp.edit(); | |||
editor.clear(); | |||
apply(editor); | |||
} | |||
/** | |||
* 保存数据的方法,我们需要拿到保存数据的具体类型,然后根据类型调用不同的保存方法 | |||
*/ | |||
public int put(String key, Object object) { | |||
SharedPreferences.Editor editor = sp.edit(); | |||
if (object instanceof String) { | |||
editor.putString(key, (String) object); | |||
} else if (object instanceof Integer) { | |||
editor.putInt(key, (Integer) object); | |||
} else if (object instanceof Boolean) { | |||
editor.putBoolean(key, (Boolean) object); | |||
} else if (object instanceof Float) { | |||
editor.putFloat(key, (Float) object); | |||
} else if (object instanceof Long) { | |||
editor.putLong(key, (Long) object); | |||
} else { | |||
editor.putString(key, object.toString()); | |||
} | |||
apply(editor); | |||
return 0; | |||
} | |||
/** | |||
* 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值 | |||
*/ | |||
public Object get(String key, Object defaultObject) { | |||
if (defaultObject instanceof String) { | |||
return sp.getString(key, (String) defaultObject); | |||
} else if (defaultObject instanceof Integer) { | |||
return sp.getInt(key, (Integer) defaultObject); | |||
} else if (defaultObject instanceof Boolean) { | |||
return sp.getBoolean(key, (Boolean) defaultObject); | |||
} else if (defaultObject instanceof Float) { | |||
return sp.getFloat(key, (Float) defaultObject); | |||
} else if (defaultObject instanceof Long) { | |||
return sp.getLong(key, (Long) defaultObject); | |||
} | |||
return defaultObject; | |||
} | |||
/** | |||
* 查询某个key是否已经存在 | |||
*/ | |||
public boolean contains(Context context, String key) { | |||
return sp.contains(key); | |||
} | |||
/** | |||
* 返回所有的键值对 | |||
*/ | |||
public Map<String, ?> getAll(Context context) { | |||
return sp.getAll(); | |||
} | |||
/** | |||
* 使用apply执行,否则使用commit | |||
*/ | |||
private static void apply(SharedPreferences.Editor editor) { | |||
try { | |||
editor.apply(); | |||
} catch (Exception e) { | |||
editor.commit(); | |||
e.printStackTrace(); | |||
} | |||
} | |||
} |
@@ -0,0 +1,18 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid.utils; | |||
import java.text.SimpleDateFormat; | |||
import java.util.Locale; | |||
/** | |||
* xing<br> | |||
* 2019/5/25<br> | |||
* java类作用描述 | |||
*/ | |||
public class TimeUtils { | |||
public static String getTime(){ | |||
java.text.SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss", Locale.US); | |||
return format.format(System.currentTimeMillis())+":\n"; | |||
} | |||
} |
@@ -0,0 +1,135 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid.view; | |||
import android.content.Context; | |||
import android.graphics.Canvas; | |||
import android.graphics.Paint; | |||
import android.graphics.Rect; | |||
import android.util.TypedValue; | |||
import android.view.View; | |||
import androidx.annotation.ColorInt; | |||
import androidx.annotation.NonNull; | |||
import androidx.recyclerview.widget.LinearLayoutManager; | |||
import androidx.recyclerview.widget.RecyclerView; | |||
/** | |||
* 2019/10/14 | |||
* RecyclerView分界线 | |||
*/ | |||
public class MyItemDecoration extends RecyclerView.ItemDecoration { | |||
private Paint mPaint; | |||
private int mDividerHeight;//分割线高度,默认为1px | |||
private int mLeft,mRight; | |||
private int mOrientation;//列表的方向:LinearLayoutManager.VERTICAL或LinearLayoutManager.HORIZONTAL | |||
/** | |||
* 自定义分割线 | |||
* | |||
* @param orientation 列表方向 | |||
* @param dividerHeight 分割线高度 | |||
* @param mLeft 距离左边的距离 | |||
* @param mRight 距离右边的距离 | |||
* @param dividerColor 分割线颜色 | |||
*/ | |||
public MyItemDecoration(Context context, int orientation, int dividerHeight, int mLeft, int mRight, @ColorInt int dividerColor) { | |||
mOrientation=orientation; | |||
mDividerHeight = dividerHeight; | |||
this.mLeft = dp2px(context,mLeft); | |||
this.mRight = dp2px(context,mRight); | |||
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); | |||
mPaint.setColor(dividerColor); | |||
mPaint.setStyle(Paint.Style.FILL); | |||
} | |||
/** | |||
* 自定义分割线 | |||
* | |||
* @param orientation 列表方向 | |||
* @param dividerHeight 分割线高度 | |||
* @param dividerColor 分割线颜色 | |||
*/ | |||
public MyItemDecoration(Context context, int orientation, int dividerHeight, @ColorInt int dividerColor) { | |||
this(context,orientation,dividerHeight,0,0,dividerColor); | |||
} | |||
//获取分割线尺寸 | |||
@Override | |||
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { | |||
super.getItemOffsets(outRect, view, parent, state); | |||
if (mOrientation == LinearLayoutManager.VERTICAL) { | |||
outRect.set(mLeft, 0, mRight, mDividerHeight); | |||
} else { | |||
outRect.set(0, 0, mDividerHeight, 0); | |||
} | |||
} | |||
//绘制分割线 | |||
@Override | |||
public void onDraw(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { | |||
super.onDraw(c, parent, state); | |||
if (mOrientation == LinearLayoutManager.VERTICAL) { | |||
drawVertical(c, parent); | |||
} else { | |||
drawHorizontal(c, parent); | |||
} | |||
} | |||
/** | |||
* 绘制纵向列表时的分隔线 这时分隔线是横着的 | |||
* 每次 left相同,top根据child变化,right相同,bottom也变化 | |||
* | |||
*/ | |||
private void drawVertical(Canvas canvas, RecyclerView parent) { | |||
final int left = parent.getPaddingLeft(); | |||
final int right = parent.getMeasuredWidth() - parent.getPaddingRight(); | |||
final int childSize = parent.getChildCount(); | |||
for (int i = 0; i < childSize-1; i++) { | |||
final View child = parent.getChildAt(i); | |||
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams(); | |||
final int top = child.getBottom() + layoutParams.bottomMargin; | |||
final int bottom = top + mDividerHeight; | |||
if (mPaint != null) { | |||
canvas.drawRect(left, top, right, bottom, mPaint); | |||
} | |||
} | |||
} | |||
/** | |||
* 绘制横向列表时的分隔线 这时分隔线是竖着的 | |||
* l、r 变化; t、b 不变 | |||
* | |||
*/ | |||
private void drawHorizontal(Canvas canvas, RecyclerView parent) { | |||
final int top = parent.getPaddingTop(); | |||
final int bottom = parent.getMeasuredHeight() - parent.getPaddingBottom(); | |||
final int childSize = parent.getChildCount(); | |||
for (int i = 0; i < childSize; i++) { | |||
final View child = parent.getChildAt(i); | |||
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams(); | |||
final int left = child.getRight() + layoutParams.rightMargin; | |||
final int right = left + mDividerHeight; | |||
if (mPaint != null) { | |||
canvas.drawRect(left, top, right, bottom, mPaint); | |||
} | |||
} | |||
} | |||
/** | |||
* dp转px | |||
* | |||
*/ | |||
private int dp2px(Context context, float dpVal) { | |||
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, | |||
dpVal, context.getResources().getDisplayMetrics()); | |||
} | |||
} |
@@ -0,0 +1,95 @@ | |||
package aicare.net.cn.sdk.ailinksdkdemoandroid.view; | |||
import android.content.Context; | |||
import android.os.Build; | |||
import android.util.AttributeSet; | |||
import android.widget.SeekBar; | |||
/** | |||
* xing<br> | |||
* 2020/5/9<br> | |||
* SeekBar允许设置最小值 | |||
* 兼容旧版本 | |||
*/ | |||
public class SeekBarMin extends SeekBar implements SeekBar.OnSeekBarChangeListener { | |||
private int mMin; | |||
private boolean mApi26 = false; | |||
private OnSeekBarChangeListener mOnSeekBarChangeListener; | |||
public SeekBarMin(Context context) { | |||
this(context, null); | |||
} | |||
public SeekBarMin(Context context, AttributeSet attrs) { | |||
this(context, attrs, 0); | |||
} | |||
public SeekBarMin(Context context, AttributeSet attrs, int defStyleAttr) { | |||
super(context, attrs, defStyleAttr); | |||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |||
mApi26 = true; | |||
} | |||
super.setOnSeekBarChangeListener(this); | |||
} | |||
@Override | |||
public synchronized void setMin(int min) { | |||
if (mApi26) { | |||
super.setMin(min); | |||
} else { | |||
mMin = min; | |||
} | |||
} | |||
@Override | |||
public synchronized void setProgress(int progress) { | |||
if (!mApi26) { | |||
progress -= mMin; | |||
} | |||
super.setProgress(progress); | |||
} | |||
@Override | |||
public synchronized void setMax(int max) { | |||
if (!mApi26) { | |||
max -= mMin; | |||
} | |||
super.setMax(max); | |||
} | |||
@Override | |||
public int getMin() { | |||
return mMin; | |||
} | |||
@Override | |||
public void setOnSeekBarChangeListener(OnSeekBarChangeListener l) { | |||
mOnSeekBarChangeListener = l; | |||
} | |||
@Override | |||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { | |||
if (!mApi26) { | |||
progress += mMin; | |||
} | |||
if (mOnSeekBarChangeListener != null) | |||
mOnSeekBarChangeListener.onProgressChanged(seekBar, progress, fromUser); | |||
} | |||
@Override | |||
public void onStartTrackingTouch(SeekBar seekBar) { | |||
if (mOnSeekBarChangeListener != null) | |||
mOnSeekBarChangeListener.onStartTrackingTouch(seekBar); | |||
} | |||
@Override | |||
public void onStopTrackingTouch(SeekBar seekBar) { | |||
if (mOnSeekBarChangeListener != null) | |||
mOnSeekBarChangeListener.onStopTrackingTouch(seekBar); | |||
} | |||
} |
@@ -0,0 +1,12 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |||
<item> | |||
<shape | |||
android:shape="rectangle"> | |||
<solid android:color="@android:color/white" /> | |||
<corners | |||
android:radius="10dp"/> | |||
</shape> | |||
</item> | |||
</selector> |
@@ -0,0 +1,209 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical"> | |||
<ScrollView | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1"> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="vertical"> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/btnVersion" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="版本号" | |||
android:textAllCaps="false" /> | |||
<Button | |||
android:id="@+id/btnDis" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="断开" | |||
android:textAllCaps="false" /> | |||
<Button | |||
android:id="@+id/btnConnect" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="连接" | |||
android:textAllCaps="false" /> | |||
</LinearLayout> | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Height:" /> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:gravity="center_vertical" | |||
android:padding="10dp"> | |||
<RadioGroup | |||
android:id="@+id/radio_height" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal"> | |||
<RadioButton | |||
android:id="@+id/radio_height_cm" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:checked="true" | |||
android:text="cm" /> | |||
<RadioButton | |||
android:id="@+id/radio_height_inch" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="inch" /> | |||
<RadioButton | |||
android:id="@+id/radio_height_foot" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="foot" /> | |||
</RadioGroup> | |||
</LinearLayout> | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Weight:" /> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:gravity="center_vertical" | |||
android:padding="10dp"> | |||
<RadioGroup | |||
android:id="@+id/radio_weight" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal"> | |||
<RadioButton | |||
android:id="@+id/radio_weight_kg" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:checked="true" | |||
android:text="kg" /> | |||
<RadioButton | |||
android:id="@+id/radio_weight_jin" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="jin" /> | |||
<RadioButton | |||
android:id="@+id/radio_weight_lb" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="lb:oz" /> | |||
<RadioButton | |||
android:id="@+id/radio_weight_oz" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="oz" /> | |||
<RadioButton | |||
android:id="@+id/radio_weight_st_lb" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="st:lb" /> | |||
<RadioButton | |||
android:id="@+id/radio_weight_g" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="g" /> | |||
<RadioButton | |||
android:id="@+id/radio_weight_lb_lb" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="lb" /> | |||
</RadioGroup> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/btn_set_tare" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Tare" | |||
android:textAllCaps="false" /> | |||
<Button | |||
android:id="@+id/btn_set_hold" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Hold" | |||
android:textAllCaps="false" /> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/clear" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="@string/clear" | |||
android:textAllCaps="false" /> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</ScrollView> | |||
<ListView | |||
android:id="@+id/listview" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
android:padding="10dp" | |||
android:stackFromBottom="true" | |||
android:transcriptMode="alwaysScroll"> | |||
</ListView> | |||
</LinearLayout> |
@@ -14,6 +14,8 @@ | |||
android:layout_weight="1" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
@@ -33,6 +35,24 @@ | |||
android:text="@string/clear" | |||
/> | |||
<Button | |||
android:id="@+id/btnPause" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="暂停" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
> | |||
<Button | |||
android:id="@+id/btnHandshake" | |||
android:layout_width="wrap_content" | |||
@@ -95,6 +115,8 @@ | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
@@ -187,6 +209,13 @@ | |||
android:text="读名称" | |||
/> | |||
<Button | |||
android:id="@+id/btn_start_ble" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="唤醒模块" | |||
/> | |||
</LinearLayout> | |||
@@ -250,6 +279,37 @@ | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
android:padding="5dp" | |||
> | |||
<EditText | |||
android:id="@+id/etSleepTime" | |||
android:layout_width="150dp" | |||
android:layout_height="wrap_content" | |||
android:digits="0987654321," | |||
android:text="1,60,1,1000" | |||
android:hint="标记,时间,操作,广播时间" | |||
/> | |||
<Button | |||
android:id="@+id/btnSleepTimeWrite" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="写自动休眠" | |||
/> | |||
<Button | |||
android:id="@+id/btnSleepTimeRead" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="读自动休眠" | |||
/> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</ScrollView> |
@@ -0,0 +1,113 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical"> | |||
<ScrollView | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="0.5"> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="vertical"> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
android:layout_marginStart="10dp" | |||
android:layout_marginTop="10dp" | |||
android:gravity="center_vertical" | |||
> | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Mac:" | |||
/> | |||
<TextView | |||
android:id="@+id/tv_broadcast_mac" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="" | |||
android:layout_marginStart="5dp" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
android:layout_marginStart="10dp" | |||
android:layout_marginTop="10dp" | |||
android:gravity="center_vertical" | |||
> | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="血氧百分比:" | |||
/> | |||
<TextView | |||
android:id="@+id/tv_broadcast_blood_oxygen" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="--%" | |||
android:layout_marginStart="5dp" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/clear" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="@string/clear" | |||
android:textAllCaps="false" /> | |||
<Button | |||
android:id="@+id/open" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="开始" | |||
android:textAllCaps="false" /> | |||
<Button | |||
android:id="@+id/stop" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="停止" | |||
android:textAllCaps="false" /> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</ScrollView> | |||
<ListView | |||
android:id="@+id/listview" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
android:padding="10dp" | |||
android:stackFromBottom="true" | |||
android:transcriptMode="alwaysScroll"> | |||
</ListView> | |||
</LinearLayout> |
@@ -0,0 +1,183 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical"> | |||
<ScrollView | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="0.5"> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="vertical"> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
android:layout_marginStart="10dp" | |||
android:layout_marginTop="10dp" | |||
android:gravity="center_vertical" | |||
> | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Mac:" | |||
/> | |||
<TextView | |||
android:id="@+id/tv_broadcast_mac" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="" | |||
android:layout_marginStart="5dp" | |||
/> | |||
</LinearLayout> | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_marginStart="10dp" | |||
android:layout_marginTop="10dp" | |||
android:text="Weight:" /> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:gravity="center_vertical" | |||
android:padding="10dp"> | |||
<RadioGroup | |||
android:id="@+id/radio_weight" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal"> | |||
<RadioButton | |||
android:id="@+id/radio_weight_kg" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:checked="true" | |||
android:text="kg" /> | |||
<RadioButton | |||
android:id="@+id/radio_weight_jin" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="jin" /> | |||
<RadioButton | |||
android:id="@+id/radio_weight_lb" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="lb:oz" /> | |||
<RadioButton | |||
android:id="@+id/radio_weight_oz" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="oz" /> | |||
<RadioButton | |||
android:id="@+id/radio_weight_st_lb" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="st:lb" /> | |||
<RadioButton | |||
android:id="@+id/radio_weight_g" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="g" /> | |||
<RadioButton | |||
android:id="@+id/radio_weight_lb_lb" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="lb" /> | |||
</RadioGroup> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
android:layout_marginStart="10dp" | |||
android:layout_marginTop="10dp" | |||
android:gravity="center_vertical" | |||
> | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Temp:" | |||
/> | |||
<TextView | |||
android:id="@+id/tv_broadcast_temp" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="30℃" | |||
android:layout_marginStart="5dp" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/clear" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="@string/clear" | |||
android:textAllCaps="false" /> | |||
<Button | |||
android:id="@+id/open" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="开始" | |||
android:textAllCaps="false" /> | |||
<Button | |||
android:id="@+id/stop" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="停止" | |||
android:textAllCaps="false" /> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</ScrollView> | |||
<ListView | |||
android:id="@+id/listview" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
android:padding="10dp" | |||
android:stackFromBottom="true" | |||
android:transcriptMode="alwaysScroll"> | |||
</ListView> | |||
</LinearLayout> |
@@ -0,0 +1,83 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:focusable="true" | |||
android:focusableInTouchMode="true" | |||
android:orientation="vertical"> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/btn" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="搜索" /> | |||
<Button | |||
android:id="@+id/btn1" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="停止" /> | |||
<Button | |||
android:id="@+id/clear" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="清空列表" /> | |||
<Button | |||
android:id="@+id/clearData" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="清空数据" /> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/filter" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="过滤:true" /> | |||
<Button | |||
android:id="@+id/跳过" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="跳过" /> | |||
</LinearLayout> | |||
<ListView | |||
android:id="@+id/listview" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
android:padding="10dp"> | |||
</ListView> | |||
<ListView | |||
android:id="@+id/listviewData" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
android:padding="10dp" | |||
android:stackFromBottom="true" | |||
android:transcriptMode="alwaysScroll" | |||
> | |||
</ListView> | |||
</LinearLayout> |
@@ -0,0 +1,70 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:orientation="vertical" android:layout_width="match_parent" | |||
android:layout_height="match_parent"> | |||
<RadioGroup | |||
android:id="@+id/unit" | |||
android:layout_below="@+id/edit_Userid" | |||
android:layout_width="match_parent" | |||
android:orientation="horizontal" | |||
android:layout_height="wrap_content"> | |||
<RadioButton | |||
android:id="@+id/kg" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:text="kg"/> | |||
<RadioButton | |||
android:id="@+id/jin" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:text="斤"/> | |||
<RadioButton | |||
android:id="@+id/st_lb" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:text="st:lb"/> | |||
<RadioButton | |||
android:id="@+id/lb" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:text="lb"/> | |||
</RadioGroup> | |||
<RadioGroup | |||
android:id="@+id/temp_unit" | |||
android:layout_below="@+id/edit_Userid" | |||
android:layout_width="match_parent" | |||
android:orientation="horizontal" | |||
android:layout_height="wrap_content"> | |||
<RadioButton | |||
android:id="@+id/c" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:text="℃"/> | |||
<RadioButton | |||
android:id="@+id/f" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:text="℉"/> | |||
</RadioGroup> | |||
<Button | |||
android:id="@+id/support_unit" | |||
android:text="查询支持单位" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
/> | |||
<ListView | |||
android:id="@+id/log_list" | |||
android:layout_marginTop="20dp" | |||
android:layout_below="@id/unit" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent"> | |||
</ListView> | |||
</LinearLayout> |
@@ -0,0 +1,459 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout | |||
xmlns:android="http://schemas.android.com/apk/res/android" | |||
xmlns:app="http://schemas.android.com/apk/res-auto" | |||
xmlns:tools="http://schemas.android.com/tools" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical"> | |||
<ScrollView | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
android:orientation="vertical" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal"> | |||
<Button | |||
android:id="@+id/button_connect" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="连接" | |||
/> | |||
<Button | |||
android:id="@+id/button_dis" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="断开" | |||
tools:layout_editor_absoluteX="281dp" | |||
tools:layout_editor_absoluteY="40dp"/> | |||
<Button | |||
android:id="@+id/button_clear" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="清空" | |||
tools:layout_editor_absoluteX="281dp" | |||
tools:layout_editor_absoluteY="120dp"/> | |||
<Button | |||
android:id="@+id/button_ota" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="OTA" | |||
tools:layout_editor_absoluteX="281dp" | |||
tools:layout_editor_absoluteY="120dp"/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal"> | |||
<Button | |||
android:id="@+id/button_time" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="同步时间" | |||
/> | |||
<Button | |||
android:id="@+id/button_status" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="获取状态" | |||
tools:layout_editor_absoluteX="281dp" | |||
tools:layout_editor_absoluteY="40dp"/> | |||
<Button | |||
android:id="@+id/button_info" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="获取参数" | |||
tools:layout_editor_absoluteX="281dp" | |||
tools:layout_editor_absoluteY="40dp"/> | |||
<Button | |||
android:id="@+id/button_log" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="读取记录" | |||
tools:layout_editor_absoluteX="16dp" | |||
tools:layout_editor_absoluteY="120dp"/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content"> | |||
<Button | |||
android:id="@+id/button_close" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="关机" | |||
tools:layout_editor_absoluteX="148dp" | |||
tools:layout_editor_absoluteY="120dp"/> | |||
<Button | |||
android:id="@+id/button_activation" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="激活设备" | |||
tools:layout_editor_absoluteX="148dp" | |||
tools:layout_editor_absoluteY="120dp"/> | |||
<Button | |||
android:id="@+id/button_close_activation" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="清除激活状态" | |||
tools:layout_editor_absoluteX="148dp" | |||
tools:layout_editor_absoluteY="120dp"/> | |||
<Button | |||
android:id="@+id/button_bind" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="绑定" | |||
tools:layout_editor_absoluteX="148dp" | |||
tools:layout_editor_absoluteY="120dp"/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content"> | |||
<Button | |||
android:id="@+id/button_reboot" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="重启" | |||
tools:layout_editor_absoluteX="148dp" | |||
tools:layout_editor_absoluteY="120dp"/> | |||
<Button | |||
android:id="@+id/button_version" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="版本号" | |||
tools:layout_editor_absoluteX="148dp" | |||
tools:layout_editor_absoluteY="120dp"/> | |||
<TextView | |||
android:id="@+id/tv_version" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="bm" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content"> | |||
<EditText | |||
android:id="@+id/et_set_user" | |||
android:layout_width="0dp" | |||
android:layout_height="match_parent" | |||
android:layout_weight="1" | |||
android:digits="0123456789" | |||
android:hint="userId" | |||
android:text="1" | |||
/> | |||
<EditText | |||
android:id="@+id/et_set_user_status" | |||
android:layout_width="0dp" | |||
android:layout_height="match_parent" | |||
android:layout_weight="1" | |||
android:digits="0123456789" | |||
android:hint="status" | |||
android:maxLength="1" | |||
android:text="0" | |||
/> | |||
<Button | |||
android:id="@+id/button_user" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="下发用户" | |||
tools:layout_editor_absoluteX="148dp" | |||
tools:layout_editor_absoluteY="41dp"/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:gravity="center_vertical" | |||
android:orientation="horizontal" | |||
> | |||
<TextView | |||
android:layout_width="100dp" | |||
android:layout_height="wrap_content" | |||
android:text="靠近报警阀值:" | |||
/> | |||
<aicare.net.cn.sdk.ailinksdkdemoandroid.view.SeekBarMin | |||
android:id="@+id/seekBar1" | |||
style="@style/Widget.AppCompat.SeekBar" | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
/> | |||
<TextView | |||
android:id="@+id/text1" | |||
android:layout_width="50dp" | |||
android:layout_height="wrap_content" | |||
android:text="阀值" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:gravity="center_vertical" | |||
android:orientation="horizontal" | |||
> | |||
<TextView | |||
android:layout_width="100dp" | |||
android:layout_height="wrap_content" | |||
android:text="接收的阀值次数:" | |||
/> | |||
<aicare.net.cn.sdk.ailinksdkdemoandroid.view.SeekBarMin | |||
android:id="@+id/seekBar2" | |||
style="@style/Widget.AppCompat.SeekBar" | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
/> | |||
<TextView | |||
android:id="@+id/text2" | |||
android:layout_width="50dp" | |||
android:layout_height="wrap_content" | |||
android:text="阀值" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:gravity="center_vertical" | |||
android:orientation="horizontal" | |||
> | |||
<TextView | |||
android:layout_width="100dp" | |||
android:layout_height="wrap_content" | |||
android:text="脱离报警时间:" | |||
/> | |||
<aicare.net.cn.sdk.ailinksdkdemoandroid.view.SeekBarMin | |||
android:id="@+id/seekBar3" | |||
style="@style/Widget.AppCompat.SeekBar" | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
/> | |||
<TextView | |||
android:id="@+id/text3" | |||
android:layout_width="50dp" | |||
android:layout_height="wrap_content" | |||
android:text="阀值" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:gravity="center_vertical" | |||
android:orientation="horizontal" | |||
> | |||
<TextView | |||
android:layout_width="100dp" | |||
android:layout_height="wrap_content" | |||
android:text="脱离报警次数:" | |||
/> | |||
<aicare.net.cn.sdk.ailinksdkdemoandroid.view.SeekBarMin | |||
android:id="@+id/seekBar4" | |||
style="@style/Widget.AppCompat.SeekBar" | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1"/> | |||
<TextView | |||
android:id="@+id/text4" | |||
android:layout_width="50dp" | |||
android:layout_height="wrap_content" | |||
android:text="阀值" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:gravity="center_vertical" | |||
android:orientation="horizontal" | |||
> | |||
<TextView | |||
android:layout_width="100dp" | |||
android:layout_height="wrap_content" | |||
android:text="Gsensor灵敏度:" | |||
/> | |||
<aicare.net.cn.sdk.ailinksdkdemoandroid.view.SeekBarMin | |||
android:id="@+id/seekBar5" | |||
style="@style/Widget.AppCompat.SeekBar" | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
/> | |||
<TextView | |||
android:id="@+id/text5" | |||
android:layout_width="50dp" | |||
android:layout_height="wrap_content" | |||
android:text="阀值" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:gravity="center_vertical" | |||
android:orientation="horizontal" | |||
> | |||
<TextView | |||
android:layout_width="100dp" | |||
android:layout_height="wrap_content" | |||
android:text="Gsensor不动的脱机时间:" | |||
/> | |||
<aicare.net.cn.sdk.ailinksdkdemoandroid.view.SeekBarMin | |||
android:id="@+id/seekBar6" | |||
style="@style/Widget.AppCompat.SeekBar" | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
/> | |||
<TextView | |||
android:id="@+id/text6" | |||
android:layout_width="50dp" | |||
android:layout_height="wrap_content" | |||
android:text="阀值" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:gravity="center_vertical" | |||
android:orientation="horizontal" | |||
> | |||
<TextView | |||
android:layout_width="100dp" | |||
android:layout_height="wrap_content" | |||
android:text="马达震动时间:" | |||
/> | |||
<aicare.net.cn.sdk.ailinksdkdemoandroid.view.SeekBarMin | |||
android:id="@+id/seekBar7" | |||
style="@style/Widget.AppCompat.SeekBar" | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
/> | |||
<TextView | |||
android:id="@+id/text7" | |||
android:layout_width="50dp" | |||
android:layout_height="wrap_content" | |||
android:text="阀值" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:gravity="right" | |||
> | |||
<Button | |||
android:id="@+id/button_set" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="设置参数" | |||
tools:layout_editor_absoluteX="281dp" | |||
tools:layout_editor_absoluteY="120dp"/> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</ScrollView> | |||
<ListView | |||
android:id="@+id/listview" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_marginTop="10dp" | |||
android:layout_weight="1" | |||
android:padding="10dp" | |||
android:stackFromBottom="true" | |||
android:transcriptMode="alwaysScroll" | |||
> | |||
</ListView> | |||
</LinearLayout> |
@@ -0,0 +1,222 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical" | |||
android:focusable="true" | |||
android:focusableInTouchMode="true" | |||
> | |||
<ScrollView | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1.5" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="vertical" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/btnVersion" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="版本号" | |||
android:textAllCaps="false" /> | |||
<Button | |||
android:id="@+id/clear" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="清空" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/btn_get_did" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="did" | |||
/> | |||
<Button | |||
android:id="@+id/btn_get_battery" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="battery" | |||
/> | |||
<Button | |||
android:id="@+id/btn_init" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="init" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/set_key" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="set_key" | |||
/> | |||
<Button | |||
android:id="@+id/syn_time" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="同步时间" | |||
/> | |||
<Button | |||
android:id="@+id/one_pwd" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="一次性密码" | |||
/> | |||
<Button | |||
android:id="@+id/resetT" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="重置T" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/openLock" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="开锁" | |||
/> | |||
<Button | |||
android:id="@+id/closeLock" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="关锁" | |||
/> | |||
<Button | |||
android:id="@+id/lockLog" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="记录" | |||
/> | |||
<Button | |||
android:id="@+id/lockErrLog" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="异常记录" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/deleteLog" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="删除记录" | |||
/> | |||
<Button | |||
android:id="@+id/cancelLog" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="取消读取" | |||
/> | |||
<Button | |||
android:id="@+id/keyType" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="支持类型" | |||
/> | |||
<Button | |||
android:id="@+id/bindingOk" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="绑定成功" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/getKey" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="同步用户" | |||
/> | |||
<Button | |||
android:id="@+id/clearKey" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="清空用户" | |||
/> | |||
<Button | |||
android:id="@+id/getModuleStatus" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="查询模块状态" | |||
/> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</ScrollView> | |||
<ListView | |||
android:id="@+id/listview" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="2.5" | |||
android:padding="10dp" | |||
android:stackFromBottom="true" | |||
android:transcriptMode="alwaysScroll" | |||
> | |||
</ListView> | |||
</LinearLayout> |
@@ -17,6 +17,7 @@ | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_margin="10dp" | |||
@@ -52,6 +53,7 @@ | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_margin="10dp" | |||
@@ -66,15 +68,50 @@ | |||
<Button | |||
android:id="@+id/btn_ad_weight" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="艾迪体脂秤" | |||
/> | |||
<Button | |||
android:id="@+id/btn_smart_mask" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="口罩" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_margin="10dp" | |||
android:layout_height="wrap_content"> | |||
<Button | |||
android:id="@+id/btn_baby_body_fat" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="婴儿体脂两用秤" | |||
/> | |||
<Button | |||
android:id="@+id/btn_broadcast_scale" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="广播秤" | |||
/> | |||
<Button | |||
android:id="@+id/btn_broadcast_blood_oxygen" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="血氧仪" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_margin="10dp" | |||
android:layout_height="wrap_content"> | |||
@@ -84,15 +121,23 @@ | |||
android:layout_height="wrap_content" | |||
android:text="WiFi+Ble体脂秤" | |||
/> | |||
<Button | |||
android:id="@+id/btn_ble_weight" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Ble体脂秤" | |||
/> | |||
<Button | |||
android:id="@+id/btn_bloodglucose" | |||
android:id="@+id/btn_wifi_ble_tooth" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="血糖仪" | |||
android:text="牙刷(wifi+ble)" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_margin="10dp" | |||
@@ -105,6 +150,79 @@ | |||
android:text="Ble通用设置" | |||
/> | |||
<Button | |||
android:id="@+id/btn_ble_test" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="BleTest" | |||
/> | |||
<Button | |||
android:id="@+id/btnConnectTest" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="BleConnectTest" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_margin="10dp"> | |||
<Button | |||
android:id="@+id/wifi_config" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="WIFI设备(配置wifi)" | |||
/> | |||
<Button | |||
android:id="@+id/eight_scale" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="八极秤" | |||
/> | |||
<Button | |||
android:id="@+id/glucometer" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="血糖仪" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_margin="10dp" | |||
> | |||
<Button | |||
android:id="@+id/btn_ota" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="OTA通用" | |||
/> | |||
<Button | |||
android:id="@+id/btn_wristband" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="手环" | |||
/> | |||
<Button | |||
android:id="@+id/btn_transmission" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="透传" | |||
/> | |||
</LinearLayout> |
@@ -0,0 +1,85 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical"> | |||
<ScrollView | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="0.5"> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="vertical"> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/clear" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="@string/clear" | |||
android:textAllCaps="false" /> | |||
<Button | |||
android:id="@+id/get_version" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="获取版本" | |||
android:textAllCaps="false" /> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp"> | |||
<Button | |||
android:id="@+id/set_status" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="获取状态" | |||
android:textAllCaps="false" /> | |||
<Button | |||
android:id="@+id/set_filter" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="更换滤网" | |||
android:textAllCaps="false" /> | |||
<Button | |||
android:id="@+id/set_fan" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="风扇控制" | |||
android:textAllCaps="false" /> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</ScrollView> | |||
<ListView | |||
android:id="@+id/listview" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
android:padding="10dp" | |||
android:stackFromBottom="true" | |||
android:transcriptMode="alwaysScroll"> | |||
</ListView> | |||
</LinearLayout> |
@@ -0,0 +1,182 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical"> | |||
<ScrollView | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="vertical" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:paddingStart="10dp" | |||
android:paddingEnd="10dp" | |||
> | |||
<EditText | |||
android:id="@+id/et_cmd" | |||
android:layout_width="180dp" | |||
android:layout_height="wrap_content" | |||
android:hint="透传数据" | |||
android:text="4" | |||
/> | |||
<Button | |||
android:id="@+id/btn1" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="发送" | |||
/> | |||
<Button | |||
android:id="@+id/btn_stop" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="停止" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:paddingStart="10dp" | |||
android:paddingEnd="10dp" | |||
> | |||
<EditText | |||
android:id="@+id/et_uuid" | |||
android:layout_width="180dp" | |||
android:layout_height="wrap_content" | |||
android:hint="uuid" | |||
android:text="0000FFE1" | |||
android:lines="1" | |||
/> | |||
<Button | |||
android:id="@+id/btn_uuid" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="特征设置" | |||
/> | |||
</LinearLayout> <LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:paddingStart="10dp" | |||
android:paddingEnd="10dp" | |||
> | |||
<EditText | |||
android:id="@+id/et_uuid_server" | |||
android:layout_width="180dp" | |||
android:layout_height="wrap_content" | |||
android:hint="uuid_server" | |||
android:text="0000FFE0" | |||
android:maxLines="1" | |||
/> | |||
<Button | |||
android:id="@+id/btn_uuid_server" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="服务设置" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:paddingStart="10dp" | |||
android:paddingEnd="10dp" | |||
> | |||
<EditText | |||
android:id="@+id/et_notify" | |||
android:layout_width="180dp" | |||
android:layout_height="wrap_content" | |||
android:hint="uuid_notify" | |||
android:text="0000FFE2" | |||
android:maxLines="1" | |||
/> | |||
<Button | |||
android:id="@+id/btn_notify" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="Notify" | |||
/> | |||
<Button | |||
android:id="@+id/btn_notify_status" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="true" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:paddingStart="10dp" | |||
android:paddingEnd="10dp" | |||
> | |||
<EditText | |||
android:id="@+id/et_time" | |||
android:layout_width="100dp" | |||
android:layout_height="wrap_content" | |||
android:hint="发送间隔" | |||
android:text="1000" | |||
android:maxLines="1" | |||
/> | |||
<Button | |||
android:id="@+id/btn_time" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="设置" | |||
/> | |||
<Button | |||
android:id="@+id/clear" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="清空" | |||
/> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</ScrollView> | |||
<ListView | |||
android:id="@+id/listview" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
android:padding="10dp" | |||
android:stackFromBottom="true" | |||
android:transcriptMode="alwaysScroll" | |||
> | |||
</ListView> | |||
</LinearLayout> |
@@ -0,0 +1,86 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical"> | |||
<ScrollView | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="vertical" | |||
android:padding="10dp" | |||
> | |||
<TextView | |||
android:id="@+id/tv_version" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="版本号:" | |||
android:textSize="18dp" | |||
/> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_marginTop="5dp" | |||
> | |||
<Button | |||
android:id="@+id/btn_ota_connect" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="连接" | |||
/> | |||
<Button | |||
android:id="@+id/btn_ota_dis" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="断开" | |||
/> | |||
<Button | |||
android:id="@+id/btn_ota_file" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="选择文件" | |||
/> | |||
<Button | |||
android:id="@+id/btn_ota_start" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="OTA" | |||
/> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</ScrollView> | |||
<ListView | |||
android:id="@+id/listview" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
android:padding="10dp" | |||
android:stackFromBottom="true" | |||
android:transcriptMode="alwaysScroll" | |||
> | |||
</ListView> | |||
</LinearLayout> |
@@ -0,0 +1,121 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<RelativeLayout | |||
xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical"> | |||
<Button | |||
android:id="@+id/wifistatus" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="查看wifi状态" /> | |||
<Button | |||
android:id="@+id/scan_wifi" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_marginStart="12dp" | |||
android:layout_toEndOf="@+id/wifistatus" | |||
android:text="搜索wifi热点" /> | |||
<Button | |||
android:id="@+id/sn" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_below="@+id/scan_wifi" | |||
android:layout_marginTop="8dp" | |||
android:text="查看设备id" /> | |||
<EditText | |||
android:id="@+id/select_wifi_et" | |||
android:layout_width="90dp" | |||
android:layout_height="wrap_content" | |||
android:layout_marginStart="22dp" | |||
android:layout_toEndOf="@+id/scan_wifi" | |||
android:hint="选择wifi序号" | |||
android:inputType="number" | |||
android:textSize="14dp" /> | |||
<Button | |||
android:id="@+id/connect_wifi" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_below="@+id/select_wifi_et" | |||
android:layout_marginStart="13dp" | |||
android:layout_marginTop="11dp" | |||
android:layout_toEndOf="@+id/disconnect" | |||
android:text="发起连接" /> | |||
<Button | |||
android:id="@+id/disconnect" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_below="@+id/scan_wifi" | |||
android:layout_marginStart="9dp" | |||
android:layout_marginTop="5dp" | |||
android:layout_toEndOf="@+id/sn" | |||
android:text="断开连接" /> | |||
<Button | |||
android:id="@+id/default_try_out" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_below="@+id/sn" | |||
android:layout_marginTop="5dp" | |||
android:text="试用" /> | |||
<Button | |||
android:id="@+id/default_mode" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_below="@+id/sn" | |||
android:layout_toEndOf="@id/default_try_out" | |||
android:layout_marginStart="9dp" | |||
android:layout_marginTop="5dp" | |||
android:text="默认档位" /> | |||
<EditText | |||
android:id="@+id/select_gears_et" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_alignTop="@id/default_mode" | |||
android:layout_toEndOf="@id/default_mode" | |||
android:hint="时长(s),档位,档位级别" | |||
android:textSize="14dp" /> | |||
<Button | |||
android:id="@+id/setedname" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_below="@+id/default_mode" | |||
android:layout_marginTop="5dp" | |||
android:text="获取wifi名称" /> | |||
<Button | |||
android:id="@+id/support_unit" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_toEndOf="@id/setedname" | |||
android:layout_below="@+id/default_mode" | |||
android:layout_marginTop="5dp" | |||
android:text="获取支持档位" /> | |||
<Button | |||
android:id="@+id/default_time_mode" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_toEndOf="@id/support_unit" | |||
android:layout_below="@+id/default_mode" | |||
android:layout_marginTop="5dp" | |||
android:text="获取时长和档位" /> | |||
<ListView | |||
android:id="@+id/log_list" | |||
android:layout_marginTop="10dp" | |||
android:layout_below="@id/setedname" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent"> | |||
</ListView> | |||
</RelativeLayout> |
@@ -0,0 +1,52 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:orientation="vertical" android:layout_width="match_parent" | |||
android:layout_height="match_parent"> | |||
<EditText | |||
android:id="@+id/et" | |||
android:hint="输入payload数据" | |||
android:digits="0123456789ABCDEFabcdef" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content"/> | |||
<LinearLayout | |||
android:orientation="horizontal" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content"> | |||
<EditText | |||
android:id="@+id/et_cid" | |||
android:digits="0123456789ABCDEFabcdef" | |||
android:layout_width="120dp" | |||
android:hint="填入cid 16进制数" | |||
android:layout_height="wrap_content"/> | |||
<Button | |||
android:id="@+id/send" | |||
android:text="发送" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content"/> | |||
<Button | |||
android:id="@+id/bt_clear" | |||
android:text="清空" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content"/> | |||
<Button | |||
android:id="@+id/bt_clear_log" | |||
android:text="清空log" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content"/> | |||
</LinearLayout> | |||
<Button | |||
android:id="@+id/bt_cid" | |||
android:text="读cid" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content"/> | |||
<ListView | |||
android:id="@+id/listview" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent"/> | |||
</LinearLayout> |
@@ -0,0 +1,111 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<RelativeLayout | |||
xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical"> | |||
<ListView | |||
android:id="@+id/user_list" | |||
android:layout_width="match_parent" | |||
android:layout_height="150dp"> | |||
</ListView> | |||
<Button | |||
android:layout_marginTop="20dp" | |||
android:layout_below="@id/user_list" | |||
android:id="@+id/history" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="请求历史记录"/> | |||
<Button | |||
android:layout_marginTop="20dp" | |||
android:layout_below="@id/user_list" | |||
android:id="@+id/userlist" | |||
android:layout_toRightOf="@id/history" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="同步用户列表"/> | |||
<Button | |||
android:layout_marginTop="20dp" | |||
android:layout_below="@id/user_list" | |||
android:id="@+id/adduser" | |||
android:layout_toRightOf="@id/userlist" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="添加用户"/> | |||
<Button | |||
android:layout_below="@id/history" | |||
android:id="@+id/user" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="同步单个用户"/> | |||
<EditText | |||
android:id="@+id/edit_Userid" | |||
android:layout_toRightOf="@id/user" | |||
android:layout_below="@id/history" | |||
android:layout_width="100dp" | |||
android:hint="输入用户id" | |||
android:padding="10dp" | |||
android:inputType="number" | |||
android:digits="12345678" | |||
android:layout_height="60dp" /> | |||
<Button | |||
android:layout_below="@id/history" | |||
android:id="@+id/syntime" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_toRightOf="@id/edit_Userid" | |||
android:text="同步时间"/> | |||
<RadioGroup | |||
android:id="@+id/unit" | |||
android:layout_below="@+id/edit_Userid" | |||
android:layout_width="match_parent" | |||
android:orientation="horizontal" | |||
android:layout_height="wrap_content"> | |||
<RadioButton | |||
android:id="@+id/kg" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:text="kg"/> | |||
<RadioButton | |||
android:id="@+id/jin" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:text="斤"/> | |||
<RadioButton | |||
android:id="@+id/st_lb" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:text="st:lb"/> | |||
<RadioButton | |||
android:id="@+id/lb" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:text="lb"/> | |||
</RadioGroup> | |||
<ListView | |||
android:id="@+id/log_list" | |||
android:layout_marginTop="20dp" | |||
android:layout_below="@id/unit" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent"> | |||
</ListView> | |||
</RelativeLayout> |
@@ -0,0 +1,210 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:orientation="vertical" android:layout_width="match_parent" | |||
android:layout_height="match_parent"> | |||
<LinearLayout | |||
android:orientation="horizontal" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:gravity="right" | |||
android:weightSum="1"> | |||
<CheckedTextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="SSID :" | |||
android:id="@+id/checkedTextView" | |||
android:checked="false" /> | |||
<EditText | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:ems="10" | |||
android:id="@+id/ssid" | |||
android:inputType="text" /> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:orientation="horizontal" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:gravity="right" | |||
android:weightSum="1" > | |||
<CheckedTextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="PASSWORD:" | |||
android:id="@+id/checkedTextView2" | |||
android:checked="false" /> | |||
<EditText | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:ems="10" | |||
android:id="@+id/password" | |||
android:inputType="text" /> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:orientation="horizontal" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:gravity="right" | |||
android:weightSum="1" > | |||
<CheckedTextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="KEY:" | |||
android:id="@+id/checkedTextView3" | |||
android:checked="false" /> | |||
<EditText | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:ems="10" | |||
android:id="@+id/key" | |||
android:inputType="text" /> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:orientation="horizontal" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:gravity="right" | |||
android:weightSum="1" > | |||
<CheckedTextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="SN:" | |||
android:id="@+id/checkedTextView4" | |||
android:checked="false" /> | |||
<EditText | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:ems="10" | |||
android:id="@+id/sn" | |||
android:inputType="text" /> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:orientation="horizontal" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:gravity="right" | |||
android:weightSum="1" > | |||
<CheckedTextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="设备名:" | |||
android:id="@+id/checkedTextView5" | |||
android:checked="false" /> | |||
<EditText | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:ems="10" | |||
android:id="@+id/device_name" | |||
android:inputType="text" /> | |||
</LinearLayout> | |||
<LinearLayout android:orientation="horizontal" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content"> | |||
<Button | |||
android:id="@+id/btn_connect" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="开始配网" | |||
/> | |||
<Button android:id="@+id/btn_login" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="登录" /> | |||
<Button | |||
android:id="@+id/deviceid" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="获取设备id" | |||
/> | |||
<Button | |||
android:id="@+id/weight_result" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="获取体重数据" | |||
/> | |||
</LinearLayout> | |||
<LinearLayout android:orientation="horizontal" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content"> | |||
<Button | |||
android:id="@+id/clear_log" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="清除log" | |||
/> | |||
<Button | |||
android:id="@+id/clear_record" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="删除这条记录" | |||
/> | |||
<Button | |||
android:id="@+id/get_record" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="获取测试数据" | |||
/> | |||
</LinearLayout> | |||
<RadioGroup | |||
android:id="@+id/unit" | |||
android:layout_below="@+id/edit_Userid" | |||
android:layout_width="match_parent" | |||
android:orientation="horizontal" | |||
android:layout_height="wrap_content"> | |||
<RadioButton | |||
android:id="@+id/kg" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:text="kg"/> | |||
<RadioButton | |||
android:id="@+id/jin" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:text="斤"/> | |||
<RadioButton | |||
android:id="@+id/st_lb" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:text="st:lb"/> | |||
<RadioButton | |||
android:id="@+id/lb" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:text="lb"/> | |||
</RadioGroup> | |||
<ListView | |||
android:id="@+id/log_list" | |||
android:layout_marginTop="20dp" | |||
android:layout_below="@id/unit" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent"> | |||
</ListView> | |||
</LinearLayout> |
@@ -0,0 +1,78 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="wrap_content" | |||
android:layout_height="match_parent" | |||
android:background="@android:color/white" | |||
android:orientation="vertical"> | |||
<TextView | |||
android:id="@+id/tv_hint_data_title" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_margin="10dp" | |||
android:text="确定移除家人?" | |||
android:padding="10dp" | |||
android:gravity="center" | |||
android:textColor="@android:color/black" | |||
android:textSize="18dp" | |||
/> | |||
<TextView | |||
android:id="@+id/tv_hint_data_context" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_margin="15dp" | |||
android:text="移除后所有数据清空" | |||
android:padding="8dp" | |||
android:gravity="center_vertical" | |||
android:textSize="18dp" | |||
/> | |||
<View | |||
android:layout_width="match_parent" | |||
android:layout_height="1dp" | |||
android:layout_marginTop="15dp" | |||
android:background="@android:color/black" | |||
/> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal" | |||
> | |||
<TextView | |||
android:id="@+id/tv_hint_data_cancel" | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:gravity="center" | |||
android:padding="10dp" | |||
android:text="取消" | |||
android:textSize="18dp" | |||
/> | |||
<View | |||
android:id="@+id/view_cancel_line" | |||
android:layout_width="1dp" | |||
android:layout_height="match_parent" | |||
android:background="@android:color/black" | |||
/> | |||
<TextView | |||
android:id="@+id/tv_hint_data_ok" | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:gravity="center" | |||
android:padding="10dp" | |||
android:text="ok" | |||
android:textSize="18dp" | |||
/> | |||
</LinearLayout> | |||
</LinearLayout> |
@@ -0,0 +1,43 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
xmlns:app="http://schemas.android.com/apk/res-auto" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:background="@drawable/bg_btn_white_dialog" | |||
android:orientation="vertical"> | |||
<TextView | |||
android:id="@+id/tv_dialog_list_data_title" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:gravity="center" | |||
android:padding="10dp" | |||
android:text="请选择" | |||
android:textColor="@android:color/black" | |||
android:textSize="16dp"/> | |||
<androidx.recyclerview.widget.RecyclerView | |||
android:id="@+id/rv_dialog_list" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:overScrollMode="never" | |||
android:scrollbars="none"/> | |||
<View | |||
android:layout_width="match_parent" | |||
android:layout_height="1px" | |||
android:background="@android:color/black"/> | |||
<TextView | |||
android:id="@+id/tv_dialog_photo_cancel" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:gravity="center" | |||
android:padding="10dp" | |||
android:text="取消" | |||
android:textColor="@android:color/black" | |||
/> | |||
</LinearLayout> |
@@ -0,0 +1,21 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="50dp" | |||
android:background="@android:color/white" | |||
android:gravity="center"> | |||
<TextView | |||
android:id="@+id/tv_dialog_list_data" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp" | |||
android:text="永久" | |||
android:textColor="@android:color/black" | |||
android:textSize="16dp" | |||
/> | |||
</LinearLayout> |
@@ -0,0 +1,195 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:background="#ffffff" | |||
android:orientation="vertical"> | |||
<TextView | |||
android:id="@+id/id" | |||
android:layout_width="match_parent" | |||
android:layout_height="60dp" | |||
android:padding="10dp" | |||
android:gravity="center" | |||
android:textSize="15dp" /> | |||
<TextView | |||
android:id="@+id/sex" | |||
android:layout_width="wrap_content" | |||
android:layout_height="40dp" | |||
android:layout_below="@id/id" | |||
android:padding="5dp" | |||
android:text="sex:" | |||
android:textSize="15dp" /> | |||
<RadioGroup | |||
android:id="@+id/sexrg" | |||
android:layout_width="wrap_content" | |||
android:layout_height="40dp" | |||
android:layout_below="@id/id" | |||
android:layout_toRightOf="@id/sex" | |||
android:orientation="horizontal" | |||
android:padding="5dp"> | |||
<RadioButton | |||
android:id="@+id/man" | |||
android:textColor="#000000" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="男" /> | |||
<RadioButton | |||
android:id="@+id/female" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:textColor="#000000" | |||
android:text="女" /> | |||
</RadioGroup> | |||
<TextView | |||
android:id="@+id/mode" | |||
android:layout_width="wrap_content" | |||
android:layout_height="40dp" | |||
android:layout_below="@id/sex" | |||
android:padding="5dp" | |||
android:text="模式:" | |||
android:textSize="15dp" /> | |||
<RadioGroup | |||
android:id="@+id/moderg" | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:layout_below="@id/sex" | |||
android:layout_toRightOf="@id/sex" | |||
android:orientation="horizontal" | |||
android:padding="5dp"> | |||
<RadioButton | |||
android:id="@+id/ordinary" | |||
android:textColor="#000000" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="普通人" /> | |||
<RadioButton | |||
android:id="@+id/athlete" | |||
android:layout_width="wrap_content" | |||
android:textColor="#000000" | |||
android:layout_height="wrap_content" | |||
android:text="运动员" /> | |||
<RadioButton | |||
android:id="@+id/pregnant" | |||
android:textColor="#000000" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="孕妇" /> | |||
</RadioGroup> | |||
<TextView | |||
android:id="@+id/age" | |||
android:layout_width="wrap_content" | |||
android:layout_height="40dp" | |||
android:layout_below="@id/mode" | |||
android:padding="5dp" | |||
android:text="年龄:" | |||
android:textSize="15dp" /> | |||
<SeekBar | |||
android:id="@+id/agesb" | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:layout_below="@id/mode" | |||
android:layout_toRightOf="@id/age" | |||
android:max="100" | |||
android:min="5" /> | |||
<TextView | |||
android:id="@+id/height" | |||
android:layout_width="wrap_content" | |||
android:layout_height="40dp" | |||
android:layout_below="@id/age" | |||
android:padding="5dp" | |||
android:text="身高:" | |||
android:textSize="15dp" /> | |||
<SeekBar | |||
android:id="@+id/heightsb" | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:layout_below="@id/age" | |||
android:layout_toRightOf="@id/height" | |||
android:max="250" | |||
android:min="0" /> | |||
<TextView | |||
android:id="@+id/weight" | |||
android:layout_width="wrap_content" | |||
android:layout_height="40dp" | |||
android:layout_below="@id/height" | |||
android:padding="5dp" | |||
android:text="体重:" | |||
android:textSize="15dp" /> | |||
<SeekBar | |||
android:id="@+id/weightsb" | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:layout_below="@id/height" | |||
android:layout_toRightOf="@id/weight" | |||
android:max="200" | |||
android:min="5" /> | |||
<TextView | |||
android:id="@+id/adc" | |||
android:layout_width="wrap_content" | |||
android:layout_height="40dp" | |||
android:layout_below="@id/weight" | |||
android:padding="5dp" | |||
android:text="阻抗:" | |||
android:textSize="15dp" /> | |||
<SeekBar | |||
android:id="@+id/adcsb" | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:layout_below="@id/weight" | |||
android:layout_toRightOf="@id/weight" | |||
android:max="1000" | |||
android:min="0" /> | |||
<TextView | |||
android:layout_below="@id/adcsb" | |||
android:id="@+id/tv_move_data_ok" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_marginEnd="25dp" | |||
android:layout_marginStart="25dp" | |||
android:layout_marginTop="40dp" | |||
android:background="#2878ce" | |||
android:gravity="center" | |||
android:padding="10dp" | |||
android:text="确认" | |||
android:textColor="#ffffff" | |||
android:textSize="18dp" | |||
/> | |||
<TextView | |||
android:layout_below="@id/tv_move_data_ok" | |||
android:id="@+id/tv_move_data_cancel" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_marginEnd="25dp" | |||
android:layout_marginStart="25dp" | |||
android:layout_marginTop="10dp" | |||
android:gravity="center" | |||
android:padding="10dp" | |||
android:text="取消" | |||
android:textSize="15dp" | |||
/> | |||
</RelativeLayout> |
@@ -3,4 +3,5 @@ | |||
<color name="colorPrimary">#008577</color> | |||
<color name="colorPrimaryDark">#00574B</color> | |||
<color name="colorAccent">#D81B60</color> | |||
<color name="public_white">#FFFFFF</color> | |||
</resources> |
@@ -8,7 +8,7 @@ buildscript { | |||
} | |||
dependencies { | |||
classpath 'com.android.tools.build:gradle:3.4.0' | |||
classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.0' | |||
// NOTE: Do not place your application dependencies here; they belong | |||
// in the individual module build.gradle files | |||
} |