TilesTimelineCache


public final class TilesTimelineCache


Timeline cache for Wear Tiles. This will take in a full timeline, and return the appropriate entry for the given time from findTimelineEntryForTime.

Summary

Public constructors

Default constructor.

This method is deprecated.

Use TilesTimelineCache instead.

Public methods

@Nullable TimelineBuilders.TimelineEntry

A (very) inexact version of findTimelineEntryForTime which finds the closest timeline entry to the current time, regardless of validity.

@Nullable TimelineBuilders.TimelineEntry

This method is deprecated.

Use findClosestTileTimelineEntry instead.

long

Finds when the timeline entry entry should be considered "expired".

long

This method is deprecated.

Use findCurrentTimelineEntryExpiry instead.

@Nullable TimelineBuilders.TimelineEntry

Finds the entry which should be active at the given time.

@Nullable TimelineBuilders.TimelineEntry

This method is deprecated.

Use findTileTimelineEntryForTime instead.

Public constructors

TilesTimelineCache

Added in 1.2.0
public TilesTimelineCache(@NonNull TimelineBuilders.Timeline timeline)

Default constructor.

TilesTimelineCache

Added in 1.0.0
Deprecated in 1.2.0
public TilesTimelineCache(@NonNull TimelineBuilders.Timeline timeline)

Default constructor.

Public methods

findClosestTileTimelineEntry

Added in 1.2.0
@MainThread
public @Nullable TimelineBuilders.TimelineEntry findClosestTileTimelineEntry(long timeMillis)

A (very) inexact version of findTimelineEntryForTime which finds the closest timeline entry to the current time, regardless of validity. This should only used as a fallback if findTimelineEntryForTime fails, so it can attempt to at least show something.

By this point, we're technically in an error state, so just show _something_. Note that calling this if findTimelineEntryForTime returns a valid entry is invalid, and may lead to incorrect results.

Parameters
long timeMillis

The time to search from, in milliseconds.

Returns
@Nullable TimelineBuilders.TimelineEntry

The timeline entry with validity period closest to timeMillis.

findClosestTimelineEntry

Added in 1.0.0
Deprecated in 1.2.0
@MainThread
public @Nullable TimelineBuilders.TimelineEntry findClosestTimelineEntry(long timeMillis)

A (very) inexact version of findTimelineEntryForTime which finds the closest timeline entry to the current time, regardless of validity. This should only used as a fallback if findTimelineEntryForTime fails, so it can attempt to at least show something.

By this point, we're technically in an error state, so just show _something_. Note that calling this if findTimelineEntryForTime returns a valid entry is invalid, and may lead to incorrect results.

Parameters
long timeMillis

The time to search from, in milliseconds.

Returns
@Nullable TimelineBuilders.TimelineEntry

The timeline entry with validity period closest to timeMillis.

findCurrentTimelineEntryExpiry

Added in 1.2.0
@MainThread
public long findCurrentTimelineEntryExpiry(
    @NonNull TimelineBuilders.TimelineEntry entry,
    long fromTimeMillis
)

Finds when the timeline entry entry should be considered "expired". This is either when it is no longer valid (i.e. end_millis), or when another entry should be presented instead.

Parameters
@NonNull TimelineBuilders.TimelineEntry entry

The entry to find the expiry time of.

long fromTimeMillis

The time to start searching from. The returned time will never be lower than the value passed here.

Returns
long

The time in millis that entry should be considered to be expired. This value will be MAX_VALUE if entry does not expire.

findCurrentTimelineEntryExpiry

Added in 1.0.0
Deprecated in 1.2.0
@MainThread
public long findCurrentTimelineEntryExpiry(
    @NonNull TimelineBuilders.TimelineEntry entry,
    long fromTimeMillis
)

Finds when the timeline entry entry should be considered "expired". This is either when it is no longer valid (i.e. end_millis), or when another entry should be presented instead.

Parameters
@NonNull TimelineBuilders.TimelineEntry entry

The entry to find the expiry time of.

long fromTimeMillis

The time to start searching from. The returned time will never be lower than the value passed here.

Returns
long

The time in millis that entry should be considered to be expired. This value will be MAX_VALUE if entry does not expire.

findTileTimelineEntryForTime

Added in 1.2.0
@MainThread
public @Nullable TimelineBuilders.TimelineEntry findTileTimelineEntryForTime(long timeMillis)

Finds the entry which should be active at the given time. This will return the entry which has the _shortest_ validity period at the current time, if validity periods overlap. Note that an entry which has no validity period set will be considered a "default" and will be used if no other entries are suitable.

Parameters
long timeMillis

The time to base the search on, in milliseconds.

Returns
@Nullable TimelineBuilders.TimelineEntry

The timeline entry which should be active at the given time. Returns null if none are valid.

findTimelineEntryForTime

Added in 1.0.0
Deprecated in 1.2.0
@MainThread
public @Nullable TimelineBuilders.TimelineEntry findTimelineEntryForTime(long timeMillis)

Finds the entry which should be active at the given time. This will return the entry which has the _shortest_ validity period at the current time, if validity periods overlap. Note that an entry which has no validity period set will be considered a "default" and will be used if no other entries are suitable.

Parameters
long timeMillis

The time to base the search on, in milliseconds.

Returns
@Nullable TimelineBuilders.TimelineEntry

The timeline entry which should be active at the given time. Returns null if none are valid.