Git Product home page Git Product logo

rangedatepicker's Introduction

CPicker (Calendar Picker)

๐Ÿ“† A simple vertical date picker for Android, written in kotlin ๐Ÿ‡ฎ๐Ÿ‡ฉ

Android Arsenal Download

Screenshoot

ย ย 

Installation

Gradle

repositories {
    jcenter()
}

dependencies {
    implementation 'com.andrewjapar.rangedatepicker:rangedatepicker:0.3'
}

Usage

1. Add CalendarPicker to your XML file

<com.andrewjapar.rangedatepicker.CalendarPicker
      android:id="@+id/calendar_view"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:clipToPadding="false"
      android:scrollbarStyle="outsideOverlay"
      app:picker_type="range" />

2. You can customize the picker range (by default current date + 1 year)

val startDate = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault())
val endDate = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault())
endDate.add(Calendar.MONTH, 6) // Add 6 months ahead from current date
 
calendar_view.apply {
  showDayOfWeekTitle(false) // If you want to disable day of the week title, just make it false
  setMode(SelectionMode.RANGE) // You can set it via XML
  setRangeDate(startDate.time, endDate.time)
  setSelectionDate(startDate.time, endDate.time)
}

3. Don't forget to set the listener to get range selection date

// Set listener first before set the selection to ensure we can track changed date range
// This will be called when range is selected
calendar_view.setOnRangeSelectedListener { startDate, endDate, startLabel, endLabel ->
    departure_date.text = startLabel
    return_date.text = endLabel
}

// This will be called when only single day is selected for both SINGLE and RANGE type
calendar_view.setOnStartSelectedListener { startDate, label ->
    departure_date.text = label
    return_date.text = "-"
}

4. But wait, there is more! If you want to custom text color and background, just override it on your colors.xml file

<!--Background color-->
<color name="calendar_picker_bg">#00FFFFFF</color>

<color name="calendar_day_unselected_bg">#00000000</color>
<color name="calendar_day_selected_bg">#E91E63</color>
<color name="calendar_day_range_selected_bg">#8CE91E63</color>

<!--Font color-->
<color name="calendar_day_disabled_font">#8CE91E63</color>
<color name="calendar_day_weekend_font">#ff0000</color>
<color name="calendar_day_selected_font">#FFFFFF</color>
<color name="calendar_day_normal_font">#333333</color>

<color name="calendar_month_font">#000000</color>
<color name="calendar_week_font">#333333</color>

5. You also can override the value of dimens.xml

<dimen name="calendar_day_height">36dp</dimen>
<dimen name="calendar_day_gap">8dp</dimen>
<dimen name="calendar_day_textsize">12sp</dimen>

<dimen name="calendar_month_padding">16dp</dimen>
<dimen name="calendar_month_textsize">16sp</dimen>

<dimen name="calendar_week_textsize">12sp</dimen>

Future Plan

  1. Support Horizontal View like Traveloka, Expedia, Airbnb, etc
  2. Change font color when the day is weekend
  3. Add a marker on some dates (e.g for public holidays)
  4. Render optimization
  5. Please let me know, if you have any other ideas

Contributing

Currently, CPicker is used only on my personal project but if you have any idea to make it more powerfull, just make a pull request, You are in!

License

    MIT License
    
    Copyright (c) 2020 andrewjapar
    
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publiAsh, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:
    
    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.

rangedatepicker's People

Contributors

andrewjapar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

rangedatepicker's Issues

getDisplayName(MONTH, style, locale) will generate IllegalArgumentException in Android versions below 7.1.2

getDisplayName(MONTH, style, locale) will generate IllegalArgumentException in Android versions below 7.1.2

Caused by: java.lang.IllegalArgumentException
at java.util.Calendar.checkDisplayNameParams(Calendar.java:1501)
at java.util.Calendar.getDisplayName(Calendar.java:1395)
at com.andrewjapar.rangedatepicker.CalendarUtilsKt.toPrettyMonthString(CalendarUtils.kt:33)
at com.andrewjapar.rangedatepicker.CalendarUtilsKt.toPrettyMonthString$default(CalendarUtils.kt:31)
at com.andrewjapar.rangedatepicker.CalendarPicker.buildCalendarData(CalendarPicker.kt:236)
at com.andrewjapar.rangedatepicker.CalendarPicker.refreshData(CalendarPicker.kt:182)
at com.andrewjapar.rangedatepicker.CalendarPicker.setRangeDate(CalendarPicker.kt:110)

Change month title and day of week display

Can display everything uppercase, lowercase or Camel Case.

For example: I want you to display the name of the month, like this: APRIL. And the day of the week like this: tue.

And to be possible to change te position of the month, be center, or on left, or on right...

Have some bugs with date displaying

I init calendar like this:

val startDate = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault())
        startDate.set(2019, 9, 1)
        val endDate = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault()) // Today is 24.01.2020. Truly, does not matter which date I set

        calendar_view.apply {
            setMode(CalendarPicker.SelectionMode.RANGE) // You can set it via XML
            setRangeDate(startDate.time, endDate.time)
        }

And my phone display calendar like this:
photo_2020-01-24_10-34-23
Xiaomi mi6, Android 9

Same day

Cannot select the same day in range mode

MIT or Apache or Mixed?

Hi Andrew,

I can see you have distributed this awesome library under MIT in GitHub. But the files in the library are using a Apache 2 License copyright header. Can you please fix this or add some info about this is the doc.

Thanks

Is it possible to customize calendar from xml?

It would be very conveniently to customize calendar_picker_bg and other colors from xml. Also i caught a problem to customize calendar for 2 different themes(for example, light and dark themes). Is it possible to set colors from attributes? I've got crash on setting resource like this:
<color name="calendar_picker_bg">?attr/colorPrimary</color>

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.