Android Question Sample app that has a SeekBar converting secornds into hh:mm:ss

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

Has anyone used a SeekBar to convert seconds into time format to display to the user in hh:mm:ss format?

Is there a sample app on the forum that shows this being done?
 

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Erel,

I did find a solution by using the AHDateUtils.

The problem with the old code was that it would display a negative number for hours if the SeekBar value went over 5 hours and my new app requires the user to go all the way up to 24 hours maximum. The old code in the link was good because that app went up to 1 hour maximum. AHDateUtils was able to handle going up to 24 hours.

Anyway, here is the coding I'm using with AHDateUtils that can handle the 24 hour maximum value:

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Dim du As AHDateUtils

    Dim PanelImageDetails As Panel
    Dim SeekBarTimeToDisplayImage As SeekBar
    Dim intTimeToKeepActive As Int
  
    Dim int15Minutes As Int = 60 * 15
    Dim int1Hour As Int = 60 * 60
    Dim int24Hours As Int = int1Hour * 24
  
    ' Time duration.
    '---------------
    Dim LabelTimeToDisplayImage As Label
End Sub

B4X:
Sub Activity_Create(FirstTime As Boolean)

    Activity.LoadLayout("ImageDetails")
  
    PanelImageDetails.SetBackgroundImage(LoadBitmap(File.DirAssets, "seamless-wood.jpg"))
    PanelImageDetails.Height = Activity.Height
    PanelImageDetails.Width = Activity.Width

    If FirstTime Then
        intTimeToKeepActive = int15Minutes
      
        SeekBarTimeToDisplayImage.Max = int24Hours
    End If

End Sub

B4X:
Sub SeekBarTimeToDisplayImage_ValueChanged (Value As Int, UserChanged As Boolean)
  
    If Value < int15Minutes Then
        Value = int15Minutes
    End If
  
    LabelTimeToDisplayImage.Text = "Time to show (" & _
        du.FormatElapsedTime(Value) & ")"

    ' This amount is for the timer tick.
    '-----------------------------------
    intTimeToKeepActive = Value * 60
End Sub

It's a lot less coding now in the SeekBar sub routine.
 
Upvote 0
Top