Search in sources :

Example 1 with Keyframe

use of android.animation.Keyframe in project android_packages_apps_OmniClock by omnirom.

the class RadialTextsView method renderAnimations.

/**
 * Render the animations for appearing and disappearing.
 */
private void renderAnimations() {
    Keyframe kf0, kf1, kf2, kf3;
    float midwayPoint = 0.2f;
    int duration = 500;
    // Set up animator for disappearing.
    kf0 = Keyframe.ofFloat(0f, 1);
    kf1 = Keyframe.ofFloat(midwayPoint, mTransitionMidRadiusMultiplier);
    kf2 = Keyframe.ofFloat(1f, mTransitionEndRadiusMultiplier);
    PropertyValuesHolder radiusDisappear = PropertyValuesHolder.ofKeyframe("animationRadiusMultiplier", kf0, kf1, kf2);
    kf0 = Keyframe.ofFloat(0f, 1f);
    kf1 = Keyframe.ofFloat(1f, 0f);
    PropertyValuesHolder fadeOut = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1);
    mDisappearAnimator = ObjectAnimator.ofPropertyValuesHolder(this, radiusDisappear, fadeOut).setDuration(duration);
    mDisappearAnimator.addUpdateListener(mInvalidateUpdateListener);
    // 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, mTransitionEndRadiusMultiplier);
    kf1 = Keyframe.ofFloat(delayPoint, mTransitionEndRadiusMultiplier);
    kf2 = Keyframe.ofFloat(midwayPoint, mTransitionMidRadiusMultiplier);
    kf3 = Keyframe.ofFloat(1f, 1);
    PropertyValuesHolder radiusReappear = PropertyValuesHolder.ofKeyframe("animationRadiusMultiplier", kf0, kf1, kf2, kf3);
    kf0 = Keyframe.ofFloat(0f, 0f);
    kf1 = Keyframe.ofFloat(delayPoint, 0f);
    kf2 = Keyframe.ofFloat(1f, 1f);
    PropertyValuesHolder fadeIn = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1, kf2);
    mReappearAnimator = ObjectAnimator.ofPropertyValuesHolder(this, radiusReappear, fadeIn).setDuration(totalDuration);
    mReappearAnimator.addUpdateListener(mInvalidateUpdateListener);
}
Also used : Keyframe(android.animation.Keyframe) PropertyValuesHolder(android.animation.PropertyValuesHolder) Paint(android.graphics.Paint)

Example 2 with Keyframe

use of android.animation.Keyframe in project android_packages_apps_OmniClock by omnirom.

the class Utils method getPulseAnimator.

/**
 * Takes a number of weeks since the epoch and calculates the Julian day of
 * the Monday for that week.
 *
 * This assumes that the week containing the {@link Time#EPOCH_JULIAN_DAY}
 * is considered week 0. It returns the Julian day for the Monday
 * {@code week} weeks after the Monday of the week containing the epoch.
 *
 * @param week Number of weeks since the epoch
 * @return The julian day for the Monday of the given week since the epoch
 */
/**
 *    public static int getJulianMondayFromWeeksSinceEpoch(int week) {
 *        return MONDAY_BEFORE_JULIAN_EPOCH + week * 7;
 *    }
 */
/**
 * Returns the week since {@link Time#EPOCH_JULIAN_DAY} (Jan 1, 1970)
 * adjusted for first day of week.
 *
 * This takes a julian day and the week start day and calculates which
 * week since {@link Time#EPOCH_JULIAN_DAY} that day occurs in, starting
 * at 0. *Do not* use this to compute the ISO week number for the year.
 *
 * @param julianDay The julian day to calculate the week number for
 * @param firstDayOfWeek Which week day is the first day of the week,
 *          see {@link Time#SUNDAY}
 * @return Weeks since the epoch
 */
/**
 *    public static int getWeeksSinceEpochFromJulianDay(int julianDay, int firstDayOfWeek) {
 *        int diff = Time.THURSDAY - firstDayOfWeek;
 *        if (diff < 0) {
 *            diff += 7;
 *        }
 *        int refDay = Time.EPOCH_JULIAN_DAY - diff;
 *        return (julianDay - refDay) / 7;
 *    }
 */
/**
 * Render an animator to pulsate a view in place.
 * @param labelToAnimate the view to pulsate.
 * @return The animator object. Use .start() to begin.
 */
public static ObjectAnimator getPulseAnimator(View labelToAnimate, float decreaseRatio, float increaseRatio) {
    Keyframe k0 = Keyframe.ofFloat(0f, 1f);
    Keyframe k1 = Keyframe.ofFloat(0.275f, decreaseRatio);
    Keyframe k2 = Keyframe.ofFloat(0.69f, increaseRatio);
    Keyframe k3 = Keyframe.ofFloat(1f, 1f);
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofKeyframe("scaleX", k0, k1, k2, k3);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofKeyframe("scaleY", k0, k1, k2, k3);
    ObjectAnimator pulseAnimator = ObjectAnimator.ofPropertyValuesHolder(labelToAnimate, scaleX, scaleY);
    pulseAnimator.setDuration(PULSE_ANIMATOR_DURATION);
    return pulseAnimator;
}
Also used : Keyframe(android.animation.Keyframe) ObjectAnimator(android.animation.ObjectAnimator) PropertyValuesHolder(android.animation.PropertyValuesHolder)

Example 3 with Keyframe

use of android.animation.Keyframe in project weiui by kuaifan.

the class SpriteAnimatorBuilder method build.

public ObjectAnimator build() {
    PropertyValuesHolder[] holders = new PropertyValuesHolder[fds.size()];
    int i = 0;
    for (Map.Entry<String, FrameData> fd : fds.entrySet()) {
        FrameData data = fd.getValue();
        Keyframe[] keyframes = new Keyframe[data.fractions.length];
        float[] fractions = data.fractions;
        float startF = fractions[startFrame];
        for (int j = startFrame; j < (startFrame + data.values.length); j++) {
            int key = j - startFrame;
            int vk = j % data.values.length;
            float fraction = fractions[vk] - startF;
            if (fraction < 0) {
                fraction = fractions[fractions.length - 1] + fraction;
            }
            if (data instanceof IntFrameData) {
                keyframes[key] = Keyframe.ofInt(fraction, (Integer) data.values[vk]);
            } else if (data instanceof FloatFrameData) {
                keyframes[key] = Keyframe.ofFloat(fraction, (Float) data.values[vk]);
            } else {
                keyframes[key] = Keyframe.ofObject(fraction, data.values[vk]);
            }
        }
        holders[i] = PropertyValuesHolder.ofKeyframe(data.property, keyframes);
        i++;
    }
    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(sprite, holders);
    animator.setDuration(duration);
    animator.setRepeatCount(repeatCount);
    animator.setInterpolator(interpolator);
    return animator;
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Keyframe(android.animation.Keyframe) PropertyValuesHolder(android.animation.PropertyValuesHolder) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with Keyframe

use of android.animation.Keyframe in project SublimePicker by vikramkakkar.

the class RadialTimePickerView method getFadeInAnimator.

private static ObjectAnimator getFadeInAnimator(IntHolder target, int startAlpha, int endAlpha, InvalidateUpdateListener updateListener) {
    final float delayMultiplier = 0.25f;
    final float transitionDurationMultiplier = 1f;
    final float totalDurationMultiplier = transitionDurationMultiplier + delayMultiplier;
    final int totalDuration = (int) (FADE_IN_DURATION * totalDurationMultiplier);
    final float delayPoint = (delayMultiplier * FADE_IN_DURATION) / totalDuration;
    final Keyframe kf0, kf1, kf2;
    kf0 = Keyframe.ofInt(0f, startAlpha);
    kf1 = Keyframe.ofInt(delayPoint, startAlpha);
    kf2 = Keyframe.ofInt(1f, endAlpha);
    final PropertyValuesHolder fadeIn = PropertyValuesHolder.ofKeyframe("value", kf0, kf1, kf2);
    final ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(target, fadeIn);
    animator.setDuration(totalDuration);
    animator.addUpdateListener(updateListener);
    return animator;
}
Also used : Keyframe(android.animation.Keyframe) ObjectAnimator(android.animation.ObjectAnimator) PropertyValuesHolder(android.animation.PropertyValuesHolder) Paint(android.graphics.Paint)

Example 5 with Keyframe

use of android.animation.Keyframe in project MaterialDateTimePicker by wdullaer.

the class RadialTextsView method renderAnimations.

/**
 * Render the animations for appearing and disappearing.
 */
private void renderAnimations() {
    Keyframe kf0, kf1, kf2, kf3;
    float midwayPoint = 0.2f;
    int duration = 500;
    // Set up animator for disappearing.
    kf0 = Keyframe.ofFloat(0f, 1);
    kf1 = Keyframe.ofFloat(midwayPoint, mTransitionMidRadiusMultiplier);
    kf2 = Keyframe.ofFloat(1f, mTransitionEndRadiusMultiplier);
    PropertyValuesHolder radiusDisappear = PropertyValuesHolder.ofKeyframe("animationRadiusMultiplier", kf0, kf1, kf2);
    kf0 = Keyframe.ofFloat(0f, 1f);
    kf1 = Keyframe.ofFloat(1f, 0f);
    PropertyValuesHolder fadeOut = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1);
    mDisappearAnimator = ObjectAnimator.ofPropertyValuesHolder(this, radiusDisappear, fadeOut).setDuration(duration);
    mDisappearAnimator.addUpdateListener(mInvalidateUpdateListener);
    // 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, mTransitionEndRadiusMultiplier);
    kf1 = Keyframe.ofFloat(delayPoint, mTransitionEndRadiusMultiplier);
    kf2 = Keyframe.ofFloat(midwayPoint, mTransitionMidRadiusMultiplier);
    kf3 = Keyframe.ofFloat(1f, 1);
    PropertyValuesHolder radiusReappear = PropertyValuesHolder.ofKeyframe("animationRadiusMultiplier", kf0, kf1, kf2, kf3);
    kf0 = Keyframe.ofFloat(0f, 0f);
    kf1 = Keyframe.ofFloat(delayPoint, 0f);
    kf2 = Keyframe.ofFloat(1f, 1f);
    PropertyValuesHolder fadeIn = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1, kf2);
    mReappearAnimator = ObjectAnimator.ofPropertyValuesHolder(this, radiusReappear, fadeIn).setDuration(totalDuration);
    mReappearAnimator.addUpdateListener(mInvalidateUpdateListener);
}
Also used : Keyframe(android.animation.Keyframe) PropertyValuesHolder(android.animation.PropertyValuesHolder) Paint(android.graphics.Paint)

Aggregations

Keyframe (android.animation.Keyframe)17 PropertyValuesHolder (android.animation.PropertyValuesHolder)17 ObjectAnimator (android.animation.ObjectAnimator)12 Paint (android.graphics.Paint)10 HashMap (java.util.HashMap)2 Map (java.util.Map)2