Example usage for android.view View startAnimation

List of usage examples for android.view View startAnimation

Introduction

In this page you can find the example usage for android.view View startAnimation.

Prototype

public void startAnimation(Animation animation) 

Source Link

Document

Start the specified animation now.

Usage

From source file:com.partynetwork.iparty.app.widget.crouton.Manager.java

/**
 * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}
 * .//from  ww w. j  a v  a  2  s  . com
 * 
 * @param crouton
 *            The {@link Crouton} that should be added.
 */
private void addCroutonToView(final Crouton crouton) {
    // don't add if it is already showing
    if (crouton.isShowing()) {
        return;
    }

    final View croutonView = crouton.getView();
    if (null == croutonView.getParent()) {
        ViewGroup.LayoutParams params = croutonView.getLayoutParams();
        if (null == params) {
            params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        // display Crouton in ViewGroup is it has been supplied
        if (null != crouton.getViewGroup()) {
            // TODO implement add to last position feature (need to align
            // with how this will be requested for activity)
            if (crouton.getViewGroup() instanceof FrameLayout) {
                crouton.getViewGroup().addView(croutonView, params);
            } else {
                crouton.getViewGroup().addView(croutonView, 0, params);
            }
        } else {
            Activity activity = crouton.getActivity();
            if (null == activity || activity.isFinishing()) {
                return;
            }

            activity.addContentView(croutonView, params);
        }
    }

    croutonView.requestLayout(); // This is needed so the animation can use
    // the measured with/height
    ViewTreeObserver observer = croutonView.getViewTreeObserver();
    if (null != observer) {
        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            @TargetApi(16)
            public void onGlobalLayout() {

                croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(this);

                croutonView.startAnimation(crouton.getInAnimation());
                announceForAccessibilityCompat(crouton.getActivity(), crouton.getText());
                if (Configuration.DURATION_INFINITE != crouton.getConfiguration().durationInMilliseconds) {
                    sendMessageDelayed(crouton, Messages.REMOVE_CROUTON,
                            crouton.getConfiguration().durationInMilliseconds
                                    + crouton.getInAnimation().getDuration());
                }
            }
        });
    }
}

From source file:com.ebaonet.lawyer.ui.weight.DraggableGridViewPager.java

private void animateDragged() {
    if (mLastDragged >= 0) {
        final View v = getChildAt(mLastDragged);

        final Rect r = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
        r.inset(-r.width() / 20, -r.height() / 20);
        v.measure(MeasureSpec.makeMeasureSpec(r.width(), MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(r.height(), MeasureSpec.EXACTLY));
        v.layout(r.left, r.top, r.right, r.bottom);

        AnimationSet animSet = new AnimationSet(true);
        ScaleAnimation scale = new ScaleAnimation(0.9091f, 1, 0.9091f, 1, v.getWidth() / 2, v.getHeight() / 2);
        scale.setDuration(ANIMATION_DURATION);
        AlphaAnimation alpha = new AlphaAnimation(1, .8f);
        alpha.setDuration(ANIMATION_DURATION);

        animSet.addAnimation(scale);/*from   w  w  w  .j a  v a  2s .c o  m*/
        animSet.addAnimation(alpha);
        animSet.setFillEnabled(true);
        animSet.setFillAfter(true);

        v.clearAnimation();
        v.startAnimation(animSet);
    }
}

From source file:android.support.v7.app.MediaRouteControllerDialog.java

void clearGroupListAnimation(boolean exceptAddedRoutes) {
    int first = mVolumeGroupList.getFirstVisiblePosition();
    for (int i = 0; i < mVolumeGroupList.getChildCount(); ++i) {
        View view = mVolumeGroupList.getChildAt(i);
        int position = first + i;
        MediaRouter.RouteInfo route = mVolumeGroupAdapter.getItem(position);
        if (exceptAddedRoutes && mGroupMemberRoutesAdded != null && mGroupMemberRoutesAdded.contains(route)) {
            continue;
        }//  w  w  w.j av a  2 s  . c o  m
        LinearLayout container = (LinearLayout) view.findViewById(R.id.volume_item_container);
        container.setVisibility(View.VISIBLE);
        AnimationSet animSet = new AnimationSet(true);
        Animation alphaAnim = new AlphaAnimation(1.0f, 1.0f);
        alphaAnim.setDuration(0);
        animSet.addAnimation(alphaAnim);
        Animation translationAnim = new TranslateAnimation(0, 0, 0, 0);
        translationAnim.setDuration(0);
        animSet.setFillAfter(true);
        animSet.setFillEnabled(true);
        view.clearAnimation();
        view.startAnimation(animSet);
    }
    mVolumeGroupList.stopAnimationAll();
    if (!exceptAddedRoutes) {
        finishAnimation(false);
    }
}

From source file:com.machine.custom.view.crouton.Manager.java

/**
 * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}.
 *
 * @param crouton/*from  w w w . jav a  2s . co m*/
 *   The {@link Crouton} that should be added.
 */
private void addCroutonToView(final Crouton crouton) {
    // don't add if it is already showing
    if (crouton.isShowing()) {
        return;
    }

    final View croutonView = crouton.getView();
    if (null == croutonView.getParent()) {
        ViewGroup.LayoutParams params = croutonView.getLayoutParams();
        if (null == params) {
            params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        // display Crouton in ViewGroup is it has been supplied
        if (null != crouton.getViewGroup()) {
            // TODO implement add to last position feature (need to align with how this will be requested for activity)
            if (crouton.getViewGroup() instanceof FrameLayout) {
                crouton.getViewGroup().addView(croutonView, params);
            } else {
                crouton.getViewGroup().addView(croutonView, 0, params);
            }
        } else {
            Activity activity = crouton.getActivity();
            if (null == activity || activity.isFinishing()) {
                return;
            }
            activity.addContentView(croutonView, params);
        }
    }

    croutonView.requestLayout(); // This is needed so the animation can use the measured with/height
    croutonView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressWarnings("deprecation")
        @Override
        public void onGlobalLayout() {
            //        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
            croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            //        } else {
            //          croutonView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            //        }

            croutonView.startAnimation(crouton.getInAnimation());
            announceForAccessibilityCompat(crouton.getActivity(), crouton.getText());
            if (Configuration.DURATION_INFINITE != crouton.getConfiguration().durationInMilliseconds) {
                sendMessageDelayed(crouton, Messages.REMOVE_CROUTON,
                        crouton.getConfiguration().durationInMilliseconds
                                + crouton.getInAnimation().getDuration());
            }
        }
    });
}

From source file:com.elephant.widget.crouton.Manager.java

/**
 * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}
 * ./*from   w ww .  ja va  2s .  com*/
 * 
 * @param crouton
 *            The {@link Crouton} that should be added.
 */
private void addCroutonToView(final Crouton crouton) {
    // don't add if it is already showing
    if (crouton.isShowing()) {
        return;
    }

    final View croutonView = crouton.getView();
    if (null == croutonView.getParent()) {
        ViewGroup.LayoutParams params = croutonView.getLayoutParams();
        if (null == params) {
            params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        // display Crouton in ViewGroup is it has been supplied
        if (null != crouton.getViewGroup()) {
            // TODO implement add to last position feature (need to align
            // with how this will be requested for activity)
            if (crouton.getViewGroup() instanceof FrameLayout) {
                crouton.getViewGroup().addView(croutonView, params);
            } else {
                crouton.getViewGroup().addView(croutonView, 0, params);
            }
        } else {
            Activity activity = crouton.getActivity();
            if (null == activity || activity.isFinishing()) {
                return;
            }
            activity.addContentView(croutonView, params);
        }
    }

    croutonView.requestLayout(); // This is needed so the animation can use
    // the measured with/height
    croutonView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressLint("NewApi")
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
                croutonView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }

            croutonView.startAnimation(crouton.getInAnimation());
            announceForAccessibilityCompat(crouton.getActivity(), crouton.getText());
            if (Configuration.DURATION_INFINITE != crouton.getConfiguration().durationInMilliseconds) {
                sendMessageDelayed(crouton, Messages.REMOVE_CROUTON,
                        crouton.getConfiguration().durationInMilliseconds
                                + crouton.getInAnimation().getDuration());
            }
        }
    });
}

From source file:Main.java

private static void expandInner(final View view, final View parentView, final ViewGroup rootContainer,
        final int targtetHeight) {

    setHeight(view, 0);//  w w  w  .  j a  v a 2 s  .  c om
    view.setVisibility(View.VISIBLE);
    final Animation animation = new Animation() {

        private final Rect rect = new Rect();
        private final Rect parentVisibleRect = new Rect();

        ViewTreeObserver.OnGlobalLayoutListener globalLayoutListener;

        private final Runnable checkViewRunnable = new Runnable() {
            @Override
            public void run() {
                checkForViewInsideVisibleArea();
            }
        };

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {

            int neededHeight = interpolatedTime == 1 ? LayoutParams.WRAP_CONTENT
                    : (int) (targtetHeight * interpolatedTime);
            setHeight(view, neededHeight);

            final ViewTreeObserver viewTreeObserver = view.getViewTreeObserver();

            if (globalLayoutListener == null) {
                globalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {

                    @Override
                    public void onGlobalLayout() {

                        if (globalLayoutListener == null) {
                            removeGlobalLayoutListener(viewTreeObserver, this);
                        }

                        checkForViewInsideVisibleArea();
                    }
                };

                viewTreeObserver.addOnGlobalLayoutListener(globalLayoutListener);
            }

            if (globalLayoutListener != null && interpolatedTime == 1) {
                runInUIThread(checkViewRunnable);
                globalLayoutListener = null;
            }

            view.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }

        private void checkForViewInsideVisibleArea() {

            if (rootContainer.indexOfChild(parentView) == -1) {
                return;
            }

            parentVisibleRect.left = 0;
            parentVisibleRect.top = 0;
            parentVisibleRect.right = parentView.getWidth();
            parentVisibleRect.bottom = parentView.getHeight();

            rootContainer.offsetDescendantRectToMyCoords(parentView, parentVisibleRect);

            if (parentVisibleRect.top < 0 || parentVisibleRect.bottom > rootContainer.getHeight()) {

                rect.left = parentView.getLeft();
                rect.top = parentView.getTop();
                rect.right = parentView.getRight();
                rect.bottom = parentView.getBottom();

                parentView.requestRectangleOnScreen(rect, true);
            }
        }
    };

    animation.setDuration(ANIMATION_DURATION);
    view.startAnimation(animation);
}

From source file:com.prashant.custom.widget.crouton.Manager.java

/**
 * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}.
 *
 * @param crouton/*from  w  w w .  j a  v  a 2s .c o m*/
 *   The {@link Crouton} that should be added.
 */
private void addCroutonToView(final Crouton crouton) {
    // don't add if it is already showing
    if (crouton.isShowing()) {
        return;
    }

    final View croutonView = crouton.getView();
    if (null == croutonView.getParent()) {
        ViewGroup.LayoutParams params = croutonView.getLayoutParams();
        if (null == params) {
            params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        // display Crouton in ViewGroup is it has been supplied
        if (null != crouton.getViewGroup()) {
            // TODO implement add to last position feature (need to align with how this will be requested for activity)
            if (crouton.getViewGroup() instanceof FrameLayout) {
                crouton.getViewGroup().addView(croutonView, params);
            } else {
                crouton.getViewGroup().addView(croutonView, 0, params);
            }
        } else {
            Activity activity = crouton.getActivity();
            if (null == activity || activity.isFinishing()) {
                return;
            }
            activity.addContentView(croutonView, params);
        }
    }

    croutonView.requestLayout(); // This is needed so the animation can use the measured with/height
    croutonView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @SuppressWarnings("deprecation")
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
                croutonView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }

            croutonView.startAnimation(crouton.getInAnimation());
            announceForAccessibilityCompat(crouton.getActivity(), crouton.getText());
            if (Configuration.DURATION_INFINITE != crouton.getConfiguration().durationInMilliseconds) {
                sendMessageDelayed(crouton, Messages.REMOVE_CROUTON,
                        crouton.getConfiguration().durationInMilliseconds
                                + crouton.getInAnimation().getDuration());
            }
        }
    });
}

From source file:com.android.hcframe.DraggableGridViewPager.java

private void animateDragged() {
    if (mLastDragged >= 0) {
        final View v = getChildAt(mLastDragged);

        final Rect r = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
        r.inset(-r.width() / 20, -r.height() / 20);
        v.measure(MeasureSpec.makeMeasureSpec(r.width(), MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(r.height(), MeasureSpec.EXACTLY));
        v.layout(r.left, r.top, r.right, r.bottom);

        AnimationSet animSet = new AnimationSet(true);
        ScaleAnimation scale = new ScaleAnimation(0.9091f, 1, 0.9091f, 1, v.getWidth() / 2, v.getHeight() / 2);
        scale.setDuration(ANIMATION_DURATION);
        AlphaAnimation alpha = new AlphaAnimation(1, .5f);
        alpha.setDuration(ANIMATION_DURATION);

        animSet.addAnimation(scale);//  ww  w  .  j  a va  2  s. c  o  m
        animSet.addAnimation(alpha);
        animSet.setFillEnabled(true);
        animSet.setFillAfter(true);

        v.clearAnimation();
        v.startAnimation(animSet);
    }
}

From source file:com.google.android.gcm.demo.ui.MainActivity.java

/**
 * Toggle the Logs View visibility with a nice animation.
 *//*from   w w w.  j ava2 s  .com*/
public void toggleLogsView(boolean showView) {
    final View logsView = findViewById(R.id.logs_layout);
    final View bodyView = findViewById(R.id.container);
    final FrameLayout.LayoutParams logsLayoutParams = (FrameLayout.LayoutParams) logsView.getLayoutParams();
    final int startLogsY, endLogsY, startBodyY, endBodyY;

    if (showView) {
        // The logsView height set in XML is a placeholder, we need to compute at runtime
        // how much is 0.4 of the screen height.
        int height = (int) (0.4 * mDrawerLayout.getHeight());

        // The LogsView is hidden being placed off-screen with a negative bottomMargin.
        // We need to update its height and bottomMargin to the correct runtime values.
        logsLayoutParams.bottomMargin = -logsLayoutParams.height;
        logsView.setLayoutParams(logsLayoutParams);
        logsLayoutParams.height = height;

        // Prepare the value for the Show animation.
        startLogsY = logsLayoutParams.bottomMargin;
        endLogsY = 0;
        startBodyY = 0;
        endBodyY = logsLayoutParams.height;
    } else {
        // Prepare the value for the Hide animation.
        startLogsY = 0;
        endLogsY = -logsLayoutParams.height;
        startBodyY = logsLayoutParams.height;
        endBodyY = 0;
    }
    final int deltaLogsY = endLogsY - startLogsY;
    final int deltaBodyY = endBodyY - startBodyY;
    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            logsLayoutParams.bottomMargin = (int) (startLogsY + deltaLogsY * interpolatedTime);
            logsView.setLayoutParams(logsLayoutParams);
            bodyView.setPadding(0, 0, 0, (int) (startBodyY + deltaBodyY * interpolatedTime));
        }
    };
    a.setDuration(500);
    logsView.startAnimation(a);
}

From source file:com.appolica.interactiveinfowindow.InfoWindowManager.java

private void animateWindowOpen(@NonNull final InfoWindow infoWindow, @NonNull final View container) {

    final SimpleAnimationListener animationListener = new SimpleAnimationListener() {

        @Override//from  w  w  w. j  av  a  2 s . co m
        public void onAnimationStart(Animation animation) {

            container.setVisibility(View.VISIBLE);
            propagateShowEvent(infoWindow, InfoWindow.State.SHOWING);

        }

        @Override
        public void onAnimationEnd(Animation animation) {

            propagateShowEvent(infoWindow, InfoWindow.State.SHOWN);
            setCurrentWindow(infoWindow);

        }
    };

    if (showAnimation == null) {

        container.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

            @Override
            public boolean onPreDraw() {
                final int containerWidth = container.getWidth();
                final int containerHeight = container.getHeight();

                final float pivotX = container.getX() + containerWidth / 2;
                final float pivotY = container.getY() + containerHeight;

                final ScaleAnimation scaleAnimation = new ScaleAnimation(0f, 1f, 0f, 1f, pivotX, pivotY);

                scaleAnimation.setDuration(DURATION_WINDOW_ANIMATION);
                scaleAnimation.setInterpolator(new DecelerateInterpolator());
                scaleAnimation.setAnimationListener(animationListener);

                container.startAnimation(scaleAnimation);

                container.getViewTreeObserver().removeOnPreDrawListener(this);
                return true;
            }
        });
    } else {
        showAnimation.setAnimationListener(animationListener);
        container.startAnimation(showAnimation);
    }
}