Understanding Drawable.Callback, difference between invalidateDrawable and invalidate()

Viewed 104

I'm using StickerView to add stickers to my app, now I'm trying to add GIF drawable as a sticker, the below code works, the GifDrawable is animated normally, but the issue here is each time the Drawable changes to the next frame, the entire StickerView is redrawn, over and over again, this consumes quite a bit of memory.

I tried to invalidate the drawable only using stickerView.invalidateDrawable(who), but GifDrawable stops animating.

   GifDrawable gifDrawable = new GifDrawable(gifSticker.getBuffer());
   gifDrawableSticker.setGIF(true);
   gifDrawable.setCallback(new Drawable.Callback() {
            @Override
            public void invalidateDrawable(@NonNull Drawable who) {

                  stickerView.invalidate(); WORKING FINE
                //stickerView.invalidateDrawable(who); NOT WORKING

            }

            @Override
            public void scheduleDrawable(@NonNull Drawable who, @NonNull Runnable what, long when) {
                  stickerView.scheduleDrawable(who, what, when);
            }

            @Override
            public void unscheduleDrawable(@NonNull Drawable who, @NonNull Runnable what) {
                stickerView.unscheduleDrawable(who, what);
            }
        });
      stickerView.addSticker(new DrawableSticker(gifDrawable));
0 Answers
Related