Browse Source

Bug fixes in statistics

Julien Clauter 10 years ago
parent
commit
81878eb944

+ 23 - 0
res/layout/fragment_statistics.xml

@@ -44,6 +44,29 @@
             android:padding="2dp"
             android:layout_weight="0.9">
 
+            <!--
+            <view
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                class="com.echo.holographlibrary.BarGraph"
+                android:id="@+id/bargraph"
+                android:layout_gravity="center_horizontal"
+                />
+            <view
+                android:layout_width="200dp"
+                android:layout_height="200dp"
+                class="com.echo.holographlibrary.PieGraph"
+                android:id="@+id/piegraph"
+                android:layout_gravity="center_horizontal"
+                />
+            <view
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                class="com.echo.holographlibrary.LineGraph"
+                android:id="@+id/linegraph"
+                android:layout_gravity="center_horizontal"
+                />
+                -->
         </LinearLayout>
 
             <ListView

+ 1 - 0
src/com/echo/holographlibrary/PieGraph.java

@@ -66,6 +66,7 @@ public class PieGraph extends View {
 
     public void onDraw(Canvas canvas) {
         super.onDraw(canvas);
+
         canvas.drawColor(Color.TRANSPARENT);
 		paint.reset();
 		paint.setAntiAlias(true);

+ 112 - 32
src/de/tudarmstadt/informatik/hostage/ui2/fragment/StatisticsFragment.java

@@ -9,8 +9,10 @@ import android.os.Bundle;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.AdapterView;
 import android.widget.LinearLayout;
 import android.widget.ListView;
+import android.widget.TextView;
 
 import com.echo.holographlibrary.Bar;
 import com.echo.holographlibrary.BarGraph;
@@ -139,14 +141,27 @@ public class StatisticsFragment extends Fragment {
 
         View rootView = inflater.inflate(this.getLayoutID(), container, false);
 
+        LinearLayout plotLayout = (LinearLayout) rootView.findViewById(R.id.plot_layout);
+        plotLayout.setWillNotDraw(false);
+
+        container.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.userTappedOnItem(i);
+            }
+        });
         this.rootView = rootView;
+        rootView.setWillNotDraw(false);
 
         this.configureRootView(rootView);
 
         return rootView;
     }
 
+
     private Context getBaseContext(){
         return this.getActivity().getBaseContext();
     }
@@ -156,27 +171,57 @@ public class StatisticsFragment extends Fragment {
     }
 
     public void configureRootView(View rootView){
+        LinearLayout plotLayout = (LinearLayout) rootView.findViewById(R.id.plot_layout);
+        plotLayout.setWillNotDraw(false);
+
+        plotLayout.removeAllViews();
+
         this.actualiseCurrentPlot();
     }
 
+    public void setTitle(String title){
+        TextView titleView = (TextView) this.rootView.findViewById(R.id.title_text_view);
+        if (title != null && titleView != null){
+            titleView.setText(title);
+        }
+    }
+
+    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();
+    }
+
     public void setChartType(ChartType type){
         boolean shouldChange = true;
         if (this.currentPlotView != null){
             if (type == ChartType.PIE_CHART){
                 shouldChange = ! (this.currentPlotView instanceof PieGraph);
+            } else {
+                this.pieGraph.setVisibility(View.INVISIBLE);
             }
             if (type == ChartType.LINE_CHART){
                 shouldChange = ! (this.currentPlotView instanceof LineGraph);
+            } else {
+                this.lineGraph.setVisibility(View.INVISIBLE);
             }
             if (type == ChartType.BAR_CHART){
                 shouldChange = ! (this.currentPlotView instanceof BarGraph);
+            } else {
+                this.barGraph.setVisibility(View.INVISIBLE);
             }
         }
         if (shouldChange){
-            LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
-            plotLayout.removeView(this.currentPlotView);
             this.currentPlotView = this.getPlotViewForType(type);
-            plotLayout.addView(this.currentPlotView);
+            this.currentPlotView.setVisibility(View.VISIBLE);
 
             this.actualiseCurrentPlot();
         }
@@ -204,10 +249,10 @@ public class StatisticsFragment extends Fragment {
     *
     * */
     public void onSliceClick(int index){
-
+        this.userTappedOnItem(index);
     }
     public void onBarClick(int index){
-
+        this.userTappedOnItem(index);
     }
     /*
     *
@@ -216,8 +261,9 @@ public class StatisticsFragment extends Fragment {
     * **/
     public PieGraph getPieGraphView(){
         if (this.pieGraph == null) {
-            this.pieGraph = new PieGraph(this.getActivity());
-            this.pieGraph.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
+            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) {
@@ -231,6 +277,8 @@ public class StatisticsFragment extends Fragment {
     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);
         }
         return this.lineGraph;
     }
@@ -238,6 +286,8 @@ public class StatisticsFragment extends Fragment {
     public BarGraph getBarGraphView(){
         if (this.barGraph == null) {
             this.barGraph = new BarGraph(this.getActivity());
+            LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
+            plotLayout.addView(this.barGraph);
             this.barGraph.setPopupImageID(R.drawable.popup_black);
             this.barGraph.setOnBarClickedListener(new BarGraph.OnBarClickedListener() {
                 @Override
@@ -264,7 +314,8 @@ public class StatisticsFragment extends Fragment {
             PieSlice slice = new PieSlice();
             slice.setColor(item.getColor());
             Double value2 = (Double) item.getValue2();
-            slice.setValue(value2.floatValue());
+            float v = value2.floatValue();
+            slice.setValue(v);
             slice.setTitle(item.getTitle());
             this.pieGraph.addSlice(slice);
         }
@@ -329,28 +380,35 @@ public class StatisticsFragment extends Fragment {
      public void actualiseCurrentPlot(){
         View plot = this.currentPlotView;
          if (plot == null){
-             if (this.pieGraph == null){
-                 this.currentPlotView = this.getPieGraphView();
-             }
              this.currentPlotView = this.getPieGraphView();
-             LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
-             plotLayout.addView(this.currentPlotView);
              plot = this.currentPlotView;
          }
+        if (plot.getVisibility() == View.INVISIBLE) plot.setVisibility(View.VISIBLE);
+
         if (plot instanceof PieGraph){
             PieGraph pie = (PieGraph) plot;
             this.setPieGraphData(pie);
+        } else {
+            if (this.pieGraph != null)
+                this.pieGraph.setVisibility(View.INVISIBLE);
         }
         if (plot instanceof BarGraph){
             BarGraph bar = (BarGraph) plot;
             this.setBarGraphData(bar);
+        } else {
+            if (this.barGraph != null)
+                this.barGraph.setVisibility(View.INVISIBLE);
         }
         if (plot instanceof LineGraph){
            LineGraph line = (LineGraph)plot;
            this.setLineGraphData(line);
+        }else {
+            if (this.lineGraph != null)
+                this.lineGraph.setVisibility(View.INVISIBLE);
         }
-
+        plot.setVisibility(View.VISIBLE);
          this.actualiseLegendList();
+         this.currentPlotView.invalidate();
      }
 
     public ArrayList<PlotComparisonItem> getPieData(){
@@ -427,7 +485,7 @@ public class StatisticsFragment extends Fragment {
         int index = 0;
         for (long date : recordMap.keySet()){
             ArrayList<Record> list = recordMap.get(date);
-            PlotComparisonItem item = new PlotComparisonItem(this.getDateAsDayString(date),this.getColor(index), (double) date, (double)list.size());
+            PlotComparisonItem item = new PlotComparisonItem(this.getDateAsDayString(date), this.getColor(index), (double) date, (double)list.size());
             plotItems.add(item);
             index++;
         }
@@ -538,6 +596,8 @@ public class StatisticsFragment extends Fragment {
 
                 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);
@@ -642,23 +702,6 @@ public class StatisticsFragment extends Fragment {
         return Color.argb(255,R,G,B);
     }
 
-    /*
-    *
-    * ACTUALISE PLOT VIEW
-    *
-     */
-
-    public void setPlotView(View view){
-        LinearLayout plotLayout = this.getPlotLayout();
-        if (this.currentPlotView != null && plotLayout != null){
-            plotLayout.removeAllViews();
-        }
-        if (view != null && plotLayout != null){
-            this.currentPlotView = view;
-            view.setLayoutParams(plotLayout.getLayoutParams());
-            plotLayout.addView(view);
-        }
-    }
 
     public LinearLayout getPlotLayout(){
         if (this.rootView != null){
@@ -744,4 +787,41 @@ public class StatisticsFragment extends Fragment {
             return "xx";
         }
     }
+
+
+    /**
+     * USERINTERACTION
+     */
+    private void userTappedOnItem(int index){
+        if (index < this.currentData.size()){
+            PlotComparisonItem item = this.currentData.get(index);
+            ArrayList<String> selectedData;
+            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){
+                // TODO set data for BSSID / ESSID
+            }
+            if (this.currentPlotView instanceof  LineGraph){
+                // TODO set data for BSSID / ESSID
+            }
+        }
+
+
+    }
+
+    private void pushRecordOverviewForFilter(LogFilter filter){
+
+    }
+
 }

+ 6 - 3
src/de/tudarmstadt/informatik/hostage/ui2/model/PlotComparisonItem.java

@@ -12,11 +12,11 @@ public class PlotComparisonItem{
 
     private String title;
 
-    private int color;
+    private Integer color = 0;
 
     private ArrayList<PlotComparisonItem> otherData;
 
-    public PlotComparisonItem(String title, int color , Double value1, Double value2){
+    public PlotComparisonItem(String title, Integer color , Double value1, Double value2){
         super();
         this.color = color;
         this.title = title;
@@ -39,7 +39,10 @@ public class PlotComparisonItem{
     public Double getValue2(){
         return this.value2;
     }
-    public int getColor(){
+    public void setColor(Integer color){
+        this.color = color;
+    }
+    public Integer getColor(){
         return this.color;
     }
 }