Java源码示例:androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat

示例1
private void startOpenAnimations() {

        // Icon
        AnimatedVectorDrawableCompat menuIcon = AnimatedVectorDrawableCompat.create(getContext(),
                R.drawable.ic_menu_animated);
        mFabView.setImageDrawable(menuIcon);
        menuIcon.start();

        // Reveal
        int centerX = mFabRect.centerX();
        int centerY = mFabRect.centerY();
        float startRadius = getMinRadius();
        float endRadius = getMaxRadius();
        Animator reveal = CircularRevealCompat.createCircularReveal(
              mNavigationView, centerX, centerY, startRadius, endRadius
        );

        // Fade in
        mNavigationMenuView.setAlpha(0);
        Animator fade = ObjectAnimator.ofFloat(mNavigationMenuView, View.ALPHA, 0, 1);

        // Animations
        AnimatorSet set = new AnimatorSet();
        set.playSequentially(reveal, fade);
        set.start();
    }
 
示例2
public void setState(State state, boolean animate) {
  if (state == this.state) return;

  @DrawableRes int resId = getDrawable(this.state, state, animate);
  if (resId == 0) {
    setImageDrawable(null);
  } else {
    Drawable icon = null;
    if (animate) {
      icon = AnimatedVectorDrawableCompat.create(getContext(), resId);
    }
    if (icon == null) {
      icon = VectorDrawableCompat.create(getResources(), resId, getContext().getTheme());
    }
    setImageDrawable(icon);

    if (icon instanceof Animatable) {
      ((Animatable) icon).start();
    }
  }

  this.state = state;
}
 
示例3
@SuppressLint("NewApi")
@Override
public Drawable createFromXmlInner(@NonNull Context context, @NonNull XmlPullParser parser,
                                   @NonNull AttributeSet attrs, @Nullable Resources.Theme theme) {
    try {
        return AnimatedVectorDrawableCompat
                .createFromXmlInner(context, context.getResources(), parser, attrs, theme);
    } catch (Exception e) {
        Log.e("AvdcInflateDelegate", "Exception while inflating <animated-vector>", e);
        return null;
    }
}
 
示例4
private void startCloseAnimations() {

        // Icon
        AnimatedVectorDrawableCompat closeIcon = AnimatedVectorDrawableCompat.create(getContext(),
                R.drawable.ic_close_animated);
        mFabView.setImageDrawable(closeIcon);
        closeIcon.start();

        // Unreveal
        int centerX = mFabRect.centerX();
        int centerY = mFabRect.centerY();
        float startRadius = getMaxRadius();
        float endRadius = getMinRadius();
        Animator reveal = CircularRevealCompat.createCircularReveal(
              mNavigationView, centerX, centerY, startRadius, endRadius
        );
        reveal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                detachNavigationView();
            }
        });

        // Fade out
        Animator fade = ObjectAnimator.ofFloat(mNavigationMenuView, View.ALPHA, 1, 0);

        // Animations
        AnimatorSet set = new AnimatorSet();
        set.playTogether(fade, reveal);
        set.start();
    }