Skip to content
Snippets Groups Projects
Commit 9c6cc0e1 authored by s22thong's avatar s22thong
Browse files

feat(UI): GoogleMaps Fragment

parent 4fc74f2a
Branches
No related tags found
1 merge request!1feat(UI): GoogleMaps Fragment
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
android:required="false" /> android:required="false" />
<uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<queries> <queries>
<intent> <intent>
......
...@@ -2,6 +2,7 @@ package fr.imt_atlantique.myfirstapplication; ...@@ -2,6 +2,7 @@ package fr.imt_atlantique.myfirstapplication;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
...@@ -18,6 +19,8 @@ import com.google.android.gms.maps.model.MarkerOptions; ...@@ -18,6 +19,8 @@ import com.google.android.gms.maps.model.MarkerOptions;
public class MapsFragment extends Fragment { public class MapsFragment extends Fragment {
private Toolbar toolbar;
private OnMapReadyCallback callback = new OnMapReadyCallback() { private OnMapReadyCallback callback = new OnMapReadyCallback() {
/** /**
...@@ -34,6 +37,9 @@ public class MapsFragment extends Fragment { ...@@ -34,6 +37,9 @@ public class MapsFragment extends Fragment {
LatLng sydney = new LatLng(-34, 151); LatLng sydney = new LatLng(-34, 151);
googleMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); googleMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
googleMap.getUiSettings().setZoomGesturesEnabled(true);
googleMap.getUiSettings().setCompassEnabled(true);
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
} }
}; };
...@@ -43,11 +49,14 @@ public class MapsFragment extends Fragment { ...@@ -43,11 +49,14 @@ public class MapsFragment extends Fragment {
@Nullable ViewGroup container, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) { @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_maps, container, false); return inflater.inflate(R.layout.fragment_maps, container, false);
} }
@Override @Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
toolbar = view.findViewById(R.id.mapsToolbar);
toolbar.inflateMenu(R.menu.menu_maps);
SupportMapFragment mapFragment = SupportMapFragment mapFragment =
(SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map); (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
if (mapFragment != null) { if (mapFragment != null) {
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<fragment 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:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map" android:id="@+id/mapsFragment"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".MapsFragment" /> android:fitsSystemWindows="true"
\ No newline at end of file tools:context=".MapsFragment">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="@color/black"
tools:ignore="MissingConstraints">
<androidx.appcompat.widget.Toolbar
android:id="@+id/mapsToolbar"
android:layout_width="match_parent"
android:layout_height="50dp"
app:title="@string/app_name"
app:titleTextColor="@color/white"/>
</com.google.android.material.appbar.AppBarLayout>
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/appBarLayout"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:context=".MapsFragment"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/MapTypeNormalAction"
android:title="@string/map_type_normal">
</item>
<item
android:id="@+id/MapTypeHybridAction"
android:title="@string/map_type_hybrid">
</item>
<item
android:id="@+id/MapTypeSatelliteAction"
android:title="@string/map_type_satellite">
</item>
</menu>
\ No newline at end of file
...@@ -31,4 +31,7 @@ ...@@ -31,4 +31,7 @@
<string name="open_wikipedia">Ouvrir Wikipédia</string> <string name="open_wikipedia">Ouvrir Wikipédia</string>
<string name="share">Partager</string> <string name="share">Partager</string>
<string name="error_first_name_empty">Le prénom ne peut pas être vide.</string> <string name="error_first_name_empty">Le prénom ne peut pas être vide.</string>
<string name="map_type_normal">Version normale</string>
<string name="map_type_hybrid">Version hybride</string>
<string name="map_type_satellite">Version satellite</string>
</resources> </resources>
\ No newline at end of file
...@@ -31,4 +31,8 @@ ...@@ -31,4 +31,8 @@
<string name="open_wikipedia">Open Wikipedia</string> <string name="open_wikipedia">Open Wikipedia</string>
<string name="share">Share</string> <string name="share">Share</string>
<string name="error_first_name_empty">The first name can not be empty.</string> <string name="error_first_name_empty">The first name can not be empty.</string>
<string name="map_type_normal">Normal version</string>
<string name="map_type_hybrid">Hydrid version</string>
<string name="map_type_satellite">Satellite version</string>
</resources> </resources>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment