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 { | |
16 // TODO(vsm): We should be able to get rid of this here | |
17 // and specify in xml instead. | |
18 System.loadLibrary("android_embedder"); | |
19 } | |
20 | |
21 @Override | 15 @Override |
22 public void onCreate(Bundle savedInstanceState) { | 16 public void onCreate(Bundle savedInstanceState) { |
23 super.onCreate(savedInstanceState); | 17 super.onCreate(savedInstanceState); |
24 try { | 18 try { |
25 File localDir = getApplicationContext().getDir("dart", 0); | 19 File localDir = getApplicationContext().getDir("dart", 0); |
26 String fileSystemPath = localDir.toString(); | 20 String fileSystemPath = localDir.toString(); |
27 String assetPath = "dart"; | 21 String assetPath = "dart"; |
28 AssetManager assetManager = getAssets(); | 22 AssetManager assetManager = getAssets(); |
29 String[] files = assetManager.list(assetPath); | 23 String[] files = assetManager.list(assetPath); |
30 byte[] buffer = new byte[1024]; | 24 byte[] buffer = new byte[1024]; |
31 int read; | 25 int read; |
32 for (String filename : files) { | 26 for (String filename : files) { |
33 String dest = fileSystemPath + "/" + filename; | 27 String dest = fileSystemPath + "/" + filename; |
34 Log.w("Dart", "Copying " + dest); | 28 Log.w("Dart", "Copying " + dest); |
35 InputStream in = assetManager.open(assetPath + "/" + filename); | 29 InputStream in = assetManager.open(assetPath + "/" + filename); |
36 OutputStream out = new FileOutputStream(dest); | 30 OutputStream out = new FileOutputStream(dest); |
37 while((read = in.read(buffer)) != -1){ | 31 while((read = in.read(buffer)) != -1){ |
38 out.write(buffer, 0, read); | 32 out.write(buffer, 0, read); |
39 } | 33 } |
40 in.close(); | 34 in.close(); |
41 out.flush(); | 35 out.flush(); |
42 ((FileOutputStream)out).getFD().sync(); | 36 ((FileOutputStream)out).getFD().sync(); |
43 out.close(); | 37 out.close(); |
44 } | 38 } |
45 } catch (IOException ex) { | 39 } catch (IOException ex) { |
46 } | 40 } |
47 } | 41 } |
48 } | 42 } |
OLD | NEW |