Example usage for android.animation Animator start

List of usage examples for android.animation Animator start

Introduction

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

Prototype

public void start() 

Source Link

Document

Starts this animation.

Usage

From source file:android.app.FragmentManager.java

public void showFragment(Fragment fragment, int transition, int transitionStyle) {
    if (DEBUG)/*  ww  w .  ja  v a  2s .c om*/
        Log.v(TAG, "show: " + fragment);
    if (fragment.mHidden) {
        fragment.mHidden = false;
        if (fragment.mView != null) {
            Animator anim = loadAnimator(fragment, transition, true, transitionStyle);
            if (anim != null) {
                anim.setTarget(fragment.mView);
                anim.start();
            }
            fragment.mView.setVisibility(View.VISIBLE);
        }
        if (fragment.mAdded && fragment.mHasMenu && fragment.mMenuVisible) {
            mNeedMenuInvalidate = true;
        }
        fragment.onHiddenChanged(false);
    }
}

From source file:android.support.transition.Transition.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//  ww  w .ja  v  a  2  s. co m
 */
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:org.numixproject.hermes.activity.ConversationActivity.java

private void hideConversationLayout() {
    // previously visible view

    // get the center for the clipping circle
    int cx = (conversationLayout.getLeft() + conversationLayout.getRight()) / 2;
    int cy = (conversationLayout.getTop() + conversationLayout.getBottom()) / 2;

    // get the initial radius for the clipping circle
    int initialRadius = conversationLayout.getWidth();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

        // create the animation (the final radius is zero)
        Animator anim = ViewAnimationUtils.createCircularReveal(conversationLayout, cx, cy, initialRadius, 0);
        anim.setInterpolator(new AccelerateDecelerateInterpolator());

        // make the view invisible when the animation is done
        anim.addListener(new AnimatorListenerAdapter() {
            @Override//w  ww .j  a v a2s .  c  o  m
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                conversationLayout.setVisibility(View.INVISIBLE);
            }
        });

        // start the animation
        anim.start();
    } else {
        conversationLayout.setAlpha(1.f);
        conversationLayout.setScaleX(1.f);
        conversationLayout.setScaleY(1.f);
        conversationLayout.animate().alpha(0.f).scaleX(0.f).scaleY(0.f).setDuration(300)
                .setInterpolator(new AccelerateDecelerateInterpolator()).start();
    }
    conversationLayout.setVisibility(View.INVISIBLE);
}

From source file:android.app.FragmentManager.java

void moveToState(Fragment f, int newState, int transit, int transitionStyle, boolean keepActive) {
    if (DEBUG && false)
        Log.v(TAG, "moveToState: " + f + " oldState=" + f.mState + " newState=" + newState + " mRemoving="
                + f.mRemoving + " Callers=" + Debug.getCallers(5));

    // Fragments that are not currently added will sit in the onCreate() state.
    if ((!f.mAdded || f.mDetached) && newState > Fragment.CREATED) {
        newState = Fragment.CREATED;/*from   w ww . j a v  a2 s . c o m*/
    }
    if (f.mRemoving && newState > f.mState) {
        // While removing a fragment, we can't change it to a higher state.
        newState = f.mState;
    }
    // Defer start if requested; don't allow it to move to STARTED or higher
    // if it's not already started.
    if (f.mDeferStart && f.mState < Fragment.STARTED && newState > Fragment.STOPPED) {
        newState = Fragment.STOPPED;
    }
    if (f.mState < newState) {
        // For fragments that are created from a layout, when restoring from
        // state we don't want to allow them to be created until they are
        // being reloaded from the layout.
        if (f.mFromLayout && !f.mInLayout) {
            return;
        }
        if (f.mAnimatingAway != null) {
            // The fragment is currently being animated...  but!  Now we
            // want to move our state back up.  Give up on waiting for the
            // animation, move to whatever the final state should be once
            // the animation is done, and then we can proceed from there.
            f.mAnimatingAway = null;
            moveToState(f, f.mStateAfterAnimating, 0, 0, true);
        }
        switch (f.mState) {
        case Fragment.INITIALIZING:
            if (DEBUG)
                Log.v(TAG, "moveto CREATED: " + f);
            if (f.mSavedFragmentState != null) {
                f.mSavedViewState = f.mSavedFragmentState
                        .getSparseParcelableArray(FragmentManagerImpl.VIEW_STATE_TAG);
                f.mTarget = getFragment(f.mSavedFragmentState, FragmentManagerImpl.TARGET_STATE_TAG);
                if (f.mTarget != null) {
                    f.mTargetRequestCode = f.mSavedFragmentState
                            .getInt(FragmentManagerImpl.TARGET_REQUEST_CODE_STATE_TAG, 0);
                }
                f.mUserVisibleHint = f.mSavedFragmentState.getBoolean(FragmentManagerImpl.USER_VISIBLE_HINT_TAG,
                        true);
                if (!f.mUserVisibleHint) {
                    f.mDeferStart = true;
                    if (newState > Fragment.STOPPED) {
                        newState = Fragment.STOPPED;
                    }
                }
            }
            f.mActivity = mActivity;
            f.mParentFragment = mParent;
            f.mFragmentManager = mParent != null ? mParent.mChildFragmentManager : mActivity.mFragments;
            f.mCalled = false;
            f.onAttach(mActivity);
            if (!f.mCalled) {
                throw new SuperNotCalledException(
                        "Fragment " + f + " did not call through to super.onAttach()");
            }
            if (f.mParentFragment == null) {
                mActivity.onAttachFragment(f);
            }

            if (!f.mRetaining) {
                f.performCreate(f.mSavedFragmentState);
            }
            f.mRetaining = false;
            if (f.mFromLayout) {
                // For fragments that are part of the content view
                // layout, we need to instantiate the view immediately
                // and the inflater will take care of adding it.
                f.mView = f.performCreateView(f.getLayoutInflater(f.mSavedFragmentState), null,
                        f.mSavedFragmentState);
                if (f.mView != null) {
                    f.mView.setSaveFromParentEnabled(false);
                    if (f.mHidden)
                        f.mView.setVisibility(View.GONE);
                    f.onViewCreated(f.mView, f.mSavedFragmentState);
                }
            }
        case Fragment.CREATED:
            if (newState > Fragment.CREATED) {
                if (DEBUG)
                    Log.v(TAG, "moveto ACTIVITY_CREATED: " + f);
                if (!f.mFromLayout) {
                    ViewGroup container = null;
                    if (f.mContainerId != 0) {
                        container = (ViewGroup) mContainer.findViewById(f.mContainerId);
                        if (container == null && !f.mRestored) {
                            throwException(new IllegalArgumentException(
                                    "No view found for id 0x" + Integer.toHexString(f.mContainerId) + " ("
                                            + f.getResources().getResourceName(f.mContainerId)
                                            + ") for fragment " + f));
                        }
                    }
                    f.mContainer = container;
                    f.mView = f.performCreateView(f.getLayoutInflater(f.mSavedFragmentState), container,
                            f.mSavedFragmentState);
                    if (f.mView != null) {
                        f.mView.setSaveFromParentEnabled(false);
                        if (container != null) {
                            Animator anim = loadAnimator(f, transit, true, transitionStyle);
                            if (anim != null) {
                                anim.setTarget(f.mView);
                                anim.start();
                            }
                            container.addView(f.mView);
                        }
                        if (f.mHidden)
                            f.mView.setVisibility(View.GONE);
                        f.onViewCreated(f.mView, f.mSavedFragmentState);
                    }
                }

                f.performActivityCreated(f.mSavedFragmentState);
                if (f.mView != null) {
                    f.restoreViewState(f.mSavedFragmentState);
                }
                f.mSavedFragmentState = null;
            }
        case Fragment.ACTIVITY_CREATED:
        case Fragment.STOPPED:
            if (newState > Fragment.STOPPED) {
                if (DEBUG)
                    Log.v(TAG, "moveto STARTED: " + f);
                f.performStart();
            }
        case Fragment.STARTED:
            if (newState > Fragment.STARTED) {
                if (DEBUG)
                    Log.v(TAG, "moveto RESUMED: " + f);
                f.mResumed = true;
                f.performResume();
                // Get rid of this in case we saved it and never needed it.
                f.mSavedFragmentState = null;
                f.mSavedViewState = null;
            }
        }
    } else if (f.mState > newState) {
        switch (f.mState) {
        case Fragment.RESUMED:
            if (newState < Fragment.RESUMED) {
                if (DEBUG)
                    Log.v(TAG, "movefrom RESUMED: " + f);
                f.performPause();
                f.mResumed = false;
            }
        case Fragment.STARTED:
            if (newState < Fragment.STARTED) {
                if (DEBUG)
                    Log.v(TAG, "movefrom STARTED: " + f);
                f.performStop();
            }
        case Fragment.STOPPED:
        case Fragment.ACTIVITY_CREATED:
            if (newState < Fragment.ACTIVITY_CREATED) {
                if (DEBUG)
                    Log.v(TAG, "movefrom ACTIVITY_CREATED: " + f);
                if (f.mView != null) {
                    // Need to save the current view state if not
                    // done already.
                    if (!mActivity.isFinishing() && f.mSavedViewState == null) {
                        saveFragmentViewState(f);
                    }
                }
                f.performDestroyView();
                if (f.mView != null && f.mContainer != null) {
                    Animator anim = null;
                    if (mCurState > Fragment.INITIALIZING && !mDestroyed) {
                        anim = loadAnimator(f, transit, false, transitionStyle);
                    }
                    if (anim != null) {
                        final ViewGroup container = f.mContainer;
                        final View view = f.mView;
                        final Fragment fragment = f;
                        container.startViewTransition(view);
                        f.mAnimatingAway = anim;
                        f.mStateAfterAnimating = newState;
                        anim.addListener(new AnimatorListenerAdapter() {
                            @Override
                            public void onAnimationEnd(Animator anim) {
                                container.endViewTransition(view);
                                if (fragment.mAnimatingAway != null) {
                                    fragment.mAnimatingAway = null;
                                    moveToState(fragment, fragment.mStateAfterAnimating, 0, 0, false);
                                }
                            }
                        });
                        anim.setTarget(f.mView);
                        anim.start();

                    }
                    f.mContainer.removeView(f.mView);
                }
                f.mContainer = null;
                f.mView = null;
            }
        case Fragment.CREATED:
            if (newState < Fragment.CREATED) {
                if (mDestroyed) {
                    if (f.mAnimatingAway != null) {
                        // The fragment's containing activity is
                        // being destroyed, but this fragment is
                        // currently animating away.  Stop the
                        // animation right now -- it is not needed,
                        // and we can't wait any more on destroying
                        // the fragment.
                        Animator anim = f.mAnimatingAway;
                        f.mAnimatingAway = null;
                        anim.cancel();
                    }
                }
                if (f.mAnimatingAway != null) {
                    // We are waiting for the fragment's view to finish
                    // animating away.  Just make a note of the state
                    // the fragment now should move to once the animation
                    // is done.
                    f.mStateAfterAnimating = newState;
                    newState = Fragment.CREATED;
                } else {
                    if (DEBUG)
                        Log.v(TAG, "movefrom CREATED: " + f);
                    if (!f.mRetaining) {
                        f.performDestroy();
                    }

                    f.mCalled = false;
                    f.onDetach();
                    if (!f.mCalled) {
                        throw new SuperNotCalledException(
                                "Fragment " + f + " did not call through to super.onDetach()");
                    }
                    if (!keepActive) {
                        if (!f.mRetaining) {
                            makeInactive(f);
                        } else {
                            f.mActivity = null;
                            f.mParentFragment = null;
                            f.mFragmentManager = null;
                        }
                    }
                }
            }
        }
    }

    f.mState = newState;
}

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

void animateContainer(final View container, final boolean dismiss) {
    container.setVisibility(View.VISIBLE);
    Animator animator = dismiss ? AnimatorInflater.loadAnimator(this, R.animator.exit_to_left)
            : AnimatorInflater.loadAnimator(this, R.animator.enter_from_right);
    animator.setTarget(container);/*from   w  ww .j a  v a 2  s. c o m*/
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (dismiss) {
                container.setVisibility(View.GONE);
                UIUtils.dismissKeyboard(LWQSettingsActivity.this);
            } else {
                UIUtils.revealKeyboard(container == addEditQuote ? editableQuote : editableQuery);
            }
        }
    });
    animator.start();
}

From source file:com.phonemetra.turbo.launcher.AsyncTaskCallback.java

private void enableOverviewMode(boolean enable, int snapPage, boolean animated) {
    State finalState = AppsCustomizePagedView.State.OVERVIEW;
    if (!enable) {
        finalState = AppsCustomizePagedView.State.NORMAL;
    }//from  w w  w.  j a v a 2s .c  o  m

    mLauncher.updateOverviewPanel();

    Animator appsCustomizeAnim = getChangeStateAnimation(finalState, animated, 0, snapPage);
    if (appsCustomizeAnim != null) {
        onTransitionPrepare();
        appsCustomizeAnim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator arg0) {
                onTransitionEnd();
            }
        });
        appsCustomizeAnim.start();
    }
}

From source file:android.app.FragmentManager.java

void moveToState(Fragment f, int newState, int transit, int transitionStyle, boolean keepActive) {
    if (DEBUG && false)
        Log.v(TAG, "moveToState: " + f + " oldState=" + f.mState + " newState=" + newState + " mRemoving="
                + f.mRemoving + " Callers=" + Debug.getCallers(5));

    // Fragments that are not currently added will sit in the onCreate() state.
    if ((!f.mAdded || f.mDetached) && newState > Fragment.CREATED) {
        newState = Fragment.CREATED;/*from  w w w  . j a  v  a 2 s.  c o m*/
    }
    if (f.mRemoving && newState > f.mState) {
        // While removing a fragment, we can't change it to a higher state.
        newState = f.mState;
    }
    // Defer start if requested; don't allow it to move to STARTED or higher
    // if it's not already started.
    if (f.mDeferStart && f.mState < Fragment.STARTED && newState > Fragment.STOPPED) {
        newState = Fragment.STOPPED;
    }
    if (f.mState < newState) {
        // For fragments that are created from a layout, when restoring from
        // state we don't want to allow them to be created until they are
        // being reloaded from the layout.
        if (f.mFromLayout && !f.mInLayout) {
            return;
        }
        if (f.mAnimatingAway != null) {
            // The fragment is currently being animated...  but!  Now we
            // want to move our state back up.  Give up on waiting for the
            // animation, move to whatever the final state should be once
            // the animation is done, and then we can proceed from there.
            f.mAnimatingAway = null;
            moveToState(f, f.mStateAfterAnimating, 0, 0, true);
        }
        switch (f.mState) {
        case Fragment.INITIALIZING:
            if (DEBUG)
                Log.v(TAG, "moveto CREATED: " + f);
            if (f.mSavedFragmentState != null) {
                f.mSavedViewState = f.mSavedFragmentState
                        .getSparseParcelableArray(FragmentManagerImpl.VIEW_STATE_TAG);
                f.mTarget = getFragment(f.mSavedFragmentState, FragmentManagerImpl.TARGET_STATE_TAG);
                if (f.mTarget != null) {
                    f.mTargetRequestCode = f.mSavedFragmentState
                            .getInt(FragmentManagerImpl.TARGET_REQUEST_CODE_STATE_TAG, 0);
                }
                f.mUserVisibleHint = f.mSavedFragmentState.getBoolean(FragmentManagerImpl.USER_VISIBLE_HINT_TAG,
                        true);
                if (!f.mUserVisibleHint) {
                    f.mDeferStart = true;
                    if (newState > Fragment.STOPPED) {
                        newState = Fragment.STOPPED;
                    }
                }
            }
            f.mActivity = mActivity;
            f.mParentFragment = mParent;
            f.mFragmentManager = mParent != null ? mParent.mChildFragmentManager : mActivity.mFragments;
            f.mCalled = false;
            f.onAttach(mActivity);
            if (!f.mCalled) {
                throw new SuperNotCalledException(
                        "Fragment " + f + " did not call through to super.onAttach()");
            }
            if (f.mParentFragment == null) {
                mActivity.onAttachFragment(f);
            }

            if (!f.mRetaining) {
                f.performCreate(f.mSavedFragmentState);
            }
            f.mRetaining = false;
            if (f.mFromLayout) {
                // For fragments that are part of the content view
                // layout, we need to instantiate the view immediately
                // and the inflater will take care of adding it.
                f.mView = f.performCreateView(f.getLayoutInflater(f.mSavedFragmentState), null,
                        f.mSavedFragmentState);
                if (f.mView != null) {
                    f.mView.setSaveFromParentEnabled(false);
                    if (f.mHidden)
                        f.mView.setVisibility(View.GONE);
                    f.onViewCreated(f.mView, f.mSavedFragmentState);
                }
            }
        case Fragment.CREATED:
            if (newState > Fragment.CREATED) {
                if (DEBUG)
                    Log.v(TAG, "moveto ACTIVITY_CREATED: " + f);
                if (!f.mFromLayout) {
                    ViewGroup container = null;
                    if (f.mContainerId != 0) {
                        container = (ViewGroup) mContainer.findViewById(f.mContainerId);
                        if (container == null && !f.mRestored) {
                            throwException(new IllegalArgumentException(
                                    "No view found for id 0x" + Integer.toHexString(f.mContainerId) + " ("
                                            + f.getResources().getResourceName(f.mContainerId)
                                            + ") for fragment " + f));
                        }
                    }
                    f.mContainer = container;
                    f.mView = f.performCreateView(f.getLayoutInflater(f.mSavedFragmentState), container,
                            f.mSavedFragmentState);
                    if (f.mView != null) {
                        f.mView.setSaveFromParentEnabled(false);
                        if (container != null) {
                            Animator anim = loadAnimator(f, transit, true, transitionStyle);
                            if (anim != null) {
                                anim.setTarget(f.mView);
                                anim.start();
                            }
                            container.addView(f.mView);
                        }
                        if (f.mHidden)
                            f.mView.setVisibility(View.GONE);
                        f.onViewCreated(f.mView, f.mSavedFragmentState);
                    }
                }

                f.performActivityCreated(f.mSavedFragmentState);
                if (f.mView != null) {
                    f.restoreViewState(f.mSavedFragmentState);
                }
                f.mSavedFragmentState = null;
            }
        case Fragment.ACTIVITY_CREATED:
        case Fragment.STOPPED:
            if (newState > Fragment.STOPPED) {
                if (DEBUG)
                    Log.v(TAG, "moveto STARTED: " + f);
                f.performStart();
            }
        case Fragment.STARTED:
            if (newState > Fragment.STARTED) {
                if (DEBUG)
                    Log.v(TAG, "moveto RESUMED: " + f);
                f.mResumed = true;
                f.performResume();
                // Get rid of this in case we saved it and never needed it.
                f.mSavedFragmentState = null;
                f.mSavedViewState = null;
            }
        }
    } else if (f.mState > newState) {
        switch (f.mState) {
        case Fragment.RESUMED:
            if (newState < Fragment.RESUMED) {
                if (DEBUG)
                    Log.v(TAG, "movefrom RESUMED: " + f);
                f.performPause();
                f.mResumed = false;
            }
        case Fragment.STARTED:
            if (newState < Fragment.STARTED) {
                if (DEBUG)
                    Log.v(TAG, "movefrom STARTED: " + f);
                f.performStop();
            }
        case Fragment.STOPPED:
        case Fragment.ACTIVITY_CREATED:
            if (newState < Fragment.ACTIVITY_CREATED) {
                if (DEBUG)
                    Log.v(TAG, "movefrom ACTIVITY_CREATED: " + f);
                if (f.mView != null) {
                    // Need to save the current view state if not
                    // done already.
                    if (!mActivity.isFinishing() && f.mSavedViewState == null) {
                        saveFragmentViewState(f);
                    }
                }
                f.performDestroyView();
                if (f.mView != null && f.mContainer != null) {
                    Animator anim = null;
                    if (mCurState > Fragment.INITIALIZING && !mDestroyed) {
                        anim = loadAnimator(f, transit, false, transitionStyle);
                    }
                    if (anim != null) {
                        final ViewGroup container = f.mContainer;
                        final View view = f.mView;
                        final Fragment fragment = f;
                        container.startViewTransition(view);
                        f.mAnimatingAway = anim;
                        f.mStateAfterAnimating = newState;
                        anim.addListener(new AnimatorListenerAdapter() {
                            @Override
                            public void onAnimationEnd(Animator anim) {
                                container.endViewTransition(view);
                                if (fragment.mAnimatingAway != null) {
                                    fragment.mAnimatingAway = null;
                                    moveToState(fragment, fragment.mStateAfterAnimating, 0, 0, false);
                                }
                            }
                        });
                        anim.setTarget(f.mView);
                        anim.start();

                    }
                    f.mContainer.removeView(f.mView);
                }
                f.mContainer = null;
                f.mView = null;
            }
        case Fragment.CREATED:
            if (newState < Fragment.CREATED) {
                if (mDestroyed) {
                    if (f.mAnimatingAway != null) {
                        // The fragment's containing activity is
                        // being destroyed, but this fragment is
                        // currently animating away.  Stop the
                        // animation right now -- it is not needed,
                        // and we can't wait any more on destroying
                        // the fragment.
                        Animator anim = f.mAnimatingAway;
                        f.mAnimatingAway = null;
                        anim.cancel();
                    }
                }
                if (f.mAnimatingAway != null) {
                    // We are waiting for the fragment's view to finish
                    // animating away.  Just make a note of the state
                    // the fragment now should move to once the animation
                    // is done.
                    f.mStateAfterAnimating = newState;
                    newState = Fragment.CREATED;
                } else {
                    if (DEBUG)
                        Log.v(TAG, "movefrom CREATED: " + f);
                    if (!f.mRetaining) {
                        f.performDestroy();
                    }

                    f.mCalled = false;
                    f.onDetach();
                    if (!f.mCalled) {
                        throw new SuperNotCalledException(
                                "Fragment " + f + " did not call through to super.onDetach()");
                    }
                    if (!keepActive) {
                        if (!f.mRetaining) {
                            makeInactive(f);
                        } else {
                            f.mActivity = null;
                            f.mParentFragment = null;
                            f.mFragmentManager = null;
                            f.mChildFragmentManager = null;
                        }
                    }
                }
            }
        }
    }

    f.mState = newState;
}

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//from   w w w  .j ava  2s .c  o  m
 *       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: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 .  j a  v  a  2 s .c om*/
    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.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/*from   w w  w .  j  av  a 2s .c  o  m*/
 *       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);
    }
}