mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
synchronization with native branch
This commit is contained in:
parent
925975f7e3
commit
65094c815a
6 changed files with 109 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
|||
#APP_ABI := armeabi
|
||||
APP_ABI := armeabi
|
||||
#APP_ABI := armeabi armeabi-v7a x86 mips mips-r2 mips-r2-sf
|
||||
APP_ABI := all
|
||||
#APP_ABI := all
|
||||
APP_STL := stlport_static
|
||||
|
|
|
@ -18,3 +18,79 @@
|
|||
*/
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <AndroidUtil.h>
|
||||
|
||||
#include "fbreader/src/formats/FormatPlugin.h"
|
||||
#include "fbreader/src/library/Author.h"
|
||||
#include "fbreader/src/library/Book.h"
|
||||
#include "fbreader/src/library/Tag.h"
|
||||
|
||||
static shared_ptr<FormatPlugin> findCppPlugin(JNIEnv *env, jobject base) {
|
||||
jstring fileTypeJava = (jstring)env->CallObjectMethod(base, AndroidUtil::MID_NativeFormatPlugin_supportedFileType);
|
||||
std::string fileTypeCpp;
|
||||
AndroidUtil::extractJavaString(env, fileTypeJava, fileTypeCpp);
|
||||
shared_ptr<FormatPlugin> plugin = PluginCollection::Instance().pluginByType(fileTypeCpp);
|
||||
if (plugin.isNull()) {
|
||||
AndroidUtil::throwRuntimeException(env, "Native FormatPlugin instance is NULL for type " + fileTypeCpp);
|
||||
}
|
||||
return plugin;
|
||||
}
|
||||
|
||||
static void fillMetaInfo(JNIEnv* env, jobject javaBook, Book &book) {
|
||||
jstring javaString;
|
||||
|
||||
javaString = AndroidUtil::createJavaString(env, book.title());
|
||||
env->CallVoidMethod(javaBook, AndroidUtil::MID_Book_setTitle, javaString);
|
||||
env->DeleteLocalRef(javaString);
|
||||
|
||||
javaString = AndroidUtil::createJavaString(env, book.language());
|
||||
if (javaString != 0) {
|
||||
env->CallVoidMethod(javaBook, AndroidUtil::MID_Book_setLanguage, javaString);
|
||||
env->DeleteLocalRef(javaString);
|
||||
}
|
||||
|
||||
javaString = AndroidUtil::createJavaString(env, book.encoding());
|
||||
if (javaString != 0) {
|
||||
env->CallVoidMethod(javaBook, AndroidUtil::MID_Book_setEncoding, javaString);
|
||||
env->DeleteLocalRef(javaString);
|
||||
}
|
||||
|
||||
javaString = AndroidUtil::createJavaString(env, book.seriesTitle());
|
||||
if (javaString != 0) {
|
||||
env->CallVoidMethod(javaBook, AndroidUtil::MID_Book_setSeriesInfo, javaString, (jfloat)book.indexInSeries());
|
||||
env->DeleteLocalRef(javaString);
|
||||
}
|
||||
|
||||
const AuthorList &authors = book.authors();
|
||||
for (size_t i = 0; i < authors.size(); ++i) {
|
||||
const Author &author = *authors[i];
|
||||
javaString = env->NewStringUTF(author.name().c_str());
|
||||
jstring key = env->NewStringUTF(author.sortKey().c_str());
|
||||
env->CallVoidMethod(javaBook, AndroidUtil::MID_Book_addAuthor, javaString, key);
|
||||
env->DeleteLocalRef(key);
|
||||
env->DeleteLocalRef(javaString);
|
||||
}
|
||||
|
||||
const TagList &tags = book.tags();
|
||||
for (size_t i = 0; i < tags.size(); ++i) {
|
||||
const Tag &tag = *tags[i];
|
||||
env->CallVoidMethod(javaBook, AndroidUtil::MID_Book_addTag, tag.javaTag(env));
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readMetaInfo(JNIEnv* env, jobject thiz, jobject javaBook) {
|
||||
shared_ptr<FormatPlugin> plugin = findCppPlugin(env, thiz);
|
||||
if (plugin.isNull()) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
shared_ptr<Book> book = Book::loadFromJavaBook(env, javaBook);
|
||||
if (!plugin->readMetaInfo(*book)) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
fillMetaInfo(env, javaBook, *book);
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ jmethodID AndroidUtil::SMID_ZLibrary_Instance;
|
|||
jmethodID AndroidUtil::MID_ZLibrary_getVersionName;
|
||||
|
||||
jmethodID AndroidUtil::MID_NativeFormatPlugin_init;
|
||||
jmethodID AndroidUtil::MID_NativeFormatPlugin_supportedFileType;
|
||||
|
||||
jmethodID AndroidUtil::SMID_PluginCollection_Instance;
|
||||
|
||||
|
@ -62,6 +63,12 @@ jfieldID AndroidUtil::FID_Book_File;
|
|||
jmethodID AndroidUtil::MID_Book_getTitle;
|
||||
jmethodID AndroidUtil::MID_Book_getLanguage;
|
||||
jmethodID AndroidUtil::MID_Book_getEncoding;
|
||||
jmethodID AndroidUtil::MID_Book_setTitle;
|
||||
jmethodID AndroidUtil::MID_Book_setSeriesInfo;
|
||||
jmethodID AndroidUtil::MID_Book_setLanguage;
|
||||
jmethodID AndroidUtil::MID_Book_setEncoding;
|
||||
jmethodID AndroidUtil::MID_Book_addAuthor;
|
||||
jmethodID AndroidUtil::MID_Book_addTag;
|
||||
|
||||
jmethodID AndroidUtil::SMID_Tag_getTag;
|
||||
|
||||
|
@ -102,7 +109,7 @@ bool AndroidUtil::init(JavaVM* jvm) {
|
|||
|
||||
CHECK_NULL( cls = env->FindClass(Class_NativeFormatPlugin) );
|
||||
CHECK_NULL( MID_NativeFormatPlugin_init = env->GetMethodID(cls, "<init>", "(Ljava/lang/String;)V") );
|
||||
//CHECK_NULL( MID_NativeFormatPlugin_supportedFileType = env->GetMethodID(cls, "supportedFileType", "()Ljava/lang/String;") );
|
||||
CHECK_NULL( MID_NativeFormatPlugin_supportedFileType = env->GetMethodID(cls, "supportedFileType", "()Ljava/lang/String;") );
|
||||
//CHECK_NULL( SMID_NativeFormatPlugin_createImage = env->GetStaticMethodID(cls, "createImage", "(Ljava/lang/String;Ljava/lang/String;II)Lorg/geometerplus/zlibrary/core/image/ZLImage;") );
|
||||
env->DeleteLocalRef(cls);
|
||||
|
||||
|
@ -129,6 +136,12 @@ bool AndroidUtil::init(JavaVM* jvm) {
|
|||
CHECK_NULL( MID_Book_getTitle = env->GetMethodID(cls, "getTitle", "()Ljava/lang/String;") );
|
||||
CHECK_NULL( MID_Book_getLanguage = env->GetMethodID(cls, "getLanguage", "()Ljava/lang/String;") );
|
||||
CHECK_NULL( MID_Book_getEncoding = env->GetMethodID(cls, "getEncoding", "()Ljava/lang/String;") );
|
||||
CHECK_NULL( MID_Book_setTitle = env->GetMethodID(cls, "setTitle", "(Ljava/lang/String;)V") );
|
||||
CHECK_NULL( MID_Book_setSeriesInfo = env->GetMethodID(cls, "setSeriesInfo", "(Ljava/lang/String;F)V") );
|
||||
CHECK_NULL( MID_Book_setLanguage = env->GetMethodID(cls, "setLanguage", "(Ljava/lang/String;)V") );
|
||||
CHECK_NULL( MID_Book_setEncoding = env->GetMethodID(cls, "setEncoding", "(Ljava/lang/String;)V") );
|
||||
CHECK_NULL( MID_Book_addAuthor = env->GetMethodID(cls, "addAuthor", "(Ljava/lang/String;Ljava/lang/String;)V") );
|
||||
CHECK_NULL( MID_Book_addTag = env->GetMethodID(cls, "addTag", "(Lorg/geometerplus/fbreader/library/Tag;)V") );
|
||||
env->DeleteLocalRef(cls);
|
||||
|
||||
CHECK_NULL( cls = env->FindClass(Class_Tag) );
|
||||
|
|
|
@ -62,6 +62,7 @@ public:
|
|||
static jmethodID MID_ZLFile_size;
|
||||
|
||||
static jmethodID MID_NativeFormatPlugin_init;
|
||||
static jmethodID MID_NativeFormatPlugin_supportedFileType;
|
||||
|
||||
static jmethodID SMID_PluginCollection_Instance;
|
||||
|
||||
|
@ -71,6 +72,12 @@ public:
|
|||
static jmethodID MID_Book_getTitle;
|
||||
static jmethodID MID_Book_getLanguage;
|
||||
static jmethodID MID_Book_getEncoding;
|
||||
static jmethodID MID_Book_setTitle;
|
||||
static jmethodID MID_Book_setSeriesInfo;
|
||||
static jmethodID MID_Book_setLanguage;
|
||||
static jmethodID MID_Book_setEncoding;
|
||||
static jmethodID MID_Book_addAuthor;
|
||||
static jmethodID MID_Book_addTag;
|
||||
|
||||
static jmethodID SMID_Tag_getTag;
|
||||
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
-keepclassmembers class org.geometerplus.fbreader.formats.PluginCollection {
|
||||
public static ** Instance();
|
||||
}
|
||||
-keepclassmembers class org.geometerplus.fbreader.formats.FormatPlugin {
|
||||
public ** supportedFileType();
|
||||
}
|
||||
-keep class org.geometerplus.fbreader.Paths
|
||||
-keepclassmembers class org.geometerplus.fbreader.Paths {
|
||||
public static ** cacheDirectory();
|
||||
|
@ -41,6 +44,12 @@
|
|||
public ** getTitle();
|
||||
public ** getLanguage();
|
||||
public ** getEncoding();
|
||||
public void setTitle(**);
|
||||
public void setSeriesInfo(**,float);
|
||||
public void setLanguage(**);
|
||||
public void setEncoding(**);
|
||||
public void addAuthor(**,**);
|
||||
public void addTag(**);
|
||||
}
|
||||
-keep class org.geometerplus.fbreader.library.Tag
|
||||
-keepclassmembers class org.geometerplus.fbreader.library.Tag {
|
||||
|
|
|
@ -45,6 +45,7 @@ public class PluginCollection {
|
|||
// This code can not be moved to constructor because nativePlugins() is a native method
|
||||
for (NativeFormatPlugin p : ourInstance.nativePlugins()) {
|
||||
ourInstance.addPlugin(p);
|
||||
System.err.println("native plugin: " + p);
|
||||
}
|
||||
}
|
||||
return ourInstance;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue