MaterialDateTimePicker

roberto64

Active Member
Licensed User
Longtime User
this is a wrap for this github project.

I´m VERY PROUD to present you this Date- and TimePicker Dialog library! I have tried to wrap about 20 different Date and TimePickers in the past 1,5 years. ALL UNSuccessfully. :-(

But this one i got working :D



MaterialDateTimePicker
Author:
DonManfred (wrapper)
Version: 1.5
  • Calendar
    Fields:
    • CANADA As Locale
    • CANADA_FRENCH As Locale
    • CHINA As Locale
    • CHINESE As Locale
    • ENGLISH As Locale
    • FRANCE As Locale
    • FRENCH As Locale
    • GERMAN As Locale
    • GERMANY As Locale
    • ITALIAN As Locale
    • ITALY As Locale
    • JAPAN As Locale
    • JAPANESE As Locale
    • KOREA As Locale
    • KOREAN As Locale
    • PRC As Locale
    • ROOT As Locale
    • SIMPLIFIED_CHINESE As Locale
    • TAIWAN As Locale
    • TRADITIONAL_CHINESE As Locale
    • UK As Locale
    • US As Locale
    Methods:
    • Initialize (dateformat As String, locale As Locale, date As String)
    • IsInitialized As Boolean
  • DatePickerDialog
    Events:
    • onCancel ( As )
    • onDateSet (year As Int, monthOfYear As Int, dayOfMonth As Int)
    • onDismiss ( As )
    Methods:
    • Initialize (EventName As String, year As Int, monthOfYear As Int, dayOfMonth As Int)
    • IsInitialized As Boolean
    • autoDismiss (autoDismiss As Boolean)
      Set whether the picker should dismiss itself when a day is selected
      autoDismiss: true if the dialog should dismiss itself when a day is selected
    • dismissOnPause (dismissOnPause As Boolean)
      Set whether the picker should dismiss itself when being paused or whether it should try to survive an orientation change
      dismissOnPause: true if the dialog should dismiss itself when it's pausing
    • isThemeDark As Boolean
      Returns true when the dark theme should be used
      Return type: @return:true if the dark theme should be used, false if the default theme should be used
    • setYearRange (startYear As Int, endYear As Int)
    • show (tag As String)
    • showYearPickerFirst (yearPicker As Boolean)
      Set whether the year picker of the month and day picker is shown first
      yearPicker: boolean
    • vibrate (vibrate As Boolean)
      Set whether the device should vibrate when touching fields
      vibrate: true if the device should vibrate when touching a field
    Properties:
    • AccentColor As Int
      Get the accent color of this dialog
    • AccentColor2 As String [write only]
      Set the accent color of this dialog
    • CancelText As String [write only]
      Set the label for the Cancel button (max 12 characters)
    • FirstDayOfWeek As Int [write only]
    • HighlightedDays()() As Calendar
      Sets an array of dates which should be highlighted when the picker is drawn
    • MaxDate As Calendar
      Sets the minimal date supported by this DatePicker. Dates after (but not including) the
      specified date will be disallowed from being selected.
    • MinDate As Calendar
      Sets the minimal date supported by this DatePicker. Dates before (but not including) the
      specified date will be disallowed from being selected.
    • OkText As String [write only]
      Set the label for the Ok button (max 12 characters)
    • SelectableDays()() As Calendar
      Set's a list of days which are the only valid selections.
      Setting this value will take precedence over using setMinDate() and setMaxDate()
    • ThemeDark As Boolean [write only]
      Set whether the dark theme should be used
    • Title As String [write only]
      Set a title to be displayed instead of the weekday
  • TimePickerDialog
    Events:
    • onCancel ( As )
    • onDismiss ( As )
    • onTimeSet (hour As Int, minute As Int, second As Int)
    Methods:
    • Initialize (EventName As String, hourOfDay As Int, minute As Int, is24HourMode As Boolean)
    • IsInitialized As Boolean
    • dismissOnPause (dismissOnPause As Boolean)
      Set whether the picker should dismiss itself when it's pausing or whether it should try to survive an orientation change
      dismissOnPause: true if the picker should dismiss itself
    • enableSeconds (enableSeconds As Boolean)
      Set whether an additional picker for seconds should be shown
      enableSeconds: true if the seconds picker should be shown
    • is24HourMode As Boolean
    • isThemeDark As Boolean
    • setMaxTime (hour As Int, minute As Int, second As Int)
    • setMinTime (hour As Int, minute As Int, second As Int)
    • setStartTime (hourOfDay As Int, minute As Int)
    • setStartTime2 (hourOfDay As Int, minute As Int, second As Int)
    • setTimeInterval2 (hourInterval As Int, minuteInterval As Int)
      Set the interval for selectable times in the TimePickerDialog
      This is a convenience wrapper around setSelectableTimes
      The interval for all three time components can be set independently
      hourInterval: The interval between 2 selectable hours ([1,24])
      minuteInterval: The interval between 2 selectable minutes ([1,60])
    • setTimeInterval3 (hourInterval As Int, minuteInterval As Int, secondInterval As Int)
      Set the interval for selectable times in the TimePickerDialog
      This is a convenience wrapper around setSelectableTimes
      The interval for all three time components can be set independently
      hourInterval: The interval between 2 selectable hours ([1,24])
      minuteInterval: The interval between 2 selectable minutes ([1,60])
      secondInterval: The interval between 2 selectable seconds ([1,60])
    • show (tag As String)
    • vibrate (vibrate As Boolean)
      Set whether the device should vibrate when touching fields
      vibrate: true if the device should vibrate when touching a field
    Properties:
    • AccentColor As Int
      Set the accent color of this dialog
    • CancelText As String [write only]
      Set the label for the Cancel button (max 12 characters)
    • MaxTime2 As Timepoint [write only]
    • MinTime2 As Timepoint [write only]
    • OkText As String [write only]
      Set the label for the Ok button (max 12 characters)
    • SelectableTimes() As Timepoint [write only]
    • ThemeDark As Boolean [write only]
      Set a dark or light theme. NOTE: this will only take effect for the next onCreateView.
    • TimeInterval As Int [write only]
      Set the interval for selectable times in the TimePickerDialog
      This is a convenience wrapper around setSelectableTimes
      The interval for all three time components can be set independently
    • Title As String
      Set a title. NOTE: this will only take effect with the next onCreateView
  • Timepoint
    Methods:
    • Initialize (hour As Int, minute As Int, second As Int)
    • IsInitialized As Boolean

View attachment 45424

View attachment 45425

Installation:
- Extract the contents (jar, xml and aar) of MaterialTimePickerV[x.yy].zip to your additional library folder

New in V1.5
- I have created an aar out from the third party lib with Android Studio
- I have changed the wrapper then to use the aar.



hello DonManfred, in the version of Android 2.3.6 when compiling in debug arrived in the line "diaDate.Initialize (" Date ", DateTime.GetYear (DateTime.Now), DateTime.GetMonth (DateTime.Now) -1, DateTime. GetDayOfMonth (DateTime.Now)) "the program exits without giving an error.
regards
 

DonManfred

Expert
Licensed User
Longtime User
hello DonManfred, in the version of Android 2.3.6 when compiling in debug arrived in the line "diaDate.Initialize (" Date ", DateTime.GetYear (DateTime.Now), DateTime.GetMonth (DateTime.Now) -1, DateTime. GetDayOfMonth (DateTime.Now)) "the program exits without giving an error.
This lib needs

Support for Android 4.0 and up.
 

Gawro777

Member
Licensed User
Longtime User
Great Job! Works perfectly! Thanks!

I would like to use it also to choose default time in AHPreference manager. Is there any way to add it to preference category? As Android intent, maybe? How to do it (short example, pls)?
Thanks for help.
 

AHilton

Active Member
Licensed User
Longtime User
I'm having the same issue as below...

B4A version 6.31 Registered
Library version 1.52 and the aar file is in my custom libraries folder.

During debug, it works fine. In Release, it give that error.



Hi @DonManfred, I've tried to run the example you provided, but it doesn't work in release mode.
In debug mode, everything works fine (also the accent color), but in release it return this error:

B4X:
java.lang.RuntimeException: Font asset not found fonts/Roboto-Medium.ttf

    at android.graphics.Typeface.createFromAsset(Typeface.java:272)
    at com.wdullaer.materialdatetimepicker.TypefaceHelper.get(TypefaceHelper.java:31)
    at com.wdullaer.materialdatetimepicker.date.DatePickerDialog.onCreateView(DatePickerDialog.java:338)
    at android.app.Fragment.performCreateView(Fragment.java:2114)
    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
    at android.app.BackStackRecord.run(BackStackRecord.java:833)
    at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
    at android.app.FragmentManagerImpl$1.run(FragmentManager.java:452)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6134)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

How can I handle it? :confused:
(I tested it on both 1.51 and 1.52)
 

Gabino A. de la Gala

Active Member
Licensed User
Longtime User
It works perfect.

What about to have a TODAY button in datepicker y NOW in timepicker?

Could be?. I did not find how to do it...
 

dealsmonkey

Active Member
Licensed User
Longtime User
Hi, nice library :)

I am having an issue where I cannot got the mindate to work. I have tried your example and that is the same I am based in the UK.

What I am trying to do is prevent the user from entering a date before today ?

B4X:
materialDateDialog.Initialize("startDate",y,m,d)   
Dim cal As Calendar   
cal.Initialize("dd.MM.yyyy",cal.UK,$"${d}.${m}.${y}"$)   
materialDateDialog.MinDate = cal

any thought please ?
 

dealsmonkey

Active Member
Licensed User
Longtime User
B4X:
    cal.Initialize("dd.MM.yyyy",cal.GERMAN,"23.11.2016")
works for me... All Dates before 23 Nov are not selectable...

Same works with
B4X:
    Dim cal As Calendar
    cal.Initialize("dd.MM.yyyy",cal.UK,"23.11.2016")
  
    date.MinDate = cal


You are correct ! Very strange, just pasted your code and all worked. Thanks for the reply ! :)
 

Douglas Farias

Expert
Licensed User
Longtime User
Hi @DonManfred
i m trying use this lib, but i got a error. (just a report)

when i try select a date of January of 2017 (or + 2018,2019 etc...) i got (- 1 month)
Example:
i selected day 01 month 01 year 2017
log = 1/0/2017


here is the sub
Sub pegardata_onDateSet(year As Int, monthOfYear As Int, dayOfMonth As Int)
Log(dayOfMonth&"/"&monthOfYear&"/"&year)
End Sub


if i select February
day 01 month 01 year 2017
log = 1/1/2017

with 2016 i dont have this error, only the next years

thx
 

fredo

Well-Known Member
Licensed User
Longtime User
I´m VERY PROUD to present you this Date- and TimePicker Dialog library!

Thank you for your work on wrapping this lib. It is very useful.

As it seems the author released a new version.

Is there a possibility that you can let your magic work again on the wrap?


In order to keep up with the MD Standards the dialog needs to be presented like this:
03-12-_2016_09-07-17.jpg
 

Attachments

  • 03-12-_2016_09-29-00.jpg
    03-12-_2016_09-29-00.jpg
    191.4 KB · Views: 304
Top