Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- int requestedWidth = getMeasuredWidth() - getPaddingLeft() - getPaddingRight();
- int requestedHeight = getMeasuredHeight() - getPaddingTop() - getPaddingBottom();
- int childWidth, childHeight;
- if (mOrientation == Orientation.Disordered) {
- int R1, R2;
- if (requestedWidth >= requestedHeight) {
- R1 = requestedHeight;
- R2 = requestedWidth;
- } else {
- R1 = requestedWidth;
- R2 = requestedHeight;
- }
- childWidth = (int) ((R1 * Math.cos(DISORDERED_MAX_ROTATION_RADIANS) - R2 * Math.sin(DISORDERED_MAX_ROTATION_RADIANS)) / Math.cos(2 * DISORDERED_MAX_ROTATION_RADIANS));
- childHeight = (int) ((R2 * Math.cos(DISORDERED_MAX_ROTATION_RADIANS) - R1 * Math.sin(DISORDERED_MAX_ROTATION_RADIANS)) / Math.cos(2 * DISORDERED_MAX_ROTATION_RADIANS));
- } else {
- childWidth = requestedWidth;
- childHeight = requestedHeight;
- }
- int childWidthMeasureSpec, childHeightMeasureSpec;
- childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.AT_MOST);
- childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeight, MeasureSpec.AT_MOST);
- for (int i = 0; i < getChildCount(); i++) {
- View child = getChildAt(i);
- assert child != null;
- child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
- }
- }
- compared with :
- def getChildren = for {
- i <- 0 to getChildCount
- } yield getChildAt(i)
- protected override def onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int): Unit = {
- super.onMeasure(widthMeasureSpec, heightMeasureSpec)
- val requestedWidth = getMeasuredWidth - getPaddingLeft - getPaddingRight
- val requestedHeight = getMeasuredHeight - getPaddingTop - getPaddingBottom
- val (childWidth, childHeight) = mOrientation match {
- case Disordered =>
- val r = if (requestedWidth >= requestedHeight) (requestedHeight, requestedWidth)
- else (requestedWidth, requestedHeight)
- (((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],
- ((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])
- case Ordered =>
- (requestedWidth, requestedHeight)
- }
- val (childWidthMeasureSpec, childHeightMeasureSpec) =
- (MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.AT_MOST),
- MeasureSpec.makeMeasureSpec(childHeight, MeasureSpec.AT_MOST))
- getChildren.foreach(_.measure(childWidthMeasureSpec, childHeightMeasureSpec))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement