Skip to content

feat: implement Java sample parity, animations, and interaction handlers - #2423

Open
dkhawk wants to merge 1 commit into
feat/compose-sample-catalogfrom
feat/apidemos-java-parity-and-tests
Open

dkhawk wants to merge 1 commit into
feat/compose-sample-catalogfrom
feat/apidemos-java-parity-and-tests

Conversation

@dkhawk

@dkhawk dkhawk commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Implement verified Java sample parity fixes across Camera, VisibleRegion, Marker, Boundaries, DatasetStyling, CloudStyling, GroundOverlay, and TileOverlay
  • Simulate Fowler / Rattlesnake GPX track and add modern runtime permission launcher in LocationSourceDemoActivity
  • Polish layouts, touch targets, and coordinate displays across Java sample activities

Stacked Base

Stacked on #2422 (feat/compose-sample-catalog).

Reviewers

@LoyalAbbas

@dkhawk
dkhawk force-pushed the feat/apidemos-java-parity-and-tests branch from 62bdc37 to c156e51 Compare September 15, 2026 00:24
@dkhawk
dkhawk force-pushed the feat/apidemos-java-parity-and-tests branch from c156e51 to e4309b7 Compare September 15, 2026 00:32
@dkhawk
dkhawk marked this pull request as ready for review September 15, 2026 00:38
@dkhawk
dkhawk requested a review from LoyalAbbas September 15, 2026 00:38
@snippet-bot

snippet-bot Bot commented Sep 15, 2026

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 6 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@dkhawk
dkhawk added this pull request to stack #2429 September 15, 2026 00:42
FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.add(android.R.id.content, mapFragment, MAP_FRAGMENT_TAG);
fragmentTransaction.add(com.example.common_ui.R.id.sample_content_container, mapFragment, MAP_FRAGMENT_TAG);

@LoyalAbbas LoyalAbbas Sep 15, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Immediate Runtime Crash : neither ProgrammaticDemoActivity nor SamplesBaseActivity.java calls setContentView(R.layout.activity_sample_base). As a result, R.id.sample_content_container does not exist in the Activity's view hierarchy.
Impact: Launching ProgrammaticDemoActivity crashes immediately with: java.lang.IllegalArgumentException: No view found for id ... for fragment SupportMapFragment.

Fix: call setContentView(com.example.common_ui.R.layout.activity_sample_base); in onCreate() before running the FragmentTransaction

* This shows how to create a simple activity with a map and a marker on the map.
*/
// [START maps_android_sample_basic_map]
@Sample(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Internal @sample(...) Metadata Leaking into Official developers.google.com Documentation
Location: 15 Java sample activities (e.g.,
BasicMapDemoActivity.java:35-56,
AdvancedMarkersDemoActivity.java:52-64,
CameraDemoActivity.java:51-69,
LocationSourceDemoActivity.java:55-75,
etc.)

Issue: AGENTS.md, code inside // [START ] and // [END ] is extracted verbatim into public Google Maps Platform documentation on developers.google.com. In this PR, @sample(...) annotations (containing internal QA metadata like failureIndicators, successCriteria, Complexity, Framework) were placed inside the // [START ...] blocks without // [START_EXCLUDE] / // [END_EXCLUDE].
Impact: The published documentation on developers.google.com will render internal @sample(...) annotations that do not exist in the Maps SDK.

Fix: Move every @sample(...) annotation above the // [START ] comment line (or wrap it in // [START_EXCLUDE silent] ... // [END_EXCLUDE]).

failureIndicators = "Full vector GL map loaded instead of lite mode, or buttons fail to move camera.",
framework = Framework.JAVA_VIEWS
)
public class LiteDemoActivity extends SamplesBaseActivity implements

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do we need to add these LiteDemoActivity, LocationSourceDemoActivity, MultiMapDemoActivity, StyledMapDemoActivity, VisibleRegionDemoActivity also in SampleCodeProvider.SNIPPETS ?

SampleCodeProvider.kt is Out of Sync
Location: SampleCodeProvider.kt:60-730

Issue:
this PR adds 6 new region tags (maps_android_sample_lite, maps_android_sample_location_source, maps_android_sample_multimap, maps_android_sample_styled_map, maps_android_sample_ui_settings, maps_android_sample_visible_region). Five of these (LiteDemoActivity, LocationSourceDemoActivity, MultiMapDemoActivity, StyledMapDemoActivity, VisibleRegionDemoActivity) have no entry in SampleCodeProvider.SNIPPETS, causing the Compose Catalog's code viewer (CodeSnippetView) to show an empty snippet.

this PR updates the Java code inside
BasicMapDemoActivity.java,
CameraDemoActivity.java,
MarkerDemoActivity.java,
AdvancedMarkersDemoActivity.java

but SampleCodeProvider.kt in :ApiDemos:common-ui still serves the old code.

- Implement verified Java sample parity fixes across Camera, VisibleRegion, Marker, Boundaries, DatasetStyling, CloudStyling, GroundOverlay, and TileOverlay
- Simulate Fowler / Rattlesnake GPX track and add modern runtime permission launcher in LocationSourceDemoActivity
- Polish layouts, touch targets, and coordinate displays across Java sample activities
@dkhawk
dkhawk force-pushed the feat/apidemos-java-parity-and-tests branch from e4309b7 to 9b6659e Compare September 15, 2026 17:36
location.setBearing(bearing);
location.setSpeed(4.5f);
location.setTime(System.currentTimeMillis());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
* obscuring the map UI or copyright notices.
*/
@Sample(
id = "com.example.kotlindemos.VisibleRegionDemoActivity",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

com.example.kotlindemos in a com.example.mapdemo file — same in StyledMap (46), MultiMap (35), LiteDemo (45) and LocationSource (56).

The other 17 here use snake_case (basic_map, camera_demo, ...), while SampleCatalogRegistry says it keys on FQCN, so nothing quite lines up. Can we pick one scheme and apply it across both apps?

Comment on lines +321 to +323
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we drop the guard and just call it? minSdk is 24 and JELLY_BEAN_MR1 is 17 — lintDebug already flags this as ObsoleteSdkInt.

Worth catching since it sits inside the new maps_android_sample_location_source region, so it'd go out on the docs page as an example of how to write a LocationSource.

}

mLocationSource = new LongPressLocationSource();
List<LatLng> trackPoints = parseGpxTrack(getResources().openRawResource(R.raw.fowler_rattlesnake));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this move off the main thread? It's a raw resource read plus a full XML pull-parse in onCreate — the Kotlin version in #2424 wraps the same call in withContext(Dispatchers.IO), so right now the two diverge.

And catch (Exception ignored) on line 238 means a malformed GPX just gives us an empty track and a blank map with no clue why. Both of these are inside the published region, so they're what people copy.

Comment on lines +353 to +354
mMelbourne.showInfoWindow();
mLastSelectedMarker = mMelbourne;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

addMarker() is @Nullable, so this can NPE. Worth guarding — AdvancedMarkers in this same PR does exactly that on line 179, so the two are inconsistent right now.

Comment on lines +154 to +164
binding.cameraTargetText.setText(String.format(
Locale.US,
"Lat: %.4f°, Lng: %.4f°",
pos.target.latitude,
pos.target.longitude
));
binding.cameraDetailsText.setText(String.format(
Locale.US,
"Zoom: %.1fx • Tilt: %.1f° • Bearing: %.1f°",
pos.zoom,
pos.tilt,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can these go into strings.xml? We're replacing a localized getString(R.string.camera_change_message, ...) with hardcoded literals, and Kotlin still uses the resource (VisibleRegionDemoActivity.kt:87) — so at this point in the stack the two behave differently. Once #2424 lands, camera_change_message ends up orphaned in common-ui.

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.

4 participants