Libraryless. Click here for Pure Java version (1303L/11K/34K).
1 | !636 |
2 | |
3 | import android.widget.*; |
4 | import android.view.*; |
5 | import android.content.Context; |
6 | import android.app.Activity; |
7 | import java.util.Timer; |
8 | import java.util.TimerTask; |
9 | import java.io.*; |
10 | |
11 | public class main {
|
12 | static class Lg {
|
13 | Activity context; |
14 | ScrollView sv; |
15 | TextView tv; |
16 | StringBuilder buf = new StringBuilder(); |
17 | |
18 | Lg(Activity context) {
|
19 | this.context = context; |
20 | sv = new ScrollView(context); |
21 | tv = new TextView(context); |
22 | tv.setText(buf.toString()); |
23 | sv.addView(tv); |
24 | } |
25 | |
26 | View getView() {
|
27 | return sv; |
28 | } |
29 | |
30 | void print(final String s) {
|
31 | context.runOnUiThread(new Runnable() {
|
32 | public void run() {
|
33 | buf.append(s); |
34 | tv.setText(buf.toString()); |
35 | } |
36 | }); |
37 | } |
38 | |
39 | void println(String s) {
|
40 | print(s + "\n"); |
41 | } |
42 | } |
43 | |
44 | static Lg lg; |
45 | |
46 | public static View main(final Activity context) {
|
47 | lg = new Lg(context); |
48 | |
49 | OutputStream outputStream = new OutputStream() {
|
50 | public void write(int b) {
|
51 | try {
|
52 | lg.print(new String(new byte[] {(byte) b}, "UTF-8")); // This is crap
|
53 | } catch (UnsupportedEncodingException e) {}
|
54 | } |
55 | |
56 | @Override |
57 | public void write(byte[] b, int off, int len) {
|
58 | try {
|
59 | lg.print(new String(b, off, len, "UTF-8")); // This is crap |
60 | } catch (UnsupportedEncodingException e) {}
|
61 | } |
62 | }; |
63 | |
64 | PrintStream ps = new PrintStream(outputStream, true); |
65 | System.setOut(ps); |
66 | System.setErr(ps); |
67 | |
68 | new Thread() {
|
69 | public void run() {
|
70 | try {
|
71 | String file = "input.txt"; |
72 | // Fails - "read-only file system, /input.txt" |
73 | // FileOutputStream out = new FileOutputStream(file); |
74 | FileOutputStream out = context.openFileOutput(file, Context.MODE_PRIVATE); |
75 | |
76 | PrintStream ps = new PrintStream(out); |
77 | ps.println("hello");
|
78 | ps.close(); |
79 | out.close(); |
80 | System.out.println("Wrote to " + file);
|
81 | |
82 | //FileInputStream in = new FileInputStream(file); |
83 | FileInputStream in = context.openFileInput(file); |
84 | int b = in.read(); |
85 | in.close(); |
86 | System.out.println("Read from " + file + ": " + (char) b);
|
87 | } catch (Throwable e) {
|
88 | e.printStackTrace(); |
89 | } |
90 | } |
91 | }.start(); |
92 | |
93 | return lg.getView(); |
94 | } |
95 | } |
96 | |
97 | !include #2000496 // class _x18 |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1000412 |
| Snippet name: | Porting JavaX 18 to Android |
| Eternal ID of this version: | #1000412/1 |
| Text MD5: | 1f9a0569a1f49798ea2947abb0bbeab2 |
| Transpilation MD5: | db5d1feaa41f7da89a16c1ee4155460b |
| Author: | stefan |
| Category: | javax android |
| Type: | JavaX source code (Android) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-08-03 15:10:38 |
| Source code size: | 2515 bytes / 97 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 850 / 883 |
| Referenced in: | [show references] |