Skip to content

Commit d1b59cf

Browse files
authored
Merge pull request #152 from NordicPlayground/improvement/scanner
Scanner improvements
2 parents f6601d8 + 145dc7d commit d1b59cf

File tree

5 files changed

+120
-9
lines changed

5 files changed

+120
-9
lines changed

scanner-ble/src/main/java/no/nordicsemi/android/common/scanner/spec/ServiceUuids.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ internal val UART_SERVICE_UUID= Uuid.parse("6E400001-B5A3-F393-E0A9-E50E24DCCA9E
5252
internal val BATTERY_SERVICE_UUID= Uuid.parse("0000180F-0000-1000-8000-00805f9b34fb")
5353
internal val THROUGHPUT_SERVICE_UUID = Uuid.parse("0483DADD-6C9D-6CA9-5D41-03AD4FFF4ABB")
5454
internal val CHANNEL_SOUND_SERVICE_UUID = Uuid.parse("0000185B-0000-1000-8000-00805F9B34FB")
55+
// Nordic Service UUIDs
5556
internal val MDS_SERVICE_UUID = Uuid.parse("54220000-f6a5-4007-a371-722f4ebd8436")
57+
internal val LBS_SERVICE_UUID = Uuid.parse("00001523-1212-EFDE-1523-785FEABCD123")
58+
internal val MESH_PROVISIONING_SERVICE_UUID = Uuid.parse("00001827-0000-1000-8000-00805F9B34FB")
59+
internal val MESH_PROXY_SERVICE_UUID = Uuid.parse("00001828-0000-1000-8000-00805F9B34FB")
60+
internal val MESH_PROXY_SOLICITATION_SERVICE_UUID = Uuid.parse("00001829-0000-1000-8000-00805F9B34FB")
5661

5762
// TODO: make a callback which checks the uuid and returns the name and icon for the service.
5863
object ServiceUuids {
@@ -67,12 +72,10 @@ object ServiceUuids {
6772
"Cycling Speed and Cadence",
6873
R.drawable.baseline_directions_bike_24,
6974
)
70-
7175
CGMS_SERVICE_UUID -> ServiceNameWithIcon(
7276
"Continuous Glucose Monitoring",
7377
R.drawable.baseline_water_drop_24
7478
)
75-
7679
DF_SERVICE_UUID -> ServiceNameWithIcon("Direction Finding", R.drawable.baseline_my_location_24)
7780
GLS_SERVICE_UUID -> ServiceNameWithIcon("Glucose", R.drawable.baseline_water_drop_24)
7881
HRS_SERVICE_UUID -> ServiceNameWithIcon("Heart Rate", R.drawable.baseline_monitor_heart_24)
@@ -90,9 +93,13 @@ object ServiceUuids {
9093
R.drawable.baseline_my_location_24
9194
)
9295
MDS_SERVICE_UUID -> ServiceNameWithIcon(
93-
"Memfault",
96+
"Monitoring & Diagnostics",
9497
R.drawable.ic_memfault_app_logo
9598
)
99+
LBS_SERVICE_UUID -> ServiceNameWithIcon("LED Button", R.drawable.outline_lightbulb_2_24)
100+
MESH_PROXY_SERVICE_UUID,
101+
MESH_PROXY_SOLICITATION_SERVICE_UUID,
102+
MESH_PROVISIONING_SERVICE_UUID -> ServiceNameWithIcon("Mesh", R.drawable.ic_mesh)
96103

97104
else -> null
98105
}

scanner-ble/src/main/java/no/nordicsemi/android/common/scanner/view/ScannerView.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,12 @@ internal fun DeviceListItem(
226226
verticalAlignment = Alignment.CenterVertically,
227227
horizontalArrangement = Arrangement.spacedBy(16.dp)
228228
) {
229-
peripheralIcon?.let { CircularIcon(painter = painterResource(it)) }
229+
peripheralIcon?.let {
230+
CircularIcon(
231+
painter = painterResource(it),
232+
iconSize = 30.dp
233+
)
234+
}
230235

231236
Column(
232237
horizontalAlignment = Alignment.Start,
@@ -236,9 +241,10 @@ internal fun DeviceListItem(
236241
Column(
237242
verticalArrangement = Arrangement.spacedBy(4.dp)
238243
) {
244+
val name = result.advertisingData.name ?: result.peripheral.name
239245
Text(
240-
text = result.peripheral.name ?: stringResource(R.string.no_name),
241-
color = if (result.peripheral.name != null) {
246+
text = name ?: stringResource(R.string.no_name),
247+
color = if (name != null) {
242248
MaterialTheme.colorScheme.onSurface
243249
} else {
244250
MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="330"
5+
android:viewportHeight="205"
6+
android:tint="#000000">
7+
8+
<group android:scaleX="1.625" android:translateX="-100">
9+
<path
10+
android:fillColor="@android:color/white"
11+
android:pathData="M164.9,33.81m-15.08,0a15.08,15.08 0,1 1,30.16 0a15.08,15.08 0,1 1,-30.16 0"
12+
android:strokeWidth="0" />
13+
14+
<path
15+
android:fillColor="@android:color/white"
16+
android:pathData="M164.9,170.67m-15.08,0a15.08,15.08 0,1 1,30.16 0a15.08,15.08 0,1 1,-30.16 0"
17+
android:strokeWidth="0" />
18+
19+
<path
20+
android:fillColor="@android:color/white"
21+
android:pathData="M105.64,68.03m-15.08,0a15.08,15.08 0,1 1,30.16 0a15.08,15.08 0,1 1,-30.16 0"
22+
android:strokeWidth="0" />
23+
24+
<path
25+
android:fillColor="@android:color/white"
26+
android:pathData="M224.16,136.46m-15.08,0a15.08,15.08 0,1 1,30.16 0a15.08,15.08 0,1 1,-30.16 0"
27+
android:strokeWidth="0" />
28+
29+
<path
30+
android:fillColor="@android:color/white"
31+
android:pathData="M105.64,136.46m-15.08,0a15.08,15.08 0,1 1,30.16 0a15.08,15.08 0,1 1,-30.16 0"
32+
android:strokeWidth="0" />
33+
34+
<path
35+
android:fillColor="@android:color/white"
36+
android:pathData="M224.16,68.03m-15.08,0a15.08,15.08 0,1 1,30.16 0a15.08,15.08 0,1 1,-30.16 0"
37+
android:strokeWidth="0" />
38+
39+
<path
40+
android:fillColor="#00000000"
41+
android:pathData="M224.16,136.46l0,-68.43l-59.26,-34.22l-59.26,34.22l0,68.43l59.26,34.21l59.26,-34.21z"
42+
android:strokeWidth="12"
43+
android:strokeColor="@android:color/white" />
44+
45+
<path
46+
android:fillColor="#00000000"
47+
android:pathData="M164.9,33.81L164.9,171.97"
48+
android:strokeWidth="12"
49+
android:strokeColor="@android:color/white" />
50+
51+
<path
52+
android:fillColor="#00000000"
53+
android:pathData="M105.64,136.46L224.91,68.03"
54+
android:strokeWidth="12"
55+
android:strokeColor="@android:color/white" />
56+
57+
<path
58+
android:fillColor="#00000000"
59+
android:pathData="M105.64,68.03L224.91,137.76"
60+
android:strokeWidth="12"
61+
android:strokeColor="@android:color/white" />
62+
</group>
63+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="960" android:viewportWidth="960" android:width="24dp">
2+
3+
<path android:fillColor="@android:color/white" android:pathData="M400,720Q367,720 343.5,696.5Q320,673 320,640L320,590Q263,551 231.5,490Q200,429 200,360Q200,243 281.5,161.5Q363,80 480,80Q597,80 678.5,161.5Q760,243 760,360Q760,429 728.5,489.5Q697,550 640,590L640,640Q640,673 616.5,696.5Q593,720 560,720L400,720ZM400,640L560,640Q560,640 560,640Q560,640 560,640L560,548L594,524Q635,496 657.5,452.5Q680,409 680,360Q680,277 621.5,218.5Q563,160 480,160Q397,160 338.5,218.5Q280,277 280,360Q280,409 302.5,452.5Q325,496 366,524L400,548L400,640Q400,640 400,640Q400,640 400,640ZM400,880Q383,880 371.5,868.5Q360,857 360,840L360,800L600,800L600,840Q600,857 588.5,868.5Q577,880 560,880L400,880ZM480,360Q480,360 480,360Q480,360 480,360L480,360L480,360Q480,360 480,360Q480,360 480,360Q480,360 480,360Q480,360 480,360Q480,360 480,360Q480,360 480,360Q480,360 480,360Q480,360 480,360L480,360L480,360Q480,360 480,360Q480,360 480,360Z"/>
4+
5+
</vector>

ui/src/main/java/no/nordicsemi/android/common/ui/view/CircularIcon.kt

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ package no.nordicsemi.android.common.ui.view
3636
import androidx.compose.foundation.Image
3737
import androidx.compose.foundation.background
3838
import androidx.compose.foundation.layout.padding
39+
import androidx.compose.foundation.layout.size
3940
import androidx.compose.foundation.shape.CircleShape
4041
import androidx.compose.material3.MaterialTheme
4142
import androidx.compose.material3.contentColorFor
@@ -48,16 +49,30 @@ import androidx.compose.ui.graphics.vector.ImageVector
4849
import androidx.compose.ui.graphics.vector.rememberVectorPainter
4950
import androidx.compose.ui.res.painterResource
5051
import androidx.compose.ui.tooling.preview.Preview
52+
import androidx.compose.ui.unit.Dp
5153
import androidx.compose.ui.unit.dp
5254
import no.nordicsemi.android.common.ui.R
5355

56+
/**
57+
* A circular icon with a background.
58+
*
59+
* @param painter The painter to be used for the icon.
60+
* @param modifier The modifier to be applied to the icon.
61+
* @param backgroundColor The background color of the circle.
62+
* @param enabled If false, the icon will be displayed in a disabled state.
63+
* @param size The size of the circular background.
64+
* @param iconSize The size of the icon inside the circle.
65+
*/
5466
@Composable
5567
fun CircularIcon(
5668
painter: Painter,
5769
modifier: Modifier = Modifier,
5870
backgroundColor: Color = MaterialTheme.colorScheme.secondary,
5971
enabled: Boolean = true,
72+
size: Dp = 40.dp,
73+
iconSize: Dp = 24.dp,
6074
) {
75+
val padding = (size - iconSize) / 2
6176
Image(
6277
painter = painter,
6378
contentDescription = null,
@@ -66,7 +81,9 @@ fun CircularIcon(
6681
} else {
6782
ColorFilter.tint(MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f))
6883
},
69-
modifier = modifier
84+
modifier = Modifier
85+
.size(size)
86+
.then(modifier)
7087
.background(
7188
color = if (enabled) {
7289
backgroundColor
@@ -75,22 +92,35 @@ fun CircularIcon(
7592
},
7693
shape = CircleShape
7794
)
78-
.padding(8.dp)
95+
.padding(padding)
7996
)
8097
}
8198

99+
/**
100+
* A circular icon with a background.
101+
*
102+
* @param imageVector The vector image to be used for the icon.
103+
* @param modifier The modifier to be applied to the icon.
104+
* @param backgroundColor The background color of the circle.
105+
* @param enabled If false, the icon will be displayed in a disabled state.
106+
* @param size The size of the circular background.
107+
* @param iconSize The size of the icon inside the circle.
108+
*/
82109
@Composable
83110
fun CircularIcon(
84111
imageVector: ImageVector,
85112
modifier: Modifier = Modifier,
86113
backgroundColor: Color = MaterialTheme.colorScheme.secondary,
87114
enabled: Boolean = true,
115+
size: Dp = 40.dp,
116+
iconSize: Dp = 24.dp,
88117
) {
89118
CircularIcon(
90119
painter = rememberVectorPainter(image = imageVector),
91120
modifier = modifier,
92121
backgroundColor = backgroundColor,
93-
enabled = enabled
122+
enabled = enabled,
123+
iconSize = iconSize,
94124
)
95125
}
96126

0 commit comments

Comments
 (0)