summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacobo Aragunde Pérez <jaragunde@igalia.com>2014-12-03 17:04:27 +0000
committerJacobo Aragunde Pérez <jaragunde@igalia.com>2015-01-09 10:51:24 +0000
commit60dd2161bb21a9232a163ce785dd18227e25a335 (patch)
tree8a76e6f04f6c55f6276e072ea697127b4249b98e
parent2e3655bb51785d14b5e5bd3b07e0b6ae2fe1f86b (diff)
Android: add context menu in document browser
Change-Id: I234f7ddb99570498f86449cf61ceb72696995b0d
-rw-r--r--android/experimental/LOAndroid3/res/menu/context_menu.xml5
-rw-r--r--android/experimental/LOAndroid3/res/values/strings.xml1
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java61
3 files changed, 54 insertions, 13 deletions
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 000000000000..3951971b4b2c
--- /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 ea505d7e5f3e..bfaa7abee839 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 d17149404eef..df7d6fa78d53 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;
+ }
+
+ });