From 2c29d3b714e19aa2b0598d778a4bbd46ff5e90c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Paczos?= Date: Thu, 7 Jun 2018 13:43:05 +0200 Subject: [android] - parsing fragment's xml attributes --- .../com/mapbox/mapboxsdk/maps/MapFragment.java | 15 ++++++++ .../mapbox/mapboxsdk/maps/SupportMapFragment.java | 14 +++++++ .../src/main/res/layout/activity_multi_map.xml | 44 +++++++++++----------- 3 files changed, 51 insertions(+), 22 deletions(-) (limited to 'platform/android') diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java index 280877d61a..f1e057f060 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java @@ -5,9 +5,11 @@ import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; + import com.mapbox.mapboxsdk.utils.MapFragmentUtils; import java.util.ArrayList; @@ -55,6 +57,19 @@ public final class MapFragment extends Fragment implements OnMapReadyCallback { return mapFragment; } + /** + * Called when this fragment is inflated, parses XML tag attributes. + * + * @param context The context inflating this fragment. + * @param attrs The XML tag attributes. + * @param savedInstanceState The saved instance state for the map fragment. + */ + @Override + public void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState) { + super.onInflate(context, attrs, savedInstanceState); + setArguments(MapFragmentUtils.createFragmentArgs(MapboxMapOptions.createFromAttributes(context, attrs))); + } + /** * Called when the context attaches to this fragment. * diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java index 307b33b0c7..005e8b19d2 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java @@ -5,6 +5,7 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; +import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -69,6 +70,19 @@ public class SupportMapFragment extends Fragment implements OnMapReadyCallback { } } + /** + * Called when this fragment is inflated, parses XML tag attributes. + * + * @param context The context inflating this fragment. + * @param attrs The XML tag attributes. + * @param savedInstanceState The saved instance state for the map fragment. + */ + @Override + public void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState) { + super.onInflate(context, attrs, savedInstanceState); + setArguments(MapFragmentUtils.createFragmentArgs(MapboxMapOptions.createFromAttributes(context, attrs))); + } + /** * Creates the fragment view hierarchy. * diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_multi_map.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_multi_map.xml index 193ae55e59..51442894e1 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_multi_map.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_multi_map.xml @@ -1,17 +1,17 @@ - + tools:ignore="NestedWeights"> @@ -21,10 +21,10 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="0.5" - mapbox:center_latitude="38.913187" - mapbox:center_longitude="-77.032546" - mapbox:style_url="mapbox://styles/mapbox/streets-v10" - mapbox:zoom="12"/> + mapbox:mapbox_cameraTargetLat="38.913187" + mapbox:mapbox_cameraTargetLng="-77.032546" + mapbox:mapbox_cameraZoom="12" + mapbox:mapbox_styleUrl="mapbox://styles/mapbox/streets-v10" /> + mapbox:mapbox_cameraTargetLat="37.775732" + mapbox:mapbox_cameraTargetLng="-122.413985" + mapbox:mapbox_cameraZoom="13" + mapbox:mapbox_styleUrl="mapbox://styles/mapbox/outdoors-v10" /> @@ -53,10 +53,10 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="0.5" - mapbox:center_latitude="12.97913" - mapbox:center_longitude="77.59188" - mapbox:style_url="mapbox://styles/mapbox/light-v9" - mapbox:zoom="14"/> + mapbox:mapbox_cameraTargetLat="12.97913" + mapbox:mapbox_cameraTargetLng="77.59188" + mapbox:mapbox_cameraZoom="14" + mapbox:mapbox_styleUrl="mapbox://styles/mapbox/light-v9" /> + mapbox:mapbox_cameraTargetLat="-13.155980" + mapbox:mapbox_cameraTargetLng="-74.217134" + mapbox:mapbox_cameraZoom="15" + mapbox:mapbox_styleUrl="mapbox://styles/mapbox/dark-v9" /> -- cgit v1.2.1