Example usage for android.view.animation ScaleAnimation ScaleAnimation

List of usage examples for android.view.animation ScaleAnimation ScaleAnimation

Introduction

In this page you can find the example usage for android.view.animation ScaleAnimation ScaleAnimation.

Prototype

public ScaleAnimation(float fromX, float toX, float fromY, float toY, float pivotX, float pivotY) 

Source Link

Document

Constructor to use when building a ScaleAnimation from code

Usage

From source file:com.chinabike.plugins.mip.activity.LocalAlbumDetail.java

private void hideViewPager() {
    pagerContainer.setVisibility(View.GONE);
    gridView.setVisibility(View.VISIBLE);
    findViewById(FakeR.getId(this, "id", "album_title_bar")).setVisibility(View.VISIBLE);
    AnimationSet set = new AnimationSet(true);
    ScaleAnimation scaleAnimation = new ScaleAnimation(1, (float) 0.9, 1, (float) 0.9,
            pagerContainer.getWidth() / 2, pagerContainer.getHeight() / 2);
    scaleAnimation.setDuration(200);//from  w w  w . ja  v a2s  .c o  m
    set.addAnimation(scaleAnimation);
    AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
    alphaAnimation.setDuration(200);
    set.addAnimation(alphaAnimation);
    pagerContainer.startAnimation(set);
    ((BaseAdapter) gridView.getAdapter()).notifyDataSetChanged();
}

From source file:com.android.andryyu.lifehelper.widget.RippleView.java

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    WIDTH = w;// ww  w  .  j a v a2 s . c o m
    HEIGHT = h;

    scaleAnimation = new ScaleAnimation(1.0f, zoomScale, 1.0f, zoomScale, w / 2, h / 2);
    scaleAnimation.setDuration(zoomDuration);
    scaleAnimation.setRepeatMode(Animation.REVERSE);
    scaleAnimation.setRepeatCount(1);
}

From source file:com.aniruddhc.acemusic.player.Drawers.QueueDrawerFragment.java

/**
 * Animates the play button to a pause button.
 *//*from   w ww . j a va 2s. co m*/
private void animatePlayToPause() {

    //Check to make sure the current icon is the play icon.
    if (mPlayPauseButton.getId() != R.drawable.play_light)
        return;

    //Fade out the play button.
    final ScaleAnimation scaleOut = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f, mPlayPauseButton.getWidth() / 2,
            mPlayPauseButton.getHeight() / 2);
    scaleOut.setDuration(150);
    scaleOut.setInterpolator(new AccelerateInterpolator());

    //Scale in the pause button.
    final ScaleAnimation scaleIn = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, mPlayPauseButton.getWidth() / 2,
            mPlayPauseButton.getHeight() / 2);
    scaleIn.setDuration(150);
    scaleIn.setInterpolator(new DecelerateInterpolator());

    scaleOut.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            mPlayPauseButton.setImageResource(R.drawable.pause_light);
            mPlayPauseButton.setPadding(0, 0, 0, 0);
            mPlayPauseButton.startAnimation(scaleIn);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

    });

    scaleIn.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            mPlayPauseButton.setScaleX(1.0f);
            mPlayPauseButton.setScaleY(1.0f);
            mPlayPauseButton.setId(R.drawable.pause_light);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

    });

    mPlayPauseButton.startAnimation(scaleOut);
}

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  ww .j  a v  a2  s.com
        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);
    }
}

From source file:com.sonvp.tooltip.Tooltip.java

/**
 * Removes the tool tip view from the view hierarchy.
 *//*w ww. ja v  a 2  s  .  c o  m*/
@UiThread
public void remove() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        container.setPivotX(pivotX);
        container.setPivotY(pivotY);
        container.animate().setDuration(ANIMATION_DURATION).alpha(0.0F).scaleX(0.0F).scaleY(0.0F)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        popupWindow.dismiss();

                    }
                });
    } else {
        AnimationSet animationSet = new AnimationSet(true);
        animationSet.setDuration(ANIMATION_DURATION);
        animationSet.addAnimation(new AlphaAnimation(1.0F, 0.0F));
        animationSet.addAnimation(new ScaleAnimation(1.0F, 0.0F, 1.0F, 0.0F, pivotX, pivotY));
        animationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                // do nothing
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                popupWindow.dismiss();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                // do nothing
            }
        });
        container.startAnimation(animationSet);
    }
}

From source file:com.aniruddhc.acemusic.player.Drawers.QueueDrawerFragment.java

/**
 * Animates the pause button to a play button.
 *//*from   w w  w . j a  va2s .c  om*/
private void animatePauseToPlay() {

    //Check to make sure the current icon is the pause icon.
    if (mPlayPauseButton.getId() != R.drawable.pause_light)
        return;

    //Scale out the pause button.
    final ScaleAnimation scaleOut = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f, mPlayPauseButton.getWidth() / 2,
            mPlayPauseButton.getHeight() / 2);
    scaleOut.setDuration(150);
    scaleOut.setInterpolator(new AccelerateInterpolator());

    //Scale in the play button.
    final ScaleAnimation scaleIn = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, mPlayPauseButton.getWidth() / 2,
            mPlayPauseButton.getHeight() / 2);
    scaleIn.setDuration(150);
    scaleIn.setInterpolator(new DecelerateInterpolator());

    scaleOut.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            mPlayPauseButton.setImageResource(R.drawable.play_light);
            mPlayPauseButton.setPadding(0, 0, -5, 0);
            mPlayPauseButton.startAnimation(scaleIn);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

    });

    scaleIn.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            mPlayPauseButton.setScaleX(1.0f);
            mPlayPauseButton.setScaleY(1.0f);
            mPlayPauseButton.setId(R.drawable.play_light);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

    });

    mPlayPauseButton.startAnimation(scaleOut);
}

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

private void internalHide(@NonNull final View container, @NonNull final InfoWindow toHideWindow,
        final boolean animated) {

    if (animated) {

        final Animation animation;

        if (hideAnimation == null) {

            final int containerWidth = container.getWidth();
            final int containerHeight = container.getHeight();

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

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

            animation.setDuration(DURATION_WINDOW_ANIMATION);
            animation.setInterpolator(new DecelerateInterpolator());

        } else {/*from   ww  w .  j a  va2s  . co  m*/
            animation = hideAnimation;
        }

        animation.setAnimationListener(new SimpleAnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
                toHideWindow.setWindowState(InfoWindow.State.HIDING);
                propagateShowEvent(toHideWindow, InfoWindow.State.HIDING);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                removeWindow(toHideWindow, container);

                if (container.getId() != InfoWindowManager.this.currentContainer.getId()) {
                    parent.removeView(container);
                }

                toHideWindow.setWindowState(InfoWindow.State.HIDDEN);
                propagateShowEvent(toHideWindow, InfoWindow.State.HIDDEN);
            }
        });

        this.currentContainer.startAnimation(animation);

    } else {

        removeWindow(toHideWindow, container);
        propagateShowEvent(toHideWindow, InfoWindow.State.HIDDEN);

    }
}

From source file:com.adityarathi.muo.ui.activities.NowPlayingActivity.java

/**
 * Animates the play button to a pause button.
 *//*from  w  ww . j  a va 2 s.com*/
private void animatePlayToPause() {

    //Check to make sure the current icon is the play icon.
    if (mPlayPauseButton.getId() != R.drawable.ic_play)
        return;

    //Fade out the play button.
    final ScaleAnimation scaleOut = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f, mPlayPauseButton.getWidth() / 2,
            mPlayPauseButton.getHeight() / 2);
    scaleOut.setDuration(150);
    scaleOut.setInterpolator(new AccelerateInterpolator());

    //Scale in the pause button.
    final ScaleAnimation scaleIn = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, mPlayPauseButton.getWidth() / 2,
            mPlayPauseButton.getHeight() / 2);
    scaleIn.setDuration(150);
    scaleIn.setInterpolator(new DecelerateInterpolator());

    scaleOut.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            mPlayPauseButton.setImageResource(R.drawable.ic_play);
            mPlayPauseButton.setPadding(0, 0, 0, 0);
            mPlayPauseButton.startAnimation(scaleIn);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

    });

    scaleIn.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            mPlayPauseButton.setScaleX(1.0f);
            mPlayPauseButton.setScaleY(1.0f);
            mPlayPauseButton.setId(R.drawable.ic_play);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

    });

    mPlayPauseButton.startAnimation(scaleOut);
}

From source file:com.adityarathi.muo.ui.activities.NowPlayingActivity.java

/**
 * Animates the pause button to a play button.
 *//*from   ww  w . j ava 2  s  .c o  m*/
private void animatePauseToPlay() {

    //Check to make sure the current icon is the pause icon.
    if (mPlayPauseButton.getId() != R.drawable.ic_play)
        return;

    //Scale out the pause button.
    final ScaleAnimation scaleOut = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f, mPlayPauseButton.getWidth() / 2,
            mPlayPauseButton.getHeight() / 2);
    scaleOut.setDuration(150);
    scaleOut.setInterpolator(new AccelerateInterpolator());

    //Scale in the play button.
    final ScaleAnimation scaleIn = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, mPlayPauseButton.getWidth() / 2,
            mPlayPauseButton.getHeight() / 2);
    scaleIn.setDuration(150);
    scaleIn.setInterpolator(new DecelerateInterpolator());

    scaleOut.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            mPlayPauseButton.setImageResource(R.drawable.ic_play);
            mPlayPauseButton.setPadding(0, 0, -5, 0);
            mPlayPauseButton.startAnimation(scaleIn);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

    });

    scaleIn.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            mPlayPauseButton.setScaleX(1.0f);
            mPlayPauseButton.setScaleY(1.0f);
            mPlayPauseButton.setId(R.drawable.ic_play);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

    });

    mPlayPauseButton.startAnimation(scaleOut);
}

From source file:com.sonvp.tooltip.Tooltip.java

@Override
public boolean onPreDraw() {
    container.getViewTreeObserver().removeOnPreDrawListener(this);

    Context context = container.getContext();
    if (!(context instanceof Activity)) {
        return false;
    }/*from   www  .  ja  v a  2  s.co m*/
    DisplayMetrics displayMetrics = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    int displayWidth = displayMetrics.widthPixels;
    int displayHeight = displayMetrics.heightPixels;
    int displayTop = getStatusBarHeight();

    int anchorTop = rectAnchorView.top;
    int anchorLeft = rectAnchorView.left;
    int anchorWidth = anchorView.getWidth();
    int anchorHeight = anchorView.getHeight();

    int textWidth = viewTooltip.getWidth();
    //default height 1 line
    int textHeight = viewTooltip.getHeight();
    int arrowWidth = arrow.getWidth();
    int arrowHeight = arrow.getHeight();

    int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(displayWidth, View.MeasureSpec.AT_MOST);
    int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);

    if (gravity == Gravity.TOP || gravity == Gravity.BOTTOM) {
        int width = Math.max(textWidth, arrowWidth);
        int height = textHeight + arrowHeight;

        int leftPadding;
        int topPadding;

        if (gravity == Gravity.TOP) {
            topPadding = anchorTop - height;
        } else {
            // gravity == Gravity.BOTTOM
            topPadding = anchorTop + anchorHeight;
        }

        int anchorHorizontalCenter = anchorLeft + anchorWidth / 2;
        int left = anchorHorizontalCenter - width / 2;
        int right = left + width;
        leftPadding = Math.max(0, right > displayWidth ? displayWidth - width : left);

        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) arrow.getLayoutParams();
        layoutParams.leftMargin = anchorHorizontalCenter - leftPadding - arrowWidth / 2;
        arrow.setLayoutParams(layoutParams);
        popupWindow.update(leftPadding, topPadding, container.getWidth(), container.getHeight());

        pivotX = width / 2;
        pivotY = gravity == Gravity.TOP ? height : 0;
    } else {
        // gravity == Gravity.LEFT || gravity == Gravity.RIGHT

        int width = textWidth + arrowWidth;

        int leftPadding;
        int topPadding;
        int rightPadding = 0;

        if (gravity == Gravity.LEFT) {
            leftPadding = Math.max(0, anchorLeft - width);
            leftPadding += (int) builder.toolTipMargin;
            rightPadding = displayWidth - anchorLeft;
        } else {
            // gravity == Gravity.RIGHT
            leftPadding = anchorLeft + anchorWidth;
            rightPadding = (int) builder.toolTipMargin;
        }

        if (viewTooltip instanceof TextView) {
            TextView text = (TextView) viewTooltip;
            text.setMaxWidth(displayWidth - rightPadding - leftPadding - arrowWidth);
            viewTooltip.measure(widthMeasureSpec, heightMeasureSpec);
            textHeight = viewTooltip.getMeasuredHeight(); // height multi line
        }

        int height = Math.max(textHeight, arrowHeight);

        int anchorVerticalCenter = anchorTop + anchorHeight / 2;
        int top = anchorVerticalCenter - height / 2;
        int bottom = top + height;

        if (builder.arrowGravity == Gravity.TOP) {
            top = anchorTop;
            bottom = anchorTop + height;
        } else if (builder.arrowGravity == Gravity.BOTTOM) {
            top = anchorTop + anchorHeight - height;
        }

        topPadding = Math.max(0,
                bottom > displayHeight ? displayHeight - height - (int) builder.toolTipMargin : top);
        topPadding = Math.max(0,
                topPadding < displayTop ? displayTop + (int) builder.toolTipMargin : topPadding);

        container.measure(widthMeasureSpec, heightMeasureSpec);
        int popupWidth = container.getMeasuredWidth();
        int popupHeight = container.getMeasuredHeight();
        popupWindow.update(leftPadding, topPadding, popupWidth, popupHeight);

        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) arrow.getLayoutParams();
        layoutParams.topMargin = anchorVerticalCenter - topPadding - arrowHeight / 2;
        arrow.setLayoutParams(layoutParams);

        pivotX = gravity == Gravity.LEFT ? popupWidth : 0;
        pivotY = anchorVerticalCenter - topPadding;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        container.setAlpha(0.0F);
        container.setPivotX(pivotX);
        container.setPivotY(pivotY);
        container.setScaleX(0.0F);
        container.setScaleY(0.0F);
        container.animate().setDuration(ANIMATION_DURATION).scaleX(1.0F).scaleY(1.0F).alpha(1.0F);
    } else {
        AnimationSet animationSet = new AnimationSet(true);
        animationSet.setDuration(ANIMATION_DURATION);
        animationSet.addAnimation(new AlphaAnimation(0.0F, 1.0F));
        animationSet.addAnimation(new ScaleAnimation(0.0F, 1.0F, 0.0F, 1.0F, pivotX, pivotY));
        container.startAnimation(animationSet);
    }

    return false;
}