mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
Field class
This commit is contained in:
parent
6b8470105c
commit
a384a82a86
7 changed files with 48 additions and 13 deletions
|
@ -243,7 +243,7 @@ JNIEXPORT jboolean JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPl
|
||||||
return JNI_FALSE;
|
return JNI_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
jobject javaBook = env->GetObjectField(javaModel, AndroidUtil::FID_NativeBookModel_Book);
|
jobject javaBook = AndroidUtil::Field_NativeBookModel_Book->value(javaModel);
|
||||||
|
|
||||||
shared_ptr<Book> book = Book::loadFromJavaBook(env, javaBook);
|
shared_ptr<Book> book = Book::loadFromJavaBook(env, javaBook);
|
||||||
shared_ptr<BookModel> model = new BookModel(book, javaModel);
|
shared_ptr<BookModel> model = new BookModel(book, javaModel);
|
||||||
|
|
|
@ -87,7 +87,7 @@ shared_ptr<Book> Book::loadFromFile(const ZLFile &file) {
|
||||||
shared_ptr<Book> Book::loadFromJavaBook(JNIEnv *env, jobject javaBook) {
|
shared_ptr<Book> Book::loadFromJavaBook(JNIEnv *env, jobject javaBook) {
|
||||||
jstring javaString;
|
jstring javaString;
|
||||||
|
|
||||||
jobject javaFile = env->GetObjectField(javaBook, AndroidUtil::FID_Book_File);
|
jobject javaFile = AndroidUtil::Field_Book_File->value(javaBook);
|
||||||
javaString = AndroidUtil::Method_ZLFile_getPath->call(javaFile);
|
javaString = AndroidUtil::Method_ZLFile_getPath->call(javaFile);
|
||||||
const std::string path = AndroidUtil::fromJavaString(env, javaString);
|
const std::string path = AndroidUtil::fromJavaString(env, javaString);
|
||||||
env->DeleteLocalRef(javaString);
|
env->DeleteLocalRef(javaString);
|
||||||
|
|
|
@ -66,7 +66,7 @@ shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_PluginCollection_Instan
|
||||||
|
|
||||||
shared_ptr<ObjectMethod> AndroidUtil::Method_Encoding_createConverter;
|
shared_ptr<ObjectMethod> AndroidUtil::Method_Encoding_createConverter;
|
||||||
|
|
||||||
jfieldID AndroidUtil::FID_EncodingConverter_Name;
|
shared_ptr<ObjectField> AndroidUtil::Field_EncodingConverter_Name;
|
||||||
shared_ptr<IntMethod> AndroidUtil::Method_EncodingConverter_convert;
|
shared_ptr<IntMethod> AndroidUtil::Method_EncodingConverter_convert;
|
||||||
shared_ptr<VoidMethod> AndroidUtil::Method_EncodingConverter_reset;
|
shared_ptr<VoidMethod> AndroidUtil::Method_EncodingConverter_reset;
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ shared_ptr<Constructor> AndroidUtil::Constructor_ZLFileImage;
|
||||||
|
|
||||||
shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_Paths_cacheDirectory;
|
shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_Paths_cacheDirectory;
|
||||||
|
|
||||||
jfieldID AndroidUtil::FID_Book_File;
|
shared_ptr<ObjectField> AndroidUtil::Field_Book_File;
|
||||||
shared_ptr<StringMethod> AndroidUtil::Method_Book_getTitle;
|
shared_ptr<StringMethod> AndroidUtil::Method_Book_getTitle;
|
||||||
shared_ptr<StringMethod> AndroidUtil::Method_Book_getLanguage;
|
shared_ptr<StringMethod> AndroidUtil::Method_Book_getLanguage;
|
||||||
shared_ptr<StringMethod> AndroidUtil::Method_Book_getEncodingNoDetection;
|
shared_ptr<StringMethod> AndroidUtil::Method_Book_getEncodingNoDetection;
|
||||||
|
@ -101,7 +101,7 @@ shared_ptr<BooleanMethod> AndroidUtil::Method_Book_save;
|
||||||
|
|
||||||
shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_Tag_getTag;
|
shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_Tag_getTag;
|
||||||
|
|
||||||
jfieldID AndroidUtil::FID_NativeBookModel_Book;
|
shared_ptr<ObjectField> AndroidUtil::Field_NativeBookModel_Book;
|
||||||
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_initInternalHyperlinks;
|
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_initInternalHyperlinks;
|
||||||
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_initTOC;
|
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_initTOC;
|
||||||
shared_ptr<ObjectMethod> AndroidUtil::Method_NativeBookModel_createTextModel;
|
shared_ptr<ObjectMethod> AndroidUtil::Method_NativeBookModel_createTextModel;
|
||||||
|
@ -157,7 +157,7 @@ bool AndroidUtil::init(JavaVM* jvm) {
|
||||||
Method_Encoding_createConverter = new ObjectMethod(*Class_Encoding, "createConverter", "org/geometerplus/zlibrary/core/encodings/EncodingConverter", "()");
|
Method_Encoding_createConverter = new ObjectMethod(*Class_Encoding, "createConverter", "org/geometerplus/zlibrary/core/encodings/EncodingConverter", "()");
|
||||||
|
|
||||||
Class_EncodingConverter = new JavaClass(env, "org/geometerplus/zlibrary/core/encodings/EncodingConverter");
|
Class_EncodingConverter = new JavaClass(env, "org/geometerplus/zlibrary/core/encodings/EncodingConverter");
|
||||||
CHECK_NULL( FID_EncodingConverter_Name = env->GetFieldID(Class_EncodingConverter->j(), "Name", "Ljava/lang/String;") );
|
Field_EncodingConverter_Name = new ObjectField(*Class_EncodingConverter, "Name", "java/lang/String");
|
||||||
Method_EncodingConverter_convert = new IntMethod(*Class_EncodingConverter, "convert", "([BII[BI)");
|
Method_EncodingConverter_convert = new IntMethod(*Class_EncodingConverter, "convert", "([BII[BI)");
|
||||||
Method_EncodingConverter_reset = new VoidMethod(*Class_EncodingConverter, "reset", "()");
|
Method_EncodingConverter_reset = new VoidMethod(*Class_EncodingConverter, "reset", "()");
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ bool AndroidUtil::init(JavaVM* jvm) {
|
||||||
StaticMethod_Paths_cacheDirectory = new StaticObjectMethod(*Class_Paths, "cacheDirectory", "java/lang/String", "()");
|
StaticMethod_Paths_cacheDirectory = new StaticObjectMethod(*Class_Paths, "cacheDirectory", "java/lang/String", "()");
|
||||||
|
|
||||||
Class_Book = new JavaClass(env, "org/geometerplus/fbreader/library/Book");
|
Class_Book = new JavaClass(env, "org/geometerplus/fbreader/library/Book");
|
||||||
CHECK_NULL( FID_Book_File = env->GetFieldID(Class_Book->j(), "File", "Lorg/geometerplus/zlibrary/core/filesystem/ZLFile;") );
|
Field_Book_File = new ObjectField(*Class_Book, "File", "org/geometerplus/zlibrary/core/filesystem/ZLFile");
|
||||||
Method_Book_getTitle = new StringMethod(*Class_Book, "getTitle", "()");
|
Method_Book_getTitle = new StringMethod(*Class_Book, "getTitle", "()");
|
||||||
Method_Book_getLanguage = new StringMethod(*Class_Book, "getLanguage", "()");
|
Method_Book_getLanguage = new StringMethod(*Class_Book, "getLanguage", "()");
|
||||||
Method_Book_getEncodingNoDetection = new StringMethod(*Class_Book, "getEncodingNoDetection", "()");
|
Method_Book_getEncodingNoDetection = new StringMethod(*Class_Book, "getEncodingNoDetection", "()");
|
||||||
|
@ -199,7 +199,7 @@ bool AndroidUtil::init(JavaVM* jvm) {
|
||||||
StaticMethod_Tag_getTag = new StaticObjectMethod(*Class_Tag, "getTag", "org/geometerplus/fbreader/library/Tag", "(Lorg/geometerplus/fbreader/library/Tag;Ljava/lang/String;)");
|
StaticMethod_Tag_getTag = new StaticObjectMethod(*Class_Tag, "getTag", "org/geometerplus/fbreader/library/Tag", "(Lorg/geometerplus/fbreader/library/Tag;Ljava/lang/String;)");
|
||||||
|
|
||||||
Class_NativeBookModel = new JavaClass(env, "org/geometerplus/fbreader/bookmodel/NativeBookModel");
|
Class_NativeBookModel = new JavaClass(env, "org/geometerplus/fbreader/bookmodel/NativeBookModel");
|
||||||
CHECK_NULL( FID_NativeBookModel_Book = env->GetFieldID(Class_NativeBookModel->j(), "Book", "Lorg/geometerplus/fbreader/library/Book;") );
|
Field_NativeBookModel_Book = new ObjectField(*Class_NativeBookModel, "Book", "org/geometerplus/fbreader/library/Book");
|
||||||
Method_NativeBookModel_initInternalHyperlinks = new VoidMethod(*Class_NativeBookModel, "initInternalHyperlinks", "(Ljava/lang/String;Ljava/lang/String;I)");
|
Method_NativeBookModel_initInternalHyperlinks = new VoidMethod(*Class_NativeBookModel, "initInternalHyperlinks", "(Ljava/lang/String;Ljava/lang/String;I)");
|
||||||
Method_NativeBookModel_initTOC = new VoidMethod(*Class_NativeBookModel, "initTOC", "(Lorg/geometerplus/zlibrary/text/model/ZLTextModel;[I[I)");
|
Method_NativeBookModel_initTOC = new VoidMethod(*Class_NativeBookModel, "initTOC", "(Lorg/geometerplus/zlibrary/text/model/ZLTextModel;[I[I)");
|
||||||
Method_NativeBookModel_createTextModel = new ObjectMethod(*Class_NativeBookModel, "createTextModel", "org/geometerplus/zlibrary/text/model/ZLTextModel", "(Ljava/lang/String;Ljava/lang/String;I[I[I[I[I[BLjava/lang/String;Ljava/lang/String;I)");
|
Method_NativeBookModel_createTextModel = new ObjectMethod(*Class_NativeBookModel, "createTextModel", "org/geometerplus/zlibrary/text/model/ZLTextModel", "(Ljava/lang/String;Ljava/lang/String;I[I[I[I[I[BLjava/lang/String;Ljava/lang/String;I)");
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
class JavaClass;
|
class JavaClass;
|
||||||
class Constructor;
|
class Constructor;
|
||||||
|
class ObjectField;
|
||||||
class VoidMethod;
|
class VoidMethod;
|
||||||
class IntMethod;
|
class IntMethod;
|
||||||
class LongMethod;
|
class LongMethod;
|
||||||
|
@ -97,7 +98,7 @@ public:
|
||||||
|
|
||||||
static shared_ptr<ObjectMethod> Method_Encoding_createConverter;
|
static shared_ptr<ObjectMethod> Method_Encoding_createConverter;
|
||||||
|
|
||||||
static jfieldID FID_EncodingConverter_Name;
|
static shared_ptr<ObjectField> Field_EncodingConverter_Name;
|
||||||
static shared_ptr<IntMethod> Method_EncodingConverter_convert;
|
static shared_ptr<IntMethod> Method_EncodingConverter_convert;
|
||||||
static shared_ptr<VoidMethod> Method_EncodingConverter_reset;
|
static shared_ptr<VoidMethod> Method_EncodingConverter_reset;
|
||||||
|
|
||||||
|
@ -108,7 +109,7 @@ public:
|
||||||
|
|
||||||
static shared_ptr<StaticObjectMethod> StaticMethod_Paths_cacheDirectory;
|
static shared_ptr<StaticObjectMethod> StaticMethod_Paths_cacheDirectory;
|
||||||
|
|
||||||
static jfieldID FID_Book_File;
|
static shared_ptr<ObjectField> Field_Book_File;
|
||||||
static shared_ptr<StringMethod> Method_Book_getTitle;
|
static shared_ptr<StringMethod> Method_Book_getTitle;
|
||||||
static shared_ptr<StringMethod> Method_Book_getLanguage;
|
static shared_ptr<StringMethod> Method_Book_getLanguage;
|
||||||
static shared_ptr<StringMethod> Method_Book_getEncodingNoDetection;
|
static shared_ptr<StringMethod> Method_Book_getEncodingNoDetection;
|
||||||
|
@ -122,7 +123,7 @@ public:
|
||||||
|
|
||||||
static shared_ptr<StaticObjectMethod> StaticMethod_Tag_getTag;
|
static shared_ptr<StaticObjectMethod> StaticMethod_Tag_getTag;
|
||||||
|
|
||||||
static jfieldID FID_NativeBookModel_Book;
|
static shared_ptr<ObjectField> Field_NativeBookModel_Book;
|
||||||
static shared_ptr<VoidMethod> Method_NativeBookModel_initInternalHyperlinks;
|
static shared_ptr<VoidMethod> Method_NativeBookModel_initInternalHyperlinks;
|
||||||
static shared_ptr<VoidMethod> Method_NativeBookModel_initTOC;
|
static shared_ptr<VoidMethod> Method_NativeBookModel_initTOC;
|
||||||
static shared_ptr<ObjectMethod> Method_NativeBookModel_createTextModel;
|
static shared_ptr<ObjectMethod> Method_NativeBookModel_createTextModel;
|
||||||
|
|
|
@ -52,6 +52,13 @@ jobject Constructor::call(...) {
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Field::Field(const JavaClass &cls, const std::string &name, const std::string &type) : Member(cls), myName(name) {
|
||||||
|
myId = env().GetFieldID(jClass(), name.c_str(), type.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
Field::~Field() {
|
||||||
|
}
|
||||||
|
|
||||||
Method::Method(const JavaClass &cls, const std::string &name, const std::string &signature) : Member(cls), myName(name) {
|
Method::Method(const JavaClass &cls, const std::string &name, const std::string &signature) : Member(cls), myName(name) {
|
||||||
myId = env().GetMethodID(jClass(), name.c_str(), signature.c_str());
|
myId = env().GetMethodID(jClass(), name.c_str(), signature.c_str());
|
||||||
}
|
}
|
||||||
|
@ -66,6 +73,16 @@ StaticMethod::StaticMethod(const JavaClass &cls, const std::string &name, const
|
||||||
StaticMethod::~StaticMethod() {
|
StaticMethod::~StaticMethod() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ObjectField::ObjectField(const JavaClass &cls, const std::string &name, const std::string &type) : Field(cls, name, "L" + type + ";") {
|
||||||
|
}
|
||||||
|
|
||||||
|
jobject ObjectField::value(jobject obj) const {
|
||||||
|
ZLLogger::Instance().println(JNI_LOGGER_CLASS, "getting value of ObjectField " + myName);
|
||||||
|
jobject val = env().GetObjectField(obj, myId);
|
||||||
|
ZLLogger::Instance().println(JNI_LOGGER_CLASS, "got value of ObjectField " + myName);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
VoidMethod::VoidMethod(const JavaClass &cls, const std::string &name, const std::string &signature) : Method(cls, name, signature + "V") {
|
VoidMethod::VoidMethod(const JavaClass &cls, const std::string &name, const std::string &signature) : Method(cls, name, signature + "V") {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,6 @@ private:
|
||||||
jclass myClass;
|
jclass myClass;
|
||||||
|
|
||||||
friend class Member;
|
friend class Member;
|
||||||
friend class Method;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Member {
|
class Member {
|
||||||
|
@ -72,6 +71,17 @@ private:
|
||||||
jmethodID myId;
|
jmethodID myId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Field : public Member {
|
||||||
|
|
||||||
|
public:
|
||||||
|
Field(const JavaClass &cls, const std::string &name, const std::string &type);
|
||||||
|
virtual ~Field();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
const std::string myName;
|
||||||
|
jfieldID myId;
|
||||||
|
};
|
||||||
|
|
||||||
class Method : public Member {
|
class Method : public Member {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -94,6 +104,13 @@ protected:
|
||||||
jmethodID myId;
|
jmethodID myId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ObjectField : public Field {
|
||||||
|
|
||||||
|
public:
|
||||||
|
ObjectField(const JavaClass &cls, const std::string &name, const std::string &type);
|
||||||
|
jobject value(jobject obj) const;
|
||||||
|
};
|
||||||
|
|
||||||
class VoidMethod : public Method {
|
class VoidMethod : public Method {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -85,7 +85,7 @@ JavaEncodingConverter::~JavaEncodingConverter() {
|
||||||
|
|
||||||
std::string JavaEncodingConverter::name() const {
|
std::string JavaEncodingConverter::name() const {
|
||||||
JNIEnv *env = AndroidUtil::getEnv();
|
JNIEnv *env = AndroidUtil::getEnv();
|
||||||
jstring javaName = (jstring)env->GetObjectField(myJavaConverter, AndroidUtil::FID_EncodingConverter_Name);
|
jstring javaName = (jstring)AndroidUtil::Field_EncodingConverter_Name->value(myJavaConverter);
|
||||||
const std::string result = AndroidUtil::fromJavaString(env, javaName);
|
const std::string result = AndroidUtil::fromJavaString(env, javaName);
|
||||||
env->DeleteLocalRef(javaName);
|
env->DeleteLocalRef(javaName);
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue