Example usage for android.view.animation DecelerateInterpolator DecelerateInterpolator

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

Introduction

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

Prototype

public DecelerateInterpolator() 

Source Link

Usage

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

private Animator makeOutAnimation() {
    ObjectAnimator buttonAnimator = ObjectAnimator.ofFloat(mClose, "translationX",
            -mClose.getWidth() - ((MarginLayoutParams) mClose.getLayoutParams()).leftMargin);
    buttonAnimator.setDuration(200);/*  ww w .java  2  s .c om*/
    buttonAnimator.addListener(this);
    buttonAnimator.setInterpolator(new DecelerateInterpolator());

    AnimatorSet set = new AnimatorSet();
    AnimatorSet.Builder b = set.play(buttonAnimator);

    if (mMenuView != null) {
        final int count = mMenuView.getChildCount();
        if (count > 0) {
            for (int i = 0; i < 0; i++) {
                AnimatorProxy child = AnimatorProxy.wrap(mMenuView.getChildAt(i));
                child.setScaleY(0);
                ObjectAnimator a = ObjectAnimator.ofFloat(child, "scaleY", 0);
                a.setDuration(100);
                a.setStartDelay(i * 70);
                b.with(a);
            }
        }
    }

    return set;
}

From source file:io.digibyte.tools.animation.BRAnimator.java

public static void animateSignalSlide(ViewGroup signalLayout, final boolean reverse,
        final OnSlideAnimationEnd listener) {
    float translationY = signalLayout.getTranslationY();
    float signalHeight = signalLayout.getHeight();
    signalLayout.setTranslationY(reverse ? translationY : translationY + signalHeight);

    signalLayout.animate().translationY(reverse ? BreadActivity.screenParametersPoint.y : translationY)
            .setDuration(SLIDE_ANIMATION_DURATION)
            .setInterpolator(reverse ? new DecelerateInterpolator() : new OvershootInterpolator(0.7f))
            .setListener(new AnimatorListenerAdapter() {
                @Override/*from   w  w w  . j  a  va 2  s. c  o  m*/
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    if (listener != null)
                        listener.onAnimationEnd();
                }
            });

}

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  www . j  a va2  s.co m
        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.anyline.reactnative.Document4Activity.java

private void showErrorMessageUiAnimated(String message) {
    if (lastErrorRecieved == 0) {
        // the cleanup takes care of removing the message after some time if the error did not show up again
        handler.post(errorMessageCleanup);
    }/*www.  ja  v a  2s  .  c  o m*/
    lastErrorRecieved = System.currentTimeMillis();
    if (errorMessageAnimator != null
            && (errorMessageAnimator.isRunning() || errorMessage.getText().equals(message))) {
        return;
    }

    errorMessageLayout.setVisibility(View.VISIBLE);
    errorMessage.setBackgroundColor(ContextCompat.getColor(this,
            getResources().getIdentifier("anyline_blue_darker", "color", getPackageName())));
    errorMessage.setAlpha(0f);
    errorMessage.setText(message);
    errorMessageAnimator = ObjectAnimator.ofFloat(errorMessage, "alpha", 0f, 1f);
    errorMessageAnimator.setDuration(ERROR_MESSAGE_DELAY);
    errorMessageAnimator.setInterpolator(new DecelerateInterpolator());
    errorMessageAnimator.start();
}

From source file:orbin.deskclock.timer.TimerFragment.java

/**
 * @param timerToRemove the timer to be removed during the animation
 *//*from   w ww.j  a v a 2s.c  om*/
private void animateTimerRemove(final Timer timerToRemove) {
    final long duration = UiDataModel.getUiDataModel().getShortAnimationDuration();

    final Animator fadeOut = ObjectAnimator.ofFloat(mViewPager, ALPHA, 1, 0);
    fadeOut.setDuration(duration);
    fadeOut.setInterpolator(new DecelerateInterpolator());
    fadeOut.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            DataModel.getDataModel().removeTimer(timerToRemove);
            Events.sendTimerEvent(R.string.action_delete, R.string.label_deskclock);
        }
    });

    final Animator fadeIn = ObjectAnimator.ofFloat(mViewPager, ALPHA, 0, 1);
    fadeIn.setDuration(duration);
    fadeIn.setInterpolator(new AccelerateInterpolator());

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(fadeOut).before(fadeIn);
    animatorSet.start();
}

From source file:com.songcode.materialnotes.ui.NoteEditActivity.java

private void animateRevealShow(View targetview, View startView) {
    if (isActionInsertOrEdit()) {
        final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        int cx = startView.getLeft() + (startView.getWidth() / 2); //middle of button
        int cy = startView.getTop() + (startView.getHeight() / 2); //middle of button
        int radius = (int) Math.sqrt(Math.pow(cx, 2) + Math.pow(cy, 2)); //hypotenuse to top left

        Animator anim = ViewAnimationUtils.createCircularReveal(targetview, cx, cy, 0, radius);
        targetview.setVisibility(View.VISIBLE);
        anim.setInterpolator(new DecelerateInterpolator());
        anim.addListener(new Animator.AnimatorListener() {
            @Override//from w  w  w .j  av  a 2 s.  co m
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                mNoteEditor.requestFocus();
                imm.showSoftInput(mNoteEditor, 0);
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        anim.setDuration(ANIM_DURATION);
        anim.start();
    } else if (isActionActionView()) {
        mAnimBackGroudView.animate().scaleX(.92f).scaleY(.92f).alpha(.6f).setDuration(ANIM_DURATION)
                .setInterpolator(new AccelerateInterpolator()).start();
        mNoteEditor.animate().alpha(1).setStartDelay(400).setDuration(ANIM_DURATION);
        ViewCompat.setTransitionName(mAnimTargetView, "target_anim_view");
    }
}

From source file:com.android.deskclock.timer.TimerFragment.java

/**
 * @param toView one of {@link #mTimersView} or {@link #mCreateTimerView}
 * @param timerToRemove the timer to be removed during the animation; {@code null} if no timer
 *      should be removed//from   w  ww.  j  av  a2s  .  com
 */
private void animateToView(View toView, final Timer timerToRemove) {
    if (mCurrentView == toView) {
        throw new IllegalStateException("toView is already the current view");
    }

    final boolean toTimers = toView == mTimersView;

    // Avoid double-taps by enabling/disabling the set of buttons active on the new view.
    mLeftButton.setEnabled(toTimers);
    mRightButton.setEnabled(toTimers);
    mCancelCreateButton.setEnabled(!toTimers);

    final Animator rotateFrom = ObjectAnimator.ofFloat(mCurrentView, SCALE_X, 1, 0);
    rotateFrom.setDuration(mShortAnimationDuration);
    rotateFrom.setInterpolator(new DecelerateInterpolator());
    rotateFrom.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (timerToRemove != null) {
                DataModel.getDataModel().removeTimer(timerToRemove);
                Events.sendTimerEvent(R.string.action_delete, R.string.label_deskclock);
            }

            mCurrentView.setScaleX(1);
            if (toTimers) {
                showTimersView();
            } else {
                showCreateTimerView();
            }
        }
    });

    final Animator rotateTo = ObjectAnimator.ofFloat(toView, SCALE_X, 0, 1);
    rotateTo.setDuration(mShortAnimationDuration);
    rotateTo.setInterpolator(new AccelerateInterpolator());

    final float preScale = toTimers ? 0 : 1;
    final float postScale = toTimers ? 1 : 0;
    final Animator fabAnimator = getScaleAnimator(mFab, preScale, postScale);
    final Animator leftButtonAnimator = getScaleAnimator(mLeftButton, preScale, postScale);
    final Animator rightButtonAnimator = getScaleAnimator(mRightButton, preScale, postScale);

    final AnimatorSet buttons = new AnimatorSet();
    buttons.setDuration(toTimers ? mMediumAnimationDuration : mShortAnimationDuration);
    buttons.play(leftButtonAnimator).with(rightButtonAnimator).with(fabAnimator);
    buttons.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mLeftButton.setVisibility(toTimers ? VISIBLE : INVISIBLE);
            mRightButton.setVisibility(toTimers ? VISIBLE : INVISIBLE);

            mFab.setScaleX(1);
            mFab.setScaleY(1);
            mLeftButton.setScaleX(1);
            mLeftButton.setScaleY(1);
            mRightButton.setScaleX(1);
            mRightButton.setScaleY(1);
        }
    });

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(rotateFrom).before(rotateTo).with(buttons);
    animatorSet.start();
}

From source file:com.taobao.weex.ui.animation.WXAnimationModule.java

private static @Nullable Interpolator createTimeInterpolator(@NonNull WXAnimationBean animation) {
    String interpolator = animation.timingFunction;
    if (!TextUtils.isEmpty(interpolator)) {
        switch (interpolator) {
        case WXAnimationBean.EASE_IN:
            return new AccelerateInterpolator();
        case WXAnimationBean.EASE_OUT:
            return new DecelerateInterpolator();
        case WXAnimationBean.EASE_IN_OUT:
            return new AccelerateDecelerateInterpolator();
        case WXAnimationBean.LINEAR:
            return new LinearInterpolator();
        default:/*from w  w w. ja  va  2 s  .  c  o  m*/
            //Parse cubic-bezier
            try {
                SingleFunctionParser<Float> parser = new SingleFunctionParser<>(animation.timingFunction,
                        new SingleFunctionParser.FlatMapper<Float>() {
                            @Override
                            public Float map(String raw) {
                                return Float.parseFloat(raw);
                            }
                        });
                List<Float> params = parser.parse(WXAnimationBean.CUBIC_BEZIER);
                if (params != null && params.size() == WXAnimationBean.NUM_CUBIC_PARAM) {
                    return PathInterpolatorCompat.create(params.get(0), params.get(1), params.get(2),
                            params.get(3));
                } else {
                    return null;
                }
            } catch (RuntimeException e) {
                return null;
            }
        }
    }
    return null;
}

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

public static void animateScale(View v, boolean animate, boolean visible) {
    v.setPivotX(v.getMeasuredWidth() / 2);
    v.setPivotY(v.getMeasuredHeight() / 2);

    if (visible) {
        if (animate) {
            v.animate().scaleX(1.0f).scaleY(1.0f).alpha(1.0f).translationY(0.0f).setDuration(400)
                    .setInterpolator(new DecelerateInterpolator()).start();
        } else {/* ww w .j  a v  a  2 s. c om*/
            v.setScaleX(1.0f);
            v.setScaleY(1.0f);
            v.setAlpha(1.0f);
            v.setTranslationY(0.0f);
        }
    } else {
        if (animate) {
            v.animate().scaleX(0.0f).scaleY(0.0f).alpha(0.0f).translationY(v.getHeight() / 4).setDuration(400)
                    .setInterpolator(new DecelerateInterpolator()).start();
        } else {
            v.setScaleX(0.0f);
            v.setScaleY(0.0f);
            v.setAlpha(0.0f);
            v.setTranslationY(v.getHeight() / 4);
        }
    }
}

From source file:com.anyline.reactnative.Document4Activity.java

private void showHighlightErrorMessageUiAnimated(String message) {
    lastErrorRecieved = System.currentTimeMillis();
    errorMessageLayout.setVisibility(View.VISIBLE);
    errorMessage.setBackgroundColor(ContextCompat.getColor(this,
            getResources().getIdentifier("anyline_red", "color", getPackageName())));
    errorMessage.setAlpha(0f);//from  www  . j  ava2s.c om
    errorMessage.setText(message);

    if (errorMessageAnimator != null && errorMessageAnimator.isRunning()) {
        errorMessageAnimator.cancel();
    }

    errorMessageAnimator = ObjectAnimator.ofFloat(errorMessage, "alpha", 0f, 1f);
    errorMessageAnimator.setDuration(ERROR_MESSAGE_DELAY);
    errorMessageAnimator.setInterpolator(new DecelerateInterpolator());
    errorMessageAnimator.setRepeatMode(ValueAnimator.REVERSE);
    errorMessageAnimator.setRepeatCount(1);
    errorMessageAnimator.start();
}