Change Assetbridge extraction dir to data dir

Only extract needed files
This commit is contained in:
Leith Bade
2014-11-11 22:50:37 +11:00
parent e8139cbcfd
commit de1f37fa9e
6 changed files with 29 additions and 13 deletions

View File

@@ -9,8 +9,12 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
public class Assetbridge {
private static final String TAG = "Assetbridge";
/*static {
System.loadLibrary("assetbridge");
}*/
@@ -19,16 +23,21 @@ public class Assetbridge {
public static void unpack(Context c) {
try {
// first let's get the temp directory
String tmpdir = c.getCacheDir().getPath();
// first let's get the data directory
String datadir = c.getFilesDir().getAbsolutePath();
Log.v(TAG, "Extracting assets to " + datadir);
// now we need the assetmanager
AssetManager am = c.getAssets();
String[] assets = am.list("");
// only extract what we need
ArrayList<String> assets = new ArrayList<String>();
assets.add("ca-bundle.crt");
assets.add("styles");
// iterate on the files...
for(String asset : assets) {
copyAssetFolder(am, asset, tmpdir + "/" + asset);
copyAssetFolder(am, asset, datadir + "/" + asset);
}
// last, set the ASSETDIR environment variable for the C
@@ -44,6 +53,7 @@ public class Assetbridge {
public static void copyAssetFolder(AssetManager am, String src, String dest)
throws IOException {
Log.v(TAG, "Copying " + src);
InputStream srcIS = null;
File destfh;
@@ -58,6 +68,8 @@ public class Assetbridge {
isDir = true;
}
Log.v(TAG, src + " was " + (isDir ? "a dir" : "a file"));
// either way, we'll use the dest as a File
destfh = new File(dest);

View File

@@ -116,18 +116,19 @@ public class MapView extends SurfaceView {
}
// Get the cache path
String cachePath = context.getCacheDir().getPath();
String cachePath = context.getCacheDir().getAbsolutePath();
String dataPath = context.getFilesDir().getAbsolutePath();
// Extract the asset files
Assetbridge.unpack(context);
// Load the map style and API key
//mStyleUrl = "https://mapbox.github.io/mapbox-gl-styles/styles/bright-v6.json";
mStyleUrl = "file://" + cachePath + "/styles/styles/bright-v6.json";
mStyleUrl = "file://" + dataPath + "/styles/styles/bright-v6.json";
mAccessToken = "pk.eyJ1IjoibGpiYWRlIiwiYSI6IlJSQ0FEZ2MifQ.7mE4aOegldh3595AG9dxpQ";
// Create the NativeMapView
mNativeMapView = new NativeMapView(this, cachePath);
mNativeMapView = new NativeMapView(this, cachePath, dataPath);
mNativeMapView.setStyleURL(mStyleUrl);
mNativeMapView.setAccessToken(mAccessToken);
mNativeMapView.setDebug(true);

View File

@@ -37,11 +37,11 @@ class NativeMapView {
// Constructors
//
public NativeMapView(MapView mapView, String cachePath) {
public NativeMapView(MapView mapView, String cachePath, String dataPath) {
mMapView = mapView;
// Create the NativeMapView
mNativeMapViewPtr = nativeCreate(cachePath);
mNativeMapViewPtr = nativeCreate(cachePath, dataPath);
}
//
@@ -407,7 +407,7 @@ class NativeMapView {
super.finalize();
}
private native long nativeCreate(String cachePath);
private native long nativeCreate(String cachePath, String dataPath);
private native void nativeDestroy(long nativeMapViewPtr);