Kotlin extensions
At the end of this chapter, I would like to introduce you to the Kotlin extensions. No, not exactly the Kotlin extensions functions, although they are very much related to the Kotlin extension functions. Kotlin extensions is a curated list of the most commonly used extension functions in Android.
For example, if you want an extension function to create a bitmap from a View/ViewGroup instance (especially useful while adding Markers in MapFragment), you can copy and paste the following extension function from there:
fun View.getBitmap(): Bitmap {
val bmp = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888)
val canvas = Canvas(bmp)
draw(canvas)
canvas.save()
return bmp
} Or, a more common case, when you need to hide your keyboard, the following extension function will help you:
fun Activity.hideSoftKeyboard() {
if (currentFocus != null) {
val inputMethodManager = getSystemService(Context
...