ImageSlider

DonManfred

Expert
Licensed User
Longtime User
This is (another) wrap for this Github project.
It is kind of the same as the lib posted here.

The Lib requires B4A 6+ and the new maven repositories as it requires Android support v4 and AppCompat.
The lib depends on 3rd party libs Nineoldandroids and Picasso. Both are included in the library zip.

ImageSlider
Comment:
AndroidSlider currently wraps version x
https://github.com/daimajia/AndroidImageSlider
Author: DonManfred (wrapper)
Version: 1.1
PagerIndicator
Events:

  • onClick ( As )
Methods:
  • DesignerCreateView (base As anywheresoftware.b4a.objects.PanelWrapper, lw As anywheresoftware.b4a.objects.LabelWrapper, props As anywheresoftware.b4a.objects.collections.Map) As void
  • setDefaultIndicatorColor (selectedColor As int, unselectedColor As int) As void
    if you are using the default indicator , this method will help you to set the selected status and
    the unselected status color.
    selectedColor:
    unselectedColor:
  • setIndicatorStyleResource (selected As java.lang.String, unselected As java.lang.String) As void
    Set Indicator style.
    selected: page selected drawable
    unselected: page unselected drawable
  • IsInitialized As boolean
  • Initialize (ba As anywheresoftware.b4a.BA, EventName As java.lang.String) As void
  • setDefaultIndicatorSize (width As float, height As float) As void
  • BringToFront As void
  • SetLayout (arg0 As int, arg1 As int, arg2 As int, arg3 As int) As void
  • GetApplicationDrawableID (DrawableName As java.lang.String) As int
    Get a Drawable from the Application Resources.
    Returns Null if the Drawable is not found.
  • SendToBack As void
  • SetVisibleAnimated (arg0 As int, arg1 As boolean) As void
  • setDefaultUnselectedIndicatorSize (width As float, height As float) As void
  • RemoveView As void
  • Invalidate3 (arg0 As int, arg1 As int, arg2 As int, arg3 As int) As void
  • setDefaultSelectedIndicatorSize (width As float, height As float) As void
  • Invalidate2 (arg0 As android.graphics.Rect) As void
  • SetColorAnimated (arg0 As int, arg1 As int, arg2 As int) As void
  • SetBackgroundImage (arg0 As android.graphics.Bitmap) As void
  • Invalidate As void
  • SetLayoutAnimated (arg0 As int, arg1 As int, arg2 As int, arg3 As int, arg4 As int) As void
  • RequestFocus As boolean
Properties:
  • Left As int
  • Background As android.graphics.drawable.Drawable
  • Parent As java.lang.Object [read only]
  • DefaultIndicatorShape As java.lang.String [write only]
    if you are using the default indicator, this method will help you to set the shape of
    indicator, there are two kind of shapes you can set, oval and rect.
  • Color As int [write only]
  • Enabled As boolean
  • Top As int
  • Visible As boolean
  • Padding As int[]
  • Height As int
  • Tag As java.lang.Object
  • IndicatorVisible As boolean [write only]
    set the visibility of indicator.
  • Width As int

ImageSlider
Events:

  • onPageScrollStateChanged (state As int)
  • onPageScrolled (position As int, positionOffset As float, positionOffsetPixels As int)
  • onPageSelected (position As int)
  • onSliderClick ( As )
Fields:
  • SLIDER_TRANSITION_FlipPage As int
  • SLIDER_TRANSITION_ZoomIn As int
  • SLIDER_TRANSITION_Tablet As int
  • SLIDER_TRANSITION_CubeIn As int
  • SLIDER_TRANSITION_ZoomOut As int
  • SLIDER_TRANSITION_RotateUp As int
  • SLIDER_TRANSITION_Background2Foreground As int
  • SLIDER_TRANSITION_ZoomOutSlide As int
  • SLIDER_TRANSITION_Default As int
    preset transformers and their names
  • SLIDER_TRANSITION_Fade As int
  • SLIDER_TRANSITION_Accordion As int
  • SLIDER_TRANSITION_RotateDown As int
  • SLIDER_TRANSITION_DepthPage As int
  • SLIDER_TRANSITION_Foreground2Background As int
  • SLIDER_TRANSITION_Stack As int
  • SLIDER_TRANSITION_FlipHorizontal As int
Methods:
  • stopAutoCycle As void
    stop the auto circle
  • DesignerCreateView (base As anywheresoftware.b4a.objects.PanelWrapper, lw As anywheresoftware.b4a.objects.LabelWrapper, props As anywheresoftware.b4a.objects.collections.Map) As void
  • onSliderClick (slider As com.daimajia.slider.library.SliderTypes.BaseSliderView) As void
  • IsInitialized As boolean
  • Initialize (ba As anywheresoftware.b4a.BA, EventName As java.lang.String) As void
  • BringToFront As void
  • SetLayout (arg0 As int, arg1 As int, arg2 As int, arg3 As int) As void
  • setSliderTransformDuration (period As int, interpolator As android.view.animation.Interpolator) As void
    set the duration between two slider changes.
    period:
    interpolator:
  • SendToBack As void
  • SetVisibleAnimated (arg0 As int, arg1 As boolean) As void
  • RemoveView As void
  • Invalidate3 (arg0 As int, arg1 As int, arg2 As int, arg3 As int) As void
  • Invalidate2 (arg0 As android.graphics.Rect) As void
  • SetColorAnimated (arg0 As int, arg1 As int, arg2 As int) As void
  • startAutoCycle As void
  • SetBackgroundImage (arg0 As android.graphics.Bitmap) As void
  • addSliderLocal (name As java.lang.String, path As java.lang.String, scale As com.daimajia.slider.library.SliderTypes.BaseSliderView.ScaleType) As void
  • addSliderUrl (name As java.lang.String, url As java.lang.String, scale As com.daimajia.slider.library.SliderTypes.BaseSliderView.ScaleType) As void
  • Invalidate As void
  • startAutoCycle2 (delay As long, duration As long, autoRecover As boolean) As void
    start auto cycle.
    delay: delay time
    duration: animation duration time.
    autoRecover: if recover after user touches the slider.
  • removeAllSliders As void
  • SetLayoutAnimated (arg0 As int, arg1 As int, arg2 As int, arg3 As int, arg4 As int) As void
  • RequestFocus As boolean
Permissions:
  • android.permission.ACCESS_NETWORK_STATE
  • android.permission.INTERNET
  • android.permission.READ_EXTERNAL_STORAGE
  • android.permission.WAKE_LOCK
  • android.permission.WRITE_EXTERNAL_STORAGE
Properties:
  • PresetTransformer2 As com.daimajia.slider.library.SliderLayout.Transformer [write only]
  • Left As int
  • RotateUp As com.daimajia.slider.library.SliderLayout.Transformer [read only]
  • Parent As java.lang.Object [read only]
  • PresetIndicator As java.lang.String [write only]
  • FitCenterCrop As com.daimajia.slider.library.SliderTypes.BaseSliderView.ScaleType [read only]
  • FlipPage As com.daimajia.slider.library.SliderLayout.Transformer [read only]
  • FlipHorizontal As com.daimajia.slider.library.SliderLayout.Transformer [read only]
  • ZoomOutSlide As com.daimajia.slider.library.SliderLayout.Transformer [read only]
  • CurrentPosition As int [read only]
    get the current item position
  • Visible As boolean
  • Padding As int[]
  • Tablet As com.daimajia.slider.library.SliderLayout.Transformer [read only]
  • Height As int
  • ZoomIn As com.daimajia.slider.library.SliderLayout.Transformer [read only]
  • DepthPage As com.daimajia.slider.library.SliderLayout.Transformer [read only]
  • Width As int
  • RotateDown As com.daimajia.slider.library.SliderLayout.Transformer [read only]
  • Background As android.graphics.drawable.Drawable
  • Background2Foreground As com.daimajia.slider.library.SliderLayout.Transformer [read only]
  • Color As int [write only]
  • CenterCrop As com.daimajia.slider.library.SliderTypes.BaseSliderView.ScaleType [read only]
  • CubeIn As com.daimajia.slider.library.SliderLayout.Transformer [read only]
  • Enabled As boolean
  • Duration As long [write only]
    set the duration between two slider changes. the duration value must >= 500
  • CustomIndicator As com.daimajia.slider.library.Indicators.PagerIndicator [write only]
  • CenterInside As com.daimajia.slider.library.SliderTypes.BaseSliderView.ScaleType [read only]
  • Default As com.daimajia.slider.library.SliderLayout.Transformer [read only]
  • Stack As com.daimajia.slider.library.SliderLayout.Transformer [read only]
  • Fit As com.daimajia.slider.library.SliderTypes.BaseSliderView.ScaleType [read only]
  • ZoomOut As com.daimajia.slider.library.SliderLayout.Transformer [read only]
  • PresetTransformer As java.lang.String [write only]
  • Accordion As com.daimajia.slider.library.SliderLayout.Transformer [read only]
  • Top As int
  • CurrentSlider As com.daimajia.slider.library.SliderTypes.BaseSliderView [read only]
    get current slider.
  • Tag As java.lang.Object
  • Fade As com.daimajia.slider.library.SliderLayout.Transformer [read only]
  • Foreground2Background As com.daimajia.slider.library.SliderLayout.Transformer [read only]

Example Code (See Example zip)

B4X:
#Extends: android.support.v7.app.AppCompatActivity
#AdditionalRes: ..\res

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Type SlideImage(name As String, path As String)
    Dim slides As List
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private slider As ImageSlider
    Private indicator As PagerIndicator
    Private currentImage As SlideImage
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    ' Globale Liste von "Slides" (List of SlideImage)
    ' Wird benötigt, um beim erreichen eines Bildes seinen Namen (pfad) wieder zu erhalten...
    slides.Initialize
  
    indicator.DefaultIndicatorShape = "Rectangle"
    indicator.setDefaultIndicatorColor(Colors.Red,Colors.Gray)
    indicator.setDefaultIndicatorSize(1dip,1dip)
    indicator.setDefaultSelectedIndicatorSize(5dip,1dip)
    indicator.setDefaultUnselectedIndicatorSize(1dip,1dip)
    indicator.Visible = True
    slider.CustomIndicator = indicator
    'indicator.setIndicatorStyleResource("ic_action_camera","ic_action_chat")
  
    Dim flist As List
    flist = File.ListFiles(File.DirRootExternal&"/DCIM/Holger.Bilder")
    Log(flist)
    For i = 0 To flist.Size-1
        Dim f As String = flist.Get(i)
        If f.StartsWith(".") Then
        Else
            Log("File added: "&f)  
            Dim sl As SlideImage
            sl.Initialize
            sl.name = f
            sl.path = File.DirRootExternal&"/DCIM/Holger.Bilder/"&f
            slides.Add(sl)
          
            slider.addSliderLocal(sl.name,sl.path,slider.CenterCrop)
        End If
    Next
    ' Wir legen auch einen Eintrag in der globalen Liste ab für Einträge die per URL aufgenommen werden
    Dim sl As SlideImage
    sl.Initialize
    sl.name = "GoT"
    sl.path = "http://images.boomsbeat.com/data/images/full/19640/game-of-thrones-season-4-jpg.jpg"
    slides.Add(sl)
  
    slider.addSliderUrl(sl.name,sl.path,slider.CenterInside)
  
    slider.PresetTransformer2 = slider.Accordion
    Log(slider.CurrentPosition)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Slider_onSliderClick()
    Log($"Slider_onClick()"$)  
End Sub
Sub Slider_onPageScrollStateChanged(state As Int)
    'Log($"Slider_onPageScrollStateChanged(${state})"$)
End Sub
Sub Slider_onPageScrolled(position As Int, positionOffset As Float, positionOffsetPixels As Int)
    'Log($"Slider_onPageScrolled(${position},${positionOffset})"$)
End Sub
Sub Slider_onPageSelected(position As Int)
    Log($"Slider_onPageSelected(${position})"$)  
    ' Setze die globale Variable currentImage (welches ein Type SlideImage ist)
    currentImage = slides.Get(position)
    ' Hier wissen wir, welche Datei (oder URL) gerade aktiv ist.
    Log("Name: "&currentImage.name)
    Log("Path: "&currentImage.path)
End Sub
Sub indicator_onClick()
    Log($"indicator_onClick()"$)
End Sub

This library is Donationware. You can download the library, you can test the library. But if you want to USE the library in your App you need to Donate for it.
Please click here to donate (You can donate any amount you want to donate for the library (or my work) :)
 

Attachments

  • ImageSliderEx.zip
    14.8 KB · Views: 637
  • ImageSliderV1.1.zip
    286.9 KB · Views: 684
Last edited:

desof

Well-Known Member
Licensed User
Longtime User
This line causes me error what should I do?


flist = File.ListFiles(File.DirRootExternal&"/DCIM/Holger.Bilder")
 

desof

Well-Known Member
Licensed User
Longtime User
Hi, I already managed to make it work.
Excellent work and I will make my donation if I can see that the images are animated automatically.
How is this achieved?
 

DonManfred

Expert
Licensed User
Longtime User
if I can see that the images are animated automatically
Play with
B4X:
 slider.PresetTransformer2 = slider.Accordion
The possible transitions are
  • preset transformers and their names
  • SLIDER_TRANSITION_Fade As int
  • SLIDER_TRANSITION_Accordion As int
  • SLIDER_TRANSITION_RotateDown As int
  • SLIDER_TRANSITION_DepthPage As int
  • SLIDER_TRANSITION_Foreground2Background As int
  • SLIDER_TRANSITION_Stack As int
  • SLIDER_TRANSITION_FlipHorizontal As int
 

desof

Well-Known Member
Licensed User
Longtime User
But is it not possible for transitions to be done every 5 seconds automatically?


I'm using this way but they do not automatically pass the images :

B4X:
Sub Activity_Create(FirstTime As Boolean)

    Activity.LoadLayout("Layout1")  
    slides.Initialize
  
    indicator.DefaultIndicatorShape = "Rectangle"
    indicator.setDefaultIndicatorColor(Colors.Red,Colors.Gray)
    indicator.setDefaultIndicatorSize(1dip,1dip)
    indicator.setDefaultSelectedIndicatorSize(5dip,1dip)
    indicator.setDefaultUnselectedIndicatorSize(1dip,1dip)
    indicator.Visible = True
    slider.CustomIndicator = indicator

    Dim flist As List
  
    flist = File.ListFiles(File.DirDefaultExternal&"/")
      
    Dim sl As SlideImage
    sl.Initialize
    sl.name = "GoT"
    sl.path = "http://www.desoft.com.ar/sancrisapp/fotos/1.jpg"
    slides.Add(sl)  
    slider.addSliderUrl("GoT","http://images.boomsbeat.com/data/images/full/19640/game-of-thrones-season-4-jpg.jpg",slider.CenterInside)
  
    slides.Add(sl)
    slider.addSliderUrl("1", "http://www.desoft.com.ar/sancrisapp/fotos/1.jpg",slider.CenterInside)
  
    slides.Add(sl)  
    slider.addSliderUrl("GoT","http://images.boomsbeat.com/data/images/full/19640/game-of-thrones-season-4-jpg.jpg",slider.CenterInside)  
  
    slides.Add(sl)
    slider.addSliderUrl("2", "http://www.desoft.com.ar/sancrisapp/fotos/1.jpg",slider.CenterInside)
  
  
    slider.Duration=5
    slider.PresetTransformer2 = slider.Accordion
    'slides.
    'slider.PresetTransformer2 = slider.Default
    Log(slider.CurrentPosition)
End Sub
 
Last edited:

desof

Well-Known Member
Licensed User
Longtime User
How can I remove this?
I tried with indicator.Visible = False and indicator.Height = 0 and it still remains



GBP0Z8F.png
 

DonManfred

Expert
Licensed User
Longtime User

desof

Well-Known Member
Licensed User
Longtime User
Yes I did but the transparent black rectangle still appears
 

desof

Well-Known Member
Licensed User
Longtime User
Hello please can you tell me how to clean the cache!
Because my app reads the photos of a page but after I update the images I still take the same and it is not the result that I hope to achieve.Please this is urgent.
You help me
 

sdixon

Member
Licensed User
Longtime User
I added the image slider to a view, it's parent is a panel. When I start the app I get the following. What am I missing. Thanks

Line 117 (Main) is

svCoupon.Panel.LoadLayout("coupon") 'load the coupon layout

** Activity (main) Create, isFirst = true **
Error occurred on line: 117 (Main)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at com.unicorn.couponcard.main.afterFirstLayout(main.java:102)
at com.unicorn.couponcard.main.access$000(main.java:17)
at com.unicorn.couponcard.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:64)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
... 17 more
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:202)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2968)
at android.content.res.Resources.getLayout(Resources.java:1984)
at android.view.LayoutInflater.inflate(LayoutInflater.java:425)
at com.daimajia.slider.library.SliderLayout.<init>(SliderLayout.java:172)
at com.daimajia.slider.library.SliderLayout.<init>(SliderLayout.java:166)
at com.daimajia.slider.library.SliderLayout.<init>(SliderLayout.java:162)
at de.donmanfred.SliderWrapper._initialize(SliderWrapper.java:141)
... 20 more
 

sdixon

Member
Licensed User
Longtime User
Thanks. That seemed to have solved that issue. When I get this one working you can expect my donation.
 
Top