toro-core/src/main/java/im/ene/toro/widget/Container.java
private void dispatchWindowVisibilityMayChange() {
    if (screenState == SCREEN_STATE_OFF) {
      List<ToroPlayer> players = playerManager.getPlayers();
      for (ToroPlayer player : players) {
        if (player.isPlaying()) {
          this.savePlaybackInfo(player.getPlayerOrder(), player.getCurrentPlaybackInfo());
          playerManager.pause(player);
        }
      }
    } else if (screenState == SCREEN_STATE_ON
        // Container has focus in current Window
        && hasFocus()
        // In fact, Android 24+ supports multi-window mode in which visible Window may not have focus.
        // In that case, other triggers will supposed to be called and we are safe here.
        // Need further investigation if need.
        && hasWindowFocus()) {
      // tmpStates may be consumed already, if there is a good reason for that, so no big deal.
      if (tmpStates != null && tmpStates.size() > 0) {
        for (int i = 0; i < tmpStates.size(); i++) {
          int order = tmpStates.keyAt(i);
          PlaybackInfo playbackInfo = tmpStates.get(order);
          this.savePlaybackInfo(order, playbackInfo);
        }
      }
      tmpStates = null;
      this.onScrollStateChanged(SCROLL_STATE_IDLE);
    }
  }
/**
   * Called when:
   * - Screen state changed.
   * or - Window focus changed.
   * or - Window visibility changed.
   *
   * For each of that change, Screen may be turned off or Window's focused state may change, this
   * is to decide if Container should keep current playback state or change it.
   *
   * <strong>Discussion</strong>: In fact, we expect that: Container will be playing if the
   * following conditions are all satisfied:
   * - Current window is visible. (but not necessarily focused).
   * - Container is visible in Window (partly is fine, we care about the Media player).
   * - Container is focused in Window. (so we don't screw up other component's focus).
   *
   * In lower API (eg: 16), {@link #getWindowVisibility()} always returns {@link #VISIBLE}, which
   * cannot tell much. We need to investigate this flag in various APIs in various Scenarios.
   */
Called when:
- Screen state changed.
or - Window focus changed.
or - Window visibility changed.

For each of that change, Screen may be turned off or Window's focused state may change, this
is to decide if Container should keep current playback state or change it.

Discussion: In fact, we expect that: Container will be playing if the
following conditions are all satisfied:
- Current window is visible. (but not necessarily focused).
- Container is visible in Window (partly is fine, we care about the Media player).
- Container is focused in Window. (so we don't screw up other component's focus).

In lower API ,  #getWindowVisibility() always returns  #VISIBLE, which
cannot tell much. We need to investigate this flag in various APIs in various Scenarios.
Called when : - Screen state changed . or - Window focus changed . or - Window visibility changed . For each of that change Screen may be turned off or Window ' s focused state may change this is to decide if Container should keep current playback state or change it . Discussion : In fact we expect that : Container will be playing if the following conditions are all satisfied : - Current window is visible . ( but not necessarily focused ) . - Container is visible in Window ( partly is fine we care about the Media player ) . - Container is focused in Window . ( so we don ' t screw up other component ' s focus ) . In lower API #getWindowVisibility () always returns #VISIBLE which cannot tell much . We need to investigate this flag in various APIs in various Scenarios .
private void dispatchWindowVisibilityMayChange() {
    if (screenState == SCREEN_STATE_OFF) {
      List<ToroPlayer> players = playerManager.getPlayers();
      for (ToroPlayer player : players) {
        if (player.isPlaying()) {
          this.savePlaybackInfo(player.getPlayerOrder(), player.getCurrentPlaybackInfo());
          playerManager.pause(player);
        }
      }
    } else if (screenState == SCREEN_STATE_ON
        && hasFocus()
        && hasWindowFocus()) {
      if (tmpStates != null && tmpStates.size() > 0) {
        for (int i = 0; i < tmpStates.size(); i++) {
          int order = tmpStates.keyAt(i);
          PlaybackInfo playbackInfo = tmpStates.get(order);
          this.savePlaybackInfo(order, playbackInfo);
        }
      }
      tmpStates = null;
      this.onScrollStateChanged(SCROLL_STATE_IDLE);
    }
  }
private void dispatchWindowVisibilityMayChange ( ) { if ( screenState == SCREEN_STATE_OFF ) { List < ToroPlayer > players = playerManager . getPlayers ( ) ; for ( ToroPlayer player : players ) { if ( player . isPlaying ( ) ) { this . savePlaybackInfo ( player . getPlayerOrder ( ) , player . getCurrentPlaybackInfo ( ) ) ; playerManager . pause ( player ) ; } } } else if ( screenState == SCREEN_STATE_ON && hasFocus ( ) && hasWindowFocus ( ) ) { if ( tmpStates != null && tmpStates . size ( ) > 0 ) { for ( int i = 0 ; i < tmpStates . size ( ) ; i ++ ) { int order = tmpStates . keyAt ( i ) ; PlaybackInfo playbackInfo = tmpStates . get ( order ) ; this . savePlaybackInfo ( order , playbackInfo ) ; } } tmpStates = null ; this . onScrollStateChanged ( SCROLL_STATE_IDLE ) ; } }
Called when:
 - Screen state changed.
Called when : - Screen state changed .
// Container has focus in current Window // In fact, Android 24+ supports multi-window mode in which visible Window may not have focus. // In that case, other triggers will supposed to be called and we are safe here. // Need further investigation if need. // tmpStates may be consumed already, if there is a good reason for that, so no big deal.