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.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   www. ja va 2  s.com*/
    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:cn.oddcloud.www.navigationtabbar.ntb.NavigationTabBar.java

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

    if (mAnimatorListener == null)
        mAnimatorListener = new AnimatorListenerAdapter() {
            @Override//from   w ww.  j a  va  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);
            }
        };
    mAnimator.removeListener(mAnimatorListener);
    mAnimator.addListener(mAnimatorListener);
}

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/*from  w w w .  ja  v a 2 s .  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.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//from   w  w w  .j  av  a2 s .c  o  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: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.ja  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

public void hideFragment(Fragment fragment, int transition, int transitionStyle) {
    if (DEBUG)//w ww  . j av  a2  s  .  c  om
        Log.v(TAG, "hide: " + fragment);
    if (!fragment.mHidden) {
        fragment.mHidden = true;
        if (fragment.mView != null) {
            Animator anim = loadAnimator(fragment, transition, true, transitionStyle);
            if (anim != null) {
                anim.setTarget(fragment.mView);
                // Delay the actual hide operation until the animation finishes, otherwise
                // the fragment will just immediately disappear
                final Fragment finalFragment = fragment;
                anim.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        if (finalFragment.mView != null) {
                            finalFragment.mView.setVisibility(View.GONE);
                        }
                    }
                });
                anim.start();
            } else {
                fragment.mView.setVisibility(View.GONE);
            }
        }
        if (fragment.mAdded && fragment.mHasMenu && fragment.mMenuVisible) {
            mNeedMenuInvalidate = true;
        }
        fragment.onHiddenChanged(true);
    }
}

From source file:android.app.FragmentManager.java

public void hideFragment(Fragment fragment, int transition, int transitionStyle) {
    if (DEBUG)//from   ww  w . ja  va 2s  .  c o m
        Log.v(TAG, "hide: " + fragment);
    if (!fragment.mHidden) {
        fragment.mHidden = true;
        if (fragment.mView != null) {
            Animator anim = loadAnimator(fragment, transition, false, transitionStyle);
            if (anim != null) {
                anim.setTarget(fragment.mView);
                // Delay the actual hide operation until the animation finishes, otherwise
                // the fragment will just immediately disappear
                final Fragment finalFragment = fragment;
                anim.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        if (finalFragment.mView != null) {
                            finalFragment.mView.setVisibility(View.GONE);
                        }
                    }
                });
                anim.start();
            } else {
                fragment.mView.setVisibility(View.GONE);
            }
        }
        if (fragment.mAdded && fragment.mHasMenu && fragment.mMenuVisible) {
            mNeedMenuInvalidate = true;
        }
        fragment.onHiddenChanged(true);
    }
}

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

Animator animateFABActions(final boolean dismiss) {
    fabBackground.setVisibility(View.VISIBLE);
    Animator backgroundAnimator;

    if (Build.VERSION.SDK_INT >= 21) {
        Rect fabRect = new Rect();
        fabAdd.getGlobalVisibleRect(fabRect);
        final Point realScreenSize = UIUtils.getRealScreenSize();
        int radius = Math.max(realScreenSize.x, realScreenSize.y);
        backgroundAnimator = ViewAnimationUtils.createCircularReveal(fabBackground, fabRect.centerX(),
                fabRect.centerY(), dismiss ? radius : 0, dismiss ? 0 : radius);
    } else {// www  .ja va  2  s  .c  o m
        backgroundAnimator = ObjectAnimator.ofFloat(fabBackground, "alpha", dismiss ? 1f : 0f,
                dismiss ? 0f : 1f);
    }
    backgroundAnimator.setDuration(300).setInterpolator(new AccelerateDecelerateInterpolator());
    backgroundAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (dismiss) {
                fabBackground.setVisibility(View.GONE);
                // Tell them to swipe again for settings!
                showTutorialTip(TutorialTooltips.SWIPE_AGAIN);
            } else {
                // Tell them about search!
                showTutorialTip(TutorialTooltips.SEARCH);
            }
        }
    });
    final long shortDelay = 50;
    final long longDelay = 100;
    final Animator createAnimator = animateFAB(fabCreate, dismiss);
    final Animator searchAnimator = animateFAB(fabSearch, dismiss);
    createAnimator.setStartDelay(dismiss ? longDelay : shortDelay);
    searchAnimator.setStartDelay(dismiss ? shortDelay : longDelay);
    AnimatorSet allAnimations = new AnimatorSet();
    allAnimations.playTogether(backgroundAnimator, createAnimator, searchAnimator);
    return allAnimations;
}

From source file:com.android.leanlauncher.Workspace.java

private void enableOverviewMode(boolean enable, boolean animated) {
    State finalState = Workspace.State.OVERVIEW;
    if (!enable) {
        finalState = Workspace.State.NORMAL;
    }// w w  w . ja v a 2 s .co m

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

From source file:com.android.leanlauncher.Workspace.java

Animator getChangeStateAnimation(final State state, boolean animated, int delay, ArrayList<View> layerViews) {
    if (mState == state) {
        return null;
    }// w  w  w  .  j a  va 2s .c  o  m

    AnimatorSet anim = animated ? LauncherAnimUtils.createAnimatorSet() : null;

    // We only want a single instance of a workspace animation to be running at once, so
    // we cancel any incomplete transition.
    if (mStateAnimator != null) {
        mStateAnimator.cancel();
    }
    mStateAnimator = anim;

    final State oldState = mState;
    final boolean oldStateIsNormal = (oldState == State.NORMAL);
    final boolean oldStateIsOverview = (oldState == State.OVERVIEW);
    setState(state);
    final boolean stateIsNormal = (state == State.NORMAL);
    final boolean stateIsSpringLoaded = (state == State.SPRING_LOADED);
    final boolean stateIsNormalHidden = (state == State.NORMAL_HIDDEN);
    final boolean stateIsOverviewHidden = (state == State.OVERVIEW_HIDDEN);
    final boolean stateIsOverview = (state == State.OVERVIEW);
    float finalBackgroundAlpha = (stateIsSpringLoaded || stateIsOverview) ? 1.0f : 0f;
    float finalOverviewPanelAlpha = stateIsOverview ? 1f : 0f;
    float finalWorkspaceTranslationY = stateIsOverview || stateIsOverviewHidden ? getOverviewModeTranslationY()
            : 0;

    boolean workspaceToAllApps = (oldStateIsNormal && stateIsNormalHidden);
    boolean overviewToAllApps = (oldStateIsOverview && stateIsOverviewHidden);
    boolean allAppsToWorkspace = (stateIsNormalHidden && stateIsNormal);
    boolean workspaceToOverview = (oldStateIsNormal && stateIsOverview);
    boolean overviewToWorkspace = (oldStateIsOverview && stateIsNormal);

    mNewScale = 1.0f;

    if (state != State.NORMAL) {
        if (stateIsSpringLoaded) {
            mNewScale = mSpringLoadedShrinkFactor;
        } else if (stateIsOverview || stateIsOverviewHidden) {
            mNewScale = mOverviewModeShrinkFactor;
        }
    }

    final int duration;
    if (workspaceToAllApps || overviewToAllApps) {
        duration = HIDE_WORKSPACE_DURATION; //getResources().getInteger(R.integer.config_workspaceUnshrinkTime);
    } else if (workspaceToOverview || overviewToWorkspace) {
        duration = getResources().getInteger(R.integer.config_overviewTransitionTime);
    } else {
        duration = getResources().getInteger(R.integer.config_appsCustomizeWorkspaceShrinkTime);
    }

    final CellLayout cl = mWorkspace;
    float initialAlpha = cl.getShortcutsAndWidgets().getAlpha();
    float finalAlpha;
    if (stateIsNormalHidden || stateIsOverviewHidden) {
        finalAlpha = 0f;
    } else {
        finalAlpha = 1f;
    }

    // If we are animating to/from the small state, then hide the side pages and fade the
    // current page in
    if (!mIsSwitchingState) {
        if (workspaceToAllApps || allAppsToWorkspace) {
            if (allAppsToWorkspace) {
                initialAlpha = 0f;
            }
            cl.setShortcutAndWidgetAlpha(initialAlpha);
        }
    }

    float oldAlpha = initialAlpha;
    float newAlpha = finalAlpha;
    if (animated) {
        mOldBackgroundAlpha = cl.getBackgroundAlpha();
        mNewBackgroundAlpha = finalBackgroundAlpha;
    } else {
        cl.setBackgroundAlpha(finalBackgroundAlpha);
        cl.setShortcutAndWidgetAlpha(finalAlpha);
    }

    final View overviewPanel = mLauncher.getOverviewPanel();
    if (animated) {
        LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this);
        scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY).setDuration(duration)
                .setInterpolator(mZoomInInterpolator);
        anim.play(scale);
        float currentAlpha = cl.getShortcutsAndWidgets().getAlpha();
        if (oldAlpha == 0 && newAlpha == 0) {
            cl.setBackgroundAlpha(mNewBackgroundAlpha);
            cl.setShortcutAndWidgetAlpha(newAlpha);
        } else {
            if (layerViews != null) {
                layerViews.add(cl);
            }
            if (oldAlpha != newAlpha || currentAlpha != newAlpha) {
                LauncherViewPropertyAnimator alphaAnim = new LauncherViewPropertyAnimator(
                        cl.getShortcutsAndWidgets());
                alphaAnim.alpha(newAlpha).setDuration(duration).setInterpolator(mZoomInInterpolator);
                anim.play(alphaAnim);
            }
            if (mOldBackgroundAlpha != 0 || mNewBackgroundAlpha != 0) {
                ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(cl, 0f, 1f);
                bgAnim.setInterpolator(mZoomInInterpolator);
                bgAnim.setDuration(duration);
                bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
                    public void onAnimationUpdate(float a, float b) {
                        cl.setBackgroundAlpha(a * mOldBackgroundAlpha + b * mNewBackgroundAlpha);
                    }
                });
                anim.play(bgAnim);
            }
        }

        Animator overviewPanelAlpha = new LauncherViewPropertyAnimator(overviewPanel)
                .alpha(finalOverviewPanelAlpha).withLayer();
        overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel));

        // For animation optimations, we may need to provide the Launcher transition
        // with a set of views on which to force build layers in certain scenarios.
        overviewPanel.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        if (layerViews != null) {
            layerViews.add(overviewPanel);
        }

        if (workspaceToOverview) {
            overviewPanelAlpha.setInterpolator(null);
        } else if (overviewToWorkspace) {
            overviewPanelAlpha.setInterpolator(new DecelerateInterpolator(2));
        }

        overviewPanelAlpha.setDuration(duration);

        anim.play(overviewPanelAlpha);
        anim.setStartDelay(delay);
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mStateAnimator = null;
            }
        });
    } else {
        overviewPanel.setAlpha(finalOverviewPanelAlpha);
        AlphaUpdateListener.updateVisibility(overviewPanel);
        setScaleX(mNewScale);
        setScaleY(mNewScale);
        setTranslationY(finalWorkspaceTranslationY);
    }

    if (stateIsNormal) {
        animateBackgroundGradient(0f, animated);
    } else {
        animateBackgroundGradient(getResources().getInteger(R.integer.config_workspaceScrimAlpha) / 100f,
                animated);
    }
    return anim;
}