summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-09-22 22:34:26 +0200
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-09-22 22:40:07 +0200
commit18c052d6d659001657ccf1ff0c7c7cff64658f44 (patch)
tree8340c1299ce2dbe849d37f238eb3c114ef3db47c
parent67ad72f574557cd8d235ceeba556b6884ecd99ed (diff)
LOKit: add "destroy" and "saveAs" to android JNI
Change-Id: I08542b736e49cb9262323e9fe6188b1976d47935
-rw-r--r--android/Bootstrap/src/org/libreoffice/kit/Document.java4
-rw-r--r--android/Bootstrap/src/org/libreoffice/kit/Office.java4
-rw-r--r--desktop/source/lib/lokandroid.cxx50
3 files changed, 49 insertions, 9 deletions
diff --git a/android/Bootstrap/src/org/libreoffice/kit/Document.java b/android/Bootstrap/src/org/libreoffice/kit/Document.java
index d0d30f106d06..d8d5286d02a6 100644
--- a/android/Bootstrap/src/org/libreoffice/kit/Document.java
+++ b/android/Bootstrap/src/org/libreoffice/kit/Document.java
@@ -24,6 +24,8 @@ public class Document {
this.handle = handle;
}
+ public native void destroy();
+
public native int getPart();
public native void setPart(int partIndex);
@@ -40,6 +42,8 @@ public class Document {
private native int getDocumentTypeNative();
+ private native void saveAs(String url, String format, String options);
+
private native void paintTileNative(ByteBuffer buffer, int canvasWidth, int canvasHeight, int tilePositionX, int tilePositionY, int tileWidth, int tileHeight);
public int getDocumentType() {
diff --git a/android/Bootstrap/src/org/libreoffice/kit/Office.java b/android/Bootstrap/src/org/libreoffice/kit/Office.java
index a680735da9f9..d6030665a3bc 100644
--- a/android/Bootstrap/src/org/libreoffice/kit/Office.java
+++ b/android/Bootstrap/src/org/libreoffice/kit/Office.java
@@ -9,8 +9,6 @@
package org.libreoffice.kit;
-import android.util.Log;
-
public class Office {
private long handle;
@@ -31,4 +29,6 @@ public class Office {
}
return document;
}
+
+ public native void destroy();
}
diff --git a/desktop/source/lib/lokandroid.cxx b/desktop/source/lib/lokandroid.cxx
index 16e7217627a0..bc9a8b0b1274 100644
--- a/desktop/source/lib/lokandroid.cxx
+++ b/desktop/source/lib/lokandroid.cxx
@@ -41,6 +41,17 @@ void setHandle(JNIEnv* pEnv, jobject aObject, T* aType)
pEnv->SetLongField(aObject, getHandleField(pEnv, aObject), aHandle);
}
+const char* copyJavaString(JNIEnv* pEnv, jstring aJavaString)
+{
+ const char* pClone = NULL;
+
+ const char* pTemp = pEnv->GetStringUTFChars(aJavaString, NULL);
+ pClone = strdup(pTemp);
+ pEnv->ReleaseStringUTFChars(aJavaString, pTemp);
+
+ return pClone;
+}
+
extern "C" SAL_JNI_EXPORT jstring JNICALL Java_org_libreoffice_kit_Office_getError(JNIEnv* pEnv, jobject aObject)
{
LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject);
@@ -53,21 +64,29 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Office_initializ
pEnv->SetLongField(aObject, getHandleField(pEnv, aObject), aLokHandle);
}
-extern "C" SAL_JNI_EXPORT jlong JNICALL Java_org_libreoffice_kit_Office_documentLoadNative(JNIEnv* pEnv, jobject aObject, jstring documentPath)
+extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Office_destroy(JNIEnv* pEnv, jobject aObject)
{
- const char* aCloneDocumentPath;
-
- const char* aCharDocumentPath = pEnv->GetStringUTFChars(documentPath, NULL);
- aCloneDocumentPath = strdup(aCharDocumentPath);
- pEnv->ReleaseStringUTFChars(documentPath, aCharDocumentPath);
+ LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject);
+ pLibreOfficeKit->pClass->destroy(pLibreOfficeKit);
+}
+extern "C" SAL_JNI_EXPORT jlong JNICALL Java_org_libreoffice_kit_Office_documentLoadNative(JNIEnv* pEnv, jobject aObject, jstring documentPath)
+{
+ const char* aCloneDocumentPath = copyJavaString(pEnv, documentPath);
LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject);
LibreOfficeKitDocument* pDocument = pLibreOfficeKit->pClass->documentLoad(pLibreOfficeKit, aCloneDocumentPath);
- return (jlong) (intptr_t) pDocument;
+ return (jlong) pDocument;
}
/* Document */
+extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_destroy
+ (JNIEnv* pEnv, jobject aObject)
+{
+ LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
+ pDocument->pClass->destroy(pDocument);
+}
+
extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_setPart
(JNIEnv* pEnv, jobject aObject, jint aPart)
{
@@ -145,4 +164,21 @@ extern "C" SAL_JNI_EXPORT jlong JNICALL Java_org_libreoffice_kit_Document_getDoc
return nWidth;
}
+extern "C" SAL_JNI_EXPORT jint JNICALL Java_org_libreoffice_kit_Office_saveAs(JNIEnv* pEnv, jobject aObject, jstring sUrl, jstring sFormat, jstring sOptions)
+{
+ LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
+
+ const char* pUrl = pEnv->GetStringUTFChars(sUrl, NULL);
+ const char* pFormat = pEnv->GetStringUTFChars(sFormat, NULL);
+ const char* pOptions = pEnv->GetStringUTFChars(sOptions, NULL);
+
+ int result = pDocument->pClass->saveAs(pDocument, pUrl, pFormat, pOptions);
+
+ pEnv->ReleaseStringUTFChars(sUrl, pUrl);
+ pEnv->ReleaseStringUTFChars(sFormat, pFormat);
+ pEnv->ReleaseStringUTFChars(sOptions, pOptions);
+
+ return result;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */