[Libreoffice-commits] core.git: 2 commits - android/experimental

Jacobo Aragunde Pérez jaragunde at igalia.com
Thu Feb 12 12:23:48 PST 2015


 android/experimental/LOAndroid3/src/java/org/libreoffice/storage/IDocumentProvider.java |    2 
 android/experimental/LOAndroid3/src/java/org/libreoffice/storage/IFile.java             |    3 
 android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java  |  116 ++++++++--
 3 files changed, 98 insertions(+), 23 deletions(-)

New commits:
commit 0f808374af3c71f45b60af3e4040c8e5f12955ac
Author: Jacobo Aragunde Pérez <jaragunde at igalia.com>
Date:   Tue Feb 10 18:46:54 2015 +0100

    Android: get the file to share in a different thread.
    
    Share feature for cloud files will probably not work properly as it
    is, but with this patch we prevent a crash at least.
    
    Change-Id: I95176e9e855a37adf1d3c46edceb0dc6067d9884

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
index 065887a..9435c092 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -360,15 +360,42 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
     }
 
     private void share(int position) {
-        File file = filePaths.get(position).getDocument();
-        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
-        Uri uri = Uri.fromFile(file);
-        sharingIntent.setType(FileUtilities.getMimeType(file.getName()));
-        sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, uri);
-        sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
-                file.getName());
-        startActivity(Intent.createChooser(sharingIntent,
-                getString(R.string.share_via)));
+
+        new AsyncTask<IFile, Void, File>() {
+            @Override
+            protected File doInBackground(IFile... document) {
+                // this operation may imply network access and must be run in
+                // a different thread
+                try {
+                    return document[0].getDocument();
+                } catch (final RuntimeException e) {
+                    final Activity activity = LibreOfficeUIActivity.this;
+                    activity.runOnUiThread(new Runnable() {
+                        @Override
+                        public void run() {
+                            Toast.makeText(activity, e.getMessage(),
+                                    Toast.LENGTH_SHORT).show();
+                        }
+                    });
+                    Log.e(tag, e.getMessage(), e.getCause());
+                    return null;
+                }
+            }
+
+            @Override
+            protected void onPostExecute(File file) {
+                if (file != null) {
+                    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
+                    Uri uri = Uri.fromFile(file);
+                    sharingIntent.setType(FileUtilities.getMimeType(file.getName()));
+                    sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, uri);
+                    sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
+                            file.getName());
+                    startActivity(Intent.createChooser(sharingIntent,
+                            getString(R.string.share_via)));
+                }
+            }
+        }.execute(filePaths.get(position));
     }
 
     @Override
commit 9e8fa856918e018f8bde4067fdbdbb37e2eaa288
Author: Jacobo Aragunde Pérez <jaragunde at igalia.com>
Date:   Tue Feb 10 16:17:12 2015 +0000

    Android: improve error handling for document providers.
    
    Now some operations in document providers may throw a RuntimeException
    in case of error. The main activity is ready to catch them and show an
    error message.
    
    Change-Id: Iad7249dbdc06b2a0890d5435ad65284b728e9707

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/IDocumentProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/IDocumentProvider.java
index 191a143..bbfdecd 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/IDocumentProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/IDocumentProvider.java
@@ -21,6 +21,7 @@ public interface IDocumentProvider {
      * Provides the content root element for the Document Provider.
      *
      * @return Content root element.
+     * @throws RuntimeException in case of error.
      */
     IFile getRootDirectory();
 
@@ -31,6 +32,7 @@ public interface IDocumentProvider {
      *            URI pointing to some content object that has been previously
      *            retrieved with IFile.getUri().
      * @return IFile object pointing to the content represented by uri.
+     * @throws RuntimeException in case of error.
      */
     IFile createFromUri(URI uri);
 
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/IFile.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/IFile.java
index 5b71c09..8effd0f 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/IFile.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/IFile.java
@@ -71,6 +71,7 @@ public interface IFile {
      *
      * @return list of files contained by this directory, or an empty list if
      *         this is not a directory.
+     * @throws RuntimeException in case of error.
      */
     List<IFile> listFiles();
 
@@ -82,6 +83,7 @@ public interface IFile {
      *            the filter to match names against.
      * @return filtered list of files contained by this directory, or an empty
      *         list if this is not a directory.
+     * @throws RuntimeException in case of error.
      */
     List<IFile> listFiles(FileFilter filter);
 
@@ -97,6 +99,7 @@ public interface IFile {
      * for a directory is not defined.
      *
      * @return local file containing the document wrapped by this object.
+     * @throws RuntimeException in case of error.
      */
     File getDocument();
 }
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
index 24cff82..065887a 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -64,6 +64,7 @@ import android.widget.ListAdapter;
 import android.widget.ListView;
 import android.widget.SpinnerAdapter;
 import android.widget.TextView;
+import android.widget.Toast;
 
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -232,11 +233,24 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
                 // switch document provider:
                 // these operations may imply network access and must be run in
                 // a different thread
-                documentProvider = provider[0];
-                homeDirectory = documentProvider.getRootDirectory();
-                currentDirectory = homeDirectory;
-                filePaths = currentDirectory.listFiles(FileUtilities
-                        .getFileFilter(filterMode));
+                try {
+                    documentProvider = provider[0];
+                    homeDirectory = documentProvider.getRootDirectory();
+                    currentDirectory = homeDirectory;
+                    filePaths = currentDirectory.listFiles(FileUtilities
+                            .getFileFilter(filterMode));
+                }
+                catch (final RuntimeException e) {
+                    final Activity activity = LibreOfficeUIActivity.this;
+                    activity.runOnUiThread(new Runnable() {
+                        @Override
+                        public void run() {
+                            Toast.makeText(activity, e.getMessage(),
+                                    Toast.LENGTH_SHORT).show();
+                        }
+                    });
+                    Log.e(tag, e.getMessage(), e.getCause());
+                }
                 return null;
             }
 
@@ -258,8 +272,21 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
                 // this operation may imply network access and must be run in
                 // a different thread
                 currentDirectory = dir[0];
-                filePaths = currentDirectory.listFiles(FileUtilities
-                        .getFileFilter(filterMode));
+                try {
+                    filePaths = currentDirectory.listFiles(FileUtilities
+                            .getFileFilter(filterMode));
+                }
+                catch (final RuntimeException e) {
+                    final Activity activity = LibreOfficeUIActivity.this;
+                    activity.runOnUiThread(new Runnable() {
+                        @Override
+                        public void run() {
+                            Toast.makeText(activity, e.getMessage(),
+                                    Toast.LENGTH_SHORT).show();
+                        }
+                    });
+                    Log.e(tag, e.getMessage(), e.getCause());
+                }
                 return null;
             }
 
@@ -276,17 +303,33 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
             protected File doInBackground(IFile... document) {
                 // this operation may imply network access and must be run in
                 // a different thread
-                return document[0].getDocument();
+                try {
+                    return document[0].getDocument();
+                }
+                catch (final RuntimeException e) {
+                    final Activity activity = LibreOfficeUIActivity.this;
+                    activity.runOnUiThread(new Runnable() {
+                        @Override
+                        public void run() {
+                            Toast.makeText(activity, e.getMessage(),
+                                    Toast.LENGTH_SHORT).show();
+                        }
+                    });
+                    Log.e(tag, e.getMessage(), e.getCause());
+                    return null;
+                }
             }
 
             @Override
             protected void onPostExecute(File file) {
-                Intent i = new Intent(Intent.ACTION_VIEW, Uri.fromFile(file));
-                String packageName = getApplicationContext().getPackageName();
-                ComponentName componentName = new ComponentName(packageName,
-                        LibreOfficeMainActivity.class.getName());
-                i.setComponent(componentName);
-                startActivity(i);
+                if (file != null) {
+                    Intent i = new Intent(Intent.ACTION_VIEW, Uri.fromFile(file));
+                    String packageName = getApplicationContext().getPackageName();
+                    ComponentName componentName = new ComponentName(packageName,
+                            LibreOfficeMainActivity.class.getName());
+                    i.setComponent(componentName);
+                    startActivity(i);
+                }
             }
         }.execute(document);
     }


More information about the Libreoffice-commits mailing list