Using the recurrence object

maltaisn edited this page Jul 1, 2018 · 6 revisions

After a recurrence is selected with the recurrence dialog or the view, you get a Recurrence object.

A few useful methods are provided with it:

  • boolean equals(Object obj): Test if a recurrence is equal to another. This compares every field and checks if start dates and end dates are on the same day (not same millis)

    • obj: recurrence to compare
  • boolean isRepeatedOnDaysOfWeek(int days): Check if the recurrence is repeated on a day of the week, if period is WEEKLY. You can also use getDaySetting() to get the bit field of all days, or the monthly option if period is MONTHLY.

    • days: bit field of Recurrence.SUNDAY to Recurrence.SATURDAY
  • List<Long> findRecurrences(long from, int amount): Get recurrence's of the recurrence.

    • from: date in milliseconds after which to get recurrence, set to -1 to get recurrences after starting date.
    • amount: maximum number of recurrences to get. There may be less depending on end type.
    • Returns an ArrayList of dates in milliseconds.
  • List<Long> findRecurrencesBasedOn(long base, int baseRepeats, long fromDate, int amount): Get recurrence's of the recurrence based on an already calculated recurrence. It is useful if you want to find the next recurrence when you already know one because it prevents useless iterations. Just make sure to use a correct recurrence as the base.

    • base: base recurrence date in milliseconds
    • baseRepeats: how many events had already happened when the base recurrence happened. If recurrence doesn't end after a number of events, you can set any value it doesn't matter.
    • fromDate: date in milliseconds after which to get recurrence, set to -1 to get any recurrence after base recurrence.
    • amount: maximum number of recurrences to get. There may be less depending on end type.
    • Returns an ArrayList of dates in milliseconds.

Here's an example of this last method:

Recurrence r = new Recurrence(System.currentTimeMillis(), Recurrence.DAILY).setEndByCount(1000);
List<Long> first900 = findRecurrences(-1, 900);  // Get first 900 recurrences

// Get 1000 more recurrences based on last one computed. Because we set baseRepeats 
// to 900, the method will only find 100 more events and not 1000.
List<Long> last = findRecurrencesBasedOn(first900.get(first900.size()-1), 900, -1, 1000);

Saving the recurrence

The Recurrence class implements Parcelable, allowing you to save it to a Bundle across configuration changes for example. Additionally, it is also possible to serialize it to a byte array and parse it back.

  • toByteArray(): serializes the recurrence to a byte[] of length Recurrence.BYTE_ARRAY_LENGTH;

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

    • array: byte array containing the recurrence.
    • index: index at which the recurrence starts in the byte array.

Editing a recurrence

If you wish to edit a recurrence, take a look at Creating or editing a recurrence.

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.