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,691
  • AnotherDatePicker_B4A.zip
    13 KB · Views: 2,752
  • AnotherDatePicker_B4i.zip
    174.2 KB · Views: 1,255
  • AnotherDatePicker.bas
    10.7 KB · Views: 1,868
Last edited:

incendio

Well-Known Member
Licensed User
Longtime 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.
 

incendio

Well-Known Member
Licensed User
Longtime 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.
 

incendio

Well-Known Member
Licensed User
Longtime 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
 

stallone.hwang2

New Member
Licensed User
Longtime User
halo
In this sample example , The Button Block to this DataPicket.
How do i do?

tks
 

Attachments

  • Screenshot_20171101-183949.png
    Screenshot_20171101-183949.png
    66.9 KB · Views: 1,166
  • Screenshot_20171101-183954.png
    Screenshot_20171101-183954.png
    101.3 KB · Views: 1,207

dcoun

Member
Licensed User
Longtime 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)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm unable to reproduce it. Please try it with this code in the class:
B4X:
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, 2dip, 0xFFA1A1A1, 0)
       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

Member
Licensed User
Longtime User
I'm unable to reproduce it. Please try it with this code in the class:
B4X:
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, 2dip, 0xFFA1A1A1, 0)
       CallSub2(CallBack, EventName & "_DateChanged", ticks)
   Else
       If dateField.IsInitialized = True Then dateField.SetColorAndBorder(dateField.Color, 2dip, xui.Color_Red, 0)
   End If
End Sub

It works OK now.
The problem was in the "else" part of the If clause.
Thank you a lot @Erel
 
Status
Not open for further replies.
Top