Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7a4c888

Browse files
committed
1.Fix bugs and update sample
1 parent 01a9c9f commit 7a4c888

9 files changed

Lines changed: 20 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ allprojects {
1313
}
1414
1515
dependencies {
16-
implementation 'com.github.Ficat:EasyBle:v3.1.1'
16+
implementation 'com.github.Ficat:EasyBle:v3.1.2'
1717
}
1818
```
1919

doc/README_CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ allprojects {
1111
1212
1313
dependencies {
14-
implementation 'com.github.Ficat:EasyBle:v3.1.1'
14+
implementation 'com.github.Ficat:EasyBle:v3.1.2'
1515
}
1616
```
1717

easyble/src/main/java/com/ficat/easyble/gatt/BleGattCommunicator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public void run() {
156156
mGatt.close();
157157
}
158158
mConnState = DISCONNECTED;
159-
mConnectCallback.onConnectionFailed(BleErrorCodes.CONNECTION_TIMEOUT, mDevice);
159+
callback.onConnectionFailed(BleErrorCodes.CONNECTION_TIMEOUT, mDevice);
160160
clearAndResetAll();
161161
}
162162
});
@@ -177,11 +177,12 @@ void disconnect() {
177177
refreshDeviceCache();
178178
mGatt.close();
179179
mConnState = DISCONNECTED;
180+
BleConnectCallback callback = mConnectCallback;
180181
mHandler.post(new Runnable() {
181182
@Override
182183
public void run() {
183-
if (mConnectCallback != null) {
184-
mConnectCallback.onConnectionFailed(BleErrorCodes.CONNECTION_CANCELED, mDevice);
184+
if (callback != null) {
185+
callback.onConnectionFailed(BleErrorCodes.CONNECTION_CANCELED, mDevice);
185186
}
186187
}
187188
});

sample/src/main/java/com/ficat/sample/OperateActivity.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,17 @@ public void onClick(View v) {
226226
BleManager.getInstance().read(device, curService.getUuid(), curCharacteristic.getUuid(), readCallback);
227227
break;
228228
case R.id.tv_write:
229-
String str = etWrite.getText().toString();
229+
String str = etWrite.getText().toString().trim();
230230
if (TextUtils.isEmpty(str)) {
231231
Toast.makeText(this, getResources().getString(R.string.tips_write_operation),
232232
Toast.LENGTH_SHORT).show();
233233
return;
234234
}
235+
if (str.length() % 2 != 0) {
236+
Toast.makeText(this, getResources().getString(R.string.tips_write_operation_length_err),
237+
Toast.LENGTH_SHORT).show();
238+
return;
239+
}
235240
BleManager.getInstance().write(device, curService.getUuid(), curCharacteristic.getUuid(),
236241
ByteUtils.hexStr2Bytes(str), writeCallback);
237242
break;

sample/src/main/res/layout/activity_operate.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@
199199
android:layout_width="match_parent"
200200
android:layout_height="0dp"
201201
android:layout_weight="1"
202+
android:imeOptions="actionDone"
203+
android:maxLines="1"
204+
android:digits="0123456789ABCDEFabcdef"
205+
android:singleLine="true"
202206
android:gravity="center"
203207
android:hint="@string/tips_write_operate_input"
204208
android:paddingEnd="10dp"

sample/src/main/res/values-en-rGB/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<string name="tips_connection_canceled">connection canceled</string>
3939
<string name="tips_connection_disconnected">connection has disconnected</string>
4040
<string name="tips_write_operation">please enter a hex string</string>
41+
<string name="tips_write_operation_length_err">hex string length is not a multiple of 2</string>
4142
<string name="tips_not_support_ble">This device not support BLE</string>
4243
<string name="tips_user_reject_permissions">User rejected bluetooth permissions</string>
4344
<string name="tips_bluetooth_on">Bluetooth turned on</string>

sample/src/main/res/values-en-rUS/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<string name="tips_connection_canceled">connection canceled</string>
3939
<string name="tips_connection_disconnected">connection has disconnected</string>
4040
<string name="tips_write_operation">please enter a hex string</string>
41+
<string name="tips_write_operation_length_err">hex string length is not a multiple of 2</string>
4142
<string name="tips_not_support_ble">This device not support BLE</string>
4243
<string name="tips_user_reject_permissions">User rejected bluetooth permissions</string>
4344
<string name="tips_bluetooth_on">Bluetooth turned on</string>

sample/src/main/res/values-zh-rCN/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<string name="tips_connection_canceled">连接已取消</string>
3939
<string name="tips_connection_disconnected">连接已断开</string>
4040
<string name="tips_write_operation">请输入十六进制字符串命令</string>
41+
<string name="tips_write_operation_length_err">字符串个数非2的倍数</string>
4142
<string name="tips_not_support_ble">该设备不支持BLE</string>
4243
<string name="tips_user_reject_permissions">用户已拒绝蓝牙权限</string>
4344
<string name="tips_bluetooth_on">蓝牙已打开</string>

sample/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<string name="tips_connection_canceled">connection canceled</string>
3939
<string name="tips_connection_disconnected">connection has disconnected</string>
4040
<string name="tips_write_operation">please input a hex string</string>
41+
<string name="tips_write_operation_length_err">hex string length is not a multiple of 2</string>
4142
<string name="tips_not_support_ble">This device not support BLE</string>
4243
<string name="tips_user_reject_permissions">User rejected bluetooth permissions</string>
4344
<string name="tips_bluetooth_on">Bluetooth turned on</string>

0 commit comments

Comments
 (0)