Skip to content

Conversation

dkhawk
Copy link
Contributor

@dkhawk dkhawk commented Aug 27, 2025

This PR completes the full migration of the com.google.maps.android.heatmaps package from Java to idiomatic Kotlin.

This effort included:

  • Porting WeightedLatLng, Gradient, and HeatmapTileProvider to Kotlin.
  • Refactoring internal data structures (like replacing LongSparseArray with a Map) to be more idiomatic and platform-agnostic.
  • Creating new unit tests from scratch for HeatmapTileProvider to improve code coverage.
  • Fixing several subtle compilation and interoperability bugs discovered during the process.

dkhawk added 4 commits August 27, 2025 09:38
The `@Deprecated` annotation has been updated to the Kotlin syntax and now includes a `ReplaceWith` expression to provide IDE quick-fix support.

Additionally, new unit tests using Google Truth have been added for the `Point` class to verify its construction and inheritance.
This commit migrates the `Gradient` and `WeightedLatLng` classes and their corresponding tests from Java to idiomatic Kotlin.

This conversion is part of the larger effort to modernize the library and prepare it for Kotlin Multiplatform (KMP) compatibility.

Key changes include:
- `WeightedLatLng` is now a `data class` with a private primary constructor to ensure correct instantiation while providing the benefits of auto-generated methods. The `@ExposedCopyVisibility` annotation has been added to maintain binary compatibility for the `copy()` method.
- `Gradient` has been converted to a Kotlin class, using `@JvmOverloads` for constructor compatibility and a `companion object` for its static helper method.
- The `internal` visibility of a method in `Gradient` was changed to `public` to ensure visibility to Java classes during the mixed-language phase of the migration.
- Unit tests for both classes have been ported to Kotlin, using the Truth assertion framework.
This commit completes the migration of the `heatmaps` package to Kotlin by porting the final and most complex class, `HeatmapTileProvider`.

This conversion modernizes the class by introducing several idiomatic Kotlin features and improves its design by refactoring a key data structure.

Key changes include:
- The `HeatmapTileProvider` and its `Builder` are now written in Kotlin.
- The `getMaxValue()` method was refactored to use a `Map` with a type-safe `Vector` key instead of the Android-specific `LongSparseArray`, improving readability and moving closer to KMP compatibility.
- A new test suite was created from scratch for the provider, as none existed previously. This improves the code coverage and reliability of the module.
- Necessary adjustments were made to the demo application to support the newly ported Kotlin class.
@dkhawk dkhawk requested a review from kikoso August 27, 2025 17:49
dkhawk added 3 commits August 27, 2025 12:02
Updates the copyright headers in the test files that were created
during the Kotlin porting process.

- Corrects the copyright year to 2025.
- Corrects the company name from "Google Inc." to "Google LLC".
Updates the copyright headers in the `heatmaps` package source and test files.

- Corrects the copyright year to 2025.
- Corrects the company name from "Google Inc." to "Google LLC".
@dkhawk dkhawk changed the title feat(heatmaps): Port heatmaps package to Kotlin chore(heatmaps): Port heatmaps package to Kotlin Aug 27, 2025
@googlemaps-bot
Copy link
Contributor

googlemaps-bot commented Aug 27, 2025

Code Coverage

Overall Project 40.25% -1.51% 🍏
Files changed 82.08% 🍏

File Coverage
WeightedLatLng.kt 100% 🍏
Point.kt 100% 🍏
HeatmapTileProvider.kt 81.27% -17.77% 🍏
Gradient.kt 81.19% -17.85% 🍏

dkhawk added 2 commits August 28, 2025 09:49
Addresses feedback to make the heatmap API more intuitive and robust.

- Renames `setWeightedData` and `setData` in `HeatmapTileProvider` to `updateData` and `updateLatLngs` respectively. The `update` prefix better communicates that these methods perform expensive operations that rebuild internal state, rather than just setting a property.
- The old method names are preserved and marked as `@Deprecated` to provide a smooth migration path for existing users and avoid a breaking change.

- Adds a default value of 0.7 to the `opacity` parameter in `Gradient.generateColorMap`. This aligns with the default in `HeatmapTileProvider` and simplifies common use cases.
- Annotates `generateColorMap` with `@JvmOverloads` to ensure the new default parameter is exposed correctly to Java clients.

- Improves KDoc for all modified methods to be more descriptive, explaining the purpose of the code and the reasoning behind the design choices.
Updates the `generateColorMap` function to use the
`HeatmapTileProvider.DEFAULT_OPACITY` constant for its default
opacity value.

This removes a hardcoded value, improving maintainability and ensuring
the default remains consistent with the provider. The accompanying
KDoc has also been corrected.
Copy link
Collaborator

@kikoso kikoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@dkhawk dkhawk merged commit 5d48344 into main Aug 28, 2025
8 checks passed
@dkhawk dkhawk deleted the feature/heatmaps-kotlin-port branch August 28, 2025 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants