Example usage for android.animation AnimatorSet start

List of usage examples for android.animation AnimatorSet start

Introduction

In this page you can find the example usage for android.animation AnimatorSet start.

Prototype

@SuppressWarnings("unchecked")
@Override
public void start() 

Source Link

Document

Starting this AnimatorSet will, in turn, start the animations for which it is responsible.

Usage

From source file:com.android.calculator2.Calculator.java

private void onResult(boolean animate) {
    // Calculate the textSize that would be used to display the result in the formula.
    // For scrollable results just use the minimum textSize to maximize the number of digits
    // that are visible on screen.
    float textSize = mFormulaText.getMinimumTextSize();
    if (!mResultText.isScrollable()) {
        textSize = mFormulaText.getVariableTextSize(mResultText.getText().toString());
    }//  w w  w . j  a v  a  2  s . c o  m

    // Scale the result to match the calculated textSize, minimizing the jump-cut transition
    // when a result is reused in a subsequent expression.
    final float resultScale = textSize / mResultText.getTextSize();

    // Set the result's pivot to match its gravity.
    mResultText.setPivotX(mResultText.getWidth() - mResultText.getPaddingRight());
    mResultText.setPivotY(mResultText.getHeight() - mResultText.getPaddingBottom());

    // Calculate the necessary translations so the result takes the place of the formula and
    // the formula moves off the top of the screen.
    final float resultTranslationY = (mFormulaText.getBottom() - mResultText.getBottom())
            - (mFormulaText.getPaddingBottom() - mResultText.getPaddingBottom());
    final float formulaTranslationY = -mFormulaText.getBottom();

    // Change the result's textColor to match the formula.
    final int formulaTextColor = mFormulaText.getCurrentTextColor();

    if (animate) {
        mResultText.announceForAccessibility(getResources().getString(R.string.desc_eq));
        mResultText.announceForAccessibility(mResultText.getText());
        setState(CalculatorState.ANIMATE);
        final AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(
                ObjectAnimator.ofPropertyValuesHolder(mResultText,
                        PropertyValuesHolder.ofFloat(View.SCALE_X, resultScale),
                        PropertyValuesHolder.ofFloat(View.SCALE_Y, resultScale),
                        PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, resultTranslationY)),
                ObjectAnimator.ofArgb(mResultText, TEXT_COLOR, formulaTextColor),
                ObjectAnimator.ofFloat(mFormulaText, View.TRANSLATION_Y, formulaTranslationY));
        animatorSet.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                setState(CalculatorState.RESULT);
                mCurrentAnimator = null;
            }
        });

        mCurrentAnimator = animatorSet;
        animatorSet.start();
    } else /* No animation desired; get there fast, e.g. when restarting */ {
        mResultText.setScaleX(resultScale);
        mResultText.setScaleY(resultScale);
        mResultText.setTranslationY(resultTranslationY);
        mResultText.setTextColor(formulaTextColor);
        mFormulaText.setTranslationY(formulaTranslationY);
        setState(CalculatorState.RESULT);
    }
}

From source file:com.stanleyidesis.quotograph.ui.activity.LWQSettingsActivity.java

void animateWallpaperActions(final boolean dismiss) {
    AnimatorSet animatorSet = new AnimatorSet();
    Animator shareButtonAnimator = generateAnimator(shareButton, dismiss, 0);
    animatorSet.playTogether(shareButtonAnimator, generateAnimator(saveButton, dismiss, 20),
            generateAnimator(skipButton, dismiss, 35));
    animatorSet.start();
}

From source file:com.tmall.wireless.tangram.ext.SwipeItemTouchListener.java

private void resetViews(RecyclerView recyclerView, final int swipingType, final boolean reachActionEdge,
        final int direction) {
    int contentWidth = recyclerView.getWidth();
    AnimatorSet animatorSet = new AnimatorSet();
    List<Animator> list = new ArrayList<>();
    String translation = "translationX";
    if (swipingType == SWIPING_VER) {
        translation = "translationY";
    }/*  w ww.  j  av a 2 s . c o  m*/
    for (View view : mChildList) {
        ObjectAnimator animator;
        if (reachActionEdge) {
            animator = ObjectAnimator.ofFloat(view, translation, contentWidth * direction)
                    .setDuration(ANIMATE_DURATION);
            animator.setInterpolator(new AccelerateInterpolator());
        } else {
            animator = ObjectAnimator.ofFloat(view, translation, 0).setDuration(ANIMATE_DURATION);
            animator.setInterpolator(new DecelerateInterpolator());
        }
        list.add(animator);
    }
    animatorSet.playTogether(list);
    animatorSet.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {

        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (swipingType == SWIPING_HOR && reachActionEdge) {
                if (mSwipeCardRef != null && mSwipeCardRef.get() != null) {
                    SwipeCard swipeCard = mSwipeCardRef.get();
                    swipeCard.switchTo(swipeCard.getCurrentIndex() - direction);
                }
            }
            mChildList.clear();
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });
    animatorSet.start();

    if (swipingType == SWIPING_VER) {
        if (pullFromEndListener != null) {
            if (mDistanceY < 0 && (mDistanceY < -pullFromEndListener.getPullEdge())) {
                pullFromEndListener.onAction();
            } else {
                pullFromEndListener.onReset();
            }
        }
    }

    swipeType = SWIPING_NONE;
}

From source file:com.b44t.ui.ActionBar.BottomSheet.java

private void startOpenAnimation() {
    containerView.setVisibility(View.VISIBLE);

    if (!onCustomOpenAnimation()) {
        if (Build.VERSION.SDK_INT >= 20) {
            container.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }/*from w  ww  .  j  av a  2 s.  c  o m*/
        containerView.setTranslationY(containerView.getMeasuredHeight());
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(ObjectAnimator.ofFloat(containerView, "translationY", 0),
                ObjectAnimator.ofInt(backDrawable, "alpha", 51));
        animatorSet.setDuration(200);
        animatorSet.setStartDelay(20);
        animatorSet.setInterpolator(new DecelerateInterpolator());
        animatorSet.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                    currentSheetAnimation = null;
                    if (delegate != null) {
                        delegate.onOpenAnimationEnd();
                    }
                    container.setLayerType(View.LAYER_TYPE_NONE, null);
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                    currentSheetAnimation = null;
                }
            }
        });
        animatorSet.start();
        currentSheetAnimation = animatorSet;
    }
}

From source file:com.arlib.floatingsearchview.FloatingSearchView.java

private void transitionInLeftSection(boolean withAnim) {

    if (mSearchProgress.getVisibility() != View.VISIBLE) {
        mLeftAction.setVisibility(View.VISIBLE);
    } else {/*from w  w w.j  a v  a2 s.co  m*/
        mLeftAction.setVisibility(View.INVISIBLE);
    }

    switch (mLeftActionMode) {
    case LEFT_ACTION_MODE_SHOW_HAMBURGER:
        openMenuDrawable(mMenuBtnDrawable, withAnim);
        if (!mMenuOpen) {
            break;
        }
        break;
    case LEFT_ACTION_MODE_SHOW_SEARCH:
        mLeftAction.setImageDrawable(mIconBackArrow);
        if (withAnim) {
            mLeftAction.setRotation(45);
            mLeftAction.setAlpha(0.0f);
            ObjectAnimator rotateAnim = ViewPropertyObjectAnimator.animate(mLeftAction).rotation(0).get();
            ObjectAnimator fadeAnim = ViewPropertyObjectAnimator.animate(mLeftAction).alpha(1.0f).get();
            AnimatorSet animSet = new AnimatorSet();
            animSet.setDuration(500);
            animSet.playTogether(rotateAnim, fadeAnim);
            animSet.start();
        }
        break;
    case LEFT_ACTION_MODE_SHOW_HOME:
        //do nothing
        break;
    case LEFT_ACTION_MODE_NO_LEFT_ACTION:
        mLeftAction.setImageDrawable(mIconBackArrow);

        if (withAnim) {
            ObjectAnimator searchInputTransXAnim = ViewPropertyObjectAnimator.animate(mSearchInputParent)
                    .translationX(0).get();

            mLeftAction.setScaleX(0.5f);
            mLeftAction.setScaleY(0.5f);
            mLeftAction.setAlpha(0.0f);
            mLeftAction.setTranslationX(Util.dpToPx(8));
            ObjectAnimator transXArrowAnim = ViewPropertyObjectAnimator.animate(mLeftAction).translationX(1.0f)
                    .get();
            ObjectAnimator scaleXArrowAnim = ViewPropertyObjectAnimator.animate(mLeftAction).scaleX(1.0f).get();
            ObjectAnimator scaleYArrowAnim = ViewPropertyObjectAnimator.animate(mLeftAction).scaleY(1.0f).get();
            ObjectAnimator fadeArrowAnim = ViewPropertyObjectAnimator.animate(mLeftAction).alpha(1.0f).get();
            transXArrowAnim.setStartDelay(150);
            scaleXArrowAnim.setStartDelay(150);
            scaleYArrowAnim.setStartDelay(150);
            fadeArrowAnim.setStartDelay(150);

            AnimatorSet animSet = new AnimatorSet();
            animSet.setDuration(500);
            animSet.playTogether(searchInputTransXAnim, transXArrowAnim, scaleXArrowAnim, scaleYArrowAnim,
                    fadeArrowAnim);
            animSet.start();
        } else {
            mSearchInputParent.setTranslationX(0);
        }
        break;
    }
}

From source file:com.hamzahrmalik.calculator2.Calculator.java

private void onResult(final String result) {
    // Calculate the values needed to perform the scale and translation
    // animations,
    // accounting for how the scale will affect the final position of the
    // text./*from ww w  . j  a va 2  s.  c om*/
    final float resultScale = mFormulaEditText.getVariableTextSize(result) / mResultEditText.getTextSize();
    final float resultTranslationX = (1.0f - resultScale)
            * (mResultEditText.getWidth() / 2.0f - mResultEditText.getPaddingEnd());
    final float resultTranslationY = (1.0f - resultScale)
            * (mResultEditText.getHeight() / 2.0f - mResultEditText.getPaddingBottom())
            + (mFormulaEditText.getBottom() - mResultEditText.getBottom())
            + (mResultEditText.getPaddingBottom() - mFormulaEditText.getPaddingBottom());
    final float formulaTranslationY = -mFormulaEditText.getBottom();

    // Use a value animator to fade to the final text color over the course
    // of the animation.
    final int resultTextColor = mResultEditText.getCurrentTextColor();
    final int formulaTextColor = mFormulaEditText.getCurrentTextColor();
    final ValueAnimator textColorAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), resultTextColor,
            formulaTextColor);
    textColorAnimator.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            /*
             * mResultEditText.setTextColor((int) valueAnimator
             * .getAnimatedValue());
             */
        }
    });

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(textColorAnimator,
            ObjectAnimator.ofFloat(mResultEditText, View.SCALE_X, resultScale),
            ObjectAnimator.ofFloat(mResultEditText, View.SCALE_Y, resultScale),
            ObjectAnimator.ofFloat(mResultEditText, View.TRANSLATION_X, resultTranslationX),
            ObjectAnimator.ofFloat(mResultEditText, View.TRANSLATION_Y, resultTranslationY),
            ObjectAnimator.ofFloat(mFormulaEditText, View.TRANSLATION_Y, formulaTranslationY));
    animatorSet.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            mResultEditText.setText(result);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            // Reset all of the values modified during the animation.
            mResultEditText.setTextColor(resultTextColor);
            mResultEditText.setScaleX(1.0f);
            mResultEditText.setScaleY(1.0f);
            mResultEditText.setTranslationX(0.0f);
            mResultEditText.setTranslationY(0.0f);
            mFormulaEditText.setTranslationY(0.0f);

            // Finally update the formula to use the current result.
            mFormulaEditText.setText(result);
            setState(CalculatorState.RESULT);

            mCurrentAnimator = null;
        }
    });

    mCurrentAnimator = animatorSet;
    animatorSet.start();
}

From source file:kr.wdream.ui.ActionBar.BottomSheet.java

private void startOpenAnimation() {
    if (dismissed) {
        return;//from   www.j a va 2 s .  c  o  m
    }
    containerView.setVisibility(View.VISIBLE);

    if (!onCustomOpenAnimation()) {
        if (Build.VERSION.SDK_INT >= 20) {
            container.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }
        containerView.setTranslationY(containerView.getMeasuredHeight());
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(ObjectAnimator.ofFloat(containerView, "translationY", 0),
                ObjectAnimator.ofInt(backDrawable, "alpha", 51));
        animatorSet.setDuration(200);
        animatorSet.setStartDelay(20);
        animatorSet.setInterpolator(new DecelerateInterpolator());
        animatorSet.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                    currentSheetAnimation = null;
                    if (delegate != null) {
                        delegate.onOpenAnimationEnd();
                    }
                    container.setLayerType(View.LAYER_TYPE_NONE, null);
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                    currentSheetAnimation = null;
                }
            }
        });
        animatorSet.start();
        currentSheetAnimation = animatorSet;
    }
}

From source file:org.michaelbel.bottomsheet.BottomSheet.java

private void startOpenAnimation() {
    containerView.setVisibility(View.VISIBLE);

    if (Build.VERSION.SDK_INT >= 20) {
        container.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }/*from   www  .  j  a v a 2s. c o m*/

    containerView.setTranslationY(containerView.getMeasuredHeight());
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(containerView, "translationY", 0),
            ObjectAnimator.ofInt(backDrawable, "alpha", 51));
    animatorSet.setDuration(200);
    animatorSet.setStartDelay(20);
    animatorSet.setInterpolator(new DecelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                currentSheetAnimation = null;
                container.setLayerType(View.LAYER_TYPE_NONE, null);
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            super.onAnimationCancel(animation);
            if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                currentSheetAnimation = null;
            }
        }
    });
    animatorSet.start();
    currentSheetAnimation = animatorSet;
}

From source file:com.arlib.floatingsearchview.FloatingSearchView.java

private void transitionOutLeftSection(boolean withAnim) {

    switch (mLeftActionMode) {
    case LEFT_ACTION_MODE_SHOW_HAMBURGER:
        closeMenuDrawable(mMenuBtnDrawable, withAnim);
        break;/*w  ww .  j  a  v  a 2 s  . c o  m*/
    case LEFT_ACTION_MODE_SHOW_SEARCH:
        changeIcon(mLeftAction, mIconSearch, withAnim);
        break;
    case LEFT_ACTION_MODE_SHOW_HOME:
        //do nothing
        break;
    case LEFT_ACTION_MODE_NO_LEFT_ACTION:
        mLeftAction.setImageDrawable(mIconBackArrow);

        if (withAnim) {
            ObjectAnimator searchInputTransXAnim = ViewPropertyObjectAnimator.animate(mSearchInputParent)
                    .translationX(-Util.dpToPx(LEFT_MENU_WIDTH_AND_MARGIN_START_DP)).get();

            ObjectAnimator scaleXArrowAnim = ViewPropertyObjectAnimator.animate(mLeftAction).scaleX(0.5f).get();
            ObjectAnimator scaleYArrowAnim = ViewPropertyObjectAnimator.animate(mLeftAction).scaleY(0.5f).get();
            ObjectAnimator fadeArrowAnim = ViewPropertyObjectAnimator.animate(mLeftAction).alpha(0.5f).get();
            scaleXArrowAnim.setDuration(300);
            scaleYArrowAnim.setDuration(300);
            fadeArrowAnim.setDuration(300);
            scaleXArrowAnim.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {

                    //restore normal state
                    mLeftAction.setScaleX(1.0f);
                    mLeftAction.setScaleY(1.0f);
                    mLeftAction.setAlpha(1.0f);
                    mLeftAction.setVisibility(View.INVISIBLE);
                }
            });

            AnimatorSet animSet = new AnimatorSet();
            animSet.setDuration(350);
            animSet.playTogether(scaleXArrowAnim, scaleYArrowAnim, fadeArrowAnim, searchInputTransXAnim);
            animSet.start();
        } else {
            mLeftAction.setVisibility(View.INVISIBLE);
        }
        break;
    }
}

From source file:org.telegram.ui.ChangePhoneActivity.java

public void setPage(int page, boolean animated, Bundle params, boolean back) {
    if (page == 3) {
        doneButton.setVisibility(View.GONE);
    } else {/*www.j av  a2 s.com*/
        if (page == 0) {
            checkPermissions = true;
        }
        doneButton.setVisibility(View.VISIBLE);
    }
    final SlideView outView = views[currentViewNum];
    final SlideView newView = views[page];
    currentViewNum = page;

    newView.setParams(params);
    actionBar.setTitle(newView.getHeaderName());
    newView.onShow();
    newView.setX(back ? -AndroidUtilities.displaySize.x : AndroidUtilities.displaySize.x);

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.setDuration(300);
    animatorSet.playTogether(
            ObjectAnimator.ofFloat(outView, "translationX",
                    back ? AndroidUtilities.displaySize.x : -AndroidUtilities.displaySize.x),
            ObjectAnimator.ofFloat(newView, "translationX", 0));
    animatorSet.addListener(new AnimatorListenerAdapterProxy() {
        @Override
        public void onAnimationStart(Animator animation) {
            newView.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            outView.setVisibility(View.GONE);
            outView.setX(0);
        }
    });
    animatorSet.start();
}