summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-02-05 19:05:05 +0900
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-02-09 08:12:10 +0100
commit768dea15b4c5c50367e40af45fc2265478ec154b (patch)
tree40b700a1dbe00f46533133a64b535dac257eb2c7 /android
parent24b28151c8b89043b0d75bf61d839a629ca3bf70 (diff)
android: copy document to temp file when using content scheme
We get the data from Intent, which has data identified by an uri. An uri can use many schemes but we support file (loading directly from a file) or content (used by GMail App). When loading from content, the document is available through a stream and has to be stored into a temporary file locally first, and then that file is should be used as input for loading the document. Change-Id: Ia4ffa8ff02b9737b91a41c03c2eb335d28fe1d61
Diffstat (limited to 'android')
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java54
1 files changed, 53 insertions, 1 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
index 56e388968e77..17fa86761dc5 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -2,6 +2,7 @@ package org.libreoffice;
import android.app.Activity;
import android.app.AlertDialog;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
@@ -26,6 +27,13 @@ import org.mozilla.gecko.ZoomConstraints;
import org.mozilla.gecko.gfx.GeckoLayerClient;
import org.mozilla.gecko.gfx.LayerView;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
@@ -49,6 +57,7 @@ public class LibreOfficeMainActivity extends LOAbout {
private String mInputFile;
private TextSelection mTextSelection;
private TextCursorLayer mTextCursorLayer;
+ private File mTempFile = null;
public LibreOfficeMainActivity() {
super(/*newActivity=*/false);
@@ -98,7 +107,15 @@ public class LibreOfficeMainActivity extends LOAbout {
mMainHandler = new Handler();
if (getIntent().getData() != null) {
- mInputFile = getIntent().getData().getPath();
+ if (getIntent().getData().getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
+ if (copyFileToTemp() && mTempFile != null) {
+ mInputFile = mTempFile.getPath();
+ } else {
+ // TODO: can't open the file
+ }
+ } else if (getIntent().getData().getScheme().equals(ContentResolver.SCHEME_FILE)) {
+ mInputFile = getIntent().getData().getPath();
+ }
} else {
mInputFile = DEFAULT_DOC_PATH;
}
@@ -137,6 +154,35 @@ public class LibreOfficeMainActivity extends LOAbout {
mLayerClient.notifyReady();
}
+ private boolean copyFileToTemp() {
+ ContentResolver contentResolver = getContentResolver();
+ InputStream inputStream = null;
+ try {
+ inputStream = contentResolver.openInputStream(getIntent().getData());
+ mTempFile = File.createTempFile("LibreOffice", null, this.getCacheDir());
+
+ OutputStream outputStream = new FileOutputStream(mTempFile);
+ byte[] buffer = new byte[4096];
+ int len = 0;
+ while ((len = inputStream.read(buffer)) != -1) {
+ outputStream.write(buffer, 0, len);
+ }
+ inputStream.close();
+ outputStream.close();
+ return true;
+ } catch (FileNotFoundException e) {
+ } catch (IOException e) {
+ } finally {
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+ return false;
+ }
+
@Override
protected void onResume() {
super.onResume();
@@ -168,6 +214,12 @@ public class LibreOfficeMainActivity extends LOAbout {
Log.i(LOGTAG, "onDestroy..");
mLayerClient.destroy();
super.onDestroy();
+
+ if (isFinishing()) { // Not an orientation change
+ if (mTempFile != null) {
+ mTempFile.delete();
+ }
+ }
}
public LOKitThread getLOKitThread() {