Browse Source

fixed threat map crash. YEAAAAAH

Fabio Arnold 10 years ago
parent
commit
52612a3d68

+ 6 - 0
src/de/tudarmstadt/informatik/hostage/ui2/fragment/RecordOverviewFragment.java

@@ -29,6 +29,7 @@ import java.util.Collections;
 import java.util.Comparator;
 import java.util.Comparator;
 import java.util.Date;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.HashMap;
+import java.util.Random;
 
 
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.logging.Record;
 import de.tudarmstadt.informatik.hostage.logging.Record;
@@ -606,6 +607,8 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 		int maxProtocolsIndex = this.getResources().getStringArray(
 		int maxProtocolsIndex = this.getResources().getStringArray(
 				R.array.protocols).length;
 				R.array.protocols).length;
 
 
+		Random random = new Random();
+
 		int numberofRecords = (int) (Math.random() * (50 - 10));
 		int numberofRecords = (int) (Math.random() * (50 - 10));
 		for (int i = 0; i < numberofRecords; i++) {
 		for (int i = 0; i < numberofRecords; i++) {
 			Record record = new Record();
 			Record record = new Record();
@@ -625,6 +628,9 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 			record.setLocalIP("127.0.0.1");
 			record.setLocalIP("127.0.0.1");
 			record.setType(TYPE.SEND);
 			record.setType(TYPE.SEND);
 
 
+			record.setLatitude(41.889 + random.nextDouble());
+			record.setLongitude(-87.622 + random.nextDouble());
+
 			dbh.addRecord(record);
 			dbh.addRecord(record);
 		}
 		}
 
 

+ 20 - 8
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ThreatMapFragment.java

@@ -7,6 +7,7 @@ import android.content.Context;
 import android.content.DialogInterface;
 import android.content.DialogInterface;
 import android.graphics.Color;
 import android.graphics.Color;
 import android.os.Bundle;
 import android.os.Bundle;
+import android.view.InflateException;
 import android.view.LayoutInflater;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.ViewGroup;
@@ -28,6 +29,7 @@ import static com.google.android.gms.common.GooglePlayServicesUtil.*;
  */
  */
 public class ThreatMapFragment extends Fragment {
 public class ThreatMapFragment extends Fragment {
 	private GoogleMap map = null;
 	private GoogleMap map = null;
+	private static View view = null;
 
 
 	/**
 	/**
 	 * if google play services aren't available an error notification will be displayed
 	 * 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()
 		MapFragment mapFragment = (MapFragment) getFragmentManager()
 				.findFragmentById(R.id.threatmapfragment);
 				.findFragmentById(R.id.threatmapfragment);
 		map = mapFragment.getMap();
 		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
 	@Override
 	public View onCreateView(LayoutInflater inflater, ViewGroup container,
 	public View onCreateView(LayoutInflater inflater, ViewGroup container,
 	                         Bundle savedInstanceState) {
 	                         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()) {
 		if (isGooglePlay()) {
 			loadMapFragment();
 			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;
 	}
 	}
 }
 }