TPSVG_Android_SVG_Library
TPSVG_Android_SVG_Library copied to clipboard
full rewrite to support scaleType
I needed scaleType to work with an imageView. That pr does that. Here is a simple example on how to use it
imageView = new ImageView(context) {
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
Drawable drawable = imageView.getDrawable();
if (!(drawable instanceof SVGDrawable)) {
return;
}
imageView.setImageDrawable(null);
int vWidth = getWidth() - getPaddingLeft() - getPaddingRight();
int vHeight = getHeight() - getPaddingTop() - getPaddingBottom();
((SVGDrawable)drawable).adjustToParentSize(vWidth, vHeight);
imageView.setImageDrawable(drawable);
}
@Override
public void setScaleType (ScaleType scaleType) {
super.setScaleType(scaleType);
Drawable drawable = getDrawable();
if (!(drawable instanceof SVGDrawable)) {
return;
}
setImageDrawable(null);
((SVGDrawable)drawable).setScaleType(scaleType);
int vWidth = getWidth() - getPaddingLeft() - getPaddingRight();
int vHeight = getHeight() - getPaddingTop() - getPaddingBottom();
((SVGDrawable)drawable).adjustToParentSize(vWidth, vHeight);
setImageDrawable(drawable);
}
@Override
public void setImageDrawable(Drawable drawable) {
if (!(drawable instanceof SVGDrawable)) {
super.setImageDrawable(drawable);
return;
}
if (getDrawable() == drawable) {
return;
}
SVGDrawable svg = (SVGDrawable) drawable;
svg.setScaleType(getScaleType());
int vWidth = getWidth() - getPaddingLeft() - getPaddingRight();
int vHeight = getHeight() - getPaddingTop()
- getPaddingBottom();
svg.adjustToParentSize(vWidth, vHeight);
super.setImageDrawable(svg);
}
};
Thank you so much for this work :) I promise I'll look at your pull requests as soon as I can.