From 7a3acad04b4fa2b1dc430b07d0e1f9fc7b2f5969 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 1 Apr 2017 12:00:32 +0200 Subject: [PATCH] use subsamplingScaleImageView for fullscreen images again --- app/build.gradle | 1 + .../gallery/activities/ViewPagerActivity.kt | 20 +++++++ .../gallery/extensions/activity.kt | 2 +- .../gallery/fragments/PhotoFragment.kt | 54 ++++++++++++++++++- .../gallery/models/Medium.kt | 3 ++ app/src/main/res/layout/pager_photo_item.xml | 7 +++ 6 files changed, 84 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f52d3f0c2..eae78811f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -33,6 +33,7 @@ android { dependencies { compile 'com.simplemobiletools:commons:2.14.7' + compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0' compile 'com.theartofdev.edmodo:android-image-cropper:2.3.1' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' compile 'com.google.code.gson:gson:2.8.0' 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 ee586f4ba..b322d3d90 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -3,6 +3,7 @@ package com.simplemobiletools.gallery.activities import android.app.Activity import android.content.Intent import android.content.pm.ActivityInfo +import android.content.res.Configuration import android.database.Cursor import android.graphics.Bitmap import android.graphics.BitmapFactory @@ -13,6 +14,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 @@ -50,6 +52,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) @@ -59,6 +66,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View return } + measureScreen() val uri = intent.data if (uri != null) { var cursor: Cursor? = null @@ -344,6 +352,18 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } } + 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 reloadViewPager() { mCurrAsyncTask = GetMediaAsynctask(applicationContext, mDirectory, false, false, mShowAll) { mMedia = it diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt index ffb1b20ea..c090fa84a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt @@ -138,7 +138,7 @@ fun Activity.hasNavBar(): Boolean { fun SimpleActivity.launchAbout() { startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_GLIDE or LICENSE_CROPPER or LICENSE_MULTISELECT or LICENSE_RTL - or LICENSE_PHOTOVIEW, BuildConfig.VERSION_NAME) + or LICENSE_PHOTOVIEW or LICENSE_SUBSAMPLING, BuildConfig.VERSION_NAME) } fun AppCompatActivity.showSystemUI() { 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 c76bffaa5..3232c6eab 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -13,8 +13,15 @@ import com.bumptech.glide.Glide import com.bumptech.glide.Priority import com.bumptech.glide.load.DecodeFormat import com.bumptech.glide.load.engine.DiskCacheStrategy +import com.bumptech.glide.request.RequestListener +import com.bumptech.glide.request.target.Target +import com.davemorrissey.labs.subscaleview.ImageSource +import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView +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.GlideRotateTransformation import com.simplemobiletools.gallery.helpers.MEDIUM @@ -72,6 +79,7 @@ class PhotoFragment : ViewPagerFragment() { } } + view.subsampling_view.apply { setOnClickListener({ photoClicked() }) } view.photo_view.apply { maximumScale = 8f mediumScale = 3f @@ -140,9 +148,18 @@ class PhotoFragment : ViewPagerFragment() { .load(medium.path) .asBitmap() .format(DecodeFormat.PREFER_ARGB_8888) - .thumbnail(0.1f) .diskCacheStrategy(DiskCacheStrategy.NONE) - .into(view.photo_view) + .override(ViewPagerActivity.screenWidth, ViewPagerActivity.screenHeight) + .listener(object : RequestListener { + override fun onException(e: java.lang.Exception?, model: String?, target: Target?, isFirstResource: Boolean): Boolean { + return false + } + + override fun onResourceReady(resource: Bitmap?, model: String?, target: Target?, isFromMemoryCache: Boolean, isFirstResource: Boolean): Boolean { + addZoomableView() + return false + } + }).into(view.photo_view) } else { Glide.with(this) .load(medium.path) @@ -155,6 +172,39 @@ class PhotoFragment : ViewPagerFragment() { } } + private fun addZoomableView() { + if (!medium.isPng()) { + view.subsampling_view.apply { + beVisible() + setDoubleTapZoomScale(1.4f) + setImage(ImageSource.uri(medium.path)) + orientation = SubsamplingScaleImageView.ORIENTATION_USE_EXIF + setOnImageEventListener(object : SubsamplingScaleImageView.OnImageEventListener { + override fun onImageLoaded() { + } + + override fun onReady() { + view.photo_view.beGone() + view.photo_view.setImageBitmap(null) + } + + override fun onTileLoadError(p0: Exception?) { + } + + override fun onPreviewReleased() { + } + + override fun onImageLoadError(p0: Exception?) { + beGone() + } + + override fun onPreviewLoadError(p0: Exception?) { + } + }) + } + } + } + fun rotateImageViewBy(degrees: Float) { loadBitmap(degrees) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt index b6749ca50..d33f51d19 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.models import com.simplemobiletools.commons.extensions.getMimeType import com.simplemobiletools.commons.extensions.isGif +import com.simplemobiletools.commons.extensions.isPng import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED import com.simplemobiletools.commons.helpers.SORT_BY_NAME import com.simplemobiletools.commons.helpers.SORT_BY_SIZE @@ -15,6 +16,8 @@ data class Medium(val name: String, var path: String, val isVideo: Boolean, val var sorting: Int = 0 } + fun isPng() = path.isPng() + fun isGif() = path.isGif() fun isImage() = !isGif() && !isVideo diff --git a/app/src/main/res/layout/pager_photo_item.xml b/app/src/main/res/layout/pager_photo_item.xml index 056e8b81a..7d7cf1e82 100644 --- a/app/src/main/res/layout/pager_photo_item.xml +++ b/app/src/main/res/layout/pager_photo_item.xml @@ -9,4 +9,11 @@ android:id="@+id/photo_view" android:layout_width="match_parent" android:layout_height="match_parent"/> + + +