googleads / googleads/googleads-mobile-android-examples

Bug: samples don't calculate dp values properly

Open
#796 2 comments 0 reactions 1 assignee View on GitHub

@malandr2 is already working on this.

Since Feb 4, 2025.

Dominant language
Java
Stars
1.9k
Forks
1.9k
Avg merge
15d 19h
Merged PRs (30d)
1

Description

When looking at the samples, I've noticed their calculation is losing the precision in a wrong way, so they can actually fail to get the ad that fits the size properly:

https://github.com/googleads/googleads-mobile-android-examples/blob/ab797ea740bd4100e61e5130c64cac44695ac6f1/kotlin/advanced/InlineAdaptiveBannerExample/app/src/main/java/com/google/android/gms/example/inlineadaptivebannerexample/MainActivity.kt#L69

https://github.com/googleads/googleads-mobile-android-examples/blob/ab797ea740bd4100e61e5130c64cac44695ac6f1/kotlin/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/MainActivity.kt#L50

The conversion should be like this:

val displayMetrics = resources.displayMetrics
val adWidthInDp = TypedValueCompat.deriveDimension(TypedValue.COMPLEX_UNIT_DIP, adWidthPixels.toFloat(), displayMetrics)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.