[android] - modularise the sdk
This commit is contained in:
@@ -20,7 +20,7 @@ public:
|
||||
|
||||
class HTTPRequest : public AsyncRequest {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/http/HTTPRequest"; };
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/http/NativeHttpRequest"; };
|
||||
|
||||
HTTPRequest(jni::JNIEnv&, const Resource&, FileSource::Callback);
|
||||
~HTTPRequest();
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
#include "text/collator_jni.hpp"
|
||||
#include "text/local_glyph_rasterizer_jni.hpp"
|
||||
#include "java/lang.hpp"
|
||||
#include "logger.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
@@ -192,6 +193,9 @@ void registerNatives(JavaVM *vm) {
|
||||
LocalGlyphRasterizer::registerNative(env);
|
||||
Locale::registerNative(env);
|
||||
Collator::registerNative(env);
|
||||
|
||||
// Logger
|
||||
Logger::registerNative(env);
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
||||
34
platform/android/src/logger.cpp
Normal file
34
platform/android/src/logger.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "logger.hpp"
|
||||
#include "java_types.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
void Logger::registerNative(jni::JNIEnv& env) {
|
||||
_class = *jni::Class<Logger>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
jni::Class<Logger> Logger::_class;
|
||||
|
||||
void Logger::log(jni::JNIEnv& env, EventSeverity severity, const std::string &msg) {
|
||||
auto tag = jni::Make<jni::String>(env, "Mbgl");
|
||||
auto message = jni::Make<jni::String>(env, msg);
|
||||
using Signature = void(jni::String, jni::String);
|
||||
|
||||
if (severity == EventSeverity::Debug) {
|
||||
auto static debug = _class.GetStaticMethod<Signature>(env, "d");
|
||||
_class.Call(env, debug, tag, message);
|
||||
} else if (severity == EventSeverity::Info) {
|
||||
auto static info = _class.GetStaticMethod<Signature>(env, "i");
|
||||
_class.Call(env, info, tag, message);
|
||||
} else if(severity == EventSeverity::Warning) {
|
||||
auto static warning = _class.GetStaticMethod<Signature>(env, "w");
|
||||
_class.Call(env, warning, tag, message);
|
||||
} else {
|
||||
auto static error = _class.GetStaticMethod<Signature>(env, "e");
|
||||
_class.Call(env, error, tag, message);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
24
platform/android/src/logger.hpp
Normal file
24
platform/android/src/logger.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/event.hpp>
|
||||
#include <jni/jni.hpp>
|
||||
#include "bitmap.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
class Logger {
|
||||
public:
|
||||
static constexpr auto Name() {
|
||||
return "com/mapbox/mapboxsdk/log/Logger";
|
||||
};
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
|
||||
static void log(jni::JNIEnv&, EventSeverity severity, const std::string &msg);
|
||||
|
||||
private:
|
||||
static jni::Class<Logger> _class;
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -1,34 +1,13 @@
|
||||
#include <mbgl/util/logging.hpp>
|
||||
|
||||
#include <android/log.h>
|
||||
#include "logger.hpp"
|
||||
#include "attach_env.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
namespace {
|
||||
|
||||
int severityToPriority(EventSeverity severity) {
|
||||
switch(severity) {
|
||||
case EventSeverity::Debug:
|
||||
return ANDROID_LOG_DEBUG;
|
||||
|
||||
case EventSeverity::Info:
|
||||
return ANDROID_LOG_INFO;
|
||||
|
||||
case EventSeverity::Warning:
|
||||
return ANDROID_LOG_WARN;
|
||||
|
||||
case EventSeverity::Error:
|
||||
return ANDROID_LOG_ERROR;
|
||||
|
||||
default:
|
||||
return ANDROID_LOG_VERBOSE;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void Log::platformRecord(EventSeverity severity, const std::string &msg) {
|
||||
__android_log_print(severityToPriority(severity), "mbgl", "%s", msg.c_str());
|
||||
auto env{ android::AttachEnv() };
|
||||
android::Logger::log(*env, severity, msg);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user