Example usage for android.animation ObjectAnimator ofFloat

List of usage examples for android.animation ObjectAnimator ofFloat

Introduction

In this page you can find the example usage for android.animation ObjectAnimator ofFloat.

Prototype

public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> xProperty, Property<T, Float> yProperty,
        Path path) 

Source Link

Document

Constructs and returns an ObjectAnimator that animates coordinates along a Path using two properties.

Usage

From source file:com.gxapplications.android.gxsuite.launcher.Launcher.java

/**
 * 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./*from  www  . j  a  va 2  s.  co m*/
 */
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);

        // If any of the objects being animated haven't been measured/laid out
        // 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() {
                // Check that mStateAnimation hasn't changed while
                // 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() {
                        // Check that mStateAnimation hasn't changed while
                        // 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);
    }
}

From source file:com.android.launcher2.Launcher.java

/**
 * Zoom the camera back into the workspace, hiding 'fromView'.
 * This is the opposite of showAppsCustomizeHelper.
 * @param animated If true, the transition will be animated.
 *//*from w  w  w .ja v  a 2  s . c  om*/
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);
    showHotseat(animated);
    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);
    }
}

From source file:g7.bluesky.launcher3.Launcher.java

private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
        final AppsCustomizePagedView.ContentType contentType) {
    if (mStateAnimation != null) {
        mStateAnimation.setDuration(0);//from  ww w .  j  a  v a2  s  .  com
        mStateAnimation.cancel();
        mStateAnimation = null;
    }

    boolean material = Utilities.isLmpOrAbove();

    final Resources res = getResources();

    final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
    final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
    final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
    final int itemsAlphaStagger = res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);

    final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
    final View fromView = mWorkspace;
    final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;

    final ArrayList<View> layerViews = new ArrayList<View>();

    Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets
            ? Workspace.State.OVERVIEW_HIDDEN
            : Workspace.State.NORMAL_HIDDEN;
    Animator workspaceAnim = mWorkspace.getChangeStateAnimation(workspaceState, animated, layerViews);
    if (!LauncherAppState.isDisableAllApps() || contentType == AppsCustomizePagedView.ContentType.Widgets) {
        // Set the content type for the all apps/widgets space
        mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
    }

    // If for some reason our views aren't initialized, don't animate
    boolean initialized = getAllAppsButton() != null;

    if (animated && initialized) {
        mStateAnimation = LauncherAnimUtils.createAnimatorSet();
        final AppsCustomizePagedView content = (AppsCustomizePagedView) toView
                .findViewById(R.id.apps_customize_pane_content);

        final View page = content.getPageAt(content.getCurrentPage());
        final View revealView = toView.findViewById(R.id.fake_page);

        final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
        if (isWidgetTray) {
            revealView.setBackground(ContextCompat.getDrawable(this, R.drawable.quantum_panel_dark));
        } else {
            revealView.setBackground(currentBgDrawable);
        }

        // Hide the real page background, and swap in the fake one
        content.setPageBackgroundsVisible(false);
        revealView.setVisibility(View.VISIBLE);
        // We need to hide this view as the animation start will be posted.
        revealView.setAlpha(0);

        int width = revealView.getMeasuredWidth();
        int height = revealView.getMeasuredHeight();
        float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);

        revealView.setTranslationY(0);
        revealView.setTranslationX(0);

        // Get the y delta between the center of the page and the center of the all apps button
        int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, getAllAppsButton(), null);

        float alpha = 0;
        float xDrift = 0;
        float yDrift = 0;
        if (material) {
            alpha = isWidgetTray ? 0.3f : 1f;
            yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
            xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
        } else {
            yDrift = 2 * height / 3;
            xDrift = 0;
        }
        final float initAlpha = alpha;

        revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        layerViews.add(revealView);
        PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f);
        PropertyValuesHolder panelDriftY = PropertyValuesHolder.ofFloat("translationY", yDrift, 0);
        PropertyValuesHolder panelDriftX = PropertyValuesHolder.ofFloat("translationX", xDrift, 0);

        ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView, panelAlpha,
                panelDriftY, panelDriftX);

        panelAlphaAndDrift.setDuration(revealDuration);
        panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));

        mStateAnimation.play(panelAlphaAndDrift);

        if (page != null) {
            page.setVisibility(View.VISIBLE);
            page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            layerViews.add(page);

            ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0);
            page.setTranslationY(yDrift);
            pageDrift.setDuration(revealDuration);
            pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
            pageDrift.setStartDelay(itemsAlphaStagger);
            mStateAnimation.play(pageDrift);

            page.setAlpha(0f);
            ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0f, 1f);
            itemsAlpha.setDuration(revealDuration);
            itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
            itemsAlpha.setStartDelay(itemsAlphaStagger);
            mStateAnimation.play(itemsAlpha);
        }

        View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator);
        pageIndicators.setAlpha(0.01f);
        ObjectAnimator indicatorsAlpha = ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f);
        indicatorsAlpha.setDuration(revealDuration);
        mStateAnimation.play(indicatorsAlpha);

        if (material) {
            final View allApps = getAllAppsButton();
            int allAppsButtonSize = LauncherAppState.getInstance().getDynamicGrid()
                    .getDeviceProfile().allAppsButtonVisualSize;
            float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
            Animator reveal = ViewAnimationUtils.createCircularReveal(revealView, width / 2, height / 2,
                    startRadius, revealRadius);
            reveal.setDuration(revealDuration);
            reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));

            reveal.addListener(new AnimatorListenerAdapter() {
                public void onAnimationStart(Animator animation) {
                    if (!isWidgetTray) {
                        allApps.setVisibility(View.INVISIBLE);
                    }
                }

                public void onAnimationEnd(Animator animation) {
                    if (!isWidgetTray) {
                        allApps.setVisibility(View.VISIBLE);
                    }
                }
            });
            mStateAnimation.play(reveal);
        }

        mStateAnimation.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                dispatchOnLauncherTransitionEnd(fromView, animated, false);
                dispatchOnLauncherTransitionEnd(toView, animated, false);

                revealView.setVisibility(View.INVISIBLE);
                revealView.setLayerType(View.LAYER_TYPE_NONE, null);
                if (page != null) {
                    page.setLayerType(View.LAYER_TYPE_NONE, null);
                }
                content.setPageBackgroundsVisible(true);

                // Hide the search bar
                if (mSearchDropTargetBar != null) {
                    mSearchDropTargetBar.hideSearchBar(false);
                }

                // This can hold unnecessary references to views.
                mStateAnimation = null;
            }

        });

        if (workspaceAnim != null) {
            mStateAnimation.play(workspaceAnim);
        }

        dispatchOnLauncherTransitionPrepare(fromView, animated, false);
        dispatchOnLauncherTransitionPrepare(toView, animated, false);
        final AnimatorSet stateAnimation = mStateAnimation;
        final Runnable startAnimRunnable = new Runnable() {
            public void run() {
                // Check that mStateAnimation hasn't changed while
                // we waited for a layout/draw pass
                if (mStateAnimation != stateAnimation)
                    return;
                dispatchOnLauncherTransitionStart(fromView, animated, false);
                dispatchOnLauncherTransitionStart(toView, animated, false);

                revealView.setAlpha(initAlpha);
                if (Utilities.isLmpOrAbove()) {
                    for (int i = 0; i < layerViews.size(); i++) {
                        View v = layerViews.get(i);
                        if (v != null) {
                            if (Utilities.isViewAttachedToWindow(v))
                                v.buildLayer();
                        }
                    }
                }
                mStateAnimation.start();
            }
        };
        toView.bringToFront();
        toView.setVisibility(View.VISIBLE);
        toView.post(startAnimRunnable);
    } 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 && !LauncherAppState.getInstance().isScreenLarge()) {
            // 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);
    }
}

From source file:com.tct.mail.ui.AbstractActivityController.java

@Override
public void animateShow(ImageButton fabButton) {
    Toolbar toolbar = mActivity.getToolbar();
    if (toolbar == null) {
        return;//www  . java2s . co  m
    }
    //Remove other animation.
    if (hideAnimatorSet != null && hideAnimatorSet.isRunning()) {
        hideAnimatorSet.cancel();
    }
    if (backAnimatorSet != null && backAnimatorSet.isRunning()) {
        //If the animation is running,do nothing.
    } else {
        if (!mToolbarHidden) {
            //toolbar is showing,no need to do the show animation.
            return;
        }
        backAnimatorSet = new AnimatorSet();
        ArrayList<Animator> animators = new ArrayList<>();
        //Show the toolbar
        ObjectAnimator headerAnimator = ObjectAnimator.ofFloat(toolbar, "translationY",
                toolbar.getTranslationY(), 0f);
        if (fabButton != null) {
            //Show the fabButton
            ObjectAnimator fabAnimator = ObjectAnimator.ofFloat(fabButton, "translationY",
                    fabButton.getTranslationY(), 0f);
            animators.add(fabAnimator);
        }
        if (mSearchHeader != null) {
            //Show search header view
            //If we are searching the message, we should also show the search header
            ObjectAnimator searchHeaderAnimator = ObjectAnimator.ofFloat(mSearchHeader, "translationY",
                    mSearchHeader.getTranslationY(), 0f);
            animators.add(searchHeaderAnimator);
        }
        animators.add(headerAnimator);
        backAnimatorSet.setDuration(200);
        backAnimatorSet.playTogether(animators);
        backAnimatorSet.start();
        mToolbarHidden = false;
    }
}

From source file:com.tct.mail.ui.AbstractActivityController.java

@Override
public void animateHide(ImageButton fabButton) {
    Toolbar toolbar = mActivity.getToolbar();
    if (toolbar == null) {
        return;//from w  ww  . j a  va  2 s  . c o  m
    }
    //Remove other animations first
    if (backAnimatorSet != null && backAnimatorSet.isRunning()) {
        backAnimatorSet.cancel();
    }
    if (hideAnimatorSet != null && hideAnimatorSet.isRunning()) {
        //If the animation is running, do nothing.
    } else {
        if (mToolbarHidden) {
            //toolbar is hidden,no need to do the hide animation
            return;
        }
        hideAnimatorSet = new AnimatorSet();
        ArrayList<Animator> animators = new ArrayList<>();
        //Hide the toolbar
        ObjectAnimator headerAnimator = ObjectAnimator.ofFloat(toolbar, "translationY",
                toolbar.getTranslationY(), -toolbar.getHeight());
        //Hide the fabButton
        ObjectAnimator fabAnimator = ObjectAnimator.ofFloat(fabButton, "translationY",
                fabButton.getTranslationY(), ((View) fabButton.getParent()).getHeight()); //TS: zheng.zou 2015-10-22 EMAIL BUGFIX-721230 MOD
        if (mSearchHeader != null) {
            //Hide search header view
            //If we are searching the message, we should also hide the search header
            ObjectAnimator searchHeaderAnimator = ObjectAnimator.ofFloat(mSearchHeader, "translationY",
                    toolbar.getTranslationY(), -mSearchHeader.getHeight());
            animators.add(searchHeaderAnimator);
        }
        animators.add(headerAnimator);
        animators.add(fabAnimator);
        hideAnimatorSet.setDuration(200);
        hideAnimatorSet.playTogether(animators);
        hideAnimatorSet.start();
        mToolbarHidden = true;
    }
}