summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorIain Billett <Iain@Iains-MacBook-Pro.local>2012-06-14 17:33:16 +0100
committerIain Billett <Iain@Iains-MacBook-Pro.local>2012-06-14 17:33:16 +0100
commit06a5ea83858607e8ca4e628b2ac5ef0267335983 (patch)
treee913bd5b872b4ff556308ab54aadfb1b24229f1b /android
parent16468bd2ea7bdefd859b68c978fdb3397d53a4d4 (diff)
More work on the file explorer. Added file type filtering. Maintains state if user switches to viewer and back.
Diffstat (limited to 'android')
-rw-r--r--android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/res/layout/file_grid.xml (renamed from android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/res/layout/file_explorer.xml)0
-rw-r--r--android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/res/values/strings.xml6
-rw-r--r--android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/FileUtilities.java88
-rw-r--r--android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/GridItemAdapter.java12
-rw-r--r--android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/LibreOfficeUIActivity.java92
-rw-r--r--android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/WriterViewerActivity.java16
6 files changed, 183 insertions, 31 deletions
diff --git a/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/res/layout/file_explorer.xml b/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/res/layout/file_grid.xml
index 1e241c00a13a..1e241c00a13a 100644
--- a/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/res/layout/file_explorer.xml
+++ b/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/res/layout/file_grid.xml
diff --git a/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/res/values/strings.xml b/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/res/values/strings.xml
index 1dfa48989749..71466dee742c 100644
--- a/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/res/values/strings.xml
+++ b/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/res/values/strings.xml
@@ -4,5 +4,11 @@
<string name="hello">Hello World, LibreOfficeUIActivity!</string>
<string name="app_name">LibreOfficeUI</string>
<string name="menu_search">Search</string>
+ <string-array name="file_view_modes">
+ <item >EVERYTHING</item>
+ <item >DOCUMENTS</item>
+ <item >SPREADSHEETS</item>
+ <item >PRESENTATIONS</item>
+ </string-array>
</resources> \ No newline at end of file
diff --git a/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/FileUtilities.java b/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/FileUtilities.java
new file mode 100644
index 000000000000..3b6bbf32f2aa
--- /dev/null
+++ b/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/FileUtilities.java
@@ -0,0 +1,88 @@
+package org.libreoffice.ui;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FilenameFilter;
+
+public class FileUtilities {
+
+ static final int ALL = -1;
+ static final int DOC = 0;
+ static final int CALC = 1;
+ static final int IMPRESS = 2;
+
+ private static String[] fileExtensions = {".odt",".ods",".odp"};
+
+ static boolean isDoc(String filename){
+ if( filename.endsWith( fileExtensions[ DOC ] ) ){
+ return true;
+ }
+ return false;
+ }
+
+ static boolean isCalc(String filename){
+ if( filename.endsWith( fileExtensions[ CALC ] ) ){
+ return true;
+ }
+ return false;
+ }
+
+ static boolean isImpress(String filename){
+ if( filename.endsWith( fileExtensions[ IMPRESS ] ) ){
+ return true;
+ }
+ return false;
+ }
+
+ static FileFilter getFileFilter(int mode){
+ if( mode != ALL){
+ final String ext = fileExtensions[ mode ];
+ return new FileFilter() {
+
+ public boolean accept(File pathname) {
+ if( pathname.getName().endsWith( ext ) ){
+ return true;
+ }
+ if( pathname.isDirectory() ){
+ return true;
+ }
+ return false;
+ }
+ };
+ }else{//return all
+ return new FileFilter() {
+
+ public boolean accept(File pathname) {
+ // TODO Auto-generated method stub
+ return true;
+ }
+ };
+ }
+ }
+
+ static FilenameFilter getFilenameFilter(int mode){
+ if( mode != ALL){
+ final String ext = fileExtensions[ mode ];
+ return new FilenameFilter() {
+
+ public boolean accept(File dir, String filename) {
+ if( filename.endsWith( ext ) ){
+ return true;
+ }
+ if( new File( dir , filename ).isDirectory() ){
+ return true;
+ }
+ return false;
+ }
+ };
+ }else{
+ return new FilenameFilter() {
+
+ public boolean accept(File dir, String filename) {
+ return true;
+ }
+ };
+ }
+ }
+
+}
diff --git a/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/GridItemAdapter.java b/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/GridItemAdapter.java
index a2cf56ab1713..9585705d5e06 100644
--- a/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/GridItemAdapter.java
+++ b/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/GridItemAdapter.java
@@ -30,6 +30,12 @@ public class GridItemAdapter extends BaseAdapter{
this.currentDirectory = currentDirectory;
filePaths = currentDirectory.listFiles();
}
+
+ public GridItemAdapter(Context mContext, File currentDirectory, File[] filteredFiles) {
+ this.mContext = mContext;
+ this.currentDirectory = currentDirectory;
+ filePaths = filteredFiles;
+ }
public int getCount() {
return filePaths.length;
@@ -69,13 +75,13 @@ public class GridItemAdapter extends BaseAdapter{
// set image based on selected text
ImageView imageView = (ImageView) gridView
.findViewById(R.id.grid_item_image);
- if( filePaths[position].getName().contains(".odt") ){
+ if( filePaths[position].getName().endsWith(".odt") ){
imageView.setImageResource(R.drawable.writer);
}
- if( filePaths[position].getName().contains(".ods") ){
+ if( filePaths[position].getName().endsWith(".ods") ){
imageView.setImageResource(R.drawable.calc);
}
- if( filePaths[position].getName().contains(".odp") ){
+ if( filePaths[position].getName().endsWith(".odp") ){
imageView.setImageResource(R.drawable.impress);
}
if( filePaths[position].isDirectory() ){//Is a folder
diff --git a/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/LibreOfficeUIActivity.java
index 05ef291f040d..6664467278cc 100644
--- a/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -2,8 +2,11 @@ package org.libreoffice.ui;
import java.io.File;
import java.io.FileFilter;
+import java.io.FilenameFilter;
import java.io.IOException;
+import android.app.ActionBar;
+import android.app.ActionBar.OnNavigationListener;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
@@ -24,43 +27,68 @@ import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ListView;
+import android.widget.SpinnerAdapter;
import android.widget.TextView;
import android.widget.Toast;
-public class LibreOfficeUIActivity extends Activity {
+public class LibreOfficeUIActivity extends Activity implements OnNavigationListener {
private String tag = "file_manager";
private File homeDirectory;//make final?
private File currentDirectory;
+ private String filter = "";
+ private String[] filters = {"all",".odt",".ods",".odp"};
+ private int filterMode = FileUtilities.ALL;
+ FileFilter fileFilter;
+ FilenameFilter filenameFilter;
private String[] fileNames;
private File[] filePaths;
private String currentDirectoryKey = "CURRENT_DIRECTORY";
+ private String filterModeKey = "FILTER_MODE";
+
GridView gv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.file_explorer);
- gv = (GridView)findViewById(R.id.file_explorer_grid_view);
+ setContentView(R.layout.file_grid);
+ ActionBar actionBar = getActionBar();
+ actionBar.setDisplayShowTitleEnabled(false);//This should show current directory if anything
+ actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
+ SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.file_view_modes,
+ android.R.layout.simple_spinner_dropdown_item);
+ actionBar.setListNavigationCallbacks(mSpinnerAdapter, this);
+
- //Need to sort out how best to maintain application state (directory, basically)
+ homeDirectory = new File(Environment.getExternalStorageDirectory(),"LibreOffice");
Intent i = this.getIntent();
if( i.hasExtra( currentDirectoryKey ) ){
//This isn't what I think it is. It's not a full path
currentDirectory = new File( i.getStringExtra( currentDirectoryKey ) );
+ }else{
+ currentDirectory = homeDirectory;
}
- homeDirectory = new File(Environment.getExternalStorageDirectory(),"LibreOffice");
- currentDirectory = homeDirectory;
+ if( i.hasExtra( filterModeKey ) ){
+ Log.d(filterModeKey+"_GRID_OC" , Integer.toString( i.getIntExtra( filterModeKey, FileUtilities.ALL ) ));
+ filterMode = i.getIntExtra( filterModeKey, FileUtilities.ALL);
+ }
+ if( !currentDirectory.equals( homeDirectory )){
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ }
+
+ //fileFilter = FileUtilities.getFileFilter( filterMode );
+ //filenameFilter = FileUtilities.getFilenameFilter( filterMode );
+
//createDummyFileSystem();
- filePaths = new File[ currentDirectory.listFiles().length ];
- fileNames = new String[ filePaths.length ];
- filePaths = currentDirectory.listFiles();// Need to write a class to order lists of Files
- fileNames = currentDirectory.list();// should be based on filePaths -> keep same order
+ //filePaths = currentDirectory.listFiles( fileFilter );
+ //order/filter filePaths here
+ //fileNames = currentDirectory.list( filenameFilter );
// code to make a grid view
- GridItemAdapter gridAdapter = new GridItemAdapter(getApplicationContext(), filePaths );
- gv.setAdapter(gridAdapter);
+ gv = (GridView)findViewById(R.id.file_explorer_grid_view);
+ //GridItemAdapter gridAdapter = new GridItemAdapter(getApplicationContext(), filePaths );
+ //gv.setAdapter(gridAdapter);
gv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
@@ -78,21 +106,30 @@ public class LibreOfficeUIActivity extends Activity {
}
});
-
-
+ actionBar.setSelectedNavigationItem( filterMode + 1 );//This triggers the listener which modifies the view.
+ //openDirectory( currentDirectory );
}
- public void openDirectory(File dir){
+ public void openDirectory(File dir ){
currentDirectory = dir;
- fileNames = currentDirectory.list();
- filePaths = currentDirectory.listFiles();
- gv.setAdapter( new GridItemAdapter(getApplicationContext(), currentDirectory ) );
+ Log.d(tag, dir.toString() + " " + homeDirectory.toString());
+ if( !currentDirectory.equals( homeDirectory )){
+ ActionBar actionBar = getActionBar();
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ }else{
+ ActionBar actionBar = getActionBar();
+ actionBar.setDisplayHomeAsUpEnabled( false );
+ }
+ fileNames = currentDirectory.list( FileUtilities.getFilenameFilter( filterMode ) );
+ filePaths = currentDirectory.listFiles( FileUtilities.getFileFilter( filterMode ) );
+ gv.setAdapter( new GridItemAdapter(getApplicationContext(), currentDirectory, filePaths ) );
}
public void open(String file){
//Should add file to the intent as an extra
Intent i = new Intent( this , WriterViewerActivity.class );
- i.putExtra( currentDirectoryKey, currentDirectory.getName() );
+ i.putExtra( currentDirectoryKey , currentDirectory.getAbsolutePath() );
+ i.putExtra( filterModeKey , filterMode );
startActivity( i );
}
@@ -107,9 +144,9 @@ public class LibreOfficeUIActivity extends Activity {
switch (item.getItemId()) {
case android.R.id.home:
// app icon in action bar clicked; go home
- Intent intent = new Intent(this, LibreOfficeUIActivity.class);
+ //Intent intent = new Intent(this, LibreOfficeUIActivity.class);
//intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(intent);
+ //startActivity(intent);
if( !currentDirectory.equals( homeDirectory ) ){
openDirectory( currentDirectory.getParentFile() );
}
@@ -167,6 +204,9 @@ public class LibreOfficeUIActivity extends Activity {
File regularDirectory = new File( currentDirectory , "Folder" );
regularDirectory.mkdir();
new File( regularDirectory , "yetAnotherDoc.odt" ).createNewFile();
+ File anotherRegularDirectory = new File( regularDirectory , "AnotherFolder" );
+ anotherRegularDirectory.mkdir();
+ new File( anotherRegularDirectory , "yetAnotherDoc2.odt" ).createNewFile();
//Should put a folder in at some stage.
} catch (IOException e) {
@@ -184,14 +224,14 @@ public class LibreOfficeUIActivity extends Activity {
protected void onSaveInstanceState(Bundle outState) {
// TODO Auto-generated method stub
super.onSaveInstanceState(outState);
- outState.putString( currentDirectoryKey , currentDirectory.getName() );
+ outState.putString( currentDirectoryKey , currentDirectory.getAbsolutePath() );
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onRestoreInstanceState(savedInstanceState);
- currentDirectory = new File( savedInstanceState.getString( currentDirectoryKey ) );
+ //currentDirectory = new File( savedInstanceState.getString( currentDirectoryKey ) );
}
@Override
@@ -200,6 +240,12 @@ public class LibreOfficeUIActivity extends Activity {
super.onPause();
}
+
+ public boolean onNavigationItemSelected(int itemPosition, long itemId) {
+ filterMode = itemPosition -1; //bit of a hack, I know. -1 is ALL 0 Docs etc
+ openDirectory( currentDirectory );// Uses filter mode
+ return true;
+ }
}
diff --git a/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/WriterViewerActivity.java b/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/WriterViewerActivity.java
index f56e577b141e..75f3b1af5020 100644
--- a/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/WriterViewerActivity.java
+++ b/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/WriterViewerActivity.java
@@ -12,16 +12,21 @@ import android.view.MenuItem;
public class WriterViewerActivity extends Activity{
private String currentDirectoryKey = "CURRENT_DIRECTORY";
- File file;
+ private String filterModeKey = "FILTER_MODE";
+ File dir;
+ private int filterMode;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
- Intent i = new Intent();
- i = this.getIntent();
+ Intent i = this.getIntent();
if( i.hasExtra( currentDirectoryKey ) ){
Log.d(currentDirectoryKey, i.getStringExtra( currentDirectoryKey ) );
- file = new File( i.getStringExtra( currentDirectoryKey ) );
+ dir = new File( i.getStringExtra( currentDirectoryKey ) );
+ }
+ if( i.hasExtra( filterModeKey ) ){
+ //Log.d("FILTER_OC_WRITER", Integer.toString(i.getIntExtra( filterModeKey , FileUtilities.ALL )));
+ filterMode = i.getIntExtra( filterModeKey , FileUtilities.ALL );
}
setContentView(R.layout.main);
ActionBar actionBar = getActionBar();
@@ -34,7 +39,8 @@ public class WriterViewerActivity extends Activity{
case android.R.id.home:
// app icon in action bar clicked; go home
Intent intent = new Intent(this, LibreOfficeUIActivity.class);
- intent.putExtra(currentDirectoryKey, file );
+ intent.putExtra(currentDirectoryKey, dir.getAbsolutePath() );
+ intent.putExtra( filterModeKey , filterMode );
//intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;