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

Fix getsize() and getMetrics deprecations #17852

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jainv4156
Copy link
Contributor

@jainv4156 jainv4156 commented Jan 22, 2025

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()
    WhatsApp Image 2025-01-24 at 4 01 53 PM

  • getSize()

WhatsApp Image 2025-01-24 at 4 06 59 PM
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.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@jainv4156 jainv4156 marked this pull request as ready for review January 22, 2025 10:34
@lukstbit
Copy link
Member

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.

@jainv4156
Copy link
Contributor Author

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.

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!

@jainv4156
Copy link
Contributor Author

jainv4156 commented Jan 22, 2025

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!

@lukstbit lukstbit changed the title Fix getsize() and getMatrix Depreciation Fix getsize() and getMetrics deprecations Jan 23, 2025
@lukstbit
Copy link
Member

The results were consistent across devices running Android 30+

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.

@jainv4156
Copy link
Contributor Author

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.

The results were consistent across devices running Android 30+

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display/Size related deprecation in API 30
3 participants