/images/avatar.png

Paolo Gatti

Android Software Engineer - Appassionato di Elettronica e IoT

Gestire gli Insets della Status Bar in Compose

Lavorando ad un progetto personale sono incappato in un problema dovuto ai nuovi comportamenti di Android; in particolare l’applicazione forzata dell’edge to edge a partire da android 15 (sdk 35).

La documentazione è chiara a riguardo e l’intento è quello di forzare ogni app a svecchiarsi e disegnare il proprio contentuto sotto le barre di sistema (o quantomeno gestirle).

Vediamo più da vicino la problematica:

/images/insets/insets1.png

Custom Layout with Compose

Have you ever needed to layout components in a way other than rows or columns?

Composable doc cover this use case but perhaps a little more information could be helpful. The example provided by the documentation creates a custom column layout:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
@Composable
fun MyBasicColumn(
    modifier: Modifier = Modifier,
    content: @Composable () -> Unit
) {
    Layout(
        modifier = modifier,
        content = content
    ) { measurables, constraints ->
        // Don't constrain child views further, measure them with given constraints
        // List of measured children
        val placeables = measurables.map { measurable ->
            // Measure each children
            measurable.measure(constraints)
        }

        // Set the size of the layout as big as it can
        layout(constraints.maxWidth, constraints.maxHeight) {
            // Track the y co-ord we have placed children up to
            var yPosition = 0

            // Place children in the parent layout
            placeables.forEach { placeable ->
                // Position item on the screen
                placeable.placeRelative(x = 0, y = yPosition)

                // Record the y co-ord placed up to
                yPosition += placeable.height
            }
        }
    }
}

let’s try the above layout with the following preview. What do you expect to see? Three lines of text with different background colors?

PMS5003 Sensor Library for Esp32 idf

Plantower PMS5003 is a laser dust sensor. It can sense particulates of various sizes (PM1, PM2.5, PM10) from sources like smoke, dust, pollen, metal and organic particles.

This library can be used with multiple sensors at the same time. For each sensor you can choose between one shot or periodic data read.

The source code is available on my GitHub at the following link.

Working principle

This sensor uses laser scattering to radiate suspending particles in the air, then collects scattering light to obtain the curve of scattering light change with time. The microprocessor calculates equivalent particle diameter and the number of particles with different diameter per unit volume.

Android Toolbar Actions with Compose

Intro

Before Jetpack Compose release we were used to add menu items in Fragments or Activities classes with xml files and onCreateOptionsMenu methods.

The new UI tool is a game changer and via Scaffold composable it’s easy to add global actions to TopAppBar. With global actions I mean items that remains visible for the entire lifecycle of the controller class. When using Jetpack Navigation however there is only one Activity and the NavHost swaps composable destinations on the screen.