Save current version
This commit is contained in:
parent
f1a85e499b
commit
1334608a27
13 changed files with 214 additions and 165 deletions
|
@ -44,7 +44,7 @@ SKIA_SRC := skia
|
|||
|
||||
LOCAL_MODULE := osmand
|
||||
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/jni \
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH) \
|
||||
$(PROTOBUF_FOLDER) \
|
||||
$(SKIA_FOLDER)/include/core \
|
||||
$(SKIA_FOLDER)/include/utils \
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
#ifndef _OSMAND_BINARY_READ
|
||||
#define _OSMAND_BINARY_READ
|
||||
|
||||
#include <jni.h>
|
||||
#include <math.h>
|
||||
#include <android/log.h>
|
||||
|
@ -91,16 +94,20 @@ bool initMapStructure(io::CodedInputStream* input, BinaryMapFile* file) {
|
|||
|
||||
|
||||
void loadJniBinaryRead() {
|
||||
jstring js = env->NewStringUTF("Privet");
|
||||
__android_log_print(ANDROID_LOG_ERROR, "net.osmand", getString(js).c_str());
|
||||
}
|
||||
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_initBinaryMapFile(JNIEnv* ienv,
|
||||
jstring path) {
|
||||
std::string inputName = getString(path);
|
||||
jobject path) {
|
||||
// Verify that the version of the library that we linked against is
|
||||
const char* utf = ienv->GetStringUTFChars((jstring)path, NULL);
|
||||
std::string inputName(utf);
|
||||
ienv->ReleaseStringUTFChars((jstring)path, utf);
|
||||
|
||||
__android_log_print(ANDROID_LOG_ERROR, "net.osmand", inputName.c_str());
|
||||
|
||||
// std::string inputName = getString((jstring) path);
|
||||
// compatible with the version of the headers we compiled against.
|
||||
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
||||
std::map<std::string, BinaryMapFile*>::iterator iterator;
|
||||
|
@ -111,7 +118,7 @@ JNIEXPORT jboolean JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_initB
|
|||
|
||||
FILE* file = fopen(inputName.c_str(), "r");
|
||||
if (file == NULL) {
|
||||
sprintf(errorMsg, "File not initialised : %s", inputName.c_str());
|
||||
sprintf(errorMsg, "File could not be open to read from C : %s", inputName.c_str());
|
||||
__android_log_print(ANDROID_LOG_WARN, "net.osmand", errorMsg);
|
||||
return false;
|
||||
}
|
||||
|
@ -130,3 +137,5 @@ JNIEXPORT jboolean JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_initB
|
|||
openFiles.insert(std::pair<std::string, BinaryMapFile*>(inputName, mapFile));
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define _OSMAND_COMMON
|
||||
|
||||
#include <common.h>
|
||||
#include <android/log.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <hash_map>
|
||||
|
@ -10,20 +11,35 @@
|
|||
|
||||
JNIEnv* env;
|
||||
|
||||
JNIEnv* globalEnv(){
|
||||
return env;
|
||||
}
|
||||
|
||||
JNIEnv* setGlobalEnv(JNIEnv* e) {
|
||||
env = e;
|
||||
return e;
|
||||
}
|
||||
|
||||
extern void loadJniCommon();
|
||||
extern void loadJniBinaryRead();
|
||||
extern void loadJNIRenderingRules();
|
||||
extern void loadJniMapObjects();
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
if(vm->GetEnv((void **)&env, JNI_VERSION_1_4)){
|
||||
return JNI_ERR; /* JNI version not supported */
|
||||
}
|
||||
loadJniCommon();
|
||||
//extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
// if(vm->GetEnv((void **)&env, JNI_VERSION_1_2)){
|
||||
// return JNI_ERR; /* JNI version not supported */
|
||||
// }
|
||||
//
|
||||
// return JNI_VERSION_1_2;
|
||||
//}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_loadLibrary(JNIEnv* ienv) {
|
||||
// env = ienv;
|
||||
loadJniCommon();
|
||||
loadJNIRenderingRules();
|
||||
loadJniMapObjects();
|
||||
loadJniBinaryRead();
|
||||
return JNI_VERSION_1_4;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -20,10 +20,13 @@ const std::string EMPTY_STRING;
|
|||
const int WHITE_COLOR = -1;
|
||||
const int BLACK_COLOR = 0xff000000;
|
||||
|
||||
extern JNIEnv* env;
|
||||
JNIEnv* globalEnv();
|
||||
|
||||
JNIEnv* setGlobalEnv(JNIEnv* e);
|
||||
|
||||
// JNI Helpers
|
||||
extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved);
|
||||
//extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved);
|
||||
|
||||
std::string getString(jstring st);
|
||||
std::string getStringMethod(jobject o, jmethodID fid, int i);
|
||||
std::string getStringMethod(jobject o, jmethodID fid);
|
||||
|
@ -142,7 +145,7 @@ struct RenderingContext {
|
|||
int shadowLevelMax;
|
||||
|
||||
bool interrupted() {
|
||||
return env->GetBooleanField(originalRC, RenderingContext_interrupted);
|
||||
return globalEnv()->GetBooleanField(originalRC, RenderingContext_interrupted);
|
||||
}
|
||||
~RenderingContext() {
|
||||
for (uint i = 0; i < textToDraw.size(); i++) {
|
||||
|
|
|
@ -67,24 +67,24 @@ std::vector <BaseMapDataObject* > marshalObjects(jobjectArray binaryMapDataObjec
|
|||
{
|
||||
std::vector<BaseMapDataObject*> v;
|
||||
|
||||
const size_t size = env->GetArrayLength(binaryMapDataObjects);
|
||||
const size_t size = globalEnv()->GetArrayLength(binaryMapDataObjects);
|
||||
size_t i = 0;
|
||||
for (; i < size; i++) {
|
||||
jobject binaryMapDataObject = (jobject) env->GetObjectArrayElement(binaryMapDataObjects, i);
|
||||
if (env->IsInstanceOf(binaryMapDataObject, MultiPolygonClass)) {
|
||||
jobject binaryMapDataObject = (jobject) globalEnv()->GetObjectArrayElement(binaryMapDataObjects, i);
|
||||
if (globalEnv()->IsInstanceOf(binaryMapDataObject, MultiPolygonClass)) {
|
||||
MultiPolygonObject* o = new MultiPolygonObject();
|
||||
v.push_back((BaseMapDataObject* )o);
|
||||
o->layer = env->CallIntMethod(binaryMapDataObject, MultiPolygon_getLayer);
|
||||
o->layer = globalEnv()->CallIntMethod(binaryMapDataObject, MultiPolygon_getLayer);
|
||||
o->tag = getStringMethod(binaryMapDataObject, MultiPolygon_getTag);
|
||||
o->value = getStringMethod(binaryMapDataObject, MultiPolygon_getValue);
|
||||
|
||||
int boundsCount = env->CallIntMethod(binaryMapDataObject, MultiPolygon_getBoundsCount);
|
||||
int boundsCount = globalEnv()->CallIntMethod(binaryMapDataObject, MultiPolygon_getBoundsCount);
|
||||
for (int ji = 0; ji < boundsCount; ji++) {
|
||||
int cnt = env->CallIntMethod(binaryMapDataObject, MultiPolygon_getBoundPointsCount, ji);
|
||||
int cnt = globalEnv()->CallIntMethod(binaryMapDataObject, MultiPolygon_getBoundPointsCount, ji);
|
||||
std::vector<std::pair<int, int> > vs;
|
||||
for (int js = 0; js < cnt; js++) {
|
||||
int xt = env->CallIntMethod(binaryMapDataObject, MultiPolygon_getPoint31XTile, js, ji);
|
||||
int yt = env->CallIntMethod(binaryMapDataObject, MultiPolygon_getPoint31YTile, js, ji);
|
||||
int xt = globalEnv()->CallIntMethod(binaryMapDataObject, MultiPolygon_getPoint31XTile, js, ji);
|
||||
int yt = globalEnv()->CallIntMethod(binaryMapDataObject, MultiPolygon_getPoint31YTile, js, ji);
|
||||
vs.push_back( std::pair<int, int> (xt, yt) );
|
||||
}
|
||||
|
||||
|
@ -95,40 +95,40 @@ std::vector <BaseMapDataObject* > marshalObjects(jobjectArray binaryMapDataObjec
|
|||
|
||||
|
||||
} else {
|
||||
jintArray types = (jintArray) env->CallObjectMethod(binaryMapDataObject, BinaryMapDataObject_getTypes);
|
||||
jintArray types = (jintArray) globalEnv()->CallObjectMethod(binaryMapDataObject, BinaryMapDataObject_getTypes);
|
||||
if (types != NULL) {
|
||||
MapDataObject* o = new MapDataObject();
|
||||
jint sizeTypes = env->GetArrayLength(types);
|
||||
jint* els = env->GetIntArrayElements(types, NULL);
|
||||
jint sizeTypes = globalEnv()->GetArrayLength(types);
|
||||
jint* els = globalEnv()->GetIntArrayElements(types, NULL);
|
||||
int j = 0;
|
||||
for (; j < sizeTypes; j++) {
|
||||
int wholeType = els[j];
|
||||
o->types.push_back(wholeType);
|
||||
jobject pair = env->CallObjectMethod(binaryMapDataObject, BinaryMapDataObject_getTagValue, j);
|
||||
jobject pair = globalEnv()->CallObjectMethod(binaryMapDataObject, BinaryMapDataObject_getTagValue, j);
|
||||
if (pair != NULL) {
|
||||
std::string tag = getStringField(pair, TagValuePair_tag);
|
||||
std::string value = getStringField(pair, TagValuePair_value);
|
||||
o->tagValues.push_back( std::pair<std:: string, std::string>(tag, value));
|
||||
env->DeleteLocalRef(pair);
|
||||
globalEnv()->DeleteLocalRef(pair);
|
||||
} else {
|
||||
o->tagValues.push_back( std::pair<std:: string, std::string>(EMPTY_STRING, EMPTY_STRING));
|
||||
}
|
||||
}
|
||||
|
||||
jint sizePoints = env->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getPointsLength);
|
||||
jint sizePoints = globalEnv()->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getPointsLength);
|
||||
for (j = 0; j < sizePoints; j++) {
|
||||
int tx = env->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getPoint31XTile, j);
|
||||
int ty = env->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getPoint31YTile, j);
|
||||
int tx = globalEnv()->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getPoint31XTile, j);
|
||||
int ty = globalEnv()->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getPoint31YTile, j);
|
||||
o->points.push_back(std::pair<int, int>(tx, ty));
|
||||
}
|
||||
o->name = getStringMethod(binaryMapDataObject, BinaryMapDataObject_getName);
|
||||
o->highwayAttributes = env->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getHighwayAttributes);
|
||||
env->ReleaseIntArrayElements(types, els, JNI_ABORT);
|
||||
env->DeleteLocalRef(types);
|
||||
o->highwayAttributes = globalEnv()->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getHighwayAttributes);
|
||||
globalEnv()->ReleaseIntArrayElements(types, els, JNI_ABORT);
|
||||
globalEnv()->DeleteLocalRef(types);
|
||||
v.push_back((BaseMapDataObject* )o);
|
||||
}
|
||||
}
|
||||
env->DeleteLocalRef(binaryMapDataObject);
|
||||
globalEnv()->DeleteLocalRef(binaryMapDataObject);
|
||||
}
|
||||
|
||||
return v;
|
||||
|
@ -145,36 +145,36 @@ void deleteObjects(std::vector <BaseMapDataObject* > & v)
|
|||
|
||||
void loadJniMapObjects()
|
||||
{
|
||||
MultiPolygonClass = globalRef(env->FindClass("net/osmand/osm/MultyPolygon"));
|
||||
MultiPolygon_getTag = env->GetMethodID(MultiPolygonClass, "getTag", "()Ljava/lang/String;");
|
||||
MultiPolygon_getValue = env->GetMethodID(MultiPolygonClass, "getValue", "()Ljava/lang/String;");
|
||||
MultiPolygon_getName = env->GetMethodID(MultiPolygonClass, "getName", "(I)Ljava/lang/String;");
|
||||
MultiPolygon_getLayer = env->GetMethodID(MultiPolygonClass, "getLayer", "()I");
|
||||
MultiPolygon_getPoint31XTile = env->GetMethodID(MultiPolygonClass, "getPoint31XTile", "(II)I");
|
||||
MultiPolygon_getPoint31YTile = env->GetMethodID(MultiPolygonClass, "getPoint31YTile", "(II)I");
|
||||
MultiPolygon_getBoundsCount = env->GetMethodID(MultiPolygonClass, "getBoundsCount", "()I");
|
||||
MultiPolygon_getBoundPointsCount = env->GetMethodID(MultiPolygonClass, "getBoundPointsCount", "(I)I");
|
||||
MultiPolygonClass = globalRef(globalEnv()->FindClass("net/osmand/osm/MultyPolygon"));
|
||||
MultiPolygon_getTag = globalEnv()->GetMethodID(MultiPolygonClass, "getTag", "()Ljava/lang/String;");
|
||||
MultiPolygon_getValue = globalEnv()->GetMethodID(MultiPolygonClass, "getValue", "()Ljava/lang/String;");
|
||||
MultiPolygon_getName = globalEnv()->GetMethodID(MultiPolygonClass, "getName", "(I)Ljava/lang/String;");
|
||||
MultiPolygon_getLayer = globalEnv()->GetMethodID(MultiPolygonClass, "getLayer", "()I");
|
||||
MultiPolygon_getPoint31XTile = globalEnv()->GetMethodID(MultiPolygonClass, "getPoint31XTile", "(II)I");
|
||||
MultiPolygon_getPoint31YTile = globalEnv()->GetMethodID(MultiPolygonClass, "getPoint31YTile", "(II)I");
|
||||
MultiPolygon_getBoundsCount = globalEnv()->GetMethodID(MultiPolygonClass, "getBoundsCount", "()I");
|
||||
MultiPolygon_getBoundPointsCount = globalEnv()->GetMethodID(MultiPolygonClass, "getBoundPointsCount", "(I)I");
|
||||
|
||||
BinaryMapDataObjectClass = globalRef(env->FindClass("net/osmand/binary/BinaryMapDataObject"));
|
||||
BinaryMapDataObject_getPointsLength = env->GetMethodID(BinaryMapDataObjectClass, "getPointsLength", "()I");
|
||||
BinaryMapDataObject_getPoint31YTile = env->GetMethodID(BinaryMapDataObjectClass, "getPoint31YTile", "(I)I");
|
||||
BinaryMapDataObject_getPoint31XTile = env->GetMethodID(BinaryMapDataObjectClass, "getPoint31XTile", "(I)I");
|
||||
BinaryMapDataObject_getHighwayAttributes = env->GetMethodID(BinaryMapDataObjectClass, "getHighwayAttributes", "()I");
|
||||
BinaryMapDataObject_getTypes = env->GetMethodID(BinaryMapDataObjectClass, "getTypes", "()[I");
|
||||
BinaryMapDataObject_getName = env->GetMethodID(BinaryMapDataObjectClass, "getName", "()Ljava/lang/String;");
|
||||
BinaryMapDataObject_getTagValue = env->GetMethodID(BinaryMapDataObjectClass, "getTagValue",
|
||||
BinaryMapDataObjectClass = globalRef(globalEnv()->FindClass("net/osmand/binary/BinaryMapDataObject"));
|
||||
BinaryMapDataObject_getPointsLength = globalEnv()->GetMethodID(BinaryMapDataObjectClass, "getPointsLength", "()I");
|
||||
BinaryMapDataObject_getPoint31YTile = globalEnv()->GetMethodID(BinaryMapDataObjectClass, "getPoint31YTile", "(I)I");
|
||||
BinaryMapDataObject_getPoint31XTile = globalEnv()->GetMethodID(BinaryMapDataObjectClass, "getPoint31XTile", "(I)I");
|
||||
BinaryMapDataObject_getHighwayAttributes = globalEnv()->GetMethodID(BinaryMapDataObjectClass, "getHighwayAttributes", "()I");
|
||||
BinaryMapDataObject_getTypes = globalEnv()->GetMethodID(BinaryMapDataObjectClass, "getTypes", "()[I");
|
||||
BinaryMapDataObject_getName = globalEnv()->GetMethodID(BinaryMapDataObjectClass, "getName", "()Ljava/lang/String;");
|
||||
BinaryMapDataObject_getTagValue = globalEnv()->GetMethodID(BinaryMapDataObjectClass, "getTagValue",
|
||||
"(I)Lnet/osmand/binary/BinaryMapIndexReader$TagValuePair;");
|
||||
|
||||
TagValuePairClass = globalRef(env->FindClass("net/osmand/binary/BinaryMapIndexReader$TagValuePair"));
|
||||
TagValuePair_tag = env->GetFieldID(TagValuePairClass, "tag", "Ljava/lang/String;");
|
||||
TagValuePair_value = env->GetFieldID(TagValuePairClass, "value", "Ljava/lang/String;");
|
||||
TagValuePairClass = globalRef(globalEnv()->FindClass("net/osmand/binary/BinaryMapIndexReader$TagValuePair"));
|
||||
TagValuePair_tag = globalEnv()->GetFieldID(TagValuePairClass, "tag", "Ljava/lang/String;");
|
||||
TagValuePair_value = globalEnv()->GetFieldID(TagValuePairClass, "value", "Ljava/lang/String;");
|
||||
|
||||
}
|
||||
|
||||
|
||||
void unloadJniMapObjects()
|
||||
{
|
||||
env->DeleteGlobalRef( MultiPolygonClass );
|
||||
env->DeleteGlobalRef( BinaryMapDataObjectClass );
|
||||
env->DeleteGlobalRef( TagValuePairClass );
|
||||
globalEnv()->DeleteGlobalRef( MultiPolygonClass );
|
||||
globalEnv()->DeleteGlobalRef( BinaryMapDataObjectClass );
|
||||
globalEnv()->DeleteGlobalRef( TagValuePairClass );
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include <hash_map>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
jclass ListClass;
|
||||
jmethodID List_size;
|
||||
jmethodID List_get;
|
||||
|
@ -154,53 +153,53 @@ public:
|
|||
|
||||
private:
|
||||
void initDictionary() {
|
||||
jobject listDictionary = env->GetObjectField(javaStorage, RenderingRulesStorageClass_dictionary);
|
||||
uint sz = env->CallIntMethod(listDictionary, List_size);
|
||||
jobject listDictionary = globalEnv()->GetObjectField(javaStorage, RenderingRulesStorageClass_dictionary);
|
||||
uint sz = globalEnv()->CallIntMethod(listDictionary, List_size);
|
||||
uint i = 0;
|
||||
for (; i < sz; i++) {
|
||||
jstring st = (jstring) env->CallObjectMethod(listDictionary, List_get, i);
|
||||
jstring st = (jstring) globalEnv()->CallObjectMethod(listDictionary, List_get, i);
|
||||
// if(st != NULL)
|
||||
// {
|
||||
const char* utf = env->GetStringUTFChars(st, NULL);
|
||||
const char* utf = globalEnv()->GetStringUTFChars(st, NULL);
|
||||
std::string d = std::string(utf);
|
||||
|
||||
env->ReleaseStringUTFChars(st, utf);
|
||||
env->DeleteLocalRef(st);
|
||||
globalEnv()->ReleaseStringUTFChars(st, utf);
|
||||
globalEnv()->DeleteLocalRef(st);
|
||||
dictionary.push_back(d);
|
||||
dictionaryMap[d] = i;
|
||||
// }
|
||||
}
|
||||
env->DeleteLocalRef(listDictionary);
|
||||
globalEnv()->DeleteLocalRef(listDictionary);
|
||||
}
|
||||
|
||||
void initProperties() {
|
||||
jobject props = env->GetObjectField(javaStorage, RenderingRulesStorage_PROPS);
|
||||
jobject listProps = env->GetObjectField(props, RenderingRuleStorageProperties_rules);
|
||||
uint sz = env->CallIntMethod(listProps, List_size);
|
||||
jobject props = globalEnv()->GetObjectField(javaStorage, RenderingRulesStorage_PROPS);
|
||||
jobject listProps = globalEnv()->GetObjectField(props, RenderingRuleStorageProperties_rules);
|
||||
uint sz = globalEnv()->CallIntMethod(listProps, List_size);
|
||||
uint i = 0;
|
||||
for (; i < sz; i++) {
|
||||
jobject rulePrope = env->CallObjectMethod(listProps, List_get, i);
|
||||
bool input = env->GetIntField(rulePrope, RenderingRuleProperty_input);
|
||||
int type = env->GetIntField(rulePrope, RenderingRuleProperty_type);
|
||||
jobject rulePrope = globalEnv()->CallObjectMethod(listProps, List_get, i);
|
||||
bool input = globalEnv()->GetIntField(rulePrope, RenderingRuleProperty_input);
|
||||
int type = globalEnv()->GetIntField(rulePrope, RenderingRuleProperty_type);
|
||||
std::string name = getStringField(rulePrope, RenderingRuleProperty_attrName);
|
||||
RenderingRuleProperty* prop = new RenderingRuleProperty(type, input, name, i);
|
||||
properties.push_back(*prop);
|
||||
propertyMap[name] = prop;
|
||||
env->DeleteLocalRef(rulePrope);
|
||||
globalEnv()->DeleteLocalRef(rulePrope);
|
||||
}
|
||||
env->DeleteLocalRef(props);
|
||||
env->DeleteLocalRef(listProps);
|
||||
globalEnv()->DeleteLocalRef(props);
|
||||
globalEnv()->DeleteLocalRef(listProps);
|
||||
|
||||
}
|
||||
|
||||
void initRules() {
|
||||
for (int i = 1; i < SIZE_STATES; i++) {
|
||||
jobjectArray rules = (jobjectArray) env->CallObjectMethod(javaStorage, RenderingRulesStorage_getRules, i);
|
||||
jsize len = env->GetArrayLength(rules);
|
||||
jobjectArray rules = (jobjectArray) globalEnv()->CallObjectMethod(javaStorage, RenderingRulesStorage_getRules, i);
|
||||
jsize len = globalEnv()->GetArrayLength(rules);
|
||||
for (jsize j = 0; j < len; j++) {
|
||||
jobject rRule = env->GetObjectArrayElement(rules, j);
|
||||
jobject rRule = globalEnv()->GetObjectArrayElement(rules, j);
|
||||
RenderingRule* rule = createRenderingRule(rRule);
|
||||
env->DeleteLocalRef(rRule);
|
||||
globalEnv()->DeleteLocalRef(rRule);
|
||||
if (rule != NULL) {
|
||||
|
||||
jsize psz = rule->properties.size();
|
||||
|
@ -219,39 +218,39 @@ private:
|
|||
}
|
||||
}
|
||||
}
|
||||
env->DeleteLocalRef(rules);
|
||||
globalEnv()->DeleteLocalRef(rules);
|
||||
}
|
||||
}
|
||||
|
||||
RenderingRule* createRenderingRule(jobject rRule)
|
||||
{
|
||||
RenderingRule* rule = new RenderingRule;
|
||||
jobjectArray props = (jobjectArray)env->GetObjectField(rRule, RenderingRule_properties);
|
||||
jintArray intProps = (jintArray)env->GetObjectField(rRule, RenderingRule_intProperties);
|
||||
jfloatArray floatProps = (jfloatArray) env->GetObjectField(rRule, RenderingRule_floatProperties);
|
||||
jobject ifChildren = env->GetObjectField(rRule, RenderingRule_ifChildren);
|
||||
jobject ifElseChildren = env->GetObjectField(rRule, RenderingRule_ifElseChildren);
|
||||
jobjectArray props = (jobjectArray)globalEnv()->GetObjectField(rRule, RenderingRule_properties);
|
||||
jintArray intProps = (jintArray)globalEnv()->GetObjectField(rRule, RenderingRule_intProperties);
|
||||
jfloatArray floatProps = (jfloatArray) globalEnv()->GetObjectField(rRule, RenderingRule_floatProperties);
|
||||
jobject ifChildren = globalEnv()->GetObjectField(rRule, RenderingRule_ifChildren);
|
||||
jobject ifElseChildren = globalEnv()->GetObjectField(rRule, RenderingRule_ifElseChildren);
|
||||
|
||||
jsize sz = env->GetArrayLength(props);
|
||||
jsize sz = globalEnv()->GetArrayLength(props);
|
||||
|
||||
if (floatProps != NULL) {
|
||||
jfloat* fe = env->GetFloatArrayElements(floatProps, NULL);
|
||||
jfloat* fe = globalEnv()->GetFloatArrayElements(floatProps, NULL);
|
||||
for (int j = 0; j < sz; j++) {
|
||||
rule->floatProperties.push_back(fe[j]);
|
||||
}
|
||||
env->ReleaseFloatArrayElements(floatProps, fe, JNI_ABORT);
|
||||
env->DeleteLocalRef(floatProps);
|
||||
globalEnv()->ReleaseFloatArrayElements(floatProps, fe, JNI_ABORT);
|
||||
globalEnv()->DeleteLocalRef(floatProps);
|
||||
} else {
|
||||
rule->floatProperties.assign(sz, 0);
|
||||
}
|
||||
|
||||
if (intProps != NULL) {
|
||||
jint* ie = env->GetIntArrayElements(intProps, NULL);
|
||||
jint* ie = globalEnv()->GetIntArrayElements(intProps, NULL);
|
||||
for (int j = 0; j < sz; j++) {
|
||||
rule->intProperties.push_back(ie[j]);
|
||||
}
|
||||
env->ReleaseIntArrayElements(intProps, ie, JNI_ABORT);
|
||||
env->DeleteLocalRef(intProps);
|
||||
globalEnv()->ReleaseIntArrayElements(intProps, ie, JNI_ABORT);
|
||||
globalEnv()->DeleteLocalRef(intProps);
|
||||
} else {
|
||||
rule->intProperties.assign(sz, -1);
|
||||
}
|
||||
|
@ -260,32 +259,32 @@ private:
|
|||
|
||||
for(jsize i = 0; i<sz;i++)
|
||||
{
|
||||
jobject prop = env->GetObjectArrayElement(props, i);
|
||||
jobject prop = globalEnv()->GetObjectArrayElement(props, i);
|
||||
std::string attr = getStringField(prop, RenderingRuleProperty_attrName);
|
||||
RenderingRuleProperty* p = getProperty(attr.c_str());
|
||||
rule->properties.push_back(p);
|
||||
env->DeleteLocalRef(prop);
|
||||
globalEnv()->DeleteLocalRef(prop);
|
||||
}
|
||||
env->DeleteLocalRef(props);
|
||||
globalEnv()->DeleteLocalRef(props);
|
||||
|
||||
if (ifChildren != NULL) {
|
||||
sz = env->CallIntMethod(ifChildren, List_size);
|
||||
sz = globalEnv()->CallIntMethod(ifChildren, List_size);
|
||||
for (jsize i = 0; i < sz; i++) {
|
||||
jobject o = env->CallObjectMethod(ifChildren, List_get, i);
|
||||
jobject o = globalEnv()->CallObjectMethod(ifChildren, List_get, i);
|
||||
rule->ifChildren.push_back(*createRenderingRule(o));
|
||||
env->DeleteLocalRef(o);
|
||||
globalEnv()->DeleteLocalRef(o);
|
||||
}
|
||||
env->DeleteLocalRef(ifChildren);
|
||||
globalEnv()->DeleteLocalRef(ifChildren);
|
||||
}
|
||||
|
||||
if (ifElseChildren != NULL) {
|
||||
sz = env->CallIntMethod(ifElseChildren, List_size);
|
||||
sz = globalEnv()->CallIntMethod(ifElseChildren, List_size);
|
||||
for (jsize i = 0; i < sz; i++) {
|
||||
jobject o = env->CallObjectMethod(ifElseChildren, List_get, i);
|
||||
jobject o = globalEnv()->CallObjectMethod(ifElseChildren, List_get, i);
|
||||
rule->ifElseChildren.push_back(*createRenderingRule(o));
|
||||
env->DeleteLocalRef(o);
|
||||
globalEnv()->DeleteLocalRef(o);
|
||||
}
|
||||
env->DeleteLocalRef(ifElseChildren);
|
||||
globalEnv()->DeleteLocalRef(ifElseChildren);
|
||||
}
|
||||
|
||||
return rule;
|
||||
|
@ -399,68 +398,68 @@ private :
|
|||
void initObject(jobject rrs)
|
||||
{
|
||||
jsize sz;
|
||||
jobjectArray oa = (jobjectArray ) env->GetObjectField(rrs, RenderingRuleSearchRequest_props);
|
||||
sz = env->GetArrayLength(oa);
|
||||
jobjectArray oa = (jobjectArray ) globalEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_props);
|
||||
sz = globalEnv()->GetArrayLength(oa);
|
||||
std::vector<RenderingRuleProperty*> requestProps;
|
||||
for(jsize i=0; i<sz; i++)
|
||||
{
|
||||
jobject prop = env->GetObjectArrayElement(oa, i);
|
||||
jobject prop = globalEnv()->GetObjectArrayElement(oa, i);
|
||||
std::string attr = getStringField(prop, RenderingRuleProperty_attrName);
|
||||
RenderingRuleProperty* p = storage -> getProperty(attr.c_str());
|
||||
requestProps.push_back(p);
|
||||
env->DeleteLocalRef(prop);
|
||||
globalEnv()->DeleteLocalRef(prop);
|
||||
}
|
||||
env->DeleteLocalRef(oa);
|
||||
globalEnv()->DeleteLocalRef(oa);
|
||||
sz = storage->getPropertiesSize();
|
||||
{
|
||||
values = new int[sz];
|
||||
jintArray ia = (jintArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_values);
|
||||
jint* ie = env->GetIntArrayElements(ia, NULL);
|
||||
jintArray ia = (jintArray) globalEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_values);
|
||||
jint* ie = globalEnv()->GetIntArrayElements(ia, NULL);
|
||||
for(int i=0; i<sz; i++){
|
||||
values[requestProps.at(i)->id] = ie[i];
|
||||
}
|
||||
env->ReleaseIntArrayElements(ia, ie, JNI_ABORT);
|
||||
env->DeleteLocalRef(ia);
|
||||
globalEnv()->ReleaseIntArrayElements(ia, ie, JNI_ABORT);
|
||||
globalEnv()->DeleteLocalRef(ia);
|
||||
}
|
||||
|
||||
{
|
||||
fvalues = new float[sz];
|
||||
jfloatArray ia = (jfloatArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_fvalues);
|
||||
jfloat* ie = env->GetFloatArrayElements(ia, NULL);
|
||||
jfloatArray ia = (jfloatArray) globalEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_fvalues);
|
||||
jfloat* ie = globalEnv()->GetFloatArrayElements(ia, NULL);
|
||||
for (int i = 0; i < sz; i++) {
|
||||
fvalues[requestProps.at(i)->id] = ie[i];
|
||||
}
|
||||
env->ReleaseFloatArrayElements(ia, ie, JNI_ABORT);
|
||||
env->DeleteLocalRef(ia);
|
||||
globalEnv()->ReleaseFloatArrayElements(ia, ie, JNI_ABORT);
|
||||
globalEnv()->DeleteLocalRef(ia);
|
||||
}
|
||||
|
||||
{
|
||||
savedValues = new int[sz];
|
||||
jintArray ia = (jintArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_values);
|
||||
jint* ie = env->GetIntArrayElements(ia, NULL);
|
||||
jintArray ia = (jintArray) globalEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_values);
|
||||
jint* ie = globalEnv()->GetIntArrayElements(ia, NULL);
|
||||
for (int i = 0; i < sz; i++) {
|
||||
savedValues[requestProps.at(i)->id] = ie[i];
|
||||
}
|
||||
env->ReleaseIntArrayElements(ia, ie, JNI_ABORT);
|
||||
env->DeleteLocalRef(ia);
|
||||
globalEnv()->ReleaseIntArrayElements(ia, ie, JNI_ABORT);
|
||||
globalEnv()->DeleteLocalRef(ia);
|
||||
}
|
||||
|
||||
{
|
||||
savedFvalues = new float[sz];
|
||||
jfloatArray ia = (jfloatArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_fvalues);
|
||||
jfloat* ie = env->GetFloatArrayElements(ia, NULL);
|
||||
jfloatArray ia = (jfloatArray) globalEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_fvalues);
|
||||
jfloat* ie = globalEnv()->GetFloatArrayElements(ia, NULL);
|
||||
for (int i = 0; i < sz; i++) {
|
||||
savedFvalues[requestProps.at(i)->id] = ie[i];
|
||||
}
|
||||
env->ReleaseFloatArrayElements(ia, ie, JNI_ABORT);
|
||||
env->DeleteLocalRef(ia);
|
||||
globalEnv()->ReleaseFloatArrayElements(ia, ie, JNI_ABORT);
|
||||
globalEnv()->DeleteLocalRef(ia);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
RenderingRuleSearchRequest(jobject rrs) : renderingRuleSearch(rrs) {
|
||||
jobject storage = env->GetObjectField(rrs, RenderingRuleSearchRequest_storage);
|
||||
jobject storage = globalEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_storage);
|
||||
if(defaultStorage == NULL || defaultStorage->javaStorage != storage){
|
||||
// multi threadn will not work?
|
||||
if(defaultStorage != NULL){
|
||||
|
@ -468,7 +467,7 @@ public:
|
|||
}
|
||||
defaultStorage = new RenderingRulesStorage(storage);
|
||||
}
|
||||
env->DeleteLocalRef(storage);
|
||||
globalEnv()->DeleteLocalRef(storage);
|
||||
this->storage = defaultStorage;
|
||||
PROPS = new RenderingRulesStorageProperties(this->storage);
|
||||
initObject(rrs);
|
||||
|
@ -662,51 +661,51 @@ RenderingRuleSearchRequest* initSearchRequest(jobject renderingRuleSearchRequest
|
|||
|
||||
void loadJNIRenderingRules()
|
||||
{
|
||||
RenderingRuleClass = globalRef(env->FindClass("net/osmand/render/RenderingRule"));
|
||||
RenderingRule_properties = env->GetFieldID(RenderingRuleClass, "properties", "[Lnet/osmand/render/RenderingRuleProperty;");
|
||||
RenderingRule_intProperties = env->GetFieldID(RenderingRuleClass, "intProperties", "[I");
|
||||
RenderingRule_floatProperties = env->GetFieldID(RenderingRuleClass, "floatProperties", "[F");
|
||||
RenderingRule_ifElseChildren = env->GetFieldID(RenderingRuleClass, "ifElseChildren", "Ljava/util/List;");
|
||||
RenderingRule_ifChildren = env->GetFieldID(RenderingRuleClass, "ifChildren", "Ljava/util/List;");
|
||||
RenderingRuleClass = globalRef(globalEnv()->FindClass("net/osmand/render/RenderingRule"));
|
||||
RenderingRule_properties = globalEnv()->GetFieldID(RenderingRuleClass, "properties", "[Lnet/osmand/render/RenderingRuleProperty;");
|
||||
RenderingRule_intProperties = globalEnv()->GetFieldID(RenderingRuleClass, "intProperties", "[I");
|
||||
RenderingRule_floatProperties = globalEnv()->GetFieldID(RenderingRuleClass, "floatProperties", "[F");
|
||||
RenderingRule_ifElseChildren = globalEnv()->GetFieldID(RenderingRuleClass, "ifElseChildren", "Ljava/util/List;");
|
||||
RenderingRule_ifChildren = globalEnv()->GetFieldID(RenderingRuleClass, "ifChildren", "Ljava/util/List;");
|
||||
|
||||
RenderingRuleStoragePropertiesClass = globalRef(env->FindClass("net/osmand/render/RenderingRuleStorageProperties"));
|
||||
RenderingRuleStorageProperties_rules = env->GetFieldID(RenderingRuleStoragePropertiesClass, "rules", "Ljava/util/List;");
|
||||
RenderingRuleStoragePropertiesClass = globalRef(globalEnv()->FindClass("net/osmand/render/RenderingRuleStorageProperties"));
|
||||
RenderingRuleStorageProperties_rules = globalEnv()->GetFieldID(RenderingRuleStoragePropertiesClass, "rules", "Ljava/util/List;");
|
||||
|
||||
RenderingRulePropertyClass = globalRef(env->FindClass("net/osmand/render/RenderingRuleProperty"));
|
||||
RenderingRuleProperty_type = env->GetFieldID(RenderingRulePropertyClass, "type", "I");
|
||||
RenderingRuleProperty_input = env->GetFieldID(RenderingRulePropertyClass, "input", "Z");
|
||||
RenderingRuleProperty_attrName = env->GetFieldID(RenderingRulePropertyClass, "attrName", "Ljava/lang/String;");
|
||||
RenderingRulePropertyClass = globalRef(globalEnv()->FindClass("net/osmand/render/RenderingRuleProperty"));
|
||||
RenderingRuleProperty_type = globalEnv()->GetFieldID(RenderingRulePropertyClass, "type", "I");
|
||||
RenderingRuleProperty_input = globalEnv()->GetFieldID(RenderingRulePropertyClass, "input", "Z");
|
||||
RenderingRuleProperty_attrName = globalEnv()->GetFieldID(RenderingRulePropertyClass, "attrName", "Ljava/lang/String;");
|
||||
|
||||
RenderingRulesStorageClass = globalRef(env->FindClass("net/osmand/render/RenderingRulesStorage"));
|
||||
RenderingRulesStorageClass_dictionary = env->GetFieldID(RenderingRulesStorageClass, "dictionary", "Ljava/util/List;");
|
||||
RenderingRulesStorage_PROPS = env->GetFieldID(RenderingRulesStorageClass, "PROPS",
|
||||
RenderingRulesStorageClass = globalRef(globalEnv()->FindClass("net/osmand/render/RenderingRulesStorage"));
|
||||
RenderingRulesStorageClass_dictionary = globalEnv()->GetFieldID(RenderingRulesStorageClass, "dictionary", "Ljava/util/List;");
|
||||
RenderingRulesStorage_PROPS = globalEnv()->GetFieldID(RenderingRulesStorageClass, "PROPS",
|
||||
"Lnet/osmand/render/RenderingRuleStorageProperties;");
|
||||
RenderingRulesStorage_getRules = env->GetMethodID(RenderingRulesStorageClass, "getRules",
|
||||
RenderingRulesStorage_getRules = globalEnv()->GetMethodID(RenderingRulesStorageClass, "getRules",
|
||||
"(I)[Lnet/osmand/render/RenderingRule;");
|
||||
|
||||
ListClass = globalRef(env->FindClass("java/util/List"));
|
||||
List_size = env->GetMethodID(ListClass, "size", "()I");
|
||||
List_get = env->GetMethodID(ListClass, "get", "(I)Ljava/lang/Object;");
|
||||
ListClass = globalRef(globalEnv()->FindClass("java/util/List"));
|
||||
List_size = globalEnv()->GetMethodID(ListClass, "size", "()I");
|
||||
List_get = globalEnv()->GetMethodID(ListClass, "get", "(I)Ljava/lang/Object;");
|
||||
|
||||
RenderingRuleSearchRequestClass = globalRef(env->FindClass("net/osmand/render/RenderingRuleSearchRequest"));
|
||||
RenderingRuleSearchRequest_storage = env->GetFieldID(RenderingRuleSearchRequestClass,
|
||||
RenderingRuleSearchRequestClass = globalRef(globalEnv()->FindClass("net/osmand/render/RenderingRuleSearchRequest"));
|
||||
RenderingRuleSearchRequest_storage = globalEnv()->GetFieldID(RenderingRuleSearchRequestClass,
|
||||
"storage", "Lnet/osmand/render/RenderingRulesStorage;");
|
||||
RenderingRuleSearchRequest_props = env->GetFieldID(RenderingRuleSearchRequestClass,
|
||||
RenderingRuleSearchRequest_props = globalEnv()->GetFieldID(RenderingRuleSearchRequestClass,
|
||||
"props", "[Lnet/osmand/render/RenderingRuleProperty;");
|
||||
RenderingRuleSearchRequest_values = env->GetFieldID(RenderingRuleSearchRequestClass, "values", "[I");
|
||||
RenderingRuleSearchRequest_fvalues = env->GetFieldID(RenderingRuleSearchRequestClass, "fvalues", "[F");
|
||||
RenderingRuleSearchRequest_savedValues = env->GetFieldID(RenderingRuleSearchRequestClass, "savedValues", "[I");
|
||||
RenderingRuleSearchRequest_savedFvalues = env->GetFieldID(RenderingRuleSearchRequestClass, "savedFvalues", "[F");
|
||||
RenderingRuleSearchRequest_values = globalEnv()->GetFieldID(RenderingRuleSearchRequestClass, "values", "[I");
|
||||
RenderingRuleSearchRequest_fvalues = globalEnv()->GetFieldID(RenderingRuleSearchRequestClass, "fvalues", "[F");
|
||||
RenderingRuleSearchRequest_savedValues = globalEnv()->GetFieldID(RenderingRuleSearchRequestClass, "savedValues", "[I");
|
||||
RenderingRuleSearchRequest_savedFvalues = globalEnv()->GetFieldID(RenderingRuleSearchRequestClass, "savedFvalues", "[F");
|
||||
|
||||
}
|
||||
|
||||
void unloadJniRenderRules() {
|
||||
env->DeleteGlobalRef(RenderingRuleSearchRequestClass);
|
||||
env->DeleteGlobalRef(RenderingRuleClass);
|
||||
env->DeleteGlobalRef(RenderingRulePropertyClass);
|
||||
env->DeleteGlobalRef(RenderingRuleStoragePropertiesClass);
|
||||
env->DeleteGlobalRef(RenderingRulesStorageClass);
|
||||
env->DeleteGlobalRef(ListClass);
|
||||
globalEnv()->DeleteGlobalRef(RenderingRuleSearchRequestClass);
|
||||
globalEnv()->DeleteGlobalRef(RenderingRuleClass);
|
||||
globalEnv()->DeleteGlobalRef(RenderingRulePropertyClass);
|
||||
globalEnv()->DeleteGlobalRef(RenderingRuleStoragePropertiesClass);
|
||||
globalEnv()->DeleteGlobalRef(RenderingRulesStorageClass);
|
||||
globalEnv()->DeleteGlobalRef(ListClass);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
#ifndef _OSMAND_RENDERING
|
||||
#define _OSMAND_RENDERING
|
||||
|
||||
#include <jni.h>
|
||||
#include <math.h>
|
||||
#include <android/log.h>
|
||||
|
@ -22,6 +25,7 @@
|
|||
#include "textdraw.cpp"
|
||||
#include "mapObjects.cpp"
|
||||
|
||||
extern JNIEnv* globalEnv();
|
||||
char debugMessage[1024];
|
||||
|
||||
void calcPoint(MapDataObject* mObj, jint ind, RenderingContext* rc) {
|
||||
|
@ -697,6 +701,7 @@ extern "C" {
|
|||
JNIEXPORT jstring JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_generateRendering( JNIEnv* ienv,
|
||||
jobject obj, jobject renderingContext, jobjectArray binaryMapDataObjects, jobject bmpObj,
|
||||
jboolean useEnglishNames, jobject renderingRuleSearchRequest, jint defaultColor) {
|
||||
setGlobalEnv(ienv);
|
||||
SkBitmap* bmp = getNativeBitmap(bmpObj);
|
||||
sprintf(debugMessage, "Image w:%d h:%d !", bmp->width(), bmp->height());
|
||||
__android_log_print(ANDROID_LOG_WARN, "net.osmand", debugMessage);
|
||||
|
@ -741,7 +746,7 @@ JNIEXPORT jstring JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_genera
|
|||
#else
|
||||
sprintf(debugMessage, "Native ok (init %d, rendering %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime());
|
||||
#endif
|
||||
jstring result = env->NewStringUTF( debugMessage);
|
||||
jstring result = globalEnv()->NewStringUTF( debugMessage);
|
||||
|
||||
// unloadLibrary();
|
||||
return result;
|
||||
|
@ -750,3 +755,4 @@ JNIEXPORT jstring JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_genera
|
|||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /**/
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
set solib-search-path /home/victor/projects/OsmAnd/git/OsmAnd/obj/local/armeabi
|
||||
directory /home/victor/projects/android-ndk-r6b/platforms/android-8/arch-arm/usr/include /home/victor/projects/OsmAnd/git/OsmAnd/jni/osmand/jni /home/victor/projects/OsmAnd/git/OsmAnd/jni/osmand/../protobuf /home/victor/projects/android//external/skia/include/core /home/victor/projects/android//external/skia/include/utils /home/victor/projects/android//external/skia/include/config /home/victor/projects/android//external/skia/include/effects /home/victor/projects/android//external/skia/include/utils/android /home/victor/projects/android//external/skia/src/core /home/victor/projects/android//system/core/include /home/victor/projects/android//frameworks/base/include /home/victor/projects/android-ndk-r6b/sources/cxx-stl/stlport/stlport /home/victor/projects/android-ndk-r6b/sources/cxx-stl/system/include /home/victor/projects/OsmAnd/git/OsmAnd/jni/protobuf
|
||||
directory /home/victor/projects/android-ndk-r6b/platforms/android-8/arch-arm/usr/include /home/victor/projects/OsmAnd/git/OsmAnd/jni/osmand /home/victor/projects/OsmAnd/git/OsmAnd/jni/osmand/../protobuf /home/victor/projects/android//external/skia/include/core /home/victor/projects/android//external/skia/include/utils /home/victor/projects/android//external/skia/include/config /home/victor/projects/android//external/skia/include/effects /home/victor/projects/android//external/skia/include/utils/android /home/victor/projects/android//external/skia/src/core /home/victor/projects/android//system/core/include /home/victor/projects/android//frameworks/base/include /home/victor/projects/android-ndk-r6b/sources/cxx-stl/stlport/stlport /home/victor/projects/android-ndk-r6b/sources/cxx-stl/system/include /home/victor/projects/OsmAnd/git/OsmAnd/jni/protobuf
|
||||
|
|
Binary file not shown.
|
@ -10,6 +10,7 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.ResourceManager;
|
||||
import net.osmand.plus.activities.search.SearchActivity;
|
||||
import net.osmand.plus.render.MapRenderRepositories;
|
||||
import net.osmand.plus.render.NativeOsmandLibrary;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
|
|
|
@ -22,6 +22,7 @@ import net.osmand.plus.PoiFiltersHelper;
|
|||
import net.osmand.plus.ProgressDialogImplementation;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.ResourceManager;
|
||||
import net.osmand.plus.render.NativeOsmandLibrary;
|
||||
import net.osmand.plus.render.RendererRegistry;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.voice.CommandPlayer;
|
||||
|
@ -301,6 +302,7 @@ public class OsmandApplication extends Application {
|
|||
public void run() {
|
||||
List<String> warnings = null;
|
||||
try {
|
||||
NativeOsmandLibrary.preloadLibrary();
|
||||
warnings = manager.reloadIndexes(startDialog);
|
||||
player = null;
|
||||
SavingTrackHelper helper = new SavingTrackHelper(OsmandApplication.this);
|
||||
|
@ -309,6 +311,7 @@ public class OsmandApplication extends Application {
|
|||
warnings.addAll(helper.saveDataToGpx());
|
||||
}
|
||||
helper.close();
|
||||
// NativeOsmandLibrary.loadLibrary();
|
||||
|
||||
} finally {
|
||||
synchronized (OsmandApplication.this) {
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.io.RandomAccessFile;
|
|||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
|
@ -57,6 +58,7 @@ public class MapRenderRepositories {
|
|||
private final Context context;
|
||||
private Handler handler;
|
||||
private Map<String, BinaryMapIndexReader> files = new LinkedHashMap<String, BinaryMapIndexReader>();
|
||||
private Set<String> nativeFiles = new HashSet<String>();
|
||||
private OsmandRenderer renderer;
|
||||
|
||||
private static String BASEMAP_NAME = "basemap";
|
||||
|
@ -100,6 +102,7 @@ public class MapRenderRepositories {
|
|||
long start = System.currentTimeMillis();
|
||||
if (files.containsKey(file.getAbsolutePath())) {
|
||||
closeConnection(files.get(file.getAbsolutePath()), file.getAbsolutePath());
|
||||
|
||||
}
|
||||
RandomAccessFile raf = null;
|
||||
BinaryMapIndexReader reader = null;
|
||||
|
@ -129,11 +132,6 @@ public class MapRenderRepositories {
|
|||
}
|
||||
throw oome;
|
||||
}
|
||||
if(prefs.NATIVE_RENDERING.get()){
|
||||
if(NativeOsmandLibrary.initBinaryMapFile(file.getAbsolutePath())){
|
||||
log.debug("Native resource " + file.getAbsolutePath() + " initialized"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Initializing db " + file.getAbsolutePath() + " " + (System.currentTimeMillis() - start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
|
@ -150,6 +148,7 @@ public class MapRenderRepositories {
|
|||
|
||||
protected void closeConnection(BinaryMapIndexReader c, String file) {
|
||||
files.remove(file);
|
||||
nativeFiles.remove(file);
|
||||
try {
|
||||
c.close();
|
||||
} catch (IOException e) {
|
||||
|
@ -303,6 +302,15 @@ public class MapRenderRepositories {
|
|||
if (basemapSearch && !mapName.toLowerCase().contains(BASEMAP_NAME)) {
|
||||
continue;
|
||||
}
|
||||
if(prefs.NATIVE_RENDERING.get()){
|
||||
if (!nativeFiles.contains(mapName)) {
|
||||
nativeFiles.add(mapName);
|
||||
if (NativeOsmandLibrary.initBinaryMapFile(mapName)) {
|
||||
continue;
|
||||
}
|
||||
log.debug("Native resource " + mapName + " initialized"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
BinaryMapIndexReader c = files.get(mapName);
|
||||
searchRequest = BinaryMapIndexReader.buildSearchRequest(leftX, rightX, topY, bottomY, zoom, searchFilter);
|
||||
List<BinaryMapDataObject> res = c.searchMapIndex(searchRequest);
|
||||
|
|
|
@ -12,6 +12,10 @@ public class NativeOsmandLibrary {
|
|||
System.loadLibrary("osmand");
|
||||
}
|
||||
|
||||
public static void preloadLibrary() {}
|
||||
|
||||
// public static native boolean loadLibrary();
|
||||
|
||||
public static native String generateRendering(RenderingContext rc, BinaryMapDataObject[] objects, Bitmap bmp,
|
||||
boolean useEnglishNames, RenderingRuleSearchRequest render, int defaultColor);
|
||||
|
||||
|
|
Loading…
Reference in a new issue