Skip to content

Conversation

@dkhawk
Copy link
Contributor

@dkhawk dkhawk commented Sep 9, 2025

This PR contains two main features:

  1. 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.

  2. 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

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.
@dkhawk dkhawk requested a review from kikoso September 9, 2025 22:16
@googlemaps-bot
Copy link
Contributor

googlemaps-bot commented Sep 9, 2025

Code Coverage

Overall Project 39.79% 🍏
Files changed 100% 🍏

File Coverage
StreetViewJavaHelper.kt 100% 🍏

@kikoso
Copy link
Collaborator

kikoso commented Sep 10, 2025

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?

/**
* An activity that demonstrates how to use the Street View utility in Java to check for Street View
* availability at different locations.
*
Copy link
Collaborator

@kikoso kikoso Sep 10, 2025

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:

Suggested change
*
* <p>

Comment on lines 100 to 102
runOnUiThread(() -> {
((TextView) findViewById(R.id.textViewSecondLocation)).setText("Location 2 is supported in StreetView: " + status);
});
Copy link
Collaborator

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

Suggested change
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));

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! Just a couple of comments. Most importantly: do we want to change the commit name to avoid triggering a new release?

@kikoso
Copy link
Collaborator

kikoso commented Sep 10, 2025

Actually, on a second thought, would it make sense to add the StreetViewHelper to the library? In this case, we would certainly want to release a new version.

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.
@dkhawk dkhawk changed the title feat(demo): Add Java StreetView demo and enable edge-to-edge feat(demo): Add StreetViewJavaHelper and demo and enable edge-to-edge Sep 10, 2025
@dkhawk dkhawk merged commit 23a4bb5 into main Sep 10, 2025
8 checks passed
@dkhawk dkhawk deleted the feature/java-streetview-helper branch September 10, 2025 17:28
googlemaps-bot pushed a commit that referenced this pull request Sep 10, 2025
# [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))
@googlemaps-bot
Copy link
Contributor

🎉 This PR is included in version 3.17.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.

Run StreetViewUtils from Java

3 participants