Example usage for android.animation Animator addListener

List of usage examples for android.animation Animator addListener

Introduction

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

Prototype

public void addListener(AnimatorListener listener) 

Source Link

Document

Adds a listener to the set of listeners that are sent events through the life of an animation, such as start, repeat, and end.

Usage

From source file:com.rbware.github.androidcouchpotato.app.OnboardingSupportFragment.java

boolean startLogoAnimation() {
    Animator animator = null;
    if (mLogoResourceId != 0) {
        mLogoView.setVisibility(View.VISIBLE);
        mLogoView.setImageResource(mLogoResourceId);
        Animator inAnimator = AnimatorInflater.loadAnimator(getActivity(), R.animator.lb_onboarding_logo_enter);
        Animator outAnimator = AnimatorInflater.loadAnimator(getActivity(), R.animator.lb_onboarding_logo_exit);
        outAnimator.setStartDelay(LOGO_SPLASH_PAUSE_DURATION_MS);
        AnimatorSet logoAnimator = new AnimatorSet();
        logoAnimator.playSequentially(inAnimator, outAnimator);
        logoAnimator.setTarget(mLogoView);
        animator = logoAnimator;/*from   w w w . java 2  s  .  co m*/
    } else {
        animator = onCreateLogoAnimation();
    }
    if (animator != null) {
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (getActivity() != null) {
                    startEnterAnimation();
                }
            }
        });
        animator.start();
        return true;
    }
    return false;
}

From source file:com.android.incallui.CallCardFragment.java

@Override
public void animateForNewOutgoingCall() {
    final ViewGroup parent = (ViewGroup) mPrimaryCallCardContainer.getParent();

    final ViewTreeObserver observer = getView().getViewTreeObserver();

    mIsAnimating = true;/*  w  ww.  j  ava2  s. co  m*/

    observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            final ViewTreeObserver observer = getView().getViewTreeObserver();
            if (!observer.isAlive()) {
                return;
            }
            observer.removeOnGlobalLayoutListener(this);

            final LayoutIgnoringListener listener = new LayoutIgnoringListener();
            mPrimaryCallCardContainer.addOnLayoutChangeListener(listener);

            // Prepare the state of views before the slide animation
            final int originalHeight = mPrimaryCallCardContainer.getHeight();
            mPrimaryCallCardContainer.setTag(R.id.view_tag_callcard_actual_height, originalHeight);
            mPrimaryCallCardContainer.setBottom(parent.getHeight());

            // Set up FAB.
            mFloatingActionButtonContainer.setVisibility(View.GONE);
            mFloatingActionButtonController.setScreenWidth(parent.getWidth());

            mCallButtonsContainer.setAlpha(0);
            mCallStateLabel.setAlpha(0);
            mPrimaryName.setAlpha(0);
            mCallTypeLabel.setAlpha(0);
            mCallNumberAndLabel.setAlpha(0);

            assignTranslateAnimation(mCallStateLabel, 1);
            assignTranslateAnimation(mCallStateIcon, 1);
            assignTranslateAnimation(mPrimaryName, 2);
            assignTranslateAnimation(mCallNumberAndLabel, 3);
            assignTranslateAnimation(mCallTypeLabel, 4);
            assignTranslateAnimation(mCallButtonsContainer, 5);

            final Animator animator = getShrinkAnimator(parent.getHeight(), originalHeight);

            animator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    mPrimaryCallCardContainer.setTag(R.id.view_tag_callcard_actual_height, null);
                    setViewStatePostAnimation(listener);
                    mIsAnimating = false;
                    InCallPresenter.getInstance().onShrinkAnimationComplete();
                }
            });
            animator.start();
        }
    });
}

From source file:android.support.transition.TransitionPort.java

/**
 * This is a utility method used by subclasses to handle standard parts of
 * setting up and running an Animator: it sets the {@link #getDuration()
 * duration} and the {@link #getStartDelay() startDelay}, starts the
 * animation, and, when the animator ends, calls {@link #end()}.
 *
 * @param animator The Animator to be run during this transition.
 * @hide/*from  ww  w. j a v  a  2s  .c  o m*/
 */
@RestrictTo(GROUP_ID)
protected void animate(Animator animator) {
    // TODO: maybe pass auto-end as a boolean parameter?
    if (animator == null) {
        end();
    } else {
        if (getDuration() >= 0) {
            animator.setDuration(getDuration());
        }
        if (getStartDelay() >= 0) {
            animator.setStartDelay(getStartDelay());
        }
        if (getInterpolator() != null) {
            animator.setInterpolator(getInterpolator());
        }
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                end();
                animation.removeListener(this);
            }
        });
        animator.start();
    }
}

From source file:com.fairphone.fplauncher3.Folder.java

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

    Animator openFolderAnim;
    final Runnable onCompleteRunnable;
    if (!Utilities.isLmpOrAbove()) {
        positionAndSizeAsIcon();
        centerAboutIcon();

        PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1f);
        PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
        PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
        final ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
        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();

        int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
        int height = getFolderHeight();

        float transX = -0.075f * (width / 2 - getPivotX());
        float transY = -0.075f * (height / 2 - getPivotY());
        final float endTransX = 0;
        final float endTransY = 0;

        setTranslationX(transX);
        setTranslationY(transY);
        PropertyValuesHolder tx = PropertyValuesHolder.ofFloat("translationX", transX, endTransX);
        PropertyValuesHolder ty = PropertyValuesHolder.ofFloat("translationY", transY, endTransY);

        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.sqrt(rx * rx + ry * ry);
        AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
        Animator reveal = LauncherAnimUtils.createCircularReveal(this, (int) getPivotX(), (int) getPivotY(), 0,
                radius);
        reveal.setDuration(mMaterialExpandDuration);
        reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));

        View[] alphaViewSet = new View[] { mContent, mFolderName };
        for (View view : alphaViewSet) {
            Animator alphaAnimator = setupAlphaAnimator(view, 0f, 1f, mMaterialExpandDuration,
                    mMaterialExpandStagger);
            anim.play(alphaAnimator);
        }

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

        Animator drift = LauncherAnimUtils.ofPropertyValuesHolder(this, tx, ty);
        drift.setDuration(mMaterialExpandDuration);
        drift.setStartDelay(mMaterialExpandStagger);
        drift.setInterpolator(new LogDecelerateInterpolator(60, 0));
        drift.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                // in low power mode the animation doesn't play, so set the end value here
                Folder.this.setTranslationX(endTransX);
                Folder.this.setTranslationY(endTransY);
            }
        });

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

        openFolderAnim = anim;

        mContent.setLayerType(LAYER_TYPE_HARDWARE, null);
        onCompleteRunnable = new Runnable() {
            @Override
            public void run() {
                mContent.setLayerType(LAYER_TYPE_NONE, null);
            }
        };
    }
    openFolderAnim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
                    String.format(getContext().getString(R.string.folder_opened), mContent.getCountX(),
                            mContent.getCountY()));
            mState = STATE_ANIMATING;
        }

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

            if (onCompleteRunnable != null) {
                onCompleteRunnable.run();
            }

            setFocusOnFirstChild();
        }
    });
    openFolderAnim.start();

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

From source file:com.matthewtamlin.sliding_intro_screen_library.core.IntroActivity.java

/**
 * Disables the supplied button by making it invisible and un-clickable. This method should only
 * be called while the supplied button is enabled (i.e. visible and clickable). The supplied
 * Animator will be used to transition the button.
 *
 * @param buttonAnimator/*ww w. j  ava  2s  .c om*/
 *       the Animator to use when transitioning the button, null to perform no animation
 * @param button
 *       the button to disable, not null
 * @throws IllegalArgumentException
 *       if {@code button} is null
 */
private void disableButton(final Animator buttonAnimator, final IntroButton button) {
    if (button == null) {
        throw new IllegalArgumentException("button cannot be null");
    }

    // Any animations currently affecting the button must be cancelled before new ones start
    if (buttonAnimations.containsKey(button)) {
        buttonAnimations.get(button).cancel();
        buttonAnimations.remove(button);
    }

    if (buttonAnimator != null) {
        // Register animation so that it may be cancelled later if necessary
        buttonAnimations.put(button, buttonAnimator);

        // End/cancel conditions ensure that the UI is not left in a transient state when
        // animations finish
        buttonAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(final Animator animation) {
                button.setVisibility(View.VISIBLE); // Make sure View is visible while animating
                button.setEnabled(false); // Click events should be ignored immediately
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                // If the animation doesn't properly hide the button, make sure it's invisible
                button.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                // Restore the button to enabled mode
                button.setVisibility(View.VISIBLE);
                button.setEnabled(true);
            }
        });

        buttonAnimator.setDuration(BUTTON_ANIMATION_DURATION_MS);
        buttonAnimator.start();
    } else {
        // If no animator was supplied, just apply the disabled conditions
        button.setVisibility(View.INVISIBLE);
        button.setEnabled(false);
    }
}

From source file:android.support.transition.Transition.java

private void runAnimator(Animator animator, final ArrayMap<Animator, AnimationInfo> runningAnimators) {
    if (animator != null) {
        // TODO: could be a single listener instance for all of them since it uses the param
        animator.addListener(new AnimatorListenerAdapter() {
            @Override//from w  w  w. j  ava2 s  . c o m
            public void onAnimationStart(Animator animation) {
                mCurrentAnimators.add(animation);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                runningAnimators.remove(animation);
                mCurrentAnimators.remove(animation);
            }
        });
        animate(animator);
    }
}

From source file:com.matthewtamlin.sliding_intro_screen_library.core.IntroActivity.java

/**
 * Enables the supplied button by making it visible and clickable. This method should only be
 * called while the supplied button is disabled (i.e. invisible and un-clickable). The supplied
 * Animator will be used to transition the button.
 *
 * @param buttonAnimator/*  w w w  .  j a  v  a 2 s. com*/
 *       the Animator to use when transitioning the button, null to perform no animation
 * @param button
 *       the button to enable, not null
 * @throws IllegalArgumentException
 *       if {@code button} is null
 */
private void enableButton(final Animator buttonAnimator, final IntroButton button) {
    if (button == null) {
        throw new IllegalArgumentException("button cannot be null");
    }

    // Any animations currently affecting the button must be cancelled before new ones start
    if (buttonAnimations.containsKey(button)) {
        buttonAnimations.get(button).cancel();
        buttonAnimations.remove(button);
    }

    if (buttonAnimator != null) {
        buttonAnimations.put(button, buttonAnimator);

        // Give any disable animations time to finish before the enable animation starts
        buttonAnimator.setStartDelay(BUTTON_ANIMATION_DURATION_MS);

        // End/cancel conditions ensure that the UI is not left in a transient state when
        // animations finish
        buttonAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(final Animator animation) {
                button.setVisibility(View.VISIBLE); // Make sure View is visible while animating
                button.setEnabled(true); // Click events should be accepted immediately
            }

            @Override
            public void onAnimationCancel(final Animator animation) {
                // Restore button to disabled mode
                button.setVisibility(View.INVISIBLE);
                button.setEnabled(false);
            }
        });

        buttonAnimator.setDuration(BUTTON_ANIMATION_DURATION_MS);
        buttonAnimator.start();
    } else {
        // If no Animator was supplied, just apply the enabled conditions
        button.setVisibility(View.VISIBLE);
        button.setEnabled(true);
    }
}

From source file:android.support.v17.leanback.app.OnboardingSupportFragment.java

/**
 * Called when the page changes.//from   w w  w .j  a va  2  s .  c  om
 */
private void onPageChangedInternal(int previousPage) {
    if (mAnimator != null) {
        mAnimator.end();
    }
    mPageIndicator.onPageSelected(mCurrentPageIndex, true);

    List<Animator> animators = new ArrayList<>();
    // Header animation
    Animator fadeAnimator = null;
    if (previousPage < getCurrentPageIndex()) {
        // sliding to left
        animators.add(createAnimator(mTitleView, false, Gravity.START, 0));
        animators.add(fadeAnimator = createAnimator(mDescriptionView, false, Gravity.START,
                DESCRIPTION_START_DELAY_MS));
        animators.add(createAnimator(mTitleView, true, Gravity.END, HEADER_APPEAR_DELAY_MS));
        animators.add(createAnimator(mDescriptionView, true, Gravity.END,
                HEADER_APPEAR_DELAY_MS + DESCRIPTION_START_DELAY_MS));
    } else {
        // sliding to right
        animators.add(createAnimator(mTitleView, false, Gravity.END, 0));
        animators.add(fadeAnimator = createAnimator(mDescriptionView, false, Gravity.END,
                DESCRIPTION_START_DELAY_MS));
        animators.add(createAnimator(mTitleView, true, Gravity.START, HEADER_APPEAR_DELAY_MS));
        animators.add(createAnimator(mDescriptionView, true, Gravity.START,
                HEADER_APPEAR_DELAY_MS + DESCRIPTION_START_DELAY_MS));
    }
    final int currentPageIndex = getCurrentPageIndex();
    fadeAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mTitleView.setText(getPageTitle(currentPageIndex));
            mDescriptionView.setText(getPageDescription(currentPageIndex));
        }
    });

    // Animator for switching between page indicator and button.
    if (getCurrentPageIndex() == getPageCount() - 1) {
        mStartButton.setVisibility(View.VISIBLE);
        Animator navigatorFadeOutAnimator = AnimatorInflater.loadAnimator(getActivity(),
                R.animator.lb_onboarding_page_indicator_fade_out);
        navigatorFadeOutAnimator.setTarget(mPageIndicator);
        navigatorFadeOutAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mPageIndicator.setVisibility(View.GONE);
            }
        });
        animators.add(navigatorFadeOutAnimator);
        Animator buttonFadeInAnimator = AnimatorInflater.loadAnimator(getActivity(),
                R.animator.lb_onboarding_start_button_fade_in);
        buttonFadeInAnimator.setTarget(mStartButton);
        animators.add(buttonFadeInAnimator);
    } else if (previousPage == getPageCount() - 1) {
        mPageIndicator.setVisibility(View.VISIBLE);
        Animator navigatorFadeInAnimator = AnimatorInflater.loadAnimator(getActivity(),
                R.animator.lb_onboarding_page_indicator_fade_in);
        navigatorFadeInAnimator.setTarget(mPageIndicator);
        animators.add(navigatorFadeInAnimator);
        Animator buttonFadeOutAnimator = AnimatorInflater.loadAnimator(getActivity(),
                R.animator.lb_onboarding_start_button_fade_out);
        buttonFadeOutAnimator.setTarget(mStartButton);
        buttonFadeOutAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mStartButton.setVisibility(View.GONE);
            }
        });
        animators.add(buttonFadeOutAnimator);
    }
    mAnimator = new AnimatorSet();
    mAnimator.playTogether(animators);
    mAnimator.start();
    onPageChanged(mCurrentPageIndex, previousPage);
}

From source file:com.numix.calculator.EventListener.java

private void deleteAnimation(View view) {
    final TextView colorLayout = (TextView) view.getRootView().findViewById(R.id.deleteColor);
    final LinearLayout displayView = (LinearLayout) view.getRootView().findViewById(R.id.displayLayout);
    final CalculatorDisplay calculatorDisplay = (CalculatorDisplay) view.getRootView()
            .findViewById(R.id.display);

    int finalRadius = Math.max(displayView.getWidth(), displayView.getHeight());

    // create the animator for this view (the start radius is zero)
    Animator colorAnim;
    colorAnim = ViewAnimationUtils.createCircularReveal(colorLayout, (int) displayView.getRight(),
            (int) displayView.getBottom(), 0, finalRadius);
    final AlphaAnimation fadeAnim = new AlphaAnimation(1.0f, 0.0f);
    final AlphaAnimation fadeDisplay = new AlphaAnimation(1.0f, 0.0f);
    fadeAnim.setDuration(250);//from w  ww .  ja va  2 s .c o m
    fadeAnim.setInterpolator(new AccelerateInterpolator());
    fadeAnim.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            colorLayout.setVisibility(View.GONE);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    fadeDisplay.setDuration(250);
    fadeDisplay.setInterpolator(new AccelerateInterpolator());
    fadeDisplay.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            mHandler.onClear();
            displayView.setAlpha(1.0f);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    colorAnim.setInterpolator(new AccelerateInterpolator());
    colorAnim.addListener(new android.animation.Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(android.animation.Animator animation) {
            calculatorDisplay.startAnimation(fadeDisplay);
        }

        @Override
        public void onAnimationRepeat(android.animation.Animator animation) {
        }

        @Override
        public void onAnimationEnd(android.animation.Animator animation) {
            colorLayout.startAnimation(fadeAnim);
        }

        @Override
        public void onAnimationCancel(android.animation.Animator animation) {
        }
    });

    colorLayout.setVisibility(View.VISIBLE);
    colorAnim.start();
}

From source file:com.gigamole.library.ntb.NavigationTabBar.java

public void setOnTabBarSelectedIndexListener(
        final OnTabBarSelectedIndexListener onTabBarSelectedIndexListener) {
    mOnTabBarSelectedIndexListener = onTabBarSelectedIndexListener;

    if (mAnimatorListener == null)
        mAnimatorListener = new Animator.AnimatorListener() {
            @Override/*from   w w w .  ja v a  2  s  .  c  o  m*/
            public void onAnimationStart(final Animator animation) {
                if (mOnTabBarSelectedIndexListener != null)
                    mOnTabBarSelectedIndexListener.onStartTabSelected(mModels.get(mIndex), mIndex);

                animation.removeListener(this);
                animation.addListener(this);
            }

            @Override
            public void onAnimationEnd(final Animator animation) {
                if (mIsViewPagerMode)
                    return;

                animation.removeListener(this);
                animation.addListener(this);

                if (mOnTabBarSelectedIndexListener != null)
                    mOnTabBarSelectedIndexListener.onEndTabSelected(mModels.get(mIndex), mIndex);
            }

            @Override
            public void onAnimationCancel(final Animator animation) {

            }

            @Override
            public void onAnimationRepeat(final Animator animation) {

            }
        };
    mAnimator.removeListener(mAnimatorListener);
    mAnimator.addListener(mAnimatorListener);
}