Skip to content

Commit

Permalink
android 13 cutout
Browse files Browse the repository at this point in the history
  • Loading branch information
yparitcher committed May 14, 2023
1 parent 2535b46 commit a9d36a0
Showing 1 changed file with 7 additions and 42 deletions.
49 changes: 7 additions & 42 deletions app/src/main/java/org/koreader/launcher/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ class MainActivity : NativeActivity(), LuaInterface,
// Path of last file imported
private var lastImportedPath: String? = null

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

// Fullscreen - only used on API levels 16-18
private var fullscreen: Boolean = true
Expand Down Expand Up @@ -163,26 +164,12 @@ 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()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val cut: DisplayCutout? = window.decorView.rootWindowInsets.displayCutout
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 @@ -436,18 +423,7 @@ class MainActivity : NativeActivity(), LuaInterface,
}

override fun getScreenHeight(): Int {
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()
}
return surfaceHeight ?: getHeight()
}

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

override fun getScreenWidth(): Int {
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()
}
return surfaceWidth ?: getWidth()
}

override fun getStatusBarHeight(): Int {
Expand Down

0 comments on commit a9d36a0

Please sign in to comment.