Browse Source

Fixed issues in statistic fragment
added filter button function

Julien Clauter 11 years ago
parent
commit
928c19ebbb

+ 17 - 4
res/layout/fragment_statistics.xml

@@ -46,12 +46,25 @@
 
         </LinearLayout>
 
-            <ListView
-                android:layout_width="match_parent"
+            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+                android:orientation="vertical"
                 android:layout_height="match_parent"
-                android:id="@+id/legend_list_view"
+                android:layout_width="match_parent"
+                android:id="@+id/list_parent_layout"
+                android:paddingTop="5dp"
                 android:layout_weight="1.1"
-                />
+                >
+                <ListView
+                    android:layout_width="match_parent"
+                    android:layout_height="match_parent"
+                    android:id="@+id/legend_list_view"
+                    android:paddingBottom="0dp"
+                    android:paddingTop="6dp"
+                    />
+            </LinearLayout>
+
+
+
 
             </LinearLayout>
 

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

@@ -43,7 +43,7 @@ import java.util.ArrayList;
 
 public class BarGraph extends View {
 
-	private final static int VALUE_FONT_SIZE = 30, AXIS_LABEL_FONT_SIZE = 15;
+	private final static int VALUE_FONT_SIZE = 23, AXIS_LABEL_FONT_SIZE = 15;
 	
     private ArrayList<Bar> mBars = new ArrayList<Bar>();
     private Paint mPaint = new Paint();
@@ -176,9 +176,9 @@ public class BarGraph extends View {
                     Rect r2 = new Rect();
                     this.mPaint.getTextBounds(bar.getValueString(), 0, 1, r2);
                     
-                    int boundLeft = (int) (((mRectangle.left+mRectangle.right)/2)-(this.mPaint.measureText(bar.getValueString())/2)-10 * mContext.getResources().getDisplayMetrics().density);
+                    int boundLeft = (int) (((mRectangle.left+mRectangle.right)/2)-(this.mPaint.measureText(bar.getValueString())/2)-5 * mContext.getResources().getDisplayMetrics().density);
                     int boundTop = (int) (mRectangle.top+(r2.top-r2.bottom)-18 * mContext.getResources().getDisplayMetrics().density);
-                    int boundRight = (int)(((mRectangle.left+mRectangle.right)/2)+(this.mPaint.measureText(bar.getValueString())/2)+10 * mContext.getResources().getDisplayMetrics().density);
+                    int boundRight = (int)(((mRectangle.left+mRectangle.right)/2)+(this.mPaint.measureText(bar.getValueString())/2)+5 * mContext.getResources().getDisplayMetrics().density);
                     popup.setBounds(boundLeft, boundTop, boundRight, mRectangle.top);
                     popup.draw(canvas);
                     

+ 45 - 9
src/de/tudarmstadt/informatik/hostage/ui2/fragment/StatisticsFragment.java

@@ -75,6 +75,7 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
     static  final String COMPARE_TITLE_AttacksPerTime       = "Attacks per time";
     static  final String COMPARE_TITLE_AttacksPerBSSID      = "Attacks per BSSID";
     static  final String COMPARE_TITLE_AttacksPerESSID      = "Attacks per ESSID";
+    static final String FILTER_MENU_PROTOCOL_SINGLE_CHOICE_TITLE = "Select Protocol";
 
 
     static final String OTHER_CHART_TITLE = "Other";
@@ -245,6 +246,7 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
 
     public void setChartType(ChartType type){
         boolean shouldChange = true;
+        this.clearFilter();
         if (this.currentPlotView != null){
             if (type == ChartType.PIE_CHART){
                 shouldChange = ! (this.currentPlotView instanceof PieGraph);
@@ -275,8 +277,9 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
             this.currentPlotView = this.getPlotViewForType(type);
             this.currentPlotView.setVisibility(View.VISIBLE);
 
-            this.actualiseCurrentPlot();
         }
+        this.actualiseCurrentPlot();
+
     }
 
     public View getPlotViewForType(ChartType type){
@@ -321,8 +324,6 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
     }
 
     private void userSelectMenuItem(AbstractPopupItem item){
-        //int id = item.getItemId();
-        //this.setChartType(ChartType.create(id));
         // OPEN A DIALOG TO SPECIFY THE VISUALISE DATA
         if (item.getTitle().equals(MENU_TITLE_PROTOCOLS)){
             this.openProtocolDataDialog();
@@ -370,6 +371,15 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
     public void onDialogPositiveClick(ChecklistDialog dialog) {
         String title = dialog.getTitle();
         ArrayList<String> titles =dialog.getSelectedItemTitles();
+
+        if (title.equals(FILTER_MENU_PROTOCOL_SINGLE_CHOICE_TITLE)){
+            this.filter.setProtocols(titles);
+            this.actualiseCurrentPlot();
+            String fragTitle = "" + this.getCurrentSelectedProtocol() + ": " + this.selectedCompareData;
+            this.setTitle(fragTitle);
+            return;
+        }
+
         if (titles.size() != 0){
             String data = titles.get(0);
             this.setTitle(data);
@@ -387,6 +397,9 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
                 ChartType chartType = ChartType.BAR_CHART;
                 this.selectedCompareData = data;
                 this.setChartType(chartType);
+
+                String fragTitle = "" + this.getCurrentSelectedProtocol() + ": " + this.selectedCompareData;
+                this.setTitle(fragTitle);
             }
         }
 
@@ -431,6 +444,15 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
     *
     * */
     private void openFilterMenuOnView(View anchor){
+        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);
 
     }
 
@@ -481,6 +503,7 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
             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()));
             plotLayout.addView(this.barGraph);
+            this.barGraph.setShowBarText(false);
             this.barGraph.setPopupImageID(R.drawable.popup_black);
             this.barGraph.setOnBarClickedListener(new BarGraph.OnBarClickedListener() {
                 @Override
@@ -525,6 +548,7 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
 
         this.lineGraph.removeAllLines();
         Line l = new Line();
+        l.setColor(this.getColor(0));
 
         for (PlotComparisonItem item : this.currentData){
             LinePoint p = new LinePoint();
@@ -552,8 +576,8 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         for (PlotComparisonItem item : this.currentData){
             Bar d = new Bar();
             d.setColor(item.getColor());
-            d.setName(item.getTitle());
-            Double value2 = (Double) item.getValue2();
+            Long value2 =  item.getValue2().longValue();
+            d.setName("" + value2);
             d.setValue(value2.floatValue());
             bars.add(d);
         }
@@ -632,10 +656,14 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         return this.attacksPerProtocols();
     }
     public ArrayList<PlotComparisonItem> getBarData(){
-        ArrayList<String> protocolTitles = this.getSelectedProtocolTitles();
+        String protocol = this.getCurrentSelectedProtocol();
+
+        if (protocol.length() > 0){
+            if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerESSID)){
+                return this.attacksPerESSID(protocol);
+            }
 
-        if (protocolTitles != null && protocolTitles.size() != 0){
-            String protocol = this.getSelectedProtocolTitles().get(0);
+            // DEFAULT
             return this.attacksPerBSSID(protocol);
         }
 
@@ -856,7 +884,15 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
     /*
     * FILTER STUFF
     * */
-    public ArrayList<String> protocolTitles(){
+     private String getCurrentSelectedProtocol(){
+         ArrayList<String> protocolTitles = this.getSelectedProtocolTitles();
+         if (protocolTitles != null && protocolTitles.size() != 0){
+             return  this.getSelectedProtocolTitles().get(0);
+         }
+         return "";
+     }
+
+     public ArrayList<String> protocolTitles(){
         ArrayList<String> titles = new ArrayList<String>();
         for (String protocol : this.getResources().getStringArray(
                 R.array.protocols)) {