Coding the MainActivity class
Let's get started with coding the Activity-based class. As usual, the class is called MainActivity, and it was autogenerated for us when we created the project.
Edit the class declaration and add the first part of the code for the MainActivity class:
import android.app.Activity
import android.os.Bundle
import android.graphics.Point
class MainActivity : Activity() {
private lateinit var liveDrawingView: LiveDrawingView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val display = windowManager.defaultDisplay
val size = Point()
display.getSize(size)
liveDrawingView = LiveDrawingView(this, size.x)
setContentView(liveDrawingView)
}
}The preceding code shows several errors that we will talk about shortly. The first thing to note is that we are declaring an instance of our LiveDrawingView class. Currently, this is an empty class:
private lateinit var liveDrawingView...