Introduction

In this article we’ll learn how to create a custom progress indicator in Jetpack Compose using the Canvas APIs. What we want to achieve is the following:

This is basically a variation on the linear progress indicator. We want the user of this composable to be able to specify:

  • the number of segments in the progress indicator.
  • the gap between the segments.
  • the color for the background bars.
  • the colors for the foreground bars.
  • the height of the bars.

Let’s get started.

The progress indicator signature

First we need to define our progress…


Introduction

In this article we will find out how to write a ViewPager composable in Jetpack Compose. Here’s what we want our composable to offer:

  • The pager can scroll horizontally or vertically.
  • Items can occupy a fraction of the container size, so that we can have neighbouring items peaking on the sides.
  • It’s possible to overshoot items so that the user can scroll past the first or last item, but the pager then resets back to centering the item.
  • We can specify a separation between items.
  • We can indicate which item will…


In this article we’ll find out how to add biometric authentication to an Android app developed with Jetpack Compose. As not all devices offer biometric authentication, we will also add a PIN fallback in case no biometric options are available, or if the user prefers to use PIN.

What we want to achieve

Let’s first describe what we want our app to do:

  • If the device has Biometric authentication available, users should be prompted to use biometric credentials.
  • Users can fallback to PIN authentication at any time.


Background

In Jetpack Compose composables accept a Modifier that alters the appearance or behaviour of the composable they are applied to. Some of the modifiers, like width, height and padding are common to all composable functions while others can only be applied to specific composables, like weight for Row and Column, In this article we will see how to create a composable function with its own modifier attribute.

What we want to achieve is the following

We want to create a composable that takes a set of pairs of children, one being a label and the other being the description. We…


Recent versions of Android offer both Light and Dark themes, which the user can set globally via the device settings. Most apps nowadays follow this setting and change their theme based on the global setting, but it is also good practice to offer users an app option to set the theme regardless of what the global setting is. In this article we’ll find out how to do that with Jetpack Compose.

Storing the user preference

The first thing we need to do is persist the user setting; we will use SharedPreferences for this, though you may want to consider using the new DataStore —…


In the Android View system it is common to have ViewModels observe lifecycle events, generated by the Fragment or Activity hosting them, in order to start and stop certain tasks. Typically ViewModels will implement the DefaultLifecycleObserver interface and listen for lifecycle events like onStart and onStop. We can see an example below

This is all pretty straightforward — the Fragment adds the ViewModel as an observer on its lifecycle, and the ViewModel overrides the lifecycle events it is interested in. In this case, we want to run a task when the fragment is started (say, fetch some data from…


One of the most common tasks developers need to implement is the display of a heterogeneous list of items, for instance a list of weather cards separated by a header for each of the days, as shown below

While this is not a particularly difficult problem to solve thanks to Android’s Recyclerview this can become rather tedious when we have different view types to display. As a result of this several libraries have been available for a while now that aim to simplify and automate much of this wok, like Epoxy, Groupie and others.

To visualize the differences between Android’s…


Background

Android has been out for over a dozen years now, and how we write applications for Android has changed over the years. From the host of architectural solutions that have been proposed over the years, MVP (Model View Presenter), MVVM (Model View, ViewModel) and more recently MVI (Model View Intent) are the most notable ones. With the release of the Android Architecture components at Google IO 2017 the spotlight was on MVVM and that’s been the preferred architecture until recently.

With the recently release of JetPack Compose Beta and the required mental shift on how we write apps for compose…

Francesc Vilarino Guell

Senior Android Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store