Browse Source

now showing location of actual records

Fabio Arnold 9 years ago
parent
commit
9a8a35fe08

+ 73 - 70
src/de/tudarmstadt/informatik/hostage/ui2/fragment/RecordOverviewFragment.java

@@ -1,5 +1,7 @@
 package de.tudarmstadt.informatik.hostage.ui2.fragment;
 
+import com.google.android.gms.maps.model.LatLng;
+
 import android.annotation.SuppressLint;
 import android.app.Fragment;
 import android.content.Context;
@@ -45,7 +47,7 @@ import de.tudarmstadt.informatik.hostage.ui2.model.ExpandableListItem;
 public class RecordOverviewFragment extends Fragment implements ChecklistDialog.ChecklistDialogListener, DateTimeDialogFragment.DateTimeDialogFragmentListener {
 	static final String SELECTED_KEY = "Selected";
 	static final String OTHERS_KEY = "Other";
-	
+
 	static final String FILTER_MENU_TITLE_BSSID = "BSSID";
 	static final String FILTER_MENU_TITLE_ESSID = "ESSID";
 	static final String FILTER_MENU_TITLE_PROTOCOLS = "Protocols";
@@ -65,20 +67,20 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
     private ExpandableListView expListView;
 
 	UglyDbHelper dbh;
-	
+
 
     public RecordOverviewFragment(){}
-    
-	
+
+
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setHasOptionsMenu(true);
     }
-    
+
 	public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
-		
+
 		dbh = new UglyDbHelper(this.getActivity().getBaseContext());
 
 	    // Get the message from the intent
@@ -98,14 +100,14 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 
 	    this.setShowFilterButton(!this.filter.isNotEditable());
 	    this.addRecordToDB();
-	    
+
 		View rootView = inflater.inflate(R.layout.fragment_record_list, container, false);
 		ExpandableListView mylist = (ExpandableListView) rootView.findViewById(R.id.loglistview);
 		this.expListView = mylist;
 		populateListViewFromDB(mylist);
-		
+
 		registerListClickCallback(mylist);
-		
+
         ImageButton filterButton = (ImageButton) rootView.findViewById(R.id.FilterButton);
         filterButton.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
@@ -113,7 +115,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
             }
         });
         filterButton.setVisibility(this.showFilterButton? View.VISIBLE : View.INVISIBLE);
-        
+
         ImageButton sortButton = (ImageButton) rootView.findViewById(R.id.SortButton);
         sortButton.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
@@ -129,7 +131,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
                 RecordOverviewFragment.this.openGroupingDialog();
             }
         });
-		
+
 		return rootView;
 	 }
 
@@ -141,13 +143,13 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 
 	public boolean onFilterMenuItemSelected(MenuItem item) {
 		String title = item.getTitle().toString();
-		
+
 		if(title.equals(FILTER_MENU_TITLE_BSSID)){
 			this.openBSSIDFilterDialog();
 		}
 		if(title.equals(FILTER_MENU_TITLE_ESSID)){
 			this.openESSIDFilterDialog();
-		}		
+		}
 		if(title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
 			this.openProtocolsFilterDialog();
 		}
@@ -166,17 +168,17 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 		}
 		return super.onOptionsItemSelected(item);
 	}
-	
-	
-	
+
+
+
 	/*****************************
-	 * 
+	 *
 	 *          ListView Stuff
-	 * 
+	 *
 	 * ***************************/
-	
+
 	private void populateListViewFromDB(ExpandableListView mylist) {
-		
+
 		HashMap<String, ArrayList<ExpandableListItem>> sectionData = new HashMap<String, ArrayList<ExpandableListItem>>();
 
 		ArrayList<Record> data = dbh.getRecordsForFilter(this.filter);
@@ -228,15 +230,15 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 
         mylist.setAdapter(adapter);
 	}
-	
+
 	private Context getBaseContext(){
 		return this.getActivity().getBaseContext();
 	}
-	
+
 	private Context getApplicationContext(){
 		return this.getActivity().getApplicationContext();
 	}
-	
+
 	private void registerListClickCallback(ExpandableListView mylist) {
 
 		mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@@ -268,16 +270,16 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 
 		});
 	}
-	
-	
-	
+
+
+
 	/*****************************
-	 * 
+	 *
 	 *          Date Transform
-	 * 
+	 *
 	 * ***************************/
-	
-	
+
+
 	@SuppressLint("SimpleDateFormat")
 	private String getDateAsString(long timeStamp) {
 
@@ -289,12 +291,12 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 			return "xx";
 		}
 	}
-	
-	
+
+
 	/*****************************
-	 * 
+	 *
 	 *          Getter / Setter
-	 * 
+	 *
 	 * ***************************/
 
 	public boolean isShowFilterButton() {
@@ -304,50 +306,50 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 	public void setShowFilterButton(boolean showFilterButton) {
 		this.showFilterButton = showFilterButton;
 	}
-	
-	
-	
+
+
+
 
 	/*****************************
-	 * 
+	 *
 	 *          Open Dialog Methods
-	 * 
+	 *
 	 * ***************************/
 
     private void openGroupingDialog(){
         ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_GROUP, this.groupingTitles(), this.selectedGroup(), false , this);
         newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_GROUP);
     }
-	
+
 	private void openBSSIDFilterDialog(){
 		ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_BSSID,this.bssids(), this.selectedBSSIDs(), true , this);
 	    newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_BSSID);
 	}
-	
+
 	private void openESSIDFilterDialog(){
 		ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_ESSID,this.essids(), this.selectedESSIDs(), true , this);
 	    newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_ESSID);
 	}
-	
+
 	private void openProtocolsFilterDialog(){
 		ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_PROTOCOLS,this.protocolTitles(), this.selectedProtocols(), true , this);
 	    newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_PROTOCOLS);
 	}
-	
+
 	private void openTimestampFromFilterDialog(){
 		this.wasBelowTimePicker = false;
 		DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
 	    newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
         if (this.filter.aboveTimestamp != Long.MIN_VALUE)newFragment.setDate(this.filter.aboveTimestamp);
 	}
-	
+
 	private void openTimestampToFilterDialog(){
 		this.wasBelowTimePicker = true;
 		DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
 	    newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
         if (this.filter.belowTimestamp != Long.MAX_VALUE) newFragment.setDate(this.filter.belowTimestamp);
     }
-	
+
 	private void openSortingDialog(){
 		ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_SORTING,this.sortTypeTtiles(), this.selectedSorttype(), false , this);
 	    newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
@@ -389,11 +391,11 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 
 
 	/*****************************
-	 * 
+	 *
 	 *          Filter Stuff
-	 * 
+	 *
 	 * ***************************/
-	
+
 	private void openFilterPopupMenuOnView(View v){
         // Open FilterMenu
         PopupMenu filterMenu = new PopupMenu(getBaseContext(), v);
@@ -411,8 +413,8 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
         });
 			filterMenu.show();
 	}
-	
-	
+
+
 	private void clearFilter(){
     	if(filter == null) this.filter = new LogFilter();
     	this.filter.clear();
@@ -436,7 +438,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
         }
         return selected;
     }
-	
+
 	public ArrayList<String> protocolTitles(){
 		ArrayList<String> titles = new ArrayList<String>();
 		for (String protocol : this.getResources().getStringArray(
@@ -448,7 +450,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 	public boolean[] selectedProtocols(){
 		ArrayList<String> protocols = this.protocolTitles();
 		boolean[] selected = new boolean[protocols.size()];
-		
+
 		int i = 0;
 		for(String protocol : protocols){
 			selected[i] =(this.filter.protocols.contains(protocol));
@@ -471,7 +473,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 	}
 	public boolean[] selectedSorttype(){
 		ArrayList<String> types = this.sortTypeTtiles();
-		boolean[] selected = new boolean[types.size()];	
+		boolean[] selected = new boolean[types.size()];
 		int i = 0;
 		for(String sorttype : types){
 			selected[i] =(this.filter.sorttype.toString() == sorttype);
@@ -479,7 +481,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 		}
 		return selected;
 	}
-	
+
 	public ArrayList<String> bssids(){
 		ArrayList<String> records = dbh.getUniqueBSSIDRecords();
 		return records;
@@ -487,7 +489,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 	public boolean[] selectedBSSIDs(){
 		ArrayList<String> bssids = this.bssids();
 		boolean[] selected = new boolean[bssids.size()];
-		
+
 		int i = 0;
 		for(String bssid : bssids){
 			selected[i] =(this.filter.BSSIDs.contains(bssid));
@@ -504,7 +506,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 	public boolean[] selectedESSIDs(){
 		ArrayList<String> essids = this.essids();
 		boolean[] selected = new boolean[essids.size()];
-		
+
 		int i = 0;
 		for(String essid : essids){
 			selected[i] =(this.filter.ESSIDs.contains(essid));
@@ -513,7 +515,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 		return selected;
 	}
 
-	
+
 	private ArrayList<String> filterMenuTitles(){
 		ArrayList<String> titles = new ArrayList<String>();
 		titles.add(FILTER_MENU_TITLE_BSSID);
@@ -525,13 +527,13 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 		return titles;
 	}
 
-	
+
 	/*****************************
-	 * 
+	 *
 	 *          Listener Actions
-	 * 
+	 *
 	 * ***************************/
-	
+
 	public void onDateTimePickerPositiveClick(DateTimeDialogFragment dialog) {
 		if(this.wasBelowTimePicker){
 			this.filter.setBelowTimestamp(dialog.getDate());
@@ -548,7 +550,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 			this.filter.setAboveTimestamp(Long.MIN_VALUE);
 		}
 	}
-	
+
 	public void onDialogPositiveClick(ChecklistDialog dialog) {
 		String title = dialog.getTitle();
 		if(title.equals(FILTER_MENU_TITLE_BSSID)){
@@ -591,14 +593,14 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 	public void onDialogNegativeClick(ChecklistDialog dialog) {
 
 	}
-	
-	
+
+
 	/*****************************
-	 * 
-	 *          TEST 
-	 * 
+	 *
+	 *          TEST
+	 *
 	 * ***************************/
-	
+
 	private void addRecordToDB() {
 
         if ((dbh.getRecordCount() > 0)) return;
@@ -610,6 +612,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 
 		Random random = new Random();
 
+		LatLng tudarmstadtLoc = new LatLng(49.86923, 8.6632768);
 		int numberofRecords = (int) (Math.random() * (50 - 10));
 		for (int i = 0; i < numberofRecords; i++) {
 			Record record = new Record();
@@ -629,8 +632,8 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 			record.setLocalIP("127.0.0.1");
 			record.setType(TYPE.SEND);
 
-			record.setLatitude(41.889 + random.nextDouble());
-			record.setLongitude(-87.622 + random.nextDouble());
+			record.setLatitude(tudarmstadtLoc.latitude + -0.01 + 0.02 * random.nextDouble());
+			record.setLongitude(tudarmstadtLoc.longitude + -0.01 + 0.02 * random.nextDouble());
 
 			dbh.addRecord(record);
 		}

+ 18 - 3
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ThreatMapFragment.java

@@ -20,7 +20,11 @@ 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 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.*;
 
@@ -31,6 +35,8 @@ public class ThreatMapFragment extends Fragment {
 	private 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,9 +57,18 @@ public class ThreatMapFragment extends Fragment {
 				.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));
+		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));
+		}
+
+		LatLng tudarmstadt = new LatLng(49.86923, 8.6632768);
+		//LatLng mapCenter = new LatLng(41.889, -87.622);
+		map.moveCamera(CameraUpdateFactory.newLatLngZoom(tudarmstadt, 13));
 	}
 
 	@Override