/** 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();
 }
 private void updatePopupSize() {
   int width = 0;
   int height = 0;
   if (mMainPanel != null) {
     Size mainPanelSize = mMainPanel.measure();
     width = mainPanelSize.getWidth();
     height = mainPanelSize.getHeight();
   }
   if (mOverflowPanel != null) {
     Size overflowPanelSize = mOverflowPanel.measure();
     width = Math.max(width, overflowPanelSize.getWidth());
     height = Math.max(height, overflowPanelSize.getHeight());
   }
   mPopupWindow.setWidth(width + mMarginHorizontal * 2);
   mPopupWindow.setHeight(height + mMarginVertical * 2);
 }
    /**
     * Opens the floating toolbar overflow. This method should not be called if menu items have not
     * been laid out with {@link #layoutMenuItems(java.util.List, MenuItem.OnMenuItemClickListener,
     * int)}.
     *
     * @throws IllegalStateException if called when menu items have not been laid out.
     */
    private void closeOverflow() {
      Preconditions.checkState(mMainPanel != null);
      Preconditions.checkState(mOverflowPanel != null);

      mOverflowPanel.fadeOut(true);
      Size mainPanelSize = mMainPanel.measure();
      final int targetWidth = mainPanelSize.getWidth();
      final int targetHeight = mainPanelSize.getHeight();
      final int startWidth = mContentContainer.getWidth();
      final int startHeight = mContentContainer.getHeight();
      final float right = mContentContainer.getX() + mContentContainer.getWidth();
      final float bottom = mContentContainer.getY() + mContentContainer.getHeight();
      final boolean morphedUpwards = (mOverflowDirection == OVERFLOW_DIRECTION_UP);
      Animation widthAnimation =
          new Animation() {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {
              ViewGroup.LayoutParams params = mContentContainer.getLayoutParams();
              int deltaWidth = (int) (interpolatedTime * (targetWidth - startWidth));
              params.width = startWidth + deltaWidth;
              mContentContainer.setLayoutParams(params);
              mContentContainer.setX(right - mContentContainer.getWidth());
            }
          };
      Animation heightAnimation =
          new Animation() {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {
              ViewGroup.LayoutParams params = mContentContainer.getLayoutParams();
              int deltaHeight = (int) (interpolatedTime * (targetHeight - startHeight));
              params.height = startHeight + deltaHeight;
              mContentContainer.setLayoutParams(params);
              if (morphedUpwards) {
                mContentContainer.setY(bottom - mContentContainer.getHeight());
              }
            }
          };
      widthAnimation.setDuration(150);
      widthAnimation.setStartOffset(150);
      heightAnimation.setDuration(210);
      mCloseOverflowAnimation.getAnimations().clear();
      mCloseOverflowAnimation.setAnimationListener(mOnOverflowClosed);
      mCloseOverflowAnimation.addAnimation(widthAnimation);
      mCloseOverflowAnimation.addAnimation(heightAnimation);
      mContentContainer.startAnimation(mCloseOverflowAnimation);
    }