ThreatMapFragment.java 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package de.tudarmstadt.informatik.hostage.ui2.fragment;
  2. import android.app.AlertDialog;
  3. import android.app.Dialog;
  4. import android.app.Fragment;
  5. import android.content.Context;
  6. import android.content.DialogInterface;
  7. import android.graphics.Color;
  8. import android.os.Bundle;
  9. import android.view.InflateException;
  10. import android.view.LayoutInflater;
  11. import android.view.View;
  12. import android.view.ViewGroup;
  13. import com.google.android.gms.common.ConnectionResult;
  14. import com.google.android.gms.maps.CameraUpdateFactory;
  15. import com.google.android.gms.maps.GoogleMap;
  16. import com.google.android.gms.maps.MapFragment;
  17. import com.google.android.gms.maps.model.CircleOptions;
  18. import com.google.android.gms.maps.model.LatLng;
  19. import com.google.android.gms.maps.model.MarkerOptions;
  20. import de.tudarmstadt.informatik.hostage.R;
  21. import static com.google.android.gms.common.GooglePlayServicesUtil.*;
  22. /**
  23. * Created by fabio on 10.02.14.
  24. */
  25. public class ThreatMapFragment extends Fragment {
  26. private GoogleMap map = null;
  27. private static View view = null;
  28. /**
  29. * if google play services aren't available an error notification will be displayed
  30. *
  31. * @return true if the google play services are available
  32. */
  33. private boolean isGooglePlay() {
  34. int status = isGooglePlayServicesAvailable(getActivity());
  35. boolean result = status == ConnectionResult.SUCCESS;
  36. if (result == false) {
  37. getErrorDialog(status, getActivity(), 10).show();
  38. }
  39. return result;
  40. }
  41. private void loadMapFragment() {
  42. // Get a handle to the Map Fragment
  43. MapFragment mapFragment = (MapFragment) getFragmentManager()
  44. .findFragmentById(R.id.threatmapfragment);
  45. map = mapFragment.getMap();
  46. LatLng mapCenter = new LatLng(41.889, -87.622);
  47. map.moveCamera(CameraUpdateFactory.newLatLngZoom(mapCenter, 13));
  48. map.addCircle(new CircleOptions().center(mapCenter).radius(200.0).fillColor(Color.argb(127, 240, 80, 60)).strokeWidth(0.0f));
  49. }
  50. @Override
  51. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  52. Bundle savedInstanceState) {
  53. super.onCreateView(inflater, container, savedInstanceState);
  54. if (view != null) {
  55. ViewGroup parent = (ViewGroup) view.getParent();
  56. if (parent != null)
  57. parent.removeView(view);
  58. }
  59. try {
  60. view = inflater.inflate(R.layout.fragment_threatmap, container, false);
  61. } catch (InflateException e) {
  62. /* map is already there, just return view as it is */
  63. }
  64. if (isGooglePlay()) {
  65. loadMapFragment();
  66. }
  67. return view;
  68. }
  69. }