123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- 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.util.Log;
- 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.Marker;
- import com.google.android.gms.maps.model.MarkerOptions;
- import java.util.ArrayList;
- import de.tudarmstadt.informatik.hostage.R;
- import de.tudarmstadt.informatik.hostage.logging.Record;
- import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
- import static com.google.android.gms.common.GooglePlayServicesUtil.*;
- /**
- * Created by fabio on 10.02.14.
- */
- public class ThreatMapFragment extends Fragment implements GoogleMap.OnMarkerClickListener {
- private static 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;
- }
- @Override
- public boolean onMarkerClick(Marker marker) {
- Log.i("MARKER", ""+marker.getId());
- return false;
- }
- 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));
- }
- @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);
- if (isGooglePlay()) {
- map = ((MapFragment) getFragmentManager()
- .findFragmentById(R.id.threatmapfragment)).getMap();
- populateMap();
- }
- } catch (InflateException e) {
- // map already exists
- }
- return view;
- }
- }
|