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.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
|
|
@ -28,10 +29,13 @@ public class HistoryActivity extends ListActivity {
|
|||
|
||||
private static final int GRAPH_LENGTH = 60;
|
||||
|
||||
private Handler handler;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
handler = new Handler();
|
||||
setContentView(R.layout.activity_history);
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
|
|
@ -76,25 +80,41 @@ public class HistoryActivity extends ListActivity {
|
|||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
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);
|
||||
fileNameView.setText(csvFile.getName());
|
||||
|
||||
|
||||
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);}
|
||||
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++){
|
||||
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");
|
||||
LineGraphView graphView = new LineGraphView(getContext(), "HistoryView");
|
||||
graphView.setLayoutParams(new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.MATCH_PARENT));
|
||||
|
|
@ -106,10 +126,16 @@ public class HistoryActivity extends ListActivity {
|
|||
graphView.setShowVerticalLabels(false);
|
||||
graphView.setShowHorizontalLabels(false);
|
||||
graphView.setDisableTouch(true);
|
||||
graphView.setDrawDataPoints(true);
|
||||
LinearLayout graphLayout = (LinearLayout)view.findViewById(R.id.graph);
|
||||
//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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,23 @@
|
|||
android:orientation="horizontal">
|
||||
</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
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue