B4J Library [B4X] [XUI] AnotherDatePicker

Status
Not open for further replies.
Edit: don't use this library. Use B4XDialog + B4XDateTemplate from XUI Views library instead.

This is a cross platform version of AnotherDatePicker custom view based on XUI library.

SS-2017-10-18_18.02.02.png
SS-2017-10-18_18.02.37.png
SS-2017-10-18_18.03.11.png


Designer properties:
SS-2017-10-18_18.06.23.png


The user can enter the date directly into the field. The field border color will change to red when the value is invalid.

Notes:

- B4J buttons raise the Action event. This is handled in the code with:
B4X:
#if B4J
Private Sub btnCancel_Action
#Else
Private Sub btnCancel_Click
#End If
   Hide
End Sub

Click event will be added in the next version of B4J.

- It depends on XUI v1.3+.
- If you are using a B4i version before 4.4 (stable) then you need to remove the reference to iDateUtils library and add the DateUtils code module instead. This is related to a bug fixed in B4i v4.4.
- You might see a warning while debugging about a missing RaiseSynchronousEvent attribute. You can ignore it. It is related to changing the text programmatically while handling the TextChanged event.
- This is quite a complicated custom view and it is a good example of using XUI library to write cross platform code.

Versions

1.03 - Fixes an issue with CloseAllDialogs always returning True (https://www.b4x.com/android/forum/threads/b4x-xui-anotherdatepicker.85160/page-2#post-581920).
1.02 - Fixes an issue with dates before 1970.
1.01 - Sets the elevation of the dialog panel.

Latest version is attached separately.
 

Attachments

  • AnotherDatePicker_B4J.zip
    7.2 KB · Views: 1,647
  • AnotherDatePicker_B4A.zip
    13 KB · Views: 2,716
  • AnotherDatePicker_B4i.zip
    174.2 KB · Views: 1,210
  • AnotherDatePicker.bas
    10.7 KB · Views: 1,829
Last edited:

Claudio Oliveira

Active Member
Licensed User
Longtime User
@Erel
CloseAllDialogs sub always returns True, so Back key can't be handled correctly.

Replacing lines 291 and 292:
B4X:
adp.Hide
res = True

With this code:
B4X:
If adp.IsVisible Then
    adp.Hide
    res = True
End If

solved the issue.
 

Claudio Oliveira

Active Member
Licensed User
Longtime User
I would add:
B4X:
#DesignerProperty: Key: Enabled, DisplayName: Enabled, FieldType: Boolean, DefaultValue: True


Public Sub setEnabled(Enabled As Boolean)
   btnOpen.Enabled = Enabled
   dateField.Enabled = Enabled
End Sub

To accomplish this, there ain't no need to add an Enabled custom designer property.
Just use the common Enabled property and handle it inside the class, like this:

B4X:
Public Sub getEnabled As Boolean
    Return mBase.Enabled
End Sub
Public Sub setEnabled(enabled As Boolean)
    mBase.Enabled=enabled
    btnOpen.Enabled = enabled
    dateField.Enabled = enabled
End Sub

Of course you should also set Enabled property of DateField and btnOpen accordingly in the DesignerCreateView sub
B4X:
dateField.Enabled=mBase.Enabled

btnOpen.Enabled=mBase.Enabled

And that's all there's to it. :)
 

Claudio Oliveira

Active Member
Licensed User
Longtime User
Hi @Erel
The 1.03 class file name has a space (or a not visible special character) in its name.
It is being saved locally as "AnotherDatePicker .bas", which causes a unknown type error.
Please take a look at it.
Thanks
 

Claudio Oliveira

Active Member
Licensed User
Longtime User
It is not so, it works. I would try creating a new layout.
Sorry, @LucaMs, but it is so indeed.
Creating a new layout is a "workaround" not a solution. This would lead to recreating all relevant layouts and editing all relevant variable types in every existing working projects. That's not reasonable.
Truth is: the file name is wrong and should be fixed.
Ok. It's not big deal. Just dowload the file, rename it locally and that's it. But I don't think that's how things should be dealt with...
 

Star-Dust

Expert
Licensed User
Longtime User
Hi @Erel
The 1.03 class file name has a space (or a not visible special character) in its name.
It is being saved locally as "AnotherDatePicker .bas", which causes a unknown type error.
Please take a look at it.
Thanks
I tried the Version for B4A and B4J I do not have this character that tells me error.

Which are you trying? What error do you report?
 

Claudio Oliveira

Active Member
Licensed User
Longtime User
I tried the Version for B4A and B4J I do not have this character that tells me error.
Which are you trying? What error do you report?

Hi @Star-Dust
Look, I have a working project which uses AnotherDatePicker class version 1.02
Today I've downloaded version 1.03 and I just couldn't compile my working project afterwards, because B4A says "AnotherDatePicker" is not a known type. This is the main error, which leads to a number of other syntax errors and stuff...
Well, after a while I realized that the class name was not "AnotherDatePicker", but "AnotherDatePicker " instead.
I removed the class from my project; renamed the .bas file from "AnotherDatePicker .bas" to "AnotherDatePicker.bas"; added it again and everything got ok and I was able to compile and run my project.
This is simple and straightforward.
Please note that I didn't and still don't mean to start an argument about this, but just point out that the file name for class version 1.03 attached in post #1 was wrong, and this could lead others to the same errors I've come across.
As I said before, this is not a big deal. Renaming the file is all it takes to make everything allright. My intention was only to let Erel know about this tiny mistake and save other people a couple of minutes of debugging.
Nevertheless, all this happened about 11:30 AM (02:30 PM GMT) today. Now it's 19:07 PM (22:07 PM GMT) and it's not happening anymore.
I'm not able to explain this.
That said, I consider this argument closed and rather leave it to Erel's comments, shall he consider it worthy...

'gonna have some icy cold beer now. ;)

Have you all an awsome weekend!
 

Star-Dust

Expert
Licensed User
Longtime User
Maybe Erel had noticed the error and he corrected or there was a failure in the download and he saved the file with none wrong, it happens when there is a drop in voltage with the pc fixed to me it happened.
 

Star-Dust

Expert
Licensed User
Longtime User
Then it will be the second hypothesis, because I did not give this error :)
 

Claudio Oliveira

Active Member
Licensed User
Longtime User
Yes, @Star-Dust, that could be the case indeed. Transmission error... Windows mess... bad disk... A lot of things could have caused this. We'll never know.
So let's forget about this and move on. ;)
 

LucaMs

Expert
Licensed User
Longtime User
I added a "feature" and an event.

I needed to highlight a certain number of dates; so I added some routines, the color properties of the dates to highlight and slightly modified the DrawDays routine for this purpose.

Without much imagination I named these dates "special dates". It can be useful, for example, to highlight appointments.

I have also added an event that triggers when you select a different month or year.

I have marked the lines added with "LM" (I hope all lines).

I do not know what Erel wants to do with the attached version, whether to make it official or not; in the meantime, I attach it :)
 

Attachments

  • ADP LM.zip
    7.7 KB · Views: 534
Last edited:

Vicente Barba

Member
Licensed User
Hello everyone,

I am using AnotherDatePicker v1.03 in a project and for internationalization I would like to be able to change the date format and be able to choose between for example:
y - m - d
m / d / y
d / m / y

Does anyone know a good way to get it?
 
Status
Not open for further replies.
Top