[android] add unknown source type

This commit is contained in:
Ivo van Dongen
2017-02-24 16:14:43 +02:00
committed by Ivo van Dongen
parent 3e48b377fd
commit 62e85c1224
5 changed files with 102 additions and 3 deletions

View File

@@ -0,0 +1,25 @@
package com.mapbox.mapboxsdk.style.sources;
import android.support.annotation.UiThread;
/**
* An unknown type of source
*/
@UiThread
public class UnknownSource extends Source {
/**
* Creates a UnknownSource.
*
* @param nativePtr pointer used by core
*/
UnknownSource(long nativePtr) {
super(nativePtr);
}
protected native void initialize();
@Override
protected native void finalize() throws Throwable;
}

View File

@@ -124,6 +124,8 @@ macro(mbgl_platform_core)
platform/android/src/style/sources/sources.hpp
platform/android/src/style/sources/raster_source.cpp
platform/android/src/style/sources/raster_source.hpp
platform/android/src/style/sources/unknown_source.cpp
platform/android/src/style/sources/unknown_source.hpp
platform/android/src/style/sources/vector_source.cpp
platform/android/src/style/sources/vector_source.hpp
platform/android/src/style/functions/stop.cpp

View File

@@ -8,6 +8,7 @@
#include "source.hpp"
#include "geojson_source.hpp"
#include "raster_source.hpp"
#include "unknown_source.hpp"
#include "vector_source.hpp"
namespace mbgl {
@@ -22,7 +23,7 @@ Source* initializeSourcePeer(mbgl::Map& map, mbgl::style::Source& coreSource) {
} else if (coreSource.is<mbgl::style::GeoJSONSource>()) {
source = new GeoJSONSource(map, *coreSource.as<mbgl::style::GeoJSONSource>());
} else {
throw new std::runtime_error("Source type not implemented");
source = new UnknownSource(map, coreSource);
}
return source;
@@ -37,9 +38,10 @@ jni::jobject* createJavaSourcePeer(jni::JNIEnv& env, mbgl::Map& map, mbgl::style
void registerNativeSources(jni::JNIEnv& env) {
Source::registerNative(env);
VectorSource::registerNative(env);
RasterSource::registerNative(env);
GeoJSONSource::registerNative(env);
RasterSource::registerNative(env);
UnknownSource::registerNative(env);
VectorSource::registerNative(env);
}
}

View File

@@ -0,0 +1,42 @@
#include "unknown_source.hpp"
namespace {
// Dummy initializer (We don't support initializing this from the JVM)
std::unique_ptr<mbgl::android::UnknownSource> init(jni::JNIEnv&) {
throw new std::runtime_error("UnknownSource should not be initialized from the JVM");
}
} // namespace
namespace mbgl {
namespace android {
UnknownSource::UnknownSource(mbgl::Map& map, mbgl::style::Source& coreSource)
: Source(map, coreSource) {
}
jni::Class<UnknownSource> UnknownSource::javaClass;
jni::jobject* UnknownSource::createJavaPeer(jni::JNIEnv& env) {
static auto constructor = UnknownSource::javaClass.template GetConstructor<jni::jlong>(env);
return UnknownSource::javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this));
}
void UnknownSource::registerNative(jni::JNIEnv& env) {
// Lookup the class
UnknownSource::javaClass = *jni::Class<UnknownSource>::Find(env).NewGlobalRef(env).release();
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
// Register the peer
jni::RegisterNativePeer<UnknownSource>(
env, UnknownSource::javaClass, "nativePtr",
init,
"initialize",
"finalize"
);
}
} // namespace android
} // namespace mbgl

View File

@@ -0,0 +1,28 @@
#pragma once
#include "source.hpp"
#include <mbgl/style/source.hpp>
#include <jni/jni.hpp>
namespace mbgl {
namespace android {
class UnknownSource : public Source {
public:
static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/sources/UnknownSource"; };
static jni::Class<UnknownSource> javaClass;
static void registerNative(jni::JNIEnv&);
UnknownSource(mbgl::Map&, mbgl::style::Source&);
~UnknownSource() = default;
jni::jobject* createJavaPeer(jni::JNIEnv&);
}; // class UnknownSource
} // namespace android
} // namespace mbgl