blob: 2789e85ed80cc6a3ec0d239d9ec3b04b8deb42c3 (
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
package com.mapbox.mapboxsdk.maps;
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.utils.ApiAccess;
/**
* Fragment wrapper around a {@link MapView}.
* <p>
* A Map component in an app. This fragment is the simplest way to place a map in an application.
* It's a wrapper around a view of a map to automatically handle the necessary life cycle needs.
* Being a fragment, this component can be added to an activity's layout or can dynamically be added
* using a FragmentManager.
* </p>
* <p>
* To get a reference to the MapView, use {@link #getMapAsync(OnMapReadyCallback)}}
* </p>
*
* @see #getMapAsync(OnMapReadyCallback)
*/
public class MapFragment extends Fragment {
private MapView mMap;
public static MapFragment newInstance(){
return new MapFragment();
}
public static MapFragment newInstance(MapboxMapOptions mapboxMapOptions) {
final MapFragment mapFragment = new MapFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(MapboxConstants.FRAG_ARG_MAPBOXMAPOPTIONS, mapboxMapOptions);
mapFragment.setArguments(bundle);
return mapFragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
mMap = (MapView) inflater.inflate(R.layout.fragment_mapview, container, false);
mMap.setAccessToken(ApiAccess.getToken(inflater.getContext()));
mMap.onCreate(savedInstanceState);
return mMap;
}
@Override
public void onStart() {
super.onStart();
mMap.onStart();
}
@Override
public void onResume() {
super.onResume();
mMap.onResume();
}
@Override
public void onPause() {
super.onPause();
mMap.onPause();
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
mMap.onSaveInstanceState(outState);
super.onSaveInstanceState(outState);
}
@Override
public void onStop() {
super.onStop();
mMap.onStop();
}
@Override
public void onLowMemory() {
mMap.onLowMemory();
super.onLowMemory();
}
@Override
public void onDestroyView() {
super.onDestroyView();
mMap.onDestroy();
mMap = null;
}
@NonNull
public void getMapAsync(@NonNull OnMapReadyCallback onMapReadyCallback){
mMap.getMapAsync(onMapReadyCallback);
}
}
|