Java Code Examples for android.animation.Animator#setDuration()

The following examples show how to use android.animation.Animator#setDuration() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrowseNearbyActivity.java    From Expert-Android-Programming with MIT License 6 votes vote down vote up
private void exitReveal(final View icon, final View toolbar) {

        // get the center for the clipping circle
        int cx = getRelativeLeft(icon) + icon.getMeasuredWidth() / 2;
        int cy = getRelativeTop(icon);

        // get the initial radius for the clipping circle
        int initialRadius = Math.max(toolbar.getWidth(), toolbar.getHeight());

        // create the animation (the final radius is zero)
        Animator anim =
                ViewAnimationUtils.createCircularReveal(toolbar, cx, cy, initialRadius, 0);

        // make the view invisible when the animation is done
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                toolbar.setVisibility(View.INVISIBLE);
            }
        });

        anim.setDuration(Constant.SEARCH_REVEAL_DURATION);
        // start the animation
        anim.start();
    }
 
Example 2
Source File: GameCard.java    From AndroidLinkup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 设置与界面卡片关联的piece
 * 
 * @param piece
 *            piece信息
 * @param isAnim
 *            是否应用动画
 */
public void setPiece(Piece piece, Bitmap bm, boolean isAnim) {
    this.piece = piece;
    imageView.setImageBitmap(bm);
    if (piece.isStar()) {
        // 卡片星星
        imageStar = new ImageView(getContext());
        imageStar.setImageResource(R.drawable.star_48);
        addView(imageStar, 48, 48);
    }

    if (isAnim) {
        setXY(piece.getBeginX(), -piece.getHeight());
        // 从上面落下
        Animator anim = ObjectAnimator.ofFloat(this, "translationY", 0, piece.getBeginY() + piece.getHeight());
        anim.setDuration(500);
        anim.setStartDelay((Piece.YSize - piece.getIndexY()) * 50 - ran.nextInt(50));
        anim.start();
    } else {
        // 设置卡片的left和top
        setXY(piece.getBeginX(), piece.getBeginY());
    }

    lineWidth = piece.getWidth() / 16 + 1;
    rect = new RectF(piece.getWidth() / 32, piece.getWidth() / 32, piece.getWidth() - lineWidth + 1, piece.getHeight() - lineWidth + 1);
}
 
Example 3
Source File: SearchAnimator.java    From MeiZiNews with MIT License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void revealOutAnimation(final Context mContext, final View view, int duration) {

    int cx = view.getWidth() - mContext.getResources().getDimensionPixelSize(R.dimen.reveal);
    int cy = view.getHeight() / 2;

    if (cx != 0 && cy != 0) {
        float initialRadius = (float) Math.hypot(cx, cy);

        Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, initialRadius, 0.0f);
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.setDuration(duration);
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                view.setVisibility(View.GONE);
            }
        });
        anim.start();
    }
}
 
Example 4
Source File: PhotoPaintView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void closeStickersView() {
    if (stickersView == null || stickersView.getVisibility() != VISIBLE) {
        return;
    }
    pickingSticker = false;

    Animator a = ObjectAnimator.ofFloat(stickersView, "alpha", 1.0f, 0.0f);
    a.setDuration(200);
    a.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            stickersView.setVisibility(GONE);
        }
    });
    a.start();
}
 
Example 5
Source File: TableView.java    From SortableTableView with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the {@link TableView} header visible or hides it.
 *
 * @param visible Whether the {@link TableView} header shall be visible or not.
 */
public void setHeaderVisible(boolean visible, int animationDuration) {
    if (visible && !isHeaderVisible()) {
        if (animationDuration > 0) {
            final Animator moveInAnimator = ObjectAnimator.ofPropertyValuesHolder((Object) null, PropertyValuesHolder.ofFloat("y", 0));
            moveInAnimator.setDuration(animationDuration);
            layoutTransition.setAnimator(LayoutTransition.APPEARING, moveInAnimator);
            setLayoutTransition(layoutTransition);
        } else {
            setLayoutTransition(null);
        }
        addView(tableHeaderView, 0);
    } else if (!visible && isHeaderVisible()) {
        if (animationDuration > 0) {
            final Animator moveOutAnimator = ObjectAnimator.ofPropertyValuesHolder((Object) null, PropertyValuesHolder.ofFloat("y", -tableHeaderView.getHeight()));
            moveOutAnimator.setDuration(animationDuration);
            layoutTransition.setAnimator(LayoutTransition.DISAPPEARING, moveOutAnimator);
            setLayoutTransition(layoutTransition);
        } else {
            setLayoutTransition(null);
        }
        removeView(tableHeaderView);
    }
}
 
Example 6
Source File: AnimHelper.java    From FastAccess with GNU General Public License v3.0 6 votes vote down vote up
@UiThread private static void reveal(final View mRevealView, final boolean show, View from) {
    Rect rect = ViewHelper.getLayoutPosition(from);
    int x = (int) rect.exactCenterX();
    int y = (int) rect.exactCenterY();
    Animator animator = ViewAnimationUtils.createCircularReveal(mRevealView, x, y, 0, Math.max(rect.width(), rect.height()));
    animator.setDuration(400L);
    animator.setInterpolator(new AccelerateDecelerateInterpolator());
    mRevealView.setVisibility(View.VISIBLE);
    if (!show) {
        animator.addListener(new AnimatorListenerAdapter() {
            @Override public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                mRevealView.setVisibility(View.GONE);
                animation.removeListener(this);
            }
        });
        animator.start();
    }
}
 
Example 7
Source File: DotsFragment.java    From android-material-motion with Apache License 2.0 5 votes vote down vote up
private Animator backgroundReveal() {
  root.setBackgroundColor(color);
  background.setBackgroundColor(color = colors.get(color));
  int cx = (int) (parent.getX() + parent.getWidth() / 2);
  int cy = (int) (parent.getY() + parent.getHeight() / 2);
  int w = background.getWidth();
  int h = background.getHeight();
  Animator animator = ViewAnimationUtils.createCircularReveal(background, cx, cy, parent.getHeight() / 2, (int) Math.hypot(w, h));
  animator.setDuration(duration(R.integer.reveal_duration) * 2);
  return animator;
}
 
Example 8
Source File: MovingViewAnimator.java    From MovingImageView with Apache License 2.0 5 votes vote down vote up
/**
 * For each animation child sets their duration using length/speed operation.
 *
 * @param speed new speed.
 */
public void setSpeed(int speed) {
    mSpeed = speed;
    List<Animator> listAnimator = mAnimatorSet.getChildAnimations();
    for (int i = 0; i < listAnimator.size(); i++) {
        Animator a = listAnimator.get(i);
        a.setDuration(parseSpeed(pathDistances.get(i)));
    }
}
 
Example 9
Source File: DemoLikeTumblrActivity.java    From ArcLayout with Apache License 2.0 5 votes vote down vote up
private void hideMenu(int cx, int cy, float startRadius, float endRadius) {
  List<Animator> animList = new ArrayList<>();

  for (int i = arcLayout.getChildCount() - 1; i >= 0; i--) {
    animList.add(createHideItemAnimator(arcLayout.getChildAt(i)));
  }

  animList.add(createHideItemAnimator(centerItem));

  Animator revealAnim = createCircularReveal(menuLayout, cx, cy, startRadius, endRadius);
  revealAnim.setInterpolator(new AccelerateDecelerateInterpolator());
  revealAnim.setDuration(200);
  revealAnim.addListener(new AnimatorListenerAdapter() {
    @Override
    public void onAnimationEnd(Animator animation) {
      super.onAnimationEnd(animation);
      menuLayout.setVisibility(View.INVISIBLE);
    }
  });

  animList.add(revealAnim);

  AnimatorSet animSet = new AnimatorSet();
  animSet.playSequentially(animList);
  animSet.start();

}
 
Example 10
Source File: SupportAnimatorLollipop.java    From material-sheet-fab with MIT License 5 votes vote down vote up
@Override
public void setDuration(int duration) {
    Animator a = mAnimator.get();
    if(a != null) {
        a.setDuration(duration);
    }
}
 
Example 11
Source File: SupportAnimatorPreLollipop.java    From Nibo with MIT License 5 votes vote down vote up
@Override
public void setDuration(int duration) {
    Animator a = mAnimator.get();
    if(a != null) {
        a.setDuration(duration);
    }
}
 
Example 12
Source File: RcvBaseAnimation.java    From RecyclerViewAdapter with Apache License 2.0 5 votes vote down vote up
/**
 * 开始动画
 */
public void startAnim(View v)
{
    Animator[] animators = getAnimator(v);
    for (Animator animator : animators)
    {
        animator.setDuration(mAnimDuration);
        animator.setInterpolator(mInterpolator);
        animator.start();
    }
}
 
Example 13
Source File: BrowseNearbyActivity.java    From Expert-Android-Programming with MIT License 5 votes vote down vote up
private void hideFilter(final View view) {

        view.setVisibility(View.VISIBLE);
        Animator iconAnim = ObjectAnimator.ofPropertyValuesHolder(view,
                PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, 0f, view.getHeight()));
        iconAnim.setDuration(Constant.REVEAL_DURATION);
        iconAnim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                view.setVisibility(View.INVISIBLE);
            }
        });
        iconAnim.start();
    }
 
Example 14
Source File: TransitionUtils.java    From KotlinMVPRxJava2Dagger2GreenDaoRetrofitDemo with Apache License 2.0 5 votes vote down vote up
/**
 *创建Reveal动画并执行
 *
 * @param viewRoot 要执行动画的布局
 * @param color 揭露的颜色
 * @param cx 揭露点的X坐标
 * @param cy 揭露点的Y坐标
 * @return 返回创建成功的动画
 */
@TargetApi(21)
private Animator animateRevealColorFromCoordinates(ViewGroup viewRoot, int color, int cx, int cy, Activity activity) {
    float finalRadius= (float) Math.hypot(viewRoot.getWidth(),viewRoot.getHeight());

    Animator anim= ViewAnimationUtils.createCircularReveal(viewRoot,cx,cy,0,finalRadius);
    viewRoot.setBackgroundColor(ContextCompat.getColor(activity,color));
    anim.setDuration(1000);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.start();
    return anim;
}
 
Example 15
Source File: FabActivity.java    From example with Apache License 2.0 5 votes vote down vote up
private void hideView(final View expandedView) {
    int cx = (btnFAB.getLeft() + btnFAB.getRight()) / 2;
    int cy = (btnFAB.getTop() + btnFAB.getBottom()) / 2;

    int initialRadius = expandedView.getWidth();

    Animator anim = ViewAnimationUtils.createCircularReveal(expandedView, cx, cy, initialRadius, 0);
    anim.setDuration(300);
    anim.setInterpolator(getLinearOutSlowInInterpolator());

    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            expandedView.setVisibility(View.INVISIBLE);
        }
    });

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            btnFAB.setVisibility(View.VISIBLE);
        }
    }, 200);

    anim.start();

}
 
Example 16
Source File: HeaderViewHolder.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
@NotNull
@Override
protected Animator getEnterAnimator(List<Animator> pendingAnimatorList) {
    Animator a = ObjectAnimator.ofFloat(itemView, "alpha", 0f, 1f);
    a.setDuration(300);
    a.setStartDelay(100);
    a.setInterpolator(new FastOutSlowInInterpolator());
    return a;
}
 
Example 17
Source File: BaseDialog.java    From Aria with Apache License 2.0 4 votes vote down vote up
private void in1() {
  Animator alpha = ObjectAnimator.ofFloat(mRootView, "alpha", 0f, 1f);
  alpha.setDuration(800);
  alpha.start();
}
 
Example 18
Source File: ToolbarPhone.java    From delion with Apache License 2.0 4 votes vote down vote up
private void populateUrlFocusingAnimatorSet(List<Animator> animators) {
    Animator animator = ObjectAnimator.ofFloat(this, mUrlFocusChangePercentProperty, 1f);
    animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
    animators.add(animator);

    for (int i = 0; i < mPhoneLocationBar.getChildCount(); i++) {
        View childView = mPhoneLocationBar.getChildAt(i);
        if (childView == mPhoneLocationBar.getFirstViewVisibleWhenFocused()) break;
        animator = ObjectAnimator.ofFloat(childView, ALPHA, 0);
        animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
        animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
        animators.add(animator);
    }

    float density = getContext().getResources().getDisplayMetrics().density;
    boolean isRtl = ApiCompatibilityUtils.isLayoutRtl(this);
    float toolbarButtonTranslationX = MathUtils.flipSignIf(
            URL_FOCUS_TOOLBAR_BUTTONS_TRANSLATION_X_DP, isRtl) * density;

    animator = ObjectAnimator.ofFloat(
            mMenuButtonWrapper, TRANSLATION_X, toolbarButtonTranslationX);
    animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
    animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE);
    animators.add(animator);

    animator = ObjectAnimator.ofFloat(mMenuButtonWrapper, ALPHA, 0);
    animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
    animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE);
    animators.add(animator);

    if (mToggleTabStackButton != null) {
        animator = ObjectAnimator.ofFloat(
                mToggleTabStackButton, TRANSLATION_X, toolbarButtonTranslationX);
        animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
        animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE);
        animators.add(animator);

        animator = ObjectAnimator.ofFloat(mToggleTabStackButton, ALPHA, 0);
        animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
        animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE);
        animators.add(animator);
    }
}
 
Example 19
Source File: AnimatorHelper.java    From FlexibleAdapter with Apache License 2.0 3 votes vote down vote up
/**
 * Adds a custom duration to the current view.
 *
 * @param animators user defined list of animators
 * @param duration  duration in milliseconds
 * @since 1.0.0-b1
 */
public static void setDuration(@NonNull List<Animator> animators, @IntRange(from = 0) long duration) {
    if (animators.size() > 0) {
        Animator animator = animators.get(animators.size() - 1);
        animator.setDuration(duration);
    }
}
 
Example 20
Source File: FlingAnimationUtils.java    From LaunchEnr with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Applies the interpolator and length to the animator, such that the fling animation is
 * consistent with the finger motion.
 *
 * @param animator the animator to apply
 * @param currValue the current value
 * @param endValue the end value of the animator
 * @param velocity the current velocity of the motion
 * @param maxDistance the maximum distance for this interaction; the maximum animation length
 *                    gets multiplied by the ratio between the actual distance and this value
 */
public void apply(Animator animator, float currValue, float endValue, float velocity,
        float maxDistance) {
    AnimatorProperties properties = getProperties(currValue, endValue, velocity,
            maxDistance);
    animator.setDuration(properties.duration);
    animator.setInterpolator(properties.interpolator);
}