Example usage for android.view View animate

List of usage examples for android.view View animate

Introduction

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

Prototype

public ViewPropertyAnimator animate() 

Source Link

Document

This method returns a ViewPropertyAnimator object, which can be used to animate specific properties on this View.

Usage

From source file:org.glucosio.android.activity.MainActivity.java

private void showFabAnimation() {
    final View fab = findViewById(R.id.activity_main_fab_add_reading);
    if (fab.getVisibility() == View.INVISIBLE) {
        // Prepare the View for the animation
        fab.setVisibility(View.VISIBLE);
        fab.setAlpha(0.0f);/*  www  . j  a  v a  2s.  c  om*/

        fab.animate().alpha(1f).setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                fab.setVisibility(View.VISIBLE);
            }
        });
    } else {
        // do nothing
        // probably swiping from OVERVIEW to HISTORY tab
    }
}

From source file:com.androzic.ui.FileListDialog.java

@SuppressLint("NewApi")
private void crossfade(boolean direct) {
    final View from = direct ? progressBar : listView;
    final View to = direct ? listView : progressBar;

    if (!direct) {
        dialogView.setMinimumWidth(dialogView.getWidth());
        dialogView.setMinimumHeight(dialogView.getHeight());
    }//from   w  w w.  j a  v  a 2s. c o m

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) {
        from.setVisibility(View.GONE);
        to.setVisibility(View.VISIBLE);
    } else {
        // Set the content view to 0% opacity but visible, so that it is visible
        // (but fully transparent) during the animation.
        to.setAlpha(0f);
        to.setVisibility(View.VISIBLE);

        // Animate the content view to 100% opacity, and clear any animation
        // listener set on the view.
        to.animate().alpha(1f).setDuration(shortAnimationDuration).setListener(null);

        // Animate the loading view to 0% opacity. After the animation ends,
        // set its visibility to GONE as an optimization step (it won't
        // participate in layout passes, etc.)
        from.animate().alpha(0f).setDuration(shortAnimationDuration).setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                from.setVisibility(View.GONE);
            }
        });
    }
}

From source file:com.offers.couponempire.ui.BaseActivity.java

protected void onActionBarAutoShowOrHide(boolean shown) {
    if (mStatusBarColorAnimator != null) {
        mStatusBarColorAnimator.cancel();
    }/*from w ww  .j  a v  a  2s. com*/
    mStatusBarColorAnimator = ObjectAnimator
            .ofInt((mDrawerLayout != null) ? mDrawerLayout : mLPreviewUtils,
                    (mDrawerLayout != null) ? "statusBarBackgroundColor" : "statusBarColor",
                    shown ? Color.BLACK : mNormalStatusBarColor, shown ? mNormalStatusBarColor : Color.BLACK)
            .setDuration(250);
    if (mDrawerLayout != null) {
        mStatusBarColorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                ViewCompat.postInvalidateOnAnimation(mDrawerLayout);
            }
        });
    }
    mStatusBarColorAnimator.setEvaluator(ARGB_EVALUATOR);
    mStatusBarColorAnimator.start();

    for (View view : mHideableHeaderViews) {
        if (shown) {
            view.animate().translationY(0).alpha(1).setDuration(HEADER_HIDE_ANIM_DURATION)
                    .setInterpolator(new DecelerateInterpolator());
        } else {
            view.animate().translationY(-view.getBottom()).alpha(0).setDuration(HEADER_HIDE_ANIM_DURATION)
                    .setInterpolator(new DecelerateInterpolator());
        }
    }
}

From source file:com.nononsenseapps.feeder.ui.BaseActivity.java

protected void onActionBarAutoShowOrHide(boolean shown) {
    if (mStatusBarColorAnimator != null) {
        mStatusBarColorAnimator.cancel();
    }//from   w w w  . j a  v a2 s  .  c o m
    mStatusBarColorAnimator = ObjectAnimator
            .ofInt(mLPreviewUtils, "statusBarColor", shown ? mThemedStatusBarColor : Color.BLACK)
            .setDuration(250);
    mStatusBarColorAnimator.setEvaluator(ARGB_EVALUATOR);
    mStatusBarColorAnimator.start();

    for (View view : mHideableHeaderViews) {
        if (shown) {
            view.animate().translationY(0).alpha(1).setDuration(HEADER_HIDE_ANIM_DURATION)
                    .setInterpolator(new DecelerateInterpolator());
        } else {
            view.animate().translationY(-view.getBottom()).alpha(0).setDuration(HEADER_HIDE_ANIM_DURATION)
                    .setInterpolator(new DecelerateInterpolator());
        }
    }
    for (View view : mHideableFooterViews) {
        if (shown) {
            view.animate().translationY(0).alpha(1).setDuration(HEADER_HIDE_ANIM_DURATION)
                    .setInterpolator(new DecelerateInterpolator());
        } else {
            view.animate().translationY(view.getHeight()).alpha(0).setDuration(HEADER_HIDE_ANIM_DURATION)
                    .setInterpolator(new DecelerateInterpolator());
        }
    }
}

From source file:fr.shywim.antoinedaniel.ui.fragment.SoundPagerFragment.java

private void openFab(View fab) {
    if (mFabIsOpen)
        return;/*  w  w w .jav a 2s. co m*/
    mFabIsOpen = true;

    ImageView icSettings = (ImageView) fab.findViewById(R.id.fab_settings_icon);
    ImageView icClose = (ImageView) fab.findViewById(R.id.fab_settings_icon_close);
    View root = (View) fab.getParent();
    View fabMiniLoop = root.findViewById(R.id.fab_mini_loop);
    View fabMiniLoopHint = root.findViewById(R.id.fab_mini_loop_hint);
    View fabMiniDownloaded = root.findViewById(R.id.fab_mini_downloaded);
    View fabMiniDownloadedHint = root.findViewById(R.id.fab_mini_downloaded_hint);

    icSettings.animate().rotation(360).alpha(0).setDuration(250);
    icClose.animate().rotation(360).alpha(1).setDuration(250);
    fabMiniLoop.clearAnimation();
    ((View) fabMiniLoop.getParent()).setVisibility(View.VISIBLE);
    fabMiniLoop.animate().scaleX(1).scaleY(1).setListener(null).setDuration(150);
    fabMiniLoopHint.animate().alpha(1).setDuration(150);
    fabMiniDownloaded.clearAnimation();
    ((View) fabMiniDownloaded.getParent()).setVisibility(View.VISIBLE);
    fabMiniDownloaded.animate().scaleX(1).scaleY(1).setListener(null).setStartDelay(100).setDuration(150);
    fabMiniDownloadedHint.animate().alpha(1).setStartDelay(100).setDuration(150);

    if (PrefUtils.getShowOnlyDownloaded(mActivity)) {
        setFabMiniChecked(fabMiniDownloaded);
    } else {
        setFabMiniUnchecked(fabMiniDownloaded);
    }

    if (SoundUtils.isLoopingSet()) {
        setFabMiniChecked(fabMiniLoop);
    } else {
        setFabMiniUnchecked(fabMiniLoop);
    }
}

From source file:com.androzic.MapList.java

@SuppressLint("NewApi")
private void crossfade(boolean direct) {
    View listView = adapter.getCount() > 0 ? getListView() : getListView().getEmptyView();
    final View from = direct ? progressBar : listView;
    final View to = direct ? listView : progressBar;

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) {
        from.setVisibility(View.GONE);
        to.setVisibility(View.VISIBLE);
    } else {/*w w w .  ja v a2s  .  c  om*/
        // Set the content view to 0% opacity but visible, so that it is visible
        // (but fully transparent) during the animation.
        to.setAlpha(0f);
        to.setVisibility(View.VISIBLE);

        // Animate the content view to 100% opacity, and clear any animation
        // listener set on the view.
        to.animate().alpha(1f).setDuration(shortAnimationDuration).setListener(null);

        // Animate the loading view to 0% opacity. After the animation ends,
        // set its visibility to GONE as an optimization step (it won't
        // participate in layout passes, etc.)
        from.animate().alpha(0f).setDuration(shortAnimationDuration).setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                from.setVisibility(View.GONE);
            }
        });
    }
}

From source file:com.google.android.apps.muzei.settings.ChooseSourceFragment.java

private void animateSettingsButton(final View settingsButton, final boolean show, boolean allowAnimate) {
    if ((show && settingsButton.getVisibility() == View.VISIBLE)
            || (!show && settingsButton.getVisibility() == View.INVISIBLE)) {
        return;//  w ww . j  av  a 2 s.c  o  m
    }
    settingsButton.setVisibility(View.VISIBLE);
    settingsButton.animate()
            .translationY(show ? 0
                    : (-getResources().getDimensionPixelSize(
                            R.dimen.settings_choose_source_settings_button_animate_distance)))
            .alpha(show ? 1f : 0f).rotation(show ? 0 : -90).setDuration(allowAnimate ? 300 : 0)
            .setStartDelay((show && allowAnimate) ? 200 : 0).withLayer().withEndAction(new Runnable() {
                @Override
                public void run() {
                    if (!show) {
                        settingsButton.setVisibility(View.INVISIBLE);
                    }
                }
            });
}

From source file:edward.com.recyclerview.BaseItemAnimator.java

private void animateChangeImpl(final ChangeInfo changeInfo) {
    final ViewHolder holder = changeInfo.oldHolder;
    final View view = holder == null ? null : holder.itemView;
    final ViewHolder newHolder = changeInfo.newHolder;
    final View newView = newHolder != null ? newHolder.itemView : null;
    if (view != null) {
        mChangeAnimations.add(changeInfo.oldHolder);
        final ViewPropertyAnimator oldViewAnim = view.animate().setDuration(getChangeDuration());
        oldViewAnim.translationX(changeInfo.toX - changeInfo.fromX);
        oldViewAnim.translationY(changeInfo.toY - changeInfo.fromY);
        oldViewAnim.alpha(0).setListener(new VpaListenerAdapter() {
            @Override//  w w w. j a  v  a  2s . com
            public void onAnimationStart(Animator animation) {
                dispatchChangeStarting(changeInfo.oldHolder, true);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                View mView = view;
                if (animation instanceof ObjectAnimator) {
                    mView = (View) ((ObjectAnimator) animation).getTarget();
                }
                oldViewAnim.setListener(null);
                mView.setAlpha(1);
                mView.setTranslationX(0);
                mView.setTranslationY(0);
                dispatchChangeFinished(changeInfo.oldHolder, true);
                mChangeAnimations.remove(changeInfo.oldHolder);
                dispatchFinishedWhenDone();
            }
        }).start();
    }
    if (newView != null) {
        mChangeAnimations.add(changeInfo.newHolder);
        final ViewPropertyAnimator newViewAnimation = newView.animate();
        newViewAnimation.translationX(0).translationY(0).setDuration(getChangeDuration()).alpha(1)
                .setListener(new VpaListenerAdapter() {
                    @Override
                    public void onAnimationStart(Animator view) {
                        dispatchChangeStarting(changeInfo.newHolder, false);
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        newViewAnimation.setListener(null);
                        newView.setAlpha(1);
                        newView.setTranslationX(0);
                        newView.setTranslationY(0);
                        dispatchChangeFinished(changeInfo.newHolder, false);
                        mChangeAnimations.remove(changeInfo.newHolder);
                        dispatchFinishedWhenDone();
                    }
                }).start();
    }
}

From source file:io.plaidapp.ui.DribbbleShot.java

private void viewEnterAnimation(View view, float offset, Interpolator interp) {
    view.setTranslationY(offset);/*  w w  w . ja v  a2 s  .c o m*/
    view.setAlpha(0.8f);
    view.animate().translationY(0f).alpha(1f).setDuration(600).setInterpolator(interp).setListener(null)
            .start();
}

From source file:com.tmall.wireless.tangram3.dataparser.concrete.Card.java

@Nullable
public final LayoutHelper getLayoutHelper() {

    LayoutHelper helper = convertLayoutHelper(mLayoutHelper);

    // bind style to helper
    if (style != null && helper != null) {
        helper.setZIndex(style.zIndex);//from   w ww.  j  av  a2s.co m

        if (helper instanceof BaseLayoutHelper) {
            BaseLayoutHelper baseHelper = (BaseLayoutHelper) helper;
            baseHelper.setBgColor(style.bgColor);
            if (!TextUtils.isEmpty(style.bgImgUrl)) {
                if (serviceManager != null && serviceManager.getService(CardSupport.class) != null) {
                    final CardSupport support = serviceManager.getService(CardSupport.class);
                    baseHelper.setLayoutViewBindListener(new BindListener(style) {
                        @Override
                        public void onBind(View layoutView, BaseLayoutHelper baseLayoutHelper) {
                            support.onBindBackgroundView(layoutView, Card.this);
                        }
                    });
                    baseHelper.setLayoutViewUnBindListener(new UnbindListener(style) {
                        @Override
                        public void onUnbind(View layoutView, BaseLayoutHelper baseLayoutHelper) {
                            support.onUnbindBackgroundView(layoutView, Card.this);
                        }
                    });
                } else {
                    baseHelper.setLayoutViewBindListener(new BindListener(style));
                    baseHelper.setLayoutViewUnBindListener(new UnbindListener(style));
                }
            } else {
                baseHelper.setLayoutViewBindListener(null);
                baseHelper.setLayoutViewUnBindListener(null);
            }

            if (!Float.isNaN(style.aspectRatio)) {
                // ((BaseLayoutHelper) helper).setAspectRatio(style.aspectRatio);
            }

        }

        if (helper instanceof FixAreaLayoutHelper) {
            FixAreaLayoutHelper fixHelper = (FixAreaLayoutHelper) helper;
            boolean hasCustomAnimatorHelper = false;
            if (serviceManager != null && serviceManager.getService(CardSupport.class) != null) {
                CardSupport support = serviceManager.getService(CardSupport.class);
                FixAreaLayoutHelper.FixViewAnimatorHelper viewAnimatorHelper = support
                        .onGetFixViewAppearAnimator(Card.this);
                if (viewAnimatorHelper != null) {
                    hasCustomAnimatorHelper = true;
                    fixHelper.setFixViewAnimatorHelper(viewAnimatorHelper);
                }
            }
            if (!hasCustomAnimatorHelper) {
                final int duration = style.extras != null
                        ? style.extras.getIntValue(Style.KEY_ANIMATION_DURATION)
                        : 0;
                if (duration > 0) {
                    fixHelper.setFixViewAnimatorHelper(new FixAreaLayoutHelper.FixViewAnimatorHelper() {
                        @Override
                        public ViewPropertyAnimator onGetFixViewAppearAnimator(View fixView) {
                            int height = fixView.getMeasuredHeight();
                            fixView.setTranslationY(-height);
                            return fixView.animate().translationYBy(height).setDuration(duration);
                        }

                        @Override
                        public ViewPropertyAnimator onGetFixViewDisappearAnimator(View fixView) {
                            int height = fixView.getMeasuredHeight();
                            return fixView.animate().translationYBy(-height).setDuration(duration);
                        }
                    });
                }
            }
        }

        if (helper instanceof MarginLayoutHelper) {
            ((MarginLayoutHelper) helper).setMargin(style.margin[Style.MARGIN_LEFT_INDEX],
                    style.margin[Style.MARGIN_TOP_INDEX], style.margin[Style.MARGIN_RIGHT_INDEX],
                    style.margin[Style.MARGIN_BOTTOM_INDEX]);
            ((MarginLayoutHelper) helper).setPadding(style.padding[Style.MARGIN_LEFT_INDEX],
                    style.padding[Style.MARGIN_TOP_INDEX], style.padding[Style.MARGIN_RIGHT_INDEX],
                    style.padding[Style.MARGIN_BOTTOM_INDEX]);
        }
    }

    if (mRetainLayout) {
        mLayoutHelper = helper;
    }

    return helper;
}