Skip to content

Commit cb074f9

Browse files
authored
feat: Transit Layer Demo & Quality Improvements (#1653)
* feat: update to maps 20.0.0 and add usage attribution * feat: add transit layer demo * feat(demo): modernize MainActivity with Compose and fix UI issues - Replace legacy MainActivity.java/xml with Compose-based MainActivity.kt - Enforce edge-to-edge support with `enableEdgeToEdge()` and Scaffold - Organize libs.versions.toml into categorized sections - Add TransitLayerDemoActivity to demonstrate transit layer usage - Fix spinner text contrast in ClusterAlgorithmsDemoActivity - Add material-icons-core dependency to resolve compilation error * feat(demo): modernize MainActivity with Compose and fix UI issues - Replace legacy MainActivity.java/xml with Compose-based MainActivity.kt - Enforce edge-to-edge support with `enableEdgeToEdge()` and Scaffold - Organize libs.versions.toml into categorized sections - Add TransitLayerDemoActivity to demonstrate transit layer usage - Fix spinner text contrast in ClusterAlgorithmsDemoActivity - Add material-icons-core dependency to resolve compilation error * Refactor: Extract strings, clean resources, modernize Demo UI - Updated MainActivity to Compose with Accordion UI - Extracted hardcoded strings to strings.xml - Removed unused resources (colors, dimens, raw files) - Fixed lint warnings for hardcoded text and unused resources - Updated Demo models to use resource IDs * Fix: Add missing copyright headers (2026 Google LLC) * Fix: Update XML copyright headers to match repo style * Delete demo_transit_layer_material.png
1 parent 860c3ef commit cb074f9

26 files changed

+704
-826
lines changed

build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ tasks.register<Delete>("clean") {
3535
delete(layout.buildDirectory)
3636
}
3737

38+
tasks.register<Exec>("installAndLaunch") {
39+
description = "Installs and launches the demo app."
40+
group = "install"
41+
dependsOn(":demo:installDebug")
42+
commandLine("adb", "shell", "am", "start", "-n", "com.google.maps.android.utils.demo/.MainActivity")
43+
}
44+
3845
allprojects {
3946
group = "com.google.maps.android"
4047
// {x-release-please-start-version}

demo/build.gradle.kts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ plugins {
2020
id("com.android.application")
2121
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
2222
id("kotlin-android")
23+
alias(libs.plugins.compose.compiler)
2324
}
2425

2526
android {
@@ -48,6 +49,7 @@ android {
4849

4950
buildFeatures {
5051
viewBinding = true
52+
compose = true
5153
}
5254

5355
kotlin {
@@ -76,6 +78,15 @@ dependencies {
7678

7779
testImplementation(libs.junit)
7880
testImplementation(libs.truth)
81+
82+
implementation(platform(libs.compose.bom))
83+
implementation(libs.activity.compose)
84+
implementation(libs.ui)
85+
implementation(libs.ui.graphics)
86+
implementation(libs.ui.tooling.preview)
87+
implementation(libs.material3)
88+
implementation(libs.material.icons.core)
89+
debugImplementation(libs.ui.tooling)
7990
// [END_EXCLUDE]
8091
}
8192
// [END maps_android_utils_install_snippet]

demo/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@
134134
<activity
135135
android:name=".ClusterAlgorithmsDemoActivity"
136136
android:exported="true" />
137+
<activity
138+
android:name=".TransitLayerDemoActivity"
139+
android:exported="true" />
137140

138141
</application>
139142

demo/src/main/java/com/google/maps/android/utils/demo/BigClusteringDemoActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected void startDemo(boolean isRestore) {
4343
try {
4444
readItems();
4545
} catch (JSONException e) {
46-
Toast.makeText(this, "Problem reading list of markers.", Toast.LENGTH_LONG).show();
46+
Toast.makeText(this, getString(R.string.error_reading_markers), Toast.LENGTH_LONG).show();
4747
}
4848
}
4949

demo/src/main/java/com/google/maps/android/utils/demo/ClusterAlgorithmsDemoActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ class ClusterAlgorithmsDemoActivity : BaseDemoActivity() {
6464
private fun setupSpinner() {
6565
val spinner: Spinner = findViewById(R.id.algorithm_spinner)
6666
val adapter = ArrayAdapter.createFromResource(
67-
this, R.array.clustering_algorithms, android.R.layout.simple_spinner_item
67+
this, R.array.clustering_algorithms, R.layout.text_view_spinner_item
6868
)
69-
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
69+
adapter.setDropDownViewResource(R.layout.text_view_spinner_dropdown_item)
7070
spinner.adapter = adapter
7171
spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
7272
override fun onItemSelected(

demo/src/main/java/com/google/maps/android/utils/demo/ClusteringDiffDemoActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ private LatLng getMidpoint() {
103103
public boolean onClusterClick(Cluster<Person> cluster) {
104104
// Show a toast with some info when the cluster is clicked.
105105
String firstName = cluster.getItems().iterator().next().name;
106-
Toast.makeText(this, cluster.getSize() + " (including " + firstName + ")", Toast.LENGTH_SHORT).show();
106+
Toast.makeText(this, getString(R.string.cluster_info_fmt, cluster.getSize(), firstName), Toast.LENGTH_SHORT)
107+
.show();
107108

108109
// Zoom in the cluster. Need to create LatLngBounds and including all the cluster items
109110
// inside of bounds, then animate to center of the bounds.

demo/src/main/java/com/google/maps/android/utils/demo/CustomAdvancedMarkerClusteringDemoActivity.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ public class CustomAdvancedMarkerClusteringDemoActivity extends BaseDemoActivity
5858
public void onMapsSdkInitialized(@NonNull MapsInitializer.Renderer renderer) {
5959
switch (renderer) {
6060
case LATEST:
61-
Log.d("MapsDemo", "The latest version of the renderer is used.");
61+
Log.d("MapsDemo", getString(R.string.renderer_latest));
6262
break;
6363
case LEGACY:
64-
Log.d("MapsDemo", "The legacy version of the renderer is used.");
64+
Log.d("MapsDemo", getString(R.string.renderer_legacy));
6565
break;
6666
default:
6767
break;
@@ -100,7 +100,7 @@ private PinConfig.Builder getPinConfig(Person person) {
100100
@SuppressLint("SetTextI18n")
101101
private View addTextAsMarker(int size) {
102102
TextView textView = new TextView(getApplicationContext());
103-
textView.setText("I am a cluster of size " + size);
103+
textView.setText(getString(R.string.cluster_text_fmt, size));
104104
textView.setBackgroundColor(Color.BLACK);
105105
textView.setTextColor(Color.YELLOW);
106106
return textView;
@@ -130,7 +130,8 @@ protected boolean shouldRenderAsCluster(@NonNull Cluster<Person> cluster) {
130130
public boolean onClusterClick(Cluster<Person> cluster) {
131131
// Show a toast with some info when the cluster is clicked.
132132
String firstName = cluster.getItems().iterator().next().name;
133-
Toast.makeText(this, cluster.getSize() + " (including " + firstName + ")", Toast.LENGTH_SHORT).show();
133+
Toast.makeText(this, getString(R.string.cluster_info_fmt, cluster.getSize(), firstName), Toast.LENGTH_SHORT)
134+
.show();
134135

135136
// Zoom in the cluster. Need to create LatLngBounds and including all the cluster items
136137
// inside of bounds, then animate to center of the bounds.

demo/src/main/java/com/google/maps/android/utils/demo/DistanceDemoActivity.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,28 +57,28 @@ protected void startDemo(boolean isRestore) {
5757
mMarkerB = getMap().addMarker(new MarkerOptions().position(new LatLng(-33.8291, 151.248)).draggable(true));
5858
mPolyline = getMap().addPolyline(new PolylineOptions().geodesic(true));
5959

60-
Toast.makeText(this, "Drag the markers!", Toast.LENGTH_LONG).show();
60+
Toast.makeText(this, getString(R.string.drag_the_markers), Toast.LENGTH_LONG).show();
6161
showDistance();
6262
}
6363

6464
@SuppressLint("SetTextI18n")
6565
private void showDistance() {
6666
double distance = SphericalUtil.computeDistanceBetween(mMarkerA.getPosition(), mMarkerB.getPosition());
67-
mTextView.setText("The markers are " + formatNumber(distance) + " apart.");
67+
mTextView.setText(getString(R.string.distance_format, formatNumber(distance)));
6868
}
6969

7070
private void updatePolyline() {
7171
mPolyline.setPoints(Arrays.asList(mMarkerA.getPosition(), mMarkerB.getPosition()));
7272
}
7373

7474
private String formatNumber(double distance) {
75-
String unit = "m";
75+
String unit = getString(R.string.unit_m);
7676
if (distance < 1) {
7777
distance *= 1000;
78-
unit = "mm";
78+
unit = getString(R.string.unit_mm);
7979
} else if (distance > 1000) {
8080
distance /= 1000;
81-
unit = "km";
81+
unit = getString(R.string.unit_km);
8282
}
8383

8484
return String.format("%4.3f%s", distance, unit);

demo/src/main/java/com/google/maps/android/utils/demo/MainActivity.java

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)