Added some robust handling to History view
This commit is contained in:
parent
1902b9374b
commit
b18e5cc649
2 changed files with 72 additions and 29 deletions
|
|
@ -6,6 +6,7 @@ import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
|
|
@ -28,10 +29,13 @@ public class HistoryActivity extends ListActivity {
|
||||||
|
|
||||||
private static final int GRAPH_LENGTH = 60;
|
private static final int GRAPH_LENGTH = 60;
|
||||||
|
|
||||||
|
private Handler handler;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
handler = new Handler();
|
||||||
setContentView(R.layout.activity_history);
|
setContentView(R.layout.activity_history);
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
|
|
@ -76,40 +80,62 @@ public class HistoryActivity extends ListActivity {
|
||||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
view = inflater.inflate(VIEW_RESOURCE, parent, false);
|
view = inflater.inflate(VIEW_RESOURCE, parent, false);
|
||||||
}
|
}
|
||||||
File csvFile = super.getItem(position);
|
final File csvFile = super.getItem(position);
|
||||||
|
|
||||||
TextView fileNameView = (TextView)view.findViewById(R.id.file_name);
|
TextView fileNameView = (TextView)view.findViewById(R.id.file_name);
|
||||||
fileNameView.setText(csvFile.getName());
|
fileNameView.setText(csvFile.getName());
|
||||||
|
|
||||||
// Read CSV File
|
|
||||||
CSVReader reader = new CSVReader(csvFile);
|
|
||||||
reader.maxNoOfEntries(GRAPH_LENGTH);
|
|
||||||
try{reader.read();}catch (IOException e){log.trace(null, e);}
|
|
||||||
GraphView.GraphViewData[] downThrp = new GraphView.GraphViewData[reader.getDownThroughput().size()];
|
|
||||||
GraphView.GraphViewData[] upThrp = new GraphView.GraphViewData[reader.getUpThroughput().size()];
|
|
||||||
for(int i=0; i<reader.getDownThroughput().size(); i++){
|
|
||||||
downThrp[i] = new GraphView.GraphViewData(
|
|
||||||
i, reader.getDownThroughput().get(i));
|
|
||||||
upThrp[i] = new GraphView.GraphViewData(
|
|
||||||
i, reader.getUpThroughput().get(i));
|
|
||||||
}
|
|
||||||
// Setup Graph
|
|
||||||
LineGraphView graphView = new LineGraphView(this.getContext(), "HistoryView");
|
|
||||||
graphView.setLayoutParams(new LinearLayout.LayoutParams(
|
|
||||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
|
||||||
LinearLayout.LayoutParams.MATCH_PARENT));
|
|
||||||
graphView.getGraphViewStyle().setGridStyle(GraphViewStyle.GridStyle.BOTH);
|
|
||||||
graphView.addSeries(new GraphViewSeries("Download Throughput",
|
|
||||||
new GraphViewSeries.GraphViewSeriesStyle(Color.GREEN, 3), downThrp));
|
|
||||||
graphView.addSeries(new GraphViewSeries("Upload Throughput",
|
|
||||||
new GraphViewSeries.GraphViewSeriesStyle(Color.RED, 3), upThrp));
|
|
||||||
graphView.setShowVerticalLabels(false);
|
|
||||||
graphView.setShowHorizontalLabels(false);
|
|
||||||
graphView.setDisableTouch(true);
|
|
||||||
graphView.setDrawDataPoints(true);
|
|
||||||
LinearLayout graphLayout = (LinearLayout)view.findViewById(R.id.graph);
|
|
||||||
graphLayout.addView(graphView);
|
|
||||||
|
|
||||||
|
final LinearLayout graphLayout = (LinearLayout)view.findViewById(R.id.graph);
|
||||||
|
final ProgressBar active = (ProgressBar)view.findViewById(R.id.active);
|
||||||
|
final ImageView warning = (ImageView)view.findViewById(R.id.warning);
|
||||||
|
// Prepare gui for CSV file parsing
|
||||||
|
graphLayout.removeAllViews();
|
||||||
|
active.setVisibility(View.VISIBLE);
|
||||||
|
warning.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
handler.postDelayed(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
// Read CSV File
|
||||||
|
CSVReader reader = new CSVReader(csvFile);
|
||||||
|
reader.maxNoOfEntries(GRAPH_LENGTH);
|
||||||
|
try {
|
||||||
|
reader.read();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.trace(null, e);
|
||||||
|
}
|
||||||
|
GraphView.GraphViewData[] downThrp = new GraphView.GraphViewData[reader.getDownThroughput().size()];
|
||||||
|
GraphView.GraphViewData[] upThrp = new GraphView.GraphViewData[reader.getUpThroughput().size()];
|
||||||
|
for (int i = 0; i < reader.getDownThroughput().size(); i++) {
|
||||||
|
downThrp[i] = new GraphView.GraphViewData(
|
||||||
|
i, reader.getDownThroughput().get(i));
|
||||||
|
upThrp[i] = new GraphView.GraphViewData(
|
||||||
|
i, reader.getUpThroughput().get(i));
|
||||||
|
}
|
||||||
|
// Setup Graph
|
||||||
|
LineGraphView graphView = new LineGraphView(getContext(), "HistoryView");
|
||||||
|
graphView.setLayoutParams(new LinearLayout.LayoutParams(
|
||||||
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||||
|
LinearLayout.LayoutParams.MATCH_PARENT));
|
||||||
|
graphView.getGraphViewStyle().setGridStyle(GraphViewStyle.GridStyle.BOTH);
|
||||||
|
graphView.addSeries(new GraphViewSeries("Download Throughput",
|
||||||
|
new GraphViewSeries.GraphViewSeriesStyle(Color.GREEN, 3), downThrp));
|
||||||
|
graphView.addSeries(new GraphViewSeries("Upload Throughput",
|
||||||
|
new GraphViewSeries.GraphViewSeriesStyle(Color.RED, 3), upThrp));
|
||||||
|
graphView.setShowVerticalLabels(false);
|
||||||
|
graphView.setShowHorizontalLabels(false);
|
||||||
|
graphView.setDisableTouch(true);
|
||||||
|
//graphView.setDrawDataPoints(true);
|
||||||
|
graphLayout.addView(graphView);
|
||||||
|
} catch (RuntimeException re){
|
||||||
|
warning.setVisibility(View.VISIBLE);
|
||||||
|
log.trace(null, re);
|
||||||
|
} finally {
|
||||||
|
active.setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,23 @@
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/warning"
|
||||||
|
android:src="@drawable/warning"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:visibility="invisible"/>
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/active"
|
||||||
|
style="@android:style/Widget.DeviceDefault.Light.ProgressBar"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:visibility="invisible"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue