Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.73 KB | None | 0 0
  1. @Override
  2.     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  3.         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  4.  
  5.         int requestedWidth = getMeasuredWidth() - getPaddingLeft() - getPaddingRight();
  6.         int requestedHeight = getMeasuredHeight() - getPaddingTop() - getPaddingBottom();
  7.         int childWidth, childHeight;
  8.  
  9.         if (mOrientation == Orientation.Disordered) {
  10.             int R1, R2;
  11.             if (requestedWidth >= requestedHeight) {
  12.                 R1 = requestedHeight;
  13.                 R2 = requestedWidth;
  14.             } else {
  15.                 R1 = requestedWidth;
  16.                 R2 = requestedHeight;
  17.             }
  18.             childWidth = (int) ((R1 * Math.cos(DISORDERED_MAX_ROTATION_RADIANS) - R2 * Math.sin(DISORDERED_MAX_ROTATION_RADIANS)) / Math.cos(2 * DISORDERED_MAX_ROTATION_RADIANS));
  19.             childHeight = (int) ((R2 * Math.cos(DISORDERED_MAX_ROTATION_RADIANS) - R1 * Math.sin(DISORDERED_MAX_ROTATION_RADIANS)) / Math.cos(2 * DISORDERED_MAX_ROTATION_RADIANS));
  20.         } else {
  21.             childWidth = requestedWidth;
  22.             childHeight = requestedHeight;
  23.         }
  24.  
  25.         int childWidthMeasureSpec, childHeightMeasureSpec;
  26.         childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.AT_MOST);
  27.         childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeight, MeasureSpec.AT_MOST);
  28.  
  29.         for (int i = 0; i < getChildCount(); i++) {
  30.             View child = getChildAt(i);
  31.             assert child != null;
  32.             child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
  33.         }
  34.     }
  35.  
  36.  
  37.  
  38. compared with :
  39.  
  40.   def getChildren = for {
  41.     i <- 0 to getChildCount
  42.   } yield getChildAt(i)
  43.  
  44.  
  45.   protected override def onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int): Unit = {
  46.     super.onMeasure(widthMeasureSpec, heightMeasureSpec)
  47.     val requestedWidth = getMeasuredWidth - getPaddingLeft - getPaddingRight
  48.     val requestedHeight = getMeasuredHeight - getPaddingTop - getPaddingBottom
  49.     val (childWidth, childHeight) = mOrientation match {
  50.       case Disordered =>
  51.         val r = if (requestedWidth >= requestedHeight) (requestedHeight, requestedWidth)
  52.           else (requestedWidth, requestedHeight)
  53.         (((r._1 * Math.cos(DISORDERED_MAX_ROTATION_RADIANS) - r._2 * Math.sin(DISORDERED_MAX_ROTATION_RADIANS)) / Math.cos(2 * DISORDERED_MAX_ROTATION_RADIANS)).asInstanceOf[Int],
  54.          ((r._2 * Math.cos(DISORDERED_MAX_ROTATION_RADIANS) - r._1 * Math.sin(DISORDERED_MAX_ROTATION_RADIANS)) / Math.cos(2 * DISORDERED_MAX_ROTATION_RADIANS)).asInstanceOf[Int])
  55.       case Ordered =>
  56.         (requestedWidth, requestedHeight)
  57.     }
  58.     val (childWidthMeasureSpec, childHeightMeasureSpec) =
  59.       (MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.AT_MOST),
  60.        MeasureSpec.makeMeasureSpec(childHeight, MeasureSpec.AT_MOST))
  61.     getChildren.foreach(_.measure(childWidthMeasureSpec, childHeightMeasureSpec))
  62.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement