|
@@ -7,6 +7,7 @@ import android.content.Context;
|
|
|
import android.content.DialogInterface;
|
|
|
import android.graphics.Color;
|
|
|
import android.os.Bundle;
|
|
|
+import android.view.InflateException;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
@@ -28,6 +29,7 @@ import static com.google.android.gms.common.GooglePlayServicesUtil.*;
|
|
|
*/
|
|
|
public class ThreatMapFragment extends Fragment {
|
|
|
private GoogleMap map = null;
|
|
|
+ private static View view = null;
|
|
|
|
|
|
/**
|
|
|
* if google play services aren't available an error notification will be displayed
|
|
@@ -48,21 +50,31 @@ public class ThreatMapFragment extends Fragment {
|
|
|
MapFragment mapFragment = (MapFragment) getFragmentManager()
|
|
|
.findFragmentById(R.id.threatmapfragment);
|
|
|
map = mapFragment.getMap();
|
|
|
+
|
|
|
+ LatLng mapCenter = new LatLng(41.889, -87.622);
|
|
|
+ map.moveCamera(CameraUpdateFactory.newLatLngZoom(mapCenter, 13));
|
|
|
+ map.addCircle(new CircleOptions().center(mapCenter).radius(200.0).fillColor(Color.argb(127, 240, 80, 60)).strokeWidth(0.0f));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
Bundle savedInstanceState) {
|
|
|
- //super.onCreateView(inflater, container, savedInstanceState);
|
|
|
- View rootView = inflater.inflate(R.layout.fragment_threatmap, container, false);
|
|
|
+ super.onCreateView(inflater, container, savedInstanceState);
|
|
|
+ if (view != null) {
|
|
|
+ ViewGroup parent = (ViewGroup) view.getParent();
|
|
|
+ if (parent != null)
|
|
|
+ parent.removeView(view);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ view = inflater.inflate(R.layout.fragment_threatmap, container, false);
|
|
|
+ } catch (InflateException e) {
|
|
|
+ /* map is already there, just return view as it is */
|
|
|
+ }
|
|
|
+
|
|
|
if (isGooglePlay()) {
|
|
|
loadMapFragment();
|
|
|
}
|
|
|
- if (map != null) {
|
|
|
- LatLng mapCenter = new LatLng(41.889, -87.622);
|
|
|
- map.moveCamera(CameraUpdateFactory.newLatLngZoom(mapCenter, 13));
|
|
|
- map.addCircle(new CircleOptions().center(mapCenter).radius(200.0).fillColor(Color.argb(127, 240, 80, 60)).strokeWidth(0.0f));
|
|
|
- }
|
|
|
- return rootView;
|
|
|
+
|
|
|
+ return view;
|
|
|
}
|
|
|
}
|