/** Places the main view panel at the appropriate resting coordinates. */
    private void positionMainPanel() {
      Preconditions.checkNotNull(mMainPanel);
      float x =
          mPopupWindow.getWidth() - (mMainPanel.getView().getMeasuredWidth() + mMarginHorizontal);
      mContentContainer.setX(x);

      float y = mMarginVertical;
      if (mOverflowDirection == OVERFLOW_DIRECTION_UP) {
        y = getHeight() - (mMainPanel.getView().getMeasuredHeight() + mMarginVertical);
      }
      mContentContainer.setY(y);
      setContentAreaAsTouchableSurface();
    }
 /** Sets the current content to be the main view panel. */
 private void setMainPanelAsContent() {
   // This should never be called if the main panel has not been initialized.
   Preconditions.checkNotNull(mMainPanel);
   mContentContainer.removeAllViews();
   Size mainPanelSize = mMainPanel.measure();
   ViewGroup.LayoutParams params = mContentContainer.getLayoutParams();
   params.width = mainPanelSize.getWidth();
   params.height = mainPanelSize.getHeight();
   mContentContainer.setLayoutParams(params);
   mContentContainer.addView(mMainPanel.getView());
   setContentAreaAsTouchableSurface();
 }
    /** Prepares the content container for show and update calls. */
    private void preparePopupContent() {
      // Reset visibility.
      if (mMainPanel != null) {
        mMainPanel.fadeIn(false);
      }
      if (mOverflowPanel != null) {
        mOverflowPanel.fadeIn(false);
      }

      // Reset position.
      if (mMainPanel != null && mContentContainer.getChildAt(0) == mMainPanel.getView()) {
        positionMainPanel();
      }
      if (mOverflowPanel != null && mContentContainer.getChildAt(0) == mOverflowPanel.getView()) {
        positionOverflowPanel();
      }
    }