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:arun.com.chromer.browsing.article.util.ArticleScrollListener.java

private void animateBackgroundColor(int from, int to, Interpolator interpolator) {
    final ValueAnimator anim = new ValueAnimator();
    anim.setIntValues(from, to);/*from  w  ww  .  j  ava2  s.  c o m*/
    anim.setEvaluator(new ArgbEvaluator());
    anim.setInterpolator(interpolator);
    anim.addUpdateListener(valueAnimator -> {
        toolbar.setBackgroundColor((Integer) valueAnimator.getAnimatedValue());
        statusBar.setBackgroundColor((Integer) valueAnimator.getAnimatedValue());
    });
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            isUpdatingBackground = false;
        }
    });

    anim.setDuration(ANIMATION_DURATION);
    anim.start();
    isUpdatingBackground = true;
}

From source file:com.example.rossetto.organizer.MainActivityFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
private void showProgress(final boolean show) {
    // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
    // for very easy animations. If available, use these APIs to fade-in
    // the progress spinner.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);

        mListView.setVisibility(show ? View.GONE : View.VISIBLE);
        mListView.animate().setDuration(shortAnimTime).alpha(show ? 0 : 1)
                .setListener(new AnimatorListenerAdapter() {
                    @Override//from w ww.j  a v  a  2s  .c o m
                    public void onAnimationEnd(Animator animation) {
                        mListView.setVisibility(show ? View.GONE : View.VISIBLE);
                    }
                });

        mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
        mProgressView.animate().setDuration(shortAnimTime).alpha(show ? 1 : 0)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
                    }
                });
    } else {
        // The ViewPropertyAnimator APIs are not available, so simply show
        // and hide the relevant UI components.
        mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
        mListView.setVisibility(show ? View.GONE : View.VISIBLE);
    }
}

From source file:com.google.samples.apps.iosched.util.LPreviewUtilsBase.java

public void setOrAnimatePlusCheckIcon(final ImageView imageView, boolean isCheck, boolean allowAnimate) {
    final int imageResId = isCheck ? R.drawable.add_schedule_button_icon_checked
            : R.drawable.add_schedule_button_icon_unchecked;

    if (imageView.getTag() != null) {
        if (imageView.getTag() instanceof Animator) {
            Animator anim = (Animator) imageView.getTag();
            anim.end();/*from   w  ww  .  ja  v  a2s.co  m*/
            imageView.setAlpha(1f);
        }
    }

    if (allowAnimate && isCheck) {
        int duration = mActivity.getResources().getInteger(android.R.integer.config_shortAnimTime);

        Animator outAnimator = ObjectAnimator.ofFloat(imageView, View.ALPHA, 0f);
        outAnimator.setDuration(duration / 2);
        outAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setImageResource(imageResId);
            }
        });

        AnimatorSet inAnimator = new AnimatorSet();
        outAnimator.setDuration(duration);
        inAnimator.playTogether(ObjectAnimator.ofFloat(imageView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_X, 0f, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 0f, 1f));

        AnimatorSet set = new AnimatorSet();
        set.playSequentially(outAnimator, inAnimator);
        set.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setTag(null);
            }
        });
        imageView.setTag(set);
        set.start();
    } else {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                imageView.setImageResource(imageResId);
            }
        });
    }
}

From source file:com.baoyz.dribble.widget.SwipeHoverLayout.java

private void startSmoothAnimation(final int state) {
    if (mHoverState == state)
        return;//from   ww  w . j av  a  2s  . c  om
    ensureHoverView();
    switch (state) {
    case HoverState.HIDE:
        mHoverView.animate().alpha(0f).setDuration(ANIMATION_DURATION)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);
                        mHoverState = state;
                        destroyHover();
                    }
                }).start();
        break;
    case HoverState.SHOW:
        mHoverView.animate().alpha(1f).setDuration(ANIMATION_DURATION)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);
                        mHoverState = state;
                    }
                }).start();
        break;
    }
}

From source file:com.example.lsy.animationproject.CrossfadeActivity.java

/**
 * Cross-fades between {@link #mContentView} and {@link #mLoadingView}.
 *///from w w w  .  j  a  v  a 2s.c  o  m
/*
private void crossfade(boolean contentLoaded)
{
//set the content view to 0% opacity but visible
mContentView.setAlpha(0f);
mContentView.setVisibility(View.VISIBLE);
        
//animate the content view to 100% opacity, and clear the animation
//listener set on the view
mContentView.animate()
        .alpha(1f)
        .setDuration(mShortAnimationDuration)
        .setListener(null);
        
//animate the loading view to 0% opacity.
mLoadingView.animate()
        .alpha(0f)
        .setDuration(mShortAnimationDuration)
        .setListener(new AnimatorListenerAdapter() {
            @Override
            //After the animation ends, set its visibility to GONE
            public void onAnimationEnd(Animator animation) {
                mLoadingView.setVisibility(View.GONE);
            }
        });
} */
private void showContentOrLoadingIndicator(boolean contentLoaded) {
    // Decide which view to hide and which to show.
    final View showView = contentLoaded ? mContentView : mLoadingView;
    final View hideView = contentLoaded ? mLoadingView : mContentView;

    // Set the "show" view to 0% opacity but visible, so that it is visible
    // (but fully transparent) during the animation.
    showView.setAlpha(0f);
    showView.setVisibility(View.VISIBLE);

    // Animate the "show" view to 100% opacity, and clear any animation listener set on
    // the view. Remember that listeners are not limited to the specific animation
    // describes in the chained method calls. Listeners are set on the
    // ViewPropertyAnimator object for the view, which persists across several
    // animations.
    showView.animate().alpha(1f).setDuration(mShortAnimationDuration).setListener(null);

    // Animate the "hide" 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.)
    hideView.animate().alpha(0f).setDuration(mShortAnimationDuration)
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    hideView.setVisibility(View.GONE);
                }
            });
}

From source file:co.com.parsoniisolutions.custombottomsheetbehavior.lib.ScrollingAppBarLayoutBehavior.java

public void setAppBarVisible(final AppBarLayout appBarLayout, final boolean visible) {

    if (visible == mVisible)
        return;//from  w  ww  .j  a  va 2s .  c  o m

    if (mAppBarYValueAnimator == null || !mAppBarYValueAnimator.isRunning()) {

        mAppBarYValueAnimator = ValueAnimator.ofFloat((int) appBarLayout.getY(),
                visible ? (int) appBarLayout.getY() + appBarLayout.getHeight() + getStatusBarHeight()
                        : (int) appBarLayout.getY() - appBarLayout.getHeight() - getStatusBarHeight());
        mAppBarYValueAnimator
                .setDuration(mContext.getResources().getInteger(android.R.integer.config_shortAnimTime));
        mAppBarYValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                appBarLayout.setY((Float) animation.getAnimatedValue());

            }
        });
        mAppBarYValueAnimator.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                if (visible)
                    setStatusBarBackgroundVisible(true);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                if (!visible)
                    setStatusBarBackgroundVisible(false);
                mVisible = visible;
                super.onAnimationEnd(animation);
            }
        });
        mAppBarYValueAnimator.start();
    }
}

From source file:com.cryart.sabbathschool.viewmodel.SSQuarterliesViewModel.java

public void onMenuClick() {
    final View view = ssQuarterliesActivityBinding.ssLanguageMenu.ssLanguageMenu;
    final int state = view.getVisibility() == View.VISIBLE ? View.INVISIBLE : View.VISIBLE;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        int centerX = view.getRight();
        int centerY = 0;
        int startRadius = (state == View.VISIBLE) ? 0 : view.getHeight();
        int endRadius = (state == View.VISIBLE) ? view.getHeight() : 0;

        Animator anim = ViewAnimationUtils.createCircularReveal(view, centerX, centerY, startRadius, endRadius);

        if (state == View.VISIBLE) {
            view.setVisibility(state);/*from www . j a  v a2 s  . co m*/
            ssQuarterliesActivityBinding.ssLanguageMenuOverlay.setVisibility(state);

        } else {
            anim.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    view.setVisibility(state);
                    ssQuarterliesActivityBinding.ssLanguageMenuOverlay.setVisibility(state);
                }
            });
        }
        anim.start();
    } else {
        view.setVisibility(state);
        ssQuarterliesActivityBinding.ssLanguageMenuOverlay.setVisibility(state);
    }
}

From source file:com.example.maxuan.photoutils.ViewPagerActivity.java

private void handleSelectedPhotoView(final boolean show) {
    recyclerView.animate().translationY(0).alpha(show ? 1.0f : 0.0f).setListener(new AnimatorListenerAdapter() {
        @Override/*from   w  ww.  j  a v  a 2 s .  c  o m*/
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            recyclerView.setVisibility(show ? View.VISIBLE : View.GONE);
        }
    });
}

From source file:com.nononsenseapps.feeder.ui.SwipeDismissTouchListener.java

@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
    // offset because the view is translated during swipe
    motionEvent.offsetLocation(mTranslationX, 0);

    if (mViewWidth < 2) {
        mViewWidth = mView.getWidth();/*from  w  w w.jav  a 2  s . c  o m*/
    }

    switch (motionEvent.getActionMasked()) {
    case MotionEvent.ACTION_DOWN: {
        // TODO: ensure this is a finger, and set a flag
        mDownX = motionEvent.getRawX();
        mDownY = motionEvent.getRawY();
        if (mCallbacks.canDismiss(mToken)) {
            mVelocityTracker = VelocityTracker.obtain();
            mVelocityTracker.addMovement(motionEvent);
        }
        return false;
    }

    case MotionEvent.ACTION_UP: {
        if (mVelocityTracker == null) {
            break;
        }

        float deltaX = motionEvent.getRawX() - mDownX;
        mVelocityTracker.addMovement(motionEvent);
        mVelocityTracker.computeCurrentVelocity(1000);
        float velocityX = mVelocityTracker.getXVelocity();
        float absVelocityX = Math.abs(velocityX);
        float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
        boolean dismiss = false;
        boolean dismissRight = false;
        if (Math.abs(deltaX) > mViewWidth / 2 && mSwiping) {
            dismiss = true;
            dismissRight = deltaX > 0;
        } else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity
                && absVelocityY < absVelocityX && absVelocityY < absVelocityX && mSwiping) {
            // dismiss only if flinging in the same direction as dragging
            dismiss = (velocityX < 0) == (deltaX < 0);
            dismissRight = mVelocityTracker.getXVelocity() > 0;
        }
        if (dismiss) {
            // dismiss
            mSwipingView.animate().translationX(dismissRight ? mViewWidth : -mViewWidth)
                    //.alpha(0)
                    .setDuration(mAnimationTime).setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            performDismiss();
                        }
                    });
        } else if (mSwiping) {
            // cancel
            mSwipingView.animate().translationX(0)
                    //.alpha(1)
                    .setDuration(mAnimationTime).setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            mCallbacks.onSwipeCancelled();
                        }
                    });
        }
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mTranslationX = 0;
        mDownX = 0;
        mDownY = 0;
        mSwiping = false;
        notNotifiedSwipeStart = true;
        break;
    }

    case MotionEvent.ACTION_CANCEL: {
        if (mVelocityTracker == null) {
            break;
        }

        mSwipingView.animate().translationX(0)
                //.alpha(1)
                .setDuration(mAnimationTime).setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        mCallbacks.onSwipeCancelled();
                    }
                });
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mTranslationX = 0;
        mDownX = 0;
        mDownY = 0;
        mSwiping = false;
        notNotifiedSwipeStart = true;
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        if (mVelocityTracker == null) {
            break;
        }

        mVelocityTracker.addMovement(motionEvent);
        float deltaX = motionEvent.getRawX() - mDownX;
        float deltaY = motionEvent.getRawY() - mDownY;
        if (Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
            mSwiping = true;
            mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
            mView.getParent().requestDisallowInterceptTouchEvent(true);

            // Cancel listview's touch
            MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
            cancelEvent.setAction(MotionEvent.ACTION_CANCEL
                    | (motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
            mView.onTouchEvent(cancelEvent);
            cancelEvent.recycle();
        }

        if (mSwiping) {
            if (notNotifiedSwipeStart) {
                notNotifiedSwipeStart = false;
                mCallbacks.onSwipeStarted(deltaX > 0);
            }
            mTranslationX = deltaX;
            mSwipingView.setTranslationX(deltaX - mSwipingSlop);
            //mView.setAlpha(mInterpolator.getInterpolation(1f - 1f * Math.abs(deltaX) / mViewWidth));
            //                    mView.setAlpha(Math.max(0f, Math.min(1f,
            //                            1f - 2f * Math.abs(deltaX) / mViewWidth)));
            return true;
        }
        break;
    }
    }
    return false;
}

From source file:fr.cph.stock.android.activity.LoginActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
private void showProgress(final boolean show, String errorMessage) {
    // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
    // for very easy animations. If available, use these APIs to fade-in
    // the progress spinner.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);

        mLoginStatusView.setVisibility(View.VISIBLE);
        mLoginStatusView.animate().setDuration(shortAnimTime).alpha(show ? 1 : 0)
                .setListener(new AnimatorListenerAdapter() {
                    @Override/* w ww.j a va2 s  .  com*/
                    public void onAnimationEnd(Animator animation) {
                        mLoginStatusView.setVisibility(show ? View.VISIBLE : View.GONE);
                    }
                });

        mLoginFormView.setVisibility(View.VISIBLE);
        mLoginFormView.animate().setDuration(shortAnimTime).alpha(show ? 0 : 1)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
                    }
                });
    } else {
        // The ViewPropertyAnimator APIs are not available, so simply show
        // and hide the relevant UI components.
        mLoginStatusView.setVisibility(show ? View.VISIBLE : View.GONE);
        mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
    }
    if (!show) {
        errorView.setText(errorMessage);
        errorView.setTextColor(Color.rgb(160, 0, 0));
    }
}