Android Open Source - TweeningTextView Svg Glyph Tween Via Interpolation






From Project

Back to project page TweeningTextView.

License

The source code is released under:

Apache License

If you think the Android project TweeningTextView listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.kokalabs.svg;
//from  www  . j  a  v a2  s .  c  o m
import android.animation.TypeEvaluator;

import com.google.common.collect.Lists;

import java.util.List;

public class SvgGlyphTweenViaInterpolation implements TypeEvaluator<SvgGlyph> {
    @Override
    public SvgGlyph evaluate(float fraction, SvgGlyph startPath, SvgGlyph endPath) {
        List<CubicBezierCurve> starts = startPath.getPath();
        List<CubicBezierCurve> ends = endPath.getPath();

        int max = Math.max(starts.size(), ends.size());
        fill(starts, max);
        fill(ends, max);

        List<CubicBezierCurve> tweened = Lists.newArrayList();
        for (int i = 0; i < max; i++) {
            tweened.add(tween(fraction, starts.get(i), ends.get(i)));
        }
        return SvgGlyph.from(tweened);
    }

    private void fill(List<CubicBezierCurve> path, int toFill) {
        CubicBezierCurve last = path.get(path.size() - 1);
        CubicBezierCurve lastPoint = new CubicBezierCurve(
                last.endX, last.endY, last.endX, last.endY, last.endX, last.endY, last.endX, last.endY);
        CubicBezierCurve filler = path.size() != 0 ? lastPoint : CubicBezierCurve.origin();
        while (path.size() < toFill) {
            path.add(filler);
        }
    }

    private CubicBezierCurve tween(float fraction, CubicBezierCurve start, CubicBezierCurve end) {
        double sX = tween(fraction, start.startX, end.startX);
        double sY = tween(fraction, start.startY, end.startY);
        double c1X = tween(fraction, start.control1X, end.control1X);
        double c1Y = tween(fraction, start.control1Y, end.control1Y);
        double c2X = tween(fraction, start.control2X, end.control2X);
        double c2Y = tween(fraction, start.control2Y, end.control2Y);
        double eX = tween(fraction, start.endX, end.endX);
        double eY = tween(fraction, start.endY, end.endY);
        return new CubicBezierCurve(sX, sY, c1X, c1Y, c2X, c2Y, eX, eY);
    }

    private double tween(double fraction, double start, double end) {
        return start + fraction * (end - start);
    }
}




Java Source Code List

com.kokalabs.svg.CubicBezierCurve.java
com.kokalabs.svg.PointD.java
com.kokalabs.svg.SvgCommandAsCubicHandler.java
com.kokalabs.svg.SvgCommandHandler.java
com.kokalabs.svg.SvgGlyphParser.java
com.kokalabs.svg.SvgGlyphTweenViaInterpolation.java
com.kokalabs.svg.SvgGlyph.java
com.kokalabs.tweening.textview.TweeningTextView.java
com.kokalabs.tweening.textview.example.ApplicationTest.java
com.kokalabs.tweening.textview.example.Char.java
com.kokalabs.tweening.textview.example.TweeningActivity.java