Example #1
0
 void getSize(SizeReadyCallback cb) {
   int currentWidth = getViewWidthOrParam();
   int currentHeight = getViewHeightOrParam();
   if (isSizeValid(currentWidth) && isSizeValid(currentHeight)) {
     int paddingAdjustedWidth =
         currentWidth == WindowManager.LayoutParams.WRAP_CONTENT
             ? currentWidth
             : currentWidth - ViewCompat.getPaddingStart(view) - ViewCompat.getPaddingEnd(view);
     int paddingAdjustedHeight =
         currentHeight == LayoutParams.WRAP_CONTENT
             ? currentHeight
             : currentHeight - view.getPaddingTop() - view.getPaddingBottom();
     cb.onSizeReady(paddingAdjustedWidth, paddingAdjustedHeight);
   } else {
     // We want to notify callbacks in the order they were added and we only expect one or two
     // callbacks to
     // be added a time, so a List is a reasonable choice.
     if (!cbs.contains(cb)) {
       cbs.add(cb);
     }
     if (layoutListener == null) {
       final ViewTreeObserver observer = view.getViewTreeObserver();
       layoutListener = new SizeDeterminerLayoutListener(this);
       observer.addOnPreDrawListener(layoutListener);
     }
   }
 }
Example #2
0
 private void notifyCbs(int width, int height) {
   for (SizeReadyCallback cb : cbs) {
     cb.onSizeReady(width, height);
   }
 }
Example #3
0
 /**
  * Immediately calls the given callback with the sizes given in the constructor.
  *
  * @param cb {@inheritDoc}
  */
 @Override
 public final void getSize(SizeReadyCallback cb) {
   cb.onSizeReady(width, height);
 }