Package com.castlabs.android.player

# Class VisualComponentProxy

java.lang.Object
com.castlabs.android.player.VisualComponentProxy

All Implemented Interfaces:
  `PlayerControllerPlugin.Component`, `PlayerControllerPlugin.ComponentViewListener`, `PlayerControllerPlugin.VisualComponent`

Direct Known Subclasses:
  `ExoSubtitlesRendererPlugin.ExoSubtitleComponent`

public abstract class VisualComponentProxy extends Object implements PlayerControllerPlugin.VisualComponent
VisualComponent whose task is to communicate a `PlayerControllerPlugin.ComponentViewListener` with the `PlayerControllerPlugin.Component` machinery.

Here we forward the events to a PlayerControllerPlugin.ComponentViewListener. Thus giving it a chance to update its inner `View`.

We also take care of async calls. For instance, the SubtitlesTrackRenderer will set the `listener` in its createRenderer() call. This is too late, for instance in the case where the client code uses `PlayerController.scanComponentViews(ViewGroup)`. In this case, we would be called `scanComponentViews(ViewGroup)` before having a `componentsViewListener`.

That's why we save the ViewGroup and forward the pending call to the `listener` as soon as it is set.

Users of this Class should implement the `PlayerControllerPlugin.Component.id()` method returning the concrete Class's class. This is why you should *not* create anonymous concrete Classes.

Since:
  4.2.2

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `VisualComponentProxy()`
  Default constructor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `onComponentViewsChanged(PlayerController playerController)`
  Called whenever the list of ComponentViews in the `PlayerController` has changed.
  `void`
  `onDestroy(PlayerController playerController)`
  Called when the controller is destroyed.
  `void`
  `onOpenBundle(PlayerController playerController, Bundle bundle)`
  Called when the player controller is opened with a bundle.
  `void`
  `onOpenState(PlayerController playerController, PlayerConfig playerConfig)`
  Called when the player controller is opened with a config.
  `Collection<Pair<Integer,View>>`
  `scanComponentViews(ViewGroup container)`
  Implementors should scan for the "desired" Views.
  `void`
  `setComponentViewListener(PlayerControllerPlugin.ComponentViewListener componentsViewListener)`
  Sets the Listener.

  ### Methods inherited from class java.lang.Object

  `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface com.castlabs.android.player.PlayerControllerPlugin.Component

  `id`

- ## Constructor Details

  - ### VisualComponentProxy

    public VisualComponentProxy()
    Default constructor.

- ## Method Details

  - ### onDestroy

    public void onDestroy(@NonNull PlayerController playerController)
    Description copied from interface: `PlayerControllerPlugin.Component`
    Called when the controller is destroyed. Implementation must use this to unregister any listeners that were attached to the controller before.
    Specified by:
      `onDestroy` in interface `PlayerControllerPlugin.Component`
    Parameters:
      `playerController` - The player controller

  - ### onOpenBundle

    public void onOpenBundle(@NonNull PlayerController playerController, @NonNull Bundle bundle)
    Description copied from interface: `PlayerControllerPlugin.Component`
    Called when the player controller is opened with a bundle. Implementations can use this to extract or modify bundle data.
    Specified by:
      `onOpenBundle` in interface `PlayerControllerPlugin.Component`
    Parameters:
      `playerController` - The player controller
      `bundle` - The bundle

  - ### onOpenState

    public void onOpenState(PlayerController playerController, PlayerConfig playerConfig)
    Description copied from interface: `PlayerControllerPlugin.Component`
    Called when the player controller is opened with a config. Implementations can use this to extract or modify config data.
    Specified by:
      `onOpenState` in interface `PlayerControllerPlugin.Component`
    Parameters:
      `playerController` - The player controller
      `playerConfig` - The playback state

  - ### onComponentViewsChanged

    public void onComponentViewsChanged(@NonNull PlayerController playerController)
    Description copied from interface: `PlayerControllerPlugin.ComponentViewListener`
    Called whenever the list of ComponentViews in the `PlayerController` has changed. This is whenever a View is added, or removed. Implementors should use this callback to detach from an old View (if any) and attach to the new one (if any). It is possible that there's actually no change affecting one particular ComponentViewListener. In this case the callback should just be ignored.
    Specified by:
      `onComponentViewsChanged` in interface `PlayerControllerPlugin.ComponentViewListener`
    Parameters:
      `playerController` - the PlayerController firing this event.

  - ### scanComponentViews

    public Collection<Pair<Integer,View>> scanComponentViews(@NonNull ViewGroup container)
    Description copied from interface: `PlayerControllerPlugin.ComponentViewListener`
    Implementors should scan for the "desired" Views. The Views could be at any hierarchy level, so the use of `View.findViewById(int)` is encouraged. You *should not* hold a reference to the found Views.
    Specified by:
      `scanComponentViews` in interface `PlayerControllerPlugin.ComponentViewListener`
    Parameters:
      `container` - the ViewGroup where there specific Views should be looked for.
    Returns:
      a Collection of the found Views in the container

  - ### setComponentViewListener

    public void setComponentViewListener(PlayerControllerPlugin.ComponentViewListener componentsViewListener)
    Sets the Listener.

    Will be immediately called if there's a pending `scanComponentViews(ViewGroup)` call.

    Parameters:
      `componentsViewListener` - the listener to set