Example usage for android.view.animation Animation setDuration

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

Introduction

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

Prototype

public void setDuration(long durationMillis) 

Source Link

Document

How long this animation should last.

Usage

From source file:com.app.jdy.ui.RegirsterActivity.java

/**
 * // w  ww . j  a va  2  s.  c  o m
 * @author zhoufeng
 * @createtime 2015-1-13 ?6:29:17
 * @Decription ?
 * 
 */
public void initAnimation() {
    // ?
    PropertyValuesHolder pvh = PropertyValuesHolder.ofFloat("translationY", 3000f, 0f);
    ObjectAnimator.ofPropertyValuesHolder(get_regirster_code, pvh).setDuration(animatorStart).start();
    ObjectAnimator.ofPropertyValuesHolder(new_username, pvh).setDuration(animatorStart).start();
    // ?
    ObjectAnimator.ofFloat(regirster_code, "translationY", 3000f, 0f).setDuration(animatorStart + 200).start();
    ObjectAnimator.ofFloat(new_password, "translationY", 3000f, 0f).setDuration(animatorStart + 400).start();
    ObjectAnimator.ofFloat(pwdEye, "translationY", 3000f, 0f).setDuration(animatorStart + 400).start();

    Animation translateAnimation7 = new TranslateAnimation(0, 0, 3000f, 0f);
    translateAnimation7.setDuration(animatorStart + 600);// ?
    // ?
    ObjectAnimator.ofFloat(sumbit_regirster, "translationY", 3000f, 0f).setDuration(animatorStart + 800)
            .start();
}

From source file:ly.kite.journey.selection.ProductOverviewFragment.java

/*****************************************************
 *
 * Called when the details control is clicked.
 *
 *****************************************************/
private void toggleSliderState() {
    // We want to animation the following:
    //   - Overlaid start button fade in / out
    //   - Sliding drawer up / down
    //   - Open / close drawer icon rotation

    boolean sliderWillBeOpening = !mSlidingOverlayFrame.sliderIsExpanded();

    float overlaidComponentsInitialAlpha;
    float overlaidComponentsFinalAlpha;

    float openCloseIconInitialRotation;
    float openCloseIconFinalRotation;

    if (sliderWillBeOpening) {
        overlaidComponentsInitialAlpha = 1f;
        overlaidComponentsFinalAlpha = 0f;

        openCloseIconInitialRotation = OPEN_CLOSE_ICON_ROTATION_UP;
        openCloseIconFinalRotation = OPEN_CLOSE_ICON_ROTATION_DOWN;
    } else {/*from w  w  w  . ja  v a 2  s  . co  m*/
        overlaidComponentsInitialAlpha = 0f;
        overlaidComponentsFinalAlpha = 1f;

        openCloseIconInitialRotation = OPEN_CLOSE_ICON_ROTATION_DOWN;
        openCloseIconFinalRotation = OPEN_CLOSE_ICON_ROTATION_UP;
    }

    // Create the overlaid components animation
    Animation overlaidComponentsAnimation = new AlphaAnimation(overlaidComponentsInitialAlpha,
            overlaidComponentsFinalAlpha);
    overlaidComponentsAnimation.setDuration(SLIDE_ANIMATION_DURATION_MILLIS);
    overlaidComponentsAnimation.setFillAfter(true);

    // Create the open/close icon animation.
    // The rotation is delayed, but will finish at the same time as the slide animation.
    Animation openCloseIconAnimation = new RotateAnimation(openCloseIconInitialRotation,
            openCloseIconFinalRotation, mOpenCloseDrawerIconImageView.getWidth() * 0.5f,
            mOpenCloseDrawerIconImageView.getHeight() * 0.5f);
    openCloseIconAnimation.setStartOffset(OPEN_CLOSE_ICON_ANIMATION_DELAY_MILLIS);
    openCloseIconAnimation.setDuration(OPEN_CLOSE_ICON_ANIMATION_DURATION_MILLIS);
    openCloseIconAnimation.setFillAfter(true);

    if (mOverlaidComponents != null) {
        mOverlaidComponents.setAlpha(1f); // Clear any alpha already applied
        mOverlaidComponents.startAnimation(overlaidComponentsAnimation);
    }

    if (mOpenCloseDrawerIconImageView != null) {
        mOpenCloseDrawerIconImageView.setRotation(0f); // Clear any rotation already applied
        mOpenCloseDrawerIconImageView.startAnimation(openCloseIconAnimation);
    }

    mSlidingOverlayFrame.animateToExpandedState(sliderWillBeOpening);
}

From source file:ca.frozen.curlingtv.activities.VideoFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    // configure the activity
    super.onCreate(savedInstanceState);

    // load the settings and cameras
    Utils.loadData();/*w w w  .j  av a2  s.  c  om*/

    // get the parameters
    camera = getArguments().getParcelable(CAMERA);
    fullScreen = getArguments().getBoolean(FULL_SCREEN);

    // create the gesture recognizers
    simpleDetector = new GestureDetector(getActivity(), new SimpleListener());
    scaleDetector = new ScaleGestureDetector(getActivity(), new ScaleListener());

    // create the fade in handler and runnable
    fadeInHandler = new Handler();
    fadeInRunner = new Runnable() {
        @Override
        public void run() {
            Animation fadeInName = new AlphaAnimation(0, 1);
            fadeInName.setDuration(FADEIN_ANIMATION_TIME);
            fadeInName.setFillAfter(true);
            Animation fadeInSnapshot = new AlphaAnimation(0, 1);
            fadeInSnapshot.setDuration(FADEIN_ANIMATION_TIME);
            fadeInSnapshot.setFillAfter(true);
            nameView.startAnimation(fadeInName);
            snapshotButton.startAnimation(fadeInSnapshot);
            fadeListener.onStartFadeIn();
        }
    };

    // create the fade out handler and runnable
    fadeOutHandler = new Handler();
    fadeOutRunner = new Runnable() {
        @Override
        public void run() {
            Animation fadeOutName = new AlphaAnimation(1, 0);
            fadeOutName.setDuration(FADEOUT_ANIMATION_TIME);
            fadeOutName.setFillAfter(true);
            Animation fadeOutSnapshot = new AlphaAnimation(1, 0);
            fadeOutSnapshot.setDuration(FADEOUT_ANIMATION_TIME);
            fadeOutSnapshot.setFillAfter(true);
            nameView.startAnimation(fadeOutName);
            snapshotButton.startAnimation(fadeOutSnapshot);
            fadeListener.onStartFadeOut();
        }
    };

    // create the finish handler and runnable
    finishHandler = new Handler();
    finishRunner = new Runnable() {
        @Override
        public void run() {
            getActivity().finish();
        }
    };
}

From source file:com.alivenet.dmvtaxi.Activity_ConfirmMybooking.java

private Animation inFromRightAnimation() {

    Animation inFromRight = 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);
    inFromRight.setDuration(2000);
    inFromRight.setInterpolator(new AccelerateInterpolator());
    return inFromRight;
}

From source file:org.mariotaku.twidere.view.TouchImageView.java

public TouchImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    final TouchGestureDetector.OnTouchGestureListener listener = new TouchGestureDetector.OnTouchGestureListener() {

        @Override/*from w ww  .j av a2s.  c o m*/
        public boolean onSingleTapConfirmed(MotionEvent e) {
            return performClick();
        }

        @Override
        public void onLongPress(MotionEvent e) {
            performLongClick();
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            loadMatrixValues();

            final float minScale = getMinScale();
            // If we have already zoomed in, we should return to our initial scale value (minScale). Otherwise, scale to full size
            final boolean shouldZoomOut = mScale > minScale;
            final float targetScale = shouldZoomOut ? minScale : mMaxScale;

            // First, we try to keep the focused point in the same position when the animation ends
            final float desiredTranslationX = e.getX() - (e.getX() - mTranslationX) * (targetScale / mScale);
            final float desiredTranslationY = e.getY() - (e.getY() - mTranslationY) * (targetScale / mScale);

            // Here, we apply a correction to avoid unwanted blank spaces
            final float targetTranslationX = desiredTranslationX + computeTranslation(getMeasuredWidth(),
                    mDrawableIntrinsicWidth * targetScale, desiredTranslationX, 0);
            final float targetTranslationY = desiredTranslationY + computeTranslation(getMeasuredHeight(),
                    mDrawableIntrinsicHeight * targetScale, desiredTranslationY, 0);

            clearAnimation();
            final Animation animation = new TouchAnimation(targetScale, targetTranslationX, targetTranslationY);
            animation.setDuration(DOUBLE_TAP_ANIMATION_DURATION);
            startAnimation(animation);

            if (mZoomListener != null) {
                if (shouldZoomOut) {
                    mZoomListener.onZoomOut();
                } else {
                    mZoomListener.onZoomIn();
                }
            }
            return true;
        }

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            // Sometimes, this method is called just after an onScaleEnd event. In this case, we want to wait until we animate back our image
            if (mIsAnimatingBack) {
                return false;
            }

            loadMatrixValues();

            final float currentDrawableWidth = mDrawableIntrinsicWidth * mScale;
            final float currentDrawableHeight = mDrawableIntrinsicHeight * mScale;

            final float dx = computeTranslation(getMeasuredWidth(), currentDrawableWidth, mTranslationX,
                    -distanceX);
            final float dy = computeTranslation(getMeasuredHeight(), currentDrawableHeight, mTranslationY,
                    -distanceY);
            mMatrix.postTranslate(dx, dy);

            clearAnimation();
            ViewCompat.postInvalidateOnAnimation(TouchImageView.this);

            return true;
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            // Sometimes, this method is called just after an onScaleEnd event. In this case, we want to wait until we animate back our image
            if (mIsAnimatingBack) {
                return false;
            }

            loadMatrixValues();

            final float horizontalSideFreeSpace = (getMeasuredWidth() - mDrawableIntrinsicWidth * mScale) / 2F;
            final float minTranslationX = horizontalSideFreeSpace > 0 ? horizontalSideFreeSpace
                    : getMeasuredWidth() - mDrawableIntrinsicWidth * mScale;
            final float maxTranslationX = horizontalSideFreeSpace > 0 ? horizontalSideFreeSpace : 0;

            final float verticalSideFreeSpace = (getMeasuredHeight() - mDrawableIntrinsicHeight * mScale) / 2F;
            final float minTranslationY = verticalSideFreeSpace > 0 ? verticalSideFreeSpace
                    : getMeasuredHeight() - mDrawableIntrinsicHeight * mScale;
            final float maxTranslationY = verticalSideFreeSpace > 0 ? verticalSideFreeSpace : 0;

            // Using FlingScroller here. The results were better than the Scroller class
            // https://android.googlesource.com/platform/packages/apps/Gallery2/+/master/src/com/android/gallery3d/ui/FlingScroller.java
            mFlingScroller.fling(Math.round(mTranslationX), Math.round(mTranslationY), Math.round(velocityX),
                    Math.round(velocityY), Math.round(minTranslationX), Math.round(maxTranslationX),
                    Math.round(minTranslationY), Math.round(maxTranslationY));

            clearAnimation();
            final Animation animation = new FlingAnimation();
            animation.setDuration(mFlingScroller.getDuration());
            animation.setInterpolator(new LinearInterpolator());
            startAnimation(animation);

            return true;
        }

        @Override
        public boolean onScaleBegin(ScaleGestureDetector detector) {
            mLastFocusX = null;
            mLastFocusY = null;

            return true;
        }

        @Override
        public boolean onScale(ScaleGestureDetector detector) {
            loadMatrixValues();

            float currentDrawableWidth = mDrawableIntrinsicWidth * mScale;
            float currentDrawableHeight = mDrawableIntrinsicHeight * mScale;

            final float focusX = computeFocus(getMeasuredWidth(), currentDrawableWidth, mTranslationX,
                    detector.getFocusX());
            final float focusY = computeFocus(getMeasuredHeight(), currentDrawableHeight, mTranslationY,
                    detector.getFocusY());

            // Here, we provide the ability to scroll while scaling
            if (mLastFocusX != null && mLastFocusY != null) {
                final float dx = computeScaleTranslation(getMeasuredWidth(), currentDrawableWidth,
                        mTranslationX, focusX - mLastFocusX);
                final float dy = computeScaleTranslation(getMeasuredHeight(), currentDrawableHeight,
                        mTranslationY, focusY - mLastFocusY);

                if (dx != 0 || dy != 0) {
                    mMatrix.postTranslate(dx, dy);
                }
            }

            final float scale = computeScale(getMinScale(), mMaxScale, mScale, detector.getScaleFactor());
            mMatrix.postScale(scale, scale, focusX, focusY);

            mLastFocusX = focusX;
            mLastFocusY = focusY;

            clearAnimation();
            ViewCompat.postInvalidateOnAnimation(TouchImageView.this);

            return true;
        }

        @Override
        public void onScaleEnd(ScaleGestureDetector detector) {
            loadMatrixValues();

            final float currentDrawableWidth = mDrawableIntrinsicWidth * mScale;
            final float currentDrawableHeight = mDrawableIntrinsicHeight * mScale;

            final float dx = computeTranslation(getMeasuredWidth(), currentDrawableWidth, mTranslationX, 0);
            final float dy = computeTranslation(getMeasuredHeight(), currentDrawableHeight, mTranslationY, 0);

            if (Math.abs(dx) < 1 && Math.abs(dy) < 1) {
                return;
            }

            final float targetTranslationX = mTranslationX + dx;
            final float targetTranslationY = mTranslationY + dy;

            clearAnimation();
            final Animation animation = new TouchAnimation(mScale, targetTranslationX, targetTranslationY);
            animation.setDuration(SCALE_END_ANIMATION_DURATION);
            startAnimation(animation);

            mIsAnimatingBack = true;
        }
    };

    mTouchGestureDetector = new TouchGestureDetector(context, listener);

    super.setScaleType(ScaleType.MATRIX);
}

From source file:com.cairoconfessions.MainActivity.java

public View addConfession(String confess, String desc) {
    final ViewGroup confession = (ViewGroup) LayoutInflater.from(this)
            .inflate(R.layout.confession_list_item_example, null);
    final TextView newConfess = (TextView) confession.findViewById(R.id.text_main);
    newConfess.setText(confess);/*  ww w.j a  v a 2 s  .co  m*/
    final float scale = getResources().getDisplayMetrics().density;
    if (!desc.equals("")) {
        confession.setContentDescription(desc);
        if (desc.equals("Love"))
            newConfess.setBackgroundResource(R.color.love);
        if (desc.equals("Pain"))
            newConfess.setBackgroundResource(R.color.pain);
        if (desc.equals("Guilt"))
            newConfess.setBackgroundResource(R.color.guilt);
        if (desc.equals("Fantasy"))
            newConfess.setBackgroundResource(R.color.fantasy);
        if (desc.equals("Dream"))
            newConfess.setBackgroundResource(R.color.dream);
    } else {
        switch ((new Random().nextInt(5)) % 5) {
        case 0:
            newConfess.setBackgroundResource(R.color.love);
            ((TextView) confession.findViewById(R.id.confess_loc)).setText("Riyadh");
            confession.setContentDescription("Love");
            break;
        case 1:
            newConfess.setBackgroundResource(R.color.pain);
            ((TextView) confession.findViewById(R.id.confess_loc)).setText("Cairo");
            confession.setContentDescription("Pain");
            break;
        case 2:
            newConfess.setBackgroundResource(R.color.guilt);
            ((TextView) confession.findViewById(R.id.confess_loc)).setText("New York");
            confession.setContentDescription("Guilt");
            break;
        case 3:
            newConfess.setBackgroundResource(R.color.fantasy);
            ((TextView) confession.findViewById(R.id.confess_loc)).setText("New York");
            confession.setContentDescription("Fantasy");
            break;
        case 4:
            newConfess.setBackgroundResource(R.color.dream);
            ((TextView) confession.findViewById(R.id.confess_loc)).setText("Riyadh");
            confession.setContentDescription("Dream");
            break;
        }
    }
    switch ((new Random().nextInt(3)) % 3) {
    case 0:
        ((TextView) confession.findViewById(R.id.confess_loc)).setText("Riyadh");
        break;
    case 1:
        ((TextView) confession.findViewById(R.id.confess_loc)).setText("Cairo");
        break;
    case 2:
        ((TextView) confession.findViewById(R.id.confess_loc)).setText("New York");
        break;
    }
    Animation fadeIn = new AlphaAnimation(0, 1);
    fadeIn.setDuration(1000);
    confession.setAnimation(fadeIn);
    confession.getChildAt(0).setPadding((int) (scale * 1.5 + 0.5f), (int) (scale * 1.5 + 0.5f),
            (int) (scale * 1.5 + 0.5f), (int) (scale * 1.5 + 0.5f));
    confession.getChildAt(0).setBackgroundResource(R.drawable.border);
    mPager.setCurrentItem(1);
    if (!desc.equals("")) {
        ((ScrollView) findViewById(R.id.feed)).fullScroll(ScrollView.FOCUS_UP);
        ((LinearLayout) findViewById(R.id.confession_list)).addView(confession, 0);
    } else {
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {

                ((ScrollView) findViewById(R.id.feed)).fullScroll(ScrollView.FOCUS_UP);
                ((LinearLayout) findViewById(R.id.confession_list)).post(new Runnable() {

                    public void run() {
                        ((LinearLayout) findViewById(R.id.confession_list)).addView(confession, 0);
                    }
                });
            }
        }, 1000);
    }
    return confession;

}

From source file:cn.jmessage.android.uikit.pickerimage.view.BaseZoomableImageView.java

protected void center(boolean vertical, boolean horizontal, boolean animate) {
    if (mBitmap == null)
        return;// w w  w  . jav a  2 s . c om

    Matrix m = getImageViewMatrix();

    float[] topLeft = new float[] { 0, 0 };
    float[] botRight = new float[] { mBitmap.getWidth(), mBitmap.getHeight() };

    translatePoint(m, topLeft);
    translatePoint(m, botRight);

    float height = botRight[1] - topLeft[1];
    float width = botRight[0] - topLeft[0];

    float deltaX = 0, deltaY = 0;

    if (vertical) {
        int viewHeight = getHeight();
        if (height < viewHeight) {
            deltaY = (viewHeight - height) / 2 - topLeft[1];
        } else if (topLeft[1] > 0) {
            deltaY = -topLeft[1];
        } else if (botRight[1] < viewHeight) {
            deltaY = getHeight() - botRight[1];
        }
    }

    if (horizontal) {
        int viewWidth = getWidth();
        if (width < viewWidth) {
            deltaX = (viewWidth - width) / 2 - topLeft[0];
        } else if (topLeft[0] > 0) {
            deltaX = -topLeft[0];
        } else if (botRight[0] < viewWidth) {
            deltaX = viewWidth - botRight[0];
        }
    }

    postTranslate(deltaX, deltaY);
    if (animate) {
        Animation a = new TranslateAnimation(-deltaX, 0, -deltaY, 0);
        a.setStartTime(SystemClock.elapsedRealtime());
        a.setDuration(250);
        setAnimation(a);
    }
    setImageMatrix(getImageViewMatrix());
}

From source file:com.google.android.gcm.demo.ui.MainActivity.java

/**
 * Toggle the Logs View visibility with a nice animation.
 *//*from   ww w  . j a v  a 2  s.  co  m*/
public void toggleLogsView(boolean showView) {
    final View logsView = findViewById(R.id.logs_layout);
    final View bodyView = findViewById(R.id.container);
    final FrameLayout.LayoutParams logsLayoutParams = (FrameLayout.LayoutParams) logsView.getLayoutParams();
    final int startLogsY, endLogsY, startBodyY, endBodyY;

    if (showView) {
        // The logsView height set in XML is a placeholder, we need to compute at runtime
        // how much is 0.4 of the screen height.
        int height = (int) (0.4 * mDrawerLayout.getHeight());

        // The LogsView is hidden being placed off-screen with a negative bottomMargin.
        // We need to update its height and bottomMargin to the correct runtime values.
        logsLayoutParams.bottomMargin = -logsLayoutParams.height;
        logsView.setLayoutParams(logsLayoutParams);
        logsLayoutParams.height = height;

        // Prepare the value for the Show animation.
        startLogsY = logsLayoutParams.bottomMargin;
        endLogsY = 0;
        startBodyY = 0;
        endBodyY = logsLayoutParams.height;
    } else {
        // Prepare the value for the Hide animation.
        startLogsY = 0;
        endLogsY = -logsLayoutParams.height;
        startBodyY = logsLayoutParams.height;
        endBodyY = 0;
    }
    final int deltaLogsY = endLogsY - startLogsY;
    final int deltaBodyY = endBodyY - startBodyY;
    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            logsLayoutParams.bottomMargin = (int) (startLogsY + deltaLogsY * interpolatedTime);
            logsView.setLayoutParams(logsLayoutParams);
            bodyView.setPadding(0, 0, 0, (int) (startBodyY + deltaBodyY * interpolatedTime));
        }
    };
    a.setDuration(500);
    logsView.startAnimation(a);
}

From source file:android.support.design.widget.BaseTransientBottomBar.java

private void animateViewOut(final int event) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        ViewCompat.animate(mView).translationY(mView.getHeight()).setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR)
                .setDuration(ANIMATION_DURATION).setListener(new ViewPropertyAnimatorListenerAdapter() {
                    @Override/*from  w w  w .ja v  a2 s.com*/
                    public void onAnimationStart(View view) {
                        mContentViewCallback.animateContentOut(0, ANIMATION_FADE_DURATION);
                    }

                    @Override
                    public void onAnimationEnd(View view) {
                        onViewHidden(event);
                    }
                }).start();
    } else {
        Animation anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.design_snackbar_out);
        anim.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
        anim.setDuration(ANIMATION_DURATION);
        anim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationEnd(Animation animation) {
                onViewHidden(event);
            }

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        mView.startAnimation(anim);
    }
}

From source file:android.support.design.widget.BaseTransientBottomBar.java

void animateViewIn() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        ViewCompat.setTranslationY(mView, mView.getHeight());
        ViewCompat.animate(mView).translationY(0f).setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR)
                .setDuration(ANIMATION_DURATION).setListener(new ViewPropertyAnimatorListenerAdapter() {
                    @Override/*from w  w w. j ava 2  s .  c  om*/
                    public void onAnimationStart(View view) {
                        mContentViewCallback.animateContentIn(ANIMATION_DURATION - ANIMATION_FADE_DURATION,
                                ANIMATION_FADE_DURATION);
                    }

                    @Override
                    public void onAnimationEnd(View view) {
                        onViewShown();
                    }
                }).start();
    } else {
        Animation anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.design_snackbar_in);
        anim.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
        anim.setDuration(ANIMATION_DURATION);
        anim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationEnd(Animation animation) {
                onViewShown();
            }

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        mView.startAnimation(anim);
    }
}