-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(demo): Add StreetViewJavaHelper and demo and enable edge-to-edge #1595
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
This commit adds a new demo activity written in Java to demonstrate the usage of the Street View utility. To facilitate this, a Kotlin helper has been introduced to bridge the gap between suspend functions and Java's callback-based asynchronous model. The key changes are: - **`StreetViewDemoActivityJava`**: A new demo activity that shows how to check for Street View availability from Java. - **`StreetViewHelper`**: A Kotlin object that wraps the `suspend` function `StreetViewUtils.fetchStreetViewData` and exposes it to Java consumers via a callback interface. - **`ApiKeyValidator`**: A new utility class to check for a valid Maps API key within the demo application. - **Unit Tests**: Added tests for `StreetViewHelper` using Robolectric, MockK, and coroutine testing libraries to verify its behavior. - **Dependencies**: Added `mockk`, `kotlinx-coroutines-test`, and `robolectric` to the demo module's test dependencies.
This commit refactors the `StreetViewDemoActivity` in both its Kotlin and Java versions to support edge-to-edge display. The key changes include: - Changing the base class from `Activity` to `AppCompatActivity`. - Using `WindowCompat.setDecorFitsSystemWindows` to allow the app to draw behind the system bars. - Adding an `OnApplyWindowInsetsListener` to the root view to apply padding for the system bars, preventing content from being obscured. - Updating the `street_view_demo.xml` layout with an ID for the root view to facilitate the insets listener. - Updating the copyright year.
Code Coverage
|
|
Since this is not adding functionality to the library, should we keep the commit name as "docs" or "chore", to avoid triggering a new release? |
demo/src/main/java/com/google/maps/android/utils/demo/ApiKeyValidator.java
Show resolved
Hide resolved
demo/src/main/java/com/google/maps/android/utils/demo/StreetViewDemoActivityJava.java
Outdated
Show resolved
Hide resolved
| /** | ||
| * An activity that demonstrates how to use the Street View utility in Java to check for Street View | ||
| * availability at different locations. | ||
| * |
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 will be ignored when the Javadoc is generated. Suggestion:
| * | |
| * <p> |
demo/src/main/java/com/google/maps/android/utils/demo/StreetViewDemoActivityJava.java
Outdated
Show resolved
Hide resolved
| runOnUiThread(() -> { | ||
| ((TextView) findViewById(R.id.textViewSecondLocation)).setText("Location 2 is supported in StreetView: " + status); | ||
| }); |
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.
nit: replace with expression lambda
| runOnUiThread(() -> { | |
| ((TextView) findViewById(R.id.textViewSecondLocation)).setText("Location 2 is supported in StreetView: " + status); | |
| }); | |
| runOnUiThread(() -> ((TextView) findViewById(R.id.textViewSecondLocation)).setText("Location 2 is supported in StreetView: " + status)); |
demo/src/main/java/com/google/maps/android/utils/demo/StreetViewHelper.kt
Outdated
Show resolved
Hide resolved
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! Just a couple of comments. Most importantly: do we want to change the commit name to avoid triggering a new release?
|
Actually, on a second thought, would it make sense to add the |
This commit moves the `StreetViewHelper` from the `demo` module to the `library` module, making it an officially supported utility for Java consumers. The key changes include: - Renaming `StreetViewHelper` to `StreetViewJavaHelper` for better clarity and moving it to the `com.google.maps.android` package within the library. - Migrating the corresponding unit tests from the `demo` to the `library` module and updating them to reflect the class rename. - Adjusting `build.gradle.kts` files to move test dependencies (`mockk`, `coroutines-test`, `robolectric`) from the `demo` to the `library` module. - Renaming `StreetViewDemoActivityJava` to `StreetViewDemoJavaActivity` and updating it to use the new helper from the library. - Improving the warning message for invalid or missing API keys in the demo app.
# [3.17.0](v3.16.2...v3.17.0) (2025-09-10) ### Features * **demo:** Add StreetViewJavaHelper and demo and enable edge-to-edge ([#1595](#1595)) ([23a4bb5](23a4bb5))
|
🎉 This PR is included in version 3.17.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This PR contains two main features:
Java Street View Demo
A new demo activity, StreetViewDemoActivityJava, has been added to show how to use the Street View utility from a Java-based Android application. This required the creation of a Kotlin helper class, StreetViewHelper, which bridges the gap between the suspend function StreetViewUtils.fetchStreetViewData and Java's callback-based asynchronous model. Additionally, an ApiKeyValidator utility was created to centralize the logic for checking for a valid Maps API key. The changes include adding unit tests for StreetViewHelper using Robolectric, MockK, and coroutine testing libraries to ensure its reliability.
Edge-to-Edge Support
Both the new Java demo and the existing Kotlin demo have been refactored to enable edge-to-edge display. This is achieved by changing the base activity to AppCompatActivity, using WindowCompat.setDecorFitsSystemWindows(window, false) to draw behind the system bars, and implementing ViewCompat.setOnApplyWindowInsetsListener on the root view to handle padding. This modern UI practice provides a more immersive and aesthetically pleasing user interface by utilizing the full screen space.
Fixes #1590