DEV Community

loading...
Cover image for As time goes by

As time goes by

tkuenneth profile image Thomas Kuenneth ・2 min read

It is inevitable that operating systems and platforms change over time, mostly through gaining new features, but certainly also through changing existing ones. Loosing functionality should in my opinion be the exception. Still, Android seems to make a habbit of it. In this short article I will take a look at some widgets that came and went. The screenshots were taken with a small sample app of mine. You can find the source code at GitHub. The idea is to enter a fully qualified class name and the app will try to instantiate this class in a view hierarchy.

android.widget.AnalogClock

This widget displays an analog clock with two hands for hours and minutes. It was added in API level 1 and deprecated in 23 with no further explanation. The docs just say

This widget is no longer supported.

Fortunately the widget still works, so here is what it looks like on Android Q:

The AnalogClock widget

If your app needs an analog clock, best of luck. You are on your own. sin() and cos() will be waiting for you... Let's move on. As there used to be AnalogClock, there surely is DigitalClock, right?

android.widget.DigitalClock

Yes there is. The docs introduce it like this:

Like AnalogClock, but digital.

Now, please read between the lines... 😀

The DigitalClock widget

In fact, the class has been present since API level 1 and was deprecated in 17. The docs say:

It is recommended you use TextClock instead.

Very well, let's take a look at this fellow.

android.widget.TextClock

The look has not changed much, if at all:

The TextClock widget

The widget unsurprisingly was introduced in API level 17. It can display the current date and time as a formatted string and honors the 24-hour format system setting. The class used to have two constants DEFAULT_FORMAT_12_HOUR and DEFAULT_FORMAT_24_HOUR; both were deprecated in API level 18 (just one version later):

This field was deprecated in API level 18. Let the system use locale-appropriate defaults instead.

Conclusion

Designing long living and stable APIs is hard, no doubt. Unfortunately Android has seen quite a few changes that did not last too long. If you target recent Android versions and need a simple text-style clock, use TextClock. If you want a more visual representation of time you need to implement it on your own.

Material Design has the concept of date and time pickers but does not detail how to visualize, or present both. If I have not overlooked something, Jetpack Compose (which will become the new technology for building Android user interfaces) has no special composables to show date or time. Am I wrong? Please feel free to correct me in the comments.

Discussion (0)

pic
Editor guide