Example usage for android.view.animation TranslateAnimation TranslateAnimation

List of usage examples for android.view.animation TranslateAnimation TranslateAnimation

Introduction

In this page you can find the example usage for android.view.animation TranslateAnimation TranslateAnimation.

Prototype

public TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType,
        float fromYValue, int toYType, float toYValue) 

Source Link

Document

Constructor to use when building a TranslateAnimation from code

Usage

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

private View switchViews(boolean forward, float xOffSet, float width, float velocity) {
    mAnimationDistance = width - xOffSet;

    float progress = Math.abs(xOffSet) / width;
    if (progress > 1.0f) {
        progress = 1.0f;// ww  w  . j  av  a  2s  . c  o m
    }

    float inFromXValue, inToXValue;
    float outFromXValue, outToXValue;
    if (forward) {
        inFromXValue = 1.0f - progress;
        inToXValue = 0.0f;
        outFromXValue = -progress;
        outToXValue = -1.0f;
    } else {
        inFromXValue = progress - 1.0f;
        inToXValue = 0.0f;
        outFromXValue = progress;
        outToXValue = 1.0f;
    }

    final Time start = new Time(mBaseDate.timezone);
    start.set(mController.getTime());
    if (forward) {
        start.monthDay += mNumDays;
    } else {
        start.monthDay -= mNumDays;
    }
    mController.setTime(start.normalize(true));

    Time newSelected = start;

    if (mNumDays == 7) {
        newSelected = new Time(start);
        adjustToBeginningOfWeek(start);
    }

    final Time end = new Time(start);
    end.monthDay += mNumDays - 1;

    // We have to allocate these animation objects each time we switch views
    // because that is the only way to set the animation parameters.
    TranslateAnimation inAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, inFromXValue,
            Animation.RELATIVE_TO_SELF, inToXValue, Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, 0.0f);

    TranslateAnimation outAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, outFromXValue,
            Animation.RELATIVE_TO_SELF, outToXValue, Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, 0.0f);

    long duration = calculateDuration(width - Math.abs(xOffSet), width, velocity);
    inAnimation.setDuration(duration);
    inAnimation.setInterpolator(mHScrollInterpolator);
    outAnimation.setInterpolator(mHScrollInterpolator);
    outAnimation.setDuration(duration);
    outAnimation.setAnimationListener(new GotoBroadcaster(start, end));

    mViewSwitcher.setInAnimation(inAnimation);
    mViewSwitcher.setOutAnimation(outAnimation);

    DayView view = (DayView) mViewSwitcher.getCurrentView();
    view.cleanup();
    mViewSwitcher.showNext();
    view = (DayView) mViewSwitcher.getCurrentView();
    view.setSelected(newSelected, true, false);
    view.requestFocus();
    view.reloadEvents();
    view.updateTitle();
    view.restartCurrentTimeUpdates();

    return view;
}

From source file:org.anurag.file.quest.TaskerActivity.java

/**
 * Creates the animation set for next ViewFlippers when loaded.
 * @return a customized animation for mViewFlippers
 *///from   w  ww .j a  va2 s.com
private static Animation nextAnim() {
    Animation anim = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, +1.0f, Animation.RELATIVE_TO_PARENT,
            0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
    anim.setDuration(100);
    anim.setInterpolator(new AccelerateInterpolator());
    return anim;
}

From source file:org.anurag.file.quest.TaskerActivity.java

/**
 * Creates the animation set for previous ViewFlippers when loaded.
 * @return a customized animation for mViewFlippers
 *//*  ww w .j a v a 2  s . com*/
private static Animation prevAnim() {
    Animation anim = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, -1.0f, Animation.RELATIVE_TO_PARENT,
            0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
    anim.setDuration(100);
    anim.setInterpolator(new AccelerateInterpolator());
    return anim;
}