handle showing fullscreen svg files
This commit is contained in:
parent
75d9e03981
commit
8e9bbbe451
9 changed files with 115 additions and 14 deletions
|
@ -58,6 +58,8 @@ dependencies {
|
||||||
implementation 'org.apache.sanselan:sanselan:0.97-incubator'
|
implementation 'org.apache.sanselan:sanselan:0.97-incubator'
|
||||||
implementation 'info.androidhive:imagefilters:1.0.7'
|
implementation 'info.androidhive:imagefilters:1.0.7'
|
||||||
implementation 'com.squareup.picasso:picasso:2.71828'
|
implementation 'com.squareup.picasso:picasso:2.71828'
|
||||||
|
implementation 'com.caverock:androidsvg-aar:1.3'
|
||||||
|
kapt 'com.github.bumptech.glide:compiler:4.8.0'
|
||||||
|
|
||||||
kapt "android.arch.persistence.room:compiler:1.1.1"
|
kapt "android.arch.persistence.room:compiler:1.1.1"
|
||||||
implementation "android.arch.persistence.room:runtime:1.1.1"
|
implementation "android.arch.persistence.room:runtime:1.1.1"
|
||||||
|
|
|
@ -290,7 +290,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
findItem(R.id.menu_properties).isVisible = visibleBottomActions and BOTTOM_ACTION_PROPERTIES == 0
|
findItem(R.id.menu_properties).isVisible = visibleBottomActions and BOTTOM_ACTION_PROPERTIES == 0
|
||||||
findItem(R.id.menu_delete).isVisible = visibleBottomActions and BOTTOM_ACTION_DELETE == 0
|
findItem(R.id.menu_delete).isVisible = visibleBottomActions and BOTTOM_ACTION_DELETE == 0
|
||||||
findItem(R.id.menu_share).isVisible = visibleBottomActions and BOTTOM_ACTION_SHARE == 0
|
findItem(R.id.menu_share).isVisible = visibleBottomActions and BOTTOM_ACTION_SHARE == 0
|
||||||
findItem(R.id.menu_edit).isVisible = visibleBottomActions and BOTTOM_ACTION_EDIT == 0
|
findItem(R.id.menu_edit).isVisible = visibleBottomActions and BOTTOM_ACTION_EDIT == 0 && !currentMedium.isSVG()
|
||||||
findItem(R.id.menu_rename).isVisible = visibleBottomActions and BOTTOM_ACTION_RENAME == 0 && !currentMedium.getIsInRecycleBin()
|
findItem(R.id.menu_rename).isVisible = visibleBottomActions and BOTTOM_ACTION_RENAME == 0 && !currentMedium.getIsInRecycleBin()
|
||||||
findItem(R.id.menu_rotate).isVisible = currentMedium.isImage() && visibleBottomActions and BOTTOM_ACTION_ROTATE == 0
|
findItem(R.id.menu_rotate).isVisible = currentMedium.isImage() && visibleBottomActions and BOTTOM_ACTION_ROTATE == 0
|
||||||
findItem(R.id.menu_set_as).isVisible = visibleBottomActions and BOTTOM_ACTION_SET_AS == 0
|
findItem(R.id.menu_set_as).isVisible = visibleBottomActions and BOTTOM_ACTION_SET_AS == 0
|
||||||
|
@ -459,7 +459,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
private fun scheduleSwipe() {
|
private fun scheduleSwipe() {
|
||||||
mSlideshowHandler.removeCallbacksAndMessages(null)
|
mSlideshowHandler.removeCallbacksAndMessages(null)
|
||||||
if (mIsSlideshowActive) {
|
if (mIsSlideshowActive) {
|
||||||
if (getCurrentMedium()!!.isImage() || getCurrentMedium()!!.isGif()) {
|
if (getCurrentMedium()!!.isImage() || getCurrentMedium()!!.isGIF()) {
|
||||||
mSlideshowHandler.postDelayed({
|
mSlideshowHandler.postDelayed({
|
||||||
if (mIsSlideshowActive && !isActivityDestroyed()) {
|
if (mIsSlideshowActive && !isActivityDestroyed()) {
|
||||||
swipeToNextMedium()
|
swipeToNextMedium()
|
||||||
|
@ -482,11 +482,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!config.slideshowIncludeVideos) {
|
if (!config.slideshowIncludeVideos) {
|
||||||
mSlideshowMedia = mSlideshowMedia.filter { it.isImage() || it.isGif() } as MutableList
|
mSlideshowMedia = mSlideshowMedia.filter { it.isImage() || it.isGIF() } as MutableList
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!config.slideshowIncludeGIFs) {
|
if (!config.slideshowIncludeGIFs) {
|
||||||
mSlideshowMedia = mSlideshowMedia.filter { !it.isGif() } as MutableList
|
mSlideshowMedia = mSlideshowMedia.filter { !it.isGIF() } as MutableList
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.slideshowRandomOrder) {
|
if (config.slideshowRandomOrder) {
|
||||||
|
@ -776,7 +776,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
toggleFavorite()
|
toggleFavorite()
|
||||||
}
|
}
|
||||||
|
|
||||||
bottom_edit.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_EDIT != 0)
|
bottom_edit.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_EDIT != 0 && getCurrentMedium()?.isSVG() == false)
|
||||||
bottom_edit.setOnClickListener {
|
bottom_edit.setOnClickListener {
|
||||||
openEditor(getCurrentPath())
|
openEditor(getCurrentPath())
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ fun ArrayList<Medium>.getDirMediaTypes(): Int {
|
||||||
types += TYPE_VIDEOS
|
types += TYPE_VIDEOS
|
||||||
}
|
}
|
||||||
|
|
||||||
if (any { it.isGif() }) {
|
if (any { it.isGIF() }) {
|
||||||
types += TYPE_GIFS
|
types += TYPE_GIFS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ fun ArrayList<Medium>.getDirMediaTypes(): Int {
|
||||||
types += TYPE_RAWS
|
types += TYPE_RAWS
|
||||||
}
|
}
|
||||||
|
|
||||||
if (any { it.isSvg() }) {
|
if (any { it.isSVG() }) {
|
||||||
types += TYPE_SVGS
|
types += TYPE_SVGS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.graphics.BitmapFactory
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.Matrix
|
import android.graphics.Matrix
|
||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
|
import android.graphics.drawable.PictureDrawable
|
||||||
import android.media.ExifInterface.*
|
import android.media.ExifInterface.*
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
@ -36,6 +37,7 @@ import com.simplemobiletools.gallery.activities.ViewPagerActivity
|
||||||
import com.simplemobiletools.gallery.extensions.*
|
import com.simplemobiletools.gallery.extensions.*
|
||||||
import com.simplemobiletools.gallery.helpers.*
|
import com.simplemobiletools.gallery.helpers.*
|
||||||
import com.simplemobiletools.gallery.models.Medium
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
|
import com.simplemobiletools.gallery.svg.SvgSoftwareLayerSetter
|
||||||
import com.squareup.picasso.Callback
|
import com.squareup.picasso.Callback
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
import it.sephiroth.android.library.exif2.ExifInterface
|
import it.sephiroth.android.library.exif2.ExifInterface
|
||||||
|
@ -165,7 +167,7 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
super.setMenuVisibility(menuVisible)
|
super.setMenuVisibility(menuVisible)
|
||||||
isFragmentVisible = menuVisible
|
isFragmentVisible = menuVisible
|
||||||
if (wasInit) {
|
if (wasInit) {
|
||||||
if (medium.isGif()) {
|
if (medium.isGIF()) {
|
||||||
gifFragmentVisibilityChanged(menuVisible)
|
gifFragmentVisibilityChanged(menuVisible)
|
||||||
} else {
|
} else {
|
||||||
photoFragmentVisibilityChanged(menuVisible)
|
photoFragmentVisibilityChanged(menuVisible)
|
||||||
|
@ -233,10 +235,10 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
|
|
||||||
private fun loadImage() {
|
private fun loadImage() {
|
||||||
imageOrientation = getImageOrientation()
|
imageOrientation = getImageOrientation()
|
||||||
if (medium.isGif()) {
|
when {
|
||||||
loadGif()
|
medium.isGIF() -> loadGif()
|
||||||
} else {
|
medium.isSVG() -> loadSVG()
|
||||||
loadBitmap()
|
else -> loadBitmap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,6 +265,14 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun loadSVG() {
|
||||||
|
Glide.with(this)
|
||||||
|
.`as`(PictureDrawable::class.java)
|
||||||
|
.listener(SvgSoftwareLayerSetter())
|
||||||
|
.load(medium.path)
|
||||||
|
.into(view.photo_view)
|
||||||
|
}
|
||||||
|
|
||||||
private fun loadBitmap(degrees: Int = 0) {
|
private fun loadBitmap(degrees: Int = 0) {
|
||||||
var targetWidth = ViewPagerActivity.screenWidth
|
var targetWidth = ViewPagerActivity.screenWidth
|
||||||
var targetHeight = ViewPagerActivity.screenHeight
|
var targetHeight = ViewPagerActivity.screenHeight
|
||||||
|
|
|
@ -32,7 +32,7 @@ data class Medium(
|
||||||
private const val serialVersionUID = -6553149366975655L
|
private const val serialVersionUID = -6553149366975655L
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isGif() = type == TYPE_GIFS
|
fun isGIF() = type == TYPE_GIFS
|
||||||
|
|
||||||
fun isImage() = type == TYPE_IMAGES
|
fun isImage() = type == TYPE_IMAGES
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ data class Medium(
|
||||||
|
|
||||||
fun isRaw() = type == TYPE_RAWS
|
fun isRaw() = type == TYPE_RAWS
|
||||||
|
|
||||||
fun isSvg() = type == TYPE_SVGS
|
fun isSVG() = type == TYPE_SVGS
|
||||||
|
|
||||||
fun isHidden() = name.startsWith('.')
|
fun isHidden() = name.startsWith('.')
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.simplemobiletools.gallery.svg
|
||||||
|
|
||||||
|
import com.bumptech.glide.load.Options
|
||||||
|
import com.bumptech.glide.load.ResourceDecoder
|
||||||
|
import com.bumptech.glide.load.engine.Resource
|
||||||
|
import com.bumptech.glide.load.resource.SimpleResource
|
||||||
|
import com.caverock.androidsvg.SVG
|
||||||
|
import com.caverock.androidsvg.SVGParseException
|
||||||
|
|
||||||
|
import java.io.IOException
|
||||||
|
import java.io.InputStream
|
||||||
|
|
||||||
|
class SvgDecoder : ResourceDecoder<InputStream, SVG> {
|
||||||
|
|
||||||
|
override fun handles(source: InputStream, options: Options) = true
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
override fun decode(source: InputStream, width: Int, height: Int, options: Options): Resource<SVG>? {
|
||||||
|
try {
|
||||||
|
val svg = SVG.getFromInputStream(source)
|
||||||
|
return SimpleResource(svg)
|
||||||
|
} catch (ex: SVGParseException) {
|
||||||
|
throw IOException("Cannot load SVG from stream", ex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.simplemobiletools.gallery.svg
|
||||||
|
|
||||||
|
import android.graphics.drawable.PictureDrawable
|
||||||
|
import com.bumptech.glide.load.Options
|
||||||
|
import com.bumptech.glide.load.engine.Resource
|
||||||
|
import com.bumptech.glide.load.resource.SimpleResource
|
||||||
|
import com.bumptech.glide.load.resource.transcode.ResourceTranscoder
|
||||||
|
import com.caverock.androidsvg.SVG
|
||||||
|
|
||||||
|
class SvgDrawableTranscoder : ResourceTranscoder<SVG, PictureDrawable> {
|
||||||
|
override fun transcode(toTranscode: Resource<SVG>, options: Options): Resource<PictureDrawable>? {
|
||||||
|
val svg = toTranscode.get()
|
||||||
|
val picture = svg.renderToPicture()
|
||||||
|
val drawable = PictureDrawable(picture)
|
||||||
|
return SimpleResource(drawable)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.simplemobiletools.gallery.svg
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.drawable.PictureDrawable
|
||||||
|
|
||||||
|
import com.bumptech.glide.Glide
|
||||||
|
import com.bumptech.glide.Registry
|
||||||
|
import com.bumptech.glide.annotation.GlideModule
|
||||||
|
import com.bumptech.glide.module.AppGlideModule
|
||||||
|
import com.caverock.androidsvg.SVG
|
||||||
|
|
||||||
|
import java.io.InputStream
|
||||||
|
|
||||||
|
@GlideModule
|
||||||
|
class SvgModule : AppGlideModule() {
|
||||||
|
override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
|
||||||
|
registry.register(SVG::class.java, PictureDrawable::class.java, SvgDrawableTranscoder()).append(InputStream::class.java, SVG::class.java, SvgDecoder())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isManifestParsingEnabled() = false
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.simplemobiletools.gallery.svg
|
||||||
|
|
||||||
|
import android.graphics.drawable.PictureDrawable
|
||||||
|
import android.widget.ImageView
|
||||||
|
|
||||||
|
import com.bumptech.glide.load.DataSource
|
||||||
|
import com.bumptech.glide.load.engine.GlideException
|
||||||
|
import com.bumptech.glide.request.RequestListener
|
||||||
|
import com.bumptech.glide.request.target.ImageViewTarget
|
||||||
|
import com.bumptech.glide.request.target.Target
|
||||||
|
|
||||||
|
class SvgSoftwareLayerSetter : RequestListener<PictureDrawable> {
|
||||||
|
|
||||||
|
override fun onLoadFailed(e: GlideException?, model: Any, target: Target<PictureDrawable>, isFirstResource: Boolean): Boolean {
|
||||||
|
val view = (target as ImageViewTarget<*>).view
|
||||||
|
view.setLayerType(ImageView.LAYER_TYPE_NONE, null)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResourceReady(resource: PictureDrawable, model: Any, target: Target<PictureDrawable>, dataSource: DataSource, isFirstResource: Boolean): Boolean {
|
||||||
|
val view = (target as ImageViewTarget<*>).view
|
||||||
|
view.setLayerType(ImageView.LAYER_TYPE_SOFTWARE, null)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue