Example usage for android.animation ObjectAnimator addListener

List of usage examples for android.animation ObjectAnimator addListener

Introduction

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

Prototype

public void addListener(AnimatorListener listener) 

Source Link

Document

Adds a listener to the set of listeners that are sent events through the life of an animation, such as start, repeat, and end.

Usage

From source file:android.support.transition.FadePort.java

/**
 * Utility method to handle creating and running the Animator.
 *//*from ww w .java  2  s  .  c om*/
private Animator createAnimation(View view, float startAlpha, float endAlpha,
        AnimatorListenerAdapter listener) {
    if (startAlpha == endAlpha) {
        // run listener if we're noop'ing the animation, to get the end-state results now
        if (listener != null) {
            listener.onAnimationEnd(null);
        }
        return null;
    }
    final ObjectAnimator anim = ObjectAnimator.ofFloat(view, "alpha", startAlpha, endAlpha);
    if (DBG) {
        Log.d(LOG_TAG, "Created animator " + anim);
    }
    if (listener != null) {
        anim.addListener(listener);
    }
    return anim;
}

From source file:org.namelessrom.devicecontrol.modules.appmanager.BaseAppListFragment.java

public void loadApps(final boolean animate) {
    if (mIsLoading) {
        return;/* w w w .  j av  a 2s  .  com*/
    }

    mIsLoading = true;
    mProgressContainer.post(new Runnable() {
        @Override
        public void run() {
            mProgressContainer.setVisibility(View.VISIBLE);

            if (animate) {
                final ObjectAnimator anim = ObjectAnimator.ofFloat(mProgressContainer, "alpha", 0f, 1f);
                anim.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        new LoadApps().execute();
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {
                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {
                    }
                });
                anim.setDuration(ANIM_DURATION);
                anim.start();
            } else {
                mProgressContainer.setAlpha(1f);
                new LoadApps().execute();
            }
        }
    });
}

From source file:com.commonsware.cwac.cam2.support.CameraFragment.java

private void changeMenuIconAnimation(final FloatingActionMenu menu) {
    AnimatorSet set = new AnimatorSet();
    final ImageView v = menu.getMenuIconView();
    ObjectAnimator scaleOutX = ObjectAnimator.ofFloat(v, "scaleX", 1.0f, 0.2f);
    ObjectAnimator scaleOutY = ObjectAnimator.ofFloat(v, "scaleY", 1.0f, 0.2f);
    ObjectAnimator scaleInX = ObjectAnimator.ofFloat(v, "scaleX", 0.2f, 1.0f);
    ObjectAnimator scaleInY = ObjectAnimator.ofFloat(v, "scaleY", 0.2f, 1.0f);

    scaleOutX.setDuration(50);//from  w ww.j  a  v  a 2s .  co  m
    scaleOutY.setDuration(50);

    scaleInX.setDuration(150);
    scaleInY.setDuration(150);
    scaleInX.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            v.setImageResource(
                    menu.isOpened() ? R.drawable.cwac_cam2_ic_close : R.drawable.cwac_cam2_ic_action_settings);
        }
    });

    set.play(scaleOutX).with(scaleOutY);
    set.play(scaleInX).with(scaleInY).after(scaleOutX);
    set.setInterpolator(new OvershootInterpolator(2));
    menu.setIconToggleAnimatorSet(set);
}

From source file:com.hannesdorfmann.home.filter.FilterAdapter.java

@Override
public FilterViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
    final FilterViewHolder holder = new FilterViewHolder(
            LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.filter_item, viewGroup, false));

    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override/*  w w  w.j  a v  a  2 s.c  om*/
        public void onClick(View v) {
            final int position = holder.getAdapterPosition();
            if (position == RecyclerView.NO_POSITION)
                return;

            final SourceFilterPresentationModel filter = filters.get(position);
            holder.itemView.setHasTransientState(true);
            ObjectAnimator fade = ObjectAnimator.ofInt(holder.filterIcon, ViewUtils.IMAGE_ALPHA,
                    filter.getEnabled() ? FILTER_ICON_DISABLED_ALPHA : FILTER_ICON_ENABLED_ALPHA);
            fade.setDuration(300);
            fade.setInterpolator(AnimationUtils.loadInterpolator(holder.itemView.getContext(),
                    android.R.interpolator.fast_out_slow_in));
            fade.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    holder.itemView.setHasTransientState(false);
                    clickedListener.onSourceFilterClicked(filter);
                }
            });
            fade.start();
        }
    });
    return holder;
}

From source file:com.android.messaging.ui.conversationlist.ConversationListSwipeHelper.java

/**
 * Animate the bounce back of the given item.
 *//*from   w  w w . jav  a  2s .co m*/
private void animateRestore(final ConversationListItemView itemView, final float velocityX) {
    onSwipeAnimationStart(itemView);

    final float translationX = itemView.getSwipeTranslationX();
    final long duration;
    if (velocityX != 0 // Has velocity.
            && velocityX > 0 != translationX > 0) { // Right direction.
        duration = calculateTranslationDuration(translationX, velocityX);
    } else {
        duration = mDefaultRestoreAnimationDuration;
    }
    final ObjectAnimator animator = getSwipeTranslationXAnimator(itemView, 0f, duration,
            UiUtils.DEFAULT_INTERPOLATOR);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(final Animator animation) {
            onSwipeAnimationEnd(itemView);
        }
    });
    animator.start();
}

From source file:com.android.messaging.ui.conversationlist.ConversationListSwipeHelper.java

/**
 * Animate the dismissal of the given item.
 *///w  w  w  .j  a  v  a2s . c o m
private void animateDismiss(final ConversationListItemView itemView, final int swipeDirection,
        final float velocityX) {
    Assert.isTrue(swipeDirection != SWIPE_DIRECTION_NONE);

    onSwipeAnimationStart(itemView);

    final float animateTo = (swipeDirection == SWIPE_DIRECTION_RIGHT) ? mRecyclerView.getWidth()
            : -mRecyclerView.getWidth();
    final long duration;
    if (velocityX != 0) {
        final float deltaX = animateTo - itemView.getSwipeTranslationX();
        duration = calculateTranslationDuration(deltaX, velocityX);
    } else {
        duration = mDefaultDismissAnimationDuration;
    }

    final ObjectAnimator animator = getSwipeTranslationXAnimator(itemView, animateTo, duration,
            UiUtils.DEFAULT_INTERPOLATOR);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(final Animator animation) {
            onSwipeAnimationEnd(itemView);
        }
    });
    animator.start();
}

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

private void toggleDownLoadToolbar(final View view) {
    // API 11//w w  w  .  j  a  va  2s  . 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:me.hammarstrom.imagerecognition.activities.MainActivity.java

/**
 * Helper method to show / hide progress bar
 *
 * @param show if progress should be shown or not
 *///from  w  w w  .j a  v a  2 s .  co  m
private void showLoading(final boolean show) {
    ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mLoadingLayout, "alpha", show ? 0f : 1f,
            show ? 1f : 0f);
    alphaAnimator.setDuration(200);
    alphaAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            if (!show) {
                mLoadingLayout.setVisibility(View.GONE);
            }
        }

        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
            if (show) {
                mLoadingLayout.setAlpha(0f);
                mLoadingLayout.setVisibility(View.VISIBLE);
                mTts.speak(getString(R.string.tts_processing_image), TextToSpeech.QUEUE_FLUSH, null);
            }
        }
    });
    alphaAnimator.start();
}

From source file:com.github.jokar.rxupload.widget.ProgressDownloadView.java

public void drawSuccess() {
    mTarget = 100;//from w w w. j av  a  2 s  .c o  m

    final ObjectAnimator successAnim = ObjectAnimator.ofFloat(this, "flip", 1, -1);
    successAnim.setInterpolator(new OvershootInterpolator());
    successAnim.setDuration(ANIMATION_DURATION_BASE);

    ObjectAnimator anim = ObjectAnimator.ofFloat(this, "progress", getProgress(), mTarget);
    anim.setInterpolator(new DecelerateInterpolator());
    anim.setDuration((long) (ANIMATION_DURATION_BASE + Math.abs(mTarget * 10 - getProgress() * 10) / 2));
    anim.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {

        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mState = State.STATE_SUCCESS;
            successAnim.start();
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });
    anim.start();
}

From source file:ch.gianulli.flashcards.ui.Flashcard.java

public void turnCard() {
    if (mPreviousAnimation != null) {
        mPreviousAnimation.cancel();//ww  w . j ava  2s .c om
        mPreviousAnimation = null;
    }

    AnimatorSet set = new AnimatorSet();

    mQuestion.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    mAnswer.setLayerType(View.LAYER_TYPE_HARDWARE, null);

    if (mQuestionShowing) {
        mQuestionShowing = false;

        mQuestion.setVisibility(View.VISIBLE);
        mQuestion.setAlpha(1.0f);
        mAnswer.setVisibility(View.VISIBLE);
        mAnswer.setAlpha(0.0f);

        ObjectAnimator questionAnim = ObjectAnimator.ofFloat(mQuestion, "alpha", 1.0f, 0.0f);
        questionAnim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mQuestion.setVisibility(View.GONE);
            }
        });

        ObjectAnimator answerAnim = ObjectAnimator.ofFloat(mAnswer, "alpha", 0.0f, 1.0f);

        set.playTogether(questionAnim, answerAnim);

        // Show button bar if necessary
        if (!mButtonBarShowing) {
            expandButtonBar();
        }
    } else {
        mQuestionShowing = true;

        mQuestion.setVisibility(View.VISIBLE);
        mQuestion.setAlpha(0.0f);
        mAnswer.setVisibility(View.VISIBLE);
        mAnswer.setAlpha(1.0f);

        ObjectAnimator questionAnim = ObjectAnimator.ofFloat(mQuestion, "alpha", 0.0f, 1.0f);

        ObjectAnimator answerAnim = ObjectAnimator.ofFloat(mAnswer, "alpha", 1.0f, 0.0f);
        answerAnim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mAnswer.setVisibility(View.GONE);
            }
        });

        set.playTogether(questionAnim, answerAnim);
    }

    set.setDuration(400);

    mPreviousAnimation = set;

    set.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mQuestion.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
            mAnswer.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
            mPreviousAnimation = null;
        }
    });

    set.start();
}