Search in sources :

Example 21 with Animator

use of android.animation.Animator in project ENViews by codeestX.

the class ENSearchView method start.

public void start() {
    if (mCurrentState == STATE_SEARCHING) {
        return;
    }
    mCurrentState = STATE_SEARCHING;
    ValueAnimator valueAnim = ValueAnimator.ofFloat(1.f, 100.f);
    valueAnim.setDuration(mDuration);
    valueAnim.setInterpolator(new LinearInterpolator());
    valueAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mFraction = valueAnimator.getAnimatedFraction();
            invalidate();
        }
    });
    valueAnim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mCurrentState = STATE_WAIT;
        }
    });
    valueAnim.start();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) LinearInterpolator(android.view.animation.LinearInterpolator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator)

Example 22 with Animator

use of android.animation.Animator in project Launcher3 by chislon.

the class CellLayout method animateChildToPosition.

public boolean animateChildToPosition(final View child, int cellX, int cellY, int duration, int delay, boolean permanent, boolean adjustOccupied) {
    ShortcutAndWidgetContainer clc = getShortcutsAndWidgets();
    boolean[][] occupied = mOccupied;
    if (!permanent) {
        occupied = mTmpOccupied;
    }
    if (clc.indexOfChild(child) != -1) {
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        final ItemInfo info = (ItemInfo) child.getTag();
        // We cancel any existing animations
        if (mReorderAnimators.containsKey(lp)) {
            mReorderAnimators.get(lp).cancel();
            mReorderAnimators.remove(lp);
        }
        final int oldX = lp.x;
        final int oldY = lp.y;
        if (adjustOccupied) {
            occupied[lp.cellX][lp.cellY] = false;
            occupied[cellX][cellY] = true;
        }
        lp.isLockedToGrid = true;
        if (permanent) {
            lp.cellX = info.cellX = cellX;
            lp.cellY = info.cellY = cellY;
        } else {
            lp.tmpCellX = cellX;
            lp.tmpCellY = cellY;
        }
        clc.setupLp(lp);
        lp.isLockedToGrid = false;
        final int newX = lp.x;
        final int newY = lp.y;
        lp.x = oldX;
        lp.y = oldY;
        // Exit early if we're not actually moving the view
        if (oldX == newX && oldY == newY) {
            lp.isLockedToGrid = true;
            return true;
        }
        ValueAnimator va = LauncherAnimUtils.ofFloat(child, 0f, 1f);
        va.setDuration(duration);
        mReorderAnimators.put(lp, va);
        va.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float r = ((Float) animation.getAnimatedValue()).floatValue();
                lp.x = (int) ((1 - r) * oldX + r * newX);
                lp.y = (int) ((1 - r) * oldY + r * newY);
                child.requestLayout();
            }
        });
        va.addListener(new AnimatorListenerAdapter() {

            boolean cancelled = false;

            public void onAnimationEnd(Animator animation) {
                // place just yet.
                if (!cancelled) {
                    lp.isLockedToGrid = true;
                    child.requestLayout();
                }
                if (mReorderAnimators.containsKey(lp)) {
                    mReorderAnimators.remove(lp);
                }
            }

            public void onAnimationCancel(Animator animation) {
                cancelled = true;
            }
        });
        va.setStartDelay(delay);
        va.start();
        return true;
    }
    return false;
}
Also used : FolderRingAnimator(com.android.launcher3.FolderIcon.FolderRingAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) Point(android.graphics.Point) Paint(android.graphics.Paint)

Example 23 with Animator

use of android.animation.Animator in project Launcher3 by chislon.

the class Cling method hide.

void hide(final int duration, final Runnable postCb) {
    if (mDrawIdentifier.equals(FIRST_RUN_PORTRAIT) || mDrawIdentifier.equals(FIRST_RUN_LANDSCAPE)) {
        View content = getContent();
        content.animate().alpha(0f).setDuration(duration).setListener(new AnimatorListenerAdapter() {

            public void onAnimationEnd(Animator animation) {
                // We are about to trigger the workspace cling, so don't do anything else
                setVisibility(View.GONE);
                postCb.run();
            }

            ;
        }).start();
    } else {
        animate().alpha(0f).setDuration(duration).setListener(new AnimatorListenerAdapter() {

            public void onAnimationEnd(Animator animation) {
                // We are about to trigger the workspace cling, so don't do anything else
                setVisibility(View.GONE);
                postCb.run();
            }

            ;
        }).start();
    }
    // Show the scrim if necessary
    if (mScrimView != null) {
        mScrimView.animate().alpha(0f).setDuration(duration).setListener(new AnimatorListenerAdapter() {

            public void onAnimationEnd(Animator animation) {
                mScrimView.setVisibility(View.GONE);
            }

            ;
        }).start();
    }
}
Also used : Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) TextView(android.widget.TextView) View(android.view.View)

Example 24 with Animator

use of android.animation.Animator in project Launcher3 by chislon.

the class DragLayer method fadeOutDragView.

private void fadeOutDragView() {
    mFadeOutAnim = new ValueAnimator();
    mFadeOutAnim.setDuration(150);
    mFadeOutAnim.setFloatValues(0f, 1f);
    mFadeOutAnim.removeAllUpdateListeners();
    mFadeOutAnim.addUpdateListener(new AnimatorUpdateListener() {

        public void onAnimationUpdate(ValueAnimator animation) {
            final float percent = (Float) animation.getAnimatedValue();
            float alpha = 1 - percent;
            mDropView.setAlpha(alpha);
        }
    });
    mFadeOutAnim.addListener(new AnimatorListenerAdapter() {

        public void onAnimationEnd(Animator animation) {
            if (mDropView != null) {
                mDragController.onDeferredEndDrag(mDropView);
            }
            mDropView = null;
            invalidate();
        }
    });
    mFadeOutAnim.start();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Example 25 with Animator

use of android.animation.Animator in project UltimateRecyclerView by cymcsg.

the class SwipeableRecyclerViewTouchListener method handleTouchEvent.

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
private boolean handleTouchEvent(MotionEvent motionEvent) {
    if (mViewWidth < 2) {
        mViewWidth = mRecyclerView.getWidth();
    }
    switch(motionEvent.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            {
                if (mPaused) {
                    break;
                }
                // Find the child view that was touched (perform a hit test)
                Rect rect = new Rect();
                int childCount = mRecyclerView.getChildCount();
                int[] listViewCoords = new int[2];
                mRecyclerView.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 = mRecyclerView.getChildAt(i);
                    child.getHitRect(rect);
                    if (rect.contains(x, y)) {
                        mDownView = child;
                        break;
                    }
                }
                if (mDownView != null && mAnimatingPosition != mRecyclerView.getChildPosition(mDownView)) {
                    mAlpha = mDownView.getAlpha();
                    mDownX = motionEvent.getRawX();
                    mDownY = motionEvent.getRawY();
                    mDownPosition = mRecyclerView.getChildPosition(mDownView);
                    if (mSwipeListener.canSwipe(mDownPosition)) {
                        mVelocityTracker = VelocityTracker.obtain();
                        mVelocityTracker.addMovement(motionEvent);
                    } else {
                        mDownView = null;
                    }
                }
                break;
            }
        case MotionEvent.ACTION_CANCEL:
            {
                if (mVelocityTracker == null) {
                    break;
                }
                if (mDownView != null && mSwiping) {
                    // cancel
                    mDownView.animate().translationX(0).alpha(mAlpha).setDuration(mAnimationTime).setListener(null);
                }
                mVelocityTracker.recycle();
                mVelocityTracker = null;
                mDownX = 0;
                mDownY = 0;
                mDownView = null;
                mDownPosition = ListView.INVALID_POSITION;
                mSwiping = false;
                break;
            }
        case MotionEvent.ACTION_UP:
            {
                if (mVelocityTracker == null) {
                    break;
                }
                mFinalDelta = 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(mFinalDelta) > mViewWidth / 2 && mSwiping) {
                    dismiss = true;
                    dismissRight = mFinalDelta > 0;
                } else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity && absVelocityY < absVelocityX && mSwiping) {
                    // dismiss only if flinging in the same direction as dragging
                    dismiss = (velocityX < 0) == (mFinalDelta < 0);
                    dismissRight = mVelocityTracker.getXVelocity() > 0;
                }
                if (dismiss && mDownPosition != mAnimatingPosition && mDownPosition != ListView.INVALID_POSITION) {
                    // dismiss
                    // mDownView gets null'd before animation ends
                    final View downView = mDownView;
                    final int downPosition = mDownPosition;
                    ++mDismissAnimationRefCount;
                    mAnimatingPosition = mDownPosition;
                    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(mAlpha).setDuration(mAnimationTime).setListener(null);
                }
                mVelocityTracker.recycle();
                mVelocityTracker = null;
                mDownX = 0;
                mDownY = 0;
                mDownView = null;
                mDownPosition = ListView.INVALID_POSITION;
                mSwiping = false;
                break;
            }
        case MotionEvent.ACTION_MOVE:
            {
                if (mVelocityTracker == null || mPaused) {
                    break;
                }
                mVelocityTracker.addMovement(motionEvent);
                float deltaX = motionEvent.getRawX() - mDownX;
                float deltaY = motionEvent.getRawY() - mDownY;
                if (!mSwiping && Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
                    mSwiping = true;
                    mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
                }
                if (mSwiping) {
                    mDownView.setTranslationX(deltaX - mSwipingSlop);
                    mDownView.setAlpha(Math.max(0f, Math.min(mAlpha, mAlpha * (1f - Math.abs(deltaX) / mViewWidth))));
                    return true;
                }
                break;
            }
    }
    return false;
}
Also used : Rect(android.graphics.Rect) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) ListView(android.widget.ListView) TargetApi(android.annotation.TargetApi)

Aggregations

Animator (android.animation.Animator)1384 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)848 ObjectAnimator (android.animation.ObjectAnimator)712 ValueAnimator (android.animation.ValueAnimator)627 AnimatorSet (android.animation.AnimatorSet)278 View (android.view.View)227 ViewGroup (android.view.ViewGroup)110 ArrayList (java.util.ArrayList)101 PropertyValuesHolder (android.animation.PropertyValuesHolder)94 Paint (android.graphics.Paint)78 StackStateAnimator (com.android.systemui.statusbar.stack.StackStateAnimator)75 ImageView (android.widget.ImageView)68 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)66 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)65 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)61 TextView (android.widget.TextView)60 RenderNodeAnimator (android.view.RenderNodeAnimator)51 ViewPropertyAnimator (android.view.ViewPropertyAnimator)50 Rect (android.graphics.Rect)49 Interpolator (android.view.animation.Interpolator)49