Skip to content

Commit 6f58109

Browse files
committed
Fixed for SimpleControls example.
1 parent e4731c6 commit 6f58109

30 files changed

+42
-6
lines changed

Examples/SimpleControls/AndroidManifest.xml

100644100755
File mode changed.

Examples/SimpleControls/ic_launcher-web.png

100644100755
File mode changed.

Examples/SimpleControls/libs/android-support-v4.jar

100644100755
File mode changed.

Examples/SimpleControls/proguard-project.txt

100644100755
File mode changed.

Examples/SimpleControls/project.properties

100644100755
File mode changed.

Examples/SimpleControls/res/drawable-hdpi/ic_launcher.png

100644100755
File mode changed.

Examples/SimpleControls/res/drawable-hdpi/splash.jpg

100644100755
File mode changed.

Examples/SimpleControls/res/drawable-mdpi/ic_launcher.png

100644100755
File mode changed.

Examples/SimpleControls/res/drawable-xhdpi/ic_launcher.png

100644100755
File mode changed.

Examples/SimpleControls/res/drawable-xxhdpi/ic_launcher.png

100644100755
File mode changed.

Examples/SimpleControls/res/drawable/btn_toggle.xml

100644100755
File mode changed.

Examples/SimpleControls/res/drawable/btn_toggle_bg.xml

100644100755
File mode changed.

Examples/SimpleControls/res/drawable/btn_toggle_no.png

100644100755
File mode changed.

Examples/SimpleControls/res/drawable/btn_toggle_yes.png

100644100755
File mode changed.

Examples/SimpleControls/res/drawable/red_button.xml

100644100755
File mode changed.

Examples/SimpleControls/res/drawable/redbear.png

100644100755
File mode changed.

Examples/SimpleControls/res/drawable/seekbar_style.xml

100644100755
File mode changed.

Examples/SimpleControls/res/layout/main.xml

100644100755
File mode changed.

Examples/SimpleControls/res/layout/title.xml

100644100755
File mode changed.

Examples/SimpleControls/res/menu/simple_controls.xml

100644100755
File mode changed.

Examples/SimpleControls/res/values-sw600dp/dimens.xml

100644100755
File mode changed.

Examples/SimpleControls/res/values-sw720dp-land/dimens.xml

100644100755
File mode changed.

Examples/SimpleControls/res/values-v11/styles.xml

100644100755
File mode changed.

Examples/SimpleControls/res/values-v14/styles.xml

100644100755
File mode changed.

Examples/SimpleControls/res/values/dimens.xml

100644100755
File mode changed.

Examples/SimpleControls/res/values/strings.xml

100644100755
File mode changed.

Examples/SimpleControls/res/values/styles.xml

100644100755
File mode changed.

Examples/SimpleControls/src/com/redbear/simplecontrols/RBLGattAttributes.java

100644100755
File mode changed.

Examples/SimpleControls/src/com/redbear/simplecontrols/RBLService.java

100644100755
File mode changed.

Examples/SimpleControls/src/com/redbear/simplecontrols/SimpleControls.java

100644100755
+42-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.redbear.simplecontrols;
22

3+
import java.util.Locale;
34
import java.util.Timer;
45
import java.util.TimerTask;
56

@@ -55,6 +56,9 @@ public class SimpleControls extends Activity {
5556
private static final int REQUEST_ENABLE_BT = 1;
5657
private static final long SCAN_PERIOD = 2000;
5758

59+
final private static char[] hexArray = { '0', '1', '2', '3', '4', '5', '6',
60+
'7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
61+
5862
private final ServiceConnection mServiceConnection = new ServiceConnection() {
5963

6064
@Override
@@ -395,21 +399,53 @@ public void run() {
395399

396400
@Override
397401
public void onLeScan(final BluetoothDevice device, final int rssi,
398-
byte[] scanRecord) {
402+
final byte[] scanRecord) {
403+
399404
runOnUiThread(new Runnable() {
400405
@Override
401406
public void run() {
402-
if (device != null) {
403-
if (device.getName().contains("Shield")
404-
|| device.getName().contains("Biscuit")) {
405-
mDevice = device;
406-
}
407+
byte[] serviceUuidBytes = new byte[16];
408+
String serviceUuid = "";
409+
for (int i = 32, j = 0; i >= 17; i--, j++) {
410+
serviceUuidBytes[j] = scanRecord[i];
411+
}
412+
serviceUuid = bytesToHex(serviceUuidBytes);
413+
if (stringToUuidString(serviceUuid).equals(
414+
RBLGattAttributes.BLE_SHIELD_SERVICE
415+
.toUpperCase(Locale.ENGLISH))) {
416+
mDevice = device;
407417
}
408418
}
409419
});
410420
}
411421
};
412422

423+
private String bytesToHex(byte[] bytes) {
424+
char[] hexChars = new char[bytes.length * 2];
425+
int v;
426+
for (int j = 0; j < bytes.length; j++) {
427+
v = bytes[j] & 0xFF;
428+
hexChars[j * 2] = hexArray[v >>> 4];
429+
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
430+
}
431+
return new String(hexChars);
432+
}
433+
434+
private String stringToUuidString(String uuid) {
435+
StringBuffer newString = new StringBuffer();
436+
newString.append(uuid.toUpperCase(Locale.ENGLISH).substring(0, 8));
437+
newString.append("-");
438+
newString.append(uuid.toUpperCase(Locale.ENGLISH).substring(8, 12));
439+
newString.append("-");
440+
newString.append(uuid.toUpperCase(Locale.ENGLISH).substring(12, 16));
441+
newString.append("-");
442+
newString.append(uuid.toUpperCase(Locale.ENGLISH).substring(16, 20));
443+
newString.append("-");
444+
newString.append(uuid.toUpperCase(Locale.ENGLISH).substring(20, 32));
445+
446+
return newString.toString();
447+
}
448+
413449
@Override
414450
protected void onStop() {
415451
super.onStop();

0 commit comments

Comments
 (0)