Example usage for android.view.animation Animation Animation

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

Introduction

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

Prototype

public Animation() 

Source Link

Document

Creates a new animation with a duration of 0ms, the default interpolator, with fillBefore set to true and fillAfter set to false

Usage

From source file:com.ray.appchallenge.view.SwipeRefreshLayoutBottom.java

private void startScaleUpAnimation(final AnimationListener listener) {
    mCircleView.setVisibility(View.VISIBLE);
    if (android.os.Build.VERSION.SDK_INT >= 11) {

        // Pre API 11, alpha is used in place of scale up to show the
        // progress circle appearing.
        // Don't adjust the alpha during appearance otherwise.
        mProgress.setAlpha(MAX_ALPHA);/*from   www  .  j a v  a2  s  .com*/
    }

    mScaleAnimation = new Animation() {
        @Override
        public void applyTransformation(final float interpolatedTime, final Transformation t) {
            setAnimationProgress(interpolatedTime);
        }
    };
    mScaleAnimation.setDuration(mMediumAnimationDuration);
    if (listener != null) {
        mCircleView.setAnimationListener(listener);
    }

    mCircleView.clearAnimation();
    mCircleView.startAnimation(mScaleAnimation);
}

From source file:anabolicandroids.chanobol.util.swipebottom.SwipeRefreshLayoutBottom.java

private void startScaleUpAnimation(AnimationListener listener) {
    mCircleView.setVisibility(View.VISIBLE);
    if (android.os.Build.VERSION.SDK_INT >= 11) {
        // Pre API 11, alpha is used in place of scale up to show the
        // progress circle appearing.
        // Don't adjust the alpha during appearance otherwise.
        mProgress.setAlpha(MAX_ALPHA);//from   w w  w . ja va  2s  .  c  o m
    }
    mScaleAnimation = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            setAnimationProgress(interpolatedTime);
        }
    };
    mScaleAnimation.setDuration(mMediumAnimationDuration);
    if (listener != null) {
        mCircleView.setAnimationListener(listener);
    }
    mCircleView.clearAnimation();
    mCircleView.startAnimation(mScaleAnimation);
}

From source file:cw.kop.autobackground.sources.SourceListFragment.java

@Override
public void onClick(final View v) {

    switch (v.getId()) {

    case R.id.set_button:
        setWallpaper();/*from w w  w  . j  a  va 2s  .  c om*/
        break;
    case R.id.floating_button_icon:
        final GradientDrawable circleDrawable = (GradientDrawable) getResources()
                .getDrawable(R.drawable.floating_button_circle);
        final float scale = (float) ((Math.hypot(addButtonBackground.getX(), addButtonBackground.getY())
                + addButtonBackground.getWidth()) / addButtonBackground.getWidth() * 2);

        Animation animation = new Animation() {

            private boolean needsFragment = true;
            private float pivot;

            @Override
            public void initialize(int width, int height, int parentWidth, int parentHeight) {
                super.initialize(width, height, parentWidth, parentHeight);

                pivot = resolveSize(RELATIVE_TO_SELF, 0.5f, width, parentWidth);
            }

            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {

                if (needsFragment && interpolatedTime >= 1) {
                    needsFragment = false;
                    showSourceAddFragment();
                } else {
                    float scaleFactor = 1.0f + ((scale - 1.0f) * interpolatedTime);
                    t.getMatrix().setScale(scaleFactor, scaleFactor, pivot, pivot);
                }
            }

            @Override
            public boolean willChangeBounds() {
                return true;
            }

        };

        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                circleDrawable.setColor(getResources().getColor(R.color.ACCENT_OPAQUE));
                addButtonBackground.setImageDrawable(circleDrawable);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        if (needsButtonReset) {
                            addButton.setOnClickListener(SourceListFragment.this);
                            addButtonBackground.setScaleX(1.0f);
                            addButtonBackground.setScaleY(1.0f);
                            addButtonBackground.clearAnimation();
                            circleDrawable.setColor(getResources().getColor(R.color.ACCENT_OPAQUE));
                            addButtonBackground.setImageDrawable(circleDrawable);
                            addButton.setVisibility(View.VISIBLE);
                        }
                    }
                }, 100);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }

        });

        ValueAnimator buttonColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
                getResources().getColor(R.color.ACCENT_OPAQUE),
                getResources().getColor(AppSettings.getBackgroundColorResource()));
        buttonColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                circleDrawable.setColor((Integer) animation.getAnimatedValue());
                addButtonBackground.setImageDrawable(circleDrawable);
            }

        });

        DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator();

        animation.setDuration(ADD_ANIMATION_TIME);
        buttonColorAnimation.setDuration((long) (ADD_ANIMATION_TIME * 0.9));
        buttonColorAnimation.setInterpolator(decelerateInterpolator);
        animation.setInterpolator(decelerateInterpolator);

        // Post a delayed Runnable to ensure reset even if animation is interrupted
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (needsButtonReset) {
                    addButtonBackground.setScaleX(1.0f);
                    addButtonBackground.setScaleY(1.0f);
                    addButtonBackground.clearAnimation();
                    circleDrawable.setColor(getResources().getColor(R.color.ACCENT_OPAQUE));
                    addButtonBackground.setImageDrawable(circleDrawable);
                    addButton.setVisibility(View.VISIBLE);
                    needsButtonReset = false;
                }
            }
        }, (long) (ADD_ANIMATION_TIME * 1.1f));

        needsButtonReset = true;
        addButton.setVisibility(View.GONE);
        buttonColorAnimation.start();
        addButtonBackground.startAnimation(animation);
        break;
    default:
    }
}

From source file:com.ray.appchallenge.view.SwipeRefreshLayoutBottom.java

private void startScaleDownAnimation(final Animation.AnimationListener listener) {
    mScaleDownAnimation = new Animation() {
        @Override//  w  w w.j  av  a  2 s.  com
        public void applyTransformation(final float interpolatedTime, final Transformation t) {
            setAnimationProgress(1 - interpolatedTime);
        }
    };
    mScaleDownAnimation.setDuration(SCALE_DOWN_DURATION);
    mCircleView.setAnimationListener(listener);
    mCircleView.clearAnimation();
    mCircleView.startAnimation(mScaleDownAnimation);
}

From source file:cw.kop.autobackground.sources.SourceInfoFragment.java

@Override
public void onStart() {
    super.onStart();
    Animation animation;//from  w w  w .  ja v a2s .  c o  m
    if (sourcePosition == -1) {
        animation = new Animation() {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {

                sourceSpinnerText.setAlpha(interpolatedTime);
                sourceSpinner.setAlpha(interpolatedTime);
                sourceTitle.setAlpha(interpolatedTime);
                settingsContainer.setAlpha(interpolatedTime);
                sourceUse.setAlpha(interpolatedTime);

            }
        };
    } else {
        animation = new Animation() {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {

                settingsContainer.setAlpha(interpolatedTime);
                sourceUse.setAlpha(interpolatedTime);

            }
        };
    }

    animation.setDuration(FADE_IN_TIME);
    animation.setInterpolator(new DecelerateInterpolator(3.0f));
    settingsContainer.startAnimation(animation);

}

From source file:com.hp.hoopeasy.widget.swipeRefresh.SwipeRefreshLayout.java

private void startScaleUpAnimation(AnimationListener listener) {
    mCircleView.setVisibility(View.VISIBLE);
    if (android.os.Build.VERSION.SDK_INT >= 11) {
        // Pre API 11, alpha is used in place of scale up to type the
        // progress circle appearing.
        // Don't adjust the alpha during appearance otherwise.
        mProgress.setAlpha(MAX_ALPHA);/*  w  w w.  ja  va  2 s .com*/
    }
    mScaleAnimation = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            setAnimationProgress(interpolatedTime);
        }
    };
    mScaleAnimation.setDuration(mMediumAnimationDuration);
    if (listener != null) {
        mCircleView.setAnimationListener(listener);
    }
    mCircleView.clearAnimation();
    mCircleView.startAnimation(mScaleAnimation);
}

From source file:com.kectech.android.wyslink.thirdparty.SwipeRefreshLayout.java

private void startScaleUpAnimation(AnimationListener listener) {
    mCircleView.setVisibility(View.VISIBLE);
    if (android.os.Build.VERSION.SDK_INT >= 11) {
        // Pre API 11, alpha is used in place of scale up to tab_main_show the
        // progress circle appearing.
        // Don't adjust the alpha during appearance otherwise.
        mProgress.setAlpha(MAX_ALPHA);/*from  w ww . j  a  v  a  2  s . c  om*/
    }
    Animation scaleAnimation = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            setAnimationProgress(interpolatedTime);
        }
    };
    scaleAnimation.setDuration(mMediumAnimationDuration);
    if (listener != null) {
        mCircleView.setAnimationListener(listener);
    }
    mCircleView.clearAnimation();
    mCircleView.startAnimation(scaleAnimation);
}

From source file:anabolicandroids.chanobol.util.swipebottom.SwipeRefreshLayoutBottom.java

private void startScaleDownAnimation(Animation.AnimationListener listener) {
    mScaleDownAnimation = new Animation() {
        @Override//from  w  w  w .j  av  a2  s .co  m
        public void applyTransformation(float interpolatedTime, Transformation t) {
            setAnimationProgress(1 - interpolatedTime);
        }
    };
    mScaleDownAnimation.setDuration(SCALE_DOWN_DURATION);
    mCircleView.setAnimationListener(listener);
    mCircleView.clearAnimation();
    mCircleView.startAnimation(mScaleDownAnimation);
}

From source file:cn.edu.bit.bookstore.bookstore_android.widget.PullToRefreshLayout.java

private void startScaleUpAnimation(Animation.AnimationListener listener) {
    mCircleView.setVisibility(View.VISIBLE);
    if (android.os.Build.VERSION.SDK_INT >= 11) {
        // Pre API 11, alpha is used in place of scale up to show the
        // progress circle appearing.
        // Don't adjust the alpha during appearance otherwise.
        mProgress.setAlpha(MAX_ALPHA);/*from   www .  j ava2 s  .c  o m*/
    }
    mScaleAnimation = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            setAnimationProgress(interpolatedTime);
        }
    };
    mScaleAnimation.setDuration(mMediumAnimationDuration);
    if (listener != null) {
        mCircleView.setAnimationListener(listener);
    }
    mCircleView.clearAnimation();
    mCircleView.startAnimation(mScaleAnimation);
}

From source file:com.ray.appchallenge.view.SwipeRefreshLayoutBottom.java

private Animation startAlphaAnimation(final int startingAlpha, final int endingAlpha) {

    // Pre API 11, alpha is used in place of scale. Don't also use it to
    // show the trigger point.
    if (mScale && isAlphaUsedForScale()) {
        return null;
    }//ww w  . jav  a  2  s .c om

    Animation alpha = new Animation() {
        @Override
        public void applyTransformation(final float interpolatedTime, final Transformation t) {
            mProgress.setAlpha((int) (startingAlpha + ((endingAlpha - startingAlpha) * interpolatedTime)));
        }
    };
    alpha.setDuration(ALPHA_ANIMATION_DURATION);

    // Clear out the previous animation listeners.
    mCircleView.setAnimationListener(null);
    mCircleView.clearAnimation();
    mCircleView.startAnimation(alpha);
    return alpha;
}