Search in sources :

Example 11 with AnimatorUpdateListener

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

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 12 with AnimatorUpdateListener

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

the class DragView method crossFade.

public void crossFade(int duration) {
    ValueAnimator va = LauncherAnimUtils.ofFloat(0f, 1f);
    va.setDuration(duration);
    va.setInterpolator(new DecelerateInterpolator(1.5f));
    va.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mCrossFadeProgress = animation.getAnimatedFraction();
        }
    });
    va.start();
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Example 13 with AnimatorUpdateListener

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

the class DeleteDropTarget method onFlingToDelete.

public void onFlingToDelete(final DragObject d, int x, int y, PointF vel) {
    final boolean isAllApps = d.dragSource instanceof AppsCustomizePagedView;
    // Don't highlight the icon as it's animating
    d.dragView.setColor(0);
    d.dragView.updateInitialScaleToCurrentScale();
    // Don't highlight the target if we are flinging from AllApps
    if (isAllApps) {
        resetHoverColor();
    }
    if (mFlingDeleteMode == MODE_FLING_DELETE_TO_TRASH) {
        // Defer animating out the drop target if we are animating to it
        mSearchDropTargetBar.deferOnDragEnd();
        mSearchDropTargetBar.finishAnimations();
    }
    final ViewConfiguration config = ViewConfiguration.get(mLauncher);
    final DragLayer dragLayer = mLauncher.getDragLayer();
    final int duration = FLING_DELETE_ANIMATION_DURATION;
    final long startTime = AnimationUtils.currentAnimationTimeMillis();
    // NOTE: Because it takes time for the first frame of animation to actually be
    // called and we expect the animation to be a continuation of the fling, we have
    // to account for the time that has elapsed since the fling finished.  And since
    // we don't have a startDelay, we will always get call to update when we call
    // start() (which we want to ignore).
    final TimeInterpolator tInterpolator = new TimeInterpolator() {

        private int mCount = -1;

        private float mOffset = 0f;

        @Override
        public float getInterpolation(float t) {
            if (mCount < 0) {
                mCount++;
            } else if (mCount == 0) {
                mOffset = Math.min(0.5f, (float) (AnimationUtils.currentAnimationTimeMillis() - startTime) / duration);
                mCount++;
            }
            return Math.min(1f, mOffset + t);
        }
    };
    AnimatorUpdateListener updateCb = null;
    if (mFlingDeleteMode == MODE_FLING_DELETE_TO_TRASH) {
        updateCb = createFlingToTrashAnimatorListener(dragLayer, d, vel, config);
    } else if (mFlingDeleteMode == MODE_FLING_DELETE_ALONG_VECTOR) {
        updateCb = createFlingAlongVectorAnimatorListener(dragLayer, d, vel, startTime, duration, config);
    }
    Runnable onAnimationEndRunnable = new Runnable() {

        @Override
        public void run() {
            mSearchDropTargetBar.onDragEnd();
            // itself, otherwise, complete the drop to initiate the deletion process
            if (!isAllApps) {
                mLauncher.exitSpringLoadedDragMode();
                completeDrop(d);
            }
            mLauncher.getDragController().onDeferredEndFling(d);
        }
    };
    dragLayer.animateView(d.dragView, updateCb, duration, tInterpolator, onAnimationEndRunnable, DragLayer.ANIMATION_END_DISAPPEAR, null);
}
Also used : ViewConfiguration(android.view.ViewConfiguration) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) TimeInterpolator(android.animation.TimeInterpolator)

Example 14 with AnimatorUpdateListener

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

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);
                }
                if (!animationCancelled) {
                    updateWallpaperVisibility(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);
        }
        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) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) ValueAnimator(android.animation.ValueAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) Resources(android.content.res.Resources) ViewTreeObserver(android.view.ViewTreeObserver)

Example 15 with AnimatorUpdateListener

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

the class LauncherTransitionable method hideAppsCustomizeHelper.

/**
	 * Zoom the camera back into the workspace, hiding 'fromView'. This is the
	 * opposite of showAppsCustomizeHelper.
	 * 
	 * @param animated
	 *            If true, the transition will be animated.
	 */
private void hideAppsCustomizeHelper(State toState, final boolean animated, final boolean springLoaded, final Runnable onCompleteRunnable) {
    if (mStateAnimation != null) {
        mStateAnimation.cancel();
        mStateAnimation = null;
    }
    Resources res = getResources();
    final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
    final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
    final float scaleFactor = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
    final View fromView = mAppsCustomizeTabHost;
    final View toView = mWorkspace;
    Animator workspaceAnim = null;
    if (toState == State.WORKSPACE) {
        int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
        workspaceAnim = mWorkspace.getChangeStateAnimation(Workspace.State.NORMAL, animated, stagger);
    } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
        workspaceAnim = mWorkspace.getChangeStateAnimation(Workspace.State.SPRING_LOADED, animated);
    }
    setPivotsForZoom(fromView, scaleFactor);
    updateWallpaperVisibility(true);
    if (animated) {
        final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(fromView);
        scaleAnim.scaleX(scaleFactor).scaleY(scaleFactor).setDuration(duration).setInterpolator(new Workspace.ZoomInInterpolator());
        final ObjectAnimator alphaAnim = ObjectAnimator.ofFloat(fromView, "alpha", 1f, 0f).setDuration(fadeOutDuration);
        alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
        alphaAnim.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float t = 1f - (Float) animation.getAnimatedValue();
                dispatchOnLauncherTransitionStep(fromView, t);
                dispatchOnLauncherTransitionStep(toView, t);
            }
        });
        mStateAnimation = LauncherAnimUtils.createAnimatorSet();
        dispatchOnLauncherTransitionPrepare(fromView, animated, true);
        dispatchOnLauncherTransitionPrepare(toView, animated, true);
        mAppsCustomizeContent.pauseScrolling();
        mStateAnimation.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                updateWallpaperVisibility(true);
                fromView.setVisibility(View.GONE);
                dispatchOnLauncherTransitionEnd(fromView, animated, true);
                dispatchOnLauncherTransitionEnd(toView, animated, true);
                if (mWorkspace != null) {
                    mWorkspace.hideScrollingIndicator(false);
                }
                if (onCompleteRunnable != null) {
                    onCompleteRunnable.run();
                }
                mAppsCustomizeContent.updateCurrentPageScroll();
                mAppsCustomizeContent.resumeScrolling();
            }
        });
        mStateAnimation.playTogether(scaleAnim, alphaAnim);
        if (workspaceAnim != null) {
            mStateAnimation.play(workspaceAnim);
        }
        dispatchOnLauncherTransitionStart(fromView, animated, true);
        dispatchOnLauncherTransitionStart(toView, animated, true);
        final Animator stateAnimation = mStateAnimation;
        mWorkspace.post(new Runnable() {

            public void run() {
                if (stateAnimation != mStateAnimation)
                    return;
                mStateAnimation.start();
            }
        });
    } else {
        fromView.setVisibility(View.GONE);
        dispatchOnLauncherTransitionPrepare(fromView, animated, true);
        dispatchOnLauncherTransitionStart(fromView, animated, true);
        dispatchOnLauncherTransitionEnd(fromView, animated, true);
        dispatchOnLauncherTransitionPrepare(toView, animated, true);
        dispatchOnLauncherTransitionStart(toView, animated, true);
        dispatchOnLauncherTransitionEnd(toView, animated, true);
        mWorkspace.hideScrollingIndicator(false);
    }
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) ImageView(android.widget.ImageView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) ValueAnimator(android.animation.ValueAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) Resources(android.content.res.Resources)

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