From 47f73e9f372e5dec65c7dcb58f70d379fd79486c Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 17 Aug 2021 16:43:20 +0200 Subject: [PATCH] adding support for .apng files --- app/build.gradle | 5 ++- .../gallery/pro/fragments/PhotoFragment.kt | 38 +++++++++++++++---- .../gallery/pro/models/Medium.kt | 7 ++-- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 16d80e0d7..79ec339c9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -78,7 +78,7 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:e3c531cbd1' + implementation 'com.github.SimpleMobileTools:Simple-Commons:94ece2461b' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.22' @@ -93,7 +93,8 @@ dependencies { implementation 'com.github.tibbi:gestureviews:a8e8fa8d27' implementation 'com.github.tibbi:subsampling-scale-image-view:60fb7362d5' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' - implementation 'com.github.penfeizhou.android.animation:awebp:2.9.0' + implementation 'com.github.penfeizhou.android.animation:awebp:2.11.0' + implementation 'com.github.penfeizhou.android.animation:apng:2.11.0' implementation('com.squareup.picasso:picasso:2.71828') { exclude group: 'com.squareup.okhttp3', module: 'okhttp' } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt index 88a2641bd..096fc56d2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt @@ -36,6 +36,7 @@ import com.davemorrissey.labs.subscaleview.DecoderFactory import com.davemorrissey.labs.subscaleview.ImageDecoder import com.davemorrissey.labs.subscaleview.ImageRegionDecoder import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView +import com.github.penfeizhou.animation.apng.APNGDrawable import com.github.penfeizhou.animation.webp.WebPDrawable import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.* @@ -289,7 +290,7 @@ class PhotoFragment : ViewPagerFragment() { super.setMenuVisibility(menuVisible) mIsFragmentVisible = menuVisible if (mWasInit) { - if (!mMedium.isGIF() && !mMedium.isWebP()) { + if (!mMedium.isGIF() && !mMedium.isWebP() && !mMedium.isApng()) { photoFragmentVisibilityChanged(menuVisible) } } @@ -357,6 +358,7 @@ class PhotoFragment : ViewPagerFragment() { when { mMedium.isGIF() -> loadGif() mMedium.isSVG() -> loadSVG() + mMedium.isApng() -> loadAPNG() else -> loadBitmap() } } @@ -396,6 +398,13 @@ class PhotoFragment : ViewPagerFragment() { } } + private fun loadAPNG() { + if (context != null) { + val drawable = APNGDrawable.fromFile(mMedium.path) + mView.gestures_view.setImageDrawable(drawable) + } + } + private fun loadBitmap(addZoomableView: Boolean = true) { if (context == null) { return @@ -440,8 +449,15 @@ class PhotoFragment : ViewPagerFragment() { return false } - override fun onResourceReady(resource: Drawable?, model: Any?, target: Target?, dataSource: DataSource?, isFirstResource: Boolean): Boolean { - mView.gestures_view.controller.settings.isZoomEnabled = mMedium.isRaw() || mCurrentRotationDegrees != 0 || context?.config?.allowZoomingImages == false + override fun onResourceReady( + resource: Drawable?, + model: Any?, + target: Target?, + dataSource: DataSource?, + isFirstResource: Boolean + ): Boolean { + val allowZoomingImages = context?.config?.allowZoomingImages ?: true + mView.gestures_view.controller.settings.isZoomEnabled = mMedium.isRaw() || mCurrentRotationDegrees != 0 || allowZoomingImages == false if (mIsFragmentVisible && addZoomableView) { scheduleZoomableView() } @@ -469,7 +485,8 @@ class PhotoFragment : ViewPagerFragment() { picasso.into(mView.gestures_view, object : Callback { override fun onSuccess() { - mView.gestures_view.controller.settings.isZoomEnabled = mMedium.isRaw() || mCurrentRotationDegrees != 0 || context?.config?.allowZoomingImages == false + mView.gestures_view.controller.settings.isZoomEnabled = + mMedium.isRaw() || mCurrentRotationDegrees != 0 || context?.config?.allowZoomingImages == false if (mIsFragmentVisible && addZoomableView) { scheduleZoomableView() } @@ -491,7 +508,7 @@ class PhotoFragment : ViewPagerFragment() { val files = File(mMedium.parentPath).listFiles()?.toMutableList() as? ArrayList if (files != null) { val screenWidth = context!!.realScreenSize.x - val itemWidth = context!!.resources.getDimension(R.dimen.portrait_photos_stripe_height).toInt() + context!!.resources.getDimension(R.dimen.one_dp).toInt() + val itemWidth = resources.getDimension(R.dimen.portrait_photos_stripe_height).toInt() + resources.getDimension(R.dimen.one_dp).toInt() val sideWidth = screenWidth / 2 - itemWidth / 2 val fakeItemsCnt = ceil(sideWidth / itemWidth.toDouble()).toInt() @@ -552,9 +569,9 @@ class PhotoFragment : ViewPagerFragment() { } private fun setupStripeBottomMargin() { - var bottomMargin = context!!.navigationBarHeight + context!!.resources.getDimension(R.dimen.normal_margin).toInt() + var bottomMargin = context!!.navigationBarHeight + resources.getDimension(R.dimen.normal_margin).toInt() if (context!!.config.bottomActions) { - bottomMargin += context!!.resources.getDimension(R.dimen.bottom_actions_height).toInt() + bottomMargin += resources.getDimension(R.dimen.bottom_actions_height).toInt() } (mView.photo_portrait_stripe_wrapper.layoutParams as RelativeLayout.LayoutParams).bottomMargin = bottomMargin } @@ -692,7 +709,12 @@ class PhotoFragment : ViewPagerFragment() { private fun checkIfPanorama() { mIsPanorama = try { - val inputStream = if (mMedium.path.startsWith("content:/")) context!!.contentResolver.openInputStream(Uri.parse(mMedium.path)) else File(mMedium.path).inputStream() + val inputStream = if (mMedium.path.startsWith("content:/")) { + context!!.contentResolver.openInputStream(Uri.parse(mMedium.path)) + } else { + File(mMedium.path).inputStream() + } + val imageParser = JpegImageParser().getXmpXml(ByteSourceInputStream(inputStream, mMedium.name), HashMap()) imageParser.contains("GPano:UsePanoramaViewer=\"True\"", true) || imageParser.contains("True", true) || diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/Medium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/Medium.kt index 05adfa524..6f38135b0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/Medium.kt @@ -3,10 +3,7 @@ package com.simplemobiletools.gallery.pro.models import android.content.Context import androidx.room.* import com.bumptech.glide.signature.ObjectKey -import com.simplemobiletools.commons.extensions.formatDate -import com.simplemobiletools.commons.extensions.formatSize -import com.simplemobiletools.commons.extensions.getFilenameExtension -import com.simplemobiletools.commons.extensions.isWebP +import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED import com.simplemobiletools.commons.helpers.SORT_BY_NAME import com.simplemobiletools.commons.helpers.SORT_BY_PATH @@ -53,6 +50,8 @@ data class Medium( fun isPortrait() = type == TYPE_PORTRAITS + fun isApng() = name.isApng() + fun isHidden() = name.startsWith('.') fun getBubbleText(sorting: Int, context: Context, dateFormat: String, timeFormat: String) = when {