use of forpdateam.ru.forpda.api.RequestFile in project ForPDA by RadiationX.
the class FilePickHelper method onActivityResult.
public static List<RequestFile> onActivityResult(Context context, Intent data) {
List<RequestFile> files = new ArrayList<>();
RequestFile tempFile;
Log.d(LOG_TAG, "onActivityResult " + data);
if (data.getData() == null) {
if (data.getClipData() != null) {
for (int i = 0; i < data.getClipData().getItemCount(); i++) {
tempFile = createFile(context, data.getClipData().getItemAt(i).getUri());
if (tempFile != null)
files.add(tempFile);
}
}
} else {
tempFile = createFile(context, data.getData());
if (tempFile != null)
files.add(tempFile);
}
return files;
}
use of forpdateam.ru.forpda.api.RequestFile in project ForPDA by RadiationX.
the class NotesFragment method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
if (data == null) {
// Display an error
return;
}
if (requestCode == REQUEST_PICK_FILE) {
List<RequestFile> files = FilePickHelper.onActivityResult(getContext(), data);
RequestFile file = files.get(0);
if (file.getFileName().matches("[\\s\\S]*?\\.json$")) {
BufferedReader r = new BufferedReader(new InputStreamReader(file.getFileStream()));
StringBuilder total = new StringBuilder();
String line;
try {
while ((line = r.readLine()) != null) {
total.append(line).append('\n');
}
r.close();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getContext(), "Ошибка при чтении файла", Toast.LENGTH_SHORT).show();
}
importNotes(total.toString());
} else {
Toast.makeText(getContext(), "Файл имеет неправильное расширение", Toast.LENGTH_SHORT).show();
}
} else if (requestCode == REQUEST_SAVE_FILE) {
}
}
}
Aggregations