Fix getsize() and getMetrics deprecations#17852
Conversation
|
Please fill the PR template with more info about what was done, especially how the changes were tested. Also you linked to the incorrect issue. |
My mistake, thanks for pointing that out! |
|
Hey @lukstbit , I’ve made the changes you mentioned. Can you take a look at the testing approach and let me know if it’s sufficient or if you think any additional testing is needed? Thanks! |
When I tested it on an emulator(Pixel8A API 35) the width seems to be identical only for portrait and not for landscape: 2279(old code) vs 2400 new code. |
|
made some changes and i'm now able to get the same values for the alternate of getMetrics() in both portrait and landscape modes. However, there is an issue with getSize(). The function calling getSize() is used in two places: it works perfectly in the whiteboard section for both portrait and landscape modes, but in the usage analytics section, it gives different results. In the old code, the usage analytics part returned a different value compared to the whiteboard, possibly due to usageAlalitics is called in oncreate() . With the new code, the value in the usage analytics part is now consistent with the old whiteboard part.
|
lukstbit
left a comment
There was a problem hiding this comment.
LGTM, this looks much better now with the handling of insets.
I left one minor code style to implement as the code is a bit too verbose.
|
Hi there @jainv4156! This is the OpenCollective Notice for PRs merged from 2025-02-01 through 2025-02-28 If you are interested in compensation for this work, the process with details is here: https://github.com/ankidroid/Anki-Android/wiki/OpenCollective-Payment-Process#how-to-get-paid We only post one comment per person per month to avoid spamming you, regardless of the number of PRs merged, but this note applies to all PRs merged for this month Please understand that our monthly budget is never guaranteed to cover all claims - the cap on payments-per-person may be lower, but we try to make our process as fair and transparent as possible, we just need your understanding. Thanks! |
Purpose / Description
Replaced deprecated methods Display.getMetrics() and Display.getSize(Point) with WindowManager.getCurrentWindowMetrics().getBounds() for Android R (API 30+) to obtain screen dimensions. Additionally, used Configuration.densityDpi for retrieving screen density. For backward compatibility, retained the use of Display.getMetrics() and Display.getSize(Point) on older Android versions
Fixes
How Has This Been Tested?
The changes were tested using Logcat by logging the values obtained from WindowMetrics.getBounds() and comparing them with the values from Display.getSize(Point) and Display.getMetrics(). The results were consistent across devices running Android 30+ and older versions.
getmetrix()

getSize()
1st log is of getSize() used by UsageAnalitics
2nd , 3rd log is of getSize() used by whiteboard portrate, landscape
Checklist
Please, go through these checks before submitting the PR.