B4A Library [B4X] [XUI] AS TimePickerDialog based on B4XDialog and AS_TimePicker

A dialog that prompts the user for the time of day using a TimePicker.

I spend a lot of time in creating views, like this and to create a high quality view cost a lot of time. If you want to support me and further views, then you can do it here by Paypal or with a coffee. :)

1690830693581.png
1690830703870.png
1690831955786.png


1690830723935.png
ezgif.com-resize (4).gif

Dark Example:
Private Sub ShowDialogDarkMode
 
    TimePickerDialog.Initialize(Root)
 
    TimePickerDialog.Theming.BackgroundColor = xui.Color_ARGB(255,19, 20, 22)
    TimePickerDialog.Theming.ClockTextColor = xui.Color_White
    TimePickerDialog.Theming.DialogButtonTextColor = xui.Color_ARGB(255,20,160,130)
    TimePickerDialog.Theming.EditTextColor = xui.Color_White
    TimePickerDialog.Theming.EditTextFocusColor = xui.Color_ARGB(255,20,160,130)
    TimePickerDialog.Theming.ThumbColor = xui.Color_ARGB(255,20,160,130)
    TimePickerDialog.Theming.TimePickerBackgroundColor = xui.Color_ARGB(255,32, 33, 37)
 
    TimePickerDialog.KeyboardEnabled = True
    TimePickerDialog.TimeFormat = TimePickerDialog.TimeFormat_24h
 
    Wait For (TimePickerDialog.ShowDialog) Complete (PickerDialogResponse As AS_TimePickerDialog_DialogResponse)
    If PickerDialogResponse.Result = xui.DialogResponse_Positive Then
        #If Debug
        Log("Hour: " & PickerDialogResponse.Hour & " Minute: " & PickerDialogResponse.Minute)
        #Else
        xui.MsgboxAsync("Hour: " & PickerDialogResponse.Hour & " Minute: " & PickerDialogResponse.Minute,"")
        #End If
    End If
 
End Sub
Light Example:
Private Sub ShowDialogLightMode
 
    TimePickerDialog.Initialize(Root)
 
    TimePickerDialog.Theming.BackgroundColor = xui.Color_White
    TimePickerDialog.Theming.ClockTextColor = xui.Color_Black
    TimePickerDialog.Theming.DialogButtonTextColor = xui.Color_ARGB(255,20,160,130)
    TimePickerDialog.Theming.EditTextColor = xui.Color_Black
    TimePickerDialog.Theming.EditTextFocusColor = xui.Color_ARGB(255,20,160,130)
    TimePickerDialog.Theming.ThumbColor = xui.Color_ARGB(255,20,160,130)
    TimePickerDialog.Theming.TimePickerBackgroundColor = xui.Color_ARGB(255,245,246,247)
 
    Wait For (TimePickerDialog.ShowDialog) Complete (PickerDialogResponse As AS_TimePickerDialog_DialogResponse)
    If PickerDialogResponse.Result = xui.DialogResponse_Positive Then
        #If Debug
        Log("Hour: " & PickerDialogResponse.Hour & " Minute: " & PickerDialogResponse.Minute)
        #Else
        xui.MsgboxAsync("Hour: " & PickerDialogResponse.Hour & " Minute: " & PickerDialogResponse.Minute,"")
        #End If
    End If
 
End Sub

You need the AS_TimePicker V1.08+

AS_TimePickerDialog
Author: Alexander Stolte
Version: 1.00

  • AS_TimePickerDialog
    • Functions:
      • Class_Globals As String
      • getHour As Int
      • getKeyboardEnabled As Boolean
      • getMinute As Int
      • getMinuteSteps As Int
      • getTimeFormat As String
      • getTimeFormat_12h As String
      • getTimeFormat_24h As String
      • Initialize (Parent As B4XView) As String
        Initializes the object. You can add parameters to this method if needed.
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • setHour (Hour As Int) As String
      • setKeyboardEnabled (Enabled As Boolean) As String
      • setMinute (Minute As Int) As String
      • setMinuteSteps (Steps As Int) As String
        Indicates in how many steps the selector can be moved
        Default: 1
      • setTimeFormat (Format As String) As String
        24h|12h
        Default: 24h
      • ShowDialog As ResumableSub
        <code> Wait For (TimePickerDialog.ShowDialog) Complete (PickerDialogResponse As AS_TimePickerDialog_DialogResponse)
        If PickerDialogResponse.Result = xui.DialogResponse_Positive Then
        End If</code>
      • Theming As AS_TimePickerDialog_Theming
    • Properties:
      • Hour As Int
      • KeyboardEnabled As Boolean
      • Minute As Int
      • MinuteSteps As Int
        Indicates in how many steps the selector can be moved
        Default: 1
      • TimeFormat As String
        24h|12h
        Default: 24h
      • TimeFormat_12h As String [read only]
      • TimeFormat_24h As String [read only]
  • AS_TimePickerDialog_DialogResponse
    • Fields:
      • Hour As Int
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • Minute As Int
      • Result As Int
    • Functions:
      • Initialize
        Initializes the fields to their default value.
  • AS_TimePickerDialog_Theming
    • Fields:
      • BackgroundColor As Int
      • ClockTextColor As Int
      • DialogButtonTextColor As Int
      • EditTextColor As Int
      • EditTextFocusColor As Int
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • ThumbColor As Int
      • TimePickerBackgroundColor As Int
    • Functions:
      • Initialize
        Initializes the fields to their default value.
Changelog
  • 1.00
    • Release
  • 1.01
    • Add get and set DialogYesText
      • Default: OK
    • Add get and set DialogNoText
      • Default: CANCEL
    • Add get and set DialogCancelText
  • 1.02 (read more)
    • BugFixes
    • Add SetDarkMode - Sets the dialog to DarkMode
    • Add SetLightMode - Sets the dialog to LightMode
  • 1.03
    • Add Close - Closes the Dialog
  • 1.04
    • BugFix on TimeFormat_12h and PM times
    • B4J - Buttons should now work
  • 1.05
    • Keyboard Type on the TextFields are now numbers
  • 1.06 (read more)
    • Add set Date - You can now set the initial time with ticks
    • BugFix on TimeFormat_12h
    • Add isPm to AS_TimePickerDialog_DialogResponse
    • Add Date to AS_TimePickerDialog_DialogResponse
    • If you are using the TimeFormat 12h then the DialogResponse.Hour returns now 0-12 and you need to check with .isPm if it is am or pm
Have Fun :)

You need the AS_TimePicker V1.08+
 

Attachments

  • AS TimePickerDialog Example.zip
    184.5 KB · Views: 229
  • AS_TimePickerDialog.b4xlib
    10.1 KB · Views: 75
Last edited:

Alexander Stolte

Expert
Licensed User
Longtime User
Update
  • 1.02
    • BugFixes
    • Add SetDarkMode - Sets the dialog to DarkMode
    • Add SetLightMode - Sets the dialog to LightMode
Example:
B4X:
    TimePicker.Initialize(Root)
    TimePicker.SetDarkMode
    
    Wait For (TimePicker.ShowDialog) Complete (PickerDialogResponse As AS_TimePickerDialog_DialogResponse)
    If PickerDialogResponse.Result = xui.DialogResponse_Positive Then
    
    End If
 

jvetterli

Member
Licensed User
Longtime User
Thank your Alexander for another nice looking tool, I've sent you some coffee's ;)

I've found a bug: for example the timer picker gets called with a preset time of 14:15 and I change it to 12:15 - the shown result is 24:15.
 

Alexander Stolte

Expert
Licensed User
Longtime User
for another nice looking tool, I've sent you some coffee's ;)
Thank you very much! :)
I've found a bug: for example the timer picker gets called with a preset time of 14:15 and I change it to 12:15 - the shown result is 24:15.
I need more informations. The best would be an example project that shows exactly what you are doing. I tried to recreate the situation, but for me it works in 24h format and also in 12h format.
 

jvetterli

Member
Licensed User
Longtime User
Strange, I'm experiencing this behavior even with your example project, without any changes, on my Android.
When I set the clock to 12:30, the log shows: Hour: 24 Minute: 30, in light & dark mode as well.
 

Alexander Stolte

Expert
Licensed User
Longtime User
Strange, I'm experiencing this behavior even with your example project, without any changes, on my Android.
When I set the clock to 12:30, the log shows: Hour: 24 Minute: 30, in light & dark mode as well.
Should be fixed in the V1.09 of the AS_TimePicker.
Thanks for reporting.
 

jvetterli

Member
Licensed User
Longtime User
Thanks for the quick fix!

I have a question: how am I able to close the timepickerdialog by intercepting the back button/_CloseRequest on my page?
Timepicker.Close is an unknown member?
 

Alexander Stolte

Expert
Licensed User
Longtime User
Update
  • 1.06
    • Add set Date - You can now set the initial time with ticks
    • BugFix on TimeFormat_12h
    • Add isPm to AS_TimePickerDialog_DialogResponse
    • Add Date to AS_TimePickerDialog_DialogResponse
    • If you are using the TimeFormat 12h then the DialogResponse.Hour returns now 0-12 and you need to check with .isPm if it is am or pm
set Date
You can now set a DateTime date to preset a time.
B4X:
    TimePickerDialog.Date = DateTime.Now
    Wait For (TimePickerDialog.ShowDialog) Complete (PickerDialogResponse As AS_TimePickerDialog_DialogResponse)
Date in AS_TimePickerDialog_DialogResponse
The same now also works in the result
B4X:
    Wait For (TimePickerDialog.ShowDialog) Complete (PickerDialogResponse As AS_TimePickerDialog_DialogResponse)
    If PickerDialogResponse.Result = xui.DialogResponse_Positive Then
        Log(DateTime.Time(PickerDialogResponse.Date))
    End If
TimeFormat 12h
If you use the 12h time format, you can now check whether your time is AM or PM.
B4X:
    Wait For (TimePickerDialog.ShowDialog) Complete (PickerDialogResponse As AS_TimePickerDialog_DialogResponse)
    If PickerDialogResponse.Result = xui.DialogResponse_Positive Then
        Log("is PM? " & PickerDialogResponse.isPm)
    End If
If you want to set the hours instead of .Date, you can now also specify isPm in the preparation
B4X:
    TimePickerDialog.Hour = 10
    TimePickerDialog.isPm = True 'Means 10PM or 22 o'clock
    Wait For (TimePickerDialog.ShowDialog) Complete (PickerDialogResponse As AS_TimePickerDialog_DialogResponse)
 
Top