|
@@ -7,6 +7,7 @@ import android.content.Context;
|
|
|
import android.content.DialogInterface;
|
|
|
import android.graphics.Color;
|
|
|
import android.os.Bundle;
|
|
|
+import android.util.Log;
|
|
|
import android.view.InflateException;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
@@ -18,6 +19,7 @@ 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.Marker;
|
|
|
import com.google.android.gms.maps.model.MarkerOptions;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
@@ -31,12 +33,10 @@ import static com.google.android.gms.common.GooglePlayServicesUtil.*;
|
|
|
/**
|
|
|
* Created by fabio on 10.02.14.
|
|
|
*/
|
|
|
-public class ThreatMapFragment extends Fragment {
|
|
|
- private GoogleMap map = null;
|
|
|
+public class ThreatMapFragment extends Fragment implements GoogleMap.OnMarkerClickListener {
|
|
|
+ private static GoogleMap map = null;
|
|
|
private static View view = null;
|
|
|
|
|
|
- private UglyDbHelper dbh;
|
|
|
-
|
|
|
/**
|
|
|
* if google play services aren't available an error notification will be displayed
|
|
|
*
|
|
@@ -51,21 +51,26 @@ public class ThreatMapFragment extends Fragment {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- private void loadMapFragment() {
|
|
|
- // Get a handle to the Map Fragment
|
|
|
- MapFragment mapFragment = (MapFragment) getFragmentManager()
|
|
|
- .findFragmentById(R.id.threatmapfragment);
|
|
|
- map = mapFragment.getMap();
|
|
|
+ @Override
|
|
|
+ public boolean onMarkerClick(Marker marker) {
|
|
|
+ Log.i("MARKER", ""+marker.getId());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- dbh = new UglyDbHelper(getActivity());
|
|
|
+ private void populateMap() {
|
|
|
+ UglyDbHelper dbh = new UglyDbHelper(getActivity());
|
|
|
ArrayList<Record> records = dbh.getAllRecords();
|
|
|
|
|
|
CircleOptions circleOptions = new CircleOptions().radius(200.0).fillColor(Color.argb(127, 240, 80, 60)).strokeWidth(0.0f);
|
|
|
for (Record record : records) {
|
|
|
LatLng location = new LatLng(record.getLatitude(), record.getLongitude());
|
|
|
map.addCircle(circleOptions.center(location));
|
|
|
+ map.addMarker(new MarkerOptions().title(record.getSsid()).position(location));
|
|
|
}
|
|
|
|
|
|
+ map.setMyLocationEnabled(true);
|
|
|
+ map.setOnMarkerClickListener(this);
|
|
|
+
|
|
|
LatLng tudarmstadt = new LatLng(49.86923, 8.6632768);
|
|
|
//LatLng mapCenter = new LatLng(41.889, -87.622);
|
|
|
map.moveCamera(CameraUpdateFactory.newLatLngZoom(tudarmstadt, 13));
|
|
@@ -75,6 +80,7 @@ public class ThreatMapFragment extends Fragment {
|
|
|
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)
|
|
@@ -82,12 +88,13 @@ public class ThreatMapFragment extends Fragment {
|
|
|
}
|
|
|
try {
|
|
|
view = inflater.inflate(R.layout.fragment_threatmap, container, false);
|
|
|
+ if (isGooglePlay()) {
|
|
|
+ map = ((MapFragment) getFragmentManager()
|
|
|
+ .findFragmentById(R.id.threatmapfragment)).getMap();
|
|
|
+ populateMap();
|
|
|
+ }
|
|
|
} catch (InflateException e) {
|
|
|
- /* map is already there, just return view as it is */
|
|
|
- }
|
|
|
-
|
|
|
- if (isGooglePlay()) {
|
|
|
- loadMapFragment();
|
|
|
+ // map already exists
|
|
|
}
|
|
|
|
|
|
return view;
|