Browse Source

More Bug Fixes

lp-tu 10 years ago
parent
commit
61730880f0

+ 93 - 94
res/layout/activity_viewlog.xml

@@ -1,121 +1,120 @@
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:orientation="vertical"
+    android:layout_height="wrap_content"
     android:paddingBottom="@dimen/activity_vertical_margin"
     android:paddingLeft="@dimen/activity_horizontal_margin"
     android:paddingRight="@dimen/activity_horizontal_margin"
-    android:paddingTop="@dimen/activity_vertical_margin" >
-
-    <TextView
-        android:id="@+id/textStatistics"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:text="@string/statistics"
-        android:textAppearance="?android:attr/textAppearanceLarge" />
-
-    <HorizontalScrollView
-        android:layout_width="fill_parent"
-        android:layout_height="wrap_content"
-        android:scrollbars="none" >
-
-        <TableLayout
-            android:id="@+id/layoutContainer"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:orientation="vertical" >
-        </TableLayout>
-        
-    </HorizontalScrollView>
+    android:paddingTop="@dimen/activity_vertical_margin"
+    android:scrollbars="none" >
 
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:orientation="horizontal" >
+        android:orientation="vertical" >
 
         <TextView
-            android:id="@+id/textFirstAttack"
+            android:id="@+id/textStatistics"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:text="@string/firstAttack"
-            android:textAppearance="?android:attr/textAppearanceMedium" />
+            android:text="@string/statistics"
+            android:textAppearance="?android:attr/textAppearanceLarge" />
 
-        <TextView
-            android:id="@+id/textFirstAttackValue"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:paddingLeft="2dp"
-            android:text=""
-            android:textAppearance="?android:attr/textAppearanceMedium" />
-    </LinearLayout>
-
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:orientation="horizontal" >
-
-        <TextView
-            android:id="@+id/textLastAttack"
+        <TableLayout
+            android:id="@+id/layoutContainer"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:text="@string/lastAttack"
-            android:textAppearance="?android:attr/textAppearanceMedium" />
+            android:orientation="vertical" >
+        </TableLayout>
 
-        <TextView
-            android:id="@+id/textLastAttackValue"
-            android:layout_width="wrap_content"
+        <LinearLayout
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:paddingLeft="2dp"
-            android:text=""
-            android:textAppearance="?android:attr/textAppearanceMedium" />
-    </LinearLayout>
-
-    <TextView
-        android:id="@+id/textLogFile"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:text="@string/log_actions"
-        android:textAppearance="?android:attr/textAppearanceLarge" />
-
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:orientation="horizontal" >
-
-        <Button
-            android:id="@+id/buttonShowLog"
-            android:layout_width="wrap_content"
+            android:orientation="horizontal" >
+
+            <TextView
+                android:id="@+id/textFirstAttack"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="@string/firstAttack"
+                android:textAppearance="?android:attr/textAppearanceMedium" />
+
+            <TextView
+                android:id="@+id/textFirstAttackValue"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:paddingLeft="2dp"
+                android:text=""
+                android:textAppearance="?android:attr/textAppearanceMedium" />
+        </LinearLayout>
+
+        <LinearLayout
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:onClick="showLog"
-            android:text="Show Log" />
+            android:orientation="horizontal" >
+
+            <TextView
+                android:id="@+id/textLastAttack"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="@string/lastAttack"
+                android:textAppearance="?android:attr/textAppearanceMedium" />
+
+            <TextView
+                android:id="@+id/textLastAttackValue"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:paddingLeft="2dp"
+                android:text=""
+                android:textAppearance="?android:attr/textAppearanceMedium" />
+        </LinearLayout>
 
-        <Button
-            android:id="@+id/buttonExportDatabase"
+        <TextView
+            android:id="@+id/textLogFile"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:onClick="exportDatabase"
-            android:text="Export Database" />
-    </LinearLayout>
+            android:text="@string/log_actions"
+            android:textAppearance="?android:attr/textAppearanceLarge" />
 
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:orientation="horizontal" >
-
-        <Button
-            android:id="@+id/buttonUploadLog"
-            android:layout_width="wrap_content"
+        <LinearLayout
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:onClick="uploadDatabase"
-            android:text="Upload Log" />
-
-        <Button
-            android:id="@+id/buttonDeleteLog"
-            android:layout_width="wrap_content"
+            android:orientation="horizontal" >
+
+            <Button
+                android:id="@+id/buttonShowLog"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:onClick="showLog"
+                android:text="Show Log" />
+
+            <Button
+                android:id="@+id/buttonExportDatabase"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:onClick="exportDatabase"
+                android:text="Export Database" />
+        </LinearLayout>
+
+        <LinearLayout
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:onClick="deleteLog"
-            android:text="Delete Log" />
+            android:orientation="horizontal" >
+
+            <Button
+                android:id="@+id/buttonUploadLog"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:onClick="uploadDatabase"
+                android:text="Upload Log" />
+
+            <Button
+                android:id="@+id/buttonDeleteLog"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:onClick="deleteLog"
+                android:text="Delete Log" />
+        </LinearLayout>
     </LinearLayout>
 
-</LinearLayout>
+</ScrollView>

+ 15 - 15
src/de/tudarmstadt/informatik/hostage/logging/DatabaseHandler.java

@@ -199,17 +199,17 @@ public class DatabaseHandler extends SQLiteOpenHelper {
     public int getSmallestAttackId(){
     	String selectQuery = "SELECT MIN(" + KEY_ATTACK_ID +") FROM " + TABLE_RECORDS;
         SQLiteDatabase db = this.getReadableDatabase();
-        Cursor cursor = db.rawQuery(selectQuery, null);
-        db.close();
+        Cursor cursor = db.rawQuery(selectQuery, null);        
+        int result;
         
         if (cursor.moveToFirst()) {
-        	int result = cursor.getInt(0);
-        	cursor.close();
-        	return result;
+        	result = cursor.getInt(0);
         } else{
-        	cursor.close();
-        	return -1;
-        }
+        	result = -1;
+        }        
+    	cursor.close();
+    	db.close();
+    	return result;
     }
     
     //Get the smallest AttackId
@@ -217,16 +217,16 @@ public class DatabaseHandler extends SQLiteOpenHelper {
     	String selectQuery = "SELECT MAX(" + KEY_ATTACK_ID +") FROM " + TABLE_RECORDS;
         SQLiteDatabase db = this.getReadableDatabase();
         Cursor cursor = db.rawQuery(selectQuery, null);
-        db.close();
+        int result;
         
         if (cursor.moveToFirst()) {
-        	int result = cursor.getInt(0);
-        	cursor.close();
-        	return result;
+        	result = cursor.getInt(0);
         } else{
-        	cursor.close();
-        	return -1;
-        }
+        	result = -1;
+        }        
+    	cursor.close();
+    	db.close();
+    	return result;
     }
     
 	// Getting first Record for each AttackId

+ 18 - 12
src/de/tudarmstadt/informatik/hostage/logging/SQLLogger.java

@@ -6,6 +6,7 @@ import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 
+import org.apache.http.HttpResponse;
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.HttpPost;
@@ -25,6 +26,7 @@ import android.os.Environment;
 import android.preference.PreferenceManager;
 import android.support.v4.app.NotificationCompat;
 import android.support.v4.app.TaskStackBuilder;
+import android.util.Log;
 import android.widget.Toast;
 
 public class SQLLogger implements Logger{
@@ -111,34 +113,38 @@ public class SQLLogger implements Logger{
 
 			  public void run() {				  
 					HttpClient httpclient = HelperUtils.createHttpClient();
-					ArrayList<Record> recordList = dbh.getRecordOfEachAttack(lastUploadedAttackId + 1);
+					ArrayList<Record> recordList = dbh.getRecordOfEachAttack(lastUploadedAttackId);
 					progressMax = recordList.size();		
-
+					Log.i("SQLLogger", "Logs to upload: " + progressMax);	
 							HttpPost httppost;
-							int progressBarStatus = 1;
+							int progressBarStatus = 0;
 							for(Record record: recordList){
+								Log.i("SQLLogger", "Uploading log: " + progressBarStatus);
 								try {
 								httppost = new HttpPost(pref.getString("pref_upload", "https://ssi.cased.de"));
 								StringEntity se = new StringEntity(record.toString(JSON));
 								httppost.setEntity(se);
-								httpclient.execute(httppost);
+								HttpResponse response = httpclient.execute(httppost);
+								Log.i("SQLLogger", "Statuscode of log: " + progressBarStatus + " " + response.getStatusLine().getStatusCode());	
+								progressBarStatus++;								
 								builder.setProgress(progressMax, progressBarStatus, false);
-								progressBarStatus++;
 			                     // Update the progress bar
 								mNotifyManager.notify(2, builder.build());
 								} catch (Exception e) {
+									Log.i("SQLLogger", "Failed");
 									// TODO Auto-generated catch block
 									e.printStackTrace();
 								}
 							}
 
-					// When the loop is finished, updates the notification
-		            builder.setContentText("Upload complete")
-		            	   .setTicker("Upload complete")
-		            // Removes the progress bar
-		                   .setProgress(0,0,false);
-		            mNotifyManager.notify(2, builder.build());
-
+					if(progressBarStatus == progressMax){
+						// When the loop is finished, updates the notification
+			            builder.setContentText("Upload complete")
+			            	   .setTicker("Upload complete")
+			            // Removes the progress bar
+			                   .setProgress(0,0,false);
+			            mNotifyManager.notify(2, builder.build());
+			        }
 			}}).start();
 		editor.putInt("LAST_UPLOADED_ATTACK_ID",currentAttackId - 1);
 		editor.commit();				

+ 9 - 12
src/de/tudarmstadt/informatik/hostage/ui/ViewLog.java

@@ -254,31 +254,28 @@ public class ViewLog extends Activity {
 		protocols.addAll(Arrays.asList(getResources().getStringArray(
 				R.array.protocols)));
 
-		TableRow tableHeader = new TableRow(this);
-		TableRow tableContent = new TableRow(this);
-		tableHeader.setBackgroundResource(R.color.dark_grey);
-		tableContent.setBackgroundResource(R.color.light_grey);
-
 		for (String protocol : protocols) {
+			TableRow row = new TableRow(this);
 			TextView protocolName = new TextView(this);
+			protocolName.setBackgroundResource(R.color.dark_grey);
 			protocolName.setText(protocol);
 			protocolName.setTextAppearance(this,
 					android.R.style.TextAppearance_Medium);
-			protocolName.setPadding(3, 0, 3, 0);
-			tableHeader.addView(protocolName);
+			protocolName.setPadding(6, 0, 0, 0);
+			row.addView(protocolName);
 			TextView value = new TextView(this);
+			value.setBackgroundResource(R.color.light_grey);
 			value.setTextAppearance(this, android.R.style.TextAppearance_Medium);
-			value.setGravity(Gravity.CENTER);
-			tableContent.addView(value);
+			value.setGravity(Gravity.RIGHT);
+			value.setPadding(3, 0, 3, 0);
+			row.addView(value);
 			if (protocol.equals("Total")) {
 				value.setText("" + dbh.getAttackCount());
 			} else {
 				value.setText("" + dbh.getAttackPerProtokolCount(protocol));
 			}
+			table.addView(row);
 		}
-		table.addView(tableHeader);
-		table.addView(tableContent);
-
 		setFirstAndLastAttack();
 	}