Browse Source

added list layout to the log list view

Julien 10 years ago
parent
commit
a55a351a95

+ 15 - 0
res/layout/activity_loglist.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent" >
+
+    <ListView
+        android:id="@+id/loglistview"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentTop="true" >
+
+    </ListView>
+
+</RelativeLayout>

+ 10 - 3
res/layout/activity_viewlog.xml

@@ -1,10 +1,10 @@
-<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
 	android:scrollbars="none">
 
-    <LinearLayout
+   <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="vertical"
@@ -117,4 +117,11 @@
         </LinearLayout>
     </LinearLayout>
 
-</ScrollView>
+        <TableLayout
+            android:id="@+id/attack_info"
+            android:layout_width="fill_parent"
+            android:layout_height="fill_parent"
+            android:orientation="vertical" >
+        </TableLayout>
+
+</RelativeLayout>

+ 38 - 0
res/layout/loglist_row.xml

@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent" >
+
+    <TextView
+        android:id="@+id/RecordTextFieldBSSID"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentTop="true"
+        android:text="BSSID" />
+
+    <TextView
+        android:id="@+id/RecordTextFieldSSID"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_below="@+id/RecordTextFieldBSSID"
+        android:text="SSID" />
+
+    <TextView
+        android:id="@+id/RecordTextFieldProtocol"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_below="@+id/RecordTextFieldSSID"
+        android:text="Protocol" />
+
+    <TextView
+        android:id="@+id/RecordTextFieldTimestamp"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_below="@+id/RecordTextFieldProtocol"
+        android:text="Timestamp" />
+
+</RelativeLayout>

+ 5 - 0
res/values/strings.xml

@@ -28,5 +28,10 @@
 	<string name="delete_dialog_title">Delete data sets by:</string>	
 	<string name="dialog_clear_database_date">Delete all data before:</string>
 	
+    <string name="RecordBSSID">BSSID</string>
+    <string name="RecordSSID">SSID</string>
+    <string name="RecordTimestamp">timestamp</string>
+    <string name="RecordProtocol">protocol</string>
+    
 
 </resources>

+ 4 - 4
src/de/tudarmstadt/informatik/hostage/ui/MainActivity.java

@@ -270,7 +270,7 @@ public class MainActivity extends Activity {
 		 * After the service is bound, check which has been clicked and start it.
 		 * @see android.content.ServiceConnection#onServiceConnected(android.content.ComponentName)
 		 */
-		@Override
+		//@Override
 		public void onServiceConnected(ComponentName name, IBinder service) {
 			mService = ((LocalBinder) service).getService();
 			if(protocolClicked != null && protocolClicked.equals("PANIC")){
@@ -285,7 +285,7 @@ public class MainActivity extends Activity {
 		 * After the service is unbound, delete reference.
 		 * @see android.content.ServiceConnection#onServiceDisconnected(android.content.ComponentName)
 		 */
-		@Override
+		//@Override
 		public void onServiceDisconnected(ComponentName name) {
 			mService = null;			
 		}
@@ -325,7 +325,7 @@ public class MainActivity extends Activity {
 		listView.setAdapter(adapter);
 		listView.setOnTouchListener(new OnTouchListener() {
 
-			@Override
+			//@Override
 			public boolean onTouch(View v, MotionEvent event) {
 				return gestureDetector.onTouchEvent(event);
 			}
@@ -333,7 +333,7 @@ public class MainActivity extends Activity {
 		});
 		listView.setOnItemClickListener(new OnItemClickListener() {
 
-			@Override
+			//@Override
 			public void onItemClick(AdapterView<?> parent, View view,
 					int position, long id) {
 				String protocolName = (String) ((HashMap<?, ?>) adapter

+ 3 - 2
src/de/tudarmstadt/informatik/hostage/ui/ViewLog.java

@@ -57,7 +57,7 @@ public class ViewLog extends Activity {
 	
 	private final SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm", Locale.US);
 
-	private Logger logger;
+	private SQLLogger logger;
 	private SharedPreferences pref;
 	private Editor editor;
 
@@ -426,7 +426,8 @@ public class ViewLog extends Activity {
 	}
 
 	/**
-	 * Initializes the Statistics. Creates a table row for every protocol and checks the dabase for the attack count.
+	 * Initializes the Statistics. Creates a table row for every protocol and checks the dabase for the 
+ count.
 	 * Calls {@link ViewLog#setFirstAndLastAttack()} to set the TextViews.
 	 * @see Logger#getAttackCount()
 	 * @see Logger#getAttackPerProtokolCount(String)

+ 156 - 17
src/de/tudarmstadt/informatik/hostage/ui/ViewLogTable.java

@@ -1,12 +1,23 @@
 package de.tudarmstadt.informatik.hostage.ui;
 
-import de.tudarmstadt.informatik.hostage.format.LogViewFormatter;
-import de.tudarmstadt.informatik.hostage.logging.DatabaseHandler;
-import de.tudarmstadt.informatik.hostage.logging.Record;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+
+import android.annotation.SuppressLint;
 import android.app.Activity;
 import android.os.Bundle;
-import android.widget.ScrollView;
-import android.widget.TextView;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ListAdapter;
+import android.widget.ListView;
+import android.widget.SimpleAdapter;
+import android.widget.Toast;
+import de.tudarmstadt.informatik.hostage.R;
+import de.tudarmstadt.informatik.hostage.logging.DatabaseHandler;
+import de.tudarmstadt.informatik.hostage.logging.Record;
 
 /**
  * Creates a simple log view. Shows the Information for every attack. The format ist defined in {@link Record#toString(int)}.
@@ -14,23 +25,151 @@ import android.widget.TextView;
  *
  */
 public class ViewLogTable extends Activity{
+	DatabaseHandler dbh;
 	
 	@Override
 	protected void onCreate(Bundle savedInstanceState) {
 		super.onCreate(savedInstanceState);
-		DatabaseHandler dbh = new DatabaseHandler(getBaseContext());
-		StringBuffer log = new StringBuffer();
-		//Create a log entry for every attack in the Database
-		for(Record record: dbh.getAllReceivedRecordsOfEachAttack()) {
-			log.append(record.toString(0));
-		}
+		dbh = new DatabaseHandler(getBaseContext());
+		setContentView(R.layout.activity_loglist);
+//		StringBuffer log = new StringBuffer();
+//		//Create a log entry for every attack in the Database
+//		for(Record record: dbh.getAllReceivedRecordsOfEachAttack()) {
+//			log.append(record.toString(0));
+//		}
+		
+//		ScrollView scroll = new ScrollView(this);
+//		TextView text = new TextView(getApplicationContext());
+//		text.setText(log);
+//		text.setTextAppearance(this, android.R.style.TextAppearance_Medium);
+//		scroll.addView(text);
+		
+		populateListViewFromDB();
+		registerListClickCallback();
+	}
+	
+
+
+
+	private void populateListViewFromDB() {
+		
+		ListView mylist = (ListView) findViewById(R.id.loglistview);
+	    
+		ArrayList<HashMap<String, String>> Items = new ArrayList<HashMap<String, String>>();
+
+		ArrayList<Record> data = dbh.getAllRecords();       
+
+	        for (Record val : data) {
+	            HashMap<String, String> map = new HashMap<String, String>();
+	            map.put(this.getString(R.string.RecordBSSID), val.getBSSID() );
+	            map.put(this.getString(R.string.RecordSSID), val.getSSID());
+	            map.put(this.getString(R.string.RecordProtocol), val.getProtocol());
+	            map.put(this.getString(R.string.RecordTimestamp), this.getDateAsString(val.getTimestamp()));
+	            Items.add(map);        
+	        }
+	        
+	     // Adding Items to ListView
+	        ListAdapter adapter = new SimpleAdapter(this, Items,
+	                R.layout.loglist_row,new String[] { this.getString(R.string.RecordBSSID), this.getString(R.string.RecordSSID), this.getString(R.string.RecordProtocol), this.getString(R.string.RecordTimestamp) },
+	                new int[] {R.id.RecordTextFieldBSSID, R.id.RecordTextFieldSSID, R.id.RecordTextFieldProtocol, R.id.RecordTextFieldTimestamp });
+
+	        mylist.setAdapter(adapter);
+
+	        
+	}
+
+	
+	
+	@SuppressLint("SimpleDateFormat")
+	private String getDateAsString(long timeStamp){
+
+	    try{
+	        DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
+	        Date netDate = (new Date(timeStamp));
+	        return sdf.format(netDate);
+	    }
+	    catch(Exception ex){
+	        return "xx";
+	    }
+	} 
+	
+	
+	private void registerListClickCallback() {
+		ListView mylist = (ListView) findViewById(R.id.loglistview);
 		
-		ScrollView scroll = new ScrollView(this);
-		TextView text = new TextView(getApplicationContext());
-		text.setText(log);
-		text.setTextAppearance(this, android.R.style.TextAppearance_Medium);
-		scroll.addView(text);
-		setContentView(scroll);
+		mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+			public void onItemClick(AdapterView<?> parent, View viewClicked, int position,
+					long idInDB) {
+				DatabaseHandler dbh = new DatabaseHandler(getBaseContext());
+				Record rec = dbh.getRecord((int) idInDB);
+				String message = createInformationStringFromRecord(rec);
+				Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
+			}
+			
+			private String createInformationStringFromRecord(Record rec){
+				String message = "id: " + rec.getId() + "\n" +
+								"attack_id: " + rec.getAttack_id() +"\n" +
+								"protocol: " + rec.getProtocol() +"\n" +
+								"type: " + rec.getType() + "\n" +
+								"externalIP: " + rec.getExternalIP() +"\n" +
+								"localIP: " + rec.getLocalIP() +"\n" +
+								"local port: " + rec.getLocalPort() +"\n" +
+								"remoteIP: " + rec.getRemoteIP() +"\n" +
+								"BSSID: " + rec.getBSSID() + "\n" +
+								"SSID: " + rec.getSSID() +"\n" +
+								"latitude: " + rec.getLatitude() +"\n" +
+								"longitude: " + rec.getLongitude() + "\n" +
+								"accuracy: " + rec.getAccuracy() +"\n" +
+								"packet: " + rec.getPacket() + "\n" +
+								getDateAsString(rec.getTimestamp()) +
+								"";
+				return message;
+			}
+			
+			@SuppressLint("SimpleDateFormat")
+			private String getDateAsString(long timeStamp){
+
+			    try{
+			        DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
+			        Date netDate = (new Date(timeStamp));
+			        return sdf.format(netDate);
+			    }
+			    catch(Exception ex){
+			        return "xx";
+			    }
+			} 
+			
+		});
 	}
+	
+	
+//    @Override
+//    public boolean onCreateOptionsMenu(Menu menu)
+//    {
+//        MenuInflater inflater = getMenuInflater();
+//        inflater.inflate(R.menu.main_menu, menu);
+//        return true;
+//    }
+
+//    @Override
+//    public boolean onOptionsItemSelected(MenuItem item)
+//    {
+//        switch (item.getItemId())
+//        {
+//            case R.id.home:
+//                ListviewActivity.this.finish();
+//                return true;
+//            case R.id.about:
+//                 Toast.makeText(getApplicationContext(), "This is collection and is created by amdel corporation",
+//                         Toast.LENGTH_LONG).show();
+//                return true;
+//            case R.id.exit:
+//                finish();
+//                System.exit(0);
+//                return true;
+//            default:
+//                return super.onOptionsItemSelected(item);
+//        }
+//    }
 
 }