[Libreoffice-commits] .: android/experimental

Iain Billett iainb at kemper.freedesktop.org
Thu Jun 14 09:37:30 PDT 2012


 android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/res/layout/file_explorer.xml                      |   20 --
 android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/res/layout/file_grid.xml                          |   20 ++
 android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/res/values/strings.xml                            |    6 
 android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/FileUtilities.java         |   88 +++++++++
 android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/GridItemAdapter.java       |   12 -
 android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/LibreOfficeUIActivity.java |   92 +++++++---
 android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/src/org/libreoffice/ui/WriterViewerActivity.java  |   16 +
 7 files changed, 203 insertions(+), 51 deletions(-)

New commits:
commit 06a5ea83858607e8ca4e628b2ac5ef0267335983
Author: Iain Billett <Iain at Iains-MacBook-Pro.local>
Date:   Thu Jun 14 17:33:16 2012 +0100

    More work on the file explorer. Added file type filtering. Maintains state if user switches to viewer and back.

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_explorer.xml
deleted file mode 100644
index 1e241c0..0000000
--- a/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/res/layout/file_explorer.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:orientation="vertical" >
-
-    <GridView
-        android:id="@+id/file_explorer_grid_view"
-    	android:layout_width="fill_parent" 
-	    android:layout_height="fill_parent"
-	    android:columnWidth="120dp"
-	    android:numColumns="auto_fit"
-	    android:verticalSpacing="10dp"
-	    android:horizontalSpacing="10dp"
-	    android:stretchMode="columnWidth"
-	    android:gravity="center">
-    </GridView>
-	
-	
-</LinearLayout>
\ No newline at end of file
diff --git a/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/res/layout/file_grid.xml b/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/res/layout/file_grid.xml
new file mode 100644
index 0000000..1e241c0
--- /dev/null
+++ b/android/experimental/GSoC-2012-eclipse-workspace/LibreOfficeUI/res/layout/file_grid.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical" >
+
+    <GridView
+        android:id="@+id/file_explorer_grid_view"
+    	android:layout_width="fill_parent" 
+	    android:layout_height="fill_parent"
+	    android:columnWidth="120dp"
+	    android:numColumns="auto_fit"
+	    android:verticalSpacing="10dp"
+	    android:horizontalSpacing="10dp"
+	    android:stretchMode="columnWidth"
+	    android:gravity="center">
+    </GridView>
+	
+	
+</LinearLayout>
\ No newline at end of file
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 1dfa489..71466de 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 0000000..3b6bbf3
--- /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 a2cf56a..9585705 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 05ef291..6664467 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 f56e577..75f3b1a 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;


More information about the Libreoffice-commits mailing list