Recurrence picker settings

maltaisn edited this page Mar 11, 2018 · 6 revisions

The recurrence picker have several options to customize its appearance and behaviour. The same options can be applied on both the dialog and the view because both classes implements RecurrencePickerSettings. Each method returns the instance of the dialog or view so the methods can be chained like this: picker.setRecurrence(r, date).setDateFormat(df1, df2).setMaxFrequency(70).

NOTE: setRecurrence should be called last, just before showing the dialog. If you are using the recurrence picker by itself, this also applies and you also have to set settings before showing the recurrence creator.

  • setDateFormat(@NonNull DateFormat endDateFormat, @NonNull DateFormat optionListDateFormat)

    • endDateFormat: date format used for showing end date in the recurrence creator. This one is usually shorter ex: 01-01-2018.
    • optionListDateFormat: date format used for showing end date in the option list. (first screen) This one is usually longer ex: Sun Jan 01, 2018.
  • setRecurrence(@Nullable Recurrence recurrence, long startDate): Initialize picker with a recurrence

    • recurrence: recurrence to display, use null for the default "does not repeat".
    • startDate: starting date of recurrence to be returned, use 0 for current date.
  • setMaxEventCount(int max): Set the maximum number of events

    • max: Maximum event count that can be set. Set -1 for no maximum (actual no maximum is RecurrencePickerView.MAX_FIELD_VALUE, or 999999999) Default value is 999.
  • setMaxFrequency(int max): Set the maximum frequency

    • max: Maximum frequency that can be set. Set -1 for no maximum (actual no maximum is RecurrencePickerView.MAX_FIELD_VALUE, or 999999999) Default value is 99.
  • setMaxEndDate(long time)

    • time: date in milliseconds, set to -1 for no maximum. Default is no maximum.
  • setDefaultEndDate(boolean usePeriod, int interval): Set the default end date

    • usePeriod: If true, will use the currently selected period as the unit of the interval ex: if repeating weekly and interval is 3, default end date will be 3 weeks after start date. If false, will use days as the unit of the interval. Default is true.
    • interval: How many periods/days after start date to set default end date. Default is 3.
  • setDefaultEndCount(int count): Set the number of events to show by default

    • count: Number of events to show by default. Default is 5 events.
  • setEnabledModes(boolean optionListEnabled, boolean creatorEnabled): Select which modes are enabled: default options list and recurrence creator. At least one of them has to be.

    • optionListEnabled: Whether to enable the default options list. Default is true.
    • creatorEnabled : Whether to enable the recurrence creator. Default is true.
  • setShowDoneButtonInOptionList(boolean show): Set whether to show the Done button in the first screen, the list of default recurrence options, or to hide it. If shown, listener won't be called when option is clicked, only when done button is.

    • show: Whether to show it or not. Default is false.
  • setShowHeaderInOptionList(boolean show): Set whether the header should be displayed in the first screen, the list of default recurrence options, or not. If you wish to also hide the header in the creator mode, you can change its background color.

    • show: Whether to show it or not. Default is true.
  • setShowCancelButton(boolean show): Set whether to show a cancel button or not. Cancel button is placed at the left side of the done button.

    • show: Whether to show it or not. Default is false.
  • setEnabledPeriods(int periods): Set which periods are available to be used. Note that NONE period cannot be disabled. You must set at least one period.

    • periods : bit field of 1 << [Recurrence.DAILY to Recurrence.YEARLY].
      Ex: periods = (1 << Recurrence.DAILY) | (1 << Recurrence.WEEKLY) (Don't forget the parentheses!)
      Another way would be to use binary literal ex: periods = 0b1111 (all periods)
  • setEnabledEndTypes(int types): Set which end types are available to be used. Note that END_BY_DATE_OR_COUNT is not implemented. You must set at least one type. If that's the case, end type spinner will be disabled. If the only end type set is forever, end type spinner completely disappears.

    • types: bit field of 1 << [Recurrence.END_NEVER, END_BY_DATE and END_BY_COUNT].
      Ex: periods = (1 << Recurrence.END_BY_DATE) | (1 << Recurrence.END_BY_COUNT) (Don't forget the parentheses!)
      Another way would be to use binary literal ex: periods = 0b111 (all types)
  • setOptionListDefaults(@Nullable Recurrence[] defaults, @Nullable CharSequence[] titles): Change defaults in option list. Note that "Does not repeat" will always be shown. By default, a daily, weekly, monthly and yearly recurrences with frequency of 1 are used. Set both parameters to null to use the default settings.

    • defaults: Array of recurrence to use as defaults, leave null to use default defaults. (that's right) You can set any start date for these recurrences before it gets overwritten by set start date.
    • titles: Array of strings to use for each recurrence, leave null to use Recurrence.format as a title instead. You can leave specific items in array null to only format those.

Here's an example of this method:

Recurrence[] defaults = new Recurrence[]{
		new Recurrence(0, Recurrence.DAILY).setFrequency(2),
		new Recurrence(0, Recurrence.WEEKLY).setWeeklySetting(0b10000010),  // Weekends
		new Recurrence(0, Recurrence.WEEKLY).setWeeklySetting(0b01111100),  // Weekdays
};
CharSequence[] titles = new CharSequence[]{
		"Every 2 days",
		"On weekends",
		"On weekdays",
};
picker.setOptionListDefaults(defaults, titles);

Screenshots

Result of the custom defaults example:
Custom defaults

Other settings:
Settings1 Settings2

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.