浏览代码

detail view in statistics and new filter options

Julien Clauter 10 年之前
父节点
当前提交
58ef887aec

+ 84 - 5
src/com/echo/holographlibrary/PieGraph.java

@@ -30,17 +30,25 @@ import android.graphics.Paint;
 import android.graphics.Path;
 import android.graphics.Path.Direction;
 import android.graphics.Point;
+import android.graphics.Rect;
 import android.graphics.RectF;
 import android.graphics.Region;
 import android.util.AttributeSet;
 import android.view.MotionEvent;
 import android.view.View;
+import android.widget.TextView;
 
 import java.util.ArrayList;
 
 public class PieGraph extends View {
 
-	private ArrayList<PieSlice> slices = new ArrayList<PieSlice>();
+    private final static int TITLE_FONT_SIZE = 14;
+    private final static int SUBTITLE_FONT_SIZE = 30;
+
+    static final String ALL_TITLE = "All";
+
+
+    private ArrayList<PieSlice> slices = new ArrayList<PieSlice>();
 	private Paint paint = new Paint();
 	private Path path = new Path();
 	
@@ -49,21 +57,30 @@ public class PieGraph extends View {
 	private OnSliceClickedListener listener;
 	
 	private boolean drawCompleted = false;
+
+    private TextView titleTextView;
+    private TextView subtitleTextView;
+
+    private String title;
+    private String subtitle;
+
+    private Context mContext;
 	
 	
 	public PieGraph(Context context) {
 		super(context);
+        this.mContext = context;
 		thickness = (int) (25f * context.getResources().getDisplayMetrics().density);
         this.setWillNotDraw(false);
 	}
 	
 	public PieGraph(Context context, AttributeSet attrs) {
 		super(context, attrs);
+        this.mContext = context;
 		thickness = (int) (25f * context.getResources().getDisplayMetrics().density);
         this.setWillNotDraw(false);
     }
 
-
     public void onDraw(Canvas canvas) {
         super.onDraw(canvas);
 
@@ -107,7 +124,7 @@ public class PieGraph extends View {
 			
 			if (indexSelected == count && listener != null){
 				path.reset();
-				paint.setColor(slice.getColor());
+				//paint.setColor(slice.getColor());
 				paint.setColor(Color.parseColor("#33B5E5"));
 				paint.setAlpha(100);
 				
@@ -127,10 +144,60 @@ public class PieGraph extends View {
 			
 			count++;
 		}
+
+
+        this.drawTitle(canvas);
+        this.drawSubtitle(canvas);
 		
 		drawCompleted = true;
 		
 	}
+
+    private void drawTitle(Canvas canvas){
+        String title = this.title;
+
+        if (title != null && title.length() != 0){
+            this.paint.reset();
+            paint.setColor(Color.BLACK);
+            paint.setAlpha(50);
+            paint.setAntiAlias(true);
+            paint.setAlpha(255);
+
+            this.paint.setTextSize(TITLE_FONT_SIZE * mContext.getResources().getDisplayMetrics().scaledDensity);
+
+            int yCenter = this.getHeight() / 2;
+            int xCenter = this.getWidth() / 2;
+
+            float textwidth = (this.paint.measureText(title));
+            Rect bounds = new Rect();
+            this.paint.getTextBounds(title,0,title.length(), bounds);
+            canvas.drawText(title,xCenter - (textwidth / 2),yCenter - bounds.height(), this.paint);
+
+            this.paint.reset();
+        }
+    }
+    private void drawSubtitle(Canvas canvas){
+        String title = this.subtitle;
+        if (title != null && title.length() != 0){
+            this.paint.reset();
+            paint.setColor(Color.BLACK);
+            paint.setAlpha(50);
+            paint.setAntiAlias(true);
+            paint.setAlpha(255);
+
+            this.paint.setTextSize(SUBTITLE_FONT_SIZE * mContext.getResources().getDisplayMetrics().scaledDensity);
+
+            int yCenter = this.getHeight() / 2;
+            int xCenter = this.getWidth() / 2;
+
+            float textwidth = (this.paint.measureText(title));
+            Rect bounds = new Rect();
+            this.paint.getTextBounds(title,0,title.length(), bounds);
+            canvas.drawText(title,xCenter - (textwidth / 2),yCenter + bounds.height(), this.paint);
+
+            this.paint.reset();
+        }
+    }
 	
 	@Override
 	public boolean onTouchEvent(MotionEvent event) {
@@ -147,6 +214,8 @@ public class PieGraph extends View {
 				r.setPath(slice.getPath(), slice.getRegion());
 				if (r.contains((int)point.x,(int) point.y) && event.getAction() == MotionEvent.ACTION_DOWN){
 					indexSelected = count;
+                    this.title = slice.getTitle();
+                    this.subtitle = "" + (long) slice.getValue();
 				} else if (event.getAction() == MotionEvent.ACTION_UP){
 					if (r.contains((int)point.x,(int) point.y) && listener != null){
 						if (indexSelected > -1){
@@ -156,8 +225,9 @@ public class PieGraph extends View {
 					}
 					
 				}
-				else if(event.getAction() == MotionEvent.ACTION_CANCEL)
-					indexSelected = -1;
+				else if(event.getAction() == MotionEvent.ACTION_CANCEL) {
+                    indexSelected = -1;
+                }
 				count++;
 			}
 			
@@ -182,6 +252,12 @@ public class PieGraph extends View {
 	}
 	public void addSlice(PieSlice slice) {
 		this.slices.add(slice);
+        long countedValue = 0;
+        for (PieSlice s : this.slices){
+            countedValue+=s.getValue();
+        }
+        this.title = ALL_TITLE;
+        this.subtitle = "" + countedValue;
 		postInvalidate();
 	}
 	public void setOnSliceClickedListener(OnSliceClickedListener listener) {
@@ -200,6 +276,9 @@ public class PieGraph extends View {
 		for (int i = slices.size()-1; i >= 0; i--){
 			slices.remove(i);
 		}
+        this.title = "";
+        this.subtitle = "";
+
 		postInvalidate();
 	}
 

+ 6 - 3
src/de/tudarmstadt/informatik/hostage/logging/UglyDbHelper.java

@@ -172,9 +172,12 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 			selectQuery = selectQuery + filter.getProtocolsQueryStatement(TABLE_ATTACK_INFO, KEY_PROTOCOL);
 		}
 
-
-		// ORDERED BY TIME
-		selectQuery = selectQuery + " ORDER BY " + filter.getSorttype();
+        if (filter.getSorttype() == LogFilter.SortType.timestamp){
+            //DESC
+            selectQuery = selectQuery + " ORDER BY " + filter.getSorttype() + " DESC";
+        } else {
+            selectQuery = selectQuery + " ORDER BY " + filter.getSorttype();
+        }
 		System.out.println(selectQuery);
 		SQLiteDatabase db = this.getReadableDatabase();
 		Cursor cursor = db.rawQuery(selectQuery, null);

+ 9 - 1
src/de/tudarmstadt/informatik/hostage/ui2/fragment/RecordOverviewFragment.java

@@ -71,6 +71,10 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 
     private String sectionToOpen = "";
 
+    public void setFilter(LogFilter filter){
+        this.filter = filter;
+    }
+
 
     public RecordOverviewFragment(){}
 
@@ -104,7 +108,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 	    this.setShowFilterButton(!this.filter.isNotEditable());
 	    this.addRecordToDB();
 
-		View rootView = inflater.inflate(R.layout.fragment_record_list, container, false);
+		View rootView = inflater.inflate(this.getLayoutId(), container, false);
 		ExpandableListView mylist = (ExpandableListView) rootView.findViewById(R.id.loglistview);
 		this.expListView = mylist;
 		populateListViewFromDB(mylist);
@@ -138,6 +142,10 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 		return rootView;
 	 }
 
+    public int getLayoutId(){
+        return R.layout.fragment_record_list;
+    }
+
 
 
 	public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

+ 101 - 34
src/de/tudarmstadt/informatik/hostage/ui2/fragment/StatisticsFragment.java

@@ -2,6 +2,8 @@ package de.tudarmstadt.informatik.hostage.ui2.fragment;
 
 import android.annotation.SuppressLint;
 import android.app.Fragment;
+import android.app.FragmentManager;
+import android.app.FragmentTransaction;
 import android.content.Context;
 import android.content.Intent;
 import android.graphics.Color;
@@ -54,7 +56,8 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
 
     static final String FILTER_MENU_TITLE_BSSID = "BSSID";
     static final String FILTER_MENU_TITLE_ESSID = "ESSID";
-    static final String FILTER_MENU_TITLE_PROTOCOLS = "Protocol";
+    static final String FILTER_MENU_TITLE_PROTOCOLS = "Protocols";
+    static final String FILTER_MENU_TITLE_PROTOCOL = "Protocol";
     static final String FILTER_MENU_TITLE_TIMESTAMP_BELOW = "Latest";
     static final String FILTER_MENU_TITLE_TIMESTAMP_ABOVE = "Earliest";
 
@@ -184,7 +187,7 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         this.legendListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
             @Override
             public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
-                StatisticsFragment.this.userTappedOnItem(i);
+                StatisticsFragment.this.userTappedOnLegendItem(i);
             }
         });
         this.rootView = rootView;
@@ -215,11 +218,10 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         ImageButton visualButton = (ImageButton) rootView.findViewById(R.id.plot_data_button);
         visualButton.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
-                StatisticsFragment.this.openPopupMenuOnView(v);
+                StatisticsFragment.this.openBarSelectionMenuOnView(v);
             }
         });
 
-        this.setTitle(this.selectedCompareData);
 
         ImageButton filterButton = this.getFilterButton();
         filterButton.setOnClickListener(new View.OnClickListener() {
@@ -227,6 +229,12 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
                 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){
@@ -249,6 +257,12 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         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){
@@ -259,10 +273,10 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
                 shouldChange = ! (this.currentPlotView instanceof PieGraph);
                 // SET FILTER BUTTON HIDDEN
                 ImageButton filterButton = this.getFilterButton();
-                if (filterButton != null) filterButton.setVisibility(View.INVISIBLE);
+                if (filterButton != null) filterButton.setVisibility(View.GONE);
             } else {
                 if (this.pieGraph != null)
-                     this.pieGraph.setVisibility(View.INVISIBLE);
+                     this.pieGraph.setVisibility(View.GONE);
                 // SHOW FILTER BUTTON
                 ImageButton filterButton = this.getFilterButton();
                 if (filterButton != null) filterButton.setVisibility(View.VISIBLE);
@@ -271,14 +285,14 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
                 shouldChange = ! (this.currentPlotView instanceof LineGraph);
             } else {
                 if (this.lineGraph != null)
-                     this.lineGraph.setVisibility(View.INVISIBLE);
+                     this.lineGraph.setVisibility(View.GONE);
             }
             if (type == ChartType.BAR_CHART){
                 shouldChange = ! (this.currentPlotView instanceof BarGraph);
 
             } else {
                 if (this.barGraph != null)
-                    this.barGraph.setVisibility(View.INVISIBLE);
+                    this.barGraph.setVisibility(View.GONE);
 
             }
         }
@@ -310,7 +324,7 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
     /*
     * MENU
     * */
-    private void openPopupMenuOnView(View anchorView){
+    private void openBarSelectionMenuOnView(View anchorView){
         SimplePopupTable visualiseMenu = new SimplePopupTable(this.getActivity(), new AbstractPopup.OnPopupItemClickListener() {
             public void onItemClick(Object ob) {
                 if (ob instanceof AbstractPopupItem){
@@ -325,7 +339,7 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
             SimplePopupItem item = new SimplePopupItem(this.getActivity());
             item.setTitle(title);
             item.setItemId(id);
-            item.setSelected(this.isFilterSetForTitle(title));
+            item.setSelected(false);
             visualiseMenu.addItem(item);
             id++;
         }
@@ -339,7 +353,6 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
             this.selectedCompareData = COMPARE_TITLE_AttacksPerProtocol;
             this.setChartType(chartType);
             this.setTitle(COMPARE_TITLE_AttacksPerProtocol);
-            //this.openProtocolDataDialog();
         }
         if (item.getTitle().equals(MENU_TITLE_NETWORK)){
             this.openNetworkDataDialog();
@@ -385,6 +398,11 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         String title = dialog.getTitle();
         ArrayList<String> titles =dialog.getSelectedItemTitles();
 
+        if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
+            this.filter.setProtocols(titles.size() == 0 ? this.protocolTitles() : titles);
+            this.actualiseCurrentPlot();
+            return;
+        }
         if (title.equals(FILTER_MENU_PROTOCOL_SINGLE_CHOICE_TITLE)){
             this.filter.setProtocols(titles);
             this.actualiseCurrentPlot();
@@ -498,6 +516,11 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
 
             filterMenu.addItem(item);
         }
+        if (this.filter.isSet()){
+            AbstractPopupItem item = new SimplePopupItem(this.getActivity());
+            item.setTitle(FILTER_MENU_TITLE_REMOVE);
+            filterMenu.addItem(item);
+        }
         filterMenu.showOnView(anchor);
     }
 
@@ -519,9 +542,12 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         if (title.equals(FILTER_MENU_TITLE_BSSID)){
             this.openBSSIDFilterDialog();
         }
-        if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
+        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();
@@ -532,12 +558,13 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         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()){
                 titles.add(FILTER_MENU_TITLE_REMOVE);
             }
         } else {
-            titles.add(FILTER_MENU_TITLE_PROTOCOLS);
+            titles.add(FILTER_MENU_TITLE_PROTOCOL);
             String protocol = this.getCurrentSelectedProtocol();
             if (protocol.length() > 0){
                 if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerBSSID)){
@@ -554,6 +581,10 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         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()];
@@ -654,17 +685,7 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         this.actualiseCurrentPlot();
     }
 
-    /**
-    *
-    * PLOT TOUCH HANDLING
-    *
-    * */
-    public void onSliceClick(int index){
-        this.userTappedOnItem(index);
-    }
-    public void onBarClick(int index){
-        this.userTappedOnItem(index);
-    }
+
     /*
     *
     *  PLOT TYPES
@@ -698,7 +719,7 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         if (this.barGraph == null) {
             this.barGraph = new BarGraph(this.getActivity());
             LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
-            this.barGraph.setLayoutParams(new ViewGroup.LayoutParams(plotLayout.getWidth() - plotLayout.getPaddingLeft() - plotLayout.getPaddingRight(), plotLayout.getHeight() -  - plotLayout.getPaddingTop() - plotLayout.getPaddingBottom()));
+            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);
@@ -795,7 +816,7 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
             }
 
             double stepRange = (rangeMax_X - rangeMin_X)/(60*60*24*1000);
-            this.lineGraph.setxAxisStep(Math.max(1,(float)Math.min(stepRange, 4)));
+            this.lineGraph.setxAxisStep(Math.max(1, (float) Math.min(stepRange, 4)));
 
             this.lineGraph.setRangeX(rangeMin_X  , rangeMax_X);
 
@@ -851,7 +872,6 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         return this.dbh.getRecordsForFilter(this.filter);
     }
 
-
      public void actualiseCurrentPlot(){
          LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
         View plot = this.currentPlotView;
@@ -859,25 +879,38 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
              this.currentPlotView = this.getPieGraphView();
              plot = this.currentPlotView;
          }
-        if (plot.getVisibility() == View.INVISIBLE) plot.setVisibility(View.VISIBLE);
+         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.INVISIBLE);
+                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.INVISIBLE);
+                this.barGraph.setVisibility(View.GONE);
                 if (this.barGraph.getParent() != null){
                     plotLayout.removeView(this.barGraph);
                 }
@@ -888,7 +921,7 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
            this.setLineGraphData(line);
         }else {
             if (this.lineGraph != null){
-                this.lineGraph.setVisibility(View.INVISIBLE);
+                this.lineGraph.setVisibility(View.GONE);
                 if (this.lineGraph.getParent() != null){
                     plotLayout.removeView(this.lineGraph);
                 }
@@ -1280,7 +1313,7 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
     /**
      * USERINTERACTION
      */
-    private void userTappedOnItem(int index){
+    private void userTappedOnLegendItem(int index){
         if (index < this.currentData.size()){
             PlotComparisonItem item = this.currentData.get(index);
             ArrayList<String> selectedData;
@@ -1298,20 +1331,54 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
                 filter.setProtocols(selectedData);
             }
             if (this.currentPlotView instanceof BarGraph){
-                // TODO set data for BSSID / ESSID
+
+                if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerESSID)){
+                    filter.setESSIDs(selectedData);
+                } else {
+                    filter.setBSSIDs(selectedData);
+                }
+                ArrayList<String> currentSelectedProtocol = new ArrayList<String>();
+                currentSelectedProtocol.add(this.getCurrentSelectedProtocol());
+                filter.setProtocols(currentSelectedProtocol);
             }
             if (this.currentPlotView instanceof  LineGraph){
-                // TODO set data for BSSID / ESSID
+                selectedData = new ArrayList<String>();
+                selectedData.add(item.getTitle());
+                filter.setESSIDs(selectedData);
+                filter.setProtocols(this.filter.getProtocols());
+            }
+
+            if (this.filter.hasATimestamp()){
+                filter.setAboveTimestamp(this.filter.getAboveTimestamp());
+                filter.setBelowTimestamp(this.filter.getBelowTimestamp());
             }
 
             this.pushRecordOverviewForFilter(filter);
         }
+    }
 
+    public void onSliceClick(int index){
 
     }
+    public void onBarClick(int index){
+        this.userTappedOnLegendItem(index);
+    }
 
     private void pushRecordOverviewForFilter(LogFilter filter){
 
+        FragmentManager fm = this.getActivity().getFragmentManager();
+
+        if (fm != null){
+            RecordOverviewFragment newFragment = new RecordOverviewFragment();
+            newFragment.setFilter(filter);
+            FragmentTransaction transaction = fm.beginTransaction();
+            transaction.replace(R.id.content_frame, newFragment, newFragment.getTag());
+            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
+            transaction.addToBackStack(null);
+
+            transaction.commit();
+        }
+
     }