Example usage for android.animation ObjectAnimator ofFloat

List of usage examples for android.animation ObjectAnimator ofFloat

Introduction

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

Prototype

public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> xProperty, Property<T, Float> 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.example.piechart3d.PieChart3DView.java

@Override
protected void onAttachedToWindow() {
    // TODO Auto-generated method stub
    super.onAttachedToWindow();

    ObjectAnimator mXAnimator = ObjectAnimator.ofFloat(mRenderer, "angle_x", 0, maxX);
    mXAnimator.setDuration(2000);//from  w  w w. j av a 2 s.  c o  m

    mXAnimator.addListener(new AnimatorListener() {

        @Override
        public void onAnimationCancel(final Animator animation) {
        }

        @Override
        public void onAnimationEnd(final Animator animation) {
            // progressBar.setProgress(progress);
        }

        @Override
        public void onAnimationRepeat(final Animator animation) {
        }

        @Override
        public void onAnimationStart(final Animator animation) {
        }
    });
    mXAnimator.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(final ValueAnimator animation) {

        }
    });
    LinearInterpolator di = new LinearInterpolator();
    mXAnimator.setInterpolator(di);
    mXAnimator.start();
}

From source file:com.zandbee.floatingtitlebar.FloatingTitleBarActivity.java

@Override
public void onScrollChanged(int deltaX, int deltaY) {
    final int scrollY = scrollView.getScrollY();

    /** title is going up and has not yet collided with a toolbar */
    if (getLocationYonScreen(bodyLayout) <= (toolbarHeight + titleViewHeight)) {
        titleLayout.setTranslationY(scrollY);
        quasiFab.setTranslationY(scrollY + toolbarHeight + titleViewHeight - quasiFabCenterHeight);

        // TODO try without delta
        if (!titleInUpperPosition
        //&& deltaY > 0
        ) {/*from   w w  w .  j a v  a2 s .co  m*/
            titleInUpperPosition = true;
            final ObjectAnimator animPd = ObjectAnimator.ofFloat(titleBackDrawable, "progress",
                    titleBackDrawable.max - titleViewHeight, 0f);
            animPd.setInterpolator(new DecelerateInterpolator(2f));
            animPd.setDuration(200).start();
        }
    }

    /** title is going down */
    if (titleInUpperPosition && getLocationYonScreen(titleView) > toolbarHeight
    // + getLocationYonScreen(toolbar)
            && deltaY < 0) {
        titleInUpperPosition = false;
        final ObjectAnimator animPd = ObjectAnimator.ofFloat(titleBackDrawable, "progress", 0f,
                titleBackDrawable.max - titleViewHeight);
        animPd.setInterpolator(new AccelerateDecelerateInterpolator());
        animPd.setDuration(250).start();
    }

    imageView.setTranslationY(scrollY * 0.5f);
}

From source file:com.example.conallcurran.quick_click.English_Infants.java

private void zoomImageFromThumb(final View thumbView, int imageResId) {

    if (mCurrentAnimator != null) {
        mCurrentAnimator.cancel();/*from w w w .  j ava 2 s  . co m*/
    }

    final ImageView expandedImageView = (ImageView) findViewById(R.id.expanded_image);
    expandedImageView.setImageResource(imageResId);
    final Rect startBounds = new Rect();
    final Rect finalBounds = new Rect();
    final Point globalOffset = new Point();

    thumbView.getGlobalVisibleRect(startBounds);
    findViewById(R.id.container).getGlobalVisibleRect(finalBounds, globalOffset);
    startBounds.offset(-globalOffset.x, -globalOffset.y);
    finalBounds.offset(-globalOffset.x, -globalOffset.y);
    float startScale;
    if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width()
            / startBounds.height()) {
        startScale = (float) startBounds.height() / finalBounds.height();
        float startWidth = startScale * finalBounds.width();
        float deltaWidth = (startWidth - startBounds.width()) / 2;
        startBounds.left -= deltaWidth;
        startBounds.right += deltaWidth;
    } else {
        // Extend start bounds vertically
        startScale = (float) startBounds.width() / finalBounds.width();
        float startHeight = startScale * finalBounds.height();
        float deltaHeight = (startHeight - startBounds.height()) / 2;
        startBounds.top -= deltaHeight;
        startBounds.bottom += deltaHeight;
    }

    thumbView.setAlpha(0f);
    expandedImageView.setVisibility(View.VISIBLE);

    expandedImageView.setPivotX(0f);
    expandedImageView.setPivotY(0f);

    AnimatorSet set = new AnimatorSet();
    set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left, finalBounds.left))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top, finalBounds.top))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale, 1f))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale, 1f));
    set.setDuration(mShortAnimationDuration);
    set.setInterpolator(new DecelerateInterpolator());
    set.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mCurrentAnimator = null;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            mCurrentAnimator = null;
        }
    });
    set.start();
    mCurrentAnimator = set;

    final float startScaleFinal = startScale;
    expandedImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mCurrentAnimator != null) {
                mCurrentAnimator.cancel();
            }

            // Animate the four positioning/sizing properties in parallel, back to their
            // original values.
            AnimatorSet set = new AnimatorSet();
            set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScaleFinal))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScaleFinal));
            set.setDuration(mShortAnimationDuration);
            set.setInterpolator(new DecelerateInterpolator());
            set.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    mCurrentAnimator = null;
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    mCurrentAnimator = null;
                }
            });
            set.start();
            mCurrentAnimator = set;
        }
    });
}

From source file:com.devilyang.musicstation.swinginadapters.AnimationAdapter.java

private void animateView(int position, ViewGroup parent, View view) {
    if (mAnimationStartMillis == -1) {
        mAnimationStartMillis = System.currentTimeMillis();
    }/*  w  ww.  j  a v  a2s. co  m*/

    //      ViewDragHelper.setAlpha(view, 0);
    view.setAlpha(0);

    Animator[] childAnimators;
    if (mDecoratedBaseAdapter instanceof AnimationAdapter) {
        childAnimators = ((AnimationAdapter) mDecoratedBaseAdapter).getAnimators(parent, view);
    } else {
        childAnimators = new Animator[0];
    }
    Animator[] animators = getAnimators(parent, view);
    Animator alphaAnimator = ObjectAnimator.ofFloat(view, "alpha", 0, 1);

    AnimatorSet set = new AnimatorSet();
    set.playTogether(concatAnimators(childAnimators, animators, alphaAnimator));
    set.setStartDelay(calculateAnimationDelay());
    set.setDuration(getAnimationDurationMillis());
    set.start();

    mAnimators.put(view.hashCode(), set);
}

From source file:comm.lib.photoview.PhotoViewActivity.java

private void toggleDownLoadToolbar(final View view) {
    // API 11/*  w w w  .  j  a va2 s.  c o  m*/
    if (Build.VERSION.SDK_INT >= 11) {
        if (view.getVisibility() == View.VISIBLE) {
            ObjectAnimator hideAnimator = ObjectAnimator.ofFloat(view, "translationY", view.getTranslationY(),
                    view.getHeight());
            hideAnimator.setDuration(400);
            hideAnimator.start();
            hideAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    view.setVisibility(View.GONE);
                }
            });
        } else {
            view.setVisibility(View.VISIBLE);
            ObjectAnimator showAnimator = ObjectAnimator.ofFloat(view, "translationY", view.getTranslationY(),
                    0);
            showAnimator.setDuration(400);
            showAnimator.start();
        }
    } else {
        if (view.getVisibility() == View.VISIBLE) {
            view.setVisibility(View.GONE);
        } else {
            view.setVisibility(View.VISIBLE);
        }
    }

}

From source file:com.yoloo.android.util.AnimUtils.java

public static Animator createCircularReveal(RevealFrameLayout view, int x, int y, float startRadius,
        float endRadius) {
    if (VersionUtil.hasL()) {
        return ViewAnimationUtils.createCircularReveal(view, x, y, startRadius, endRadius);
    } else {/*from   www .j av a 2  s  . c o m*/
        view.setClipOutLines(true);
        view.setClipCenter(x, y);
        final Animator reveal = ObjectAnimator.ofFloat(view, "ClipRadius", startRadius, endRadius);
        reveal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                view.setClipOutLines(false);
            }
        });

        return reveal;
    }
}

From source file:com.andremion.music.MusicCoverView.java

public MusicCoverView(Context context, AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MusicCoverView);
    @Shape//from   w  w  w .ja v  a 2  s  .c  o  m
    int shape = a.getInt(R.styleable.MusicCoverView_shape, SHAPE_SQUARE);
    @ColorInt
    int trackColor = a.getColor(R.styleable.MusicCoverView_trackColor, TRACK_COLOR);
    a.recycle();

    // TODO: Canvas.clipPath works wrong when running with hardware acceleration on Android N
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
        setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }

    final float density = getResources().getDisplayMetrics().density;
    mTrackSize = TRACK_SIZE * density;
    mTrackPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTrackPaint.setStyle(Paint.Style.STROKE);
    mTrackPaint.setStrokeWidth(TRACK_WIDTH * density);

    mDiscPaintCenterDecor = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDiscPaintCenterDecor.setStyle(Paint.Style.FILL);
    mDiscPaintCenter = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDiscPaintCenter.setStyle(Paint.Style.FILL);

    setShape(shape);
    setTrackColor(trackColor);
    if (getDrawable() != null && ((BitmapDrawable) getDrawable()).getBitmap() != null) {
        setCenterColor(DISC_CENTER_COLOR, Palette.generate(((BitmapDrawable) getDrawable()).getBitmap(), 32)
                .getLightVibrantColor(DISC_CENTER_DECOR_COLOR));
    } else {
        setCenterColor(DISC_CENTER_COLOR, DISC_CENTER_DECOR_COLOR);
    }
    setScaleType();

    mStartRotateAnimator = ObjectAnimator.ofFloat(this, View.ROTATION, 0, FULL_ANGLE);
    mStartRotateAnimator.setInterpolator(new LinearInterpolator());
    if (SHAPE_SQUARE == mShape) {
        mStartRotateAnimator.setDuration(DURATION_SQUARE);
    } else {
        mStartRotateAnimator.setDuration(DURATION);
        mStartRotateAnimator.setRepeatCount(Animation.INFINITE);
    }

    mStartRotateAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            float current = getRotation();
            float target = current > HALF_ANGLE ? FULL_ANGLE : 0; // Choose the shortest distance to 0 rotation
            float diff = target > 0 ? FULL_ANGLE - current : current;
            mEndRotateAnimator.setFloatValues(current, target);
            if (SHAPE_SQUARE == mShape) {
                mEndRotateAnimator.setDuration((int) (DURATION_SQUARE_PER_DEGREES * diff));
            } else {
                mEndRotateAnimator.setDuration((int) (DURATION_PER_DEGREES * diff));
            }

            mEndRotateAnimator.start();
        }
    });

    mEndRotateAnimator = ObjectAnimator.ofFloat(MusicCoverView.this, View.ROTATION, 0);
    mEndRotateAnimator.setInterpolator(new LinearInterpolator());
    mEndRotateAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            setRotation(0);
            // isRunning method return true if it's called form here.
            // So we need call from post method to get the right returning.
            post(new Runnable() {
                @Override
                public void run() {
                    if (mCallbacks != null) {
                        mCallbacks.onRotateEnd(MusicCoverView.this);
                    }
                }
            });
        }
    });

    mRectToCircleTransition = new MorphTransition(SHAPE_RECTANGLE);
    mRectToCircleTransition.addTarget(this);
    mRectToCircleTransition.addListener(new TransitionAdapter() {
        @Override
        public void onTransitionStart(Transition transition) {
            mIsMorphing = true;
        }

        @Override
        public void onTransitionEnd(Transition transition) {
            mIsMorphing = false;
            mShape = SHAPE_CIRCLE;
            if (mCallbacks != null) {
                mCallbacks.onMorphEnd(MusicCoverView.this);
            }
        }
    });

    mCircleToRectTransition = new MorphTransition(SHAPE_CIRCLE);
    mCircleToRectTransition.addTarget(this);
    mCircleToRectTransition.addListener(new TransitionAdapter() {
        @Override
        public void onTransitionStart(Transition transition) {
            mIsMorphing = true;
        }

        @Override
        public void onTransitionEnd(Transition transition) {
            mIsMorphing = false;
            mShape = SHAPE_RECTANGLE;
            if (mCallbacks != null) {
                mCallbacks.onMorphEnd(MusicCoverView.this);
            }
        }
    });

    mSquareToSquareTransition = new MorphTransition(SHAPE_SQUARE);
    mSquareToSquareTransition.addTarget(this);
    mSquareToSquareTransition.addListener(new TransitionAdapter() {
        @Override
        public void onTransitionStart(Transition transition) {
            mIsMorphing = true;
        }

        @Override
        public void onTransitionEnd(Transition transition) {
            mIsMorphing = false;
            mShape = SHAPE_SQUARE;
            if (mCallbacks != null) {
                mCallbacks.onMorphEnd(MusicCoverView.this);
            }
        }
    });
}

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);/* w ww . j  a  va2s  . c  o 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.zhihu.android.app.mirror.widget.ArtboardView.java

private void onActionRelease() {
    if (mCallback != null && Math.abs(mDragDistance) > mDragDismissDistance) {
        mCallback.onDragDismiss(this, mIsDragDown);
    } else {//from ww  w.j  a v  a2 s.c  om
        if (mTransYAnim != null && mTransYAnim.isRunning()) {
            mTransYAnim.cancel();
        }

        mTransYAnim = ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, getTranslationY(), 0.0F);
        mTransYAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float dragTo = (Float) animation.getAnimatedValue();
                if (mCallback != null) {
                    mCallback.onDrag(ArtboardView.this, mDragDismissDistance, dragTo);
                }
            }
        });
        mTransYAnim.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));
        mTransYAnim.setInterpolator(PathInterpolatorCompat.create(0.4F, 0.0F, 0.2F, 1.0F));
        mTransYAnim.start();
    }
}

From source file:com.fugueweb.pub.animation.ZoomActivity.java

/**
 * "Zooms" in a thumbnail view by assigning the high resolution image to a hidden "zoomed-in"
 * image view and animating its bounds to fit the entire activity content area. More
 * specifically://from   w w  w .  j  av a  2s.  com
 *
 * <ol>
 *   <li>Assign the high-res image to the hidden "zoomed-in" (expanded) image view.</li>
 *   <li>Calculate the starting and ending bounds for the expanded view.</li>
 *   <li>Animate each of four positioning/sizing properties (X, Y, SCALE_X, SCALE_Y)
 *       simultaneously, from the starting bounds to the ending bounds.</li>
 *   <li>Zoom back out by running the reverse animation on click.</li>
 * </ol>
 *
 * @param thumbView  The thumbnail view to zoom in.
 * @param imageResId The high-resolution version of the image represented by the thumbnail.
 */
private void zoomImageFromThumb(final View thumbView, int imageResId) {
    // If there's an animation in progress, cancel it immediately and proceed with this one.
    if (mCurrentAnimator != null) {
        mCurrentAnimator.cancel();
    }

    // Load the high-resolution "zoomed-in" image.
    final ImageView expandedImageView = (ImageView) findViewById(R.id.expanded_image);
    expandedImageView.setImageResource(imageResId);

    // Calculate the starting and ending bounds for the zoomed-in image. This step
    // involves lots of math. Math.
    final Rect startBounds = new Rect();
    final Rect finalBounds = new Rect();
    final Point globalOffset = new Point();

    // The start bounds are the global visible rectangle of the thumbnail, and the
    // final bounds are the global visible rectangle of the container view. Also
    // set the container view's offset as the origin for the bounds, since that's
    // the origin for the positioning animation properties (X, Y).
    thumbView.getGlobalVisibleRect(startBounds);
    findViewById(R.id.container).getGlobalVisibleRect(finalBounds, globalOffset);
    startBounds.offset(-globalOffset.x, -globalOffset.y);
    finalBounds.offset(-globalOffset.x, -globalOffset.y);

    // Adjust the start bounds to be the same aspect ratio as the final bounds using the
    // "center crop" technique. This prevents undesirable stretching during the animation.
    // Also calculate the start scaling factor (the end scaling factor is always 1.0).
    float startScale;
    if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width()
            / startBounds.height()) {
        // Extend start bounds horizontally
        startScale = (float) startBounds.height() / finalBounds.height();
        float startWidth = startScale * finalBounds.width();
        float deltaWidth = (startWidth - startBounds.width()) / 2;
        startBounds.left -= deltaWidth;
        startBounds.right += deltaWidth;
    } else {
        // Extend start bounds vertically
        startScale = (float) startBounds.width() / finalBounds.width();
        float startHeight = startScale * finalBounds.height();
        float deltaHeight = (startHeight - startBounds.height()) / 2;
        startBounds.top -= deltaHeight;
        startBounds.bottom += deltaHeight;
    }

    // Hide the thumbnail and show the zoomed-in view. When the animation begins,
    // it will position the zoomed-in view in the place of the thumbnail.
    thumbView.setAlpha(0f);
    expandedImageView.setVisibility(View.VISIBLE);

    // Set the pivot point for SCALE_X and SCALE_Y transformations to the top-left corner of
    // the zoomed-in view (the default is the center of the view).
    expandedImageView.setPivotX(0f);
    expandedImageView.setPivotY(0f);

    // Construct and run the parallel animation of the four translation and scale properties
    // (X, Y, SCALE_X, and SCALE_Y).
    AnimatorSet set = new AnimatorSet();
    set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left, finalBounds.left))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top, finalBounds.top))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale, 1f))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale, 1f));
    set.setDuration(mShortAnimationDuration);
    set.setInterpolator(new DecelerateInterpolator());
    set.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mCurrentAnimator = null;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            mCurrentAnimator = null;
        }
    });
    set.start();
    mCurrentAnimator = set;

    // Upon clicking the zoomed-in image, it should zoom back down to the original bounds
    // and show the thumbnail instead of the expanded image.
    final float startScaleFinal = startScale;
    expandedImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mCurrentAnimator != null) {
                mCurrentAnimator.cancel();
            }

            // Animate the four positioning/sizing properties in parallel, back to their
            // original values.
            AnimatorSet set = new AnimatorSet();
            set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScaleFinal))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScaleFinal));
            set.setDuration(mShortAnimationDuration);
            set.setInterpolator(new DecelerateInterpolator());
            set.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    mCurrentAnimator = null;
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    mCurrentAnimator = null;
                }
            });
            set.start();
            mCurrentAnimator = set;
        }
    });
}