-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
got working file browser example from http://androidgenuine.com/wordp…
- Loading branch information
0 parents
commit fc62d4b
Showing
18 changed files
with
256 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
bin/ | ||
gen/ | ||
libs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
140
src/info/guardianproject/iocipherexample/FileBrowser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
|
||
|
||
} | ||
} |