1 package uk.org.distorted.tripe;
3 import java.io.{File, FileOutputStream, InputStream, IOException};
5 import android.app.{Activity, Application};
6 import android.content.Context; import Context.MODE_WORLD_READABLE;
7 import android.content.res.AssetManager;
8 import android.os.Build; import Build.{CPU_ABI, CPU_ABI2};
9 import android.os.Bundle;
10 import android.util.Log;
11 import android.view.View;
13 import scala.util.control.Breaks;
16 private final val TAG = "Setup";
17 private val BREAK = new Breaks;
18 import BREAK.{breakable, break};
20 def setup(ctx: Context) {
21 val bindir = ctx.getDir("bin", MODE_WORLD_READABLE);
22 val assets = ctx.getAssets;
25 try { classOf[Build].getField("SUPPORTED_ABIS").get(null).asInstanceOf[Array[String]] }
27 case _: NoSuchFieldException => Array(CPU_ABI, CPU_ABI2) flatMap {
28 case null | "" => None
33 Log.d(TAG, s"abis = ${abis.mkString(", ")}");
34 Log.d(TAG, s"assets: ${assets.list("bin").mkString(", ")}");
37 val binsrc = s"bin/$abi";
38 for (base <- assets.list(binsrc)) {
39 val prog = new File(bindir, base);
40 if (!prog.exists) try {
41 Log.d(TAG, s"creating $prog...");
42 val in = assets.open(s"$binsrc/$base");
43 Log.d(TAG, "opened source...");
44 val out = new FileOutputStream(prog);
45 Log.d(TAG, "opened target...");
46 val buf = new Array[Byte](4096);
50 Log.d(TAG, s"read $n bytes...");
57 Log.d(TAG, "set permissions...");
58 if (!prog.setReadable(true, false) ||
59 !prog.setExecutable(true, false))
60 throw new IOException("failed to set program permissions");
62 case exc: IOException =>
63 Log.wtf(TAG, "fuck, failed to create prog", exc);
72 private final val TAG = "ToyActivity";
73 System.loadLibrary("jni");
74 @native protected def foo();
77 class ToyActivity extends Activity {
80 override protected def onCreate(joy: Bundle) {
83 setContentView(R.layout.toy);
84 Log.d(TAG, s"created ${this}");
86 def clickOk(v: View) {
87 Log.d(TAG, "OK, OK. (Scala was here.)");
90 val bindir = getDir("bin", MODE_WORLD_READABLE);
91 Runtime.getRuntime.exec(Array(new File(bindir, "prog").getPath,
92 "testing", "1", "2", "3"));