Search in sources :

Example 51 with AnimatorSet

use of android.animation.AnimatorSet in project android-tooltips by rharter.

the class ToolTipLayout method addTooltip.

public void addTooltip(ToolTip tooltip, boolean animate) {
    mToolTips.add(tooltip);
    View v = tooltip.getView();
    if (tooltip.isDismissOnTouch()) {
        v.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }
    addView(v);
    requestLayout();
    if (animate) {
        // We use a two pass preDrawListener so we can get the post animation
        // position of the item and then animate it.
        getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {

            @Override
            public boolean onPreDraw() {
                if (!mShouldRemoveObserver) {
                    mShouldRemoveObserver = true;
                    mFinalPositions.clear();
                    for (ToolTip t : mToolTips) {
                        float position = 0;
                        if (Gravity.isVertical(t.getGravity())) {
                            position = t.getView().getY();
                        } else {
                            position = t.getView().getX();
                        }
                        mFinalPositions.put(t, position);
                    }
                    return false;
                }
                mShouldRemoveObserver = false;
                getViewTreeObserver().removeOnPreDrawListener(this);
                List<Animator> animators = new ArrayList<>();
                for (ToolTip t : mToolTips) {
                    t.getView().setAlpha(0);
                    animators.add(ObjectAnimator.ofFloat(t.getView(), View.ALPHA, 0, 1));
                // TODO Restore this once I can fix the flicker
                //                        final float finalPosition = mFinalPositions.get(t);
                //                        if ((Gravity.VERTICAL_GRAVITY_MASK & t.getGravity()) == Gravity.TOP) {
                //                            float start = finalPosition - t.getView().getHeight() / 2;
                //                            t.getView().setY(start);
                //
                //                            animators.add(ObjectAnimator
                //                                    .ofFloat(t.getView(), View.TRANSLATION_Y,
                //                                            start,
                //                                            finalPosition));
                //                        } else if ((Gravity.VERTICAL_GRAVITY_MASK & t.getGravity())
                //                                == Gravity.BOTTOM) {
                //                            float start = finalPosition + t.getView().getHeight() / 2;
                //                            t.getView().setY(start);
                //
                //                            animators.add(ObjectAnimator
                //                                    .ofFloat(t.getView(), View.TRANSLATION_Y,
                //                                            start,
                //                                            finalPosition));
                //                        } else if ((Gravity.HORIZONTAL_GRAVITY_MASK & t.getGravity())
                //                                == Gravity.LEFT) {
                //                            float start = finalPosition - t.getView().getWidth() / 2;
                //                            t.getView().setX(start);
                //
                //                            animators.add(ObjectAnimator
                //                                    .ofFloat(t.getView(), View.TRANSLATION_X,
                //                                            start,
                //                                            finalPosition));
                //                        } else if ((Gravity.HORIZONTAL_GRAVITY_MASK & t.getGravity())
                //                                == Gravity.RIGHT) {
                //                            float start = finalPosition + t.getView().getWidth() / 2;
                //                            t.getView().setX(start);
                //
                //                            animators.add(ObjectAnimator
                //                                    .ofFloat(t.getView(), View.TRANSLATION_X,
                //                                            start,
                //                                            finalPosition));
                //                        }
                }
                AnimatorSet s = new AnimatorSet();
                s.playTogether(animators);
                s.start();
                return true;
            }
        });
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) AnimatorSet(android.animation.AnimatorSet) View(android.view.View) OnPreDrawListener(android.view.ViewTreeObserver.OnPreDrawListener)

Example 52 with AnimatorSet

use of android.animation.AnimatorSet in project android-tooltips by rharter.

the class ToolTipLayout method dismiss.

/**
     * Dismisses all tooltips currently being displayed.
     *
     * @param animate True to animate the transition.
     */
public void dismiss(boolean animate) {
    mToolTips.clear();
    if (animate) {
        final List<View> viewsToRemove = new ArrayList<>();
        List<Animator> a = new ArrayList<>();
        for (int i = 0; i < getChildCount(); i++) {
            a.add(ObjectAnimator.ofFloat(getChildAt(i), View.ALPHA, 0));
            viewsToRemove.add(getChildAt(i));
        }
        AnimatorSet s = new AnimatorSet();
        s.playTogether(a);
        s.addListener(new AnimatorListener() {

            @Override
            public void onAnimationStart(Animator animation) {
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                for (View v : viewsToRemove) {
                    removeView(v);
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
            }
        });
        s.start();
    } else {
        removeAllViews();
    }
}
Also used : AnimatorListener(android.animation.Animator.AnimatorListener) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ArrayList(java.util.ArrayList) AnimatorSet(android.animation.AnimatorSet) View(android.view.View)

Example 53 with AnimatorSet

use of android.animation.AnimatorSet in project ToggleDrawable by renaudcerrato.

the class MainActivity method toggle.

private void toggle() {
    isFaded = !isFaded;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        AnimatorSet set = new AnimatorSet();
        ObjectAnimator backgroundAnim = ObjectAnimator.ofInt(mContainer.getBackground(), "alpha", isFaded ? 128 : 0);
        ObjectAnimator drawableAnim = ObjectAnimator.ofInt(mSeekBar, "progress", isFaded ? mSeekBar.getMax() : 0);
        set.setDuration(700);
        set.setInterpolator(new DecelerateInterpolator(3f));
        set.playTogether(backgroundAnim, drawableAnim);
        set.start();
    } else {
        Animation set = new ToggleAnimationSet(isFaded);
        set.setDuration(700);
        set.setInterpolator(new DecelerateInterpolator(3f));
        mContainer.startAnimation(set);
    }
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ObjectAnimator(android.animation.ObjectAnimator) Animation(android.view.animation.Animation) AnimatorSet(android.animation.AnimatorSet)

Example 54 with AnimatorSet

use of android.animation.AnimatorSet in project ActivityAnimationLib by dkmeteor.

the class SplitEffect method animate.

public void animate(final Activity destActivity, final int duration) {
    final Interpolator interpolator = new DecelerateInterpolator();
    destActivity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
    new Handler().post(new Runnable() {

        @Override
        public void run() {
            mSetAnim = new AnimatorSet();
            mTopImage.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            mBottomImage.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            mSetAnim.addListener(new Animator.AnimatorListener() {

                @Override
                public void onAnimationStart(Animator animation) {
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    clean(destActivity);
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                    clean(destActivity);
                }

                @Override
                public void onAnimationRepeat(Animator animation) {
                }
            });
            Animator anim1 = ObjectAnimator.ofFloat(mTopImage, "translationY", mTopImage.getHeight() * -1);
            Animator anim2 = ObjectAnimator.ofFloat(mBottomImage, "translationY", mBottomImage.getHeight());
            if (interpolator != null) {
                anim1.setInterpolator(interpolator);
                anim2.setInterpolator(interpolator);
            }
            mSetAnim.setDuration(duration);
            mSetAnim.playTogether(anim1, anim2);
            mSetAnim.start();
        }
    });
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) Handler(android.os.Handler) Interpolator(android.view.animation.Interpolator) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) AnimatorSet(android.animation.AnimatorSet)

Example 55 with AnimatorSet

use of android.animation.AnimatorSet in project kickmaterial by byoutline.

the class AnimatorUtils method getScaleAnimator.

public static AnimatorSet getScaleAnimator(View view, float startScale, float endScale) {
    AnimatorSet set = new AnimatorSet();
    ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(view, View.SCALE_X, startScale, endScale);
    ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(view, View.SCALE_Y, startScale, endScale);
    set.playTogether(scaleXAnimator, scaleYAnimator);
    return set;
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) AnimatorSet(android.animation.AnimatorSet)

Aggregations

AnimatorSet (android.animation.AnimatorSet)491 ObjectAnimator (android.animation.ObjectAnimator)343 Animator (android.animation.Animator)285 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)144 View (android.view.View)109 ValueAnimator (android.animation.ValueAnimator)103 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)52 ArrayList (java.util.ArrayList)50 Rect (android.graphics.Rect)43 ViewGroup (android.view.ViewGroup)42 ImageView (android.widget.ImageView)36 TextView (android.widget.TextView)32 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)26 PropertyValuesHolder (android.animation.PropertyValuesHolder)25 Paint (android.graphics.Paint)25 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)25 Bitmap (android.graphics.Bitmap)17 Point (android.graphics.Point)15 OvershootInterpolator (android.view.animation.OvershootInterpolator)15 BitmapDrawable (android.graphics.drawable.BitmapDrawable)14