[Libreoffice-commits] core.git: android/experimental
Jacobo Aragunde Pérez
jaragunde at igalia.com
Tue Feb 10 10:05:49 PST 2015
android/experimental/LOAndroid3/src/java/org/libreoffice/ui/FileUtilities.java | 30 ++++++++++
android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java | 5 -
2 files changed, 31 insertions(+), 4 deletions(-)
New commits:
commit 5654e0f6afd93b371954456523460397564b4602
Author: Jacobo Aragunde Pérez <jaragunde at igalia.com>
Date: Tue Feb 10 18:42:40 2015 +0100
Android: fix share feature for .odp/.odt files
Added our own map of MIME types because we cannot rely on Android's.
Change-Id: I11d4b639f42d30aa8adb0ea092797fb30b4fc8b9
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/FileUtilities.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/FileUtilities.java
index f658d92..118eded 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/FileUtilities.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/FileUtilities.java
@@ -18,6 +18,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Comparator;
import android.util.Log;
+import android.webkit.MimeTypeMap;
public class FileUtilities {
static final int ALL = -1;
@@ -42,6 +43,7 @@ public class FileUtilities {
static final int SORT_SMALLEST = 5;
private static final Map<String,Integer> mExtnMap = new HashMap<String,Integer>();
+ private static final Map<String, String> extensionToMimeTypeMap = new HashMap<String, String>();
static {
// Please keep this in sync with AndroidManifest.xml
@@ -97,6 +99,22 @@ public class FileUtilities {
mExtnMap.put(".svm", DRAWING);
mExtnMap.put(".wmf", DRAWING);
mExtnMap.put(".svg", DRAWING);
+
+ // Some basic MIME types
+ // Android's MimeTypeMap lacks some types that we need
+ extensionToMimeTypeMap.put("odb", "application/vnd.oasis.opendocument.database");
+ extensionToMimeTypeMap.put("odf", "application/vnd.oasis.opendocument.formula");
+ extensionToMimeTypeMap.put("odg", "application/vnd.oasis.opendocument.graphics");
+ extensionToMimeTypeMap.put("otg", "application/vnd.oasis.opendocument.graphics-template");
+ extensionToMimeTypeMap.put("odi", "application/vnd.oasis.opendocument.image");
+ extensionToMimeTypeMap.put("odp", "application/vnd.oasis.opendocument.presentation");
+ extensionToMimeTypeMap.put("otp", "application/vnd.oasis.opendocument.presentation-template");
+ extensionToMimeTypeMap.put("ods", "application/vnd.oasis.opendocument.spreadsheet");
+ extensionToMimeTypeMap.put("ots", "application/vnd.oasis.opendocument.spreadsheet-template");
+ extensionToMimeTypeMap.put("odt", "application/vnd.oasis.opendocument.text");
+ extensionToMimeTypeMap.put("odm", "application/vnd.oasis.opendocument.text-master");
+ extensionToMimeTypeMap.put("ott", "application/vnd.oasis.opendocument.text-template");
+ extensionToMimeTypeMap.put("oth", "application/vnd.oasis.opendocument.text-web");
}
private static final String getExtension(String filename)
@@ -124,6 +142,18 @@ public class FileUtilities {
return type;
}
+ static String getMimeType(String filename)
+ {
+ String extension = MimeTypeMap.getFileExtensionFromUrl(filename);
+ String mime = extensionToMimeTypeMap.get(extension);
+ if(mime == null) {
+ //fallback to Android's MimeTypeMap
+ mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
+ extension);
+ }
+ return mime;
+ }
+
// Filter by mode, and/or in future by filename/wildcard
static private boolean doAccept(String filename, int byMode, String byFilename)
{
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 25870c0..24cff82 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -54,7 +54,6 @@ import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
-import android.webkit.MimeTypeMap;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
@@ -321,9 +320,7 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
File file = filePaths.get(position).getDocument();
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
Uri uri = Uri.fromFile(file);
- String extension = MimeTypeMap.getFileExtensionFromUrl(uri.toString());
- sharingIntent.setType(MimeTypeMap.getSingleton()
- .getMimeTypeFromExtension(extension));
+ sharingIntent.setType(FileUtilities.getMimeType(file.getName()));
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, uri);
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
file.getName());
More information about the Libreoffice-commits
mailing list