/** * 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 openOverflow() { Preconditions.checkState(mMainPanel != null); Preconditions.checkState(mOverflowPanel != null); mMainPanel.fadeOut(true); Size overflowPanelSize = mOverflowPanel.measure(); final int targetWidth = overflowPanelSize.getWidth(); final int targetHeight = overflowPanelSize.getHeight(); final boolean morphUpwards = (mOverflowDirection == OVERFLOW_DIRECTION_UP); final int startWidth = mContentContainer.getWidth(); final int startHeight = mContentContainer.getHeight(); final float startY = mContentContainer.getY(); final float right = mContentContainer.getX() + mContentContainer.getWidth(); 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 (morphUpwards) { float y = startY - (mContentContainer.getHeight() - startHeight); mContentContainer.setY(y); } } }; widthAnimation.setDuration(240); heightAnimation.setDuration(180); heightAnimation.setStartOffset(60); mOpenOverflowAnimation.getAnimations().clear(); mOpenOverflowAnimation.setAnimationListener(mOnOverflowOpened); mOpenOverflowAnimation.addAnimation(widthAnimation); mOpenOverflowAnimation.addAnimation(heightAnimation); mContentContainer.startAnimation(mOpenOverflowAnimation); }
/** * Returns how big this panel's view should be. This method should only be called when the view * has not been attached to a parent otherwise it will throw an illegal state. */ public Size measure() throws IllegalStateException { Preconditions.checkState(mContentView.getParent() == null); mContentView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); return new Size(mContentView.getMeasuredWidth(), mContentView.getMeasuredHeight()); }