Example usage for android.animation ObjectAnimator ofInt

List of usage examples for android.animation ObjectAnimator ofInt

Introduction

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

Prototype

public static <T> ObjectAnimator ofInt(T target, Property<T, Integer> xProperty, Property<T, Integer> 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.xixicm.de.presentation.view.fragment.SentenceDetailFragment.java

private void initAnimatiorIfNeed() {
    if (mAudioFabAnimator == null) {
        mAudioFabAnimator = ObjectAnimator.ofInt(mAudioFab, "imageLevel", 0, 10000);
        mAudioFabAnimator.setDuration(1000);
        mAudioFabAnimator.setRepeatCount(ValueAnimator.INFINITE);
    }/*from   w  w  w  . j  a va2 s  .  com*/
}

From source file:com.microntek.music.MusicActivity.java

private void updateStatusBarColor(int color) {
    if (color == Color.TRANSPARENT) {
        color = getResources().getColor(R.color.primary_dark);
    }/*from  w  w w . ja  v  a2  s .c  om*/
    final Window window = getWindow();
    ObjectAnimator animator = ObjectAnimator.ofInt(window, "statusBarColor", window.getStatusBarColor(), color);
    animator.setEvaluator(new ArgbEvaluator());
    animator.setDuration(300);
    animator.start();
}

From source file:com.example.george.sharedelementimplementation.MainActivity.java

public void runEnterAnimation() {
    final long duration = (long) (ANIM_DURATION * MainActivity.sAnimatorScale);
    // set starting values for properties we're going to animate. These
    // values scale and position the full size version down to the thumbnail
    // size/location, from which we'll animate it back up
    ObjectAnimator anim = ObjectAnimator.ofInt(mBackground, "alpha", 0, 255);
    anim.addListener(new Animator.AnimatorListener() {
        @Override/*from  w w w  .  j a  v a 2  s . c  o  m*/
        public void onAnimationStart(Animator animation) {

        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mIsAnimationPlaying = false;
            mImage.setVisibility(View.GONE);
            mPager.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });

    AnimatorSet set = new AnimatorSet();
    set.playTogether(ObjectAnimator.ofFloat(mImage, "translationX", mXDelta, 0),
            ObjectAnimator.ofFloat(mImage, "translationY", mYDelta, 0),
            ObjectAnimator.ofFloat(mImage, "scaleX", mImageScale, 1),
            ObjectAnimator.ofFloat(mImage, "scaleY", mImageScale, 1),
            //            ObjectAnimator.ofFloat(mImage, "alpha", 0, 1),
            ObjectAnimator.ofFloat(mImage, "imageCrop", clipRatio, 0f), anim);
    set.setInterpolator(sDecelerator);
    set.setDuration(duration).start();
    mIsAnimationPlaying = true;
}

From source file:com.example.android.tryanimationt.TryAnimationFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mCardView = (CardView) view.findViewById(R.id.cardview);

    fab1st = (android.widget.ImageButton) view.findViewById(R.id.fabBt);
    fab2nd = (android.widget.ImageButton) view.findViewById(R.id.fabBt2);
    fab3rd = (android.widget.ImageButton) view.findViewById(R.id.fab3);

    footer = view.findViewById(R.id.footer);

    animButtons(fab1st, true, 2500, 0);/*from w  w  w. j  av a  2s  . co m*/
    animButtons(fab2nd, true, 1000, 150);
    animButtons(fab3rd, true, 2000, 250);

    fab1st.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AnimatorSet animSet = new AnimatorSet();
            ObjectAnimator anim2 = ObjectAnimator.ofFloat(fab1st, "rotationX", 0, 359);
            anim2.setDuration(1500);

            ObjectAnimator anim3 = ObjectAnimator.ofFloat(fab1st, "rotationY", 0, 359);
            anim3.setDuration(1500);

            ObjectAnimator animTrx = ObjectAnimator.ofFloat(fab1st, "translationX", 0, -20);
            animTrx.setDuration(2500);
            ObjectAnimator animTry = ObjectAnimator.ofFloat(fab1st, "translationY", 0, -20);
            animTry.setDuration(2500);

            animSet.setInterpolator(new BounceInterpolator());
            animSet.playTogether(anim2, anim3, animTry, animTrx);

            animSet.start();

        }
    });

    fab1st.setOutlineProvider(new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            int size = getResources().getDimensionPixelSize(R.dimen.fab_size);
            outline.setOval(0, 0, size, size);
            outline.setRoundRect(0, 0, size, size, size / 2);
        }
    });

    fab1st.setClipToOutline(true);

    final View vImage = view.findViewById(R.id.image);
    final View vCard = view.findViewById(R.id.cardview);
    final View vCardTextPart = view.findViewById(R.id.cardview_textpart2);
    final View vCardContentContainer = view.findViewById(R.id.cardContentContainer);

    vCard.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(),

                    // Now we provide a list of Pair items which contain the view we can transitioning
                    // from, and the name of the view it is transitioning to, in the launched activity

                    android.support.v4.util.Pair.create(vImage, "photo_hero"),
                    android.support.v4.util.Pair.create(vCardTextPart, "sharedSceneTrasintionText"));

            Intent intent = new Intent(getActivity(), sceneTransitionActivity.class);
            intent.putExtra("photo_hero", R.drawable.image1);
            ActivityCompat.startActivity(getActivity(), intent, options.toBundle());
        }
    });

    fab2nd.setOutlineProvider(new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            int size = getResources().getDimensionPixelSize(R.dimen.fab_size);
            outline.setOval(0, 0, size, size);
            outline.setRoundRect(0, 0, size, size, size / 2);
        }
    });

    fab2nd.setClipToOutline(true);

    final AnimationDrawable[] animDrawables = new AnimationDrawable[2];
    animDrawables[0] = (AnimationDrawable) getResources().getDrawable(R.drawable.anim_off_to_on);
    animDrawables[1] = (AnimationDrawable) getResources().getDrawable(R.drawable.anim_on_to_off);
    animDrawables[0].setOneShot(true);
    animDrawables[1].setOneShot(true);

    fab2nd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            final int fab2InconIndex = mAnimationStateIndex;
            mAnimationStateIndex = (mAnimationStateIndex + 1) % 2;

            /*****************************************************/
            // animate the card

            //final Animation myRotation = AnimationUtils.loadAnimation(getActivity(), R.anim.rotate_anim);
            //mCardView.startAnimation(myRotation);

            int start;
            int end;
            if (mAnimationStateIndex == 0) {
                start = Color.rgb(0x71, 0xc3, 0xde);
                end = Color.rgb(0x68, 0xe8, 0xee);
            } else {
                start = Color.rgb(0x68, 0xe8, 0xee);
                end = Color.rgb(0x71, 0xc3, 0xde);
            }

            AnimatorSet animSet = new AnimatorSet();

            ValueAnimator valueAnimator = ObjectAnimator.ofInt(vCardContentContainer, "backgroundColor", start,
                    end);
            valueAnimator.setInterpolator(new BounceInterpolator());
            valueAnimator.setDuration(2000);
            valueAnimator.setEvaluator(new ArgbEvaluator());

            valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    int animProgress = (Integer) animation.getAnimatedValue();

                }
            });
            valueAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    mCardView.setRadius(8);
                    //mCardView.setElevation(0);
                }
            });

            float rotateStart, rotateEnd;
            float scaleXStart, scaleXEnd;
            float rotateXStart, rotateXEnd;
            float rotateYStart, rotateYEnd;
            float transitionXStart, transitionXEnd;
            float transitionYStart, transitionYEnd;

            if (mAnimationStateIndex == 0) {
                rotateStart = 0f;
                rotateEnd = 80f;
                scaleXStart = 1f;
                scaleXEnd = 0.66f;
                rotateXStart = 0f;
                rotateXEnd = 30f;
                rotateYStart = 0f;
                rotateYEnd = 30f;
                transitionYStart = 0f;
                transitionYEnd = -100f;
                transitionXStart = 0f;
                transitionXEnd = 100f;
            } else {
                rotateStart = 80f;
                rotateEnd = 0f;
                scaleXStart = 0.66f;
                scaleXEnd = 1;
                rotateXStart = 30;
                rotateXEnd = 0f;
                rotateYStart = 30f;
                rotateYEnd = 0f;
                transitionYStart = -100f;
                transitionYEnd = 0f;
                transitionXStart = 100f;
                transitionXEnd = 0f;
            }

            ObjectAnimator anim = ObjectAnimator.ofFloat(mCardView, "rotation", rotateStart, rotateEnd);
            anim.setDuration(2000);

            ObjectAnimator anim1 = ObjectAnimator.ofFloat(mCardView, "scaleX", scaleXStart, scaleXEnd);
            anim1.setDuration(2000);

            ObjectAnimator anim2 = ObjectAnimator.ofFloat(mCardView, "rotationX", rotateXStart, rotateXEnd);
            anim2.setDuration(2000);

            ObjectAnimator anim3 = ObjectAnimator.ofFloat(mCardView, "rotationY", rotateYStart, rotateYEnd);
            anim3.setDuration(2000);

            ObjectAnimator animTry = ObjectAnimator.ofFloat(mCardView, "translationY", transitionYStart,
                    transitionYEnd);
            animTry.setDuration(2000);
            ObjectAnimator animTrx = ObjectAnimator.ofFloat(mCardView, "translationX", transitionXStart,
                    transitionXEnd);
            animTrx.setDuration(2000);
            animSet.setInterpolator(new BounceInterpolator());
            animSet.playTogether(valueAnimator, anim, anim2, anim3, anim1, animTry, animTrx);

            float controlX1, controlY1, controlX2, controlY2;
            if (mAnimationStateIndex == 0) {
                controlX1 = 0f;
                controlY1 = 0.25f;
                controlX2 = 1;
                controlY2 = 1;
            } else {
                controlX1 = 1;
                controlY1 = 1;
                controlX2 = 0.25f;
                controlY2 = 1;
            }

            PathInterpolator pathInterpolator = new PathInterpolator(controlX1, controlY1, controlX2,
                    controlY2);
            animTrx.setInterpolator(pathInterpolator);

            animSet.start();

            /*****************************************************/
            // animate rotate white button

            RotateAnimation r = new RotateAnimation(0, 359, Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            r.setDuration(2000);
            r.setFillAfter(true);

            r.setInterpolator(new BounceInterpolator());

            fab2nd.startAnimation(r);

            // change 2nd button image
            fab2nd.setImageDrawable(animDrawables[fab2InconIndex]);
            animDrawables[fab2InconIndex].start();

            /*****************************************************/
            // animate changing 3rd button image
            fab3rd.setImageDrawable(animDrawables[mAnimationStateIndex]);
            animDrawables[mAnimationStateIndex].start();

            /*****************************************************/
            // using AnimatedStateListDrawable to animate the 1st button image by its state
            {
                Drawable drawable = getActivity().getResources().getDrawable(R.drawable.icon_anim);
                fab1st.setImageDrawable(drawable);

                final int[] STATE_CHECKED = new int[] { android.R.attr.state_checked };
                final int[] STATE_UNCHECKED = new int[] {};

                // set state
                fab1st.setImageState((mAnimationStateIndex != 0) ? STATE_UNCHECKED : STATE_CHECKED, false);
                drawable.jumpToCurrentState();
                // change to state
                fab1st.setImageState((mAnimationStateIndex != 0) ? STATE_CHECKED : STATE_UNCHECKED, false);
            }

        }
    });

    fab3rd.setOutlineProvider(new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            int size = getResources().getDimensionPixelSize(R.dimen.fab_size);
            outline.setOval(0, 0, size, size);
            outline.setRoundRect(0, 0, size, size, size / 2);
        }
    });

    fab3rd.setClipToOutline(true);
    final CheckBox circleFadeout = (CheckBox) view.findViewById(R.id.circleFadeout);

    circleFadeout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (((CheckBox) v).isChecked()) {
            }
        }
    });

    final ImageButton vLogoBt = fab3rd;
    vLogoBt.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            animButtons(fab1st, false, 2000, 0);
            animButtons(fab2nd, false, 600, 150);
            animButtons(fab3rd, false, 1500, 250);

            Handler delayHandler = new Handler();
            delayHandler.postDelayed(new Runnable() {

                @Override
                public void run() {

                    Intent logoIntent = new Intent(getActivity(), LogoActivity.class);

                    logoIntent.putExtra(LogoActivity.LOGO_VIEW_IMAGE_FADEOUT,
                            (circleFadeout.isChecked() ? 1 : 0));
                    logoIntent.putExtra(LogoActivity.LOGO_VIEW_TRANSTION_TYPE, logoActivityTransitionType);

                    startActivityForResult(logoIntent, mRequestCode,
                            ActivityOptions.makeSceneTransitionAnimation(getActivity()).toBundle());

                }
            }, 1000);

            // footer slide down
            slideView(footer, false);
        }
    });

    mRadioGrp = (RadioGroup) view.findViewById(R.id.radioGroup);
    mRadioGrp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {

            int selectedId = mRadioGrp.getCheckedRadioButtonId();

            String transitionType = "using";
            switch (selectedId) {
            case R.id.radioFade:
                logoActivityTransitionType = 0;
                transitionType = transitionType + " Fade";
                break;
            case R.id.radioExplode:
                logoActivityTransitionType = 1;
                transitionType = transitionType + " Explode";
                break;
            default:
                logoActivityTransitionType = 2;
                transitionType = transitionType + " Slide";
            }
            mSwitcher.setText(transitionType + " transition");
        }
    });

    mSwitcher = (TextSwitcher) view.findViewById(R.id.textSwitcher);
    mSwitcher.setFactory(mFactory);

    Animation in = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_in_top);
    Animation out = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_out_top);
    mSwitcher.setInAnimation(in);
    mSwitcher.setOutAnimation(out);
    mSwitcher.setCurrentText("using Fade transition");

    // footer slide up
    slideView(footer, true);
}

From source file:com.google.samples.apps.topeka.activity.QuizActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void prepareCircularReveal(View startView, FrameLayout targetView) {
    int centerX = (startView.getLeft() + startView.getRight()) / 2;
    // Subtract the start view's height to adjust for relative coordinates on screen.
    int centerY = (startView.getTop() + startView.getBottom()) / 2 - startView.getHeight();
    float endRadius = (float) Math.hypot(centerX, centerY);
    mCircularReveal = ViewAnimationUtils.createCircularReveal(targetView, centerX, centerY,
            startView.getWidth(), endRadius);
    mCircularReveal.setInterpolator(new FastOutLinearInInterpolator());

    mCircularReveal.addListener(new AnimatorListenerAdapter() {
        @Override/*from   www. j a v a 2s.c  o m*/
        public void onAnimationEnd(Animator animation) {
            mIcon.setVisibility(View.GONE);
            mCircularReveal.removeListener(this);
        }
    });
    // Adding a color animation from the FAB's color to transparent creates a dissolve like
    // effect to the circular reveal.
    int accentColor = ContextCompat.getColor(this, mCategory.getTheme().getAccentColor());
    mColorChange = ObjectAnimator.ofInt(targetView, ViewUtils.FOREGROUND_COLOR, accentColor, Color.TRANSPARENT);
    mColorChange.setEvaluator(new ArgbEvaluator());
    mColorChange.setInterpolator(mInterpolator);
}

From source file:sg.fxl.topekaport.QuizActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void prepareCircularReveal(View startView, FrameLayout targetView) {
    int centerX = (startView.getLeft() + startView.getRight()) / 2;
    // Subtract the start view's height to adjust for relative coordinates on screen.
    int centerY = (startView.getTop() + startView.getBottom()) / 2 - startView.getHeight();
    float endRadius = (float) Math.hypot((double) centerX, (double) centerY);
    circularReveal = ViewAnimationUtils.createCircularReveal(targetView, centerX, centerY, startView.getWidth(),
            endRadius);//from w w  w .  j  a  v a 2 s .c o m
    circularReveal.setInterpolator(new FastOutLinearInInterpolator());

    circularReveal.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            icon.setVisibility(View.GONE);
            circularReveal.removeListener(this);
        }
    });
    // Adding a color animation from the FAB's color to transparent creates a dissolve like
    // effect to the circular reveal.
    int accentColor = ContextCompat.getColor(this, quiz.getTheme().getAccentColor());
    colorChange = ObjectAnimator.ofInt(targetView, ViewUtils.FOREGROUND_COLOR, accentColor, Color.TRANSPARENT);
    colorChange.setEvaluator(new ArgbEvaluator());
    colorChange.setInterpolator(interpolator);
}

From source file:com.google.samples.apps.topeka.view.quiz.QuizActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void prepareCircularReveal(View startView, FrameLayout targetView, int themeAccentColor) {
    int centerX = (startView.getLeft() + startView.getRight()) / 2;
    // Subtract the start view's height to adjust for relative coordinates on screen.
    int centerY = (startView.getTop() + startView.getBottom()) / 2 - startView.getHeight();
    float endRadius = (float) Math.hypot(centerX, centerY);
    mCircularReveal = ViewAnimationUtils.createCircularReveal(targetView, centerX, centerY,
            startView.getWidth(), endRadius);
    mCircularReveal.setInterpolator(new FastOutLinearInInterpolator());

    mCircularReveal.addListener(new AnimatorListenerAdapter() {
        @Override/*from   w w w.  j ava 2s . c  om*/
        public void onAnimationEnd(Animator animation) {
            mIcon.setVisibility(View.GONE);
            mCircularReveal.removeListener(this);
        }
    });
    // Adding a color animation from the FAB's color to transparent creates a dissolve like
    // effect to the circular reveal.
    mColorChange = ObjectAnimator.ofInt(targetView, ViewUtils.FOREGROUND_COLOR, themeAccentColor,
            Color.TRANSPARENT);
    mColorChange.setEvaluator(new ArgbEvaluator());
    mColorChange.setInterpolator(mInterpolator);
}

From source file:com.google.samples.apps.topeka.widget.quiz.AbsQuizView.java

private void animateForegroundColor(@ColorInt final int targetColor) {
    ObjectAnimator animator = ObjectAnimator.ofInt(this, ViewUtils.FOREGROUND_COLOR, Color.TRANSPARENT,
            targetColor);//from ww w.  j a  va 2  s  .c o m
    animator.setEvaluator(new ArgbEvaluator());
    animator.setStartDelay(FOREGROUND_COLOR_CHANGE_DELAY);
    animator.start();
}

From source file:com.hippo.android.animator.AnimatorsBase.java

static Animator crossFade(final View from, final View to, ViewGroup ancestor, final boolean toIsTop) {
    // Ensure views is laid out
    if (!ViewCompat.isLaidOut(from) || !ViewCompat.isLaidOut(to)) {
        Log.w(LOG_TAG, "From view and to view must be laid out before calling crossFade().");
        return null;
    }//  w ww.jav  a2 s .co m

    // Get overlay
    final ViewOverlayCompat overlay = ViewOverlayCompat.from(ancestor);
    if (overlay == null) {
        Log.w(LOG_TAG, "The ancestor in crossFade() must be able to create a ViewOverlay.");
        return null;
    }

    // Get the location of from view
    if (!Utils.getLocationInAncestor(from, ancestor, TEMP_LOCATION)) {
        Log.w(LOG_TAG, "From view must be in ancestor in crossFade().");
        return null;
    }
    int fromX = TEMP_LOCATION[0];
    int fromY = TEMP_LOCATION[1];

    // Get the location of to view
    if (!Utils.getLocationInAncestor(to, ancestor, TEMP_LOCATION)) {
        Log.w(LOG_TAG, "From view must be in ancestor in crossFade().");
        return null;
    }
    int toX = TEMP_LOCATION[0];
    int toY = TEMP_LOCATION[1];

    // Get the screenshot of from view
    final Bitmap fromBitmap = Utils.screenshot(from);
    if (fromBitmap == null) {
        Log.w(LOG_TAG, "Can't screenshot from view in crossFade().");
        return null;
    }

    // Get the screenshot of to view
    final Bitmap toBitmap = Utils.screenshot(to);
    if (toBitmap == null) {
        Log.w(LOG_TAG, "Can't screenshot to view in crossFade().");
        fromBitmap.recycle();
        return null;
    }

    // Create start drawables
    final Drawable fromDrawable = new BitmapDrawable(from.getContext().getResources(), fromBitmap);
    int fromWidth = fromBitmap.getWidth();
    int fromHeight = fromBitmap.getHeight();
    fromDrawable.setBounds(fromX, fromY, fromX + fromWidth, fromY + fromHeight);

    int fromCenterX = fromX + fromWidth / 2;
    int fromCenterY = fromY + fromHeight / 2;

    // Create end drawable
    final Drawable toDrawable = new BitmapDrawable(to.getContext().getResources(), toBitmap);
    int toWidth = toBitmap.getWidth();
    int toHeight = toBitmap.getHeight();
    int toStartX = fromCenterX - toWidth / 2;
    int toStartY = fromCenterY - toHeight / 2;
    toDrawable.setBounds(toStartX, toStartY, toStartX + toWidth, toStartY + toHeight);

    int toCenterX = toX + toWidth / 2;
    int toCenterY = toY + toHeight / 2;

    List<Animator> set = new ArrayList<>(4);

    // Create alpha animators
    Animator fromAlpha = ObjectAnimator.ofInt(fromDrawable, DRAWABLE_ALPHA_PROPERTY, 255, 0);
    Animator toAlpha = ObjectAnimator.ofInt(toDrawable, DRAWABLE_ALPHA_PROPERTY, 0, 255);
    set.add(fromAlpha);
    set.add(toAlpha);

    // Create position animators
    if (fromCenterX != toCenterX || fromCenterY != toCenterY) {
        Path path = ACR_PATH_MOTION.getPath(fromCenterX, fromCenterY, toCenterX, toCenterY);
        Animator fromPosition = Animators.ofPointF(fromDrawable, DRAWABLE_POSITION_PROPERTY, path);
        Animator toPosition = Animators.ofPointF(toDrawable, DRAWABLE_POSITION_PROPERTY, path);
        set.add(fromPosition);
        set.add(toPosition);
    }

    Animator animator = Animators.playTogether(set);
    animator.addListener(new AnimatorListenerAdapter() {
        float fromAlpha;
        float toAlpha;

        @Override
        public void onAnimationStart(Animator animation) {
            // Add drawables to overlay
            if (toIsTop) {
                overlay.add(fromDrawable);
                overlay.add(toDrawable);
            } else {
                overlay.add(toDrawable);
                overlay.add(fromDrawable);
            }
            // Hide from view and to view
            fromAlpha = from.getAlpha();
            toAlpha = to.getAlpha();
            from.setAlpha(0.0f);
            to.setAlpha(0.0f);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            // Remove drawables from overlay
            overlay.remove(fromDrawable);
            overlay.remove(toDrawable);
            // Show from view and to view
            from.setAlpha(fromAlpha);
            to.setAlpha(toAlpha);
            // Recycle bitmaps
            fromBitmap.recycle();
            toBitmap.recycle();
        }
    });

    return animator;
}

From source file:com.test.slidebutton.SlideButton.java

/**
 * max_leftmin_left/*from ww  w. j  a  va 2  s .co  m*/
 * @param toRight
 */
private void moveTo(final boolean toRight) {
    ObjectAnimator anim = ObjectAnimator.ofInt(this, "sliderCurrentLeft", sliderCurrentLeft,
            toRight ? max_left : min_left);
    anim.setInterpolator(new OvershootInterpolator());
    anim.setDuration(200);
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (toRight) {
                isOpen = true;
                if (listener != null) {
                    listener.open();
                }
                sliderCurrentLeft = sliderMoveStartLeft = max_left;
            } else {
                isOpen = false;
                if (listener != null) {
                    listener.close();
                }
                sliderCurrentLeft = sliderMoveStartLeft = min_left;
            }
            invalidateView();
        }
    });
    anim.start();
}