Zero to Kotlin hero: More on Anko Commons

The previous Answer introduced the Anko library and briefly covered Anko Commons.

(If you are not familiar with Anko or how to add it to your Android project, please read that article before reading this).

In this article, we will cover the rest of the features that Anko Commons has. These features include helpers for logging, resources, and dimensions.

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

AnkoLogger

AnkoLogger is part of anko-commons. If you have not added the anko-commons artifact to your project, I have written about how to add it here.

In my opinion, AnkoLogger does not necessarily affect the length of your code. However, it does make the code easier to read if you have an Android beginner trying to go through your codebase.

I mean, Log.d(TAG, "Message"); is cool, but for someone with a technical background in other domains other than Android, what does Log.d even mean?

Well, AnkoLogger to the rescue!

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

The table below shows the translation of the android.util.Log class to its AnkoLogger equivalent.

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

There are two ways to add AnkoLogger to your project:

  • Using AnkoLogger trait-like interface
  • Using AnkoLogger as an object

The trait-like interface

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

AnkoLogger as an object

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

There are some helpers that are not grouped into any of the Anko subsystems (e.g., colors and dimensions).

Free Resources

Attributions:
  1. undefined by undefined