2

I'm trying to find out end of gif with glide.

this is the code that I find on web:

Glide.with(thisActivity).asGif().load(R.raw.logo_gif_motion_low).listener(object : RequestListener<GifDrawable> {
                override fun onLoadFailed(p0: GlideException?, p1: Any?, p2: Target<GifDrawable>, p3: Boolean): Boolean {

                }
                override  fun onResourceReady(p0: GifDrawable?, p1: Any?, p2: Target<GifDrawable>, p3: DataSource?, p4: Boolean): Boolean {

                    return false
                }
            }).into(splashscreen);

the problem is , it doesn't accept GifDrawable in Target.

the error saying that:

enter image description here

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ahad Porkar
  • 1,666
  • 2
  • 33
  • 68

3 Answers3

6

Use

target: com.bumptech.glide.request.target.Target<GifDrawable>?

instead of

Target<GifDrawable>

Try this

    Glide.with(this).asGif().load("").listener(object : RequestListener<GifDrawable> {
        override fun onResourceReady(resource: GifDrawable?, model: Any?, target: Target<GifDrawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
            TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
        }

        override fun onLoadFailed(e: GlideException?, model: Any?, target: com.bumptech.glide.request.target.Target<GifDrawable>?, isFirstResource: Boolean): Boolean {
            TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
        }


    }).into(splashscreen)
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
1

In your build.gradle file add following

Including Glide’s annotation processor requires dependencies on Glide’s annotations and the annotation processor:

compile 'com.github.bumptech.glide:annotations:4.8.0'

Add a dependency on Glide’s annotation processor:

repositories {
 mavenCentral()
 }

dependencies {
 annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
}
sasikumar
  • 12,540
  • 3
  • 28
  • 48
1

Import the latest Glide dependencies to grade file.

implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'

Then use one of these solutions:

Glide.with(thisActivity)
        .asGif()
        .load(R.raw.logo_gif_motion_low)
        .listener(object : RequestListener<GifDrawable> {
            override fun onResourceReady(resource: GifDrawable?, model: Any?, target: Target<GifDrawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
                // TODO: Process your gif drawable here
                return false
            }

            override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<GifDrawable>?, isFirstResource: Boolean): Boolean {
                return false
            }
        }).into(splashscreen)

or

Glide.with(thisActivity)
        .load(R.raw.logo_gif_motion_low)
        .listener(object : RequestListener<Drawable> {
            override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
                val gifDrawable = resource as GifDrawable?
                gifDrawable?.let {
                    // TODO: Process your gif drawable here
                }
                return false
            }

            override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
                return false
            }
        })
        .into(splashscreen)
Son Truong
  • 13,661
  • 5
  • 32
  • 58