Example usage for android.animation ObjectAnimator addListener

List of usage examples for android.animation ObjectAnimator addListener

Introduction

In this page you can find the example usage for android.animation ObjectAnimator 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.example.customview.DynamicListView.java

/**
 * Resets all the appropriate fields to a default state while also animating
 * the hover cell back to its correct location.
 *//*from w  ww. j av a  2 s .c o m*/
private void touchEventsEnded() {
    final View mobileView = getViewForID(mMobileItemId);
    if (mCellIsMobile || mIsWaitingForScrollFinish) {
        mCellIsMobile = false;
        mIsWaitingForScrollFinish = false;
        mIsMobileScrolling = false;
        mActivePointerId = INVALID_POINTER_ID;

        // If the autoscroller has not completed scrolling, we need to wait for it to
        // finish in order to determine the final location of where the hover cell
        // should be animated to.
        if (mScrollState != OnScrollListener.SCROLL_STATE_IDLE) {
            mIsWaitingForScrollFinish = true;
            return;
        }

        mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left, mobileView.getTop());

        ObjectAnimator hoverViewAnimator = ObjectAnimator.ofObject(mHoverCell, "bounds", sBoundEvaluator,
                mHoverCellCurrentBounds);
        hoverViewAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                invalidate();
            }
        });
        hoverViewAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                setEnabled(false);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                mAboveItemId = INVALID_ID;
                mMobileItemId = INVALID_ID;
                mBelowItemId = INVALID_ID;
                mobileView.setVisibility(VISIBLE);
                mHoverCell = null;
                setEnabled(true);
                invalidate();
            }
        });
        hoverViewAnimator.start();
    } else {
        touchEventsCancelled();
    }
}

From source file:com.sinyuk.jianyimaterial.widgets.FloatingToolbar.java

private void showDefaultImpl() {
    int rootWidth = mRoot.getWidth();
    setScaleX(0f);//from  w  w w  .  ja  v a  2s .c  o  m

    float endFabX;

    if (mFabOriginalX > rootWidth / 2f) {
        endFabX = rootWidth / 2f + (mFabOriginalX - rootWidth / 2f) / 4f;
    } else {
        endFabX = rootWidth / 2f - (mFabOriginalX - rootWidth / 2f) / 4f;
    }

    if (mFab != null) {
        PropertyValuesHolder xProperty = PropertyValuesHolder.ofFloat(X, endFabX);
        PropertyValuesHolder yProperty = PropertyValuesHolder.ofFloat(Y, mFabOriginalY * 1.05f);
        PropertyValuesHolder scaleXProperty = PropertyValuesHolder.ofFloat(SCALE_X, 0);
        PropertyValuesHolder scaleYProperty = PropertyValuesHolder.ofFloat(SCALE_Y, 0);

        ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(mFab, xProperty, yProperty,
                scaleXProperty, scaleYProperty);
        animator.setDuration(FAB_MORPH_DURATION);
        animator.setInterpolator(new AccelerateInterpolator());
        animator.start();
    }

    ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(this, "scaleX", 1f);
    objectAnimator.setDuration(CIRCULAR_REVEAL_DURATION);
    objectAnimator.setStartDelay(CIRCULAR_REVEAL_DELAY);
    objectAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
    objectAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
            setVisibility(View.VISIBLE);
            mFab.setVisibility(View.INVISIBLE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            mMorphing = false;
        }
    });
    objectAnimator.start();
}

From source file:ucsc.hci.rankit.DynamicListView.java

/**
 * Resets all the appropriate fields to a default state while also animating
 * the hover cell back to its correct location.
 */// w ww. j  av a  2 s  . c om
private void touchEventsEnded() {
    final View mobileView = getViewForID(mMobileItemId);
    if (mCellIsMobile || mIsWaitingForScrollFinish) {
        mCellIsMobile = false;
        mIsWaitingForScrollFinish = false;
        mIsMobileScrolling = false;
        mActivePointerId = INVALID_POINTER_ID;

        // If the autoscroller has not completed scrolling, we need to wait for it to
        // finish in order to determine the final location of where the hover cell
        // should be animated to.
        if (mScrollState != OnScrollListener.SCROLL_STATE_IDLE) {
            mIsWaitingForScrollFinish = true;
            return;
        }

        try {
            mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left, mobileView.getTop());
        } catch (Exception e) {
            e.printStackTrace();
        }

        ObjectAnimator hoverViewAnimator = ObjectAnimator.ofObject(mHoverCell, "bounds", sBoundEvaluator,
                mHoverCellCurrentBounds);
        hoverViewAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                invalidate();
            }
        });
        hoverViewAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                setEnabled(false);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                mAboveItemId = INVALID_ID;
                mMobileItemId = INVALID_ID;
                mBelowItemId = INVALID_ID;
                mobileView.setVisibility(VISIBLE);
                mHoverCell = null;
                setEnabled(true);
                invalidate();
            }
        });
        try {
            hoverViewAnimator.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        touchEventsCancelled();
    }
}

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

private void gotoTimersView() {
    if (mLastVisibleView == null || mLastVisibleView.getId() == R.id.timers_list_page) {
        mTimerSetup.setVisibility(View.GONE);
        mTimersListPage.setVisibility(View.VISIBLE);
        mTimersListPage.setScaleX(1f);//w w  w .j  a v  a2s . co m
    } else {
        // Animate
        ObjectAnimator a = ObjectAnimator.ofFloat(mTimerSetup, View.SCALE_X, 1f, 0f);
        a.setInterpolator(new AccelerateInterpolator());
        a.setDuration(125);
        a.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mTimerSetup.setVisibility(View.GONE);
                mTimersListPage.setScaleX(0);
                mTimersListPage.setVisibility(View.VISIBLE);
                ObjectAnimator b = ObjectAnimator.ofFloat(mTimersListPage, View.SCALE_X, 0f, 1f);
                b.setInterpolator(new DecelerateInterpolator());
                b.setDuration(225);
                b.start();
            }
        });
        a.start();
    }
    startClockTicks();
    mLastVisibleView = mTimersListPage;
}

From source file:com.amaze.carbonfilemanager.utils.files.Futils.java

public void revealShow(final View view, boolean reveal) {
    if (reveal) {
        ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.ALPHA, 0f, 1f);
        animator.setDuration(300); //ms
        animator.addListener(new AnimatorListenerAdapter() {
            @Override//w  w w  .  j a v a 2  s  . c  o  m
            public void onAnimationStart(Animator animation) {
                view.setVisibility(View.VISIBLE);
            }
        });
        animator.start();
    } else {

        ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.ALPHA, 1f, 0f);
        animator.setDuration(300); //ms
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                view.setVisibility(View.GONE);
            }
        });
        animator.start();
    }
}

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

private void gotoSetupView() {
    if (mLastVisibleView == null || mLastVisibleView.getId() == R.id.timer_setup) {
        mTimerSetup.setVisibility(View.VISIBLE);
        mTimerSetup.setScaleX(1f);//from   w  w  w  .ja  v  a  2  s.co  m
        mTimersListPage.setVisibility(View.GONE);
    } else {
        // Animate
        ObjectAnimator a = ObjectAnimator.ofFloat(mTimersListPage, View.SCALE_X, 1f, 0f);
        a.setInterpolator(new AccelerateInterpolator());
        a.setDuration(125);
        a.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mTimersListPage.setVisibility(View.GONE);
                mTimerSetup.setScaleX(0);
                mTimerSetup.setVisibility(View.VISIBLE);
                ObjectAnimator b = ObjectAnimator.ofFloat(mTimerSetup, View.SCALE_X, 0f, 1f);
                b.setInterpolator(new DecelerateInterpolator());
                b.setDuration(225);
                b.start();
            }
        });
        a.start();

    }
    stopClockTicks();
    mTimerSetup.updateDeleteButtonAndDivider();
    mLastVisibleView = mTimerSetup;
}

From source file:com.bartoszlipinski.viewpropertyobjectanimator.ViewPropertyObjectAnimator.java

@SuppressLint("NewApi")
public ObjectAnimator get() {
    if (hasView()) {
        Collection<PropertyValuesHolder> holders = mPropertyHoldersMap.values();
        ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(mView.get(),
                holders.toArray(new PropertyValuesHolder[holders.size()]));
        if (mWithLayer) {
            animator.addListener(new AnimatorListenerAdapter() {
                int mCurrentLayerType = View.LAYER_TYPE_NONE;

                @Override/*w w w .  jav  a 2 s  .  c  o  m*/
                public void onAnimationStart(Animator animation) {
                    if (hasView()) {
                        View view = mView.get();
                        mCurrentLayerType = view.getLayerType();
                        view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
                        if (ViewCompat.isAttachedToWindow(view)) {
                            view.buildLayer();
                        }
                    }
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    if (hasView()) {
                        mView.get().setLayerType(mCurrentLayerType, null);
                    }
                }
            });
        }
        if (mStartDelay != -1) {
            animator.setStartDelay(mStartDelay);
        }
        if (mDuration != -1) {
            animator.setDuration(mDuration);
        }
        if (mInterpolator != null) {
            animator.setInterpolator(mInterpolator);
        }
        for (Animator.AnimatorListener listener : mListeners) {
            animator.addListener(listener);
        }
        if (mMarginListener != null) {
            animator.addUpdateListener(mMarginListener);
        }
        if (mDimensionListener != null) {
            animator.addUpdateListener(mDimensionListener);
        }
        if (mPaddingListener != null) {
            animator.addUpdateListener(mPaddingListener);
        }
        if (mScrollListener != null) {
            animator.addUpdateListener(mScrollListener);
        }
        if (mPercentListener != null) {
            animator.addUpdateListener(mPercentListener);
        }
        for (ValueAnimator.AnimatorUpdateListener listener : mUpdateListeners) {
            animator.addUpdateListener(listener);
        }
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            for (Animator.AnimatorPauseListener listener : mPauseListeners) {
                animator.addPauseListener(listener);
            }
        }
        return animator;
    }
    return ObjectAnimator.ofFloat(null, View.ALPHA, 1, 1);
}

From source file:com.gsoc.ijosa.liquidgalaxycontroller.PW.NearbyBeaconsFragment.java

private void showListView() {
    if (getListView() != null) {
        if (getListView().getVisibility() == View.VISIBLE) {
            return;
        }//  w w w  .ja  va  2s.c o  m

        mSwipeRefreshWidget.setRefreshing(false);
        getListView().setAlpha(0f);
        getListView().setVisibility(View.VISIBLE);
        safeNotifyChange();
        ObjectAnimator alphaAnimation = ObjectAnimator.ofFloat(getListView(), "alpha", 0f, 1f);
        alphaAnimation.setDuration(400);
        alphaAnimation.setInterpolator(new DecelerateInterpolator());
        alphaAnimation.addListener(new AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                mScanningAnimationTextView.setAlpha(0f);
                mScanningAnimationDrawable.stop();
                arrowDownLayout.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
            }

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

From source file:support.plus.reportit.rv.FragmentActivity.java

private void createCustomAnimation() {
    final FloatingActionMenu menu3 = (FloatingActionMenu) findViewById(R.id.menuShareReport);

    AnimatorSet set = new AnimatorSet();

    ObjectAnimator scaleOutX = ObjectAnimator.ofFloat(menu3.getMenuIconView(), "scaleX", 1.0f, 0.2f);
    ObjectAnimator scaleOutY = ObjectAnimator.ofFloat(menu3.getMenuIconView(), "scaleY", 1.0f, 0.2f);

    ObjectAnimator scaleInX = ObjectAnimator.ofFloat(menu3.getMenuIconView(), "scaleX", 0.2f, 1.0f);
    ObjectAnimator scaleInY = ObjectAnimator.ofFloat(menu3.getMenuIconView(), "scaleY", 0.2f, 1.0f);

    scaleOutX.setDuration(50);//from   ww w  . ja  va2 s  . c  o m
    scaleOutY.setDuration(50);

    scaleInX.setDuration(150);
    scaleInY.setDuration(150);

    scaleInX.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            menu3.getMenuIconView().setImageResource(
                    menu3.isOpened() ? R.drawable.ic_unarchive_white_24dp : R.drawable.ic_done_white_24dp);
        }
    });

    set.play(scaleOutX).with(scaleOutY);
    set.play(scaleInX).with(scaleInY).after(scaleOutX);
    set.setInterpolator(new OvershootInterpolator(2));

    menu3.setIconToggleAnimatorSet(set);
}

From source file:net.osmand.plus.views.controls.DynamicListView.java

/**
 * Resets all the appropriate fields to a default state while also animating
 * the hover cell back to its correct location.
 *///from  www . j a  v a 2  s. co m
private void touchEventsEnded() {
    final View mobileView = getViewForID(mMobileItemId);
    if (mCellIsMobile || mIsWaitingForScrollFinish) {
        mCellIsMobile = false;
        mIsWaitingForScrollFinish = false;
        mIsMobileScrolling = false;
        mActivePointerId = INVALID_POINTER_ID;

        // If the autoscroller has not completed scrolling, we need to wait for it to
        // finish in order to determine the final location of where the hover cell
        // should be animated to.
        if (mScrollState != OnScrollListener.SCROLL_STATE_IDLE) {
            mIsWaitingForScrollFinish = true;
            return;
        }

        mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left, mobileView.getTop());

        if (android.os.Build.VERSION.SDK_INT < 12) {
            finishTouch();
        } else {
            /**
             * This TypeEvaluator is used to animate the BitmapDrawable back to its
             * final location when the user lifts his finger by modifying the
             * BitmapDrawable's bounds.
             */
            TypeEvaluator<Rect> sBoundEvaluator = new TypeEvaluator<Rect>() {
                public Rect evaluate(float fraction, Rect startValue, Rect endValue) {
                    return new Rect(interpolate(startValue.left, endValue.left, fraction),
                            interpolate(startValue.top, endValue.top, fraction),
                            interpolate(startValue.right, endValue.right, fraction),
                            interpolate(startValue.bottom, endValue.bottom, fraction));
                }

                public int interpolate(int start, int end, float fraction) {
                    return (int) (start + fraction * (end - start));
                }
            };

            ObjectAnimator hoverViewAnimator = ObjectAnimator.ofObject(mHoverCell, "bounds", sBoundEvaluator,
                    mHoverCellCurrentBounds);
            hoverViewAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    invalidate();
                }
            });
            hoverViewAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationStart(Animator animation) {
                    setEnabled(false);
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    finishTouch();
                }
            });
            hoverViewAnimator.start();
        }
    } else {
        touchEventsCancelled();
    }
}