This repository has been archived by the owner on Aug 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from qoqa/support-xml-string
Support SVG from XML raw string
- Loading branch information
Showing
14 changed files
with
182 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Project-wide Gradle settings. | ||
|
||
# IDE (e.g. Android Studio) users: | ||
# Gradle settings configured through the IDE *will override* | ||
# any settings specified in this file. | ||
|
||
# For more details on how to configure your build environment visit | ||
# http://www.gradle.org/docs/current/userguide/build_environment.html | ||
|
||
# Specifies the JVM arguments used for the daemon process. | ||
# The setting is particularly useful for tweaking memory settings. | ||
android.enableJetifier=true | ||
android.useAndroidX=true | ||
org.gradle.jvmargs=-Xmx1536m | ||
|
||
# When configured, Gradle will run in incubating parallel mode. | ||
# This option should only be used with decoupled projects. More details, visit | ||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects | ||
# org.gradle.parallel=true |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Tue Nov 28 21:29:22 CET 2017 | ||
#Wed Nov 13 12:58:15 CET 2019 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
library/src/main/java/ch/qoqa/glide/svg/SvgStringModelLoaderFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package ch.qoqa.glide.svg | ||
|
||
import com.bumptech.glide.Priority | ||
import com.bumptech.glide.load.DataSource | ||
import com.bumptech.glide.load.Key | ||
import com.bumptech.glide.load.Options | ||
import com.bumptech.glide.load.ResourceDecoder | ||
import com.bumptech.glide.load.data.DataFetcher | ||
import com.bumptech.glide.load.engine.Resource | ||
import com.bumptech.glide.load.model.ModelLoader | ||
import com.bumptech.glide.load.model.ModelLoaderFactory | ||
import com.bumptech.glide.load.model.MultiModelLoaderFactory | ||
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 | ||
|
||
/** | ||
* Decodes an SVG internal representation from an [String]. | ||
*/ | ||
class SvgStringModelLoaderFactory : ModelLoaderFactory<String, InputStream> { | ||
override fun build(multiFactory: MultiModelLoaderFactory): ModelLoader<String, InputStream> { | ||
return object : ModelLoader<String, InputStream> { | ||
override fun handles(model: String) = model.contains("<svg") | ||
|
||
override fun buildLoadData( | ||
model: String, | ||
width: Int, | ||
height: Int, | ||
options: Options | ||
): ModelLoader.LoadData<InputStream>? { | ||
return ModelLoader.LoadData<InputStream>( | ||
Key { messageDigest -> messageDigest.update("svg_string_$model".toByteArray()) }, | ||
object : DataFetcher<InputStream> { | ||
override fun cancel() {} | ||
|
||
override fun getDataSource() = DataSource.LOCAL | ||
|
||
override fun loadData( | ||
priority: Priority, | ||
callback: DataFetcher.DataCallback<in InputStream> | ||
) { | ||
callback.onDataReady(model.byteInputStream()) | ||
} | ||
|
||
override fun getDataClass() = InputStream::class.java | ||
|
||
override fun cleanup() {} | ||
}) | ||
} | ||
} | ||
} | ||
|
||
override fun teardown() { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.