B4A Library SingleDateAndTimePicker

A partly wrap for this Github project. Posting:
1. B4A library files - extract them and copy them to your additional library folder
2. B4A sample project
3. LibRes.zip - extract the folder and copy it to the same folder level as that of the /Files and /Objects folders of the B4A project

1.gif


Library:

SingleDateAndTimePicker
Author:
Github: Florent CHAMPIGNY, Wrapped by: Johan Schoeman
Version: 1.03
  • SingleDateAndTimePicker
    Events:
    • date_time_changed (year As Int, month As Int, dayOfMonth As Int, dayOfWeek As Int, hour As Int, minute As Int, stringDateTime As String)
    Fields:
    • ALIGN_CENTER As Int
    • ALIGN_LEFT As Int
    • ALIGN_RIGHT As Int
    • ba As BA
    • mydate As String
    • mydayofmonth As Int
    • mydayofweek As Int
    • myhour As Int
    • myminute As Int
    • mymonth As Int
    • myyear As Int
    Methods:
    • 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]
    • Date As String [read only]
    • DayAtmospheric As Boolean [write only]
    • DayCurtain As Boolean [write only]
    • DayCurtainColor As Int [write only]
    • DayCurved As Boolean [write only]
    • DayCyclic As Boolean [write only]
    • DayIndicator As Boolean [write only]
    • DayIndicatorColor As Int [write only]
    • DayIndicatorSize As Int [write only]
    • DayItemAlign As Int [write only]
    • DayItemTextColor As Int [write only]
    • DaySelectedItemTextColor As Int [write only]
    • DayVisibleItemCount As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • HourAtmospheric As Boolean [write only]
    • HourCurtain As Boolean [write only]
    • HourCurtainColor As Int [write only]
    • HourCurved As Boolean [write only]
    • HourCyclic As Boolean [write only]
    • HourIndicator As Boolean [write only]
    • HourIndicatorColor As Int [write only]
    • HourIndicatorSize As Int [write only]
    • HourItemAlign As Int [write only]
    • HourItemTextColor As Int [write only]
    • HourSelectedItemTextColor As Int [write only]
    • HourVisibleItemCount As Int [write only]
    • Left As Int
    • MinuteAtmospheric As Boolean [write only]
    • MinuteCurtain As Boolean [write only]
    • MinuteCurtainColor As Int [write only]
    • MinuteCurved As Boolean [write only]
    • MinuteCyclic As Boolean [write only]
    • MinuteIndicator As Boolean [write only]
    • MinuteIndicatorColor As Int [write only]
    • MinuteIndicatorSize As Int [write only]
    • MinuteItemAlign As Int [write only]
    • MinuteItemTextColor As Int [write only]
    • MinuteSelectedItemTextColor As Int [write only]
    • MinuteVisibleItemCount As Int [write only]
    • Parent As Object [read only]
    • ShowToastMessage As Boolean [write only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int


Sample Code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: b4aSingleDateAndTimePicker
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#AdditionalRes: ..\LibRes

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

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

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

    Private sdtp1 As SingleDateAndTimePicker
    Private b1 As Button
    Dim monthlist As List
    Dim daylist As List
    Private Label1 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
 
    monthlist.Initialize2(Array As String("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))
    daylist.Initialize2(Array As String("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", " Friday", " Saturday"))
 
    sdtp1.DayCurtain = True
    sdtp1.DayCurtainColor = Colors.ARGB(100, 0, 255, 0)
    sdtp1.DayCurved = True
    sdtp1.DayIndicator = True
    sdtp1.DayIndicatorColor = Colors.Black
    sdtp1.DayItemTextColor = Colors.Red
    sdtp1.DaySelectedItemTextColor = Colors.Blue
    sdtp1.DayItemAlign = sdtp1.ALIGN_LEFT
    sdtp1.DayIndicatorSize = 5                              'the line thickness of the indicator
    sdtp1.DayVisibleItemCount = 7
    sdtp1.DayAtmospheric = True
    sdtp1.DayCyclic = True
 
 
    sdtp1.HourCurtain = True
    sdtp1.HourCurtainColor = Colors.ARGB(100, 255, 0, 0)
    sdtp1.HourCurved = True
    sdtp1.HourIndicator = True
    sdtp1.HourIndicatorColor = Colors.Magenta
    sdtp1.HourItemTextColor = Colors.Blue
    sdtp1.HourSelectedItemTextColor = Colors.Cyan
    sdtp1.HourItemAlign = sdtp1.ALIGN_LEFT
    sdtp1.HourIndicatorSize = 5                              'the line thickness of the indicator
    sdtp1.HourVisibleItemCount = 7
    sdtp1.HourAtmospheric = True
    sdtp1.HourCyclic = True 
 
 

    sdtp1.MinuteCurtain = False
    sdtp1.MinuteCurtainColor = Colors.ARGB(100, 0, 0, 175)
    sdtp1.MinuteCurved = True
    sdtp1.MinuteIndicator = True
    sdtp1.MinuteIndicatorColor = Colors.Blue
    sdtp1.MinuteItemTextColor = Colors.Cyan
    sdtp1.MinuteSelectedItemTextColor = Colors.Magenta
    sdtp1.MinuteItemAlign = sdtp1.ALIGN_LEFT
    sdtp1.MinuteIndicatorSize = 5                              'the line thickness of the indicator
    sdtp1.MinuteVisibleItemCount = 7
    sdtp1.MinuteAtmospheric = True
    sdtp1.MinuteCyclic = True     
 
 
    sdtp1.ShowToastMessage = False
 
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub sdtp1_date_time_changed(year As Int, month As Int, dayOfMonth As Int, dayOfWeek As Int, hour As Int, minute As Int, stringDateTime As String)
 
    Log("YEAR = " & year)
    Log("MONTH = " & monthlist.Get(month))
    Log("DAY OF MONTH = " & dayOfMonth)
    Log("DAY OF WEEK = " & daylist.Get(dayOfWeek))
    Log("HOUR = " & hour)
    Log("MINUTE = " & minute)
    Log("STRING DATE AND TIME = " & stringDateTime)
 
 
End Sub

Sub b1_Click
 
    Log(sdtp1.myyear)
    Log(monthlist.Get(sdtp1.mymonth))
    Log(sdtp1.mydayofmonth)
    Log(daylist.Get(sdtp1.mydayofweek))
    Log(sdtp1.myhour)
    Log(sdtp1.myminute)
    Log(sdtp1.mydate)
 
End Sub
 

Attachments

  • b4aSingleDateAndTimePicker.zip
    8.9 KB · Views: 691
  • LibRes.zip
    7.8 KB · Views: 655
  • 1.png
    1.png
    52.1 KB · Views: 667
  • SingleDateAndTimePickerLibFiles.zip
    65.2 KB · Views: 729
Last edited:

cengolo

Member
Licensed User
Longtime User
is it possible to use this picker without the date part? i need a time picker exactly this style, but without the date.
 

Johan Schoeman

Expert
Licensed User
Longtime User
is it possible to use this picker without the date part? i need a time picker exactly this style, but without the date.
Try the attached B4A project and lib files. Read post #1 to see what you must do with LibRes.zip. Copy the jar and xml to your additional libs folder

It looks like this:

1.png
 

Attachments

  • b4aSingleTimePicker.zip
    8.7 KB · Views: 469
  • SingleTimePicker.xml
    15.5 KB · Views: 517
  • SingleTimePicker.jar
    64.4 KB · Views: 468
  • LibRes.zip
    7.8 KB · Views: 472

aeric

Expert
Licensed User
Longtime User
I try to add the view into a project. It show following errors when compiling.
B4X:
B4A Version: 9.50
Java Version: 8
Parsing code.    (0.09s)
Building folders structure.    (0.02s)
Compiling code.    (0.62s)
Compiling layouts code.    (0.02s)
Organizing libraries.    (0.00s)
    (AndroidX SDK)
Generating R file.    (0.95s)
Compiling debugger engine code.    (4.84s)
Compiling generated Java code.    (6.22s)
Convert byte code - optimized dex.    Error
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroidx/annotation/AnimRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroidx/annotation/AnimatorRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroidx/annotation/AnyRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroidx/annotation/ArrayRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroidx/annotation/AttrRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroidx/annotation/BinderThread;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroidx/annotation/BoolRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroidx/annotation/CallSuper;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroidx/annotation/CheckResult;
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Translation has been interrupted
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:692)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:315)
    at com.android.dx.command.dexer.Main.runDx(Main.java:293)
    at com.android.dx.command.dexer.Main.main(Main.java:249)
    at com.android.dx.command.Main.main(Main.java:94)
Caused by: java.lang.InterruptedException: Too many errors
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:684)
    ... 4 more
 

aeric

Expert
Licensed User
Longtime User
I try to add the view into a project. It show following errors when compiling.
B4X:
B4A Version: 9.50
Java Version: 8
Parsing code.    (0.09s)
Building folders structure.    (0.02s)
Compiling code.    (0.62s)
Compiling layouts code.    (0.02s)
Organizing libraries.    (0.00s)
    (AndroidX SDK)
Generating R file.    (0.95s)
Compiling debugger engine code.    (4.84s)
Compiling generated Java code.    (6.22s)
Convert byte code - optimized dex.    Error
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroidx/annotation/AnimRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroidx/annotation/AnimatorRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroidx/annotation/AnyRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroidx/annotation/ArrayRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroidx/annotation/AttrRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroidx/annotation/BinderThread;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroidx/annotation/BoolRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroidx/annotation/CallSuper;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroidx/annotation/CheckResult;
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Translation has been interrupted
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:692)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:315)
    at com.android.dx.command.dexer.Main.runDx(Main.java:293)
    at com.android.dx.command.dexer.Main.main(Main.java:249)
    at com.android.dx.command.Main.main(Main.java:94)
Caused by: java.lang.InterruptedException: Too many errors
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:684)
    ... 4 more
It crashed with FirebaseNotifications library (version 1.21)
 

Johan Schoeman

Expert
Licensed User
Longtime User
It crashed with FirebaseNotifications library (version 1.21)
Can you upload a sample project that shows the problem? I am running it on B4A V9.50 and with target SDK set to 28 and I get no errors whatsoever. Maybe something that you have in your project that causes the duplication of Annotations.
 

aeric

Expert
Licensed User
Longtime User
Hi Johan,
I like this library and hope I can use it in my project. Thanks.
Here is my sample project. I just select the FirebaseNotifications library without even use it yet it shows error during compiling.
 

Attachments

  • SingleDateAndTimePicker.zip
    9.1 KB · Views: 413

aeric

Expert
Licensed User
Longtime User
I fixed it by changing the following line at the bottom of xml file (according to xml file for b4aSingleTimePicker).
From:
B4X:
<dependsOn>android-support-annotations</dependsOn>
To:
B4X:
<dependsOn>com.android.support:support-annotations</dependsOn>
 

Johan Schoeman

Expert
Licensed User
Longtime User
We are once again in the very fortunate position where we have another power outage today. First one was from 04h00 to 06h00 this morning. Now again. Will look at your sample project once power has been restored after load shedding.
 

Johan Schoeman

Expert
Licensed User
Longtime User
I fixed it by changing the following line at the bottom of xml file (according to xml file for b4aSingleTimePicker).
From:
B4X:
<dependsOn>android-support-annotations</dependsOn>
To:
B4X:
<dependsOn>com.android.support:support-annotations</dependsOn>
Old library. I will change the wrapper to reference the new required dependency, recompile it, and post the new library.
 

aeric

Expert
Licensed User
Longtime User
Thanks Johan. Issue is resolved. I am also able to add a custom Today value for Chinese locale.
Screenshot_20200105_213244.jpg



Can I allow to select date or time which already past?
Can you look at this question? I can't select old date or time. It will automatically reset to current date and time.

Is there anyway to get the ticks value , without parsing the string ?
This feature will be useful too.

If you could add AM/PM then it will be nice and look much similar to iOS Datepicker view.
 

aeric

Expert
Licensed User
Longtime User
Hi Johan,
I found that I can assign values such as sdtp1.myyear, sdtp1.mydayofmonth, sdtp1.myhour or sdtp1.myminute to the SingleDateAndTimePicker but the values are not selected. It still display current date and time as default. If this is working then it is great.
 

Amir__Gheibi

New Member
@Johan schoeman the time in first show, shows the phone time and when we try to write for example:
B4X:
TimePicker1.myhour  =11
TimePicker2.myhour  =23
TimePicker1.myminute=25
TimePicker2.myminute=50
that not working and again both of them shows the now time, is this codes wrong?
 
Last edited:
Top