Search in sources :

Example 1 with DocumentData

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;
        }
    });
}
Also used : LottieFrameInfo(com.airbnb.lottie.value.LottieFrameInfo) DocumentData(com.airbnb.lottie.model.DocumentData)

Example 2 with 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();
}
Also used : DocumentData(com.airbnb.lottie.model.DocumentData) Font(com.airbnb.lottie.model.Font) Paint(android.graphics.Paint)

Example 3 with DocumentData

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);
}
Also used : DocumentData(com.airbnb.lottie.model.DocumentData) Justification(com.airbnb.lottie.model.DocumentData.Justification)

Aggregations

DocumentData (com.airbnb.lottie.model.DocumentData)3 Paint (android.graphics.Paint)1 Justification (com.airbnb.lottie.model.DocumentData.Justification)1 Font (com.airbnb.lottie.model.Font)1 LottieFrameInfo (com.airbnb.lottie.value.LottieFrameInfo)1