summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorMert Tumer <merttumer@outlook.com>2018-08-10 05:00:06 -0700
committerTomaž Vajngerl <quikee@gmail.com>2018-08-11 23:27:51 +0200
commitcb059f7e1930aee73024fd8a697f8ed02aee5bd6 (patch)
tree5509d89bca495f9c0c0f220e012d8efae13176cb /android
parent5262ec68f36216cdca9be87b3b2e126d724b69c5 (diff)
Added PDF Export option on Android Viewer
Change-Id: I89d0ca239e3a713979f84a77a66d6da95aad234d Signed-off-by: Mert Tumer <merttumer@outlook.com> Reviewed-on: https://gerrit.libreoffice.org/58826 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'android')
-rw-r--r--android/source/res/menu/main.xml6
-rw-r--r--android/source/res/values/strings.xml2
-rw-r--r--android/source/src/java/org/libreoffice/LOKitTileProvider.java39
-rw-r--r--android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java4
-rw-r--r--android/source/src/java/org/libreoffice/ToolbarController.java3
5 files changed, 51 insertions, 3 deletions
diff --git a/android/source/res/menu/main.xml b/android/source/res/menu/main.xml
index ba807dfd53b3..257a5844b3b3 100644
--- a/android/source/res/menu/main.xml
+++ b/android/source/res/menu/main.xml
@@ -36,6 +36,12 @@
android:title="@string/action_save"
android:orderInCategory="100" />
+ <item android:id="@+id/action_exportToPDF"
+ android:title="@string/action_exportToPDF"
+ android:orderInCategory="100"
+ android:visible="true"
+ />
+
<item android:id="@+id/action_UNO_commands"
android:title="@string/action_UNO_commands"
android:orderInCategory="100" />
diff --git a/android/source/res/values/strings.xml b/android/source/res/values/strings.xml
index da23400202d6..fa83cf4a74b3 100644
--- a/android/source/res/values/strings.xml
+++ b/android/source/res/values/strings.xml
@@ -209,5 +209,5 @@
<string name="UNO_commands_string_type_hint">Type</string>
<string name="UNO_commands_string_value_hint">Value</string>
<string name="UNO_commands_string_parent_value_hint">Parent Value</string>
-
+ <string name="action_exportToPDF">Export To PDF</string>
</resources>
diff --git a/android/source/src/java/org/libreoffice/LOKitTileProvider.java b/android/source/src/java/org/libreoffice/LOKitTileProvider.java
index 3fcaf6ce0939..2815b839ad5c 100644
--- a/android/source/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/source/src/java/org/libreoffice/LOKitTileProvider.java
@@ -10,6 +10,7 @@ package org.libreoffice;
import android.graphics.Bitmap;
import android.graphics.PointF;
+import android.os.Environment;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.Toast;
@@ -301,7 +302,7 @@ class LOKitTileProvider implements TileProvider {
@Override
- public void saveDocumentAs(String filePath, String format) {
+ public void saveDocumentAs(final String filePath, String format) {
final String newFilePath = "file://" + filePath;
Log.d("saveFilePathURL", newFilePath);
LOKitShell.showProgressSpinner(mContext);
@@ -311,7 +312,16 @@ class LOKitTileProvider implements TileProvider {
if (format.equals("svg")) {
// error in creating temp slideshow svg file
Log.d(LOGTAG, "Error in creating temp slideshow svg file");
- } else {
+ } else if(format.equals("pdf")){
+ Log.d(LOGTAG, "Error in creating pdf file");
+ LOKitShell.getMainHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ // There was some error
+ mContext.showCustomStatusMessage("Unable to export to pdf");
+ }
+ });
+ }else {
LOKitShell.getMainHandler().post(new Runnable() {
@Override
public void run() {
@@ -329,6 +339,14 @@ class LOKitTileProvider implements TileProvider {
mContext.startPresentation(newFilePath);
}
});
+ }else if(format.equals("pdf")){
+ LOKitShell.getMainHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ // There was no error
+ mContext.showCustomStatusMessage("Exported to PDF at "+filePath);
+ }
+ });
} else {
LOKitShell.getMainHandler().post(new Runnable() {
@Override
@@ -342,6 +360,23 @@ class LOKitTileProvider implements TileProvider {
LOKitShell.hideProgressSpinner(mContext);
}
+ public void exportToPDF(boolean print){
+ String dir = Environment.getExternalStorageDirectory().getAbsolutePath()+"/Documents";
+ File docDir = new File(dir);
+ if(!docDir.exists()){
+ docDir.mkdir();
+ }
+ String mInputFileName = (new File(mInputFile)).getName();
+ String file = mInputFileName.substring(0,(mInputFileName.length()-3))+"pdf";
+ if(print){
+ String cacheFile = mContext.getExternalCacheDir().getAbsolutePath()
+ + "/" + file;
+ mDocument.saveAs("file://"+cacheFile,"pdf","");
+ //TODO PRINT
+ }else{
+ saveDocumentAs(dir+"/"+file,"pdf");
+ }
+ }
public boolean isDocumentCached(){
File input = new File(mInputFile);
final String cacheFile = mContext.getExternalCacheDir().getAbsolutePath() + "/lo_cached_" + input.getName();
diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
index 544fab1b6f50..b3e00fc40840 100644
--- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -927,6 +927,10 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
else
Snackbar.make(mDrawerLayout, getString(R.string.create_new_file_error) + mInputFile.getName(), Snackbar.LENGTH_LONG).show(); }
+ public void showCustomStatusMessage(String message){
+ Snackbar.make(mDrawerLayout, message, Snackbar.LENGTH_LONG).show();
+ }
+
public void preparePresentation() {
if (getExternalCacheDir() != null) {
String tempPath = getExternalCacheDir().getPath() + "/" + mInputFile.getName() + ".svg";
diff --git a/android/source/src/java/org/libreoffice/ToolbarController.java b/android/source/src/java/org/libreoffice/ToolbarController.java
index ffd0afddc9cd..8aa638e12b2f 100644
--- a/android/source/src/java/org/libreoffice/ToolbarController.java
+++ b/android/source/src/java/org/libreoffice/ToolbarController.java
@@ -171,6 +171,9 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener {
case R.id.action_parts:
mContext.openDrawer();
return true;
+ case R.id.action_exportToPDF:
+ mContext.getTileProvider().exportToPDF(false);
+ return true;
case R.id.action_settings:
mContext.showSettings();
return true;