B4A Library SwitchDateTimePicker

A wrap for this Github project. Extract DemoRes.zip, LibRes.zip, and resource.zip and then copy the folders (with their contents) to be on the same folder level as that of the /Files and /Objects folders of the B4A project. Take note of the B4A manifest file.

You need to enable DesignSupport (V2.00) and AppCompat (V3.20) for the project to work. Copy the attached library files to your additional library folder.

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

#AdditionalRes: ..\resource
#AdditionalRes: ..\LibRes
#AdditionalRes: ..\DemoRes


'#AdditionalRes: C:\Android\extras\android\support\v7\appcompat\res, android.support.v7.appcompat
'#AdditionalRes: C:\Android\extras\google\google-play-services\libproject\google-play-services_lib\res, com.google.android.gms
'#AdditionalRes: C:\Android\extras\android\support\design\res, android.support.design

'#ExcludeClasses: .games, .drive, .ads, .fitness, .wearable, .measurement, .cast, .auth, .nearby
'#ExcludeClasses: .tagmanager, .analytics, .wallet, .plus, .gcm, .maps, .panorama

'#Extends: android.support.v7.app.AppCompatActivity

#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 Button1 As Button
    Dim sdtp As SwitchDateTimePicker
 
 
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")
    sdtp.Initialize("sdtp")
 
 
End Sub

Sub Activity_Resume
 

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click

    sdtp.Start_Picker

End Sub

Sub sdtp_selected_date_time(year As Int, month As Int, day As Int, hour As Int, minute As Int, full_date As String)
 
    Log("YEAR = " & year)
    Log("MONTH = " & month)
    Log("DAY = " & day)
    Log("HOUR = " & hour)
    Log("MINUTE = " & minute)
    Log("FULL DATE = " & full_date)
 
End Sub

Sub sdtp_cancelled
 
    Log("CANCELLED")
 
End Sub

Library:
SwitchDateTimePicker
Author:
Github: Jeremy JAMET, Wrapped by: Johan Schoeman
Version: 1
  • SwitchDateTimePicker
    Events:
    • cancelled
    • selected_date_time (year As Int, month As Int, day As Int, hour As Int, minute As Int, full_date As String)
    Methods:
    • Initialize (paramString As String)
    • IsInitialized As Boolean
    • Start_Picker

What it looks like on KitKat:
kitkat1.png



kitkat2.png



What it looks like on Lollipop:
lollipop1.png



lollipop2.png
 

Attachments

  • DemoRes.zip
    31.4 KB · Views: 639
  • LibRes.zip
    18.3 KB · Views: 630
  • resource.zip
    423 bytes · Views: 642
  • SwitchDateTimePickerLibFiles.zip
    15.1 KB · Views: 673
  • b4aSwitchDateTimePicker.zip
    8.5 KB · Views: 653
Last edited:

freedom2000

Well-Known Member
Licensed User
Longtime User
Really great library Johan.

Is it easy to change the color of the theme ?
 

Johan Schoeman

Expert
Licensed User
Longtime User
Really great library Johan.

Is it easy to change the color of the theme ?
JP, you can change the theme color in themes.xml in the /resource/values folder. This will for eg give a bluish color:

B4X:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyAppTheme" parent="Theme.AppCompat">
        <item name="colorPrimary">#0098FF</item>
        <item name="colorPrimaryDark">#007CF5</item>
        <item name="colorAccent">#26A7FF</item>
    </style>
</resources>

It was:

B4X:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyAppTheme" parent="Theme.AppCompat">
        <item name="colorPrimary">#FF9800</item>
        <item name="colorPrimaryDark">#F57C00</item>
        <item name="colorAccent">#FFA726</item>
    </style>
</resources>

lollipop3.png
 

freedom2000

Well-Known Member
Licensed User
Longtime User
Another question :confused:

If I am only interested in date (or time), is there a way to do it without entering other parameter (respectively : time (or date)) ?

in other words :
- time only picker ?
- date only picker ?
 

Johan Schoeman

Expert
Licensed User
Longtime User
Another question :confused:

If I am only interested in date (or time), is there a way to do it without entering other parameter (respectively : time (or date)) ?

in other words :
- time only picker ?
- date only picker ?
JP, I guess it can be done by changing the code of the original Github project. The original project does not at present make provision for this option. Attached is the Java code should you want to amend it to add the functionality that you require.
 

Attachments

  • TheJavaCode.zip
    6.3 KB · Views: 383

leitor79

Active Member
Licensed User
Longtime User
thank you for your contribution! very useful!

I have an issue however; when I call start_picker, nothing is shown and I get the log message:

onActivityResult: wi is null

I have referenced appcompat v3.52 and designsupport v2.32

Regards!
 

Johan Schoeman

Expert
Licensed User
Longtime User
thank you for your contribution! very useful!

I have an issue however; when I call start_picker, nothing is shown and I get the log message:

onActivityResult: wi is null

I have referenced appcompat v3.52 and designsupport v2.32

Regards!
If you started your own project then take note of the Manifest file of the project that I have posted.
 

Johan Schoeman

Expert
Licensed User
Longtime User
that it was. I've missed it, sorry.

thank you for your answer!
Whenever I download a sample project from the forum I always check the following before compiling the project:
1. What is going on in the project's Manifest file (there might for eg be permissions that have been added, etc)
2. Is there anything out of the odinary in the project's /Objects/res folder
3. If (2) above = true then make sure the files are set to READ ONLY or move them to a folder where you can make use of #AdditionalRes in your B4A project.
 

trueboss323

Active Member
Licensed User
Longtime User
There's a problem with this library, I'm using the 12 hour format and it is not switching between AM and PM when I try to select a time.
 

Johan Schoeman

Expert
Licensed User
Longtime User
There's a problem with this library, I'm using the 12 hour format and it is not switching between AM and PM when I try to select a time.
I will post the Java library / code and you can then look into the original code and change it and compile to create a new Jar.
 

trueboss323

Active Member
Licensed User
Longtime User
I will post the Java library / code and you can then look into the original code and change it and compile to create a new Jar.

Thank you, i have probably figured it out now. I had to select the AM/PM first and then select an hour, and it would finally change the time.

Now I have also discovered another problem, possibly a bug. See my topic about it here. This is possibly a bug on Android 4.x devices which i don't know if it is able to be fixed with your library. When I try to parse the date/time and get in ticks representation, it returns it an hour earlier than what I selected. Maybe you can try testing it yourself? Or another solution would be if there could be support getting the ticks value directly instead of having to parse it first and avoid problems. I have another topic about that here. I'd change the original Java code if only i was experienced and knew Java.
 

james_sgp

Active Member
Licensed User
Longtime User
I`m getting an error when I`m trying to install the demo (see screenshot for full errors) "..\demores\values\styles.xml:3: error: Error retrieving parent for item:..."
I`ve added the Resources, LibRes, and DemoRes into the demo folder, what else am I doing wrong?

James
 

Attachments

  • Capture.PNG
    Capture.PNG
    43.4 KB · Views: 282

Johan Schoeman

Expert
Licensed User
Longtime User
I`m getting an error when I`m trying to install the demo (see screenshot for full errors) "..\demores\values\styles.xml:3: error: Error retrieving parent for item:..."
I`ve added the Resources, LibRes, and DemoRes into the demo folder, what else am I doing wrong?

James
upload_2019-12-22_10-37-5.png



You need to select the AppCompat library. If you don't have it, search the forum, download it, and copy it to your additional library folder
You might also have to replace dialog_switch_datetime_picker.xml in /LibRes/layout with the attached xml file (prepared for androidx). Have tested in with B4A V9.50 and target SDK set to 28 and it is working.
 

Attachments

  • dialog_switch_datetime_picker.xml
    3 KB · Views: 322
Last edited:
Top