android.support.graphics.drawable.AnimatedVectorDrawableCompat Java Examples

The following examples show how to use android.support.graphics.drawable.AnimatedVectorDrawableCompat. 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: MainActivity.java    From journaldev with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    FloatingActionButton fabSync = findViewById(R.id.fabSync);
    FloatingActionButton fabTickCross = findViewById(R.id.fabTickCross);

    tickToCross = (AnimatedVectorDrawable) getDrawable(R.drawable.avd_tick2cross);
    crossToTick = (AnimatedVectorDrawable) getDrawable(R.drawable.avd_cross2tick);


    ImageView imgSettings = findViewById(R.id.imgSettings);
    ImageView imgJD = findViewById(R.id.imgJD);
    imgSettings.setOnClickListener(this);
    imgJD.setOnClickListener(this);

    AnimatedVectorDrawableCompat animatedVectorDrawableCompat = AnimatedVectorDrawableCompat.create(this, R.drawable.avd_sync);
    fabSync.setImageDrawable(animatedVectorDrawableCompat);
    fabSync.setOnClickListener(this);
    fabTickCross.setOnClickListener(this);

}
 
Example #2
Source File: MainActivity.java    From android-list-to-grid with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.action_list_to_grid) {
        if (!((Animatable) item.getIcon()).isRunning()) {
            if (gridLayoutManager.getSpanCount() == 1) {
                item.setIcon(AnimatedVectorDrawableCompat.create(MainActivity.this, R.drawable.avd_list_to_grid));
                gridLayoutManager.setSpanCount(3);
            } else {
                item.setIcon(AnimatedVectorDrawableCompat.create(MainActivity.this, R.drawable.avd_grid_to_list));
                gridLayoutManager.setSpanCount(1);
            }
            ((Animatable) item.getIcon()).start();
            simpleAdapter.notifyItemRangeChanged(0, simpleAdapter.getItemCount());
        }
        return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example #3
Source File: AnimationHelper.java    From ListItemView with Apache License 2.0 6 votes vote down vote up
public void toggleCheckBoxMenu(ListItemView listItemView, boolean toggle) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable drawable = listItemView.isChecked() ?
                AnimatedVectorDrawableCompat
                        .create(mContext, R.drawable.avd_checkbox_checked_to_unchecked) :
                AnimatedVectorDrawableCompat
                        .create(mContext, R.drawable.avd_checkbox_unchecked_to_checked);
        ImageView imageView =
                (ImageView) listItemView.findMenuItem(R.id.action_checkable).getActionView();
        imageView.setImageDrawable(drawable);
        ((Animatable) drawable).start();
    }
    if (toggle) {
        listItemView.toggle();
    }
}
 
Example #4
Source File: FingerprintIconView.java    From BiometricPromptCompat with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #5
Source File: AnimationHelper.java    From ListItemView with Apache License 2.0 6 votes vote down vote up
public void setupRadioButton(ListItemView listItemView) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        AnimatedStateListDrawable asl = new AnimatedStateListDrawable();
        asl.addState(
                new int[]{android.R.attr.state_checked},
                AppCompatResources.getDrawable(mContext, R.drawable.vd_radiobutton_checked),
                R.id.checked);
        asl.addState(
                new int[0],
                AppCompatResources.getDrawable(mContext, R.drawable.vd_radiobutton_unchecked),
                R.id.unchecked);
        asl.addTransition(
                R.id.unchecked,
                R.id.checked,
                AnimatedVectorDrawableCompat.create(mContext, R.drawable.avd_radiobutton_unchecked_to_checked),
                false);
        asl.addTransition(
                R.id.checked,
                R.id.unchecked,
                AnimatedVectorDrawableCompat.create(mContext, R.drawable.avd_radiobutton_checked_to_unchecked),
                false);
        listItemView.setIconDrawable(asl);
    } else {
        listItemView.setIconResId(R.drawable.selector_ic_radio);
    }
}
 
Example #6
Source File: AnimationHelper.java    From ListItemView with Apache License 2.0 6 votes vote down vote up
public void setupCheckBox(ListItemView listItemView) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        AnimatedStateListDrawable asl = new AnimatedStateListDrawable();
        asl.addState(
                new int[]{android.R.attr.state_checked},
                AppCompatResources.getDrawable(mContext, R.drawable.vd_checkbox_checked),
                R.id.checked);
        asl.addState(
                new int[0],
                AppCompatResources.getDrawable(mContext, R.drawable.vd_checkbox_unchecked),
                R.id.unchecked);
        asl.addTransition(
                R.id.unchecked,
                R.id.checked,
                AnimatedVectorDrawableCompat.create(mContext, R.drawable.avd_checkbox_unchecked_to_checked),
                false);
        asl.addTransition(
                R.id.checked,
                R.id.unchecked,
                AnimatedVectorDrawableCompat.create(mContext, R.drawable.avd_checkbox_checked_to_unchecked),
                false);
        listItemView.setIconDrawable(asl);
    } else {
        listItemView.setIconResId(R.drawable.selector_ic_check);
    }
}
 
Example #7
Source File: FavoriteToSendMorphView.java    From MorphView with Apache License 2.0 5 votes vote down vote up
public void morph() {
    AnimatedVectorDrawableCompat drawable = showingFavorite ? favoriteToSend : sendToFavorite;
    setImageDrawable(drawable);
    if (drawable != null) {
        drawable.start();
    }
    showingFavorite = !showingFavorite;
}
 
Example #8
Source File: SkinCompatDrawableManager.java    From Android-skin-support with MIT License 5 votes vote down vote up
@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;
    }
}
 
Example #9
Source File: AwesomeBar.java    From AwesomeBar with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    super.handleMessage(msg);
    switch (msg.what) {
        case MESSAGE_ANIMATION_START:
            final Drawable drawable = iconMenu.getDrawable();
            if (drawable instanceof AnimatedVectorDrawableCompat) {
                ((AnimatedVectorDrawableCompat) iconMenu.getDrawable()).start();
                sendEmptyMessageDelayed(MESSAGE_ANIMATION_START, 5000);
            }
            break;
    }
}
 
Example #10
Source File: AnimationHelper.java    From ListItemView with Apache License 2.0 5 votes vote down vote up
public void toggleCheckBox(ListItemView listItemView, boolean toggle) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable drawable = listItemView.isChecked() ?
                AnimatedVectorDrawableCompat
                        .create(mContext, R.drawable.avd_checkbox_checked_to_unchecked) :
                AnimatedVectorDrawableCompat
                        .create(mContext, R.drawable.avd_checkbox_unchecked_to_checked);
        listItemView.setIconDrawable(drawable);
        ((Animatable) drawable).start();
    }
    if (toggle) {
        listItemView.toggle();
    }
}
 
Example #11
Source File: AnimationHelper.java    From ListItemView with Apache License 2.0 5 votes vote down vote up
public void setupCheckBoxMenu(ListItemView listItemView) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        AnimatedStateListDrawable asl = new AnimatedStateListDrawable();
        asl.addState(
                new int[]{android.R.attr.state_checked},
                AppCompatResources.getDrawable(mContext, R.drawable.vd_checkbox_checked),
                R.id.checked);
        asl.addState(
                new int[0],
                AppCompatResources.getDrawable(mContext, R.drawable.vd_checkbox_unchecked),
                R.id.unchecked);
        asl.addTransition(
                R.id.unchecked,
                R.id.checked,
                AnimatedVectorDrawableCompat.create(mContext, R.drawable.avd_checkbox_unchecked_to_checked),
                false);
        asl.addTransition(
                R.id.checked,
                R.id.unchecked,
                AnimatedVectorDrawableCompat.create(mContext, R.drawable.avd_checkbox_checked_to_unchecked),
                false);

        listItemView.inflateMenu(R.menu.checkable_action_menu);
        ImageView imageView = (ImageView) listItemView.findMenuItem(R.id.action_checkable).getActionView();
        imageView.setImageDrawable(asl);
        asl.jumpToCurrentState();
    } else {
        listItemView.inflateMenu(R.menu.checkable_action_menu);
    }
}
 
Example #12
Source File: AnimationHelper.java    From ListItemView with Apache License 2.0 5 votes vote down vote up
public void setRadioButtonState(ListItemView listItemView, boolean checked) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP &&
            listItemView.isChecked() != checked) {
        Drawable drawable = checked ?
                AnimatedVectorDrawableCompat
                        .create(mContext, R.drawable.avd_radiobutton_unchecked_to_checked) :
                AnimatedVectorDrawableCompat
                        .create(mContext, R.drawable.avd_radiobutton_checked_to_unchecked);
        listItemView.setIconDrawable(drawable);
        ((Animatable) drawable).start();
    }
    listItemView.setChecked(checked);
}
 
Example #13
Source File: MorphView.java    From MorphView with Apache License 2.0 5 votes vote down vote up
public void morph() {
    AnimatedVectorDrawableCompat drawable = showingAvdFirst ? avdFirstToSecond : avdSecondToFirst;
    setImageDrawable(drawable);
    if (drawable != null) {
        drawable.start();
    }
    showingAvdFirst = !showingAvdFirst;
}
 
Example #14
Source File: MorphView.java    From MorphView with Apache License 2.0 5 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    if (isInEditMode()) {
        setImageResource(android.R.drawable.ic_media_play);
        return;
    }

    TypedArray a = context.getTheme().obtainStyledAttributes(
            attrs,
            R.styleable.MorphView,
            0, 0);

    @DrawableRes int avdFromRes;
    @DrawableRes int avdToRes;
    try {
        avdFromRes = a.getResourceId(R.styleable.MorphView_avdFirst, -1);
        avdToRes = a.getResourceId(R.styleable.MorphView_avdSecond, -1);
    } finally {
        a.recycle();
    }

    showingAvdFirst = true;
    avdFirstToSecond = AnimatedVectorDrawableCompat.create(getContext(), avdFromRes);
    avdSecondToFirst = AnimatedVectorDrawableCompat.create(getContext(), avdToRes);

    if (avdSecondToFirst == null || avdFirstToSecond == null) {
        throw new RuntimeException("Drawable is not a valid AnimatedVectorDrawable");
    } else {
        setImageDrawable(avdFirstToSecond);
    }
}
 
Example #15
Source File: CustomAnimatedDrawable.java    From RoundButton with MIT License 4 votes vote down vote up
@Override
public void setupAnimations() {
    animateDrawable = AnimatedVectorDrawableCompat.create(view.getContext(), resource);
    DrawableCompat.setTint(animateDrawable, color);
    animateDrawable.setBounds(bounds);
}
 
Example #16
Source File: MorphView.java    From MorphView with Apache License 2.0 4 votes vote down vote up
public void setAvdSecond(@NonNull AnimatedVectorDrawableCompat avdSecond) {
    avdSecondToFirst = avdSecond;
    invalidate();
}
 
Example #17
Source File: AnimationHelper.java    From RecordView with Apache License 2.0 4 votes vote down vote up
public AnimationHelper(Context context, ImageView basketImg, ImageView smallBlinkingMic) {
    this.context = context;
    this.smallBlinkingMic = smallBlinkingMic;
    this.basketImg = basketImg;
    animatedVectorDrawable = AnimatedVectorDrawableCompat.create(context, R.drawable.recv_basket_animated);
}
 
Example #18
Source File: AwesomeBar.java    From AwesomeBar with Apache License 2.0 4 votes vote down vote up
private void animateMenuImage() {
    final Drawable drawable = iconMenu.getDrawable();
    if (drawable instanceof AnimatedVectorDrawableCompat) {
        ((AnimatedVectorDrawableCompat) iconMenu.getDrawable()).start();
    }
}
 
Example #19
Source File: MorphView.java    From MorphView with Apache License 2.0 4 votes vote down vote up
public void setAvdFirst(@NonNull AnimatedVectorDrawableCompat avdFirst) {
    avdFirstToSecond = avdFirst;
    invalidate();
}
 
Example #20
Source File: FavoriteToSendMorphView.java    From MorphView with Apache License 2.0 4 votes vote down vote up
private void init() {
    showingFavorite = true;
    favoriteToSend = AnimatedVectorDrawableCompat.create(getContext(), R.drawable.avd_favorite_to_send);
    sendToFavorite = AnimatedVectorDrawableCompat.create(getContext(), R.drawable.avd_send_to_favorite);
    setImageDrawable(favoriteToSend);
}
 
Example #21
Source File: PagingDayPickerView.java    From BottomSheetPickers with Apache License 2.0 4 votes vote down vote up
private void animateArrow(AnimatedVectorDrawableCompat arrow) {
    setArrowDrawableOnTitle(arrow);
    arrow.start();
}
 
Example #22
Source File: SpotlightView.java    From Spotlight with Apache License 2.0 4 votes vote down vote up
/**
 * Add arc above/below the circular target overlay.
 */
private void addArcAnimation(final Activity activity) {
    AppCompatImageView mImageView = new AppCompatImageView(activity);
    mImageView.setImageResource(R.drawable.ic_spotlight_arc);
    LayoutParams params = new LayoutParams(2 * (circleShape.getRadius() + extraPaddingForArc),
            2 * (circleShape.getRadius() + extraPaddingForArc));


    if (targetView.getPoint().y > getHeight() / 2) {//bottom
        if (targetView.getPoint().x > getWidth() / 2) {//Right
            params.rightMargin = getWidth() - targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc;
            params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc;
            params.gravity = Gravity.RIGHT | Gravity.BOTTOM;
        } else {
            params.leftMargin = targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc;
            params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc;
            params.gravity = Gravity.LEFT | Gravity.BOTTOM;
        }
    } else {//up
        mImageView.setRotation(180); //Reverse the view
        if (targetView.getPoint().x > getWidth() / 2) {//Right
            params.rightMargin = getWidth() - targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc;
            params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc;
            params.gravity = Gravity.RIGHT | Gravity.BOTTOM;
        } else {
            params.leftMargin = targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc;
            params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc;
            params.gravity = Gravity.LEFT | Gravity.BOTTOM;
        }

    }
    mImageView.postInvalidate();
    mImageView.setLayoutParams(params);
    addView(mImageView);

    PorterDuffColorFilter porterDuffColorFilter = new PorterDuffColorFilter(lineAndArcColor,
            PorterDuff.Mode.SRC_ATOP);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        AnimatedVectorDrawable avd = (AnimatedVectorDrawable)
                ContextCompat.getDrawable(activity, R.drawable.avd_spotlight_arc);
        avd.setColorFilter(porterDuffColorFilter);
        mImageView.setImageDrawable(avd);
        avd.start();
    } else {
        AnimatedVectorDrawableCompat avdc =
                AnimatedVectorDrawableCompat.create(activity, R.drawable.avd_spotlight_arc);
        avdc.setColorFilter(porterDuffColorFilter);
        mImageView.setImageDrawable(avdc);
        avdc.start();
    }

    new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
        @Override
        public void run() {
            addPathAnimation(activity);
        }
    }, 400);
}
 
Example #23
Source File: StepTab.java    From android-material-stepper with Apache License 2.0 2 votes vote down vote up
/**
 * Inflates an animated vector drawable.
 *
 * @param animatedVectorDrawableResId resource ID for the animated vector
 * @return animated vector drawable
 */
public Drawable createAnimatedVectorDrawable(@DrawableRes int animatedVectorDrawableResId) {
    return AnimatedVectorDrawableCompat.create(getContext(), animatedVectorDrawableResId);
}