Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions app/src/main/java/org/koreader/launcher/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class MainActivity : NativeActivity(), LuaInterface,

// surface used on devices that need a view
private var view: NativeSurfaceView? = null

// cached root view for EPD mode calls from NativeThread (avoids window.decorView on non-UI thread)
private var epdRootView: android.view.View? = null
private class NativeSurfaceView(context: Context): SurfaceView(context),
SurfaceHolder.Callback {
init { holder.addCallback(this) }
Expand Down Expand Up @@ -133,6 +136,10 @@ class MainActivity : NativeActivity(), LuaInterface,
}
Log.v(TAG_SURFACE, "Using $surfaceKind implementation")

// Cache root view for EPD calls from NativeThread (window.decorView must not be
// accessed from a non-UI thread; pre-cache it here on the main thread instead).
epdRootView = view ?: window.decorView.findViewById(android.R.id.content)

@Suppress("DEPRECATION")
screenIsLandscape = windowManager.defaultDisplay.width > windowManager.defaultDisplay.height

Expand Down Expand Up @@ -165,6 +172,7 @@ class MainActivity : NativeActivity(), LuaInterface,

override fun surfaceCreated(holder: SurfaceHolder) {
super.surfaceCreated(holder)
epdRootView = view ?: window.decorView.rootView
drawSplashScreen(holder)
}

Expand Down Expand Up @@ -314,7 +322,7 @@ class MainActivity : NativeActivity(), LuaInterface,
}

override fun einkUpdate(mode: Int) {
val rootView = view ?: window.decorView.findViewById<View>(android.R.id.content)
val rootView = epdRootView ?: return
val modeName = when (mode) {
1 -> "EPD_FULL"
2 -> "EPD_PART"
Expand All @@ -332,7 +340,7 @@ class MainActivity : NativeActivity(), LuaInterface,
}

override fun einkUpdate(mode: Int, delay: Long, x: Int, y: Int, width: Int, height: Int) {
val rootView = view ?: window.decorView.findViewById<View>(android.R.id.content)
val rootView = epdRootView ?: return
Log.v(tag, String.format(Locale.US,
"requesting epd update, mode:%d, delay:%d, [x:%d, y:%d, w:%d, h:%d]",
mode, delay, x, y, width, height))
Expand Down Expand Up @@ -645,7 +653,7 @@ class MainActivity : NativeActivity(), LuaInterface,
}

override fun performHapticFeedback(constant: Int, force: Int) {
val rootView = view ?: window.decorView.findViewById<View>(android.R.id.content)
val rootView = epdRootView ?: return
hapticFeedback(constant, force > 0, rootView)
}

Expand Down