Skip to content

Commit

Permalink
got working file browser example from http://androidgenuine.com/wordp…
Browse files Browse the repository at this point in the history
  • Loading branch information
eighthave committed Mar 27, 2012
0 parents commit fc62d4b
Show file tree
Hide file tree
Showing 18 changed files with 256 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin/
gen/
libs/
33 changes: 33 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>IOCipherExample</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
19 changes: 19 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.guardianproject.iocipherexample"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="8"/>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".FileBrowser"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>


</manifest>
14 changes: 14 additions & 0 deletions project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-7
Binary file added res/drawable-hdpi/folder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi/text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-ldpi/folder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-ldpi/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-ldpi/text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/folder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions res/layout/main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id = "@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ListView
android:id = "@android:id/list"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"
android:drawSelectorOnTop = "false"/>
</LinearLayout>
17 changes: 17 additions & 0 deletions res/layout/row.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id ="@+id/icon"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:paddingRight = "2px"
/>
<TextView
android:id = "@+id/label"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:textStyle = "bold"/>
</LinearLayout>
5 changes: 5 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, FileBrowser!</string>
<string name="app_name">IOCipherExample</string>
</resources>
140 changes: 140 additions & 0 deletions src/info/guardianproject/iocipherexample/FileBrowser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package info.guardianproject.iocipherexample;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;



public class FileBrowser extends ListActivity {

private List<String> item = null;
private List<String> path = null;
private TextView fileInfo;
private String[] items;
private String root = "/";

/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
fileInfo = (TextView)findViewById(R.id.info);
getFileList(root);
}

//To make listview for the list of file
public void getFileList(String dirPath){

item = new ArrayList<String>(); //Declare as Array list
path = new ArrayList<String>();



File file = new File(dirPath); // get the file
File[] files = file.listFiles(); //get the list array of file

if(!dirPath.equals(root)){
item.add(root);
path.add(root);// to get back to main list

item.add("..");
path.add(file.getParent()); // back one level
}

for (int i = 0; i < files.length; i++){

File fileItem = files[i];
path.add(fileItem.getPath());
if(fileItem.isDirectory()){
item.add("["+fileItem.getName()+"]"); // input name directory to array list
}
else {
item.add(fileItem.getName()); // input name file to array list
}
}
fileInfo.setText("Info: "+dirPath+" [ " +files.length +" item ]");
items = new String[item.size()]; //declare array with specific number off item
item.toArray(items); //send data arraylist(item) to array(items
setListAdapter(new IconicList()); //set the list with icon
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id){
File file = new File(path.get(position));
if(file.isDirectory()){
if(file.canRead()){
getFileList(path.get(position));
}
else {
new AlertDialog.Builder(this)
.setIcon(R.drawable.icon).setTitle("["+file.getName()+"] folder can't be read")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {

//@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub

}
}).show();

}
}
else {
new AlertDialog.Builder(this)
.setIcon(R.drawable.icon)
.setTitle("["+file.getName()+"]")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {

//@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub

}
}).show();
}
}

class IconicList extends ArrayAdapter {


public IconicList() {
super(FileBrowser.this, R.layout.row, items);

// TODO Auto-generated constructor stub
}

public View getView(int position, View convertView, ViewGroup parent){
LayoutInflater inflater = getLayoutInflater(); //to instantiate layout XML file into its corresponding View objects
View row = inflater.inflate(R.layout.row, null); //to Quick access to the LayoutInflater instance that this Window retrieved from its Context.
TextView label = (TextView)row.findViewById(R.id.label); //access the textview for the name file
ImageView icon = (ImageView)row.findViewById(R.id.icon);//access the imageview for the icon list
label.setText(items[position]);
File f = new File(path.get(position)); //get the file according the position
if(f.isDirectory()){ //decide are the file folder or file
icon.setImageResource(R.drawable.folder);
}
else {
icon.setImageResource(R.drawable.text);
}
return(row);
}



}
}

0 comments on commit fc62d4b

Please sign in to comment.