-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBrowser.java
125 lines (112 loc) · 2.96 KB
/
Browser.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Binaural player
* © Nicolas George -- 2010
* Files browser
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*/
package org.cigaes.binaural_player;
import java.io.File;
import java.util.Arrays;
import android.content.Context;
import android.widget.*;
import android.view.View;
import android.os.PatternMatcher;
public class Browser extends LinearLayout
implements TabHost.TabContentFactory, AdapterView.OnItemClickListener
{
File cur_dir;
PatternMatcher glob;
File_click_listener callback;
final TextView wid_cur_dir;
final ListView wid_files;
final ArrayAdapter<String> files;
public Browser(Context context)
{
super(context);
setOrientation(VERTICAL);
wid_cur_dir = new TextView(context);
addView(wid_cur_dir);
wid_files = new ListView(context);
wid_files.setFastScrollEnabled(true);
files = new ArrayAdapter<String>(context,
android.R.layout.simple_list_item_1);
wid_files.setAdapter(files);
wid_files.setOnItemClickListener(this);
addView(wid_files);
}
public void set_file_click_listener(File_click_listener c)
{
callback = c;
}
public void set_glob(String g)
{
set_glob(new PatternMatcher(g, PatternMatcher.PATTERN_SIMPLE_GLOB));
}
public void set_glob(PatternMatcher m)
{
glob = m;
}
public void chdir(String dir)
{
chdir(new File(dir));
}
public void chdir(File dir)
{
cur_dir = dir;
wid_cur_dir.setText(cur_dir.getPath());
files.clear();
files.add("../");
File[] lf = dir.listFiles();
if(lf == null)
return;
Arrays.sort(lf);
for(int i = 0; i < lf.length; i++) {
if(lf[i].isDirectory()) {
files.add(lf[i].getName() + "/");
lf[i] = null;
}
}
for(int i = 0; i < lf.length; i++) {
if(lf[i] == null)
continue;
String n = lf[i].getName();
if(glob != null && !glob.match(n))
continue;
files.add(n);
lf[i] = null;
}
wid_files.scrollTo(0, 0);
}
public File get_dir()
{
return cur_dir;
}
public void onItemClick(AdapterView list, View view, int item, long row)
{
String f = files.getItem(item);
int fl = f.length() - 1;
if(fl >= 0 && f.charAt(fl) == '/') {
String d = f.substring(0, fl);
File nd = d.equals("..") ? cur_dir.getParentFile() :
new File(cur_dir, d);
//android.util.Log.v("Binaural_player", "-> " + );
chdir(nd);
} else {
callback.on_browser_file_click(new File(cur_dir, f));
}
}
public android.view.View createTabContent(String tag) {
return this;
}
public interface File_click_listener {
public void on_browser_file_click(File f);
}
}