B4i Library [class] AnotherDatePicker

B4i implementation of AnotherDatePicker: http://www.b4x.com/android/forum/threads/27548/#content

SS-2014-11-06_16.26.52.png
 

Attachments

  • AnotherDatePicker.zip
    9 KB · Views: 341
Last edited:

billzhan

Active Member
Licensed User
Longtime User
I have an issue when debug the demo with iPad mini. After click btnMonths month actionsheet show, if I click any space outside action sheet, app crashed.

B4X:
    Application_Start
Application_Active
Error occurred on line: 111 (anotherdatepicker)
*** -[__NSArrayM objectAtIndex:]: index 4294967295 beyond bounds [0 .. 11]
Stack Trace: (
  CoreFoundation       <redacted> + 150
  libobjc.A.dylib      objc_exception_throw + 38
  CoreFoundation       <redacted> + 230
  B4i Example          -[B4IActionSheetDelegate actionSheet:clickedButtonAtIndex:] + 106
  UIKit                <redacted> + 170
  UIKit                <redacted> + 46
  UIKit                <redacted> + 152
  UIKit                <redacted> + 168
  UIKit                <redacted> + 116
  UIKit                <redacted> + 120
UIKit                <redacted> + 308
UIKit                <redacted> + 184
UIKit                <redacted> + 70
QuartzCore           <redacted> + 234
libdispatch.dylib    <redacted> + 22
libdispatch.dylib    <redacted> + 712
CoreFoundation       <redacted> + 8
CoreFoundation       <redacted> + 1512
CoreFoundation       CFRunLoopRunSpecific + 476
CoreFoundation       CFRunLoopRunInMode + 106
GraphicsServices     GSEventRunModal + 136
UIKit                UIApplicationMain + 1440
B4i Example          main + 116
libdyld.dylib        <redacted> + 2
)

Same issue found in Dbutils demo when btnId btnTest click.
 

Eric Baker

Member
Licensed User
Longtime User
The example on how to use this works fine on my iPad.

But I tried to use it in a module like this:

B4X:
Public Sub ShowPage
    If Not(myPage.IsInitialized) Then
        myPage.Initialize("Page")
        myPage.RootPanel.LoadLayout("ShowTask")
        adp.Initialize(Me, "adp")
        adp.AddToParent(myPage.RootPanel, btnCreated)
        adp.SetDate(DateTime.Now, True)
    End If
    Main.NavControl.ShowPage(myPage)
End Sub

And the Picker would only display a small strip (maybe 20 pixels) on the top of the page.

It seems that when AddToParent is called:

B4X:
Public Sub AddToParent(ACT As Panel, btn As Button)
    .
    .
    ACT.AddView(holder, 0, 0, 100%x, 100%y)
    .
    .

100%y (and possibly 100%x) are in an unknown (or incorrect) state.

To make it work, I had to move the code for the adp into the resize event:

B4X:
Sub Page_Resize(Width As Float, Height As Float)
    If Not(adp.IsInitialized) Then
        adp.Initialize(Me, "adp")
        adp.AddToParent(myPage.RootPanel, btnCreated)
        adp.SetDate(DateTime.Now, True)
    End If
End Sub

Not sure if this can be considered a bug or not. Anyhow, it would be nice to not have to put this code into the resize event.

Also, a recommended change is to to add a designer script to the date picker:

B4X:
'All variants script
AutoScaleAll
Base.HorizontalCenter = 50%x
Base.VerticalCenter = 50%y

This centers the calendar to the center of the screen and looks much better than the calendar in the upper left hand corner on an iPad.
 

Eric Baker

Member
Licensed User
Longtime User
Erel,

I knew that the size is only available in the resize event. Unfortunately I blindly tried to follow your example in the sample code, where you do not have it in the resize event. Only after looking at the source of the module, did I realize why it did not work. Thanks for the reply.
 

Eric Baker

Member
Licensed User
Longtime User
In AnotherDatePicker, keeping a reference to the parent:

B4X:
Sub Class_Globals
    .
    .
    Private Parent As Panel
End Sub

Public Sub AddToParent(ACT As Panel, btn As Button)
    Parent = ACT
    .
    .
End Sub

And handling the resize event in it

B4X:
Public Sub holder_Resize(Width As Float, Height As Float)
    holder.Width = Parent.Width
    holder.Height = Parent.Height
    ' Let's center this thing on the page while we are here
    Base.Top = (Parent.Height - Base.Height) / 2
    Base.Left = (Parent.Width - Base.Width) / 2
End Sub

Does the trick for me. Unfortunately the resize event is now recursive and can get called twice.
 

drponciano

Member
Licensed User
Longtime User
Trying to use AnotherDatePicker example I get an error during program startup. No changes made, just loaded the example end compiled and run. The error is in line 175 of file Date Utils (I’m using B4i version 1.50):
Application_Start
Error: Invalid value: d.C.20150116 000000
Error occurred on line: 175 (dateutils)
Cannot parse: invalid date
Stack Trace: (
CoreFoundation <redacted> + 150
libobjc.A.dylib objc_exception_throw + 38
CoreFoundation <redacted> + 0
B4i Example -[B4I ObjectToNumber:] + 556
B4i Example -[b4i_dateutils _setdateandtime::::::] + 3158
B4i Example -[b4i_dateutils _setdate:::] + 240
B4i Example -[b4i_anotherdatepicker _selectday:::] + 598
B4i Example -[b4i_anotherdatepicker _setdate:::] + 676
B4i Example -[b4i_anotherdatepicker _addtoparent:::] + 9006
B4i Example -[b4i_main _application_start:] + 1278
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 300
B4i Example +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1928
B4i Example -[B4IShell runMethod:] + 496
B4i Example -[B4IShell raiseEventImpl:method:args::] + 2060
B4i Example -[B4IShellBI raiseEvent:event:params:] + 1316
B4i Example __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74
libdispatch.dylib <redacted> + 10
libdispatch.dylib <redacted> + 22
libdispatch.dylib <redacted> + 712
CoreFoundation <redacted> + 8
CoreFoundation <redacted> + 1512
CoreFoundation CFRunLoopRunSpecific + 476
CoreFoundation CFRunLoopRunInMode + 106
GraphicsServices GSEventRunModal + 136
UIKit UIApplicationMain + 1440
B4i Example main + 116
libdyld.dylib <redacted> + 2
)
Application_Active

Any idea what is wrong?
 
Last edited:

drponciano

Member
Licensed User
Longtime User
I did some work and found that the problem is with function DateTimeParse.

  • d=GetEra(Years<0) & d returns “d.C” (Después de Cristo, After Christ) and that develops an error with the parse. If I comment the line, DateParse works fine
  • Using a correctly formatted string “20150116” as Date and “000000” as Time, DateTimeParse function sends the Invalid Value error (The date string works fine with DateParse so Time must be the problem)

I guess the issue has something to do with Spanish or Mexican DateTime format as we use D.C. instead of AD for era and some other problem with Time format.

Also, the calendar format with the [- +] 2015 style to change the year is not very usable when trying to set a birthday! (In my case I have to click 58 times the minus button, ha ha ha :) )
 
Last edited:

drponciano

Member
Licensed User
Longtime User
The code is from anotherdatepicker.zip unchaged. I downloaded the file AND tryied to run. That's it.
 

drponciano

Member
Licensed User
Longtime User
Somehow the problem appears only in the Ipod (iOS 8.0) I’m using for development. No problem with my iPhone and Ipad. Thanks
.
 

Asistente App

Member
Licensed User
Longtime User
Hi Erel , good night, I also had problems in implementing DateTime.DateTimeParse .
The tests in the simulator that had the US region were satisfactory , but installing the Iphone the region was in Spanish , the date format in Spanish dd/MM/yy that gave me the device. I only solve it changing the region to the United States, and it worked.

but this would have to do in each device this in this region. you will have a solution soon?

Thanks
 

Descartex

Well-Known Member
Licensed User
Longtime User
Hi,
Im trying to add this code to my project.
I have added the .bil layout file to my project, and initialized the object like this:
B4X:
adt.Initialize(Me,"Date")
        adt.AddToParent(Page_EditAccount.RootPanel,btnDate)
        adt.SetDate(DateTime.Now,True)
But, when i make adt.Show, it shows like this:
40136-e0dff5ae642ec668c80db388aa81eabc.jpg

It shows the control cropped... Its weird.

Thanks in advance.
 

Attachments

  • la foto.PNG
    la foto.PNG
    56.8 KB · Views: 71

Descartex

Well-Known Member
Licensed User
Longtime User
Hi.
I'm adding the ADP just after loading the layout that initializes the panel that content ADP, and after that, no other control is added to this panel.
This panes is only used to host the ADP.
Thanks.
 
Top