Code Monkey home page Code Monkey logo

material-slide-date-picker's Introduction

Material Slide Date Picker

A slide date picker for Android.

alt text

Prerequisites

This library uses AndroidX library. If your project uses Android Support Library, consider migrating your project to AndroidX.

Installation

Add this to project level build.gradle

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

Add the dependency into you app level build.gradle

implementation 'com.github.niwattep:material-slide-date-picker:v2.0.0'  

Usage

Show Dialog

Slide Date Picker implements DialogFragment so that it will retain its state when configuration change happens. You can show the dialog by using supportFragmentManager of an activity (or childFragmentManager of a fragment).

SlideDatePickerDialog.newInstance().show(supportFragmentManager, "TAG")

You can show the dialog using its builder.

SlideDatePickerDialog.Builder().build().show(supportFragmentManager, "TAG")

Callback

Your activity or fragment must implement interface SlideDatePickerDialogCallback.

class MainActivity : AppCompatActivity(), SlideDatePickerDialogCallback {
    override fun onPositiveClick(day: Int, month: Int, year: Int, calendar: Calendar) {
        tvDate.text = SimpleDateFormat("EEEE, MMM dd, yyyy").format(calendar.time)
    }

Customization

SlideDatePickerDialog.Builder()
  .setStartDate(startCalendar)
  .setEndDate(endCaledar)
  .setPreselectedDate(todayCalendar)
  .setYearModifier(543)
  .setLocale(Locale("th"))
  .setThemeColor(Color.RED)
  .setHeaderTextColor(Color.WHITE)
  .setHeaderDateFormat("EEE dd MMMM")
  .setShowYear(true)
  .setCancelText("Cancel")
  .setConfirmText("Confirm")
  .build()
  .show(supportFragmentManager, "TAG")

There are 11 things you can customize:

  1. StartDate - Calendar object of minimum available date (default value is January 1st, current year - 100)
  2. EndDate - Calendar object of maximum available date (default value is Calendar.getInstance())
  3. PreselectedDate - Date that is selected when start the dialog (dafault value is Calendar.getInstance())
  4. YearModifier - When you want to show year in diffent format (default is 0)
  5. Locale - Locale for formatting date (default is Locale.US)
  6. ThemeColor - Color of dialog
  7. HeaderTextColor - Color of display date
  8. HeaderDateFormat - Format of display date
  9. ShowYear - Show or hide year of display date
  10. CancelText - String of cancel button
  11. ConfirmText - String of confirm button

Acknowledgment

This library is inspired by https://github.com/akexorcist/Android-SnapTimePicker

Donation

Give me a cup of coffee โ˜•

paypal

material-slide-date-picker's People

Contributors

niwattep avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.