Example usage for android.animation ObjectAnimator setStartDelay

List of usage examples for android.animation ObjectAnimator setStartDelay

Introduction

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

Prototype

@Override
public void setStartDelay(long startDelay) 

Source Link

Document

The amount of time, in milliseconds, to delay starting the animation after #start() is called.

Usage

From source file:com.google.samples.apps.topeka.widget.quiz.AbsQuizView.java

private void animateForegroundColor(@ColorInt final int targetColor) {
    ObjectAnimator animator = ObjectAnimator.ofInt(this, ViewUtils.FOREGROUND_COLOR, Color.TRANSPARENT,
            targetColor);//from ww  w.j  av a 2s .  c  om
    animator.setEvaluator(new ArgbEvaluator());
    animator.setStartDelay(FOREGROUND_COLOR_CHANGE_DELAY);
    animator.start();
}

From source file:com.android.tv.settings.dialog.old.BaseDialogFragment.java

public void performEntryTransition(final Activity activity, final ViewGroup contentView, int iconResourceId,
        Uri iconResourceUri, final ImageView icon, final TextView title, final TextView description,
        final TextView breadcrumb) {
    // Pull out the root layout of the dialog and set the background drawable, to be
    // faded in during the transition.
    final ViewGroup twoPane = (ViewGroup) contentView.getChildAt(0);
    twoPane.setVisibility(View.INVISIBLE);

    // If the appropriate data is embedded in the intent and there is an icon specified
    // in the content fragment, we animate the icon from its initial position to the final
    // position. Otherwise, we perform a simpler transition in which the ActionFragment
    // slides in and the ContentFragment text fields slide in.
    mIntroAnimationInProgress = true;/*w  ww  .jav  a  2  s  .  c  om*/
    List<TransitionImage> images = TransitionImage.readMultipleFromIntent(activity, activity.getIntent());
    TransitionImageAnimation ltransitionAnimation = null;
    final Uri iconUri;
    final int color;
    if (images != null && images.size() > 0) {
        if (iconResourceId != 0) {
            iconUri = Uri.parse(UriUtils.getAndroidResourceUri(activity, iconResourceId));
        } else if (iconResourceUri != null) {
            iconUri = iconResourceUri;
        } else {
            iconUri = null;
        }
        TransitionImage src = images.get(0);
        color = src.getBackground();
        if (iconUri != null) {
            ltransitionAnimation = new TransitionImageAnimation(contentView);
            ltransitionAnimation.addTransitionSource(src);
            ltransitionAnimation.transitionDurationMs(ANIMATE_IN_DURATION).transitionStartDelayMs(0)
                    .interpolator(new DecelerateInterpolator(1f));
        }
    } else {
        iconUri = null;
        color = 0;
    }
    final TransitionImageAnimation transitionAnimation = ltransitionAnimation;

    // Fade out the old activity, and hard cut the new activity.
    activity.overridePendingTransition(R.anim.hard_cut_in, R.anim.fade_out);

    int bgColor = mFragment.getResources().getColor(R.color.dialog_activity_background);
    mBgDrawable.setColor(bgColor);
    mBgDrawable.setAlpha(0);
    twoPane.setBackground(mBgDrawable);

    // If we're animating the icon, we create a new ImageView in which to place the embedded
    // bitmap. We place it in the root layout to match its location in the previous activity.
    mShadowLayer = (FrameLayoutWithShadows) twoPane.findViewById(R.id.shadow_layout);
    if (transitionAnimation != null) {
        transitionAnimation.listener(new TransitionImageAnimation.Listener() {
            @Override
            public void onRemovedView(TransitionImage src, TransitionImage dst) {
                if (icon != null) {
                    //want to make sure that users still see at least the source image
                    // if the dst image is too large to finish downloading before the
                    // animation is done. Check if the icon is not visible. This mean
                    // BaseContentFragement have not finish downloading the image yet.
                    if (icon.getVisibility() != View.VISIBLE) {
                        icon.setImageDrawable(src.getBitmap());
                        int intrinsicWidth = icon.getDrawable().getIntrinsicWidth();
                        LayoutParams lp = icon.getLayoutParams();
                        lp.height = lp.width * icon.getDrawable().getIntrinsicHeight() / intrinsicWidth;
                        icon.setVisibility(View.VISIBLE);
                    }
                    icon.setAlpha(1f);
                }
                if (mShadowLayer != null) {
                    mShadowLayer.setShadowsAlpha(1f);
                }
                onIntroAnimationFinished();
            }
        });
        icon.setAlpha(0f);
        if (mShadowLayer != null) {
            mShadowLayer.setShadowsAlpha(0f);
        }
    }

    // We need to defer the remainder of the animation preparation until the first
    // layout has occurred, as we don't yet know the final location of the icon.
    twoPane.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            twoPane.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            // if we buildLayer() at this time,  the texture is actually not created
            // delay a little so we can make sure all hardware layer is created before
            // animation, in that way we can avoid the jittering of start animation
            twoPane.postOnAnimationDelayed(mEntryAnimationRunnable, ANIMATE_DELAY);
        }

        final Runnable mEntryAnimationRunnable = new Runnable() {
            @Override
            public void run() {
                if (!mFragment.isAdded()) {
                    // We have been detached before this could run, so just bail
                    return;
                }

                twoPane.setVisibility(View.VISIBLE);
                final int secondaryDelay = SLIDE_IN_DISTANCE;

                // Fade in the activity background protection
                ObjectAnimator oa = ObjectAnimator.ofInt(mBgDrawable, "alpha", 255);
                oa.setDuration(ANIMATE_IN_DURATION);
                oa.setStartDelay(secondaryDelay);
                oa.setInterpolator(new DecelerateInterpolator(1.0f));
                oa.start();

                View actionFragmentView = activity.findViewById(mActionAreaId);
                boolean isRtl = ViewCompat.getLayoutDirection(contentView) == ViewCompat.LAYOUT_DIRECTION_RTL;
                int startDist = isRtl ? SLIDE_IN_DISTANCE : -SLIDE_IN_DISTANCE;
                int endDist = isRtl ? -actionFragmentView.getMeasuredWidth()
                        : actionFragmentView.getMeasuredWidth();

                // Fade in and slide in the ContentFragment TextViews from the start.
                prepareAndAnimateView(title, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION,
                        new DecelerateInterpolator(1.0f), false);
                prepareAndAnimateView(breadcrumb, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION,
                        new DecelerateInterpolator(1.0f), false);
                prepareAndAnimateView(description, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION,
                        new DecelerateInterpolator(1.0f), false);

                // Fade in and slide in the ActionFragment from the end.
                prepareAndAnimateView(actionFragmentView, 0, endDist, secondaryDelay, ANIMATE_IN_DURATION,
                        new DecelerateInterpolator(1.0f), false);

                if (icon != null && transitionAnimation != null) {
                    // now we get the icon view in place,  update the transition target
                    TransitionImage target = new TransitionImage();
                    target.setUri(iconUri);
                    target.createFromImageView(icon);
                    if (icon.getBackground() instanceof ColorDrawable) {
                        ColorDrawable d = (ColorDrawable) icon.getBackground();
                        target.setBackground(d.getColor());
                    }
                    transitionAnimation.addTransitionTarget(target);
                    transitionAnimation.startTransition();
                } else if (icon != null) {
                    prepareAndAnimateView(icon, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION,
                            new DecelerateInterpolator(1.0f), true /* is the icon */);
                    if (mShadowLayer != null) {
                        mShadowLayer.setShadowsAlpha(0f);
                    }
                }
            }
        };
    });
}

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;//from  w  ww.j  a va  2  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:com.grepsound.activities.MainActivity.java

/**
 * 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.
 *//*  www.j a v  a  2 s .  c om*/
public void slideBack(Animator.AnimatorListener listener) {

    // Make sure Toolbar is visible
    mToolbar.setTranslationY(0);

    View movingFragmentView = mMainFrag.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();
}

From source file:com.grepsound.activities.MainActivity.java

/**
 * 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.
 *///from w  w w .  ja  v  a2 s.c  o  m
public void slideForward(Animator.AnimatorListener listener) {
    View movingFragmentView = mMainFrag.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();
}

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

private ObjectAnimator startAnimator(View labelToAnimate, float decreaseRatio, float increaseRatio) {
    ObjectAnimator pulseAnimator = Utils.getPulseAnimator(labelToAnimate, decreaseRatio, increaseRatio);
    if (mDelayAnimation) {
        if (pulseAnimator != null) {
            pulseAnimator.setStartDelay(ANIMATION_DELAY);
        }//from   w  ww.  ja v  a 2s .c  om
        mDelayAnimation = false;
    }
    return pulseAnimator;
}

From source file:com.ibm.mil.readyapps.physio.fragments.LandingFragment.java

private void animateMetricsOut(boolean isInitial) {
    int delay = 0;
    if (isInitial) {
        delay = INIT_DELAY;/*from   w  ww  .  j  a v a 2s .c o  m*/
    }

    ObjectAnimator weightSlideOutAnimator = ObjectAnimator.ofFloat(weightTab, "translationX",
            1f + SLIDE_OFFSET);
    ObjectAnimator heartRateSlideOutAnimator = ObjectAnimator.ofFloat(heartRateTab, "translationX",
            1f + SLIDE_OFFSET);
    ObjectAnimator stepsSlideOutAnimator = ObjectAnimator.ofFloat(stepsTab, "translationX", 1f + SLIDE_OFFSET);

    heartRateSlideOutAnimator.setDuration(ANIM_SPEED * 2);
    heartRateSlideOutAnimator.setStartDelay(ANIM_SPEED * 2);

    weightSlideOutAnimator.setDuration(ANIM_SPEED * 2);
    weightSlideOutAnimator.setStartDelay(delay);

    stepsSlideOutAnimator.setDuration(ANIM_SPEED * 2);
    stepsSlideOutAnimator.setStartDelay(ANIM_SPEED);

    AnimatorSet outAnimation = new AnimatorSet();
    outAnimation.play(weightSlideOutAnimator).with(stepsSlideOutAnimator).with(heartRateSlideOutAnimator);
    outAnimation.start();
}

From source file:com.ibm.mil.readyapps.physio.fragments.LandingFragment.java

private void animateMetricsIn(boolean isInitial) {
    int delay = 0;
    if (isInitial) {
        delay = INIT_DELAY;//from   w  w w.  j ava2s  .c  om
    }

    ObjectAnimator heartRateSlideInAnimator = ObjectAnimator.ofFloat(heartRateTab, "translationX", 1f);
    ObjectAnimator weightSlideInAnimator = ObjectAnimator.ofFloat(weightTab, "translationX", 1f);
    ObjectAnimator stepsSlideInAnimator = ObjectAnimator.ofFloat(stepsTab, "translationX", 1f);

    heartRateSlideInAnimator.setDuration(ANIM_SPEED * 2);
    heartRateSlideInAnimator.setStartDelay(delay);

    weightSlideInAnimator.setDuration(ANIM_SPEED * 2);
    weightSlideInAnimator.setStartDelay(delay + (ANIM_SPEED * 2));

    stepsSlideInAnimator.setDuration(ANIM_SPEED * 2);
    stepsSlideInAnimator.setStartDelay(delay + ANIM_SPEED);

    AnimatorSet slideIn = new AnimatorSet();
    slideIn.play(heartRateSlideInAnimator).with(stepsSlideInAnimator).with(weightSlideInAnimator);
    slideIn.start();
}

From source file:com.example.android.tryanimationt.TryAnimationFragment.java

void animButtons(ImageButton bt, boolean in, int animTime, int delay) {

    //delay = 0;// www  .  ja va  2 s.  com

    float rotateStart, rotateEnd;
    float scaleXStart, scaleXEnd;
    float scaleYStart, scaleYEnd;
    float transitionXStart, transitionXEnd;
    float transitionYStart, transitionYEnd;

    if (in) {
        rotateStart = 0;
        rotateEnd = 359;
        scaleXStart = 0.66f;
        scaleXEnd = 1;
        scaleYStart = 0.66f;
        scaleYEnd = 1;
        transitionXStart = 60;
        transitionXEnd = 0;
        transitionYStart = 10;
        transitionYEnd = 0;

    } else {
        rotateStart = 359;
        rotateEnd = 0;
        scaleXStart = 1;
        scaleXEnd = 0.66f;
        scaleYStart = 1;
        scaleYEnd = 0.66f;
        transitionXStart = 0;
        transitionXEnd = 60;
        transitionYStart = 0;
        transitionYEnd = 10;
    }
    bt.setTranslationX(transitionXStart);
    bt.setTranslationY(transitionYStart);

    AnimatorSet animSet = new AnimatorSet();
    ObjectAnimator animRotate = ObjectAnimator.ofFloat(bt, "rotation", rotateStart, rotateEnd);
    animRotate.setDuration(animTime);

    ObjectAnimator animScaleX = ObjectAnimator.ofFloat(bt, "scaleX", scaleXStart, scaleXEnd);
    animScaleX.setDuration(animTime);
    animScaleX.setStartDelay(Math.round(delay * 0.66));
    ObjectAnimator animScaleY = ObjectAnimator.ofFloat(bt, "scaleY", scaleYStart, scaleYEnd);
    animScaleY.setDuration(animTime);
    animScaleY.setStartDelay(Math.round(delay * 0.66));

    ObjectAnimator animTrx = ObjectAnimator.ofFloat(bt, "translationX", transitionXStart, transitionXEnd);
    animTrx.setDuration(animTime);
    animTrx.setStartDelay(delay);
    ObjectAnimator animTry = ObjectAnimator.ofFloat(bt, "translationY", transitionYStart, transitionYEnd);
    animTry.setDuration(animTime);
    animTry.setStartDelay(delay);

    animSet.setInterpolator(new BounceInterpolator());
    animSet.playTogether(animRotate, animScaleX, animScaleY, animTrx, animTry);

    animSet.start();
}

From source file:com.taobao.weex.ui.animation.WXAnimationModule.java

private static @Nullable ObjectAnimator createAnimator(@NonNull WXAnimationBean animation, final View target,
        final int viewPortWidth) {
    if (target == null) {
        return null;
    }//from  w  w  w.j a v a 2 s.  c o m
    WXAnimationBean.Style style = animation.styles;
    if (style != null) {
        ObjectAnimator animator;
        List<PropertyValuesHolder> holders = style.getHolders();
        if (!TextUtils.isEmpty(style.backgroundColor)) {
            BorderDrawable borderDrawable;
            if ((borderDrawable = WXViewUtils.getBorderDrawable(target)) != null) {
                holders.add(PropertyValuesHolder.ofObject(WXAnimationBean.Style.BACKGROUND_COLOR,
                        new ArgbEvaluator(), borderDrawable.getColor(),
                        WXResourceUtils.getColor(style.backgroundColor)));
            } else if (target.getBackground() instanceof ColorDrawable) {
                holders.add(PropertyValuesHolder.ofObject(WXAnimationBean.Style.BACKGROUND_COLOR,
                        new ArgbEvaluator(), ((ColorDrawable) target.getBackground()).getColor(),
                        WXResourceUtils.getColor(style.backgroundColor)));
            }
        }
        if (style.getPivot() != null) {
            Pair<Float, Float> pair = style.getPivot();
            target.setPivotX(pair.first);
            target.setPivotY(pair.second);
        }
        animator = ObjectAnimator.ofPropertyValuesHolder(target,
                holders.toArray(new PropertyValuesHolder[holders.size()]));
        animator.setStartDelay(animation.delay);
        if (target.getLayoutParams() != null
                && (!TextUtils.isEmpty(style.width) || !TextUtils.isEmpty(style.height))) {
            DimensionUpdateListener listener = new DimensionUpdateListener(target);
            ViewGroup.LayoutParams layoutParams = target.getLayoutParams();
            if (!TextUtils.isEmpty(style.width)) {
                listener.setWidth(layoutParams.width,
                        (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.width), viewPortWidth));
            }
            if (!TextUtils.isEmpty(style.height)) {
                listener.setHeight(layoutParams.height,
                        (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.height), viewPortWidth));
            }
            animator.addUpdateListener(listener);
        }
        return animator;
    } else {
        return null;
    }
}