-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
75 additions
and
2 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
35 changes: 35 additions & 0 deletions
35
app/src/main/java/com/bumptech/glide/samples/svg/SvgDecoder.java
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,35 @@ | ||
package com.bumptech.glide.samples.svg; | ||
|
||
import androidx.annotation.NonNull; | ||
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; | ||
|
||
/** | ||
* Decodes an SVG internal representation from an {@link InputStream}. | ||
*/ | ||
public class SvgDecoder implements ResourceDecoder<InputStream, SVG> { | ||
|
||
@Override | ||
public boolean handles(@NonNull InputStream source, @NonNull Options options) { | ||
// TODO: Can we tell? | ||
return true; | ||
} | ||
|
||
public Resource<SVG> decode( | ||
@NonNull InputStream source, int width, int height, @NonNull Options options) | ||
throws IOException { | ||
try { | ||
SVG svg = SVG.getFromInputStream(source); | ||
return new SimpleResource<>(svg); | ||
} catch (SVGParseException ex) { | ||
throw new IOException("Cannot load SVG from stream", ex); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/bumptech/glide/samples/svg/SvgDrawableTranscoder.java
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,26 @@ | ||
package com.bumptech.glide.samples.svg; | ||
|
||
import android.graphics.Picture; | ||
import android.graphics.drawable.PictureDrawable; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
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; | ||
|
||
/** | ||
* Convert the {@link SVG}'s internal representation to an Android-compatible one ({@link Picture}). | ||
*/ | ||
public class SvgDrawableTranscoder implements ResourceTranscoder<SVG, PictureDrawable> { | ||
@Nullable | ||
@Override | ||
public Resource<PictureDrawable> transcode( | ||
@NonNull Resource<SVG> toTranscode, @NonNull Options options) { | ||
SVG svg = toTranscode.get(); | ||
Picture picture = svg.renderToPicture(); | ||
PictureDrawable drawable = new PictureDrawable(picture); | ||
return new SimpleResource<>(drawable); | ||
} | ||
} |
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