├── bluetoothlib ├── class_files.txt ├── mapping.txt ├── src │ └── main │ │ ├── res │ │ └── values │ │ │ └── strings.xml │ │ ├── java │ │ └── com │ │ │ └── clock │ │ │ └── bluetoothlib │ │ │ ├── Test1.java │ │ │ └── logic │ │ │ ├── network │ │ │ ├── connection │ │ │ │ ├── BLEScanDevice.java │ │ │ │ ├── DeviceState.java │ │ │ │ ├── BLEAppDevice.java │ │ │ │ ├── BLEState.java │ │ │ │ ├── BLEServerListener.java │ │ │ │ ├── BLEConnector.java │ │ │ │ ├── BLEBaseDevice.java │ │ │ │ ├── BLEDeviceBiz.java │ │ │ │ ├── BLEScanner.java │ │ │ │ ├── BLEServerCentral.java │ │ │ │ └── BLEBaseManager.java │ │ │ ├── DeviceInfoSyncListener.java │ │ │ ├── DeviceAuthorizeListener.java │ │ │ └── data │ │ │ │ ├── BLEPacket.java │ │ │ │ ├── DataParserAdapter.java │ │ │ │ ├── BLEAllDispatcher.java │ │ │ │ └── DataCircularBuffer.java │ │ │ ├── analysis │ │ │ ├── OnDataSendCallBack.java │ │ │ ├── OnRespDataListener.java │ │ │ ├── OnRespResultListener.java │ │ │ ├── NotifyCmdAdapter.java │ │ │ ├── ConstantTransfer.java │ │ │ ├── DecodeAdapter.java │ │ │ ├── CmdInterface.java │ │ │ ├── DataTransferManager.java │ │ │ ├── NotifyCmdLib.java │ │ │ ├── CmdBase.java │ │ │ ├── Decode.java │ │ │ └── RecvCallbackManager.java │ │ │ └── utils │ │ │ ├── ThreadPoolUtil.java │ │ │ └── LogUtil.java │ │ └── AndroidManifest.xml ├── build.gradle └── proguard-rules.pro ├── settings.gradle ├── app ├── libs │ └── eventbus-3.1.1.jar ├── src │ └── main │ │ ├── res │ │ ├── drawable-xhdpi │ │ │ └── loading.png │ │ ├── drawable-xxhdpi │ │ │ └── bledevice.png │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ ├── values │ │ │ ├── colors.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ ├── drawable │ │ │ ├── anim_rotate_load.xml │ │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ │ ├── popwindow_scan_list.xml │ │ │ ├── dialog_loading2.xml │ │ │ ├── item_list_scan.xml │ │ │ ├── activity_main.xml │ │ │ └── item_device_list_device.xml │ │ └── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ ├── java │ │ └── com │ │ │ └── clock │ │ │ └── blelib │ │ │ ├── adapter │ │ │ ├── OnItemClickListener.java │ │ │ ├── ScanListAdapter.java │ │ │ └── DeviceListAdapter.java │ │ │ ├── event │ │ │ ├── BleSendResultEvent.java │ │ │ ├── AddPreConnDeviceEvent.java │ │ │ ├── updateDeviceInfoEvent.java │ │ │ ├── AddNewDeviceEvent.java │ │ │ ├── ReconnectDeviceEvent.java │ │ │ ├── ConnectDeviceEvent.java │ │ │ └── AddScanDeviceEvent.java │ │ │ ├── bleissus │ │ │ ├── blemodel │ │ │ │ ├── heart │ │ │ │ │ ├── HeaterDataAdapter.java │ │ │ │ │ └── HeaterDevice.java │ │ │ │ ├── bracelet │ │ │ │ │ └── BraceletDevice.java │ │ │ │ ├── led │ │ │ │ │ ├── LedDataAdapter.java │ │ │ │ │ ├── BLELedNecessaryBiz.java │ │ │ │ │ └── LedDevice.java │ │ │ │ └── BLEManager.java │ │ │ └── ProtocolVh.java │ │ │ ├── util │ │ │ └── WidgetUitl.java │ │ │ ├── widget │ │ │ └── ScanListPopWindow.java │ │ │ ├── BaseActivity.java │ │ │ └── MainActivity.java │ │ └── AndroidManifest.xml ├── proguard-rules.pro └── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── local.properties ├── gradle.properties ├── README.md ├── gradlew.bat └── gradlew /bluetoothlib/class_files.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bluetoothlib/mapping.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':bluetoothlib' 2 | -------------------------------------------------------------------------------- /app/libs/eventbus-3.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruigeyun/Android-DualBle/HEAD/app/libs/eventbus-3.1.1.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruigeyun/Android-DualBle/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /bluetoothlib/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | BluetoothLib 3 | 4 | -------------------------------------------------------------------------------- /bluetoothlib/src/main/java/com/clock/bluetoothlib/Test1.java: -------------------------------------------------------------------------------- 1 | package com.clock.bluetoothlib; 2 | 3 | public class Test1 { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/loading.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruigeyun/Android-DualBle/HEAD/app/src/main/res/drawable-xhdpi/loading.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/bledevice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruigeyun/Android-DualBle/HEAD/app/src/main/res/drawable-xxhdpi/bledevice.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruigeyun/Android-DualBle/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | DualBle 3 | 4 | Please turn on bluetooth first 5 | Device connect max number 7! 6 | 7 | 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Jul 29 15:48:13 CST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/anim_rotate_load.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /bluetoothlib/src/main/java/com/clock/bluetoothlib/logic/network/connection/BLEScanDevice.java: -------------------------------------------------------------------------------- 1 | package com.clock.bluetoothlib.logic.network.connection; 2 | 3 | import android.bluetooth.BluetoothDevice; 4 | 5 | public class BLEScanDevice { 6 | BluetoothDevice scanBle; 7 | int deviceType; 8 | 9 | BLEScanDevice(BluetoothDevice scanBle, int deviceType) { 10 | this.scanBle = scanBle; 11 | this.deviceType = deviceType; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /local.properties: -------------------------------------------------------------------------------- 1 | ## This file is automatically generated by Android Studio. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file should *NOT* be checked into Version Control Systems, 5 | # as it contains information specific to your local configuration. 6 | # 7 | # Location of the SDK. This is only used by Gradle. 8 | # For customization when using a Version Control System, please read the 9 | # header note. 10 | sdk.dir=D\:\\software\\android\\sdk 11 | -------------------------------------------------------------------------------- /bluetoothlib/src/main/java/com/clock/bluetoothlib/logic/analysis/OnDataSendCallBack.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.bluetoothlib.logic.analysis; 7 | 8 | public interface OnDataSendCallBack { 9 | 10 | public void onSendData(byte[] values, int deviceId); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /bluetoothlib/src/main/java/com/clock/bluetoothlib/logic/analysis/OnRespDataListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.bluetoothlib.logic.analysis; 7 | 8 | /** 9 | * 数据发送后,回应的数据 10 | * @param 11 | */ 12 | public interface OnRespDataListener { 13 | void onResponse(T resultSrc); 14 | } 15 | -------------------------------------------------------------------------------- /bluetoothlib/src/main/java/com/clock/bluetoothlib/logic/analysis/OnRespResultListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.bluetoothlib.logic.analysis; 7 | 8 | /** 9 | * 数据请求后,回应的最终结果 10 | */ 11 | public interface OnRespResultListener { 12 | void onSuccess(int code); 13 | void onFailure(int code); 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/clock/blelib/adapter/OnItemClickListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.blelib.adapter; 7 | 8 | 9 | /** 10 | * Created by ysh_leo on 2018/3/5. 11 | */ 12 | 13 | public interface OnItemClickListener { 14 | void onItemClick(int position); 15 | void onItemLongClick(int position); 16 | } -------------------------------------------------------------------------------- /bluetoothlib/src/main/java/com/clock/bluetoothlib/logic/analysis/NotifyCmdAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.bluetoothlib.logic.analysis; 7 | 8 | import java.util.HashMap; 9 | 10 | public abstract class NotifyCmdAdapter { 11 | 12 | public abstract void getNotifyCmds(HashMap cmdLib); 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/clock/blelib/event/BleSendResultEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.blelib.event; 7 | 8 | /** 9 | * 发送结果 10 | */ 11 | public class BleSendResultEvent { 12 | 13 | public String result; 14 | 15 | public BleSendResultEvent(String result) { 16 | this.result = result; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /bluetoothlib/src/main/java/com/clock/bluetoothlib/logic/network/DeviceInfoSyncListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.bluetoothlib.logic.network; 7 | 8 | public interface DeviceInfoSyncListener { 9 | 10 | /** 11 | * 同步结束后,调用此接口,设备进入正式使用状态 12 | * @param type 目前没有意义 13 | */ 14 | public void onInfoSync(int type); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /bluetoothlib/src/main/java/com/clock/bluetoothlib/logic/network/DeviceAuthorizeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.bluetoothlib.logic.network; 7 | 8 | public interface DeviceAuthorizeListener { 9 | /** 10 | * 校验通过,继续往下走,校验失败,删除设备 11 | * @param isAuthorize true 校验通过, false 校验失败 12 | */ 13 | public void onAuthorize(boolean isAuthorize); 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/clock/blelib/event/AddPreConnDeviceEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.blelib.event; 7 | 8 | 9 | import com.clock.bluetoothlib.logic.network.connection.BLEAppDevice; 10 | 11 | public class AddPreConnDeviceEvent { 12 | public BLEAppDevice device; 13 | 14 | public AddPreConnDeviceEvent(BLEAppDevice device) { 15 | this.device = device; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/clock/blelib/event/updateDeviceInfoEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.blelib.event; 7 | 8 | 9 | import com.clock.bluetoothlib.logic.network.connection.BLEAppDevice; 10 | 11 | public class updateDeviceInfoEvent { 12 | 13 | public BLEAppDevice device; 14 | 15 | public updateDeviceInfoEvent(BLEAppDevice device) { 16 | this.device = device; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/clock/blelib/event/AddNewDeviceEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.blelib.event; 7 | 8 | 9 | import com.clock.bluetoothlib.logic.network.connection.BLEAppDevice; 10 | 11 | /** 12 | * 连接上新设备,到设备列表中显示 13 | */ 14 | public class AddNewDeviceEvent { 15 | 16 | public BLEAppDevice device; 17 | 18 | public AddNewDeviceEvent(BLEAppDevice device) { 19 | this.device = device; 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /bluetoothlib/src/main/java/com/clock/bluetoothlib/logic/analysis/ConstantTransfer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.bluetoothlib.logic.analysis; 7 | 8 | public class ConstantTransfer { 9 | 10 | public static final int CODE_SUCCESS = 0; 11 | public static final int CODE_FAILURE = -1; 12 | public static final int CODE_EXCEPTION = -2; 13 | public static final int CODE_TIMEOUT = -3; 14 | public static final int CODE_DATA_NULL = -4; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /bluetoothlib/src/main/java/com/clock/bluetoothlib/logic/network/connection/DeviceState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.bluetoothlib.logic.network.connection; 7 | 8 | public enum DeviceState { 9 | 10 | Normal(0), // normal 状态的设备,才可以被连接 11 | Remove(1), // 被删除 12 | DisConnRelease(2);// 被断开,在释放资源状态,此状态下,不可以被连接 13 | 14 | // 成员变量 15 | private int index; 16 | // 构造方法 17 | private DeviceState(int index) { 18 | this.index = index; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/clock/blelib/event/ReconnectDeviceEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.blelib.event; 7 | 8 | 9 | import com.clock.bluetoothlib.logic.network.connection.BLEAppDevice; 10 | 11 | /** 12 | * 重连设备,分:自动连接,手动连接 13 | * 手动连接:指在设备列表的设备,被新设备顶下去了,再手动连接 14 | * 自动连接:设备蓝牙自爆异常,自动去连接,恢复状态 15 | */ 16 | public class ReconnectDeviceEvent { 17 | 18 | public BLEAppDevice device; 19 | 20 | public ReconnectDeviceEvent(BLEAppDevice device) { 21 | this.device = device; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/clock/blelib/event/ConnectDeviceEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.blelib.event; 7 | 8 | 9 | import com.clock.bluetoothlib.logic.network.connection.BLEAppDevice; 10 | 11 | /** 12 | * 连接扫描列表的设备,有些设备无法识别,则删除 13 | */ 14 | public class ConnectDeviceEvent { 15 | 16 | public BLEAppDevice device; 17 | public int type; // 连接反馈,无法识别的设备,删除 18 | 19 | public ConnectDeviceEvent(BLEAppDevice device, int type) { 20 | this.device = device; 21 | this.type = type; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | 15 | 16 | -------------------------------------------------------------------------------- /bluetoothlib/src/main/java/com/clock/bluetoothlib/logic/analysis/DecodeAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.bluetoothlib.logic.analysis; 7 | 8 | public abstract class DecodeAdapter { 9 | public DecodeAdapter() { 10 | } 11 | /** 12 | * 命令字节的位置 13 | * @return 14 | */ 15 | public abstract byte getIndexCmd(); 16 | /** 17 | * 校验码的位置 18 | * @return 19 | */ 20 | public abstract int getIndexCheckCode(); 21 | /** 22 | * 包标识 到 内容 间的距离,找到内容长的位置 23 | * @return 24 | */ 25 | public abstract int getDistMarkToContent(); 26 | } 27 | -------------------------------------------------------------------------------- /bluetoothlib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /bluetoothlib/src/main/java/com/clock/bluetoothlib/logic/analysis/CmdInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.bluetoothlib.logic.analysis; 7 | 8 | /** 9 | * 命令模式 10 | * @author clock 11 | * 12 | */ 13 | public interface CmdInterface { 14 | /** 15 | * 16 | * @param data 一包数据 17 | * @param index 命令的内容部分开始的位置 18 | * @param len 命令内容部分的长度 19 | * @return 20 | */ 21 | public int parseNotifyCmd(byte[] data, int index, int len, int deviceId); 22 | public int parseTransmitCmd(byte[] data, int index, int len); 23 | public int parseConfigCmd(byte[] data, int index, int len); 24 | public boolean packDataForSend(); 25 | } 26 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/popwindow_scan_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/layout/dialog_loading2.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 15 | 16 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/clock/blelib/event/AddScanDeviceEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.blelib.event; 7 | 8 | import android.bluetooth.BluetoothDevice; 9 | 10 | public class AddScanDeviceEvent { 11 | private BluetoothDevice bluetoothDevice; 12 | 13 | public AddScanDeviceEvent(BluetoothDevice bluetoothDevice) { 14 | this.bluetoothDevice = bluetoothDevice; 15 | } 16 | 17 | public BluetoothDevice getBluetoothDevice() { 18 | return bluetoothDevice; 19 | } 20 | 21 | public void setBluetoothDevice(BluetoothDevice bluetoothDevice) { 22 | this.bluetoothDevice = bluetoothDevice; 23 | } 24 | 25 | @Override 26 | public String toString() { 27 | final StringBuffer sb = new StringBuffer("ScanEvent{"); 28 | sb.append("bluetoothDevice=").append(bluetoothDevice); 29 | sb.append('}'); 30 | return sb.toString(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "com.clock.blelib" 7 | minSdkVersion 19 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(include: ['*.jar'], dir: 'libs') 23 | implementation 'com.android.support:appcompat-v7:28.0.0' 24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 25 | testImplementation 'junit:junit:4.12' 26 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 28 | 29 | implementation 'com.android.support:recyclerview-v7:28.0.0' 30 | implementation files('libs/eventbus-3.1.1.jar') 31 | implementation project(path: ':bluetoothlib') 32 | } 33 | -------------------------------------------------------------------------------- /bluetoothlib/src/main/java/com/clock/bluetoothlib/logic/network/connection/BLEAppDevice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.bluetoothlib.logic.network.connection; 7 | 8 | import android.bluetooth.BluetoothDevice; 9 | 10 | import com.clock.bluetoothlib.logic.network.data.DataParserAdapter; 11 | 12 | public abstract class BLEAppDevice extends BLELogicDevice { 13 | /** 14 | * 没有被扫描出来,但是之前连接过,需要显示在列表,这样的设备定义为虚拟设备,在界面手动连接虚拟设备,需启动扫描,扫描到再连接,非虚拟设备,不需要再启动扫描。 15 | * 虚拟设备连接成功后,将在列表中替换,所以这边变量没有清空处理 16 | */ 17 | public boolean isVirtualDevice = false; 18 | 19 | public BLEAppDevice() {} 20 | 21 | public BLEAppDevice(BluetoothDevice device, DataParserAdapter adapter){ 22 | super(adapter); 23 | } 24 | 25 | // @Override 26 | // public UUID getServiceUUID() { 27 | // return null; 28 | // } 29 | // 30 | // @Override 31 | // public UUID getRxUUID() { 32 | // return null; 33 | // } 34 | // 35 | // @Override 36 | // public UUID getTxUUID() { 37 | // return null; 38 | // } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /bluetoothlib/src/main/java/com/clock/bluetoothlib/logic/network/data/BLEPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.bluetoothlib.logic.network.data; 7 | 8 | public final class BLEPacket { 9 | 10 | /** 11 | * 数据 12 | */ 13 | public byte[] bleData; 14 | /** 15 | * ble id 标志不同的蓝牙设备,也就是设备的mDeviceId 16 | */ 17 | public int bleDeviceId; 18 | 19 | public BLEPacket(byte[] data, int id) { 20 | bleData = data; 21 | bleDeviceId = id; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | final StringBuffer sb = new StringBuffer("BLEPacket{"); 27 | sb.append("bleData="); 28 | if (bleData == null) sb.append("null"); 29 | else { 30 | sb.append('['); 31 | for (int i = 0; i < bleData.length; ++i) 32 | sb.append(i == 0 ? "" : ", ").append(bleData[i]); 33 | sb.append(']'); 34 | } 35 | sb.append(", bleAddr='").append(bleDeviceId).append('\''); 36 | sb.append('}'); 37 | return sb.toString(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/clock/blelib/bleissus/blemodel/heart/HeaterDataAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.blelib.bleissus.blemodel.heart; 7 | 8 | import com.clock.blelib.bleissus.ProtocolVh; 9 | import com.clock.bluetoothlib.logic.network.data.DataParserAdapter; 10 | 11 | public class HeaterDataAdapter extends DataParserAdapter { 12 | // aa 0a 07 00 14 00 00 00 00 00 13 | // 包标志 指令 内容长度 内容 14 | public HeaterDataAdapter() {} 15 | /** 16 | * 包标志 17 | * @return 18 | */ 19 | @Override 20 | public byte getPackageMark() { 21 | // aa 22 | return (byte) ProtocolVh.SYNC_FLAG_HEADER; 23 | } 24 | /** 25 | * 包数据中,除了包标识,包内容,的其他数据的总长度 26 | * @return 27 | */ 28 | @Override 29 | public int getExtraDataNum() { 30 | // 命令字(1字节) + 长度(1字节)0a 07 31 | return ProtocolVh.LED_EXTRA_DATA_CNT; 32 | } 33 | /** 34 | * 包标识 到 内容 间的距离,找到内容长的位置 35 | * @return 36 | */ 37 | @Override 38 | public int getDistMarkToContent() { 39 | // aa 0a 07 距离为2 40 | return ProtocolVh.DIST_FLAG_2_LEN; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /bluetoothlib/src/main/java/com/clock/bluetoothlib/logic/utils/ThreadPoolUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C), 2019. by [clock - Individual developer] ,All rights reserved. 3 | * The article is original, writing is also the strength to live, reference please indicate the source and author. 4 | */ 5 | 6 | package com.clock.bluetoothlib.logic.utils; 7 | 8 | import java.util.concurrent.ExecutorService; 9 | import java.util.concurrent.Executors; 10 | 11 | public final class ThreadPoolUtil { 12 | 13 | private ExecutorService mExecutorService; 14 | private static ThreadPoolUtil instance = new ThreadPoolUtil(); 15 | 16 | private ThreadPoolUtil() { 17 | // 线程池为无限大,当执行第二个任务时第一个任务已经完成,会复用执行第一个任务的线程,而不用每次新建线程。 18 | mExecutorService = Executors.newCachedThreadPool(); 19 | // // 创建一个定长线程池,可控制线程最大并发数,超出的线程会在队列中等待 20 | // ExecutorService fixedThreadPool = Executors.newFixedThreadPool(3); 21 | // // 创建一个定长线程池,支持定时及周期性任务执行 22 | // ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(5); 23 | // // 创建一个单线程化的线程池,它只会用唯一的工作线程来执行任务,保证所有任务按照指定顺序(FIFO, LIFO, 优先级)执行 24 | // ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(); 25 | } 26 | 27 | public static ThreadPoolUtil get() { 28 | return instance; 29 | } 30 | 31 | public ExecutorService getThread() { 32 | return mExecutorService; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_list_scan.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 16 | 17 | 29 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 |