[Libreoffice-commits] core.git: 2 commits - android/experimental
Jacobo Aragunde Pérez
jaragunde at igalia.com
Fri Jan 9 02:52:43 PST 2015
android/experimental/LOAndroid3/res/menu/context_menu.xml | 7
android/experimental/LOAndroid3/res/values/strings.xml | 3
android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java | 79 ++++++++--
3 files changed, 76 insertions(+), 13 deletions(-)
New commits:
commit 04df164860df64fe0b54f1a13b010101c49d38c7
Author: Jacobo Aragunde Pérez <jaragunde at igalia.com>
Date: Wed Dec 3 19:07:11 2014 +0000
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
diff --git a/android/experimental/LOAndroid3/res/menu/context_menu.xml b/android/experimental/LOAndroid3/res/menu/context_menu.xml
index 3951971..4382487 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 bfaa7ab..473616a 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 df7d6fa..61f8450 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();
commit 60dd2161bb21a9232a163ce785dd18227e25a335
Author: Jacobo Aragunde Pérez <jaragunde at igalia.com>
Date: Wed Dec 3 17:04:27 2014 +0000
Android: add context menu in document browser
Change-Id: I234f7ddb99570498f86449cf61ceb72696995b0d
diff --git a/android/experimental/LOAndroid3/res/menu/context_menu.xml b/android/experimental/LOAndroid3/res/menu/context_menu.xml
new file mode 100644
index 0000000..3951971
--- /dev/null
+++ b/android/experimental/LOAndroid3/res/menu/context_menu.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android" >
+ <item android:id="@+id/context_menu_open"
+ android:title="@string/open"/>
+</menu>
diff --git a/android/experimental/LOAndroid3/res/values/strings.xml b/android/experimental/LOAndroid3/res/values/strings.xml
index ea505d7..bfaa7ab 100644
--- a/android/experimental/LOAndroid3/res/values/strings.xml
+++ b/android/experimental/LOAndroid3/res/values/strings.xml
@@ -25,5 +25,6 @@
<string name="action_about">About</string>
<string name="action_parts">Parts</string>
+ <string name="open">Open</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 d171494..df7d6fa 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -36,14 +36,18 @@ import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.util.Log;
+import android.view.ContextMenu;
+import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
+import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
+import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.GridView;
@@ -134,17 +138,12 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
gv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
- File file = filePaths[position];
- if(!file.isDirectory()){
- open(file);
- }else{
- openDirectory( file );
- }
-
+ open(position);
}
});
gv.setAdapter( new GridItemAdapter(getApplicationContext(), currentDirectory, filePaths ) );
actionBar.setSelectedNavigationItem( filterMode + 1 );//This triggers the listener which modifies the view.
+ registerForContextMenu(gv);
}else{
setContentView(R.layout.file_list);
lv = (ListView)findViewById( R.id.file_explorer_list_view);
@@ -152,10 +151,32 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
filePaths = currentDirectory.listFiles( FileUtilities.getFileFilter( filterMode ) );
lv.setAdapter( new ListItemAdapter(getApplicationContext(), filePaths) );
actionBar.setSelectedNavigationItem( filterMode + 1 );
+ registerForContextMenu(lv);
}
}
+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View v,
+ ContextMenuInfo menuInfo) {
+ super.onCreateContextMenu(menu, v, menuInfo);
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.context_menu, menu);
+ }
+
+ @Override
+ public boolean onContextItemSelected(MenuItem item) {
+ AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
+ .getMenuInfo();
+ switch (item.getItemId()) {
+ case R.id.context_menu_open:
+ open(info.position);
+ return true;
+ default:
+ return super.onContextItemSelected(item);
+ }
+ }
+
public void openDirectory(File dir ){
currentDirectory = dir;
if( !currentDirectory.equals( homeDirectory )){
@@ -191,6 +212,15 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
startActivity(i);
}
+ private void open(int position) {
+ File file = filePaths[position];
+ if (!file.isDirectory()) {
+ open(file);
+ } else {
+ openDirectory(file);
+ }
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
@@ -423,14 +453,19 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
listItem.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
- Log.d("LIST", "click!");
- if(filePaths[ pos ].isDirectory() ){
- openDirectory( filePaths[ pos ] );
- }else{
- open( filePaths[ pos ] );
- }
+ open(pos);
}
});
+ listItem.setOnLongClickListener(new OnLongClickListener() {
+
+ @Override
+ public boolean onLongClick(View v) {
+ // workaround to show the context menu:
+ // prevent onClickListener from getting this event
+ return false;
+ }
+
+ });
More information about the Libreoffice-commits
mailing list