@Override
  public CloseableImage decode(
      final EncodedImage encodedImage,
      int length,
      QualityInfo qualityInfo,
      ImageDecodeOptions options) {
    InputStream is = encodedImage.getInputStream();
    try {
      ByteArrayOutputStream out = new ByteArrayOutputStream();

      // NULLSAFE_FIXME[Parameter Not Nullable]
      GifMetadataDecoder decoder = GifMetadataDecoder.create(is, out);

      if (out.size() > 0) { // let's use the fixed gif version if exists
        Preconditions.checkNotNull(is).close();
        is = new ByteArrayInputStream(out.toByteArray());
      }

      Preconditions.checkNotNull(is).reset();

      Movie movie = Movie.decodeStream(is);

      MovieDrawer drawer = new MovieDrawer(movie);

      MovieFrame[] frames = new MovieFrame[decoder.getFrameCount()];
      int currTime = 0;
      for (int frameNumber = 0, N = frames.length; frameNumber < N; frameNumber++) {
        int frameDuration = decoder.getFrameDurationMs(frameNumber);
        currTime += frameDuration;
        frames[frameNumber] =
            new MovieFrame(
                drawer,
                currTime,
                frameDuration,
                movie.width(),
                movie.height(),
                translateFrameDisposal(decoder.getFrameDisposal(frameNumber)));
      }
      return new CloseableAnimatedImage(
          AnimatedImageResult.forAnimatedImage(
              new MovieAnimatedImage(
                  frames,
                  encodedImage.getSize(),
                  movie.duration(),
                  decoder.getLoopCount(),
                  options.animatedBitmapConfig)),
          false);
    } catch (IOException e) {
      throw new RuntimeException("Error while decoding gif", e);
    } finally {
      try {
        Preconditions.checkNotNull(is).close();
      } catch (IOException ignored) {
      }
    }
  }
A simple Gif decoder that uses Android's {@link Movie} class to decode Gif images.
animated-gif-lite/src/main/java/com/facebook/animated/giflite/GifDecoder.java