diff options
author | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2015-02-10 16:17:12 +0000 |
---|---|---|
committer | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2015-02-12 20:23:03 +0000 |
commit | 9e8fa856918e018f8bde4067fdbdbb37e2eaa288 (patch) | |
tree | b56e70b4a044b351986cf5df45a0a2e669bc7898 /android | |
parent | 8c5e87852965715389d0bed87eefc663a149f052 (diff) |
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
Diffstat (limited to 'android')
3 files changed, 62 insertions, 14 deletions
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 191a1437e26b..bbfdecd94d48 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 5b71c09c051c..8effd0f6b73b 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 24cff823b2a0..065887a3743b 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); } |