summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorBrad Leege <bleege@gmail.com>2015-08-12 18:22:17 -0500
committerBrad Leege <bleege@gmail.com>2015-08-12 18:22:17 -0500
commit72aaf3934a8aa3569e455b04975d4f8ee2126dc4 (patch)
tree5b9deaff8db61bde467ef27679d765bdabb014fe /android
parent05a7e29d2fac31cb6e10901ee82f334a44b9ee3f (diff)
parentd4159d51419ae59824c1a20cb682d2a66150a7ea (diff)
downloadqtlocation-mapboxgl-72aaf3934a8aa3569e455b04975d4f8ee2126dc4.tar.gz
Merge branch 'master' into 1856-material-take-2
# Conflicts: # android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java
Diffstat (limited to 'android')
-rw-r--r--android/cpp/jni.cpp142
-rw-r--r--android/cpp/native_map_view.cpp81
-rw-r--r--android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/http/HTTPContext.java93
-rw-r--r--android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/util/JavaFileSource.java51
-rw-r--r--android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java12
-rw-r--r--android/mapboxgl-app.gypi5
6 files changed, 241 insertions, 143 deletions
diff --git a/android/cpp/jni.cpp b/android/cpp/jni.cpp
index 6d7def861c..f1e9072cbd 100644
--- a/android/cpp/jni.cpp
+++ b/android/cpp/jni.cpp
@@ -28,6 +28,8 @@
namespace mbgl {
namespace android {
+JavaVM* theJVM;
+
std::string cachePath;
std::string dataPath;
std::string apkPath;
@@ -90,7 +92,15 @@ jmethodID pointFConstructorId = nullptr;
jfieldID pointFXId = nullptr;
jfieldID pointFYId = nullptr;
-bool throw_error(JNIEnv *env, const char *msg) {
+jclass httpContextClass = nullptr;
+jmethodID httpContextGetInstanceId = nullptr;
+jmethodID httpContextCreateRequestId = nullptr;
+
+jclass httpRequestClass = nullptr;
+jmethodID httpRequestStartId = nullptr;
+jmethodID httpRequestCancelId = nullptr;
+
+bool throw_jni_error(JNIEnv *env, const char *msg) {
if (env->ThrowNew(runtimeExceptionClass, msg) < 0) {
env->ExceptionDescribe();
return false;
@@ -99,6 +109,41 @@ bool throw_error(JNIEnv *env, const char *msg) {
return true;
}
+bool attach_jni_thread(JavaVM* vm, JNIEnv** env, std::string threadName) {
+ JavaVMAttachArgs args = {JNI_VERSION_1_2, threadName.c_str(), NULL};
+
+ jint ret;
+ *env = nullptr;
+ bool detach = false;
+ ret = vm->GetEnv(reinterpret_cast<void **>(env), JNI_VERSION_1_6);
+ if (ret != JNI_OK) {
+ if (ret != JNI_EDETACHED) {
+ mbgl::Log::Error(mbgl::Event::JNI, "GetEnv() failed with %i", ret);
+ throw new std::runtime_error("GetEnv() failed");
+ } else {
+ ret = vm->AttachCurrentThread(env, &args);
+ if (ret != JNI_OK) {
+ mbgl::Log::Error(mbgl::Event::JNI, "AttachCurrentThread() failed with %i", ret);
+ throw new std::runtime_error("AttachCurrentThread() failed");
+ }
+ detach = true;
+ }
+ }
+
+ return detach;
+}
+
+void detach_jni_thread(JavaVM* vm, JNIEnv** env, bool detach) {
+ if (detach) {
+ jint ret;
+ if ((ret = vm->DetachCurrentThread()) != JNI_OK) {
+ mbgl::Log::Error(mbgl::Event::JNI, "DetachCurrentThread() failed with %i", ret);
+ throw new std::runtime_error("DetachCurrentThread() failed");
+ }
+ }
+ *env = nullptr;
+}
+
std::string std_string_from_jstring(JNIEnv *env, jstring jstr) {
std::string str;
@@ -342,7 +387,7 @@ void JNICALL nativeInitializeDisplay(JNIEnv *env, jobject obj, jlong nativeMapVi
{
nativeMapView->initializeDisplay();
} catch(const std::exception& e) {
- throw_error(env, "Unable to initialize GL display.");
+ throw_jni_error(env, "Unable to initialize GL display.");
}
}
@@ -361,7 +406,7 @@ void JNICALL nativeInitializeContext(JNIEnv *env, jobject obj, jlong nativeMapVi
try {
nativeMapView->initializeContext();
} catch(const std::exception& e) {
- throw_error(env, "Unable to initialize GL context.");
+ throw_jni_error(env, "Unable to initialize GL context.");
}
}
@@ -380,7 +425,7 @@ void JNICALL nativeCreateSurface(JNIEnv *env, jobject obj, jlong nativeMapViewPt
try {
nativeMapView->createSurface(ANativeWindow_fromSurface(env, surface));
} catch(const std::exception& e) {
- throw_error(env, "Unable to create GL surface.");
+ throw_jni_error(env, "Unable to create GL surface.");
}
}
@@ -1131,6 +1176,8 @@ extern "C" {
extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
mbgl::Log::Debug(mbgl::Event::JNI, "JNI_OnLoad");
+ theJVM = vm;
+
JNIEnv *env = nullptr;
jint ret = vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6);
if (ret != JNI_OK) {
@@ -1426,6 +1473,36 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_ERR;
}
+ httpContextClass = env->FindClass("com/mapbox/mapboxgl/http/HTTPContext");
+ if (httpContextClass == nullptr) {
+ env->ExceptionDescribe();
+ }
+
+ httpContextGetInstanceId = env->GetStaticMethodID(httpContextClass, "getInstance", "()Lcom/mapbox/mapboxgl/http/HTTPContext;");
+ if (httpContextGetInstanceId == nullptr) {
+ env->ExceptionDescribe();
+ }
+
+ httpContextCreateRequestId = env->GetMethodID(httpContextClass, "createRequest", "(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lcom/mapbox/mapboxgl/http/HTTPContext$HTTPRequest;");
+ if (httpContextCreateRequestId == nullptr) {
+ env->ExceptionDescribe();
+ }
+
+ httpRequestClass = env->FindClass("com/mapbox/mapboxgl/http/HTTPContext$HTTPRequest");
+ if (httpRequestClass == nullptr) {
+ env->ExceptionDescribe();
+ }
+
+ httpRequestStartId = env->GetMethodID(httpRequestClass, "start", "()V");
+ if (httpRequestStartId == nullptr) {
+ env->ExceptionDescribe();
+ }
+
+ httpRequestCancelId = env->GetMethodID(httpRequestClass, "cancel", "()V");
+ if (httpRequestCancelId == nullptr) {
+ env->ExceptionDescribe();
+ }
+
const std::vector<JNINativeMethod> methods = {
{"nativeCreate", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;FIJ)J",
reinterpret_cast<void *>(&nativeCreate)},
@@ -1524,10 +1601,16 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
//{"nativeGetWorldBoundsMeters", "(J)V", reinterpret_cast<void *>(&nativeGetWorldBoundsMeters)},
//{"nativeGetWorldBoundsLatLng", "(J)V", reinterpret_cast<void *>(&nativeGetWorldBoundsLatLng)},
{"nativeGetMetersPerPixelAtLatitude", "(JDD)D", reinterpret_cast<void *>(&nativeGetMetersPerPixelAtLatitude)},
- {"nativeProjectedMetersForLatLng", "(JLcom/mapbox/mapboxgl/geometry/LatLng;)Lcom/mapbox/mapboxgl/geometry/ProjectedMeters;", reinterpret_cast<void *>(&nativeProjectedMetersForLatLng)},
- {"nativeLatLngForProjectedMeters", "(JLcom/mapbox/mapboxgl/geometry/ProjectedMeters;)Lcom/mapbox/mapboxgl/geometry/LatLng;", reinterpret_cast<void *>(&nativeLatLngForProjectedMeters)},
- {"nativePixelForLatLng", "(JLcom/mapbox/mapboxgl/geometry/LatLng;)Landroid/graphics/PointF;", reinterpret_cast<void *>(&nativePixelForLatLng)},
- {"nativeLatLngForPixel", "(JLandroid/graphics/PointF;)Lcom/mapbox/mapboxgl/geometry/LatLng;", reinterpret_cast<void *>(&nativeLatLngForPixel)},
+ {"nativeProjectedMetersForLatLng",
+ "(JLcom/mapbox/mapboxgl/geometry/LatLng;)Lcom/mapbox/mapboxgl/geometry/ProjectedMeters;",
+ reinterpret_cast<void *>(&nativeProjectedMetersForLatLng)},
+ {"nativeLatLngForProjectedMeters",
+ "(JLcom/mapbox/mapboxgl/geometry/ProjectedMeters;)Lcom/mapbox/mapboxgl/geometry/LatLng;",
+ reinterpret_cast<void *>(&nativeLatLngForProjectedMeters)},
+ {"nativePixelForLatLng", "(JLcom/mapbox/mapboxgl/geometry/LatLng;)Landroid/graphics/PointF;",
+ reinterpret_cast<void *>(&nativePixelForLatLng)},
+ {"nativeLatLngForPixel", "(JLandroid/graphics/PointF;)Lcom/mapbox/mapboxgl/geometry/LatLng;",
+ reinterpret_cast<void *>(&nativeLatLngForPixel)},
};
if (env->RegisterNatives(nativeMapViewClass, methods.data(), methods.size()) < 0) {
@@ -1641,6 +1724,37 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_ERR;
}
+ httpContextClass = reinterpret_cast<jclass>(env->NewGlobalRef(httpContextClass));
+ if (httpContextClass == nullptr) {
+ env->ExceptionDescribe();
+ env->DeleteGlobalRef(latLngClass);
+ env->DeleteGlobalRef(markerClass);
+ env->DeleteGlobalRef(latLngZoomClass);
+ env->DeleteGlobalRef(polylineClass);
+ env->DeleteGlobalRef(polygonClass);
+ env->DeleteGlobalRef(runtimeExceptionClass);
+ env->DeleteGlobalRef(nullPointerExceptionClass);
+ env->DeleteGlobalRef(arrayListClass);
+ env->DeleteGlobalRef(projectedMetersClass);
+ env->DeleteGlobalRef(pointFClass);
+ }
+
+ httpRequestClass = reinterpret_cast<jclass>(env->NewGlobalRef(httpRequestClass));
+ if (httpRequestClass == nullptr) {
+ env->ExceptionDescribe();
+ env->DeleteGlobalRef(latLngClass);
+ env->DeleteGlobalRef(markerClass);
+ env->DeleteGlobalRef(latLngZoomClass);
+ env->DeleteGlobalRef(polylineClass);
+ env->DeleteGlobalRef(polygonClass);
+ env->DeleteGlobalRef(runtimeExceptionClass);
+ env->DeleteGlobalRef(nullPointerExceptionClass);
+ env->DeleteGlobalRef(arrayListClass);
+ env->DeleteGlobalRef(projectedMetersClass);
+ env->DeleteGlobalRef(pointFClass);
+ env->DeleteGlobalRef(httpContextClass);
+ }
+
char release[PROP_VALUE_MAX] = "";
__system_property_get("ro.build.version.release", release);
androidRelease = std::string(release);
@@ -1651,6 +1765,8 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
extern "C" JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) {
mbgl::Log::Debug(mbgl::Event::JNI, "JNI_OnUnload");
+ theJVM = vm;
+
JNIEnv *env = nullptr;
jint ret = vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6);
if (ret != JNI_OK) {
@@ -1725,5 +1841,15 @@ extern "C" JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) {
pointFConstructorId = nullptr;
pointFXId = nullptr;
pointFYId = nullptr;
+
+ env->DeleteGlobalRef(httpContextClass);
+ httpContextGetInstanceId = nullptr;
+ httpContextCreateRequestId = nullptr;
+
+ env->DeleteGlobalRef(httpRequestClass);
+ httpRequestStartId = nullptr;
+ httpRequestCancelId = nullptr;
+
+ theJVM = nullptr;
}
}
diff --git a/android/cpp/native_map_view.cpp b/android/cpp/native_map_view.cpp
index d0581212df..d7c40ba5a1 100644
--- a/android/cpp/native_map_view.cpp
+++ b/android/cpp/native_map_view.cpp
@@ -148,38 +148,15 @@ void NativeMapView::invalidate() {
assert(vm != nullptr);
assert(obj != nullptr);
- JavaVMAttachArgs args = {JNI_VERSION_1_2, "NativeMapView::invalidate()", NULL};
-
- jint ret;
JNIEnv *env = nullptr;
- bool detach = false;
- ret = vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6);
- if (ret != JNI_OK) {
- if (ret != JNI_EDETACHED) {
- mbgl::Log::Error(mbgl::Event::JNI, "GetEnv() failed with %i", ret);
- throw new std::runtime_error("GetEnv() failed");
- } else {
- ret = vm->AttachCurrentThread(&env, &args);
- if (ret != JNI_OK) {
- mbgl::Log::Error(mbgl::Event::JNI, "AttachCurrentThread() failed with %i", ret);
- throw new std::runtime_error("AttachCurrentThread() failed");
- }
- detach = true;
- }
- }
+ bool detach = attach_jni_thread(vm, &env, "NativeMapView::invalidate()");
env->CallVoidMethod(obj, onInvalidateId);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
}
- if (detach) {
- if ((ret = vm->DetachCurrentThread()) != JNI_OK) {
- mbgl::Log::Error(mbgl::Event::JNI, "DetachCurrentThread() failed with %i", ret);
- throw new std::runtime_error("DetachCurrentThread() failed");
- }
- }
- env = nullptr;
+ detach_jni_thread(vm, &env, detach);
}
void NativeMapView::swap() {
@@ -662,38 +639,15 @@ void NativeMapView::notifyMapChange(mbgl::MapChange) {
assert(vm != nullptr);
assert(obj != nullptr);
- JavaVMAttachArgs args = {JNI_VERSION_1_2, "NativeMapView::notifyMapChange()", NULL};
-
- jint ret;
JNIEnv *env = nullptr;
- bool detach = false;
- ret = vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6);
- if (ret != JNI_OK) {
- if (ret != JNI_EDETACHED) {
- mbgl::Log::Error(mbgl::Event::JNI, "GetEnv() failed with %i", ret);
- throw new std::runtime_error("GetEnv() failed");
- } else {
- ret = vm->AttachCurrentThread(&env, &args);
- if (ret != JNI_OK) {
- mbgl::Log::Error(mbgl::Event::JNI, "AttachCurrentThread() failed with %i", ret);
- throw new std::runtime_error("AttachCurrentThread() failed");
- }
- detach = true;
- }
- }
+ bool detach = attach_jni_thread(vm, &env, "NativeMapView::notifyMapChange()");
env->CallVoidMethod(obj, onMapChangedId);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
}
- if (detach) {
- if ((ret = vm->DetachCurrentThread()) != JNI_OK) {
- mbgl::Log::Error(mbgl::Event::JNI, "DetachCurrentThread() failed with %i", ret);
- throw new std::runtime_error("DetachCurrentThread() failed");
- }
- }
- env = nullptr;
+ detach_jni_thread(vm, &env, detach);
}
void NativeMapView::enableFps(bool enable) {
@@ -727,38 +681,15 @@ void NativeMapView::updateFps() {
assert(vm != nullptr);
assert(obj != nullptr);
- JavaVMAttachArgs args = {JNI_VERSION_1_2, "NativeMapView::updateFps()", NULL};
-
- jint ret;
JNIEnv *env = nullptr;
- bool detach = false;
- ret = vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6);
- if (ret != JNI_OK) {
- if (ret != JNI_EDETACHED) {
- mbgl::Log::Error(mbgl::Event::JNI, "GetEnv() failed with %i", ret);
- throw new std::runtime_error("GetEnv() failed");
- } else {
- ret = vm->AttachCurrentThread(&env, &args);
- if (ret != JNI_OK) {
- mbgl::Log::Error(mbgl::Event::JNI, "AttachCurrentThread() failed with %i", ret);
- throw new std::runtime_error("AttachCurrentThread() failed");
- }
- detach = true;
- }
- }
+ bool detach = attach_jni_thread(vm, &env, "NativeMapView::updateFps()");
env->CallVoidMethod(obj, onFpsChangedId, fps);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
}
- if (detach) {
- if ((ret = vm->DetachCurrentThread()) != JNI_OK) {
- mbgl::Log::Error(mbgl::Event::JNI, "DetachCurrentThread() failed with %i", ret);
- throw new std::runtime_error("DetachCurrentThread() failed");
- }
- }
- env = nullptr;
+ detach_jni_thread(vm, &env, detach);
}
void NativeMapView::onInvalidate() {
diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/http/HTTPContext.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/http/HTTPContext.java
new file mode 100644
index 0000000000..509c79a4a5
--- /dev/null
+++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/http/HTTPContext.java
@@ -0,0 +1,93 @@
+package com.mapbox.mapboxgl.http;
+
+import com.mapbox.mapboxgl.constants.MapboxConstants;
+import com.squareup.okhttp.Call;
+import com.squareup.okhttp.Callback;
+import com.squareup.okhttp.OkHttpClient;
+import com.squareup.okhttp.Request;
+import com.squareup.okhttp.Response;
+
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.net.ProtocolException;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+
+import javax.net.ssl.SSLException;
+
+class HTTPContext {
+
+ private static final int CONNECTION_ERROR = 0;
+ private static final int TEMPORARY_ERROR = 1;
+ private static final int PERMANENT_ERROR = 2;
+
+ private static HTTPContext mInstance = null;
+
+ private OkHttpClient mClient;
+
+ private HTTPContext() {
+ super();
+ mClient = new OkHttpClient();
+ }
+
+ public static HTTPContext getInstance() {
+ if (mInstance == null) {
+ mInstance = new HTTPContext();
+ }
+
+ return mInstance;
+ }
+
+ public HTTPRequest createRequest(long nativePtr, String resourceUrl, String userAgent, String etag, String modified) {
+ return new HTTPRequest(nativePtr, resourceUrl, userAgent, etag, modified);
+ }
+
+ public class HTTPRequest implements Callback {
+ private long mNativePtr = 0;
+
+ private Call mCall;
+ private Request mRequest;
+
+ private native void nativeOnFailure(long nativePtr, int type, String message);
+ private native void nativeOnResponse(long nativePtr, int code, String message, String etag, String modified, String cacheControl, String expires, byte[] body);
+
+ private HTTPRequest(long nativePtr, String resourceUrl, String userAgent, String etag, String modified) {
+ mNativePtr = nativePtr;
+ Request.Builder builder = new Request.Builder().url(resourceUrl).tag(resourceUrl.toLowerCase(MapboxConstants.MAPBOX_LOCALE)).addHeader("User-Agent", userAgent);
+ if (etag.length() > 0) {
+ builder = builder.addHeader("If-None-Match", etag);
+ } else if (modified.length() > 0) {
+ builder = builder.addHeader("If-Modified-Since", modified);
+ }
+ mRequest = builder.build();
+ }
+
+ public void start() {
+ mCall = HTTPContext.getInstance().mClient.newCall(mRequest);
+ mCall.enqueue(this);
+ }
+
+ public void cancel() {
+ mCall.cancel();
+ }
+
+ @Override
+ public void onFailure(Request request, IOException e) {
+ int type = PERMANENT_ERROR;
+ if ((e instanceof UnknownHostException) || (e instanceof SocketException) || (e instanceof ProtocolException) || (e instanceof SSLException)) {
+ type = CONNECTION_ERROR;
+ } else if ((e instanceof InterruptedIOException)) {
+ type = TEMPORARY_ERROR;
+ }
+ nativeOnFailure(mNativePtr, type, e.getMessage());
+ }
+
+ @Override
+ public void onResponse(Response response) throws IOException {
+ byte[] body = response.body().bytes();
+ response.body().close();
+
+ nativeOnResponse(mNativePtr, response.code(), response.message(), response.header("ETag"), response.header("Last-Modified"), response.header("Cache-Control"), response.header("Expires"), body);
+ }
+ }
+}
diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/util/JavaFileSource.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/util/JavaFileSource.java
deleted file mode 100644
index bd86241888..0000000000
--- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/util/JavaFileSource.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.mapbox.mapboxgl.util;
-
-import com.mapbox.mapboxgl.constants.MapboxConstants;
-import com.squareup.okhttp.Callback;
-import com.squareup.okhttp.OkHttpClient;
-import com.squareup.okhttp.Request;
-
-public class JavaFileSource {
-
- private static JavaFileSource instance = null;
-
- // Single reference to OkHttp for performance gains
- private OkHttpClient client;
-
- /**
- * Private Constructor to support Singleton pattern
- */
- private JavaFileSource() {
- super();
- client = new OkHttpClient();
- }
-
- /**
- * Get the singleton instance of JavaFileSource
- * @return Reference to the Singleton Instance of JavaFileSource
- */
- public static JavaFileSource getInstance() {
- if (instance == null) {
- instance = new JavaFileSource();
- }
- return instance;
- }
-
- /**
- * Make an HTTP Request
- * @param resourceUrl URL to resource
- * @param callback Callback class
- */
- public void request(final String resourceUrl, final Callback callback) {
- Request request = new Request.Builder().url(resourceUrl).tag(resourceUrl.toLowerCase(MapboxConstants.MAPBOX_LOCALE)).build();
- client.newCall(request).enqueue(callback);
- }
-
- /**
- * Attempt to cancel HTTP Request made
- * @param resourceUrl URL of request to cancel
- */
- public void cancel(final String resourceUrl) {
- client.cancel(resourceUrl.toLowerCase(MapboxConstants.MAPBOX_LOCALE));
- }
-}
diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java
index 60c57593c1..ca0b2526f8 100644
--- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java
+++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java
@@ -191,6 +191,7 @@ public class MapView extends FrameLayout implements LocationListener {
//
// Common initialization code goes here
+ @TargetApi(16)
private void initialize(Context context, AttributeSet attrs) {
// Save the context
@@ -217,9 +218,12 @@ public class MapView extends FrameLayout implements LocationListener {
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.getMemoryInfo(memoryInfo);
- long totalMemory = memoryInfo.totalMem;
- mNativeMapView = new NativeMapView(this, cachePath, dataPath, apkPath, mScreenDensity,availableProcessors, totalMemory);
-
+ if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ long totalMemory = memoryInfo.totalMem;
+ mNativeMapView = new NativeMapView(this, cachePath, dataPath, apkPath, mScreenDensity, availableProcessors, totalMemory);
+ } else {
+ throw new RuntimeException("Need to implement totalMemory on pre-Jelly Bean devices.");
+ }
// Load the attributes
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MapView, 0, 0);
try {
@@ -678,7 +682,7 @@ public class MapView extends FrameLayout implements LocationListener {
}
public void onSizeChanged(int width, int height, int oldw, int oldh) {
- mNativeMapView.resizeView((int)(width / mScreenDensity), (int)(height / mScreenDensity));
+ mNativeMapView.resizeView((int) (width / mScreenDensity), (int) (height / mScreenDensity));
}
// This class handles SurfaceHolder callbacks
diff --git a/android/mapboxgl-app.gypi b/android/mapboxgl-app.gypi
index e32775ff72..e3db1269d6 100644
--- a/android/mapboxgl-app.gypi
+++ b/android/mapboxgl-app.gypi
@@ -25,8 +25,6 @@
'<@(boost_cflags)',
],
'libraries': [
- '<@(openssl_static_libs)',
- '<@(libcurl_static_libs)',
'<@(libpng_static_libs)',
'<@(jpeg_static_libs)',
'<@(sqlite_static_libs)',
@@ -45,8 +43,6 @@
'<@(libpng_ldflags)',
'<@(jpeg_ldflags)',
'<@(sqlite_ldflags)',
- '<@(openssl_ldflags)',
- '<@(libcurl_ldflags)',
'<@(zlib_ldflags)',
'<@(libzip_ldflags)',
],
@@ -74,7 +70,6 @@
'copies': [
{
'files': [
- '../common/ca-bundle.crt',
'../styles/styles'
],
'destination': '<(pwd)/../android/java/MapboxGLAndroidSDK/src/main/assets'