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:com.wenwen.chatuidemo.activity.NewFragment.java

@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
    AnimationSet _AnimationSet = new AnimationSet(true);
    TranslateAnimation _TranslateAnimation;
    if (checkedId == R.id.btn1) {
        _TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft,
                getResources().getDimension(R.dimen.rdo1), 0f, 0f);
        _AnimationSet.addAnimation(_TranslateAnimation);
        _AnimationSet.setFillBefore(false);
        _AnimationSet.setFillAfter(true);
        _AnimationSet.setDuration(100);/*from w w w  . ja  v a2 s  .co m*/
        mImageView.startAnimation(_AnimationSet);
        mViewPager.setCurrentItem(1);
        mRadioButton1.setTextColor(Color.RED);

    } else if (checkedId == R.id.btn2) {
        _TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft,
                getResources().getDimension(R.dimen.rdo2), 0f, 0f);
        _AnimationSet.addAnimation(_TranslateAnimation);
        _AnimationSet.setFillBefore(false);
        _AnimationSet.setFillAfter(true);
        _AnimationSet.setDuration(100);
        mImageView.startAnimation(_AnimationSet);
        mViewPager.setCurrentItem(2);
    } else if (checkedId == R.id.btn3) {
        _TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft,
                getResources().getDimension(R.dimen.rdo3), 0f, 0f);
        _AnimationSet.addAnimation(_TranslateAnimation);
        _AnimationSet.setFillBefore(false);
        _AnimationSet.setFillAfter(true);
        _AnimationSet.setDuration(100);
        mImageView.startAnimation(_AnimationSet);
        mViewPager.setCurrentItem(3);
    } else if (checkedId == R.id.btn4) {
        _TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft,
                getResources().getDimension(R.dimen.rdo4), 0f, 0f);
        _AnimationSet.addAnimation(_TranslateAnimation);
        _AnimationSet.setFillBefore(false);
        _AnimationSet.setFillAfter(true);
        _AnimationSet.setDuration(100);
        mImageView.startAnimation(_AnimationSet);
        mViewPager.setCurrentItem(4);
    }
    mCurrentCheckedRadioLeft = getCurrentCheckedRadioLeft();
    DebugLog.i("zj", "getCurrentCheckedRadioLeft=" + getCurrentCheckedRadioLeft());
    DebugLog.i("zj", "getDimension=" + getResources().getDimension(R.dimen.rdo2));
    mHorizontalScrollView.smoothScrollTo(
            (int) mCurrentCheckedRadioLeft - (int) getResources().getDimension(R.dimen.rdo2), 0);
}

From source file:de.dmxcontrol.activity.ControlActivity.java

private Dialog createSplashDialog() {
    Dialog dialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar);
    dialog.setContentView(R.layout.dialog_splash);
    ImageView image = (ImageView) dialog.findViewById(R.id.image_splash);
    image.setImageResource(R.drawable.image_splash);

    AnimationSet set = new AnimationSet(true);
    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(500);/*  w  w  w.ja va2  s  .  co m*/
    animation.setInterpolator(
            AnimationUtils.loadInterpolator(this, android.R.anim.accelerate_decelerate_interpolator));
    set.addAnimation(animation);
    animation = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f,
            Animation.RELATIVE_TO_SELF, 0.5f);
    animation.setDuration(1000);
    animation.setInterpolator(
            AnimationUtils.loadInterpolator(this, android.R.anim.accelerate_decelerate_interpolator));
    set.addAnimation(animation);

    image.setAnimation(set);
    dismissSplashDelayed();
    return dialog;
}

From source file:com.sociablue.nanodegree_p1.MovieListFragment.java

private void initializeFab(View rootView) {
    final RelativeLayout buttonContainer = (RelativeLayout) rootView.findViewById(R.id.menu_button_container);
    final FloatingActionButton Fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
    final ImageView bottomBar = (ImageView) rootView.findViewById(R.id.menu_bottom_bar);
    final ImageView topBar = (ImageView) rootView.findViewById(R.id.menu_top_bar);
    Fab.setOnClickListener(new View.OnClickListener() {
        @TargetApi(Build.VERSION_CODES.LOLLIPOP)
        @Override//from   ww w .  j  av a2s . co  m
        public void onClick(View v) {

            //Menu Button Icon Animation
            //Setting up necessary variables
            long animationDuration = 500;
            float containerHeight = buttonContainer.getHeight();
            float containerCenterY = containerHeight / 2;
            float containerCenterX = buttonContainer.getWidth() / 2;
            float topBarCenter = topBar.getTop() + topBar.getHeight() / 2;
            float widthOfBar = topBar.getWidth();
            float heightOfBar = topBar.getHeight();
            final float distanceBetweenBars = (containerCenterY - topBarCenter);

            /**
             *TODO: Refactor block of code to use Value Property Animator. Should be more efficient to animate multiple properties
             *and objects at the same time. Also, will try to break intialization into smaller functions.
             */

            //Setting up animations of hamburger bars and rotation

            /**
             * Animation For Top Menu Button Icon Bar. Sliding from the top to rest on top of the middle bar.
             * Y Translation is 1/2 the height of the hamburger bar minus the distance.
             * Subtracting the distance from the height because the distance between bars is
             * calculated of the exact center of the button.
             * With out the subtraction the bar would translate slightly below the middle bar.
             */
            float yTranslation = heightOfBar / 2 - distanceBetweenBars;
            float xTranslation = widthOfBar / 2 + heightOfBar / 2;
            TranslateAnimation topBarTranslationAnim = new TranslateAnimation(Animation.ABSOLUTE, 0f,
                    Animation.ABSOLUTE, 0F, Animation.ABSOLUTE, 0f, Animation.ABSOLUTE, distanceBetweenBars);
            topBarTranslationAnim.setDuration((long) (animationDuration * 0.8));
            topBarTranslationAnim.setFillAfter(true);

            //Animation for bottom hamburger bar. Translates and Rotates to create 'X'
            AnimationSet bottomBarAnimation = new AnimationSet(true);
            bottomBarAnimation.setFillAfter(true);

            //Rotate to create cross. (The cross becomes the X after the button rotation completes"
            RotateAnimation bottomBarRotationAnimation = new RotateAnimation(0f, 90f,
                    Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 1f);
            bottomBarRotationAnimation.setDuration(animationDuration);
            bottomBarAnimation.addAnimation(bottomBarRotationAnimation);

            //Translate to correct X alignment
            TranslateAnimation bottomBarTranslationAnimation = new TranslateAnimation(Animation.ABSOLUTE, 0f,
                    Animation.ABSOLUTE, -xTranslation, Animation.ABSOLUTE, 0f, Animation.ABSOLUTE,
                    -yTranslation);
            bottomBarTranslationAnimation.setDuration(animationDuration);
            bottomBarAnimation.addAnimation(bottomBarTranslationAnimation);

            //Button Specific Animations
            //Rotate Button Container
            RotateAnimation containerRotationAnimation = new RotateAnimation(0, 135f,
                    Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
            containerRotationAnimation.setDuration(animationDuration);
            containerRotationAnimation.setFillAfter(true);

            //Animate change of button color between Active and Disabled colors that have been
            //defined in color.xml
            int activeColor = getResources().getColor(R.color.active_button);
            int disabledColor = getResources().getColor(R.color.disabled_button);

            //Need to use ValueAnimator because property animator does not support BackgroundTint
            ValueAnimator buttonColorAnimation = ValueAnimator.ofArgb(activeColor, disabledColor);
            buttonColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    Fab.setBackgroundTintList(ColorStateList.valueOf((int) animation.getAnimatedValue()));
                }
            });
            buttonColorAnimation.setDuration(animationDuration);

            //Start all the animations
            topBar.startAnimation(topBarTranslationAnim);
            bottomBar.startAnimation(bottomBarAnimation);
            buttonContainer.startAnimation(containerRotationAnimation);
            buttonColorAnimation.start();

            //Toogle mMenu open and closed
            if (mMenu.isOpen()) {
                //If mMenu is open, do the reverse of the animation
                containerRotationAnimation
                        .setInterpolator(new ReverseInterpolator(new AccelerateInterpolator()));
                topBarTranslationAnim.setInterpolator(new ReverseInterpolator(new AccelerateInterpolator()));
                bottomBarAnimation.setInterpolator(new ReverseInterpolator(new AccelerateInterpolator()));
                buttonColorAnimation.setInterpolator(new ReverseInterpolator(new LinearInterpolator()));
                mMenu.close();
            } else {
                bottomBarAnimation.setInterpolator(new AccelerateInterpolator());
                mMenu.open();
            }
        }
    });
}

From source file:com.sonvp.tooltip.Tooltip.java

/**
 * Removes the tool tip view from the view hierarchy.
 *///from   w  w  w .j a  v a2 s .c om
@UiThread
public void remove() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        container.setPivotX(pivotX);
        container.setPivotY(pivotY);
        container.animate().setDuration(ANIMATION_DURATION).alpha(0.0F).scaleX(0.0F).scaleY(0.0F)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        popupWindow.dismiss();

                    }
                });
    } else {
        AnimationSet animationSet = new AnimationSet(true);
        animationSet.setDuration(ANIMATION_DURATION);
        animationSet.addAnimation(new AlphaAnimation(1.0F, 0.0F));
        animationSet.addAnimation(new ScaleAnimation(1.0F, 0.0F, 1.0F, 0.0F, pivotX, pivotY));
        animationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                // do nothing
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                popupWindow.dismiss();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                // do nothing
            }
        });
        container.startAnimation(animationSet);
    }
}

From source file:com.example.fragment.PrimitiveFragment.java

public void testAnimation(float destX, float destY) {
    this.mDestX = Factory.getAdjustedX(destX);
    this.mDestY = Factory.getAdjustedY(destY);
    // SELECT LAYER
    FrameLayout relate = (FrameLayout) mRootView.findViewById(R.id.FLBackLayer);
    //       ScrollView relate = (ScrollView)mRootView.findViewById(R.id.content);
    //       relate.setVisibility(View.VISIBLE);

    AnimationSet set = new AnimationSet(true);
    set.setAnimationListener(this);

    TranslateAnimation translate;/*from  w  w  w  . j a  v  a2s.  co  m*/
    float toX = this.mDestX;
    float fromX = this.mSrcX;
    float toY = this.mDestY;
    float fromY = this.mSrcY;
    translate = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, fromX, Animation.RELATIVE_TO_PARENT, toX,
            Animation.RELATIVE_TO_PARENT, fromY, Animation.RELATIVE_TO_PARENT, toY);
    translate.setDuration(Constants.Animation.IPF_START);
    translate.setInterpolator(new AccelerateInterpolator());

    set.addAnimation(translate);
    set.setFillBefore(true);
    //          set.setFillBefore(false);
    //         set.setFillAfter(false);
    set.setFillAfter(true);

    relate.startAnimation(set);
}

From source file:com.example.fragment.PrimitiveFragment.java

public void move(float destX, float destY) {
    if (!this.mIsAlive)
        return;/*from w  w  w  . j a  va2s  .co  m*/
    if (this.mIsMoving) {
        return;// ADD Array
    }
    this.mDestX = Factory.getAdjustedX(destX - this.mPaddingW);
    this.mDestY = Factory.getAdjustedY(destY - this.mPaddingH);
    // SELECT LAYER 
    FrameLayout relate = (FrameLayout) mRootView.findViewById(R.id.FLBackLayer);
    //       ScrollView relate = (ScrollView)mRootView.findViewById(R.id.content);
    //       relate.setVisibility(View.VISIBLE);

    AnimationSet set = new AnimationSet(true);
    set.setAnimationListener(this);

    TranslateAnimation translate;
    float toX = this.mDestX;
    float fromX = this.mSrcX;
    float toY = this.mDestY;
    float fromY = this.mSrcY;
    translate = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, fromX, Animation.RELATIVE_TO_PARENT, toX,
            Animation.RELATIVE_TO_PARENT, fromY, Animation.RELATIVE_TO_PARENT, toY);
    translate.setDuration(Constants.Animation.IPF);
    translate.setInterpolator(new AccelerateInterpolator());

    set.addAnimation(translate);
    set.setFillBefore(true);
    //          set.setFillBefore(false);
    //         set.setFillAfter(false);
    set.setFillAfter(true);

    relate.startAnimation(set);
    this.mIsMoving = true;
    this.mIsMove = true;
}

From source file:com.watasan.infospider.fragment.PrimitiveFragment.java

/** SCRIPT ACTION AREA --------------------------------------------------> */

public void testAnimation(float destX, float destY) {
    this.mDestX = Factory.getAdjustedX(destX);
    this.mDestY = Factory.getAdjustedY(destY);
    // SELECT LAYER
    FrameLayout relate = (FrameLayout) mRootView.findViewById(R.id.FLBackLayer);
    //       ScrollView relate = (ScrollView)mRootView.findViewById(R.id.content);
    //       relate.setVisibility(View.VISIBLE);

    AnimationSet set = new AnimationSet(true);
    set.setAnimationListener(this);

    TranslateAnimation translate;/*w  w  w  .  j  av a2 s.co m*/
    float toX = this.mDestX;
    float fromX = this.mSrcX;
    float toY = this.mDestY;
    float fromY = this.mSrcY;
    translate = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, fromX, Animation.RELATIVE_TO_PARENT, toX,
            Animation.RELATIVE_TO_PARENT, fromY, Animation.RELATIVE_TO_PARENT, toY);
    translate.setDuration(Constants.Animation.IPF_START);
    translate.setInterpolator(new AccelerateInterpolator());

    set.addAnimation(translate);
    set.setFillBefore(true);
    //          set.setFillBefore(false);
    //         set.setFillAfter(false);
    set.setFillAfter(true);

    relate.startAnimation(set);
}

From source file:com.sonvp.tooltip.Tooltip.java

@Override
public boolean onPreDraw() {
    container.getViewTreeObserver().removeOnPreDrawListener(this);

    Context context = container.getContext();
    if (!(context instanceof Activity)) {
        return false;
    }//  www .j ava  2  s  .co  m
    DisplayMetrics displayMetrics = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    int displayWidth = displayMetrics.widthPixels;
    int displayHeight = displayMetrics.heightPixels;
    int displayTop = getStatusBarHeight();

    int anchorTop = rectAnchorView.top;
    int anchorLeft = rectAnchorView.left;
    int anchorWidth = anchorView.getWidth();
    int anchorHeight = anchorView.getHeight();

    int textWidth = viewTooltip.getWidth();
    //default height 1 line
    int textHeight = viewTooltip.getHeight();
    int arrowWidth = arrow.getWidth();
    int arrowHeight = arrow.getHeight();

    int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(displayWidth, View.MeasureSpec.AT_MOST);
    int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);

    if (gravity == Gravity.TOP || gravity == Gravity.BOTTOM) {
        int width = Math.max(textWidth, arrowWidth);
        int height = textHeight + arrowHeight;

        int leftPadding;
        int topPadding;

        if (gravity == Gravity.TOP) {
            topPadding = anchorTop - height;
        } else {
            // gravity == Gravity.BOTTOM
            topPadding = anchorTop + anchorHeight;
        }

        int anchorHorizontalCenter = anchorLeft + anchorWidth / 2;
        int left = anchorHorizontalCenter - width / 2;
        int right = left + width;
        leftPadding = Math.max(0, right > displayWidth ? displayWidth - width : left);

        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) arrow.getLayoutParams();
        layoutParams.leftMargin = anchorHorizontalCenter - leftPadding - arrowWidth / 2;
        arrow.setLayoutParams(layoutParams);
        popupWindow.update(leftPadding, topPadding, container.getWidth(), container.getHeight());

        pivotX = width / 2;
        pivotY = gravity == Gravity.TOP ? height : 0;
    } else {
        // gravity == Gravity.LEFT || gravity == Gravity.RIGHT

        int width = textWidth + arrowWidth;

        int leftPadding;
        int topPadding;
        int rightPadding = 0;

        if (gravity == Gravity.LEFT) {
            leftPadding = Math.max(0, anchorLeft - width);
            leftPadding += (int) builder.toolTipMargin;
            rightPadding = displayWidth - anchorLeft;
        } else {
            // gravity == Gravity.RIGHT
            leftPadding = anchorLeft + anchorWidth;
            rightPadding = (int) builder.toolTipMargin;
        }

        if (viewTooltip instanceof TextView) {
            TextView text = (TextView) viewTooltip;
            text.setMaxWidth(displayWidth - rightPadding - leftPadding - arrowWidth);
            viewTooltip.measure(widthMeasureSpec, heightMeasureSpec);
            textHeight = viewTooltip.getMeasuredHeight(); // height multi line
        }

        int height = Math.max(textHeight, arrowHeight);

        int anchorVerticalCenter = anchorTop + anchorHeight / 2;
        int top = anchorVerticalCenter - height / 2;
        int bottom = top + height;

        if (builder.arrowGravity == Gravity.TOP) {
            top = anchorTop;
            bottom = anchorTop + height;
        } else if (builder.arrowGravity == Gravity.BOTTOM) {
            top = anchorTop + anchorHeight - height;
        }

        topPadding = Math.max(0,
                bottom > displayHeight ? displayHeight - height - (int) builder.toolTipMargin : top);
        topPadding = Math.max(0,
                topPadding < displayTop ? displayTop + (int) builder.toolTipMargin : topPadding);

        container.measure(widthMeasureSpec, heightMeasureSpec);
        int popupWidth = container.getMeasuredWidth();
        int popupHeight = container.getMeasuredHeight();
        popupWindow.update(leftPadding, topPadding, popupWidth, popupHeight);

        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) arrow.getLayoutParams();
        layoutParams.topMargin = anchorVerticalCenter - topPadding - arrowHeight / 2;
        arrow.setLayoutParams(layoutParams);

        pivotX = gravity == Gravity.LEFT ? popupWidth : 0;
        pivotY = anchorVerticalCenter - topPadding;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        container.setAlpha(0.0F);
        container.setPivotX(pivotX);
        container.setPivotY(pivotY);
        container.setScaleX(0.0F);
        container.setScaleY(0.0F);
        container.animate().setDuration(ANIMATION_DURATION).scaleX(1.0F).scaleY(1.0F).alpha(1.0F);
    } else {
        AnimationSet animationSet = new AnimationSet(true);
        animationSet.setDuration(ANIMATION_DURATION);
        animationSet.addAnimation(new AlphaAnimation(0.0F, 1.0F));
        animationSet.addAnimation(new ScaleAnimation(0.0F, 1.0F, 0.0F, 1.0F, pivotX, pivotY));
        container.startAnimation(animationSet);
    }

    return false;
}

From source file:com.chuhan.privatecalc.fragment.os.FragmentManager.java

static Animation makeOpenCloseAnimation(Context context, float startScale, float endScale, float startAlpha,
        float endAlpha) {
    AnimationSet set = new AnimationSet(false);
    ScaleAnimation scale = new ScaleAnimation(startScale, endScale, startScale, endScale,
            Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f);
    scale.setInterpolator(DECELERATE_QUINT);
    scale.setDuration(ANIM_DUR);/*from ww w. j av  a2s .  c  o m*/
    set.addAnimation(scale);
    AlphaAnimation alpha = new AlphaAnimation(startAlpha, endAlpha);
    alpha.setInterpolator(DECELERATE_CUBIC);
    alpha.setDuration(ANIM_DUR);
    set.addAnimation(alpha);
    return set;
}

From source file:android.support.v7.app.MediaRouteControllerDialog.java

void clearGroupListAnimation(boolean exceptAddedRoutes) {
    int first = mVolumeGroupList.getFirstVisiblePosition();
    for (int i = 0; i < mVolumeGroupList.getChildCount(); ++i) {
        View view = mVolumeGroupList.getChildAt(i);
        int position = first + i;
        MediaRouter.RouteInfo route = mVolumeGroupAdapter.getItem(position);
        if (exceptAddedRoutes && mGroupMemberRoutesAdded != null && mGroupMemberRoutesAdded.contains(route)) {
            continue;
        }//from  w  w  w.  j av a 2s. c  om
        LinearLayout container = (LinearLayout) view.findViewById(R.id.volume_item_container);
        container.setVisibility(View.VISIBLE);
        AnimationSet animSet = new AnimationSet(true);
        Animation alphaAnim = new AlphaAnimation(1.0f, 1.0f);
        alphaAnim.setDuration(0);
        animSet.addAnimation(alphaAnim);
        Animation translationAnim = new TranslateAnimation(0, 0, 0, 0);
        translationAnim.setDuration(0);
        animSet.setFillAfter(true);
        animSet.setFillEnabled(true);
        view.clearAnimation();
        view.startAnimation(animSet);
    }
    mVolumeGroupList.stopAnimationAll();
    if (!exceptAddedRoutes) {
        finishAnimation(false);
    }
}