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
Conversation
This reverts commit a9d36a0.
Wondering why the changes for Android 14 don't work for me after I merged the changes with the checks and then I went to logging. 09-24 09:50:34.558 20926 20926 V Android_Version: onAttachedToWindow Android version is: 33 It is because my device is Android 13. DUH, DUH, DUH. I feel so dumb. That Xiaomi version screen really tricks me out." Now the discussion about Android 14 doesn't make any sense since I actually have an Android 13 device. @pazos Should I then apply my working changes to Android 13 then since I simulate the problem now on a real device? Oh boy.... |
} | ||
// ONLY FOR ANDROID 14 | ||
else if (android.os.Build.VERSION.SDK_INT == 34) { | ||
val cut = windowManager.defaultDisplay.cutout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this chunk of code works for android 9 - 12?
It would be wonderful to have a single codepath for all versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this chunk of code works for android 9 - 12?
It would be wonderful to have a single codepath for all versions.
That's what I would like to show you!
for android <= 12 as you say so works.
val cut: DisplayCutout? = window.decorView.rootWindowInsets.displayCutout
for android 13 this seems to be the secret:
windowManager.defaultDisplay.cutout
Following the doc this method should work for >= P
For now I've tested on devices without the hole on some devices < 13 and works.
But I can test some more on the emulator enabling holes in the dev options.
Did you remember to try the method windowManager.defaultDisplay.cutout before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you remember to try the method windowManager.defaultDisplay.cutout before?
I actually don't remember. I think I didn't try anything. Just read the documentation, find something useful, went with that and pushed an APK for others to test. Since the test were ok I never bothered again :)
So please go with that for everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you remember to try the method windowManager.defaultDisplay.cutout before?
I actually don't remember. I think I didn't try anything. Just read the documentation, find something useful, went with that and pushed an APK for others to test. Since the test were ok I never bothered again :)
So please go with that for everything.
Tested on emulator and doesn't work for Android 9. Need Android >= 10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks!.
Then from 9 up to 12 the legacy method and from 13 onwards the new one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks!.
Then from 9 up to 12 the legacy method and from 13 onwards the new one.
Already there ;-)
else if (android.os.Build.VERSION.SDK_INT == 34) { | ||
val cut = windowManager.defaultDisplay.cutout | ||
if (cut != null && cut.boundingRects.isNotEmpty()) { | ||
// TODO: we can handle various kinds of cutouts: getSafeInsetLeft, getSafeInsetRight, getSafeInsetTop, getSafeInsetBottom |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of random TODO lists.
Do you have something in mind to do with those cutouts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of random TODO lists.
Do you have something in mind to do with those cutouts?
Yes. Today we only deal with topInsetHeight when the hole is at the top.
On the emulator, we can enable holes in any direction: top, bottom, left, or right.
When you guys changed surfaceWidth = width; surfaceHeight = height inside the surfaceChanged method, it enabled support for all kinds of holes.
When I reverted the changes I realized that it was not implemented in the old version ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so remove the TODO and add a NOTE instead.
Somebody else that reads the code in the future might find that useful.
Not so with a TODO.
@hugleo: sorry for the delay. two nitpicks and this can be merged. Please add a log statement in the new condition, too. Use exactly the same string, so logs provide the same feedback in all android versions. Please fix https://app.codacy.com/gh/koreader/android-luajit-launcher/pullRequest?prid=12685762 |
@pazos nitpicks addressed |
if (Build.VERSION.SDK_INT >= 33) { | ||
val cut = windowManager.defaultDisplay.cutout | ||
if (cut != null && cut.boundingRects.isNotEmpty()) { | ||
insetsHeight = cut.safeInsetTop + cut.safeInsetBottom |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason to take in account safeInsetBottom?. Did you find a device (I mean any device outside an emulator with fake cutouts) where it is not 0?.
It's not a vetto. Just trying to figure out what's the best option:
a) ignore cut.safeInsetBottom
on both branches.
b) count cut.safeInsetBottom
on both branches.
Anyhow, I'm fine if you go with b* but then please use the same log statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason to take in account safeInsetBottom?. Did you find a device (I mean any device outside an emulator with fake cutouts) where it is not 0?.
It's not a vetto. Just trying to figure out what's the best option:
a) ignore
cut.safeInsetBottom
on both branches. b) countcut.safeInsetBottom
on both branches.Anyhow, I'm fine if you go with b* but then please use the same log statement.
No, see only in the emulator. Fine with a) since it makes more sense for the log as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think can get rid of cut.boundingRects.isNotEmpty() as well since I don't remember if it's needed and it would save some duplication
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks much better, thanks!
This broke the screen for my Xiaomi. I don't read on the phone. Just letting you know. MIUI 14 too. I am using the patch I used to use previously to the original fix that this is reverting to add the missing height. |
Do you have a screenshot of the problem? |
If you rotate to landscape in KOReader options and then back to portrait, does the problem go away? |
Also tell which device model |
It is not a problem to be honest. Just curious. |
This change is