private void smoothScrollTo(int desX, int desY, AnimatorListener listener) { ObjectAnimator xTranslate = ObjectAnimator.ofInt(this, "scrollX", desX); ObjectAnimator yTranslate = ObjectAnimator.ofInt(this, "scrollY", desY); yTranslate.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { if (mHeaderStatusChangedListener != null) mHeaderStatusChangedListener.onHeaderOffsetChanged((int) (mScrollOffsetHeight * animation.getAnimatedFraction()), animation.getAnimatedFraction()); } }); AnimatorSet animators = new AnimatorSet(); animators.setDuration(240L); animators.playTogether(xTranslate, yTranslate); if (listener != null) animators.addListener(listener); animators.start(); }
/** * This method is used to toggle between the two fragment states by * calling the appropriate animations between them. The entry and exit * animations of the text fragment are specified in R.animator resource * files. The entry and exit animations of the image fragment are * specified in the slideBack and slideForward methods below. The reason * for separating the animation logic in this way is because the translucent * dark hover view must fade in at the same time as the image fragment * animates into the background, which would be difficult to time * properly given that the setCustomAnimations method can only modify the * two fragments in the transaction. */ private void switchFragments () { if (mIsAnimating) { return; } mIsAnimating = true; if (mDidSlideOut) { mDidSlideOut = false; getFragmentManager().popBackStack(); } else { mDidSlideOut = true; AnimatorListener listener = new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator arg0) { FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.setCustomAnimations(R.animator.slide_fragment_in, 0, 0, R.animator.slide_fragment_out); transaction.add(R.id.move_to_back_container, mTextFragment); transaction.addToBackStack(null); transaction.commit(); } }; slideBack (listener); } }
/** * This method animates the image fragment into the background by both * scaling and rotating the fragment's view, as well as adding a * translucent dark hover view to inform the user that it is inactive. */ public void slideBack(AnimatorListener listener) { View movingFragmentView = mImageFragment.getView(); PropertyValuesHolder rotateX = PropertyValuesHolder.ofFloat("rotationX", 40f); PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.8f); PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.8f); ObjectAnimator movingFragmentAnimator = ObjectAnimator. ofPropertyValuesHolder(movingFragmentView, rotateX, scaleX, scaleY); ObjectAnimator darkHoverViewAnimator = ObjectAnimator. ofFloat(mDarkHoverView, "alpha", 0.0f, 0.5f); ObjectAnimator movingFragmentRotator = ObjectAnimator. ofFloat(movingFragmentView, "rotationX", 0); movingFragmentRotator.setStartDelay(getResources(). getInteger(R.integer.half_slide_up_down_duration)); AnimatorSet s = new AnimatorSet(); s.playTogether(movingFragmentAnimator, darkHoverViewAnimator, movingFragmentRotator); s.addListener(listener); s.start(); }
/** * Creates and returns an animation listener, which allows to adapt the currently selected tab, * when swiping the tabs horizontally has been ended. * * @param tabItem * The tab item, which corresponds to the tab, which should be selected, as an instance * of the class {@link TabItem}. The tab item may not be null * @return The animation listener, which has been created, as an instance of the type {@link * AnimatorListener}. The listener may not be null */ @NonNull private AnimatorListener createSwipeSelectedTabAnimationListener( @NonNull final TabItem tabItem) { return new AnimatorListenerAdapter() { @Override public void onAnimationEnd(final Animator animation) { super.onAnimationEnd(animation); Tab tab = tabItem.getTab(); if (getModel().getSelectedTab() != tab) { getModel().selectTab(tab); } } }; }
/** * Animates the position and size of a specific tab in order to hide the tab switcher. * * @param item * The item, which corresponds to the tab, which should be animated, as an instance of * the class {@link AbstractItem}. The item may not be null * @param duration * The duration of the animation in milliseconds as a {@link Long} value * @param interpolator * The interpolator, which should be used by the animation, as an instance of the class * {@link Interpolator}. The interpolator may not be null * @param delay * The delay of the animation in milliseconds as a {@link Long} value * @param listener * The listener, which should be notified about the animation's progress, as an instance * of the type {@link AnimatorListener} or null, if no listener should be notified */ private void animateHideSwitcher(@NonNull final AbstractItem item, final long duration, @NonNull final Interpolator interpolator, final long delay, @Nullable final AnimatorListener listener) { View view = item.getView(); animateBottomMargin(view, -(tabInset + tabBorderWidth), duration, delay); ViewPropertyAnimator animation = view.animate(); animation.setDuration(duration); animation.setInterpolator(interpolator); animation.setListener(new AnimationListenerWrapper(listener)); getArithmetics().animateScale(Axis.DRAGGING_AXIS, animation, 1); getArithmetics().animateScale(Axis.ORTHOGONAL_AXIS, animation, 1); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams(); getArithmetics().animatePosition(Axis.ORTHOGONAL_AXIS, animation, item, getTabSwitcher().getLayout() == Layout.PHONE_LANDSCAPE ? layoutParams.topMargin : 0); int selectedTabIndex = getModel().getSelectedTabIndex(); if (item.getIndex() < selectedTabIndex) { getArithmetics().animatePosition(Axis.DRAGGING_AXIS, animation, item, getArithmetics().getTabContainerSize(Axis.DRAGGING_AXIS)); } else if (item.getIndex() > selectedTabIndex) { getArithmetics().animatePosition(Axis.DRAGGING_AXIS, animation, item, getTabSwitcher().getLayout() == Layout.PHONE_LANDSCAPE ? 0 : layoutParams.topMargin); } else { getArithmetics().animatePosition(Axis.DRAGGING_AXIS, animation, item, getTabSwitcher().getLayout() == Layout.PHONE_LANDSCAPE ? 0 : layoutParams.topMargin); } animation.setStartDelay(delay); animation.start(); }
/** * Animates to rotation of all tabs to be reset to normal. * * @param interpolator * The interpolator, which should be used by the animation, as an instance of the type * {@link Interpolator}. The interpolator may not be null * @param maxAngle * The angle, the tabs may be rotated by at maximum, in degrees as a {@link Float} * value * @param listener * The listener, which should be notified about the animation's progress, as an instance * of the type {@link AnimatorListener} or null, if no listener should be notified * @return True, if at least one tab was animated, false otherwise */ private boolean animateTilt(@NonNull final Interpolator interpolator, final float maxAngle, @Nullable final AnimatorListener listener) { ItemIterator iterator = new ItemIterator.Builder(getTabSwitcher(), tabViewRecycler).reverse(true).create(); AbstractItem item; boolean result = false; while ((item = iterator.next()) != null) { if (item.isInflated() && getArithmetics().getRotation(Axis.ORTHOGONAL_AXIS, item) != 0) { View view = item.getView(); ViewPropertyAnimator animation = view.animate(); animation.setListener(new AnimationListenerWrapper( createRevertOvershootAnimationListener(item, !result ? listener : null))); animation.setDuration(Math.round(revertOvershootAnimationDuration * (Math.abs(getArithmetics().getRotation(Axis.ORTHOGONAL_AXIS, item)) / maxAngle))); animation.setInterpolator(interpolator); getArithmetics().animateRotation(Axis.ORTHOGONAL_AXIS, animation, 0); animation.setStartDelay(0); animation.start(); result = true; } } return result; }
/** * Creates and returns a listener, which allows to handle, when a tab has been swiped, but was * not removed. * * @param item * The item, which corresponds to the tab, which has been swiped, as an instance of the * class {@link AbstractItem}. The item may not be null * @return The listener, which has been created, as an instance of the type {@link * AnimatorListener}. The listener may not be null */ @NonNull private AnimatorListener createSwipeAnimationListener(@NonNull final AbstractItem item) { return new AnimatorListenerAdapter() { @Override public void onAnimationEnd(final Animator animation) { super.onAnimationEnd(animation); inflateOrRemoveView(item, false); adaptStackOnSwipeAborted(item, item.getIndex() + 1); item.getTag().setClosing(false); getArithmetics().setPivot(Axis.DRAGGING_AXIS, item, getArithmetics().getPivot(Axis.DRAGGING_AXIS, item, DragState.NONE)); animateToolbarVisibility(true, 0); } }; }
/** * Creates and returns an animation listener, which allows to adapt the pivot of a specific * tab, when an animation, which reverted an overshoot, has been ended. * * @param item * The item, which corresponds to the tab, whose pivot should be adapted, as an instance * of the class {@link AbstractItem}. The item may not be null * @param listener * The listener, which should be notified about the animation's progress, as an instance * of the type {@link AnimatorListener} or null, if no listener should be notified * @return The listener, which has been created, as an instance of the type {@link * AnimatorListener}. The listener may not be null */ @NonNull private AnimatorListener createRevertOvershootAnimationListener( @NonNull final AbstractItem item, @Nullable final AnimatorListener listener) { return new AnimatorListenerAdapter() { @Override public void onAnimationEnd(final Animator animation) { super.onAnimationEnd(animation); getArithmetics().setPivot(Axis.DRAGGING_AXIS, item, getArithmetics().getPivot(Axis.DRAGGING_AXIS, item, DragState.NONE)); getArithmetics().setPivot(Axis.ORTHOGONAL_AXIS, item, getArithmetics().getPivot(Axis.DRAGGING_AXIS, item, DragState.NONE)); if (listener != null) { listener.onAnimationEnd(animation); } } }; }
/** * Creates and returns an animation listener, which allows to hide a tab, which has been added * by using a peek animation, when the animation has been ended. * * @param item * The item, which corresponds to the tab, which has been added by using the peek * animation, as an instance of the class {@link AbstractItem}. The item may not be * null * @param peekAnimation * The peek animation as an instance of the class {@link PeekAnimation}. The peek * animation may not be null * @return The listener, which has been created, as an instance of the type {@link * AnimatorListener}. The listener may not be null */ @NonNull private AnimatorListener createPeekAnimationListener(@NonNull final AbstractItem item, @NonNull final PeekAnimation peekAnimation) { return new AnimatorListenerAdapter() { @Override public void onAnimationEnd(final Animator animation) { super.onAnimationEnd(animation); long totalDuration = peekAnimation.getDuration() != -1 ? peekAnimation.getDuration() : peekAnimationDuration; long duration = totalDuration / 3; Interpolator interpolator = peekAnimation.getInterpolator() != null ? peekAnimation.getInterpolator() : new AccelerateDecelerateInterpolator(); View view = item.getView(); getArithmetics().setPivot(Axis.DRAGGING_AXIS, item, tabTitleContainerHeight); getArithmetics().setPivot(Axis.ORTHOGONAL_AXIS, item, getArithmetics().getSize(Axis.ORTHOGONAL_AXIS, item) / 2f); ViewPropertyAnimator animator = view.animate(); animator.setDuration(duration); animator.setStartDelay(duration); animator.setInterpolator(interpolator); animator.setListener( new AnimationListenerWrapper(createRevertPeekAnimationListener(item))); animator.alpha(0); getArithmetics().animatePosition(Axis.DRAGGING_AXIS, animator, item, getArithmetics().getPosition(Axis.DRAGGING_AXIS, item) * 1.5f); getArithmetics().animateScale(Axis.DRAGGING_AXIS, animator, 0); getArithmetics().animateScale(Axis.ORTHOGONAL_AXIS, animator, 0); animator.start(); } }; }
/** * Creates and returns an animation listener, which allows to zoom in the currently selected * tab, when a peek animation has been ended. * * @param selectedItem * The item, which corresponds to the currently selected tab, as an instance of the * class {@link AbstractItem}. The item may not be null * @param peekAnimation * The peek animation as an instance of the class {@link PeekAnimation}. The peek * animation may not be null * @return The listener, which has been created, as an instance of the type {@link * AnimatorListener}. The listener may not be null */ @NonNull private AnimatorListener createZoomOutAnimationListener( @NonNull final AbstractItem selectedItem, @NonNull final PeekAnimation peekAnimation) { return new AnimatorListenerAdapter() { @Override public void onAnimationEnd(final Animator animation) { super.onAnimationEnd(animation); getModel().removeListener(PhoneTabSwitcherLayout.this); getModel().hideSwitcher(); long totalDuration = peekAnimation.getDuration() != -1 ? peekAnimation.getDuration() : peekAnimationDuration; long duration = totalDuration / 3; Interpolator interpolator = peekAnimation.getInterpolator() != null ? peekAnimation.getInterpolator() : new AccelerateDecelerateInterpolator(); animateHideSwitcher(selectedItem, duration, interpolator, duration, createZoomInAnimationListener(selectedItem)); } }; }
/** * Creates and returns an animation listener, which allows to restore the original state of a * tab, when an animation, which zooms in the tab, has been ended. * * @param item * The item, which corresponds to the tab, which has been zoomed in, as an instance of * the class {@link AbstractItem}. The item may not be null * @return The listener, which has been created, as an instance of the type {@link * AnimatorListener}. The listener may not be null */ private AnimatorListener createZoomInAnimationListener(@NonNull final AbstractItem item) { return new AnimatorListenerAdapter() { @Override public void onAnimationEnd(final Animator animation) { super.onAnimationEnd(animation); getModel().addListener(PhoneTabSwitcherLayout.this); tabViewRecycler.inflate(item); tabViewRecycler.clearCache(); tabRecyclerAdapter.clearCachedPreviews(); tabViewBottomMargin = -1; } }; }
/** * Animates the position and size of a specific tab item in order to hide the tab switcher. * * @param tabItem * The tab item, which should be animated, as an instance of the class {@link TabItem}. * The tab item may not be null * @param duration * The duration of the animation in milliseconds as a {@link Long} value * @param interpolator * The interpolator, which should be used by the animation, as an instance of the class * {@link Interpolator}. The interpolator may not be null * @param delay * The delay of the animation in milliseconds as a {@link Long} value * @param listener * The listener, which should be notified about the animation's progress, as an instance * of the type {@link AnimatorListener} or null, if no listener should be notified */ private void animateHideSwitcher(@NonNull final TabItem tabItem, final long duration, @NonNull final Interpolator interpolator, final long delay, @Nullable final AnimatorListener listener) { View view = tabItem.getView(); animateBottomMargin(view, -(tabInset + tabBorderWidth), duration, delay); ViewPropertyAnimator animation = view.animate(); animation.setDuration(duration); animation.setInterpolator(interpolator); animation.setListener(new AnimationListenerWrapper(listener)); getArithmetics().animateScale(Axis.DRAGGING_AXIS, animation, 1); getArithmetics().animateScale(Axis.ORTHOGONAL_AXIS, animation, 1); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams(); getArithmetics().animatePosition(Axis.ORTHOGONAL_AXIS, animation, view, getTabSwitcher().getLayout() == Layout.PHONE_LANDSCAPE ? layoutParams.topMargin : 0, false); int selectedTabIndex = getModel().getSelectedTabIndex(); if (tabItem.getIndex() < selectedTabIndex) { getArithmetics().animatePosition(Axis.DRAGGING_AXIS, animation, view, getArithmetics().getTabContainerSize(Axis.DRAGGING_AXIS), false); } else if (tabItem.getIndex() > selectedTabIndex) { getArithmetics().animatePosition(Axis.DRAGGING_AXIS, animation, view, getTabSwitcher().getLayout() == Layout.PHONE_LANDSCAPE ? 0 : layoutParams.topMargin, false); } else { getArithmetics().animatePosition(Axis.DRAGGING_AXIS, animation, view, getTabSwitcher().getLayout() == Layout.PHONE_LANDSCAPE ? 0 : layoutParams.topMargin, false); } animation.setStartDelay(delay); animation.start(); }
/** * Animates to rotation of all tabs to be reset to normal. * * @param interpolator * The interpolator, which should be used by the animation, as an instance of the type * {@link Interpolator}. The interpolator may not be null * @param maxAngle * The angle, the tabs may be rotated by at maximum, in degrees as a {@link Float} * value * @param listener * The listener, which should be notified about the animation's progress, as an instance * of the type {@link AnimatorListener} or null, if no listener should be notified * @return True, if at least one tab was animated, false otherwise */ private boolean animateTilt(@NonNull final Interpolator interpolator, final float maxAngle, @Nullable final AnimatorListener listener) { TabItemIterator iterator = new TabItemIterator.Builder(getTabSwitcher(), viewRecycler).reverse(true).create(); TabItem tabItem; boolean result = false; while ((tabItem = iterator.next()) != null) { if (tabItem.isInflated()) { View view = tabItem.getView(); if (getArithmetics().getRotation(Axis.ORTHOGONAL_AXIS, view) != 0) { ViewPropertyAnimator animation = view.animate(); animation.setListener(new AnimationListenerWrapper( createRevertOvershootAnimationListener(view, !result ? listener : null))); animation.setDuration(Math.round(revertOvershootAnimationDuration * (Math.abs(getArithmetics().getRotation(Axis.ORTHOGONAL_AXIS, view)) / maxAngle))); animation.setInterpolator(interpolator); getArithmetics().animateRotation(Axis.ORTHOGONAL_AXIS, animation, 0); animation.setStartDelay(0); animation.start(); result = true; } } } return result; }
/** * Creates and returns an animation listener, which allows to inflate or remove the views, which * are used to visualize tabs, when an animation, which is used to hide the tab switcher, * has been finished. * * @return The animation listener, which has been created, as an instance of the type {@link * AnimatorListener}. The listener may not be null */ @NonNull private AnimatorListener createHideSwitcherAnimationListener() { return new AnimatorListenerAdapter() { @Override public void onAnimationEnd(final Animator animation) { super.onAnimationEnd(animation); AbstractTabItemIterator iterator = new TabItemIterator.Builder(getTabSwitcher(), viewRecycler).create(); TabItem tabItem; while ((tabItem = iterator.next()) != null) { if (tabItem.getTab() == getModel().getSelectedTab()) { Pair<View, Boolean> pair = viewRecycler.inflate(tabItem); View view = pair.first; FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams(); view.setAlpha(1f); getArithmetics().setScale(Axis.DRAGGING_AXIS, view, 1); getArithmetics().setScale(Axis.ORTHOGONAL_AXIS, view, 1); view.setX(layoutParams.leftMargin); view.setY(layoutParams.topMargin); } else { viewRecycler.remove(tabItem); } } viewRecycler.clearCache(); recyclerAdapter.clearCachedPreviews(); tabViewBottomMargin = -1; } }; }
/** * Creates and returns a listener, which allows to handle, when a tab has been swiped, but was * not removed. * * @param tabItem * The tab item, which corresponds to the tab, which has been swiped, as an instance of * the class {@link TabItem}. The tab item may not be null * @return The listener, which has been created, as an instance of the type {@link * AnimatorListener}. The listener may not be null */ @NonNull private AnimatorListener createSwipeAnimationListener(@NonNull final TabItem tabItem) { return new AnimatorListenerAdapter() { @Override public void onAnimationEnd(final Animator animation) { super.onAnimationEnd(animation); inflateOrRemoveView(tabItem); View view = tabItem.getView(); adaptStackOnSwipeAborted(tabItem, tabItem.getIndex() + 1); tabItem.getTag().setClosing(false); getArithmetics().setPivot(Axis.DRAGGING_AXIS, view, getArithmetics().getPivot(Axis.DRAGGING_AXIS, view, DragState.NONE)); animateToolbarVisibility(true, 0); } }; }
/** * Creates and returns an animation listener, which allows to adapt the pivot of a specific * view, when an animation, which reverted an overshoot, has been ended. * * @param view * The view, whose pivot should be adapted, as an instance of the class {@link View}. * The view may not be null * @param listener * The listener, which should be notified about the animation's progress, as an instance * of the type {@link AnimatorListener} or null, if no listener should be notified * @return The listener, which has been created, as an instance of the type {@link * AnimatorListener}. The listener may not be null */ @NonNull private AnimatorListener createRevertOvershootAnimationListener(@NonNull final View view, @Nullable final AnimatorListener listener) { return new AnimatorListenerAdapter() { @Override public void onAnimationEnd(final Animator animation) { super.onAnimationEnd(animation); getArithmetics().setPivot(Axis.DRAGGING_AXIS, view, getArithmetics().getPivot(Axis.DRAGGING_AXIS, view, DragState.NONE)); getArithmetics().setPivot(Axis.ORTHOGONAL_AXIS, view, getArithmetics().getPivot(Axis.DRAGGING_AXIS, view, DragState.NONE)); if (listener != null) { listener.onAnimationEnd(animation); } } }; }
/** * Creates and returns an animation listener, which allows to zoom in the currently selected * tab, when a peek animation has been ended. * * @param selectedTabItem * The tab item, which corresponds to the currently selected tab, as an instance of the * class {@link TabItem}. The tab item may not be null * @param peekAnimation * The peek animation as an instance of the class {@link PeekAnimation}. The peek * animation may not be null * @return The listener, which has been created, as an instance of the type {@link * AnimatorListener}. The listener may not be null */ @NonNull private AnimatorListener createZoomOutAnimationListener(@NonNull final TabItem selectedTabItem, @NonNull final PeekAnimation peekAnimation) { return new AnimatorListenerAdapter() { @Override public void onAnimationEnd(final Animator animation) { super.onAnimationEnd(animation); getModel().removeListener(PhoneTabSwitcherLayout.this); getModel().hideSwitcher(); long totalDuration = peekAnimation.getDuration() != -1 ? peekAnimation.getDuration() : peekAnimationDuration; long duration = totalDuration / 3; Interpolator interpolator = peekAnimation.getInterpolator() != null ? peekAnimation.getInterpolator() : new AccelerateDecelerateInterpolator(); animateHideSwitcher(selectedTabItem, duration, interpolator, duration, createZoomInAnimationListener(selectedTabItem)); } }; }
/** * Creates and returns an animation listener, which allows to restore the original state of a * tab, when an animation, which zooms in the tab, has been ended. * * @param tabItem * The tab item, which corresponds to the tab, which has been zoomed in, as an instance * of the class {@link TabItem}. The tab item may not be null * @return The listener, which has been created, as an instance of the type {@link * AnimatorListener}. The listener may not be null */ private AnimatorListener createZoomInAnimationListener(@NonNull final TabItem tabItem) { return new AnimatorListenerAdapter() { @Override public void onAnimationEnd(final Animator animation) { super.onAnimationEnd(animation); getModel().addListener(PhoneTabSwitcherLayout.this); viewRecycler.inflate(tabItem); viewRecycler.clearCache(); recyclerAdapter.clearCachedPreviews(); tabViewBottomMargin = -1; } }; }
private void createScrimAnimation( View child, boolean expanded, boolean currentlyAnimating, List<Animator> animations, List<AnimatorListener> unusedListeners) { MotionTiming timing = expanded ? expandTiming : collapseTiming; Animator animator; if (expanded) { if (!currentlyAnimating) { child.setAlpha(0f); } animator = ObjectAnimator.ofFloat(child, View.ALPHA, 1f); } else { animator = ObjectAnimator.ofFloat(child, View.ALPHA, 0f); } timing.apply(animator); animations.add(animator); }
@TargetApi(VERSION_CODES.LOLLIPOP) private void createElevationAnimation( View dependency, View child, boolean expanded, boolean currentlyAnimating, FabTransformationSpec spec, List<Animator> animations, List<AnimatorListener> unusedListeners) { float translationZ = ViewCompat.getElevation(child) - ViewCompat.getElevation(dependency); Animator animator; if (expanded) { if (!currentlyAnimating) { child.setTranslationZ(-translationZ); } animator = ObjectAnimator.ofFloat(child, View.TRANSLATION_Z, 0f); } else { animator = ObjectAnimator.ofFloat(child, View.TRANSLATION_Z, -translationZ); } MotionTiming timing = spec.timings.getTiming("elevation"); timing.apply(animator); animations.add(animator); }
private void animateTranslation( BackLayerLayout backLayerLayout, View child, boolean animated, @Nullable AnimatorListener listener) { if (currentAnimator != null) { currentAnimator.cancel(); } if (backLayerLayout.isExpanded()) { currentAnimator = createExpandAnimation(backLayerLayout, child); } else { currentAnimator = createCollapseAnimation(backLayerLayout, child); } if (listener != null) { currentAnimator.addListener(listener); } currentAnimator.start(); if (!animated) { // Synchronously end the animation, jumping to the end state. currentAnimator.end(); } }
/** * Creates an animator, which should be used for a fade animation. * * @param animatedView * The animated view as an instance of the class {@link View}. The view may not be null * @param animation * The animation as an instance of the class {@link FadeAnimation}. The animation may * not be null * @param listener * The listener, which should be notified about the animation's events, as an instance * of the type {@link AnimatorListener} or null, if no listener should be notified * @param show * True, if the animation should be used to show the dialog, false otherwise * @return The animator, which has been created, as an instance of the class {@link * ViewPropertyAnimator} or null, if no animation should be used */ private ViewPropertyAnimator createAnimator(@NonNull final View animatedView, @NonNull final FadeAnimation animation, @Nullable final AnimatorListener listener, final boolean show) { if (animation.getAlpha() != null) { ViewPropertyAnimator animator = animatedView.animate().setInterpolator(animation.getInterpolator()) .setDuration(getDuration(animatedView, animation)) .setStartDelay(animation.getStartDelay()).setListener(listener); if (show) { animatedView.setAlpha(animation.getAlpha()); animator.alpha(1); } else { animatedView.setAlpha(1f); animator.alpha(animation.getAlpha()); } return animator; } return null; }
private void animateOut(final PieItem fixed, AnimatorListener listener) { if ((mCurrentItems == null) || (fixed == null)) return; final float target = fixed.getStartAngle(); ValueAnimator anim = ValueAnimator.ofFloat(0, 1); anim.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { for (PieItem item : mCurrentItems) { if (item != fixed) { item.setAnimationAngle(animation.getAnimatedFraction() * (target - item.getStart())); } } invalidate(); } }); anim.setDuration(ANIMATION); anim.addListener(listener); anim.start(); }
private void animateIn(final PieItem fixed, AnimatorListener listener) { if ((mCurrentItems == null) || (fixed == null)) return; final float target = fixed.getStartAngle(); ValueAnimator anim = ValueAnimator.ofFloat(0, 1); anim.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { for (PieItem item : mCurrentItems) { if (item != fixed) { item.setAnimationAngle((1 - animation.getAnimatedFraction()) * (target - item.getStart())); } } invalidate(); } }); anim.setDuration(ANIMATION); anim.addListener(listener); anim.start(); }
/** * Add animations to translate a view's X-translation. {@link android.animation.Animator.AnimatorListener} can be null. */ private static void addXTranslationAnimators(List<Animator> animators, final View view, int startTranslation, final int endTranslation, int animationDelay, AnimatorListener listener) { // We used to skip the animation if startTranslation == endTranslation, // but to add a recycle view listener, we need at least one animation view.setTranslationX(startTranslation); final ObjectAnimator translateAnimatorX = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, startTranslation, endTranslation); translateAnimatorX.setInterpolator(sDecelerateQuintInterpolator); translateAnimatorX.setDuration(sAnimationDuration); translateAnimatorX.setStartDelay(animationDelay); if (listener != null) { translateAnimatorX.addListener(listener); } animators.add(translateAnimatorX); }
/** * Add animations to translate a view's Y-translation. {@link android.animation.Animator.AnimatorListener} can be null. */ private static void addYTranslationAnimators(List<Animator> animators, final View view, int startTranslation, final int endTranslation, int animationDelay, AnimatorListener listener) { // We used to skip the animation if startTranslation == endTranslation, // but to add a recycle view listener, we need at least one animation view.setTranslationY(startTranslation); final ObjectAnimator translateAnimatorY = ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, startTranslation, endTranslation); translateAnimatorY.setInterpolator(sDecelerateQuintInterpolator); translateAnimatorY.setDuration(sAnimationDuration); translateAnimatorY.setStartDelay(animationDelay); if (listener != null) { translateAnimatorY.addListener(listener); } animators.add(translateAnimatorY); }
/** * Animate. * * @param progressBar the progress bar * @param listener the listener */ private void animate(final HoloCircularProgressBar progressBar, final AnimatorListener listener) { final float progress = (float) (Math.random() * 2); int duration = 3000; animate(progressBar, listener, progress, duration); }
public void animLayoutByTime(int start, int end, long time, AnimatorUpdateListener listener, AnimatorListener animatorListener) { ValueAnimator va = ValueAnimator.ofInt(start, end); va.setInterpolator(new DecelerateInterpolator()); va.addUpdateListener(listener); va.addListener(animatorListener); va.setDuration(time); va.start(); }
public void animLayoutByTime(int start, int end, AnimatorUpdateListener listener, AnimatorListener animatorListener) { ValueAnimator va = ValueAnimator.ofInt(start, end); va.setInterpolator(new DecelerateInterpolator()); va.addUpdateListener(listener); va.addListener(animatorListener); va.setDuration((int) (Math.abs(start - end) * animFraction)); va.start(); }
private void showGlow(int duration, int delay, float finalAlpha, AnimatorListener finishListener) { mGlowAnimations.cancel(); mGlowAnimations.add(Tweener.to(mPointCloud.glowManager, duration, "ease", Ease.Cubic.easeIn, "delay", delay, "alpha", finalAlpha, "onUpdate", mUpdateListener, "onComplete", finishListener)); mGlowAnimations.start(); }
private void hideGlow(int duration, int delay, float finalAlpha, AnimatorListener finishListener) { mGlowAnimations.cancel(); mGlowAnimations.add(Tweener.to(mPointCloud.glowManager, duration, "ease", Ease.Quart.easeOut, "delay", delay, "alpha", finalAlpha, "x", 0.0f, "y", 0.0f, "onUpdate", mUpdateListener, "onComplete", finishListener)); mGlowAnimations.start(); }
public void animLayoutByTime(int start, int end, long time, AnimatorUpdateListener listener, AnimatorListener animatorListener) { ValueAnimator va = ValueAnimator.ofInt(start, end); va.setInterpolator(new DecelerateInterpolator()); va.addUpdateListener(listener); va.addListener(animatorListener); va.setDuration(time); va.start(); // offerToQueue(va); }
public void animLayoutByTime(int start, int end, AnimatorUpdateListener listener, AnimatorListener animatorListener) { ValueAnimator va = ValueAnimator.ofInt(start, end); va.setInterpolator(new DecelerateInterpolator()); va.addUpdateListener(listener); va.addListener(animatorListener); va.setDuration((int) (Math.abs(start - end) * animFraction)); va.start(); // offerToQueue(va); }
/** * Creates an AnimatorListenerAdapter that cleans up after an animation is completed. * @return {@link AnimatorListenerAdapter} to use for animations. */ private AnimatorListener createAnimatorListener() { return new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mGestureState = GESTURE_NONE; mCurrentAnimation = null; mIsBeingDisplayedForFirstTime = false; } }; }
public static Animator createAnimator(View view, float toAlpha, int durationMillis, int startDelayMillis, AnimatorListener listener) { Animator animator = ObjectAnimator.ofFloat(view, "alpha", view.getAlpha(), toAlpha); animator.setDuration((long) durationMillis); animator.setStartDelay((long) startDelayMillis); animator.addListener(listener); return animator; }
/** * This method animates the image fragment into the foreground by both * scaling and rotating the fragment's view, while also removing the * previously added translucent dark hover view. Upon the completion of * this animation, the image fragment regains focus since this method is * called from the onBackStackChanged method. */ public void slideForward(AnimatorListener listener) { View movingFragmentView = mImageFragment.getView(); PropertyValuesHolder rotateX = PropertyValuesHolder.ofFloat("rotationX", 40f); PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f); PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f); ObjectAnimator movingFragmentAnimator = ObjectAnimator. ofPropertyValuesHolder(movingFragmentView, rotateX, scaleX, scaleY); ObjectAnimator darkHoverViewAnimator = ObjectAnimator. ofFloat(mDarkHoverView, "alpha", 0.5f, 0.0f); ObjectAnimator movingFragmentRotator = ObjectAnimator. ofFloat(movingFragmentView, "rotationX", 0); movingFragmentRotator.setStartDelay( getResources().getInteger(R.integer.half_slide_up_down_duration)); AnimatorSet s = new AnimatorSet(); s.playTogether(movingFragmentAnimator, movingFragmentRotator, darkHoverViewAnimator); s.setStartDelay(getResources().getInteger(R.integer.slide_up_down_duration)); s.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mIsAnimating = false; } }); s.start(); }
/** * Creates and returns an animation listener, which allows to remove the view, which is used to * visualize a specific tab, when swiping the tabs horizontally has been ended. * * @param tabItem * The tab item, which corresponds to the tab, whose view should be removed, as an * instance of the class {@link TabItem}. The tab item may not be null * @return The animation listener, which has been created, as an instance of the type {@link * AnimatorListener}. The listener may not be null */ @NonNull private AnimatorListener createSwipeNeighborAnimationListener(@NonNull final TabItem tabItem) { return new AnimatorListenerAdapter() { @Override public void onAnimationEnd(final Animator animation) { super.onAnimationEnd(animation); contentViewRecycler.remove(tabItem.getTab()); } }; }