Example usage for android.animation ValueAnimator setDuration

List of usage examples for android.animation ValueAnimator setDuration

Introduction

In this page you can find the example usage for android.animation ValueAnimator setDuration.

Prototype

@Override
public ValueAnimator setDuration(long duration) 

Source Link

Document

Sets the length of the animation.

Usage

From source file:com.jsibbold.zoomage.ZoomageView.java

private void animateMatrixIndex(final int index, final float to) {
    ValueAnimator animator = ValueAnimator.ofFloat(mValues[index], to);
    animator.addUpdateListener(new AnimatorUpdateListener() {

        final float[] values = new float[9];
        Matrix current = new Matrix();

        @Override/* w w  w .j av a  2s  . c o  m*/
        public void onAnimationUpdate(ValueAnimator animation) {
            current.set(getImageMatrix());
            current.getValues(values);
            values[index] = (Float) animation.getAnimatedValue();
            current.setValues(values);
            setImageMatrix(current);
        }
    });
    animator.setDuration(RESET_DURATION);
    animator.start();
}

From source file:android.support.graphics.drawable.AnimatorInflaterCompat.java

/**
 * @param anim                The animator, must not be null
 * @param arrayAnimator       Incoming typed array for Animator's attributes.
 * @param arrayObjectAnimator Incoming typed array for Object Animator's
 *                            attributes.
 * @param pixelSize           The relative pixel size, used to calculate the
 *                            maximum error for path animations.
 *//* w  w  w  . j av a 2s .  c  o  m*/
private static void parseAnimatorFromTypeArray(ValueAnimator anim, TypedArray arrayAnimator,
        TypedArray arrayObjectAnimator, float pixelSize, XmlPullParser parser) {
    long duration = TypedArrayUtils.getNamedInt(arrayAnimator, parser, "duration",
            AndroidResources.STYLEABLE_ANIMATOR_DURATION, 300);
    long startDelay = TypedArrayUtils.getNamedInt(arrayAnimator, parser, "startOffset",
            AndroidResources.STYLEABLE_ANIMATOR_START_OFFSET, 0);
    int valueType = TypedArrayUtils.getNamedInt(arrayAnimator, parser, "valueType",
            AndroidResources.STYLEABLE_ANIMATOR_VALUE_TYPE, VALUE_TYPE_UNDEFINED);

    // Change to requiring both value from and to, otherwise, throw exception for now.
    if (TypedArrayUtils.hasAttribute(parser, "valueFrom") && TypedArrayUtils.hasAttribute(parser, "valueTo")) {
        if (valueType == VALUE_TYPE_UNDEFINED) {
            valueType = inferValueTypeFromValues(arrayAnimator, AndroidResources.STYLEABLE_ANIMATOR_VALUE_FROM,
                    AndroidResources.STYLEABLE_ANIMATOR_VALUE_TO);
        }
        PropertyValuesHolder pvh = getPVH(arrayAnimator, valueType,
                AndroidResources.STYLEABLE_ANIMATOR_VALUE_FROM, AndroidResources.STYLEABLE_ANIMATOR_VALUE_TO,
                "");
        if (pvh != null) {
            anim.setValues(pvh);
        }
    }
    anim.setDuration(duration);
    anim.setStartDelay(startDelay);

    anim.setRepeatCount(TypedArrayUtils.getNamedInt(arrayAnimator, parser, "repeatCount",
            AndroidResources.STYLEABLE_ANIMATOR_REPEAT_COUNT, 0));
    anim.setRepeatMode(TypedArrayUtils.getNamedInt(arrayAnimator, parser, "repeatMode",
            AndroidResources.STYLEABLE_ANIMATOR_REPEAT_MODE, ValueAnimator.RESTART));

    if (arrayObjectAnimator != null) {
        setupObjectAnimator(anim, arrayObjectAnimator, valueType, pixelSize, parser);
    }
}

From source file:com.geecko.QuickLyric.adapter.IntroScreenSlidePagerAdapter.java

public IntroScreenSlidePagerAdapter(FragmentManager fm, final Activity activity) {
    super(fm);//from  ww w. jav a 2 s  .  co  m
    this.mActivity = activity;
    mPager = ((ViewPager) mActivity.findViewById(R.id.pager));
    mPager.setOnTouchListener(exitTouchListener);
    if (Build.VERSION.SDK_INT >= 17)
        rightToLeft = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == 1;
    if (rightToLeft) {
        List<Integer> list = Arrays.asList(colors);
        Collections.reverse(list);
        colors = (Integer[]) list.toArray();
    }
    ImageButton pagerArrow = ((ImageButton) mActivity.findViewById(R.id.pager_arrow));
    Button okButton = ((Button) mActivity.findViewById(R.id.pager_ok));
    okButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && !Tutorial_5.nlEnabled) {
                final ViewGroup nlFrame = (ViewGroup) activity.findViewById(R.id.NL_frame);
                final ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
                        Color.parseColor("#30000000"), Color.parseColor("#80FFFFFF"));
                colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        nlFrame.setBackgroundColor((int) animation.getAnimatedValue());
                    }
                });
                colorAnimation.setInterpolator(new LinearOutSlowInInterpolator());
                colorAnimation.setRepeatCount(3);
                colorAnimation.setRepeatMode(ValueAnimator.REVERSE);
                colorAnimation.setDuration(650L);
                colorAnimation.start();
            } else if (!hasClicked) {
                exitAction();
                hasClicked = true;
            }
        }
    });
    pagerArrow.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            nextAction();
        }
    });
}

From source file:nl.thehyve.transmartclient.MainActivity.java

private void animateToArrow(boolean toArrow) {
    int start, stop;
    if (toArrow) {
        start = 0;//from ww w  .  j av a2 s. c  o m
        stop = 1;
    } else {
        start = 1;
        stop = 0;
    }
    ValueAnimator anim = ValueAnimator.ofFloat(start, stop);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float slideOffset = (Float) valueAnimator.getAnimatedValue();
            toggle.onDrawerSlide(drawer, slideOffset);
        }
    });
    anim.setInterpolator(new DecelerateInterpolator());
    anim.setDuration(300);
    anim.start();
}

From source file:com.shopify.buy.ui.ProductDetailsFragmentView.java

@Override
public void setImageAreaSize(final boolean grow) {
    final int finalHeight = grow ? getHeight() : imageAreaHeight;

    // hide or show the checkout button
    if (grow && !imageAreaIsExpanded) {
        hideCheckoutButton(IMAGE_AREA_FEATURES_ANIMATION_DURATION);
    } else if (!grow && imageAreaIsExpanded) {
        showCheckoutButton(IMAGE_AREA_FEATURES_ANIMATION_DURATION);
    }//  www .  j  av a2s .c  o m

    // Animate the image changing size
    ValueAnimator anim = ValueAnimator.ofInt(imageAreaWrapper.getHeight(), finalHeight);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams containerLayoutParams = imageAreaWrapper.getLayoutParams();
            containerLayoutParams.height = val;
            imageAreaWrapper.setLayoutParams(containerLayoutParams);
        }

    });
    anim.setDuration(IMAGE_AREA_FEATURES_ANIMATION_DURATION);

    // Disable touch handler for duration of image resizing
    imagePager.setOnTouchListener(null);
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);

            // Re-enable the touch handle on the image
            imagePager.setOnTouchListener(imageAreaTouchHandler);

            if (grow) {
                onExpandImageArea();
            } else {
                onCollapseImageArea();
            }
        }
    });

    anim.start();
}

From source file:com.quanliren.quan_one.pull.swipe.SwipeRefreshLayout.java

private ValueAnimator startAlphaAnimation(final int startingAlpha, final int endingAlpha) {
    // Pre API 11, alpha is used in place of scale. Don't also use it to
    // show the trigger point.
    if (mScale && isAlphaUsedForScale()) {
        return null;
    }//www .  j a v  a2s .c om
    ValueAnimator alpha = new ObjectAnimator().ofFloat(0f, 1f);
    alpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mProgress.setAlpha((int) (startingAlpha + ((endingAlpha - startingAlpha)
                    * Float.valueOf(animation.getAnimatedValue().toString()))));
        }
    });
    alpha.setDuration(ALPHA_ANIMATION_DURATION);
    alpha.start();
    return alpha;
}

From source file:com.velli.passwordmanager.ActivityMain.java

public boolean lockDrawer(final boolean lock, boolean animate) {
    final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    boolean locked = isDrawerLocked();

    if (drawer != null && lock != locked) {
        if (lock) {
            drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        } else {// w  w  w .j a  va2 s .com
            drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
            if (!animate) {
                initDrawer();
            }
        }

        if (animate) {
            final ValueAnimator anim = ValueAnimator.ofFloat(lock ? 0 : 1, lock ? 1 : 0);
            anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    float slideOffset = (Float) valueAnimator.getAnimatedValue();
                    mToolbarDrawerToggle.onDrawerSlide(drawer, slideOffset);
                }
            });
            anim.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    anim.removeAllUpdateListeners();
                    if (!lock) {
                        initDrawer();
                    }
                    animation.removeAllListeners();
                }
            });
            anim.setInterpolator(new DecelerateInterpolator());
            anim.setDuration(500);
            anim.start();
        } else {
            mToolbarDrawerToggle.onDrawerSlide(drawer, lock ? 1 : 0);

        }
        return true;
    }
    return false;
}

From source file:org.protocoderrunner.apprunner.api.PUI.java

@ProtocoderScript
@APIMethod(description = "Makes the view jump", example = "")
@APIParam(params = { "View" })
public void jump(View v) {

    ValueAnimator w = ObjectAnimator.ofFloat(v, "scaleX", 1f, 0.9f, 1.2f, 1f);
    w.setDuration(AppSettings.animGeneralSpeed);

    ValueAnimator h = ObjectAnimator.ofFloat(v, "scaleY", 1f, 0.9f, 1.2f, 1f);
    h.setDuration(AppSettings.animGeneralSpeed);

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(w).with(h);//ww w.j  av a2  s . c  o  m
    animatorSet.start();
}

From source file:co.ceryle.segmentedbutton.SegmentedButtonGroup.java

private void expand(final View v, Interpolator interpolator, int duration, int targetWidth) {

    int prevWidth = v.getWidth();

    ValueAnimator valueAnimator = ValueAnimator.ofInt(prevWidth, targetWidth);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override//from   ww  w  .  j  av a 2  s  . co m
        public void onAnimationUpdate(ValueAnimator animation) {
            v.getLayoutParams().width = (int) animation.getAnimatedValue();
            v.requestLayout();
        }
    });
    valueAnimator.setInterpolator(interpolator);
    valueAnimator.setDuration(duration);
    valueAnimator.start();
}

From source file:org.protocoderrunner.apprunner.api.PUI.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@ProtocoderScript//  w w  w  .  j a v  a 2 s  . c  om
@APIParam(params = { "View" })
public void reveal(final View v) {
    // previously invisible view

    // get the center for the clipping circle
    int cx = (v.getLeft() + v.getRight()) / 2;
    int cy = (v.getTop() + v.getBottom()) / 2;

    // get the final radius for the clipping circle
    int finalRadius = v.getWidth();

    // create and start the animator for this view
    // (the start radius is zero)
    ValueAnimator anim = (ValueAnimator) ViewAnimationUtils.createCircularReveal(v, cx, cy, 0, finalRadius);

    anim.setDuration(1000);
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
            v.setVisibility(View.VISIBLE);
        }
    });
    anim.start();
}