|
@@ -1,6 +1,7 @@
|
|
|
package de.tudarmstadt.informatik.hostage.ui2.fragment;
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
+import android.app.Activity;
|
|
|
import android.app.Fragment;
|
|
|
import android.app.FragmentManager;
|
|
|
import android.content.Context;
|
|
@@ -15,6 +16,7 @@ import android.widget.AdapterView;
|
|
|
import android.widget.ImageButton;
|
|
|
import android.widget.LinearLayout;
|
|
|
import android.widget.ListView;
|
|
|
+import android.widget.ProgressBar;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
import com.echo.holographlibrary.Bar;
|
|
@@ -35,8 +37,8 @@ import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
|
-import de.tudarmstadt.informatik.hostage.logging.Record;
|
|
|
import de.tudarmstadt.informatik.hostage.deprecated.UglyDbHelper;
|
|
|
+import de.tudarmstadt.informatik.hostage.logging.Record;
|
|
|
import de.tudarmstadt.informatik.hostage.ui.LogFilter;
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.adapter.StatisticListAdapter;
|
|
@@ -114,6 +116,8 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
|
|
|
private View rootView;
|
|
|
private View currentPlotView;
|
|
|
|
|
|
+ private Thread loader;
|
|
|
+ private ProgressBar spinner;
|
|
|
|
|
|
private ArrayList<Integer> colorList;
|
|
|
private ArrayList<PlotComparisonItem> currentData;
|
|
@@ -224,6 +228,9 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
|
|
|
|
|
|
plotLayout.setWillNotDraw(false);
|
|
|
|
|
|
+ this.spinner = (ProgressBar) rootView.findViewById(R.id.progressBar1);
|
|
|
+ this.spinner.setVisibility(View.GONE);
|
|
|
+
|
|
|
this.legendListView = (ListView) rootView.findViewById(R.id.legend_list_view);
|
|
|
this.legendListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
@Override
|
|
@@ -954,7 +961,17 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
|
|
|
|
|
|
/*Actualises the current plot.*/
|
|
|
public void actualiseCurrentPlot(){
|
|
|
+ this.spinner.setVisibility(View.VISIBLE);
|
|
|
+
|
|
|
LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
|
|
|
+
|
|
|
+ if (this.barGraph != null)
|
|
|
+ this.barGraph.setVisibility(View.GONE);
|
|
|
+ if (this.lineGraph != null)
|
|
|
+ this.lineGraph.setVisibility(View.GONE);
|
|
|
+ if (this.pieGraph != null)
|
|
|
+ this.pieGraph.setVisibility(View.GONE);
|
|
|
+
|
|
|
View plot = this.currentPlotView;
|
|
|
if (plot == null){
|
|
|
this.currentPlotView = this.getPieGraphView();
|
|
@@ -967,54 +984,97 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
|
|
|
plotLayout.addView(plot);
|
|
|
}
|
|
|
|
|
|
- if (plot.getVisibility() == View.GONE) plot.setVisibility(View.VISIBLE);
|
|
|
+ this.currentPlotView = plot;
|
|
|
|
|
|
- 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.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.GONE);
|
|
|
- if (this.barGraph.getParent() != null){
|
|
|
- plotLayout.removeView(this.barGraph);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (plot instanceof LineGraph){
|
|
|
- LineGraph line = (LineGraph)plot;
|
|
|
- this.setLineGraphData(line);
|
|
|
- }else {
|
|
|
- if (this.lineGraph != null){
|
|
|
- this.lineGraph.setVisibility(View.GONE);
|
|
|
- if (this.lineGraph.getParent() != null){
|
|
|
- plotLayout.removeView(this.lineGraph);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- plot.setVisibility(View.VISIBLE);
|
|
|
- if (plot.getParent() == null){
|
|
|
- plotLayout.addView(plot);
|
|
|
- }
|
|
|
- this.actualiseLegendList();
|
|
|
- this.currentPlotView.bringToFront();
|
|
|
- this.currentPlotView.invalidate();
|
|
|
+ final LinearLayout thePlotlayout = plotLayout;
|
|
|
+
|
|
|
+ if (this.loader != null && this.loader.isAlive()) this.loader.interrupt();
|
|
|
+
|
|
|
+ this.loader = null;
|
|
|
+
|
|
|
+ this.loader = new Thread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ this.loadDataInBackground();
|
|
|
+ this.actualiseUI();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void loadDataInBackground(){
|
|
|
+ View plot = StatisticsFragment.this.currentPlotView;
|
|
|
+ if (plot instanceof PieGraph){
|
|
|
+ PieGraph pie = (PieGraph) plot;
|
|
|
+ StatisticsFragment.this.setPieGraphData(pie);
|
|
|
+ }
|
|
|
+ if (plot instanceof BarGraph){
|
|
|
+ BarGraph bar = (BarGraph) plot;
|
|
|
+ StatisticsFragment.this.setBarGraphData(bar);
|
|
|
+ }
|
|
|
+ if (plot instanceof LineGraph){
|
|
|
+ LineGraph line = (LineGraph)plot;
|
|
|
+ StatisticsFragment.this.setLineGraphData(line);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void actualiseUI(){
|
|
|
+
|
|
|
+ Activity actv = StatisticsFragment.this.getActivity();
|
|
|
+
|
|
|
+ if (actv != null){
|
|
|
+ actv.runOnUiThread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ // SET VISIBILITY
|
|
|
+ View plot = StatisticsFragment.this.currentPlotView;
|
|
|
+
|
|
|
+ if (plot instanceof PieGraph){
|
|
|
+ // HIDE FILTER BUTTON
|
|
|
+ ImageButton filterButton = StatisticsFragment.this.getFilterButton();
|
|
|
+ if (filterButton != null) filterButton.setVisibility(View.GONE);
|
|
|
+ } else {
|
|
|
+ if (StatisticsFragment.this.pieGraph != null){
|
|
|
+ StatisticsFragment.this.pieGraph.setVisibility(View.GONE);
|
|
|
+ if (StatisticsFragment.this.pieGraph.getParent() != null){
|
|
|
+ thePlotlayout.removeView(StatisticsFragment.this.pieGraph);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // SHOW FILTER BUTTON
|
|
|
+ ImageButton filterButton = StatisticsFragment.this.getFilterButton();
|
|
|
+ if (filterButton != null) filterButton.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+ if (! (plot instanceof BarGraph)){
|
|
|
+ if (StatisticsFragment.this.barGraph != null){
|
|
|
+ StatisticsFragment.this.barGraph.setVisibility(View.GONE);
|
|
|
+ if (StatisticsFragment.this.barGraph.getParent() != null){
|
|
|
+ thePlotlayout.removeView(StatisticsFragment.this.barGraph);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!(plot instanceof LineGraph)){
|
|
|
+ if (StatisticsFragment.this.lineGraph != null){
|
|
|
+ StatisticsFragment.this.lineGraph.setVisibility(View.GONE);
|
|
|
+ if (StatisticsFragment.this.lineGraph.getParent() != null){
|
|
|
+ thePlotlayout.removeView(StatisticsFragment.this.lineGraph);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ plot.setVisibility(View.VISIBLE);
|
|
|
+
|
|
|
+ if (plot.getParent() == null){
|
|
|
+ thePlotlayout.addView(plot);
|
|
|
+ }
|
|
|
+ StatisticsFragment.this.actualiseLegendList();
|
|
|
+ StatisticsFragment.this.currentPlotView.bringToFront();
|
|
|
+ StatisticsFragment.this.currentPlotView.invalidate();
|
|
|
+
|
|
|
+ StatisticsFragment.this.spinner.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ this.loader.start();
|
|
|
}
|
|
|
|
|
|
public ArrayList<PlotComparisonItem> getPieData(){
|