B4A Library SlideSwitch V1.0.2

SlideSwitch
Version:
1.02
  • SlideSwitch
    Events:
    • close (swview as Object As , token as Object As )
    • onClick (swview as Object As )
    • open (swview as Object As , token as Object As )
    Fields:
    • ba As BA
    Methods:
    • AddToParent (Parent As ViewGroup, left As Int, top As Int, width As Int, height As Int)
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    Properties:
    • Background As Drawable
    • Color As Int [write only]
      Set the Color for the SlideSwitch
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Rounded As Boolean [write only]
      Set this to true if you want to get an rounded SlideSwitch
      Default is false
    • State As Boolean
      The State of the the SlideSwitch
      If true the Switch is open
      false if Switch is closed
    • Tag As Object
    • Token As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int

SlideSwitch001.png
 

Attachments

  • libSlideSwitch1.0.0.zip
    8.9 KB · Views: 529
  • SlideSwitchEx.zip
    64.6 KB · Views: 719
  • libSlideSwitch1.0.1.zip
    9.4 KB · Views: 497
  • libSlideSwitch1.0.2.zip
    10.4 KB · Views: 725
Last edited:

DonManfred

Expert
Licensed User
Longtime User
this is a small project to show the problem
i see the problem.
Sadly i cant find a solution. The slide-functionality cannot be deactivated, setting a onclickevent will not work too.
Using the touch to slide on/off does not work inside a viewpager. But a single click on in will change the state
It is not ideal but it works.

I would suggest to not use this component inside a viewpager. Consider using a normal switch instead
 

ArminKH

Well-Known Member
@DonManfred
Thank u
I know click on slide switch works but the slide is not good inside ahviewpager
Is possible to solve this problem inside AhViewPager side ?
Thats not possible to release a modified version for deactive slide event?
Its good for me if state can be changed by using click and not work by using slide
Thank u again for your response this is very important for me to use your lib in my app
If this problem cant be solved then we must use 2 image for state on and off i think
 

walterf25

Expert
Licensed User
Longtime User
I'm simply not willing to do so much donkey work. Be my guest, take all my libraries and write the code for every method in ViewWrapper or other.
Uh Oh, somebody got grumpy!
And this is the reason i don't post all the libraries i write, as I only wrap the functions that are of importance to me when i need a library in any of the apps I make for my clients. I'm the type of person who thinks that if you're going to do something you gotta do it right or don't do it at all. But that's just me :p.
Any how my comment is not meant for you to get upset bud, I know you're going through hormonal changes so i'll let it slide this time.

;)
 

thedesolatesoul

Expert
Licensed User
Longtime User
Uh Oh, somebody got grumpy!
And this is the reason i don't post all the libraries i write, as I only wrap the functions that are of importance to me when i need a library in any of the apps I make for my clients. I'm the type of person who thinks that if you're going to do something you gotta do it right or don't do it at all. But that's just me :p.
Any how my comment is not meant for you to get upset bud, I know you're going through hormonal changes so i'll let it slide this time.

;)
I'm not grumpy :p
I am also the type of person who thinks that if you're going to do something you gotta do it right or don't do it at all, unfortunately what is 'right' isnt the same for both of us. In my opinion, there should be a system of automatically inheriting the docs from the source lib. This will ensure there are less errors and the docs are always up-to-date. Your solution is error-prone and requires an update everytime the underlying java-docs is updated for whatever reason. I think everything that can be, should be automatically generated and built from source, wherever possible.
 

corwin42

Expert
Licensed User
Longtime User
@DonManfred
Thank u
I know click on slide switch works but the slide is not good inside ahviewpager
Is possible to solve this problem inside AhViewPager side ?
Thats not possible to release a modified version for deactive slide event?
Its good for me if state can be changed by using click and not work by using slide
Thank u again for your response this is very important for me to use your lib in my app
If this problem cant be solved then we must use 2 image for state on and off i think

Maybe the library needs to change the onTouchEvent() method to implement this solution.
 

ArminKH

Well-Known Member
thank u @corwin42
I am not familar with java syntax maybe mr @DonManfred can solve this problem or suggest a good solution like your above link solution on b4a
If this can be solved or not thank u both for your hard work
 

DonManfred

Expert
Licensed User
Longtime User
aybe the library needs to change the onTouchEvent() method to implement this solution.
Seems to do the job! Thanx you very much for this hint, @corwin42!

Will update the library soon

Edit: Library updated to V1.0.2 (See Post #1)
 
Last edited:

walterf25

Expert
Licensed User
Longtime User
SlideSwitch
Version:
1.02
  • SlideSwitch
    Events:
    • close (swview as Object As , token as Object As )
    • onClick (swview as Object As )
    • open (swview as Object As , token as Object As )
    Fields:
    • ba As BA
    Methods:
    • AddToParent (Parent As ViewGroup, left As Int, top As Int, width As Int, height As Int)
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    Properties:
    • Background As Drawable
    • Color As Int [write only]
      Set the Color for the SlideSwitch
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Rounded As Boolean [write only]
      Set this to true if you want to get an rounded SlideSwitch
      Default is false
    • State As Boolean
      The State of the the SlideSwitch
      If true the Switch is open
      false if Switch is closed
    • Tag As Object
    • Token As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int

SlideSwitch001.png
Great library Don, one question though, is it possible to change the color of the switch when in the off position, i know you can change the color but it only shows the chosen color when the switch is on (or clicked to the right), i would like to find out if possible to change the color of the background when the switch is moved to the Off(or left position).

Thanks,
Walter
 

GMan

Well-Known Member
Licensed User
Longtime User
Hoi DonManfred,

is this the rigth syntax to catch an event on i.e. ssw1 ?

B4X:
Sub ssw1_open(swview As Object,token As Object)
    txtInput.Text = "R1H"' & CRLF
    btnSend_Click
End Sub
Sub ssw1_close(swview As Object,token As Object)
    txtInput.Text = "R1L"' & CRLF
    btnSend_Click
End Sub
 

GMan

Well-Known Member
Licensed User
Longtime User
Thats the kind of answer i like to her from a wrapper
You are pumping out libraries right now, trying to break some record? Erels perhaps? :D
Yeah, but .....
 

DonManfred

Expert
Licensed User
Longtime User
That´s the kind of answer i like to hear from a customer of FREE libraries.
Yeah, but .....
Feel free NOT TO USE my libraries. I´ve lost the source. Shit happens.
If the lib does not do what you expect then use another library.
 
Top