Example usage for android.view.animation AnimationUtils loadInterpolator

List of usage examples for android.view.animation AnimationUtils loadInterpolator

Introduction

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

Prototype

public static Interpolator loadInterpolator(Context context, @AnimRes @InterpolatorRes int id)
        throws NotFoundException 

Source Link

Document

Loads an Interpolator object from a resource

Usage

From source file:io.plaidapp.ui.DribbbleShot.java

/**
 * Animate in the title, description and author  can't do this in a content transition as they
 * are within the ListView so do it manually.  Also handle the FAB tanslation here so that it
 * plays nicely with #calculateFabPosition
 */// w  w  w.j  av a 2  s  . c  om
private void enterAnimation(boolean isOrientationChange) {
    Interpolator interp = AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in);
    int offset = title.getHeight();
    viewEnterAnimation(title, offset, interp);
    if (description.getVisibility() == View.VISIBLE) {
        offset *= 1.5f;
        viewEnterAnimation(description, offset, interp);
    }
    // animate the fab without touching the alpha as this is handled in the content transition
    offset *= 1.5f;
    float fabTransY = fab.getTranslationY();
    fab.setTranslationY(fabTransY + offset);
    fab.animate().translationY(fabTransY).setDuration(600).setInterpolator(interp).start();
    offset *= 1.5f;
    viewEnterAnimation(shotActions, offset, interp);
    offset *= 1.5f;
    viewEnterAnimation(playerName, offset, interp);
    viewEnterAnimation(playerAvatar, offset, interp);
    viewEnterAnimation(shotTimeAgo, offset, interp);
    back.animate().alpha(1f).setDuration(600).setInterpolator(interp).start();

    if (isOrientationChange) {
        // we rely on the window enter content transition to show the fab. This isn't run on
        // orientation changes so manually show it.
        Animator showFab = ObjectAnimator.ofPropertyValuesHolder(fab,
                PropertyValuesHolder.ofFloat(View.ALPHA, 0f, 1f),
                PropertyValuesHolder.ofFloat(View.SCALE_X, 0f, 1f),
                PropertyValuesHolder.ofFloat(View.SCALE_Y, 0f, 1f));
        showFab.setStartDelay(300L);
        showFab.setDuration(300L);
        showFab.setInterpolator(
                AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in));
        showFab.start();
    }
}

From source file:android.support.v7.internal.app.WindowDecorActionBar.java

public void doShow(boolean fromSystem) {
    if (mCurrentShowAnim != null) {
        mCurrentShowAnim.cancel();/*from w w w.  java  2  s  .  c o m*/
    }
    mContainerView.setVisibility(View.VISIBLE);

    if (mCurWindowVisibility == View.VISIBLE && ALLOW_SHOW_HIDE_ANIMATIONS
            && (mShowHideAnimationEnabled || fromSystem)) {
        // because we're about to ask its window loc
        ViewCompat.setTranslationY(mContainerView, 0f);
        float startingY = -mContainerView.getHeight();
        if (fromSystem) {
            int topLeft[] = { 0, 0 };
            mContainerView.getLocationInWindow(topLeft);
            startingY -= topLeft[1];
        }
        ViewCompat.setTranslationY(mContainerView, startingY);
        ViewPropertyAnimatorCompatSet anim = new ViewPropertyAnimatorCompatSet();
        ViewPropertyAnimatorCompat a = ViewCompat.animate(mContainerView).translationY(0f);
        a.setUpdateListener(mUpdateListener);
        anim.play(a);
        if (mContentAnimations && mContentView != null) {
            ViewCompat.setTranslationY(mContentView, startingY);
            anim.play(ViewCompat.animate(mContentView).translationY(0f));
        }
        if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) {
            ViewCompat.setTranslationY(mSplitView, mSplitView.getHeight());
            mSplitView.setVisibility(View.VISIBLE);
            anim.play(ViewCompat.animate(mSplitView).translationY(0f));
        }
        anim.setInterpolator(AnimationUtils.loadInterpolator(mContext, android.R.anim.decelerate_interpolator));
        anim.setDuration(250);
        // If this is being shown from the system, add a small delay.
        // This is because we will also be animating in the status bar,
        // and these two elements can't be done in lock-step.  So we give
        // a little time for the status bar to start its animation before
        // the action bar animates.  (This corresponds to the corresponding
        // case when hiding, where the status bar has a small delay before
        // starting.)
        anim.setListener(mShowListener);
        mCurrentShowAnim = anim;
        anim.start();
    } else {
        ViewCompat.setAlpha(mContainerView, 1f);
        ViewCompat.setTranslationY(mContainerView, 0);
        if (mContentAnimations && mContentView != null) {
            ViewCompat.setTranslationY(mContentView, 0);
        }
        if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) {
            ViewCompat.setAlpha(mSplitView, 1f);
            ViewCompat.setTranslationY(mSplitView, 0);
            mSplitView.setVisibility(View.VISIBLE);
        }
        mShowListener.onAnimationEnd(null);
    }
    if (mOverlayLayout != null) {
        ViewCompat.requestApplyInsets(mOverlayLayout);
    }
}

From source file:com.brandao.tictactoe.board.BoardFragment.java

public void panelInAnimate(ImageView i, final int symble) {
    boolean animate = mPrefs.getBoolean(Settings.PREF_ANIMATE, Settings.PREF_ANIMATE_DEFAULT);

    if (!animate) {
        finishMove(symble);/*  ww w  .  j a  va 2  s . c  o  m*/
        return;
    }

    Animation anim = AnimationUtils.loadAnimation(getActivity(), R.anim.zoom_in);
    anim.setInterpolator(AnimationUtils.loadInterpolator(getActivity(), android.R.anim.overshoot_interpolator));
    anim.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationEnd(Animation animation) {
            mAnimating = false;
            finishMove(symble);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

        @Override
        public void onAnimationStart(Animation animation) {
            mAnimating = true;
        }
    });

    i.startAnimation(anim);
}

From source file:pl.motyczko.scrollheader.PagerSlidingTabStrip.java

/**
 * Restore the Y position of this view to the last manually requested value.
 * This can be done after the parent has been re-laid out again, where this
 * view's position could have been lost if the view laid outside its
 * parent's bounds.//w  ww.j  a va 2  s.  c  o  m
 *
 * @param duration The duration of the animation
 * @param tabIndex The index to restore
 */
public void restoreYCoordinate(int duration, int tabIndex) {
    final float storedYCoordinate = getStoredYCoordinateForTab(tabIndex);
    if (getTranslationY() == storedYCoordinate || mIsAnimating)
        return;
    if (duration == 0) {
        setTranslationY(storedYCoordinate);
        invalidate();
        return;
    }

    mIsAnimating = true;
    final Interpolator interpolator = AnimationUtils.loadInterpolator(getContext(),
            android.R.anim.accelerate_decelerate_interpolator);

    final ObjectAnimator animator = ObjectAnimator.ofFloat(this, "translationY", storedYCoordinate);
    animator.setInterpolator(interpolator);
    animator.setDuration(duration);
    animator.start();
    animator.addUpdateListener(mAnimatorListener);
    animator.addListener(mAnimatorListener);
}

From source file:com.android.launcher3.folder.Folder.java

public void animateOpen() {
    if (!(getParent() instanceof DragLayer))
        return;// w  ww.  ja  va2  s.  c om

    mContent.completePendingPageChanges();
    if (!mDragInProgress) {
        // Open on the first page.
        mContent.snapToPageImmediately(0);
    }

    // This is set to true in close(), but isn't reset to false until onDropCompleted(). This
    // leads to an inconsistent state if you drag out of the folder and drag back in without
    // dropping. One resulting issue is that replaceFolderWithFinalItem() can be called twice.
    mDeleteFolderOnDropCompleted = false;

    Animator openFolderAnim = null;
    final Runnable onCompleteRunnable;
    if (!Utilities.ATLEAST_LOLLIPOP) {
        positionAndSizeAsIcon();
        centerAboutIcon();

        final ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(this, 1, 1, 1);
        oa.setDuration(mExpandDuration);
        openFolderAnim = oa;

        setLayerType(LAYER_TYPE_HARDWARE, null);
        onCompleteRunnable = new Runnable() {
            @Override
            public void run() {
                setLayerType(LAYER_TYPE_NONE, null);
            }
        };
    } else {
        prepareReveal();
        centerAboutIcon();

        AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
        int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
        int height = getFolderHeight();

        float transX = -0.075f * (width / 2 - getPivotX());
        float transY = -0.075f * (height / 2 - getPivotY());
        setTranslationX(transX);
        setTranslationY(transY);
        PropertyValuesHolder tx = PropertyValuesHolder.ofFloat(TRANSLATION_X, transX, 0);
        PropertyValuesHolder ty = PropertyValuesHolder.ofFloat(TRANSLATION_Y, transY, 0);

        Animator drift = ObjectAnimator.ofPropertyValuesHolder(this, tx, ty);
        drift.setDuration(mMaterialExpandDuration);
        drift.setStartDelay(mMaterialExpandStagger);
        drift.setInterpolator(new LogDecelerateInterpolator(100, 0));

        int rx = (int) Math.max(Math.max(width - getPivotX(), 0), getPivotX());
        int ry = (int) Math.max(Math.max(height - getPivotY(), 0), getPivotY());
        float radius = (float) Math.hypot(rx, ry);

        Animator reveal = new CircleRevealOutlineProvider((int) getPivotX(), (int) getPivotY(), 0, radius)
                .createRevealAnimator(this);
        reveal.setDuration(mMaterialExpandDuration);
        reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));

        mContent.setAlpha(0f);
        Animator iconsAlpha = ObjectAnimator.ofFloat(mContent, "alpha", 0f, 1f);
        iconsAlpha.setDuration(mMaterialExpandDuration);
        iconsAlpha.setStartDelay(mMaterialExpandStagger);
        iconsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));

        mFooter.setAlpha(0f);
        Animator textAlpha = ObjectAnimator.ofFloat(mFooter, "alpha", 0f, 1f);
        textAlpha.setDuration(mMaterialExpandDuration);
        textAlpha.setStartDelay(mMaterialExpandStagger);
        textAlpha.setInterpolator(new AccelerateInterpolator(1.5f));

        anim.play(drift);
        anim.play(iconsAlpha);
        anim.play(textAlpha);
        anim.play(reveal);

        openFolderAnim = anim;

        mContent.setLayerType(LAYER_TYPE_HARDWARE, null);
        mFooter.setLayerType(LAYER_TYPE_HARDWARE, null);
        onCompleteRunnable = new Runnable() {
            @Override
            public void run() {
                mContent.setLayerType(LAYER_TYPE_NONE, null);
                mFooter.setLayerType(LAYER_TYPE_NONE, null);
                mLauncher.getUserEventDispatcher().resetElapsedContainerMillis();
            }
        };
    }
    openFolderAnim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            Utilities.sendCustomAccessibilityEvent(Folder.this, AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
                    mContent.getAccessibilityDescription());
            mState = STATE_ANIMATING;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mState = STATE_OPEN;

            onCompleteRunnable.run();
            mContent.setFocusOnFirstChild();
        }
    });

    // Footer animation
    if (mContent.getPageCount() > 1 && !mInfo.hasOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION)) {
        int footerWidth = mContent.getDesiredWidth() - mFooter.getPaddingLeft() - mFooter.getPaddingRight();

        float textWidth = mFolderName.getPaint().measureText(mFolderName.getText().toString());
        float translation = (footerWidth - textWidth) / 2;
        mFolderName.setTranslationX(mContent.mIsRtl ? -translation : translation);
        mPageIndicator.prepareEntryAnimation();

        // Do not update the flag if we are in drag mode. The flag will be updated, when we
        // actually drop the icon.
        final boolean updateAnimationFlag = !mDragInProgress;
        openFolderAnim.addListener(new AnimatorListenerAdapter() {

            @SuppressLint("InlinedApi")
            @Override
            public void onAnimationEnd(Animator animation) {
                mFolderName.animate().setDuration(FOLDER_NAME_ANIMATION_DURATION).translationX(0)
                        .setInterpolator(Utilities.ATLEAST_LOLLIPOP
                                ? AnimationUtils.loadInterpolator(mLauncher,
                                        android.R.interpolator.fast_out_slow_in)
                                : new LogDecelerateInterpolator(100, 0));
                mPageIndicator.playEntryAnimation();

                if (updateAnimationFlag) {
                    mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, true, mLauncher);
                }
            }
        });
    } else {
        mFolderName.setTranslationX(0);
    }

    mPageIndicator.stopAllAnimations();
    openFolderAnim.start();

    // Make sure the folder picks up the last drag move even if the finger doesn't move.
    if (mDragController.isDragging()) {
        mDragController.forceTouchMove();
    }

    mContent.verifyVisibleHighResIcons(mContent.getNextPage());
}

From source file:com.klinker.android.sliding.MultiShrinkScroller.java

/**
 * Scroll the activity up as the entrace animation.
 * @param scrollToCurrentPosition if true, will scroll from the bottom of the screen to the
 * current position. Otherwise, will scroll from the bottom of the screen to the top of the
 * screen.//from w  w w  . j a  v a2  s. c  o  m
 */
public void performEntranceAnimation(OpenAnimation animation, boolean scrollToCurrentPosition) {
    final int currentPosition = getScroll();
    final int bottomScrollPosition = currentPosition - (getHeight() - getTransparentViewHeight()) + 1;

    final int desiredValue = currentPosition
            + (scrollToCurrentPosition ? currentPosition : getTransparentViewHeight());

    if (animation == OpenAnimation.EXPAND_FROM_VIEW) {
        scrollTo(0, desiredValue);
        runExpansionAnimation();

        openAnimation = animation;
    } else {
        final Interpolator interpolator;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            interpolator = AnimationUtils.loadInterpolator(getContext(),
                    android.R.interpolator.linear_out_slow_in);
        } else {
            interpolator = new DecelerateInterpolator();
        }

        final ObjectAnimator animator = ObjectAnimator.ofInt(this, "scroll", bottomScrollPosition,
                desiredValue);
        animator.setInterpolator(interpolator);
        animator.addUpdateListener(new AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                if (animation.getAnimatedValue().equals(desiredValue) && listener != null) {
                    listener.onEntranceAnimationDone();
                }
            }
        });

        animator.start();
    }

}

From source file:android.support.v7.internal.app.WindowDecorActionBar.java

public void doHide(boolean fromSystem) {
    if (mCurrentShowAnim != null) {
        mCurrentShowAnim.cancel();/*from  w w w. j  a v  a2s . c o  m*/
    }

    if (mCurWindowVisibility == View.VISIBLE && ALLOW_SHOW_HIDE_ANIMATIONS
            && (mShowHideAnimationEnabled || fromSystem)) {
        ViewCompat.setAlpha(mContainerView, 1f);
        mContainerView.setTransitioning(true);
        ViewPropertyAnimatorCompatSet anim = new ViewPropertyAnimatorCompatSet();
        float endingY = -mContainerView.getHeight();
        if (fromSystem) {
            int topLeft[] = { 0, 0 };
            mContainerView.getLocationInWindow(topLeft);
            endingY -= topLeft[1];
        }
        ViewPropertyAnimatorCompat a = ViewCompat.animate(mContainerView).translationY(endingY);
        a.setUpdateListener(mUpdateListener);
        anim.play(a);
        if (mContentAnimations && mContentView != null) {
            anim.play(ViewCompat.animate(mContentView).translationY(endingY));
        }
        if (mSplitView != null && mSplitView.getVisibility() == View.VISIBLE) {
            ViewCompat.setAlpha(mSplitView, 1f);
            anim.play(ViewCompat.animate(mSplitView).translationY(mSplitView.getHeight()));
        }
        anim.setInterpolator(AnimationUtils.loadInterpolator(mContext, android.R.anim.accelerate_interpolator));
        anim.setDuration(250);
        anim.setListener(mHideListener);
        mCurrentShowAnim = anim;
        anim.start();
    } else {
        mHideListener.onAnimationEnd(null);
    }
}

From source file:com.klinker.android.sliding.MultiShrinkScroller.java

public void runExpansionAnimation() {

    final Interpolator interpolator;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        interpolator = AnimationUtils.loadInterpolator(getContext(), android.R.interpolator.linear_out_slow_in);
    } else {/*from   www .ja v a 2  s.com*/
        interpolator = new DecelerateInterpolator();
    }

    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int screenHeight = size.y;
    int screenWidth = size.x;

    final ValueAnimator heightExpansion = ValueAnimator.ofInt(expansionViewHeight, getHeight());
    heightExpansion.setInterpolator(interpolator);
    heightExpansion.setDuration(ANIMATION_DURATION);
    heightExpansion.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int val = (int) animation.getAnimatedValue();

            ViewGroup.LayoutParams params = getLayoutParams();
            params.height = val;
            setLayoutParams(params);
        }
    });
    heightExpansion.start();

    final ValueAnimator widthExpansion = ValueAnimator.ofInt(expansionViewWidth, getWidth());
    widthExpansion.setInterpolator(interpolator);
    widthExpansion.setDuration(ANIMATION_DURATION);
    widthExpansion.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int val = (int) animation.getAnimatedValue();

            ViewGroup.LayoutParams params = getLayoutParams();
            params.width = val;
            setLayoutParams(params);
        }
    });
    widthExpansion.start();

    ObjectAnimator translationX = ObjectAnimator.ofFloat(this, View.TRANSLATION_X, expansionLeftOffset, 0f);
    translationX.setInterpolator(interpolator);
    translationX.setDuration(ANIMATION_DURATION);
    translationX.start();

    ObjectAnimator translationY = ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, expansionTopOffset, 0f);
    translationY.setInterpolator(interpolator);
    translationY.setDuration(ANIMATION_DURATION);
    translationY.start();
}

From source file:com.actionbarsherlock.internal.widget.IcsProgressBar.java

/**
 * Sets the acceleration curve for the indeterminate animation.
 * The interpolator is loaded as a resource from the specified context.
 *
 * @param context The application environment
 * @param resID The resource identifier of the interpolator to load
 *//*from   ww  w  . j  a  va2s . co  m*/
public void setInterpolator(Context context, int resID) {
    setInterpolator(AnimationUtils.loadInterpolator(context, resID));
}

From source file:com.klinker.android.sliding.MultiShrinkScroller.java

public void reverseExpansionAnimation() {

    final Interpolator interpolator;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        interpolator = AnimationUtils.loadInterpolator(getContext(), android.R.interpolator.linear_out_slow_in);
    } else {/* ww  w.  ja v a 2s  .  c o m*/
        interpolator = new DecelerateInterpolator();
    }

    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int screenHeight = size.y;
    int screenWidth = size.x;

    final ValueAnimator heightExpansion = ValueAnimator.ofInt(screenHeight, expansionViewHeight);
    heightExpansion.setInterpolator(interpolator);
    heightExpansion.setDuration(ANIMATION_DURATION);
    heightExpansion.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int val = (int) animation.getAnimatedValue();

            ViewGroup.LayoutParams params = getLayoutParams();
            params.height = val;
            setLayoutParams(params);
        }
    });
    heightExpansion.start();

    final ValueAnimator widthExpansion = ValueAnimator.ofInt(getWidth(), expansionViewWidth);
    widthExpansion.setInterpolator(interpolator);
    widthExpansion.setDuration(ANIMATION_DURATION);
    widthExpansion.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int val = (int) animation.getAnimatedValue();

            ViewGroup.LayoutParams params = getLayoutParams();
            params.width = val;
            setLayoutParams(params);
        }
    });
    widthExpansion.start();

    ObjectAnimator translationX = ObjectAnimator.ofFloat(this, View.TRANSLATION_X, 0f, expansionLeftOffset);
    translationX.setInterpolator(interpolator);
    translationX.setDuration(ANIMATION_DURATION);
    translationX.start();

    ObjectAnimator translationY = ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, 0f, expansionTopOffset);
    translationY.setInterpolator(interpolator);
    translationY.setDuration(ANIMATION_DURATION);
    translationY.addListener(exitAnimationListner);
    translationY.start();
}