Skip to content

Commit eae8e9c

Browse files
committed
Added Bluetooth Major Class resolver
1 parent ab6997b commit eae8e9c

5 files changed

Lines changed: 51 additions & 0 deletions

File tree

library/src/main/java/uk/co/alt236/bluetoothlelib/device/BluetoothLeDevice.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ public String getBluetoothDeviceClassName() {
212212
return BluetoothClassResolver.resolveDeviceClass(mDevice.getBluetoothClass().getDeviceClass());
213213
}
214214

215+
/**
216+
* Gets the bluetooth device major class name.
217+
*
218+
* @return the bluetooth device major class name
219+
*/
220+
public String getBluetoothDeviceMajorClassName() {
221+
return BluetoothClassResolver.resolveMajorDeviceClass(mDevice.getBluetoothClass().getMajorDeviceClass());
222+
}
223+
215224
/**
216225
* Gets the device.
217226
*

library/src/main/java/uk/co/alt236/bluetoothlelib/resolvers/BluetoothClassResolver.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,33 @@ public static String resolveDeviceClass(final int btClass) {
110110
return "Unknown, Unknown (class=" + btClass + ")";
111111
}
112112
}
113+
114+
public static String resolveMajorDeviceClass(final int majorBtClass) {
115+
switch (majorBtClass) {
116+
case BluetoothClass.Device.Major.AUDIO_VIDEO:
117+
return "Audio/ Video";
118+
case BluetoothClass.Device.Major.COMPUTER:
119+
return "Computer";
120+
case BluetoothClass.Device.Major.HEALTH:
121+
return "Health";
122+
case BluetoothClass.Device.Major.IMAGING:
123+
return "Imaging";
124+
case BluetoothClass.Device.Major.MISC:
125+
return "Misc";
126+
case BluetoothClass.Device.Major.NETWORKING:
127+
return "Networking";
128+
case BluetoothClass.Device.Major.PERIPHERAL:
129+
return "Peripheral";
130+
case BluetoothClass.Device.Major.PHONE:
131+
return "Phone";
132+
case BluetoothClass.Device.Major.TOY:
133+
return "Toy";
134+
case BluetoothClass.Device.Major.UNCATEGORIZED:
135+
return "Uncategorized";
136+
case BluetoothClass.Device.Major.WEARABLE:
137+
return "Wearable";
138+
default:
139+
return "Unknown (" +majorBtClass+ ")";
140+
}
141+
}
113142
}

sample_app/src/main/java/uk/co/alt236/btlescan/activities/DeviceDetailsActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ private void appendDeviceInfo(final MergeAdapter adapter, final BluetoothLeDevic
5555
final TextView tvName = (TextView) lt.findViewById(R.id.deviceName);
5656
final TextView tvAddress = (TextView) lt.findViewById(R.id.deviceAddress);
5757
final TextView tvClass = (TextView) lt.findViewById(R.id.deviceClass);
58+
final TextView tvMajorClass = (TextView) lt.findViewById(R.id.deviceMajorClass);
5859
final TextView tvBondingState = (TextView) lt.findViewById(R.id.deviceBondingState);
5960

6061
tvName.setText(device.getName());
6162
tvAddress.setText(device.getAddress());
6263
tvClass.setText(device.getBluetoothDeviceClassName());
64+
tvMajorClass.setText(device.getBluetoothDeviceMajorClassName());
6365
tvBondingState.setText(device.getBluetoothDeviceBondState());
6466

6567
adapter.addView(lt);

sample_app/src/main/res/layout/list_item_view_device_info.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@
4242
android:id="@+id/deviceClass"
4343
style="@style/GridLayoutDataTextView"/>
4444

45+
<TextView
46+
style="@style/GridLayoutTitleTextView"
47+
android:layout_width="wrap_content"
48+
android:layout_height="wrap_content"
49+
android:text="@string/label_device_major_class"/>
50+
51+
<TextView
52+
android:id="@+id/deviceMajorClass"
53+
style="@style/GridLayoutDataTextView"/>
54+
4555
<TextView
4656
style="@style/GridLayoutTitleTextView"
4757
android:layout_width="wrap_content"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<string name="label_desc">Desc:</string>
5454
<string name="label_device_address">Device address:</string>
5555
<string name="label_device_class">Device Class:</string>
56+
<string name="label_device_major_class">Major Class:</string>
5657
<string name="label_device_name">Device Name:</string>
5758
<string name="label_distance">Distance:</string>
5859
<string name="label_first_rssi">First RSSI:</string>

0 commit comments

Comments
 (0)