B4A Class [custom view] GifViewer

Discussion in 'Additional libraries, classes and official updates' started by Erel, Jul 26, 2017.

  1. Erel

    Erel Administrator Staff Member Licensed User

    [​IMG]

    Simple view that shows an animated gif. Based on agraham's GifDecoder library.

    The animated gifs included in this example are from giphy.com. I'm not sure whether they can be used commercially or not.

    Tip: B4J ImageView supports animated gifs.

    V1.20 - Images are cached once loaded. You need to add the following variable to the Main module:
    Code:
    Sub Process_Globals
       
    Public GifsCache As Map
    End Sub
     

    Attached Files:

    Last edited: Jul 27, 2017
  2. Erel

    Erel Administrator Staff Member Licensed User

    I've uploaded a new version. You should call GifViewer1.CallFromResume from Activity_Resume. This allows the animation to continue after activity is resumed.

    While the examples work properly in debug mode they look better in release mode.
     
    somed3v3loper likes this.
  3. Erel

    Erel Administrator Staff Member Licensed User

    Example of using it in a CustomLayoutDialog (Dialogs library):

    [​IMG]
     

    Attached Files:

    Last edited: Jul 27, 2017
  4. LucaMs

    LucaMs Expert Licensed User

    Copying updated assets files (4)
    *** Service (starter) Create ***
    ** Service (starter) Start **
    ** Activity (main) Create, isFirst = true **
    java.lang.OutOfMemoryError
    at android.graphics.Bitmap.nativeCreate(Native Method)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:882)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:906)
    at anywheresoftware.b4a.agraham.gifdecoder.GifDecoder.SetPixels(GifDecoder.java:298)
    at anywheresoftware.b4a.agraham.gifdecoder.GifDecoder.SetPixels(GifDecoder.java:396)
    at anywheresoftware.b4a.agraham.gifdecoder.GifDecoder.ReadImage(GifDecoder.java:805)
    at anywheresoftware.b4a.agraham.gifdecoder.GifDecoder.ReadContents(GifDecoder.java:672)
    at anywheresoftware.b4a.agraham.gifdecoder.GifDecoder.Read(GifDecoder.java:559)
    at anywheresoftware.b4a.agraham.gifdecoder.GifDecoder.Load(GifDecoder.java:211)
    at b4a.example.gifviewer._setgif(gifviewer.java:64)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
    at b4a.example.main.afterFirstLayout(main.java:102)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:149)
    at android.app.ActivityThread.main(ActivityThread.java:5257)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
    at dalvik.system.NativeStart.main(Native Method)
    ** Activity (main) Resume **


    Tablet, 7.70 Gb free (your first example).
     
  5. LucaMs

    LucaMs Expert Licensed User

    It is Source.gif (app crashes even if If I use GifViewer3 only)
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Use a smaller gif file or set android:largeHeap to true.
     
    LucaMs likes this.
  7. LucaMs

    LucaMs Expert Licensed User

    This was enough but... I flipped my tablet (then restated Activity_Create) and crash again. Somewhere something does not free memory.


    P.S. DisposeFrames?
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Probably. I will check it.
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    V1.20 is released. The decoded frames are cached. Note that you need to add the following variable to the main module:
    Code:
    Sub Process_Globals
       
    Public GifsCache As Map
    End Sub
     
    Rantor777 likes this.
  10. omarruben

    omarruben Member Licensed User

    Is it possible to create ,by code, a new gifviewer object from the cache???, I have already load a few gifs, then I want to create a random gifviewer-objects without loading again from the file.
     
  11. Erel

    Erel Administrator Staff Member Licensed User

  12. Mike1970

    Mike1970 Active Member Licensed User

    Hi everyone, someone knows whats the problem here?
    i jsut copied the class and loaded my gif


    Error occurred on line: 63 (Main)
    java.lang.RuntimeException: Class instance was not initialized (gifviewer)
    at anywheresoftware.b4a.debug.Debug.shouldDelegate(Debug.java:241)
    at b4a.example.gifviewer._setgif(gifviewer.java:59)
    at b4a.example.main._activity_create(main.java:450)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:360)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.example.main.afterFirstLayout(main.java:104)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:82)
    at android.os.Handler.handleCallback(Handler.java:815)
    at android.os.Handler.dispatchMessage(Handler.java:104)
    at android.os.Looper.loop(Looper.java:207)
    at android.app.ActivityThread.main(ActivityThread.java:6020)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:936)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:797)
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    Have you added it with the designer?
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice