-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
In Android 11 two methods are deprecated #276
base: master
Are you sure you want to change the base?
Conversation
'getter for defaultDisplay: Display!' is deprecated. and 'getMetrics(DisplayMetrics!): Unit' is deprecated.
Hi @Sourav-21 thanks for contributing. I think the correct fix is to use We should also change this for the other samples. If you would like to make and verify those changes I can approve and merge. |
Hi @stowy |
val display = windowManager.defaultDisplay | ||
val outMetrics = DisplayMetrics() | ||
display.getMetrics(outMetrics) | ||
val outMetrics = resources.displayMetrics | ||
|
||
val density = outMetrics.density |
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.
inline this to resources.displayMetrics.density
val display = windowManager.defaultDisplay | ||
val outMetrics = DisplayMetrics() | ||
display.getMetrics(outMetrics) | ||
val outMetrics = resources.displayMetrics |
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.
this line can be removed, no need for outMetrics to be a variable.
Thanks @Sourav-21 point taken. Added some comments but we still need to update for other samples. |
@stowy, I think proper implementation will be something like this-
|
@stowy , I also found in AOSP DisplayInfo source that So an alternative better solution is |
I think that that latest option (using DENSITY_DEFAULT_SCALE) sounds good
to me.
…On Wed, Dec 9, 2020 at 2:21 PM Sourav Bagchi ***@***.***> wrote:
@stowy <https://github.com/stowy> , I also found in AOSP DisplayInfo
<https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/view/DisplayInfo.java>
source that density=densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE
So an alternative better solution is getContext().getResources().getConfiguration().densityDpi
* DisplayMetrics.DENSITY_DEFAULT_SCALE
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#276 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABNGOFAYUUHRVHUZFGQZERDST33NDANCNFSM4R5GCU7A>
.
|
I was wrong. To convert pixels into dp, we should divide pixels by a scaling factor and that scaling factor is
And I have tested these methods and work perfectly. |
Any updates on this? |
'getter for defaultDisplay: Display!' is deprecated.
and
'getMetrics(DisplayMetrics!): Unit' is deprecated.