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:org.onebusaway.android.view.RealtimeIndicatorView.java

/**
 * Setup the animation/* ww w. j  a  v a 2s .  co  m*/
 */
private synchronized void initAnimation() {
    // Animate circle expand/contract
    mAnimation1 = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            int height = getHeight();
            mNewRadius = height * interpolatedTime;
            invalidate();
        }
    };

    mAnimation1.setDuration(mDuration);
    mAnimation1.setRepeatMode(Animation.REVERSE);
    mAnimation1.setInterpolator(new FastOutLinearInInterpolator());
    mAnimation1.setRepeatCount(Animation.INFINITE);
    startAnimation(mAnimation1);
    mInitComplete = true;
}

From source file:com.chronosystems.nearbyapp.components.loader.ProgressView.java

private void startScaleUpAnimation(AnimationListener listener) {
    setVisibility(View.VISIBLE);/*from  w w w.  j  a  va2s  .com*/
    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);
    }
    mScaleAnimation = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            setAnimationProgress(interpolatedTime);
        }
    };
    mScaleAnimation.setDuration(mMediumAnimationDuration);
    if (listener != null) {
        setAnimationListener(listener);
    }
    clearAnimation();
    startAnimation(mScaleAnimation);
}

From source file:com.taobao.luaview.view.widget.SuperSwipeRefreshLayout.java

private void startScaleUpAnimation(AnimationListener listener) {
    mScaleAnimation = new Animation() {
        @Override//from w  ww  .  j a v a 2 s .  c o  m
        public void applyTransformation(float interpolatedTime, Transformation t) {
            setAnimationProgress(interpolatedTime);
        }
    };
    mScaleAnimation.setDuration(mMediumAnimationDuration);
    if (listener != null) {
        mHeadViewContainer.setAnimationListener(listener);
    }
    mHeadViewContainer.clearAnimation();
    mHeadViewContainer.startAnimation(mScaleAnimation);
}

From source file:com.chronosystems.nearbyapp.components.loader.ProgressView.java

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

From source file:com.fastbootmobile.encore.utils.Utils.java

/**
 * Animate a view expansion (unwrapping)
 *
 * @param v      The view to animate/*  w w w  .  j  av  a  2 s.com*/
 * @param expand True to animate expanding, false to animate closing
 * @return The animation object created
 */
public static Animation animateExpand(final View v, final boolean expand) {
    try {
        Method m = v.getClass().getDeclaredMethod("onMeasure", int.class, int.class);
        m.setAccessible(true);
        m.invoke(v, View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec
                .makeMeasureSpec(((View) v.getParent()).getMeasuredWidth(), View.MeasureSpec.UNSPECIFIED));
    } catch (Exception e) {
        e.printStackTrace();
    }

    final int initialHeight = v.getMeasuredHeight();

    if (expand) {
        v.getLayoutParams().height = 0;
    } else {
        v.getLayoutParams().height = initialHeight;
    }
    v.setVisibility(View.VISIBLE);

    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            int newHeight;
            if (expand) {
                newHeight = (int) (initialHeight * interpolatedTime);
            } else {
                newHeight = (int) (initialHeight * (1 - interpolatedTime));
            }
            v.getLayoutParams().height = newHeight;
            v.requestLayout();

            if (interpolatedTime == 1 && !expand)
                v.setVisibility(View.GONE);
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };
    a.setDuration(500);
    return a;
}

From source file:com.sohu.xzd.widget.SwipeRefresh.java

private void startAlphaInAnimation(AnimationListener listener) {
    mRefreshHeader.setVisibility(View.VISIBLE);
    Animation scaleAnimation = new Animation() {
        @Override//w ww. ja  v a2  s. c  o m
        public void applyTransformation(float interpolatedTime, Transformation t) {
            //                setAnimationProgress(interpolatedTime);
        }
    };
    scaleAnimation.setDuration(200L);
    if (listener != null) {
        mRefreshHeader.setAnimationListener(listener);
    }
    mRefreshHeader.clearAnimation();
    mRefreshHeader.startAnimation(scaleAnimation);
}

From source file:com.kkbox.toolkit.app.KKFragment.java

@Override
public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
    animationEnded = false;//from  www.  j ava  2  s  .co m
    Animation animation = null;
    if (enter && customEnterAnimation != 0) {
        animation = AnimationUtils.loadAnimation(activity, customEnterAnimation);
    } else if (!enter && customExitAnimation != 0) {
        animation = AnimationUtils.loadAnimation(activity, customExitAnimation);
    } else if (animationType == AnimationType.POP) {
        if (enter) {
            animation = AnimationUtils.loadAnimation(activity, R.anim.slide_in_left);
        } else {
            animation = AnimationUtils.loadAnimation(activity, R.anim.slide_out_right);
        }
    } else if (animationType == AnimationType.PUSH) {
        if (enter) {
            animation = AnimationUtils.loadAnimation(activity, R.anim.slide_in_right);
        } else {
            animation = AnimationUtils.loadAnimation(activity, R.anim.slide_out_left);
        }
    } else if (animationType == AnimationType.FADE_OUT) {
        if (enter) {
            animation = AnimationUtils.loadAnimation(activity, R.anim.fade_in);
        } else {
            animation = AnimationUtils.loadAnimation(activity, R.anim.fade_out);
        }
    } else if (animation == null) {
        animation = new Animation() {
        };
        animation.setDuration(0);
    }
    animation.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationEnd(Animation a) {
            animationEnded = true;
            if (dataFetchedStatus == DataFetchStatus.SUCCESS && !uiLoaded) {
                onLoadUI();
            }
        }

        @Override
        public void onAnimationStart(Animation a) {
        }

        @Override
        public void onAnimationRepeat(Animation a) {
        }
    });
    return animation;
}

From source file:com.sohu.xzd.widget.SwipeRefresh.java

private void startScaleDownAnimation(AnimationListener listener) {
    mScaleDownAnimation = new Animation() {
        @Override/*from   w w  w  .j  av  a  2 s . c  o  m*/
        public void applyTransformation(float interpolatedTime, Transformation t) {

        }
    };
    mScaleDownAnimation.setDuration(SCALE_DOWN_DURATION);
    mRefreshHeader.setAnimationListener(listener);
    mRefreshHeader.clearAnimation();
    mRefreshHeader.startAnimation(mScaleDownAnimation);
}

From source file:com.hakerjack.experiments.CustomSwipeRefreshLayout.java

private void startScaleUpAnimation(AnimationListener listener) {
    mSpinner.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.
        mSpinner.setSpinnerAlpha(MAX_ALPHA);
    }//  w w w.  j av  a  2s  .  com
    mScaleAnimation = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            setAnimationProgress(interpolatedTime);
        }
    };
    mScaleAnimation.setDuration(mMediumAnimationDuration);
    if (listener != null) {
        mSpinner.setAnimationListener(listener);
    }
    mSpinner.clearAnimation();
    mSpinner.startAnimation(mScaleAnimation);
}

From source file:com.mirasense.scanditsdk.plugin.ScanditSDK.java

/**
 * Adjusts the layout parameters of the barcode picker according to the margins set through java script.
 *
 * @param bundle The bundle with the java script parameters.
 * @param animationDuration Over how long the change should be animated.
 *//*from   w  ww  . j  a  v a  2 s. co m*/
private void adjustLayout(Bundle bundle, double animationDuration) {
    if (mBarcodePicker == null) {
        return;
    }
    final RelativeLayout.LayoutParams rLayoutParams = (RelativeLayout.LayoutParams) mBarcodePicker
            .getLayoutParams();

    Display display = ((WindowManager) webView.getContext().getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();
    if (bundle.containsKey(ScanditSDKParameterParser.paramPortraitMargins)
            && display.getHeight() > display.getWidth()) {
        String portraitMargins = bundle.getString(ScanditSDKParameterParser.paramPortraitMargins);
        String[] split = portraitMargins.split("[/]");
        if (split.length == 4) {
            try {
                final Rect oldPortraitMargins = new Rect(mPortraitMargins);
                mPortraitMargins = new Rect(Integer.valueOf(split[0]), Integer.valueOf(split[1]),
                        Integer.valueOf(split[2]), Integer.valueOf(split[3]));
                if (animationDuration > 0) {
                    Animation anim = new Animation() {
                        @Override
                        protected void applyTransformation(float interpolatedTime, Transformation t) {
                            rLayoutParams.topMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                                    (int) (oldPortraitMargins.top
                                            + (mPortraitMargins.top - oldPortraitMargins.top)
                                                    * interpolatedTime));
                            rLayoutParams.rightMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                                    (int) (oldPortraitMargins.right
                                            + (mPortraitMargins.right - oldPortraitMargins.right)
                                                    * interpolatedTime));
                            rLayoutParams.bottomMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                                    (int) (oldPortraitMargins.bottom
                                            + (mPortraitMargins.bottom - oldPortraitMargins.bottom)
                                                    * interpolatedTime));
                            rLayoutParams.leftMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                                    (int) (oldPortraitMargins.left
                                            + (mPortraitMargins.left - oldPortraitMargins.left)
                                                    * interpolatedTime));
                            mBarcodePicker.setLayoutParams(rLayoutParams);
                        }
                    };
                    anim.setDuration((int) (animationDuration * 1000));
                    mBarcodePicker.startAnimation(anim);
                } else {

                    rLayoutParams.topMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                            mPortraitMargins.top);
                    rLayoutParams.rightMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                            mPortraitMargins.right);
                    rLayoutParams.bottomMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                            mPortraitMargins.bottom);
                    rLayoutParams.leftMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                            mPortraitMargins.left);
                    mBarcodePicker.setLayoutParams(rLayoutParams);
                }
            } catch (NumberFormatException e) {

            }
        }
    } else if (bundle.containsKey(ScanditSDKParameterParser.paramLandscapeMargins)
            && display.getWidth() > display.getHeight()) {
        String landscapeMargins = bundle.getString(ScanditSDKParameterParser.paramLandscapeMargins);
        String[] split = landscapeMargins.split("[/]");
        if (split.length == 4) {
            final Rect oldLandscapeMargins = new Rect(mLandscapeMargins);
            mLandscapeMargins = new Rect(Integer.valueOf(split[0]), Integer.valueOf(split[1]),
                    Integer.valueOf(split[2]), Integer.valueOf(split[3]));

            Animation anim = new Animation() {
                @Override
                protected void applyTransformation(float interpolatedTime, Transformation t) {
                    rLayoutParams.topMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                            (int) (oldLandscapeMargins.top
                                    + (mLandscapeMargins.top - oldLandscapeMargins.top) * interpolatedTime));
                    rLayoutParams.rightMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                            (int) (oldLandscapeMargins.right
                                    + (mLandscapeMargins.right - oldLandscapeMargins.right)
                                            * interpolatedTime));
                    rLayoutParams.bottomMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                            (int) (oldLandscapeMargins.bottom
                                    + (mLandscapeMargins.bottom - oldLandscapeMargins.bottom)
                                            * interpolatedTime));
                    rLayoutParams.leftMargin = SbSystemUtils.pxFromDp(webView.getContext(),
                            (int) (oldLandscapeMargins.left
                                    + (mLandscapeMargins.left - oldLandscapeMargins.left) * interpolatedTime));
                    mBarcodePicker.setLayoutParams(rLayoutParams);
                }
            };
            anim.setDuration((int) (animationDuration * 1000));
            mBarcodePicker.startAnimation(anim);
        }
    }
}