Example usage for android.animation ValueAnimator getAnimatedValue

List of usage examples for android.animation ValueAnimator getAnimatedValue

Introduction

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

Prototype

public Object getAnimatedValue() 

Source Link

Document

The most recent value calculated by this ValueAnimator when there is just one property being animated.

Usage

From source file:com.ruesga.timelinechart.TimelineChartView.java

private void setupAnimators() {
    // A zoom-in/zoom-out animator
    mZoomAnimator = ValueAnimator.ofFloat(1.f);
    mZoomAnimator.setDuration(350L);//from   ww w  .  ja v a  2 s . c o  m
    mZoomAnimator.setInterpolator(new DecelerateInterpolator());
    mZoomAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mCurrentZoom = (Float) animation.getAnimatedValue();
            ViewCompat.postInvalidateOnAnimation(TimelineChartView.this);
        }
    });
    mZoomAnimator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (mInZoomOut) {
                // Swap temporary refs
                swapRefs();

                // Update the view, notify and end the animation
                Message.obtain(mUiHandler, MSG_UPDATE_COMPUTED_DATA, 1, 0).sendToTarget();
            } else {
                mState = STATE_IDLE;
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            mState = STATE_IDLE;
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }
    });
}

From source file:com.dish.browser.activity.BrowserActivity.java

private void changeToolbarBackground(Bitmap favicon) {
    Palette.from(favicon).generate(new Palette.PaletteAsyncListener() {
        @Override/*from  w  ww . j a  va2 s. c  o  m*/
        public void onGenerated(Palette palette) {

            // OR with opaque black to remove transparency glitches
            int color = 0xff000000
                    | palette.getVibrantColor(mActivity.getResources().getColor(R.color.primary_color));

            int finalColor; // Lighten up the dark color if it is
            // too dark
            if (isColorTooDark(color)) {
                finalColor = mixTwoColors(mActivity.getResources().getColor(R.color.primary_color), color,
                        0.25f);
            } else {
                finalColor = color;
            }

            ValueAnimator anim = ValueAnimator.ofObject(new ArgbEvaluator(), mBackground.getColor(),
                    finalColor);

            anim.addUpdateListener(new AnimatorUpdateListener() {

                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    int color = (Integer) animation.getAnimatedValue();
                    mBackground.setColor(color);
                    getWindow().setBackgroundDrawable(mBackground);
                    mToolbarLayout.setBackgroundColor(color);
                }

            });

            anim.setDuration(300);
            anim.start();

        }
    });
}

From source file:com.android.leanlauncher.Workspace.java

private void animateBackgroundGradient(float finalAlpha, boolean animated) {
    final DragLayer dragLayer = mLauncher.getDragLayer();

    if (mBackgroundFadeInAnimation != null) {
        mBackgroundFadeInAnimation.cancel();
        mBackgroundFadeInAnimation = null;
    }/* w w  w  . ja v a  2s. co m*/
    if (mBackgroundFadeOutAnimation != null) {
        mBackgroundFadeOutAnimation.cancel();
        mBackgroundFadeOutAnimation = null;
    }
    float startAlpha = dragLayer.getBackgroundAlpha();
    if (finalAlpha != startAlpha) {
        if (animated) {
            mBackgroundFadeOutAnimation = LauncherAnimUtils.ofFloat(this, startAlpha, finalAlpha);
            mBackgroundFadeOutAnimation.addUpdateListener(new AnimatorUpdateListener() {
                public void onAnimationUpdate(ValueAnimator animation) {
                    dragLayer.setBackgroundAlpha((Float) animation.getAnimatedValue());
                }
            });
            mBackgroundFadeOutAnimation.setInterpolator(new DecelerateInterpolator(1.5f));
            mBackgroundFadeOutAnimation.setDuration(BACKGROUND_FADE_OUT_DURATION);
            mBackgroundFadeOutAnimation.start();
        } else {
            dragLayer.setBackgroundAlpha(finalAlpha);
        }
    }
}

From source file:com.android.systemui.statusbar.phone.NotificationPanelView.java

private void flingSettings(float vel, boolean expand, final Runnable onFinishRunnable, boolean isClick) {
    float target = expand ? mQsMaxExpansionHeight : mQsMinExpansionHeight;
    if (target == mQsExpansionHeight) {
        mScrollYOverride = -1;/*w w  w  . j  a  va  2 s.c o m*/
        if (onFinishRunnable != null) {
            onFinishRunnable.run();
        }
        return;
    }
    boolean belowFalsingThreshold = isBelowFalsingThreshold();
    if (belowFalsingThreshold) {
        vel = 0;
    }
    mScrollView.setBlockFlinging(true);
    ValueAnimator animator = ValueAnimator.ofFloat(mQsExpansionHeight, target);
    if (isClick) {
        animator.setInterpolator(mTouchResponseInterpolator);
        animator.setDuration(368);
    } else {
        mFlingAnimationUtils.apply(animator, mQsExpansionHeight, target, vel);
    }
    if (belowFalsingThreshold) {
        animator.setDuration(350);
    }
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            setQsExpansion((Float) animation.getAnimatedValue());
        }
    });
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mScrollView.setBlockFlinging(false);
            mScrollYOverride = -1;
            mQsExpansionAnimator = null;
            if (onFinishRunnable != null) {
                onFinishRunnable.run();
            }
        }
    });
    animator.start();
    mQsExpansionAnimator = animator;
    mQsAnimatorExpand = expand;
}

From source file:com.marlonjones.voidlauncher.CellLayout.java

public boolean animateChildToPosition(final View child, int cellX, int cellY, int duration, int delay,
        boolean permanent, boolean adjustOccupied) {
    ShortcutAndWidgetContainer clc = getShortcutsAndWidgets();

    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);
        }/*from   w ww.jav  a2s.  c  o m*/

        final int oldX = lp.x;
        final int oldY = lp.y;
        if (adjustOccupied) {
            GridOccupancy occupied = permanent ? mOccupied : mTmpOccupied;
            occupied.markCells(lp.cellX, lp.cellY, lp.cellHSpan, lp.cellVSpan, false);
            occupied.markCells(cellX, cellY, lp.cellHSpan, lp.cellVSpan, 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) {
                // If the animation was cancelled, it means that another animation
                // has interrupted this one, and we don't want to lock the item into
                // 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;
}

From source file:com.android.launcher3.CellLayout.java

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;/*from  w  w w .jav a2  s .c o m*/
    }

    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) {
                // If the animation was cancelled, it means that another animation
                // has interrupted this one, and we don't want to lock the item into
                // 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;
}

From source file:com.android.leanlauncher.CellLayout.java

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;/*from w ww  .j av  a2  s.  c om*/
    }

    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();
                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) {
                // If the animation was cancelled, it means that another animation
                // has interrupted this one, and we don't want to lock the item into
                // 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;
}

From source file:ticwear.design.widget.CoordinatorLayout.java

private void animateScrollingOffsetTo(final int offset) {
    final int currentOffset = getUnconsumedScrollingOffset();

    if (currentOffset == offset) {
        if (mAnimator != null && mAnimator.isRunning()) {
            mAnimator.cancel();/*from w w  w.  j  a  va 2 s .c om*/
        }
        return;
    }

    if (mAnimator == null) {
        mAnimator = new ValueAnimator();
        mAnimator.setInterpolator(AnimationUtils.DECELERATE_INTERPOLATOR);
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                int offset = (int) animator.getAnimatedValue();
                setScrollingOffset(offset);
            }
        });
    } else {
        mAnimator.cancel();
    }

    mAnimator.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));

    mAnimator.setIntValues(currentOffset, offset);
    mAnimator.start();
}

From source file:com.marlonjones.voidlauncher.CellLayout.java

public CellLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show
    // the user where a dragged item will land when dropped.
    setWillNotDraw(false);//from  w  w  w  . j  av  a2 s.c  o m
    setClipToPadding(false);
    mLauncher = Launcher.getLauncher(context);

    DeviceProfile grid = mLauncher.getDeviceProfile();

    mCellWidth = mCellHeight = -1;
    mFixedCellWidth = mFixedCellHeight = -1;
    mWidthGap = mOriginalWidthGap = 0;
    mHeightGap = mOriginalHeightGap = 0;
    mMaxGap = Integer.MAX_VALUE;

    mCountX = grid.inv.numColumns;
    mCountY = grid.inv.numRows;
    mOccupied = new GridOccupancy(mCountX, mCountY);
    mTmpOccupied = new GridOccupancy(mCountX, mCountY);

    mPreviousReorderDirection[0] = INVALID_DIRECTION;
    mPreviousReorderDirection[1] = INVALID_DIRECTION;

    mFolderLeaveBehind.delegateCellX = -1;
    mFolderLeaveBehind.delegateCellY = -1;

    setAlwaysDrawnWithCacheEnabled(false);
    final Resources res = getResources();
    mHotseatScale = (float) grid.hotseatIconSizePx / grid.iconSizePx;

    mBackground = (TransitionDrawable) res.getDrawable(
            FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND ? R.drawable.bg_screenpanel : R.drawable.bg_celllayout);
    mBackground.setCallback(this);
    mBackground.setAlpha((int) (mBackgroundAlpha * 255));

    mReorderPreviewAnimationMagnitude = (REORDER_PREVIEW_MAGNITUDE * grid.iconSizePx);

    // Initialize the data structures used for the drag visualization.
    mEaseOutInterpolator = new DecelerateInterpolator(2.5f); // Quint ease out
    mDragCell[0] = mDragCell[1] = -1;
    for (int i = 0; i < mDragOutlines.length; i++) {
        mDragOutlines[i] = new Rect(-1, -1, -1, -1);
    }
    mDragOutlinePaint.setColor(getResources().getColor(R.color.outline_color));

    // When dragging things around the home screens, we show a green outline of
    // where the item will land. The outlines gradually fade out, leaving a trail
    // behind the drag path.
    // Set up all the animations that are used to implement this fading.
    final int duration = res.getInteger(R.integer.config_dragOutlineFadeTime);
    final float fromAlphaValue = 0;
    final float toAlphaValue = (float) res.getInteger(R.integer.config_dragOutlineMaxAlpha);

    Arrays.fill(mDragOutlineAlphas, fromAlphaValue);

    for (int i = 0; i < mDragOutlineAnims.length; i++) {
        final InterruptibleInOutAnimator anim = new InterruptibleInOutAnimator(this, duration, fromAlphaValue,
                toAlphaValue);
        anim.getAnimator().setInterpolator(mEaseOutInterpolator);
        final int thisIndex = i;
        anim.getAnimator().addUpdateListener(new AnimatorUpdateListener() {
            public void onAnimationUpdate(ValueAnimator animation) {
                final Bitmap outline = (Bitmap) anim.getTag();

                // If an animation is started and then stopped very quickly, we can still
                // get spurious updates we've cleared the tag. Guard against this.
                if (outline == null) {
                    if (LOGD) {
                        Object val = animation.getAnimatedValue();
                        Log.d(TAG, "anim " + thisIndex + " update: " + val + ", isStopped " + anim.isStopped());
                    }
                    // Try to prevent it from continuing to run
                    animation.cancel();
                } else {
                    mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue();
                    CellLayout.this.invalidate(mDragOutlines[thisIndex]);
                }
            }
        });
        // The animation holds a reference to the drag outline bitmap as long is it's
        // running. This way the bitmap can be GCed when the animations are complete.
        anim.getAnimator().addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if ((Float) ((ValueAnimator) animation).getAnimatedValue() == 0f) {
                    anim.setTag(null);
                }
            }
        });
        mDragOutlineAnims[i] = anim;
    }

    mShortcutsAndWidgets = new ShortcutAndWidgetContainer(context);
    mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mWidthGap, mHeightGap, mCountX, mCountY);

    mStylusEventHelper = new StylusEventHelper(new SimpleOnStylusPressListener(this), this);

    mTouchFeedbackView = new ClickShadowView(context);
    addView(mTouchFeedbackView);
    addView(mShortcutsAndWidgets);
}

From source file:com.android.launcher3.CellLayout.java

public CellLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show
    // the user where a dragged item will land when dropped.
    setWillNotDraw(false);//w w w . jav  a 2s . c om
    setClipToPadding(false);
    mLauncher = (Launcher) context;

    DeviceProfile grid = mLauncher.getDeviceProfile();

    mCellWidth = mCellHeight = -1;
    mFixedCellWidth = mFixedCellHeight = -1;
    mWidthGap = mOriginalWidthGap = 0;
    mHeightGap = mOriginalHeightGap = 0;
    mMaxGap = Integer.MAX_VALUE;
    mCountX = (int) grid.inv.numColumns;
    mCountY = (int) grid.inv.numRows;
    mOccupied = new boolean[mCountX][mCountY];
    mTmpOccupied = new boolean[mCountX][mCountY];
    mPreviousReorderDirection[0] = INVALID_DIRECTION;
    mPreviousReorderDirection[1] = INVALID_DIRECTION;

    setAlwaysDrawnWithCacheEnabled(false);
    final Resources res = getResources();
    mHotseatScale = (float) grid.hotseatIconSizePx / grid.iconSizePx;

    mBackground = (TransitionDrawable) res.getDrawable(R.drawable.bg_screenpanel);
    mBackground.setCallback(this);
    mBackground.setAlpha((int) (mBackgroundAlpha * 255));

    mReorderPreviewAnimationMagnitude = (REORDER_PREVIEW_MAGNITUDE * grid.iconSizePx);

    // Initialize the data structures used for the drag visualization.
    mEaseOutInterpolator = new DecelerateInterpolator(2.5f); // Quint ease out
    mDragCell[0] = mDragCell[1] = -1;
    for (int i = 0; i < mDragOutlines.length; i++) {
        mDragOutlines[i] = new Rect(-1, -1, -1, -1);
    }

    // When dragging things around the home screens, we show a green outline of
    // where the item will land. The outlines gradually fade out, leaving a trail
    // behind the drag path.
    // Set up all the animations that are used to implement this fading.
    final int duration = res.getInteger(R.integer.config_dragOutlineFadeTime);
    final float fromAlphaValue = 0;
    final float toAlphaValue = (float) res.getInteger(R.integer.config_dragOutlineMaxAlpha);

    Arrays.fill(mDragOutlineAlphas, fromAlphaValue);

    for (int i = 0; i < mDragOutlineAnims.length; i++) {
        final InterruptibleInOutAnimator anim = new InterruptibleInOutAnimator(this, duration, fromAlphaValue,
                toAlphaValue);
        anim.getAnimator().setInterpolator(mEaseOutInterpolator);
        final int thisIndex = i;
        anim.getAnimator().addUpdateListener(new AnimatorUpdateListener() {
            public void onAnimationUpdate(ValueAnimator animation) {
                final Bitmap outline = (Bitmap) anim.getTag();

                // If an animation is started and then stopped very quickly, we can still
                // get spurious updates we've cleared the tag. Guard against this.
                if (outline == null) {
                    if (LOGD) {
                        Object val = animation.getAnimatedValue();
                        Log.d(TAG, "anim " + thisIndex + " update: " + val + ", isStopped " + anim.isStopped());
                    }
                    // Try to prevent it from continuing to run
                    animation.cancel();
                } else {
                    mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue();
                    CellLayout.this.invalidate(mDragOutlines[thisIndex]);
                }
            }
        });
        // The animation holds a reference to the drag outline bitmap as long is it's
        // running. This way the bitmap can be GCed when the animations are complete.
        anim.getAnimator().addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if ((Float) ((ValueAnimator) animation).getAnimatedValue() == 0f) {
                    anim.setTag(null);
                }
            }
        });
        mDragOutlineAnims[i] = anim;
    }

    mShortcutsAndWidgets = new ShortcutAndWidgetContainer(context);
    mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mWidthGap, mHeightGap, mCountX, mCountY);

    mStylusEventHelper = new StylusEventHelper(this);

    mTouchFeedbackView = new ClickShadowView(context);
    addView(mTouchFeedbackView);
    addView(mShortcutsAndWidgets);
}