blob: 884e0a42bef16db15f75ca045a84f9e4ba6f6b58 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
package com.mapbox.mapboxsdk.utils;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
/**
* MapFragment utility class.
* <p>
* Used to extract duplicate code between {@link com.mapbox.mapboxsdk.maps.MapFragment} and
* {@link com.mapbox.mapboxsdk.maps.SupportMapFragment}.
* </p>
*/
public class MapFragmentUtils {
/**
* Convert MapboxMapOptions to a bundle of fragment arguments.
*
* @param options The MapboxMapOptions to convert
* @return a bundle of converted fragment arguments
*/
@NonNull
public static Bundle createFragmentArgs(MapboxMapOptions options) {
Bundle bundle = new Bundle();
bundle.putParcelable(MapboxConstants.FRAG_ARG_MAPBOXMAPOPTIONS, options);
return bundle;
}
/**
* Convert a bundle of fragment arguments to MapboxMapOptions.
*
* @param context The context of the activity hosting the fragment
* @param args The fragment arguments
* @return converted MapboxMapOptions
*/
@Nullable
public static MapboxMapOptions resolveArgs(@NonNull Context context, @Nullable Bundle args) {
MapboxMapOptions options;
if (args != null && args.containsKey(MapboxConstants.FRAG_ARG_MAPBOXMAPOPTIONS)) {
options = args.getParcelable(MapboxConstants.FRAG_ARG_MAPBOXMAPOPTIONS);
} else {
// load default options
options = MapboxMapOptions.createFromAttributes(context);
}
return options;
}
}
|