Java Code Examples for android.view.View#combineMeasuredStates()
The following examples show how to use
android.view.View#combineMeasuredStates() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaselineLayout.java From material-components-android with Apache License 2.0 | 5 votes |
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int count = getChildCount(); int maxWidth = 0; int maxHeight = 0; int maxChildBaseline = -1; int maxChildDescent = -1; int childState = 0; for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } measureChild(child, widthMeasureSpec, heightMeasureSpec); final int baseline = child.getBaseline(); if (baseline != -1) { maxChildBaseline = Math.max(maxChildBaseline, baseline); maxChildDescent = Math.max(maxChildDescent, child.getMeasuredHeight() - baseline); } maxWidth = Math.max(maxWidth, child.getMeasuredWidth()); maxHeight = Math.max(maxHeight, child.getMeasuredHeight()); childState = View.combineMeasuredStates(childState, child.getMeasuredState()); } if (maxChildBaseline != -1) { maxChildDescent = Math.max(maxChildDescent, getPaddingBottom()); maxHeight = Math.max(maxHeight, maxChildBaseline + maxChildDescent); this.baseline = maxChildBaseline; } maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight()); maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth()); setMeasuredDimension( View.resolveSizeAndState(maxWidth, widthMeasureSpec, childState), View.resolveSizeAndState( maxHeight, heightMeasureSpec, childState << MEASURED_HEIGHT_STATE_SHIFT)); }
Example 2
Source File: FlexboxLayout.java From Collection-Android with MIT License | 4 votes |
/** * Set this FlexboxLayouts' width and height depending on the calculated size of main axis and * cross axis. * * @param flexDirection the value of the flex direction * @param widthMeasureSpec horizontal space requirements as imposed by the parent * @param heightMeasureSpec vertical space requirements as imposed by the parent * @param childState the child state of the View * @see #getFlexDirection() * @see #setFlexDirection(int) */ private void setMeasuredDimensionForFlex(@FlexDirection int flexDirection, int widthMeasureSpec, int heightMeasureSpec, int childState) { int widthMode = MeasureSpec.getMode(widthMeasureSpec); int widthSize = MeasureSpec.getSize(widthMeasureSpec); int heightMode = MeasureSpec.getMode(heightMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); int calculatedMaxHeight; int calculatedMaxWidth; switch (flexDirection) { case FlexDirection.ROW: // Intentional fall through case FlexDirection.ROW_REVERSE: calculatedMaxHeight = getSumOfCrossSize() + getPaddingTop() + getPaddingBottom(); calculatedMaxWidth = getLargestMainSize(); break; case FlexDirection.COLUMN: // Intentional fall through case FlexDirection.COLUMN_REVERSE: calculatedMaxHeight = getLargestMainSize(); calculatedMaxWidth = getSumOfCrossSize() + getPaddingLeft() + getPaddingRight(); break; default: throw new IllegalArgumentException("Invalid flex direction: " + flexDirection); } int widthSizeAndState; switch (widthMode) { case MeasureSpec.EXACTLY: if (widthSize < calculatedMaxWidth) { childState = View .combineMeasuredStates(childState, View.MEASURED_STATE_TOO_SMALL); } widthSizeAndState = View.resolveSizeAndState(widthSize, widthMeasureSpec, childState); break; case MeasureSpec.AT_MOST: { if (widthSize < calculatedMaxWidth) { childState = View .combineMeasuredStates(childState, View.MEASURED_STATE_TOO_SMALL); } else { widthSize = calculatedMaxWidth; } widthSizeAndState = View.resolveSizeAndState(widthSize, widthMeasureSpec, childState); break; } case MeasureSpec.UNSPECIFIED: { widthSizeAndState = View .resolveSizeAndState(calculatedMaxWidth, widthMeasureSpec, childState); break; } default: throw new IllegalStateException("Unknown width mode is set: " + widthMode); } int heightSizeAndState; switch (heightMode) { case MeasureSpec.EXACTLY: if (heightSize < calculatedMaxHeight) { childState = View.combineMeasuredStates(childState, View.MEASURED_STATE_TOO_SMALL >> View.MEASURED_HEIGHT_STATE_SHIFT); } heightSizeAndState = View.resolveSizeAndState(heightSize, heightMeasureSpec, childState); break; case MeasureSpec.AT_MOST: { if (heightSize < calculatedMaxHeight) { childState = View.combineMeasuredStates(childState, View.MEASURED_STATE_TOO_SMALL >> View.MEASURED_HEIGHT_STATE_SHIFT); } else { heightSize = calculatedMaxHeight; } heightSizeAndState = View.resolveSizeAndState(heightSize, heightMeasureSpec, childState); break; } case MeasureSpec.UNSPECIFIED: { heightSizeAndState = View.resolveSizeAndState(calculatedMaxHeight, heightMeasureSpec, childState); break; } default: throw new IllegalStateException("Unknown height mode is set: " + heightMode); } setMeasuredDimension(widthSizeAndState, heightSizeAndState); }
Example 3
Source File: Utility11.java From CSipSimple with GNU General Public License v3.0 | 4 votes |
@Override public int combineMeasuredStates(int curState, int newState) { return View.combineMeasuredStates(curState, newState); }
Example 4
Source File: ViewCompatHC.java From letv with Apache License 2.0 | 4 votes |
public static int combineMeasuredStates(int curState, int newState) { return View.combineMeasuredStates(curState, newState); }
Example 5
Source File: ShadowView.java From YCCardView with Apache License 2.0 | 4 votes |
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int maxHeight = 0; int maxWidth = 0; int childState = 0; ViewGroup.LayoutParams layoutParams = getLayoutParams(); setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec)); boolean shadowMeasureWidthMatchParent = layoutParams.width == ViewGroup.LayoutParams.MATCH_PARENT; boolean shadowMeasureHeightMatchParent = layoutParams.height == ViewGroup.LayoutParams.MATCH_PARENT; int widthSpec = widthMeasureSpec; if (shadowMeasureWidthMatchParent) { int childWidthSize = getMeasuredWidth() - shadowMarginRight - shadowMarginLeft; widthSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY); } int heightSpec = heightMeasureSpec; if (shadowMeasureHeightMatchParent) { int childHeightSize = getMeasuredHeight() - shadowMarginTop - shadowMarginBottom; heightSpec = MeasureSpec.makeMeasureSpec(childHeightSize, MeasureSpec.EXACTLY); } View child = getChildAt(0); if (child.getVisibility() != View.GONE) { measureChildWithMargins(child, widthSpec, 0, heightSpec, 0); LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (shadowMeasureWidthMatchParent) { maxWidth = Math.max(maxWidth, child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin); } else { maxWidth = Math.max(maxWidth, child.getMeasuredWidth() + shadowMarginLeft + shadowMarginRight + lp.leftMargin + lp.rightMargin); } if (shadowMeasureHeightMatchParent) { maxHeight = Math.max(maxHeight, child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin); } else { maxHeight = Math.max(maxHeight, child.getMeasuredHeight() + shadowMarginTop + shadowMarginBottom + lp.topMargin + lp.bottomMargin); } childState = View.combineMeasuredStates(childState, child.getMeasuredState()); } maxWidth += getPaddingLeft() + getPaddingRight(); maxHeight += getPaddingTop() + getPaddingBottom(); maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight()); maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth()); Drawable drawable = getForeground(); if (drawable != null) { maxHeight = Math.max(maxHeight, drawable.getMinimumHeight()); maxWidth = Math.max(maxWidth, drawable.getMinimumWidth()); } setMeasuredDimension(View.resolveSizeAndState(maxWidth, shadowMeasureWidthMatchParent ? widthMeasureSpec : widthSpec, childState), View.resolveSizeAndState(maxHeight, shadowMeasureHeightMatchParent ? heightMeasureSpec : heightSpec, childState << View.MEASURED_HEIGHT_STATE_SHIFT)); }
Example 6
Source File: BaseCardView.java From adt-leanback-support with Apache License 2.0 | 4 votes |
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { mMeasuredWidth = 0; mMeasuredHeight = 0; int state = 0; int mainHeight = 0; int infoHeight = 0; int extraHeight = 0; findChildrenViews(); final int unspecifiedSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); // MAIN is always present for (int i = 0; i < mMainViewList.size(); i++) { View mainView = mMainViewList.get(i); if (mainView.getVisibility() != View.GONE) { measureChild(mainView, unspecifiedSpec, unspecifiedSpec); mMeasuredWidth = Math.max(mMeasuredWidth, mainView.getMeasuredWidth()); mainHeight += mainView.getMeasuredHeight(); state = View.combineMeasuredStates(state, mainView.getMeasuredState()); } } setPivotX(mMeasuredWidth / 2); setPivotY(mainHeight / 2); // The MAIN area determines the card width int cardWidthMeasureSpec = MeasureSpec.makeMeasureSpec(mMeasuredWidth, MeasureSpec.EXACTLY); if (hasInfoRegion()) { for (int i = 0; i < mInfoViewList.size(); i++) { View infoView = mInfoViewList.get(i); if (infoView.getVisibility() != View.GONE) { measureChild(infoView, cardWidthMeasureSpec, unspecifiedSpec); if (mCardType != CARD_TYPE_INFO_OVER) { infoHeight += infoView.getMeasuredHeight(); } state = View.combineMeasuredStates(state, infoView.getMeasuredState()); } } if (hasExtraRegion()) { for (int i = 0; i < mExtraViewList.size(); i++) { View extraView = mExtraViewList.get(i); if (extraView.getVisibility() != View.GONE) { measureChild(extraView, cardWidthMeasureSpec, unspecifiedSpec); extraHeight += extraView.getMeasuredHeight(); state = View.combineMeasuredStates(state, extraView.getMeasuredState()); } } } } boolean infoAnimating = hasInfoRegion() && mInfoVisibility == CARD_REGION_VISIBLE_SELECTED; mMeasuredHeight = (int) (mainHeight + (infoAnimating ? (infoHeight * mInfoVisFraction) : infoHeight) + extraHeight - (infoAnimating ? 0 : mInfoOffset)); // Report our final dimensions. setMeasuredDimension(View.resolveSizeAndState(mMeasuredWidth + getPaddingLeft() + getPaddingRight(), widthMeasureSpec, state), View.resolveSizeAndState(mMeasuredHeight + getPaddingTop() + getPaddingBottom(), heightMeasureSpec, state << View.MEASURED_HEIGHT_STATE_SHIFT)); }