Search in sources :

Example 76 with AnimatorUpdateListener

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

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(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 : Animator(android.animation.Animator) FolderRingAnimator(com.android.launcher2.FolderIcon.FolderRingAnimator) 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 77 with AnimatorUpdateListener

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

the class LauncherTransitionable method showAppsCustomizeHelper.

/**
     * Things to test when changing the following seven functions.
     *   - Home from workspace
     *          - from center screen
     *          - from other screens
     *   - Home from all apps
     *          - from center screen
     *          - from other screens
     *   - Back from all apps
     *          - from center screen
     *          - from other screens
     *   - Launch app from workspace and quit
     *          - with back
     *          - with home
     *   - Launch app from all apps and quit
     *          - with back
     *          - with home
     *   - Go to a screen that's not the default, then all
     *     apps, and launch and app, and go back
     *          - with back
     *          -with home
     *   - On workspace, long press power and go back
     *          - with back
     *          - with home
     *   - On all apps, long press power and go back
     *          - with back
     *          - with home
     *   - On workspace, power off
     *   - On all apps, power off
     *   - Launch an app and turn off the screen while in that app
     *          - Go back with home key
     *          - Go back with back key  TODO: make this not go to workspace
     *          - From all apps
     *          - From workspace
     *   - Enter and exit car mode (becuase it causes an extra configuration changed)
     *          - From all apps
     *          - From the center workspace
     *          - From another workspace
     */
/**
     * Zoom the camera out from the workspace to reveal 'toView'.
     * Assumes that the view to show is anchored at either the very top or very bottom
     * of the screen.
     */
private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
    if (mStateAnimation != null) {
        mStateAnimation.cancel();
        mStateAnimation = null;
    }
    final Resources res = getResources();
    final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
    final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
    final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
    final View fromView = mWorkspace;
    final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
    final int startDelay = res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
    setPivotsForZoom(toView, scale);
    // Shrink workspaces away if going to AppsCustomize from workspace
    Animator workspaceAnim = mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
    if (animated) {
        toView.setScaleX(scale);
        toView.setScaleY(scale);
        final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
        scaleAnim.scaleX(1f).scaleY(1f).setDuration(duration).setInterpolator(new Workspace.ZoomOutInterpolator());
        toView.setVisibility(View.VISIBLE);
        toView.setAlpha(0f);
        final ObjectAnimator alphaAnim = ObjectAnimator.ofFloat(toView, "alpha", 0f, 1f).setDuration(fadeDuration);
        alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
        alphaAnim.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                if (animation == null) {
                    throw new RuntimeException("animation is null");
                }
                float t = (Float) animation.getAnimatedValue();
                dispatchOnLauncherTransitionStep(fromView, t);
                dispatchOnLauncherTransitionStep(toView, t);
            }
        });
        // toView should appear right at the end of the workspace shrink
        // animation
        mStateAnimation = LauncherAnimUtils.createAnimatorSet();
        mStateAnimation.play(scaleAnim).after(startDelay);
        mStateAnimation.play(alphaAnim).after(startDelay);
        mStateAnimation.addListener(new AnimatorListenerAdapter() {

            boolean animationCancelled = false;

            @Override
            public void onAnimationStart(Animator animation) {
                updateWallpaperVisibility(true);
                // Prepare the position
                toView.setTranslationX(0.0f);
                toView.setTranslationY(0.0f);
                toView.setVisibility(View.VISIBLE);
                toView.bringToFront();
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                dispatchOnLauncherTransitionEnd(fromView, animated, false);
                dispatchOnLauncherTransitionEnd(toView, animated, false);
                if (mWorkspace != null && !springLoaded && !LauncherApplication.isScreenLarge()) {
                    // Hide the workspace scrollbar
                    mWorkspace.hideScrollingIndicator(true);
                    hideDockDivider();
                }
                if (!animationCancelled) {
                    updateWallpaperVisibility(false);
                }
                // Hide the search bar
                if (mSearchDropTargetBar != null) {
                    mSearchDropTargetBar.hideSearchBar(false);
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                animationCancelled = true;
            }
        });
        if (workspaceAnim != null) {
            mStateAnimation.play(workspaceAnim);
        }
        boolean delayAnim = false;
        final ViewTreeObserver observer;
        dispatchOnLauncherTransitionPrepare(fromView, animated, false);
        dispatchOnLauncherTransitionPrepare(toView, animated, false);
        // yet, delay the animation until we get a layout pass
        if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) || (mWorkspace.getMeasuredWidth() == 0) || (toView.getMeasuredWidth() == 0)) {
            observer = mWorkspace.getViewTreeObserver();
            delayAnim = true;
        } else {
            observer = null;
        }
        final AnimatorSet stateAnimation = mStateAnimation;
        final Runnable startAnimRunnable = new Runnable() {

            public void run() {
                // we waited for a layout/draw pass
                if (mStateAnimation != stateAnimation)
                    return;
                setPivotsForZoom(toView, scale);
                dispatchOnLauncherTransitionStart(fromView, animated, false);
                dispatchOnLauncherTransitionStart(toView, animated, false);
                toView.post(new Runnable() {

                    public void run() {
                        // we waited for a layout/draw pass
                        if (mStateAnimation != stateAnimation)
                            return;
                        mStateAnimation.start();
                    }
                });
            }
        };
        if (delayAnim) {
            final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() {

                public void onGlobalLayout() {
                    toView.post(startAnimRunnable);
                    observer.removeOnGlobalLayoutListener(this);
                }
            };
            observer.addOnGlobalLayoutListener(delayedStart);
        } else {
            startAnimRunnable.run();
        }
    } else {
        toView.setTranslationX(0.0f);
        toView.setTranslationY(0.0f);
        toView.setScaleX(1.0f);
        toView.setScaleY(1.0f);
        toView.setVisibility(View.VISIBLE);
        toView.bringToFront();
        if (!springLoaded && !LauncherApplication.isScreenLarge()) {
            // Hide the workspace scrollbar
            mWorkspace.hideScrollingIndicator(true);
            hideDockDivider();
            // Hide the search bar
            if (mSearchDropTargetBar != null) {
                mSearchDropTargetBar.hideSearchBar(false);
            }
        }
        dispatchOnLauncherTransitionPrepare(fromView, animated, false);
        dispatchOnLauncherTransitionStart(fromView, animated, false);
        dispatchOnLauncherTransitionEnd(fromView, animated, false);
        dispatchOnLauncherTransitionPrepare(toView, animated, false);
        dispatchOnLauncherTransitionStart(toView, animated, false);
        dispatchOnLauncherTransitionEnd(toView, animated, false);
        updateWallpaperVisibility(false);
    }
}
Also used : AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ObjectAnimator(android.animation.ObjectAnimator) OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) AnimatorSet(android.animation.AnimatorSet) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AppWidgetHostView(android.appwidget.AppWidgetHostView) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) Resources(android.content.res.Resources) ViewTreeObserver(android.view.ViewTreeObserver)

Example 78 with AnimatorUpdateListener

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

the class FolderIcon method animateFirstItem.

private void animateFirstItem(final Drawable d, int duration, final boolean reverse, final Runnable onCompleteRunnable) {
    final PreviewItemDrawingParams finalParams = computePreviewItemDrawingParams(0, null);
    final float scale0 = 1.0f;
    final float transX0 = (mAvailableSpaceInPreview - d.getIntrinsicWidth()) / 2;
    final float transY0 = (mAvailableSpaceInPreview - d.getIntrinsicHeight()) / 2;
    mAnimParams.drawable = d;
    ValueAnimator va = LauncherAnimUtils.ofFloat(0f, 1.0f);
    va.addUpdateListener(new AnimatorUpdateListener() {

        public void onAnimationUpdate(ValueAnimator animation) {
            float progress = (Float) animation.getAnimatedValue();
            if (reverse) {
                progress = 1 - progress;
                mPreviewBackground.setAlpha(progress);
            }
            mAnimParams.transX = transX0 + progress * (finalParams.transX - transX0);
            mAnimParams.transY = transY0 + progress * (finalParams.transY - transY0);
            mAnimParams.scale = scale0 + progress * (finalParams.scale - scale0);
            invalidate();
        }
    });
    va.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animation) {
            mAnimating = true;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mAnimating = false;
            if (onCompleteRunnable != null) {
                onCompleteRunnable.run();
            }
        }
    });
    va.setDuration(duration);
    va.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 79 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project Fairphone by Kwamecorp.

the class DeleteDropTarget method createFlingToTrashAnimatorListener.

/**
     * Creates an animation from the current drag view to the delete trash icon.
     */
private AnimatorUpdateListener createFlingToTrashAnimatorListener(final DragLayer dragLayer, DragObject d, PointF vel, ViewConfiguration config) {
    final Rect to = getIconRect(d.dragView.getMeasuredWidth(), d.dragView.getMeasuredHeight(), mCurrentDrawable.getIntrinsicWidth(), mCurrentDrawable.getIntrinsicHeight());
    final Rect from = new Rect();
    dragLayer.getViewRectRelativeToSelf(d.dragView, from);
    // Calculate how far along the velocity vector we should put the intermediate point on
    // the bezier curve
    float velocity = Math.abs(vel.length());
    float vp = Math.min(1f, velocity / (config.getScaledMaximumFlingVelocity() / 2f));
    int offsetY = (int) (-from.top * vp);
    int offsetX = (int) (offsetY / (vel.y / vel.x));
    // intermediate t/l
    final float y2 = from.top + offsetY;
    final float x2 = from.left + offsetX;
    // drag view t/l
    final float x1 = from.left;
    final float y1 = from.top;
    // delete target t/l
    final float x3 = to.left;
    final float y3 = to.top;
    final TimeInterpolator scaleAlphaInterpolator = new TimeInterpolator() {

        @Override
        public float getInterpolation(float t) {
            return t * t * t * t * t * t * t * t;
        }
    };
    return new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            final DragView dragView = (DragView) dragLayer.getAnimatedView();
            float t = ((Float) animation.getAnimatedValue()).floatValue();
            float tp = scaleAlphaInterpolator.getInterpolation(t);
            float initialScale = dragView.getInitialScale();
            float finalAlpha = 0.5f;
            float scale = dragView.getScaleX();
            float x1o = ((1f - scale) * dragView.getMeasuredWidth()) / 2f;
            float y1o = ((1f - scale) * dragView.getMeasuredHeight()) / 2f;
            float x = (1f - t) * (1f - t) * (x1 - x1o) + 2 * (1f - t) * t * (x2 - x1o) + (t * t) * x3;
            float y = (1f - t) * (1f - t) * (y1 - y1o) + 2 * (1f - t) * t * (y2 - x1o) + (t * t) * y3;
            dragView.setTranslationX(x);
            dragView.setTranslationY(y);
            dragView.setScaleX(initialScale * (1f - tp));
            dragView.setScaleY(initialScale * (1f - tp));
            dragView.setAlpha(finalAlpha + (1f - finalAlpha) * (1f - tp));
        }
    };
}
Also used : Rect(android.graphics.Rect) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) TimeInterpolator(android.animation.TimeInterpolator)

Example 80 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project Fairphone by Kwamecorp.

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(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 : Animator(android.animation.Animator) FolderRingAnimator(org.fairphone.launcher.FolderIcon.FolderRingAnimator) 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)

Aggregations

AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)94 ValueAnimator (android.animation.ValueAnimator)88 Animator (android.animation.Animator)65 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)62 ObjectAnimator (android.animation.ObjectAnimator)31 TimeInterpolator (android.animation.TimeInterpolator)14 View (android.view.View)13 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)12 Interpolator (android.view.animation.Interpolator)12 Resources (android.content.res.Resources)9 SuppressLint (android.annotation.SuppressLint)8 AnimatorSet (android.animation.AnimatorSet)7 Rect (android.graphics.Rect)7 ImageView (android.widget.ImageView)7 PropertyValuesHolder (android.animation.PropertyValuesHolder)6 AppWidgetHostView (android.appwidget.AppWidgetHostView)6 Point (android.graphics.Point)6 PointF (android.graphics.PointF)6 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)6 TextView (android.widget.TextView)6