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 #3 from qoqa/wip-2
Remove useless SvgSoftwareLayerSetter #2
- Loading branch information
Showing
9 changed files
with
88 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ dependencies { | |
## Usage | ||
```kotlin | ||
GlideApp.with(this) | ||
.asSvg() | ||
.load(url) | ||
.into(picto_view) | ||
``` |
20 changes: 0 additions & 20 deletions
20
library/src/main/java/ch/qoqa/glide/svg/GlideSvgExtension.kt
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
library/src/main/java/ch/qoqa/glide/svg/SvgBitmapTranscoder.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,29 @@ | ||
package ch.qoqa.glide.svg | ||
|
||
import android.graphics.Bitmap | ||
import android.graphics.Canvas | ||
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 SvgBitmapTranscoder : ResourceTranscoder<SVG, Bitmap> { | ||
override fun transcode(toTranscode: Resource<SVG>, options: Options): Resource<Bitmap> { | ||
val svg = toTranscode.get() | ||
val width = svg.documentWidth.toInt().takeIf { it > 0 } | ||
?: (svg.documentViewBox.right - svg.documentViewBox.left).toInt() | ||
val height = svg.documentHeight.toInt().takeIf { it > 0 } | ||
?: (svg.documentViewBox.bottom - svg.documentViewBox.top).toInt() | ||
|
||
val picture = svg.renderToPicture(width, height) | ||
val drawable = PictureDrawable(picture) | ||
|
||
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) | ||
val canvas = Canvas(bitmap) | ||
canvas.drawPicture(drawable.picture) | ||
|
||
return SimpleResource(bitmap) | ||
} | ||
} |
25 changes: 8 additions & 17 deletions
25
library/src/main/java/ch/qoqa/glide/svg/SvgDrawableTranscoder.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 |
---|---|---|
@@ -1,29 +1,20 @@ | ||
package ch.qoqa.glide.svg | ||
|
||
import android.graphics.Bitmap | ||
import android.graphics.Canvas | ||
import android.graphics.drawable.PictureDrawable | ||
import android.content.Context | ||
import android.graphics.drawable.BitmapDrawable | ||
import android.graphics.drawable.Drawable | ||
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, Bitmap> { | ||
override fun transcode(toTranscode: Resource<SVG>, options: Options): Resource<Bitmap> { | ||
val svg = toTranscode.get() | ||
val width = svg.documentWidth.toInt().takeIf { it > 0 } | ||
?: (svg.documentViewBox.right - svg.documentViewBox.left).toInt() | ||
val height = svg.documentHeight.toInt().takeIf { it > 0 } | ||
?: (svg.documentViewBox.bottom - svg.documentViewBox.top).toInt() | ||
class SvgDrawableTranscoder(private val context: Context) : ResourceTranscoder<SVG, Drawable> { | ||
private val bitmapTranscoder = SvgBitmapTranscoder() | ||
|
||
val picture = svg.renderToPicture(width, height) | ||
val drawable = PictureDrawable(picture) | ||
override fun transcode(toTranscode: Resource<SVG>, options: Options): Resource<Drawable> { | ||
val bitmap = bitmapTranscoder.transcode(toTranscode, options).get() | ||
|
||
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) | ||
val canvas = Canvas(bitmap) | ||
canvas.drawPicture(drawable.picture) | ||
|
||
return SimpleResource(bitmap) | ||
return SimpleResource(BitmapDrawable(context.resources, bitmap)) | ||
} | ||
} |
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
29 changes: 0 additions & 29 deletions
29
library/src/main/java/ch/qoqa/glide/svg/SvgSoftwareLayerSetter.kt
This file was deleted.
Oops, something went wrong.
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<ImageView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/sample_image_view" | ||
android:layout_width="60dp" | ||
android:layout_height="60dp" | ||
android:layout_centerInParent="true" /> |
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