package loon;
import loon.core.FileHandle;
import android.content.res.AssetManager;
import android.os.Environment;
public class AndroidFiles implements Files {
protected final String sdcard = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
protected final String localpath;
protected final AssetManager assets;
public AndroidFiles (AssetManager assets) {
this.assets = assets;
localpath = sdcard;
}
public AndroidFiles (AssetManager assets, String localpath) {
this.assets = assets;
this.localpath = localpath.endsWith("/") ? localpath : localpath + "/";
}
@Override
public FileHandle getFileHandle (String path, FileType type) {
return new AndroidFileHandle(type == FileType.Internal ? assets : null, path, type);
}
@Override
public FileHandle classpath (String path) {
return new AndroidFileHandle(null, path, FileType.Classpath);
}
@Override
public FileHandle internal (String path) {
return new AndroidFileHandle(assets, path, FileType.Internal);
}
@Override
public FileHandle external (String path) {
return new AndroidFileHandle(null, path, FileType.External);
}
@Override
public FileHandle absolute (String path) {
return new AndroidFileHandle(null, path, FileType.Absolute);
}
@Override
public FileHandle local (String path) {
return new AndroidFileHandle(null, path, FileType.Local);
}
@Override
public String getExternalStoragePath () {
return sdcard;
}
@Override
public boolean isExternalStorageAvailable () {
return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
}
@Override
public String getLocalStoragePath () {
return localpath;
}
@Override
public boolean isLocalStorageAvailable () {
return true;
}
}