use the GlideDecoder at SubsamplingScaleImageView

This commit is contained in:
tibbi 2017-09-05 10:20:15 +02:00
parent 467f603ba1
commit f4d9ab0ff5
2 changed files with 15 additions and 0 deletions

View file

@ -33,6 +33,7 @@ import com.simplemobiletools.gallery.extensions.config
import com.simplemobiletools.gallery.extensions.getFileSignature
import com.simplemobiletools.gallery.extensions.getRealPathFromURI
import com.simplemobiletools.gallery.extensions.portrait
import com.simplemobiletools.gallery.helpers.GlideDecoder
import com.simplemobiletools.gallery.helpers.GlideRotateTransformation
import com.simplemobiletools.gallery.helpers.MEDIUM
import com.simplemobiletools.gallery.models.Medium
@ -199,6 +200,7 @@ class PhotoFragment : ViewPagerFragment() {
private fun addZoomableView() {
if ((medium.isImage()) && isFragmentVisible && view.subsampling_view.visibility == View.GONE) {
view.subsampling_view.apply {
setBitmapDecoderClass(GlideDecoder::class.java)
maxScale = 10f
beVisible()
setImage(ImageSource.uri(medium.path))

View file

@ -5,6 +5,7 @@ import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.media.ExifInterface
import android.net.Uri
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DecodeFormat
@ -14,9 +15,13 @@ import com.davemorrissey.labs.subscaleview.decoder.ImageDecoder
class GlideDecoder : ImageDecoder {
override fun decode(context: Context, uri: Uri): Bitmap {
val exif = android.media.ExifInterface(uri.path)
val orientation = exif.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, android.media.ExifInterface.ORIENTATION_NORMAL)
val options = RequestOptions()
.format(DecodeFormat.PREFER_ARGB_8888)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.transform(GlideRotateTransformation(context, getRotationDegrees(orientation)))
val drawable = Glide.with(context)
.load(uri)
@ -45,4 +50,12 @@ class GlideDecoder : ImageDecoder {
drawable.draw(canvas)
return bitmap
}
// 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
}
}