Example usage for android.view ViewPropertyAnimator setDuration

List of usage examples for android.view ViewPropertyAnimator setDuration

Introduction

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

Prototype

public ViewPropertyAnimator setDuration(long duration) 

Source Link

Document

Sets the duration for the underlying animator that animates the requested properties.

Usage

From source file:Main.java

private static void scaleInternal(final View view, int startScaleValue, int endScaleValue, int durationMs,
        int startDelay, AnimatorListenerAdapter listener, Interpolator interpolator) {
    view.setScaleX(startScaleValue);/*from w  w w . ja  v  a  2 s  .c  o m*/
    view.setScaleY(startScaleValue);

    final ViewPropertyAnimator animator = view.animate();
    animator.cancel();

    animator.setInterpolator(interpolator).scaleX(endScaleValue).scaleY(endScaleValue).setListener(listener)
            .withLayer();

    if (durationMs != DEFAULT_DURATION) {
        animator.setDuration(durationMs);
    }
    animator.setStartDelay(startDelay);

    animator.start();
}

From source file:Main.java

private static void scaleInternal(final View view, int startScaleValue, int endScaleValue, int durationMs,
        int startDelay, AnimatorListenerAdapter listener, Interpolator interpolator) {
    view.setScaleX(startScaleValue);/*from w w  w  .j  a  va2  s. c om*/
    view.setScaleY(startScaleValue);

    final ViewPropertyAnimator animator = view.animate();
    animator.cancel();

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        animator.setInterpolator(interpolator).scaleX(endScaleValue).scaleY(endScaleValue)
                .setListener(listener);
    } else {
        animator.setInterpolator(interpolator).scaleX(endScaleValue).scaleY(endScaleValue).setListener(listener)
                .withLayer();
    }
    if (durationMs != DEFAULT_DURATION) {
        animator.setDuration(durationMs);
    }
    animator.setStartDelay(startDelay);

    animator.start();
}

From source file:org.sufficientlysecure.keychain.ui.ViewKeyAdvActivity.java

private void animateMenuItem(final MenuItem vEditSubkeys, final boolean animateShow) {

    View actionView = LayoutInflater.from(this).inflate(R.layout.edit_icon, null);
    vEditSubkeys.setActionView(actionView);
    actionView.setTranslationX(animateShow ? 150 : 0);

    ViewPropertyAnimator animator = actionView.animate();
    animator.translationX(animateShow ? 0 : 150);
    animator.setDuration(300);
    animator.setInterpolator(new OvershootInterpolator(1.5f));
    animator.setListener(new AnimatorListenerAdapter() {
        @Override//from ww  w . j  a v a  2s  . c o  m
        public void onAnimationEnd(Animator animation) {
            if (!animateShow) {
                vEditSubkeys.setVisible(false);
            }
            vEditSubkeys.setActionView(null);
        }
    });
    animator.start();

}

From source file:edward.com.recyclerview.BaseItemAnimator.java

private void animateMoveImpl(final ViewHolder holder, int fromX, int fromY, int toX, int toY) {
    final View view = holder.itemView;
    final int deltaX = toX - fromX;
    final int deltaY = toY - fromY;
    if (deltaX != 0) {
        view.animate().translationX(0);//from w  w  w  .java 2  s.  c  o  m
    }
    if (deltaY != 0) {
        view.animate().translationY(0);
    }
    // TODO: make EndActions end listeners instead, since end actions aren't called when
    // vpas are canceled (and can't end them. why?)
    // need listener functionality in VPACompat for this. Ick.
    mMoveAnimations.add(holder);
    final ViewPropertyAnimator animation = view.animate();
    animation.setDuration(getMoveDuration()).setListener(new VpaListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animator) {
            dispatchMoveStarting(holder);
        }

        @Override
        public void onAnimationCancel(Animator animator) {
            View mView = view;
            if (animator instanceof ObjectAnimator) {
                mView = (View) ((ObjectAnimator) animator).getTarget();
            }
            if (deltaX != 0) {
                mView.setTranslationX(0);
            }
            if (deltaY != 0) {
                mView.setTranslationY(0);
            }
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            animation.setListener(null);
            dispatchMoveFinished(holder);
            mMoveAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
}

From source file:com.android.contacts.detail.ContactDetailLayoutController.java

public void setContactData(Contact data) {
    final boolean contactWasLoaded;
    final boolean contactHadUpdates;
    final boolean isDifferentContact;
    if (mContactData == null) {
        contactHadUpdates = false;/*w w w  . ja v a  2s  . c om*/
        contactWasLoaded = false;
        isDifferentContact = true;
    } else {
        contactHadUpdates = mContactHasUpdates;
        contactWasLoaded = true;
        isDifferentContact = !UriUtils.areEqual(mContactData.getLookupUri(), data.getLookupUri());
    }
    mContactData = data;

    if (PhoneCapabilityTester.isUsingTwoPanes(mActivity)) {
        // Tablet: If we already showed data before, we want to cross-fade from screen to screen
        if (contactWasLoaded && mTransitionAnimationView != null && isDifferentContact) {
            mTransitionAnimationView.startMaskTransition(mContactData == null, -1);
        }
    } else {
        // Small screen: We are on our own screen. Fade the data in, but only the first time
        if (!contactWasLoaded) {
            mViewContainer.setAlpha(0.0f);
            final ViewPropertyAnimator animator = mViewContainer.animate();
            animator.alpha(1.0f);
            animator.setDuration(SINGLE_PANE_FADE_IN_DURATION);
        }
    }

    showContactWithoutUpdates();
}

From source file:com.silentcircle.contacts.detail.ContactDetailLayoutController.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public void setContactData(Contact data) {
    final boolean contactWasLoaded;
    final boolean contactHadUpdates;
    final boolean isDifferentContact;
    if (mContactData == null) {
        contactHadUpdates = false;//from  ww  w. j  ava  2  s.  c  om
        contactWasLoaded = false;
        isDifferentContact = true;
    } else {
        contactHadUpdates = mContactHasUpdates;
        contactWasLoaded = true;
        isDifferentContact = !UriUtils.areEqual(mContactData.getLookupUri(), data.getLookupUri());
    }
    mContactData = data;
    mContactHasUpdates = !data.getStreamItems().isEmpty();

    if (PhoneCapabilityTester.isUsingTwoPanes(mActivity)) {
        // Tablet: If we already showed data before, we want to cross-fade from screen to screen
        if (contactWasLoaded && mTransitionAnimationView != null && isDifferentContact) {
            mTransitionAnimationView.startMaskTransition(mContactData == null);
        }
    } else {
        // Small screen: We are on our own screen. Fade the data in, but only the first time
        if (!contactWasLoaded) {
            mViewContainer.setVisibility(View.VISIBLE);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
                mViewContainer.setAlpha(0.0f);
                final ViewPropertyAnimator animator = mViewContainer.animate();
                animator.alpha(1.0f);
                animator.setDuration(SINGLE_PANE_FADE_IN_DURATION);
            }
        }
    }

    if (mContactHasUpdates) {
        showContactWithUpdates(contactWasLoaded && !contactHadUpdates);
    } else {
        showContactWithoutUpdates();
    }
}

From source file:org.apache.appharness.AppHarnessUI.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setSlaveVisible(boolean value, CallbackContext callbackContext) {
    if (value == slaveVisible) {
        return;/*  w  w  w.j a  v a2 s .  com*/
    }
    if (slaveWebView == null) {
        Log.w(LOG_TAG, "setSlaveVisible: slave not created");
    } else {
        slaveVisible = value;
        ViewPropertyAnimator anim = slaveWebView.getView().animate();
        // Note: Pivot is set in onSizeChanged.
        if (value) {
            anim.scaleX(1.0f).scaleY(1.0f);
            webView.getView().setEnabled(false);
            slaveWebView.getView().setEnabled(true);
            slaveWebView.getView().requestFocus();
        } else {
            anim.scaleX(.25f).scaleY(.25f);
            webView.getView().setEnabled(true);
            slaveWebView.getView().setEnabled(false);
            webView.getView().requestFocus();
        }
        slaveWebViewEngine.setStealTapEvents(!value);
        anim.setDuration(300).setInterpolator(new DecelerateInterpolator(2.0f)).start();
    }
    if (callbackContext != null) {
        callbackContext.success();
    }
}

From source file:com.waz.zclient.pages.main.conversation.SingleImageFragment.java

private void backToConversation(boolean afterFling) {
    if (isClosing) {
        return;// ww  w  .  j a  v  a  2  s  .  co m
    }
    isClosing = true;
    loadClickedImageSizeAndPosition();
    initAnimatingImageView(afterFling);

    restoreRotation();
    getControllerFactory().getSingleImageController().hideSingleImage();
    fadeControls(false);

    PointF currentFocusPoint = messageTouchImageView.getScrollPosition();
    if (currentFocusPoint == null) {
        getControllerFactory().getSingleImageController().clearReferences();
        getFragmentManager().popBackStack();
        return;
    }
    TouchImageView.FocusAndScale startFocusAndScale = new TouchImageView.FocusAndScale(currentFocusPoint.x,
            currentFocusPoint.y, messageTouchImageView.getCurrentZoom());
    TouchImageView.FocusAndScale finishFocusAndScale = new TouchImageView.FocusAndScale(0.5f, 0.5f, 1f);
    if ((MathUtils.floatEqual(currentFocusPoint.x, 0.5f) || MathUtils.floatEqual(currentFocusPoint.y, 0.5f))
            && MathUtils.floatEqual(messageTouchImageView.getCurrentZoom(), 1f)) {
        zoomOutAndRotateBackOnCloseDuration = 1;
    }
    ObjectAnimator
            .ofObject(messageTouchImageView, "focusAndScale", new TouchImageView.FocusAndScaleEvaluator(),
                    startFocusAndScale, finishFocusAndScale)
            .setDuration(zoomOutAndRotateBackOnCloseDuration).start();

    final boolean imageOffScreenInList = getControllerFactory().getSingleImageController()
            .isContainerOutOfScreen();
    ViewPropertyAnimator exitAnimation = animatingImageView.animate();
    if (imageOffScreenInList) {
        exitAnimation.alpha(0);
    } else {
        exitAnimation.x(clickedImageLocation.x).y(clickedImageLocation.y).rotation(0f).scaleX(1f).scaleY(1f);
    }
    exitAnimation.setDuration(openAnimationDuration).setStartDelay(zoomOutAndRotateBackOnCloseDuration)
            .setInterpolator(new Expo.EaseOut()).withStartAction(new Runnable() {
                @Override
                public void run() {
                    animatingImageView.setVisibility(View.VISIBLE);
                    messageTouchImageView.setVisibility(View.GONE);
                    if (imageOffScreenInList) {
                        getControllerFactory().getSingleImageController().getImageContainer()
                                .setVisibility(View.VISIBLE);
                    } else {
                        getControllerFactory().getSingleImageController().getImageContainer()
                                .setVisibility(View.INVISIBLE);
                    }
                    ViewUtils.fadeInView(
                            getControllerFactory().getSingleImageController().getLoadingIndicator(),
                            getResources().getInteger(R.integer.framework_animation_duration_short));
                }
            }).withEndAction(new Runnable() {
                @Override
                public void run() {
                    getControllerFactory().getSingleImageController().getImageContainer()
                            .setVisibility(View.VISIBLE);
                    getControllerFactory().getSingleImageController().clearReferences();
                    getFragmentManager().popBackStack();
                }
            });

    exitAnimation.start();

    background.animate().alpha(0f)
            .setStartDelay(zoomOutAndRotateBackOnCloseDuration + closeAnimationBackgroundDelay)
            .setDuration(openAnimationBackgroundDuration).setInterpolator(new Quart.EaseOut()).start();
}