01: package org.garret.bench;
02:
03: import android.widget.*;
04: import android.os.Handler;
05:
06: import java.io.*;
07:
08: public class ProgressMonitor implements Runnable {
09: Test test;
10: ByteArrayOutputStream result;
11: long start;
12: TextView view;
13: Handler handler;
14:
15: ProgressMonitor(Test test, TextView view,
16: ByteArrayOutputStream result) {
17: this .test = test;
18: this .view = view;
19: this .result = result;
20: start = System.currentTimeMillis();
21: handler = new Handler();
22: }
23:
24: public void run() {
25: try {
26: synchronized (test) {
27: while (!test.completed) {
28: handler.post(new Runnable() {
29: public void run() {
30: view
31: .setText("Running test for "
32: + test.getName()
33: + "\nElapsed time: "
34: + (System
35: .currentTimeMillis() - start)
36: / 1000 + " sec");
37: view.invalidate();
38: }
39: });
40: test.wait(10000);
41: }
42: handler.post(new Runnable() {
43: public void run() {
44: view.setText(result.toString());
45: view.invalidate();
46: }
47: });
48: }
49: } catch (Exception x) {
50: System.out.println("Exception caught: " + x);
51: }
52: }
53: }
|