Example usage for android.animation ObjectAnimator addUpdateListener

List of usage examples for android.animation ObjectAnimator addUpdateListener

Introduction

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

Prototype

public void addUpdateListener(AnimatorUpdateListener listener) 

Source Link

Document

Adds a listener to the set of listeners that are sent update events through the life of an animation.

Usage

From source file:com.actionbarsherlock.sample.hcgallery.MainActivity.java

public void toggleVisibleTitles() {
    // Use these for custom animations.
    final FragmentManager fm = getSupportFragmentManager();
    final TitlesFragment f = (TitlesFragment) fm.findFragmentById(R.id.frag_title);
    final View titlesView = f.getView();
    mLabelIndex = 1 - mLabelIndex;/*w w  w  .  j a  v  a  2s  . c o  m*/

    // Determine if we're in portrait, and whether we're showing or hiding the titles
    // with this toggle.
    final boolean isPortrait = getResources()
            .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;

    final boolean shouldShow = f.isHidden() || mCurrentTitlesAnimator != null;

    // Cancel the current titles animation if there is one.
    if (mCurrentTitlesAnimator != null)
        mCurrentTitlesAnimator.cancel();

    // Begin setting up the object animator. We'll animate the bottom or right edge of the
    // titles view, as well as its alpha for a fade effect.
    ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(titlesView,
            PropertyValuesHolder.ofInt(isPortrait ? "bottom" : "right",
                    shouldShow ? getResources().getDimensionPixelSize(R.dimen.titles_size) : 0),
            PropertyValuesHolder.ofFloat("alpha", shouldShow ? 1 : 0));

    // At each step of the animation, we'll perform layout by calling setLayoutParams.
    final ViewGroup.LayoutParams lp = titlesView.getLayoutParams();
    objectAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            // *** WARNING ***: triggering layout at each animation frame highly impacts
            // performance so you should only do this for simple layouts. More complicated
            // layouts can be better served with individual animations on child views to
            // avoid the performance penalty of layout.
            if (isPortrait) {
                lp.height = (Integer) valueAnimator.getAnimatedValue();
            } else {
                lp.width = (Integer) valueAnimator.getAnimatedValue();
            }
            titlesView.setLayoutParams(lp);
        }
    });

    if (shouldShow) {
        fm.beginTransaction().show(f).commit();
        objectAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animator) {
                mCurrentTitlesAnimator = null;
            }
        });

    } else {
        objectAnimator.addListener(new AnimatorListenerAdapter() {
            boolean canceled;

            @Override
            public void onAnimationCancel(Animator animation) {
                canceled = true;
                super.onAnimationCancel(animation);
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                if (canceled)
                    return;
                mCurrentTitlesAnimator = null;
                fm.beginTransaction().hide(f).commit();
            }
        });
    }

    // Start the animation.
    objectAnimator.start();
    mCurrentTitlesAnimator = objectAnimator;

    invalidateOptionsMenu();

    // Manually trigger onNewIntent to check for ACTION_DIALOG.
    onNewIntent(getIntent());
}

From source file:io.plaidapp.ui.FeedAdapter.java

private void bindDribbbleShotHolder(final Shot shot, final DribbbleShotHolder holder, int position) {
    final int[] imageSize = shot.images.bestSize();
    Glide.with(host).load(shot.images.best()).listener(new RequestListener<String, GlideDrawable>() {

        @Override/*from  www  .j  a  v a  2  s.  co m*/
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target,
                boolean isFromMemoryCache, boolean isFirstResource) {
            if (!shot.hasFadedIn) {
                holder.image.setHasTransientState(true);
                final ObservableColorMatrix cm = new ObservableColorMatrix();
                final ObjectAnimator saturation = ObjectAnimator.ofFloat(cm, ObservableColorMatrix.SATURATION,
                        0f, 1f);
                saturation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        // just animating the color matrix does not invalidate the
                        // drawable so need this update listener.  Also have to create a
                        // new CMCF as the matrix is immutable :(
                        holder.image.setColorFilter(new ColorMatrixColorFilter(cm));
                    }
                });
                saturation.setDuration(2000L);
                saturation.setInterpolator(getFastOutSlowInInterpolator(host));
                saturation.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        holder.image.clearColorFilter();
                        holder.image.setHasTransientState(false);
                    }
                });
                saturation.start();
                shot.hasFadedIn = true;
            }
            return false;
        }

        @Override
        public boolean onException(Exception e, String model, Target<GlideDrawable> target,
                boolean isFirstResource) {
            return false;
        }
    }).placeholder(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length])
            .diskCacheStrategy(DiskCacheStrategy.SOURCE).fitCenter().override(imageSize[0], imageSize[1])
            .into(new DribbbleTarget(holder.image, false));
    // need both placeholder & background to prevent seeing through shot as it fades in
    holder.image.setBackground(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length]);
    holder.image.showBadge(shot.animated);
    // need a unique transition name per shot, let's use it's url
    holder.image.setTransitionName(shot.html_url);
}

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

/**
 * //from w ww  . j  a  v  a  2  s.  c o  m
 *
 * @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.gitstudy.rili.liarbry.CalendarLayout.java

/**
 * //from   w w w .ja  v  a2 s  .c o m
 *
 * @return ?
 */
public boolean shrink() {
    if (isAnimating || mContentView == null) {
        return false;
    }
    ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mContentView, "translationY",
            mContentView.getTranslationY(), -mContentViewTranslateY);
    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;
            showWeek();

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

From source file:net.osmand.plus.views.controls.DynamicListView.java

/**
 * Resets all the appropriate fields to a default state while also animating
 * the hover cell back to its correct location.
 *//*from   w w w .j a  v  a 2s .com*/
private void touchEventsEnded() {
    final View mobileView = getViewForID(mMobileItemId);
    if (mCellIsMobile || mIsWaitingForScrollFinish) {
        mCellIsMobile = false;
        mIsWaitingForScrollFinish = false;
        mIsMobileScrolling = false;
        mActivePointerId = INVALID_POINTER_ID;

        // If the autoscroller has not completed scrolling, we need to wait for it to
        // finish in order to determine the final location of where the hover cell
        // should be animated to.
        if (mScrollState != OnScrollListener.SCROLL_STATE_IDLE) {
            mIsWaitingForScrollFinish = true;
            return;
        }

        mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left, mobileView.getTop());

        if (android.os.Build.VERSION.SDK_INT < 12) {
            finishTouch();
        } else {
            /**
             * This TypeEvaluator is used to animate the BitmapDrawable back to its
             * final location when the user lifts his finger by modifying the
             * BitmapDrawable's bounds.
             */
            TypeEvaluator<Rect> sBoundEvaluator = new TypeEvaluator<Rect>() {
                public Rect evaluate(float fraction, Rect startValue, Rect endValue) {
                    return new Rect(interpolate(startValue.left, endValue.left, fraction),
                            interpolate(startValue.top, endValue.top, fraction),
                            interpolate(startValue.right, endValue.right, fraction),
                            interpolate(startValue.bottom, endValue.bottom, fraction));
                }

                public int interpolate(int start, int end, float fraction) {
                    return (int) (start + fraction * (end - start));
                }
            };

            ObjectAnimator hoverViewAnimator = ObjectAnimator.ofObject(mHoverCell, "bounds", sBoundEvaluator,
                    mHoverCellCurrentBounds);
            hoverViewAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    invalidate();
                }
            });
            hoverViewAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationStart(Animator animation) {
                    setEnabled(false);
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    finishTouch();
                }
            });
            hoverViewAnimator.start();
        }
    } else {
        touchEventsCancelled();
    }
}

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

/**
 * ??//w  w w  . ja  va2 s .c  om
 */
final void initStatus() {
    if (mContentView == null) {
        return;
    }
    if ((mDefaultStatus == STATUS_SHRINK || mCalendarShowMode == CALENDAR_SHOW_MODE_ONLY_WEEK_VIEW)
            && mCalendarShowMode != CALENDAR_SHOW_MODE_ONLY_MONTH_VIEW) {
        post(new Runnable() {
            @Override
            public void run() {
                ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mContentView, "translationY",
                        mContentView.getTranslationY(), -mContentViewTranslateY);
                objectAnimator.setDuration(0);
                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;
                        showWeek();

                    }
                });
                objectAnimator.start();
            }
        });
    } else {
        if (mDelegate.mViewChangeListener == null) {
            return;
        }
        post(new Runnable() {
            @Override
            public void run() {
                mDelegate.mViewChangeListener.onViewChange(true);
            }
        });
    }
}

From source file:com.amitupadhyay.aboutexample.ui.widget.BottomSheet.java

private void animateSettle(int initialOffset, final int targetOffset, float initialVelocity) {
    if (settling)
        return;/*w  w w  .j a  v  a 2 s .  c  om*/
    if (sheetOffsetHelper.getTopAndBottomOffset() == targetOffset) {
        if (targetOffset >= dismissOffset) {
            dispatchDismissCallback();
        }
        return;
    }

    settling = true;
    final boolean dismissing = targetOffset == dismissOffset;
    final long duration = computeSettleDuration(initialVelocity, dismissing);
    final ObjectAnimator settleAnim = ObjectAnimator.ofInt(sheetOffsetHelper, ViewOffsetHelper.OFFSET_Y,
            initialOffset, targetOffset);
    settleAnim.setDuration(duration);
    settleAnim.setInterpolator(getSettleInterpolator(dismissing, initialVelocity));
    settleAnim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            dispatchPositionChangedCallback();
            if (dismissing) {
                dispatchDismissCallback();
            }
            settling = false;
        }
    });
    if (callbacks != null && !callbacks.isEmpty()) {
        settleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                if (animation.getAnimatedFraction() > 0f) {
                    dispatchPositionChangedCallback();
                }
            }
        });
    }
    settleAnim.start();
}

From source file:com.lovejjfg.blogdemo.ui.BottomSheet.java

private void animateSettle(int initialOffset, final int targetOffset, long duration) {
    if (settling)
        return;/*from   ww  w.jav  a2s  .  c  o m*/
    if (sheetOffsetHelper.getTopAndBottomOffset() == targetOffset)
        return;

    settling = true;
    final ObjectAnimator settleAnim = ObjectAnimator.ofInt(sheetOffsetHelper, ViewOffsetHelper.OFFSET_Y,
            initialOffset, targetOffset);
    settleAnim.setDuration(duration);
    settleAnim.setInterpolator(AnimUtils.getFastOutSlowInInterpolator(getContext()));
    settleAnim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            dispatchPositionChangedCallback();
            if (targetOffset == dismissOffset) {
                dispatchDismissCallback();
            }
            settling = false;
        }
    });
    if (callbacks != null && !callbacks.isEmpty()) {
        settleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                if (animation.getAnimatedFraction() > 0f) {
                    dispatchPositionChangedCallback();
                }
            }
        });
    }
    settleAnim.start();
}

From source file:com.example.tt.pullrefresh.widget.CurveLayout.java

private void animateSettle(int initialOffset, final int targetOffset, float initialVelocity) {
    if (settling)
        return;/*from  w w  w  . ja  v  a2 s  . c o  m*/
    Log.e(TAG, "animateSettle:TopAndBottom :::" + sheetOffsetHelper.getTopAndBottomOffset());
    if (sheetOffsetHelper.getTopAndBottomOffset() == targetOffset) {
        if (targetOffset >= dismissOffset) {
            dispatchDismissCallback();
        }
        return;
    }

    settling = true;
    final boolean dismissing = targetOffset == dismissOffset;
    final long duration = computeSettleDuration(initialVelocity, dismissing);
    final ObjectAnimator settleAnim = ObjectAnimator.ofInt(sheetOffsetHelper, ViewOffsetHelper.OFFSET_Y,
            initialOffset, targetOffset);
    settleAnim.setDuration(duration);
    settleAnim.setInterpolator(getSettleInterpolator(dismissing, initialVelocity));
    settleAnim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            dispatchPositionChangedCallback();
            if (dismissing) {
                dispatchDismissCallback();
            }
            settling = false;
        }
    });
    if (callbacks != null && !callbacks.isEmpty()) {
        settleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                if (animation.getAnimatedFraction() > 0f) {
                    dispatchPositionChangedCallback();
                }
            }
        });
    }
    settleAnim.start();
}

From source file:com.example.piechart3d.PieChart3DView.java

@Override
protected void onAttachedToWindow() {
    // TODO Auto-generated method stub
    super.onAttachedToWindow();

    ObjectAnimator mXAnimator = ObjectAnimator.ofFloat(mRenderer, "angle_x", 0, maxX);
    mXAnimator.setDuration(2000);//www  .  ja va 2  s  . com

    mXAnimator.addListener(new AnimatorListener() {

        @Override
        public void onAnimationCancel(final Animator animation) {
        }

        @Override
        public void onAnimationEnd(final Animator animation) {
            // progressBar.setProgress(progress);
        }

        @Override
        public void onAnimationRepeat(final Animator animation) {
        }

        @Override
        public void onAnimationStart(final Animator animation) {
        }
    });
    mXAnimator.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(final ValueAnimator animation) {

        }
    });
    LinearInterpolator di = new LinearInterpolator();
    mXAnimator.setInterpolator(di);
    mXAnimator.start();
}