| OLD | NEW |
| 1 package com.google.dartndk; | 1 package com.google.dartndk; |
| 2 | 2 |
| 3 import java.io.File; | 3 import java.io.File; |
| 4 import java.io.FileOutputStream; | 4 import java.io.FileOutputStream; |
| 5 import java.io.InputStream; | 5 import java.io.InputStream; |
| 6 import java.io.IOException; | 6 import java.io.IOException; |
| 7 import java.io.OutputStream; | 7 import java.io.OutputStream; |
| 8 | 8 |
| 9 import android.app.NativeActivity; | 9 import android.app.NativeActivity; |
| 10 import android.content.res.AssetManager; | 10 import android.content.res.AssetManager; |
| 11 import android.os.Bundle; | 11 import android.os.Bundle; |
| 12 import android.util.Log; | 12 import android.util.Log; |
| 13 | 13 |
| 14 public class DummyActivity extends NativeActivity { | 14 public class DummyActivity extends NativeActivity { |
| 15 static { | 15 static { |
| 16 // TODO(vsm): We should be able to get rid of this here |
| 17 // and specify in xml instead. |
| 16 System.loadLibrary("android_embedder"); | 18 System.loadLibrary("android_embedder"); |
| 17 System.loadLibrary("DartNDK"); | |
| 18 } | 19 } |
| 19 | 20 |
| 20 @Override | 21 @Override |
| 21 public void onCreate(Bundle savedInstanceState) { | 22 public void onCreate(Bundle savedInstanceState) { |
| 22 super.onCreate(savedInstanceState); | 23 super.onCreate(savedInstanceState); |
| 23 try { | 24 try { |
| 24 File localDir = getApplicationContext().getDir("dart", 0); | 25 File localDir = getApplicationContext().getDir("dart", 0); |
| 25 String fileSystemPath = localDir.toString(); | 26 String fileSystemPath = localDir.toString(); |
| 26 String assetPath = "dart"; | 27 String assetPath = "dart"; |
| 27 AssetManager assetManager = getAssets(); | 28 AssetManager assetManager = getAssets(); |
| 28 String[] files = assetManager.list(assetPath); | 29 String[] files = assetManager.list(assetPath); |
| 29 byte[] buffer = new byte[1024]; | 30 byte[] buffer = new byte[1024]; |
| 30 int read; | 31 int read; |
| 31 for (String filename : files) { | 32 for (String filename : files) { |
| 32 String dest = fileSystemPath + "/" + filename; | 33 String dest = fileSystemPath + "/" + filename; |
| 33 Log.w("Dart", "Copying " + dest); | 34 Log.w("Dart", "Copying " + dest); |
| 34 InputStream in = assetManager.open(assetPath + "/" + filename); | 35 InputStream in = assetManager.open(assetPath + "/" + filename); |
| 35 OutputStream out = new FileOutputStream(dest); | 36 OutputStream out = new FileOutputStream(dest); |
| 36 while((read = in.read(buffer)) != -1){ | 37 while((read = in.read(buffer)) != -1){ |
| 37 out.write(buffer, 0, read); | 38 out.write(buffer, 0, read); |
| 38 } | 39 } |
| 39 in.close(); | 40 in.close(); |
| 40 out.flush(); | 41 out.flush(); |
| 41 ((FileOutputStream)out).getFD().sync(); | 42 ((FileOutputStream)out).getFD().sync(); |
| 42 out.close(); | 43 out.close(); |
| 43 } | 44 } |
| 44 } catch (IOException ex) { | 45 } catch (IOException ex) { |
| 45 } | 46 } |
| 46 } | 47 } |
| 47 } | 48 } |
| OLD | NEW |