Skip to content

Commit

Permalink
Fix for proper measuement
Browse files Browse the repository at this point in the history
When setting view dimensions in Gingerbread we need to clear measurement flags which where introduced in Honeycomb, cause getMeasuredWidth/Height method on that version is not doing that (not clearing them).
  • Loading branch information
Łukasz Gawin committed Apr 1, 2014
1 parent 93cfc3f commit b41deb2
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions library/src/org/holoeverywhere/widget/LinearLayout.java
@@ -1,17 +1,19 @@

package org.holoeverywhere.widget;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;

import org.holoeverywhere.R;
import org.holoeverywhere.drawable.DrawableCompat;

Expand Down Expand Up @@ -531,8 +533,8 @@ void measureHorizontal(int widthMeasureSpec, int heightMeasureSpec) {
}
final int margin = lp.topMargin + lp.bottomMargin;
final int childHeight = child.getMeasuredHeight() + margin;
if (VERSION.SDK_INT >= 11) {
childState |= child.getMeasuredState();
if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
childState |= getChildMeasuredState(child);
}
if (baselineAligned) {
final int childBaseline = child.getBaseline();
Expand Down Expand Up @@ -631,8 +633,8 @@ heightMeasureSpec, getPaddingTop() + getPaddingBottom() + lp.topMargin
share > 0 ? share : 0, MeasureSpec.EXACTLY),
childHeightMeasureSpec);
}
if (VERSION.SDK_INT >= 11) {
childState |= child.getMeasuredState() & MEASURED_STATE_MASK;
if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
childState |= getChildMeasuredState(child) & MEASURED_STATE_MASK;
}
}
if (isExactly) {
Expand Down Expand Up @@ -701,9 +703,9 @@ heightMeasureSpec, getPaddingTop() + getPaddingBottom() + lp.topMargin
}
maxHeight += getPaddingTop() + getPaddingBottom();
maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
setMeasuredDimension(widthSizeAndState | childState & MEASURED_STATE_MASK,
ViewCompat.resolveSizeAndState(maxHeight, heightMeasureSpec,
childState << MEASURED_HEIGHT_STATE_SHIFT));
setMeasuredDimensionsCompat(widthSizeAndState | childState & MEASURED_STATE_MASK,
ViewCompat.resolveSizeAndState(maxHeight, heightMeasureSpec,
childState << MEASURED_HEIGHT_STATE_SHIFT));
if (matchHeight) {
forceUniformHeight(count, widthMeasureSpec);
}
Expand Down Expand Up @@ -812,8 +814,8 @@ void measureVertical(int widthMeasureSpec, int heightMeasureSpec) {
final int margin = lp.leftMargin + lp.rightMargin;
final int measuredWidth = child.getMeasuredWidth() + margin;
maxWidth = Math.max(maxWidth, measuredWidth);
if (VERSION.SDK_INT >= 11) {
childState |= child.getMeasuredState();
if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
childState |= getChildMeasuredState(child);
}
allFillParent = allFillParent
&& lp.width == android.view.ViewGroup.LayoutParams.MATCH_PARENT;
Expand Down Expand Up @@ -878,8 +880,8 @@ void measureVertical(int widthMeasureSpec, int heightMeasureSpec) {
MeasureSpec.makeMeasureSpec(share > 0 ? share : 0,
MeasureSpec.EXACTLY));
}
if (VERSION.SDK_INT >= 11) {
childState |= child.getMeasuredState()
if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
childState |= getChildMeasuredState(child)
& MEASURED_STATE_MASK >> MEASURED_HEIGHT_STATE_SHIFT;
}
}
Expand Down Expand Up @@ -922,13 +924,28 @@ void measureVertical(int widthMeasureSpec, int heightMeasureSpec) {
}
maxWidth += getPaddingLeft() + getPaddingRight();
maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
setMeasuredDimension(ViewCompat.resolveSizeAndState(maxWidth, widthMeasureSpec, childState),
heightSizeAndState);

setMeasuredDimensionsCompat(ViewCompat.resolveSizeAndState(maxWidth, widthMeasureSpec, childState),
heightSizeAndState);
if (matchWidth) {
forceUniformWidth(count, heightMeasureSpec);
}
}

private void setMeasuredDimensionsCompat(int measuredWidth,
int measuredHeight) {
if (VERSION.SDK_INT < VERSION_CODES.HONEYCOMB) {
measuredWidth &= MEASURED_SIZE_MASK;
measuredHeight &= MEASURED_SIZE_MASK;
}
setMeasuredDimension(measuredWidth, measuredHeight);
}

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private int getChildMeasuredState(final View child) {
return child.getMeasuredState();
}

@Override
protected void onDraw(Canvas canvas) {
if (mDivider == null) {
Expand Down

0 comments on commit b41deb2

Please sign in to comment.