[Libreoffice-commits] core.git: Branch 'feature/tiled-editing' - 2 commits - android/experimental

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Thu Feb 5 02:09:59 PST 2015


 android/experimental/LOAndroid3/AndroidManifest.xml.in                                |    9 +
 android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java |   54 +++++++++-
 2 files changed, 61 insertions(+), 2 deletions(-)

New commits:
commit c6ccd7ea4447955366eddd845db83962cd29d376
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Thu Feb 5 19:05:05 2015 +0900

    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

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
index 56e3889..17fa867 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() {
commit d8a0d515ca36763e13fa9eec90a810a646f1ab16
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Thu Feb 5 19:03:06 2015 +0900

    android: allow only "file" and "content" URI scheme
    
    Content scheme is used by GMail App for example.
    
    Change-Id: I3583d38c42b9ad96209f0cd178ea6957a7aec86c

diff --git a/android/experimental/LOAndroid3/AndroidManifest.xml.in b/android/experimental/LOAndroid3/AndroidManifest.xml.in
index 3a17f62..244c6db 100644
--- a/android/experimental/LOAndroid3/AndroidManifest.xml.in
+++ b/android/experimental/LOAndroid3/AndroidManifest.xml.in
@@ -16,7 +16,9 @@
         android:icon="@drawable/main"
         android:label="@string/app_name"
         android:hardwareAccelerated="true"
-        android:theme="@style/AppTheme">
+        android:theme="@style/AppTheme"
+        android:largeHeap="false">
+
         <!-- Viewer Activity -->
         <activity
             android:name=".LibreOfficeMainActivity"
@@ -28,6 +30,9 @@
                 <action android:name="android.intent.action.PICK" />
                 <category android:name="android.intent.category.DEFAULT" />
 
+                <data android:scheme="file"/>
+                <data android:scheme="content"/>
+
                 <!-- Please keep this in sync with FileUtilities.java. -->
 
                 <!-- ODF -->
@@ -83,6 +88,7 @@
 
             </intent-filter>
         </activity>
+
         <!-- Document Browser Activity -->
         <activity android:name=".ui.LibreOfficeUIActivity"
                   android:label="@string/app_name">
@@ -91,6 +97,7 @@
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
+
     </application>
 
 </manifest>


More information about the Libreoffice-commits mailing list