SublimePicker Documentation

repository·master·Indexed 25 days ago

https://github.com/vikramkakkar/sublimepicker

A customizable Android library providing a unified interface for selecting dates, times, and recurrence options. It features material-styled pickers backported to API 14, supports single or date-range selection via DayPickerView, and includes a RecurrencePicker with a RecurrenceOptionCreator for granular rules.

Tokens
1.1K
Snippets
1
Records
9
Agent score
31%

What's inside SublimePicker

  1. Overview of SublimePicker components

    master

    SublimePicker is a unified user interface that provides access to three distinct pickers. All components are implemented as Android Views, meaning they can be embedded in a Dialog, a PopupWindow, or used as standard widgets in your layout.

    • DatePicker: Selects a single date or a date range (via SublimeOptions#setCanPickDateRange).
    • TimePicker: Accessible via a button in the bottom-left corner of the DatePicker.
    • RecurrencePicker: Accessible via an overflow button in the top-right corner. It allows users to define how often an event repeats.
    • RecurrenceOptionCreator: Triggered when selecting 'Custom...' from the RecurrencePicker, allowing for more granular recurrence rules (e.g., 'Until a date').
  2. Enable date-range selection in SublimePicker

    master

    By default, SublimePicker performs single date selection. To enable date-range selection, use the setCanPickDateRange(boolean) method on a SublimeOptions object.

    When enabled, users can select a range using a single fluent gesture: long-press on the intended start-date and drag to the intended end-date. Dragging near the edges of the picker will scroll through months.

  3. Configure DayPickerView via XML attributes

    master

    When using DayPickerView in your Android layout XML, you can customize its appearance using the following attributes:

    • spMonthTextAppearance: A text appearance resource for the month label.
    • spWeekDayTextAppearance: A text appearance resource for the days of the week.
    • spDateTextAppearance: A text appearance resource for the individual day numbers.
    • spDaySelectorColor: A ColorStateList defining the color used when a day is selected.
  4. Configure DayPickerView appearance and behavior

    master

    The DayPickerView provides several methods to customize its internal adapter and behavior:

    • setCanPickRange(boolean canPickRange): Enables or disables the ability to select a range of dates.
    • setFirstDayOfWeek(int firstDayOfWeek): Sets which day of the week is considered the first day (e.g., Sunday).
    • getFirstDayOfWeek(): Returns the current first day of the week.
    • setDayOfWeekTextAppearance(int resId): Sets the text appearance for the day-of-week labels.
    • getDayOfWeekTextAppearance(): Returns the current day-of-week text appearance.
    • setDayTextAppearance(int resId): Sets the text appearance for the day numbers.
    • getDayTextAppearance(): Returns the current day text appearance.
  5. Configure date constraints (Min/Max Date) in DayPickerView

    master

    You can restrict the range of dates a user can select by setting minimum and maximum allowed timestamps.

    • setMinDate(long timeInMillis): Sets the earliest selectable date.
    • setMaxDate(long timeInMillis): Sets the latest selectable date.
    • getMinDate(): Returns the current minimum date in milliseconds.
    • getMaxDate(): Returns the current maximum date in milliseconds.
  6. Get the current state of DayPickerView

    master

    Use these methods to retrieve the current selection or view state:

    • getDate(): Returns the currently SelectedDate.
    • getMostVisiblePosition(): Returns the index of the month currently most prominently displayed in the view.
    • getPosition(int position): (Internal/Indirect) The view uses a ViewPager to manage month positions.
  7. Handle date selection events with ProxyDaySelectionEventListener

    master

    To respond to user interactions in the DayPickerView, implement the ProxyDaySelectionEventListener interface and register it using setProxyDaySelectionEventListener(ProxyDaySelectionEventListener listener). This listener provides callbacks for both single date selection and date range selection.

    Methods available in ProxyDaySelectionEventListener:

    • onDaySelected(DayPickerView view, Calendar day): Called when a single day is selected.
    • onDateRangeSelectionStarted(@NonNull SelectedDate selectedDate): Called when the user begins selecting a range.
    • onDateRangeSelectionEnded(@Nullable SelectedDate selectedDate): Called when the user finishes selecting a range.
    • onDateRangeSelectionUpdated(@NonNull SelectedDate selectedDate): Called as the user updates the range during selection.
  8. Set the selected date in DayPickerView

    master

    You can programmatically set the currently selected date in the DayPickerView. You can choose whether to jump immediately or animate the transition to the new date.

    Use the following methods:

    • setDate(SelectedDate date): Jumps immediately to the new date.
    • setDate(SelectedDate date, boolean animate): Optionally animates the transition.
    • setDate(SelectedDate date, boolean animate, boolean goToPosition): Controls both animation and whether the view scrolls to the position of the new date.