Skip to content

Conversation

@dkhawk
Copy link
Contributor

@dkhawk dkhawk commented Sep 5, 2025

Refactored PolylineProgressDemoActivity to improve code quality, add documentation, and align it with BaseDemoActivity.

@dkhawk dkhawk requested a review from kikoso September 5, 2025 18:41
@googlemaps-bot
Copy link
Contributor

googlemaps-bot commented Sep 5, 2025

Code Coverage

Overall Project 40.12% 🍏
Files changed 99.23% 🍏

File Coverage
SphericalUtil.kt 99.61% -0.13% 🍏

This commit introduces two new utility functions to `SphericalUtil` for calculating points and prefixes on a polyline based on a percentage of its total length. A new demo has also been added to showcase this functionality.

The key changes are:
- **`SphericalUtil.getPointOnPolyline()`**: A new function that returns a `LatLng` at a specified percentage along a given polyline.
- **`SphericalUtil.getPolylinePrefix()`**: A new function that returns a new list of `LatLng`s representing a prefix of the original polyline up to a specified percentage.
- **New Demo**: A `PolylineProgressDemoActivity` has been added to the demo application. It demonstrates how to animate progress along a polyline using the new utility functions, complete with a `SeekBar` for user control.
- **Tests**: Added comprehensive unit tests for `getPointOnPolyline` and `getPolylinePrefix` to ensure correctness and handle edge cases.
This commit significantly refactors the `PolylineProgressDemoActivity` to align with modern Android development practices and better showcase the library's features.

Key changes include:
- **View Binding**: Replaced `findViewById` with View Binding for type-safe and more concise access to UI components. This required enabling `viewBinding` in the demo's `build.gradle.kts`.
- **Lifecycle-Aware Coroutines**: The animation now uses `lifecycleScope`, ensuring the coroutine is automatically canceled when the Activity is destroyed, preventing memory leaks.
- **State Management**: Replaced multiple `MutableLiveData` instances with a single `LiveData<AnimationState>` data class. This creates a single source of truth for the animation's state, leading to more predictable and maintainable UI updates.
- **Code Structure and Documentation**: The code has been reorganized into smaller, more focused functions. Extensive KDoc comments have been added to explain the implementation, highlight the use of `SphericalUtil`, and document the modern Android patterns being used.
@dkhawk dkhawk changed the title Refactor PolylineProgressDemoActivity feat(library): Add polyline progress utilities to SphericalUtil Sep 5, 2025

@Test
public void testGetPolylinePrefix() {
final LatLng a = new LatLng(0, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

An assertion for percentages very close to 0 or 1 (like 0.0001 or 0.9999) could help to ensure numerical stability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have a utility for comparing locations that I wrote for Google Truth (a Subject). I'll consider porting that to this library.

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 686774f into main Sep 15, 2025
8 checks passed
@dkhawk dkhawk deleted the polyline-progress branch September 15, 2025 16:58
googlemaps-bot pushed a commit that referenced this pull request Sep 15, 2025
# [3.18.0](v3.17.0...v3.18.0) (2025-09-15)

### Features

* **library:** Add polyline progress utilities to SphericalUtil ([#1588](#1588)) ([686774f](686774f))
@googlemaps-bot
Copy link
Contributor

🎉 This PR is included in version 3.18.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants