-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(library): Add polyline progress utilities to SphericalUtil #1588
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
Conversation
demo/src/main/res/layout/activity_polyline_progress_demo.xml
Dismissed
Show dismissed
Hide dismissed
demo/src/main/res/layout/activity_polyline_progress_demo.xml
Dismissed
Show dismissed
Hide dismissed
demo/src/main/res/layout/activity_polyline_progress_demo.xml
Dismissed
Show dismissed
Hide dismissed
demo/src/main/res/layout/activity_polyline_progress_demo.xml
Dismissed
Show dismissed
Hide dismissed
demo/src/main/res/layout/activity_polyline_progress_demo.xml
Dismissed
Show dismissed
Hide dismissed
demo/src/main/res/layout/activity_polyline_progress_demo.xml
Dismissed
Show dismissed
Hide dismissed
Code Coverage
|
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.
cc6282e to
38c49d9
Compare
|
|
||
| @Test | ||
| public void testGetPolylinePrefix() { | ||
| final LatLng a = new LatLng(0, 0); |
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.
An assertion for percentages very close to 0 or 1 (like 0.0001 or 0.9999) could help to ensure numerical stability.
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.
I have a utility for comparing locations that I wrote for Google Truth (a Subject). I'll consider porting that to this library.
kikoso
left a comment
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.
LGTM!
# [3.18.0](v3.17.0...v3.18.0) (2025-09-15) ### Features * **library:** Add polyline progress utilities to SphericalUtil ([#1588](#1588)) ([686774f](686774f))
|
🎉 This PR is included in version 3.18.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Refactored
PolylineProgressDemoActivityto improve code quality, add documentation, and align it withBaseDemoActivity.