From 036641c0c421be0a7791967eef94e1a2cdd7a509 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 5 Sep 2018 22:13:31 +0200 Subject: [PATCH] calculate minimal tile dpi at fullscreen view dynamically --- .../gallery/fragments/PhotoFragment.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt index 71a3dff74..ce012e47e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -354,7 +354,9 @@ class PhotoFragment : ViewPagerFragment() { private fun addZoomableView() { val rotation = degreesForRotation(imageOrientation) + view.subsampling_view.apply { + setMinimumTileDpi(getMinTileDpi()) background = ColorDrawable(Color.TRANSPARENT) setBitmapDecoderFactory { PicassoDecoder(medium.path, Picasso.get(), rotation) } setRegionDecoderFactory { PicassoRegionDecoder() } @@ -396,6 +398,16 @@ class PhotoFragment : ViewPagerFragment() { } } + private fun getMinTileDpi(): Int { + val metrics = resources.displayMetrics + val averageDpi = (metrics.xdpi + metrics.ydpi) / 2 + return when { + averageDpi > 400 -> 320 + averageDpi > 300 -> 240 + else -> 160 + } + } + private fun checkIfPanorama() { isPanorama = try { val inputStream = if (medium.path.startsWith("content:/")) context!!.contentResolver.openInputStream(Uri.parse(medium.path)) else File(medium.path).inputStream()