Example usage for android.animation ObjectAnimator start

List of usage examples for android.animation ObjectAnimator start

Introduction

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

Prototype

@Override
    public void start() 

Source Link

Usage

From source file:com.android.contacts.activities.PhotoSelectionActivity.java

private void closePhotoAndFinish() {
    mAnimationListener = new AnimatorListenerAdapter() {
        @Override/*from  w w w  .j a  va  2 s . c  o m*/
        public void onAnimationEnd(Animator animation) {
            // After the photo animates down, fade it away and finish.
            ObjectAnimator anim = ObjectAnimator.ofFloat(mPhotoView, "alpha", 0f)
                    .setDuration(PHOTO_CONTRACT_DURATION);
            anim.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    finishImmediatelyWithNoAnimation();
                }
            });
            anim.start();
        }
    };

    animatePhoto(mPhotoStartParams);
    animateAwayBackground();
}

From source file:com.telenav.expandablepager.SlidingContainer.java

/**
 * Animate translationY to the next stopValue
 * @param amount translationY amount/*from w w w .j  a va 2s  . c  om*/
 * @param duration animation duration
 * @param interpolator  animation interpolator
 */
private void animate(final float amount, int duration, Interpolator interpolator) {
    ObjectAnimator oa = ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, amount).setDuration(duration);
    oa.setInterpolator(interpolator);
    oa.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            notifySlideEvent(Math.round(((Float) animation.getAnimatedValue())));
        }
    });
    oa.addListener(new CustomAnimationListener() {
        @Override
        public void onAnimationEnd(Animator animator) {
            onSettled(stopValueIndex);
        }
    });
    oa.start();
}

From source file:Main.java

private static void setupChangeAnimationOneTime(final View view) {
    ObjectAnimator objectAnimator = sMapAnimators.get(view);
    if (objectAnimator != null) {
        objectAnimator.cancel();//from   w  ww.j a  v a 2s .c om
        sMapAnimators.remove(objectAnimator);
    }
    OnLayoutChangeListener listener = sMapListeners.get(view);
    if (listener != null) {
        view.removeOnLayoutChangeListener(listener);
        sMapListeners.remove(view);
    }

    final OnLayoutChangeListener onLayoutChangeListener = new OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {

            ObjectAnimator objectAnimator = sMapAnimators.get(view);
            if (objectAnimator != null) {
                objectAnimator.cancel();
                sMapAnimators.remove(objectAnimator);
            }

            final ObjectAnimator changeAnimator = getChangeAnimator(v, left, top, right, bottom, oldLeft,
                    oldTop, oldRight, oldBottom);

            sMapAnimators.put(view, changeAnimator);

            if (left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom) {
                Animator.AnimatorListener animatorListener = new Animator.AnimatorListener() {

                    @Override
                    public void onAnimationStart(Animator animation) {
                        if (sAnimatorListener != null) {
                            sAnimatorListener.onAnimationStart(animation);
                        }
                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {
                        if (sAnimatorListener != null) {
                            sAnimatorListener.onAnimationRepeat(animation);
                        }
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        sMapAnimators.remove(view);
                        if (sAnimatorListener != null) {
                            sAnimatorListener.onAnimationEnd(animation);
                        }
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {
                        if (sAnimatorListener != null) {
                            sAnimatorListener.onAnimationCancel(animation);
                        }
                    }
                };
                changeAnimator.addListener(animatorListener);

                changeAnimator.start();
            } else {
                sMapAnimators.remove(view);
                if (sAnimatorListener != null) {
                    sAnimatorListener.onAnimationEnd(changeAnimator);
                }
            }
        }
    };
    view.addOnLayoutChangeListener(onLayoutChangeListener);
    sMapListeners.put(view, onLayoutChangeListener);
}

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

/**
 * This method determines whether the hover cell has been shifted far enough
 * to invoke a cell swap. If so, then the respective cell swap candidate is
 * determined and the data set is changed. Upon posting a notification of the
 * data set change, a layout is invoked to place the cells in the right place.
 * Using a ViewTreeObserver and a corresponding OnPreDrawListener, we can
 * offset the cell being swapped to where it previously was and then animate it to
 * its new position.//from ww  w.  j a v  a2  s  .  c  om
 */
private void handleCellSwitch() {
    final int deltaY = mLastEventY - mDownY;
    final int deltaYTotal = mHoverCellOriginalBounds.top + mTotalOffset + deltaY;

    View belowView = getViewForID(mBelowItemId);
    View mobileView = getViewForID(mMobileItemId);
    View aboveView = getViewForID(mAboveItemId);

    boolean isBelow = (belowView != null) && (deltaYTotal > belowView.getTop());
    boolean isAbove = (aboveView != null) && (deltaYTotal < aboveView.getTop());

    if (isBelow || isAbove) {

        final long switchItemID = isBelow ? mBelowItemId : mAboveItemId;
        View switchView = isBelow ? belowView : aboveView;
        final int originalItem = getPositionForView(mobileView) - getHeaderViewsCount();
        final int switchItem = getPositionForView(switchView) - getHeaderViewsCount();
        swapElements(originalItem, switchItem);

        getStableAdapter().notifyDataSetChanged();

        mDownY = mLastEventY;

        final int switchViewStartTop = switchView.getTop();

        if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.KITKAT) {
            mobileView.setVisibility(View.VISIBLE);
            switchView.setVisibility(View.INVISIBLE);
        }
        updateNeighborViewsForID(mMobileItemId);

        final ViewTreeObserver observer = getViewTreeObserver();
        observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            public boolean onPreDraw() {
                observer.removeOnPreDrawListener(this);

                View switchView = getViewForID(switchItemID);

                mTotalOffset += deltaY;

                int switchViewNewTop = switchView.getTop();
                int delta = switchViewStartTop - switchViewNewTop;

                ViewCompat.setTranslationY(switchView, delta);

                if (android.os.Build.VERSION.SDK_INT < 12) {
                    ViewCompat.animate(switchView).translationY(0).setDuration(MOVE_DURATION);
                } else {
                    ObjectAnimator animator = ObjectAnimator.ofFloat(switchView, View.TRANSLATION_Y, 0);
                    animator.setDuration(MOVE_DURATION);
                    animator.start();
                }

                return true;
            }
        });
    }
}

From source file:com.betterAlarm.deskclock.DeskClock.java

private void setBackgroundColor() {
    final int duration;
    if (mLastHourColor == UNKNOWN_COLOR_ID) {
        mLastHourColor = getResources().getColor(R.color.default_background);
        duration = BACKGROUND_COLOR_INITIAL_ANIMATION_DURATION_MILLIS;
    } else {/*from   www  . j  a v a2s .  co  m*/
        duration = getResources().getInteger(android.R.integer.config_longAnimTime);
    }
    final int currHourColor = Utils.getCurrentHourColor();
    if (mLastHourColor != currHourColor) {
        final ObjectAnimator animator = ObjectAnimator.ofInt(getWindow().getDecorView(), "backgroundColor",
                mLastHourColor, currHourColor);
        animator.setDuration(duration);
        animator.setEvaluator(new ArgbEvaluator());
        animator.start();
        mLastHourColor = currHourColor;
    }
}

From source file:com.justplay1.shoppist.features.search.widget.FloatingSearchView.java

private void fadeIn(boolean enter) {
    ValueAnimator backgroundAnim;/*  w  ww.ja  va2  s.c om*/

    if (Build.VERSION.SDK_INT >= 19) {
        backgroundAnim = ObjectAnimator.ofInt(backgroundDrawable, "alpha", enter ? 255 : 0);
    } else {
        backgroundAnim = ValueAnimator.ofInt(enter ? 0 : 255, enter ? 255 : 0);
        backgroundAnim.addUpdateListener(animation -> {
            int value = (Integer) animation.getAnimatedValue();
            backgroundDrawable.setAlpha(value);
        });
    }

    backgroundAnim.setDuration(enter ? DEFAULT_DURATION_ENTER : DEFAULT_DURATION_EXIT);
    backgroundAnim.setInterpolator(enter ? DECELERATE : ACCELERATE);
    backgroundAnim.start();

    Drawable icon = unwrap(getIcon());

    if (icon != null) {
        ObjectAnimator iconAnim = ObjectAnimator.ofFloat(icon, "progress", enter ? 1 : 0);
        iconAnim.setDuration(backgroundAnim.getDuration());
        iconAnim.setInterpolator(backgroundAnim.getInterpolator());
        iconAnim.start();
    }
}

From source file:com.phonemetra.deskclock.DeskClock.java

private void setBackgroundColor() {
    final int duration;
    if (mLastHourColor == UNKNOWN_COLOR_ID) {
        mLastHourColor = getResources().getColor(R.color.default_background);
        duration = BACKGROUND_COLOR_INITIAL_ANIMATION_DURATION_MILLIS;
    } else {/*from  ww  w.ja v a2s .  co  m*/
        duration = getResources().getInteger(android.R.integer.config_longAnimTime);
    }
    final int currHourColor = Utils.getCurrentHourColor(this);
    if (mLastHourColor != currHourColor) {
        final ObjectAnimator animator = ObjectAnimator.ofInt(getWindow().getDecorView(), "backgroundColor",
                mLastHourColor, currHourColor);
        animator.setDuration(duration);
        animator.setEvaluator(new ArgbEvaluator());
        animator.start();
        mLastHourColor = currHourColor;
    }
}

From source file:com.sinyuk.jianyimaterial.widgets.FloatingToolbar.java

@TargetApi(21)
private void showLollipopImpl() {
    int rootWidth = mRoot.getWidth();

    float endFabX;
    float controlX;

    if (mFabOriginalX > rootWidth / 2f) {
        endFabX = rootWidth / 2f + (mFabOriginalX - rootWidth / 2f) / 4f;
        controlX = mFabOriginalX * 0.98f;
    } else {//w  w w.j  a v a 2s . c  o m
        endFabX = rootWidth / 2f - (mFabOriginalX - rootWidth / 2f) / 4f;
        controlX = mFabOriginalX * 1.02f;
    }

    /**
     * Animate FAB movement
     */
    final Path path = new Path();
    path.moveTo(mFab.getX(), mFab.getY());
    final float x2 = controlX;
    final float y2 = getY();
    path.quadTo(x2, y2, endFabX, getY());
    ObjectAnimator anim = ObjectAnimator.ofFloat(mFab, View.X, View.Y, path);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_MORPH_DURATION);
    anim.start();

    /**
     * Fade FAB drawable
     */
    Drawable drawable = mFab.getDrawable();
    if (drawable != null) {
        anim = ObjectAnimator.ofPropertyValuesHolder(drawable, PropertyValuesHolder.ofInt("alpha", 0));
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.setDuration((long) (FAB_MORPH_DURATION / 3f));
        anim.start();
    }

    /**
     * Animate FAB elevation to 8dp
     */
    anim = ObjectAnimator.ofFloat(mFab, View.TRANSLATION_Z, dpToPixels(2));
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_MORPH_DURATION);
    anim.start();

    /**
     * Create circular reveal
     */
    Animator toolbarReveal = ViewAnimationUtils.createCircularReveal(this, getWidth() / 2, getHeight() / 2,
            (float) mFab.getWidth() / 2f, (float) (Math.hypot(getWidth() / 2, getHeight() / 2)));

    toolbarReveal.setDuration(CIRCULAR_REVEAL_DURATION);
    toolbarReveal.setTarget(this);
    toolbarReveal.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
            mFab.setVisibility(View.INVISIBLE);
            setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            mMorphing = false;
        }
    });

    toolbarReveal.setInterpolator(new AccelerateInterpolator());
    toolbarReveal.setStartDelay(CIRCULAR_REVEAL_DELAY);
    toolbarReveal.start();

    /**
     * Animate FloatingToolbar elevation to 8dp
     */
    anim = ObjectAnimator.ofFloat(this, View.TRANSLATION_Z, dpToPixels(2));
    anim.setDuration(CIRCULAR_REVEAL_DURATION);
    anim.setStartDelay(CIRCULAR_REVEAL_DELAY);
    anim.start();
}

From source file:com.android.datetimepicker.date.DatePickerDialog.java

private void setCurrentView(final int viewIndex) {
    long millis = mCalendar.getTimeInMillis();

    switch (viewIndex) {
    case MONTH_AND_DAY_VIEW:
        ObjectAnimator pulseAnimator = Utils.getPulseAnimator(mMonthAndDayView, 0.9f, 1.05f);
        if (mDelayAnimation) {
            pulseAnimator.setStartDelay(ANIMATION_DELAY);
            mDelayAnimation = false;// w  ww  . j a v a2  s  .c om
        }
        mDayPickerView.onDateChanged();
        if (mCurrentView != viewIndex) {
            mMonthAndDayView.setSelected(true);
            mYearView.setSelected(false);
            mAnimator.setDisplayedChild(MONTH_AND_DAY_VIEW);
            mCurrentView = viewIndex;
        }
        pulseAnimator.start();

        int flags = DateUtils.FORMAT_SHOW_DATE;
        String dayString = DateUtils.formatDateTime(getActivity(), millis, flags);
        mAnimator.setContentDescription(mDayPickerDescription + ": " + dayString);
        Utils.tryAccessibilityAnnounce(mAnimator, mSelectDay);
        break;
    case YEAR_VIEW:
        pulseAnimator = Utils.getPulseAnimator(mYearView, 0.85f, 1.1f);
        if (mDelayAnimation) {
            pulseAnimator.setStartDelay(ANIMATION_DELAY);
            mDelayAnimation = false;
        }
        mYearPickerView.onDateChanged();
        if (mCurrentView != viewIndex) {
            mMonthAndDayView.setSelected(false);
            mYearView.setSelected(true);
            mAnimator.setDisplayedChild(YEAR_VIEW);
            mCurrentView = viewIndex;
        }
        pulseAnimator.start();

        CharSequence yearString = YEAR_FORMAT.format(millis);
        mAnimator.setContentDescription(mYearPickerDescription + ": " + yearString);
        Utils.tryAccessibilityAnnounce(mAnimator, mSelectYear);
        break;
    }
}

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

@Override
public FilterViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
    final FilterViewHolder holder = new FilterViewHolder(
            LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.filter_item, viewGroup, false));
    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override// w w w  . j  a  v  a 2  s  .c  o m
        public void onClick(View v) {
            final int position = holder.getAdapterPosition();
            if (position == RecyclerView.NO_POSITION)
                return;
            final Source filter = filters.get(position);
            if (isAuthorisedDribbbleSource(filter)
                    && !DribbblePrefs.get(holder.itemView.getContext()).isLoggedIn()) {
                authoriser.requestDribbbleAuthorisation(holder.filterIcon, filter);
            } else {
                holder.itemView.setHasTransientState(true);
                ObjectAnimator fade = ObjectAnimator.ofInt(holder.filterIcon, ViewUtils.IMAGE_ALPHA,
                        filter.active ? FILTER_ICON_DISABLED_ALPHA : FILTER_ICON_ENABLED_ALPHA);
                fade.setDuration(300);
                fade.setInterpolator(AnimationUtils.loadInterpolator(holder.itemView.getContext(),
                        android.R.interpolator.fast_out_slow_in));
                fade.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        holder.itemView.setHasTransientState(false);
                    }
                });
                fade.start();
                filter.active = !filter.active;
                holder.filterName.setEnabled(filter.active);
                notifyItemChanged(position);
                SourceManager.updateSource(filter, holder.itemView.getContext());
                dispatchFiltersChanged(filter);
            }
        }
    });
    return holder;
}