Example usage for android.animation AnimatorSet AnimatorSet

List of usage examples for android.animation AnimatorSet AnimatorSet

Introduction

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

Prototype

public AnimatorSet() 

Source Link

Usage

From source file:com.android.mail.browse.ConversationItemView.java

/**
 * Grow the height of the item and fade it in when bringing a conversation
 * back from a destructive action.//w w  w .  j a  va 2  s .  co  m
 */
public Animator createUndoAnimation() {
    ObjectAnimator height = createHeightAnimation(true);
    Animator fade = ObjectAnimator.ofFloat(this, "alpha", 0, 1.0f);
    fade.setDuration(sShrinkAnimationDuration);
    fade.setInterpolator(new DecelerateInterpolator(2.0f));
    AnimatorSet transitionSet = new AnimatorSet();
    transitionSet.playTogether(height, fade);
    transitionSet.addListener(new HardwareLayerEnabler(this));
    return transitionSet;
}

From source file:cc.flydev.launcher.Page.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (DISABLE_TOUCH_INTERACTION) {
        return false;
    }/*from www .  j a  v  a 2s .com*/

    super.onTouchEvent(ev);

    // Skip touch handling if there are no pages to swipe
    if (getChildCount() <= 0)
        return super.onTouchEvent(ev);

    acquireVelocityTrackerAndAddMovement(ev);

    final int action = ev.getAction();

    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        /*
         * If being flinged and user touches, stop the fling. isFinished
         * will be false if being flinged.
         */
        if (!mScroller.isFinished()) {
            mScroller.abortAnimation();
        }

        // Remember where the motion event started
        mDownMotionX = mLastMotionX = ev.getX();
        mDownMotionY = mLastMotionY = ev.getY();
        mDownScrollX = getScrollX();
        float[] p = mapPointFromViewToParent(this, mLastMotionX, mLastMotionY);
        mParentDownMotionX = p[0];
        mParentDownMotionY = p[1];
        mLastMotionXRemainder = 0;
        mTotalMotionX = 0;
        mActivePointerId = ev.getPointerId(0);

        if (mTouchState == TOUCH_STATE_SCROLLING) {
            pageBeginMoving();
        }
        break;

    case MotionEvent.ACTION_MOVE:
        if (mTouchState == TOUCH_STATE_SCROLLING) {
            // Scroll to follow the motion event
            final int pointerIndex = ev.findPointerIndex(mActivePointerId);

            if (pointerIndex == -1)
                return true;

            final float x = ev.getX(pointerIndex);
            final float deltaX = mLastMotionX + mLastMotionXRemainder - x;

            mTotalMotionX += Math.abs(deltaX);

            // Only scroll and update mLastMotionX if we have moved some discrete amount.  We
            // keep the remainder because we are actually testing if we've moved from the last
            // scrolled position (which is discrete).
            if (Math.abs(deltaX) >= 1.0f) {
                mTouchX += deltaX;
                mSmoothingTime = System.nanoTime() / NANOTIME_DIV;
                if (!mDeferScrollUpdate) {
                    scrollBy((int) deltaX, 0);
                    if (DEBUG)
                        Log.d(TAG, "onTouchEvent().Scrolling: " + deltaX);
                } else {
                    invalidate();
                }
                mLastMotionX = x;
                mLastMotionXRemainder = deltaX - (int) deltaX;
            } else {
                awakenScrollBars();
            }
        } else if (mTouchState == TOUCH_STATE_REORDERING) {
            // Update the last motion position
            mLastMotionX = ev.getX();
            mLastMotionY = ev.getY();

            // Update the parent down so that our zoom animations take this new movement into
            // account
            float[] pt = mapPointFromViewToParent(this, mLastMotionX, mLastMotionY);
            mParentDownMotionX = pt[0];
            mParentDownMotionY = pt[1];
            updateDragViewTranslationDuringDrag();

            // Find the closest page to the touch point
            final int dragViewIndex = indexOfChild(mDragView);

            // Change the drag view if we are hovering over the drop target
            boolean isHoveringOverDelete = isHoveringOverDeleteDropTarget((int) mParentDownMotionX,
                    (int) mParentDownMotionY);
            setPageHoveringOverDeleteDropTarget(dragViewIndex, isHoveringOverDelete);

            if (DEBUG)
                Log.d(TAG, "mLastMotionX: " + mLastMotionX);
            if (DEBUG)
                Log.d(TAG, "mLastMotionY: " + mLastMotionY);
            if (DEBUG)
                Log.d(TAG, "mParentDownMotionX: " + mParentDownMotionX);
            if (DEBUG)
                Log.d(TAG, "mParentDownMotionY: " + mParentDownMotionY);

            final int pageUnderPointIndex = getNearestHoverOverPageIndex();
            if (pageUnderPointIndex > -1 && pageUnderPointIndex != indexOfChild(mDragView)
                    && !isHoveringOverDelete) {
                mTempVisiblePagesRange[0] = 0;
                mTempVisiblePagesRange[1] = getPageCount() - 1;
                getOverviewModePages(mTempVisiblePagesRange);
                if (mTempVisiblePagesRange[0] <= pageUnderPointIndex
                        && pageUnderPointIndex <= mTempVisiblePagesRange[1]
                        && pageUnderPointIndex != mSidePageHoverIndex && mScroller.isFinished()) {
                    mSidePageHoverIndex = pageUnderPointIndex;
                    mSidePageHoverRunnable = new Runnable() {
                        @Override
                        public void run() {
                            // Setup the scroll to the correct page before we swap the views
                            snapToPage(pageUnderPointIndex);

                            // For each of the pages between the paged view and the drag view,
                            // animate them from the previous position to the new position in
                            // the layout (as a result of the drag view moving in the layout)
                            int shiftDelta = (dragViewIndex < pageUnderPointIndex) ? -1 : 1;
                            int lowerIndex = (dragViewIndex < pageUnderPointIndex) ? dragViewIndex + 1
                                    : pageUnderPointIndex;
                            int upperIndex = (dragViewIndex > pageUnderPointIndex) ? dragViewIndex - 1
                                    : pageUnderPointIndex;
                            for (int i = lowerIndex; i <= upperIndex; ++i) {
                                View v = getChildAt(i);
                                // dragViewIndex < pageUnderPointIndex, so after we remove the
                                // drag view all subsequent views to pageUnderPointIndex will
                                // shift down.
                                int oldX = getViewportOffsetX() + getChildOffset(i);
                                int newX = getViewportOffsetX() + getChildOffset(i + shiftDelta);

                                // Animate the view translation from its old position to its new
                                // position
                                AnimatorSet anim = (AnimatorSet) v.getTag(ANIM_TAG_KEY);
                                if (anim != null) {
                                    anim.cancel();
                                }

                                v.setTranslationX(oldX - newX);
                                anim = new AnimatorSet();
                                anim.setDuration(REORDERING_REORDER_REPOSITION_DURATION);
                                anim.playTogether(ObjectAnimator.ofFloat(v, "translationX", 0f));
                                anim.start();
                                v.setTag(anim);
                            }

                            removeView(mDragView);
                            onRemoveView(mDragView, false);
                            addView(mDragView, pageUnderPointIndex);
                            onAddView(mDragView, pageUnderPointIndex);
                            mSidePageHoverIndex = -1;
                            mPageIndicator.setActiveMarker(getNextPage());
                        }
                    };
                    postDelayed(mSidePageHoverRunnable, REORDERING_SIDE_PAGE_HOVER_TIMEOUT);
                }
            } else {
                removeCallbacks(mSidePageHoverRunnable);
                mSidePageHoverIndex = -1;
            }
        } else {
            determineScrollingStart(ev);
        }
        break;

    case MotionEvent.ACTION_UP:
        if (mTouchState == TOUCH_STATE_SCROLLING) {
            final int activePointerId = mActivePointerId;
            final int pointerIndex = ev.findPointerIndex(activePointerId);
            final float x = ev.getX(pointerIndex);
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            int velocityX = (int) velocityTracker.getXVelocity(activePointerId);
            final int deltaX = (int) (x - mDownMotionX);
            final int pageWidth = getPageAt(mCurrentPage).getMeasuredWidth();
            boolean isSignificantMove = Math.abs(deltaX) > pageWidth * SIGNIFICANT_MOVE_THRESHOLD;

            mTotalMotionX += Math.abs(mLastMotionX + mLastMotionXRemainder - x);

            boolean isFling = mTotalMotionX > MIN_LENGTH_FOR_FLING
                    && Math.abs(velocityX) > mFlingThresholdVelocity;

            if (!mFreeScroll) {
                // In the case that the page is moved far to one direction and then is flung
                // in the opposite direction, we use a threshold to determine whether we should
                // just return to the starting page, or if we should skip one further.
                boolean returnToOriginalPage = false;
                if (Math.abs(deltaX) > pageWidth * RETURN_TO_ORIGINAL_PAGE_THRESHOLD
                        && Math.signum(velocityX) != Math.signum(deltaX) && isFling) {
                    returnToOriginalPage = true;
                }

                int finalPage;
                // We give flings precedence over large moves, which is why we short-circuit our
                // test for a large move if a fling has been registered. That is, a large
                // move to the left and fling to the right will register as a fling to the right.
                final boolean isRtl = isLayoutRtl();
                boolean isDeltaXLeft = isRtl ? deltaX > 0 : deltaX < 0;
                boolean isVelocityXLeft = isRtl ? velocityX > 0 : velocityX < 0;
                if (((isSignificantMove && !isDeltaXLeft && !isFling) || (isFling && !isVelocityXLeft))
                        && mCurrentPage > 0) {
                    finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage - 1;
                    snapToPageWithVelocity(finalPage, velocityX);
                } else if (((isSignificantMove && isDeltaXLeft && !isFling) || (isFling && isVelocityXLeft))
                        && mCurrentPage < getChildCount() - 1) {
                    finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage + 1;
                    snapToPageWithVelocity(finalPage, velocityX);
                } else {
                    snapToDestination();
                }
            } else if (mTouchState == TOUCH_STATE_PREV_PAGE) {
                // at this point we have not moved beyond the touch slop
                // (otherwise mTouchState would be TOUCH_STATE_SCROLLING), so
                // we can just page
                int nextPage = Math.max(0, mCurrentPage - 1);
                if (nextPage != mCurrentPage) {
                    snapToPage(nextPage);
                } else {
                    snapToDestination();
                }
            } else {
                if (!mScroller.isFinished()) {
                    mScroller.abortAnimation();
                }

                float scaleX = getScaleX();
                int vX = (int) (-velocityX * scaleX);
                int initialScrollX = (int) (getScrollX() * scaleX);

                mScroller.fling(initialScrollX, getScrollY(), vX, 0, Integer.MIN_VALUE, Integer.MAX_VALUE, 0,
                        0);
                invalidate();
            }
        } else if (mTouchState == TOUCH_STATE_NEXT_PAGE) {
            // at this point we have not moved beyond the touch slop
            // (otherwise mTouchState would be TOUCH_STATE_SCROLLING), so
            // we can just page
            int nextPage = Math.min(getChildCount() - 1, mCurrentPage + 1);
            if (nextPage != mCurrentPage) {
                snapToPage(nextPage);
            } else {
                snapToDestination();
            }
        } else if (mTouchState == TOUCH_STATE_REORDERING) {
            // Update the last motion position
            mLastMotionX = ev.getX();
            mLastMotionY = ev.getY();

            // Update the parent down so that our zoom animations take this new movement into
            // account
            float[] pt = mapPointFromViewToParent(this, mLastMotionX, mLastMotionY);
            mParentDownMotionX = pt[0];
            mParentDownMotionY = pt[1];
            updateDragViewTranslationDuringDrag();
            boolean handledFling = false;
            if (!DISABLE_FLING_TO_DELETE) {
                // Check the velocity and see if we are flinging-to-delete
                PointF flingToDeleteVector = isFlingingToDelete();
                if (flingToDeleteVector != null) {
                    onFlingToDelete(flingToDeleteVector);
                    handledFling = true;
                }
            }
            if (!handledFling
                    && isHoveringOverDeleteDropTarget((int) mParentDownMotionX, (int) mParentDownMotionY)) {
                onDropToDelete();
            }
        } else {
            if (!mCancelTap) {
                onUnhandledTap(ev);
            }
        }

        // Remove the callback to wait for the side page hover timeout
        removeCallbacks(mSidePageHoverRunnable);
        // End any intermediate reordering states
        resetTouchState();
        break;

    case MotionEvent.ACTION_CANCEL:
        if (mTouchState == TOUCH_STATE_SCROLLING) {
            snapToDestination();
        }
        resetTouchState();
        break;

    case MotionEvent.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        releaseVelocityTracker();
        break;
    }

    return true;
}

From source file:com.android.mail.browse.ConversationItemView.java

/**
 * Grow the height of the item and fade it in when bringing a conversation
 * back from a destructive action.//from   w  w w .  ja v a  2 s . c o  m
 */
public Animator createDestroyWithSwipeAnimation() {
    ObjectAnimator slide = createTranslateXAnimation(false);
    ObjectAnimator height = createHeightAnimation(false);
    AnimatorSet transitionSet = new AnimatorSet();
    transitionSet.playSequentially(slide, height);
    return transitionSet;
}

From source file:com.n2hsu.launcher.Page.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (DISABLE_TOUCH_INTERACTION) {
        return false;
    }/*from  w w w  .  j a  va 2s  .  com*/

    super.onTouchEvent(ev);

    // Skip touch handling if there are no pages to swipe
    if (getChildCount() <= 0)
        return super.onTouchEvent(ev);

    acquireVelocityTrackerAndAddMovement(ev);

    final int action = ev.getAction();

    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        /*
         * If being flinged and user touches, stop the fling. isFinished
         * will be false if being flinged.
         */
        if (!mScroller.isFinished()) {
            mScroller.abortAnimation();
        }

        // Remember where the motion event started
        mDownMotionX = mLastMotionX = ev.getX();
        mDownMotionY = mLastMotionY = ev.getY();
        mDownScrollX = getScrollX();
        float[] p = mapPointFromViewToParent(this, mLastMotionX, mLastMotionY);
        mParentDownMotionX = p[0];
        mParentDownMotionY = p[1];
        mLastMotionXRemainder = 0;
        mTotalMotionX = 0;
        mActivePointerId = ev.getPointerId(0);

        if (mTouchState == TOUCH_STATE_SCROLLING) {
            pageBeginMoving();
        }
        break;

    case MotionEvent.ACTION_MOVE:
        if (mTouchState == TOUCH_STATE_SCROLLING) {
            // Scroll to follow the motion event
            final int pointerIndex = ev.findPointerIndex(mActivePointerId);

            if (pointerIndex == -1)
                return true;

            final float x = ev.getX(pointerIndex);
            final float deltaX = mLastMotionX + mLastMotionXRemainder - x;

            mTotalMotionX += Math.abs(deltaX);

            // Only scroll and update mLastMotionX if we have moved some
            // discrete amount. We
            // keep the remainder because we are actually testing if we've
            // moved from the last
            // scrolled position (which is discrete).
            if (Math.abs(deltaX) >= 1.0f) {
                mTouchX += deltaX;
                mSmoothingTime = System.nanoTime() / NANOTIME_DIV;
                if (!mDeferScrollUpdate) {
                    scrollBy((int) deltaX, 0);
                    if (DEBUG)
                        Log.d(TAG, "onTouchEvent().Scrolling: " + deltaX);
                } else {
                    invalidate();
                }
                mLastMotionX = x;
                mLastMotionXRemainder = deltaX - (int) deltaX;
            } else {
                awakenScrollBars();
            }
        } else if (mTouchState == TOUCH_STATE_REORDERING) {
            // Update the last motion position
            mLastMotionX = ev.getX();
            mLastMotionY = ev.getY();

            // Update the parent down so that our zoom animations take this
            // new movement into
            // account
            float[] pt = mapPointFromViewToParent(this, mLastMotionX, mLastMotionY);
            mParentDownMotionX = pt[0];
            mParentDownMotionY = pt[1];
            updateDragViewTranslationDuringDrag();

            // Find the closest page to the touch point
            final int dragViewIndex = indexOfChild(mDragView);

            // Change the drag view if we are hovering over the drop target
            boolean isHoveringOverDelete = isHoveringOverDeleteDropTarget((int) mParentDownMotionX,
                    (int) mParentDownMotionY);
            setPageHoveringOverDeleteDropTarget(dragViewIndex, isHoveringOverDelete);

            if (DEBUG)
                Log.d(TAG, "mLastMotionX: " + mLastMotionX);
            if (DEBUG)
                Log.d(TAG, "mLastMotionY: " + mLastMotionY);
            if (DEBUG)
                Log.d(TAG, "mParentDownMotionX: " + mParentDownMotionX);
            if (DEBUG)
                Log.d(TAG, "mParentDownMotionY: " + mParentDownMotionY);

            final int pageUnderPointIndex = getNearestHoverOverPageIndex();
            if (pageUnderPointIndex > -1 && pageUnderPointIndex != indexOfChild(mDragView)
                    && !isHoveringOverDelete) {
                mTempVisiblePagesRange[0] = 0;
                mTempVisiblePagesRange[1] = getPageCount() - 1;
                getOverviewModePages(mTempVisiblePagesRange);
                if (mTempVisiblePagesRange[0] <= pageUnderPointIndex
                        && pageUnderPointIndex <= mTempVisiblePagesRange[1]
                        && pageUnderPointIndex != mSidePageHoverIndex && mScroller.isFinished()) {
                    mSidePageHoverIndex = pageUnderPointIndex;
                    mSidePageHoverRunnable = new Runnable() {
                        @Override
                        public void run() {
                            // Setup the scroll to the correct page before
                            // we swap the views
                            snapToPage(pageUnderPointIndex);

                            // For each of the pages between the paged view
                            // and the drag view,
                            // animate them from the previous position to
                            // the new position in
                            // the layout (as a result of the drag view
                            // moving in the layout)
                            int shiftDelta = (dragViewIndex < pageUnderPointIndex) ? -1 : 1;
                            int lowerIndex = (dragViewIndex < pageUnderPointIndex) ? dragViewIndex + 1
                                    : pageUnderPointIndex;
                            int upperIndex = (dragViewIndex > pageUnderPointIndex) ? dragViewIndex - 1
                                    : pageUnderPointIndex;
                            for (int i = lowerIndex; i <= upperIndex; ++i) {
                                View v = getChildAt(i);
                                // dragViewIndex < pageUnderPointIndex, so
                                // after we remove the
                                // drag view all subsequent views to
                                // pageUnderPointIndex will
                                // shift down.
                                int oldX = getViewportOffsetX() + getChildOffset(i);
                                int newX = getViewportOffsetX() + getChildOffset(i + shiftDelta);

                                // Animate the view translation from its old
                                // position to its new
                                // position
                                AnimatorSet anim = (AnimatorSet) v.getTag(ANIM_TAG_KEY);
                                if (anim != null) {
                                    anim.cancel();
                                }

                                v.setTranslationX(oldX - newX);
                                anim = new AnimatorSet();
                                anim.setDuration(REORDERING_REORDER_REPOSITION_DURATION);
                                anim.playTogether(ObjectAnimator.ofFloat(v, "translationX", 0f));
                                anim.start();
                                v.setTag(anim);
                            }

                            removeView(mDragView);
                            onRemoveView(mDragView, false);
                            addView(mDragView, pageUnderPointIndex);
                            onAddView(mDragView, pageUnderPointIndex);
                            mSidePageHoverIndex = -1;
                            mPageIndicator.setActiveMarker(getNextPage());
                        }
                    };
                    postDelayed(mSidePageHoverRunnable, REORDERING_SIDE_PAGE_HOVER_TIMEOUT);
                }
            } else {
                removeCallbacks(mSidePageHoverRunnable);
                mSidePageHoverIndex = -1;
            }
        } else {
            determineScrollingStart(ev);
        }
        break;

    case MotionEvent.ACTION_UP:
        if (mTouchState == TOUCH_STATE_SCROLLING) {
            final int activePointerId = mActivePointerId;
            final int pointerIndex = ev.findPointerIndex(activePointerId);
            final float x = ev.getX(pointerIndex);
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            int velocityX = (int) velocityTracker.getXVelocity(activePointerId);
            final int deltaX = (int) (x - mDownMotionX);
            final int pageWidth = getPageAt(mCurrentPage).getMeasuredWidth();
            boolean isSignificantMove = Math.abs(deltaX) > pageWidth * SIGNIFICANT_MOVE_THRESHOLD;

            mTotalMotionX += Math.abs(mLastMotionX + mLastMotionXRemainder - x);

            boolean isFling = mTotalMotionX > MIN_LENGTH_FOR_FLING
                    && Math.abs(velocityX) > mFlingThresholdVelocity;

            if (!mFreeScroll) {
                // In the case that the page is moved far to one direction
                // and then is flung
                // in the opposite direction, we use a threshold to
                // determine whether we should
                // just return to the starting page, or if we should skip
                // one further.
                boolean returnToOriginalPage = false;
                if (Math.abs(deltaX) > pageWidth * RETURN_TO_ORIGINAL_PAGE_THRESHOLD
                        && Math.signum(velocityX) != Math.signum(deltaX) && isFling) {
                    returnToOriginalPage = true;
                }

                int finalPage;
                // We give flings precedence over large moves, which is why
                // we short-circuit our
                // test for a large move if a fling has been registered.
                // That is, a large
                // move to the left and fling to the right will register as
                // a fling to the right.
                final boolean isRtl = isLayoutRtl();
                boolean isDeltaXLeft = isRtl ? deltaX > 0 : deltaX < 0;
                boolean isVelocityXLeft = isRtl ? velocityX > 0 : velocityX < 0;
                if (((isSignificantMove && !isDeltaXLeft && !isFling) || (isFling && !isVelocityXLeft))
                        && mCurrentPage > 0) {
                    finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage - 1;
                    snapToPageWithVelocity(finalPage, velocityX);
                } else if (((isSignificantMove && isDeltaXLeft && !isFling) || (isFling && isVelocityXLeft))
                        && mCurrentPage < getChildCount() - 1) {
                    finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage + 1;
                    snapToPageWithVelocity(finalPage, velocityX);
                } else {
                    snapToDestination();
                }
            } else if (mTouchState == TOUCH_STATE_PREV_PAGE) {
                // at this point we have not moved beyond the touch slop
                // (otherwise mTouchState would be TOUCH_STATE_SCROLLING),
                // so
                // we can just page
                int nextPage = Math.max(0, mCurrentPage - 1);
                if (nextPage != mCurrentPage) {
                    snapToPage(nextPage);
                } else {
                    snapToDestination();
                }
            } else {
                if (!mScroller.isFinished()) {
                    mScroller.abortAnimation();
                }

                float scaleX = getScaleX();
                int vX = (int) (-velocityX * scaleX);
                int initialScrollX = (int) (getScrollX() * scaleX);

                mScroller.fling(initialScrollX, getScrollY(), vX, 0, Integer.MIN_VALUE, Integer.MAX_VALUE, 0,
                        0);
                invalidate();
            }
        } else if (mTouchState == TOUCH_STATE_NEXT_PAGE) {
            // at this point we have not moved beyond the touch slop
            // (otherwise mTouchState would be TOUCH_STATE_SCROLLING), so
            // we can just page
            int nextPage = Math.min(getChildCount() - 1, mCurrentPage + 1);
            if (nextPage != mCurrentPage) {
                snapToPage(nextPage);
            } else {
                snapToDestination();
            }
        } else if (mTouchState == TOUCH_STATE_REORDERING) {
            // Update the last motion position
            mLastMotionX = ev.getX();
            mLastMotionY = ev.getY();

            // Update the parent down so that our zoom animations take this
            // new movement into
            // account
            float[] pt = mapPointFromViewToParent(this, mLastMotionX, mLastMotionY);
            mParentDownMotionX = pt[0];
            mParentDownMotionY = pt[1];
            updateDragViewTranslationDuringDrag();
            boolean handledFling = false;
            if (!DISABLE_FLING_TO_DELETE) {
                // Check the velocity and see if we are flinging-to-delete
                PointF flingToDeleteVector = isFlingingToDelete();
                if (flingToDeleteVector != null) {
                    onFlingToDelete(flingToDeleteVector);
                    handledFling = true;
                }
            }
            if (!handledFling
                    && isHoveringOverDeleteDropTarget((int) mParentDownMotionX, (int) mParentDownMotionY)) {
                onDropToDelete();
            }
        } else {
            if (!mCancelTap) {
                onUnhandledTap(ev);
            }
        }

        // Remove the callback to wait for the side page hover timeout
        removeCallbacks(mSidePageHoverRunnable);
        // End any intermediate reordering states
        resetTouchState();
        break;

    case MotionEvent.ACTION_CANCEL:
        if (mTouchState == TOUCH_STATE_SCROLLING) {
            snapToDestination();
        }
        resetTouchState();
        break;

    case MotionEvent.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        releaseVelocityTracker();
        break;
    }

    return true;
}

From source file:org.telegram.ui.Components.ChatAttachAlert.java

private void showHint() {
    if (SearchQuery.inlineBots.isEmpty()) {
        return;// w w w  . j a  v  a 2 s . c  o  m
    }
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig",
            Activity.MODE_PRIVATE);
    if (preferences.getBoolean("bothint", false)) {
        return;
    }
    hintShowed = true;

    hintTextView.setVisibility(View.VISIBLE);
    currentHintAnimation = new AnimatorSet();
    currentHintAnimation.playTogether(ObjectAnimator.ofFloat(hintTextView, "alpha", 0.0f, 1.0f));
    currentHintAnimation.setInterpolator(decelerateInterpolator);
    currentHintAnimation.addListener(new AnimatorListenerAdapterProxy() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (currentHintAnimation == null || !currentHintAnimation.equals(animation)) {
                return;
            }
            currentHintAnimation = null;
            AndroidUtilities.runOnUIThread(hideHintRunnable = new Runnable() {
                @Override
                public void run() {
                    if (hideHintRunnable != this) {
                        return;
                    }
                    hideHintRunnable = null;
                    hideHint();
                }
            }, 2000);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            if (currentHintAnimation != null && currentHintAnimation.equals(animation)) {
                currentHintAnimation = null;
            }
        }
    });
    currentHintAnimation.setDuration(300);
    currentHintAnimation.start();
}

From source file:org.chromium.chrome.browser.toolbar.ToolbarPhone.java

private void triggerUrlFocusAnimation(final boolean hasFocus) {
    if (mUrlFocusLayoutAnimator != null && mUrlFocusLayoutAnimator.isRunning()) {
        mUrlFocusLayoutAnimator.cancel();
        mUrlFocusLayoutAnimator = null;/*from  w  w  w  .j av  a 2  s  .c  o m*/
    }

    List<Animator> animators = new ArrayList<>();
    if (hasFocus) {
        populateUrlFocusingAnimatorSet(animators);
    } else {
        populateUrlClearFocusingAnimatorSet(animators);
    }
    mUrlFocusLayoutAnimator = new AnimatorSet();
    mUrlFocusLayoutAnimator.playTogether(animators);

    mUrlFocusChangeInProgress = true;
    mUrlFocusLayoutAnimator.addListener(new AnimatorListenerAdapter() {
        private boolean mCanceled;

        @Override
        public void onAnimationStart(Animator animation) {
            if (!hasFocus) {
                mDisableLocationBarRelayout = true;
            } else {
                mLayoutLocationBarInFocusedMode = true;
                requestLayout();
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            mCanceled = true;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (mCanceled)
                return;

            if (!hasFocus) {
                mDisableLocationBarRelayout = false;
                mLayoutLocationBarInFocusedMode = false;
                requestLayout();
            }
            mLocationBar.finishUrlFocusChange(hasFocus);
            mUrlFocusChangeInProgress = false;
        }
    });
    mUrlFocusLayoutAnimator.start();
}

From source file:org.telegram.ui.Components.ChatActivityEnterView.java

private void hideRecordedAudioPanel() {
    audioToSendPath = null;/*from   w w  w .j  a v  a  2s  .c  om*/
    audioToSend = null;
    audioToSendMessageObject = null;
    AnimatorSet AnimatorSet = new AnimatorSet();
    AnimatorSet.playTogether(ObjectAnimator.ofFloat(recordedAudioPanel, "alpha", 0.0f));
    AnimatorSet.setDuration(200);
    AnimatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            recordedAudioPanel.setVisibility(GONE);

        }
    });
    AnimatorSet.start();
}

From source file:com.wb.launcher3.Page.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (DISABLE_TOUCH_INTERACTION) {
        return false;
    }/*from w  ww  . j a  v a 2 s.  c  o m*/

    super.onTouchEvent(ev);

    // Skip touch handling if there are no pages to swipe
    if (getChildCount() <= 0)
        return super.onTouchEvent(ev);

    acquireVelocityTrackerAndAddMovement(ev);

    final int action = ev.getAction();

    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        /*
         * If being flinged and user touches, stop the fling. isFinished
         * will be false if being flinged.
         */
        if (!mScroller.isFinished()) {
            mScroller.abortAnimation();
        }

        // Remember where the motion event started
        mDownMotionX = mLastMotionX = ev.getX();
        mDownMotionY = mLastMotionY = ev.getY();
        mDownScrollX = getScrollX();
        float[] p = mapPointFromViewToParent(this, mLastMotionX, mLastMotionY);
        mParentDownMotionX = p[0];
        mParentDownMotionY = p[1];
        mLastMotionXRemainder = 0;
        mTotalMotionX = 0;
        mActivePointerId = ev.getPointerId(0);

        if (mTouchState == TOUCH_STATE_SCROLLING) {
            pageBeginMoving();
        }
        break;

    case MotionEvent.ACTION_MOVE:
        //*/zhangwuba add 2014-5-8
        if (getLauncherDeleteAppSate()) {
            return true;
        }
        //*/
        if (mTouchState == TOUCH_STATE_SCROLLING) {
            // Scroll to follow the motion event
            final int pointerIndex = ev.findPointerIndex(mActivePointerId);

            if (pointerIndex == -1)
                return true;

            final float x = ev.getX(pointerIndex);
            final float deltaX = mLastMotionX + mLastMotionXRemainder - x;

            mTotalMotionX += Math.abs(deltaX);

            // Only scroll and update mLastMotionX if we have moved some discrete amount.  We
            // keep the remainder because we are actually testing if we've moved from the last
            // scrolled position (which is discrete).
            if (Math.abs(deltaX) >= 1.0f) {
                mTouchX += deltaX;
                mSmoothingTime = System.nanoTime() / NANOTIME_DIV;
                if (!mDeferScrollUpdate) {
                    scrollBy((int) deltaX, 0);
                    if (DEBUG)
                        Log.d(TAG, "onTouchEvent().Scrolling: " + deltaX);
                } else {
                    invalidate();
                }
                mLastMotionX = x;
                mLastMotionXRemainder = deltaX - (int) deltaX;
            } else {
                awakenScrollBars();
            }
        } else if (mTouchState == TOUCH_STATE_REORDERING) {
            // Update the last motion position
            mLastMotionX = ev.getX();
            mLastMotionY = ev.getY();

            // Update the parent down so that our zoom animations take this new movement into
            // account
            float[] pt = mapPointFromViewToParent(this, mLastMotionX, mLastMotionY);
            mParentDownMotionX = pt[0];
            mParentDownMotionY = pt[1];
            updateDragViewTranslationDuringDrag();

            // Find the closest page to the touch point
            final int dragViewIndex = indexOfChild(mDragView);

            // Change the drag view if we are hovering over the drop target
            boolean isHoveringOverDelete = isHoveringOverDeleteDropTarget((int) mParentDownMotionX,
                    (int) mParentDownMotionY);
            setPageHoveringOverDeleteDropTarget(dragViewIndex, isHoveringOverDelete);

            if (DEBUG)
                Log.d(TAG, "mLastMotionX: " + mLastMotionX);
            if (DEBUG)
                Log.d(TAG, "mLastMotionY: " + mLastMotionY);
            if (DEBUG)
                Log.d(TAG, "mParentDownMotionX: " + mParentDownMotionX);
            if (DEBUG)
                Log.d(TAG, "mParentDownMotionY: " + mParentDownMotionY);

            final int pageUnderPointIndex = getNearestHoverOverPageIndex();
            if (pageUnderPointIndex > -1 && pageUnderPointIndex != indexOfChild(mDragView)
                    && !isHoveringOverDelete) {
                mTempVisiblePagesRange[0] = 0;
                mTempVisiblePagesRange[1] = getPageCount() - 1;
                getOverviewModePages(mTempVisiblePagesRange);
                if (mTempVisiblePagesRange[0] <= pageUnderPointIndex
                        && pageUnderPointIndex <= mTempVisiblePagesRange[1]
                        && pageUnderPointIndex != mSidePageHoverIndex && mScroller.isFinished()) {
                    mSidePageHoverIndex = pageUnderPointIndex;
                    mSidePageHoverRunnable = new Runnable() {
                        @Override
                        public void run() {
                            // Setup the scroll to the correct page before we swap the views
                            snapToPage(pageUnderPointIndex);

                            // For each of the pages between the paged view and the drag view,
                            // animate them from the previous position to the new position in
                            // the layout (as a result of the drag view moving in the layout)
                            int shiftDelta = (dragViewIndex < pageUnderPointIndex) ? -1 : 1;
                            int lowerIndex = (dragViewIndex < pageUnderPointIndex) ? dragViewIndex + 1
                                    : pageUnderPointIndex;
                            int upperIndex = (dragViewIndex > pageUnderPointIndex) ? dragViewIndex - 1
                                    : pageUnderPointIndex;
                            for (int i = lowerIndex; i <= upperIndex; ++i) {
                                View v = getChildAt(i);
                                // dragViewIndex < pageUnderPointIndex, so after we remove the
                                // drag view all subsequent views to pageUnderPointIndex will
                                // shift down.
                                int oldX = getViewportOffsetX() + getChildOffset(i);
                                int newX = getViewportOffsetX() + getChildOffset(i + shiftDelta);

                                // Animate the view translation from its old position to its new
                                // position
                                AnimatorSet anim = (AnimatorSet) v.getTag(ANIM_TAG_KEY);
                                if (anim != null) {
                                    anim.cancel();
                                }

                                v.setTranslationX(oldX - newX);
                                anim = new AnimatorSet();
                                anim.setDuration(REORDERING_REORDER_REPOSITION_DURATION);
                                anim.playTogether(ObjectAnimator.ofFloat(v, "translationX", 0f));
                                anim.start();
                                v.setTag(anim);
                            }

                            removeView(mDragView);
                            onRemoveView(mDragView, false);
                            addView(mDragView, pageUnderPointIndex);
                            onAddView(mDragView, pageUnderPointIndex);
                            mSidePageHoverIndex = -1;
                            mPageIndicator.setActiveMarker(getNextPage());
                        }
                    };
                    postDelayed(mSidePageHoverRunnable, REORDERING_SIDE_PAGE_HOVER_TIMEOUT);
                }
            } else {
                removeCallbacks(mSidePageHoverRunnable);
                mSidePageHoverIndex = -1;
            }
        } else {
            determineScrollingStart(ev);
        }
        break;

    case MotionEvent.ACTION_UP:
        if (mTouchState == TOUCH_STATE_SCROLLING) {
            final int activePointerId = mActivePointerId;
            final int pointerIndex = ev.findPointerIndex(activePointerId);
            final float x = ev.getX(pointerIndex);
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            int velocityX = (int) velocityTracker.getXVelocity(activePointerId);
            final int deltaX = (int) (x - mDownMotionX);
            final int pageWidth = getPageAt(mCurrentPage).getMeasuredWidth();
            boolean isSignificantMove = Math.abs(deltaX) > pageWidth * SIGNIFICANT_MOVE_THRESHOLD;

            mTotalMotionX += Math.abs(mLastMotionX + mLastMotionXRemainder - x);

            boolean isFling = mTotalMotionX > MIN_LENGTH_FOR_FLING
                    && Math.abs(velocityX) > mFlingThresholdVelocity;

            if (!mFreeScroll) {
                // In the case that the page is moved far to one direction and then is flung
                // in the opposite direction, we use a threshold to determine whether we should
                // just return to the starting page, or if we should skip one further.
                boolean returnToOriginalPage = false;
                if (Math.abs(deltaX) > pageWidth * RETURN_TO_ORIGINAL_PAGE_THRESHOLD
                        && Math.signum(velocityX) != Math.signum(deltaX) && isFling) {
                    returnToOriginalPage = true;
                }

                //*/Added by tyd Greg 2014-03-20,for transition effect
                if (TydtechConfig.CYCLE_ROLL_PAGES_ENABLED) {
                    m_moveNextDeltaX = deltaX;
                    m_isSignificantMoveNext = (!returnToOriginalPage && (isSignificantMove || isFling));
                }
                //*/

                int finalPage;
                // We give flings precedence over large moves, which is why we short-circuit our
                // test for a large move if a fling has been registered. That is, a large
                // move to the left and fling to the right will register as a fling to the right.
                final boolean isRtl = isLayoutRtl();
                boolean isDeltaXLeft = isRtl ? deltaX > 0 : deltaX < 0;
                boolean isVelocityXLeft = isRtl ? velocityX > 0 : velocityX < 0;
                if (((isSignificantMove && !isDeltaXLeft && !isFling) || (isFling && !isVelocityXLeft))
                        && mCurrentPage > 0) {
                    finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage - 1;
                    snapToPageWithVelocity(finalPage, velocityX);
                } else if (((isSignificantMove && isDeltaXLeft && !isFling) || (isFling && isVelocityXLeft))
                        && mCurrentPage < getChildCount() - 1) {
                    finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage + 1;
                    snapToPageWithVelocity(finalPage, velocityX);
                } else {
                    snapToDestination();
                }
            } else if (mTouchState == TOUCH_STATE_PREV_PAGE) {
                // at this point we have not moved beyond the touch slop
                // (otherwise mTouchState would be TOUCH_STATE_SCROLLING), so
                // we can just page
                int nextPage = Math.max(0, mCurrentPage - 1);
                if (nextPage != mCurrentPage) {
                    snapToPage(nextPage);
                } else {
                    snapToDestination();
                }
            } else {
                if (!mScroller.isFinished()) {
                    mScroller.abortAnimation();
                }

                float scaleX = getScaleX();
                int vX = (int) (-velocityX * scaleX);
                int initialScrollX = (int) (getScrollX() * scaleX);

                mScroller.fling(initialScrollX, getScrollY(), vX, 0, Integer.MIN_VALUE, Integer.MAX_VALUE, 0,
                        0);
                invalidate();
            }
        } else if (mTouchState == TOUCH_STATE_NEXT_PAGE) {
            // at this point we have not moved beyond the touch slop
            // (otherwise mTouchState would be TOUCH_STATE_SCROLLING), so
            // we can just page
            int nextPage = Math.min(getChildCount() - 1, mCurrentPage + 1);
            if (nextPage != mCurrentPage) {
                snapToPage(nextPage);
            } else {
                snapToDestination();
            }
        } else if (mTouchState == TOUCH_STATE_REORDERING) {
            // Update the last motion position
            mLastMotionX = ev.getX();
            mLastMotionY = ev.getY();

            // Update the parent down so that our zoom animations take this new movement into
            // account
            float[] pt = mapPointFromViewToParent(this, mLastMotionX, mLastMotionY);
            mParentDownMotionX = pt[0];
            mParentDownMotionY = pt[1];
            updateDragViewTranslationDuringDrag();
            boolean handledFling = false;
            if (!DISABLE_FLING_TO_DELETE) {
                // Check the velocity and see if we are flinging-to-delete
                PointF flingToDeleteVector = isFlingingToDelete();
                if (flingToDeleteVector != null) {
                    onFlingToDelete(flingToDeleteVector);
                    handledFling = true;
                }
            }
            if (!handledFling
                    && isHoveringOverDeleteDropTarget((int) mParentDownMotionX, (int) mParentDownMotionY)) {
                onDropToDelete();
            }
        }
        //*/Added by tyd Greg 2014-03-21,for support the touch swipe gesture
        else if (mTouchState == TOUCH_SWIPE_DOWN_GESTURE) {
            if (mOnTouchSwipeGestureListener != null) {
                mOnTouchSwipeGestureListener.fireSwipeDownAction();
            }
        } else if (mTouchState == TOUCH_SWIPE_UP_GESTURE) {
            if (mOnTouchSwipeGestureListener != null) {
                mOnTouchSwipeGestureListener.fireSwipeUpAction();
            }
        }
        //*/

        else {
            if (!mCancelTap) {
                onUnhandledTap(ev);
            }
        }

        // Remove the callback to wait for the side page hover timeout
        removeCallbacks(mSidePageHoverRunnable);
        // End any intermediate reordering states
        resetTouchState();
        break;

    case MotionEvent.ACTION_CANCEL:
        if (mTouchState == TOUCH_STATE_SCROLLING) {
            snapToDestination();
        }
        resetTouchState();
        break;

    case MotionEvent.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        releaseVelocityTracker();
        break;
    }

    return true;
}

From source file:org.telegram.ui.ChannelAdminLogActivity.java

private void hideFloatingDateView(boolean animated) {
    if (floatingDateView.getTag() != null && !currentFloatingDateOnScreen
            && (!scrollingFloatingDate || currentFloatingTopIsNotMessage)) {
        floatingDateView.setTag(null);//from w ww  .  j  a  va2s.c  o  m
        if (animated) {
            floatingDateAnimation = new AnimatorSet();
            floatingDateAnimation.setDuration(150);
            floatingDateAnimation.playTogether(ObjectAnimator.ofFloat(floatingDateView, "alpha", 0.0f));
            floatingDateAnimation.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    if (animation.equals(floatingDateAnimation)) {
                        floatingDateAnimation = null;
                    }
                }
            });
            floatingDateAnimation.setStartDelay(500);
            floatingDateAnimation.start();
        } else {
            if (floatingDateAnimation != null) {
                floatingDateAnimation.cancel();
                floatingDateAnimation = null;
            }
            floatingDateView.setAlpha(0.0f);
        }
    }
}

From source file:org.telegram.ui.Components.ChatActivityEnterView.java

private void checkSendButton(boolean animated) {
    if (editingMessageObject != null) {
        return;//w  w w  . j a  v a2  s.com
    }
    if (isPaused) {
        animated = false;
    }
    CharSequence message = AndroidUtilities.getTrimmedString(messageEditText.getText());
    if (message.length() > 0 || forceShowSendButton || audioToSend != null) {
        final String caption = messageEditText.getCaption();
        boolean showBotButton = caption != null && sendButton.getVisibility() == VISIBLE;
        boolean showSendButton = caption == null && cancelBotButton.getVisibility() == VISIBLE;
        if (audioVideoButtonContainer.getVisibility() == VISIBLE || showBotButton || showSendButton) {
            if (animated) {
                if (runningAnimationType == 1 && messageEditText.getCaption() == null
                        || runningAnimationType == 3 && caption != null) {
                    return;
                }
                if (runningAnimation != null) {
                    runningAnimation.cancel();
                    runningAnimation = null;
                }
                if (runningAnimation2 != null) {
                    runningAnimation2.cancel();
                    runningAnimation2 = null;
                }

                if (attachLayout != null) {
                    runningAnimation2 = new AnimatorSet();
                    runningAnimation2.playTogether(ObjectAnimator.ofFloat(attachLayout, "alpha", 0.0f),
                            ObjectAnimator.ofFloat(attachLayout, "scaleX", 0.0f));
                    runningAnimation2.setDuration(100);
                    runningAnimation2.addListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            if (runningAnimation2 != null && runningAnimation2.equals(animation)) {
                                attachLayout.setVisibility(GONE);
                            }
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {
                            if (runningAnimation2 != null && runningAnimation2.equals(animation)) {
                                runningAnimation2 = null;
                            }
                        }
                    });
                    runningAnimation2.start();
                    updateFieldRight(0);
                    if (delegate != null && getVisibility() == VISIBLE) {
                        delegate.onAttachButtonHidden();
                    }
                }

                runningAnimation = new AnimatorSet();

                ArrayList<Animator> animators = new ArrayList<>();
                if (audioVideoButtonContainer.getVisibility() == VISIBLE) {
                    animators.add(ObjectAnimator.ofFloat(audioVideoButtonContainer, "scaleX", 0.1f));
                    animators.add(ObjectAnimator.ofFloat(audioVideoButtonContainer, "scaleY", 0.1f));
                    animators.add(ObjectAnimator.ofFloat(audioVideoButtonContainer, "alpha", 0.0f));
                }
                if (showBotButton) {
                    animators.add(ObjectAnimator.ofFloat(sendButton, "scaleX", 0.1f));
                    animators.add(ObjectAnimator.ofFloat(sendButton, "scaleY", 0.1f));
                    animators.add(ObjectAnimator.ofFloat(sendButton, "alpha", 0.0f));
                } else if (showSendButton) {
                    animators.add(ObjectAnimator.ofFloat(cancelBotButton, "scaleX", 0.1f));
                    animators.add(ObjectAnimator.ofFloat(cancelBotButton, "scaleY", 0.1f));
                    animators.add(ObjectAnimator.ofFloat(cancelBotButton, "alpha", 0.0f));
                }
                if (caption != null) {
                    runningAnimationType = 3;
                    animators.add(ObjectAnimator.ofFloat(cancelBotButton, "scaleX", 1.0f));
                    animators.add(ObjectAnimator.ofFloat(cancelBotButton, "scaleY", 1.0f));
                    animators.add(ObjectAnimator.ofFloat(cancelBotButton, "alpha", 1.0f));
                    cancelBotButton.setVisibility(VISIBLE);
                } else {
                    runningAnimationType = 1;
                    animators.add(ObjectAnimator.ofFloat(sendButton, "scaleX", 1.0f));
                    animators.add(ObjectAnimator.ofFloat(sendButton, "scaleY", 1.0f));
                    animators.add(ObjectAnimator.ofFloat(sendButton, "alpha", 1.0f));
                    sendButton.setVisibility(VISIBLE);
                }

                runningAnimation.playTogether(animators);
                runningAnimation.setDuration(150);
                runningAnimation.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        if (runningAnimation != null && runningAnimation.equals(animation)) {
                            if (caption != null) {
                                cancelBotButton.setVisibility(VISIBLE);
                                sendButton.setVisibility(GONE);
                            } else {
                                sendButton.setVisibility(VISIBLE);
                                cancelBotButton.setVisibility(GONE);
                            }
                            audioVideoButtonContainer.setVisibility(GONE);
                            runningAnimation = null;
                            runningAnimationType = 0;
                        }
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {
                        if (runningAnimation != null && runningAnimation.equals(animation)) {
                            runningAnimation = null;
                        }
                    }
                });
                runningAnimation.start();
            } else {
                audioVideoButtonContainer.setScaleX(0.1f);
                audioVideoButtonContainer.setScaleY(0.1f);
                audioVideoButtonContainer.setAlpha(0.0f);
                if (caption != null) {
                    sendButton.setScaleX(0.1f);
                    sendButton.setScaleY(0.1f);
                    sendButton.setAlpha(0.0f);
                    cancelBotButton.setScaleX(1.0f);
                    cancelBotButton.setScaleY(1.0f);
                    cancelBotButton.setAlpha(1.0f);
                    cancelBotButton.setVisibility(VISIBLE);
                    sendButton.setVisibility(GONE);
                } else {
                    cancelBotButton.setScaleX(0.1f);
                    cancelBotButton.setScaleY(0.1f);
                    cancelBotButton.setAlpha(0.0f);
                    sendButton.setScaleX(1.0f);
                    sendButton.setScaleY(1.0f);
                    sendButton.setAlpha(1.0f);
                    sendButton.setVisibility(VISIBLE);
                    cancelBotButton.setVisibility(GONE);
                }
                audioVideoButtonContainer.setVisibility(GONE);
                if (attachLayout != null) {
                    attachLayout.setVisibility(GONE);
                    if (delegate != null && getVisibility() == VISIBLE) {
                        delegate.onAttachButtonHidden();
                    }
                    updateFieldRight(0);
                }
            }
        }
    } else if (sendButton.getVisibility() == VISIBLE || cancelBotButton.getVisibility() == VISIBLE) {
        if (animated) {
            if (runningAnimationType == 2) {
                return;
            }

            if (runningAnimation != null) {
                runningAnimation.cancel();
                runningAnimation = null;
            }
            if (runningAnimation2 != null) {
                runningAnimation2.cancel();
                runningAnimation2 = null;
            }

            if (attachLayout != null) {
                attachLayout.setVisibility(VISIBLE);
                runningAnimation2 = new AnimatorSet();
                runningAnimation2.playTogether(ObjectAnimator.ofFloat(attachLayout, "alpha", 1.0f),
                        ObjectAnimator.ofFloat(attachLayout, "scaleX", 1.0f));
                runningAnimation2.setDuration(100);
                runningAnimation2.start();
                updateFieldRight(1);
                if (getVisibility() == VISIBLE) {
                    delegate.onAttachButtonShow();
                }
            }

            audioVideoButtonContainer.setVisibility(VISIBLE);
            runningAnimation = new AnimatorSet();
            runningAnimationType = 2;

            ArrayList<Animator> animators = new ArrayList<>();
            animators.add(ObjectAnimator.ofFloat(audioVideoButtonContainer, "scaleX", 1.0f));
            animators.add(ObjectAnimator.ofFloat(audioVideoButtonContainer, "scaleY", 1.0f));
            animators.add(ObjectAnimator.ofFloat(audioVideoButtonContainer, "alpha", 1.0f));
            if (cancelBotButton.getVisibility() == VISIBLE) {
                animators.add(ObjectAnimator.ofFloat(cancelBotButton, "scaleX", 0.1f));
                animators.add(ObjectAnimator.ofFloat(cancelBotButton, "scaleY", 0.1f));
                animators.add(ObjectAnimator.ofFloat(cancelBotButton, "alpha", 0.0f));
            } else {
                animators.add(ObjectAnimator.ofFloat(sendButton, "scaleX", 0.1f));
                animators.add(ObjectAnimator.ofFloat(sendButton, "scaleY", 0.1f));
                animators.add(ObjectAnimator.ofFloat(sendButton, "alpha", 0.0f));
            }

            runningAnimation.playTogether(animators);
            runningAnimation.setDuration(150);
            runningAnimation.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    if (runningAnimation != null && runningAnimation.equals(animation)) {
                        sendButton.setVisibility(GONE);
                        cancelBotButton.setVisibility(GONE);
                        audioVideoButtonContainer.setVisibility(VISIBLE);
                        runningAnimation = null;
                        runningAnimationType = 0;
                    }
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                    if (runningAnimation != null && runningAnimation.equals(animation)) {
                        runningAnimation = null;
                    }
                }
            });
            runningAnimation.start();
        } else {
            sendButton.setScaleX(0.1f);
            sendButton.setScaleY(0.1f);
            sendButton.setAlpha(0.0f);
            cancelBotButton.setScaleX(0.1f);
            cancelBotButton.setScaleY(0.1f);
            cancelBotButton.setAlpha(0.0f);
            audioVideoButtonContainer.setScaleX(1.0f);
            audioVideoButtonContainer.setScaleY(1.0f);
            audioVideoButtonContainer.setAlpha(1.0f);
            cancelBotButton.setVisibility(GONE);
            sendButton.setVisibility(GONE);
            audioVideoButtonContainer.setVisibility(VISIBLE);
            if (attachLayout != null) {
                if (getVisibility() == VISIBLE) {
                    delegate.onAttachButtonShow();
                }
                attachLayout.setVisibility(VISIBLE);
                updateFieldRight(1);
            }
        }
    }
}