@Override
  public void setPanelState(PanelState toState, StateChangeReason reason) {
    // Store the previous state of the panel for when super changes it. 'super' should be the
    // first thing with significant logic that runs in this method which is why
    // onPanelStateChanged is not called here.
    PanelState fromState = getPanelState();
    super.setPanelState(toState, reason);

    mPanelMetrics.onPanelStateChanged(fromState, toState, reason);

    if (toState == PanelState.PEEKED
        && (fromState == PanelState.CLOSED || fromState == PanelState.UNDEFINED)) {
      // If the Peek Promo is visible, it should animate when the SearchBar peeks.
      if (getPeekPromoControl().isVisible()) {
        getPeekPromoControl().animateAppearance();
      }
    }

    if (fromState == PanelState.PEEKED
        && (toState == PanelState.EXPANDED || toState == PanelState.MAXIMIZED)) {
      // After opening the Panel to either expanded or maximized state,
      // the promo should disappear.
      getPeekPromoControl().hide();
    }
  }