Skip to content

3. ToroStrategy: the Judgement

Nam Nguyen Hoai edited this page Oct 23, 2016 · 2 revisions

TL,DR: Toro asks ToroStrategy to decide best player to start playing. Toro comes with 4 optimized built-in Strategies, but Clients can always implement their own.

Concept:

Toro helps user to decide when to start her Player by providing ToroStrategy. A ToroStrategy will decide whether it allows a Player to player or not (despite of the Player's will). Toro ask ToroStrategy if it allows a specific Player to play inside its parent View by calling ToroStrategy#allowsToPlay(Player player, ViewParent parent). Furthermore, when a parent View holds many playable Children (called Candidates), Toro asks ToroStrategy to call ToroStrategy#findBestPlayer(List<ToroPlayer>) to get the best one to start playing.

Built-in Strategies (see Toro$$Strategies)

  • MOST_VISIBLE_TOP_DOWN (This is Toro's default playback Strategy.): in the list of Candidates, this Strategy sort them in the increasing playback order (result from ToroPlayer#getPlayOrder()), and then ask for the most visible candidate (results of ToroPlayer#visibleAreaOffset) and select the first one, despite the current player is playing or not.

  • MOST_VISIBLE_TOP_DOWN_KEEP_LAST: same with MOST_VISIBLE_TOP_DOWN, but after finding the best candidate, if current Player is playing (ToroPlayer#isPlaying() returns true), this Strategy allow that player to keep playing, and ignore the selected one.

  • FIRST_PLAYABLE_TOP_DOWN: this Strategy scans through the list of candidates, sorted by their play order, then selects the first Playable candidate (as long as it wants to play, it is selected).

  • FIRST_PLAYABLE_TOP_DOWN_KEEP_LAST: the same result with FIRST_PLAYABLE_TOP_DOWN. But if current player is still playing, ignore the result and let the current player keeps playing.

Customise a Strategy

  • Simply implement ToroStrategy interface and provide expected result. Built-in strategies can be used as delegations.