-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Fix getsize() and getMetrics deprecations #17852
base: main
Are you sure you want to change the base?
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.
|
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.