Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaccetta committed May 2, 2018
1 parent 036ccdf commit 36be00c
Showing 1 changed file with 39 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,39 +303,47 @@ public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
}

private void handleChoosePictureResult(int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK && data != null && data.getData()!=null) {
//Extract the file path from the uri.
String path = fileUtils.getPathFromUri(activity, data.getData());
//Path may be null if source is remote.
if (path == null){
InputStream inputStream = null;
OutputStream outputStream = null;
try {
inputStream = activity.getContentResolver().openInputStream(data.getData());
File file = File.createTempFile("cachedImage", "jpg", activity.getCacheDir());
outputStream = new FileOutputStream(file);
if (inputStream != null) {
byte[] buffer = new byte[4 * 1024];
int read;
while ((read = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, read);
}
outputStream.flush();
handleResult(file.getPath());
} else {
finishWithError("pickFromGalleryError", "Error while reading selected image");
}
} catch (FileNotFoundException e) {
finishWithError("pickFromGalleryError", "FileNotFoundException - Error while reading selected image");
} catch (IOException e) {
finishWithError("pickFromGalleryError", "IOException - Error while reading selected image");
} finally {
try { if (inputStream != null) inputStream.close();} catch(IOException ignored) {}
try { if (outputStream != null) outputStream.close();} catch(IOException ignored) {}
if (resultCode == Activity.RESULT_OK && data != null && data.getData() != null) {
//Extract the file path from the uri.
String path = fileUtils.getPathFromUri(activity, data.getData());
//Path may be null if, for example, source is remote.
if (path == null) {
InputStream inputStream = null;
OutputStream outputStream = null;
try {
inputStream = activity.getContentResolver().openInputStream(data.getData());
File file = File.createTempFile("cachedImage", "jpg", activity.getCacheDir());
outputStream = new FileOutputStream(file);
if (inputStream != null) {
byte[] buffer = new byte[4 * 1024];
int read;
while ((read = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, read);
}
} else {
handleResult(path);
outputStream.flush();
handleResult(file.getPath());
} else {
finishWithError("pickFromGalleryError", "Error while reading selected image");
}
} catch (FileNotFoundException e) {
finishWithError(
"pickFromGalleryError", "FileNotFoundException - Error while reading selected image");
} catch (IOException e) {
finishWithError(
"pickFromGalleryError", "IOException - Error while reading selected image");
} finally {
try {
if (inputStream != null) inputStream.close();
} catch (IOException ignored) {
}
try {
if (outputStream != null) outputStream.close();
} catch (IOException ignored) {
}
}
} else {
handleResult(path);
}
return;
}

Expand Down

0 comments on commit 36be00c

Please sign in to comment.