diff options
14 files changed, 221 insertions, 129 deletions
@@ -72,6 +72,7 @@ build/linux/mapboxgl-app.xcodeproj: linux/mapboxgl-app.gyp config.gypi .PHONY: android android: ./scripts/local_mason.sh && \ + MASON_DIR=./.mason MASON_PLATFORM=android ./.mason/mason env PATH && \ export CXX="`MASON_DIR=./.mason MASON_PLATFORM=android ./.mason/mason env CXX`" && \ export CC="`MASON_DIR=./.mason MASON_PLATFORM=android ./.mason/mason env CC`" && \ export LD="`MASON_DIR=./.mason MASON_PLATFORM=android ./.mason/mason env LD`" && \ diff --git a/android/cpp/JNI.cpp b/android/cpp/JNI.cpp index d664ef1ade..e1731aa99d 100644 --- a/android/cpp/JNI.cpp +++ b/android/cpp/JNI.cpp @@ -37,11 +37,11 @@ jfieldID lon_lat_zoom_zoom_id = nullptr; jclass runtime_exception_class = nullptr; -jmethodID set_to_array_id = nullptr; +jmethodID list_to_array_id = nullptr; -jclass tree_set_class = nullptr; -jmethodID tree_set_constructor_id = nullptr; -jmethodID tree_set_add_id = nullptr; +jclass array_list_class = nullptr; +jmethodID array_list_constructor_id = nullptr; +jmethodID array_list_add_id = nullptr; bool throw_error(JNIEnv* env, const char* msg) { if (env->ThrowNew(runtime_exception_class, msg) < 0) { @@ -83,12 +83,10 @@ jstring std_string_to_jstring(JNIEnv* env, std::string str) { return jstr; } - -// TODO: change from Java TreeSet to ArrayList -std::vector<std::string> std_vector_string_from_jobject(JNIEnv* env, jobject jset) { +std::vector<std::string> std_vector_string_from_jobject(JNIEnv* env, jobject jlist) { std::vector<std::string> vector; - jobjectArray array = reinterpret_cast<jobjectArray>(env->CallObjectMethod(jset, set_to_array_id)); + jobjectArray array = reinterpret_cast<jobjectArray>(env->CallObjectMethod(jlist, list_to_array_id)); if (env->ExceptionCheck() || (array == nullptr)) { env->ExceptionDescribe(); return vector; @@ -113,23 +111,22 @@ std::vector<std::string> std_vector_string_from_jobject(JNIEnv* env, jobject jse return vector; } -// TODO: change from Java TreeSet to ArrayList jobject std_vector_string_to_jobject(JNIEnv* env, std::vector<std::string> vector) { - jobject jset = env->NewObject(tree_set_class, tree_set_constructor_id); - if (jset == nullptr) { + jobject jlist = env->NewObject(array_list_class, array_list_constructor_id); + if (jlist == nullptr) { env->ExceptionDescribe(); return nullptr; } for (std::string str : vector) { - env->CallBooleanMethod(jset, tree_set_add_id, std_string_to_jstring(env, str)); + env->CallBooleanMethod(jlist, array_list_add_id, std_string_to_jstring(env, str)); if (env->ExceptionCheck()) { env->ExceptionDescribe(); return nullptr; } } - return jset; + return jlist; } } // namespace android @@ -142,10 +139,10 @@ using namespace mbgl::android; // TODO: wrap C++ exceptions? // TODO: wrap other sorts of exceptions? eg coffee catch -jlong JNICALL nativeCreate(JNIEnv* env, jobject obj, jstring cache_path_, jstring style_url, jstring api_key) { +jlong JNICALL nativeCreate(JNIEnv* env, jobject obj, jstring cache_path_) { LOG_VERBOSE("nativeCreate"); cache_path = std_string_from_jstring(env, cache_path_); - NativeMapView* native_map_view = new NativeMapView(env, obj, std_string_from_jstring(env, style_url), std_string_from_jstring(env, api_key)); + NativeMapView* native_map_view = new NativeMapView(env, obj); if (native_map_view == nullptr) { throw_error(env, "Unable to create NativeMapView."); return 0; @@ -224,6 +221,13 @@ void JNICALL nativeStop(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { native_map_view->stop(); } +void JNICALL nativeRun(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { + LOG_VERBOSE("nativeRun"); + LOG_ASSERT(native_map_view_ptr != 0); + NativeMapView* native_map_view = reinterpret_cast<NativeMapView*>(native_map_view_ptr); + native_map_view->getMap()->run(); +} + void JNICALL nativeRerender(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeRerender"); LOG_ASSERT(native_map_view_ptr != 0); @@ -245,6 +249,27 @@ void JNICALL nativeCleanup(JNIEnv* env, jobject obj, jlong native_map_view_ptr) native_map_view->getMap()->cleanup(); } +void JNICALL nativeTerminate(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { + LOG_VERBOSE("nativeTerminate"); + LOG_ASSERT(native_map_view_ptr != 0); + NativeMapView* native_map_view = reinterpret_cast<NativeMapView*>(native_map_view_ptr); + native_map_view->getMap()->terminate(); +} + +jboolean JNICALL nativeNeedsSwap(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { + LOG_VERBOSE("nativeNeedsSwap"); + LOG_ASSERT(native_map_view_ptr != 0); + NativeMapView* native_map_view = reinterpret_cast<NativeMapView*>(native_map_view_ptr); + return native_map_view->getMap()->needsSwap(); +} + +void JNICALL nativeSwapped(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { + LOG_VERBOSE("nativeSwapped"); + LOG_ASSERT(native_map_view_ptr != 0); + NativeMapView* native_map_view = reinterpret_cast<NativeMapView*>(native_map_view_ptr); + native_map_view->getMap()->swapped(); +} + void JNICALL nativeResize(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jint width, jint height, jfloat ratio) { LOG_VERBOSE("nativeResize"); LOG_ASSERT(native_map_view_ptr != 0); @@ -271,11 +296,11 @@ void JNICALL nativeResize(JNIEnv* env, jobject obj, jlong native_map_view_ptr, j native_map_view->getMap()->resize(width, height, ratio, fb_width, fb_height); } -void JNICALL nativeSetAppliedClasses(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jobject applied_classes) { +void JNICALL nativeSetAppliedClasses(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jobject classes) { LOG_VERBOSE("nativeSetAppliedClasses"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast<NativeMapView*>(native_map_view_ptr); - native_map_view->getMap()->setAppliedClasses(std_vector_string_from_jobject(env, applied_classes)); + native_map_view->getMap()->setAppliedClasses(std_vector_string_from_jobject(env, classes)); } jobject JNICALL nativeGetAppliedClasses(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { @@ -294,11 +319,18 @@ void JNICALL nativeSetDefaultTransitionDuration(JNIEnv* env, jobject obj, jlong native_map_view->getMap()->setDefaultTransitionDuration(duration_milliseconds); } -void JNICALL nativeSetStyleJSON(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jstring new_style_json) { +void JNICALL nativeSetStyleURL(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jstring url) { + LOG_VERBOSE("nativeSetStyleURL"); + LOG_ASSERT(native_map_view_ptr != 0); + NativeMapView* native_map_view = reinterpret_cast<NativeMapView*>(native_map_view_ptr); + native_map_view->getMap()->setStyleURL(std_string_from_jstring(env, url)); +} + +void JNICALL nativeSetStyleJSON(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jstring new_style_json, jstring base) { LOG_VERBOSE("nativeSetStyleJSON"); LOG_ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast<NativeMapView*>(native_map_view_ptr); - native_map_view->getMap()->setStyleJSON(std_string_from_jstring(env, new_style_json)); + native_map_view->getMap()->setStyleJSON(std_string_from_jstring(env, new_style_json), std_string_from_jstring(env, base)); } jstring JNICALL nativeGetStyleJSON(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { @@ -308,6 +340,20 @@ jstring JNICALL nativeGetStyleJSON(JNIEnv* env, jobject obj, jlong native_map_vi return std_string_to_jstring(env, native_map_view->getMap()->getStyleJSON()); } +void JNICALL nativeSetAccessToken(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jstring access_token) { + LOG_VERBOSE("nativeSetAccessToken"); + LOG_ASSERT(native_map_view_ptr != 0); + NativeMapView* native_map_view = reinterpret_cast<NativeMapView*>(native_map_view_ptr); + native_map_view->getMap()->setAccessToken(std_string_from_jstring(env, access_token)); +} + +jstring JNICALL nativeGetAccessToken(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { + LOG_VERBOSE("nativeGetAccessToken"); + LOG_ASSERT(native_map_view_ptr != 0); + NativeMapView* native_map_view = reinterpret_cast<NativeMapView*>(native_map_view_ptr); + return std_string_to_jstring(env, native_map_view->getMap()->getAccessToken()); +} + void JNICALL nativeCancelTransitions(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeCancelTransitions"); LOG_ASSERT(native_map_view_ptr != 0); @@ -570,6 +616,13 @@ jboolean JNICALL nativeGetDebug(JNIEnv* env, jobject obj, jlong native_map_view_ return native_map_view->getMap()->getDebug(); } +void JNICALL nativeSetReachability(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jboolean status) { + LOG_VERBOSE("nativeSetReachability"); + LOG_ASSERT(native_map_view_ptr != 0); + NativeMapView* native_map_view = reinterpret_cast<NativeMapView*>(native_map_view_ptr); + native_map_view->getMap()->setReachability(status); +} + } // namespace extern "C" { @@ -655,39 +708,39 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { return JNI_ERR; } - jclass set_class = env->FindClass("java/util/Set"); - if (set_class == nullptr) { + jclass list_class = env->FindClass("java/util/List"); + if (list_class == nullptr) { env->ExceptionDescribe(); return JNI_ERR; } - set_to_array_id = env->GetMethodID(set_class, "toArray", "()[Ljava/lang/Object;"); - if (set_to_array_id == nullptr) { + list_to_array_id = env->GetMethodID(list_class, "toArray", "()[Ljava/lang/Object;"); + if (list_to_array_id == nullptr) { env->ExceptionDescribe(); return JNI_ERR; } - tree_set_class = env->FindClass("java/util/TreeSet"); - if (tree_set_class == nullptr) { + array_list_class = env->FindClass("java/util/ArrayList"); + if (array_list_class == nullptr) { env->ExceptionDescribe(); return JNI_ERR; } - tree_set_constructor_id = env->GetMethodID(tree_set_class, "<init>", "()V"); - if (tree_set_constructor_id == nullptr) { + array_list_constructor_id = env->GetMethodID(array_list_class, "<init>", "()V"); + if (array_list_constructor_id == nullptr) { env->ExceptionDescribe(); return JNI_ERR; } - tree_set_add_id = env->GetMethodID(tree_set_class, "add", "(Ljava/lang/Object;)Z"); - if (tree_set_add_id == nullptr) { + array_list_add_id = env->GetMethodID(array_list_class, "add", "(Ljava/lang/Object;)Z"); + if (array_list_add_id == nullptr) { env->ExceptionDescribe(); return JNI_ERR; } // NOTE: if you get java.lang.UnsatisfiedLinkError you likely forgot to set the size of the array correctly (too large) - std::array<JNINativeMethod, 50> methods = {{ // Can remove the extra brace in C++14 - { "nativeCreate", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)J", reinterpret_cast<void*>(&nativeCreate) }, + std::array<JNINativeMethod, 58> methods = {{ // Can remove the extra brace in C++14 + { "nativeCreate", "(Ljava/lang/String;)J", reinterpret_cast<void*>(&nativeCreate) }, { "nativeDestroy", "(J)V", reinterpret_cast<void*>(&nativeDestroy) }, { "nativeInitializeDisplay", "(J)V", reinterpret_cast<void*>(&nativeInitializeDisplay) }, { "nativeTerminateDisplay", "(J)V", reinterpret_cast<void*>(&nativeTerminateDisplay) }, @@ -697,16 +750,23 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { { "nativeDestroySurface", "(J)V", reinterpret_cast<void*>(&nativeDestroySurface) }, { "nativeStart", "(J)V", reinterpret_cast<void*>(&nativeStart) }, { "nativeStop", "(J)V", reinterpret_cast<void*>(&nativeStop) }, + { "nativeRun", "(J)V", reinterpret_cast<void*>(&nativeRun) }, { "nativeRerender", "(J)V", reinterpret_cast<void*>(&nativeRerender) }, { "nativeUpdate", "(J)V", reinterpret_cast<void*>(&nativeUpdate) }, { "nativeCleanup", "(J)V", reinterpret_cast<void*>(&nativeCleanup) }, + { "nativeTerminate", "(J)V", reinterpret_cast<void*>(&nativeTerminate) }, + { "nativeNeedsSwap", "(J)Z", reinterpret_cast<void*>(&nativeNeedsSwap) }, + { "nativeSwapped", "(J)V", reinterpret_cast<void*>(&nativeSwapped) }, { "nativeResize", "(JIIF)V", reinterpret_cast<void*>(static_cast<void JNICALL(*)(JNIEnv*,jobject,jlong,jint,jint,jfloat)>(&nativeResize)) }, { "nativeResize", "(JIIFII)V", reinterpret_cast<void*>(static_cast<void JNICALL(*)(JNIEnv*,jobject,jlong,jint,jint,jfloat,jint,jint)>(&nativeResize)) }, - { "nativeSetAppliedClasses", "(JLjava/util/Set;)V", reinterpret_cast<void*>(&nativeSetAppliedClasses) }, - { "nativeGetAppliedClasses", "(J)Ljava/util/Set;", reinterpret_cast<void*>(&nativeGetAppliedClasses) }, + { "nativeSetAppliedClasses", "(JLjava/util/List;)V", reinterpret_cast<void*>(&nativeSetAppliedClasses) }, + { "nativeGetAppliedClasses", "(J)Ljava/util/List;", reinterpret_cast<void*>(&nativeGetAppliedClasses) }, { "nativeSetDefaultTransitionDuration", "(JJ)V", reinterpret_cast<void*>(&nativeSetDefaultTransitionDuration) }, - { "nativeSetStyleJSON", "(JLjava/lang/String;)V", reinterpret_cast<void*>(&nativeSetStyleJSON) }, + { "nativeSetStyleURL", "(JLjava/lang/String;)V", reinterpret_cast<void*>(&nativeSetStyleURL) }, + { "nativeSetStyleJSON", "(JLjava/lang/String;Ljava/lang/String;)V", reinterpret_cast<void*>(&nativeSetStyleJSON) }, { "nativeGetStyleJSON", "(J)Ljava/lang/String;", reinterpret_cast<void*>(&nativeGetStyleJSON) }, + { "nativeSetAccessToken", "(JLjava/lang/String;)V", reinterpret_cast<void*>(&nativeSetAccessToken) }, + { "nativeGetAccessToken", "(J)Ljava/lang/String;", reinterpret_cast<void*>(&nativeGetAccessToken) }, { "nativeCancelTransitions", "(J)V", reinterpret_cast<void*>(&nativeCancelTransitions) }, { "nativeMoveBy", "(JDDD)V", reinterpret_cast<void*>(&nativeMoveBy) }, { "nativeSetLonLat", "(JLcom/mapbox/mapboxgl/lib/LonLat;D)V", reinterpret_cast<void*>(&nativeSetLonLat) }, @@ -736,7 +796,8 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { { "nativeCanRotate", "(J)Z", reinterpret_cast<void*>(&nativeCanRotate) }, { "nativeSetDebug", "(JZ)V", reinterpret_cast<void*>(&nativeSetDebug) }, { "nativeToggleDebug", "(J)V", reinterpret_cast<void*>(&nativeToggleDebug) }, - { "nativeGetDebug", "(J)Z", reinterpret_cast<void*>(&nativeGetDebug) } + { "nativeGetDebug", "(J)Z", reinterpret_cast<void*>(&nativeGetDebug) }, + { "nativeSetReachability", "(JZ)V", reinterpret_cast<void*>(&nativeSetReachability) } }}; if (env->RegisterNatives(native_map_view_class, methods.data(), methods.size()) < 0) { @@ -765,8 +826,8 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { return JNI_ERR; } - tree_set_class = reinterpret_cast<jclass>(env->NewGlobalRef(tree_set_class)); - if (tree_set_class == nullptr) { + array_list_class = reinterpret_cast<jclass>(env->NewGlobalRef(array_list_class)); + if (array_list_class == nullptr) { env->ExceptionDescribe(); env->DeleteGlobalRef(lon_lat_class); env->DeleteGlobalRef(lon_lat_zoom_class); @@ -804,12 +865,12 @@ extern "C" JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) { env->DeleteGlobalRef(runtime_exception_class); runtime_exception_class = nullptr; - set_to_array_id = nullptr; + list_to_array_id = nullptr; - env->DeleteGlobalRef(tree_set_class); - tree_set_class = nullptr; - tree_set_constructor_id = nullptr; - tree_set_add_id = nullptr; + env->DeleteGlobalRef(array_list_class); + array_list_class = nullptr; + array_list_constructor_id = nullptr; + array_list_add_id = nullptr; } } // extern "C" diff --git a/android/cpp/NativeMapView.cpp b/android/cpp/NativeMapView.cpp index 080b18d3be..4765661b23 100644 --- a/android/cpp/NativeMapView.cpp +++ b/android/cpp/NativeMapView.cpp @@ -30,9 +30,7 @@ void log_gl_string(GLenum name, const char* label) { } } -NativeMapView::NativeMapView(JNIEnv* env, jobject obj_, - std::string style_url_, std::string api_key_) : - style_url(style_url_), api_key(api_key_) { +NativeMapView::NativeMapView(JNIEnv* env, jobject obj_) { LOG_VERBOSE("NativeMapView::NativeMapView"); LOG_ASSERT(env != nullptr); @@ -53,9 +51,6 @@ NativeMapView::NativeMapView(JNIEnv* env, jobject obj_, view = new MBGLView(this); map = new mbgl::Map(*view); - - map->setAccessToken(api_key); - map->setStyleURL(style_url); } NativeMapView::~NativeMapView() { diff --git a/android/cpp/NativeMapView.hpp b/android/cpp/NativeMapView.hpp index 459ef9343e..866365c6d4 100644 --- a/android/cpp/NativeMapView.hpp +++ b/android/cpp/NativeMapView.hpp @@ -31,11 +31,11 @@ extern jfieldID lon_lat_zoom_zoom_id; extern jclass runtime_exception_class; -extern jmethodID set_to_array_id; +extern jmethodID list_to_array_id; -extern jclass tree_set_class; -extern jmethodID tree_set_constructor_id; -extern jmethodID tree_set_add_id; +extern jclass array_list_class; +extern jmethodID array_list_constructor_id; +extern jmethodID array_list_add_id; class MBGLView; @@ -43,7 +43,7 @@ class NativeMapView { friend class MBGLView; public: - NativeMapView(JNIEnv* env, jobject obj, std::string style_url, std::string api_key); + NativeMapView(JNIEnv* env, jobject obj); ~NativeMapView(); mbgl::Map* getMap() const { diff --git a/android/java/app/src/main/java/com/mapbox/mapboxgl/app/MainActivity.java b/android/java/app/src/main/java/com/mapbox/mapboxgl/app/MainActivity.java index 43537f9ac8..798e05a84c 100644 --- a/android/java/app/src/main/java/com/mapbox/mapboxgl/app/MainActivity.java +++ b/android/java/app/src/main/java/com/mapbox/mapboxgl/app/MainActivity.java @@ -2,6 +2,7 @@ package com.mapbox.mapboxgl.app; import android.app.Activity; import android.os.Bundle; +import android.support.annotation.NonNull; import android.util.Log; import com.mapbox.mapboxgl.lib.MapView; @@ -88,7 +89,7 @@ public class MainActivity extends Activity { // Called before activity is destroyed @Override - protected void onSaveInstanceState(Bundle outState) { + protected void onSaveInstanceState(@NonNull Bundle outState) { Log.v(TAG, "onSaveInstanceState"); // Need to retrieve any saved state from the map diff --git a/android/java/lib/build.gradle b/android/java/lib/build.gradle index 900bedd594..3784d2a9f1 100644 --- a/android/java/lib/build.gradle +++ b/android/java/lib/build.gradle @@ -27,5 +27,6 @@ android { } dependencies { - compile "commons-io:commons-io:2.4" + compile 'commons-io:commons-io:2.4' + compile 'com.android.support:support-annotations:21.0.0' } diff --git a/android/java/lib/src/main/java/com/almeros/android/multitouch/gesturedetectors/BaseGestureDetector.java b/android/java/lib/src/main/java/com/almeros/android/multitouch/gesturedetectors/BaseGestureDetector.java index 86d1d50f68..720a1f541b 100644 --- a/android/java/lib/src/main/java/com/almeros/android/multitouch/gesturedetectors/BaseGestureDetector.java +++ b/android/java/lib/src/main/java/com/almeros/android/multitouch/gesturedetectors/BaseGestureDetector.java @@ -91,7 +91,8 @@ public abstract class BaseGestureDetector { * handling in this implementation may set the gesture out of progress (via * mGestureInProgress). * - * @param action + * + * @param actionCode * @param event */ protected abstract void handleInProgressEvent(int actionCode, diff --git a/android/java/lib/src/main/java/com/almeros/android/multitouch/gesturedetectors/MoveGestureDetector.java b/android/java/lib/src/main/java/com/almeros/android/multitouch/gesturedetectors/MoveGestureDetector.java index 0136183ed2..2430f3f920 100644 --- a/android/java/lib/src/main/java/com/almeros/android/multitouch/gesturedetectors/MoveGestureDetector.java +++ b/android/java/lib/src/main/java/com/almeros/android/multitouch/gesturedetectors/MoveGestureDetector.java @@ -74,8 +74,6 @@ public class MoveGestureDetector extends BaseGestureDetector { private final OnMoveGestureListener mListener; - private PointF mCurrFocusInternal; - private PointF mPrevFocusInternal; private PointF mFocusExternal = new PointF(); private PointF mFocusDeltaExternal = new PointF(); @@ -134,8 +132,8 @@ public class MoveGestureDetector extends BaseGestureDetector { final MotionEvent prev = mPrevEvent; // Focus intenal - mCurrFocusInternal = determineFocalPoint(curr); - mPrevFocusInternal = determineFocalPoint(prev); + PointF mCurrFocusInternal = determineFocalPoint(curr); + PointF mPrevFocusInternal = determineFocalPoint(prev); // Focus external // - Prevent skipping of focus delta when a finger is added or removed @@ -155,8 +153,7 @@ public class MoveGestureDetector extends BaseGestureDetector { * Determine (multi)finger focal point (a.k.a. center point between all * fingers) * - * @param MotionEvent - * e + * @param e * @return PointF focal point */ private PointF determineFocalPoint(MotionEvent e) { diff --git a/android/java/lib/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java b/android/java/lib/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java index 5215a91bba..e26d6b5ae4 100644 --- a/android/java/lib/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java +++ b/android/java/lib/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java @@ -38,8 +38,6 @@ import android.view.ViewConfiguration; public abstract class TwoFingerGestureDetector extends BaseGestureDetector { private final float mEdgeSlop; - private float mRightSlopEdge; - private float mBottomSlopEdge; protected float mPrevFingerDiffX; protected float mPrevFingerDiffY; @@ -168,22 +166,20 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector { protected boolean isSloppyGesture(MotionEvent event) { // As orientation can change, query the metrics in touch down DisplayMetrics metrics = mContext.getResources().getDisplayMetrics(); - mRightSlopEdge = metrics.widthPixels - mEdgeSlop; - mBottomSlopEdge = metrics.heightPixels - mEdgeSlop; + float mRightSlopEdge = metrics.widthPixels - mEdgeSlop; + float mBottomSlopEdge = metrics.heightPixels - mEdgeSlop; final float edgeSlop = mEdgeSlop; - final float rightSlop = mRightSlopEdge; - final float bottomSlop = mBottomSlopEdge; final float x0 = event.getRawX(); final float y0 = event.getRawY(); final float x1 = getRawX(event, 1); final float y1 = getRawY(event, 1); - boolean p0sloppy = x0 < edgeSlop || y0 < edgeSlop || x0 > rightSlop - || y0 > bottomSlop; - boolean p1sloppy = x1 < edgeSlop || y1 < edgeSlop || x1 > rightSlop - || y1 > bottomSlop; + boolean p0sloppy = x0 < edgeSlop || y0 < edgeSlop || x0 > mRightSlopEdge + || y0 > mBottomSlopEdge; + boolean p1sloppy = x1 < edgeSlop || y1 < edgeSlop || x1 > mRightSlopEdge + || y1 > mBottomSlopEdge; if (p0sloppy && p1sloppy) { return true; @@ -199,8 +195,7 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector { * Determine (multi)finger focal point (a.k.a. center point between all * fingers) * - * @param MotionEvent - * e + * @param e * @return PointF focal point */ public static PointF determineFocalPoint(MotionEvent e) { diff --git a/android/java/lib/src/main/java/com/arieslabs/assetbridge/Assetbridge.java b/android/java/lib/src/main/java/com/arieslabs/assetbridge/Assetbridge.java index e322d1c613..8730cf4cad 100644 --- a/android/java/lib/src/main/java/com/arieslabs/assetbridge/Assetbridge.java +++ b/android/java/lib/src/main/java/com/arieslabs/assetbridge/Assetbridge.java @@ -3,22 +3,18 @@ package com.arieslabs.assetbridge; import android.content.Context; import android.content.res.AssetManager; import android.util.Log; + import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; - - public class Assetbridge { /*static { System.loadLibrary("assetbridge"); }*/ - // unpack public static void unpack(Context c) { @@ -47,7 +43,7 @@ public class Assetbridge { public static void copyAssetFolder(AssetManager am, String src, String dest) - throws IOException{ + throws IOException { InputStream srcIS = null; File destfh; @@ -69,8 +65,10 @@ public class Assetbridge { if(isDir) { // If the directory doesn't yet exist, create it - if( !destfh.exists() ){ - destfh.mkdir(); + if( !destfh.exists() ) { + if (!destfh.mkdir()) { + throw new IOException("Failed to mkdir"); + } } // list the assets in the directory... @@ -101,7 +99,6 @@ public class Assetbridge { } } - // the native method to set the environment variable //public static native void setassetdir(String s); } diff --git a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/LonLat.java b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/LonLat.java index 87260c2a9e..69e9a68351 100644 --- a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/LonLat.java +++ b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/LonLat.java @@ -65,11 +65,7 @@ public class LonLat implements Parcelable { if (getClass() != obj.getClass()) return false; LonLat other = (LonLat) obj; - if (Double.doubleToLongBits(lat) != Double.doubleToLongBits(other.lat)) - return false; - if (Double.doubleToLongBits(lon) != Double.doubleToLongBits(other.lon)) - return false; - return true; + return Double.doubleToLongBits(lat) == Double.doubleToLongBits(other.lat) && Double.doubleToLongBits(lon) == Double.doubleToLongBits(other.lon); } @Override diff --git a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/LonLatZoom.java b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/LonLatZoom.java index d20cccd47b..ad8b5dd477 100644 --- a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/LonLatZoom.java +++ b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/LonLatZoom.java @@ -93,14 +93,7 @@ public class LonLatZoom implements Parcelable { if (getClass() != obj.getClass()) return false; LonLatZoom other = (LonLatZoom) obj; - if (Double.doubleToLongBits(lat) != Double.doubleToLongBits(other.lat)) - return false; - if (Double.doubleToLongBits(lon) != Double.doubleToLongBits(other.lon)) - return false; - if (Double.doubleToLongBits(zoom) != Double - .doubleToLongBits(other.zoom)) - return false; - return true; + return Double.doubleToLongBits(lat) == Double.doubleToLongBits(other.lat) && Double.doubleToLongBits(lon) == Double.doubleToLongBits(other.lon) && Double.doubleToLongBits(zoom) == Double.doubleToLongBits(other.zoom); } @Override diff --git a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java index 1bd092c736..6360bd1645 100644 --- a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java +++ b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java @@ -1,9 +1,5 @@ package com.mapbox.mapboxgl.lib; -import java.io.IOException; - -import org.apache.commons.io.Charsets; -import org.apache.commons.io.IOUtils; import org.json.JSONException; import org.json.JSONObject; @@ -12,6 +8,7 @@ import android.content.pm.PackageManager; import android.content.res.TypedArray; import android.graphics.PointF; import android.os.Bundle; +import android.support.annotation.NonNull; import android.util.AttributeSet; import android.util.Log; import android.view.GestureDetector; @@ -61,7 +58,7 @@ public class MapView extends SurfaceView { private String mStyleUrl; // Used to load map tiles - private String mApiKey; + private String mAccessToken; // Touch gesture detectors private GestureDetector mGestureDetector; @@ -90,19 +87,19 @@ public class MapView extends SurfaceView { // Called when no properties are being set from XML public MapView(Context context) { super(context); - initialize(context, null, 0); + initialize(context, null); } // Called when properties are being set from XML public MapView(Context context, AttributeSet attrs) { super(context, attrs); - initialize(context, attrs, 0); + initialize(context, attrs); } // Called when properties are being set from XML public MapView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); - initialize(context, attrs, defStyle); + initialize(context, attrs); } // @@ -110,7 +107,7 @@ public class MapView extends SurfaceView { // // Common initialization code goes here - private void initialize(Context context, AttributeSet attrs, int defStyle) { + private void initialize(Context context, AttributeSet attrs) { Log.v(TAG, "initialize"); // Check if we are in Eclipse UI editor @@ -128,10 +125,12 @@ public class MapView extends SurfaceView { // 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"; - mApiKey = "pk.eyJ1IjoibGpiYWRlIiwiYSI6IlJSQ0FEZ2MifQ.7mE4aOegldh3595AG9dxpQ"; + mAccessToken = "pk.eyJ1IjoibGpiYWRlIiwiYSI6IlJSQ0FEZ2MifQ.7mE4aOegldh3595AG9dxpQ"; // Create the NativeMapView - mNativeMapView = new NativeMapView(this, cachePath, mStyleUrl, mApiKey); + mNativeMapView = new NativeMapView(this, cachePath); + mNativeMapView.setStyleURL(mStyleUrl); + mNativeMapView.setAccessToken(mAccessToken); // Load the attributes TypedArray typedArray = context.obtainStyledAttributes(attrs, @@ -500,7 +499,7 @@ public class MapView extends SurfaceView { // Called when view is hidden and shown @Override - protected void onVisibilityChanged(View changedView, int visibility) { + protected void onVisibilityChanged(@NonNull View changedView, int visibility) { // Required by ZoomButtonController (from Android SDK documentation) if ((mZoomButtonsController != null) && (visibility != View.VISIBLE)) { mZoomButtonsController.setVisible(false); @@ -542,7 +541,7 @@ public class MapView extends SurfaceView { // Called when user touches the screen, all positions are absolute @Override - public boolean onTouchEvent(MotionEvent event) { + public boolean onTouchEvent(@NonNull MotionEvent event) { // Check and ignore non touch or left clicks if ((event.getButtonState() != 0) && (event.getButtonState() != MotionEvent.BUTTON_PRIMARY)) { @@ -563,11 +562,7 @@ public class MapView extends SurfaceView { case MotionEvent.ACTION_POINTER_DOWN: // Second pointer down - if (event.getPointerCount() == 2) { - mTwoTap = true; - } else { - mTwoTap = false; - } + mTwoTap = event.getPointerCount() == 2; break; case MotionEvent.ACTION_POINTER_UP: @@ -598,6 +593,7 @@ public class MapView extends SurfaceView { } // Do not change this code! It will break very easily. + // TODO fix up these warnings boolean retVal = rotateRetVal || scaleRetVal; retVal = mGestureDetector.onTouchEvent(event) || retVal; return retVal || super.onTouchEvent(event); @@ -871,7 +867,7 @@ public class MapView extends SurfaceView { // Called when the user presses a key, also called for repeating keys held // down @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { + public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) { // If the user has held the scroll key down for a while then accelerate // the scroll speed double scrollDist = event.getRepeatCount() >= 5 ? 50.0 : 10.0; @@ -1123,7 +1119,7 @@ public class MapView extends SurfaceView { // Called when the mouse pointer enters or exits the view // or when it fades in or out due to movement @Override - public boolean onHoverEvent(MotionEvent event) { + public boolean onHoverEvent(@NonNull MotionEvent event) { switch (event.getActionMasked()) { case MotionEvent.ACTION_HOVER_ENTER: case MotionEvent.ACTION_HOVER_MOVE: diff --git a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java index 5be250cf9a..56578eeb2d 100644 --- a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java +++ b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java @@ -1,10 +1,10 @@ package com.mapbox.mapboxgl.lib; -import java.util.Set; - import android.util.Log; import android.view.Surface; +import java.util.List; + // Class that wraps the native methods for convenience class NativeMapView { @@ -37,11 +37,11 @@ class NativeMapView { // Constructors // - public NativeMapView(MapView mapView, String cachePath, String styleUrl, String apiKey) { + public NativeMapView(MapView mapView, String cachePath) { mMapView = mapView; // Create the NativeMapView - mNativeMapViewPtr = nativeCreate(cachePath, styleUrl, apiKey); + mNativeMapViewPtr = nativeCreate(cachePath); } // @@ -80,6 +80,10 @@ class NativeMapView { nativeStop(mNativeMapViewPtr); } + public void run() { + nativeRun(mNativeMapViewPtr); + } + public void rerender() { nativeRerender(mNativeMapViewPtr); } @@ -92,6 +96,18 @@ class NativeMapView { nativeCleanup(mNativeMapViewPtr); } + public void terminate() { + nativeTerminate(mNativeMapViewPtr); + } + + public boolean needsSwap() { + return nativeNeedsSwap(mNativeMapViewPtr); + } + + public void swapped() { + nativeSwapped(mNativeMapViewPtr); + } + public void resize(int width, int height) { resize(width, height, 1.0f); } @@ -148,11 +164,15 @@ class NativeMapView { nativeResize(mNativeMapViewPtr, width, height, ratio, fbWidth, fbHeight); } - public void setAppliedClasses(Set<String> appliedClasses) { - nativeSetAppliedClasses(mNativeMapViewPtr, appliedClasses); + /*public void Set<StyleSource> getActiveSources() { + return nativeGetActiveSources(mNativeMapViewPtr); + }*/ + + public void setAppliedClasses(List<String> classes) { + nativeSetAppliedClasses(mNativeMapViewPtr, classes); } - public Set<String> getAppliedClasses() { + public List<String> getAppliedClasses() { return nativeGetAppliedClasses(mNativeMapViewPtr); } @@ -170,14 +190,30 @@ class NativeMapView { durationMilliseconds); } + public void setStyleURL(String url) { + nativeSetStyleURL(mNativeMapViewPtr, url); + } + public void setStyleJSON(String newStyleJSON) { - nativeSetStyleJSON(mNativeMapViewPtr, newStyleJSON); + setStyleJSON(newStyleJSON, ""); + } + + public void setStyleJSON(String newStyleJSON, String base) { + nativeSetStyleJSON(mNativeMapViewPtr, newStyleJSON, base); } public String getStyleJSON() { return nativeGetStyleJSON(mNativeMapViewPtr); } + public void setAccessToken(String accessToken) { + nativeSetAccessToken(mNativeMapViewPtr, accessToken); + } + + public String getAccessToken() { + return nativeGetAccessToken(mNativeMapViewPtr); + } + public void cancelTransitions() { nativeCancelTransitions(mNativeMapViewPtr); } @@ -339,6 +375,10 @@ class NativeMapView { return nativeGetDebug(mNativeMapViewPtr); } + public void setReachability(boolean status) { + nativeSetReachability(mNativeMapViewPtr, status); + } + // // Callbacks // @@ -359,7 +399,7 @@ class NativeMapView { super.finalize(); } - private native long nativeCreate(String cachePath, String styleUrl, String apiKey); + private native long nativeCreate(String cachePath); private native void nativeDestroy(long nativeMapViewPtr); @@ -380,31 +420,47 @@ class NativeMapView { private native void nativeStop(long nativeMapViewPtr); + private native void nativeRun(long nativeMapViewPtr); + private native void nativeRerender(long nativeMapViewPtr); private native void nativeUpdate(long nativeMapViewPtr); private native void nativeCleanup(long nativeMapViewPtr); + private native void nativeTerminate(long nativeMapViewPtr); + + private native boolean nativeNeedsSwap(long nativeMapViewPtr); + + private native void nativeSwapped(long nativeMapViewPtr); + private native void nativeResize(long nativeMapViewPtr, int width, int height, float ratio); private native void nativeResize(long nativeMapViewPtr, int width, int height, float ratio, int fbWidth, int fbHeight); + //private native void Set<StyleSource> nativeGetActiveSources(long nativeMapViewPtr); + private native void nativeSetAppliedClasses(long nativeMapViewPtr, - Set<String> appliedClasses); + List<String> classes); - private native Set<String> nativeGetAppliedClasses(long nativeMapViewPtr); + private native List<String> nativeGetAppliedClasses(long nativeMapViewPtr); private native void nativeSetDefaultTransitionDuration( long nativeMapViewPtr, long durationMilliseconds); + private native void nativeSetStyleURL(long nativeMapViewPtr, String url); + private native void nativeSetStyleJSON(long nativeMapViewPtr, - String newStyleJSON); + String newStyleJSON, String base); private native String nativeGetStyleJSON(long nativeMapViewPtr); + private native void nativeSetAccessToken(long nativeMapViewPtr, String accessToken); + + private native String nativeGetAccessToken(long nativeMapViewPtr); + private native void nativeCancelTransitions(long nativeMapViewPtr); private native void nativeMoveBy(long nativeMapViewPtr, double dx, @@ -473,4 +529,6 @@ class NativeMapView { private native void nativeToggleDebug(long nativeMapViewPtr); private native boolean nativeGetDebug(long nativeMapViewPtr); + + private native void nativeSetReachability(long nativeMapViewPtr, boolean status); } |