Example usage for android.animation Animator setTarget

List of usage examples for android.animation Animator setTarget

Introduction

In this page you can find the example usage for android.animation Animator setTarget.

Prototype

public void setTarget(@Nullable Object target) 

Source Link

Document

Sets the target object whose property will be animated by this animation.

Usage

From source file:despotoski.nikola.github.com.bottomnavigationlayout.BottomTabLayout.java

/**
 * @param position        Position of the bottom tab to be removed (0 based)
 * @param removeAnimation Animation to be perfomed before tab being removed from its container
 *///w  w  w .jav  a  2 s. com
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void removeTabAt(final int position, @NonNull Animator removeAnimation) {
    ensureListenersList();
    final View removedTab = mBottomTabViews.remove(position);
    if (removedTab != null) {
        removeAnimation.setTarget(removedTab);
        removeAnimation.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                removeTabInternal(removedTab, position);
            }
        });
        removeAnimation.start();
    }
}

From source file:android.support.v17.leanback.app.OnboardingSupportFragment.java

private void startEnterAnimation() {
    mEnterTransitionFinished = true;// w  ww. j  a  va 2  s. c  o m
    initializeViews(getView());
    List<Animator> animators = new ArrayList<>();
    Animator animator = AnimatorInflater.loadAnimator(getActivity(),
            R.animator.lb_onboarding_page_indicator_enter);
    animator.setTarget(getPageCount() <= 1 ? mStartButton : mPageIndicator);
    animators.add(animator);
    // Header title
    View view = getActivity().findViewById(R.id.title);
    view.setAlpha(0);
    animator = AnimatorInflater.loadAnimator(getActivity(), R.animator.lb_onboarding_title_enter);
    animator.setStartDelay(START_DELAY_TITLE_MS);
    animator.setTarget(view);
    animators.add(animator);
    // Header description
    view = getActivity().findViewById(R.id.description);
    view.setAlpha(0);
    animator = AnimatorInflater.loadAnimator(getActivity(), R.animator.lb_onboarding_description_enter);
    animator.setStartDelay(START_DELAY_DESCRIPTION_MS);
    animator.setTarget(view);
    animators.add(animator);
    // Customized animation by the inherited class.
    Animator customAnimator = onCreateEnterAnimation();
    if (customAnimator != null) {
        animators.add(customAnimator);
    }
    mAnimator = new AnimatorSet();
    mAnimator.playTogether(animators);
    mAnimator.start();
    // Search focus and give the focus to the appropriate child which has become visible.
    getView().requestFocus();
}

From source file:com.rbware.github.androidcouchpotato.app.OnboardingSupportFragment.java

void startEnterAnimation() {
    mEnterTransitionFinished = true;/*w ww  .  j  a va 2 s .  c o m*/
    initializeViews(getView());
    List<Animator> animators = new ArrayList<>();
    Animator animator = AnimatorInflater.loadAnimator(getActivity(),
            R.animator.lb_onboarding_page_indicator_enter);
    animator.setTarget(getPageCount() <= 1 ? mStartButton : mPageIndicator);
    animators.add(animator);
    // Header title
    View view = getActivity().findViewById(R.id.title);
    view.setAlpha(0);
    animator = AnimatorInflater.loadAnimator(getActivity(), R.animator.lb_onboarding_title_enter);
    animator.setStartDelay(START_DELAY_TITLE_MS);
    animator.setTarget(view);
    animators.add(animator);
    // Header description
    view = getActivity().findViewById(R.id.description);
    view.setAlpha(0);
    animator = AnimatorInflater.loadAnimator(getActivity(), R.animator.lb_onboarding_description_enter);
    animator.setStartDelay(START_DELAY_DESCRIPTION_MS);
    animator.setTarget(view);
    animators.add(animator);
    // Customized animation by the inherited class.
    Animator customAnimator = onCreateEnterAnimation();
    if (customAnimator != null) {
        animators.add(customAnimator);
    }
    mAnimator = new AnimatorSet();
    mAnimator.playTogether(animators);
    mAnimator.start();
    // Search focus and give the focus to the appropriate child which has become visible.
    getView().requestFocus();
}

From source file:android.support.v17.leanback.app.OnboardingSupportFragment.java

/**
 * Called when the page changes./*  w w  w  .  j av a2 s.  c o  m*/
 */
private void onPageChangedInternal(int previousPage) {
    if (mAnimator != null) {
        mAnimator.end();
    }
    mPageIndicator.onPageSelected(mCurrentPageIndex, true);

    List<Animator> animators = new ArrayList<>();
    // Header animation
    Animator fadeAnimator = null;
    if (previousPage < getCurrentPageIndex()) {
        // sliding to left
        animators.add(createAnimator(mTitleView, false, Gravity.START, 0));
        animators.add(fadeAnimator = createAnimator(mDescriptionView, false, Gravity.START,
                DESCRIPTION_START_DELAY_MS));
        animators.add(createAnimator(mTitleView, true, Gravity.END, HEADER_APPEAR_DELAY_MS));
        animators.add(createAnimator(mDescriptionView, true, Gravity.END,
                HEADER_APPEAR_DELAY_MS + DESCRIPTION_START_DELAY_MS));
    } else {
        // sliding to right
        animators.add(createAnimator(mTitleView, false, Gravity.END, 0));
        animators.add(fadeAnimator = createAnimator(mDescriptionView, false, Gravity.END,
                DESCRIPTION_START_DELAY_MS));
        animators.add(createAnimator(mTitleView, true, Gravity.START, HEADER_APPEAR_DELAY_MS));
        animators.add(createAnimator(mDescriptionView, true, Gravity.START,
                HEADER_APPEAR_DELAY_MS + DESCRIPTION_START_DELAY_MS));
    }
    final int currentPageIndex = getCurrentPageIndex();
    fadeAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mTitleView.setText(getPageTitle(currentPageIndex));
            mDescriptionView.setText(getPageDescription(currentPageIndex));
        }
    });

    // Animator for switching between page indicator and button.
    if (getCurrentPageIndex() == getPageCount() - 1) {
        mStartButton.setVisibility(View.VISIBLE);
        Animator navigatorFadeOutAnimator = AnimatorInflater.loadAnimator(getActivity(),
                R.animator.lb_onboarding_page_indicator_fade_out);
        navigatorFadeOutAnimator.setTarget(mPageIndicator);
        navigatorFadeOutAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mPageIndicator.setVisibility(View.GONE);
            }
        });
        animators.add(navigatorFadeOutAnimator);
        Animator buttonFadeInAnimator = AnimatorInflater.loadAnimator(getActivity(),
                R.animator.lb_onboarding_start_button_fade_in);
        buttonFadeInAnimator.setTarget(mStartButton);
        animators.add(buttonFadeInAnimator);
    } else if (previousPage == getPageCount() - 1) {
        mPageIndicator.setVisibility(View.VISIBLE);
        Animator navigatorFadeInAnimator = AnimatorInflater.loadAnimator(getActivity(),
                R.animator.lb_onboarding_page_indicator_fade_in);
        navigatorFadeInAnimator.setTarget(mPageIndicator);
        animators.add(navigatorFadeInAnimator);
        Animator buttonFadeOutAnimator = AnimatorInflater.loadAnimator(getActivity(),
                R.animator.lb_onboarding_start_button_fade_out);
        buttonFadeOutAnimator.setTarget(mStartButton);
        buttonFadeOutAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mStartButton.setVisibility(View.GONE);
            }
        });
        animators.add(buttonFadeOutAnimator);
    }
    mAnimator = new AnimatorSet();
    mAnimator.playTogether(animators);
    mAnimator.start();
    onPageChanged(mCurrentPageIndex, previousPage);
}

From source file:com.sinyuk.jianyimaterial.widgets.FloatingToolbar.java

@TargetApi(21)
private void hideLollipopImpl() {
    int rootWidth = mRoot.getWidth();

    float controlX;

    if (mFabOriginalX > rootWidth / 2f) {
        controlX = mFabOriginalX * 0.98f;
    } else {//from   w ww. j  a v a2s  . co  m
        controlX = mFabOriginalX * 1.02f;
    }

    final Path path = new Path();
    path.moveTo(mFab.getX(), mFab.getY());
    final float x2 = controlX;
    final float y2 = getY();
    path.quadTo(x2, y2, mFabOriginalX, mFabOriginalY + getTranslationY());
    ObjectAnimator anim = ObjectAnimator.ofFloat(mFab, View.X, View.Y, path);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_UNMORPH_DURATION);
    anim.setStartDelay(FAB_UNMORPH_DELAY);
    anim.start();

    /**
     * Animate FAB elevation back to 6dp
     */
    anim = ObjectAnimator.ofFloat(mFab, View.TRANSLATION_Z, 0);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_UNMORPH_DURATION);
    anim.setStartDelay(FAB_UNMORPH_DELAY);
    anim.start();

    /**
     * Restore alpha of FAB drawable
     */
    Drawable drawable = mFab.getDrawable();
    if (drawable != null) {
        anim = ObjectAnimator.ofPropertyValuesHolder(drawable, PropertyValuesHolder.ofInt("alpha", 255));
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.setDuration(FAB_UNMORPH_DURATION);
        anim.setStartDelay(FAB_UNMORPH_DELAY);
        anim.start();
    }

    Animator toolbarReveal = ViewAnimationUtils.createCircularReveal(this, getWidth() / 2, getHeight() / 2,
            (float) (Math.hypot(getWidth() / 2, getHeight() / 2)), (float) mFab.getWidth() / 2f);

    toolbarReveal.setTarget(this);
    toolbarReveal.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            setVisibility(View.INVISIBLE);
            mFab.setVisibility(View.VISIBLE);
            mMorphing = false;
        }
    });
    toolbarReveal.setDuration(CIRCULAR_UNREVEAL_DURATION);
    toolbarReveal.setInterpolator(new AccelerateInterpolator());
    toolbarReveal.setStartDelay(CIRCULAR_UNREVEAL_DELAY);
    toolbarReveal.start();

    /**
     * Animate FloatingToolbar animation back to 6dp
     */
    anim = ObjectAnimator.ofFloat(this, View.TRANSLATION_Z, 0);
    anim.setDuration(CIRCULAR_UNREVEAL_DURATION);
    anim.setStartDelay(CIRCULAR_UNREVEAL_DELAY);
    anim.start();
}

From source file:com.sinyuk.jianyimaterial.widgets.FloatingToolbar.java

@TargetApi(21)
private void showLollipopImpl() {
    int rootWidth = mRoot.getWidth();

    float endFabX;
    float controlX;

    if (mFabOriginalX > rootWidth / 2f) {
        endFabX = rootWidth / 2f + (mFabOriginalX - rootWidth / 2f) / 4f;
        controlX = mFabOriginalX * 0.98f;
    } else {// w w w  .  ja  v a 2  s  . com
        endFabX = rootWidth / 2f - (mFabOriginalX - rootWidth / 2f) / 4f;
        controlX = mFabOriginalX * 1.02f;
    }

    /**
     * Animate FAB movement
     */
    final Path path = new Path();
    path.moveTo(mFab.getX(), mFab.getY());
    final float x2 = controlX;
    final float y2 = getY();
    path.quadTo(x2, y2, endFabX, getY());
    ObjectAnimator anim = ObjectAnimator.ofFloat(mFab, View.X, View.Y, path);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_MORPH_DURATION);
    anim.start();

    /**
     * Fade FAB drawable
     */
    Drawable drawable = mFab.getDrawable();
    if (drawable != null) {
        anim = ObjectAnimator.ofPropertyValuesHolder(drawable, PropertyValuesHolder.ofInt("alpha", 0));
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.setDuration((long) (FAB_MORPH_DURATION / 3f));
        anim.start();
    }

    /**
     * Animate FAB elevation to 8dp
     */
    anim = ObjectAnimator.ofFloat(mFab, View.TRANSLATION_Z, dpToPixels(2));
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_MORPH_DURATION);
    anim.start();

    /**
     * Create circular reveal
     */
    Animator toolbarReveal = ViewAnimationUtils.createCircularReveal(this, getWidth() / 2, getHeight() / 2,
            (float) mFab.getWidth() / 2f, (float) (Math.hypot(getWidth() / 2, getHeight() / 2)));

    toolbarReveal.setDuration(CIRCULAR_REVEAL_DURATION);
    toolbarReveal.setTarget(this);
    toolbarReveal.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
            mFab.setVisibility(View.INVISIBLE);
            setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            mMorphing = false;
        }
    });

    toolbarReveal.setInterpolator(new AccelerateInterpolator());
    toolbarReveal.setStartDelay(CIRCULAR_REVEAL_DELAY);
    toolbarReveal.start();

    /**
     * Animate FloatingToolbar elevation to 8dp
     */
    anim = ObjectAnimator.ofFloat(this, View.TRANSLATION_Z, dpToPixels(2));
    anim.setDuration(CIRCULAR_REVEAL_DURATION);
    anim.setStartDelay(CIRCULAR_REVEAL_DELAY);
    anim.start();
}

From source file:com.android.tv.settings.dialog.DialogFragment.java

private Animator createAnimator(View v, int resourceId) {
    Animator animator = AnimatorInflater.loadAnimator(v.getContext(), resourceId);
    animator.setTarget(v);
    return animator;
}

From source file:android.support.v17.leanback.app.OnboardingSupportFragment.java

private Animator createAnimator(View view, boolean fadeIn, int slideDirection, long startDelay) {
    boolean isLtr = getView().getLayoutDirection() == View.LAYOUT_DIRECTION_LTR;
    boolean slideRight = (isLtr && slideDirection == Gravity.END) || (!isLtr && slideDirection == Gravity.START)
            || slideDirection == Gravity.RIGHT;
    Animator fadeAnimator;
    Animator slideAnimator;/*from   w  w w  . jav  a 2  s. c  o  m*/
    if (fadeIn) {
        fadeAnimator = ObjectAnimator.ofFloat(view, View.ALPHA, 0.0f, 1.0f);
        slideAnimator = ObjectAnimator.ofFloat(view, View.TRANSLATION_X,
                slideRight ? sSlideDistance : -sSlideDistance, 0);
        fadeAnimator.setInterpolator(HEADER_APPEAR_INTERPOLATOR);
        slideAnimator.setInterpolator(HEADER_APPEAR_INTERPOLATOR);
    } else {
        fadeAnimator = ObjectAnimator.ofFloat(view, View.ALPHA, 1.0f, 0.0f);
        slideAnimator = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, 0,
                slideRight ? sSlideDistance : -sSlideDistance);
        fadeAnimator.setInterpolator(HEADER_DISAPPEAR_INTERPOLATOR);
        slideAnimator.setInterpolator(HEADER_DISAPPEAR_INTERPOLATOR);
    }
    fadeAnimator.setDuration(HEADER_ANIMATION_DURATION_MS);
    fadeAnimator.setTarget(view);
    slideAnimator.setDuration(HEADER_ANIMATION_DURATION_MS);
    slideAnimator.setTarget(view);
    AnimatorSet animator = new AnimatorSet();
    animator.playTogether(fadeAnimator, slideAnimator);
    if (startDelay > 0) {
        animator.setStartDelay(startDelay);
    }
    return animator;
}

From source file:com.stanleyidesis.quotograph.ui.activity.LWQSettingsActivity.java

void animateAction(final View button) {
    runOnUiThread(new Runnable() {
        @Override/*www  .ja  v  a 2  s  . co  m*/
        public void run() {
            final Animator animator = AnimatorInflater.loadAnimator(LWQSettingsActivity.this,
                    R.animator.progress_rotation);
            animator.setTarget(button);
            button.setTag(R.id.view_tag_animator, animator);
            animator.start();
        }
    });
}

From source file:com.stanleyidesis.quotograph.ui.activity.LWQSettingsActivity.java

void animateContainer(final View container, final boolean dismiss) {
    container.setVisibility(View.VISIBLE);
    Animator animator = dismiss ? AnimatorInflater.loadAnimator(this, R.animator.exit_to_left)
            : AnimatorInflater.loadAnimator(this, R.animator.enter_from_right);
    animator.setTarget(container);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override//from  ww w.jav  a 2 s  .com
        public void onAnimationEnd(Animator animation) {
            if (dismiss) {
                container.setVisibility(View.GONE);
                UIUtils.dismissKeyboard(LWQSettingsActivity.this);
            } else {
                UIUtils.revealKeyboard(container == addEditQuote ? editableQuote : editableQuery);
            }
        }
    });
    animator.start();
}