Search in sources :

Example 56 with ValueAnimator

use of android.animation.ValueAnimator in project android_packages_apps_Launcher2 by CyanogenMod.

the class AppWidgetResizeFrame method snapToWidget.

public void snapToWidget(boolean animate) {
    final DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
    int xOffset = mCellLayout.getLeft() + mCellLayout.getPaddingLeft() + mDragLayer.getPaddingLeft() - mWorkspace.getScrollX();
    int yOffset = mCellLayout.getTop() + mCellLayout.getPaddingTop() + mDragLayer.getPaddingTop() - mWorkspace.getScrollY();
    int newWidth = mWidgetView.getWidth() + 2 * mBackgroundPadding - mWidgetPaddingLeft - mWidgetPaddingRight;
    int newHeight = mWidgetView.getHeight() + 2 * mBackgroundPadding - mWidgetPaddingTop - mWidgetPaddingBottom;
    int newX = mWidgetView.getLeft() - mBackgroundPadding + xOffset + mWidgetPaddingLeft;
    int newY = mWidgetView.getTop() - mBackgroundPadding + yOffset + mWidgetPaddingTop;
    // down accordingly to provide a proper touch target.
    if (newY < 0) {
        // In this case we shift the touch region down to start at the top of the DragLayer
        mTopTouchRegionAdjustment = -newY;
    } else {
        mTopTouchRegionAdjustment = 0;
    }
    if (newY + newHeight > mDragLayer.getHeight()) {
        // In this case we shift the touch region up to end at the bottom of the DragLayer
        mBottomTouchRegionAdjustment = -(newY + newHeight - mDragLayer.getHeight());
    } else {
        mBottomTouchRegionAdjustment = 0;
    }
    if (!animate) {
        lp.width = newWidth;
        lp.height = newHeight;
        lp.x = newX;
        lp.y = newY;
        mLeftHandle.setAlpha(1.0f);
        mRightHandle.setAlpha(1.0f);
        mTopHandle.setAlpha(1.0f);
        mBottomHandle.setAlpha(1.0f);
        requestLayout();
    } else {
        PropertyValuesHolder width = PropertyValuesHolder.ofInt("width", lp.width, newWidth);
        PropertyValuesHolder height = PropertyValuesHolder.ofInt("height", lp.height, newHeight);
        PropertyValuesHolder x = PropertyValuesHolder.ofInt("x", lp.x, newX);
        PropertyValuesHolder y = PropertyValuesHolder.ofInt("y", lp.y, newY);
        ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(lp, width, height, x, y);
        ObjectAnimator leftOa = LauncherAnimUtils.ofFloat(mLeftHandle, "alpha", 1.0f);
        ObjectAnimator rightOa = LauncherAnimUtils.ofFloat(mRightHandle, "alpha", 1.0f);
        ObjectAnimator topOa = LauncherAnimUtils.ofFloat(mTopHandle, "alpha", 1.0f);
        ObjectAnimator bottomOa = LauncherAnimUtils.ofFloat(mBottomHandle, "alpha", 1.0f);
        oa.addUpdateListener(new AnimatorUpdateListener() {

            public void onAnimationUpdate(ValueAnimator animation) {
                requestLayout();
            }
        });
        AnimatorSet set = LauncherAnimUtils.createAnimatorSet();
        if (mResizeMode == AppWidgetProviderInfo.RESIZE_VERTICAL) {
            set.playTogether(oa, topOa, bottomOa);
        } else if (mResizeMode == AppWidgetProviderInfo.RESIZE_HORIZONTAL) {
            set.playTogether(oa, leftOa, rightOa);
        } else {
            set.playTogether(oa, leftOa, rightOa, topOa, bottomOa);
        }
        set.setDuration(SNAP_DURATION);
        set.start();
    }
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) PropertyValuesHolder(android.animation.PropertyValuesHolder) AnimatorSet(android.animation.AnimatorSet) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Example 57 with ValueAnimator

use of android.animation.ValueAnimator in project GSYVideoPlayer by CarGuo.

the class ENDownloadView method downloadAnim.

private void downloadAnim() {
    if (mValueAnimator != null) {
        mValueAnimator.removeAllListeners();
        mValueAnimator.removeAllUpdateListeners();
        if (mValueAnimator.isRunning())
            mValueAnimator.cancel();
        mValueAnimator = null;
    }
    if (mCurrentState != STATE_DOWNLOADING) {
        return;
    }
    mValueAnimator = ValueAnimator.ofFloat(1.f, 100.f);
    mValueAnimator.setDuration(mDownloadTime);
    mValueAnimator.setInterpolator(new LinearInterpolator());
    mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mFraction = valueAnimator.getAnimatedFraction();
            if (mUnit != DownloadUnit.NONE && mTotalSize > 0)
                mCurrentSize = mFraction * mTotalSize;
            invalidate();
        }
    });
    mValueAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mCurrentState = STATE_DOWNLOADING;
            downloadAnim();
        }
    });
    mValueAnimator.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 58 with ValueAnimator

use of android.animation.ValueAnimator in project GSYVideoPlayer by CarGuo.

the class ENDownloadView method endAnim.

private void endAnim() {
    if (mValueAnimator != null) {
        mValueAnimator.removeAllListeners();
        mValueAnimator.removeAllUpdateListeners();
        if (mValueAnimator.isRunning())
            mValueAnimator.cancel();
        mValueAnimator = null;
    }
    mValueAnimator = ValueAnimator.ofFloat(1.f, 100.f);
    mValueAnimator.setDuration(700);
    mValueAnimator.setInterpolator(new OvershootInterpolator());
    mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

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

        @Override
        public void onAnimationEnd(Animator animation) {
            mFraction = 0;
            mCurrentState = STATE_RESET;
            if (onDownloadStateListener != null) {
                onDownloadStateListener.onDownloadFinish();
            }
        }
    });
    mValueAnimator.start();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) OvershootInterpolator(android.view.animation.OvershootInterpolator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator)

Example 59 with ValueAnimator

use of android.animation.ValueAnimator in project GSYVideoPlayer by CarGuo.

the class ENPlayView method pause.

public void pause() {
    if (mCurrentState == STATE_PAUSE) {
        return;
    }
    mCurrentState = STATE_PAUSE;
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(1.f, 100.f);
    valueAnimator.setDuration(mDuration);
    valueAnimator.setInterpolator(new AnticipateInterpolator());
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mFraction = valueAnimator.getAnimatedFraction();
            invalidate();
        }
    });
    if (!valueAnimator.isRunning()) {
        valueAnimator.start();
    }
}
Also used : ValueAnimator(android.animation.ValueAnimator) AnticipateInterpolator(android.view.animation.AnticipateInterpolator)

Example 60 with ValueAnimator

use of android.animation.ValueAnimator in project GSYVideoPlayer by CarGuo.

the class ENPlayView method play.

public void play() {
    if (mCurrentState == STATE_PLAY) {
        return;
    }
    mCurrentState = STATE_PLAY;
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(1.f, 100.f);
    valueAnimator.setDuration(mDuration);
    valueAnimator.setInterpolator(new AnticipateInterpolator());
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mFraction = 1 - valueAnimator.getAnimatedFraction();
            invalidate();
        }
    });
    if (!valueAnimator.isRunning()) {
        valueAnimator.start();
    }
}
Also used : ValueAnimator(android.animation.ValueAnimator) AnticipateInterpolator(android.view.animation.AnticipateInterpolator)

Aggregations

ValueAnimator (android.animation.ValueAnimator)1224 Animator (android.animation.Animator)625 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)455 ObjectAnimator (android.animation.ObjectAnimator)187 ArrayList (java.util.ArrayList)128 Paint (android.graphics.Paint)124 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)111 LinearInterpolator (android.view.animation.LinearInterpolator)102 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)91 View (android.view.View)90 AnimatorSet (android.animation.AnimatorSet)87 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)74 ArgbEvaluator (android.animation.ArgbEvaluator)57 ViewGroup (android.view.ViewGroup)44 TextView (android.widget.TextView)44 StackStateAnimator (com.android.systemui.statusbar.stack.StackStateAnimator)40 PropertyValuesHolder (android.animation.PropertyValuesHolder)36 ImageView (android.widget.ImageView)34 Interpolator (android.view.animation.Interpolator)31 SuppressLint (android.annotation.SuppressLint)25