Skip to content

Commit 3198483

Browse files
committed
chore: added Fragment sample
1 parent b825285 commit 3198483

File tree

8 files changed

+75
-0
lines changed

8 files changed

+75
-0
lines changed

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ mapsecrets = "2.0.1"
1818
mapsktx = "5.2.0"
1919
org-jacoco-core = "0.8.12"
2020
screenshot = "0.0.1-alpha10"
21+
constraintlayout = "2.2.1"
2122

2223
[libraries]
2324
android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "agp" }
@@ -48,6 +49,7 @@ maps-ktx-utils = { module = "com.google.maps.android:maps-utils-ktx", version.re
4849
maps-secrets-plugin = { module = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin", version.ref = "mapsecrets" }
4950
org-jacoco-core = { module = "org.jacoco:org.jacoco.core", version.ref = "org-jacoco-core" }
5051
test-junit = { module = "junit:junit", version.ref = "junit" }
52+
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
5153

5254
[plugins]
5355
android-application = { id = "com.android.application", version.ref = "agp" }

maps-app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ dependencies {
6565
implementation(libs.kotlin)
6666
implementation(libs.kotlinx.coroutines.android)
6767
implementation(libs.androidx.compose.ui.preview.tooling)
68+
implementation(libs.androidx.constraintlayout)
6869
debugImplementation(libs.androidx.compose.ui.tooling)
6970
debugImplementation(libs.leakcanary.android)
7071

maps-app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272
<activity
7373
android:name=".RecompositionActivity"
7474
android:exported="false"/>
75+
<activity
76+
android:name=".FragmentDemoActivity"
77+
android:exported="false"/>
7578
<activity
7679
android:name=".markerexamples.markerdragevents.MarkerDragEventsActivity"
7780
android:exported="false"/>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.google.maps.android.compose
2+
3+
import android.os.Bundle
4+
import androidx.fragment.app.FragmentActivity
5+
6+
class FragmentDemoActivity : FragmentActivity() {
7+
8+
override fun onCreate(savedInstanceState: Bundle?) {
9+
super.onCreate(savedInstanceState)
10+
setContentView(R.layout.activity_main)
11+
}
12+
}

maps-app/src/main/java/com/google/maps/android/compose/MainActivity.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ class MainActivity : ComponentActivity() {
199199
}) {
200200
Text(getString(R.string.draggable_markers_collection_with_polygon))
201201
}
202+
Spacer(modifier = Modifier.padding(5.dp))
203+
Button(
204+
onClick = {
205+
context.startActivity(Intent(context, FragmentDemoActivity::class.java))
206+
}) {
207+
Text(getString(R.string.fragment_demo_activity))
208+
}
202209
}
203210
}
204211
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.google.maps.android.compose
2+
3+
import android.os.Bundle
4+
import android.view.LayoutInflater
5+
import android.view.View
6+
import android.view.ViewGroup
7+
import androidx.compose.material.MaterialTheme
8+
import androidx.compose.material.Text
9+
import androidx.compose.ui.platform.ComposeView
10+
import androidx.fragment.app.Fragment
11+
12+
13+
class MainFragment : Fragment() {
14+
override fun onCreateView(
15+
inflater: LayoutInflater,
16+
container: ViewGroup?,
17+
savedInstanceState: Bundle?
18+
): View = ComposeView(requireContext()).apply {
19+
setContent {
20+
MaterialTheme {
21+
GoogleMap {
22+
MarkerComposable {
23+
Text(text = "Hello, World!")
24+
}
25+
}
26+
}
27+
}
28+
}
29+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
android:id="@+id/container"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent"
8+
tools:context=".MainActivity">
9+
10+
<androidx.fragment.app.FragmentContainerView
11+
android:layout_width="match_parent"
12+
android:layout_height="match_parent"
13+
android:id="@+id/viewFragment"
14+
android:name="com.google.maps.android.compose.MainFragment"
15+
app:layout_constraintTop_toTopOf="parent"
16+
app:layout_constraintBottom_toBottomOf="parent"
17+
app:layout_constraintStart_toStartOf="parent"
18+
app:layout_constraintEnd_toEndOf="parent" />
19+
20+
</androidx.constraintlayout.widget.ConstraintLayout>

maps-app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<string name="syncing_draggable_marker_with_data_model">Syncing Draggable Marker With Model</string>
2929
<string name="updating_non_draggable_marker_with_data_model">Updating Non-Draggable Marker With Model</string>
3030
<string name="draggable_markers_collection_with_polygon">Polygon around draggable markers</string>
31+
<string name="fragment_demo_activity">Fragment Demo Activity</string>
3132
<string name="recomposition_activity">Recomposition Map</string>
3233
<string name="street_view">Street View</string>
3334
<string name="custom_location_button">Custom Location Button</string>

0 commit comments

Comments
 (0)