Bladeren bron

Merge branch 'master' of https://git.tk.informatik.tu-darmstadt.de/scm-ssi-student-hostagev2

Alexander Brakowski 11 jaren geleden
bovenliggende
commit
d14a93f22d

BIN
res/drawable-xxxhdpi/wifi_marker.png


+ 16 - 2
res/layout/expandable_section_header.xml

@@ -3,9 +3,10 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
-    android:orientation="vertical"
+    android:orientation="horizontal"
     android:padding="8dp"
-    android:background="#ffffff">
+    android:background="#ffffff"
+    android:weightSum="1">
 
 
     <TextView
@@ -14,6 +15,19 @@
         android:layout_height="wrap_content"
         android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
         android:textSize="17dp"
+        android:layout_weight="0.4"
         android:textColor="#505c6d" />
 
+    <TextView
+        android:id="@+id/sectionHeaderValue"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
+        android:textSize="15dp"
+        android:gravity="right"
+        android:textColor="#505c6d"
+        android:layout_weight="0.6"
+        />
+
+
 </LinearLayout>

+ 22 - 0
res/layout/fragment_threatmap_infowindow.xml

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+			  android:orientation="vertical"
+			  android:layout_width="match_parent"
+			  android:layout_height="match_parent">
+
+	<TextView
+			android:layout_width="wrap_content"
+			android:layout_height="wrap_content"
+			android:textAppearance="?android:attr/textAppearanceMedium"
+			android:text="undefined"
+			android:id="@+id/threatmap_infowindow_title" android:layout_gravity="center_horizontal"/>
+	<TextView
+			android:layout_width="wrap_content"
+			android:layout_height="wrap_content"
+			android:textAppearance="?android:attr/textAppearanceSmall"
+			android:text="@string/threatmap_show_records"
+			android:id="@id/textView" android:layout_gravity="center_horizontal"
+			android:textColor="@color/dark_grey" android:clickable="false"
+			android:textIsSelectable="false"/>
+</LinearLayout>

+ 3 - 1
res/values/strings.xml

@@ -54,6 +54,8 @@
 	<string name="export_dialog_title">Choose Export Format</string>		
 	<string name="delete_dialog_title">Delete data sets by:</string>	
 	<string name="dialog_clear_database_date">Delete all data before:</string>
+
+	<string name="threatmap_show_records"><u>Show records</u></string>
 	
     <string name="RecordBSSID">BSSID</string>
     <string name="RecordSSID">SSID</string>
@@ -68,7 +70,7 @@
     <string name="drawer_records">Records</string>
     <string name="drawer_services">Services</string>
     <string name="drawer_settings">Settings</string>
-    <string name="drawer_profile_manager">Profile Manager</string>
+    <string name="drawer_profile_manager">Profiles</string>
     <string name="drawer_app_info">Application info</string>
 	<string name="drawer_statistics">Statistics</string>
 

+ 29 - 0
src/de/tudarmstadt/informatik/hostage/logging/UglyDbHelper.java

@@ -713,6 +713,35 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 		return recordList;
 	}
 
+
+    /*
+    * Returns the Conversation of a specific attack id
+    * @param attack_id
+    *           Tha attack id to match the query against.
+    *
+    *  @return A arraylist with all {@link Record Records}s for an attack id.
+    *
+    * */
+    public ArrayList<Record> getConversationForAttackID(long attack_id) {
+        ArrayList<Record> recordList = new ArrayList<Record>();
+        String selectQuery = "SELECT  * FROM " + TABLE_RECORDS
+                + " NATURAL JOIN " + TABLE_ATTACK_INFO + " JOIN "
+                + TABLE_BSSIDS + " USING " + "(" + KEY_BSSID + ")" + " WHERE " + TABLE_RECORDS+"."+KEY_ATTACK_ID + " = " + attack_id;
+
+        SQLiteDatabase db = this.getReadableDatabase();
+        Cursor cursor = db.rawQuery(selectQuery, null);
+
+        if (cursor.moveToFirst()) {
+            do {
+                Record record = createRecord(cursor);
+                recordList.add(record);
+            } while (cursor.moveToNext());
+        }
+        cursor.close();
+
+        db.close();
+        return recordList;
+    }
 	/**
 	 * Gets a representative {@link Record} for every attack with a higher
 	 * attack id than the specified.

+ 8 - 3
src/de/tudarmstadt/informatik/hostage/ui2/adapter/RecordListAdapter.java

@@ -1,12 +1,13 @@
 package de.tudarmstadt.informatik.hostage.ui2.adapter;
 
+import android.content.Context;
+import android.view.View;
+import android.widget.TextView;
+
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 
-import android.content.Context;
-import android.view.View;
-import android.widget.TextView;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.ui2.model.ExpandableListItem;
 
@@ -37,8 +38,12 @@ public class RecordListAdapter extends ExpandableListAdapter {
     @Override
     public void configureSectionHeaderView(View sectionHeader, int section) {
         int headerLabelID = R.id.sectionHeaderTitle;
+        int valueLabelID = R.id.sectionHeaderValue;
         TextView tView = (TextView) sectionHeader.findViewById(headerLabelID);
+        TextView vView = (TextView) sectionHeader.findViewById(valueLabelID);
+        int value = this.getChildrenCount(section);
         tView.setText(this._sectionHeader.get(section));
+        vView.setText("" + value);
     }
 
     @Override

+ 31 - 16
src/de/tudarmstadt/informatik/hostage/ui2/fragment/RecordOverviewFragment.java

@@ -65,6 +65,9 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
     private LogFilter filter;
     private boolean showFilterButton;
 
+    private int mListPosition = -1;
+    private int mItemPosition = -1;
+
     public String groupingKey;
 
     private ExpandableListView expListView;
@@ -72,6 +75,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
     UglyDbHelper dbh;
 
     private String sectionToOpen = "";
+    private ArrayList<Integer> openSections;
 
     public void setFilter(LogFilter filter){
         this.filter = filter;
@@ -119,28 +123,24 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 		View rootView = inflater.inflate(this.getLayoutId(), container, false);
 		ExpandableListView mylist = (ExpandableListView) rootView.findViewById(R.id.loglistview);
 
-        ArrayList<Integer> openSections = new ArrayList<Integer>();
-        if(this.expListView != null){
-            int numOfGroups = this.expListView.getExpandableListAdapter().getGroupCount();
-
-            for (int i = 0; i < numOfGroups; i++){
-                boolean isOpen = this.expListView.isGroupExpanded(i);
-                if (isOpen){
-                    openSections.add(i);
-                }
-            }
-        }
-
 		this.expListView = mylist;
 		populateListViewFromDB(mylist);
 
-        if (openSections.size() != 0){
-            for (int i = 0; i < openSections.size(); i++){
-                int index = openSections.get(i);
+        if (this.openSections != null && this.openSections.size() != 0){
+            for (int i = 0; i < this.openSections.size(); i++){
+                int index = this.openSections.get(i);
                 this.expListView.expandGroup(index);
             }
+        } else {
+            this.openSections = new ArrayList<Integer>();
         }
 
+        if (mListPosition != -1 && mItemPosition != -1)
+            this.expListView.setSelectedChild(mListPosition, mItemPosition, true);
+
+        mListPosition = -1;
+        mItemPosition = -1;
+
 		registerListClickCallback(mylist);
 
         ImageButton filterButton = (ImageButton) rootView.findViewById(R.id.FilterButton);
@@ -303,6 +303,8 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
                 sectionData.put(groupID, items);
                 groupTitle.add(groupID);
             }
+
+
 			items.add(item);
 		}
 
@@ -345,13 +347,26 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 
                 ExpandableListItem item = (ExpandableListItem)adapter.getChild(i,i2);
 
+                mListPosition = i;
+                mItemPosition = i2;
                 UglyDbHelper dbh = new UglyDbHelper(getBaseContext());
                 Record rec = dbh.getRecordOfAttackId((int) item.getTag());
                 RecordOverviewFragment.this.pushRecordDetailViewForRecord(rec);
                 return true;
             }
         });
-
+        mylist.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
+            @Override
+            public void onGroupExpand(int i) {
+                RecordOverviewFragment.this.openSections.add(new Integer(i));
+            }
+        });
+        mylist.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
+            @Override
+            public void onGroupCollapse(int i) {
+                RecordOverviewFragment.this.openSections.remove(new Integer(i));
+            }
+        });
 	}
 
 

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

@@ -12,6 +12,7 @@ import android.view.InflateException;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.TextView;
 
 import com.google.android.gms.common.ConnectionResult;
 import com.google.android.gms.common.GooglePlayServicesClient;
@@ -21,6 +22,8 @@ import com.google.android.gms.location.LocationRequest;
 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.BitmapDescriptor;
+import com.google.android.gms.maps.model.BitmapDescriptorFactory;
 import com.google.android.gms.maps.model.CircleOptions;
 import com.google.android.gms.maps.model.LatLng;
 import com.google.android.gms.maps.model.Marker;
@@ -225,6 +228,7 @@ public class ThreatMapFragment extends Fragment implements GoogleMap.OnInfoWindo
 		}
 
 		CircleOptions circleOptions = new CircleOptions().radius(200.0).fillColor(Color.argb(127, 240, 80, 60)).strokeWidth(0.0f);
+		BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.wifi_marker);
 		for (Map.Entry<String, ArrayList<SSIDArea>> entry : threadAreas.entrySet()) {
 			String ssid = entry.getKey();
 			ArrayList<SSIDArea> areas = entry.getValue();
@@ -236,9 +240,11 @@ public class ThreatMapFragment extends Fragment implements GoogleMap.OnInfoWindo
 
 				sMap.addCircle(circleOptions.center(center).radius(100.0 + radius).fillColor(color));
 				Marker marker = sMap.addMarker(new MarkerOptions()
-						.title(ssid + ": " + area.numPoints + (area.numPoints == 1 ? getResources().getString(R.string.attack)
+						.title(ssid + ": " + area.numPoints + (area.numPoints == 1 ? getResources()
+								.getString(R.string.attack)
 								: getResources().getString(R.string.attacks))).position(
 								center));
+				marker.setIcon(bitmapDescriptor);
 
 				sMarkerIDToSSID.put(marker.getId(), ssid);
 			}
@@ -262,7 +268,7 @@ public class ThreatMapFragment extends Fragment implements GoogleMap.OnInfoWindo
 	 * @return the view
 	 */
 	@Override
-	public View onCreateView(LayoutInflater inflater, ViewGroup container,
+	public View onCreateView(final LayoutInflater inflater, ViewGroup container,
 	                         Bundle savedInstanceState) {
 		super.onCreateView(inflater, container, savedInstanceState);
 
@@ -296,10 +302,29 @@ public class ThreatMapFragment extends Fragment implements GoogleMap.OnInfoWindo
 		}
 		if (sMap != null) {
 			sMap.setOnInfoWindowClickListener(this);
+			// custom info window layout
+			sMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
+				@Override
+				public View getInfoWindow(Marker marker) {
+					return null;
+				}
+
+				@Override
+				public View getInfoContents(Marker marker) {
+					View view = inflater.inflate(R.layout.fragment_threatmap_infowindow, null);
+					if (view != null) {
+						TextView titleTextView = (TextView)view.findViewById(R.id.threatmap_infowindow_title);
+						if (titleTextView != null) {
+							titleTextView.setText(marker.getTitle());
+						}
+					}
+					return view;
+				}
+			});
 		}
 
 		// tell the user to enable wifi so map data can be streamed
-		if (!HelperUtils.isWifiConnected(activity)) {
+		if (activity != null && !HelperUtils.isWifiConnected(activity)) {
 			new AlertDialog.Builder(activity)
 					.setTitle(R.string.information)
 					.setMessage(R.string.no_network_connection_threatmap_msg)