calculate minimal tile dpi at fullscreen view dynamically

This commit is contained in:
tibbi 2018-09-05 22:13:31 +02:00
parent cff5949f94
commit 036641c0c4

View file

@ -354,7 +354,9 @@ class PhotoFragment : ViewPagerFragment() {
private fun addZoomableView() { private fun addZoomableView() {
val rotation = degreesForRotation(imageOrientation) val rotation = degreesForRotation(imageOrientation)
view.subsampling_view.apply { view.subsampling_view.apply {
setMinimumTileDpi(getMinTileDpi())
background = ColorDrawable(Color.TRANSPARENT) background = ColorDrawable(Color.TRANSPARENT)
setBitmapDecoderFactory { PicassoDecoder(medium.path, Picasso.get(), rotation) } setBitmapDecoderFactory { PicassoDecoder(medium.path, Picasso.get(), rotation) }
setRegionDecoderFactory { PicassoRegionDecoder() } 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() { private fun checkIfPanorama() {
isPanorama = try { isPanorama = try {
val inputStream = if (medium.path.startsWith("content:/")) context!!.contentResolver.openInputStream(Uri.parse(medium.path)) else File(medium.path).inputStream() val inputStream = if (medium.path.startsWith("content:/")) context!!.contentResolver.openInputStream(Uri.parse(medium.path)) else File(medium.path).inputStream()