Example usage for android.animation AnimatorListenerAdapter AnimatorListenerAdapter

List of usage examples for android.animation AnimatorListenerAdapter AnimatorListenerAdapter

Introduction

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

Prototype

AnimatorListenerAdapter

Source Link

Usage

From source file:com.pictureperfect.FaceTrackerActivity.java

public void initializeAnimation() {
    if (flash != null) {
        ObjectAnimator fadeOut = ObjectAnimator.ofFloat(flash, "alpha", 7f, 0f);
        fadeOut.setDuration(250);//w  w  w . j  a  va2s. c  o  m
        ObjectAnimator fadeIn = ObjectAnimator.ofFloat(flash, "alpha", 0f, 7f);
        fadeIn.setDuration(250);

        mAnimationSet = new AnimatorSet();

        mAnimationSet.play(fadeOut).after(fadeIn);

        mAnimationSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                flash.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                Toast.makeText(getApplicationContext(), "Picture Taken", Toast.LENGTH_SHORT).show();
            }
        });
    }
}

From source file:com.commonsware.cwac.crossport.design.widget.FloatingActionButtonImpl.java

void show(@Nullable final InternalVisibilityChangedListener listener, final boolean fromUser) {
    if (isOrWillBeShown()) {
        // We either are or will soon be visible, skip the call
        return;/*from   w  w w. j a  v a  2  s. com*/
    }

    mView.animate().cancel();

    if (shouldAnimateVisibilityChange()) {
        mAnimState = ANIM_STATE_SHOWING;

        if (mView.getVisibility() != View.VISIBLE) {
            // If the view isn't visible currently, we'll animate it from a single pixel
            mView.setAlpha(0f);
            mView.setScaleY(0f);
            mView.setScaleX(0f);
        }

        mView.animate().scaleX(1f).scaleY(1f).alpha(1f).setDuration(SHOW_HIDE_ANIM_DURATION)
                .setInterpolator(AnimationUtils.LINEAR_OUT_SLOW_IN_INTERPOLATOR)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationStart(Animator animation) {
                        mView.internalSetVisibility(View.VISIBLE, fromUser);
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        mAnimState = ANIM_STATE_NONE;
                        if (listener != null) {
                            listener.onShown();
                        }
                    }
                });
    } else {
        mView.internalSetVisibility(View.VISIBLE, fromUser);
        mView.setAlpha(1f);
        mView.setScaleY(1f);
        mView.setScaleX(1f);
        if (listener != null) {
            listener.onShown();
        }
    }
}

From source file:com.grepsound.activities.MainActivity.java

/**
 * This method is used to toggle between the two fragment states by
 * calling the appropriate animations between them. The entry and exit
 * animations of the text fragment are specified in R.animator resource
 * files. The entry and exit animations of the image fragment are
 * specified in the slideBack and slideForward methods below. The reason
 * for separating the animation logic in this way is because the translucent
 * dark hover view must fade in at the same time as the image fragment
 * animates into the background, which would be difficult to time
 * properly given that the setCustomAnimations method can only modify the
 * two fragments in the transaction./*from  w  ww.j a v  a  2 s. co  m*/
 */
private void switchFragments() {
    if (mIsAnimating) {
        Log.i(TAG, "IS animating!");
        return;
    }
    mIsAnimating = true;
    if (mDidSlideOut) {
        Log.i(TAG, "Did Slide Out!");
        mDidSlideOut = false;
        getFragmentManager().popBackStack();
    } else {
        mDidSlideOut = true;

        Animator.AnimatorListener listener = new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator arg0) {
                FragmentTransaction transaction = getFragmentManager().beginTransaction();
                transaction.setCustomAnimations(R.animator.slide_fragment_left, 0, 0,
                        R.animator.slide_fragment_right);
                transaction.add(R.id.move_to_back_container, mDetailsFragment);
                transaction.addToBackStack(null);
                transaction.commit();
                mDidSlideOut = false;
            }
        };
        slideBack(listener);
    }
}

From source file:com.itsronald.widget.IndicatorDotPathView.java

@NonNull
Animator connectPathAnimator() {//ww  w. j a va2 s.c  om
    final Rect startSegmentBounds = viewRectInNeighborCoords(startPathSegment, endPathSegment);
    final Rect endSegmentBounds = viewRectInNeighborCoords(endPathSegment, startPathSegment);

    final int startSegmentToX = endSegmentBounds.centerX() < 0 ? endSegmentBounds.left : endSegmentBounds.right;
    final int startSegmentToY = endSegmentBounds.centerY() < 0 ? endSegmentBounds.top : endSegmentBounds.bottom;
    final int endSegmentToX = startSegmentBounds.centerX() < 0 ? startSegmentBounds.left
            : startSegmentBounds.right;
    final int endSegmentToY = startSegmentBounds.centerY() < 0 ? startSegmentBounds.top
            : startSegmentBounds.bottom;

    final Animator startSegmentAnimator = startPathSegment.stretchAnimator(PATH_STRETCH_ANIM_DURATION,
            startSegmentToX, startSegmentToY);
    final Animator endSegmentAnimator = endPathSegment.stretchAnimator(PATH_STRETCH_ANIM_DURATION,
            endSegmentToX, endSegmentToY);

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(startSegmentAnimator, endSegmentAnimator, centerSegmentGrowAnimator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            startDot.setVisibility(VISIBLE);
            endDot.setVisibility(VISIBLE);
        }
    });

    return animatorSet;
}

From source file:com.appsummary.luoxf.myappsummary.recyclerView.fastscroll.Views.FastScroller.java

public void show() {
    if (!mAnimatingShow) {
        if (mAutoHideAnimator != null) {
            mAutoHideAnimator.cancel();//from   ww w .ja va 2s .  com
        }
        mAutoHideAnimator = ObjectAnimator.ofInt(this, "offsetX", 0);
        mAutoHideAnimator.setInterpolator(new LinearOutSlowInInterpolator());
        mAutoHideAnimator.setDuration(150);
        mAutoHideAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationCancel(Animator animation) {
                super.onAnimationCancel(animation);
                mAnimatingShow = false;
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                mAnimatingShow = false;
            }
        });
        mAnimatingShow = true;
        mAutoHideAnimator.start();
    }
    if (mAutoHideEnabled) {
        postAutoHideDelayed();
    } else {
        cancelAutoHide();
    }
}

From source file:com.amaze.filemanager.utils.files.FileUtils.java

public static void crossfadeInverse(final View buttons, final View pathbar) {
    // Set the content view to 0% opacity but visible, so that it is visible
    // (but fully transparent) during the animation.

    pathbar.setAlpha(0f);//w  ww .  j  a v  a2  s  .  c o  m
    pathbar.setVisibility(View.VISIBLE);

    // Animate the content view to 100% opacity, and clear any animation
    // listener set on the view.
    pathbar.animate().alpha(1f).setDuration(500).setListener(null);
    buttons.animate().alpha(0f).setDuration(500).setListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            buttons.setVisibility(View.GONE);
        }
    });
    // Animate the loading view to 0% opacity. After the animation ends,
    // set its visibility to GONE as an optimization step (it won't
    // participate in layout passes, etc.)
}

From source file:com.alexandrepiveteau.library.tutorial.TutorialActivity.java

private void animateViewFadeOut(final View view) {
    view.animate().alpha(0f).setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime))
            .setListener(new AnimatorListenerAdapter() {
                @Override/*  ww w.j  a  v  a 2s . com*/
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    view.setVisibility(View.GONE);
                }
            }).start();
}

From source file:com.android.clear.reminder.ItemAnimator.java

@Override
public void runPendingAnimations() {
    final AnimatorSet removeAnimatorSet = new AnimatorSet();
    removeAnimatorSet.playTogether(mRemoveAnimatorsList);
    mRemoveAnimatorsList.clear();//from  www  . ja v a  2s . c  om

    final AnimatorSet addAnimatorSet = new AnimatorSet();
    addAnimatorSet.playTogether(mAddAnimatorsList);
    mAddAnimatorsList.clear();

    final AnimatorSet changeAnimatorSet = new AnimatorSet();
    changeAnimatorSet.playTogether(mChangeAnimatorsList);
    mChangeAnimatorsList.clear();

    final AnimatorSet moveAnimatorSet = new AnimatorSet();
    moveAnimatorSet.playTogether(mMoveAnimatorsList);
    mMoveAnimatorsList.clear();

    final AnimatorSet pendingAnimatorSet = new AnimatorSet();
    pendingAnimatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            animator.removeAllListeners();
            dispatchFinishedWhenDone();
        }
    });
    // Required order: removes, then changes & moves simultaneously, then additions. There are
    // redundant edges because changes or moves may be empty, causing the removes to incorrectly
    // play immediately.
    pendingAnimatorSet.play(removeAnimatorSet).before(changeAnimatorSet);
    pendingAnimatorSet.play(removeAnimatorSet).before(moveAnimatorSet);
    pendingAnimatorSet.play(changeAnimatorSet).with(moveAnimatorSet);
    pendingAnimatorSet.play(addAnimatorSet).after(changeAnimatorSet);
    pendingAnimatorSet.play(addAnimatorSet).after(moveAnimatorSet);
    pendingAnimatorSet.start();
}

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

@Override
public Animator onDisappear(ViewGroup sceneRoot, TransitionValues startValues, int startVisibility,
        TransitionValues endValues, int endVisibility) {
    if ((mFadingMode & OUT) != OUT) {
        return null;
    }/*from ww w.  j a v a2s.com*/
    View view = null;
    View startView = (startValues != null) ? startValues.view : null;
    View endView = (endValues != null) ? endValues.view : null;
    if (DBG) {
        Log.d(LOG_TAG, "Fade.onDisappear: startView, startVis, endView, endVis = " + startView + ", "
                + startVisibility + ", " + endView + ", " + endVisibility);
    }
    View overlayView = null;
    View viewToKeep = null;
    if (endView == null || endView.getParent() == null) {
        if (endView != null) {
            // endView was removed from its parent - add it to the overlay
            view = overlayView = endView;
        } else if (startView != null) {
            // endView does not exist. Use startView only under certain
            // conditions, because placing a view in an overlay necessitates
            // it being removed from its current parent
            if (startView.getParent() == null) {
                // no parent - safe to use
                view = overlayView = startView;
            } else if (startView.getParent() instanceof View && startView.getParent().getParent() == null) {
                View startParent = (View) startView.getParent();
                int id = startParent.getId();
                if (id != View.NO_ID && sceneRoot.findViewById(id) != null && mCanRemoveViews) {
                    // no parent, but its parent is unparented  but the parent
                    // hierarchy has been replaced by a new hierarchy with the same id
                    // and it is safe to un-parent startView
                    view = overlayView = startView;
                }
            }
        }
    } else {
        // visibility change
        if (endVisibility == View.INVISIBLE) {
            view = endView;
            viewToKeep = view;
        } else {
            // Becoming GONE
            if (startView == endView) {
                view = endView;
                viewToKeep = view;
            } else {
                view = startView;
                overlayView = view;
            }
        }
    }
    final int finalVisibility = endVisibility;
    // TODO: add automatic facility to Visibility superclass for keeping views around
    if (overlayView != null) {
        // TODO: Need to do this for general case of adding to overlay
        int screenX = (Integer) startValues.values.get(PROPNAME_SCREEN_X);
        int screenY = (Integer) startValues.values.get(PROPNAME_SCREEN_Y);
        int[] loc = new int[2];
        sceneRoot.getLocationOnScreen(loc);
        ViewCompat.offsetLeftAndRight(overlayView, (screenX - loc[0]) - overlayView.getLeft());
        ViewCompat.offsetTopAndBottom(overlayView, (screenY - loc[1]) - overlayView.getTop());
        ViewGroupOverlay.createFrom(sceneRoot).add(overlayView);
        //            sceneRoot.getOverlay().add(overlayView);
        // TODO: add automatic facility to Visibility superclass for keeping views around
        final float startAlpha = 1;
        float endAlpha = 0;
        final View finalView = view;
        final View finalOverlayView = overlayView;
        final View finalViewToKeep = viewToKeep;
        final ViewGroup finalSceneRoot = sceneRoot;
        final AnimatorListenerAdapter endListener = new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                finalView.setAlpha(startAlpha);
                // TODO: restore view offset from overlay repositioning
                if (finalViewToKeep != null) {
                    finalViewToKeep.setVisibility(finalVisibility);
                }
                if (finalOverlayView != null) {
                    ViewGroupOverlay.createFrom(finalSceneRoot).remove(finalOverlayView);
                    //                        finalSceneRoot.getOverlay().remove(finalOverlayView);
                }
            }
            //
            //                @Override
            //                public void onAnimationPause(Animator animation) {
            //                    if (finalOverlayView != null) {
            //                        finalSceneRoot.getOverlay().remove(finalOverlayView);
            //                    }
            //                }
            //
            //                @Override
            //                public void onAnimationResume(Animator animation) {
            //                    if (finalOverlayView != null) {
            //                        finalSceneRoot.getOverlay().add(finalOverlayView);
            //                    }
            //                }
        };
        return createAnimation(view, startAlpha, endAlpha, endListener);
    }
    if (viewToKeep != null) {
        // TODO: find a different way to do this, like just changing the view to be
        // VISIBLE for the duration of the transition
        viewToKeep.setVisibility((View.VISIBLE));
        // TODO: add automatic facility to Visibility superclass for keeping views around
        final float startAlpha = 1;
        float endAlpha = 0;
        final View finalView = view;
        final View finalOverlayView = overlayView;
        final View finalViewToKeep = viewToKeep;
        final ViewGroup finalSceneRoot = sceneRoot;
        final AnimatorListenerAdapter endListener = new AnimatorListenerAdapter() {
            boolean mCanceled = false;

            float mPausedAlpha = -1;

            //                @Override
            //                public void onAnimationPause(Animator animation) {
            //                    if (finalViewToKeep != null && !mCanceled) {
            //                        finalViewToKeep.setVisibility(finalVisibility);
            //                    }
            //                    mPausedAlpha = finalView.getAlpha();
            //                    finalView.setAlpha(startAlpha);
            //                }
            //
            //                @Override
            //                public void onAnimationResume(Animator animation) {
            //                    if (finalViewToKeep != null && !mCanceled) {
            //                        finalViewToKeep.setVisibility(View.VISIBLE);
            //                    }
            //                    finalView.setAlpha(mPausedAlpha);
            //                }

            @Override
            public void onAnimationCancel(Animator animation) {
                mCanceled = true;
                if (mPausedAlpha >= 0) {
                    finalView.setAlpha(mPausedAlpha);
                }
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                if (!mCanceled) {
                    finalView.setAlpha(startAlpha);
                }
                // TODO: restore view offset from overlay repositioning
                if (finalViewToKeep != null && !mCanceled) {
                    finalViewToKeep.setVisibility(finalVisibility);
                }
                if (finalOverlayView != null) {
                    ViewGroupOverlay.createFrom(finalSceneRoot).add(finalOverlayView);
                    //                        finalSceneRoot.getOverlay().remove(finalOverlayView);
                }
            }
        };
        return createAnimation(view, startAlpha, endAlpha, endListener);
    }
    return null;
}

From source file:com.androidinspain.deskclock.DeskClock.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.desk_clock);
    mSnackbarAnchor = findViewById(R.id.content);

    // Configure the toolbar.
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*w  w  w  .  ja v  a2  s .  co m*/

    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowTitleEnabled(false);
    }

    // Configure the menu item controllers add behavior to the toolbar.
    mOptionsMenuManager.addMenuItemController(new NightModeMenuItemController(this),
            new SettingsMenuItemController(this));
    mOptionsMenuManager
            .addMenuItemController(MenuItemControllerFactory.getInstance().buildMenuItemControllers(this));

    // Inflate the menu during creation to avoid a double layout pass. Otherwise, the menu
    // inflation occurs *after* the initial draw and a second layout pass adds in the menu.
    onCreateOptionsMenu(toolbar.getMenu());

    // Create the tabs that make up the user interface.
    mTabLayout = (TabLayout) findViewById(R.id.tabs);
    final int tabCount = UiDataModel.getUiDataModel().getTabCount();
    final boolean showTabLabel = getResources().getBoolean(R.bool.showTabLabel);
    final boolean showTabHorizontally = getResources().getBoolean(R.bool.showTabHorizontally);
    for (int i = 0; i < tabCount; i++) {
        final UiDataModel.Tab tabModel = UiDataModel.getUiDataModel().getTab(i);
        final @StringRes int labelResId = tabModel.getLabelResId();

        final TabLayout.Tab tab = mTabLayout.newTab().setTag(tabModel).setIcon(tabModel.getIconResId())
                .setContentDescription(labelResId);

        if (showTabLabel) {
            tab.setText(labelResId);
            tab.setCustomView(R.layout.tab_item);

            @SuppressWarnings("ConstantConditions")
            final TextView text = (TextView) tab.getCustomView().findViewById(android.R.id.text1);
            text.setTextColor(mTabLayout.getTabTextColors());

            // Bind the icon to the TextView.
            final Drawable icon = tab.getIcon();
            if (showTabHorizontally) {
                // Remove the icon so it doesn't affect the minimum TabLayout height.
                tab.setIcon(null);
                text.setCompoundDrawablesRelativeWithIntrinsicBounds(icon, null, null, null);
            } else {
                text.setCompoundDrawablesRelativeWithIntrinsicBounds(null, icon, null, null);
            }
        }

        mTabLayout.addTab(tab);
    }

    // Configure the buttons shared by the tabs.
    mFab = (ImageView) findViewById(R.id.fab);
    mLeftButton = (Button) findViewById(R.id.left_button);
    mRightButton = (Button) findViewById(R.id.right_button);

    mFab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            getSelectedDeskClockFragment().onFabClick(mFab);
        }
    });
    mLeftButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            getSelectedDeskClockFragment().onLeftButtonClick(mLeftButton);
        }
    });
    mRightButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            getSelectedDeskClockFragment().onRightButtonClick(mRightButton);
        }
    });

    final long duration = UiDataModel.getUiDataModel().getShortAnimationDuration();

    final ValueAnimator hideFabAnimation = getScaleAnimator(mFab, 1f, 0f);
    final ValueAnimator showFabAnimation = getScaleAnimator(mFab, 0f, 1f);

    final ValueAnimator leftHideAnimation = getScaleAnimator(mLeftButton, 1f, 0f);
    final ValueAnimator rightHideAnimation = getScaleAnimator(mRightButton, 1f, 0f);
    final ValueAnimator leftShowAnimation = getScaleAnimator(mLeftButton, 0f, 1f);
    final ValueAnimator rightShowAnimation = getScaleAnimator(mRightButton, 0f, 1f);

    hideFabAnimation.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            getSelectedDeskClockFragment().onUpdateFab(mFab);
        }
    });

    leftHideAnimation.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            getSelectedDeskClockFragment().onUpdateFabButtons(mLeftButton, mRightButton);
        }
    });

    // Build the reusable animations that hide and show the fab and left/right buttons.
    // These may be used independently or be chained together.
    mHideAnimation.setDuration(duration).play(hideFabAnimation).with(leftHideAnimation)
            .with(rightHideAnimation);

    mShowAnimation.setDuration(duration).play(showFabAnimation).with(leftShowAnimation)
            .with(rightShowAnimation);

    // Build the reusable animation that hides and shows only the fab.
    mUpdateFabOnlyAnimation.setDuration(duration).play(showFabAnimation).after(hideFabAnimation);

    // Build the reusable animation that hides and shows only the buttons.
    mUpdateButtonsOnlyAnimation.setDuration(duration).play(leftShowAnimation).with(rightShowAnimation)
            .after(leftHideAnimation).after(rightHideAnimation);

    // Customize the view pager.
    mFragmentTabPagerAdapter = new FragmentTabPagerAdapter(this);
    mFragmentTabPager = (ViewPager) findViewById(R.id.desk_clock_pager);
    // Keep all four tabs to minimize jank.
    mFragmentTabPager.setOffscreenPageLimit(3);
    // Set Accessibility Delegate to null so view pager doesn't intercept movements and
    // prevent the fab from being selected.
    mFragmentTabPager.setAccessibilityDelegate(null);
    // Mirror changes made to the selected page of the view pager into UiDataModel.
    mFragmentTabPager.addOnPageChangeListener(new PageChangeWatcher());
    mFragmentTabPager.setAdapter(mFragmentTabPagerAdapter);

    // Mirror changes made to the selected tab into UiDataModel.
    mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            UiDataModel.getUiDataModel().setSelectedTab((UiDataModel.Tab) tab.getTag());
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
        }
    });

    // Honor changes to the selected tab from outside entities.
    UiDataModel.getUiDataModel().addTabListener(mTabChangeWatcher);
}