Browse Source

bug fixed in statistics:
legend table header
no dublicated reset button
deselectable pieslice
correct numbers in legend table
fixed bug in ugly db manager

Julien Clauter 11 năm trước cách đây
mục cha
commit
24c1ff2625

+ 46 - 13
res/layout/fragment_statistics.xml

@@ -34,34 +34,67 @@
             android:layout_height="match_parent"
             android:layout_above="@+id/toolbar_layout"
             android:layout_below="@+id/title_layout"
-            android:weightSum="2">
+            android:weightSum="2.">
 
-        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-            android:orientation="vertical"
-            android:layout_height="match_parent"
-            android:layout_width="match_parent"
-            android:id="@+id/plot_layout"
-            android:padding="2dp"
-            android:layout_weight="0.9">
+            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:orientation="vertical"
+              android:layout_height="match_parent"
+              android:layout_width="match_parent"
+              android:id="@+id/plot_layout"
+               android:padding="2dp"
+               android:layout_weight="1.1">
+            </LinearLayout>
 
-        </LinearLayout>
 
-            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-                android:orientation="vertical"
+            <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                 android:layout_height="match_parent"
                 android:layout_width="match_parent"
                 android:id="@+id/list_parent_layout"
                 android:paddingTop="5dp"
-                android:layout_weight="1.1"
+                android:layout_weight="0.9"
                 >
+
+                <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+                    android:orientation="horizontal"
+                    android:layout_height="30dp"
+                    android:layout_width="match_parent"
+                    android:id="@+id/table_header_layout"
+                    android:weightSum="1"
+                    android:paddingLeft="2dp"
+                    android:paddingRight="2dp">
+
+                    <TextView
+                        android:layout_width="fill_parent"
+                        android:layout_height="fill_parent"
+                        android:textAppearance="?android:attr/textAppearanceSmall"
+                        android:text="table header title"
+                        android:id="@+id/table_header_title_textview"
+                        android:gravity="bottom|left"
+                        android:textAlignment="viewStart"
+                        android:paddingLeft="75dp"
+                        android:layout_weight="0.4"
+                        android:textStyle="bold" />
+                    <TextView
+                        android:layout_width="fill_parent"
+                        android:layout_height="fill_parent"
+                        android:textAppearance="?android:attr/textAppearanceSmall"
+                        android:text="value"
+                        android:id="@+id/table_header_value_textview"
+                        android:textAlignment="viewEnd"
+                        android:layout_weight="0.6"
+                        android:gravity="bottom|right"
+                        android:textStyle="bold" />
+                </LinearLayout>
                 <ListView
                     android:layout_width="match_parent"
                     android:layout_height="match_parent"
+                    android:layout_below="@+id/table_header_layout"
                     android:id="@+id/legend_list_view"
                     android:paddingBottom="0dp"
                     android:paddingTop="6dp"
                     />
-            </LinearLayout>
+
+            </RelativeLayout>
 
 
 

+ 4 - 0
src/com/echo/holographlibrary/LineGraph.java

@@ -82,6 +82,8 @@ public class LineGraph extends View {
     public void setYAxisStep(float step){
         this.yAxisStep = step;
     }
+    public float getyAxisStep(){return  this.yAxisStep;}
+    public float getxAxisStep(){return this.xAxisStep;}
 
     public void setConverter(AxisDataConverter conv){
         this.converter = conv;
@@ -338,6 +340,8 @@ public class LineGraph extends View {
 	public void onDraw(Canvas ca) {
         super.onDraw(ca);
 
+        if (this.lines == null || this.lines.size() == 0) return;
+
         if (fullImage == null || shouldUpdate) {
 			fullImage = Bitmap.createBitmap(getWidth(), getHeight(), Config.ARGB_8888);
 			Canvas canvas = new Canvas(fullImage);

+ 9 - 2
src/com/echo/holographlibrary/PieGraph.java

@@ -209,6 +209,7 @@ public class PieGraph extends View {
 			point.y = (int) event.getY();
 			
 			int count = 0;
+            boolean drawedTitle = false;
 			for (PieSlice slice : slices){
 				Region r = new Region();
 				r.setPath(slice.getPath(), slice.getRegion());
@@ -216,6 +217,7 @@ public class PieGraph extends View {
 					indexSelected = count;
                     this.title = slice.getTitle();
                     this.subtitle = "" + (long) slice.getValue();
+                    drawedTitle = true;
 				} else if (event.getAction() == MotionEvent.ACTION_UP){
 					if (r.contains((int)point.x,(int) point.y) && listener != null){
 						if (indexSelected > -1){
@@ -230,7 +232,10 @@ public class PieGraph extends View {
                 }
 				count++;
 			}
-			
+			if ( event.getAction() == MotionEvent.ACTION_DOWN && !drawedTitle ) {
+                // refresh title & subtitle
+                this.addSlice(null);
+            }
 			if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL){
 				postInvalidate();
 			}
@@ -251,7 +256,9 @@ public class PieGraph extends View {
 		return slices.get(index);
 	}
 	public void addSlice(PieSlice slice) {
-		this.slices.add(slice);
+        if (slice != null)
+		    this.slices.add(slice);
+
         long countedValue = 0;
         for (PieSlice s : this.slices){
             countedValue+=s.getValue();

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

@@ -223,7 +223,7 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 
     private ArrayList<String> getUniqueIDForProtocol(String id, String protocol){
         ArrayList<String> recordList = new ArrayList<String>();
-        String selectQuery = "SELECT DISTINCT " + id + " FROM " + TABLE_ATTACK_INFO + " JOIN " + TABLE_BSSIDS + " USING "+ "(" + id + ") " + " WHERE " + TABLE_ATTACK_INFO + "."+ KEY_PROTOCOL + " = " + "'" + protocol + "'"+ " ORDER BY " + id; // " NATURAL JOIN " + TABLE_ATTACK_INFO + " NATURAL JOIN " + TABLE_BSSIDS + " NATURAL JOIN " + TABLE_PORTS +
+        String selectQuery = "SELECT DISTINCT " + id + " FROM " + TABLE_ATTACK_INFO + " JOIN " + TABLE_BSSIDS + " USING "+ "(" + KEY_BSSID + ") " + " WHERE " + TABLE_ATTACK_INFO + "."+ KEY_PROTOCOL + " = " + "'" + protocol + "'"+ " ORDER BY " + id; // " NATURAL JOIN " + TABLE_ATTACK_INFO + " NATURAL JOIN " + TABLE_BSSIDS + " NATURAL JOIN " + TABLE_PORTS +
 
 
         // ORDERED BY TIME

+ 15 - 1
src/de/tudarmstadt/informatik/hostage/ui2/adapter/StatisticListAdapter.java

@@ -23,9 +23,18 @@ public class StatisticListAdapter extends ArrayAdapter<PlotComparisonItem> {
         public TextView colorView;
     }
 
+    public interface ValueFormatter {
+        public String convertValueToString(double value);
+    }
+
+    private ValueFormatter formatter;
     private final Context context;
     private List<PlotComparisonItem> values;
 
+    public void setValueFormatter(ValueFormatter formatter){
+        this.formatter = formatter;
+    }
+
     public StatisticListAdapter(Context context, List<PlotComparisonItem> objects) {
         super(context, getLayoutID(), objects);
         List<PlotComparisonItem> list = objects == null ? new ArrayList<PlotComparisonItem>() : objects;
@@ -71,6 +80,11 @@ public class StatisticListAdapter extends ArrayAdapter<PlotComparisonItem> {
     private void configureView(ViewHolder holder, PlotComparisonItem item){
         holder.colorView.setBackgroundColor(item.getColor());
         holder.titleView.setText(item.getTitle());
-        holder.valueView.setText("" + item.getValue2());
+
+        if (this.formatter == null){
+            holder.valueView.setText("" + item.getValue2());
+        } else {
+            holder.valueView.setText(this.formatter.convertValueToString(item.getValue2()));
+        }
     }
 }

+ 60 - 13
src/de/tudarmstadt/informatik/hostage/ui2/fragment/StatisticsFragment.java

@@ -87,6 +87,9 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
     static  final String COMPARE_TITLE_AttacksPerESSID      = "Attacks per ESSID";
     static final String FILTER_MENU_PROTOCOL_SINGLE_CHOICE_TITLE = "Select Protocol";
 
+    static final String TABLE_HEADER_VALUE_TITLE_ATTACKS_COUNT = "Attacks count";
+    static final String TABLE_HEADER_VALUE_TITLE_ATTACKS_PERCENTAGE = "% of all";
+
 
     static final String OTHER_CHART_TITLE = "Other";
 
@@ -322,7 +325,44 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
 
     public void actualiseLegendList(){
         StatisticListAdapter adapter = new StatisticListAdapter(this.getApplicationContext(), this.currentData);
+        if (this.currentPlotView instanceof LineGraph){
+            adapter.setValueFormatter(new StatisticListAdapter.ValueFormatter() {
+                @Override
+                public String convertValueToString(double value) {
+                    return String.format("%.02f", value) + " %";
+                }
+            });
+        } else {
+
+            adapter.setValueFormatter(new StatisticListAdapter.ValueFormatter() {
+                @Override
+                public String convertValueToString(double value) {
+                    int v = (int) value;
+                    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);
+            }
+        }
     }
 
     /*
@@ -520,11 +560,6 @@ 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);
     }
 
@@ -578,7 +613,8 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
                 titles.add(FILTER_MENU_TITLE_ESSID);
             }
             titles.add(FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
-            if (this.filter.hasProtocols() || this.filter.hasATimestamp() || this.filter.hasESSIDs() || this.filter.hasBSSIDs()){
+            if (this.filter.hasATimestamp() || this.filter.hasESSIDs() || this.filter.hasBSSIDs()
+                    || (this.currentPlotView instanceof LineGraph && this.filter.hasProtocols())){
                 titles.add(FILTER_MENU_TITLE_REMOVE);
             }
         }
@@ -586,7 +622,11 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
     }
 
     private void openProtocolsFilterDialog(){
-        ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_PROTOCOLS,this.protocolTitles(), this.selectedProtocols(), true , this);
+        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(){
@@ -840,7 +880,11 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
             this.lineGraph.setConverter(null);
         }
 
-        this.lineGraph.setRangeY(rangeMin_Y, rangeMax_Y);
+        int maxY = (int)(rangeMax_Y - rangeMin_Y);
+        this.lineGraph.setYAxisStep(Math.min(maxY, 5));
+        int yStep = (int)this.lineGraph.getyAxisStep();
+        maxY = maxY + (maxY % yStep);
+        this.lineGraph.setRangeY(rangeMin_Y, rangeMin_Y + maxY);
         this.lineGraph.setLineToFill(0);
         this.lineGraph.invalidate();
     }
@@ -991,7 +1035,8 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
 
         boolean shouldUseDate = this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerDate);
 
-        for (Record record : this.getFetchedRecords()){
+        ArrayList<Record> records = this.getFetchedRecords();
+        for (Record record : records){
             long timestamp = record.getTimestamp();
             long time = 0;
             if (shouldUseDate){
@@ -1028,11 +1073,13 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
             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>() {
@@ -1042,8 +1089,8 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
                 }
             });
 
-
-            PlotComparisonItem item = new PlotComparisonItem(groupKey, this.getColor(index), 0., (double) singleLineItems.size());
+            double itemValue = (((double)numbOfAttacks / (double)records.size())*100.);
+            PlotComparisonItem item = new PlotComparisonItem(groupKey, this.getColor(index), 0., itemValue);
             item.setOtherData(singleLineItems);
             plotItems.add(item);
             index++;
@@ -1168,9 +1215,9 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
      private String getCurrentSelectedProtocol(){
          ArrayList<String> protocolTitles = this.getSelectedProtocolTitles();
          if (protocolTitles != null && protocolTitles.size() != 0){
-             return  this.getSelectedProtocolTitles().get(0);
+             return  protocolTitles.get(0);
          }
-         return "";
+         return this.protocolTitles().get(0);
      }
 
      public ArrayList<String> protocolTitles(){