From 686cee83ed3ec58d52b78bea90500945e2b5e002 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 7 Aug 2018 20:14:57 +0200 Subject: [PATCH] remeasure the screen if the width and height are set to 0 at fullscreen view --- app/build.gradle | 2 +- .../gallery/activities/ViewPagerActivity.kt | 4 +++- .../gallery/fragments/PhotoFragment.kt | 23 ++++++++++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 859e9af36..0a4c5c4d5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:4.6.0' + implementation 'com.simplemobiletools:commons:4.6.3' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' 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 c59f342be..75690a206 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.animation.Animator import android.animation.ValueAnimator +import android.annotation.SuppressLint import android.annotation.TargetApi import android.app.Activity import android.content.Intent @@ -965,9 +966,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View initBottomActionsLayout() } + @SuppressLint("NewApi") private fun measureScreen() { val metrics = DisplayMetrics() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + if (isJellyBean1Plus()) { windowManager.defaultDisplay.getRealMetrics(metrics) screenWidth = metrics.widthPixels screenHeight = metrics.heightPixels 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 e26acd52a..8804784fc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -1,5 +1,6 @@ package com.simplemobiletools.gallery.fragments +import android.annotation.SuppressLint import android.content.Intent import android.content.res.Configuration import android.graphics.Bitmap @@ -11,6 +12,7 @@ import android.media.ExifInterface.* import android.net.Uri import android.os.Bundle import android.os.Handler +import android.util.DisplayMetrics import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -19,6 +21,7 @@ import com.davemorrissey.labs.subscaleview.ImageSource import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.OTG_PATH +import com.simplemobiletools.commons.helpers.isJellyBean1Plus import com.simplemobiletools.commons.helpers.isLollipopPlus import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.PanoramaActivity @@ -39,7 +42,7 @@ import java.io.FileOutputStream class PhotoFragment : ViewPagerFragment() { private val DEFAULT_DOUBLE_TAP_ZOOM = 2f - private val ZOOMABLE_VIEW_LOAD_DELAY = 500L + private val ZOOMABLE_VIEW_LOAD_DELAY = 300L private var isFragmentVisible = false private var isFullscreen = false @@ -78,6 +81,10 @@ class PhotoFragment : ViewPagerFragment() { } } + if (ViewPagerActivity.screenWidth == 0 || ViewPagerActivity.screenHeight == 0) { + measureScreen() + } + storeStateVariables() if (!isFragmentVisible && activity is PhotoActivity) { isFragmentVisible = true @@ -167,6 +174,20 @@ class PhotoFragment : ViewPagerFragment() { } } + @SuppressLint("NewApi") + private fun measureScreen() { + val metrics = DisplayMetrics() + if (isJellyBean1Plus()) { + activity!!.windowManager.defaultDisplay.getRealMetrics(metrics) + ViewPagerActivity.screenWidth = metrics.widthPixels + ViewPagerActivity.screenHeight = metrics.heightPixels + } else { + activity!!.windowManager.defaultDisplay.getMetrics(metrics) + ViewPagerActivity.screenWidth = metrics.widthPixels + ViewPagerActivity.screenHeight = metrics.heightPixels + } + } + private fun gifFragmentVisibilityChanged(isVisible: Boolean) { if (isVisible) { gifDrawable?.start()