2

I have implemented a custom view that has a DraweeHolder. I have implemented all callbacks and listeners for my custom view (attach / detach / invalidateDrawable / setListener).

If I set a GIF image url to controller - it does not play gif correctly. It refreshes the gif only when the view is redrawn. I guess that animated GIF should have some invalidation callback or something.

P.S. Gif does work correctly if I use DraweeView. Also all other images work correctly inside my custom view.

Creating holder:

private DraweeHolder<GenericDraweeHierarchy> createComponentHolder(View parent, Context context) {
    GenericDraweeHierarchy componentHierarchy = new GenericDraweeHierarchyBuilder(parent.getResources())
            .setRoundingParams(RoundingParams.fromCornersRadius(LayoutHelper.dp(3)).setBorder(Theme.COLOR_MEDIA_BORDER, 1))
            .build();
    DraweeHolder<GenericDraweeHierarchy> holder = DraweeHolder.create(componentHierarchy, context);
    holder.getTopLevelDrawable().setCallback(parent);
    return holder;
}

Setting controller:

PipelineDraweeControllerBuilder controllerBuilder = Fresco.newDraweeControllerBuilder()
            .setImageRequest(MediaHelper.getImageRequest(filePath))
            .setAutoPlayAnimations(true)
            .setControllerListener(controllerListener)
            .setOldController(draweeHolder.getController());

    if (thumbUrl != null) {
        controllerBuilder.setLowResImageRequest(getThumbnailRequest(thumbUrl));
    }

    draweeHolder.setController(controllerBuilder.build());

Image request:

public static ImageRequest getImageRequest(String filePath) {
    int imageSize = LayoutHelper.dp(100);
    return ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(new File(filePath)))
            .setResizeOptions(new ResizeOptions(imageSize, imageSize))
            .setAutoRotateEnabled(true)
            .build();
}
Ermat Alymbaev
  • 721
  • 6
  • 15

1 Answers1

1

There is no custom invalidation callback for GIFs, the animated drawable just invalidates itself for each frame, so if you set the callbacks the invalidation should just work.

However, if your Drawable callback (in your case parent) does not invalidate the correct area (or everything), the animated drawable invalidation will not refresh correctly. An example when this can happen is when the callback does not know the exact location of the Drawable and invalidates a wrong area. You can try debugging what the Drawable.Callback of your custom view does or write a custom Drawable.Callback class that invalidates the whole view including the GIF drawable.

Also, make sure to override verifyDrawable and follow all other steps for custom views as described in the Custom View documentation.

Alexander Oprisnik
  • 1,212
  • 9
  • 9
  • Can you show example how I can add callback to animated drawable. – Rafael Dec 21 '16 at 04:14
  • Take a look at http://frescolib.org/docs/animations.html - this shows how to manually start and stop the animation. – Alexander Oprisnik Dec 22 '16 at 21:30
  • You link didn't help me much. Can you provide more clues or example how animated fresco view (GIF inside Fresco drawee) can invalidate my custom parent view, while its playing. – Rafael Dec 26 '16 at 11:02
  • 1
    Check out http://frescolib.org/docs/writing-custom-views.html - The section about other responsibilities is the one you're looking for. Setting the `Drawable.Callback` and making sure that `invalidateDrawable` invalidates the correct region is important. – Alexander Oprisnik Dec 26 '16 at 11:14
  • Thanks, now it works. Overriding verifyDrawable in parent view did the change. – Rafael Dec 26 '16 at 11:37
  • Great. I've added a sentence about `verifyDrawable` to my answer. – Alexander Oprisnik Dec 26 '16 at 12:00