Browse Source

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

Alexander Brakowski 10 years ago
parent
commit
6403ec5f6f

+ 9 - 0
res/layout/fragment_record_list.xml

@@ -5,6 +5,15 @@
     android:background="@android:color/transparent"
     >
 
+    <ProgressBar
+        android:id="@+id/progressBar1"
+        style="?android:attr/progressBarStyleLarge"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_centerHorizontal="true"
+        android:layout_centerVertical="true"
+        android:visibility="gone"/>
+
             <ExpandableListView
                 xmlns:android="http://schemas.android.com/apk/res/android"
                 android:id="@+id/loglistview"

+ 9 - 0
res/layout/fragment_statistics.xml

@@ -21,6 +21,15 @@
                 android:id="@+id/plot_parent_layout"
                 android:layout_weight="0.9">
 
+                <ProgressBar
+                    android:id="@+id/progressBar1"
+                    style="?android:attr/progressBarStyleLarge"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_centerHorizontal="true"
+                    android:layout_centerVertical="true"
+                    android:visibility="gone"/>
+
                 <!-- TITLE LAYOUT -->
                 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                     android:orientation="vertical"

+ 2 - 0
res/values-de/strings.xml

@@ -103,6 +103,8 @@
     <string name="discard">Verwerfen</string>
     <string name="save">Speichern</string>
     <string name="rec_protocol">Protokol</string>
+    <string name="ESSID">ESSID</string>
+    <string name="BSSID">BSSID</string>
     <string name="rec_sortby">Sortieren</string>
     <string name="rec_latest">Bis</string>
     <string name="rec_earliest">Von</string>

+ 2 - 0
res/values/strings.xml

@@ -103,6 +103,8 @@
     <string name="save">Save</string>
 	<string name="really_want_delete_profiel">Do you really want to delete this profile?</string>
     <string name="rec_protocol">Protocol</string>
+    <string name="ESSID">ESSID</string>
+    <string name="BSSID">BSSID</string>
     <string name="rec_sortby">Sort by</string>
     <string name="rec_latest">Latest</string>
     <string name="rec_earliest">Earliest</string>

+ 1 - 1
src/com/echo/holographlibrary/BarGraph.java

@@ -82,7 +82,7 @@ public class BarGraph extends View {
     public void setBars(ArrayList<Bar> points){
         this.mBars = points;
         mShouldUpdate = true;
-        postInvalidate();
+        //postInvalidate();
     }
     
     public ArrayList<Bar> getBars(){

+ 14 - 15
src/com/echo/holographlibrary/LineGraph.java

@@ -64,9 +64,8 @@ public class LineGraph extends View {
 	private Bitmap fullImage;
 	private boolean shouldUpdate = false;
 
-    static final float bottomPadding = 40, topPadding = 10;
-    static final float rightPadding = 10;
-    static final float leftPadding = 50;
+    static final float bottomPadding = 50, topPadding = 10;
+    static final float leftPadding = 50, rightPadding = 10;
     static final float sidePadding = rightPadding + leftPadding;
 
     private float xAxisStep = 4;
@@ -109,13 +108,13 @@ public class LineGraph extends View {
 			lines.remove(0);
 		}
 		shouldUpdate = true;
-		postInvalidate();
+		//postInvalidate();
 	}
 	
 	public void addLine(Line line) {
 		lines.add(line);
 		shouldUpdate = true;
-		postInvalidate();
+		//postInvalidate();
 	}
 	public void addPointToLine(int lineIndex, double x, double y){
 		addPointToLine(lineIndex, (float) x, (float) y);
@@ -146,7 +145,7 @@ public class LineGraph extends View {
 		lines.set(lineIndex, line);
 		resetLimits();
 		shouldUpdate = true;
-		postInvalidate();
+		//postInvalidate();
 	}
 	
 	public void addPointsToLine(int lineIndex, LinePoint[] points){
@@ -157,7 +156,7 @@ public class LineGraph extends View {
 		lines.set(lineIndex, line);
 		resetLimits();
 		shouldUpdate = true;
-		postInvalidate();
+		//postInvalidate();
 	}
 	
 	public void removeAllPointsAfter(int lineIndex, double x){
@@ -178,7 +177,7 @@ public class LineGraph extends View {
 		lines.set(lineIndex, line);
 		resetLimits();
 		shouldUpdate = true;
-		postInvalidate();
+		//postInvalidate();
 	}
 	public void removePointsFromLine(int lineIndex, LinePoint[] points){
 		Line line = getLine(lineIndex);
@@ -188,7 +187,7 @@ public class LineGraph extends View {
 		lines.set(lineIndex, line);
 		resetLimits();
 		shouldUpdate = true;
-		postInvalidate();
+		//postInvalidate();
 	}
 	public void removePointFromLine(int lineIndex, float x, float y){
 		LinePoint p = null;
@@ -202,7 +201,7 @@ public class LineGraph extends View {
 		lines.set(lineIndex, line);
 		resetLimits();
 		shouldUpdate = true;
-		postInvalidate();
+		//postInvalidate();
 	}
 	
 	public void resetYLimits(){
@@ -225,7 +224,7 @@ public class LineGraph extends View {
 	public void setLineToFill(int indexOfLine) {
 		this.lineToFill = indexOfLine;
 		shouldUpdate = true;
-		postInvalidate();
+		//postInvalidate();
 	}
 	public int getLineToFill(){
 		return lineToFill;
@@ -459,7 +458,7 @@ public class LineGraph extends View {
         float usableWidth = getWidth() - 2*sidePadding;
         float usableHeight = getHeight() - bottomPadding - topPadding;
 
-        float yPixels = getHeight() - (bottomPadding*3/5);
+        float yPixels = getHeight() - (bottomPadding*(4.f/5.f));
 
         // DRAW SEPERATOR
         paint.setColor(Color.BLACK);
@@ -474,18 +473,18 @@ public class LineGraph extends View {
         this.paint.setTextSize(AXIS_LABEL_FONT_SIZE * mContext.getResources().getDisplayMetrics().scaledDensity);
 
         // Draw y-axis label text
-        //double skippedValue = (maxY - minY ) / (Math.max(1., yAxisStep));
         double step = Math.max(1., (maxY - minY) / (Math.max(1., yAxisStep)));
-
+        double v = 0;
         for (double y = minY; y <= maxY; y+=step){
             double yPercent = (y-minY)/(maxY - minY);
 
             double newYPixels = topPadding + (yPercent*usableHeight);
             canvas.drawLine((float)leftPadding,(float)newYPixels,(float)leftPadding-5.f,(float)newYPixels, paint);
-            String title = this.getY_AxisTitle(maxY - y);
+            String title = this.getY_AxisTitle(maxY - v);
             float textwidth = (this.paint.measureText(title));
             canvas.drawText(title, 5.f ,(float)newYPixels + (textwidth/2), this.paint);
 
+            v+=step;
             //value+=skippedValue;
         }
 

+ 17 - 8
src/com/echo/holographlibrary/PieGraph.java

@@ -39,6 +39,7 @@ import android.view.View;
 import android.widget.TextView;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
@@ -253,7 +254,7 @@ public class PieGraph extends View {
 	}
 	public void setSlices(ArrayList<PieSlice> slices) {
 		this.slices = slices;
-		postInvalidate();
+		//postInvalidate();
 	}
 	public PieSlice getSlice(int index) {
 		return slices.get(index);
@@ -263,12 +264,17 @@ public class PieGraph extends View {
 		    this.slices.add(slice);
 
         long countedValue = 0;
-        for (PieSlice s : this.slices){
-            countedValue+=s.getValue();
+
+        Iterator<PieSlice> iter = this.slices.iterator();
+
+        while (iter.hasNext()){
+            PieSlice s = iter.next();
+            countedValue+= s.getValue();
         }
+
         this.title = ALL_TITLE;
         this.subtitle = "" + countedValue;
-		postInvalidate();
+		//postInvalidate();
 	}
 	public void setOnSliceClickedListener(OnSliceClickedListener listener) {
 		this.listener = listener;
@@ -279,17 +285,20 @@ public class PieGraph extends View {
 	}
 	public void setThickness(int thickness) {
 		this.thickness = thickness;
-		postInvalidate();
+		//postInvalidate();
 	}
 	
 	public void removeSlices(){
-		for (int i = slices.size()-1; i >= 0; i--){
-			slices.remove(i);
+        Iterator<PieSlice> iter = slices.iterator();
+
+        while (iter.hasNext()) {
+            iter.next();
+            iter.remove();
 		}
         this.title = "";
         this.subtitle = "";
 
-		postInvalidate();
+		//postInvalidate();
 	}
 
 	public static interface OnSliceClickedListener {

+ 21 - 14
src/de/tudarmstadt/informatik/hostage/deprecated/UglyDbHelper.java

@@ -1,16 +1,17 @@
 package de.tudarmstadt.informatik.hostage.deprecated;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-
 import android.content.ContentValues;
 import android.content.Context;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.database.sqlite.SQLiteOpenHelper;
 import android.util.Log;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+
 import de.tudarmstadt.informatik.hostage.logging.Record;
 import de.tudarmstadt.informatik.hostage.logging.Record.TYPE;
 import de.tudarmstadt.informatik.hostage.model.Profile;
@@ -286,7 +287,7 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 		bssidValues.put(KEY_LATITUDE, record.getLatitude());
 		bssidValues.put(KEY_LONGITUDE, record.getLongitude());
 		bssidValues.put(KEY_ACCURACY, record.getAccuracy());
-		bssidValues.put(KEY_TIME, record.getTimestampLocation());
+		bssidValues.put(KEY_GEO_TIMESTAMP, record.getTimestampLocation());
 
 		ContentValues attackValues = new ContentValues();
 		attackValues.put(KEY_ATTACK_ID, record.getAttack_id()); // Log Attack ID
@@ -513,7 +514,10 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 		String countQuery = "SELECT  * FROM " + TABLE_ATTACK_INFO;
 		SQLiteDatabase db = this.getReadableDatabase();
 		Cursor cursor = db.rawQuery(countQuery, null);
-		int result = cursor.getCount();
+
+        if (!cursor.moveToFirst()) return 0;
+
+        int result = cursor.getCount();
 		cursor.close();
 
 		// return count
@@ -534,12 +538,15 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 	public int getAttackPerProtocolCount(String protocol) {
 		String countQuery = "SELECT  * FROM " + TABLE_ATTACK_INFO + " WHERE " + KEY_PROTOCOL + " = " + "'" + protocol + "'";
 		SQLiteDatabase db = this.getReadableDatabase();
-		Cursor cursor = db.rawQuery(countQuery, null);
+
+        Cursor cursor = db.rawQuery(countQuery, null);
+
+        if (!cursor.moveToFirst()) return 0;
 		int result = cursor.getCount();
-		cursor.close();
 
-		// return count
-		db.close();
+        cursor.close();
+		//db.close();
+
 		return result;
 	}
 
@@ -580,7 +587,7 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 				values.put(KEY_LATITUDE, Double.parseDouble(cursor.getString(2)));
 				values.put(KEY_LONGITUDE, Double.parseDouble(cursor.getString(3)));
 				values.put(KEY_ACCURACY, Float.parseFloat(cursor.getString(4)));
-				values.put(KEY_TIME, cursor.getLong(5));
+				values.put(KEY_GEO_TIMESTAMP, cursor.getLong(5));
 				networkInformation.add(values);
 			} while (cursor.moveToNext());
 		}
@@ -919,7 +926,7 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 		String bssidQuery = "SELECT  * FROM " + TABLE_BSSIDS + " WHERE " + KEY_BSSID + " = " + "'" + bssid + "'";
 		Cursor cursor = db.rawQuery(bssidQuery, null);
 		int result = cursor.getCount();
-		if (cursor != null && cursor.moveToFirst() && (result <= 0 || cursor.getLong(5) < (Long) networkInformation.get(KEY_TIME)))
+		if (cursor != null && cursor.moveToFirst() && (result <= 0 || cursor.getLong(5) < (Long) networkInformation.get(KEY_GEO_TIMESTAMP)))
 			;
 		{
 			ContentValues bssidValues = new ContentValues();
@@ -928,7 +935,7 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 			bssidValues.put(KEY_LATITUDE, (double) (Double) networkInformation.get(KEY_LATITUDE));
 			bssidValues.put(KEY_LONGITUDE, (double) (Double) networkInformation.get(KEY_LONGITUDE));
 			bssidValues.put(KEY_ACCURACY, (float) (Float) networkInformation.get(KEY_ACCURACY));
-			bssidValues.put(KEY_TIME, (Long) networkInformation.get(KEY_TIME));
+			bssidValues.put(KEY_GEO_TIMESTAMP, (Long) networkInformation.get(KEY_GEO_TIMESTAMP));
 			db.insertWithOnConflict(TABLE_BSSIDS, null, bssidValues, SQLiteDatabase.CONFLICT_REPLACE);
 		}
 		cursor.close();

+ 18 - 6
src/de/tudarmstadt/informatik/hostage/ui2/adapter/ExpandableListAdapter.java

@@ -1,15 +1,14 @@
 package de.tudarmstadt.informatik.hostage.ui2.adapter;
 
+import android.content.Context;
+import android.view.LayoutInflater;
 import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseExpandableListAdapter;
 
 import java.util.ArrayList;
 import java.util.HashMap;
-        import java.util.List;
-
-        import android.content.Context;
-        import android.view.LayoutInflater;
-        import android.view.ViewGroup;
-        import android.widget.BaseExpandableListAdapter;
+import java.util.List;
 
 import de.tudarmstadt.informatik.hostage.ui2.model.ExpandableListItem;
 
@@ -33,6 +32,19 @@ public abstract class ExpandableListAdapter extends BaseExpandableListAdapter {
         this._sectionTitleToChildData = dataMapping;
     }
 
+    public void setData(HashMap<String, ArrayList<ExpandableListItem>> dataMapping){
+        this._sectionTitleToChildData = dataMapping;
+    }
+    public HashMap<String, ArrayList<ExpandableListItem>> getData(){
+        return this._sectionTitleToChildData;
+    }
+    public void setSectionHeader(List<String> listSectionHeaders){
+        this._sectionHeader = listSectionHeaders;
+    }
+    public List<String> getSectionHeaders(){
+        return this._sectionHeader;
+    }
+
     @Override
     public Object getChild(int section, int row) {
         return this._sectionTitleToChildData.get(this._sectionHeader.get(section))

File diff suppressed because it is too large
+ 646 - 436
src/de/tudarmstadt/informatik/hostage/ui2/fragment/RecordOverviewFragment.java


+ 1473 - 1375
src/de/tudarmstadt/informatik/hostage/ui2/fragment/StatisticsFragment.java

@@ -1,15 +1,7 @@
 package de.tudarmstadt.informatik.hostage.ui2.fragment;
 
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-
 import android.annotation.SuppressLint;
+import android.app.Activity;
 import android.app.Fragment;
 import android.app.FragmentManager;
 import android.content.Context;
@@ -24,6 +16,7 @@ import android.widget.AdapterView;
 import android.widget.ImageButton;
 import android.widget.LinearLayout;
 import android.widget.ListView;
+import android.widget.ProgressBar;
 import android.widget.TextView;
 
 import com.echo.holographlibrary.Bar;
@@ -34,6 +27,15 @@ import com.echo.holographlibrary.LinePoint;
 import com.echo.holographlibrary.PieGraph;
 import com.echo.holographlibrary.PieSlice;
 
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.deprecated.UglyDbHelper;
 import de.tudarmstadt.informatik.hostage.logging.Record;
@@ -55,1425 +57,1521 @@ import de.tudarmstadt.informatik.hostage.ui2.popup.SplitPopupItem;
  */
 public class StatisticsFragment extends Fragment implements ChecklistDialog.ChecklistDialogListener, DateTimeDialogFragment.DateTimeDialogFragmentListener {
 
-	static final String FILTER_MENU_TITLE_BSSID = "BSSID";
-	static final String FILTER_MENU_TITLE_ESSID = "ESSID";
-	static final String FILTER_MENU_TITLE_PROTOCOLS = MainActivity.getContext().getString(R.string.stats_protocols);
-	static final String FILTER_MENU_TITLE_PROTOCOL = MainActivity.getContext().getString(R.string.rec_protocol);
-	static final String FILTER_MENU_TITLE_TIMESTAMP_BELOW = MainActivity.getContext().getString(R.string.rec_latest);
-	static final String FILTER_MENU_TITLE_TIMESTAMP_ABOVE = MainActivity.getContext().getString(R.string.rec_earliest);
-
-	static final String FILTER_MENU_TITLE_REMOVE = MainActivity.getContext().getString(R.string.rec_reset_filter);
-	static final String FILTER_MENU_POPUP_TITLE = MainActivity.getContext().getString(R.string.rec_filter_by);
-
-	static final String MENU_TITLE_PROTOCOLS = MainActivity.getContext().getString(R.string.stats_protocols);
-	static final String MENU_TITLE_NETWORK = MainActivity.getContext().getString(R.string.stats_networks);
-	static final String MENU_TITLE_ATTACKS = MainActivity.getContext().getString(R.string.stats_attacks);
-
-	static final String MENU_POPUP_TITLE = MainActivity.getContext().getString(R.string.stats_visualize);
-
-	static final String CHART_TYPE_TITLE_BAR = MainActivity.getContext().getString(R.string.stats_bar_plot);
-	static final String CHART_TYPE_TITLE_PIE = MainActivity.getContext().getString(R.string.stats_pie_plot);
-	static final String CHART_TYPE_TITLE_LINE = MainActivity.getContext().getString(R.string.stats_line_plot);
-
-	static final String DIALOG_PROTOCOLS_TITLE = MainActivity.getContext().getString(R.string.stats_select_protocol_data);
-	static final String DIALOG_NETWORK_TITLE = MainActivity.getContext().getString(R.string.stats_select_network_data);
-	static final String DIALOG_ATTACK_TITLE = MainActivity.getContext().getString(R.string.stats_select_attack_data);
-
-	static final String COMPARE_TITLE_AttacksPerProtocol = MainActivity.getContext().getString(R.string.stats_attacks_protocol);
-	static final String COMPARE_TITLE_UsesPerProtocol = MainActivity.getContext().getString(R.string.stats_uses_protocol);
-	static final String COMPARE_TITLE_AttacksPerDate = MainActivity.getContext().getString(R.string.stats_attacks_date);
-	static final String COMPARE_TITLE_AttacksPerTime = MainActivity.getContext().getString(R.string.stats_attacks_time);
-	static final String COMPARE_TITLE_AttacksPerBSSID = MainActivity.getContext().getString(R.string.stats_attacks_bssid);
-	static final String COMPARE_TITLE_AttacksPerESSID = MainActivity.getContext().getString(R.string.stats_attacks_essid);
-	static final String FILTER_MENU_PROTOCOL_SINGLE_CHOICE_TITLE = MainActivity.getContext().getString(R.string.stats_select_protocol);
-
-	static final String TABLE_HEADER_VALUE_TITLE_ATTACKS_COUNT = MainActivity.getContext().getString(R.string.stats_attacks_count);
-	static final String TABLE_HEADER_VALUE_TITLE_ATTACKS_PERCENTAGE = MainActivity.getContext().getString(R.string.stats_per_cent_all);
-
-	static final String OTHER_CHART_TITLE = MainActivity.getContext().getString(R.string.stats_other);
-
-	// MINIMAL 2
-	static int MAX_NUMBER_OF_CHART_OBJECTS = 6;
-
-	private boolean wasBelowTimePicker;
-
-	private LogFilter filter;
-	private boolean showFilterButton;
-
-	private PieGraph pieGraph;
-	private LineGraph lineGraph;
-	private BarGraph barGraph;
-
-	private View rootView;
-	private View currentPlotView;
-
-	private ArrayList<Integer> colorList;
-	private ArrayList<PlotComparisonItem> currentData;
-
-	private UglyDbHelper dbh;
-
-	private ListView legendListView;
-
-	private String selectedCompareData = COMPARE_TITLE_AttacksPerProtocol;
-
-	public enum ChartType {
-		PIE_CHART(0), BAR_CHART(1), LINE_CHART(2);
-
-		private int value;
-
-		private ChartType(int value) {
-			this.value = value;
-		}
-
-		static public ChartType create(int value) {
-			if (value < 0 || value >= ChartType.values().length)
-				return ChartType.PIE_CHART;
-			return ChartType.values()[value];
-		}
-
-		public String toString() {
-			if (this.equals(ChartType.create(0))) {
-				return CHART_TYPE_TITLE_PIE;
-			}
-			if (this.equals(ChartType.create(1))) {
-				return CHART_TYPE_TITLE_BAR;
-			}
-			return CHART_TYPE_TITLE_LINE;
-		}
-
-	}
-
-	private ImageButton getFilterButton() {
-		return (ImageButton) this.rootView.findViewById(R.id.FilterButton);
-	}
-
-	public int getLayoutID() {
-		return R.layout.fragment_statistics;
-	}
-
-	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
-
-		super.onCreateView(inflater, container, savedInstanceState);
-
-		getActivity().setTitle(getResources().getString(R.string.drawer_statistics));
-
-		dbh = new UglyDbHelper(this.getBaseContext());
-
-		// Get the message from the intent
-
-		if (this.filter == null) {
-			Intent intent = this.getActivity().getIntent();
-			LogFilter filter = intent.getParcelableExtra(LogFilter.LOG_FILTER_INTENT_KEY);
-			if (filter == null) {
-				this.clearFilter();
-			} else {
-				this.filter = filter;
-			}
-		}
-
-		this.rootView = inflater.inflate(this.getLayoutID(), container, false);
-
-		this.configureRootView(this.rootView);
-
-		return this.rootView;
-	}
-
-	@Override
-	public void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		setHasOptionsMenu(true);
-		setRetainInstance(true);
-	}
-
-	@Override
-	public void onConfigurationChanged(Configuration newConfig) {
-		super.onConfigurationChanged(newConfig);
-		LayoutInflater inflater = LayoutInflater.from(getActivity());
-
-		ViewGroup container = (ViewGroup) this.getView();
-		container.removeAllViewsInLayout();
-		this.rootView = inflater.inflate(this.getLayoutID(), container, false);
-		container.addView(this.rootView);
-
-		this.configureRootView(this.rootView);
-	}
-
-	private Context getBaseContext() {
-		return this.getActivity().getBaseContext();
-	}
-
-	private Context getApplicationContext() {
-		return this.getActivity().getApplicationContext();
-	}
-
-	public void configureRootView(View rootView) {
-		LinearLayout plotLayout = (LinearLayout) rootView.findViewById(R.id.plot_layout);
-		plotLayout.setWillNotDraw(false);
-		plotLayout.removeAllViews();
-
-		plotLayout.setWillNotDraw(false);
-
-		this.legendListView = (ListView) rootView.findViewById(R.id.legend_list_view);
-		this.legendListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
-			@Override
-			public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
-				StatisticsFragment.this.userTappedOnLegendItem(i);
-			}
-		});
-		rootView.setWillNotDraw(false);
-
-		this.actualiseCurrentPlot();
-
-		ImageButton visualButton = (ImageButton) rootView.findViewById(R.id.plot_data_button);
-		visualButton.setOnClickListener(new View.OnClickListener() {
-			public void onClick(View v) {
-				StatisticsFragment.this.openBarSelectionMenuOnView(v);
-			}
-		});
-
-		ImageButton filterButton = this.getFilterButton();
-		filterButton.setOnClickListener(new View.OnClickListener() {
-			public void onClick(View v) {
-				StatisticsFragment.this.openFilterMenuOnView(v);
-			}
-		});
-
-		if (this.currentPlotView instanceof BarGraph) {
-			this.setTitle("" + this.getCurrentSelectedProtocol() + ": " + this.selectedCompareData);
-		} else {
-			this.setTitle(this.selectedCompareData);
-		}
-	}
-
-	public void setTitle(String title) {
-		TextView titleView = (TextView) this.rootView.findViewById(R.id.title_text_view);
-		if (title != null && titleView != null) {
-			titleView.setText(title);
-			titleView.invalidate();
-		}
-	}
-
-	public String getTitle() {
-		TextView titleView = (TextView) this.rootView.findViewById(R.id.title_text_view);
-		if (titleView != null) {
-			return "" + titleView.getText();
-		}
-		return "";
-	}
-
-	public void onStart() {
-		super.onStart();
-		this.actualiseCurrentPlot();
-		this.currentPlotView.invalidate();
-
-		if (this.currentPlotView instanceof BarGraph) {
-			this.setTitle("" + this.getCurrentSelectedProtocol() + ": " + this.selectedCompareData);
-		} else {
-			this.setTitle(this.selectedCompareData);
-		}
-	}
-
-	public void setChartType(ChartType type) {
-		boolean shouldChange = true;
-		this.clearFilter();
-		if (this.currentPlotView != null) {
-			if (type == ChartType.PIE_CHART) {
-				shouldChange = !(this.currentPlotView instanceof PieGraph);
-				// SET FILTER BUTTON HIDDEN
-				ImageButton filterButton = this.getFilterButton();
-				if (filterButton != null)
-					filterButton.setVisibility(View.GONE);
-			} else {
-				if (this.pieGraph != null)
-					this.pieGraph.setVisibility(View.GONE);
-				// SHOW FILTER BUTTON
-				ImageButton filterButton = this.getFilterButton();
-				if (filterButton != null)
-					filterButton.setVisibility(View.VISIBLE);
-			}
-			if (type == ChartType.LINE_CHART) {
-				shouldChange = !(this.currentPlotView instanceof LineGraph);
-			} else {
-				if (this.lineGraph != null)
-					this.lineGraph.setVisibility(View.GONE);
-			}
-			if (type == ChartType.BAR_CHART) {
-				shouldChange = !(this.currentPlotView instanceof BarGraph);
-
-			} else {
-				if (this.barGraph != null)
-					this.barGraph.setVisibility(View.GONE);
-
-			}
-		}
-		if (shouldChange) {
-			this.currentPlotView = this.getPlotViewForType(type);
-			this.currentPlotView.setVisibility(View.VISIBLE);
-
-		}
-		this.actualiseCurrentPlot();
-
-	}
-
-	public View getPlotViewForType(ChartType type) {
-		switch (type) {
-		case PIE_CHART:
-			return this.getPieGraphView();
-		case LINE_CHART:
-			return this.getLineGraphView();
-		default:
-			return this.getBarGraphView();
-		}
-	}
-
-	public void actualiseLegendList() {
-		StatisticListAdapter adapter = new StatisticListAdapter(this.getApplicationContext(), this.currentData);
-		if (this.currentPlotView instanceof LineGraph) {
-			adapter.setValueFormatter(new StatisticListAdapter.ValueFormatter() {
-				@Override
-				public String convertValueForItemToString(PlotComparisonItem item) {
-					return String.format("%.02f", item.getValue2()) + " %" + " " + "(" + (item.getValue1().intValue()) + ")";
-				}
-			});
-		} else {
-
-			adapter.setValueFormatter(new StatisticListAdapter.ValueFormatter() {
-				@Override
-				public String convertValueForItemToString(PlotComparisonItem item) {
-					int v = (int) item.getValue2().intValue();
-					return "" + v;
-				}
-			});
-
-		}
-		this.legendListView.setAdapter(adapter);
-
-		TextView tableHeaderTitleView = (TextView) this.rootView.findViewById(R.id.table_header_title_textview);
-		TextView tableHeaderValueView = (TextView) this.rootView.findViewById(R.id.table_header_value_textview);
-		if (this.currentPlotView instanceof LineGraph) {
-			tableHeaderTitleView.setText(FILTER_MENU_TITLE_ESSID);
-			tableHeaderValueView.setText(TABLE_HEADER_VALUE_TITLE_ATTACKS_PERCENTAGE);
-		}
-		if (this.currentPlotView instanceof PieGraph) {
-			tableHeaderTitleView.setText(FILTER_MENU_TITLE_PROTOCOL);
-			tableHeaderValueView.setText(TABLE_HEADER_VALUE_TITLE_ATTACKS_COUNT);
-		}
-		if (this.currentPlotView instanceof BarGraph) {
-			tableHeaderValueView.setText(TABLE_HEADER_VALUE_TITLE_ATTACKS_COUNT);
-			if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerBSSID)) {
-				tableHeaderTitleView.setText(FILTER_MENU_TITLE_BSSID);
-			} else {
-				tableHeaderTitleView.setText(FILTER_MENU_TITLE_ESSID);
-			}
-		}
-	}
-
-	/*
-	 * MENU
-	 */
-	private void openBarSelectionMenuOnView(View anchorView) {
-		SimplePopupTable visualiseMenu = new SimplePopupTable(this.getActivity(), new AbstractPopup.OnPopupItemClickListener() {
-			public void onItemClick(Object ob) {
-				if (ob instanceof AbstractPopupItem) {
-					AbstractPopupItem item = (AbstractPopupItem) ob;
-					StatisticsFragment.this.userSelectMenuItem(item);
-				}
-			}
-		});
-		visualiseMenu.setTitle(MENU_POPUP_TITLE);
-		int id = 0;
-		for (String title : StatisticsFragment.this.getMenuTitles()) {
-			SimplePopupItem item = new SimplePopupItem(this.getActivity());
-			item.setTitle(title);
-			item.setItemId(id);
-			item.setSelected(false);
-			visualiseMenu.addItem(item);
-			id++;
-		}
-		visualiseMenu.showOnView(anchorView);
-	}
-
-	private void userSelectMenuItem(AbstractPopupItem item) {
-		// OPEN A DIALOG TO SPECIFY THE VISUALISE DATA
-		if (item.getTitle().equals(MENU_TITLE_PROTOCOLS)) {
-			ChartType chartType = ChartType.PIE_CHART;
-			this.selectedCompareData = COMPARE_TITLE_AttacksPerProtocol;
-			this.setChartType(chartType);
-			this.setTitle(COMPARE_TITLE_AttacksPerProtocol);
-		}
-		if (item.getTitle().equals(MENU_TITLE_NETWORK)) {
-			this.openNetworkDataDialog();
-		}
-		if (item.getTitle().equals(MENU_TITLE_ATTACKS)) {
-			this.openAttackDataDialog();
-		}
-	}
-
-	private ArrayList<String> getMenuTitles() {
-		ArrayList<String> titles = new ArrayList<String>();
-		titles.add(MENU_TITLE_PROTOCOLS);
-		titles.add(MENU_TITLE_NETWORK);
-		titles.add(MENU_TITLE_ATTACKS);
-		return titles;
-	}
-
-	/*
-	 * PLOT DATA DIALOGS
-	 */
-	private void openProtocolDataDialog() {
-		ArrayList<String> titles = this.getDialogProtocolDataTitle();
-		ChecklistDialog newFragment = new ChecklistDialog(DIALOG_PROTOCOLS_TITLE, titles, this.selectedData(titles), false, this);
-		newFragment.show(this.getActivity().getFragmentManager(), DIALOG_PROTOCOLS_TITLE);
-	}
-
-	private void openNetworkDataDialog() {
-		ArrayList<String> titles = this.getDialogNetworkDataTitle();
-		ChecklistDialog newFragment = new ChecklistDialog(DIALOG_NETWORK_TITLE, titles, this.selectedData(titles), false, this);
-		newFragment.show(this.getActivity().getFragmentManager(), DIALOG_NETWORK_TITLE);
-	}
-
-	private void openAttackDataDialog() {
-		ArrayList<String> titles = this.getDialogAttackDataTitle();
-		ChecklistDialog newFragment = new ChecklistDialog(DIALOG_ATTACK_TITLE, titles, this.selectedData(titles), false, this);
-		newFragment.show(this.getActivity().getFragmentManager(), DIALOG_ATTACK_TITLE);
-	}
-
-	/*
-	 * 
-	 * DIALOG ACTION METHODS
-	 */
-	public void onDialogPositiveClick(ChecklistDialog dialog) {
-		String title = dialog.getTitle();
-		ArrayList<String> titles = dialog.getSelectedItemTitles();
-
-		if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)) {
-			// titles = titles.size() == 0 ? this.protocolTitles() : titles;
-			this.filter.setProtocols(titles);
-			this.actualiseCurrentPlot();
-			return;
-		}
-		if (title.equals(FILTER_MENU_PROTOCOL_SINGLE_CHOICE_TITLE)) {
-			if (titles.size() == 0) {
-				titles = new ArrayList<String>();
-				titles.add(this.protocolTitles().get(0));
-			}
-			this.filter.setProtocols(titles);
-
-			this.actualiseCurrentPlot();
-			String fragTitle = "" + this.getCurrentSelectedProtocol() + ": " + this.selectedCompareData;
-			this.setTitle(fragTitle);
-			return;
-		}
-		if (title.equals(FILTER_MENU_TITLE_ESSID)) {
-			this.filter.setESSIDs(titles);
-			this.actualiseCurrentPlot();
-			return;
-		}
-		if (title.equals(FILTER_MENU_TITLE_BSSID)) {
-			this.filter.setBSSIDs(titles);
-			this.actualiseCurrentPlot();
-			return;
-		}
-
-		if (titles.size() != 0) {
-			String data = titles.get(0);
-			this.setTitle(data);
-			if (title.equals(DIALOG_PROTOCOLS_TITLE)) {
-				ChartType chartType = ChartType.PIE_CHART;
-				this.selectedCompareData = data;
-				this.setChartType(chartType);
-			}
-			if (title.equals(DIALOG_ATTACK_TITLE)) {
-				ChartType chartType = ChartType.LINE_CHART;
-				this.selectedCompareData = data;
-				this.setChartType(chartType);
-			}
-			if (title.equals(DIALOG_NETWORK_TITLE)) {
-				ChartType chartType = ChartType.BAR_CHART;
-				this.selectedCompareData = data;
-				this.setChartType(chartType);
-
-				String fragTitle = "" + this.getCurrentSelectedProtocol() + ": " + this.selectedCompareData;
-				this.setTitle(fragTitle);
-			}
-		}
-
-	}
-
-	public void onDialogNegativeClick(ChecklistDialog dialog) {
-
-	}
-
-	/*
-	 * 
-	 * DIALOG DATA
-	 */
-	private ArrayList<String> getDialogProtocolDataTitle() {
-		ArrayList<String> data = new ArrayList<String>();
-		data.add(COMPARE_TITLE_AttacksPerProtocol);
-		data.add(COMPARE_TITLE_UsesPerProtocol);
-		return data;
-	}
-
-	private ArrayList<String> getDialogAttackDataTitle() {
-		ArrayList<String> data = new ArrayList<String>();
-		data.add(COMPARE_TITLE_AttacksPerDate);
-		data.add(COMPARE_TITLE_AttacksPerTime);
-		return data;
-	}
+    static final String FILTER_MENU_TITLE_BSSID = "BSSID";
+    static final String FILTER_MENU_TITLE_ESSID = "ESSID";
+    static final String FILTER_MENU_TITLE_PROTOCOLS = MainActivity.getContext().getString(R.string.stats_protocols);
+    static final String FILTER_MENU_TITLE_PROTOCOL = MainActivity.getContext().getString(R.string.rec_protocol);
+    static final String FILTER_MENU_TITLE_TIMESTAMP_BELOW = MainActivity.getContext().getString(R.string.rec_latest);
+    static final String FILTER_MENU_TITLE_TIMESTAMP_ABOVE = MainActivity.getContext().getString(R.string.rec_earliest);
 
-	private ArrayList<String> getDialogNetworkDataTitle() {
-		ArrayList<String> data = new ArrayList<String>();
-		data.add(COMPARE_TITLE_AttacksPerESSID);
-		data.add(COMPARE_TITLE_AttacksPerBSSID);
-		return data;
-	}
+    static final String FILTER_MENU_TITLE_REMOVE = MainActivity.getContext().getString(R.string.rec_reset_filter);
+    static final String FILTER_MENU_POPUP_TITLE = MainActivity.getContext().getString(R.string.rec_filter_by);
 
-	private boolean[] selectedData(ArrayList<String> data) {
-		boolean[] selected = new boolean[data.size()];
-		// SET DEFAULT
-		selected[0] = true;
-		return selected;
-	}
 
-	/*
-	 * 
-	 * FILTER BUTTON
-	 */
-	private void openFilterMenuOnView(View anchor) {
-		SimplePopupTable filterMenu = new SimplePopupTable(this.getActivity(), new AbstractPopup.OnPopupItemClickListener() {
-			public void onItemClick(Object ob) {
-				if (ob instanceof AbstractPopupItem) {
-					AbstractPopupItem item = (AbstractPopupItem) ob;
-					StatisticsFragment.this.onFilterMenuItemSelected(item);
-				}
-			}
-		});
-
-		filterMenu.setTitle(FILTER_MENU_POPUP_TITLE);
-		for (String title : StatisticsFragment.this.filterMenuTitles()) {
-			AbstractPopupItem item = null;
-			if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW))
-				continue;
-			if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)) {
-				item = new SplitPopupItem(this.getActivity());
-				item.setValue(SplitPopupItem.RIGHT_TITLE, FILTER_MENU_TITLE_TIMESTAMP_BELOW);
-				item.setValue(SplitPopupItem.LEFT_TITLE, FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
-				if (this.filter.hasBelowTimestamp()) {
-					item.setValue(SplitPopupItem.RIGHT_SUBTITLE, this.getDateAsString(this.filter.belowTimestamp));
-				}
-				if (this.filter.hasAboveTimestamp()) {
-					item.setValue(SplitPopupItem.LEFT_SUBTITLE, this.getDateAsString(this.filter.aboveTimestamp));
-				}
-			} else {
-				item = new SimplePopupItem(this.getActivity());
-				item.setTitle(title);
-				((SimplePopupItem) item).setSelected(this.isFilterSetForTitle(title));
-			}
-
-			filterMenu.addItem(item);
-		}
-		filterMenu.showOnView(anchor);
-	}
+    static final String MENU_TITLE_PROTOCOLS = MainActivity.getContext().getString(
+			R.string.stats_protocols);
+    static final String MENU_TITLE_NETWORK = MainActivity.getContext().getString(
+			R.string.stats_networks);
+    static final String MENU_TITLE_ATTACKS = MainActivity.getContext().getString(
+			R.string.stats_attacks);
 
-	private void onFilterMenuItemSelected(AbstractPopupItem item) {
-		if (item instanceof SplitPopupItem) {
-			SplitPopupItem sItem = (SplitPopupItem) item;
-			this.wasBelowTimePicker = sItem.wasRightTouch;
-			if (this.wasBelowTimePicker) {
-				this.openTimestampToFilterDialog();
-			} else {
-				this.openTimestampFromFilterDialog();
-			}
-			return;
-		}
-		String title = item.getTitle();
-		if (title.equals(FILTER_MENU_TITLE_ESSID)) {
-			this.openESSIDFilterDialog();
-		}
-		if (title.equals(FILTER_MENU_TITLE_BSSID)) {
-			this.openBSSIDFilterDialog();
-		}
-		if (title.equals(FILTER_MENU_TITLE_PROTOCOL)) {
-			this.openFilterDialogSelectProtocol();
-		}
-		if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)) {
-			this.openProtocolsFilterDialog();
-		}
-		if (title.equals(FILTER_MENU_TITLE_REMOVE)) {
-			this.clearFilter();
-			this.actualiseCurrentPlot();
-		}
-	}
+    static final String MENU_POPUP_TITLE = MainActivity.getContext().getString(
+			R.string.stats_visualize);
 
-	private ArrayList<String> filterMenuTitles() {
-		ArrayList<String> titles = new ArrayList<String>();
-		if (this.currentPlotView instanceof LineGraph) {
-			titles.add(FILTER_MENU_TITLE_ESSID);
-			titles.add(FILTER_MENU_TITLE_PROTOCOLS);
-			titles.add(FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
-			if (this.filter.hasESSIDs() || this.filter.hasATimestamp()
-					|| (this.filter.getProtocols() != null && this.filter.hasProtocols() && this.filter.getProtocols().size() != this.protocolTitles().size())) {
-				titles.add(FILTER_MENU_TITLE_REMOVE);
-			}
-		} else {
-			titles.add(FILTER_MENU_TITLE_PROTOCOL);
-			String protocol = this.getCurrentSelectedProtocol();
-			if (protocol.length() > 0) {
-				if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerBSSID)) {
-					titles.add(FILTER_MENU_TITLE_BSSID);
-				} else {
-					// DEFAULT
-					titles.add(FILTER_MENU_TITLE_ESSID);
-				}
-			}
-			titles.add(FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
-			if (this.filter.hasATimestamp() || this.filter.hasESSIDs() || this.filter.hasBSSIDs()
-					|| (this.currentPlotView instanceof LineGraph && this.filter.hasProtocols())) {
-				titles.add(FILTER_MENU_TITLE_REMOVE);
-			}
-		}
-		return titles;
-	}
+    static final String CHART_TYPE_TITLE_BAR = MainActivity.getContext().getString(
+			R.string.stats_bar_plot);
+    static final String CHART_TYPE_TITLE_PIE = MainActivity.getContext().getString(R.string.stats_pie_plot);
+    static final String CHART_TYPE_TITLE_LINE = MainActivity.getContext().getString(R.string.stats_line_plot);
 
-	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);
-	}
+    static final String DIALOG_PROTOCOLS_TITLE = MainActivity.getContext().getString(R.string.stats_select_protocol_data);
+    static final String DIALOG_NETWORK_TITLE = MainActivity.getContext().getString(R.string.stats_select_network_data);
+    static final String DIALOG_ATTACK_TITLE = MainActivity.getContext().getString(R.string.stats_select_attack_data);
 
-	private void openFilterDialogSelectProtocol() {
-		ArrayList<String> titles = this.protocolTitles();
-		boolean[] selected = new boolean[titles.size()];
-		int i = 0;
-		for (String title : titles) {
-			selected[i] = title.equals(this.getCurrentSelectedProtocol());
-			i++;
-		}
-		ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_PROTOCOL_SINGLE_CHOICE_TITLE, titles, selected, false, this);
-		newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_PROTOCOL_SINGLE_CHOICE_TITLE);
-	}
-
-	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);
-	}
+    static  final String COMPARE_TITLE_AttacksPerProtocol   = MainActivity.getContext().getString(R.string.stats_attacks_protocol);
+    static  final String COMPARE_TITLE_UsesPerProtocol      = MainActivity.getContext().getString(R.string.stats_uses_protocol);
+    static  final String COMPARE_TITLE_AttacksPerDate       = MainActivity.getContext().getString(R.string.stats_attacks_date);
+    static  final String COMPARE_TITLE_AttacksPerTime       = MainActivity.getContext().getString(R.string.stats_attacks_time);
+    static  final String COMPARE_TITLE_AttacksPerBSSID      = MainActivity.getContext().getString(R.string.stats_attacks_bssid);
+    static  final String COMPARE_TITLE_AttacksPerESSID      = MainActivity.getContext().getString(R.string.stats_attacks_essid);
+    static final String FILTER_MENU_PROTOCOL_SINGLE_CHOICE_TITLE = MainActivity.getContext().getString(R.string.stats_select_protocol);
 
-	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 openTimestampFromFilterDialog() {
-		this.wasBelowTimePicker = false;
-		DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
-		newFragment.setDateChangeListener(this);
-		newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
+    static final String TABLE_HEADER_VALUE_TITLE_ATTACKS_COUNT = MainActivity.getContext().getString(R.string.stats_attacks_count);
+    static final String TABLE_HEADER_VALUE_TITLE_ATTACKS_PERCENTAGE = MainActivity.getContext().getString(R.string.stats_per_cent_all);
 
-		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.setDateChangeListener(this);
-		newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_TIMESTAMP_BELOW);
-		if (this.filter.belowTimestamp != Long.MAX_VALUE)
-			newFragment.setDate(this.filter.belowTimestamp);
-	}
+    static final String OTHER_CHART_TITLE = MainActivity.getContext().getString(R.string.stats_other);
 
-	public ArrayList<String> essids() {
-		ArrayList<String> records;
-		if (this.currentPlotView instanceof BarGraph) {
-			records = dbh.getUniqueESSIDRecordsForProtocol(this.getCurrentSelectedProtocol());
-		} else {
-			records = dbh.getUniqueESSIDRecords();
-		}
-		return records;
-	}
+    // MINIMAL 2
+    static int MAX_NUMBER_OF_CHART_OBJECTS = 6;
 
-	public boolean[] selectedESSIDs() {
-		ArrayList<String> essids = this.essids();
-		boolean[] selected = new boolean[essids.size()];
+    private boolean wasBelowTimePicker;
 
-		int i = 0;
-		for (String essid : essids) {
-			selected[i] = (this.filter.getESSIDs().contains(essid));
-			i++;
-		}
-		return selected;
-	}
+    private LogFilter filter;
+    private boolean showFilterButton;
 
-	public ArrayList<String> bssids() {
-		ArrayList<String> records;
-		if (this.currentPlotView instanceof BarGraph) {
-			records = dbh.getUniqueBSSIDRecordsForProtocol(this.getCurrentSelectedProtocol());
-		} else {
-			records = dbh.getUniqueBSSIDRecords();
-		}
-		return records;
-	}
+    private PieGraph pieGraph;
+    private LineGraph lineGraph;
+    private BarGraph barGraph;
 
-	public boolean[] selectedBSSIDs() {
-		ArrayList<String> bssids = this.bssids();
+    private View rootView;
+    private View currentPlotView;
 
-		boolean[] selected = new boolean[bssids.size()];
+    private Thread loader;
+    private ProgressBar spinner;
 
-		int i = 0;
-		for (String bssid : bssids) {
-			selected[i] = (this.filter.getBSSIDs().contains(bssid));
-			i++;
-		}
-		return selected;
-	}
+    private ArrayList<Integer> colorList;
+    private ArrayList<PlotComparisonItem> currentData;
 
-	public void onDateTimePickerPositiveClick(DateTimeDialogFragment dialog) {
-		if (this.wasBelowTimePicker) {
-			this.filter.setBelowTimestamp(dialog.getDate());
-		} else {
-			this.filter.setAboveTimestamp(dialog.getDate());
-		}
-		this.actualiseCurrentPlot();
-	}
+    private UglyDbHelper dbh;
 
-	public void onDateTimePickerNegativeClick(DateTimeDialogFragment dialog) {
-		if (this.wasBelowTimePicker) {
-			this.filter.setBelowTimestamp(Long.MAX_VALUE);
-		} else {
-			this.filter.setAboveTimestamp(Long.MIN_VALUE);
-		}
-		this.actualiseCurrentPlot();
-	}
+    private ListView legendListView;
 
-	/*
-	 * 
-	 * PLOT TYPES
-	 * 
-	 * *
-	 */
-	public PieGraph getPieGraphView() {
-		if (this.pieGraph == null) {
-			this.pieGraph = new PieGraph(this.getApplicationContext());
-			LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
-			plotLayout.addView(this.pieGraph);
-			this.pieGraph.setOnSliceClickedListener(new PieGraph.OnSliceClickedListener() {
-				@Override
-				public void onClick(int index) {
-					StatisticsFragment.this.onSliceClick(index);
-				}
-			});
-		}
-		return this.pieGraph;
-	}
 
-	public LineGraph getLineGraphView() {
-		if (this.lineGraph == null) {
-			this.lineGraph = new LineGraph(this.getActivity());
-			LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
-			plotLayout.addView(this.lineGraph);
-			this.lineGraph.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
-		}
-		return this.lineGraph;
-	}
 
-	public BarGraph getBarGraphView() {
-		if (this.barGraph == null) {
-			this.barGraph = new BarGraph(this.getActivity());
-			LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
-			this.barGraph.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
-			plotLayout.addView(this.barGraph);
-			this.barGraph.setShowBarText(false);
-			this.barGraph.setPopupImageID(R.drawable.popup_black);
-			this.barGraph.setOnBarClickedListener(new BarGraph.OnBarClickedListener() {
-				@Override
-				public void onClick(int i) {
-					StatisticsFragment.this.onBarClick(i);
-				}
-			});
-		}
-		return this.barGraph;
-	}
+    private String selectedCompareData = COMPARE_TITLE_AttacksPerProtocol;
 
-	/*
-	 * FEED PLOTS WITH DATA
-	 */
-	public void setPieGraphData(PieGraph piegraph) {
-		this.currentData = this.getPieData();
-		if (this.currentData == null) {
-			this.currentData = new ArrayList<PlotComparisonItem>();
-		}
-
-		this.pieGraph.removeSlices();
-
-		for (PlotComparisonItem item : this.currentData) {
-			PieSlice slice = new PieSlice();
-			slice.setColor(item.getColor());
-			Double value2 = (Double) item.getValue2();
-			float v = value2.floatValue();
-			slice.setValue(v);
-			slice.setTitle(item.getTitle());
-			this.pieGraph.addSlice(slice);
-		}
-		this.pieGraph.invalidate();
+    public enum ChartType {
+        PIE_CHART(0),
+        BAR_CHART(1),
+        LINE_CHART(2);
 
-	}
+        private int value;
 
-	public void setLineGraphData(LineGraph linegraph) {
-		this.currentData = this.getLineData();
-		if (this.currentData == null) {
-			this.currentData = new ArrayList<PlotComparisonItem>();
-		}
-
-		this.lineGraph.removeAllLines();
-		double rangeMax_Y = 0;
-		double rangeMin_Y = 0;
-
-		double rangeMax_X = 0;
-		double rangeMin_X = 0;
-
-		int count = 0;
-		for (PlotComparisonItem lineItem : this.currentData) {
-			ArrayList<PlotComparisonItem> data = lineItem.getOtherData();
-			int index = 0;
-			Line l = new Line();
-			int lineColor = lineItem.getColor();
-			l.setColor(lineColor);
-
-			for (PlotComparisonItem pointItem : data) {
-				LinePoint p = new LinePoint();
-				p.setX(pointItem.getValue1());
-				Double value2 = pointItem.getValue2();
-				p.setY(value2);
-				p.setColor(lineColor);
-				l.addPoint(p);
-				rangeMax_Y = Math.max(pointItem.getValue2(), rangeMax_Y);
-				rangeMax_X = Math.max(pointItem.getValue1(), rangeMax_X);
-
-				if (count != 0) {
-					rangeMin_Y = Math.min(pointItem.getValue2(), rangeMin_Y);
-					rangeMin_X = Math.min(pointItem.getValue1(), rangeMin_X);
-				} else {
-					rangeMin_Y = pointItem.getValue2();
-					rangeMin_X = pointItem.getValue1();
-				}
-				index++;
-				count++;
-			}
-			this.lineGraph.addLine(l);
-		}
-		// add a bit more space
-		rangeMax_Y++;
-		rangeMin_Y--;
-
-		boolean shouldUseDate = this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerDate);
-		if (shouldUseDate) {
-			this.lineGraph.resetXLimits();
-
-			if (this.filter.hasBelowTimestamp()) {
-				rangeMax_X = Math.max(this.filter.belowTimestamp, rangeMax_X);
-			}
-			if (this.filter.hasAboveTimestamp()) {
-				rangeMin_X = Math.min(this.filter.aboveTimestamp, rangeMin_X);
-			}
-
-			double stepRange = (rangeMax_X - rangeMin_X) / (60 * 60 * 24 * 1000);
-			this.lineGraph.setxAxisStep(Math.max(1, (float) Math.min(stepRange, 4)));
-
-			this.lineGraph.setRangeX(rangeMin_X, rangeMax_X);
-
-			this.lineGraph.setConverter(new LineGraph.AxisDataConverter() {
-				@Override
-				public String convertDataForX_Position(double x) {
-					return StatisticsFragment.this.getDateAsDayString((long) x);
-				}
-
-				@Override
-				public String convertDataForY_Position(double y) {
-					return "" + (long) y;
-				}
-			});
-		} else {
-			this.lineGraph.setxAxisStep(12.f);
-			this.lineGraph.setRangeX(0, 24);
-			this.lineGraph.setConverter(null);
-		}
-
-		int maxY = (int) (rangeMax_Y - rangeMin_Y);
-		this.lineGraph.setYAxisStep(Math.min(maxY, 5));
-		int yStep = (int) this.lineGraph.getyAxisStep();
-		if ((maxY % yStep) != 0) {
-			maxY = maxY + (yStep - (maxY % yStep));
-		}
-		this.lineGraph.setRangeY(rangeMin_Y, rangeMin_Y + maxY);
-		this.lineGraph.setLineToFill(0);
-		this.lineGraph.invalidate();
-	}
+        private ChartType(int value) {
+            this.value = value;
+        }
+        static public ChartType create(int value){
+            if (value < 0 || value  >= ChartType.values().length) return ChartType.PIE_CHART;
+            return  ChartType.values()[value];
+        }
 
-	public void setBarGraphData(BarGraph bargraph) {
-		this.currentData = this.getBarData();
-		if (this.currentData == null) {
-			this.currentData = new ArrayList<PlotComparisonItem>();
-		}
-
-		ArrayList<Bar> bars = new ArrayList<Bar>();
-
-		for (PlotComparisonItem item : this.currentData) {
-			Bar d = new Bar();
-			d.setColor(item.getColor());
-			Long value2 = item.getValue2().longValue();
-			d.setName("" + value2);
-			d.setValue(value2.floatValue());
-			bars.add(d);
-		}
-
-		this.barGraph.setBars(bars);
-		this.barGraph.invalidate();
-	}
+        public String toString(){
+            if (this.equals(ChartType.create(0))){
+                return CHART_TYPE_TITLE_PIE;
+            }
+            if (this.equals(ChartType.create(1))){
+                return CHART_TYPE_TITLE_BAR;
+            }
+            return CHART_TYPE_TITLE_LINE;
+        }
 
-	/*
-	 * 
-	 * FETCH & ACTUALISE RECORD DATA
-	 */
-	public ArrayList<Record> getFetchedRecords() {
-		if (this.filter == null)
-			this.clearFilter();
-		return this.dbh.getRecordsForFilter(this.filter);
-	}
+    }
 
-	public void actualiseCurrentPlot() {
-		LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
-		View plot = this.currentPlotView;
-		if (plot == null) {
-			this.currentPlotView = this.getPieGraphView();
-			plot = this.currentPlotView;
-		}
-		if (plot.getParent() != null && !plot.getParent().equals(plotLayout)) {
-			LinearLayout linLayout = (LinearLayout) plot.getParent();
-			linLayout.removeView(plot);
-			plot.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
-			plotLayout.addView(plot);
-		}
-
-		if (plot.getVisibility() == View.GONE)
-			plot.setVisibility(View.VISIBLE);
-
-		if (plot instanceof PieGraph) {
-			PieGraph pie = (PieGraph) plot;
-			this.setPieGraphData(pie);
-			// HIDE FILTER BUTTON
-			ImageButton filterButton = this.getFilterButton();
-			if (filterButton != null)
-				filterButton.setVisibility(View.GONE);
-		} else {
-			if (this.pieGraph != null) {
-				this.pieGraph.setVisibility(View.GONE);
-				if (this.pieGraph.getParent() != null) {
-					plotLayout.removeView(this.pieGraph);
-				}
-			}
-			// SHOW FILTER BUTTON
-			ImageButton filterButton = this.getFilterButton();
-			if (filterButton != null)
-				filterButton.setVisibility(View.VISIBLE);
-		}
-		if (plot instanceof BarGraph) {
-			BarGraph bar = (BarGraph) plot;
-			this.setBarGraphData(bar);
-		} else {
-			if (this.barGraph != null) {
-				this.barGraph.setVisibility(View.GONE);
-				if (this.barGraph.getParent() != null) {
-					plotLayout.removeView(this.barGraph);
-				}
-			}
-		}
-		if (plot instanceof LineGraph) {
-			LineGraph line = (LineGraph) plot;
-			this.setLineGraphData(line);
-		} else {
-			if (this.lineGraph != null) {
-				this.lineGraph.setVisibility(View.GONE);
-				if (this.lineGraph.getParent() != null) {
-					plotLayout.removeView(this.lineGraph);
-				}
-			}
-		}
-		plot.setVisibility(View.VISIBLE);
-		if (plot.getParent() == null) {
-			plotLayout.addView(plot);
-		}
-		this.actualiseLegendList();
-		this.currentPlotView.bringToFront();
-		this.currentPlotView.invalidate();
-	}
+    private ImageButton getFilterButton(){
+        return (ImageButton) this.rootView.findViewById(R.id.FilterButton);
+    }
 
-	public ArrayList<PlotComparisonItem> getPieData() {
-		// DEFAULT
-		return this.attacksPerProtocols();
-	}
+    public int getLayoutID(){
+        return R.layout.fragment_statistics;
+    }
 
-	public ArrayList<PlotComparisonItem> getBarData() {
-		String protocol = this.getCurrentSelectedProtocol();
-
-		if (protocol.length() > 0) {
-			if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerESSID)) {
-				return this.attacksPerESSID(protocol);
-			}
-			// DEFAULT
-			return this.attacksPerBSSID(protocol);
-		}
-		// Nothing available
-		return new ArrayList<PlotComparisonItem>();
-	}
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+                             Bundle savedInstanceState) {
 
-	public ArrayList<PlotComparisonItem> getLineData() {
-		return this.attacksPerTime();
-	}
+	    super.onCreateView(inflater, container, savedInstanceState);
 
-	/*
-	 * DATA SOURCE
-	 */
-
-	/* PROTOCOLS OVERVIEW */
-	public ArrayList<PlotComparisonItem> attacksPerProtocols() {
-		ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
-		int index = 0;
-		for (String title : this.getSelectedProtocolTitles()) {
-			int attacksCount = this.dbh.getAttackPerProtocolCount(title);
-			if (attacksCount == 0)
-				continue;
-			PlotComparisonItem item = new PlotComparisonItem(title, this.getColor(index), 0., (double) attacksCount);
-			plotItems.add(item);
-			index++;
-		}
-		Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
-			@Override
-			public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
-				return s2.getValue2().compareTo(s1.getValue2());
-			}
-		});
-		return this.resizeData(plotItems);
-	}
+	    getActivity().setTitle(getResources().getString(R.string.drawer_statistics));
 
-	/* LINE PLOT DATA */
-
-	public ArrayList<PlotComparisonItem> attacksPerTime() {
-		HashMap<String, HashMap<Long, ArrayList<Record>>> lineMap = new HashMap<String, HashMap<Long, ArrayList<Record>>>();
-
-		boolean shouldUseDate = this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerDate);
-
-		ArrayList<Record> records = this.getFetchedRecords();
-		for (Record record : records) {
-			long timestamp = record.getTimestamp();
-			long time = 0;
-			if (shouldUseDate) {
-				time = this.getDateFromMilliseconds(timestamp);
-			} else {
-				time = this.getDayHourFromDate(timestamp);
-			}
-
-			// GET CORRECT MAP
-			HashMap<Long, ArrayList<Record>> recordMap;
-			String groupKey = record.getSsid();
-			if (lineMap.containsKey(groupKey)) {
-				recordMap = lineMap.get(record.getSsid());
-			} else {
-				recordMap = new HashMap<Long, ArrayList<Record>>();
-				lineMap.put(groupKey, recordMap);
-			}
-
-			// GET LIST OF RECORDS
-			ArrayList<Record> list;
-			if (recordMap.containsKey(time)) {
-				list = recordMap.get(time);
-			} else {
-				list = new ArrayList<Record>();
-				recordMap.put(time, list);
-			}
-			list.add(record);
-		}
-
-		ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
-
-		int index = 0;
-		for (String groupKey : lineMap.keySet()) {
-			HashMap<Long, ArrayList<Record>> recordMap = lineMap.get(groupKey);
-			ArrayList<PlotComparisonItem> singleLineItems = new ArrayList<PlotComparisonItem>();
-
-			int numbOfAttacks = 0;
-			for (long time : recordMap.keySet()) {
-				ArrayList<Record> list = recordMap.get(time);
-				if (list.size() == 0)
-					continue;
-				PlotComparisonItem item = new PlotComparisonItem(this.getHourAsTimeString(time), 0, (double) time, (double) list.size());
-				singleLineItems.add(item);
-				numbOfAttacks += list.size();
-			}
-
-			Collections.sort(singleLineItems, new Comparator<PlotComparisonItem>() {
-				@Override
-				public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
-					return s1.getValue1().compareTo(s2.getValue1());
-				}
-			});
-
-			double itemValue = (((double) numbOfAttacks / (double) records.size()) * 100.);
-			PlotComparisonItem item = new PlotComparisonItem(groupKey, this.getColor(index), (double) numbOfAttacks, itemValue);
-			item.setOtherData(singleLineItems);
-			plotItems.add(item);
-			index++;
-		}
-		Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
-			@Override
-			public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
-				return s2.getValue2().compareTo(s1.getValue2());
-			}
-		});
-		return plotItems;
-	}
+        dbh = new UglyDbHelper(this.getBaseContext());
 
-	// BAR PLOT DATA
-	public ArrayList<PlotComparisonItem> attacksPerBSSID(String protocol) {
-		LogFilter filter = new LogFilter();
-		ArrayList<String> protocollist = new ArrayList<String>();
-		filter.setAboveTimestamp(this.filter.getAboveTimestamp());
-		filter.setBelowTimestamp(this.filter.getBelowTimestamp());
-		filter.setBSSIDs(this.filter.getBSSIDs());
-		protocollist.add(protocol);
-		filter.setProtocols(protocollist);
-
-		ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
-
-		HashMap<String, Integer> recordMap = new HashMap<String, Integer>();
-		ArrayList<Record> records = this.dbh.getRecordsForFilter(filter);
-		for (Record record : records) {
-			int count = 0;
-			if (recordMap.containsKey(record.getBssid())) {
-				count = recordMap.get(record.getBssid());
-			}
-			count++;
-			recordMap.put(record.getBssid(), count);
-		}
-		int index = 0;
-		for (String key : recordMap.keySet()) {
-			double value = (double) recordMap.get(key);
-			if (value == 0.)
-				continue;
-			PlotComparisonItem item = new PlotComparisonItem(key, this.getColor(index), 0., value);
-			plotItems.add(item);
-			index++;
-		}
-		Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
-			@Override
-			public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
-				return s2.getValue2().compareTo(s1.getValue2());
-			}
-		});
-		return this.resizeData(plotItems);
-	}
+        // Get the message from the intent
 
-	public ArrayList<PlotComparisonItem> attacksPerESSID(String protocol) {
-		LogFilter filter = new LogFilter();
-		filter.setAboveTimestamp(this.filter.getAboveTimestamp());
-		filter.setBelowTimestamp(this.filter.getBelowTimestamp());
-		filter.setESSIDs(this.filter.getESSIDs());
-		ArrayList<String> protocollist = new ArrayList<String>();
-		protocollist.add(protocol);
-		filter.setProtocols(protocollist);
-
-		ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
-
-		HashMap<String, Integer> recordMap = new HashMap<String, Integer>();
-		ArrayList<Record> records = this.dbh.getRecordsForFilter(filter);
-		for (Record record : records) {
-			int count = 0;
-			if (recordMap.containsKey(record.getSsid())) {
-				count = recordMap.get(record.getSsid());
-			}
-			count++;
-			recordMap.put(record.getSsid(), count);
-		}
-		int index = 0;
-		for (String key : recordMap.keySet()) {
-			double value = (double) recordMap.get(key);
-			if (value == 0.)
-				continue;
-			PlotComparisonItem item = new PlotComparisonItem(key, this.getColor(index), 0., value);
-			plotItems.add(item);
-			index++;
-		}
-		Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
-			@Override
-			public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
-				return s2.getValue2().compareTo(s1.getValue2());
-			}
-		});
-
-		return this.resizeData(plotItems);
-	}
+        if (this.filter == null){
+            Intent intent = this.getActivity().getIntent();
+            LogFilter filter = intent.getParcelableExtra(LogFilter.LOG_FILTER_INTENT_KEY);
+            if(filter == null){
+                this.clearFilter();
+            } else {
+                this.filter = filter;
+            }
+        }
 
-	private ArrayList<PlotComparisonItem> resizeData(ArrayList<PlotComparisonItem> plotItems) {
-		if (plotItems != null) {
-			if (plotItems.size() > MAX_NUMBER_OF_CHART_OBJECTS && MAX_NUMBER_OF_CHART_OBJECTS > 1) {
-				ArrayList<PlotComparisonItem> copy = new ArrayList<PlotComparisonItem>();
-				ArrayList<PlotComparisonItem> others = new ArrayList<PlotComparisonItem>();
-				double valueOfOthers = 0;
-
-				for (int i = 0; i < plotItems.size(); i++) {
-					if (i < MAX_NUMBER_OF_CHART_OBJECTS - 1) {
-						PlotComparisonItem item = plotItems.get(i);
-						item.setColor(this.getColor(i));
-						copy.add(plotItems.get(i));
-					} else {
-						PlotComparisonItem item = plotItems.get(i);
-						others.add(item);
-						valueOfOthers += item.getValue2();
-					}
-				}
-				PlotComparisonItem otherItem = new PlotComparisonItem(OTHER_CHART_TITLE, this.getOtherColor(), 0., valueOfOthers);
-				otherItem.setOtherData(others);
-				copy.add(otherItem);
-
-				Collections.sort(copy, new Comparator<PlotComparisonItem>() {
-					@Override
-					public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
-						return s2.getValue2().compareTo(s1.getValue2());
-					}
-				});
-
-				return copy;
-			}
-		}
-		return plotItems;
-	}
+        this.rootView = inflater.inflate(this.getLayoutID(), container, false);
 
-	/*
-	 * FILTER STUFF
-	 */
-	private String getCurrentSelectedProtocol() {
-		ArrayList<String> protocolTitles = this.getSelectedProtocolTitles();
-		if (protocolTitles != null && protocolTitles.size() != 0) {
-			return protocolTitles.get(0);
-		}
-		return this.protocolTitles().get(0);
-	}
+        this.configureRootView(this.rootView);
 
-	public ArrayList<String> protocolTitles() {
-		ArrayList<String> titles = new ArrayList<String>();
-		for (String protocol : this.getResources().getStringArray(R.array.protocols)) {
-			titles.add(protocol);
-		}
-		return titles;
-	}
+        return this.rootView;
+    }
 
-	public boolean[] selectedProtocols() {
-		ArrayList<String> protocols = this.protocolTitles();
-		boolean[] selected = new boolean[protocols.size()];
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setHasOptionsMenu(true);
+        setRetainInstance(true);
+    }
+
+    @Override
+    public void onConfigurationChanged(Configuration newConfig){
+        super.onConfigurationChanged(newConfig);
+        LayoutInflater inflater = LayoutInflater.from(getActivity());
+
+        ViewGroup container = (ViewGroup) this.getView();
+        container.removeAllViewsInLayout();
+        this.rootView = inflater.inflate(this.getLayoutID(), container, false);
+        container.addView(this.rootView);
+
+        this.configureRootView(this.rootView);
+    }
+
+    private Context getBaseContext(){
+        return this.getActivity().getBaseContext();
+    }
+
+    private Context getApplicationContext(){
+        return this.getActivity().getApplicationContext();
+    }
+
+    public void configureRootView(View rootView){
+        LinearLayout plotLayout = (LinearLayout) rootView.findViewById(R.id.plot_layout);
+        plotLayout.setWillNotDraw(false);
+        plotLayout.removeAllViews();
+
+        plotLayout.setWillNotDraw(false);
+
+        this.spinner = (ProgressBar) rootView.findViewById(R.id.progressBar1);
+        this.spinner.setVisibility(View.GONE);
+
+        this.legendListView = (ListView) rootView.findViewById(R.id.legend_list_view);
+        this.legendListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+            @Override
+            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
+                StatisticsFragment.this.userTappedOnLegendItem(i);
+            }
+        });
+        rootView.setWillNotDraw(false);
+
+        this.actualiseCurrentPlot();
+
+        ImageButton visualButton = (ImageButton) rootView.findViewById(R.id.plot_data_button);
+        visualButton.setOnClickListener(new View.OnClickListener() {
+            public void onClick(View v) {
+                StatisticsFragment.this.openBarSelectionMenuOnView(v);
+            }
+        });
+
+
+        ImageButton filterButton = this.getFilterButton();
+        filterButton.setOnClickListener(new View.OnClickListener() {
+            public void onClick(View v) {
+                StatisticsFragment.this.openFilterMenuOnView(v);
+            }
+        });
+
+        if (this.currentPlotView instanceof BarGraph){
+            this.setTitle("" + this.getCurrentSelectedProtocol() + ": " +this.selectedCompareData);
+        } else {
+            this.setTitle(this.selectedCompareData);
+        }
+    }
+
+    public void setTitle(String title){
+        TextView titleView = (TextView) this.rootView.findViewById(R.id.title_text_view);
+        if (title != null && titleView != null){
+            titleView.setText(title);
+            titleView.invalidate();
+        }
+    }
+
+    public String getTitle(){
+        TextView titleView = (TextView) this.rootView.findViewById(R.id.title_text_view);
+        if (titleView != null){
+            return "" + titleView.getText();
+        }
+        return "";
+    }
+
+    public void onStart() {
+        super.onStart();
+        this.actualiseCurrentPlot();
+        this.currentPlotView.invalidate();
+
+        if (this.currentPlotView instanceof BarGraph){
+            this.setTitle("" + this.getCurrentSelectedProtocol() + ": " +this.selectedCompareData);
+        } else {
+            this.setTitle(this.selectedCompareData);
+        }
+    }
+
+    public void setChartType(ChartType type){
+        boolean shouldChange = true;
+        this.clearFilter();
+        if (this.currentPlotView != null){
+            if (type == ChartType.PIE_CHART){
+                shouldChange = ! (this.currentPlotView instanceof PieGraph);
+                // SET FILTER BUTTON HIDDEN
+                ImageButton filterButton = this.getFilterButton();
+                if (filterButton != null) filterButton.setVisibility(View.GONE);
+            } else {
+                if (this.pieGraph != null)
+                     this.pieGraph.setVisibility(View.GONE);
+                // SHOW FILTER BUTTON
+                ImageButton filterButton = this.getFilterButton();
+                if (filterButton != null) filterButton.setVisibility(View.VISIBLE);
+            }
+            if (type == ChartType.LINE_CHART){
+                shouldChange = ! (this.currentPlotView instanceof LineGraph);
+            } else {
+                if (this.lineGraph != null)
+                     this.lineGraph.setVisibility(View.GONE);
+            }
+            if (type == ChartType.BAR_CHART){
+                shouldChange = ! (this.currentPlotView instanceof BarGraph);
+
+            } else {
+                if (this.barGraph != null)
+                    this.barGraph.setVisibility(View.GONE);
+
+            }
+        }
+        if (shouldChange){
+            this.currentPlotView = this.getPlotViewForType(type);
+            this.currentPlotView.setVisibility(View.VISIBLE);
+
+        }
+        this.actualiseCurrentPlot();
+
+    }
+
+    public View getPlotViewForType(ChartType type){
+        switch (type){
+            case PIE_CHART:
+                return this.getPieGraphView();
+            case LINE_CHART:
+                return this.getLineGraphView();
+            default:
+                return this.getBarGraphView();
+        }
+    }
+
+    public void actualiseLegendList(){
+        StatisticListAdapter adapter = new StatisticListAdapter(this.getApplicationContext(), this.currentData);
+        if (this.currentPlotView instanceof LineGraph){
+            adapter.setValueFormatter(new StatisticListAdapter.ValueFormatter() {
+                @Override
+                public String convertValueForItemToString(PlotComparisonItem item) {
+                    return String.format("%.02f", item.getValue2()) + " %" + " " + "("+ (item.getValue1().intValue())  +")";
+                }
+            });
+        } else {
+
+            adapter.setValueFormatter(new StatisticListAdapter.ValueFormatter() {
+                @Override
+                public String convertValueForItemToString(PlotComparisonItem item)  {
+                    int v = (int) item.getValue2().intValue();
+                    return "" + v;
+                }
+            });
+
+        }
+        this.legendListView.setAdapter(adapter);
+
+        TextView tableHeaderTitleView = (TextView) this.rootView.findViewById(R.id.table_header_title_textview);
+        TextView tableHeaderValueView = (TextView) this.rootView.findViewById(R.id.table_header_value_textview);
+        if (this.currentPlotView instanceof LineGraph){
+            tableHeaderTitleView.setText(FILTER_MENU_TITLE_ESSID);
+            tableHeaderValueView.setText(TABLE_HEADER_VALUE_TITLE_ATTACKS_PERCENTAGE);
+        }
+        if (this.currentPlotView instanceof PieGraph){
+            tableHeaderTitleView.setText(FILTER_MENU_TITLE_PROTOCOL);
+            tableHeaderValueView.setText(TABLE_HEADER_VALUE_TITLE_ATTACKS_COUNT);
+        }
+        if (this.currentPlotView instanceof BarGraph){
+            tableHeaderValueView.setText(TABLE_HEADER_VALUE_TITLE_ATTACKS_COUNT);
+            if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerBSSID)){
+                tableHeaderTitleView.setText(FILTER_MENU_TITLE_BSSID);
+            } else {
+                tableHeaderTitleView.setText(FILTER_MENU_TITLE_ESSID);
+            }
+        }
+    }
+
+    /*
+    * MENU
+    * */
+    private void openBarSelectionMenuOnView(View anchorView){
+        SimplePopupTable visualiseMenu = new SimplePopupTable(this.getActivity(), new AbstractPopup.OnPopupItemClickListener() {
+            public void onItemClick(Object ob) {
+                if (ob instanceof AbstractPopupItem){
+                    AbstractPopupItem item = (AbstractPopupItem) ob;
+                    StatisticsFragment.this.userSelectMenuItem(item);
+                }
+            }
+        });
+        visualiseMenu.setTitle(MENU_POPUP_TITLE);
+        int id = 0;
+        for(String title : StatisticsFragment.this.getMenuTitles()){
+            SimplePopupItem item = new SimplePopupItem(this.getActivity());
+            item.setTitle(title);
+            item.setItemId(id);
+            item.setSelected(false);
+            visualiseMenu.addItem(item);
+            id++;
+        }
+        visualiseMenu.showOnView(anchorView);
+    }
+
+    private void userSelectMenuItem(AbstractPopupItem item){
+        // OPEN A DIALOG TO SPECIFY THE VISUALISE DATA
+        if (item.getTitle().equals(MENU_TITLE_PROTOCOLS)){
+            ChartType chartType = ChartType.PIE_CHART;
+            this.selectedCompareData = COMPARE_TITLE_AttacksPerProtocol;
+            this.setChartType(chartType);
+            this.setTitle(COMPARE_TITLE_AttacksPerProtocol);
+        }
+        if (item.getTitle().equals(MENU_TITLE_NETWORK)){
+            this.openNetworkDataDialog();
+        }
+        if (item.getTitle().equals(MENU_TITLE_ATTACKS)){
+            this.openAttackDataDialog();
+        }
+    }
+
+    private ArrayList<String> getMenuTitles(){
+        ArrayList<String> titles = new ArrayList<String>();
+        titles.add(MENU_TITLE_PROTOCOLS);
+        titles.add(MENU_TITLE_NETWORK);
+        titles.add(MENU_TITLE_ATTACKS);
+        return titles;
+    }
+
+    /*
+    * PLOT DATA DIALOGS
+    * */
+    private void openProtocolDataDialog(){
+        ArrayList<String> titles = this.getDialogProtocolDataTitle();
+        ChecklistDialog newFragment = new ChecklistDialog(DIALOG_PROTOCOLS_TITLE, titles, this.selectedData(titles), false , this);
+        newFragment.show(this.getActivity().getFragmentManager(), DIALOG_PROTOCOLS_TITLE);
+    }
+    private void openNetworkDataDialog(){
+        ArrayList<String> titles = this.getDialogNetworkDataTitle();
+        ChecklistDialog newFragment = new ChecklistDialog(DIALOG_NETWORK_TITLE, titles, this.selectedData(titles), false , this);
+        newFragment.show(this.getActivity().getFragmentManager(), DIALOG_NETWORK_TITLE);
+    }
+    private void openAttackDataDialog(){
+        ArrayList<String> titles = this.getDialogAttackDataTitle();
+        ChecklistDialog newFragment = new ChecklistDialog(DIALOG_ATTACK_TITLE, titles, this.selectedData(titles), false , this);
+        newFragment.show(this.getActivity().getFragmentManager(), DIALOG_ATTACK_TITLE);
+    }
+
+    /*
+    *
+    * DIALOG ACTION METHODS
+    *
+    * */
+    public void onDialogPositiveClick(ChecklistDialog dialog) {
+        String title = dialog.getTitle();
+        ArrayList<String> titles =dialog.getSelectedItemTitles();
+
+        if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
+            //titles = titles.size() == 0 ? this.protocolTitles() : titles;
+            this.filter.setProtocols(titles);
+            this.actualiseCurrentPlot();
+            return;
+        }
+        if (title.equals(FILTER_MENU_PROTOCOL_SINGLE_CHOICE_TITLE)){
+            if (titles.size() == 0){
+                titles = new ArrayList<String>();
+                titles.add(this.protocolTitles().get(0));
+            }
+            this.filter.setProtocols(titles);
+
+            this.actualiseCurrentPlot();
+            String fragTitle = "" + this.getCurrentSelectedProtocol() + ": " + this.selectedCompareData;
+            this.setTitle(fragTitle);
+            return;
+        }
+        if (title.equals(FILTER_MENU_TITLE_ESSID)){
+            this.filter.setESSIDs(titles);
+            this.actualiseCurrentPlot();
+            return;
+        }
+        if (title.equals(FILTER_MENU_TITLE_BSSID)){
+            this.filter.setBSSIDs(titles);
+            this.actualiseCurrentPlot();
+            return;
+        }
+
+        if (titles.size() != 0){
+            String data = titles.get(0);
+            this.setTitle(data);
+
+            if (data.equals(COMPARE_TITLE_AttacksPerTime) || data.equals(COMPARE_TITLE_AttacksPerDate)){
+                ChartType chartType = ChartType.LINE_CHART;
+                this.selectedCompareData = data;
+                this.setChartType(chartType);
+                return;
+            }
+            if (data.equals(COMPARE_TITLE_AttacksPerBSSID) || data.equals(COMPARE_TITLE_AttacksPerESSID)){
+                ChartType chartType = ChartType.BAR_CHART;
+                this.selectedCompareData = data;
+                this.setChartType(chartType);
+
+                String fragTitle = "" + this.getCurrentSelectedProtocol() + ": " + this.selectedCompareData;
+                this.setTitle(fragTitle);
+                return;
+            }
+        }
+
+    }
+
+    public void onDialogNegativeClick(ChecklistDialog dialog) {
+
+    }
+    /*
+    *
+    * DIALOG DATA
+    *
+    * */
+    private ArrayList<String> getDialogProtocolDataTitle(){
+        ArrayList<String> data = new ArrayList<String>();
+        data.add(COMPARE_TITLE_AttacksPerProtocol);
+        data.add(COMPARE_TITLE_UsesPerProtocol);
+        return data;
+    }
+    private ArrayList<String> getDialogAttackDataTitle(){
+        ArrayList<String> data = new ArrayList<String>();
+        data.add(COMPARE_TITLE_AttacksPerDate);
+        data.add(COMPARE_TITLE_AttacksPerTime);
+        return data;
+    }
+    private ArrayList<String> getDialogNetworkDataTitle(){
+        ArrayList<String> data = new ArrayList<String>();
+        data.add(COMPARE_TITLE_AttacksPerESSID);
+        data.add(COMPARE_TITLE_AttacksPerBSSID);
+        return data;
+    }
+    private boolean[] selectedData(ArrayList<String> data){
+        boolean[] selected = new boolean[data.size()];
+         // SET DEFAULT
+        selected[0] = true;
+        return selected;
+    }
+
+    /*
+    *
+    *  FILTER BUTTON
+    *
+    * */
+    private void openFilterMenuOnView(View anchor){
+        SimplePopupTable filterMenu = new SimplePopupTable(this.getActivity(), new AbstractPopup.OnPopupItemClickListener() {
+            public void onItemClick(Object ob) {
+                if (ob instanceof  AbstractPopupItem){
+                    AbstractPopupItem item = (AbstractPopupItem) ob;
+                    StatisticsFragment.this.onFilterMenuItemSelected(item);
+                }
+            }
+        });
+
+        filterMenu.setTitle(FILTER_MENU_POPUP_TITLE);
+        for(String title : StatisticsFragment.this.filterMenuTitles()){
+            AbstractPopupItem item = null;
+            if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)) continue;
+            if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
+                item = new SplitPopupItem(this.getActivity());
+                item.setValue(SplitPopupItem.RIGHT_TITLE, FILTER_MENU_TITLE_TIMESTAMP_BELOW);
+                item.setValue(SplitPopupItem.LEFT_TITLE, FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
+                if (this.filter.hasBelowTimestamp()){
+                    item.setValue(SplitPopupItem.RIGHT_SUBTITLE, this.getDateAsString(this.filter.belowTimestamp));
+                }
+                if (this.filter.hasAboveTimestamp()){
+                    item.setValue(SplitPopupItem.LEFT_SUBTITLE, this.getDateAsString(this.filter.aboveTimestamp));
+                }
+            } else {
+                item = new SimplePopupItem(this.getActivity());
+                item.setTitle(title);
+                ((SimplePopupItem)item).setSelected(this.isFilterSetForTitle(title));
+            }
+
+            filterMenu.addItem(item);
+        }
+        filterMenu.showOnView(anchor);
+    }
+
+    private void onFilterMenuItemSelected(AbstractPopupItem item){
+        if (item instanceof SplitPopupItem){
+            SplitPopupItem sItem = (SplitPopupItem) item;
+            this.wasBelowTimePicker = sItem.wasRightTouch;
+            if (this.wasBelowTimePicker){
+                this.openTimestampToFilterDialog();
+            } else {
+                this.openTimestampFromFilterDialog();
+            }
+            return;
+        }
+        String title = item.getTitle();
+        if (title.equals(FILTER_MENU_TITLE_ESSID)){
+            this.openESSIDFilterDialog();
+        }
+        if (title.equals(FILTER_MENU_TITLE_BSSID)){
+            this.openBSSIDFilterDialog();
+        }
+        if (title.equals(FILTER_MENU_TITLE_PROTOCOL)){
+            this.openFilterDialogSelectProtocol();
+        }
+        if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
+            this.openProtocolsFilterDialog();
+        }
+        if (title.equals(FILTER_MENU_TITLE_REMOVE)){
+            this.clearFilter();
+            this.actualiseCurrentPlot();
+        }
+    }
+
+    private ArrayList<String> filterMenuTitles(){
+        ArrayList<String> titles = new ArrayList<String>();
+        if (this.currentPlotView instanceof LineGraph){
+            titles.add(FILTER_MENU_TITLE_ESSID);
+            titles.add(FILTER_MENU_TITLE_PROTOCOLS);
+            titles.add(FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
+            if (this.filter.hasESSIDs() || this.filter.hasATimestamp() || (this.filter.getProtocols() != null  && this.filter.hasProtocols() && this.filter.getProtocols().size() != this.protocolTitles().size())){
+                titles.add(FILTER_MENU_TITLE_REMOVE);
+            }
+        } else {
+            titles.add(FILTER_MENU_TITLE_PROTOCOL);
+            String protocol = this.getCurrentSelectedProtocol();
+            if (protocol.length() > 0){
+                if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerBSSID)){
+                    titles.add(FILTER_MENU_TITLE_BSSID);
+                } else {
+                    // DEFAULT
+                    titles.add(FILTER_MENU_TITLE_ESSID);
+                }
+            }
+            titles.add(FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
+            if (this.filter.hasATimestamp() || this.filter.hasESSIDs() || this.filter.hasBSSIDs()
+                    || (this.currentPlotView instanceof LineGraph && this.filter.hasProtocols())){
+                titles.add(FILTER_MENU_TITLE_REMOVE);
+            }
+        }
+        return titles;
+    }
+
+    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 openFilterDialogSelectProtocol(){
+        ArrayList<String> titles = this.protocolTitles();
+        boolean[] selected = new boolean[titles.size()];
+        int i = 0;
+        for (String title : titles){
+            selected[i] = title.equals(this.getCurrentSelectedProtocol());
+            i++;
+        }
+        ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_PROTOCOL_SINGLE_CHOICE_TITLE, titles, selected, false , this);
+        newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_PROTOCOL_SINGLE_CHOICE_TITLE);
+    }
+
+    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 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 openTimestampFromFilterDialog(){
+        this.wasBelowTimePicker = false;
+        DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
+        newFragment.setDateChangeListener(this);
+        newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
+
+        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.setDateChangeListener(this);
+        newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_TIMESTAMP_BELOW);
+        if (this.filter.belowTimestamp != Long.MAX_VALUE) newFragment.setDate(this.filter.belowTimestamp);
+    }
+
+    public ArrayList<String> essids(){
+        ArrayList<String> records;
+        if (this.currentPlotView instanceof BarGraph){
+            records = dbh.getUniqueESSIDRecordsForProtocol(this.getCurrentSelectedProtocol());
+        } else {
+            records = dbh.getUniqueESSIDRecords();
+        }
+        return records;
+    }
+    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.getESSIDs().contains(essid));
+            i++;
+        }
+        return selected;
+    }
+
+    public ArrayList<String> bssids(){
+        ArrayList<String> records ;
+        if (this.currentPlotView instanceof BarGraph){
+            records = dbh.getUniqueBSSIDRecordsForProtocol(this.getCurrentSelectedProtocol());
+        } else {
+            records = dbh.getUniqueBSSIDRecords();
+        }
+        return records;
+    }
+    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.getBSSIDs().contains(bssid));
+            i++;
+        }
+        return selected;
+    }
+
+    public void onDateTimePickerPositiveClick(DateTimeDialogFragment dialog) {
+        if(this.wasBelowTimePicker){
+            this.filter.setBelowTimestamp(dialog.getDate());
+        } else {
+            this.filter.setAboveTimestamp(dialog.getDate());
+        }
+        this.actualiseCurrentPlot();
+    }
+
+    public void onDateTimePickerNegativeClick(DateTimeDialogFragment dialog) {
+        if(this.wasBelowTimePicker){
+            this.filter.setBelowTimestamp(Long.MAX_VALUE);
+        } else {
+            this.filter.setAboveTimestamp(Long.MIN_VALUE);
+        }
+        this.actualiseCurrentPlot();
+    }
+
+
+    /*
+    *
+    *  PLOT TYPES
+    *
+    * **/
+    public PieGraph getPieGraphView(){
+        if (this.pieGraph == null) {
+            this.pieGraph = new PieGraph(this.getApplicationContext());
+            LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
+            plotLayout.addView(this.pieGraph);
+            this.pieGraph.setOnSliceClickedListener(new PieGraph.OnSliceClickedListener() {
+                @Override
+                public void onClick(int index) {
+                    StatisticsFragment.this.onSliceClick(index);
+                }
+            });
+        }
+         return this.pieGraph;
+    }
+
+    public LineGraph getLineGraphView(){
+        if (this.lineGraph == null) {
+            this.lineGraph = new LineGraph(this.getActivity());
+            LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
+            plotLayout.addView(this.lineGraph);
+            this.lineGraph.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
+        }
+        return this.lineGraph;
+    }
+
+    public BarGraph getBarGraphView(){
+        if (this.barGraph == null) {
+            this.barGraph = new BarGraph(this.getActivity());
+            LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
+            this.barGraph.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT ));
+            plotLayout.addView(this.barGraph);
+            this.barGraph.setShowBarText(false);
+            this.barGraph.setPopupImageID(R.drawable.popup_black);
+            this.barGraph.setOnBarClickedListener(new BarGraph.OnBarClickedListener() {
+                @Override
+                public void onClick(int i) {
+                    StatisticsFragment.this.onBarClick(i);
+                }
+            });
+        }
+        return this.barGraph;
+    }
+
+    /*
+    *  FEED PLOTS WITH DATA
+    * */
+    public void setPieGraphData(PieGraph piegraph){
+        this.currentData = this.getPieData();
+        if (this.currentData == null){
+            this.currentData = new ArrayList<PlotComparisonItem>();
+        }
+
+        piegraph.removeSlices();
+
+        for (PlotComparisonItem item : this.currentData){
+            PieSlice slice = new PieSlice();
+            slice.setColor(item.getColor());
+            Double value2 = (Double) item.getValue2();
+            float v = value2.floatValue();
+            slice.setValue(v);
+            slice.setTitle(item.getTitle());
+            piegraph.addSlice(slice);
+        }
+        piegraph.invalidate();
+
+    }
+
+    public void setLineGraphData(LineGraph linegraph){
+        this.currentData = this.getLineData();
+        if (this.currentData == null){
+            this.currentData = new ArrayList<PlotComparisonItem>();
+        }
+
+        linegraph.removeAllLines();
+        double rangeMax_Y = 0;
+        double rangeMin_Y = 0;
+
+        double rangeMax_X = 0;
+        double rangeMin_X = 0;
+
+        int count = 0;
+        for (PlotComparisonItem lineItem : this.currentData){
+            ArrayList<PlotComparisonItem> data = lineItem.getOtherData();
+            int index = 0;
+            Line l = new Line();
+            int lineColor = lineItem.getColor();
+            l.setColor(lineColor);
+
+            for (PlotComparisonItem pointItem : data){
+                LinePoint p = new LinePoint();
+                p.setX(pointItem.getValue1());
+                Double value2 = pointItem.getValue2();
+                p.setY(value2);
+                p.setColor(lineColor);
+                l.addPoint(p);
+                rangeMax_Y = Math.max(pointItem.getValue2(), rangeMax_Y);
+                rangeMax_X = Math.max(pointItem.getValue1(), rangeMax_X);
+
+                if (count != 0){
+                    rangeMin_Y = Math.min(pointItem.getValue2(), rangeMin_Y);
+                    rangeMin_X = Math.min(pointItem.getValue1(), rangeMin_X);
+                } else {
+                    rangeMin_Y = pointItem.getValue2();
+                    rangeMin_X = pointItem.getValue1();
+                }
+                index++;
+                count++;
+            }
+            linegraph.addLine(l);
+        }
+        // add a bit more space
+        rangeMax_Y++;
+        rangeMin_Y--;
+
+        boolean shouldUseDate = this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerDate);
+        if (shouldUseDate){
+            linegraph.resetXLimits();
+
+            if (this.filter.hasBelowTimestamp()){
+                rangeMax_X = Math.max(this.filter.belowTimestamp, rangeMax_X);
+            }
+            if (this.filter.hasAboveTimestamp()){
+                rangeMin_X = Math.min(this.filter.aboveTimestamp, rangeMin_X);
+            }
+
+            if (rangeMax_X == rangeMin_X){
+                double aDay = 60*60*24*1000;
+                rangeMax_X+= aDay;
+                rangeMin_X-= aDay;
+            }
+
+            double stepRange = (rangeMax_X - rangeMin_X)/(60*60*24*1000);
+            linegraph.setxAxisStep(Math.max(1, (float) Math.min(stepRange, 4)));
+
+            linegraph.setRangeX(rangeMin_X  , rangeMax_X);
+
+            linegraph.setConverter(new LineGraph.AxisDataConverter() {
+                @Override
+                public String convertDataForX_Position(double x) {
+                    return StatisticsFragment.this.getDateAsDayString((long)x);
+                }
+                @Override
+                public  String convertDataForY_Position(double y){
+                    return "" + (long)y;
+                }
+            });
+        } else {
+            linegraph.setxAxisStep(12.f);
+            linegraph.setRangeX(0, 24);
+            linegraph.setConverter(null);
+        }
+
+        int maxY = (int)(rangeMax_Y - rangeMin_Y);
+        linegraph.setYAxisStep(Math.min(maxY, 5));
+        int yStep = (int)linegraph.getyAxisStep();
+        if ((maxY % yStep) != 0) {
+            maxY = maxY + (yStep - (maxY % yStep));
+        }
+        rangeMax_Y = rangeMin_Y + maxY;
+        linegraph.setRangeY(rangeMin_Y, rangeMax_Y);
+        linegraph.setLineToFill(0);
+        linegraph.invalidate();
+    }
+
+    /*
+    * Set the graph data to the given graph
+    * @param BarGraph bargraph
+    * */
+    public void setBarGraphData(BarGraph bargraph){
+        this.currentData = this.getBarData();
+        if (this.currentData == null){
+            this.currentData = new ArrayList<PlotComparisonItem>();
+        }
+
+        ArrayList<Bar> bars = new ArrayList<Bar>();
+
+        for (PlotComparisonItem item : this.currentData){
+            Bar d = new Bar();
+            d.setColor(item.getColor());
+            Long value2 =  item.getValue2().longValue();
+            d.setName("");
+            d.setValue(value2.floatValue());
+            bars.add(d);
+        }
+
+        barGraph.setBars(bars);
+        barGraph.invalidate();
+    }
+
+    /*
+    *
+    *  FETCH & ACTUALISE RECORD DATA
+    *
+    * */
+    public ArrayList<Record> getFetchedRecords(){
+        if (this.filter == null) this.clearFilter();
+        return this.dbh.getRecordsForFilter(this.filter);
+    }
+
+    /*Actualises the current plot.*/
+     public void actualiseCurrentPlot(){
+         this.spinner.setVisibility(View.VISIBLE);
+
+         LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
+
+         if (this.barGraph != null)
+            this.barGraph.setVisibility(View.GONE);
+         if (this.lineGraph != null)
+            this.lineGraph.setVisibility(View.GONE);
+         if (this.pieGraph != null)
+            this.pieGraph.setVisibility(View.GONE);
+
+        View plot = this.currentPlotView;
+         if (plot == null){
+             this.currentPlotView = this.getPieGraphView();
+             plot = this.currentPlotView;
+         }
+         if (plot.getParent() != null && !plot.getParent().equals(plotLayout)){
+             LinearLayout linLayout = (LinearLayout)plot.getParent();
+             linLayout.removeView(plot);
+             plot.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT ));
+             plotLayout.addView(plot);
+         }
+
+         this.currentPlotView = plot;
+
+         final LinearLayout thePlotlayout = plotLayout;
+
+         if (this.loader != null && this.loader.isAlive()) this.loader.interrupt();
+
+         this.loader = null;
+
+         this.loader = new Thread(new Runnable() {
+             @Override
+             public void run() {
+                 this.loadDataInBackground();
+                 this.actualiseUI();
+             }
+
+             private void loadDataInBackground(){
+                 View plot = StatisticsFragment.this.currentPlotView;
+                 if (plot instanceof PieGraph){
+                     PieGraph pie = (PieGraph) plot;
+                     StatisticsFragment.this.setPieGraphData(pie);
+                 }
+                 if (plot instanceof BarGraph){
+                     BarGraph bar = (BarGraph) plot;
+                     StatisticsFragment.this.setBarGraphData(bar);
+                 }
+                 if (plot instanceof LineGraph){
+                     LineGraph line = (LineGraph)plot;
+                     StatisticsFragment.this.setLineGraphData(line);
+                 }
+             }
+
+             private void actualiseUI(){
+
+                 Activity actv = StatisticsFragment.this.getActivity();
+
+                 if (actv != null){
+                     actv.runOnUiThread(new Runnable() {
+                         @Override
+                         public void run() {
+                             // SET VISIBILITY
+                             View plot = StatisticsFragment.this.currentPlotView;
+
+                             if (plot instanceof PieGraph){
+                                 // HIDE FILTER BUTTON
+                                 ImageButton filterButton = StatisticsFragment.this.getFilterButton();
+                                 if (filterButton != null) filterButton.setVisibility(View.GONE);
+                             } else {
+                                 if (StatisticsFragment.this.pieGraph != null){
+                                     StatisticsFragment.this.pieGraph.setVisibility(View.GONE);
+                                     if (StatisticsFragment.this.pieGraph.getParent() != null){
+                                         thePlotlayout.removeView(StatisticsFragment.this.pieGraph);
+                                     }
+                                 }
+                                 // SHOW FILTER BUTTON
+                                 ImageButton filterButton = StatisticsFragment.this.getFilterButton();
+                                 if (filterButton != null) filterButton.setVisibility(View.VISIBLE);
+                             }
+                             if (! (plot instanceof BarGraph)){
+                                 if (StatisticsFragment.this.barGraph != null){
+                                     StatisticsFragment.this.barGraph.setVisibility(View.GONE);
+                                     if (StatisticsFragment.this.barGraph.getParent() != null){
+                                         thePlotlayout.removeView(StatisticsFragment.this.barGraph);
+                                     }
+                                 }
+                             }
+                             if (!(plot instanceof LineGraph)){
+                                 if (StatisticsFragment.this.lineGraph != null){
+                                     StatisticsFragment.this.lineGraph.setVisibility(View.GONE);
+                                     if (StatisticsFragment.this.lineGraph.getParent() != null){
+                                         thePlotlayout.removeView(StatisticsFragment.this.lineGraph);
+                                     }
+                                 }
+                             }
+
+                             plot.setVisibility(View.VISIBLE);
+
+                             if (plot.getParent() == null){
+                                 thePlotlayout.addView(plot);
+                             }
+                             StatisticsFragment.this.actualiseLegendList();
+                             StatisticsFragment.this.currentPlotView.bringToFront();
+                             StatisticsFragment.this.currentPlotView.invalidate();
+
+                             StatisticsFragment.this.spinner.setVisibility(View.GONE);
+                         }
+                     });
+                 }
+             }
+         });
+
+        this.loader.start();
+     }
+
+    public ArrayList<PlotComparisonItem> getPieData(){
+        // DEFAULT
+        return this.attacksPerProtocols();
+    }
+    public ArrayList<PlotComparisonItem> getBarData(){
+        String protocol = this.getCurrentSelectedProtocol();
+
+        if (protocol.length() > 0){
+            if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerESSID)){
+                return this.attacksPerESSID(protocol);
+            }
+            // DEFAULT
+            return this.attacksPerBSSID(protocol);
+        }
+        // Nothing available
+        return new ArrayList<PlotComparisonItem>();
+    }
+    public ArrayList<PlotComparisonItem> getLineData(){
+        return this.attacksPerTime();
+    }
+
+    /*
+    *  DATA SOURCE
+    * */
 
-		int i = 0;
-		for (String protocol : protocols) {
-			selected[i] = (this.filter.protocols.contains(protocol));
-			i++;
-		}
-		return selected;
-	}
+    /*PROTOCOLS OVERVIEW*/
+     public ArrayList<PlotComparisonItem> attacksPerProtocols(){
+        ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
+         int index = 0;
+        for (String title : this.getSelectedProtocolTitles()){
+            int attacksCount = this.dbh.getAttackPerProtocolCount(title);
+            if (attacksCount == 0) continue;
+            PlotComparisonItem item = new PlotComparisonItem(title,this.getColor(index), 0., (double) attacksCount);
+            plotItems.add(item);
+            index++;
+        }
+         Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
+             @Override
+             public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
+                 return s2.getValue2().compareTo(s1.getValue2());
+             }
+         });
+         return this.resizeData(plotItems);
+    }
+
+
+    /*
+    *  LINE PLOT DATA
+    */
+
+    /*Returns the line graph data responding to the selectedCompareData key.
+    * @return ArrayList<PlotComparisonItem attacksPerTime or attacksPerDate*/
+    public ArrayList<PlotComparisonItem> attacksPerTime(){
+        HashMap<String,HashMap<Long, ArrayList<Record> > > lineMap = new HashMap<String, HashMap<Long, ArrayList<Record>>>();
+
+        boolean shouldUseDate = this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerDate);
+
+        ArrayList<Record> records = this.getFetchedRecords();
+        for (Record record : records){
+            long timestamp = record.getTimestamp();
+            long time = 0;
+            if (shouldUseDate){
+                time = this.getDateFromMilliseconds(timestamp);
+            } else {
+                time = this.getDayHourFromDate(timestamp);
+            }
+
+            // GET CORRECT MAP
+            HashMap<Long, ArrayList<Record> > recordMap;
+            String groupKey = record.getSsid();
+            if (lineMap.containsKey(groupKey)){
+                recordMap = lineMap.get(record.getSsid());
+            } else {
+                recordMap = new HashMap<Long, ArrayList<Record> >();
+                lineMap.put(groupKey, recordMap);
+            }
+
+            // GET LIST OF RECORDS
+            ArrayList<Record> list;
+            if (recordMap.containsKey(time)){
+                list = recordMap.get(time);
+            } else {
+                list = new ArrayList<Record>();
+                recordMap.put(time, list);
+            }
+            list.add(record);
+        }
+
+        ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
+
+        int index = 0;
+        for (String groupKey : lineMap.keySet()){
+            HashMap<Long, ArrayList<Record> > recordMap = lineMap.get(groupKey);
+            ArrayList<PlotComparisonItem> singleLineItems = new ArrayList<PlotComparisonItem>();
+
+            int numbOfAttacks = 0;
+            for (long time : recordMap.keySet()){
+                ArrayList<Record>list = recordMap.get(time);
+                if (list.size() == 0) continue;
+                PlotComparisonItem item = new PlotComparisonItem(this.getHourAsTimeString(time), 0 , (double)time, (double) list.size());
+                singleLineItems.add(item);
+                numbOfAttacks +=list.size();
+            }
+
+            Collections.sort(singleLineItems, new Comparator<PlotComparisonItem>() {
+                @Override
+                public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
+                    return s1.getValue1().compareTo(s2.getValue1());
+                }
+            });
+
+            double itemValue = (((double)numbOfAttacks / (double)records.size())*100.);
+            PlotComparisonItem item = new PlotComparisonItem(groupKey, this.getColor(index), (double) numbOfAttacks, itemValue);
+            item.setOtherData(singleLineItems);
+            plotItems.add(item);
+            index++;
+        }
+        Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
+            @Override
+            public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
+                return s2.getValue2().compareTo(s1.getValue2());
+            }
+        });
+        return plotItems;
+    }
+
+    /*
+    *  BAR PLOT DATA
+    */
+    /*Returns plotitems for the comparison "attacks per bssid"
+    * @return ArrayList<PlotComparisonItem> the data
+    */
+    public ArrayList<PlotComparisonItem> attacksPerBSSID(String protocol){
+        LogFilter filter = new LogFilter();
+        ArrayList<String> protocollist = new ArrayList<String>();
+        filter.setAboveTimestamp(this.filter.getAboveTimestamp());
+        filter.setBelowTimestamp(this.filter.getBelowTimestamp());
+        filter.setBSSIDs(this.filter.getBSSIDs());
+        protocollist.add(protocol);
+        filter.setProtocols(protocollist);
+
+        ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
+
+        HashMap<String, Integer> recordMap = new HashMap<String, Integer>();
+        ArrayList<Record> records = this.dbh.getRecordsForFilter(filter);
+        for (Record record : records){
+            int count = 0;
+            if (recordMap.containsKey(record.getBssid())){
+                count = recordMap.get(record.getBssid());
+            }
+            count++;
+            recordMap.put(record.getBssid(), count);
+        }
+        int index = 0;
+        for (String key : recordMap.keySet()){
+            double value = (double)recordMap.get(key);
+            if (value == 0.) continue;
+            PlotComparisonItem item = new PlotComparisonItem(key, this.getColor(index), 0., value);
+            plotItems.add(item);
+            index++;
+        }
+        Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
+            @Override
+            public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
+                return s2.getValue2().compareTo(s1.getValue2());
+            }
+        });
+        return this.resizeData(plotItems);
+    }
+    /*Returns plotitems for the comparison "attacks per essid"
+    * @return ArrayList<PlotComparisonItem> the data
+    */
+    public ArrayList<PlotComparisonItem> attacksPerESSID(String protocol){
+        LogFilter filter = new LogFilter();
+        filter.setAboveTimestamp(this.filter.getAboveTimestamp());
+        filter.setBelowTimestamp(this.filter.getBelowTimestamp());
+        filter.setESSIDs(this.filter.getESSIDs());
+        ArrayList<String> protocollist = new ArrayList<String>();
+        protocollist.add(protocol);
+        filter.setProtocols(protocollist);
+
+        ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
+
+        HashMap<String, Integer> recordMap = new HashMap<String, Integer>();
+        ArrayList<Record> records = this.dbh.getRecordsForFilter(filter);
+        for (Record record : records){
+            int count = 0;
+            if (recordMap.containsKey(record.getSsid())){
+                count = recordMap.get(record.getSsid());
+            }
+            count++;
+            recordMap.put(record.getSsid(), count);
+        }
+        int index = 0;
+        for (String key : recordMap.keySet()){
+            double value =  (double)recordMap.get(key);
+            if (value == 0.) continue;
+            PlotComparisonItem item = new PlotComparisonItem(key,this.getColor(index), 0. ,value);
+            plotItems.add(item);
+            index++;
+        }
+        Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
+            @Override
+            public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
+                return s2.getValue2().compareTo(s1.getValue2());
+            }
+        });
+
+        return this.resizeData(plotItems);
+    }
+
+    /*
+    * This will normalize the given list of plot items to the specified length of MAX_NUMBER_OF_CHART_OBJECTS.
+    * Creates an "others" group, containing all objects after the (MAX_NUMBER_OF_CHART_OBJECTS - 1)th object from the given list.
+    * If the given list does contain MAX_NUMBER_OF_CHART_OBJECTS+1 or more objects, nothing will change.
+    *
+    * @param AtrrayList<PlotComparisonItem> the list to normalize
+    * @return ArrayList<PlotComparisonItem> the normalized data
+    */
+    private ArrayList<PlotComparisonItem> resizeData(ArrayList<PlotComparisonItem> plotItems){
+        if (plotItems != null){
+            if (plotItems.size() > MAX_NUMBER_OF_CHART_OBJECTS && MAX_NUMBER_OF_CHART_OBJECTS > 1){
+                ArrayList<PlotComparisonItem> copy = new ArrayList<PlotComparisonItem>();
+                ArrayList<PlotComparisonItem> others = new ArrayList<PlotComparisonItem>();
+                double valueOfOthers = 0;
+
+                for (int i = 0; i < plotItems.size(); i++){
+                    if (i < MAX_NUMBER_OF_CHART_OBJECTS - 1){
+                        PlotComparisonItem item = plotItems.get(i);
+                        item.setColor(this.getColor(i));
+                        copy.add(plotItems.get(i));
+                    } else {
+                        PlotComparisonItem item = plotItems.get(i);
+                        others.add(item);
+                        valueOfOthers+=item.getValue2();
+                    }
+                }
+                PlotComparisonItem otherItem = new PlotComparisonItem(OTHER_CHART_TITLE, this.getOtherColor(), 0., valueOfOthers);
+                otherItem.setOtherData(others);
+                copy.add(otherItem);
+
+                Collections.sort(copy, new Comparator<PlotComparisonItem>() {
+                    @Override
+                    public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
+                        return s2.getValue2().compareTo(s1.getValue2());
+                    }
+                });
+
+                return copy;
+            }
+        }
+        return plotItems;
+    }
+
+    /*
+    * FILTER STUFF
+    * */
 
-	public ArrayList<String> getSelectedProtocolTitles() {
-		ArrayList<String> knownProtocols = this.protocolTitles();
-		if (this.filter.hasProtocols()) {
-			ArrayList<String> titles = new ArrayList<String>();
-			int i = 0;
-			for (boolean b : this.selectedProtocols()) {
-				if (b) {
-					String title = knownProtocols.get(i);
-					titles.add(title);
-				}
-				i++;
-			}
-			return titles;
-		}
-		return this.protocolTitles();
-	}
+    /*
+    * Returns the first selected protocol from all selected protocols.
+    * If no protocol is selected, it return the first protocol in the protocolTitles() list.
+    * @return String protocolName
+    * */
+    private String getCurrentSelectedProtocol(){
+         ArrayList<String> protocolTitles = this.getSelectedProtocolTitles();
+         if (protocolTitles != null && protocolTitles.size() != 0){
+             return  protocolTitles.get(0);
+         }
+         return this.protocolTitles().get(0);
+     }
+
+    /*Return all Protocols
+    *
+    * @return ArrayList<String> protocolNames
+    * */
+     public ArrayList<String> protocolTitles(){
+        ArrayList<String> titles = new ArrayList<String>();
+        for (String protocol : this.getResources().getStringArray(
+                R.array.protocols)) {
+            titles.add(protocol);
+        }
+        return titles;
+    }
+    /*
+    * Returns a boolean array containing a bool value for each protocol. If the value is true, the filter object contains the protocol.
+    * The array sequence equates to the protocolTitles() list.
+    * @return boolean[] selection array
+    * */
+    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));
+            i++;
+        }
+        return selected;
+    }
+    public ArrayList<String> getSelectedProtocolTitles(){
+        ArrayList<String> knownProtocols = this.protocolTitles();
+        if (this.filter.hasProtocols()){
+            ArrayList<String> titles = new ArrayList<String>();
+            int i =0;
+            for (boolean b : this.selectedProtocols()){
+                if (b){
+                    String title = knownProtocols.get(i);
+                    titles.add(title);
+                }
+                i++;
+            }
+            return titles;
+        }
+        return this.protocolTitles();
+    }
+    /*
+    *
+    * COLOR STUFF
+    *
+    * */
 
-	/*
-	 * 
-	 * COLOR STUFF
-	 */
 
-	public int getOtherColor() {
-		return Color.argb(255, 80, 80, 80); // grey
+    public int getOtherColor(){
+        return Color.argb(255, 80, 80, 80); // grey
 	}
-
-	public Integer getColor(int index) {
+	
+    public Integer getColor(int index) {
 		return ColorSequenceGenerator.getColorForIndex(index);
-	}
-
-	public LinearLayout getPlotLayout() {
-		if (this.rootView != null) {
-			return (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
-		} else {
-			return null;
-		}
-	}
-
-	/**
-	 * 
-	 * FILTER STUFF
-	 * 
-	 * */
-	private boolean isFilterSetForTitle(String title) {
-		if (title.equals(FILTER_MENU_TITLE_BSSID)) {
-			return this.filter.hasBSSIDs();
-		}
-		if (title.equals(FILTER_MENU_TITLE_ESSID)) {
-			return this.filter.hasESSIDs();
-		}
-		if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)) {
-			return (this.filter.getProtocols() != null && this.filter.hasProtocols() && this.filter.getProtocols().size() != this.protocolTitles().size());
-		}
-		if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)) {
-			return this.filter.hasBelowTimestamp();
-		}
-		if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)) {
-			return this.filter.hasAboveTimestamp();
-		}
-		return false;
-	}
-
-	private void clearFilter() {
-		if (filter == null)
-			this.filter = new LogFilter();
-		this.filter.clear();
-	}
-
-	/*
-	 * 
-	 * DATE TRANSFORMATION
-	 */
-	public long getDayHourFromDate(long timeInMillis) {
-
-		Calendar calendar = Calendar.getInstance();
+    }
+
+
+    public LinearLayout getPlotLayout(){
+        if (this.rootView != null){
+            return (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     *
+     *  FILTER STUFF
+     *
+     * */
+    private boolean isFilterSetForTitle(String title){
+        if (title.equals(FILTER_MENU_TITLE_BSSID)){
+            return this.filter.hasBSSIDs();
+        }
+        if (title.equals(FILTER_MENU_TITLE_ESSID)){
+            return this.filter.hasESSIDs();
+        }
+        if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
+            return (this.filter.getProtocols() != null  && this.filter.hasProtocols() && this.filter.getProtocols().size() != this.protocolTitles().size());
+        }
+        if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)){
+            return this.filter.hasBelowTimestamp();
+        }
+        if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
+            return this.filter.hasAboveTimestamp();
+        }
+        return false;
+    }
+
+    private void clearFilter(){
+        if(filter == null) this.filter = new LogFilter();
+        this.filter.clear();
+    }
+
+    /*
+    *
+    *  DATE TRANSFORMATION
+    *
+    */
+    public long getDayHourFromDate(long timeInMillis){
 
-		calendar.setTimeInMillis(timeInMillis);
-		int hour = calendar.get(Calendar.HOUR_OF_DAY);
-		int min = calendar.get(Calendar.MINUTE);
+        Calendar calendar = Calendar.getInstance();
 
-		return hour;
+        calendar.setTimeInMillis (timeInMillis);
+        int hour    = calendar.get(Calendar.HOUR_OF_DAY);
+        int min     = calendar.get(Calendar.MINUTE);
 
-	}
+        return hour;
 
-	public long getDateFromMilliseconds(long timeInMillis) {
-		long millisInDay = 60 * 60 * 24 * 1000;
-		return (timeInMillis / millisInDay) * millisInDay;
+    }
+    public long getDateFromMilliseconds(long timeInMillis){
+        long millisInDay = 60 * 60 * 24 * 1000;
+        return (timeInMillis / millisInDay) * millisInDay;
 
-	}
+    }
 
-	/*
+    /*
     *
     * */
-	private String getHourAsTimeString(long hour) {
-		return "" + hour + ":00";
-	}
-
-	static final DateFormat dateFormat = new SimpleDateFormat("d.M.yyyy");
-
-	@SuppressLint("SimpleDateFormat")
-	private String getDateAsDayString(long timeStamp) {
-		try {
-			Date netDate = (new Date(timeStamp));
-			return dateFormat.format(netDate);
-		} catch (Exception ex) {
-			return "xx";
-		}
-	}
-
-	@SuppressLint("SimpleDateFormat")
-	private String getDateAsString(long timeStamp) {
-
-		try {
-			DateFormat sdf = new SimpleDateFormat("H:mm  dd/MM/yyyy");
-			Date netDate = (new Date(timeStamp));
-			return sdf.format(netDate);
-		} catch (Exception ex) {
-			return "xx";
-		}
-	}
-
-	/**
-	 * USERINTERACTION
-	 */
-	private void userTappedOnLegendItem(int index) {
-		if (index < this.currentData.size()) {
-			PlotComparisonItem item = this.currentData.get(index);
-			ArrayList<String> selectedData;
-			String sortKey = null;
-			selectedData = new ArrayList<String>();
-
-			if (item.getOtherData() == null) {
-				selectedData.add(item.getTitle());
-			} else {
-				for (PlotComparisonItem other : item.getOtherData()) {
-					selectedData.add(other.getTitle());
-				}
-			}
-			LogFilter filter = new LogFilter();
-			if (this.currentPlotView instanceof PieGraph) {
-				filter.setProtocols(selectedData);
-			}
-			if (this.currentPlotView instanceof BarGraph) {
-
-				if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerESSID)) {
-					filter.setESSIDs(selectedData);
-					sortKey = "ESSID";
-				} else {
-					filter.setBSSIDs(selectedData);
-					sortKey = "BSSID";
-				}
-				ArrayList<String> currentSelectedProtocol = new ArrayList<String>();
-				currentSelectedProtocol.add(this.getCurrentSelectedProtocol());
-				filter.setProtocols(currentSelectedProtocol);
-			}
-			if (this.currentPlotView instanceof LineGraph) {
-				selectedData = new ArrayList<String>();
-				selectedData.add(item.getTitle());
-				filter.setESSIDs(selectedData);
-				filter.setProtocols(this.filter.getProtocols());
-				sortKey = "ESSID";
-			}
-
-			if (this.filter.hasATimestamp()) {
-				filter.setAboveTimestamp(this.filter.getAboveTimestamp());
-				filter.setBelowTimestamp(this.filter.getBelowTimestamp());
-			}
-
-			this.pushRecordOverviewForFilter(filter, sortKey);
-		}
-	}
+    private String getHourAsTimeString(long hour) {
+        return "" + hour + ":00";
+    }
+
+    static final DateFormat dateFormat = new SimpleDateFormat("d.M.yyyy");
+    @SuppressLint("SimpleDateFormat")
+    private String getDateAsDayString(long timeStamp) {
+        try {
+            Date netDate = (new Date(timeStamp));
+            return dateFormat.format(netDate);
+        } catch (Exception ex) {
+            return "xx";
+        }
+    }
+
+    @SuppressLint("SimpleDateFormat")
+    private String getDateAsString(long timeStamp) {
+
+        try {
+            DateFormat sdf = new SimpleDateFormat("H:mm  dd/MM/yyyy");
+            Date netDate = (new Date(timeStamp));
+            return sdf.format(netDate);
+        } catch (Exception ex) {
+            return "xx";
+        }
+    }
+
+
+    /**
+     * USERINTERACTION
+     */
+    private void userTappedOnLegendItem(int index){
+        if (index < this.currentData.size()){
+            PlotComparisonItem item = this.currentData.get(index);
+            ArrayList<String> selectedData;
+            String sortKey = null;
+            selectedData = new ArrayList<String>();
+
+            if (item.getOtherData() == null){
+                selectedData.add(item.getTitle());
+            } else {
+                for (PlotComparisonItem other : item.getOtherData()){
+                    selectedData.add(other.getTitle());
+                }
+            }
+            LogFilter filter = new LogFilter();
+            if (this.currentPlotView instanceof PieGraph){
+                filter.setProtocols(selectedData);
+            }
+            if (this.currentPlotView instanceof BarGraph){
+
+                if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerESSID)){
+                    filter.setESSIDs(selectedData);
+                    sortKey = "ESSID";
+                } else {
+                    filter.setBSSIDs(selectedData);
+                    sortKey = "BSSID";
+                }
+                ArrayList<String> currentSelectedProtocol = new ArrayList<String>();
+                currentSelectedProtocol.add(this.getCurrentSelectedProtocol());
+                filter.setProtocols(currentSelectedProtocol);
+            }
+            if (this.currentPlotView instanceof  LineGraph){
+                selectedData = new ArrayList<String>();
+                selectedData.add(item.getTitle());
+                filter.setESSIDs(selectedData);
+                filter.setProtocols(this.filter.getProtocols());
+                sortKey = "ESSID";
+            }
+
+            if (this.filter.hasATimestamp()){
+                filter.setAboveTimestamp(this.filter.getAboveTimestamp());
+                filter.setBelowTimestamp(this.filter.getBelowTimestamp());
+            }
+
+            this.pushRecordOverviewForFilter(filter, sortKey);
+        }
+    }
+
+    public void onSliceClick(int index){
+
+    }
+    public void onBarClick(int index){
+        this.userTappedOnLegendItem(index);
+    }
+
+    private void pushRecordOverviewForFilter(LogFilter filter, String sortKey){
+
+        FragmentManager fm = this.getActivity().getFragmentManager();
+
+        if (fm != null){
+            RecordOverviewFragment newFragment = new RecordOverviewFragment();
+	        newFragment.setUpNavigatible(true);
+            newFragment.setFilter(filter);
+
+            if (sortKey != null && sortKey.length() != 0) newFragment.setGroupKey(sortKey);
+
+            MainActivity.getInstance().injectFragment(newFragment);
+
+        }
+
+    }
 
-	public void onSliceClick(int index) {
-
-	}
-
-	public void onBarClick(int index) {
-		this.userTappedOnLegendItem(index);
-	}
-
-	private void pushRecordOverviewForFilter(LogFilter filter, String sortKey) {
-
-		FragmentManager fm = this.getActivity().getFragmentManager();
-
-		if (fm != null) {
-			RecordOverviewFragment newFragment = new RecordOverviewFragment();
-			newFragment.setUpNavigatible(true);
-			newFragment.setFilter(filter);
-
-			if (sortKey != null && sortKey.length() != 0)
-				newFragment.setGroupKey(sortKey);
-
-			MainActivity.getInstance().injectFragment(newFragment);
-
-		}
-
-	}
 
 }

+ 38 - 0
src/de/tudarmstadt/informatik/hostage/ui2/task/LoaderTask.java

@@ -0,0 +1,38 @@
+package de.tudarmstadt.informatik.hostage.ui2.task;
+
+import android.annotation.SuppressLint;
+import android.os.AsyncTask;
+
+/**
+ * Created by Julien on 23.03.14.
+ */
+public class LoaderTask extends AsyncTask<Void, Void, Void> {
+
+    private TaskListener listener;
+
+    @SuppressLint("ValidFragment")
+    public interface TaskListener {
+        public void doInBackgorund();
+        public void onFinish();
+    }
+
+    public LoaderTask(TaskListener listener){
+        super();
+        this.listener = listener;
+    }
+
+    @Override
+    protected Void doInBackground(Void... unused) {
+        if (this.listener != null){
+            this.listener.doInBackgorund();
+        }
+        return(null);
+    }
+
+    @Override
+    protected void onPostExecute(Void unused) {
+        if (this.listener != null){
+            this.listener.onFinish();
+        }
+    }
+}

Some files were not shown because too many files changed in this diff