/** * Creates a {@link KyrieDrawable} from an existing {@link VectorDrawable} or {@link * AnimatedVectorDrawable} XML file. */ @Nullable public static KyrieDrawable create(Context context, @DrawableRes int resId) { try { final KyrieDrawable.Builder builder = KyrieDrawable.builder(); InflationUtils.inflate(builder, context, resId); return builder.build(); } catch (XmlPullParserException | IOException e) { e.printStackTrace(); Log.e(TAG, "Error parsing drawable", e); return null; } }
inflateGroup(groupBuilder, context, parser, attrs, targetMap); if (groupBuilderStack.isEmpty()) { builder.child(groupBuilder); } else { groupBuilderStack.peek().child(groupBuilder); inflatePath(pathBuilder, context, parser, attrs, targetMap); if (groupBuilderStack.isEmpty()) { builder.child(pathBuilder); } else { groupBuilderStack.peek().child(pathBuilder); inflateClipPath(clipPathBuilder, context, parser, attrs, targetMap); if (groupBuilderStack.isEmpty()) { builder.child(clipPathBuilder); } else { groupBuilderStack.peek().child(clipPathBuilder);
/** Constructs a new {@link KyrieDrawable.Builder}. */ @NonNull public static Builder builder() { return new Builder(); }
private KyrieDrawable createLapsDrawable() { final KyrieDrawable.Builder builder = KyrieDrawable.builder().viewport(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); for (Polygon polygon : polygons) { builder.child( PathNode.builder() .pathData(PathData.parse(polygon.pathData)) .strokeWidth(4f) .strokeColor(polygon.color)); } for (Polygon polygon : polygons) { final PathData pathData = PathData.parse(TextUtils.join(" ", Collections.nCopies(polygon.laps, polygon.pathData))); final Animation<PointF, PointF> pathMotion = Animation.ofPathMotion(PathData.toPath(pathData)) .repeatCount(Animation.INFINITE) .duration(DURATION); builder.child( CircleNode.builder() .fillColor(Color.BLACK) .radius(8) .centerX(pathMotion.transform(p -> p.x)) .centerY(pathMotion.transform(p -> p.y))); } return builder.build(); }
private static void updateVectorFromTypedArray( KyrieDrawable.Builder builder, TypedArray a, XmlPullParser parser, @Nullable Map<String, Animation[]> animationMap) { builder.tintList(a.getColorStateList(Styleable.Vector.TINT)); final int tintMode = TypedArrayUtils.getNamedInt(a, parser, "tintMode", Styleable.Vector.TINT_MODE, -1); builder.tintMode(parseTintMode(tintMode, PorterDuff.Mode.SRC_IN)); builder.autoMirrored( TypedArrayUtils.getNamedBoolean( a, parser, "autoMirrored", Styleable.Vector.AUTO_MIRRORED, false)); builder.viewportWidth( TypedArrayUtils.getNamedFloat( a, parser, "viewportWidth", Styleable.Vector.VIEWPORT_WIDTH, -1)); builder.viewportHeight( TypedArrayUtils.getNamedFloat( a, parser, "viewportHeight", Styleable.Vector.VIEWPORT_HEIGHT, -1)); builder.width((int) a.getDimension(Styleable.Vector.WIDTH, -1)); builder.height((int) a.getDimension(Styleable.Vector.HEIGHT, -1)); builder.alpha(TypedArrayUtils.getNamedFloat(a, parser, "alpha", Styleable.Vector.ALPHA, 1)); if (animationMap != null && animationMap.containsKey("alpha")) { builder.alpha((Animation<?, Float>[]) animationMap.get("alpha")); } }
private KyrieDrawable createVortexDrawable() { final KyrieDrawable.Builder builder = KyrieDrawable.builder().viewport(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); for (Polygon polygon : polygons) { final float length = polygon.length; final float totalLength = length * polygon.laps; builder.child( PathNode.builder() .pathData(PathData.parse(polygon.pathData)) .strokeWidth(4f) .strokeColor(polygon.color) .strokeDashArray( Animation.ofFloatArray(new float[] {0, length}, new float[] {length, 0}) .repeatCount(Animation.INFINITE) .duration(DURATION)) .strokeDashOffset( Animation.ofFloat(0f, 2 * totalLength) .repeatCount(Animation.INFINITE) .duration(DURATION))); } return builder.build(); }
public final Builder child(Node.Builder builder) { return child(builder.build()); }
public final Builder tint(@ColorInt int tint) { return tintList(ColorStateList.valueOf(tint)); }
public final Builder viewport( @FloatRange(from = 0f) float viewportWidth, @FloatRange(from = 0f) float viewportHeight) { viewportWidth(viewportWidth); viewportHeight(viewportHeight); return this; }