Sample Android app for showcasing custom implementation of OpenGL camera preview display, written in Kotlin.
Structure inspired by TextureFromCameraActivity
in Grafika repository.
-
Stay as close to idiomatic Kotlin as possible.
Only place I knowingly depart from idiomatic Kotlin is the use of
lateinit
.lateinit
is used for critical variables to catch bugs faster & fix them, rather then letting them pass with use of nullables &?
keyword. -
Reduce complexity using single Executor & single Class.
Main class is intentionally flat, to avoid complexity caused by
Handler
s &RenderThread
s. A singleExecutor
replaces most of their functionality. -
Handle all state machines in a separate non-Activity class.
Activity lifecycle & Surface lifecycle doesn't match, so there is a need to account for both of them. Android Architecture Components
LifecycleObserver
is used to handle all in one single class. Grafika implementation handled all this in one Activity, which is fine for a sample app, but lacks extensibility. -
Overcome possible thread problems using Annotations.
@WorkerThread
,@MainThread
annotations are strategically placed to avoid GL operations on wrong threads.