File Picker
//Add This on Build
dependencies {
compile 'com.github.angads25:filepicker:1.1.1'
}
//Add Import file
import com.github.angads25.filepicker.model.DialogProperties;
import com.github.angads25.filepicker.model.DialogConfigs;
import com.github.angads25.filepicker.view.FilePickerDialog;
import com.github.angads25.filepicker.controller.DialogSelectionListener;
//Add on File Chooser
DialogProperties properties = new DialogProperties();
properties.selection_mode = DialogConfigs.SINGLE_MODE;
properties.selection_type = DialogConfigs.FILE_SELECT;
properties.root = new java.io.File(DialogConfigs.DEFAULT_DIR);
properties.error_dir = new java.io.File(DialogConfigs.DEFAULT_DIR);
properties.offset = new java.io.File(DialogConfigs.DEFAULT_DIR);
properties.extensions = null;
final FilePickerDialog dialog = new FilePickerDialog(MainActivity.this,properties);
dialog.setTitle("Select a File");
dialog.setDialogSelectionListener(new DialogSelectionListener() {
@Override
public void onSelectedFilePaths(String[] files) {
//files is the array of the paths of files selected by the Application User.
showMessage(files[0]);
}
});
dialog.show();
//Done and test
//Multi Choice: MULTI_MODE
//Path Select: DIR_SELECT
//Default Root: "/sdcard"
//use extention
private int countCommas(String fextension) {
int count = 0;
for(char ch:fextension.toCharArray())
{ if(ch==',') {
count++;
}
}
return count;
}
String fextension = "txt,pdf";
if(fextension.length()>0) {
int commas = countCommas(fextension);
String[] exts = new String[commas + 1];
StringBuffer buff = new StringBuffer();
int i = 0;
for (int j = 0; j < fextension.length(); j++) {
if (fextension.charAt(j) == ',') {
exts[i] = buff.toString();
buff = new StringBuffer();
i++;
} else {
buff.append(fextension.charAt(j));
}
}
exts[i] = buff.toString();
properties.extensions=exts;
} else {
properties.extensions=null;
}
Comments