Example usage for android.view.animation AnimationSet addAnimation

List of usage examples for android.view.animation AnimationSet addAnimation

Introduction

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

Prototype

public void addAnimation(Animation a) 

Source Link

Document

Add a child animation to this animation set.

Usage

From source file:Main.java

private static void ApplyHorizontalScrollAnimation(View view, boolean left, int speed) {
    float sign = left ? 1f : -1f;
    AnimationSet animationSet = new AnimationSet(true);
    animationSet.setRepeatCount(Animation.INFINITE);
    animationSet.setRepeatMode(Animation.RESTART);

    TranslateAnimation move = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, sign * 0.70f,
            Animation.RELATIVE_TO_PARENT, sign * -0.70f, Animation.RELATIVE_TO_PARENT, 0,
            Animation.RELATIVE_TO_PARENT, 0);
    move.setStartOffset(0);//from  www  . j a  v  a 2 s  .co  m
    move.setDuration(speed);
    move.setFillAfter(true);
    animationSet.addAnimation(move);
    view.startAnimation(animationSet);
}

From source file:org.videolan.vlc.gui.helpers.UiTools.java

public static void fillAboutView(View v) {
    TextView link = (TextView) v.findViewById(R.id.main_link);
    link.setText(Html.fromHtml(VLCApplication.getAppResources().getString(R.string.about_link)));

    String revision = VLCApplication.getAppResources().getString(R.string.build_revision) + " VLC: "
            + VLCApplication.getAppResources().getString(R.string.build_vlc_revision);
    String builddate = VLCApplication.getAppResources().getString(R.string.build_time);
    String builder = VLCApplication.getAppResources().getString(R.string.build_host);

    TextView compiled = (TextView) v.findViewById(R.id.main_compiled);
    compiled.setText(builder + " (" + builddate + ")");
    TextView textview_rev = (TextView) v.findViewById(R.id.main_revision);
    textview_rev.setText(VLCApplication.getAppResources().getString(R.string.revision) + " " + revision + " ("
            + builddate + ") " + BuildConfig.FLAVOR_abi);

    final ImageView logo = (ImageView) v.findViewById(R.id.logo);
    logo.setOnClickListener(new View.OnClickListener() {
        @Override//  w  w w  . j  a  v  a 2s.  com
        public void onClick(View v) {
            AnimationSet anim = new AnimationSet(true);
            RotateAnimation rotate = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            rotate.setDuration(800);
            rotate.setInterpolator(new DecelerateInterpolator());
            anim.addAnimation(rotate);
            logo.startAnimation(anim);
        }
    });
}

From source file:enterprayz.megatools.Tools.java

public static void replace(View source, int xTo, int yTo, float xScale, float yScale) {
    AnimationSet replaceAnimation = new AnimationSet(false);
    replaceAnimation.setFillAfter(true);

    ScaleAnimation scale = new ScaleAnimation(1.0f, xScale, 1.0f, yScale);
    scale.setDuration(1000);/* w  w w . j av  a2  s.  c  om*/

    TranslateAnimation trans = new TranslateAnimation(0, 0, TranslateAnimation.ABSOLUTE, xTo - source.getLeft(),
            0, 0, TranslateAnimation.ABSOLUTE, yTo - source.getTop());
    trans.setDuration(1000);

    replaceAnimation.addAnimation(scale);
    replaceAnimation.addAnimation(trans);

    source.startAnimation(replaceAnimation);
}

From source file:com.appassit.common.Utils.java

/**
 * ??// w w w.j av a 2  s  .  c o m
 * 
 * @return
 */
public static LayoutAnimationController getLayoutAnimation() {
    AnimationSet set = new AnimationSet(true);

    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(50);
    set.addAnimation(animation);

    animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
    animation.setDuration(100);
    set.addAnimation(animation);

    LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
    return controller;
}

From source file:com.example.testtab.fragment.GalleryPageFragment.java

public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
    this.mImageView.setImageResource(this.mThumbIds[position]);

    if (this.mThumbIds[position] != null) {
        AnimationSet set = new AnimationSet(true);

        AlphaAnimation alpha = new AlphaAnimation(0.0f, 1.0f);

        set.addAnimation(alpha);
        set.setDuration(500);/*from  www.  jav a2  s  .c  o m*/
        set.setFillAfter(true);

        this.mImageView.startAnimation(set);
    }

}

From source file:com.example.demo_highlights.slidingmenu.fragment.PageFragment1.java

private LayoutAnimationController getListAnim() {
    AnimationSet set = new AnimationSet(true);
    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(200);//from   w  w w .j a v  a2 s  .  com
    set.addAnimation(animation);

    animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
    animation.setDuration(200);
    set.addAnimation(animation);

    Animation inAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1.0f,
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            0.0f);
    inAnimation.setDuration(200);
    inAnimation.setFillAfter(true);
    set.addAnimation(inAnimation);

    Animation outAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            0.0f);
    outAnimation.setDuration(200);
    outAnimation.setFillAfter(true);
    // 
    LayoutAnimationController inController = new LayoutAnimationController(inAnimation, 0.3f);
    // 
    LayoutAnimationController outController = new LayoutAnimationController(outAnimation, 0.3f);

    LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
    return controller;
}

From source file:Main.java

@SuppressWarnings("IfCanBeSwitch")
private static Animation createAnimationFromXml(Context c, XmlPullParser parser, AnimationSet parent,
        AttributeSet attrs) throws XmlPullParserException, IOException {

    Animation anim = null;/*from ww  w .java  2 s.c o m*/

    // Make sure we are on a start tag.
    int type;
    int depth = parser.getDepth();

    while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
            && type != XmlPullParser.END_DOCUMENT) {

        if (type != XmlPullParser.START_TAG) {
            continue;
        }

        String name = parser.getName();

        if (name.equals("set")) {
            anim = new AnimationSet(c, attrs);
            createAnimationFromXml(c, parser, (AnimationSet) anim, attrs);
        } else if (name.equals("alpha")) {
            anim = new AlphaAnimation(c, attrs);
        } else if (name.equals("scale")) {
            anim = new ScaleAnimation(c, attrs);
        } else if (name.equals("rotate")) {
            anim = new RotateAnimation(c, attrs);
        } else if (name.equals("translate")) {
            anim = new TranslateAnimation(c, attrs);
        } else {
            throw new RuntimeException("Unknown animation name: " + parser.getName());
        }

        if (parent != null) {
            parent.addAnimation(anim);
        }
    }

    return anim;

}

From source file:eu.thedarken.rootvalidator.ValidatorFragment.java

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    AnimationSet set = new AnimationSet(true);
    Animation fadeIn = new AlphaAnimation(0.0f, 1.0f);
    fadeIn.setDuration(350);/*from  w  w w . j  a va2s. c o  m*/
    set.addAnimation(fadeIn);
    Animation dropDown = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF,
            0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f);
    dropDown.setDuration(400);
    set.addAnimation(dropDown);
    LayoutAnimationController controller = new LayoutAnimationController(set, 0.2f);
    mRecyclerView.setLayoutAnimation(controller);

    mFab.attachToRecyclerView(mRecyclerView);
    mFab.setVisibility(View.INVISIBLE);
    mEmptyStartView.setVisibility(View.GONE);
    mEmptyWorkingView.setVisibility(View.GONE);
    mListContainer.addView(mEmptyStartView);
    mListContainer.addView(mEmptyWorkingView);
    mRecyclerView.setEmptyView(mEmptyStartView);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
}

From source file:org.videolan.myvlc.core.gui.about.AboutMainFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.about_main, container, false);
    TextView link = (TextView) v.findViewById(R.id.main_link);
    link.setText(Html.fromHtml(this.getString(R.string.about_link)));

    String builddate = Util.readAsset("builddate.txt", "Unknown");
    String builder = Util.readAsset("builder.txt", "unknown");
    String revision = Util.readAsset("revision.txt", "unknown");

    TextView compiled = (TextView) v.findViewById(R.id.main_compiled);
    compiled.setText(builder + " (" + builddate + ")");
    TextView textview_rev = (TextView) v.findViewById(R.id.main_revision);
    textview_rev.setText(getResources().getString(R.string.revision) + " " + revision + " (" + builddate + ")");

    final ImageView logo = (ImageView) v.findViewById(R.id.logo);
    logo.setOnClickListener(new OnClickListener() {
        @Override/*  w w w.  ja v a 2 s  .c om*/
        public void onClick(View v) {
            AnimationSet anim = new AnimationSet(true);
            RotateAnimation rotate = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            rotate.setDuration(800);
            rotate.setInterpolator(new DecelerateInterpolator());
            anim.addAnimation(rotate);
            logo.startAnimation(anim);
        }
    });

    return v;
}

From source file:com.ycdyng.onemulti.MultiFragment.java

@Override
public Animation onCreateAnimation(final int transit, final boolean enter, final int nextAnim) {
    if (nextAnim == 0) {
        return null;
    }// ww  w .ja  v a2 s  .  co m
    //        if(enter) {
    //            if(nextAnim == StartAnimations[0]) {
    //                ViewCompat.setTranslationZ(getView(), 1.0f);
    //            } else {
    //                ViewCompat.setTranslationZ(getView(), 0.0f);
    //            }
    //        } else {
    //            if(nextAnim == BackAnimations[0]) {
    //                ViewCompat.setTranslationZ(getView(), 1.0f);
    //            } else {
    //                ViewCompat.setTranslationZ(getView(), 0.0f);
    //            }
    //        }
    Animation animation = AnimationUtils.loadAnimation(getActivity(), nextAnim);
    animation.setAnimationListener(new Animation.AnimationListener() {

        private int mLayerType;

        @Override
        public void onAnimationStart(Animation animation) {
            if (getView() != null) {
                mLayerType = getView().getLayerType();
                getView().setLayerType(View.LAYER_TYPE_HARDWARE, null);
            }
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            //                if(getView() != null) {
            //                    getView().setLayerType(mLayerType, null);
            //                    getView().post(new Runnable() {
            //                        @Override
            //                        public void run() {
            //                            if(getView() != null) {
            //                                ViewCompat.setTranslationZ(getView(), 0.0f);
            //                            }
            //                        }
            //                    });
            //                }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    // NOTE: the animation must be added to an animation set in order for the listener
    // to work on the exit animation
    AnimationSet animSet = new AnimationSet(true);
    animSet.addAnimation(animation);
    return animSet;
}