1 | import android.widget.*;
|
2 | import android.view.*;
|
3 | import android.content.Context;
|
4 | import android.app.Activity;
|
5 | import java.util.Timer;
|
6 | import java.util.TimerTask;
|
7 | import java.io.*;
|
8 |
|
9 | public class main {
|
10 | static class Lg {
|
11 | Activity context;
|
12 | ScrollView sv;
|
13 | TextView tv;
|
14 | StringBuilder buf = new StringBuilder();
|
15 |
|
16 | Lg(Activity context) {
|
17 | this.context = context;
|
18 | sv = new ScrollView(context);
|
19 | tv = new TextView(context);
|
20 | tv.setText(buf.toString());
|
21 | sv.addView(tv);
|
22 | }
|
23 |
|
24 | View getView() {
|
25 | return sv;
|
26 | }
|
27 |
|
28 | void print(final String s) {
|
29 | context.runOnUiThread(new Runnable() {
|
30 | public void run() {
|
31 | buf.append(s);
|
32 | tv.setText(buf.toString());
|
33 | }
|
34 | });
|
35 | }
|
36 |
|
37 | void println(String s) {
|
38 | print(s + "\n");
|
39 | }
|
40 | }
|
41 |
|
42 | static Lg lg;
|
43 |
|
44 | public static View main(final Activity context) {
|
45 | lg = new Lg(context);
|
46 |
|
47 | OutputStream outputStream = new OutputStream() {
|
48 | public void write(int b) {
|
49 | try {
|
50 | lg.print(new String(new byte[] {(byte) b}, "UTF-8")); // This is crap
|
51 | } catch (UnsupportedEncodingException e) {}
|
52 | }
|
53 |
|
54 | @Override
|
55 | public void write(byte[] b, int off, int len) {
|
56 | try {
|
57 | lg.print(new String(b, off, len, "UTF-8")); // This is crap
|
58 | } catch (UnsupportedEncodingException e) {}
|
59 | }
|
60 | };
|
61 |
|
62 | PrintStream ps = new PrintStream(outputStream, true);
|
63 | System.setOut(ps);
|
64 | System.setErr(ps);
|
65 |
|
66 | Timer myTimer = new Timer();
|
67 | myTimer.schedule(new TimerTask() {
|
68 | public void run() {
|
69 | System.out.println("More text");
|
70 | System.err.println("Also on System.err!");
|
71 | }
|
72 | }, 0, 1000);
|
73 |
|
74 | return lg.getView();
|
75 | }
|
76 | }
|