Save current version

This commit is contained in:
Victor Shcherb 2011-10-28 16:01:18 +02:00
parent f1a85e499b
commit 1334608a27
13 changed files with 214 additions and 165 deletions

View file

@ -44,7 +44,7 @@ SKIA_SRC := skia
LOCAL_MODULE := osmand LOCAL_MODULE := osmand
LOCAL_C_INCLUDES := $(LOCAL_PATH)/jni \ LOCAL_C_INCLUDES := $(LOCAL_PATH) \
$(PROTOBUF_FOLDER) \ $(PROTOBUF_FOLDER) \
$(SKIA_FOLDER)/include/core \ $(SKIA_FOLDER)/include/core \
$(SKIA_FOLDER)/include/utils \ $(SKIA_FOLDER)/include/utils \

View file

@ -1,3 +1,6 @@
#ifndef _OSMAND_BINARY_READ
#define _OSMAND_BINARY_READ
#include <jni.h> #include <jni.h>
#include <math.h> #include <math.h>
#include <android/log.h> #include <android/log.h>
@ -91,16 +94,20 @@ bool initMapStructure(io::CodedInputStream* input, BinaryMapFile* file) {
void loadJniBinaryRead() { void loadJniBinaryRead() {
jstring js = env->NewStringUTF("Privet");
__android_log_print(ANDROID_LOG_ERROR, "net.osmand", getString(js).c_str());
} }
extern "C" extern "C"
JNIEXPORT jboolean JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_initBinaryMapFile(JNIEnv* ienv, JNIEXPORT jboolean JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_initBinaryMapFile(JNIEnv* ienv,
jstring path) { jobject path) {
std::string inputName = getString(path);
// Verify that the version of the library that we linked against is // 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. // compatible with the version of the headers we compiled against.
GOOGLE_PROTOBUF_VERIFY_VERSION; GOOGLE_PROTOBUF_VERIFY_VERSION;
std::map<std::string, BinaryMapFile*>::iterator iterator; 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"); FILE* file = fopen(inputName.c_str(), "r");
if (file == NULL) { 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); __android_log_print(ANDROID_LOG_WARN, "net.osmand", errorMsg);
return false; 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)); openFiles.insert(std::pair<std::string, BinaryMapFile*>(inputName, mapFile));
return true; return true;
} }
#endif

View file

@ -2,6 +2,7 @@
#define _OSMAND_COMMON #define _OSMAND_COMMON
#include <common.h> #include <common.h>
#include <android/log.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include <hash_map> #include <hash_map>
@ -10,20 +11,35 @@
JNIEnv* env; JNIEnv* env;
JNIEnv* globalEnv(){
return env;
}
JNIEnv* setGlobalEnv(JNIEnv* e) {
env = e;
return e;
}
extern void loadJniCommon(); extern void loadJniCommon();
extern void loadJniBinaryRead(); extern void loadJniBinaryRead();
extern void loadJNIRenderingRules(); extern void loadJNIRenderingRules();
extern void loadJniMapObjects(); extern void loadJniMapObjects();
extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { //extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if(vm->GetEnv((void **)&env, JNI_VERSION_1_4)){ // if(vm->GetEnv((void **)&env, JNI_VERSION_1_2)){
return JNI_ERR; /* JNI version not supported */ // return JNI_ERR; /* JNI version not supported */
} // }
loadJniCommon(); //
// return JNI_VERSION_1_2;
//}
extern "C" JNIEXPORT jboolean JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_loadLibrary(JNIEnv* ienv) {
// env = ienv;
loadJniCommon();
loadJNIRenderingRules(); loadJNIRenderingRules();
loadJniMapObjects(); loadJniMapObjects();
loadJniBinaryRead(); loadJniBinaryRead();
return JNI_VERSION_1_4; return true;
} }

View file

@ -20,10 +20,13 @@ const std::string EMPTY_STRING;
const int WHITE_COLOR = -1; const int WHITE_COLOR = -1;
const int BLACK_COLOR = 0xff000000; const int BLACK_COLOR = 0xff000000;
extern JNIEnv* env; JNIEnv* globalEnv();
JNIEnv* setGlobalEnv(JNIEnv* e);
// JNI Helpers // 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 getString(jstring st);
std::string getStringMethod(jobject o, jmethodID fid, int i); std::string getStringMethod(jobject o, jmethodID fid, int i);
std::string getStringMethod(jobject o, jmethodID fid); std::string getStringMethod(jobject o, jmethodID fid);
@ -142,7 +145,7 @@ struct RenderingContext {
int shadowLevelMax; int shadowLevelMax;
bool interrupted() { bool interrupted() {
return env->GetBooleanField(originalRC, RenderingContext_interrupted); return globalEnv()->GetBooleanField(originalRC, RenderingContext_interrupted);
} }
~RenderingContext() { ~RenderingContext() {
for (uint i = 0; i < textToDraw.size(); i++) { for (uint i = 0; i < textToDraw.size(); i++) {

View file

@ -67,24 +67,24 @@ std::vector <BaseMapDataObject* > marshalObjects(jobjectArray binaryMapDataObjec
{ {
std::vector<BaseMapDataObject*> v; std::vector<BaseMapDataObject*> v;
const size_t size = env->GetArrayLength(binaryMapDataObjects); const size_t size = globalEnv()->GetArrayLength(binaryMapDataObjects);
size_t i = 0; size_t i = 0;
for (; i < size; i++) { for (; i < size; i++) {
jobject binaryMapDataObject = (jobject) env->GetObjectArrayElement(binaryMapDataObjects, i); jobject binaryMapDataObject = (jobject) globalEnv()->GetObjectArrayElement(binaryMapDataObjects, i);
if (env->IsInstanceOf(binaryMapDataObject, MultiPolygonClass)) { if (globalEnv()->IsInstanceOf(binaryMapDataObject, MultiPolygonClass)) {
MultiPolygonObject* o = new MultiPolygonObject(); MultiPolygonObject* o = new MultiPolygonObject();
v.push_back((BaseMapDataObject* )o); 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->tag = getStringMethod(binaryMapDataObject, MultiPolygon_getTag);
o->value = getStringMethod(binaryMapDataObject, MultiPolygon_getValue); 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++) { 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; std::vector<std::pair<int, int> > vs;
for (int js = 0; js < cnt; js++) { for (int js = 0; js < cnt; js++) {
int xt = env->CallIntMethod(binaryMapDataObject, MultiPolygon_getPoint31XTile, js, ji); int xt = globalEnv()->CallIntMethod(binaryMapDataObject, MultiPolygon_getPoint31XTile, js, ji);
int yt = env->CallIntMethod(binaryMapDataObject, MultiPolygon_getPoint31YTile, js, ji); int yt = globalEnv()->CallIntMethod(binaryMapDataObject, MultiPolygon_getPoint31YTile, js, ji);
vs.push_back( std::pair<int, int> (xt, yt) ); vs.push_back( std::pair<int, int> (xt, yt) );
} }
@ -95,40 +95,40 @@ std::vector <BaseMapDataObject* > marshalObjects(jobjectArray binaryMapDataObjec
} else { } else {
jintArray types = (jintArray) env->CallObjectMethod(binaryMapDataObject, BinaryMapDataObject_getTypes); jintArray types = (jintArray) globalEnv()->CallObjectMethod(binaryMapDataObject, BinaryMapDataObject_getTypes);
if (types != NULL) { if (types != NULL) {
MapDataObject* o = new MapDataObject(); MapDataObject* o = new MapDataObject();
jint sizeTypes = env->GetArrayLength(types); jint sizeTypes = globalEnv()->GetArrayLength(types);
jint* els = env->GetIntArrayElements(types, NULL); jint* els = globalEnv()->GetIntArrayElements(types, NULL);
int j = 0; int j = 0;
for (; j < sizeTypes; j++) { for (; j < sizeTypes; j++) {
int wholeType = els[j]; int wholeType = els[j];
o->types.push_back(wholeType); o->types.push_back(wholeType);
jobject pair = env->CallObjectMethod(binaryMapDataObject, BinaryMapDataObject_getTagValue, j); jobject pair = globalEnv()->CallObjectMethod(binaryMapDataObject, BinaryMapDataObject_getTagValue, j);
if (pair != NULL) { if (pair != NULL) {
std::string tag = getStringField(pair, TagValuePair_tag); std::string tag = getStringField(pair, TagValuePair_tag);
std::string value = getStringField(pair, TagValuePair_value); std::string value = getStringField(pair, TagValuePair_value);
o->tagValues.push_back( std::pair<std:: string, std::string>(tag, value)); o->tagValues.push_back( std::pair<std:: string, std::string>(tag, value));
env->DeleteLocalRef(pair); globalEnv()->DeleteLocalRef(pair);
} else { } else {
o->tagValues.push_back( std::pair<std:: string, std::string>(EMPTY_STRING, EMPTY_STRING)); 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++) { for (j = 0; j < sizePoints; j++) {
int tx = env->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getPoint31XTile, j); int tx = globalEnv()->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getPoint31XTile, j);
int ty = env->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getPoint31YTile, j); int ty = globalEnv()->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getPoint31YTile, j);
o->points.push_back(std::pair<int, int>(tx, ty)); o->points.push_back(std::pair<int, int>(tx, ty));
} }
o->name = getStringMethod(binaryMapDataObject, BinaryMapDataObject_getName); o->name = getStringMethod(binaryMapDataObject, BinaryMapDataObject_getName);
o->highwayAttributes = env->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getHighwayAttributes); o->highwayAttributes = globalEnv()->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getHighwayAttributes);
env->ReleaseIntArrayElements(types, els, JNI_ABORT); globalEnv()->ReleaseIntArrayElements(types, els, JNI_ABORT);
env->DeleteLocalRef(types); globalEnv()->DeleteLocalRef(types);
v.push_back((BaseMapDataObject* )o); v.push_back((BaseMapDataObject* )o);
} }
} }
env->DeleteLocalRef(binaryMapDataObject); globalEnv()->DeleteLocalRef(binaryMapDataObject);
} }
return v; return v;
@ -145,36 +145,36 @@ void deleteObjects(std::vector <BaseMapDataObject* > & v)
void loadJniMapObjects() void loadJniMapObjects()
{ {
MultiPolygonClass = globalRef(env->FindClass("net/osmand/osm/MultyPolygon")); MultiPolygonClass = globalRef(globalEnv()->FindClass("net/osmand/osm/MultyPolygon"));
MultiPolygon_getTag = env->GetMethodID(MultiPolygonClass, "getTag", "()Ljava/lang/String;"); MultiPolygon_getTag = globalEnv()->GetMethodID(MultiPolygonClass, "getTag", "()Ljava/lang/String;");
MultiPolygon_getValue = env->GetMethodID(MultiPolygonClass, "getValue", "()Ljava/lang/String;"); MultiPolygon_getValue = globalEnv()->GetMethodID(MultiPolygonClass, "getValue", "()Ljava/lang/String;");
MultiPolygon_getName = env->GetMethodID(MultiPolygonClass, "getName", "(I)Ljava/lang/String;"); MultiPolygon_getName = globalEnv()->GetMethodID(MultiPolygonClass, "getName", "(I)Ljava/lang/String;");
MultiPolygon_getLayer = env->GetMethodID(MultiPolygonClass, "getLayer", "()I"); MultiPolygon_getLayer = globalEnv()->GetMethodID(MultiPolygonClass, "getLayer", "()I");
MultiPolygon_getPoint31XTile = env->GetMethodID(MultiPolygonClass, "getPoint31XTile", "(II)I"); MultiPolygon_getPoint31XTile = globalEnv()->GetMethodID(MultiPolygonClass, "getPoint31XTile", "(II)I");
MultiPolygon_getPoint31YTile = env->GetMethodID(MultiPolygonClass, "getPoint31YTile", "(II)I"); MultiPolygon_getPoint31YTile = globalEnv()->GetMethodID(MultiPolygonClass, "getPoint31YTile", "(II)I");
MultiPolygon_getBoundsCount = env->GetMethodID(MultiPolygonClass, "getBoundsCount", "()I"); MultiPolygon_getBoundsCount = globalEnv()->GetMethodID(MultiPolygonClass, "getBoundsCount", "()I");
MultiPolygon_getBoundPointsCount = env->GetMethodID(MultiPolygonClass, "getBoundPointsCount", "(I)I"); MultiPolygon_getBoundPointsCount = globalEnv()->GetMethodID(MultiPolygonClass, "getBoundPointsCount", "(I)I");
BinaryMapDataObjectClass = globalRef(env->FindClass("net/osmand/binary/BinaryMapDataObject")); BinaryMapDataObjectClass = globalRef(globalEnv()->FindClass("net/osmand/binary/BinaryMapDataObject"));
BinaryMapDataObject_getPointsLength = env->GetMethodID(BinaryMapDataObjectClass, "getPointsLength", "()I"); BinaryMapDataObject_getPointsLength = globalEnv()->GetMethodID(BinaryMapDataObjectClass, "getPointsLength", "()I");
BinaryMapDataObject_getPoint31YTile = env->GetMethodID(BinaryMapDataObjectClass, "getPoint31YTile", "(I)I"); BinaryMapDataObject_getPoint31YTile = globalEnv()->GetMethodID(BinaryMapDataObjectClass, "getPoint31YTile", "(I)I");
BinaryMapDataObject_getPoint31XTile = env->GetMethodID(BinaryMapDataObjectClass, "getPoint31XTile", "(I)I"); BinaryMapDataObject_getPoint31XTile = globalEnv()->GetMethodID(BinaryMapDataObjectClass, "getPoint31XTile", "(I)I");
BinaryMapDataObject_getHighwayAttributes = env->GetMethodID(BinaryMapDataObjectClass, "getHighwayAttributes", "()I"); BinaryMapDataObject_getHighwayAttributes = globalEnv()->GetMethodID(BinaryMapDataObjectClass, "getHighwayAttributes", "()I");
BinaryMapDataObject_getTypes = env->GetMethodID(BinaryMapDataObjectClass, "getTypes", "()[I"); BinaryMapDataObject_getTypes = globalEnv()->GetMethodID(BinaryMapDataObjectClass, "getTypes", "()[I");
BinaryMapDataObject_getName = env->GetMethodID(BinaryMapDataObjectClass, "getName", "()Ljava/lang/String;"); BinaryMapDataObject_getName = globalEnv()->GetMethodID(BinaryMapDataObjectClass, "getName", "()Ljava/lang/String;");
BinaryMapDataObject_getTagValue = env->GetMethodID(BinaryMapDataObjectClass, "getTagValue", BinaryMapDataObject_getTagValue = globalEnv()->GetMethodID(BinaryMapDataObjectClass, "getTagValue",
"(I)Lnet/osmand/binary/BinaryMapIndexReader$TagValuePair;"); "(I)Lnet/osmand/binary/BinaryMapIndexReader$TagValuePair;");
TagValuePairClass = globalRef(env->FindClass("net/osmand/binary/BinaryMapIndexReader$TagValuePair")); TagValuePairClass = globalRef(globalEnv()->FindClass("net/osmand/binary/BinaryMapIndexReader$TagValuePair"));
TagValuePair_tag = env->GetFieldID(TagValuePairClass, "tag", "Ljava/lang/String;"); TagValuePair_tag = globalEnv()->GetFieldID(TagValuePairClass, "tag", "Ljava/lang/String;");
TagValuePair_value = env->GetFieldID(TagValuePairClass, "value", "Ljava/lang/String;"); TagValuePair_value = globalEnv()->GetFieldID(TagValuePairClass, "value", "Ljava/lang/String;");
} }
void unloadJniMapObjects() void unloadJniMapObjects()
{ {
env->DeleteGlobalRef( MultiPolygonClass ); globalEnv()->DeleteGlobalRef( MultiPolygonClass );
env->DeleteGlobalRef( BinaryMapDataObjectClass ); globalEnv()->DeleteGlobalRef( BinaryMapDataObjectClass );
env->DeleteGlobalRef( TagValuePairClass ); globalEnv()->DeleteGlobalRef( TagValuePairClass );
} }

View file

@ -9,7 +9,6 @@
#include <hash_map> #include <hash_map>
#include "common.h" #include "common.h"
jclass ListClass; jclass ListClass;
jmethodID List_size; jmethodID List_size;
jmethodID List_get; jmethodID List_get;
@ -154,53 +153,53 @@ public:
private: private:
void initDictionary() { void initDictionary() {
jobject listDictionary = env->GetObjectField(javaStorage, RenderingRulesStorageClass_dictionary); jobject listDictionary = globalEnv()->GetObjectField(javaStorage, RenderingRulesStorageClass_dictionary);
uint sz = env->CallIntMethod(listDictionary, List_size); uint sz = globalEnv()->CallIntMethod(listDictionary, List_size);
uint i = 0; uint i = 0;
for (; i < sz; i++) { 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) // if(st != NULL)
// { // {
const char* utf = env->GetStringUTFChars(st, NULL); const char* utf = globalEnv()->GetStringUTFChars(st, NULL);
std::string d = std::string(utf); std::string d = std::string(utf);
env->ReleaseStringUTFChars(st, utf); globalEnv()->ReleaseStringUTFChars(st, utf);
env->DeleteLocalRef(st); globalEnv()->DeleteLocalRef(st);
dictionary.push_back(d); dictionary.push_back(d);
dictionaryMap[d] = i; dictionaryMap[d] = i;
// } // }
} }
env->DeleteLocalRef(listDictionary); globalEnv()->DeleteLocalRef(listDictionary);
} }
void initProperties() { void initProperties() {
jobject props = env->GetObjectField(javaStorage, RenderingRulesStorage_PROPS); jobject props = globalEnv()->GetObjectField(javaStorage, RenderingRulesStorage_PROPS);
jobject listProps = env->GetObjectField(props, RenderingRuleStorageProperties_rules); jobject listProps = globalEnv()->GetObjectField(props, RenderingRuleStorageProperties_rules);
uint sz = env->CallIntMethod(listProps, List_size); uint sz = globalEnv()->CallIntMethod(listProps, List_size);
uint i = 0; uint i = 0;
for (; i < sz; i++) { for (; i < sz; i++) {
jobject rulePrope = env->CallObjectMethod(listProps, List_get, i); jobject rulePrope = globalEnv()->CallObjectMethod(listProps, List_get, i);
bool input = env->GetIntField(rulePrope, RenderingRuleProperty_input); bool input = globalEnv()->GetIntField(rulePrope, RenderingRuleProperty_input);
int type = env->GetIntField(rulePrope, RenderingRuleProperty_type); int type = globalEnv()->GetIntField(rulePrope, RenderingRuleProperty_type);
std::string name = getStringField(rulePrope, RenderingRuleProperty_attrName); std::string name = getStringField(rulePrope, RenderingRuleProperty_attrName);
RenderingRuleProperty* prop = new RenderingRuleProperty(type, input, name, i); RenderingRuleProperty* prop = new RenderingRuleProperty(type, input, name, i);
properties.push_back(*prop); properties.push_back(*prop);
propertyMap[name] = prop; propertyMap[name] = prop;
env->DeleteLocalRef(rulePrope); globalEnv()->DeleteLocalRef(rulePrope);
} }
env->DeleteLocalRef(props); globalEnv()->DeleteLocalRef(props);
env->DeleteLocalRef(listProps); globalEnv()->DeleteLocalRef(listProps);
} }
void initRules() { void initRules() {
for (int i = 1; i < SIZE_STATES; i++) { for (int i = 1; i < SIZE_STATES; i++) {
jobjectArray rules = (jobjectArray) env->CallObjectMethod(javaStorage, RenderingRulesStorage_getRules, i); jobjectArray rules = (jobjectArray) globalEnv()->CallObjectMethod(javaStorage, RenderingRulesStorage_getRules, i);
jsize len = env->GetArrayLength(rules); jsize len = globalEnv()->GetArrayLength(rules);
for (jsize j = 0; j < len; j++) { for (jsize j = 0; j < len; j++) {
jobject rRule = env->GetObjectArrayElement(rules, j); jobject rRule = globalEnv()->GetObjectArrayElement(rules, j);
RenderingRule* rule = createRenderingRule(rRule); RenderingRule* rule = createRenderingRule(rRule);
env->DeleteLocalRef(rRule); globalEnv()->DeleteLocalRef(rRule);
if (rule != NULL) { if (rule != NULL) {
jsize psz = rule->properties.size(); jsize psz = rule->properties.size();
@ -219,39 +218,39 @@ private:
} }
} }
} }
env->DeleteLocalRef(rules); globalEnv()->DeleteLocalRef(rules);
} }
} }
RenderingRule* createRenderingRule(jobject rRule) RenderingRule* createRenderingRule(jobject rRule)
{ {
RenderingRule* rule = new RenderingRule; RenderingRule* rule = new RenderingRule;
jobjectArray props = (jobjectArray)env->GetObjectField(rRule, RenderingRule_properties); jobjectArray props = (jobjectArray)globalEnv()->GetObjectField(rRule, RenderingRule_properties);
jintArray intProps = (jintArray)env->GetObjectField(rRule, RenderingRule_intProperties); jintArray intProps = (jintArray)globalEnv()->GetObjectField(rRule, RenderingRule_intProperties);
jfloatArray floatProps = (jfloatArray) env->GetObjectField(rRule, RenderingRule_floatProperties); jfloatArray floatProps = (jfloatArray) globalEnv()->GetObjectField(rRule, RenderingRule_floatProperties);
jobject ifChildren = env->GetObjectField(rRule, RenderingRule_ifChildren); jobject ifChildren = globalEnv()->GetObjectField(rRule, RenderingRule_ifChildren);
jobject ifElseChildren = env->GetObjectField(rRule, RenderingRule_ifElseChildren); jobject ifElseChildren = globalEnv()->GetObjectField(rRule, RenderingRule_ifElseChildren);
jsize sz = env->GetArrayLength(props); jsize sz = globalEnv()->GetArrayLength(props);
if (floatProps != NULL) { if (floatProps != NULL) {
jfloat* fe = env->GetFloatArrayElements(floatProps, NULL); jfloat* fe = globalEnv()->GetFloatArrayElements(floatProps, NULL);
for (int j = 0; j < sz; j++) { for (int j = 0; j < sz; j++) {
rule->floatProperties.push_back(fe[j]); rule->floatProperties.push_back(fe[j]);
} }
env->ReleaseFloatArrayElements(floatProps, fe, JNI_ABORT); globalEnv()->ReleaseFloatArrayElements(floatProps, fe, JNI_ABORT);
env->DeleteLocalRef(floatProps); globalEnv()->DeleteLocalRef(floatProps);
} else { } else {
rule->floatProperties.assign(sz, 0); rule->floatProperties.assign(sz, 0);
} }
if (intProps != NULL) { if (intProps != NULL) {
jint* ie = env->GetIntArrayElements(intProps, NULL); jint* ie = globalEnv()->GetIntArrayElements(intProps, NULL);
for (int j = 0; j < sz; j++) { for (int j = 0; j < sz; j++) {
rule->intProperties.push_back(ie[j]); rule->intProperties.push_back(ie[j]);
} }
env->ReleaseIntArrayElements(intProps, ie, JNI_ABORT); globalEnv()->ReleaseIntArrayElements(intProps, ie, JNI_ABORT);
env->DeleteLocalRef(intProps); globalEnv()->DeleteLocalRef(intProps);
} else { } else {
rule->intProperties.assign(sz, -1); rule->intProperties.assign(sz, -1);
} }
@ -260,32 +259,32 @@ private:
for(jsize i = 0; i<sz;i++) 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); std::string attr = getStringField(prop, RenderingRuleProperty_attrName);
RenderingRuleProperty* p = getProperty(attr.c_str()); RenderingRuleProperty* p = getProperty(attr.c_str());
rule->properties.push_back(p); rule->properties.push_back(p);
env->DeleteLocalRef(prop); globalEnv()->DeleteLocalRef(prop);
} }
env->DeleteLocalRef(props); globalEnv()->DeleteLocalRef(props);
if (ifChildren != NULL) { if (ifChildren != NULL) {
sz = env->CallIntMethod(ifChildren, List_size); sz = globalEnv()->CallIntMethod(ifChildren, List_size);
for (jsize i = 0; i < sz; i++) { 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)); rule->ifChildren.push_back(*createRenderingRule(o));
env->DeleteLocalRef(o); globalEnv()->DeleteLocalRef(o);
} }
env->DeleteLocalRef(ifChildren); globalEnv()->DeleteLocalRef(ifChildren);
} }
if (ifElseChildren != NULL) { if (ifElseChildren != NULL) {
sz = env->CallIntMethod(ifElseChildren, List_size); sz = globalEnv()->CallIntMethod(ifElseChildren, List_size);
for (jsize i = 0; i < sz; i++) { 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)); rule->ifElseChildren.push_back(*createRenderingRule(o));
env->DeleteLocalRef(o); globalEnv()->DeleteLocalRef(o);
} }
env->DeleteLocalRef(ifElseChildren); globalEnv()->DeleteLocalRef(ifElseChildren);
} }
return rule; return rule;
@ -399,68 +398,68 @@ private :
void initObject(jobject rrs) void initObject(jobject rrs)
{ {
jsize sz; jsize sz;
jobjectArray oa = (jobjectArray ) env->GetObjectField(rrs, RenderingRuleSearchRequest_props); jobjectArray oa = (jobjectArray ) globalEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_props);
sz = env->GetArrayLength(oa); sz = globalEnv()->GetArrayLength(oa);
std::vector<RenderingRuleProperty*> requestProps; std::vector<RenderingRuleProperty*> requestProps;
for(jsize i=0; i<sz; i++) 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); std::string attr = getStringField(prop, RenderingRuleProperty_attrName);
RenderingRuleProperty* p = storage -> getProperty(attr.c_str()); RenderingRuleProperty* p = storage -> getProperty(attr.c_str());
requestProps.push_back(p); requestProps.push_back(p);
env->DeleteLocalRef(prop); globalEnv()->DeleteLocalRef(prop);
} }
env->DeleteLocalRef(oa); globalEnv()->DeleteLocalRef(oa);
sz = storage->getPropertiesSize(); sz = storage->getPropertiesSize();
{ {
values = new int[sz]; values = new int[sz];
jintArray ia = (jintArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_values); jintArray ia = (jintArray) globalEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_values);
jint* ie = env->GetIntArrayElements(ia, NULL); jint* ie = globalEnv()->GetIntArrayElements(ia, NULL);
for(int i=0; i<sz; i++){ for(int i=0; i<sz; i++){
values[requestProps.at(i)->id] = ie[i]; values[requestProps.at(i)->id] = ie[i];
} }
env->ReleaseIntArrayElements(ia, ie, JNI_ABORT); globalEnv()->ReleaseIntArrayElements(ia, ie, JNI_ABORT);
env->DeleteLocalRef(ia); globalEnv()->DeleteLocalRef(ia);
} }
{ {
fvalues = new float[sz]; fvalues = new float[sz];
jfloatArray ia = (jfloatArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_fvalues); jfloatArray ia = (jfloatArray) globalEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_fvalues);
jfloat* ie = env->GetFloatArrayElements(ia, NULL); jfloat* ie = globalEnv()->GetFloatArrayElements(ia, NULL);
for (int i = 0; i < sz; i++) { for (int i = 0; i < sz; i++) {
fvalues[requestProps.at(i)->id] = ie[i]; fvalues[requestProps.at(i)->id] = ie[i];
} }
env->ReleaseFloatArrayElements(ia, ie, JNI_ABORT); globalEnv()->ReleaseFloatArrayElements(ia, ie, JNI_ABORT);
env->DeleteLocalRef(ia); globalEnv()->DeleteLocalRef(ia);
} }
{ {
savedValues = new int[sz]; savedValues = new int[sz];
jintArray ia = (jintArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_values); jintArray ia = (jintArray) globalEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_values);
jint* ie = env->GetIntArrayElements(ia, NULL); jint* ie = globalEnv()->GetIntArrayElements(ia, NULL);
for (int i = 0; i < sz; i++) { for (int i = 0; i < sz; i++) {
savedValues[requestProps.at(i)->id] = ie[i]; savedValues[requestProps.at(i)->id] = ie[i];
} }
env->ReleaseIntArrayElements(ia, ie, JNI_ABORT); globalEnv()->ReleaseIntArrayElements(ia, ie, JNI_ABORT);
env->DeleteLocalRef(ia); globalEnv()->DeleteLocalRef(ia);
} }
{ {
savedFvalues = new float[sz]; savedFvalues = new float[sz];
jfloatArray ia = (jfloatArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_fvalues); jfloatArray ia = (jfloatArray) globalEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_fvalues);
jfloat* ie = env->GetFloatArrayElements(ia, NULL); jfloat* ie = globalEnv()->GetFloatArrayElements(ia, NULL);
for (int i = 0; i < sz; i++) { for (int i = 0; i < sz; i++) {
savedFvalues[requestProps.at(i)->id] = ie[i]; savedFvalues[requestProps.at(i)->id] = ie[i];
} }
env->ReleaseFloatArrayElements(ia, ie, JNI_ABORT); globalEnv()->ReleaseFloatArrayElements(ia, ie, JNI_ABORT);
env->DeleteLocalRef(ia); globalEnv()->DeleteLocalRef(ia);
} }
} }
public: public:
RenderingRuleSearchRequest(jobject rrs) : renderingRuleSearch(rrs) { 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){ if(defaultStorage == NULL || defaultStorage->javaStorage != storage){
// multi threadn will not work? // multi threadn will not work?
if(defaultStorage != NULL){ if(defaultStorage != NULL){
@ -468,7 +467,7 @@ public:
} }
defaultStorage = new RenderingRulesStorage(storage); defaultStorage = new RenderingRulesStorage(storage);
} }
env->DeleteLocalRef(storage); globalEnv()->DeleteLocalRef(storage);
this->storage = defaultStorage; this->storage = defaultStorage;
PROPS = new RenderingRulesStorageProperties(this->storage); PROPS = new RenderingRulesStorageProperties(this->storage);
initObject(rrs); initObject(rrs);
@ -662,51 +661,51 @@ RenderingRuleSearchRequest* initSearchRequest(jobject renderingRuleSearchRequest
void loadJNIRenderingRules() void loadJNIRenderingRules()
{ {
RenderingRuleClass = globalRef(env->FindClass("net/osmand/render/RenderingRule")); RenderingRuleClass = globalRef(globalEnv()->FindClass("net/osmand/render/RenderingRule"));
RenderingRule_properties = env->GetFieldID(RenderingRuleClass, "properties", "[Lnet/osmand/render/RenderingRuleProperty;"); RenderingRule_properties = globalEnv()->GetFieldID(RenderingRuleClass, "properties", "[Lnet/osmand/render/RenderingRuleProperty;");
RenderingRule_intProperties = env->GetFieldID(RenderingRuleClass, "intProperties", "[I"); RenderingRule_intProperties = globalEnv()->GetFieldID(RenderingRuleClass, "intProperties", "[I");
RenderingRule_floatProperties = env->GetFieldID(RenderingRuleClass, "floatProperties", "[F"); RenderingRule_floatProperties = globalEnv()->GetFieldID(RenderingRuleClass, "floatProperties", "[F");
RenderingRule_ifElseChildren = env->GetFieldID(RenderingRuleClass, "ifElseChildren", "Ljava/util/List;"); RenderingRule_ifElseChildren = globalEnv()->GetFieldID(RenderingRuleClass, "ifElseChildren", "Ljava/util/List;");
RenderingRule_ifChildren = env->GetFieldID(RenderingRuleClass, "ifChildren", "Ljava/util/List;"); RenderingRule_ifChildren = globalEnv()->GetFieldID(RenderingRuleClass, "ifChildren", "Ljava/util/List;");
RenderingRuleStoragePropertiesClass = globalRef(env->FindClass("net/osmand/render/RenderingRuleStorageProperties")); RenderingRuleStoragePropertiesClass = globalRef(globalEnv()->FindClass("net/osmand/render/RenderingRuleStorageProperties"));
RenderingRuleStorageProperties_rules = env->GetFieldID(RenderingRuleStoragePropertiesClass, "rules", "Ljava/util/List;"); RenderingRuleStorageProperties_rules = globalEnv()->GetFieldID(RenderingRuleStoragePropertiesClass, "rules", "Ljava/util/List;");
RenderingRulePropertyClass = globalRef(env->FindClass("net/osmand/render/RenderingRuleProperty")); RenderingRulePropertyClass = globalRef(globalEnv()->FindClass("net/osmand/render/RenderingRuleProperty"));
RenderingRuleProperty_type = env->GetFieldID(RenderingRulePropertyClass, "type", "I"); RenderingRuleProperty_type = globalEnv()->GetFieldID(RenderingRulePropertyClass, "type", "I");
RenderingRuleProperty_input = env->GetFieldID(RenderingRulePropertyClass, "input", "Z"); RenderingRuleProperty_input = globalEnv()->GetFieldID(RenderingRulePropertyClass, "input", "Z");
RenderingRuleProperty_attrName = env->GetFieldID(RenderingRulePropertyClass, "attrName", "Ljava/lang/String;"); RenderingRuleProperty_attrName = globalEnv()->GetFieldID(RenderingRulePropertyClass, "attrName", "Ljava/lang/String;");
RenderingRulesStorageClass = globalRef(env->FindClass("net/osmand/render/RenderingRulesStorage")); RenderingRulesStorageClass = globalRef(globalEnv()->FindClass("net/osmand/render/RenderingRulesStorage"));
RenderingRulesStorageClass_dictionary = env->GetFieldID(RenderingRulesStorageClass, "dictionary", "Ljava/util/List;"); RenderingRulesStorageClass_dictionary = globalEnv()->GetFieldID(RenderingRulesStorageClass, "dictionary", "Ljava/util/List;");
RenderingRulesStorage_PROPS = env->GetFieldID(RenderingRulesStorageClass, "PROPS", RenderingRulesStorage_PROPS = globalEnv()->GetFieldID(RenderingRulesStorageClass, "PROPS",
"Lnet/osmand/render/RenderingRuleStorageProperties;"); "Lnet/osmand/render/RenderingRuleStorageProperties;");
RenderingRulesStorage_getRules = env->GetMethodID(RenderingRulesStorageClass, "getRules", RenderingRulesStorage_getRules = globalEnv()->GetMethodID(RenderingRulesStorageClass, "getRules",
"(I)[Lnet/osmand/render/RenderingRule;"); "(I)[Lnet/osmand/render/RenderingRule;");
ListClass = globalRef(env->FindClass("java/util/List")); ListClass = globalRef(globalEnv()->FindClass("java/util/List"));
List_size = env->GetMethodID(ListClass, "size", "()I"); List_size = globalEnv()->GetMethodID(ListClass, "size", "()I");
List_get = env->GetMethodID(ListClass, "get", "(I)Ljava/lang/Object;"); List_get = globalEnv()->GetMethodID(ListClass, "get", "(I)Ljava/lang/Object;");
RenderingRuleSearchRequestClass = globalRef(env->FindClass("net/osmand/render/RenderingRuleSearchRequest")); RenderingRuleSearchRequestClass = globalRef(globalEnv()->FindClass("net/osmand/render/RenderingRuleSearchRequest"));
RenderingRuleSearchRequest_storage = env->GetFieldID(RenderingRuleSearchRequestClass, RenderingRuleSearchRequest_storage = globalEnv()->GetFieldID(RenderingRuleSearchRequestClass,
"storage", "Lnet/osmand/render/RenderingRulesStorage;"); "storage", "Lnet/osmand/render/RenderingRulesStorage;");
RenderingRuleSearchRequest_props = env->GetFieldID(RenderingRuleSearchRequestClass, RenderingRuleSearchRequest_props = globalEnv()->GetFieldID(RenderingRuleSearchRequestClass,
"props", "[Lnet/osmand/render/RenderingRuleProperty;"); "props", "[Lnet/osmand/render/RenderingRuleProperty;");
RenderingRuleSearchRequest_values = env->GetFieldID(RenderingRuleSearchRequestClass, "values", "[I"); RenderingRuleSearchRequest_values = globalEnv()->GetFieldID(RenderingRuleSearchRequestClass, "values", "[I");
RenderingRuleSearchRequest_fvalues = env->GetFieldID(RenderingRuleSearchRequestClass, "fvalues", "[F"); RenderingRuleSearchRequest_fvalues = globalEnv()->GetFieldID(RenderingRuleSearchRequestClass, "fvalues", "[F");
RenderingRuleSearchRequest_savedValues = env->GetFieldID(RenderingRuleSearchRequestClass, "savedValues", "[I"); RenderingRuleSearchRequest_savedValues = globalEnv()->GetFieldID(RenderingRuleSearchRequestClass, "savedValues", "[I");
RenderingRuleSearchRequest_savedFvalues = env->GetFieldID(RenderingRuleSearchRequestClass, "savedFvalues", "[F"); RenderingRuleSearchRequest_savedFvalues = globalEnv()->GetFieldID(RenderingRuleSearchRequestClass, "savedFvalues", "[F");
} }
void unloadJniRenderRules() { void unloadJniRenderRules() {
env->DeleteGlobalRef(RenderingRuleSearchRequestClass); globalEnv()->DeleteGlobalRef(RenderingRuleSearchRequestClass);
env->DeleteGlobalRef(RenderingRuleClass); globalEnv()->DeleteGlobalRef(RenderingRuleClass);
env->DeleteGlobalRef(RenderingRulePropertyClass); globalEnv()->DeleteGlobalRef(RenderingRulePropertyClass);
env->DeleteGlobalRef(RenderingRuleStoragePropertiesClass); globalEnv()->DeleteGlobalRef(RenderingRuleStoragePropertiesClass);
env->DeleteGlobalRef(RenderingRulesStorageClass); globalEnv()->DeleteGlobalRef(RenderingRulesStorageClass);
env->DeleteGlobalRef(ListClass); globalEnv()->DeleteGlobalRef(ListClass);
} }

View file

@ -1,3 +1,6 @@
#ifndef _OSMAND_RENDERING
#define _OSMAND_RENDERING
#include <jni.h> #include <jni.h>
#include <math.h> #include <math.h>
#include <android/log.h> #include <android/log.h>
@ -22,6 +25,7 @@
#include "textdraw.cpp" #include "textdraw.cpp"
#include "mapObjects.cpp" #include "mapObjects.cpp"
extern JNIEnv* globalEnv();
char debugMessage[1024]; char debugMessage[1024];
void calcPoint(MapDataObject* mObj, jint ind, RenderingContext* rc) { 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, JNIEXPORT jstring JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_generateRendering( JNIEnv* ienv,
jobject obj, jobject renderingContext, jobjectArray binaryMapDataObjects, jobject bmpObj, jobject obj, jobject renderingContext, jobjectArray binaryMapDataObjects, jobject bmpObj,
jboolean useEnglishNames, jobject renderingRuleSearchRequest, jint defaultColor) { jboolean useEnglishNames, jobject renderingRuleSearchRequest, jint defaultColor) {
setGlobalEnv(ienv);
SkBitmap* bmp = getNativeBitmap(bmpObj); SkBitmap* bmp = getNativeBitmap(bmpObj);
sprintf(debugMessage, "Image w:%d h:%d !", bmp->width(), bmp->height()); sprintf(debugMessage, "Image w:%d h:%d !", bmp->width(), bmp->height());
__android_log_print(ANDROID_LOG_WARN, "net.osmand", debugMessage); __android_log_print(ANDROID_LOG_WARN, "net.osmand", debugMessage);
@ -741,7 +746,7 @@ JNIEXPORT jstring JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_genera
#else #else
sprintf(debugMessage, "Native ok (init %d, rendering %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime()); sprintf(debugMessage, "Native ok (init %d, rendering %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime());
#endif #endif
jstring result = env->NewStringUTF( debugMessage); jstring result = globalEnv()->NewStringUTF( debugMessage);
// unloadLibrary(); // unloadLibrary();
return result; return result;
@ -750,3 +755,4 @@ JNIEXPORT jstring JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_genera
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /**/

View file

@ -1,2 +1,2 @@
set solib-search-path /home/victor/projects/OsmAnd/git/OsmAnd/obj/local/armeabi 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.

View file

@ -10,6 +10,7 @@ import net.osmand.plus.R;
import net.osmand.plus.ResourceManager; import net.osmand.plus.ResourceManager;
import net.osmand.plus.activities.search.SearchActivity; import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.render.MapRenderRepositories; import net.osmand.plus.render.MapRenderRepositories;
import net.osmand.plus.render.NativeOsmandLibrary;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;

View file

@ -22,6 +22,7 @@ import net.osmand.plus.PoiFiltersHelper;
import net.osmand.plus.ProgressDialogImplementation; import net.osmand.plus.ProgressDialogImplementation;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.ResourceManager; import net.osmand.plus.ResourceManager;
import net.osmand.plus.render.NativeOsmandLibrary;
import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.voice.CommandPlayer; import net.osmand.plus.voice.CommandPlayer;
@ -301,6 +302,7 @@ public class OsmandApplication extends Application {
public void run() { public void run() {
List<String> warnings = null; List<String> warnings = null;
try { try {
NativeOsmandLibrary.preloadLibrary();
warnings = manager.reloadIndexes(startDialog); warnings = manager.reloadIndexes(startDialog);
player = null; player = null;
SavingTrackHelper helper = new SavingTrackHelper(OsmandApplication.this); SavingTrackHelper helper = new SavingTrackHelper(OsmandApplication.this);
@ -309,6 +311,7 @@ public class OsmandApplication extends Application {
warnings.addAll(helper.saveDataToGpx()); warnings.addAll(helper.saveDataToGpx());
} }
helper.close(); helper.close();
// NativeOsmandLibrary.loadLibrary();
} finally { } finally {
synchronized (OsmandApplication.this) { synchronized (OsmandApplication.this) {

View file

@ -12,6 +12,7 @@ import java.io.RandomAccessFile;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.LinkedList; import java.util.LinkedList;
@ -57,6 +58,7 @@ public class MapRenderRepositories {
private final Context context; private final Context context;
private Handler handler; private Handler handler;
private Map<String, BinaryMapIndexReader> files = new LinkedHashMap<String, BinaryMapIndexReader>(); private Map<String, BinaryMapIndexReader> files = new LinkedHashMap<String, BinaryMapIndexReader>();
private Set<String> nativeFiles = new HashSet<String>();
private OsmandRenderer renderer; private OsmandRenderer renderer;
private static String BASEMAP_NAME = "basemap"; private static String BASEMAP_NAME = "basemap";
@ -100,6 +102,7 @@ public class MapRenderRepositories {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
if (files.containsKey(file.getAbsolutePath())) { if (files.containsKey(file.getAbsolutePath())) {
closeConnection(files.get(file.getAbsolutePath()), file.getAbsolutePath()); closeConnection(files.get(file.getAbsolutePath()), file.getAbsolutePath());
} }
RandomAccessFile raf = null; RandomAccessFile raf = null;
BinaryMapIndexReader reader = null; BinaryMapIndexReader reader = null;
@ -129,11 +132,6 @@ public class MapRenderRepositories {
} }
throw oome; 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()) { if (log.isDebugEnabled()) {
log.debug("Initializing db " + file.getAbsolutePath() + " " + (System.currentTimeMillis() - start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 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) { protected void closeConnection(BinaryMapIndexReader c, String file) {
files.remove(file); files.remove(file);
nativeFiles.remove(file);
try { try {
c.close(); c.close();
} catch (IOException e) { } catch (IOException e) {
@ -303,6 +302,15 @@ public class MapRenderRepositories {
if (basemapSearch && !mapName.toLowerCase().contains(BASEMAP_NAME)) { if (basemapSearch && !mapName.toLowerCase().contains(BASEMAP_NAME)) {
continue; 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); BinaryMapIndexReader c = files.get(mapName);
searchRequest = BinaryMapIndexReader.buildSearchRequest(leftX, rightX, topY, bottomY, zoom, searchFilter); searchRequest = BinaryMapIndexReader.buildSearchRequest(leftX, rightX, topY, bottomY, zoom, searchFilter);
List<BinaryMapDataObject> res = c.searchMapIndex(searchRequest); List<BinaryMapDataObject> res = c.searchMapIndex(searchRequest);

View file

@ -12,6 +12,10 @@ public class NativeOsmandLibrary {
System.loadLibrary("osmand"); System.loadLibrary("osmand");
} }
public static void preloadLibrary() {}
// public static native boolean loadLibrary();
public static native String generateRendering(RenderingContext rc, BinaryMapDataObject[] objects, Bitmap bmp, public static native String generateRendering(RenderingContext rc, BinaryMapDataObject[] objects, Bitmap bmp,
boolean useEnglishNames, RenderingRuleSearchRequest render, int defaultColor); boolean useEnglishNames, RenderingRuleSearchRequest render, int defaultColor);