Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverted cutout and fix rotations #439

Merged
merged 8 commits into from Dec 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 49 additions & 7 deletions app/src/main/java/org/koreader/launcher/MainActivity.kt
Expand Up @@ -44,9 +44,8 @@ class MainActivity : NativeActivity(), LuaInterface,
// Path of last file imported
private var lastImportedPath: String? = null

// Surface height & width determined at runtime to account for device cutout
private var surfaceHeight: Int? = null
private var surfaceWidth: Int? = null
// Device cutout - only used on API 28+
private var topInsetHeight: Int = 0

// Fullscreen - only used on API levels 16-18
private var fullscreen: Boolean = true
Expand Down Expand Up @@ -165,12 +164,33 @@ class MainActivity : NativeActivity(), LuaInterface,
"surface changed {\n width: %d\n height: %d\n format: %s\n}",
width, height, pixelFormatName(format))
)
surfaceWidth = width
surfaceHeight = height

super.surfaceChanged(holder, format, width, height)
drawSplashScreen(holder)
}

override fun onAttachedToWindow() {
Log.d(TAG_SURFACE, "onAttachedToWindow()")
super.onAttachedToWindow()

val cut = when {
Build.VERSION.SDK_INT >= 33 -> {
windowManager.defaultDisplay.cutout as? DisplayCutout
} Build.VERSION.SDK_INT >= Build.VERSION_CODES.P -> {
window.decorView.rootWindowInsets?.displayCutout as? DisplayCutout
} else -> null
}

if (cut != null) {
val cutPixels = cut.safeInsetTop
if (topInsetHeight != cutPixels) {
Log.v(TAG_SURFACE,
"top $cutPixels pixels are not available, reason: window inset")
topInsetHeight = cutPixels
}
}
}

/* Called just before the activity is resumed by an intent */
override fun onNewIntent(intent: Intent) {
val scheme = intent.scheme
Expand Down Expand Up @@ -424,7 +444,18 @@ class MainActivity : NativeActivity(), LuaInterface,
}

override fun getScreenHeight(): Int {
return surfaceHeight ?: getHeight()
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// We need to handle the notch in Portrait
// NOTE: getScreenAvailableHeight does it automatically, but it also excludes the nav bar, when there's one :/
if (getOrientationCompat(screenIsLandscape).and(1) == 0) {
// getScreenOrientation returns LinuxFB rotation constants, Portrait rotations are always even
getHeight() - topInsetHeight
} else {
getHeight()
}
} else {
getHeight()
}
}

override fun getScreenMaxBrightness(): Int {
Expand Down Expand Up @@ -452,7 +483,18 @@ class MainActivity : NativeActivity(), LuaInterface,
}

override fun getScreenWidth(): Int {
return surfaceWidth ?: getWidth()
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// We need to handle the notch in Landscape
// NOTE: getScreenAvailableWidth does it automatically, but it also excludes the nav bar, when there's one :/
if (getOrientationCompat(screenIsLandscape).and(1) == 1) {
// getScreenOrientation returns LinuxFB rotation constants, Landscape rotations are always odd
getWidth() - topInsetHeight
} else {
getWidth()
}
} else {
getWidth()
}
}

override fun getStatusBarHeight(): Int {
Expand Down