B4A Library [B4X] B4XGifView - Cross platform animated gif view

1591098949811.png


I was missing a cross platform, animated gif view, so created one.

Usage is simple:
Add with the visual designer and call SetGif to set the gif file.


The B4i implementation depends on FLAnimatedImage open source project: https://github.com/Flipboard/FLAnimatedImage
The FLAnimatedImage library was uploaded to the hosted builders. If you are using a local Mac then download FLAnimatedImage-Mac and copy the files to the Libs folder.
The B4A implementation is based on this open source project: https://github.com/koral--/android-gif-drawable
The two dependent aars are attached. Copy them to B4A additional libraries folder.

Updates:

1.12 - SetGif2 - Allows loading an animated gif from an array of bytes.
1.11 - GIF image ratio is preserved.
1.10 - New B4A implementation based on Android GIF Drawable. It provides better performance. Note that the Activity_Resume method has been removed. Don't miss the B4A-Dependencies zip file.
 

Attachments

  • B4A-Dependencies.zip
    168.2 KB · Views: 3,145
  • Example.zip
    256.4 KB · Views: 1,800
  • B4XGifView.b4xlib
    1.5 KB · Views: 2,052
  • FLAnimatedImage-Mac.zip
    140 KB · Views: 443
Last edited:

Beja

Expert
Licensed User
Longtime User
Hi Erel,
Tried to run the B4A example and got this error message.. Any meaning appreciated..

Could not find file 'C:\B4A95\libraries\relinker-1.3.1.aar'.
 

Beja

Expert
Licensed User
Longtime User
You need to download B4A-dependencies.zip, unzip it and copy the files to the additional libraries folder. It is attached to the first post.

Perfect.. working like a charm.. the two GIF files loaded in no time and started immediately!!

Thanks Erel
 

AnandGupta

Expert
Licensed User
Longtime User
Can I Start & Stop Animation ?
See

Regards,

Anand
 

Guenter Becker

Active Member
Licensed User
View attachment 95135

I was missing a cross platform, animated gif view, so created one.

Usage is simple:
Add with the visual designer and call SetGif to set the gif file.


The B4i implementation depends on FLAnimatedImage open source project: https://github.com/Flipboard/FLAnimatedImage
The FLAnimatedImage library was uploaded to the hosted builders. If you are using a local Mac then download FLAnimatedImage-Mac and copy the files to the Libs folder.
The B4A implementation is based on this open source project: https://github.com/koral--/android-gif-drawable
The two dependent aars are attached. Copy them to B4A additional libraries folder.

Updates:

1.11 - GIF image ratio is preserved.
1.10 - New B4A implementation based on Android GIF Drawable. It provides better performance. Note that the Activity_Resume method has been removed. Don't miss the B4A-Dependencies zip file.


Hello, hope you are well.
Is it possible and if yes how to do it, to start/stop the animation by code?I
Is it possible and if yes how to do it, to start/stop repeating the animation by code?
 

AnandGupta

Expert
Licensed User
Longtime User
See,

Regards,

Anand
 

Daica

Active Member
Licensed User
Hi Erel, do you think you can add a click event to this library?
Thank you!

I tried editing the source code and added:

B4X:
#Event: Click

Private Sub iv_Click
    If xui.SubExists(mCallBack,mEventName&"_Click",0) Then
        CallSub(mCallBack,mEventName&"_Click")
    End If
End Sub

Nothing happens when I click the view. I think I might be doing something wrong?
 
Last edited:

Unobtainius

Active Member
Licensed User
Longtime User
it could be other languages I am used to but
mEventName&"_Click"
in a continuous line looks odd to me
does
mEventName & "_Click" work?
 

Daica

Active Member
Licensed User
it could be other languages I am used to but
mEventName&"_Click"
in a continuous line looks odd to me
does
mEventName & "_Click" work?

I tried to format it correctly but nothing happens when I click. Maybe the view that is being returned isn't the one that is actually being clicked on?
 

Unobtainius

Active Member
Licensed User
Longtime User
Sorry I cant help much I've never dived into the source code of any of the controls before but I think you may be on the right track.
They are usually made up of a few control and IV is like the base for getting at the other controls, so yeah, dig a bit deeper, the click event of some of the other controls may yield a result. Good luck
 

Unobtainius

Active Member
Licensed User
Longtime User
Also, it's best not to post questions directly at Erel, as we are all here to help if we can.
plus @klaus will tell you off ;)
 

Daica

Active Member
Licensed User
Also, it's best not to post questions directly at Erel, as we are all here to help if we can.
plus @klaus will tell you off ;)

I know there are many great talented people here, I just assumed since Erel created it, I should direct the attention of the person writing the library.
 

LucaMs

Expert
Licensed User
Longtime User
I tried editing the source code and added:

B4X:
#Event: Click

Private Sub iv_Click
If xui.SubExists(mCallBack,mEventName&"_Click",0) Then
CallSub(mCallBack,mEventName&"_Click")
End If
End Sub
Nothing happens when I click the view. I think I might be doing something wrong?
The wrong thing is that you should also set the event name when the ImageView is initialized, within the DesignerCreateView routine:
B4X:
Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
    mBase = Base
    Tag = mBase.Tag
    mBase.Tag = Me
    #if B4J
    iv.Initialize("iv") '<--------- here
    mBase.AddView(iv, 0, 0, mBase.Width, mBase.Height)
    #Else If B4i
    Dim no As NativeObject
    AnimatedImageView = no.Initialize("FLAnimatedImageView").RunMethod("new", Null)
    mBase.AddView(AnimatedImageView, 0, 0, mBase.Width, mBase.Height)
    Dim iv As ImageView = AnimatedImageView
    iv.ContentMode = iv.MODE_FIT
    #Else If B4A
    iv.Initialize("iv") ' <--------- here
    mBase.AddView(iv, 0, 0, mBase.Width, mBase.Height)
    #End If
End Sub
As you can see I did it and it works but I couldn't do it for B4i.

I'm attaching a version (1.12) that works with B4A and B4J; Erel will probably be able to fix it to work with B4i as well.
a.gif
 

Attachments

  • B4XGifView.b4xlib
    1.5 KB · Views: 339
Last edited:

Daica

Active Member
Licensed User
The wrong thing is that you should also set the event name when the ImageView is initialized, within the DesignerCreateView routine:

Ahh of course, there is no event name so there is no _click event for the iv. ?‍♂️
 

aeric

Expert
Licensed User
Longtime User
The wrong thing is that you should also set the event name when the ImageView is initialized, within the DesignerCreateView routine:
B4X:
Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
    mBase = Base
    Tag = mBase.Tag
    mBase.Tag = Me
    #if B4J
    iv.Initialize("iv") '<--------- here
    mBase.AddView(iv, 0, 0, mBase.Width, mBase.Height)
    #Else If B4i
    Dim no As NativeObject
    AnimatedImageView = no.Initialize("FLAnimatedImageView").RunMethod("new", Null)
    mBase.AddView(AnimatedImageView, 0, 0, mBase.Width, mBase.Height)
    Dim iv As ImageView = AnimatedImageView
    iv.ContentMode = iv.MODE_FIT
    #Else If B4A
    iv.Initialize("iv") ' <--------- here
    mBase.AddView(iv, 0, 0, mBase.Width, mBase.Height)
    #End If
End Sub
As you can see I did it and it works but I couldn't do it for B4i.

I'm attaching a version (1.12) that works with B4A and B4J; Erel will probably be able to fix it to work with B4i as well.
View attachment 115395
It works for B4J and B4A.
I tried to make it work with B4i but no success.
In B4i, when I don't have an image loaded, the click event is fired but once I loaded a Gif file, the click event is not fired.
 
Top