Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - simple JNI Style class
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Jan 23, 2018
1 parent bb76dce commit f588815
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

public class Style {

private long nativePtr;

// todo remove NativeMapView facade
private NativeMapView nativeMapView;

Expand All @@ -28,7 +30,7 @@ public class Style {

// todo make private
Style() {

initialize();
}

// todo remove
Expand Down Expand Up @@ -398,6 +400,15 @@ public String getJson() {
return json;
}

//
// Native methods
//

private native void initialize();

@Override
protected native void finalize() throws Throwable;

//
// Constants
//
Expand Down
2 changes: 2 additions & 0 deletions platform/android/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ add_library(mbgl-android STATIC
platform/android/src/style/position.hpp
platform/android/src/style/light.cpp
platform/android/src/style/light.hpp
platform/android/src/style/style.cpp
platform/android/src/style/style.hpp

# FileSource holder
platform/android/src/file_source.cpp
Expand Down
2 changes: 2 additions & 0 deletions platform/android/src/jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "style/layers/layers.hpp"
#include "style/sources/source.hpp"
#include "style/light.hpp"
#include "style/style.hpp"
#include "snapshotter/map_snapshotter.hpp"
#include "snapshotter/map_snapshot.hpp"
#include "text/local_glyph_rasterizer_jni.hpp"
Expand Down Expand Up @@ -170,6 +171,7 @@ void registerNatives(JavaVM *vm) {
ExponentialStops::registerNative(env);
IdentityStops::registerNative(env);
IntervalStops::registerNative(env);
Style::registerNative(env);

// Map
CameraPosition::registerNative(env);
Expand Down
32 changes: 32 additions & 0 deletions platform/android/src/style/style.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "style.hpp"

namespace mbgl {
namespace android {

Style::Style(jni::JNIEnv &) {

}

Style::~Style() {
}

jni::Class<Style> Style::javaClass;

void Style::registerNative(jni::JNIEnv& env) {
//Register classes
Style::javaClass = *jni::Class<Style>::Find(env).NewGlobalRef(env).release();

#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)

// Register the peer
jni::RegisterNativePeer<Style>(
env, Style::javaClass, "nativePtr",
std::make_unique<Style, JNIEnv&>,
"initialize",
"finalize"
);
}


} // namespace mbgl
} // namespace android
33 changes: 33 additions & 0 deletions platform/android/src/style/style.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include <mbgl/style/style.hpp>

#include <jni/jni.hpp>

namespace mbgl {
namespace android {

/**
* Peer class for the Android Style holder.
*/
class Style {
public:

// TODO move to style package
static constexpr auto Name() { return "com/mapbox/mapboxsdk/maps/Style"; };

Style(jni::JNIEnv &);

~Style();

static jni::Class<Style> javaClass;

// TODO add methods
static void registerNative(jni::JNIEnv &);

private:

};

}
}

0 comments on commit f588815

Please sign in to comment.