use of com.airbnb.lottie.model.DocumentData in project lottie-android by airbnb.
the class TextKeyframeAnimation method setStringValueCallback.
public void setStringValueCallback(LottieValueCallback<String> valueCallback) {
final LottieFrameInfo<String> stringFrameInfo = new LottieFrameInfo<>();
final DocumentData documentData = new DocumentData();
super.setValueCallback(new LottieValueCallback<DocumentData>() {
@Override
public DocumentData getValue(LottieFrameInfo<DocumentData> frameInfo) {
stringFrameInfo.set(frameInfo.getStartFrame(), frameInfo.getEndFrame(), frameInfo.getStartValue().text, frameInfo.getEndValue().text, frameInfo.getLinearKeyframeProgress(), frameInfo.getInterpolatedKeyframeProgress(), frameInfo.getOverallProgress());
String text = valueCallback.getValue(stringFrameInfo);
DocumentData baseDocumentData = frameInfo.getInterpolatedKeyframeProgress() == 1f ? frameInfo.getEndValue() : frameInfo.getStartValue();
documentData.set(text, baseDocumentData.fontName, baseDocumentData.size, baseDocumentData.justification, baseDocumentData.tracking, baseDocumentData.lineHeight, baseDocumentData.baselineShift, baseDocumentData.color, baseDocumentData.strokeColor, baseDocumentData.strokeWidth, baseDocumentData.strokeOverFill);
return documentData;
}
});
}
use of com.airbnb.lottie.model.DocumentData in project lottie-android by airbnb.
the class TextLayer method drawLayer.
@Override
void drawLayer(Canvas canvas, Matrix parentMatrix, int parentAlpha) {
canvas.save();
if (!lottieDrawable.useTextGlyphs()) {
canvas.concat(parentMatrix);
}
DocumentData documentData = textAnimation.getValue();
Font font = composition.getFonts().get(documentData.fontName);
if (font == null) {
// Something is wrong.
canvas.restore();
return;
}
if (colorCallbackAnimation != null) {
fillPaint.setColor(colorCallbackAnimation.getValue());
} else if (colorAnimation != null) {
fillPaint.setColor(colorAnimation.getValue());
} else {
fillPaint.setColor(documentData.color);
}
if (strokeColorCallbackAnimation != null) {
strokePaint.setColor(strokeColorCallbackAnimation.getValue());
} else if (strokeColorAnimation != null) {
strokePaint.setColor(strokeColorAnimation.getValue());
} else {
strokePaint.setColor(documentData.strokeColor);
}
int opacity = transform.getOpacity() == null ? 100 : transform.getOpacity().getValue();
int alpha = opacity * 255 / 100;
fillPaint.setAlpha(alpha);
strokePaint.setAlpha(alpha);
if (strokeWidthCallbackAnimation != null) {
strokePaint.setStrokeWidth(strokeWidthCallbackAnimation.getValue());
} else if (strokeWidthAnimation != null) {
strokePaint.setStrokeWidth(strokeWidthAnimation.getValue());
} else {
float parentScale = Utils.getScale(parentMatrix);
strokePaint.setStrokeWidth(documentData.strokeWidth * Utils.dpScale() * parentScale);
}
if (lottieDrawable.useTextGlyphs()) {
drawTextGlyphs(documentData, parentMatrix, font, canvas);
} else {
drawTextWithFont(documentData, font, canvas);
}
canvas.restore();
}
use of com.airbnb.lottie.model.DocumentData in project lottie-android by airbnb.
the class DocumentDataParser method parse.
@Override
public DocumentData parse(JsonReader reader, float scale) throws IOException {
String text = null;
String fontName = null;
float size = 0f;
Justification justification = Justification.CENTER;
int tracking = 0;
float lineHeight = 0f;
float baselineShift = 0f;
int fillColor = 0;
int strokeColor = 0;
float strokeWidth = 0f;
boolean strokeOverFill = true;
reader.beginObject();
while (reader.hasNext()) {
switch(reader.selectName(NAMES)) {
case 0:
text = reader.nextString();
break;
case 1:
fontName = reader.nextString();
break;
case 2:
size = (float) reader.nextDouble();
break;
case 3:
int justificationInt = reader.nextInt();
if (justificationInt > Justification.CENTER.ordinal() || justificationInt < 0) {
justification = Justification.CENTER;
} else {
justification = Justification.values()[justificationInt];
}
break;
case 4:
tracking = reader.nextInt();
break;
case 5:
lineHeight = (float) reader.nextDouble();
break;
case 6:
baselineShift = (float) reader.nextDouble();
break;
case 7:
fillColor = JsonUtils.jsonToColor(reader);
break;
case 8:
strokeColor = JsonUtils.jsonToColor(reader);
break;
case 9:
strokeWidth = (float) reader.nextDouble();
break;
case 10:
strokeOverFill = reader.nextBoolean();
break;
default:
reader.skipName();
reader.skipValue();
}
}
reader.endObject();
return new DocumentData(text, fontName, size, justification, tracking, lineHeight, baselineShift, fillColor, strokeColor, strokeWidth, strokeOverFill);
}
Aggregations