B4A Library [Class] ICS Like Horizontal and Vertical Seekbars

This class implements ICS Like SeekBars.

Every seekbar is drawn when created so you can set :
- color and size of the button
- color and width of the stroke
- choose if value is shown or not
- choose where is the max value for the vertical one (up or down)
- set the max value and the start value
- enable/disable

Requirements:
- B4A 2.xx
- ABExtDrawing Lib

How to use (example for the horizontal one):

Initialize the class :
B4X:
Sub Globals
   Dim SBT1 As mbHSeekBar
End Sub

then create it :
B4X:
'Activity, Module,EventName,Left,Top,Width,Height,StrokeWidth,StrokeDefautColor,Color,TextVisible,InitValue,MaxValue
SBT1.Initialize(Activity,Me,"SBT_Click",1%x,10%y,98%x,52dip,5dip,Colors.DarkGray,Colors.RGB(0xcc,0x00,0x00),True,200,255)

(Don't forget to add True or False at the end if ou use the vertical class to choose where must be the max value, at the top or the bottom)

You can customize the text showing the value:
B4X:
SBT1.CustomizeText(Colors.Red,22,Typeface.DEFAULT_BOLD)

You can set a value at any time:
B4X:
SBT1.setValue(33)

You can set a step value:
B4X:
SBT1.stepValue = 10 ' value will be rounded from 10 to 10

in the main activity you can get the selected value:

B4X:
Sub SBT_Click(returnValue)
   Activity.Title = "Value is " & returnValue    
End Sub

That's it. Have a look at the demos and send feedback or ideas for enhancements.
 

Attachments

  • demoh.png
    demoh.png
    32.3 KB · Views: 1,010
  • demov.png
    demov.png
    32.1 KB · Views: 881
  • ICSLike_SeekBars.zip
    14.8 KB · Views: 817
Last edited:

Mahares

Expert
Licensed User
Longtime User
@Mabool: C'est magnifique! It must be the water in France. Between you and Frederic (Informatix), you are making some classy contributions to the forum.
 

Mahares

Expert
Licensed User
Longtime User
How do you make a seekbar increment by decimal numbers such as: 0.5 instead of 1 or 10. I tried to do the following changes, but would not help. I only get integer increments:

B4X:
'In class module:
Public  maxValue As Float
Public stepValue As Float = .5
and in main module:
B4X:
SBT6.setValue(.5)
Merci d' avance
 

mabool

Member
Licensed User
Longtime User
@Mahares : I wrote the stepValue to help when values are BIG, like between 0 and 100. Or more. But for your problem you can do something like this :
If you need values from 0 to 10 step 0.5 :

B4X:
Sub Globals
   Dim SBT1 As mbHSeekBar
   Dim myStep As Float
   Dim temp As String
   Dim init,total As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Activity, Module,EventName,Left,Top,Width,Height,StrokeWidth,StrokeDefautColor,Color,TextVisible,InitValue,MaxValue
   myStep = 0.5
   init = 7 / myStep
   total = 10 / myStep
   SBT1.Initialize(Activity,Me,"SBT_Click",1%x,10%y,98%x,52dip,5dip,Colors.DarkGray,Colors.RGB(0xcc,0x00,0x00),True, init , total)
   showValue(init, SBT1)
End Sub

Sub SBT_Click(returnValue)
   showValue(returnValue, SBT1)
End Sub
Sub showValue(returnvalue As Int,SBT As mbHSeekBar)
   temp = NumberFormat(returnvalue * myStep,1,2)
   SBT.mbLabel.Text = temp
   Activity.Title = "Value is :   " & temp    
End Sub

This does the trick.
 

Mahares

Expert
Licensed User
Longtime User
Thank you Mabool for addressing it. I will check it out as I just saw your response. I thought the best solution was if the class addresses all options without having to modify it for when you want a decimal or integer. This way, it will be more versatile. You may have one seekbar in the same app that require integers and another seekbar that requires decimals.
 

mabool

Member
Licensed User
Longtime User
@Marcel : Just replace "Activity" with Panel.

B4X:
SBT1.Initialize(Panel1,Me,"SBT_Click",1%x,10%y,98%x,52dip,5dip,Colors.DarkGray,Colors.RGB(0xcc,0x00,0x00),True,200,255)

Sorry I didn't saw your post. Have fun.
 

bluedude

Well-Known Member
Licensed User
Longtime User
I like it, want to use if for a few projects. How hard would it be to add a lock/freeze option? So on top of enable a freeze so that users cannot change the value but that is still shows the normal colors and values.
 

mabool

Member
Licensed User
Longtime User
@BlueDude : Just add these two routines at the end of the class :

B4X:
Public Sub Freeze
   mbBackground.Enabled = False
   If textVisible = True Then
      mbLabel.Visible = False
   End If
End Sub
Public Sub UnFreeze
   mbBackground.Enabled = True
   If textVisible = True Then
      mbLabel.Visible = True
   End If   
End Sub

and call them in your code :

B4X:
SBT.Freeze
or 
SBT.UnFreeze


Have fun.
 
Last edited:

Mahares

Expert
Licensed User
Longtime User
@Mabool:
1. If you want to still show the label and freeze a seekbar, shouldn't the code for the below sub be like this:
B4X:
Public Sub Freeze
    mbBackground.Enabled = False
End Sub
2. I have been trying to change your demo so each of the 6 seekbars can have its own increment that can be either integers or decimals or integers. I was able to change it where all seekbars change using decimals, but I want to have some of them using decimals, the others integers increments in the same demo, but could not. For instance SBT1 may change using integer intervals and SBT6 may use 0.5 increments in the same application, etc.
Could you please take a closer look and see if it is doable.
Cordialement
 

metrick

Active Member
Licensed User
Longtime User
How do I invalidate? Leave a ghost mark if setting left for a while.
 

Informatix

Expert
Licensed User
Longtime User
Hello,

I am having a small issue with the scroll bar moving to the end when the user moves up and down while setting the seekbar value.

Hoping someone can help me out, here is a link to my question:

http://www.b4x.com/forum/basic4andr...-like-horizontal-seekbar-help.html#post158498

B4X:
Private Sub mbBackground_Touch (Action As Int, X As Float, Y As Float)
   Dim r as Reflector
   r.Target = Sender
   r.RunMethod2("requestDisallowInterceptTouchEvent", True, "java.lang.boolean")
...

EDIT:
Replace also line#135:
Case mbActivity.ACTION_UP
by
Case 1, 3 'UP/CANCEL
 
Last edited:

aaronk

Well-Known Member
Licensed User
Longtime User
B4X:
Private Sub mbBackground_Touch (Action As Int, X As Float, Y As Float)
   Dim r as Reflector
   r.Target = Sender
   r.RunMethod2("requestDisallowInterceptTouchEvent", True, "java.lang.boolean")
...

EDIT:
Replace also line#135:
Case mbActivity.ACTION_UP
by
Case 1, 3 'UP/CANCEL

Thanks heaps.. that seems to of fixed my issue.
 

jazzzzzzz

Active Member
Licensed User
Longtime User
@Mahares : I wrote the stepValue to help when values are BIG, like between 0 and 100. Or more. But for your problem you can do something like this :
If you need values from 0 to 10 step 0.5 :

B4X:
Sub Globals
   Dim SBT1 As mbHSeekBar
   Dim myStep As Float
   Dim temp As String
   Dim init,total As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Activity, Module,EventName,Left,Top,Width,Height,StrokeWidth,StrokeDefautColor,Color,TextVisible,InitValue,MaxValue
   myStep = 0.5
   init = 7 / myStep
   total = 10 / myStep
   SBT1.Initialize(Activity,Me,"SBT_Click",1%x,10%y,98%x,52dip,5dip,Colors.DarkGray,Colors.RGB(0xcc,0x00,0x00),True, init , total)
   showValue(init, SBT1)
End Sub

Sub SBT_Click(returnValue)
   showValue(returnValue, SBT1)
End Sub
Sub showValue(returnvalue As Int,SBT As mbHSeekBar)
   temp = NumberFormat(returnvalue * myStep,1,2)
   SBT.mbLabel.Text = temp
   Activity.Title = "Value is :   " & temp   
End Sub

This does the trick.
Sorry for bumbing this old thread....I wanna make this seekbar to seek video so after 1.59 minutes seekbar should return and show in the knob as 2.00 how can i do this...By the way this is the best seekbar i have ever seen main feature is value showing in knob...
 
Top