Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - parsing fragment's xml attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Łukasz Paczos committed Jun 7, 2018
1 parent 2da57bd commit 2c29d3b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
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;
Expand Down Expand Up @@ -55,6 +57,19 @@ public static MapFragment newInstance(@Nullable MapboxMapOptions mapboxMapOption
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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
Expand Down Expand Up @@ -69,6 +70,19 @@ public void onAttach(Context context) {
}
}

/**
* 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.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mapbox="http://schemas.android.com/tools"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
mapbox:ignore="NestedWeights">
tools:ignore="NestedWeights">

<LinearLayout
android:baselineAligned="false"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:baselineAligned="false"
android:orientation="horizontal">

<!-- DC -->
Expand All @@ -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" />

<!-- SF -->
<fragment
Expand All @@ -33,17 +33,17 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
mapbox:center_latitude="37.775732"
mapbox:center_longitude="-122.413985"
mapbox:style_url="mapbox://styles/mapbox/outdoors-v10"
mapbox:zoom="13"/>
mapbox:mapbox_cameraTargetLat="37.775732"
mapbox:mapbox_cameraTargetLng="-122.413985"
mapbox:mapbox_cameraZoom="13"
mapbox:mapbox_styleUrl="mapbox://styles/mapbox/outdoors-v10" />
</LinearLayout>

<LinearLayout
android:baselineAligned="false"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:baselineAligned="false"
android:orientation="horizontal">

<!-- Bangalore -->
Expand All @@ -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" />

<!-- Ayacucho -->
<fragment
Expand All @@ -65,9 +65,9 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
mapbox:center_latitude="-13.155980"
mapbox:center_longitude="-74.217134"
mapbox:style_url="mapbox://styles/mapbox/dark-v9"
mapbox:zoom="15"/>
mapbox:mapbox_cameraTargetLat="-13.155980"
mapbox:mapbox_cameraTargetLng="-74.217134"
mapbox:mapbox_cameraZoom="15"
mapbox:mapbox_styleUrl="mapbox://styles/mapbox/dark-v9" />
</LinearLayout>
</LinearLayout>

0 comments on commit 2c29d3b

Please sign in to comment.