Example usage for android.animation AnimatorListenerAdapter AnimatorListenerAdapter

List of usage examples for android.animation AnimatorListenerAdapter AnimatorListenerAdapter

Introduction

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

Prototype

AnimatorListenerAdapter

Source Link

Usage

From source file:com.gitstudy.rili.liarbry.CalendarLayout.java

/**
 * //from ww w. j  ava 2s . c  om
 *
 * @return ??
 */
public boolean expand() {
    if (isAnimating || mCalendarShowMode == CALENDAR_SHOW_MODE_ONLY_WEEK_VIEW || mContentView == null)
        return false;
    if (mMonthView.getVisibility() != VISIBLE) {
        mWeekPager.setVisibility(GONE);
        onShowMonthView();
        mMonthView.setVisibility(VISIBLE);
    }
    ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mContentView, "translationY",
            mContentView.getTranslationY(), 0f);
    objectAnimator.setDuration(240);
    objectAnimator.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float currentValue = (Float) animation.getAnimatedValue();
            float percent = currentValue * 1.0f / mContentViewTranslateY;
            mMonthView.setTranslationY(mViewPagerTranslateY * percent);
            isAnimating = true;
        }
    });
    objectAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            isAnimating = false;
            hideWeek();

        }
    });
    objectAnimator.start();
    return true;
}

From source file:com.android.deskclock.timer.TimerFragment.java

/**
 * @param toView one of {@link #mTimersView} or {@link #mCreateTimerView}
 * @param timerToRemove the timer to be removed during the animation; {@code null} if no timer
 *      should be removed/*www. j  a v  a 2s.  co m*/
 */
private void animateToView(View toView, final Timer timerToRemove) {
    if (mCurrentView == toView) {
        throw new IllegalStateException("toView is already the current view");
    }

    final boolean toTimers = toView == mTimersView;

    // Avoid double-taps by enabling/disabling the set of buttons active on the new view.
    mLeftButton.setEnabled(toTimers);
    mRightButton.setEnabled(toTimers);
    mCancelCreateButton.setEnabled(!toTimers);

    final Animator rotateFrom = ObjectAnimator.ofFloat(mCurrentView, SCALE_X, 1, 0);
    rotateFrom.setDuration(mShortAnimationDuration);
    rotateFrom.setInterpolator(new DecelerateInterpolator());
    rotateFrom.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (timerToRemove != null) {
                DataModel.getDataModel().removeTimer(timerToRemove);
                Events.sendTimerEvent(R.string.action_delete, R.string.label_deskclock);
            }

            mCurrentView.setScaleX(1);
            if (toTimers) {
                showTimersView();
            } else {
                showCreateTimerView();
            }
        }
    });

    final Animator rotateTo = ObjectAnimator.ofFloat(toView, SCALE_X, 0, 1);
    rotateTo.setDuration(mShortAnimationDuration);
    rotateTo.setInterpolator(new AccelerateInterpolator());

    final float preScale = toTimers ? 0 : 1;
    final float postScale = toTimers ? 1 : 0;
    final Animator fabAnimator = getScaleAnimator(mFab, preScale, postScale);
    final Animator leftButtonAnimator = getScaleAnimator(mLeftButton, preScale, postScale);
    final Animator rightButtonAnimator = getScaleAnimator(mRightButton, preScale, postScale);

    final AnimatorSet buttons = new AnimatorSet();
    buttons.setDuration(toTimers ? mMediumAnimationDuration : mShortAnimationDuration);
    buttons.play(leftButtonAnimator).with(rightButtonAnimator).with(fabAnimator);
    buttons.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mLeftButton.setVisibility(toTimers ? VISIBLE : INVISIBLE);
            mRightButton.setVisibility(toTimers ? VISIBLE : INVISIBLE);

            mFab.setScaleX(1);
            mFab.setScaleY(1);
            mLeftButton.setScaleX(1);
            mLeftButton.setScaleY(1);
            mRightButton.setScaleX(1);
            mRightButton.setScaleY(1);
        }
    });

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(rotateFrom).before(rotateTo).with(buttons);
    animatorSet.start();
}

From source file:com.android.incallui.CallCardFragment.java

/**
 * Sets the visibility of the primary call card.
 * Ensures that when the primary call card is hidden, the video surface slides over to fill the
 * entire screen.//ww w  .ja  va2  s  .c o m
 *
 * @param visible {@code True} if the primary call card should be visible.
 */
@Override
public void setCallCardVisible(final boolean visible) {
    Log.v(this, "setCallCardVisible : isVisible = " + visible);
    // When animating the hide/show of the views in a landscape layout, we need to take into
    // account whether we are in a left-to-right locale or a right-to-left locale and adjust
    // the animations accordingly.
    final boolean isLayoutRtl = InCallPresenter.isRtl();

    // Retrieve here since at fragment creation time the incoming video view is not inflated.
    final View videoView = getView().findViewById(R.id.incomingVideo);
    if (videoView == null) {
        return;
    }

    // Determine how much space there is below or to the side of the call card.
    final float spaceBesideCallCard = getSpaceBesideCallCard();

    // We need to translate the video surface, but we need to know its position after the layout
    // has occurred so use a {@code ViewTreeObserver}.
    final ViewTreeObserver observer = getView().getViewTreeObserver();
    observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            // We don't want to continue getting called.
            getView().getViewTreeObserver().removeOnPreDrawListener(this);

            float videoViewTranslation = 0f;

            // Translate the call card to its pre-animation state.
            if (!mIsLandscape) {
                mPrimaryCallCardContainer.setTranslationY(visible ? -mPrimaryCallCardContainer.getHeight() : 0);

                ViewGroup.LayoutParams p = videoView.getLayoutParams();
                videoViewTranslation = p.height / 2 - spaceBesideCallCard / 2;
            }

            // Perform animation of video view.
            ViewPropertyAnimator videoViewAnimator = videoView.animate()
                    .setInterpolator(AnimUtils.EASE_OUT_EASE_IN).setDuration(mVideoAnimationDuration);
            if (mIsLandscape) {
                videoViewAnimator.translationX(visible ? videoViewTranslation : 0);
            } else {
                videoViewAnimator.translationY(visible ? videoViewTranslation : 0);
            }
            videoViewAnimator.start();

            // Animate the call card sliding.
            ViewPropertyAnimator callCardAnimator = mPrimaryCallCardContainer.animate()
                    .setInterpolator(AnimUtils.EASE_OUT_EASE_IN).setDuration(mVideoAnimationDuration)
                    .setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            super.onAnimationEnd(animation);
                            if (!visible) {
                                mPrimaryCallCardContainer.setVisibility(View.GONE);
                            }
                        }

                        @Override
                        public void onAnimationStart(Animator animation) {
                            super.onAnimationStart(animation);
                            if (visible) {
                                mPrimaryCallCardContainer.setVisibility(View.VISIBLE);
                            }
                        }
                    });

            if (mIsLandscape) {
                float translationX = mPrimaryCallCardContainer.getWidth();
                translationX *= isLayoutRtl ? 1 : -1;
                callCardAnimator.translationX(visible ? 0 : translationX).start();
            } else {
                callCardAnimator.translationY(visible ? 0 : -mPrimaryCallCardContainer.getHeight()).start();
            }

            return true;
        }
    });
}

From source file:com.betterAlarm.deskclock.timer.TimerFragment.java

@Override
public void onFabClick(View view) {
    if (mLastView != mTimerView) {
        // Timer is at Setup View, so fab is "play", rotate from setup view to timer view
        final AnimatorListenerAdapter adapter = new AnimatorListenerAdapter() {
            @Override/*ww  w  . j  a v a 2  s .  c o  m*/
            public void onAnimationStart(Animator animation) {
                final int timerLength = mSetupView.getTime();
                final TimerObj timerObj = new TimerObj(timerLength * DateUtils.SECOND_IN_MILLIS, getActivity());
                timerObj.mState = TimerObj.STATE_RUNNING;
                updateTimerState(timerObj, Timers.START_TIMER);

                // Go to the newly created timer view
                mAdapter.addTimer(timerObj);
                mViewPager.setCurrentItem(0);
                highlightPageIndicator(0);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                mSetupView.reset(); // Make sure the setup is cleared for next time
                mSetupView.setScaleX(1.0f); // Reset the scale for setup view
                goToPagerView();
            }
        };
        createRotateAnimator(adapter, false).start();
    } else {
        // Timer is at view pager, so fab is "play" or "pause" or "square that means reset"
        final TimerObj t = getCurrentTimer();
        switch (t.mState) {
        case TimerObj.STATE_RUNNING:
            // Stop timer and save the remaining time of the timer
            t.mState = TimerObj.STATE_STOPPED;
            t.mView.pause();
            t.updateTimeLeft(true);
            updateTimerState(t, Timers.TIMER_STOP);
            break;
        case TimerObj.STATE_STOPPED:
        case TimerObj.STATE_RESTART:
            // Reset the remaining time and continue timer
            t.mState = TimerObj.STATE_RUNNING;
            t.mStartTime = Utils.getTimeNow() - (t.mOriginalLength - t.mTimeLeft);
            t.mView.start();
            updateTimerState(t, Timers.START_TIMER);
            break;
        case TimerObj.STATE_TIMESUP:
            if (t.mDeleteAfterUse) {
                cancelTimerNotification(t.mTimerId);
                // Tell receiver the timer was deleted.
                // It will stop all activity related to the
                // timer
                t.mState = TimerObj.STATE_DELETED;
                updateTimerState(t, Timers.DELETE_TIMER);
            } else {
                t.mState = TimerObj.STATE_RESTART;
                t.mOriginalLength = t.mSetupLength;
                t.mTimeLeft = t.mSetupLength;
                t.mView.stop();
                t.mView.setTime(t.mTimeLeft, false);
                t.mView.set(t.mOriginalLength, t.mTimeLeft, false);
                updateTimerState(t, Timers.TIMER_RESET);
                cancelTimerNotification(t.mTimerId);
            }
            break;
        }
        setTimerViewFabIcon(t);
    }
}

From source file:ca.taglab.PictureFrame.ScreenSlidePageFragment.java

private void messageSent(View v) {
    switch (v.getId()) {
    case R.id.video:
        mConfirmation.setImageResource(R.drawable.confirm_red);
        break;//from ww w .  java 2 s  .  c o  m

    case R.id.photo:
        mConfirmation.setImageResource(R.drawable.confirm_blue);
        break;

    case R.id.audio:
        mConfirmation.setImageResource(R.drawable.confirm_green);
        break;

    case R.id.wave:
        mConfirmation.setImageResource(R.drawable.confirm_orange);
        break;
    }

    MediaPlayer mPlayer = MediaPlayer.create(getActivity().getApplicationContext(), R.raw.success_low);
    mPlayer.start();

    mConfirmation.setAlpha(0f);
    mConfirmation.setVisibility(View.VISIBLE);
    mConfirmation.animate().alpha(1f).setDuration(mLongAnimationDuration * 2)
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    mConfirmation.animate().alpha(0f).setDuration(mLongAnimationDuration * 2)
                            .setListener(new AnimatorListenerAdapter() {
                                @Override
                                public void onAnimationEnd(Animator animation) {
                                    mConfirmation.setVisibility(View.GONE);
                                }
                            });
                }
            });

}

From source file:com.mark.quick.ui.view.snackbar.BaseTransientBottomBar.java

void animateViewIn() {
    if (Build.VERSION.SDK_INT >= 12) {
        //TODO CHANGE ?
        final int viewHeight = -mView.getHeight();
        if (USE_OFFSET_API) {
            ViewCompat.offsetTopAndBottom(mView, viewHeight);
        } else {/*from w  ww . j a v  a2 s.c om*/
            mView.setTranslationY(viewHeight);
        }

        final ValueAnimator animator = new ValueAnimator();
        animator.setIntValues(viewHeight, 0);
        animator.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
        animator.setDuration(ANIMATION_DURATION);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animator) {
                mContentViewCallback.animateContentIn(ANIMATION_DURATION - ANIMATION_FADE_DURATION,
                        ANIMATION_FADE_DURATION);
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                onViewShown();
            }
        });
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            private int mPreviousAnimatedIntValue = viewHeight;

            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                int currentAnimatedIntValue = (int) animator.getAnimatedValue();
                if (USE_OFFSET_API) {
                    ViewCompat.offsetTopAndBottom(mView, currentAnimatedIntValue - mPreviousAnimatedIntValue);
                } else {
                    mView.setTranslationY(currentAnimatedIntValue);
                }
                mPreviousAnimatedIntValue = currentAnimatedIntValue;
            }
        });
        animator.start();
    } else {
        final Animation anim = android.view.animation.AnimationUtils.loadAnimation(mView.getContext(),
                R.anim.design_snackbar_in);
        anim.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
        anim.setDuration(ANIMATION_DURATION);
        anim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationEnd(Animation animation) {
                onViewShown();
            }

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        mView.startAnimation(anim);
    }
}

From source file:com.commonsware.cwac.crossport.design.widget.BaseTransientBottomBar.java

void animateViewIn() {
    if (Build.VERSION.SDK_INT >= 12) {
        final int viewHeight = mView.getHeight();
        if (USE_OFFSET_API) {
            ViewCompat.offsetTopAndBottom(mView, viewHeight);
        } else {/*from w ww .j a  v a  2  s.  c  o  m*/
            mView.setTranslationY(viewHeight);
        }
        final ValueAnimator animator = new ValueAnimator();
        animator.setIntValues(viewHeight, 0);
        animator.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
        animator.setDuration(ANIMATION_DURATION);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animator) {
                mContentViewCallback.animateContentIn(ANIMATION_DURATION - ANIMATION_FADE_DURATION,
                        ANIMATION_FADE_DURATION);
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                onViewShown();
            }
        });
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            private int mPreviousAnimatedIntValue = viewHeight;

            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                int currentAnimatedIntValue = (int) animator.getAnimatedValue();
                if (USE_OFFSET_API) {
                    ViewCompat.offsetTopAndBottom(mView, currentAnimatedIntValue - mPreviousAnimatedIntValue);
                } else {
                    mView.setTranslationY(currentAnimatedIntValue);
                }
                mPreviousAnimatedIntValue = currentAnimatedIntValue;
            }
        });
        animator.start();
    } else {
        final Animation anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.design_snackbar_in);
        anim.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
        anim.setDuration(ANIMATION_DURATION);
        anim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationEnd(Animation animation) {
                onViewShown();
            }

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        mView.startAnimation(anim);
    }
}

From source file:com.appunite.appunitevideoplayer.PlayerActivity.java

private void toggleControlsVisibility() {
    if (mElementsHidden) {
        showControls();/*from  ww w.j  a  v  a  2  s. co m*/
    } else {
        toolbar.animate().translationY(-toolbar.getHeight()).setDuration(ANIMATION_DURATION)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        mElementsHidden = true;
                    }
                }).start();
        controllerView.animate().translationY(controllerView.getHeight()).setDuration(ANIMATION_DURATION)
                .start();
    }
}

From source file:com.jinzht.pro.swipelistview.SwipeListViewTouchListener.java

/**
 * Create reveal animation//from w  ww  .  j a  va 2s.  c o  m
 *
 * @param view      affected view
 * @param swap      If will change state. If "false" returns to the original position
 * @param swapRight If swap is true, this parameter tells if movement is toward right or left
 * @param position  list position
 */
private void generateRevealAnimate(final View view, final boolean swap, final boolean swapRight,
        final int position) {
    int moveTo = 0;
    if (opened.get(position)) {
        if (!swap) {
            moveTo = openedRight.get(position) ? (int) (viewWidth - rightOffset)
                    : (int) (-viewWidth + leftOffset);
        }
    } else {
        if (swap) {
            moveTo = swapRight ? (int) (viewWidth - rightOffset) : (int) (-viewWidth + leftOffset);
        }
    }

    view.animate().translationX(moveTo).setDuration(animationTime).setListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            swipeListView.resetScrolling();
            if (swap) {
                boolean aux = !opened.get(position);
                opened.set(position, aux);
                if (aux) {
                    swipeListView.onOpened(position, swapRight);
                    openedRight.set(position, swapRight);
                } else {
                    swipeListView.onClosed(position, openedRight.get(position));
                }
            }
            resetCell();
        }
    });
}

From source file:fr.cph.chicago.core.fragment.NearbyFragment.java

private void showProgress(final boolean show) {
    try {// www .  j  av  a2 s.  c om
        if (isAdded()) {
            int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
            loadLayout.setVisibility(View.VISIBLE);
            loadLayout.animate().setDuration(shortAnimTime).alpha(show ? 1 : 0)
                    .setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(final Animator animation) {
                            loadLayout.setVisibility(show ? View.VISIBLE : View.GONE);
                        }
                    });
        }
    } catch (final IllegalStateException e) {
        Log.w(TAG, e.getMessage(), e);
    }
}