Creating or editing a recurrence

maltaisn edited this page Jul 1, 2018 · 5 revisions

In case you want to set another default recurrence than "does not repeat" to the picker, it will be useful to know how to create one.

Creating a recurrence

  • new Recurrence(long startDate, int period)

    • startDate: date in milliseconds on which to start the recurrence
    • period: either Recurrence.NONE, DAILY, WEEKLY, MONTHLY or YEARLY The recurrence created has the default attribute, repeats forever with a frequency of one.
      If period is WEEKLY, recurrence will happen on the same day of the week as the start date.
      If period is MONTHLY, recurrence will happen on the same day of the month as the start date.
  • new Recurrence(Recurrence r): Creates a copy of recurrence r

  • new Recurrence(byte[] array, int index): Creates a recurrence from a byte array

    • array: byte array containing recurrence
    • index: recurrence object position in byte array

      You can use Recurrence.toByteArray() to generate the byte array. This is useful if you want to save the recurrence to a file.
  • Recurrence can also be created from a Parcel, for example with bundle.getParcelable(String key)

Editing a recurrence

Following methods can be used to edit a recurrence, but also set the settings on one you just created. Every method returns the recurrence so you can chain them: recurrence.setPeriod(Recurrence.DAILY).setFrequency(1).setEndNever()

  • setStartDate(long date)

    • date: date in milliseconds on which to start the recurrence

      If recurrence has the default attribute, some settings may change to keep it default. If period WEEKLY, the day of the week on which recurrence happens will change to the one of the start date. If period is MONTHLY and recurrence happens on the last day of the month but given start date isn't the last day of its month, monthly setting will change to SAME_DAY_OF_THE_MONTH.
  • setPeriod(int period)

    • period: either Recurrence.NONE, DAILY, WEEKLY, MONTHLY or YEARLY

      If new period is WEEKLY, recurrence will happen on the same day of the week as the start date.
      If new period is MONTHLY, recurrence will happen on the same day of the month as the start date.
      If new period is NONE, recurrence becomes "Does not repeat"
  • setFrequency(int freq)

    • freq: the recurrence frequency i.e. how many periods between two recurrences. Minimum is 1 for repeating every period.

      This method removes the default attribute
  • setWeeklySettings(int days)

    • days: days of the week on which weekly recurrence happens.

      The parameter is a bit field of Recurrence.SUNDAY to Recurrence.SATURDAY values. If parameter is 0 or 1 (no days), the recurrence will become "Does not repeat". If setting all days and frequency is 1, the recurrence becomes daily. So make sure to set frequency before weekly settings.
  • setMonthlySettings(int option)

    • option: when to repeat recurrence in the month, must be one of Recurrence.SAME_DAY_OF_MONTH, SAME_DAY_OF_WEEK or LAST_DAY_OF_MONTH.
  • setEndNever(): Set recurrence to never end.

  • setEndByDate(long date)

    • date: date in millis on which recurrence stops. Note that recurrence can happen on this day.
  • setEndByCount(int count)

    • count: the number of events after which to stop the recurrence
  • setDefault(boolean flag)

    • flag: true to add the default attribute, false to remove it.

      This method tries to set the default attribute. This attribute has no use outside the picker, it appears if the recurrence was created using the recurrence creator. To qualify for the attribute, the recurrence must never end and have a frequency of 1. If period is NONE, the recurrence is automatically default. If period is WEEKLY, it must repeat on one day of the week, the same as start date's. If period is MONTHLY, recurrence must repeat on the same day of the month as start date.

All these method also have getters.

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.