B4J Library [B4X] [XUI] AnotherDatePicker

Discussion in 'B4J Libraries & Classes' started by Erel, Oct 18, 2017.

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

    Erel Administrator Staff Member Licensed User

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

    [​IMG] [​IMG] [​IMG]

    Designer properties:
    [​IMG]

    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:
    Code:
    #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.
     

    Attached Files:

    Last edited: Apr 20, 2018
  2. incendio

    incendio Well-Known Member Licensed User

    Are there any specific OS requirements for this class/XUI library to run?

    Tested with B4A 7.0 on GenyMotion emulator, compiled OK, no error, but when run on Android 4.2.2, forced closed.
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Can you post the error logs?
     
  4. incendio

    incendio Well-Known Member Licensed User

    That's the problem.

    No Error log on B4A, compiled OK, but on the device (Genymotion), error message raised :
    "Unfortunelly B4A Example has stopped."

    Tested on Android 4.2.2 and 5.0.
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    There must be an error message in the logs. Run the app in debug mode if you are using B4A-Bridge.
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    I've tested it on a real device running Android 4.1. It ran properly.
     
  7. incendio

    incendio Well-Known Member Licensed User

    Errors log :
    ** Activity (main) Create, isFirst = true **
    ** Activity (main) Resume **
    java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: Field daystitlespane was declared with the wrong type.
    at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1656)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5041)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Field daystitlespane was declared with the wrong type.
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:166)
    at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
    at anywheresoftware.b4a.objects.B4XViewWrapper.LoadLayout(B4XViewWrapper.java:231)
    at b4a.example3.anotherdatepicker$ResumableSub_DesignerCreateView.resume(anotherdatepicker.java:361)
    at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1654)
    ... 9 more
    Caused by: java.lang.RuntimeException: Field daystitlespane was declared with the wrong type.
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:399)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:425)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:144)
    ... 13 more
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    incendio likes this.
  9. incendio

    incendio Well-Known Member Licensed User

    Oh, OK.

    I will compiled it with ver 7.3.
     
  10. stallone.hwang2

    stallone.hwang2 New Member Licensed User

    halo
    In this sample example , The Button Block to this DataPicket.
    How do i do?

    tks
     

    Attached Files:

  11. Erel

    Erel Administrator Staff Member Licensed User

    It is fixed in v1.01.
     
  12. nibbo

    nibbo Active Member Licensed User

    Is there an example anywhere showing how to se this?
     
  13. DonManfred

    DonManfred Expert Licensed User

    Yes, in #1! There are Examples for B4A/B4J/B4i
     
    nibbo and Erel like this.
  14. nibbo

    nibbo Active Member Licensed User

    Thanks, sometimes I amaze myself with my own stupidity!
     
  15. Meigionel TS

    Meigionel TS Member Licensed User

    It is says package is not installed when trying to install on phone when compiling with Android.jar of 26 API.
     
  16. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread in the questions forum.
     
  17. dcoun

    dcoun Member Licensed User

    Private a_dat As AnotherDatePicker
    Debug version works OK. In production release:

    anotherdatepicker_datefield_textchanged (java line: 265)
    java.lang.RuntimeException: Object should first be initialized (B4XView).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4a.objects.B4XViewWrapper.getViewObject(B4XViewWrapper.java:66)
    at anywheresoftware.b4a.objects.B4XViewWrapper.getColor(B4XViewWrapper.java:299)
    at medsite.myfamilydoctor.anotherdatepicker._datefield_textchanged(anotherdatepicker.java:265)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
    at anywheresoftware.b4a.objects.EditTextWrapper$1.afterTextChanged(EditTextWrapper.java:83)
    at android.widget.TextView.sendAfterTextChanged(TextView.java:8202)
    at android.widget.TextView.setText(TextView.java:4488)
    at android.widget.TextView.setText(TextView.java:4336)
    at android.widget.EditText.setText(EditText.java:89)
    at android.widget.TextView.setText(TextView.java:4311)
    at android.widget.TextView.setTransformationMethod(TextView.java:1936)
    at android.widget.TextView.applySingleLine(TextView.java:7883)
    at android.widget.TextView.setSingleLine(TextView.java:7858)
    at anywheresoftware.b4a.objects.EditTextWrapper.setSingleLine(EditTextWrapper.java:140)
    at medsite.myfamilydoctor.anotherdatepicker$ResumableSub_DesignerCreateView.resume(anotherdatepicker.java:331)
    at medsite.myfamilydoctor.anotherdatepicker._designercreateview(anotherdatepicker.java:283)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:67)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
    at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
    at anywheresoftware.b4a.objects.B4XViewWrapper.LoadLayout(B4XViewWrapper.java:236)
    at medsite.myfamilydoctor.sharedrev._addpanel(sharedrev.java:428)
    at medsite.myfamilydoctor.sharedrev._mkpanels(sharedrev.java:507)
    at medsite.myfamilydoctor.sharedrev._activity_resume(sharedrev.java:406)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
    at medsite.myfamilydoctor.sharedrev.afterFirstLayout(sharedrev.java:110)
    at medsite.myfamilydoctor.sharedrev.access$000(sharedrev.java:17)
    at medsite.myfamilydoctor.sharedrev$WaitForLayout.run(sharedrev.java:82)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6077)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
    java.lang.RuntimeException: Object should first be initialized (B4XView).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4a.objects.B4XViewWrapper.getViewObject(B4XViewWrapper.java:66)
    at anywheresoftware.b4a.objects.B4XViewWrapper.getColor(B4XViewWrapper.java:299)
    at medsite.myfamilydoctor.anotherdatepicker._datefield_textchanged(anotherdatepicker.java:265)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
    at anywheresoftware.b4a.objects.EditTextWrapper$1.afterTextChanged(EditTextWrapper.java:83)
    at android.widget.TextView.sendAfterTextChanged(TextView.java:8202)
    at android.widget.TextView.setText(TextView.java:4488)
    at android.widget.TextView.setText(TextView.java:4336)
    at android.widget.EditText.setText(EditText.java:89)
    at android.widget.TextView.setText(TextView.java:4311)
    at android.widget.TextView.setTransformationMethod(TextView.java:1936)
    at android.widget.TextView.applySingleLine(TextView.java:7883)
    at android.widget.TextView.setSingleLine(TextView.java:7858)
    at anywheresoftware.b4a.objects.EditTextWrapper.setSingleLine(EditTextWrapper.java:140)
    at medsite.myfamilydoctor.anotherdatepicker$ResumableSub_DesignerCreateView.resume(anotherdatepicker.java:331)
    at medsite.myfamilydoctor.anotherdatepicker._designercreateview(anotherdatepicker.java:283)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:67)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
    at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
    at anywheresoftware.b4a.objects.B4XViewWrapper.LoadLayout(B4XViewWrapper.java:236)
    at medsite.myfamilydoctor.sharedrev._addpanel(sharedrev.java:428)
    at medsite.myfamilydoctor.sharedrev._mkpanels(sharedrev.java:507)
    at medsite.myfamilydoctor.sharedrev._activity_resume(sharedrev.java:406)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
    at medsite.myfamilydoctor.sharedrev.afterFirstLayout(sharedrev.java:110)
    at medsite.myfamilydoctor.sharedrev.access$000(sharedrev.java:17)
    at medsite.myfamilydoctor.sharedrev$WaitForLayout.run(sharedrev.java:82)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6077)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
     
  18. Erel

    Erel Administrator Staff Member Licensed User

    I'm unable to reproduce it. Please try it with this code in the class:
    Code:
    Private Sub DateField_TextChanged (Old As String, New As String)
       
    Dim ticks As Long = GetCurrentDateFromTextField (New)
       
    If ticks > 0 Then
           setDate(ticks)
           
    If dateField.IsInitialized = True Then dateField.SetColorAndBorder(dateField.Color, 2dip0xFFA1A1A10)
           
    CallSub2(CallBack, EventName & "_DateChanged", ticks)
       
    Else
           
    If dateField.IsInitialized = True Then dateField.SetColorAndBorder(dateField.Color, 2dip, xui.Color_Red, 0)
       
    End If
    End Sub
     
    dcoun likes this.
  19. dcoun

    dcoun Member Licensed User

    It works OK now.
    The problem was in the "else" part of the If clause.
    Thank you a lot @Erel
     
  20. LucaMs

    LucaMs Expert Licensed User

    I would add:
    Code:
    #DesignerProperty: Key: Enabled, DisplayName: Enabled, FieldType: Boolean, DefaultValue: True


    Public Sub setEnabled(Enabled As Boolean)
       btnOpen.Enabled = Enabled
       dateField.Enabled = Enabled
    End Sub
     
    Claudio Oliveira and dcoun like 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