Example usage for android.animation Keyframe ofFloat

List of usage examples for android.animation Keyframe ofFloat

Introduction

In this page you can find the example usage for android.animation Keyframe ofFloat.

Prototype

public static Keyframe ofFloat(float fraction, float value) 

Source Link

Document

Constructs a Keyframe object with the given time and value.

Usage

From source file:android.support.graphics.drawable.AnimatorInflaterCompat.java

private static Keyframe loadKeyframe(Context context, Resources res, Theme theme, AttributeSet attrs,
        int valueType, XmlPullParser parser) throws XmlPullParserException, IOException {

    TypedArray a = TypedArrayUtils.obtainAttributes(res, theme, attrs, AndroidResources.STYLEABLE_KEYFRAME);

    Keyframe keyframe = null;//from www  . j av  a  2s  .c  o  m

    float fraction = TypedArrayUtils.getNamedFloat(a, parser, "fraction",
            AndroidResources.STYLEABLE_KEYFRAME_FRACTION, -1);

    TypedValue keyframeValue = TypedArrayUtils.peekNamedValue(a, parser, "value",
            AndroidResources.STYLEABLE_KEYFRAME_VALUE);
    boolean hasValue = (keyframeValue != null);
    if (valueType == VALUE_TYPE_UNDEFINED) {
        // When no value type is provided, check whether it's a color type first.
        // If not, fall back to default value type (i.e. float type).
        if (hasValue && isColorType(keyframeValue.type)) {
            valueType = VALUE_TYPE_COLOR;
        } else {
            valueType = VALUE_TYPE_FLOAT;
        }
    }

    if (hasValue) {
        switch (valueType) {
        case VALUE_TYPE_FLOAT:
            float value = TypedArrayUtils.getNamedFloat(a, parser, "value",
                    AndroidResources.STYLEABLE_KEYFRAME_VALUE, 0);
            keyframe = Keyframe.ofFloat(fraction, value);
            break;
        case VALUE_TYPE_COLOR:
        case VALUE_TYPE_INT:
            int intValue = TypedArrayUtils.getNamedInt(a, parser, "value",
                    AndroidResources.STYLEABLE_KEYFRAME_VALUE, 0);
            keyframe = Keyframe.ofInt(fraction, intValue);
            break;
        }
    } else {
        keyframe = (valueType == VALUE_TYPE_FLOAT) ? Keyframe.ofFloat(fraction) : Keyframe.ofInt(fraction);
    }

    final int resID = TypedArrayUtils.getNamedResourceId(a, parser, "interpolator",
            AndroidResources.STYLEABLE_KEYFRAME_INTERPOLATOR, 0);
    if (resID > 0) {
        final Interpolator interpolator = AnimationUtilsCompat.loadInterpolator(context, resID);
        keyframe.setInterpolator(interpolator);
    }
    a.recycle();

    return keyframe;
}

From source file:io.doist.datetimepicker.time.RadialTimePickerView.java

private static ObjectAnimator getRadiusDisappearAnimator(Object target, String radiusPropertyName,
        InvalidateUpdateListener updateListener, float midRadiusMultiplier, float endRadiusMultiplier) {
    Keyframe kf0, kf1, kf2;/*from   w  ww .j  a  v a  2  s  .  c o  m*/
    float midwayPoint = 0.2f;
    int duration = 500;

    kf0 = Keyframe.ofFloat(0f, 1);
    kf1 = Keyframe.ofFloat(midwayPoint, midRadiusMultiplier);
    kf2 = Keyframe.ofFloat(1f, endRadiusMultiplier);
    PropertyValuesHolder radiusDisappear = PropertyValuesHolder.ofKeyframe(radiusPropertyName, kf0, kf1, kf2);

    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(target, radiusDisappear)
            .setDuration(duration);
    animator.addUpdateListener(updateListener);
    return animator;
}

From source file:io.doist.datetimepicker.time.RadialTimePickerView.java

private static ObjectAnimator getRadiusReappearAnimator(Object target, String radiusPropertyName,
        InvalidateUpdateListener updateListener, float midRadiusMultiplier, float endRadiusMultiplier) {
    Keyframe kf0, kf1, kf2, kf3;/*from  w  w w .java  2s. c o m*/
    float midwayPoint = 0.2f;
    int duration = 500;

    // Set up animator for reappearing.
    float delayMultiplier = 0.25f;
    float transitionDurationMultiplier = 1f;
    float totalDurationMultiplier = transitionDurationMultiplier + delayMultiplier;
    int totalDuration = (int) (duration * totalDurationMultiplier);
    float delayPoint = (delayMultiplier * duration) / totalDuration;
    midwayPoint = 1 - (midwayPoint * (1 - delayPoint));

    kf0 = Keyframe.ofFloat(0f, endRadiusMultiplier);
    kf1 = Keyframe.ofFloat(delayPoint, endRadiusMultiplier);
    kf2 = Keyframe.ofFloat(midwayPoint, midRadiusMultiplier);
    kf3 = Keyframe.ofFloat(1f, 1);
    PropertyValuesHolder radiusReappear = PropertyValuesHolder.ofKeyframe(radiusPropertyName, kf0, kf1, kf2,
            kf3);

    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(target, radiusReappear)
            .setDuration(totalDuration);
    animator.addUpdateListener(updateListener);
    return animator;
}