B4A Library Image Slider wrapper (daimajia.AndroidImageSlider)

Discussion in 'Additional libraries, classes and official updates' started by Asim A Baki, Oct 30, 2015.

  1. Asim A Baki

    Asim A Baki Active Member Licensed User

    Hi
    This is my first experience with Library wrappers

    Below is the wrapper for daimajia.AndroidImageSlider
    from https://github.com/daimajia/AndroidImageSlider

    [​IMG]


    simple to use, it is very simple features as well, I'll post here the source code for the wrapper in case someone wants to help enhancing the wrapper

    to use the wrapper
    1- Extract the "res" folder to your any path
    2- Extract the "jar1.zip" and "jar2.zip" attachments to your android additional library folder
    3- Add android-support-v4.jar to your android additional library folder
    4- Create a new project
    5- Goto the Libraries Manager and check AndroidSlider library
    6- Add the line below to Project Attributes region
    Code:
    #AdditionalRes: YOUR-RES-FOLDER-PATH, com.daimajia.slider.library
    7- Add Slider object to the Globals sub
    Code:
    Dim Slider As Slider
    8- replace the Activity_create sub with the following code
    Code:
    Sub Activity_Create(FirstTime As Boolean)
        
    'Do not forget to load the layout file created with the visual designer. For example:
        'Activity.LoadLayout("Layout1")
        Activity.LoadLayout("1")
         
    Slider.Initialize("Slider")
       
        
    Activity.AddView(Slider,0dip,0dip,100%x,100%y)
    '   
        Slider.AddSlide("Hannibal""http://static2.hypable.com/wp-content/uploads/2013/12/hannibal-season-2-release-date.jpg")
        
    Slider.AddSlide("Big Bang Theory""http://tvfiles.alphacoders.com/100/hdclearart-10.png")
        
    Slider.AddSlide("House of Cards""http://cdn3.nflximg.net/images/3093/2043093.jpg")
        
    Slider.AddSlide("Game of Thrones""http://images.boomsbeat.com/data/images/full/19640/game-of-thrones-season-4-jpg.jpg")
       
        
    Dim filelist As List = File.ListFiles(File.DirDefaultExternal  )
       
        
    For Each fi As String In filelist
            
    Dim path As String =File.Combine(File.DirDefaultExternal  , fi)
            
    If fi.LastIndexOf (".JPG")>0 Or fi.LastIndexOf (".png")>0  Then        
                
    Slider.AddSlide(fi , "file:" & path )
                
            
    End If
           
        
    Next
        
    Slider.SetTransition(Slider.SLIDER_TRANSITION_Fade)
        
    Slider.Delay=5000
        
    Slider.Start
    End Sub
     

    Attached Files:

  2. susu

    susu Well-Known Member Licensed User

    Thank you @Asim A Baki . But how can I get click event?
     
  3. Asim A Baki

    Asim A Baki Active Member Licensed User

    Actually I didn't implement the events, I just made what I needed for the time being, and I have posted the source code, just in case someone may help in improving the wrapper and re-post in the forum
     
    susu likes this.
  4. cambopad

    cambopad Active Member Licensed User

    Thanks you for sharing this awesome lib! This is really good to showcase our photos.
     
  5. Pcbeta Rabbit

    Pcbeta Rabbit Member Licensed User

    Bitmap format at this stage can not import it?
     
  6. andyr00d

    andyr00d Member Licensed User

    I'm getting a crash running your example project in release and debug mode... I have placed the files where they should go and there are no errors before I compile?

    Code:
    java.lang.IllegalAccessError: Method 'void android.support.v4.view.PagerAdapter.registerDataSetObserver(android.database.DataSetObserver)' is inaccessible to class 'com.daimajia.slider.library.Tricks.ViewPagerEx' (declaration of 'com.daimajia.slider.library.Tricks.ViewPagerEx' appears in /data/app/b4a.example-1/base.apk)
     
  7. Asim A Baki

    Asim A Baki Active Member Licensed User

    You need to have the right android-support-v4.jar added to your lib folder, the right file size is 758727KB length so I couldn't attach to the post but look for the file in the internet with the same size
     
  8. andyr00d

    andyr00d Member Licensed User

    ok I will try and find another version... but do you mean bytes? because 758727 KB = 758 MB :)
     
    Peter Simpson and Asim A Baki like this.
  9. Asim A Baki

    Asim A Baki Active Member Licensed User

    yes bytes, sorry for mistake
     
  10. phukol

    phukol Active Member Licensed User

    Thank you for the great library. Just want to ask what should i do if i want to use the images inside DirAssets? how should i go about in calling them?
     
  11. Asim A Baki

    Asim A Baki Active Member Licensed User

    I tried it before but looks like the uploading of assets to DirAssets cause the images to have a different header, I even tried to open the images by android album but it didn't work
     
    phukol likes this.
  12. phukol

    phukol Active Member Licensed User

    Thanks Asim, i really wish it could be possible because i do not see any difference when the images are from online (theyre just downloaded to phone right?) and from internal phone resources.
     
  13. Asim A Baki

    Asim A Baki Active Member Licensed User

    this protion of code adds images from the phone, if I understand you right, but the DirAssets specially which it's files are added from the B4X designer doesn't work

    Code:
    Dim filelist As List = File.ListFiles(File.DirDefaultExternal  )
      
        
    For Each fi As String In filelist
            
    Dim path As String =File.Combine(File.DirDefaultExternal  , fi)
            
    If fi.LastIndexOf (".JPG")>0 Or fi.LastIndexOf (".png")>0  Then       
                
    Slider.AddSlide(fi , "file:" & path )
               
            
    End If
          
        
    Next
     
    phukol likes this.
  14. phukol

    phukol Active Member Licensed User

    Thanks Asim, from the bottom of my heart here in the Philippines, salamat. I just want to know a better sliding image alternative aside from the slidingpanels that i can use ....
     
  15. Mashiane

    Mashiane Expert Licensed User

    Hi, I'm getting an error

    Code:
    java.lang.NoSuchFieldError: com.daimajia.slider.library.R$attr.SliderStyle
    on compilation of your example, any advise please...
     
  16. Johan Schoeman

    Johan Schoeman Expert Licensed User

    I think you are missing this step in post #1.....?

    1- Extract the "res" folder to your any path

    Code:
    #AdditionalRes: YOUR-RES-FOLDER-PATH, com.daimajia.slider.library
     
    Last edited: Dec 3, 2015
    Asim A Baki likes this.
  17. Blue.Sky

    Blue.Sky Active Member Licensed User

    @Asim A Baki Excellent
    Thank you for sharing this library
    ImageChanged Event does not work
    What is the reason?

    Code:
    Sub Slider_ImageChanged(index As Int)
        
    Log("ImageChanged")
    End Sub
     
  18. Asim A Baki

    Asim A Baki Active Member Licensed User

    Actually I didn't implement the events, I just made what I needed for the time being, and I have posted the source code, just in case someone may help in improving the wrapper and re-post in the forum
     
    Blue.Sky likes this.
  19. cwkoomy

    cwkoomy Member Licensed User

    ** Activity (main) Pause, UserClosed = true ** how to use .sorry, im newbie
     
  20. Anser

    Anser Well-Known Member Licensed User

    Good work @Asim A Baki

    This library seems to be very useful. Most of the apps available in the PlayStore seems to have used this kind of ImageSlider View to show sliding images in their apps in one way or other.

    Unfortunately, this lib, the only ImageSliderView lib available that can be used in B4A does not support Click event.

    1. Has anyone here modified the source to support click event ?
    2. Will this view support display of Image from a table's Blob column ie without writing the file to the device's File.DirInternal/File.External. For eg
      Slider.AddSlide("Test", BlobColumnData )
     
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