B4A Library [Class] AnotherDatePicker - A simple "web style" date picker

Discussion in 'Additional libraries, classes and official updates' started by Erel, Mar 21, 2013.

Thread Status:
Not open for further replies.
  1. Erel

    Erel Administrator Staff Member Licensed User

    AnotherDatePicker is an inline date picker:

    [​IMG]

    The advantage of this class over the built-in dialog (DateDialog from the Dialogs library) is that you can easily customize it as needed.

    Most of the layout is created with the visual designer and designer script.

    ADP.GetDate returns the selected date.

    The months names and days names are based on the device locale.

    In order to use this class in your code you should add AnotherDatePicker class, reference DateUtils library and add DatePicker layout file to the Files tab.

    Starting from v2.0, ADP should be added as a custom view from the designer:

    [​IMG]

    v2.0 - Better support for visual designer and more configurable options (including first day of week).
    v1.11 - Fixes an issue with SetDate that is called before the view is ready.
    v1.10 - Adds a Closed event. See the attached example.
     

    Attached Files:

    Last edited: Feb 10, 2016
    msali, luke2012, stanks and 11 others like this.
  2. barx

    barx Well-Known Member Licensed User

    Been looking for a good alternative to the date dialog as that seems to go all wrong looking when target sdk is high e.g. 17
     
    tdocs2 likes this.
  3. AscySoft

    AscySoft Active Member Licensed User

    This is a nice class. Keep them coming! Thanks
     
  4. barx

    barx Well-Known Member Licensed User

    I would just like to post an 'in use' pic of this date picker in action. I like this class and it has helped solve my issue with the date dialog available in the dialogs library. I have made s few UI tweak (but that is the joy of classes, right?)

    datepicker.png

    Thanks Erel
     
    luke2012 likes this.
  5. Erel

    Erel Administrator Staff Member Licensed User

    Looks great!

    Can you upload your class (its looks better than the original...)?
     
  6. barx

    barx Well-Known Member Licensed User

    I just want to check that it works good in a couple more devices then yes, of course I will upload it. I didn't change alot to be honest. Just a couple of tweaks.
     
  7. barx

    barx Well-Known Member Licensed User

    As promised here is my edit (See attached below). Please note that I only edited a few minor UI things, nothing special or functional.

    A few of the colors are slightly different to my screenshot, mainly due to, the app I posted screenshot from uses a Custom Light theme, so default texts are dark. Applying that to the sample would just complicate matters.

    Anybody that uses Erel original class files, one thing I would add to the DatePicker designer layout script is:

    Add
    Code:
    Base.Height = Min(300dip100%y)
    Just after
    Code:
    AutoScaleAll
    If Erel agrees with this, maybe he will update the original for those that don't read past post #1 :cool:
    On my phone 480x800 I found that the bottom of the date picker would be cropped slightly in landscape mode. Adding the above line solves that issue.

    Updated to reflect Erels update to DateUtils (now v1.03)

    Thanks again Erel, great class.
     

    Attached Files:

    Last edited: Mar 29, 2013
    msali and luke2012 like this.
  8. NJDude

    NJDude Expert Licensed User

    NICE!!

    However, there are some issues:

    1- Today is March 29th, and I don't see that date HERE (March has 31 days)

    2- Tapping on the TODAY button at the button, brings the right date to the label, however the "blank square" still remains.

    3- If you tap on March 28, the "blank square" goes away, but, tapping on the TODAY button brings it back.

    4- There are other months containing the wrong number of days, check December 2013 for example.

    I've tried that on 4 different devices, same deal.
     
    Last edited: Mar 29, 2013
  9. Erel

    Erel Administrator Staff Member Licensed User

    Do you get these errors with the original class as well? Works fine here.
     
  10. NJDude

    NJDude Expert Licensed User

    Same thing on both, the original and the modified.

    These are the results (2013):

    Jan: OK
    Feb: OK
    Mar: WRONG
    Apr: OK
    May: WRONG
    Jun: OK
    Jul: WRONG
    Aug: OK
    Sep: OK
    Oct: WRONG
    Nov: OK
    Dec: WRONG
     
    Last edited: Mar 29, 2013
  11. Erel

    Erel Administrator Staff Member Licensed User

    Which locale is set on your device?

    What is the value of:
    Code:
    Log(DateUtils.NumberOfDaysInMonth(32013))
     
  12. NJDude

    NJDude Expert Licensed User

    It returns 28
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    Which locale is selected in your device? You can see it under Settings - Language and Input (or Locale and text).
     
  14. NJDude

    NJDude Expert Licensed User

    Oops, forgot to answer that: us_EN
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    I forgot to ask, which time zone is selected?
     
  16. NJDude

    NJDude Expert Licensed User

    Eastern US - (GMT -4)
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    Good. I believe that I found the problem. Please update DateUtils.NumberOfDaysInMonth with this code and test it again:
    Code:
    Public Sub NumberOfDaysInMonth(Month As Int, Year As Int) As Int
       
    Dim Ticks As Long = SetDate(Year, Month, 1)
       
    Dim nextMonth As Long = DateTime.Add(Ticks, 010)
       
    Dim res As Int =  Round((nextMonth - Ticks) / DateTime.TicksPerDay)
       
    Return res
    End Sub
     
  18. NJDude

    NJDude Expert Licensed User

    Yup, it seems that FIXED the problem.
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    Great. Thank you for your help. I will update the relevant files.
     
  20. Erel

    Erel Administrator Staff Member Licensed User

    The project in the first post was updated with DateUtils v1.03. This is an important update.

    The following line was added to the designer script:
    Code:
    Base.Height = Min(100%y, Base.Height)
    This is relevant for phones in landscape orientation.
     
    Macuz likes this.
Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice