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.bottomsheetbehavior.MergedAppBarLayoutBehavior.java

private boolean setToolbarVisible(boolean visible, final View child) {
    ViewPropertyAnimator mAppBarLayoutAnimation;
    boolean childMoved = false;
    if (visible && !mVisible) {
        childMoved = true;/*from  www .  ja  va2 s .  c o m*/
        child.setY(-child.getHeight() / 3);
        mAppBarLayoutAnimation = child.animate()
                .setDuration(mContext.getResources().getInteger(android.R.integer.config_shortAnimTime));
        mAppBarLayoutAnimation.setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                child.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                mVisible = true;
            }
        });
        mAppBarLayoutAnimation.alpha(1).y(mInitialY).start();
    } else if (!visible && mVisible) {
        mAppBarLayoutAnimation = child.animate()
                .setDuration(mContext.getResources().getInteger(android.R.integer.config_shortAnimTime));
        mAppBarLayoutAnimation.setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                child.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                mVisible = false;
            }
        });
        mAppBarLayoutAnimation.alpha(0).start();
    }

    return childMoved;
}

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

private boolean setToolbarVisible(boolean visible, final View child) {
    ViewPropertyAnimator mAppBarLayoutAnimation;
    boolean childMoved = false;
    if (visible && !mVisible) {
        childMoved = true;//  w w w.  j  a v  a2s  .  c  o  m
        child.setY(-child.getHeight() / 3);
        mAppBarLayoutAnimation = child.animate()
                .setDuration(mContext.getResources().getInteger(android.R.integer.config_shortAnimTime));
        mAppBarLayoutAnimation.setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                child.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                ((AppCompatActivity) mContext).setSupportActionBar(mToolbar);
                mToolbar.setNavigationOnClickListener(mOnNavigationClickListener);
                ActionBar actionBar = ((AppCompatActivity) mContext).getSupportActionBar();
                if (actionBar != null) {
                    actionBar.setDisplayHomeAsUpEnabled(true);
                }
                mVisible = true;
            }
        });
        mAppBarLayoutAnimation.alpha(1).y(mInitialY).start();
    } else if (!visible && mVisible) {
        mAppBarLayoutAnimation = child.animate()
                .setDuration(mContext.getResources().getInteger(android.R.integer.config_shortAnimTime));
        mAppBarLayoutAnimation.setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                child.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                ((AppCompatActivity) mContext).setSupportActionBar(null);
                mVisible = false;
            }
        });
        mAppBarLayoutAnimation.alpha(0).start();
    }

    return childMoved;
}

From source file:com.audionote.widget.SlideSwitch.java

public void moveToDest(final boolean toRight) {
    ValueAnimator toDestAnim = ValueAnimator.ofInt(frontRect_left, toRight ? max_left : min_left);
    toDestAnim.setDuration(200);/*  w w  w  .j av a2s . c  om*/
    toDestAnim.setInterpolator(new AccelerateDecelerateInterpolator());
    toDestAnim.start();
    toDestAnim.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            frontRect_left = (Integer) animation.getAnimatedValue();
            alpha = (int) (255 * (float) frontRect_left / (float) max_left);
            invalidateView();
        }
    });
    toDestAnim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (toRight) {
                isOpen = true;
                if (listener != null)
                    listener.open();
                frontRect_left_begin = max_left;
            } else {
                isOpen = false;
                if (listener != null)
                    listener.close();
                frontRect_left_begin = min_left;
            }
        }
    });
}

From source file:com.activiti.android.app.fragments.account.AccountEditFragment.java

/**
 * Shows the progress UI and hides the login form.
 *///from ww w. ja v  a2s.  com
public void showProgress(final boolean show) {
    int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
    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);
                }
            });
    mFormView.setVisibility(show ? View.GONE : View.VISIBLE);
    mFormView.animate().setDuration(shortAnimTime).alpha(show ? 0 : 1)
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    mFormView.setVisibility(show ? View.GONE : View.VISIBLE);
                }
            });
}

From source file:com.example.fansonlib.widget.calendar.CalendarView.java

/**
 * /*  w ww .  j  a  va  2 s . c o m*/
 *
 * @param year 
 */
public void showSelectLayout(final int year) {
    if (mParentLayout != null && mParentLayout.mContentView != null) {
        mParentLayout.mContentView.setVisibility(GONE);
    }
    mLinearWeek.animate().translationY(-mLinearWeek.getHeight()).setInterpolator(new LinearInterpolator())
            .setDuration(180).setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    mLinearWeek.setVisibility(GONE);
                    mSelectLayout.setVisibility(VISIBLE);
                    mSelectLayout.init(year);
                }
            });
    mViewPager.animate().scaleX(0).scaleY(0).setDuration(180).setInterpolator(new LinearInterpolator())
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    mViewPager.setVisibility(GONE);
                }
            });
}

From source file:com.android.volley.ui.NetworkImageView.java

@SuppressLint("NewApi")
private void setAnimateImageBitmap(final Bitmap bitmap, boolean fadeIn) {

    // If we're fading in and on HC MR1+
    if (fadeIn && Utils.hasHoneycombMR1()) {
        // Use ViewPropertyAnimator to run a simple fade in + fade out animation to update the
        // ImageView
        animate().scaleY(0.95f).scaleX(0.95f).alpha(0f)
                .setDuration(getDrawable() == null ? 0 : HALF_FADE_IN_TIME)
                .setListener(new AnimatorListenerAdapter() {
                    @Override//from   ww  w . j a v a 2  s .co  m
                    public void onAnimationEnd(Animator animation) {
                        setImageBitmap(bitmap);
                        animate().alpha(1f).scaleY(1f).scaleX(1f).setDuration(HALF_FADE_IN_TIME)
                                .setListener(null);
                    }
                });
    } else if (fadeIn) {
        // Otherwise use a TransitionDrawable to fade in
        Drawable initialDrawable;
        if (getDrawable() != null) {
            initialDrawable = getDrawable();
        } else {
            initialDrawable = transparentDrawable;
        }

        BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
        // Use TransitionDrawable to fade in
        final TransitionDrawable td = new TransitionDrawable(
                new Drawable[] { initialDrawable, bitmapDrawable });
        setImageDrawable(td);
        td.startTransition(Utils.ANIMATION_FADE_IN_TIME);
    } else {
        // No fade in, just set bitmap directly
        setImageBitmap(bitmap);
    }
}

From source file:com.msn.support.gallery.ZoomActivity.java

/**
 * "Zooms" in a thumbnail view by assigning the high resolution image to a hidden "zoomed-in"
 * image view and animating its bounds to fit the entire activity content area. More
 * specifically://from   w ww . j  a  v a2  s. c  om
 * <ol>
 *   <li>Assign the high-res image to the hidden "zoomed-in" (expanded) image view.</li>
 *   <li>Calculate the starting and ending bounds for the expanded view.</li>
 *   <li>Animate each of four positioning/sizing properties (X, Y, SCALE_X, SCALE_Y)
 *       simultaneously, from the starting bounds to the ending bounds.</li>
 *   <li>Zoom back out by running the reverse animation on click.</li>
 * </ol>
 * ??ImageView?
 * Activity
 * <ol>
 *     <li>???ImageView</li>
 *     <li>?ImageView?</li>
 *     <li>??ImageView?/?X, Y, SCALE_X, SCALE_Y
 *     ??</li>
 *     <li>???</li>
 * @param thumbView  The thumbnail view to zoom in. 
 * @param imageResId The high-resolution version of the image represented by the thumbnail.
 *                   
 */
@TargetApi(11)
private void zoomImageFromThumb(final View thumbView, int imageResId) {
    // If there's an animation in progress, cancel it immediately and proceed with this one.
    // ?
    if (mCurrentAnimator != null) {
        mCurrentAnimator.cancel();
    }

    // Load the high-resolution "zoomed-in" image.?ImageView
    final ImageView expandedImageView = (ImageView) findViewById(R.id.expanded_image);
    expandedImageView.setImageResource(imageResId);

    // Calculate the starting and ending bounds for the zoomed-in image. This step
    // involves lots of math. Yay, math.
    //?ImageView??
    final Rect startBounds = new Rect();
    final Rect finalBounds = new Rect();
    final Point globalOffset = new Point();

    // The start bounds are the global visible rectangle of the thumbnail, and the
    // final bounds are the global visible rectangle of the container view. Also
    // set the container view's offset as the origin for the bounds, since that's
    // the origin for the positioning animation properties (X, Y).
    // ?????
    // ????
    thumbView.getGlobalVisibleRect(startBounds);
    findViewById(R.id.container).getGlobalVisibleRect(finalBounds, globalOffset);
    Log.e("Test", "globalOffset.x=" + globalOffset.x + " globalOffset.y=" + globalOffset.y);
    Log.e("Test", "startBounds.top=" + startBounds.top + " startBounds.left=" + startBounds.left);
    startBounds.offset(-globalOffset.x, -globalOffset.y);
    Log.e("Test", "startBounds2.top=" + startBounds.top + " startBounds2.left=" + startBounds.left);
    finalBounds.offset(-globalOffset.x, -globalOffset.y);

    // Adjust the start bounds to be the same aspect ratio as the final bounds using the
    // "center crop" technique. This prevents undesirable stretching during the animation.
    // Also calculate the start scaling factor (the end scaling factor is always 1.0).
    // ??"center crop"???
    // ????1.0
    float startScale;
    if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width()
            / startBounds.height()) {
        // Extend start bounds horizontally ?
        startScale = (float) startBounds.height() / finalBounds.height();
        float startWidth = startScale * finalBounds.width();
        float deltaWidth = (startWidth - startBounds.width()) / 2;
        startBounds.left -= deltaWidth;
        startBounds.right += deltaWidth;
    } else {
        // Extend start bounds vertically ?
        startScale = (float) startBounds.width() / finalBounds.width();
        float startHeight = startScale * finalBounds.height();
        float deltaHeight = (startHeight - startBounds.height()) / 2;
        startBounds.top -= deltaHeight;
        startBounds.bottom += deltaHeight;
    }

    // Hide the thumbnail and show the zoomed-in view. When the animation begins,
    // it will position the zoomed-in view in the place of the thumbnail.
    //thumbView.setAlpha(0f);
    expandedImageView.setVisibility(View.VISIBLE);

    // Set the pivot point for SCALE_X and SCALE_Y transformations to the top-left corner of
    // the zoomed-in view (the default is the center of the view).
    expandedImageView.setPivotX(0f);
    expandedImageView.setPivotY(0f);

    // Construct and run the parallel animation of the four translation and scale properties
    // (X, Y, SCALE_X, and SCALE_Y).
    AnimatorSet set = new AnimatorSet();
    set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left, finalBounds.left))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top, finalBounds.top))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale, 1f))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale, 1f));
    set.setDuration(mShortAnimationDuration);
    set.setInterpolator(new DecelerateInterpolator());
    set.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mCurrentAnimator = null;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            mCurrentAnimator = null;
        }
    });
    set.start();
    mCurrentAnimator = set;

    // Upon clicking the zoomed-in image, it should zoom back down to the original bounds
    // and show the thumbnail instead of the expanded image.
    final float startScaleFinal = startScale;
    expandedImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mCurrentAnimator != null) {
                mCurrentAnimator.cancel();
            }

            // Animate the four positioning/sizing properties in parallel, back to their
            // original values.
            AnimatorSet set = new AnimatorSet();
            set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScaleFinal))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScaleFinal));
            set.setDuration(mShortAnimationDuration);
            set.setInterpolator(new DecelerateInterpolator());
            set.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    mCurrentAnimator = null;
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    mCurrentAnimator = null;
                }
            });
            set.start();
            mCurrentAnimator = set;
        }
    });
}

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

private void animateViewFadeIn(final View view) {
    view.animate().alpha(1f).setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime))
            .setListener(new AnimatorListenerAdapter() {
                @Override/*from   w  w  w .  ja v  a2s .  c  o m*/
                public void onAnimationStart(Animator animation) {
                    super.onAnimationStart(animation);
                    view.setVisibility(View.VISIBLE);
                }
            }).start();
}

From source file:com.github.shareme.gwsswwipetodismiss.library.SwipeDismissListViewTouchListener.java

@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
    if (mViewWidth < 2) {
        mViewWidth = mListView.getWidth();
    }/*from  w  w w. j  av  a 2 s .c  o m*/

    switch (MotionEventCompat.getActionMasked(motionEvent)) {
    case MotionEvent.ACTION_DOWN: {
        if (mPaused) {
            return false;
        }

        // TODO: ensure this is a finger, and set a flag

        // Find the child view that was touched (perform a hit test)
        Rect rect = new Rect();
        int childCount = mListView.getChildCount();
        int[] listViewCoords = new int[2];
        mListView.getLocationOnScreen(listViewCoords);
        int x = (int) motionEvent.getRawX() - listViewCoords[0];
        int y = (int) motionEvent.getRawY() - listViewCoords[1];
        View child;
        for (int i = 0; i < childCount; i++) {
            child = mListView.getChildAt(i);
            child.getHitRect(rect);
            if (rect.contains(x, y)) {
                mDownView = child;
                break;
            }
        }

        if (mDownView != null) {
            mDownX = motionEvent.getRawX();
            mDownY = motionEvent.getRawY();
            mDownPosition = mListView.getPositionForView(mDownView);
            mCanDismissCurrent = null != mCallback && mCallback.canDismiss(mListView, mDownPosition);

            mVelocityTracker = VelocityTracker.obtain();
            mVelocityTracker.addMovement(motionEvent);
        }
        view.onTouchEvent(motionEvent);
        return true;
    }

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

        float deltaX = motionEvent.getRawX() - mDownX;
        float deltaY = motionEvent.getRawY() - mDownY;
        mVelocityTracker.addMovement(motionEvent);
        mVelocityTracker.computeCurrentVelocity(1000);
        float velocityX = Math.abs(mVelocityTracker.getXVelocity());
        float velocityY = Math.abs(mVelocityTracker.getYVelocity());
        boolean dismiss = false;
        boolean dismissRight = false;

        if (mCanDismissCurrent && Math.abs(deltaY) < Math.abs(deltaX)) {
            if (Math.abs(deltaX) > mViewWidth / 2) {
                dismiss = true;
                dismissRight = deltaX > 0;
            } else if (Math.abs(deltaX) > mSlop && mMinFlingVelocity <= velocityX
                    && velocityX <= mMaxFlingVelocity && velocityY < velocityX) {
                dismiss = true;
                dismissRight = mVelocityTracker.getXVelocity() > 0;
            }
        }

        if (dismiss) {
            // dismiss
            final View downView = mDownView; // mDownView gets null'd before animation ends
            final int downPosition = mDownPosition;
            ++mDismissAnimationRefCount;
            mDownView.animate().translationX(dismissRight ? mViewWidth : -mViewWidth).alpha(0)
                    .setDuration(mAnimationTime).setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            performDismiss(downView, downPosition);
                        }
                    });
        } else {
            // cancel
            mDownView.animate().translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
        }

        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mDownX = 0;
        mDownY = 0;
        mDownView = null;
        mDownPosition = ListView.INVALID_POSITION;
        mSwiping = false;
        mCanDismissCurrent = false;
        break;
    }

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

        mVelocityTracker.addMovement(motionEvent);
        float deltaX = motionEvent.getRawX() - mDownX;
        if (Math.abs(deltaX) > mSlop) {
            mSwiping = true;
            mListView.requestDisallowInterceptTouchEvent(true);

            // Cancel ListView's touch (un-highlighting the item)
            MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
            cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (MotionEventCompat
                    .getActionIndex(motionEvent) << MotionEventCompat.ACTION_POINTER_INDEX_SHIFT));
            mListView.onTouchEvent(cancelEvent);
        }

        if (mSwiping) {
            if (mCanDismissCurrent) {
                setTranslationX(mDownView, deltaX);
                setAlpha(mDownView, Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth)));
            } else {
                setTranslationX(mDownView, deltaX * 0.2f);
            }
            return true;
        }
        break;
    }
    }
    return false;
}

From source file:com.personal.taskmanager2.utilities.RecyclerViewTouchListener.java

private void dismiss(final View view, final int position, boolean dismissRight) {

    view.animate().translationX(dismissRight ? mViewWidth : -mViewWidth).alpha(0).setDuration(mAnimationTime)
            .setListener(new AnimatorListenerAdapter() {
                @Override/*from ww  w . j  av  a 2  s.  c o  m*/
                public void onAnimationEnd(Animator animation) {
                    //performDismiss(view, position);
                }
            });
}