do not autosave rotated images, related to #372
This commit is contained in:
parent
64f8d37544
commit
80f6df5e29
|
@ -37,7 +37,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.simplemobiletools:commons:2.28.4'
|
compile 'com.simplemobiletools:commons:2.28.5'
|
||||||
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0'
|
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0'
|
||||||
compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0'
|
compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0'
|
||||||
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
|
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
|
||||||
|
|
|
@ -434,34 +434,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun rotateImage() {
|
private fun rotateImage() {
|
||||||
val currentMedium = getCurrentMedium() ?: return
|
|
||||||
if (currentMedium.isJpg() && !isPathOnSD(currentMedium.path)) {
|
|
||||||
rotateByExif()
|
|
||||||
} else {
|
|
||||||
rotateByDegrees()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun rotateByExif() {
|
|
||||||
val exif = ExifInterface(getCurrentPath())
|
|
||||||
val orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)
|
|
||||||
val newOrientation = getNewOrientation(orientation)
|
|
||||||
exif.setAttribute(ExifInterface.TAG_ORIENTATION, newOrientation)
|
|
||||||
exif.saveAttributes()
|
|
||||||
File(getCurrentPath()).setLastModified(System.currentTimeMillis())
|
|
||||||
(getCurrentFragment() as? PhotoFragment)?.refreshBitmap()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getNewOrientation(rotation: Int): String {
|
|
||||||
return when (rotation) {
|
|
||||||
ExifInterface.ORIENTATION_ROTATE_90 -> ExifInterface.ORIENTATION_ROTATE_180
|
|
||||||
ExifInterface.ORIENTATION_ROTATE_180 -> ExifInterface.ORIENTATION_ROTATE_270
|
|
||||||
ExifInterface.ORIENTATION_ROTATE_270 -> ExifInterface.ORIENTATION_NORMAL
|
|
||||||
else -> ExifInterface.ORIENTATION_ROTATE_90
|
|
||||||
}.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun rotateByDegrees() {
|
|
||||||
mRotationDegrees = (mRotationDegrees + 90) % 360
|
mRotationDegrees = (mRotationDegrees + 90) % 360
|
||||||
getCurrentFragment()?.let {
|
getCurrentFragment()?.let {
|
||||||
(it as? PhotoFragment)?.rotateImageViewBy(mRotationDegrees)
|
(it as? PhotoFragment)?.rotateImageViewBy(mRotationDegrees)
|
||||||
|
@ -475,7 +447,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
Thread({
|
Thread({
|
||||||
toast(R.string.saving)
|
toast(R.string.saving)
|
||||||
val selectedFile = File(it)
|
val selectedFile = File(it)
|
||||||
val tmpFile = File(selectedFile.parent, "tmp_${it.getFilenameFromPath()}")
|
val tmpFile = File(selectedFile.parent, ".tmp_${it.getFilenameFromPath()}")
|
||||||
try {
|
try {
|
||||||
val bitmap = BitmapFactory.decodeFile(currPath)
|
val bitmap = BitmapFactory.decodeFile(currPath)
|
||||||
getFileOutputStream(tmpFile) {
|
getFileOutputStream(tmpFile) {
|
||||||
|
@ -498,7 +470,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
toast(R.string.out_of_memory_error)
|
toast(R.string.out_of_memory_error)
|
||||||
deleteFile(tmpFile) {}
|
deleteFile(tmpFile) {}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
toast(R.string.unknown_error_occurred)
|
showErrorToast(e)
|
||||||
deleteFile(tmpFile) {}
|
deleteFile(tmpFile) {}
|
||||||
}
|
}
|
||||||
}).start()
|
}).start()
|
||||||
|
@ -513,9 +485,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
out.flush()
|
out.flush()
|
||||||
out.close()
|
out.close()
|
||||||
toast(R.string.file_saved)
|
toast(R.string.file_saved)
|
||||||
|
mRotationDegrees = 0f
|
||||||
|
invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun isShowHiddenFlagNeeded(): Boolean {
|
private fun isShowHiddenFlagNeeded(): Boolean {
|
||||||
val file = File(mPath)
|
val file = File(mPath)
|
||||||
if (file.isHidden)
|
if (file.isHidden)
|
||||||
|
|
Loading…
Reference in New Issue