Example usage for android.animation ObjectAnimator setDuration

List of usage examples for android.animation ObjectAnimator setDuration

Introduction

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

Prototype

@Override
@NonNull
public ObjectAnimator setDuration(long duration) 

Source Link

Document

Sets the length of the animation.

Usage

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

private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
        final AppsCustomizePagedView.ContentType contentType) {
    if (mStateAnimation != null) {
        mStateAnimation.setDuration(0);/* w w  w.j  ava2 s  . c om*/
        mStateAnimation.cancel();
        mStateAnimation = null;
    }

    boolean material = Utilities.isLmpOrAbove();

    final Resources res = getResources();

    final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
    final int itemsAlphaStagger = res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);

    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);
    // 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;
        revealView.setBackgroundColor(getResources().getColor(R.color.widget_text_panel));

        // 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);

                // 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();

        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.android.launcher2.Launcher.java

private void dismissCling(final Cling cling, final String flag, int duration) {
    // To catch cases where siblings of top-level views are made invisible, just check whether
    // the cling is directly set to GONE before dismissing it.
    if (cling != null && cling.getVisibility() != View.GONE) {
        ObjectAnimator anim = LauncherAnimUtils.ofFloat(cling, "alpha", 0f);
        anim.setDuration(duration);
        anim.addListener(new AnimatorListenerAdapter() {
            public void onAnimationEnd(Animator animation) {
                cling.setVisibility(View.GONE);
                cling.cleanup();//from w ww. jav  a  2 s .  c  o  m
                // We should update the shared preferences on a background thread
                new Thread("dismissClingThread") {
                    public void run() {
                        SharedPreferences.Editor editor = mSharedPrefs.edit();
                        editor.putBoolean(flag, true);
                        editor.commit();
                    }
                }.start();
            };
        });
        anim.start();
        mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
    }
}

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

private void growAndFadeOutFolderIcon(FolderIcon fi) {
    if (fi == null)
        return;//w w w. ja  va2 s . com
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);

    FolderInfo info = (FolderInfo) fi.getTag();
    if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
        CellLayout cl = (CellLayout) fi.getParent().getParent();
        CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
        cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
    }

    // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
    copyFolderIconToImage(fi);
    fi.setVisibility(View.INVISIBLE);

    ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, scaleX, scaleY);
    oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
    oa.start();
}

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

private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
    if (fi == null)
        return;//from w  ww  .  j  av a 2s  . co  m
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);

    final CellLayout cl = (CellLayout) fi.getParent().getParent();

    // We remove and re-draw the FolderIcon in-case it has changed
    mDragLayer.removeView(mFolderIconImageView);
    copyFolderIconToImage(fi);
    ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, scaleX, scaleY);
    oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
    oa.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (cl != null) {
                cl.clearFolderLeaveBehind();
                // Remove the ImageView copy of the FolderIcon and make the original visible.
                mDragLayer.removeView(mFolderIconImageView);
                fi.setVisibility(View.VISIBLE);
            }
        }
    });
    oa.start();
}

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

private void dismissCling(final Cling cling, final String flag, int duration) {
    if (cling != null && cling.getVisibility() == View.VISIBLE) {
        ObjectAnimator anim = LauncherAnimUtils.ofFloat(cling, "alpha", 0f);
        anim.setDuration(duration);
        anim.addListener(new AnimatorListenerAdapter() {
            public void onAnimationEnd(Animator animation) {
                cling.setVisibility(View.GONE);
                cling.cleanup();/*w w  w . j a  v a 2s.  co  m*/
                // We should update the shared preferences on a background thread
                new Thread("dismissClingThread") {
                    public void run() {
                        SharedPreferences.Editor editor = mSharedPrefs.edit();
                        editor.putBoolean(flag, true);
                        editor.commit();
                    }
                }.start();
            };
        });
        anim.start();
        mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
    }
}

From source file:com.aliyun.homeshell.Folder.java

public void animateOpen() {
    positionAndSizeAsIcon();/*from  w  w w .j  a  v  a 2  s  .  c o m*/
    if (!(getParent() instanceof DragLayer))
        return;
    centerAboutIcon();
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1);
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
    final ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);

    oa.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
                    String.format(getContext().getString(R.string.folder_opened), mContent.getCountX(),
                            mContent.getCountY()));
            mState = STATE_ANIMATING;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mState = STATE_OPEN;
            setLayerType(LAYER_TYPE_NONE, null);

            /* YUNOS BEGIN */
            // ##date:2013/11/27 ##author:zhangqiang.zq
            // remove cling
            /*
             * Cling cling = mLauncher.showFirstRunFoldersCling(); if (cling
             * != null) { cling.bringToFront(); }
             */
            /* YUNOS END */
            setFocusOnFirstChild();
            setAlpha(1);
            setScaleX(1);
            setScaleY(1);
            /*YUNOS BEGIN*/
            //##date:2014/06/10 ##author:guoshuai.lgs ##BugID:
            //support the folder feature in mainmenu
            if (mInfo.isMainmenuFolder() && (LauncherApplication.isMainmenuMode())) {
                mLauncher.getAppsCustomizeTabHost().setVisibility(View.INVISIBLE);
            }
            /*YUNOS END*/
        }
    });
    oa.setDuration(mExpandDuration);
    setLayerType(LAYER_TYPE_HARDWARE, null);
    oa.start();
}

From source file:com.klinker.android.launcher.launcher3.Workspace.java

private void fadeAndRemoveEmptyScreen(int delay, int duration, final Runnable onComplete,
        final boolean stripEmptyScreens) {
    // XXX: Do we need to update LM workspace screens below?
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0f);
    PropertyValuesHolder bgAlpha = PropertyValuesHolder.ofFloat("backgroundAlpha", 0f);

    final CellLayout cl = mWorkspaceScreens.get(EXTRA_EMPTY_SCREEN_ID);

    mRemoveEmptyScreenRunnable = new Runnable() {
        @Override/*from  ww  w .  j  ava 2  s .  c om*/
        public void run() {
            if (hasExtraEmptyScreen()) {
                mWorkspaceScreens.remove(EXTRA_EMPTY_SCREEN_ID);
                mScreenOrder.remove(EXTRA_EMPTY_SCREEN_ID);
                removeView(cl);
                if (stripEmptyScreens) {
                    stripEmptyScreens();
                }
            }
        }
    };

    ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(cl, alpha, bgAlpha);
    oa.setDuration(duration);
    oa.setStartDelay(delay);
    oa.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (mRemoveEmptyScreenRunnable != null) {
                mRemoveEmptyScreenRunnable.run();
            }
            if (onComplete != null) {
                onComplete.run();
            }
        }
    });
    oa.start();
}

From source file:com.phonemetra.turbo.launcher.Workspace.java

private void fadeAndRemoveEmptyScreen(int delay, int duration, final Runnable onComplete,
        final boolean stripEmptyScreens) {

    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0f);
    PropertyValuesHolder bgAlpha = PropertyValuesHolder.ofFloat("backgroundAlpha", 0f);

    final CellLayout cl = mWorkspaceScreens.get(EXTRA_EMPTY_SCREEN_ID);

    mRemoveEmptyScreenRunnable = new Runnable() {
        @Override/*w  w  w.  j a  v a 2 s . com*/
        public void run() {
            if (hasExtraEmptyScreen()) {
                mWorkspaceScreens.remove(EXTRA_EMPTY_SCREEN_ID);
                mScreenOrder.remove(EXTRA_EMPTY_SCREEN_ID);
                removeView(cl);
                if (stripEmptyScreens) {
                    stripEmptyScreens();
                }
            }
        }
    };

    ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(cl, alpha, bgAlpha);
    oa.setDuration(duration);
    oa.setStartDelay(delay);
    oa.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (mRemoveEmptyScreenRunnable != null) {
                mRemoveEmptyScreenRunnable.run();
            }
            if (onComplete != null) {
                onComplete.run();
            }
        }
    });
    oa.start();
}

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

private void shrinkAndFadeInFolderIcon(final FolderIcon fi, boolean animate) {
    if (fi == null)
        return;//from w  ww . jav  a2  s.  com
    final CellLayout cl = (CellLayout) fi.getParent().getParent();

    // We remove and re-draw the FolderIcon in-case it has changed
    mDragLayer.removeView(mFolderIconImageView);
    copyFolderIconToImage(fi);

    if (cl != null) {
        cl.clearFolderLeaveBehind();
    }

    ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(mFolderIconImageView, 1, 1, 1);
    oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
    oa.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (cl != null) {
                // Remove the ImageView copy of the FolderIcon and make the original visible.
                mDragLayer.removeView(mFolderIconImageView);
                fi.setVisibility(View.VISIBLE);
            }
        }
    });
    oa.start();
    if (!animate) {
        oa.end();
    }
}

From source file:com.klinker.android.launcher.launcher3.Launcher.java

private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
    if (fi == null)
        return;/*from   w ww  . j  a va2s  . co  m*/
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);

    final CellLayout cl = (CellLayout) fi.getParent().getParent();

    // We remove and re-draw the FolderIcon in-case it has changed
    mDragLayer.removeView(mFolderIconImageView);
    copyFolderIconToImage(fi);
    ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, scaleX, scaleY);
    oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
    oa.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (cl != null) {
                cl.clearFolderLeaveBehind();
                // Remove the ImageView copy of the FolderIcon and make the original visible.
                mDragLayer.removeView(mFolderIconImageView);
                fi.setVisibility(View.VISIBLE);
            }
        }
    });
    oa.start();
}