use of group.pals.android.lib.ui.filechooser.providers.basefile.BaseFileContract.BaseFile in project keepass2android by PhilippC.
the class LocalFileProvider method listFiles.
// doRetrieveFileInfo()
/**
* Lists all file inside {@code dir}.
*
* @param taskId
* the task ID.
* @param dir
* the source directory.
* @param showHiddenFiles
* {@code true} or {@code false}.
* @param filterMode
* can be one of {@link BaseFile#FILTER_DIRECTORIES_ONLY},
* {@link BaseFile#FILTER_FILES_ONLY},
* {@link BaseFile#FILTER_FILES_AND_DIRECTORIES}.
* @param limit
* the limit.
* @param positiveRegex
* the positive regex filter.
* @param negativeRegex
* the negative regex filter.
* @param results
* the results.
* @param hasMoreFiles
* the first item will contain a value representing that there is
* more files (exceeding {@code limit}) or not.
*/
private void listFiles(final int taskId, final File dir, final boolean showHiddenFiles, final int filterMode, final int limit, String positiveRegex, String negativeRegex, final List<File> results, final boolean[] hasMoreFiles) {
final Pattern positivePattern = Texts.compileRegex(positiveRegex);
final Pattern negativePattern = Texts.compileRegex(negativeRegex);
hasMoreFiles[0] = false;
try {
dir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
if (mMapInterruption.get(taskId))
throw new CancellationException();
final boolean isFile = pathname.isFile();
final String name = pathname.getName();
/*
* Filters...
*/
if (filterMode == BaseFile.FILTER_DIRECTORIES_ONLY && isFile)
return false;
if (!showHiddenFiles && name.startsWith("."))
return false;
if (isFile && positivePattern != null && !positivePattern.matcher(name).find())
return false;
if (isFile && negativePattern != null && negativePattern.matcher(name).find())
return false;
/*
* Limit...
*/
if (results.size() >= limit) {
hasMoreFiles[0] = true;
throw new CancellationException("Exceeding limit...");
}
results.add(pathname);
return false;
}
});
} catch (CancellationException e) {
if (Utils.doLog())
Log.d(CLASSNAME, "listFiles() >> cancelled... >> " + e);
}
}
use of group.pals.android.lib.ui.filechooser.providers.basefile.BaseFileContract.BaseFile in project keepass2android by PhilippC.
the class LocalFileProvider method doCheckAncestor.
// deleteFile()
/**
* Checks ancestor with {@link BaseFile#CMD_IS_ANCESTOR_OF},
* {@link BaseFile#PARAM_SOURCE} and {@link BaseFile#PARAM_TARGET}.
*
* @param uri
* the original URI from client.
* @return {@code null} if source is not ancestor of target; or a
* <i>non-null but empty</i> cursor if the source is.
*/
private MatrixCursor doCheckAncestor(Uri uri) {
File source = new File(Uri.parse(uri.getQueryParameter(BaseFile.PARAM_SOURCE)).getPath());
File target = new File(Uri.parse(uri.getQueryParameter(BaseFile.PARAM_TARGET)).getPath());
if (source == null || target == null)
return null;
boolean validate = ProviderUtils.getBooleanQueryParam(uri, BaseFile.PARAM_VALIDATE, true);
if (validate) {
if (!source.isDirectory() || !target.exists())
return null;
}
if (source.equals(target.getParentFile()) || (target.getParent() != null && target.getParent().startsWith(source.getAbsolutePath())))
return BaseFileProviderUtils.newClosedCursor();
return null;
}
Aggregations