use of android.support.v4.provider.DocumentFile in project AmazeFileManager by TeamAmaze.
the class OTGUtil method getDocumentFiles.
/**
* Get the files at a specific path in OTG
*
* @param path the path to the directory tree, starts with prefix 'otg:/'
* Independent of URI (or mount point) for the OTG
* @param context context for loading
* @return an array of list of files at the path
*/
public static void getDocumentFiles(String path, Context context, OnFileFound fileFound) {
SharedPreferences manager = PreferenceManager.getDefaultSharedPreferences(context);
String rootUriString = manager.getString(MainActivity.KEY_PREF_OTG, null);
DocumentFile rootUri = DocumentFile.fromTreeUri(context, Uri.parse(rootUriString));
String[] parts = path.split("/");
for (String part : parts) {
// first omit 'otg:/' before iterating through DocumentFile
if (path.equals(OTGUtil.PREFIX_OTG + "/"))
break;
if (part.equals("otg:") || part.equals(""))
continue;
// iterating through the required path to find the end point
rootUri = rootUri.findFile(part);
}
// we have the end point DocumentFile, list the files inside it and return
for (DocumentFile file : rootUri.listFiles()) {
if (file.exists()) {
long size = 0;
if (!file.isDirectory())
size = file.length();
Log.d(context.getClass().getSimpleName(), "Found file: " + file.getName());
HybridFileParcelable baseFile = new HybridFileParcelable(path + "/" + file.getName(), RootHelper.parseDocumentFilePermission(file), file.lastModified(), size, file.isDirectory());
baseFile.setName(file.getName());
baseFile.setMode(OpenMode.OTG);
fileFound.onFileFound(baseFile);
}
}
}
use of android.support.v4.provider.DocumentFile in project AmazeFileManager by TeamAmaze.
the class DeleteTask method doInBackground.
protected Boolean doInBackground(ArrayList<HybridFileParcelable>... p1) {
files = p1[0];
boolean wasDeleted = true;
if (files.size() == 0)
return true;
if (files.get(0).isOtgFile()) {
for (HybridFileParcelable file : files) {
DocumentFile documentFile = OTGUtil.getDocumentFile(file.getPath(), cd, false);
wasDeleted = documentFile.delete();
}
} else if (files.get(0).isDropBoxFile()) {
CloudStorage cloudStorageDropbox = dataUtils.getAccount(OpenMode.DROPBOX);
for (HybridFileParcelable baseFile : files) {
try {
cloudStorageDropbox.delete(CloudUtil.stripPath(OpenMode.DROPBOX, baseFile.getPath()));
} catch (Exception e) {
e.printStackTrace();
wasDeleted = false;
break;
}
}
} else if (files.get(0).isBoxFile()) {
CloudStorage cloudStorageBox = dataUtils.getAccount(OpenMode.BOX);
for (HybridFileParcelable baseFile : files) {
try {
cloudStorageBox.delete(CloudUtil.stripPath(OpenMode.BOX, baseFile.getPath()));
} catch (Exception e) {
e.printStackTrace();
wasDeleted = false;
break;
}
}
} else if (files.get(0).isGoogleDriveFile()) {
CloudStorage cloudStorageGdrive = dataUtils.getAccount(OpenMode.GDRIVE);
for (HybridFileParcelable baseFile : files) {
try {
cloudStorageGdrive.delete(CloudUtil.stripPath(OpenMode.GDRIVE, baseFile.getPath()));
} catch (Exception e) {
e.printStackTrace();
wasDeleted = false;
break;
}
}
} else if (files.get(0).isOneDriveFile()) {
CloudStorage cloudStorageOnedrive = dataUtils.getAccount(OpenMode.ONEDRIVE);
for (HybridFileParcelable baseFile : files) {
try {
cloudStorageOnedrive.delete(CloudUtil.stripPath(OpenMode.ONEDRIVE, baseFile.getPath()));
} catch (Exception e) {
e.printStackTrace();
wasDeleted = false;
break;
}
}
} else {
for (HybridFileParcelable file : files) {
try {
if (file.delete(cd, rootMode)) {
wasDeleted = true;
} else {
wasDeleted = false;
break;
}
} catch (ShellNotRunningException e) {
e.printStackTrace();
wasDeleted = false;
break;
}
}
}
// delete file from media database
if (!files.get(0).isSmb()) {
try {
for (HybridFileParcelable f : files) {
delete(cd, f.getPath());
}
} catch (Exception e) {
for (HybridFileParcelable f : files) {
FileUtils.scanFile(f.getPath(), cd);
}
}
}
// delete file entry from encrypted database
for (HybridFileParcelable file : files) {
if (file.getName().endsWith(CryptUtil.CRYPT_EXTENSION)) {
CryptHandler handler = new CryptHandler(cd);
handler.clear(file.getPath());
}
}
return wasDeleted;
}
use of android.support.v4.provider.DocumentFile in project Camera-Roll-Android-App by kollerlukas.
the class StorageUtil method createDocumentDir.
public static DocumentFile createDocumentDir(Context context, Uri treeUri, String path) {
int index = path.lastIndexOf("/");
String dirPath = path.substring(0, index);
DocumentFile file = parseDocumentFile(context, treeUri, new File(dirPath));
if (file != null) {
String name = path.substring(index + 1);
file = file.createDirectory(name);
}
return file;
}
use of android.support.v4.provider.DocumentFile in project Camera-Roll-Android-App by kollerlukas.
the class Delete method deleteFileOnRemovableStorage.
boolean deleteFileOnRemovableStorage(Context context, Uri treeUri, String path) {
boolean success = false;
DocumentFile file = StorageUtil.parseDocumentFile(context, treeUri, new File(path));
if (file != null) {
success = file.delete();
}
// remove from MediaStore
addPathToScan(path);
return success;
}
use of android.support.v4.provider.DocumentFile in project Camera-Roll-Android-App by kollerlukas.
the class FileOperation method getTreeUri.
public Uri getTreeUri(Intent workIntent, String path) {
Log.d("FileOperation", "getTreeUri");
Uri treeUri;
String treeUriExtra = workIntent.getStringExtra(FileOperation.REMOVABLE_STORAGE_TREE_URI);
if (treeUriExtra != null) {
treeUri = Uri.parse(treeUriExtra);
} else {
Settings s = Settings.getInstance(getApplicationContext());
treeUri = s.getRemovableStorageTreeUri();
}
if (path != null) {
// check if path is child of the treeUri
DocumentFile file = StorageUtil.parseDocumentFile(getApplicationContext(), treeUri, new File(path));
if (file != null) {
return treeUri;
} else {
requestPermissionForRemovableStorageBroadcast(workIntent);
}
} else {
return treeUri;
}
return null;
}
Aggregations