Kaynağa Gözat

added filter button without functionallity and fixed many issues for line and bar graph

Julien Clauter 10 yıl önce
ebeveyn
işleme
444ef34b2e

+ 11 - 24
res/layout/fragment_statistics.xml

@@ -23,7 +23,7 @@
                 android:textAppearance="?android:attr/textAppearanceMedium"
                 android:text="Title"
                 android:textAlignment="center"
-                android:id="@+id/title_textView" />
+                android:id="@+id/title_text_view" />
         </LinearLayout>
 
 
@@ -44,29 +44,6 @@
             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
@@ -90,6 +67,16 @@
         android:layout_alignParentLeft="true"
         android:layout_alignParentStart="true">
 
+        <ImageButton
+            style="@android:style/Widget.DeviceDefault.ActionButton.Overflow"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:id="@+id/FilterButton"
+            android:src="@drawable/ic_filter"
+            android:layout_alignParentTop="true"
+            android:visibility="invisible"
+            />
+
         <ImageButton
             style="@android:style/Widget.DeviceDefault.ActionButton.Overflow"
             android:layout_width="wrap_content"

+ 1 - 0
res/layout/plot_list_item.xml

@@ -39,6 +39,7 @@
         android:text="value"
         android:id="@+id/value_text_view"
         android:textAlignment="textEnd"
+        android:gravity="right"
         android:layout_weight="4"
         android:textColor="#000000" />
     </LinearLayout>

+ 2 - 2
src/com/echo/holographlibrary/LineGraph.java

@@ -430,7 +430,7 @@ public class LineGraph extends View {
 						}
 						int innerRadius = outerRadius / 2;
 
-						paint.setColor(Color.parseColor(p.getColor()));
+						paint.setColor(p.getColor());
 						canvas.drawCircle(xPixels, yPixels, outerRadius, paint);
 						paint.setColor(Color.WHITE);
 						canvas.drawCircle(xPixels, yPixels, innerRadius, paint);
@@ -441,7 +441,7 @@ public class LineGraph extends View {
 						p.setRegion(new Region((int)(xPixels-30), (int)(yPixels-30), (int)(xPixels+30), (int)(yPixels+30)));
 						
 						if (indexSelected == pointCount && listener != null){
-                            paint.setColor(Color.parseColor(p.getColor()));
+                            paint.setColor(p.getColor());
 							paint.setAlpha(100);
 							canvas.drawPath(p.getPath(), paint);
 							paint.setAlpha(255);

+ 5 - 4
src/com/echo/holographlibrary/LinePoint.java

@@ -23,6 +23,7 @@
 
 package com.echo.holographlibrary;
 
+import android.graphics.Color;
 import android.graphics.Path;
 import android.graphics.Region;
 
@@ -31,7 +32,7 @@ public class LinePoint {
 	private float y = 0;
 	private Path path;
 	private Region region;
-    private String color;
+    private Integer color;
 
     public LinePoint(){
     }
@@ -82,11 +83,11 @@ public class LinePoint {
 		return "x= " + x + ", y= " + y;
 	}
 
-    public String getColor() {
-        return color != null ? color : "#33B5E5";
+    public Integer getColor() {
+        return color != null ? color : Color.parseColor("#33B5E5");
     }
 
-    public void setColor(String color) {
+    public void setColor(Integer color) {
         this.color = color;
     }
 }

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

@@ -80,7 +80,7 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
     static final String OTHER_CHART_TITLE = "Other";
 
     // MINIMAL 2
-    static int MAX_NUMBER_OF_CHART_OBJECTS = 5;
+    static int MAX_NUMBER_OF_CHART_OBJECTS = 6;
 
     private boolean wasBelowTimePicker;
 
@@ -102,6 +102,8 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
 
     private ListView legendListView;
 
+
+
     private String selectedCompareData = COMPARE_TITLE_AttacksPerProtocol;
 
     public enum ChartType {
@@ -137,6 +139,10 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         setHasOptionsMenu(true);
     }
 
+    private ImageButton getFilterButton(){
+        return (ImageButton) this.rootView.findViewById(R.id.FilterButton);
+    }
+
     public int getLayoutID(){
         return R.layout.fragment_statistics;
     }
@@ -198,18 +204,28 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
 
         this.actualiseCurrentPlot();
 
-        ImageButton filterButton = (ImageButton) rootView.findViewById(R.id.plot_data_button);
-        filterButton.setOnClickListener(new View.OnClickListener() {
+        ImageButton visualButton = (ImageButton) rootView.findViewById(R.id.plot_data_button);
+        visualButton.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 StatisticsFragment.this.openPopupMenuOnView(v);
             }
         });
+
+        this.setTitle(this.selectedCompareData);
+
+        ImageButton filterButton = this.getFilterButton();
+        filterButton.setOnClickListener(new View.OnClickListener() {
+            public void onClick(View v) {
+                StatisticsFragment.this.openFilterMenuOnView(v);
+            }
+        });
     }
 
     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();
         }
     }
 
@@ -245,10 +261,14 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
             if (type == ChartType.BAR_CHART){
                 shouldChange = ! (this.currentPlotView instanceof BarGraph);
                 // SHOW FILTER BUTTON
+                ImageButton filterButton = this.getFilterButton();
+                if (filterButton != null) filterButton.setVisibility(View.VISIBLE);
             } else {
                 if (this.barGraph != null)
                     this.barGraph.setVisibility(View.INVISIBLE);
                 // SET FILTER BUTTON HIDDEN
+                ImageButton filterButton = this.getFilterButton();
+                if (filterButton != null) filterButton.setVisibility(View.INVISIBLE);
             }
         }
         if (shouldChange){
@@ -352,7 +372,7 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         ArrayList<String> titles =dialog.getSelectedItemTitles();
         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;
@@ -369,6 +389,7 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
                 this.setChartType(chartType);
             }
         }
+
     }
 
     public void onDialogNegativeClick(ChecklistDialog dialog) {
@@ -404,6 +425,16 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         return selected;
     }
 
+    /*
+    *
+    *  FILTER BUTTON
+    *
+    * */
+    private void openFilterMenuOnView(View anchor){
+
+    }
+
+
     /**
     *
     * PLOT TOUCH HANDLING
@@ -448,7 +479,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.getHeight()));
+            this.barGraph.setLayoutParams(new ViewGroup.LayoutParams(plotLayout.getWidth() - plotLayout.getPaddingLeft() - plotLayout.getPaddingRight(), plotLayout.getHeight() -  - plotLayout.getPaddingTop() - plotLayout.getPaddingBottom()));
             plotLayout.addView(this.barGraph);
             this.barGraph.setPopupImageID(R.drawable.popup_black);
             this.barGraph.setOnBarClickedListener(new BarGraph.OnBarClickedListener() {
@@ -500,6 +531,8 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
             p.setX(index);
             Double value2 = (Double) item.getValue2();
             p.setY(value2.floatValue());
+            p.setColor(item.getColor());
+            l.addPoint(p);
             index++;
         }
         this.lineGraph.addLine(l);
@@ -663,7 +696,8 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         HashMap<Long, ArrayList<Record> > recordMap = new HashMap<Long, ArrayList<Record> >();
 
         for (Record record : this.getFetchedRecords()){
-            long date = this.getDateFromMilliseconds(record.getTimestamp());
+            long timestamp = record.getTimestamp();
+            long date = this.getDateFromMilliseconds(timestamp);
             ArrayList<Record> list = recordMap.get(date);
             if (list == null){
                 list = new ArrayList<Record>();
@@ -675,7 +709,8 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         for (long date : recordMap.keySet()){
             ArrayList<Record> list = recordMap.get(date);
             if (list.size() == 0) continue;
-            PlotComparisonItem item = new PlotComparisonItem(this.getDateAsDayString(date), this.getColor(index), (double) date, (double)list.size());
+            // TODO SET CORRECT COLOR
+            PlotComparisonItem item = new PlotComparisonItem(this.getDateAsDayString(date), this.getColor(0), (double) date, (double)list.size());
             plotItems.add(item);
             index++;
         }
@@ -692,11 +727,12 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         HashMap<Long, ArrayList<Record> > recordMap = new HashMap<Long, ArrayList<Record> >();
 
         for (Record record : this.getFetchedRecords()){
-            long date = this.getDayHourFromDate(record.getTimestamp());
-            ArrayList<Record> list = recordMap.get(date);
+            long timestamp = record.getTimestamp();
+            long time = this.getDayHourFromDate(timestamp);
+            ArrayList<Record> list = recordMap.get(time);
             if (list == null){
                 list = new ArrayList<Record>();
-                recordMap.put(date, list);
+                recordMap.put(time, list);
             }
             list.add(record);
         }
@@ -704,7 +740,8 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         for (long time : recordMap.keySet()){
             ArrayList<Record> list = recordMap.get(time);
             if (list.size() == 0) continue;
-            PlotComparisonItem item = new PlotComparisonItem(this.getDateAsTimeString(time), this.getColor(index) , (double)time, (double) list.size());
+            // TODO SET CURRECT COLOR
+            PlotComparisonItem item = new PlotComparisonItem(this.getDateAsTimeString(time), this.getColor(0) , (double)time, (double) list.size());
             plotItems.add(item);
             index++;
         }
@@ -947,15 +984,21 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
     *
     */
     public long getDayHourFromDate(long timeInMillis){
+
         Calendar calendar = Calendar.getInstance();
 
         calendar.setTimeInMillis (timeInMillis);
-        int hour    = calendar.get(Calendar.HOUR);
+        int hour    = calendar.get(Calendar.HOUR_OF_DAY);
         int min     = calendar.get(Calendar.MINUTE);
 
-        return (hour*60*60)*1000;
+        return hour;
+
     }
     public long getDateFromMilliseconds(long timeInMillis){
+        long millisInDay = 60 * 60 * 24 * 1000;
+        return (timeInMillis / millisInDay) * millisInDay;
+
+        /*
         Calendar calendar = Calendar.getInstance();
         calendar.setTimeInMillis (timeInMillis);
 
@@ -965,17 +1008,21 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
 
         calendar.set(year, month, day, 0,0);
         return calendar.getTimeInMillis();
+        */
     }
 
     static final DateFormat timeFormat = new SimpleDateFormat("H:mm");
     @SuppressLint("SimpleDateFormat")
     private String getDateAsTimeString(long timeStamp) {
+        return "" + timeStamp + ":00";
+        /*
         try {
             Date netDate = (new Date(timeStamp));
             return timeFormat.format(netDate);
         } catch (Exception ex) {
             return "xx";
         }
+        */
     }
 
     static final DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");