Introduction

DateTimePicker is a library which contains the beautiful DatePicker that can be seen in the new Google Agenda app.

Tutorial Video


Informations

Creator
flavienlaurent
flavienlaurent
Git URL:
Language
Java
Min SDK:
Android 2.1
License:
Apache License
Created At:
Jun 02, 2013
Last Updated:
Jan 14, 2018
Star:
1880
Fork:
637
Watcher count:
103
Tags

Description

official source:

https://android.googlesource.com/platform/frameworks/opt/datetimepicker/ (android 4.3+)

datetimepicker

datetimepicker is a library which contains the beautiful datepicker and timepicker that can be seen in the new google agenda app.

this picker is available for 2.1+

you have a recurrence picker in the same style here.

warning

  • requires android-support-v4 and nineoldandroids
  • accessibility is missing for datepicker on all devices and below ics devices for timepicker.
  • scroll adjustment is missing below ics devices for timepicker and datepicker.

description

this library reproduces as much as possible the original picker contained in the new google agenda app.

example image

try out the sample apk here

or browse the source code of the sample application for a complete example of use.

including in your project

last version is 0.0.2

just add the following statement in your build.gradle


compile 'com.github.flavienlaurent.datetimepicker:library:version'

usage

using the library is simple, just look at the source code of the provided sample here

acknowledgements

  • thanks to google for this beautiful picker

license


copyright 2013 flavien laurent (datepicker) edisonw (timepicker)

licensed under the apache license, version 2.0 (the "license"); you may not use this file except in compliance with the license. you may obtain a copy of the license at

http://www.apache.org/licenses/license-2.0

unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "as is" basis, without warranties or conditions of any kind, either express or implied. see the license for the specific language governing permissions and limitations under the license.

Step by Step

Step-by-step integrated DateTimePicker:

Step 1: Include in your project

Add the following statement inside your project

compile 'com.github.flavienlaurent.datetimepicker:library:VERSION'

* Remember to change VERSION text to lastest DateTimePicker Version. When this tutorial writen it is 0.0.2 so the text will be

compile 'com.github.flavienlaurent.datetimepicker:library:0.0.2'

 

Step 2: Add Vibrate Permission inside Manifest file

<uses-permission android:name="android.permission.VIBRATE" />

 

Step 3: Show DatePicker Dialog

//Show choose date Dialog, the this variable will error, but don't worry, go to step 4
DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(this,2015,9,5);
//Set year Range from - to
datePickerDialog.setYearRange(1990,2015);
//Set is vibrate on click dialog
datePickerDialog.setVibrate(true);
//Set close when choose the day
datePickerDialog.setCloseOnSingleTapDay(true);
//show the dialog - TAG_DATE_PICKER_DIALOG is just the string variable it could be anything
datePickerDialog.show(getSupportFragmentManager(),TAG_DATE_PICKER_DIALOG);

 

Step 4: Register your Activity to implements DatePickerDialog.OnDateSetListener

public class MainActivity extends AppCompatActivity implements
        DatePickerDialog.OnDateSetListener

After implements OnDateSetListener you will be notify to override this method below:

    @Override
    public void onDateSet(DatePickerDialog datePickerDialog, int year, int month, int day) {
        //When date is choosen
        Toast.makeText(MainActivity.this,"Year: " + year + " - Month: " + month + " - Day: " + day,
                1000).show();
    }

Now you are ready to go :) 

 

Step 5: Show TimePicker Dialog

TimePickerDialog timePickerDialog = TimePickerDialog.newInstance(this,10,20,true,false);
//Optional set vibrate
timePickerDialog.setVibrate(true);
//Optional 
timePickerDialog.setCloseOnSingleTapMinute(true);
//Optional
timePickerDialog.setStartTime(10,20);
timePickerDialog.show(getSupportFragmentManager(),TAG_TIME_PICKER_DIALOG);

 

Step 6: Register your Activity to implements TimePickerDialog.OnTimeSetListener

public class MainActivity extends AppCompatActivity implements TimePickerDialog.OnTimeSetListener{

After implements OnDateSetListener you will be notify to override this method below:

    @Override
    public void onTimeSet(RadialPickerLayout radialPickerLayout, int hour, int minutes) {
        //When time is choosen
        Toast.makeText(MainActivity.this,"Hour: " + hour + " - Min: " + minutes,1000).show();
    }

 

Discussion