package de.tudarmstadt.informatik.hostage.ui2.fragment; import android.app.AlertDialog; import android.app.Dialog; import android.app.Fragment; 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; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.CircleOptions; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; import de.tudarmstadt.informatik.hostage.R; import static com.google.android.gms.common.GooglePlayServicesUtil.*; /** * Created by fabio on 10.02.14. */ 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 * * @return true if the google play services are available */ private boolean isGooglePlay() { int status = isGooglePlayServicesAvailable(getActivity()); boolean result = status == ConnectionResult.SUCCESS; if (result == false) { getErrorDialog(status, getActivity(), 10).show(); } return result; } private void loadMapFragment() { // Get a handle to the Map 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); 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(); } return view; } }