-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileCacher.java
37 lines (31 loc) · 950 Bytes
/
FileCacher.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
package wags.gravatar;
import android.content.Context;
import android.os.Environment;
import java.io.File;
public class FileCacher {
private File cacherDir;
public FileCacher(Context context) {
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
cacherDir = new File(Environment.getExternalStorageDirectory(), "fcImages");
} else {
cacherDir = context.getCacheDir();
}
if (!cacherDir.mkdirs()) {
cacherDir.mkdirs();
}
}
public File getFile(String url) {
String Filename = String.valueOf(url.hashCode());
File f = new File(cacherDir, Filename);
return f;
}
public void clear() {
File[] files = cacherDir.listFiles();
if (files == null) {
return;
}
for (File f : files) {
f.delete();
}
}
}