# MaterialDateRangePicker **Repository Path**: baijuncheng-open-source/material-date-range-picker ## Basic Information - **Project Name**: MaterialDateRangePicker - **Description**: A material Date Range Picker library for HarmonyOS - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-06-07 - **Last Updated**: 2021-07-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Material Date and Time Picker with Range Selection ====================================================== Credits to the original amazing material date picker library by wdullaer - https://github.com/wdullaer/MaterialDateTimePicker ##### Add RangePicker to your project 1.Copy the MaterialDateRangePicker/library folder to the project directory 2.Modify settings.gradle under the project and add the dependency on this module as follows: include ':library', ':sample' 3. Introduce the dependency of the module under the project. Taking the entry module as an example, you need to modify the build.gradle file under the entry module to add the dependency: compile project(path: ':library') or implementation project(':library') Solution 2: local use of har package integration 1. Compile this project, copy the har package generated in the build directory of the Tray/library folder to the project lib folder: directory:\MaterialDateRangePicker\library\build\outputs\har\debug\library-debug.har 2. Add the following code in the entry's gradle implementation fileTree(dir:'libs', include: ['*.jar','*.har']) 3.dependencies { implementation 'com.gitee.baijuncheng-open-source:materialdaterangepicker:1.0.0' } ## PREVIEW
## Date Selection
## Time Selection
From the original library documentation - Using the Pickers -------------------------------- 1. Implement an `OnDateSetListener` or `OnTimeSetListener` 2. Create a ``DatePickerDialog` using the supplied factory ### Implement an `OnDateSetListener` In order to receive the date set in the picker, you will need to implement the `OnDateSetListener` interfaces. Typically this will be the `Ability` or `AbilitySlice` that creates the Pickers. or ### Implement an `OnTimeSetListener` In order to receive the time set in the picker, you will need to implement the `OnTimeSetListener` interfaces. Typically this will be the `Ability` or `Ability` that creates the Pickers. ```java @Override public void onDateSet(DatePickerDialog dialog, int year, int monthOfYear, int dayOfMonth, int yearEnd, int monthOfYearEnd, int dayOfMonthEnd) { String date = "You picked the following date from : " + dayOfMonth + "/" + (++monthOfYear) + "/" + year + "to " + dayOfMonthEnd + "/" + (++monthOfYearEnd) + "/" + yearEnd; dateText.setText(date); dpd = null; } @Override public void onTimeSet(TimePickerDialog dialog, int hourOfDay, int minute, int hourOfDayEnd, int minuteEnd) { String hourString = hourOfDay < 10 ? "0" + hourOfDay : "" + hourOfDay; String minuteString = minute < 10 ? "0" + minute : "" + minute; String hourStringEnd = hourOfDayEnd < 10 ? "0" + hourOfDayEnd : "" + hourOfDayEnd; String minuteStringEnd = minuteEnd < 10 ? "0" + minuteEnd : "" + minuteEnd; String time = "You picked the following time start : " + hourString + "h" + minuteString + "m" + " to " + hourStringEnd + "h" + minuteStringEnd + "m"; timeText.setText(time); tpd = null; } ``` ### Create a DatePickerDialog` using the supplied factory You will need to create a new instance of `DatePickerDialog` using the static `newInstance()` method, supplying proper default values and a callback. Once the dialogs are configured, you can call `show()`. ```java Calendar now = Calendar.getInstance(); DatePickerDialog dpd = DatePickerDialog.newInstance( context, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH) ); dpd.show(getFragmentManager(), "Datepickerdialog"); ``` ### Create a TimePickerDialog` using the supplied factory You will need to create a new instance of `TimePickerDialog` using the static `newInstance()` method, supplying proper default values and a callback. Once the dialogs are configured, you can call `show()`. ```java Calendar now = Calendar.getInstance(); TimePickerDialog tpd = TimePickerDialog.newInstance( context, now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), false ); tpd.show(getFragmentManager(), "Timepickerdialog"); ``` For other documentation regarding theming , handling orientation changes , and callbacks - check out the original documentation - https://github.com/wdullaer/MaterialDateTimePicker