Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

communitycreator
kotlin

Zero to Kotlin hero: More on Anko Commons

Adora Nwodo

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The previous shot 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.

widget

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!

widget

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

widget

There are two ways to add AnkoLogger to your project:

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

The trait-like interface

class MainActivity : Activity(), AnkoLogger {
fun doSomething() {
...
info("This is some information")
warn("Be careful")
}
}

AnkoLogger as an object

class MainActivity : Activity() {
private val log = AnkoLogger(this.javaClass)
private fun doSomething() {
...
log.info("This is some information")
log.warn("Be careful")
}

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

RELATED TAGS

communitycreator
kotlin

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring