diff options
author | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2014-12-03 19:07:11 +0000 |
---|---|---|
committer | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2015-01-09 10:51:24 +0000 |
commit | 04df164860df64fe0b54f1a13b010101c49d38c7 (patch) | |
tree | 848e81252fe0359c25f24a169739b311219c2f0e | |
parent | 60dd2161bb21a9232a163ce785dd18227e25a335 (diff) |
Android: add share feature in the context menu
Known issues: the mimetype returned for .odp files is null and share
does not work on these files.
Change-Id: I61e752763a6934657c30fff3cefc57ac0144ec71
3 files changed, 22 insertions, 0 deletions
diff --git a/android/experimental/LOAndroid3/res/menu/context_menu.xml b/android/experimental/LOAndroid3/res/menu/context_menu.xml index 3951971b4b2c..43824875d867 100644 --- a/android/experimental/LOAndroid3/res/menu/context_menu.xml +++ b/android/experimental/LOAndroid3/res/menu/context_menu.xml @@ -2,4 +2,6 @@ <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/context_menu_open" android:title="@string/open"/> + <item android:id="@+id/context_menu_share" + android:title="@string/share"/> </menu> diff --git a/android/experimental/LOAndroid3/res/values/strings.xml b/android/experimental/LOAndroid3/res/values/strings.xml index bfaa7abee839..473616a9d9e5 100644 --- a/android/experimental/LOAndroid3/res/values/strings.xml +++ b/android/experimental/LOAndroid3/res/values/strings.xml @@ -26,5 +26,7 @@ <string name="action_about">About</string> <string name="action_parts">Parts</string> <string name="open">Open</string> + <string name="share">Share</string> + <string name="share_via">Share via</string> </resources> 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 df7d6fa78d53..61f8450842c8 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java @@ -46,6 +46,7 @@ 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; @@ -172,6 +173,9 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga case R.id.context_menu_open: open(info.position); return true; + case R.id.context_menu_share: + share(info.position); + return true; default: return super.onContextItemSelected(item); } @@ -221,6 +225,20 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga } } + private void share(int position) { + File file = filePaths[position]; + 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.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))); + } + @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); |