Skip to content

Commit 6ed3671

Browse files
committed
feat: added Java samples
1 parent 53692d7 commit 6ed3671

38 files changed

Lines changed: 3392 additions & 17 deletions

Maps3DSamples/ApiDemos/common/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
alias(libs.plugins.android.library)
33
alias(libs.plugins.kotlin.android)
4+
alias(libs.plugins.kotlin.compose)
45
}
56

67
android {
@@ -45,6 +46,10 @@ dependencies {
4546
testImplementation(libs.junit)
4647
androidTestImplementation(libs.androidx.junit)
4748
androidTestImplementation(libs.androidx.espresso.core)
49+
implementation(platform(libs.androidx.compose.bom))
50+
implementation(libs.androidx.lifecycle.runtime.ktx)
51+
52+
implementation(libs.androidx.material3)
4853

4954
implementation("com.google.android.gms:play-services-maps3d:0.0.1")
5055
}

Maps3DSamples/ApiDemos/kotlin-app/src/main/java/com/example/maps3dkotlin/common/CameraUpdate.kt renamed to Maps3DSamples/ApiDemos/common/src/main/java/com/example/maps3d/common/CameraUpdate.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package com.example.maps3dkotlin.common
15+
package com.example.maps3d.common
1616

1717
import com.google.android.gms.maps3d.GoogleMap3D
1818
import com.google.android.gms.maps3d.OnCameraAnimationEndListener

Maps3DSamples/ApiDemos/kotlin-app/src/main/java/com/example/maps3dkotlin/common/Units.kt renamed to Maps3DSamples/ApiDemos/common/src/main/java/com/example/maps3d/common/Units.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package com.example.maps3dkotlin.common
15+
package com.example.maps3d.common
1616

1717

1818
import android.content.res.Resources
@@ -22,7 +22,7 @@ import androidx.compose.runtime.Immutable
2222
import androidx.compose.runtime.Stable
2323
import androidx.compose.runtime.compositionLocalOf
2424
import androidx.compose.ui.res.stringResource
25-
import com.example.maps3dkotlin.R
25+
import com.example.maps3dcommon.R
2626

2727
const val METERS_PER_FOOT = 3.28084
2828
const val METERS_PER_KILOMETER = 1_000

Maps3DSamples/ApiDemos/kotlin-app/src/main/java/com/example/maps3dkotlin/common/Utilities.kt renamed to Maps3DSamples/ApiDemos/common/src/main/java/com/example/maps3d/common/Utilities.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package com.example.maps3dkotlin.common
15+
package com.example.maps3d.common
1616

1717
import com.google.android.gms.maps3d.model.Camera
1818
import com.google.android.gms.maps3d.model.LatLngAltitude

Maps3DSamples/ApiDemos/common/src/main/res/values/strings.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,30 @@
5656
<string name="snapshot_camera">Snapshot</string>
5757
<string name="stop_camera">Stop camera animations</string>
5858

59+
60+
<!--
61+
Distance in feet, formatted to 0 decimal places.
62+
For example, 1234.56 feet will be formatted as "1,235 ft".
63+
-->
64+
<string name="in_feet" translatable="false">%1$,.0f ft</string>
65+
66+
<!--
67+
Distance in miles, formatted to 1 decimal place.
68+
For example, 1.2345 miles will be formatted as "1.2 miles".
69+
-->
70+
<string name="in_miles" translatable="false">%1$,.1f miles</string>
71+
72+
<!--
73+
Distance in meters, formatted to 0 decimal places.
74+
For example, 1234.56 meters will be formatted as "1,235 m".
75+
-->
76+
<string name="in_meters" translatable="false">%1$,.0f m</string>
77+
78+
<!--
79+
Distance in kilometers, formatted to 1 decimal place.
80+
For example, 1.2345 kilometers will be formatted as "1.2 km".
81+
-->
82+
<string name="in_kilometers" translatable="false">%1$,.1f km</string>
83+
84+
5985
</resources>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
plugins {
2+
alias(libs.plugins.android.application)
3+
alias(libs.plugins.kotlin.android)
4+
alias(libs.plugins.kotlin.compose)
5+
alias(libs.plugins.secrets.gradle.plugin)
6+
}
7+
8+
android {
9+
lint {
10+
sarifOutput = file("$buildDir/reports/lint-results.sarif")
11+
}
12+
namespace = "com.example.maps3djava"
13+
compileSdk = 35
14+
15+
defaultConfig {
16+
applicationId = "com.example.maps3djava"
17+
minSdk = 26
18+
targetSdk = 35
19+
versionCode = 1
20+
versionName = "1.0"
21+
22+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
23+
}
24+
25+
buildTypes {
26+
release {
27+
isMinifyEnabled = false
28+
proguardFiles(
29+
getDefaultProguardFile("proguard-android-optimize.txt"),
30+
"proguard-rules.pro"
31+
)
32+
}
33+
}
34+
compileOptions {
35+
isCoreLibraryDesugaringEnabled = true
36+
sourceCompatibility = JavaVersion.VERSION_11
37+
targetCompatibility = JavaVersion.VERSION_11
38+
}
39+
kotlinOptions {
40+
jvmTarget = "11"
41+
}
42+
buildFeatures {
43+
compose = true
44+
}
45+
}
46+
47+
dependencies {
48+
coreLibraryDesugaring(libs.desugar.jdk.libs)
49+
50+
implementation(libs.androidx.core.ktx)
51+
implementation(libs.androidx.appcompat)
52+
implementation(libs.material)
53+
implementation(libs.androidx.lifecycle.runtime.ktx)
54+
implementation(libs.androidx.activity.compose)
55+
implementation(platform(libs.androidx.compose.bom))
56+
implementation(libs.androidx.ui)
57+
implementation(libs.androidx.ui.graphics)
58+
implementation(libs.androidx.ui.tooling.preview)
59+
implementation(libs.androidx.material3)
60+
testImplementation(libs.junit)
61+
androidTestImplementation(libs.androidx.junit)
62+
androidTestImplementation(libs.androidx.espresso.core)
63+
androidTestImplementation(platform(libs.androidx.compose.bom))
64+
androidTestImplementation(libs.androidx.ui.test.junit4)
65+
debugImplementation(libs.androidx.ui.tooling)
66+
debugImplementation(libs.androidx.ui.test.manifest)
67+
68+
implementation(libs.play.services.maps3d)
69+
70+
implementation(project(":common"))
71+
}
72+
73+
secrets {
74+
// Optionally specify a different file name containing your secrets.
75+
// The plugin defaults to "local.properties"
76+
propertiesFileName = "secrets.properties"
77+
78+
// A properties file containing default secret values. This file can be
79+
// checked in version control.
80+
defaultPropertiesFileName = "local.defaults.properties"
81+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2025 Google LLC
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:tools="http://schemas.android.com/tools">
19+
20+
<application
21+
android:name="com.example.maps3djava.Maps3DJavaApplication"
22+
android:allowBackup="true"
23+
android:dataExtractionRules="@xml/data_extraction_rules"
24+
android:fullBackupContent="@xml/backup_rules"
25+
android:icon="@mipmap/ic_launcher"
26+
android:label="@string/app_name"
27+
android:roundIcon="@mipmap/ic_launcher_round"
28+
android:supportsRtl="true"
29+
android:theme="@style/Theme.Maps3DSamples"
30+
tools:targetApi="31">
31+
32+
<meta-data
33+
android:name="com.google.android.geo.maps3d.API_KEY"
34+
android:value="${MAPS3D_API_KEY}"
35+
/>
36+
37+
<activity
38+
android:name="com.example.maps3djava.mainactivity.MainActivity"
39+
android:exported="true"
40+
android:label="@string/title_activity_main"
41+
android:theme="@style/Theme.Maps3DSamples">
42+
<intent-filter>
43+
<action android:name="android.intent.action.MAIN" />
44+
45+
<category android:name="android.intent.category.LAUNCHER" />
46+
</intent-filter>
47+
</activity>
48+
49+
<activity
50+
android:name="com.example.maps3djava.hellomap.HelloMapActivity"
51+
android:theme="@style/Theme.Maps3DSamples"
52+
android:label="@string/feature_title_overview_hello_3d_map"
53+
android:exported="true"
54+
/>
55+
56+
<activity
57+
android:name="com.example.maps3djava.cameracontrols.CameraControlsActivity"
58+
android:theme="@style/Theme.Maps3DSamples"
59+
android:label="@string/feature_title_camera_controls"
60+
android:exported="true"
61+
/>
62+
63+
<activity
64+
android:name="com.example.maps3djava.markers.MarkersActivity"
65+
android:theme="@style/Theme.Maps3DSamples"
66+
android:label="@string/feature_title_markers"
67+
android:exported="true"
68+
/>
69+
70+
<activity
71+
android:name="com.example.maps3djava.polygons.PolygonsActivity"
72+
android:theme="@style/Theme.Maps3DSamples"
73+
android:label="@string/feature_title_polygons"
74+
android:exported="true"
75+
/>
76+
77+
<activity
78+
android:name="com.example.maps3djava.polylines.PolylinesActivity"
79+
android:theme="@style/Theme.Maps3DSamples"
80+
android:label="@string/feature_title_polylines"
81+
android:exported="true"
82+
/>
83+
84+
<activity
85+
android:name="com.example.maps3djava.models.ModelsActivity"
86+
android:theme="@style/Theme.Maps3DSamples"
87+
android:label="@string/feature_title_3d_models"
88+
android:exported="true"
89+
/>
90+
91+
</application>
92+
93+
</manifest>
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.example.maps3djava;
16+
17+
import android.app.Application;
18+
import android.content.pm.ApplicationInfo;
19+
import android.content.pm.PackageManager;
20+
import android.os.Bundle;
21+
import android.util.Log;
22+
import android.widget.Toast;
23+
24+
import java.util.Objects;
25+
26+
/**
27+
* `Maps3DKotlinApplication` is a custom Application class for the API demo.
28+
*
29+
* This class is responsible for application-wide initialization and setup,
30+
* such as checking for the presence and validity of the API key during the
31+
* application's startup.
32+
*
33+
* It extends the [Application] class and overrides the [.onCreate]
34+
* method to perform these initialization tasks.
35+
*/
36+
public class Maps3DJavaApplication extends Application {
37+
private final String TAG = this.getClass().getSimpleName();
38+
39+
/**
40+
* Called when the application is starting, before any activity, service,
41+
* or receiver objects (excluding content providers) have been created.
42+
* This is where application-wide initialization should be performed.
43+
*/
44+
@Override
45+
public void onCreate() {
46+
super.onCreate();
47+
checkApiKey();
48+
}
49+
50+
/**
51+
* Checks if the API key for Google Maps is properly configured in the application's metadata.
52+
*
53+
* This method retrieves the API key from the application's metadata, specifically looking for
54+
* a string value associated with the key "com.google.android.geo.maps3d.API_KEY".
55+
* The key must be present, not blank, and not set to the placeholder value "DEFAULT_API_KEY".
56+
*
57+
* If any of these checks fail, a Toast message is displayed indicating that the API key is missing or
58+
* incorrectly configured, and a RuntimeException is thrown.
59+
*/
60+
private void checkApiKey() {
61+
try {
62+
// Get the application's info, including its meta-data.
63+
ApplicationInfo appInfo =
64+
getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
65+
// Ensure the meta-data bundle is not null.
66+
Bundle bundle = Objects.requireNonNull(appInfo.metaData);
67+
68+
// Retrieve the API key string from the bundle. The key name is crucial.
69+
String apiKey =
70+
bundle.getString("com.google.android.geo.maps3d.API_KEY"); // Key name is important!
71+
72+
// Check if the API key is null, blank, or still the default placeholder value.
73+
if (apiKey == null || apiKey.isBlank() || apiKey.equals("DEFAULT_API_KEY")) {
74+
// Display a Toast message to the user indicating the API key issue.
75+
Toast.makeText(
76+
this,
77+
"API Key was not set in secrets.properties",
78+
Toast.LENGTH_LONG
79+
).show();
80+
// Throw a RuntimeException to halt the application if the API key is misconfigured.
81+
throw new RuntimeException("API Key was not set in secrets.properties");
82+
}
83+
} catch (PackageManager.NameNotFoundException e) {
84+
// Log an error if the package name is not found (should not happen in a running app).
85+
Log.e(TAG, "Package name not found.", e);
86+
// Re-throw as a RuntimeException as this is a critical application setup issue.
87+
throw new RuntimeException("Error getting package info.", e);
88+
} catch (NullPointerException e) {
89+
// Log an error if meta-data is completely missing from the application info.
90+
Log.e(TAG, "Error accessing meta-data.", e); // Handle the case where meta-data is completely missing.
91+
// Re-throw as a RuntimeException.
92+
throw new RuntimeException("Error accessing meta-data in manifest", e);
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)