├── FileExplore
├── .classpath
├── .project
├── AndroidManifest.xml
├── default.properties
├── res
│ ├── drawable-hdpi
│ │ ├── directory_icon.png
│ │ ├── directory_up.png
│ │ ├── file_icon.png
│ │ └── icon.png
│ ├── drawable-ldpi
│ │ └── icon.png
│ ├── drawable-mdpi
│ │ └── icon.png
│ ├── layout
│ │ └── main.xml
│ └── values
│ │ └── strings.xml
└── src
│ └── com
│ └── mburman
│ └── fileexplore
│ └── FileExplore.java
└── README.markdown
/FileExplore/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/FileExplore/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | FileExplore
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/FileExplore/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/FileExplore/default.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "build.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Project target.
11 | target=android-7
12 |
--------------------------------------------------------------------------------
/FileExplore/res/drawable-hdpi/directory_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mburman/Android-File-Explore/7f12d25c424725cb04d6a09e605043f0cd788556/FileExplore/res/drawable-hdpi/directory_icon.png
--------------------------------------------------------------------------------
/FileExplore/res/drawable-hdpi/directory_up.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mburman/Android-File-Explore/7f12d25c424725cb04d6a09e605043f0cd788556/FileExplore/res/drawable-hdpi/directory_up.png
--------------------------------------------------------------------------------
/FileExplore/res/drawable-hdpi/file_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mburman/Android-File-Explore/7f12d25c424725cb04d6a09e605043f0cd788556/FileExplore/res/drawable-hdpi/file_icon.png
--------------------------------------------------------------------------------
/FileExplore/res/drawable-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mburman/Android-File-Explore/7f12d25c424725cb04d6a09e605043f0cd788556/FileExplore/res/drawable-hdpi/icon.png
--------------------------------------------------------------------------------
/FileExplore/res/drawable-ldpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mburman/Android-File-Explore/7f12d25c424725cb04d6a09e605043f0cd788556/FileExplore/res/drawable-ldpi/icon.png
--------------------------------------------------------------------------------
/FileExplore/res/drawable-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mburman/Android-File-Explore/7f12d25c424725cb04d6a09e605043f0cd788556/FileExplore/res/drawable-mdpi/icon.png
--------------------------------------------------------------------------------
/FileExplore/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/FileExplore/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Hello World, FileExplore!
4 | File Explore
5 |
6 |
--------------------------------------------------------------------------------
/FileExplore/src/com/mburman/fileexplore/FileExplore.java:
--------------------------------------------------------------------------------
1 | package com.mburman.fileexplore;
2 |
3 | import java.io.File;
4 | import java.io.FilenameFilter;
5 | import java.util.ArrayList;
6 |
7 | import android.app.Activity;
8 | import android.app.AlertDialog;
9 | import android.app.AlertDialog.Builder;
10 | import android.app.Dialog;
11 | import android.content.DialogInterface;
12 | import android.os.Bundle;
13 | import android.os.Environment;
14 | import android.util.Log;
15 | import android.view.View;
16 | import android.view.ViewGroup;
17 | import android.widget.ArrayAdapter;
18 | import android.widget.ListAdapter;
19 | import android.widget.TextView;
20 |
21 | public class FileExplore extends Activity {
22 |
23 | // Stores names of traversed directories
24 | ArrayList str = new ArrayList();
25 |
26 | // Check if the first level of the directory structure is the one showing
27 | private Boolean firstLvl = true;
28 |
29 | private static final String TAG = "F_PATH";
30 |
31 | private Item[] fileList;
32 | private File path = new File(Environment.getExternalStorageDirectory() + "");
33 | private String chosenFile;
34 | private static final int DIALOG_LOAD_FILE = 1000;
35 |
36 | ListAdapter adapter;
37 |
38 | @Override
39 | public void onCreate(Bundle savedInstanceState) {
40 |
41 | super.onCreate(savedInstanceState);
42 |
43 | loadFileList();
44 |
45 | showDialog(DIALOG_LOAD_FILE);
46 | Log.d(TAG, path.getAbsolutePath());
47 |
48 | }
49 |
50 | private void loadFileList() {
51 | try {
52 | path.mkdirs();
53 | } catch (SecurityException e) {
54 | Log.e(TAG, "unable to write on the sd card ");
55 | }
56 |
57 | // Checks whether path exists
58 | if (path.exists()) {
59 | FilenameFilter filter = new FilenameFilter() {
60 | @Override
61 | public boolean accept(File dir, String filename) {
62 | File sel = new File(dir, filename);
63 | // Filters based on whether the file is hidden or not
64 | return (sel.isFile() || sel.isDirectory())
65 | && !sel.isHidden();
66 |
67 | }
68 | };
69 |
70 | String[] fList = path.list(filter);
71 | fileList = new Item[fList.length];
72 | for (int i = 0; i < fList.length; i++) {
73 | fileList[i] = new Item(fList[i], R.drawable.file_icon);
74 |
75 | // Convert into file path
76 | File sel = new File(path, fList[i]);
77 |
78 | // Set drawables
79 | if (sel.isDirectory()) {
80 | fileList[i].icon = R.drawable.directory_icon;
81 | Log.d("DIRECTORY", fileList[i].file);
82 | } else {
83 | Log.d("FILE", fileList[i].file);
84 | }
85 | }
86 |
87 | if (!firstLvl) {
88 | Item temp[] = new Item[fileList.length + 1];
89 | for (int i = 0; i < fileList.length; i++) {
90 | temp[i + 1] = fileList[i];
91 | }
92 | temp[0] = new Item("Up", R.drawable.directory_up);
93 | fileList = temp;
94 | }
95 | } else {
96 | Log.e(TAG, "path does not exist");
97 | }
98 |
99 | adapter = new ArrayAdapter- (this,
100 | android.R.layout.select_dialog_item, android.R.id.text1,
101 | fileList) {
102 | @Override
103 | public View getView(int position, View convertView, ViewGroup parent) {
104 | // creates view
105 | View view = super.getView(position, convertView, parent);
106 | TextView textView = (TextView) view
107 | .findViewById(android.R.id.text1);
108 |
109 | // put the image on the text view
110 | textView.setCompoundDrawablesWithIntrinsicBounds(
111 | fileList[position].icon, 0, 0, 0);
112 |
113 | // add margin between image and text (support various screen
114 | // densities)
115 | int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f);
116 | textView.setCompoundDrawablePadding(dp5);
117 |
118 | return view;
119 | }
120 | };
121 |
122 | }
123 |
124 | private class Item {
125 | public String file;
126 | public int icon;
127 |
128 | public Item(String file, Integer icon) {
129 | this.file = file;
130 | this.icon = icon;
131 | }
132 |
133 | @Override
134 | public String toString() {
135 | return file;
136 | }
137 | }
138 |
139 | @Override
140 | protected Dialog onCreateDialog(int id) {
141 | Dialog dialog = null;
142 | AlertDialog.Builder builder = new Builder(this);
143 |
144 | if (fileList == null) {
145 | Log.e(TAG, "No files loaded");
146 | dialog = builder.create();
147 | return dialog;
148 | }
149 |
150 | switch (id) {
151 | case DIALOG_LOAD_FILE:
152 | builder.setTitle("Choose your file");
153 | builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
154 | @Override
155 | public void onClick(DialogInterface dialog, int which) {
156 | chosenFile = fileList[which].file;
157 | File sel = new File(path + "/" + chosenFile);
158 | if (sel.isDirectory()) {
159 | firstLvl = false;
160 |
161 | // Adds chosen directory to list
162 | str.add(chosenFile);
163 | fileList = null;
164 | path = new File(sel + "");
165 |
166 | loadFileList();
167 |
168 | removeDialog(DIALOG_LOAD_FILE);
169 | showDialog(DIALOG_LOAD_FILE);
170 | Log.d(TAG, path.getAbsolutePath());
171 |
172 | }
173 |
174 | // Checks if 'up' was clicked
175 | else if (chosenFile.equalsIgnoreCase("up") && !sel.exists()) {
176 |
177 | // present directory removed from list
178 | String s = str.remove(str.size() - 1);
179 |
180 | // path modified to exclude present directory
181 | path = new File(path.toString().substring(0,
182 | path.toString().lastIndexOf(s)));
183 | fileList = null;
184 |
185 | // if there are no more directories in the list, then
186 | // its the first level
187 | if (str.isEmpty()) {
188 | firstLvl = true;
189 | }
190 | loadFileList();
191 |
192 | removeDialog(DIALOG_LOAD_FILE);
193 | showDialog(DIALOG_LOAD_FILE);
194 | Log.d(TAG, path.getAbsolutePath());
195 |
196 | }
197 | // File picked
198 | else {
199 | // Perform action with file picked
200 | }
201 |
202 | }
203 | });
204 | break;
205 | }
206 | dialog = builder.show();
207 | return dialog;
208 | }
209 |
210 | }
--------------------------------------------------------------------------------
/README.markdown:
--------------------------------------------------------------------------------
1 | #Android File Explore Implementation
2 |
3 | ###This is an android file explorer implementation. Features include:
4 | * Ability to navigate through multiple heirarchial levels
5 | * Ability to select a file & or directory
6 | * Currently does not support adding or deleting files
7 | * Also does not support opening files once selected. This feature can be implemented very seasily using intents. [Display applications that handle a particular filetype](http://stackoverflow.com/questions/5305731/display-applications-that-can-handle-a-particular-filetype).
8 |
9 | ###How to use:
10 | * Copy the FileExplore.java source file into your project
11 | * Copy the res folder. This contains graphical elements to improve file browsing
12 | * In FileExplore.java, search for the comment //Perform action with file picked
13 | * Just add your own functionality in there
14 |
15 | ###Note:
16 | * This is not (yet) an Android Library project. I plan to make it one though in the future and add a few more features. Until then you can get by by modifying the source file.
17 | * A similar library can be found at https://github.com/vaal12/AndroidFileBrowser, which provides a separate Activity (not Dialog) to browse and select files and directories on the phone. That library is based on the code from Android File Explore.
18 |
19 | ###Licence:
20 |
21 | > Copyright 2011 Manish Burman
22 |
23 | > Licensed under the Apache License, Version 2.0 (the "License");
24 | > you may not use this file except in compliance with the License.
25 | > You may obtain a copy of the License at
26 |
27 | > http://www.apache.org/licenses/LICENSE-2.0
28 |
29 | > Unless required by applicable law or agreed to in writing, software
30 | > distributed under the License is distributed on an "AS IS" BASIS,
31 | > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32 | > See the License for the specific language governing permissions and
33 | > limitations under the License.
34 |
35 |
--------------------------------------------------------------------------------