Android Question How to add Enabled property in the old AnotherDatePicker?

Theera

Well-Known Member
Licensed User
Longtime User
Due to I must edit some code for Thai programmer about calendar. I can't found Enabled property of AnotherDatePicker.
I would like to add it. I'm not good at programming ,please to help me.

Refer to : https://www.b4x.com/android/forum/t...epicker-a-simple-web-style-date-picker.27548/

I have tried to code ,but I can't do it.
B4X:
Public Sub Enabled as Boolean
      dim res as Boolean
      If enabled=False then return True
      mBase.enabled=False
      return  False
End Sub
 

rraswisak

Active Member
Licensed User
Open AnotherPicker class and follow this step:

Since Enabled property name reserved, let use Disabled instead

1. Add Disabled property name
Property name:
'AnotherDatePicker - v2.00
#Event: Closed (Cancelled As Boolean, Date As Long)
#DesignerProperty: Key: Disabled, DisplayName: Disabled, FieldType: Boolean, DefaultValue: false, Description: Disable date picker.
#DesignerProperty: Key: CancelVisible, DisplayName: Cancel Visible, FieldType: Boolean, DefaultValue: True, Description: Whether the cancel button should be displayed.
#DesignerProperty: Key: TodayVisible, DisplayName: Today Visible, FieldType: Boolean, DefaultValue: True
'...
'...

2. Add isDisable global variable
Global variable:
Sub Class_Globals
    Private isDisabled As Boolean
    Private holder As Panel
    Private cvs, cvsBackground As Canvas
    Private DaysPanel As Panel
    '...
    '...
End Sub

3. Read current property value
Read property value:
Public Sub AfterLoadLayout (Props As Map)
    isDisabled=Props.Get("Disabled")
    waitForAddToActivity = False
    holder.Initialize("holder")
    '...
    '...
End Sub

4. Modify Date Picker click behaviour
Modify click event:
Private Sub lbl_Click
    If isDisabled=False Then Show
End Sub

5. Last, Create new method to enable/disable via code
Enable/Disable via code:
public Sub Disabled(value As Boolean)
    isDisabled = value
End Sub
1672900379167.png

To enable/disable via code:
B4X:
AnotherDatePicker1.Disabled(False) 'or true
 
Last edited:
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
3. Read current property value
Read property value:
Public Sub AfterLoadLayout (Props As Map)
    isDisabled=Props.Get("Disabled")
    waitForAddToActivity = False
    holder.Initialize("holder")
    '..

I don't have waitForAddToActivity andholder parameters. How do I docontinue, please?
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Please to see my code. I have the switch (using UiSwitch library) to control ON/OFF calendar to be enabled/disabled.
How do I code it ?
 

Attachments

  • mySwTH_ON3.png
    mySwTH_ON3.png
    76.4 KB · Views: 50
  • mySwTH_OFF3.png
    mySwTH_OFF3.png
    40.2 KB · Views: 44
  • AnotherThaiDatePicker.zip
    123.1 KB · Views: 69
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
The simplest way would be to check isdisabled in HandleMouse

B4X:
Private Sub HandleMouse(x As Double, y As Double, move As Boolean)

    'check if the control is disabled and do nothing with mouse event.
    if isDisabled then return
    
    Dim boxX = x / boxW, boxY =  y / boxH As Int
    Dim newSelectedDay As Int = boxY * 7 + boxX + 1 - dayOfWeekOffset
    Dim validDay As Boolean = newSelectedDay > 0 And newSelectedDay <= daysInMonth
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
I have changed #Event:Closed to be#Event: Clicked instead.
And create this module as belows
B4X:
Public  Sub DatePicker_Clicked
  If isDisabled Then return
EndSub
I don't know that how I should refer to thecalendar button.
 
Upvote 0

emexes

Expert
Licensed User
I am starting to think that a simpler solution might have been to

just cover the AnotherDatePicker with a semi-transparent panel whenever you need to disable it.
 
Upvote 0
Top