List of usage examples for android.animation AnimatorListenerAdapter AnimatorListenerAdapter
AnimatorListenerAdapter
From source file:com.matthewtamlin.sliding_intro_screen_library.core.IntroActivity.java
/** * Enables the supplied button by making it visible and clickable. This method should only be * called while the supplied button is disabled (i.e. invisible and un-clickable). The supplied * Animator will be used to transition the button. * * @param buttonAnimator//from w w w.java 2 s . c o m * the Animator to use when transitioning the button, null to perform no animation * @param button * the button to enable, not null * @throws IllegalArgumentException * if {@code button} is null */ private void enableButton(final Animator buttonAnimator, final IntroButton button) { if (button == null) { throw new IllegalArgumentException("button cannot be null"); } // Any animations currently affecting the button must be cancelled before new ones start if (buttonAnimations.containsKey(button)) { buttonAnimations.get(button).cancel(); buttonAnimations.remove(button); } if (buttonAnimator != null) { buttonAnimations.put(button, buttonAnimator); // Give any disable animations time to finish before the enable animation starts buttonAnimator.setStartDelay(BUTTON_ANIMATION_DURATION_MS); // End/cancel conditions ensure that the UI is not left in a transient state when // animations finish buttonAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(final Animator animation) { button.setVisibility(View.VISIBLE); // Make sure View is visible while animating button.setEnabled(true); // Click events should be accepted immediately } @Override public void onAnimationCancel(final Animator animation) { // Restore button to disabled mode button.setVisibility(View.INVISIBLE); button.setEnabled(false); } }); buttonAnimator.setDuration(BUTTON_ANIMATION_DURATION_MS); buttonAnimator.start(); } else { // If no Animator was supplied, just apply the enabled conditions button.setVisibility(View.VISIBLE); button.setEnabled(true); } }
From source file:android.support.v17.leanback.app.OnboardingSupportFragment.java
/** * Called when the page changes.//from w ww . ja va2s.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.btmura.android.reddit.app.AbstractBrowserActivity.java
private AnimatorSet newCloseNavAnimator() { ObjectAnimator ncTransX = ObjectAnimator.ofFloat(navContainer, "translationX", 0, -leftWidth); AnimatorSet as = new AnimatorSet(); as.setDuration(durationMs).play(ncTransX); as.addListener(new AnimatorListenerAdapter() { @Override//from w w w .java 2s . co m public void onAnimationStart(Animator animation) { navContainer.setLayerType(View.LAYER_TYPE_HARDWARE, null); navContainer.setVisibility(View.VISIBLE); thingContainer.setLayerType(View.LAYER_TYPE_HARDWARE, null); thingContainer.setVisibility(View.GONE); thingContainer.setTranslationX(0); } @Override public void onAnimationEnd(Animator animation) { navContainer.setLayerType(View.LAYER_TYPE_NONE, null); navContainer.setVisibility(View.GONE); thingContainer.setLayerType(View.LAYER_TYPE_NONE, null); thingContainer.setVisibility(View.VISIBLE); } }); return as; }
From source file:com.lovejjfg.demo.TouchCircleView.java
private void setupAnimations() { mObjectAnimatorAngle = ObjectAnimator.ofFloat(this, mAngleProperty, mCurrentGlobalAngle, 360f); mObjectAnimatorAngle.setInterpolator(ANGLE_INTERPOLATOR); mObjectAnimatorAngle.setDuration(ANGLE_ANIMATOR_DURATION); mObjectAnimatorAngle.setRepeatMode(ValueAnimator.RESTART); mObjectAnimatorAngle.setRepeatCount(ValueAnimator.INFINITE); mObjectAnimatorAngle.addListener(new AnimatorListenerAdapter() { @Override//from w ww.j a va 2 s . c o m public void onAnimationRepeat(Animator animation) { mObjectAnimatorAngle.setFloatValues(360f); } }); mObjectAnimatorSweep = ObjectAnimator.ofFloat(this, mSweepProperty, mCurrentSweepAngle, 360f - MIN_SWEEP_ANGLE * 2); mObjectAnimatorSweep.setInterpolator(SWEEP_INTERPOLATOR); mObjectAnimatorSweep.setDuration(SWEEP_ANIMATOR_DURATION); mObjectAnimatorSweep.setRepeatMode(ValueAnimator.RESTART); mObjectAnimatorSweep.setRepeatCount(ValueAnimator.INFINITE); mObjectAnimatorSweep.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationRepeat(Animator animation) { mObjectAnimatorSweep.setFloatValues(360f - MIN_SWEEP_ANGLE * 2); toggleAppearingMode(); } }); fractionAnimator = ValueAnimator.ofInt(0, ALPHA_FULL); fractionAnimator.setInterpolator(ANGLE_INTERPOLATOR); fractionAnimator.setDuration(FRACTION_DURATION); fractionAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { fraction = animation.getAnimatedFraction(); mHookPaint.setAlpha((Integer) animation.getAnimatedValue()); invalidate(); } }); fractionAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mRunning = false; postDelayed(idleAction, 0); } }); translateAnimator = ValueAnimator.ofFloat(0, 100); translateAnimator.setInterpolator(ANGLE_INTERPOLATOR); translateAnimator.setDuration(200); translateAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { private float tranlateFraction; @Override public void onAnimationUpdate(ValueAnimator animation) { Float animatedValue = (Float) animation.getAnimatedValue(); updateState(STATE_TRANSLATE_PATH, false); tranlateFraction = animation.getAnimatedFraction(); if (!isBack) { mixPaint.setColor(ColorUtils.blendARGB(Color.RED, Color.GREEN, tranlateFraction)); mCurrentRadius = (int) (outCirRadius + tranlateFraction * (secondRadius - outCirRadius)); } else { mixPaint.setColor(ColorUtils.blendARGB(Color.GREEN, Color.RED, tranlateFraction)); mCurrentRadius = (int) (secondRadius - tranlateFraction * (secondRadius - outCirRadius)); } mCurrentPaint = mixPaint; resetPoints(secondRectf.centerX(), animatedValue); invalidate(); } }); translateAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { updateState(isBack ? STATE_DRAW_ARROW : abortReset ? STATE_DRAW_BACK : STATE_DRAW_CIRCLE, abortReset); updateRectF(); invalidate(); } }); }
From source file:com.grarak.kerneladiutor.fragments.RecyclerViewFragment.java
public void dismissForeground() { float translation = mForegroundParent.getTranslationY(); mForegroundAnimator = ValueAnimator.ofFloat(translation, mForegroundHeight); mForegroundAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/*ww w . j a v a2 s. c o m*/ public void onAnimationUpdate(ValueAnimator animation) { mForegroundParent.setTranslationY((float) animation.getAnimatedValue()); } }); mForegroundAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); mForegroundParent.setVisibility(View.GONE); mForegroundVisible = false; mForegroundAnimator = null; } }); mForegroundAnimator.start(); }
From source file:com.bartoszlipinski.viewpropertyobjectanimator.ViewPropertyObjectAnimator.java
@SuppressLint("NewApi") public ObjectAnimator get() { if (hasView()) { Collection<PropertyValuesHolder> holders = mPropertyHoldersMap.values(); ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(mView.get(), holders.toArray(new PropertyValuesHolder[holders.size()])); if (mWithLayer) { animator.addListener(new AnimatorListenerAdapter() { int mCurrentLayerType = View.LAYER_TYPE_NONE; @Override//from www. ja v a2 s . c om public void onAnimationStart(Animator animation) { if (hasView()) { View view = mView.get(); mCurrentLayerType = view.getLayerType(); view.setLayerType(View.LAYER_TYPE_HARDWARE, null); if (ViewCompat.isAttachedToWindow(view)) { view.buildLayer(); } } } @Override public void onAnimationEnd(Animator animation) { if (hasView()) { mView.get().setLayerType(mCurrentLayerType, null); } } }); } if (mStartDelay != -1) { animator.setStartDelay(mStartDelay); } if (mDuration != -1) { animator.setDuration(mDuration); } if (mInterpolator != null) { animator.setInterpolator(mInterpolator); } for (Animator.AnimatorListener listener : mListeners) { animator.addListener(listener); } if (mMarginListener != null) { animator.addUpdateListener(mMarginListener); } if (mDimensionListener != null) { animator.addUpdateListener(mDimensionListener); } if (mPaddingListener != null) { animator.addUpdateListener(mPaddingListener); } if (mScrollListener != null) { animator.addUpdateListener(mScrollListener); } if (mPercentListener != null) { animator.addUpdateListener(mPercentListener); } for (ValueAnimator.AnimatorUpdateListener listener : mUpdateListeners) { animator.addUpdateListener(listener); } if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { for (Animator.AnimatorPauseListener listener : mPauseListeners) { animator.addPauseListener(listener); } } return animator; } return ObjectAnimator.ofFloat(null, View.ALPHA, 1, 1); }
From source file:com.android.deskclock.timer.TimerFullScreenFragment.java
private void gotoTimersView() { if (mLastVisibleView == null || mLastVisibleView.getId() == R.id.timers_list_page) { mTimerSetup.setVisibility(View.GONE); mTimersListPage.setVisibility(View.VISIBLE); mTimersListPage.setScaleX(1f);/*from w w w . j a v a 2 s . c o m*/ } else { // Animate ObjectAnimator a = ObjectAnimator.ofFloat(mTimerSetup, View.SCALE_X, 1f, 0f); a.setInterpolator(new AccelerateInterpolator()); a.setDuration(125); a.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mTimerSetup.setVisibility(View.GONE); mTimersListPage.setScaleX(0); mTimersListPage.setVisibility(View.VISIBLE); ObjectAnimator b = ObjectAnimator.ofFloat(mTimersListPage, View.SCALE_X, 0f, 1f); b.setInterpolator(new DecelerateInterpolator()); b.setDuration(225); b.start(); } }); a.start(); } startClockTicks(); mLastVisibleView = mTimersListPage; }
From source file:com.android.systemui.statusbar.phone.NotificationPanelView.java
private void startClockAnimation(int y) { if (mClockAnimationTarget == y) { return;//from w ww . j a va2 s . c om } mClockAnimationTarget = y; getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { getViewTreeObserver().removeOnPreDrawListener(this); if (mClockAnimator != null) { mClockAnimator.removeAllListeners(); mClockAnimator.cancel(); } mClockAnimator = ObjectAnimator.ofFloat(mKeyguardStatusView, View.Y, mClockAnimationTarget); mClockAnimator.setInterpolator(mFastOutSlowInInterpolator); mClockAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD); mClockAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mClockAnimator = null; mClockAnimationTarget = -1; } }); mClockAnimator.start(); return true; } }); }
From source file:com.fairphone.fplauncher3.Folder.java
public void animateClosed() { if (!(getParent() instanceof DragLayer)) { return;//from w w w. j av a2s .c o m } PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0f); PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f); PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f); /*final ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);*/ setLayerType(LAYER_TYPE_HARDWARE, null); float animatorDurationScale = Settings.Global.getFloat(getContext().getContentResolver(), Settings.Global.ANIMATOR_DURATION_SCALE, 1); ObjectAnimator oa; if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && mPowerManager.isPowerSaveMode()) || animatorDurationScale < 0.01f) { // power save mode is no fun - skip alpha animation and just set it to 0 // otherwise the icons will stay around until the duration of the animation oa = LauncherAnimUtils.ofPropertyValuesHolder(this, scaleX, scaleY); setAlpha(0f); } else { oa = LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY); } oa.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { onCloseComplete(); setLayerType(LAYER_TYPE_NONE, null); mState = STATE_SMALL; } @Override public void onAnimationStart(Animator animation) { sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, getContext().getString(R.string.folder_closed)); mState = STATE_ANIMATING; } }); oa.setDuration(mExpandDuration); setLayerType(LAYER_TYPE_HARDWARE, null); oa.start(); }
From source file:com.androidinspain.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/*from w w w . ja va 2s.c om*/ * @param animateDown {@code true} if the views should animate upwards, otherwise downwards */ private void animateToView(final View toView, final Timer timerToRemove, final boolean animateDown) { if (mCurrentView == toView) { return; } final boolean toTimers = toView == mTimersView; if (toTimers) { mTimersView.setVisibility(VISIBLE); } else { mCreateTimerView.setVisibility(VISIBLE); } // Avoid double-taps by enabling/disabling the set of buttons active on the new view. updateFab(BUTTONS_DISABLE); final long animationDuration = UiDataModel.getUiDataModel().getLongAnimationDuration(); final ViewTreeObserver viewTreeObserver = toView.getViewTreeObserver(); viewTreeObserver.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { if (viewTreeObserver.isAlive()) { viewTreeObserver.removeOnPreDrawListener(this); } final View view = mTimersView.findViewById(com.androidinspain.deskclock.R.id.timer_time); final float distanceY = view != null ? view.getHeight() + view.getY() : 0; final float translationDistance = animateDown ? distanceY : -distanceY; toView.setTranslationY(-translationDistance); mCurrentView.setTranslationY(0f); toView.setAlpha(0f); mCurrentView.setAlpha(1f); final Animator translateCurrent = ObjectAnimator.ofFloat(mCurrentView, TRANSLATION_Y, translationDistance); final Animator translateNew = ObjectAnimator.ofFloat(toView, TRANSLATION_Y, 0f); final AnimatorSet translationAnimatorSet = new AnimatorSet(); translationAnimatorSet.playTogether(translateCurrent, translateNew); translationAnimatorSet.setDuration(animationDuration); translationAnimatorSet.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN); final Animator fadeOutAnimator = ObjectAnimator.ofFloat(mCurrentView, ALPHA, 0f); fadeOutAnimator.setDuration(animationDuration / 2); fadeOutAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { super.onAnimationStart(animation); // The fade-out animation and fab-shrinking animation should run together. updateFab(FAB_AND_BUTTONS_SHRINK); } @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); if (toTimers) { showTimersView(FAB_AND_BUTTONS_EXPAND); // Reset the state of the create view. mCreateTimerView.reset(); } else { showCreateTimerView(FAB_AND_BUTTONS_EXPAND); } if (timerToRemove != null) { DataModel.getDataModel().removeTimer(timerToRemove); Events.sendTimerEvent(com.androidinspain.deskclock.R.string.action_delete, com.androidinspain.deskclock.R.string.label_deskclock); } // Update the fab and button states now that the correct view is visible and // before the animation to expand the fab and buttons starts. updateFab(FAB_AND_BUTTONS_IMMEDIATE); } }); final Animator fadeInAnimator = ObjectAnimator.ofFloat(toView, ALPHA, 1f); fadeInAnimator.setDuration(animationDuration / 2); fadeInAnimator.setStartDelay(animationDuration / 2); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(fadeOutAnimator, fadeInAnimator, translationAnimatorSet); animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); mTimersView.setTranslationY(0f); mCreateTimerView.setTranslationY(0f); mTimersView.setAlpha(1f); mCreateTimerView.setAlpha(1f); } }); animatorSet.start(); return true; } }); }