summaryrefslogtreecommitdiff
path: root/platform/android/src
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/src')
-rw-r--r--platform/android/src/asset_file_source.cpp4
-rw-r--r--platform/android/src/http_request_android.cpp21
-rwxr-xr-xplatform/android/src/jni.cpp51
-rwxr-xr-xplatform/android/src/native_map_view.cpp2
4 files changed, 68 insertions, 10 deletions
diff --git a/platform/android/src/asset_file_source.cpp b/platform/android/src/asset_file_source.cpp
index 7eb2007778..d2aab30a52 100644
--- a/platform/android/src/asset_file_source.cpp
+++ b/platform/android/src/asset_file_source.cpp
@@ -2,6 +2,7 @@
#include <mbgl/storage/response.hpp>
#include <mbgl/util/util.hpp>
#include <mbgl/util/thread.hpp>
+#include <mbgl/util/url.hpp>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
@@ -59,7 +60,8 @@ public:
struct zip_stat stat;
::zip_stat_init(&stat);
- std::string path = std::string("assets/") + url.substr(8);
+ std::string path = std::string("assets/") + mbgl::util::percentDecode(url.substr(8));
+
int ret = ::zip_stat(archive.archive, path.c_str(), 0, &stat);
if (ret < 0 || !(stat.valid & ZIP_STAT_SIZE)) {
reportError(Response::Error::Reason::NotFound, "Could not stat file in zip archive", callback);
diff --git a/platform/android/src/http_request_android.cpp b/platform/android/src/http_request_android.cpp
index 390334627a..2e2fd6408d 100644
--- a/platform/android/src/http_request_android.cpp
+++ b/platform/android/src/http_request_android.cpp
@@ -199,17 +199,18 @@ void HTTPAndroidRequest::onResponse(JNIEnv* env, int code, jstring /* message */
response->expires = util::parseTimePoint(mbgl::android::std_string_from_jstring(env, expires).c_str());
}
- if (body != nullptr) {
- jbyte* bodyData = env->GetByteArrayElements(body, nullptr);
- response->data = std::make_shared<std::string>(reinterpret_cast<char*>(bodyData), env->GetArrayLength(body));
- env->ReleaseByteArrayElements(body, bodyData, JNI_ABORT);
- }
-
if (code == 200) {
- // Nothing to do; this is what we want
+ if (body != nullptr) {
+ jbyte* bodyData = env->GetByteArrayElements(body, nullptr);
+ response->data = std::make_shared<std::string>(reinterpret_cast<char*>(bodyData), env->GetArrayLength(body));
+ env->ReleaseByteArrayElements(body, bodyData, JNI_ABORT);
+ } else {
+ response->data = std::make_shared<std::string>();
+ }
+ } else if (code == 204 || (code == 404 && resource.kind == Resource::Kind::Tile)) {
+ response->noContent = true;
} else if (code == 304) {
response->notModified = true;
- response->data.reset();
} else if (code == 404) {
response->error = std::make_unique<Error>(Error::Reason::NotFound, "HTTP status code 404");
} else if (code >= 500 && code < 600) {
@@ -248,6 +249,10 @@ std::unique_ptr<HTTPContextBase> HTTPContextBase::createContext() {
return std::make_unique<HTTPAndroidContext>();
}
+uint32_t HTTPContextBase::maximumConcurrentRequests() {
+ return 20;
+}
+
void JNICALL nativeOnFailure(JNIEnv* env, jobject, jlong nativePtr, jint type, jstring message) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeOnFailure");
assert(nativePtr != 0);
diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp
index 00148562bb..db6bc73726 100755
--- a/platform/android/src/jni.cpp
+++ b/platform/android/src/jni.cpp
@@ -60,6 +60,7 @@ jfieldID iconIdId = nullptr;
jclass markerClass = nullptr;
jfieldID markerPositionId = nullptr;
jfieldID markerIconId = nullptr;
+jfieldID markerIdId = nullptr;
jclass polylineClass = nullptr;
jfieldID polylineAlphaId = nullptr;
@@ -834,6 +835,47 @@ jlong JNICALL nativeAddMarker(JNIEnv *env, jobject obj, jlong nativeMapViewPtr,
return nativeMapView->getMap().addPointAnnotation(mbgl::PointAnnotation(mbgl::LatLng(latitude, longitude), id));
}
+void JNICALL nativeUpdateMarker(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject marker) {
+ mbgl::Log::Debug(mbgl::Event::JNI, "nativeUpdateMarker");
+ assert(nativeMapViewPtr != 0);
+ NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
+
+ jlong markerId = env->GetLongField(marker, markerIdId);
+ if (env->ExceptionCheck()) {
+ env->ExceptionDescribe();
+ }
+
+ if (markerId == -1) {
+ return;
+ }
+
+ jobject position = env->GetObjectField(marker, markerPositionId);
+ if (env->ExceptionCheck()) {
+ env->ExceptionDescribe();
+ }
+
+ jobject icon = env->GetObjectField(marker, markerIconId);
+ if (env->ExceptionCheck()) {
+ env->ExceptionDescribe();
+ }
+
+ jstring jid = reinterpret_cast<jstring>(env->GetObjectField(icon, iconIdId));
+ std::string iconId = std_string_from_jstring(env, jid);
+
+ jdouble latitude = env->GetDoubleField(position, latLngLatitudeId);
+ if (env->ExceptionCheck()) {
+ env->ExceptionDescribe();
+ }
+
+ jdouble longitude = env->GetDoubleField(position, latLngLongitudeId);
+ if (env->ExceptionCheck()) {
+ env->ExceptionDescribe();
+ }
+
+ // Because Java only has int, not unsigned int, we need to bump the annotation id up to a long.
+ nativeMapView->getMap().updatePointAnnotation(markerId, mbgl::PointAnnotation(mbgl::LatLng(latitude, longitude), iconId));
+}
+
jlongArray JNICALL nativeAddMarkers(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject jlist) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddMarkers");
assert(nativeMapViewPtr != 0);
@@ -1685,6 +1727,12 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_ERR;
}
+ markerIdId = env->GetFieldID(markerClass, "id", "J");
+ if (markerIdId == nullptr) {
+ env->ExceptionDescribe();
+ return JNI_ERR;
+ }
+
polylineClass = env->FindClass("com/mapbox/mapboxsdk/annotations/Polyline");
if (polylineClass == nullptr) {
env->ExceptionDescribe();
@@ -2044,6 +2092,8 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
reinterpret_cast<void *>(&nativeAddPolygon)},
{"nativeAddPolygons", "(JLjava/util/List;)[J",
reinterpret_cast<void *>(&nativeAddPolygons)},
+ {"nativeUpdateMarker", "(JLcom/mapbox/mapboxsdk/annotations/Marker;)V",
+ reinterpret_cast<void *>(&nativeUpdateMarker)} ,
{"nativeRemoveAnnotation", "(JJ)V", reinterpret_cast<void *>(&nativeRemoveAnnotation)},
{"nativeRemoveAnnotations", "(J[J)V", reinterpret_cast<void *>(&nativeRemoveAnnotations)},
{"nativeGetAnnotationsInBounds", "(JLcom/mapbox/mapboxsdk/geometry/LatLngBounds;)[J",
@@ -2304,6 +2354,7 @@ extern "C" JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) {
markerClass = nullptr;
markerPositionId = nullptr;
markerIconId = nullptr;
+ markerIdId = nullptr;
env->DeleteGlobalRef(polylineClass);
polylineClass = nullptr;
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp
index 8c7115a1e4..d32f3c81cb 100755
--- a/platform/android/src/native_map_view.cpp
+++ b/platform/android/src/native_map_view.cpp
@@ -15,7 +15,7 @@
#include <mbgl/platform/platform.hpp>
#include <mbgl/platform/event.hpp>
#include <mbgl/platform/log.hpp>
-#include <mbgl/platform/gl.hpp>
+#include <mbgl/gl/gl.hpp>
#include <mbgl/util/constants.hpp>
namespace mbgl {