Merge pull request #443 from ltGuillaume/patch-1

Adding handleSAFDialog for EXIF rotation
This commit is contained in:
Tibor Kaputa 2017-11-07 23:55:42 +01:00 committed by GitHub
commit 6bc3e4cfa6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 30 deletions

View File

@ -456,41 +456,43 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
val currPath = getCurrentPath()
SaveAsDialog(this, currPath, false) {
Thread({
toast(R.string.saving)
val selectedFile = File(it)
val tmpFile = File(filesDir, ".tmp_${it.getFilenameFromPath()}")
try {
val bitmap = BitmapFactory.decodeFile(currPath)
getFileOutputStream(tmpFile) {
if (it == null) {
toast(R.string.unknown_error_occurred)
return@getFileOutputStream
}
handleSAFDialog(selectedFile) {
toast(R.string.saving)
val tmpFile = File(filesDir, ".tmp_${it.getFilenameFromPath()}")
try {
val bitmap = BitmapFactory.decodeFile(currPath)
getFileOutputStream(tmpFile) {
if (it == null) {
toast(R.string.unknown_error_occurred)
return@getFileOutputStream
}
if (currPath.isJpg()) {
saveRotation(getCurrentFile(), tmpFile)
} else {
saveFile(tmpFile, bitmap, it as FileOutputStream)
}
if (currPath.isJpg()) {
saveRotation(getCurrentFile(), tmpFile)
} else {
saveFile(tmpFile, bitmap, it as FileOutputStream)
}
if (tmpFile.length() > 0 && selectedFile.exists()) {
deleteFile(selectedFile) {}
}
copyFile(tmpFile, selectedFile)
scanPath(selectedFile.absolutePath) {}
toast(R.string.file_saved)
if (tmpFile.length() > 0 && selectedFile.exists()) {
deleteFile(selectedFile) {}
}
copyFile(tmpFile, selectedFile)
scanPath(selectedFile.absolutePath) {}
toast(R.string.file_saved)
it.flush()
it.close()
mRotationDegrees = 0f
invalidateOptionsMenu()
it.flush()
it.close()
mRotationDegrees = 0f
invalidateOptionsMenu()
}
} catch (e: OutOfMemoryError) {
toast(R.string.out_of_memory_error)
} catch (e: Exception) {
showErrorToast(e)
} finally {
deleteFile(tmpFile) {}
}
} catch (e: OutOfMemoryError) {
toast(R.string.out_of_memory_error)
} catch (e: Exception) {
showErrorToast(e)
} finally {
deleteFile(tmpFile) {}
}
}).start()
}