Example usage for android.animation AnimatorSet AnimatorSet

List of usage examples for android.animation AnimatorSet AnimatorSet

Introduction

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

Prototype

public AnimatorSet() 

Source Link

Usage

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  w ww .  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:com.itsronald.widget.IndicatorDotPathView.java

@NonNull
private static Animator scaleAnimator(final View view, float originalScale, float scaleX, float scaleY) {
    final Animator animator;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        final PropertyValuesHolder scaleXProperty = PropertyValuesHolder.ofFloat(View.SCALE_X, originalScale,
                scaleX);//from   w  ww  .j ava 2s  .co m
        final PropertyValuesHolder scaleYProperty = PropertyValuesHolder.ofFloat(View.SCALE_Y, originalScale,
                scaleY);
        animator = ObjectAnimator.ofPropertyValuesHolder(view, scaleXProperty, scaleYProperty);
    } else {
        final Animator scaleXAnimator = ObjectAnimator.ofFloat(view, "scaleX", originalScale, scaleX);
        final Animator scaleYAnimator = ObjectAnimator.ofFloat(view, "scaleY", originalScale, scaleY);

        final AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(scaleXAnimator, scaleYAnimator);
        animator = animatorSet;
    }
    return animator;
}

From source file:io.romain.passport.ui.AddCityActivity.java

private void showLoadingSpinner() {
    View view = getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }/*from   www . j  a v a2s .c  o m*/

    ObjectAnimator a = ObjectAnimator.ofFloat(mLoading, View.ALPHA, 0, 1);
    a.addListener(new SimpleAnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
            mLoading.setAlpha(0);
            mLoading.setVisibility(View.VISIBLE);
        }
    });
    ObjectAnimator b = ObjectAnimator.ofFloat(mContainer, View.ALPHA, 1, 0);
    b.addListener(new SimpleAnimatorListener() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mContainer.setVisibility(View.INVISIBLE);
        }
    });

    AnimatorSet transition = new AnimatorSet();
    transition.playTogether(a, b);
    transition.setDuration(300);
    transition.setInterpolator(AnimUtils.getFastOutSlowInInterpolator(this));

    transition.start();
}

From source file:com.arlib.floatingsearchview.util.view.MenuView.java

/**
 * Shows all the menu items that were hidden by hideIfRoomItems(boolean withAnim)
 *
 * @param withAnim// w ww .  j  ava  2  s  .co  m
 */
public void showIfRoomItems(boolean withAnim) {

    if (mMenu == -1)
        return;

    cancelChildAnimListAndClear();

    if (mMenuItems.isEmpty())
        return;

    anims = new ArrayList<>();

    for (int i = 0; i < getChildCount(); i++) {

        final View currentView = getChildAt(i);

        if (i < mActionItems.size()) {
            ImageView action = (ImageView) currentView;
            final MenuItem actionItem = mActionItems.get(i);
            action.setImageDrawable(Util.setIconColor(actionItem.getIcon(), mActionIconColor));

            action.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (mMenuCallback != null)
                        mMenuCallback.onMenuItemSelected(mMenuBuilder, actionItem);
                }
            });
        }

        //todo go over logic
        int animDuration = withAnim ? SHOW_IF_ROOM_ITEMS_ANIM_DURATION : 0;

        Interpolator interpolator = new DecelerateInterpolator();

        //todo check logic
        if (i > mActionShowAlwaysItems.size() - 1)
            interpolator = new LinearInterpolator();

        currentView.setClickable(true);
        anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                currentView.setTranslationX(0);
            }
        }).setInterpolator(interpolator).setDuration(animDuration).translationX(0).get());
        anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                currentView.setScaleX(1.0f);
            }
        }).setInterpolator(interpolator).setDuration(animDuration).scaleX(1.0f).get());
        anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                currentView.setScaleY(1.0f);
            }
        }).setInterpolator(interpolator).setDuration(animDuration).scaleY(1.0f).get());
        anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                currentView.setAlpha(1.0f);
            }
        }).setInterpolator(interpolator).setDuration(animDuration).alpha(1.0f).get());
    }

    AnimatorSet animSet = new AnimatorSet();

    //temporary, from laziness
    if (!withAnim)
        animSet.setDuration(0);
    animSet.playTogether(anims.toArray(new ObjectAnimator[anims.size()]));
    animSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {

            if (mOnVisibleWidthChanged != null)
                mOnVisibleWidthChanged.onVisibleWidthChanged(
                        (getChildCount() * (int) ACTION_DIMENSION_PX) - (mHasOverflow ? Util.dpToPx(8) : 0));
        }
    });
    animSet.start();

}

From source file:com.b44t.ui.Components.PasscodeView.java

private void processDone(boolean fingerprint) {
    if (!fingerprint) {
        String password = passwordEditText.getText().toString();
        if (password.length() == 0) {
            onPasscodeError();/*from  w  w w.jav  a 2s .  c  o m*/
            return;
        }
        if (!UserConfig.checkPasscode(password)) {
            passwordEditText.setText("");
            onPasscodeError();
            return;
        }
    }
    passwordEditText.clearFocus();
    AndroidUtilities.hideKeyboard(passwordEditText);

    AnimatorSet AnimatorSet = new AnimatorSet();
    AnimatorSet.setDuration(200);
    AnimatorSet.playTogether(ObjectAnimator.ofFloat(this, "translationY", AndroidUtilities.dp(20)),
            ObjectAnimator.ofFloat(this, "alpha", AndroidUtilities.dp(0.0f)));
    AnimatorSet.addListener(new AnimatorListenerAdapterProxy() {
        @Override
        public void onAnimationEnd(Animator animation) {
            setVisibility(View.GONE);
        }
    });
    AnimatorSet.start();

    UserConfig.appLocked = false;
    UserConfig.saveConfig(false);
    NotificationCenter.getInstance().postNotificationName(NotificationCenter.didSetPasscode);
    setOnTouchListener(null);
    if (delegate != null) {
        delegate.didAcceptedPassword();
    }
}

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

/**
 * @param timerToRemove the timer to be removed during the animation
 *///from  ww w.  j  a va 2  s .  co m
private void animateTimerRemove(final Timer timerToRemove) {
    final Animator fadeOut = ObjectAnimator.ofFloat(mViewPager, ALPHA, 1, 0);
    fadeOut.setDuration(mShortAnimationDuration);
    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(mShortAnimationDuration);
    fadeIn.setInterpolator(new AccelerateInterpolator());

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

From source file:com.hannesdorfmann.search.SearchActivity.java

@OnClick(R.id.results_scrim)
  protected void hideSaveConfimation() {
      if (confirmSaveContainer.getVisibility() == View.VISIBLE) {
          // contract the bubble & hide the scrim
          AnimatorSet hideConfirmation = new AnimatorSet();
          hideConfirmation.playTogether(
                  ViewAnimationUtils.createCircularReveal(confirmSaveContainer,
                          confirmSaveContainer.getWidth() / 2, confirmSaveContainer.getHeight() / 2,
                          confirmSaveContainer.getWidth() / 2, fab.getWidth() / 2),
                  ObjectAnimator.ofArgb(resultsScrim, ViewUtils.BACKGROUND_COLOR, Color.TRANSPARENT));
          hideConfirmation.setDuration(150L);
          hideConfirmation.setInterpolator(
                  AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.fast_out_slow_in));
          hideConfirmation.addListener(new AnimatorListenerAdapter() {
              @Override//w ww. ja v  a 2  s .  co  m
              public void onAnimationEnd(Animator animation) {
                  confirmSaveContainer.setVisibility(View.GONE);
                  resultsScrim.setVisibility(View.GONE);
                  fab.setVisibility(results.getVisibility());
              }
          });
          hideConfirmation.start();
      }
  }

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

@OnClick(R.id.results_scrim)
protected void hideSaveConfimation() {
    if (confirmSaveContainer.getVisibility() == View.VISIBLE) {
        // contract the bubble & hide the scrim
        AnimatorSet hideConfirmation = new AnimatorSet();
        hideConfirmation.playTogether(//w  w  w  .  j av a 2 s . c o m
                ViewAnimationUtils.createCircularReveal(confirmSaveContainer,
                        confirmSaveContainer.getWidth() / 2, confirmSaveContainer.getHeight() / 2,
                        confirmSaveContainer.getWidth() / 2, fab.getWidth() / 2),
                ObjectAnimator.ofArgb(resultsScrim, ViewUtils.BACKGROUND_COLOR, Color.TRANSPARENT));
        hideConfirmation.setDuration(150L);
        hideConfirmation.setInterpolator(
                AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.fast_out_slow_in));
        hideConfirmation.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                confirmSaveContainer.setVisibility(View.GONE);
                resultsScrim.setVisibility(View.GONE);
                fab.setVisibility(results.getVisibility());
            }
        });
        hideConfirmation.start();
    }
}

From source file:com.androidinspain.deskclock.alarms.dataadapter.ExpandedAlarmViewHolder.java

private Animator createCollapsingAnimator(AlarmItemViewHolder newHolder, long duration) {
    arrow.setVisibility(View.INVISIBLE);
    clock.setVisibility(View.INVISIBLE);
    onOff.setVisibility(View.INVISIBLE);

    final boolean daysVisible = repeatDays.getVisibility() == View.VISIBLE;
    final int numberOfItems = countNumberOfItems();

    final View oldView = itemView;
    final View newView = newHolder.itemView;

    final Animator backgroundAnimator = ObjectAnimator.ofPropertyValuesHolder(oldView,
            PropertyValuesHolder.ofInt(AnimatorUtils.BACKGROUND_ALPHA, 255, 0));
    backgroundAnimator.setDuration(duration);

    final Animator boundsAnimator = AnimatorUtils.getBoundsAnimator(oldView, oldView, newView);
    boundsAnimator.setDuration(duration);
    boundsAnimator.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

    final long shortDuration = (long) (duration * ANIM_SHORT_DURATION_MULTIPLIER);
    final Animator repeatAnimation = ObjectAnimator.ofFloat(repeat, View.ALPHA, 0f).setDuration(shortDuration);
    final Animator editLabelAnimation = ObjectAnimator.ofFloat(editLabel, View.ALPHA, 0f)
            .setDuration(shortDuration);
    final Animator repeatDaysAnimation = ObjectAnimator.ofFloat(repeatDays, View.ALPHA, 0f)
            .setDuration(shortDuration);
    final Animator vibrateAnimation = ObjectAnimator.ofFloat(vibrate, View.ALPHA, 0f)
            .setDuration(shortDuration);
    final Animator ringtoneAnimation = ObjectAnimator.ofFloat(ringtone, View.ALPHA, 0f)
            .setDuration(shortDuration);
    final Animator dismissAnimation = ObjectAnimator.ofFloat(preemptiveDismissButton, View.ALPHA, 0f)
            .setDuration(shortDuration);
    final Animator deleteAnimation = ObjectAnimator.ofFloat(delete, View.ALPHA, 0f).setDuration(shortDuration);
    final Animator hairLineAnimation = ObjectAnimator.ofFloat(hairLine, View.ALPHA, 0f)
            .setDuration(shortDuration);

    // Set the staggered delays; use the first portion (duration * (1 - 1/4 - 1/6)) of the time,
    // so that the final animation, with a duration of 1/4 the total duration, finishes exactly
    // before the collapsed holder begins expanding.
    long startDelay = 0L;
    final long delayIncrement = (long) (duration * ANIM_LONG_DELAY_INCREMENT_MULTIPLIER) / (numberOfItems - 1);
    deleteAnimation.setStartDelay(startDelay);
    if (preemptiveDismissButton.getVisibility() == View.VISIBLE) {
        startDelay += delayIncrement;/* w  w w.  j a  v  a  2  s  .  c  o m*/
        dismissAnimation.setStartDelay(startDelay);
    }
    hairLineAnimation.setStartDelay(startDelay);
    startDelay += delayIncrement;
    editLabelAnimation.setStartDelay(startDelay);
    startDelay += delayIncrement;
    vibrateAnimation.setStartDelay(startDelay);
    ringtoneAnimation.setStartDelay(startDelay);
    startDelay += delayIncrement;
    if (daysVisible) {
        repeatDaysAnimation.setStartDelay(startDelay);
        startDelay += delayIncrement;
    }
    repeatAnimation.setStartDelay(startDelay);

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(backgroundAnimator, boundsAnimator, repeatAnimation, repeatDaysAnimation,
            vibrateAnimation, ringtoneAnimation, editLabelAnimation, deleteAnimation, hairLineAnimation,
            dismissAnimation);
    return animatorSet;
}

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

private Animator createRotateAnimator(AnimatorListenerAdapter adapter, boolean toSetup) {
    final AnimatorSet animatorSet = new AnimatorSet();
    final Animator rotateFrom = getRotateFromAnimator(toSetup ? mTimerView : mSetupView);
    rotateFrom.addListener(adapter);/* w  w  w  .  ja  va 2s  .co m*/
    final Animator rotateTo = getRotateToAnimator(toSetup ? mSetupView : mTimerView);
    final Animator expandFooterButton = getScaleFooterButtonsAnimator(!toSetup);
    animatorSet.play(rotateFrom).before(rotateTo).with(expandFooterButton);
    return animatorSet;
}