2

I am using Glide to load GIF image in splash screen. After completion of GIF loading, I want to open next activity using Intent.

I tried below code,

Glide.with(this).load(R.drawable.image1).override(width, height).into(imageViewTarget);

and Glide Version : com.github.bumptech.glide:glide:3.7.0'

But not able to find any help, please help to solve this.

Sam Judd
  • 7,317
  • 1
  • 38
  • 38
Janak
  • 607
  • 5
  • 23
  • Add listener to your glide then go your another activity after done. And make sure your image view is visible, otherwise glide has the issue with image visibility http://stackoverflow.com/questions/32503327/glide-listener-doesnt-work. – james Oct 20 '16 at 10:17

3 Answers3

2

Just spent a couple hours trying to find a solution for this for Glide V4 and this is what I finally came across and it works perfect. https://github.com/bumptech/glide/pull/3438

        @Override
        public boolean onResourceReady(GifDrawable resource, Object model, Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) {
            resource.setLoopCount(1);
            resource.registerAnimationCallback(new Animatable2Compat.AnimationCallback() {
                @Override
                public void onAnimationEnd(Drawable drawable) {
                    //in your case start new Activity
                }
            });
            return false;
        }
    }).into(imageView);
landnbloc
  • 498
  • 4
  • 10
1

put listner to handle this..

     Glide.with(this)
    .load(R.drawable.image1)
    .asGif()
    .override(width, height)
                 .listener(new RequestListener<String, GlideDrawable>() {
                                    @Override
                                    public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                                        return false;
                                    }

                                    @Override
                                    public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                                       //AFTER LOAD OUT YOUR LOGIC
                                      //open next activity
                                        return false;
                                    }
                                })
     .into(imageViewTarget);

and make sure your imageview is always visible. Hope this helps..

Nikhil Borad
  • 2,065
  • 16
  • 20
  • With this Glide Version : com.github.bumptech.glide:glide:3.7.0', if I use asGif() It's not work. It will generate an error in code. – Janak Oct 20 '16 at 12:07
1

From my point of view,what you want is to start another activity when the GIF Animation finished rather than the gif is just load into your ImageView. In such case, you'd better measure how long it will take to finish the gif animation and make it a local variable.In order to make sure the gif animation is complete,it's better to make the time a bit longer than the animation costs. Then do it like this.

long gifAnimationTime = 1000;// A bit more than the gif animation,you can ajust this to your situation.
Glide.with(this)
        .load(R.drawable.image1)
        .listener(new RequestListener<String, GlideDrawable>() {
            @Override
            public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                return false;
            }

            @Override
            public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                new Timer().schedule(new TimerTask() {
                    @Override
                    public void run() {
                        // start your activity here.
                    }
                }, gifAnimationTime);
                return false;
            }
        })
        .into(imageViewTarget);    

I got something new.Try this:

    Movie movie = Movie.decodeByteArray(gifdata,offset,length);
    long period = movie.duration();
superjos
  • 12,189
  • 6
  • 89
  • 134
Qian Sijianhao
  • 564
  • 7
  • 19
  • No, I don't want to provide fixed time. Will get time form gif then it will help. – Janak Oct 20 '16 at 10:51
  • You'd better known that gif is made of several frames and keeps looping.There seems no way to measure its single period in android. – Qian Sijianhao Oct 20 '16 at 10:59
  • If you have to do this,you can try to make the gif into seperate pictures using **GifSplitter**.Then it is easy to create an animation with the pictures . – Qian Sijianhao Oct 20 '16 at 11:03
  • It will take more time because Split and Generate new gif in splash screen, we have to provide max 6sec not more then that. – Janak Oct 20 '16 at 11:10
  • I modified my answer above.Have a try. – Qian Sijianhao Oct 20 '16 at 11:12
  • Not work, because in this we have to provideByteArray. – Janak Oct 20 '16 at 11:19
  • Due to my limited network,it seems difficult for me to join the chat.The page shows "Loading discussion between ... and ... Just a second." for quite a long time. You can transfer it into ByteArray by this: Glide.with(context).load(url).asBitmap().toBytes().listener(......) – Qian Sijianhao Oct 20 '16 at 11:31
  • If I convert in to Bitmap or in to Bytes Array then it will not work like a GIF. – Janak Oct 20 '16 at 11:34