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:nuclei.ui.view.ButtonBarView.java

private void setSelected(final Item item, boolean selected) {
    if (mItems.length < 5)
        return;/*  w w w  .j  a va2s.c  om*/
    if (selected) {
        item.imageView.setColorFilter(mSelectedTint, PorterDuff.Mode.SRC_ATOP);
        if (item.textView != null) {
            item.textView.setTextColor(mSelectedTint);
            item.textView.setVisibility(View.VISIBLE);
            item.textView.setTextSize(0);
            ValueAnimator animator = mLabelAnimators.get(item);
            if (animator != null)
                animator.cancel();
            animator = new ValueAnimator();
            mLabelAnimators.put(item, animator);
            animator.setDuration(200);
            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    int animatedValue = (Integer) valueAnimator.getAnimatedValue();
                    item.textView.setTextSize(animatedValue);
                }
            });
            animator.setIntValues(0, 14);
            animator.start();
        }
    } else {
        item.imageView.setColorFilter(mUnselectedTint, PorterDuff.Mode.SRC_ATOP);
        if (item.textView != null) {
            item.textView.setTextColor(mUnselectedTint);
            ValueAnimator animator = mLabelAnimators.get(item);
            if (animator != null)
                animator.cancel();
            animator = new ValueAnimator();
            mLabelAnimators.put(item, animator);
            animator.setDuration(200);
            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    int animatedValue = (Integer) valueAnimator.getAnimatedValue();
                    item.textView.setTextSize(animatedValue);
                    if (animatedValue == 0)
                        item.textView.setVisibility(View.GONE);
                }
            });
            animator.setIntValues(14, 0);
            animator.start();
        }
    }
}

From source file:com.alimuzaffar.lib.pin.PinEntryEditText.java

private void animateBottomUp(CharSequence text, final int start) {
    mCharBottom[start] = mLineCoords[start].bottom - mTextBottomPadding;
    ValueAnimator animUp = ValueAnimator.ofFloat(mCharBottom[start] + getPaint().getTextSize(),
            mCharBottom[start]);/*  w w  w .  ja va  2 s .  c  o m*/
    animUp.setDuration(300);
    animUp.setInterpolator(new OvershootInterpolator());
    animUp.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            Float value = (Float) animation.getAnimatedValue();
            mCharBottom[start] = value;
            PinEntryEditText.this.invalidate();
        }
    });

    mLastCharPaint.setAlpha(255);
    ValueAnimator animAlpha = ValueAnimator.ofInt(0, 255);
    animAlpha.setDuration(300);
    animAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            Integer value = (Integer) animation.getAnimatedValue();
            mLastCharPaint.setAlpha(value);
        }
    });

    AnimatorSet set = new AnimatorSet();
    if (text.length() == mMaxLength && mOnPinEnteredListener != null) {
        set.addListener(new Animator.AnimatorListener() {

            @Override
            public void onAnimationStart(Animator animation) {
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                mOnPinEnteredListener.onPinEntered(getText());
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
    }
    set.playTogether(animUp, animAlpha);
    set.start();
}

From source file:io.github.trulyfree.easyaspi.MainActivity.java

/**
 *
 *///from   w w w  .  j  ava2  s . c  om
private void resetConfigReturned() {
    final ImageView configResponseBlock = (ImageView) findViewById(R.id.block_module_returned);
    LinearLayout layout = (LinearLayout) findViewById(R.id.module_returned_config);
    EditText moduleName = (EditText) findViewById(R.id.module_returned_configname);
    EditText moduleVersion = (EditText) findViewById(R.id.module_returned_configversion);
    EditText moduleConfigUrl = (EditText) findViewById(R.id.module_returned_configurl);
    EditText moduleJarUrl = (EditText) findViewById(R.id.module_returned_jarurl);
    LinearLayout moduleDependencies = (LinearLayout) findViewById(R.id.module_returned_dependencies);
    Button validate = (Button) findViewById(R.id.module_returned_validate);
    Button cancel = (Button) findViewById(R.id.module_returned_cancel);
    moduleName.setText(R.string.module_returned_configname);
    moduleVersion.setText(R.string.module_returned_configversion);
    moduleConfigUrl.setText(R.string.module_returned_configurl);
    moduleJarUrl.setText(R.string.module_returned_jarurl);
    moduleDependencies.removeAllViewsInLayout();
    validate.setOnClickListener(null);
    cancel.setOnClickListener(null);
    final int colorFrom = ContextCompat.getColor(MainActivity.this, R.color.colorClear);
    final int colorTo = ContextCompat.getColor(MainActivity.this, R.color.colorFillingTint);
    ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
    colorAnimation.setDuration(ANIMATION_DURATION);
    colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animator) {
            configResponseBlock.setBackgroundColor((Integer) animator.getAnimatedValue());
        }
    });
    layout.setClickable(false);
    configResponseBlock.setVisibility(View.VISIBLE);
    colorAnimation.start();
}

From source file:com.awt.supark.LayoutHandler.java

public void smallButtonPressed(final View view, final MainActivity act) {
    if (!act.pullUp && !act.pullUpStarted) { // If it isn't already up
        act.pullUpStarted = true;/*from   w ww  .  ja  v  a2s  .co  m*/
        // Declaring animator
        ValueAnimator animation = ValueAnimator.ofFloat(1f, 0.17f);

        // ****** UI ELEMENTS FADING OUT ANIMATION ******
        // Sets the animation properties
        animation.setDuration(act.layoutFadeOutDuration);

        animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float value = (float) animation.getAnimatedValue();

                // Fades out contentLinear and all buttons, except the one that is pressed
                act.contentLinear.setAlpha(value);
                if (view.getId() != R.id.buttonMap) {
                    act.btnMap.setAlpha(value);
                }
                if (view.getId() != R.id.buttonCars) {
                    act.btnCars.setAlpha(value);
                }
                if (view.getId() != R.id.buttonStatistics) {
                    act.btnStatistics.setAlpha(value);
                }
                if (view.getId() != R.id.buttonEtc) {
                    act.btnEtc.setAlpha(value);
                }
            }
        });

        animation.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                // Sets the visibility of the other layout and contentlinear
                act.contentLinear.setVisibility(View.GONE);
                act.otherContent.setVisibility(View.VISIBLE);

                // ****** BUTTON PULL UP ANIMATION ******
                // Declaring animator
                ValueAnimator nextAnimation = ValueAnimator.ofFloat(1f, 0f);

                // Sets the animation properties
                nextAnimation.setDuration(act.layoutPullUpDuration);
                nextAnimation.setInterpolator(new AccelerateDecelerateInterpolator());

                nextAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        float value = (float) animation.getAnimatedValue();

                        // Sets weight of the two layouts, this makes one smaller and the other bigger
                        act.tableRowTopHalf
                                .setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                        ViewGroup.LayoutParams.WRAP_CONTENT, value));
                        act.otherContent.setLayoutParams(
                                new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                        ViewGroup.LayoutParams.WRAP_CONTENT, 1 - value));
                    }
                });

                // ****** LAYOUT PULL UP ANIMATION ******
                nextAnimation.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        act.otherContentHandler(view); // Takes care of including new views
                        act.otherContent.startAnimation(act.anim_slide_up_fade_in); // Animates the new activity
                        act.pullUp = true; // Changing the pull up status indicator
                        act.pullUpStarted = false;
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {
                        act.pullUpStarted = false;
                        act.otherContent.setVisibility(View.GONE);
                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                nextAnimation.start();
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        animation.start();
    } else if (view.getId() == act.openedLayout) {
        act.pullDown(); // If there is a layout already pulled up we have to pull it down
    } else if (act.pullUp && (act.openedLayout != 0) && !act.pullUpStarted) {
        act.pullUpStarted = true; // To prevent more than one highlight

        // Changing highlight from previous to current button
        ValueAnimator animation = ValueAnimator.ofFloat(0.17f, 1f);
        animation.setDuration(act.smallButtonHighlightChangeDuration);
        animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float value = (float) animation.getAnimatedValue();
                act.findViewById(view.getId()).setAlpha(value);
                act.findViewById(act.openedLayout).setAlpha(1.17f - value);
            }
        });
        animation.start();

        // Fades out current layout
        act.otherContent.startAnimation(act.anim_fade_out);
        act.anim_fade_out.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                act.otherContentHandler(view); // Switches the layout to the new one
                act.otherContent.startAnimation(act.anim_slide_up_fade_in); // Fades in the new layout
                act.pullUpStarted = false;
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }
}

From source file:me.lizheng.deckview.views.DeckChildView.java

/**
 * Animates the deletion of this task view
 *///from ww  w  . j  a v a2 s  . c o  m
void startDeleteTaskAnimation(final Runnable r) {
    // Disabling clipping with the stack while the view is animating away
    setClipViewInStack(false);
    ValueAnimator anim = ObjectAnimator.ofFloat(this, View.TRANSLATION_X, getSize());
    anim.setInterpolator(new LinearInterpolator());
    anim.setDuration(100);
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            setClipViewInStack(true);

            setTouchEnabled(true);
            r.run();
        }
    });
    anim.start();
}

From source file:bottombar.BottomBarTab.java

void updateWidth(float endWidth, boolean animated) {
    if (!animated) {
        getLayoutParams().width = (int) endWidth;

        if (!isActive && badge != null) {
            badge.adjustPositionAndSize(this);
            badge.show();/*  www.  j a  va 2  s .  c  o  m*/
        }
        return;
    }

    float start = getWidth();

    ValueAnimator animator = ValueAnimator.ofFloat(start, endWidth);
    animator.setDuration(150);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animator) {
            ViewGroup.LayoutParams params = getLayoutParams();
            if (params == null)
                return;

            params.width = Math.round((float) animator.getAnimatedValue());
            setLayoutParams(params);
        }
    });
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (!isActive && badge != null) {
                badge.adjustPositionAndSize(BottomBarTab.this);
                badge.show();
            }
        }
    });
    animator.start();
}

From source file:com.android.deskclock.alarms.AlarmActivity.java

private Animator getAlertAnimator(final View source, final int titleResId, final String infoText,
        final String accessibilityText, final int revealColor, final int backgroundColor) {
    final ViewGroup containerView = (ViewGroup) findViewById(android.R.id.content);

    final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth());
    containerView.offsetDescendantRectToMyCoords(source, sourceBounds);

    final int centerX = sourceBounds.centerX();
    final int centerY = sourceBounds.centerY();

    final int xMax = Math.max(centerX, containerView.getWidth() - centerX);
    final int yMax = Math.max(centerY, containerView.getHeight() - centerY);

    final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f;
    final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax);

    final CircleView revealView = new CircleView(this).setCenterX(centerX).setCenterY(centerY)
            .setFillColor(revealColor);//from  www.j  a va2s  . c o  m
    containerView.addView(revealView);

    // TODO: Fade out source icon over the reveal (like LOLLIPOP version).

    final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius,
            endRadius);
    revealAnimator.setDuration(ALERT_REVEAL_DURATION_MILLIS);
    revealAnimator.setInterpolator(REVEAL_INTERPOLATOR);
    revealAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            mAlertView.setVisibility(View.VISIBLE);
            mAlertTitleView.setText(titleResId);

            if (infoText != null) {
                mAlertInfoView.setText(infoText);
                mAlertInfoView.setVisibility(View.VISIBLE);
            }
            mContentView.setVisibility(View.GONE);

            getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor));
        }
    });

    final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    fadeAnimator.setDuration(ALERT_FADE_DURATION_MILLIS);
    fadeAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            containerView.removeView(revealView);
        }
    });

    final AnimatorSet alertAnimator = new AnimatorSet();
    alertAnimator.play(revealAnimator).before(fadeAnimator);
    alertAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            mAlertView.announceForAccessibility(accessibilityText);
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    finish();
                }
            }, ALERT_DISMISS_DELAY_MILLIS);
        }
    });

    return alertAnimator;
}

From source file:com.onyx.deskclock.deskclock.alarms.AlarmActivity.java

private Animator getAlertAnimator(final View source, final int titleResId, final String infoText,
        final String accessibilityText, final int revealColor, final int backgroundColor) {
    final ViewGroup containerView = (ViewGroup) findViewById(android.R.id.content);

    final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth());
    containerView.offsetDescendantRectToMyCoords(source, sourceBounds);

    final int centerX = sourceBounds.centerX();
    final int centerY = sourceBounds.centerY();

    final int xMax = Math.max(centerX, containerView.getWidth() - centerX);
    final int yMax = Math.max(centerY, containerView.getHeight() - centerY);

    final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f;
    final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax);

    final CircleView revealView = new CircleView(this).setCenterX(centerX).setCenterY(centerY)
            .setFillColor(revealColor);//from ww w  .j a  v  a  2 s  .c o m
    containerView.addView(revealView);

    // TODO: Fade out source icon over the reveal (like LOLLIPOP version).

    final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius,
            endRadius);
    revealAnimator.setDuration(ALERT_REVEAL_DURATION_MILLIS);
    revealAnimator.setInterpolator(REVEAL_INTERPOLATOR);
    revealAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            mAlertView.setVisibility(View.VISIBLE);
            mAlertTitleView.setText(titleResId);

            if (infoText != null) {
                mAlertInfoView.setText(infoText);
                mAlertInfoView.setVisibility(View.VISIBLE);
            }
            mContentView.setVisibility(View.GONE);

            getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor));
        }
    });

    final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    fadeAnimator.setDuration(ALERT_FADE_DURATION_MILLIS);
    fadeAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            containerView.removeView(revealView);
        }
    });

    final AnimatorSet alertAnimator = new AnimatorSet();
    alertAnimator.play(revealAnimator).before(fadeAnimator);
    alertAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            if (Build.VERSION.SDK_INT >= 16) {
                mAlertView.announceForAccessibility(accessibilityText);
            }

            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    finish();
                }
            }, ALERT_DISMISS_DELAY_MILLIS);
        }
    });

    return alertAnimator;
}

From source file:com.nshmura.recyclertablayout.RecyclerTabLayout.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
protected void startAnimation(final int position) {

    float distance = 1;

    View view = mLinearLayoutManager.findViewByPosition(position);
    if (view != null) {
        float currentX = view.getX() + view.getMeasuredWidth() / 2.f;
        float centerX = getMeasuredWidth() / 2.f;
        distance = Math.abs(centerX - currentX) / view.getMeasuredWidth();
    }/*from w w  w . j a va  2 s .c o m*/

    ValueAnimator animator;
    if (position < mIndicatorPosition) {
        animator = ValueAnimator.ofFloat(distance, 0);
    } else {
        animator = ValueAnimator.ofFloat(-distance, 0);
    }
    animator.setDuration(DEFAULT_SCROLL_DURATION);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            scrollToTab(position, (float) animation.getAnimatedValue(), true);
        }
    });
    animator.start();
}

From source file:com.ruesga.rview.wizard.WizardActivity.java

private Animator createHeaderAnimation(int from, int to) {
    final ValueAnimator animator = ValueAnimator.ofInt(from, to);
    animator.setInterpolator(new AccelerateDecelerateInterpolator());
    animator.setDuration(250L);
    animator.addUpdateListener(animation -> {
        final View v = mBinding.pageHeader;
        v.getLayoutParams().height = (Integer) animation.getAnimatedValue();
        v.requestLayout();//from  ww w  .  ja  va  2  s.  c  o  m
    });
    animator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animator) {
            mWorkflow.isBackEnabled = false;
            mWorkflow.isForwardEnabled = false;
            mBinding.setWorkflow(mWorkflow);
            mIsHeaderAnimatorRunning = true;
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            if (mCurrentPageFragment != null) {
                onValidationChanged(mCurrentPageFragment);
            }
            mBinding.setWorkflow(mWorkflow);
            mIsHeaderAnimatorRunning = false;
        }

        @Override
        public void onAnimationCancel(Animator animator) {
        }

        @Override
        public void onAnimationRepeat(Animator animator) {
        }
    });
    return animator;
}