From 19d4ff53cb74859006cbdb3af47524a0dd5df3cd Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 17 Mar 2017 20:09:11 +0100 Subject: [PATCH] store the screen resolution at view pager activity --- .../gallery/activities/ViewPagerActivity.kt | 20 +++++++++++++++++++ .../gallery/fragments/PhotoFragment.kt | 6 ++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 183a929c7..6b1a26c38 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.activities import android.app.Activity import android.content.Intent +import android.content.res.Configuration import android.database.Cursor import android.graphics.Bitmap import android.graphics.BitmapFactory @@ -12,6 +13,7 @@ import android.os.Build import android.os.Bundle import android.provider.MediaStore import android.support.v4.view.ViewPager +import android.util.DisplayMetrics import android.view.Menu import android.view.MenuItem import android.view.View @@ -49,6 +51,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private var mShowAll = false private var mRotationDegrees = 0f + companion object { + var screenWidth = 0 + var screenHeight = 0 + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_medium) @@ -58,6 +65,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View return } + measureScreen() val uri = intent.data if (uri != null) { var cursor: Cursor? = null @@ -156,6 +164,18 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View return true } + override fun onConfigurationChanged(newConfig: Configuration?) { + super.onConfigurationChanged(newConfig) + measureScreen() + } + + private fun measureScreen() { + val metrics = DisplayMetrics() + windowManager.defaultDisplay.getMetrics(metrics) + screenWidth = metrics.widthPixels + screenHeight = metrics.heightPixels + } + private fun updatePagerItems() { val pagerAdapter = MyPagerAdapter(this, supportFragmentManager, mMedia) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && !isDestroyed) { 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 c76dc7a71..c99d56add 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -6,7 +6,6 @@ import android.graphics.BitmapFactory import android.graphics.Matrix import android.net.Uri import android.os.Bundle -import android.util.DisplayMetrics import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -16,6 +15,7 @@ import com.simplemobiletools.commons.extensions.beGone import com.simplemobiletools.commons.extensions.beVisible import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.activities.ViewPagerActivity import com.simplemobiletools.gallery.extensions.getRealPathFromURI import com.simplemobiletools.gallery.helpers.MEDIUM import com.simplemobiletools.gallery.models.Medium @@ -132,11 +132,9 @@ class PhotoFragment : ViewPagerFragment() { } private fun loadBitmap(degrees: Float = 0f) { - val metrics = DisplayMetrics() - activity.windowManager.defaultDisplay.getMetrics(metrics) Picasso.with(activity) .load("file:${medium.path}") - .resize(metrics.widthPixels * 2, metrics.heightPixels * 2) + .resize(ViewPagerActivity.screenWidth * 2, ViewPagerActivity.screenHeight * 2) .rotate(degrees) .centerInside() .into(view.photo_view)