B4A Library [Moved] xImageSliderIG

Alexander Stolte

Expert
Licensed User
Longtime User
Adds the PageChange Event to the view:
Header:
#Event: PageChanged(Position As Int)

the only change i made is this: If xui.SubExists(mCallBack, mEventName & "_PageChanged",1) Then CallSub2(mCallBack, mEventName & "_PageChanged",CurrentIndex) End If

Call the Event:
#if b4i
Private Sub ImgCont_ScrollChanged (OffsetX As Int, OffsetY As Int)
    Dim centerIndex As Int = 0
    If OffsetX > 0 Then
        centerIndex = OffsetX/ImgCont.width
    End If
   
    If OffsetX = centerIndex*ImgCont.width Then
#else if b4a
Private Sub ImgCont_PageChanged (Position As Int)
    Dim centerIndex As Int = Position
#end if
        If CurrentIndex <> centerIndex Then
            PrevIndex = CurrentIndex
            CurrentIndex = centerIndex
            ShowCount
            UpdateDots
           
        If xui.SubExists(mCallBack, mEventName & "_PageChanged",1) Then
            CallSub2(mCallBack, mEventName & "_PageChanged",CurrentIndex)
        End If

        End If
#if b4i
    End If
#end if
    ShowImage
End Sub

Tested on android.
 

Devv

Active Member
Licensed User
Longtime User
hello

i am getting this error

*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **

5
** Activity (main) Pause, UserClosed = false **
** Activity (zoom) Create, isFirst = true **
Error occurred on line: 98 (xImageSliderIG)
java.lang.RuntimeException: Object should first be initialized (JavaObject).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4j.object.JavaObject.getCurrentClass(JavaObject.java:258)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:118)
at com.beisat.android.ximagesliderig._designercreateview(ximagesliderig.java:409)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:61)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
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:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at com.beisat.android.zoom.afterFirstLayout(zoom.java:104)
at com.beisat.android.zoom.access$000(zoom.java:17)
at com.beisat.android.zoom$WaitForLayout.run(zoom.java:82)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
** Activity (zoom) Resume **



i have all libraries enabled
 

Attachments

  • Untitled.png
    Untitled.png
    9.7 KB · Views: 246
Last edited:

Alexander Stolte

Expert
Licensed User
Longtime User
i am getting this error
I had the same error, but read this:
activityHasActionBar As Boolean
Set it to false if there is no Action bar (b4a) / Navigation bar (B4I). Default is True. Only needed if the pinch zoom is enabled.

set this property to "false" and try it now.
 

Devv

Active Member
Licensed User
Longtime User
I had the same error, but read this:


set this property to "false" and try it now.
thanks for fast replay

i tried but still the same

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    xImageSliderIG1.activityHasActionBar = False
 

Devv

Active Member
Licensed User
Longtime User
the provided example is working

but copying the same layouts ,code to my project case this error !
 

Brandsum

Well-Known Member
Licensed User
thanks for fast replay

i tried but still the same

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    xImageSliderIG1.activityHasActionBar = False
Could you please post the whole code?
 
Last edited:

Devv

Active Member
Licensed User
Longtime User
Could you please the whole code?


B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: False
#End Region

Sub Process_Globals
End Sub

Sub Globals
    Type SliderContainer(slider As xImageSliderIG, items As List)
    Private CustomListView1 As CustomListView
    Private xImageSliderIG1 As xImageSliderIG
    
    Private sliders As List
End Sub

Sub Activity_Create(FirstTime As Boolean)
    
    xImageSliderIG1.activityHasActionBar = False
    
    Activity.LoadLayout("Layout2")
    sliders.Initialize

    Dim p As Panel
    p.Initialize("")
    p.SetLayout(0,0,100%x,300dip)
    p.LoadLayout("layout1")
        
        
    Dim sc As SliderContainer
    sc.Initialize
    sc.slider = xImageSliderIG1
    sc.items.Initialize
        
    sc.items.Add(CreateMap("image":"https://doduae-image.s3.ap-south-1.amazonaws.com/cache/catalog/banner/2020/web/feb/003/dresseee-327x351.jpg"))
    sc.items.Add(CreateMap("image":"https://doduae-image.s3.ap-south-1.amazonaws.com/cache/catalog/banner/2020/web/feb/003/wintrr-591x628.jpg"))

    sc.slider.SetImages(sc.items)
    sc.slider.SetZoomPanel(Activity)
        
    sliders.Add(sc)
    CustomListView1.Add(p,"")
    CustomListView1.GetPanel(0).Color = Colors.White

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub



Sub xImageSliderIG1_SingleTap(CurrentIndex As Int, Data As Object)
    Dim str As String = Data
    ToastMessageShow("Single Tap:" & CurrentIndex &", "& str,False)
End Sub

Sub xImageSliderIG1_DoubleTap(CurrentIndex As Int, Data As Object)
    Dim str As String = Data
    ToastMessageShow("Double Tap:" & CurrentIndex &", "& str,False)
End Sub
 

Brandsum

Well-Known Member
Licensed User
B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: False
#End Region

Sub Process_Globals
End Sub

Sub Globals
    Type SliderContainer(slider As xImageSliderIG, items As List)
    Private CustomListView1 As CustomListView
    Private xImageSliderIG1 As xImageSliderIG
  
    Private sliders As List
End Sub

Sub Activity_Create(FirstTime As Boolean)
  
    xImageSliderIG1.activityHasActionBar = False
  
    Activity.LoadLayout("Layout2")
    sliders.Initialize

    Dim p As Panel
    p.Initialize("")
    p.SetLayout(0,0,100%x,300dip)
    p.LoadLayout("layout1")
      
      
    Dim sc As SliderContainer
    sc.Initialize
    sc.slider = xImageSliderIG1
    sc.items.Initialize
      
    sc.items.Add(CreateMap("image":"https://doduae-image.s3.ap-south-1.amazonaws.com/cache/catalog/banner/2020/web/feb/003/dresseee-327x351.jpg"))
    sc.items.Add(CreateMap("image":"https://doduae-image.s3.ap-south-1.amazonaws.com/cache/catalog/banner/2020/web/feb/003/wintrr-591x628.jpg"))

    sc.slider.SetImages(sc.items)
    sc.slider.SetZoomPanel(Activity)
      
    sliders.Add(sc)
    CustomListView1.Add(p,"")
    CustomListView1.GetPanel(0).Color = Colors.White

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub



Sub xImageSliderIG1_SingleTap(CurrentIndex As Int, Data As Object)
    Dim str As String = Data
    ToastMessageShow("Single Tap:" & CurrentIndex &", "& str,False)
End Sub

Sub xImageSliderIG1_DoubleTap(CurrentIndex As Int, Data As Object)
    Dim str As String = Data
    ToastMessageShow("Double Tap:" & CurrentIndex &", "& str,False)
End Sub

Your code was wrong. Check this.
B4X:
Sub Activity_Create(FirstTime As Boolean)
   
    'xImageSliderIG1.activityHasActionBar = False
    ...
   
    Dim sc As SliderContainer
    sc.Initialize
    sc.slider = xImageSliderIG1
    sc.items.Initialize
       
    sc.items.Add(CreateMap("image":"https://doduae-image.s3.ap-south-1.amazonaws.com/cache/catalog/banner/2020/web/feb/003/dresseee-327x351.jpg"))
    sc.items.Add(CreateMap("image":"https://doduae-image.s3.ap-south-1.amazonaws.com/cache/catalog/banner/2020/web/feb/003/wintrr-591x628.jpg"))
   
    sc.slider.activityHasActionBar = False 'this should be here
    sc.slider.SetImages(sc.items)
    sc.slider.SetZoomPanel(Activity)
       
    sliders.Add(sc)
    CustomListView1.Add(p,"")
    CustomListView1.GetPanel(0).Color = Colors.White

End Sub
 

Brandsum

Well-Known Member
Licensed User
good to know
Yes. Its because he is using SliderContainer. So he needs to set that property of the slider which is inside that SliderContainer instance. I will recommend using the slider directly for single usage. For multiple sliders in a single page you need SliderContainer.
 
Last edited:

Alexander Stolte

Expert
Licensed User
Longtime User
I have this Error if i click on the view if theres no image loaded:
B4X:
ximagesliderig_imgcont_gd_ontouch (java line: 295)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.get(ArrayList.java:437)
    at anywheresoftware.b4a.objects.collections.List.Get(List.java:117)
    at com.stoltex.fasterinstasaver.ximagesliderig._imgcont_gd_ontouch(ximagesliderig.java:295)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at flm.b4a.gesturedetector.GestureDetectorForB4A$1.onTouch(GestureDetectorForB4A.java:99)
    at android.view.View.dispatchTouchEvent(View.java:13495)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3079)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2756)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3085)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2770)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3085)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2770)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3085)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2770)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3085)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2770)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3085)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2770)
    at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:472)
    at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1878)
    at android.app.Activity.dispatchTouchEvent(Activity.java:4006)
    at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:430)
    at android.view.View.dispatchPointerEvent(View.java:13758)
    at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5837)
    at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5620)
    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5116)
    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5169)
    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5135)
    at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:5275)
    at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5143)
    at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5332)
    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5116)
    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5169)
    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5135)
    at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5143)
    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5116)
    at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7895)
    at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7864)
    at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7804)
    at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:8020)
    at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:189)
    at android.os.MessageQueue.nativePollOnce(Native Method)
    at android.os.MessageQueue.next(MessageQueue.java:336)
    at android.os.Looper.loop(Looper.java:174)
    at android.app.ActivityThread.main(ActivityThread.java:7682)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
 

mkh_fx

Member
Licensed User
Longtime User
i need a method for changing slider current page index
also i need a option for autoplay
 

Devv

Active Member
Licensed User
Longtime User
thank you for the great library

i wish you can add support for caching the images

as the library already knows the list of images why not cash them and save the user time ?
 

Alexander Stolte

Expert
Licensed User
Longtime User
If i disable "Fit Image" then the following error occurs:
B4X:
Error occurred on line: 467 (xImageSliderIG)
java.lang.RuntimeException: Object should first be initialized (View).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4a.objects.B4XViewWrapper.GetView(B4XViewWrapper.java:299)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
    at com.stoltex.randompic.ximagesliderig._showimage(ximagesliderig.java:987)
    at com.stoltex.randompic.ximagesliderig._setimages(ximagesliderig.java:260)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at com.stoltex.randompic.frm_main.afterFirstLayout(frm_main.java:104)
    at com.stoltex.randompic.frm_main.access$000(frm_main.java:17)
    at com.stoltex.randompic.frm_main$WaitForLayout.run(frm_main.java:82)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7682)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
 

Biswajit

Active Member
Licensed User
Longtime User
If i disable "Fit Image" then the following error occurs:
B4X:
Error occurred on line: 467 (xImageSliderIG)
java.lang.RuntimeException: Object should first be initialized (View).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4a.objects.B4XViewWrapper.GetView(B4XViewWrapper.java:299)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
    at com.stoltex.randompic.ximagesliderig._showimage(ximagesliderig.java:987)
    at com.stoltex.randompic.ximagesliderig._setimages(ximagesliderig.java:260)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at com.stoltex.randompic.frm_main.afterFirstLayout(frm_main.java:104)
    at com.stoltex.randompic.frm_main.access$000(frm_main.java:17)
    at com.stoltex.randompic.frm_main$WaitForLayout.run(frm_main.java:82)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7682)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Yes I saw this while working on an update. Will post the update soon. The new update will fixed this error and it will also support video playback, dot indicator positioning and visibility, fill/fit/stretch scaling for image and also for video.

This is my own account. I will post the update from this account.
 
Last edited:
Top