updating Commons to 3.17.23, use image rotating functions from there
This commit is contained in:
parent
543f68e18d
commit
6f361a7296
|
@ -46,7 +46,7 @@ ext {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:3.17.16'
|
||||
implementation 'com.simplemobiletools:commons:3.17.23'
|
||||
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0'
|
||||
implementation 'com.android.support:multidex:1.0.3'
|
||||
implementation 'it.sephiroth.android.exif:library:1.0.1'
|
||||
|
|
|
@ -65,7 +65,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
private var mCurrAsyncTask: GetDirectoriesAsynctask? = null
|
||||
private var mZoomListener: MyRecyclerView.MyZoomListener? = null
|
||||
|
||||
private var mStoredUseEnglish = false
|
||||
private var mStoredAnimateGifs = true
|
||||
private var mStoredCropThumbnails = true
|
||||
private var mStoredScrollHorizontally = true
|
||||
|
@ -117,10 +116,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
override fun onResume() {
|
||||
super.onResume()
|
||||
config.isThirdPartyIntent = false
|
||||
if (mStoredUseEnglish != config.useEnglish) {
|
||||
restartActivity()
|
||||
return
|
||||
}
|
||||
|
||||
if (mStoredAnimateGifs != config.animateGifs) {
|
||||
getRecyclerAdapter()?.updateAnimateGifs(config.animateGifs)
|
||||
|
@ -236,7 +231,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
|
||||
private fun storeStateVariables() {
|
||||
config.apply {
|
||||
mStoredUseEnglish = useEnglish
|
||||
mStoredAnimateGifs = animateGifs
|
||||
mStoredCropThumbnails = cropThumbnails
|
||||
mStoredScrollHorizontally = scrollHorizontally
|
||||
|
|
|
@ -63,7 +63,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
private var mZoomListener: MyRecyclerView.MyZoomListener? = null
|
||||
private var mSearchMenuItem: MenuItem? = null
|
||||
|
||||
private var mStoredUseEnglish = false
|
||||
private var mStoredAnimateGifs = true
|
||||
private var mStoredCropThumbnails = true
|
||||
private var mStoredScrollHorizontally = true
|
||||
|
@ -110,11 +109,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (mStoredUseEnglish != config.useEnglish) {
|
||||
restartActivity()
|
||||
return
|
||||
}
|
||||
|
||||
if (mStoredAnimateGifs != config.animateGifs) {
|
||||
getMediaAdapter()?.updateAnimateGifs(config.animateGifs)
|
||||
}
|
||||
|
@ -232,7 +226,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
|
||||
private fun storeStateVariables() {
|
||||
config.apply {
|
||||
mStoredUseEnglish = useEnglish
|
||||
mStoredAnimateGifs = animateGifs
|
||||
mStoredCropThumbnails = cropThumbnails
|
||||
mStoredScrollHorizontally = scrollHorizontally
|
||||
|
|
|
@ -6,7 +6,10 @@ import android.os.Bundle
|
|||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
import com.simplemobiletools.commons.dialogs.SecurityDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
|
||||
import com.simplemobiletools.commons.extensions.handleHiddenFolderPasswordProtection
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import com.simplemobiletools.commons.helpers.PROTECTION_FINGERPRINT
|
||||
import com.simplemobiletools.commons.helpers.SHOW_ALL_TABS
|
||||
import com.simplemobiletools.commons.models.RadioItem
|
||||
|
@ -89,7 +92,7 @@ class SettingsActivity : SimpleActivity() {
|
|||
settings_use_english_holder.setOnClickListener {
|
||||
settings_use_english.toggle()
|
||||
config.useEnglish = settings_use_english.isChecked
|
||||
useEnglishToggled()
|
||||
System.exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
private var mShowAll = false
|
||||
private var mIsSlideshowActive = false
|
||||
private var mSkipConfirmationDialog = false
|
||||
private var mRotationDegrees = 0f
|
||||
private var mRotationDegrees = 0
|
||||
private var mPrevHashcode = 0
|
||||
|
||||
private var mSlideshowHandler = Handler()
|
||||
|
@ -66,7 +66,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
private var mAreSlideShowMediaVisible = false
|
||||
private var mIsOrientationLocked = false
|
||||
|
||||
private var mStoredUseEnglish = false
|
||||
private var mStoredReplaceZoomableImages = false
|
||||
private var mMediaFiles = ArrayList<Medium>()
|
||||
|
||||
|
@ -101,11 +100,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
return
|
||||
}
|
||||
|
||||
if (mStoredUseEnglish != config.useEnglish) {
|
||||
restartActivity()
|
||||
return
|
||||
}
|
||||
|
||||
if (mStoredReplaceZoomableImages != config.replaceZoomableImages) {
|
||||
mPrevHashcode = 0
|
||||
refreshViewPager()
|
||||
|
@ -256,13 +250,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
findItem(R.id.menu_share_1).isVisible = !config.replaceShare
|
||||
findItem(R.id.menu_share_2).isVisible = config.replaceShare
|
||||
findItem(R.id.menu_rotate).isVisible = currentMedium.isImage()
|
||||
findItem(R.id.menu_save_as).isVisible = mRotationDegrees != 0f
|
||||
findItem(R.id.menu_save_as).isVisible = mRotationDegrees != 0
|
||||
findItem(R.id.menu_hide).isVisible = !currentMedium.name.startsWith('.')
|
||||
findItem(R.id.menu_unhide).isVisible = currentMedium.name.startsWith('.')
|
||||
findItem(R.id.menu_lock_orientation).isVisible = mRotationDegrees == 0f
|
||||
findItem(R.id.menu_lock_orientation).isVisible = mRotationDegrees == 0
|
||||
findItem(R.id.menu_lock_orientation).title = getString(if (mIsOrientationLocked) R.string.unlock_orientation else R.string.lock_orientation)
|
||||
findItem(R.id.menu_rotate).setShowAsAction(
|
||||
if (mRotationDegrees != 0f) {
|
||||
if (mRotationDegrees != 0) {
|
||||
MenuItem.SHOW_AS_ACTION_ALWAYS
|
||||
} else {
|
||||
MenuItem.SHOW_AS_ACTION_IF_ROOM
|
||||
|
@ -304,7 +298,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
|
||||
private fun storeStateVariables() {
|
||||
config.apply {
|
||||
mStoredUseEnglish = useEnglish
|
||||
mStoredReplaceZoomableImages = replaceZoomableImages
|
||||
}
|
||||
}
|
||||
|
@ -543,7 +536,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
val oldLastModified = getCurrentFile().lastModified()
|
||||
if (oldPath.isJpg()) {
|
||||
copyFile(getCurrentFile(), tmpFile)
|
||||
saveExifRotation(ExifInterface(tmpFile.absolutePath))
|
||||
saveExifRotation(ExifInterface(tmpFile.absolutePath), mRotationDegrees)
|
||||
} else {
|
||||
val bitmap = BitmapFactory.decodeFile(oldPath)
|
||||
saveFile(tmpFile, bitmap, it as FileOutputStream)
|
||||
|
@ -563,7 +556,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
|
||||
it.flush()
|
||||
it.close()
|
||||
mRotationDegrees = 0f
|
||||
mRotationDegrees = 0
|
||||
invalidateOptionsMenu()
|
||||
|
||||
// we cannot refresh a specific image in Glide Cache, so just clear it all
|
||||
|
@ -584,29 +577,14 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
|
||||
@TargetApi(Build.VERSION_CODES.N)
|
||||
private fun tryRotateByExif(path: String): Boolean {
|
||||
try {
|
||||
if (!isPathOnSD(path)) {
|
||||
saveExifRotation(ExifInterface(path))
|
||||
mRotationDegrees = 0f
|
||||
invalidateOptionsMenu()
|
||||
toast(R.string.file_saved)
|
||||
return true
|
||||
} else if (isNougatPlus()) {
|
||||
val documentFile = getSomeDocumentFile(path)
|
||||
if (documentFile != null) {
|
||||
val parcelFileDescriptor = contentResolver.openFileDescriptor(documentFile.uri, "rw")
|
||||
val fileDescriptor = parcelFileDescriptor.fileDescriptor
|
||||
saveExifRotation(ExifInterface(fileDescriptor))
|
||||
mRotationDegrees = 0f
|
||||
invalidateOptionsMenu()
|
||||
toast(R.string.file_saved)
|
||||
return true
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
return if (saveImageRotation(path, mRotationDegrees)) {
|
||||
mRotationDegrees = 0
|
||||
invalidateOptionsMenu()
|
||||
toast(R.string.file_saved)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun copyFile(source: File, destination: File) {
|
||||
|
@ -625,32 +603,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
|
||||
private fun saveFile(file: File, bitmap: Bitmap, out: FileOutputStream) {
|
||||
val matrix = Matrix()
|
||||
matrix.postRotate(mRotationDegrees)
|
||||
matrix.postRotate(mRotationDegrees.toFloat())
|
||||
val bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true)
|
||||
bmp.compress(file.absolutePath.getCompressionFormat(), 90, out)
|
||||
}
|
||||
|
||||
private fun saveExifRotation(exif: ExifInterface) {
|
||||
val orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)
|
||||
val orientationDegrees = (degreesForRotation(orientation) + mRotationDegrees) % 360
|
||||
exif.setAttribute(ExifInterface.TAG_ORIENTATION, rotationFromDegrees(orientationDegrees))
|
||||
exif.saveAttributes()
|
||||
}
|
||||
|
||||
private fun degreesForRotation(orientation: Int) = when (orientation) {
|
||||
ExifInterface.ORIENTATION_ROTATE_270 -> 270f
|
||||
ExifInterface.ORIENTATION_ROTATE_180 -> 180f
|
||||
ExifInterface.ORIENTATION_ROTATE_90 -> 90f
|
||||
else -> 0f
|
||||
}
|
||||
|
||||
private fun rotationFromDegrees(degrees: Float) = when (degrees) {
|
||||
270f -> ExifInterface.ORIENTATION_ROTATE_270
|
||||
180f -> ExifInterface.ORIENTATION_ROTATE_180
|
||||
90f -> ExifInterface.ORIENTATION_ROTATE_90
|
||||
else -> ExifInterface.ORIENTATION_NORMAL
|
||||
}.toString()
|
||||
|
||||
private fun isShowHiddenFlagNeeded(): Boolean {
|
||||
val file = File(mPath)
|
||||
if (file.isHidden) {
|
||||
|
@ -943,7 +900,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
if (mPos != position) {
|
||||
mPos = position
|
||||
updateActionbarTitle()
|
||||
mRotationDegrees = 0f
|
||||
mRotationDegrees = 0
|
||||
supportInvalidateOptionsMenu()
|
||||
scheduleSwipe()
|
||||
}
|
||||
|
|
|
@ -229,8 +229,8 @@ class PhotoFragment : ViewPagerFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun loadBitmap(degrees: Float = 0f) {
|
||||
if (degrees == 0f) {
|
||||
private fun loadBitmap(degrees: Int = 0) {
|
||||
if (degrees == 0) {
|
||||
var targetWidth = if (ViewPagerActivity.screenWidth == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenWidth
|
||||
var targetHeight = if (ViewPagerActivity.screenHeight == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenHeight
|
||||
if (useHalfResolution) {
|
||||
|
@ -371,7 +371,7 @@ class PhotoFragment : ViewPagerFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
fun rotateImageViewBy(degrees: Float) {
|
||||
fun rotateImageViewBy(degrees: Int) {
|
||||
view.subsampling_view.beGone()
|
||||
loadBitmap(degrees)
|
||||
}
|
||||
|
|
|
@ -30,8 +30,9 @@ class GlideDecoder : ImageDecoder {
|
|||
.override(targetWidth, targetHeight)
|
||||
|
||||
val degrees = getRotationDegrees(orientation)
|
||||
if (degrees != 0f)
|
||||
if (degrees != 0) {
|
||||
options.transform(GlideRotateTransformation(context, getRotationDegrees(orientation)))
|
||||
}
|
||||
|
||||
val drawable = Glide.with(context)
|
||||
.load(uri)
|
||||
|
@ -61,9 +62,9 @@ class GlideDecoder : ImageDecoder {
|
|||
|
||||
// rotating backwards intentionally, as SubsamplingScaleImageView will rotate it properly at displaying
|
||||
private fun getRotationDegrees(orientation: Int) = when (orientation) {
|
||||
ExifInterface.ORIENTATION_ROTATE_270 -> 90f
|
||||
ExifInterface.ORIENTATION_ROTATE_180 -> 180f
|
||||
ExifInterface.ORIENTATION_ROTATE_90 -> 270f
|
||||
else -> 0f
|
||||
ExifInterface.ORIENTATION_ROTATE_270 -> 90
|
||||
ExifInterface.ORIENTATION_ROTATE_180 -> 180
|
||||
ExifInterface.ORIENTATION_ROTATE_90 -> 270
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,13 +7,13 @@ import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
|
|||
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation
|
||||
import java.security.MessageDigest
|
||||
|
||||
class GlideRotateTransformation(context: Context, val rotateRotationAngle: Float) : BitmapTransformation(context) {
|
||||
class GlideRotateTransformation(context: Context, val rotateRotationAngle: Int) : BitmapTransformation(context) {
|
||||
override fun transform(pool: BitmapPool, bitmap: Bitmap, outWidth: Int, outHeight: Int): Bitmap {
|
||||
if (rotateRotationAngle % 360 == 0f)
|
||||
if (rotateRotationAngle % 360 == 0)
|
||||
return bitmap
|
||||
|
||||
val matrix = Matrix()
|
||||
matrix.postRotate(rotateRotationAngle)
|
||||
matrix.postRotate(rotateRotationAngle.toFloat())
|
||||
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue