Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added material to samples #1991

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ApiDemos/java/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ limitations under the License.
android:icon="@mipmap/ic_launcher"
android:label="@string/demo_title"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/MaterialAppTheme">

<!--
To add your Maps API key to this project:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
Expand Down Expand Up @@ -52,12 +57,24 @@ public class AdvancedMarkersDemoActivity extends AppCompatActivity implements On
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.advanced_markers_demo);

SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
if (mapFragment != null) {
mapFragment.getMapAsync(this);
}
applyInsets(findViewById(R.id.map_container));
}

private static void applyInsets(View container) {
ViewCompat.setOnApplyWindowInsetsListener(container,
(view, insets) -> {
Insets innerPadding = insets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout());
view.setPadding(innerPadding.left, innerPadding.top, innerPadding.right, innerPadding.bottom);
return insets;
}
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.material.switchmaterial.SwitchMaterial;

/**
* This shows how to create a simple activity with a custom background color appiled to the map, and
Expand Down Expand Up @@ -52,7 +53,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
public void onMapReady(GoogleMap map) {
map.setMapType(GoogleMap.MAP_TYPE_NONE);

CheckBox mapTypeToggleCheckbox = (CheckBox) findViewById(R.id.map_type_toggle);
SwitchMaterial mapTypeToggleCheckbox = findViewById(R.id.map_type_toggle);
mapTypeToggleCheckbox.setOnCheckedChangeListener(
(view, isChecked) -> map.setMapType(isChecked ? GoogleMap.MAP_TYPE_NORMAL : GoogleMap.MAP_TYPE_NONE));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public void onMapReady(GoogleMap googleMap) {
}

// [START_EXCLUDE silent]

/**
* When the map is not ready the CameraUpdateFactory cannot be used. This should be called on
* all entry points that call methods on the Google Maps API.
Expand Down
27 changes: 23 additions & 4 deletions ApiDemos/java/app/src/main/res/layout/advanced_markers_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,36 @@
limitations under the License.
-->

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map_container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!--We need to add the map id to make advanced markers work. For more information,
check out https://developers.google.com/maps/documentation/get-map-id#create-a-map-id. -->
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/top_bar"
style="@style/Widget.MaterialComponents.Toolbar.Primary"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:title="@string/advanced_markers_demo_label"
app:titleTextColor="?attr/colorOnPrimary" />

<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/top_bar"
map:backgroundColor="#fff0b2dd"
map:mapId="@string/map_id"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
map:mapId="@string/map_id" />

</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,49 @@
limitations under the License.
-->

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/top_bar"
style="@style/Widget.MaterialComponents.Toolbar.Primary"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:title="@string/background_color_customization_demo_label"
app:titleTextColor="?attr/colorOnPrimary" />

<androidx.fragment.app.FragmentContainerView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_height="0dp"
map:backgroundColor="#fff0b2dd"
class="com.google.android.gms.maps.SupportMapFragment"/>
<FrameLayout
class="com.google.android.gms.maps.SupportMapFragment"
app:layout_constraintTop_toBottomOf="@+id/top_bar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#D000"
android:padding="5dp">
<CheckBox
android:orientation="horizontal"
android:layout_margin="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/map_type_toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingRight="5dp"
android:checked="false"
android:text="@string/show_map_tiles"/>
</FrameLayout>
</RelativeLayout>
android:layout_height="48dp"
android:text="@string/show_map_tiles"
android:checked="false"/>
</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,65 @@
limitations under the License.
-->

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<!--
Copyright 2021 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
you may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#D000"
android:padding="5dp">
<CheckBox
android:id="@+id/map_type_toggle"
android:layout_height="match_parent">

<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/top_bar" />

<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingRight="5dp"
android:checked="false"
android:text="@string/show_map_tiles"/>
</FrameLayout>
</FrameLayout>
android:background="#D000"
android:padding="5dp"
app:layout_constraintBottom_toBottomOf="@+id/map"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/map_type_toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/white"
android:checked="false"
android:paddingEnd="5dp"
android:text="@string/show_map_tiles" />
</FrameLayout>

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/top_bar"
style="@style/Widget.MaterialComponents.Toolbar.Primary"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:title="@string/background_color_customization_programmatic_demo_label"
app:titleTextColor="?attr/colorOnPrimary" />
</androidx.constraintlayout.widget.ConstraintLayout>
34 changes: 27 additions & 7 deletions ApiDemos/java/app/src/main/res/layout/basic_demo.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2025 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,9 +13,30 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- This can go anywhere in your layout (see other demos for some examples). -->
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/map_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
android:layout_height="match_parent">

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/top_bar"
style="@style/Widget.MaterialComponents.Toolbar.Primary"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:title="@string/basic_map_demo_label"
app:titleTextColor="?attr/colorOnPrimary" />

<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/top_bar" />
</androidx.constraintlayout.widget.ConstraintLayout>
Loading