private ViewFader(View view) {
   mView = Preconditions.checkNotNull(view);
   mFadeOutAnimation =
       ObjectAnimator.ofFloat(view, View.ALPHA, 1, 0).setDuration(FADE_OUT_DURATION);
   mFadeInAnimation =
       ObjectAnimator.ofFloat(view, View.ALPHA, 0, 1).setDuration(FADE_IN_DURATION);
 }
 /**
  * Initializes a new floating toolbar popup.
  *
  * @param parent A parent view to get the {@link android.view.View#getWindowToken()} token from.
  */
 public FloatingToolbarPopup(View parent) {
   mParent = Preconditions.checkNotNull(parent);
   mContentContainer = createContentContainer(parent.getContext());
   mPopupWindow = createPopupWindow(mContentContainer);
   mShowAnimation = createGrowFadeInFromBottom(mContentContainer);
   mDismissAnimation =
       createShrinkFadeOutFromBottomAnimation(
           mContentContainer,
           new AnimatorListenerAdapter() {
             @Override
             public void onAnimationEnd(Animator animation) {
               mPopupWindow.dismiss();
               mContentContainer.removeAllViews();
             }
           });
   mHideAnimation =
       createShrinkFadeOutFromBottomAnimation(
           mContentContainer,
           new AnimatorListenerAdapter() {
             @Override
             public void onAnimationEnd(Animator animation) {
               mPopupWindow.dismiss();
             }
           });
   mMarginHorizontal =
       parent.getResources().getDimensionPixelSize(R.dimen.floating_toolbar_horizontal_margin);
   mMarginVertical =
       parent.getResources().getDimensionPixelSize(R.dimen.floating_toolbar_vertical_margin);
 }
  private PrintJobInfo(@NonNull Parcel parcel) {
    mId = parcel.readParcelable(null);
    mLabel = parcel.readString();
    mPrinterId = parcel.readParcelable(null);
    mPrinterName = parcel.readString();
    mState = parcel.readInt();
    mAppId = parcel.readInt();
    mTag = parcel.readString();
    mCreationTime = parcel.readLong();
    mCopies = parcel.readInt();
    Parcelable[] parcelables = parcel.readParcelableArray(null);
    if (parcelables != null) {
      mPageRanges = new PageRange[parcelables.length];
      for (int i = 0; i < parcelables.length; i++) {
        mPageRanges[i] = (PageRange) parcelables[i];
      }
    }
    mAttributes = (PrintAttributes) parcel.readParcelable(null);
    mDocumentInfo = (PrintDocumentInfo) parcel.readParcelable(null);
    mProgress = parcel.readFloat();
    mStatus = parcel.readCharSequence();
    mStatusRes = parcel.readInt();
    mStatusResAppPackageName = parcel.readCharSequence();
    mCanceling = (parcel.readInt() == 1);
    mAdvancedOptions = parcel.readBundle();

    if (mAdvancedOptions != null) {
      Preconditions.checkArgument(!mAdvancedOptions.containsKey(null));
    }
  }
    /**
     * 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);
    }
    /**
     * Puts an advanced (printer specific) option.
     *
     * @param key The option key.
     * @param value The option value.
     */
    public void putAdvancedOption(@NonNull String key, @Nullable String value) {
      Preconditions.checkNotNull(key, "key cannot be null");

      if (mPrototype.mAdvancedOptions == null) {
        mPrototype.mAdvancedOptions = new Bundle();
      }
      mPrototype.mAdvancedOptions.putString(key, value);
    }
 /** Places the main view panel at the appropriate resting coordinates. */
 private void positionOverflowPanel() {
   Preconditions.checkNotNull(mOverflowPanel);
   float x =
       mPopupWindow.getWidth()
           - (mOverflowPanel.getView().getMeasuredWidth() + mMarginHorizontal);
   mContentContainer.setX(x);
   mContentContainer.setY(mMarginVertical);
   setContentAreaAsTouchableSurface();
 }
 private int setOverflowWidth() {
   for (int i = 0; i < mListView.getAdapter().getCount(); i++) {
     MenuItem menuItem = (MenuItem) mListView.getAdapter().getItem(i);
     Preconditions.checkNotNull(menuItem);
     mListViewItemWidthCalculator.setText(menuItem.getTitle());
     mListViewItemWidthCalculator.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
     mOverflowWidth = Math.max(mListViewItemWidthCalculator.getMeasuredWidth(), mOverflowWidth);
   }
   return mOverflowWidth;
 }
 /** Sets the current content to be the overflow view panel. */
 private void setOverflowPanelAsContent() {
   // This should never be called if the overflow panel has not been initialized.
   Preconditions.checkNotNull(mOverflowPanel);
   mContentContainer.removeAllViews();
   Size overflowPanelSize = mOverflowPanel.measure();
   ViewGroup.LayoutParams params = mContentContainer.getLayoutParams();
   params.width = overflowPanelSize.getWidth();
   params.height = overflowPanelSize.getHeight();
   mContentContainer.setLayoutParams(params);
   mContentContainer.addView(mOverflowPanel.getView());
   setContentAreaAsTouchableSurface();
 }
    /** 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();
    }
 /**
  * Caches the specified token until the specified expiryMillis. The token will be associated with
  * the given token type, package name, and digest of signatures.
  *
  * @param token
  * @param tokenType
  * @param packageName
  * @param sigDigest
  * @param expiryMillis
  */
 public void put(
     Account account,
     String token,
     String tokenType,
     String packageName,
     byte[] sigDigest,
     long expiryMillis) {
   Preconditions.checkNotNull(account);
   if (token == null || System.currentTimeMillis() > expiryMillis) {
     return;
   }
   Key k = new Key(account, tokenType, packageName, sigDigest);
   Value v = new Value(token, expiryMillis);
   mCachedTokens.putToken(k, v);
 }
    /**
     * Initializes a floating toolbar popup overflow view panel.
     *
     * @param context
     * @param closeOverflow The code that closes the toolbar popup's overflow.
     */
    public FloatingToolbarOverflowPanel(Context context, Runnable closeOverflow) {
      mCloseOverflow = Preconditions.checkNotNull(closeOverflow);

      mContentView = new LinearLayout(context);
      mContentView.setOrientation(LinearLayout.VERTICAL);
      mViewFader = new ViewFader(mContentView);

      mBackButton =
          LayoutInflater.from(context).inflate(R.layout.floating_popup_close_overflow_button, null);
      mBackButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              mCloseOverflow.run();
            }
          });
      mBackButtonContainer = new LinearLayout(context);
      mBackButtonContainer.addView(mBackButton);

      mListView = createOverflowListView();
      mListView.setOnItemClickListener(
          new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
              MenuItem menuItem = (MenuItem) mListView.getAdapter().getItem(position);
              if (mOnMenuItemClickListener != null) {
                mOnMenuItemClickListener.onMenuItemClick(menuItem);
              }
            }
          });

      mContentView.addView(mListView);
      mContentView.addView(mBackButtonContainer);

      mListViewItemWidthCalculator = createOverflowMenuItemButton(context);
      mListViewItemWidthCalculator.setLayoutParams(
          new ViewGroup.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    }
 /** Initializes a floating toolbar. */
 public FloatingToolbar(Context context, Window window) {
   mContext = Preconditions.checkNotNull(context);
   mPopup = new FloatingToolbarPopup(window.getDecorView());
 }
 /**
  * Sets the content rectangle. This is the area of the interesting content that this toolbar
  * should avoid obstructing. NOTE: Call {@link #updateLayout()} or {@link #show()} to effect
  * visual changes to the toolbar.
  */
 public FloatingToolbar setContentRect(Rect rect) {
   mContentRect.set(Preconditions.checkNotNull(rect));
   return this;
 }
 /**
  * Initializes a floating toolbar popup main view panel.
  *
  * @param context
  * @param openOverflow The code that opens the toolbar popup overflow.
  */
 public FloatingToolbarMainPanel(Context context, Runnable openOverflow) {
   mContext = Preconditions.checkNotNull(context);
   mContentView = new LinearLayout(context);
   viewFader = new ViewFader(mContentView);
   mOpenOverflow = Preconditions.checkNotNull(openOverflow);
 }
 /**
  * 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());
 }
 void init(ChartAxis axis) {
   mAxis = Preconditions.checkNotNull(axis, "missing axis");
 }
 void init(ChartAxis horiz, ChartAxis vert) {
   mHoriz = Preconditions.checkNotNull(horiz, "missing horiz");
   mVert = Preconditions.checkNotNull(vert, "missing vert");
 }
 public DrawableWrapper(Drawable drawable) {
   mDrawable = Preconditions.checkNotNull(drawable);
   mDrawable.setCallback(this);
 }
 /**
  * Sets the menu to be shown in this floating toolbar. NOTE: Call {@link #updateLayout()} or
  * {@link #show()} to effect visual changes to the toolbar.
  */
 public FloatingToolbar setMenu(Menu menu) {
   mMenu = Preconditions.checkNotNull(menu);
   return this;
 }
    /**
     * Sets the progress of the print job.
     *
     * @param progress the progress of the job
     * @hide
     */
    public void setProgress(@FloatRange(from = 0.0, to = 1.0) float progress) {
      Preconditions.checkArgumentInRange(progress, 0, 1, "progress");

      mPrototype.mProgress = progress;
    }