Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

97
LINES

< > BotCompany Repo | #1000412 // Porting JavaX 18 to Android

JavaX source code (Android) [tags: use-pretranspiled] - run with: the app

Libraryless. Click here for Pure Java version (1303L/11K/34K).

!636

import android.widget.*;
import android.view.*;
import android.content.Context;
import android.app.Activity;
import java.util.Timer;
import java.util.TimerTask;
import java.io.*;

public class main {
  static class Lg {
    Activity context;
    ScrollView sv;
    TextView tv;
    StringBuilder buf = new StringBuilder();
    
    Lg(Activity context) {
      this.context = context;
      sv = new ScrollView(context);
      tv = new TextView(context);
      tv.setText(buf.toString());
      sv.addView(tv);
    }
    
    View getView() {
      return sv;
    }
    
    void print(final String s) {
      context.runOnUiThread(new Runnable() {
        public void run() {
          buf.append(s);
          tv.setText(buf.toString());
        }
      });
    }
    
    void println(String s) {
      print(s + "\n");
    }
  }
  
  static Lg lg;
  
  public static View main(final Activity context) {
    lg = new Lg(context);
    
    OutputStream outputStream = new OutputStream() {
      public void write(int b) {
        try {
          lg.print(new String(new byte[] {(byte) b}, "UTF-8")); // This is crap
        } catch (UnsupportedEncodingException e) {}
      }
      
      @Override
      public void write(byte[] b, int off, int len) {
        try {
          lg.print(new String(b, off, len, "UTF-8")); // This is crap
        } catch (UnsupportedEncodingException e) {}
      }
    };
    
    PrintStream ps = new PrintStream(outputStream, true);
    System.setOut(ps);
    System.setErr(ps);
    
    new Thread() {
      public void run() {
        try {
          String file = "input.txt";
          // Fails - "read-only file system, /input.txt"
          // FileOutputStream out = new FileOutputStream(file);
          FileOutputStream out = context.openFileOutput(file, Context.MODE_PRIVATE);

          PrintStream ps = new PrintStream(out);
          ps.println("hello");
          ps.close();
          out.close();
          System.out.println("Wrote to " + file);
          
          //FileInputStream in = new FileInputStream(file);
          FileInputStream in = context.openFileInput(file);
          int b = in.read();
          in.close();
          System.out.println("Read from " + file + ": " + (char) b);
        } catch (Throwable e) {
          e.printStackTrace();
        }
      }
    }.start();
    
    return lg.getView();
  }
}

!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: 551 / 520
Referenced in: [show references]