Example usage for android.view View getVisibility

List of usage examples for android.view View getVisibility

Introduction

In this page you can find the example usage for android.view View getVisibility.

Prototype

@ViewDebug.ExportedProperty(mapping = { @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"),
        @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"),
        @ViewDebug.IntToString(from = GONE, to = "GONE") })
@Visibility
public int getVisibility() 

Source Link

Document

Returns the visibility status for this view.

Usage

From source file:com.honeywell.printer.tabhost.CustomViewPager.java

/**
 * We only want the current page that is being shown to be focusable.
 *///from w ww .  j a  v a2 s. c  o m
@Override
public void addFocusables(ArrayList<View> views, int direction, int focusableMode) {
    if (views == null) {
        throw new IllegalStateException("addFocusables views is null");
    }
    final int focusableCount = views.size();

    final int descendantFocusability = getDescendantFocusability();

    if (descendantFocusability != FOCUS_BLOCK_DESCENDANTS) {
        for (int i = 0; i < getChildCount(); i++) {
            final View child = getChildAt(i);
            if (child.getVisibility() == VISIBLE) {
                ItemInfo ii = infoForChild(child);
                if (ii != null && ii.position == mCurItem) {
                    child.addFocusables(views, direction, focusableMode);
                }
            }
        }
    }

    // we add ourselves (if focusable) in all cases except for when we are
    // FOCUS_AFTER_DESCENDANTS and there are some descendants focusable.  this is
    // to avoid the focus search finding layouts when a more precise search
    // among the focusable children would be more interesting.
    if (descendantFocusability != FOCUS_AFTER_DESCENDANTS ||
    // No focusable descendants
            (focusableCount == views.size())) {
        // Note that we can't call the superclass here, because it will
        // add all views in.  So we need to do the same thing View does.
        if (!isFocusable()) {
            return;
        }
        if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE && isInTouchMode()
                && !isFocusableInTouchMode()) {
            return;
        }
        if (views != null) {
            views.add(this);
        }
    }
}

From source file:com.cxsplay.wallyskim.widget.flexbox.FlexboxLayout.java

/**
 * Expand the flex items along the main axis based on the individual flexGrow attribute.
 *
 * @param widthMeasureSpec     the horizontal space requirements as imposed by the parent
 * @param heightMeasureSpec    the vertical space requirements as imposed by the parent
 * @param flexLine             the flex line to which flex items belong
 * @param flexDirection        the flexDirection value for this FlexboxLayout
 * @param maxMainSize          the maximum main size. Expanded main size will be this size
 * @param paddingAlongMainAxis the padding value along the main axis
 * @param startIndex           the start index of the children views to be expanded. This index
 *                             needs to/*from w  w  w . j a  va 2 s.  c  o  m*/
 *                             be an absolute index in the flex container (FlexboxLayout),
 *                             not the relative index in the flex line.
 * @param calledRecursively    true if this method is called recursively, false otherwise
 * @return the next index, the next flex line's first flex item starts from the returned index
 * @see #getFlexDirection()
 * @see #setFlexDirection(int)
 * @see LayoutParams#flexGrow
 */
private int expandFlexItems(int widthMeasureSpec, int heightMeasureSpec, FlexLine flexLine,
        @FlexDirection int flexDirection, int maxMainSize, int paddingAlongMainAxis, int startIndex,
        boolean calledRecursively) {
    int childIndex = startIndex;
    if (flexLine.mTotalFlexGrow <= 0 || maxMainSize < flexLine.mMainSize) {
        childIndex += flexLine.mItemCount;
        return childIndex;
    }
    int sizeBeforeExpand = flexLine.mMainSize;
    boolean needsReexpand = false;
    float unitSpace = (maxMainSize - flexLine.mMainSize) / flexLine.mTotalFlexGrow;
    flexLine.mMainSize = paddingAlongMainAxis + flexLine.mDividerLengthInMainSize;

    // Setting the cross size of the flex line as the temporal value since the cross size of
    // each flex item may be changed from the initial calculation
    // (in the measureHorizontal/measureVertical method) even this method is part of the main
    // size determination.
    // E.g. If a TextView's layout_width is set to 0dp, layout_height is set to wrap_content,
    // and layout_flexGrow is set to 1, the TextView is trying to expand to the vertical
    // direction to enclose its content (in the measureHorizontal method), but
    // the width will be expanded in this method. In that case, the height needs to be measured
    // again with the expanded width.
    if (!calledRecursively) {
        flexLine.mCrossSize = Integer.MIN_VALUE;
    }
    int largestCrossSize = 0;
    float accumulatedRoundError = 0;
    for (int i = 0; i < flexLine.mItemCount; i++) {
        View child = getReorderedChildAt(childIndex);
        if (child == null) {
            continue;
        } else if (child.getVisibility() == View.GONE) {
            childIndex++;
            continue;
        }
        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (isMainAxisDirectionHorizontal(flexDirection)) {
            // The direction of the main axis is horizontal
            if (!mChildrenFrozen[childIndex]) {
                float rawCalculatedWidth = child.getMeasuredWidth() + unitSpace * lp.flexGrow;
                if (i == flexLine.mItemCount - 1) {
                    rawCalculatedWidth += accumulatedRoundError;
                    accumulatedRoundError = 0;
                }
                int newWidth = Math.round(rawCalculatedWidth);
                if (newWidth > lp.maxWidth) {
                    // This means the child can't expand beyond the value of the maxWidth attribute.
                    // To adjust the flex line length to the size of maxMainSize, remaining
                    // positive free space needs to be re-distributed to other flex items
                    // (children views). In that case, invoke this method again with the same
                    // startIndex.
                    needsReexpand = true;
                    newWidth = lp.maxWidth;
                    mChildrenFrozen[childIndex] = true;
                    flexLine.mTotalFlexGrow -= lp.flexGrow;
                } else {
                    accumulatedRoundError += (rawCalculatedWidth - newWidth);
                    if (accumulatedRoundError > 1.0) {
                        newWidth += 1;
                        accumulatedRoundError -= 1.0;
                    } else if (accumulatedRoundError < -1.0) {
                        newWidth -= 1;
                        accumulatedRoundError += 1.0;
                    }
                }
                int childHeightMeasureSpec = getChildHeightMeasureSpec(heightMeasureSpec, lp);
                child.measure(MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY),
                        childHeightMeasureSpec);
                largestCrossSize = Math.max(largestCrossSize,
                        child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin);
            }
            flexLine.mMainSize += child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
        } else {
            // The direction of the main axis is vertical
            if (!mChildrenFrozen[childIndex]) {
                float rawCalculatedHeight = child.getMeasuredHeight() + unitSpace * lp.flexGrow;
                if (i == flexLine.mItemCount - 1) {
                    rawCalculatedHeight += accumulatedRoundError;
                    accumulatedRoundError = 0;
                }
                int newHeight = Math.round(rawCalculatedHeight);
                if (newHeight > lp.maxHeight) {
                    // This means the child can't expand beyond the value of the maxHeight
                    // attribute.
                    // To adjust the flex line length to the size of maxMainSize, remaining
                    // positive free space needs to be re-distributed to other flex items
                    // (children views). In that case, invoke this method again with the same
                    // startIndex.
                    needsReexpand = true;
                    newHeight = lp.maxHeight;
                    mChildrenFrozen[childIndex] = true;
                    flexLine.mTotalFlexGrow -= lp.flexGrow;
                } else {
                    accumulatedRoundError += (rawCalculatedHeight - newHeight);
                    if (accumulatedRoundError > 1.0) {
                        newHeight += 1;
                        accumulatedRoundError -= 1.0;
                    } else if (accumulatedRoundError < -1.0) {
                        newHeight -= 1;
                        accumulatedRoundError += 1.0;
                    }
                }
                int childWidthMeasureSpec = getChildWidthMeasureSpec(widthMeasureSpec, lp);
                child.measure(childWidthMeasureSpec,
                        MeasureSpec.makeMeasureSpec(newHeight, MeasureSpec.EXACTLY));
                largestCrossSize = Math.max(largestCrossSize,
                        child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin);
            }
            flexLine.mMainSize += child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
        }
        flexLine.mCrossSize = Math.max(flexLine.mCrossSize, largestCrossSize);
        childIndex++;
    }

    if (needsReexpand && sizeBeforeExpand != flexLine.mMainSize) {
        // Re-invoke the method with the same startIndex to distribute the positive free space
        // that wasn't fully distributed (because of maximum length constraint)
        expandFlexItems(widthMeasureSpec, heightMeasureSpec, flexLine, flexDirection, maxMainSize,
                paddingAlongMainAxis, startIndex, true);
    }
    return childIndex;
}

From source file:com.cxsplay.wallyskim.widget.flexbox.FlexboxLayout.java

/**
 * Sub method for {@link #onLayout(boolean, int, int, int, int)} when the
 * {@link #mFlexDirection} is either {@link #FLEX_DIRECTION_ROW} or
 * {@link #FLEX_DIRECTION_ROW_REVERSE}.//w w  w.j ava2s  .c  o  m
 *
 * @param isRtl  {@code true} if the horizontal layout direction is right to left, {@code
 *               false} otherwise.
 * @param left   the left position of this View
 * @param top    the top position of this View
 * @param right  the right position of this View
 * @param bottom the bottom position of this View
 * @see #getFlexWrap()
 * @see #setFlexWrap(int)
 * @see #getJustifyContent()
 * @see #setJustifyContent(int)
 * @see #getAlignItems()
 * @see #setAlignItems(int)
 * @see LayoutParams#alignSelf
 */
private void layoutHorizontal(boolean isRtl, int left, int top, int right, int bottom) {
    int paddingLeft = getPaddingLeft();
    int paddingRight = getPaddingRight();
    // Use float to reduce the round error that may happen in when justifyContent ==
    // SPACE_BETWEEN or SPACE_AROUND
    float childLeft;
    int currentViewIndex = 0;

    int height = bottom - top;
    int width = right - left;
    // childBottom is used if the mFlexWrap is FLEX_WRAP_WRAP_REVERSE otherwise
    // childTop is used to align the vertical position of the children views.
    int childBottom = height - getPaddingBottom();
    int childTop = getPaddingTop();

    // Used only for RTL layout
    // Use float to reduce the round error that may happen in when justifyContent ==
    // SPACE_BETWEEN or SPACE_AROUND
    float childRight;
    for (int i = 0, size = mFlexLines.size(); i < size; i++) {
        FlexLine flexLine = mFlexLines.get(i);
        if (hasDividerBeforeFlexLine(i)) {
            childBottom -= mDividerHorizontalHeight;
            childTop += mDividerHorizontalHeight;
        }
        float spaceBetweenItem = 0f;
        switch (mJustifyContent) {
        case JUSTIFY_CONTENT_FLEX_START:
            childLeft = paddingLeft;
            childRight = width - paddingRight;
            break;
        case JUSTIFY_CONTENT_FLEX_END:
            childLeft = width - flexLine.mMainSize + paddingRight;
            childRight = flexLine.mMainSize - paddingLeft;
            break;
        case JUSTIFY_CONTENT_CENTER:
            childLeft = paddingLeft + (width - flexLine.mMainSize) / 2f;
            childRight = width - paddingRight - (width - flexLine.mMainSize) / 2f;
            break;
        case JUSTIFY_CONTENT_SPACE_AROUND:
            int visibleCount = flexLine.getItemCountNotGone();
            if (visibleCount != 0) {
                spaceBetweenItem = (width - flexLine.mMainSize) / (float) visibleCount;
            }
            childLeft = paddingLeft + spaceBetweenItem / 2f;
            childRight = width - paddingRight - spaceBetweenItem / 2f;
            break;
        case JUSTIFY_CONTENT_SPACE_BETWEEN:
            childLeft = paddingLeft;
            int visibleItem = flexLine.getItemCountNotGone();
            float denominator = visibleItem != 1 ? visibleItem - 1 : 1f;
            spaceBetweenItem = (width - flexLine.mMainSize) / denominator;
            childRight = width - paddingRight;
            break;
        default:
            throw new IllegalStateException("Invalid justifyContent is set: " + mJustifyContent);
        }
        spaceBetweenItem = Math.max(spaceBetweenItem, 0);

        for (int j = 0; j < flexLine.mItemCount; j++) {
            View child = getReorderedChildAt(currentViewIndex);
            if (child == null) {
                continue;
            } else if (child.getVisibility() == View.GONE) {
                currentViewIndex++;
                continue;
            }
            LayoutParams lp = ((LayoutParams) child.getLayoutParams());
            childLeft += lp.leftMargin;
            childRight -= lp.rightMargin;
            if (hasDividerBeforeChildAtAlongMainAxis(currentViewIndex, j)) {
                childLeft += mDividerVerticalWidth;
                childRight -= mDividerVerticalWidth;
            }

            if (mFlexWrap == FLEX_WRAP_WRAP_REVERSE) {
                if (isRtl) {
                    layoutSingleChildHorizontal(child, flexLine, mFlexWrap, mAlignItems,
                            Math.round(childRight) - child.getMeasuredWidth(),
                            childBottom - child.getMeasuredHeight(), Math.round(childRight), childBottom);
                } else {
                    layoutSingleChildHorizontal(child, flexLine, mFlexWrap, mAlignItems, Math.round(childLeft),
                            childBottom - child.getMeasuredHeight(),
                            Math.round(childLeft) + child.getMeasuredWidth(), childBottom);
                }
            } else {
                if (isRtl) {
                    layoutSingleChildHorizontal(child, flexLine, mFlexWrap, mAlignItems,
                            Math.round(childRight) - child.getMeasuredWidth(), childTop, Math.round(childRight),
                            childTop + child.getMeasuredHeight());
                } else {
                    layoutSingleChildHorizontal(child, flexLine, mFlexWrap, mAlignItems, Math.round(childLeft),
                            childTop, Math.round(childLeft) + child.getMeasuredWidth(),
                            childTop + child.getMeasuredHeight());
                }
            }
            childLeft += child.getMeasuredWidth() + spaceBetweenItem + lp.rightMargin;
            childRight -= child.getMeasuredWidth() + spaceBetweenItem + lp.leftMargin;
            currentViewIndex++;

            flexLine.mLeft = Math.min(flexLine.mLeft, child.getLeft() - lp.leftMargin);
            flexLine.mTop = Math.min(flexLine.mTop, child.getTop() - lp.topMargin);
            flexLine.mRight = Math.max(flexLine.mRight, child.getRight() + lp.rightMargin);
            flexLine.mBottom = Math.max(flexLine.mBottom, child.getBottom() + lp.bottomMargin);
        }
        childTop += flexLine.mCrossSize;
        childBottom -= flexLine.mCrossSize;
    }
}

From source file:com.cxsplay.wallyskim.widget.flexbox.FlexboxLayout.java

/**
 * Sub method for {@link #onLayout(boolean, int, int, int, int)} when the
 * {@link #mFlexDirection} is either {@link #FLEX_DIRECTION_COLUMN} or
 * {@link #FLEX_DIRECTION_COLUMN_REVERSE}.
 *
 * @param isRtl           {@code true} if the horizontal layout direction is right to left,
 *                        {@code false}//  w w  w  .  ja va  2s .c  o m
 *                        otherwise
 * @param fromBottomToTop {@code true} if the layout direction is bottom to top, {@code false}
 *                        otherwise
 * @param left            the left position of this View
 * @param top             the top position of this View
 * @param right           the right position of this View
 * @param bottom          the bottom position of this View
 * @see #getFlexWrap()
 * @see #setFlexWrap(int)
 * @see #getJustifyContent()
 * @see #setJustifyContent(int)
 * @see #getAlignItems()
 * @see #setAlignItems(int)
 * @see LayoutParams#alignSelf
 */
private void layoutVertical(boolean isRtl, boolean fromBottomToTop, int left, int top, int right, int bottom) {
    int paddingTop = getPaddingTop();
    int paddingBottom = getPaddingBottom();

    int paddingRight = getPaddingRight();
    int childLeft = getPaddingLeft();
    int currentViewIndex = 0;

    int width = right - left;
    int height = bottom - top;
    // childRight is used if the mFlexWrap is FLEX_WRAP_WRAP_REVERSE otherwise
    // childLeft is used to align the horizontal position of the children views.
    int childRight = width - paddingRight;

    // Use float to reduce the round error that may happen in when justifyContent ==
    // SPACE_BETWEEN or SPACE_AROUND
    float childTop;

    // Used only for if the direction is from bottom to top
    float childBottom;

    for (int i = 0, size = mFlexLines.size(); i < size; i++) {
        FlexLine flexLine = mFlexLines.get(i);
        if (hasDividerBeforeFlexLine(i)) {
            childLeft += mDividerVerticalWidth;
            childRight -= mDividerVerticalWidth;
        }
        float spaceBetweenItem = 0f;
        switch (mJustifyContent) {
        case JUSTIFY_CONTENT_FLEX_START:
            childTop = paddingTop;
            childBottom = height - paddingBottom;
            break;
        case JUSTIFY_CONTENT_FLEX_END:
            childTop = height - flexLine.mMainSize + paddingBottom;
            childBottom = flexLine.mMainSize - paddingTop;
            break;
        case JUSTIFY_CONTENT_CENTER:
            childTop = paddingTop + (height - flexLine.mMainSize) / 2f;
            childBottom = height - paddingBottom - (height - flexLine.mMainSize) / 2f;
            break;
        case JUSTIFY_CONTENT_SPACE_AROUND:
            int visibleCount = flexLine.getItemCountNotGone();
            if (visibleCount != 0) {
                spaceBetweenItem = (height - flexLine.mMainSize) / (float) visibleCount;
            }
            childTop = paddingTop + spaceBetweenItem / 2f;
            childBottom = height - paddingBottom - spaceBetweenItem / 2f;
            break;
        case JUSTIFY_CONTENT_SPACE_BETWEEN:
            childTop = paddingTop;
            int visibleItem = flexLine.getItemCountNotGone();
            float denominator = visibleItem != 1 ? visibleItem - 1 : 1f;
            spaceBetweenItem = (height - flexLine.mMainSize) / denominator;
            childBottom = height - paddingBottom;
            break;
        default:
            throw new IllegalStateException("Invalid justifyContent is set: " + mJustifyContent);
        }
        spaceBetweenItem = Math.max(spaceBetweenItem, 0);

        for (int j = 0; j < flexLine.mItemCount; j++) {
            View child = getReorderedChildAt(currentViewIndex);
            if (child == null) {
                continue;
            } else if (child.getVisibility() == View.GONE) {
                currentViewIndex++;
                continue;
            }
            LayoutParams lp = ((LayoutParams) child.getLayoutParams());
            childTop += lp.topMargin;
            childBottom -= lp.bottomMargin;
            if (hasDividerBeforeChildAtAlongMainAxis(currentViewIndex, j)) {
                childTop += mDividerHorizontalHeight;
                childBottom -= mDividerHorizontalHeight;
            }
            if (isRtl) {
                if (fromBottomToTop) {
                    layoutSingleChildVertical(child, flexLine, true, mAlignItems,
                            childRight - child.getMeasuredWidth(),
                            Math.round(childBottom) - child.getMeasuredHeight(), childRight,
                            Math.round(childBottom));
                } else {
                    layoutSingleChildVertical(child, flexLine, true, mAlignItems,
                            childRight - child.getMeasuredWidth(), Math.round(childTop), childRight,
                            Math.round(childTop) + child.getMeasuredHeight());
                }
            } else {
                if (fromBottomToTop) {
                    layoutSingleChildVertical(child, flexLine, false, mAlignItems, childLeft,
                            Math.round(childBottom) - child.getMeasuredHeight(),
                            childLeft + child.getMeasuredWidth(), Math.round(childBottom));
                } else {
                    layoutSingleChildVertical(child, flexLine, false, mAlignItems, childLeft,
                            Math.round(childTop), childLeft + child.getMeasuredWidth(),
                            Math.round(childTop) + child.getMeasuredHeight());
                }
            }
            childTop += child.getMeasuredHeight() + spaceBetweenItem + lp.bottomMargin;
            childBottom -= child.getMeasuredHeight() + spaceBetweenItem + lp.topMargin;
            currentViewIndex++;

            flexLine.mLeft = Math.min(flexLine.mLeft, child.getLeft() - lp.leftMargin);
            flexLine.mTop = Math.min(flexLine.mTop, child.getTop() - lp.topMargin);
            flexLine.mRight = Math.max(flexLine.mRight, child.getRight() + lp.rightMargin);
            flexLine.mBottom = Math.max(flexLine.mBottom, child.getBottom() + lp.bottomMargin);
        }
        childLeft += flexLine.mCrossSize;
        childRight -= flexLine.mCrossSize;
    }
}

From source file:cc.flydev.launcher.Page.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (!mIsDataReady || getChildCount() == 0) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        return;/* ww  w .  j  av a2 s. c  om*/
    }

    // We measure the dimensions of the PagedView to be larger than the pages so that when we
    // zoom out (and scale down), the view is still contained in the parent
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);
    // NOTE: We multiply by 1.5f to account for the fact that depending on the offset of the
    // viewport, we can be at most one and a half screens offset once we scale down
    DisplayMetrics dm = getResources().getDisplayMetrics();
    int maxSize = Math.max(dm.widthPixels, dm.heightPixels + mInsets.top + mInsets.bottom);

    int parentWidthSize, parentHeightSize;
    int scaledWidthSize, scaledHeightSize;
    if (mUseMinScale) {
        parentWidthSize = (int) (1.5f * maxSize);
        parentHeightSize = maxSize;
        scaledWidthSize = (int) (parentWidthSize / mMinScale);
        scaledHeightSize = (int) (parentHeightSize / mMinScale);
    } else {
        scaledWidthSize = widthSize;
        scaledHeightSize = heightSize;
    }
    mViewport.set(0, 0, widthSize, heightSize);

    if (widthMode == MeasureSpec.UNSPECIFIED || heightMode == MeasureSpec.UNSPECIFIED) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        return;
    }

    // Return early if we aren't given a proper dimension
    if (widthSize <= 0 || heightSize <= 0) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        return;
    }

    /* Allow the height to be set as WRAP_CONTENT. This allows the particular case
     * of the All apps view on XLarge displays to not take up more space then it needs. Width
     * is still not allowed to be set as WRAP_CONTENT since many parts of the code expect
     * each page to have the same width.
     */
    final int verticalPadding = getPaddingTop() + getPaddingBottom();
    final int horizontalPadding = getPaddingLeft() + getPaddingRight();

    // The children are given the same width and height as the workspace
    // unless they were set to WRAP_CONTENT
    if (DEBUG)
        Log.d(TAG, "PagedView.onMeasure(): " + widthSize + ", " + heightSize);
    if (DEBUG)
        Log.d(TAG, "PagedView.scaledSize: " + scaledWidthSize + ", " + scaledHeightSize);
    if (DEBUG)
        Log.d(TAG, "PagedView.parentSize: " + parentWidthSize + ", " + parentHeightSize);
    if (DEBUG)
        Log.d(TAG, "PagedView.horizontalPadding: " + horizontalPadding);
    if (DEBUG)
        Log.d(TAG, "PagedView.verticalPadding: " + verticalPadding);
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        // disallowing padding in paged view (just pass 0)
        final View child = getPageAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();

            int childWidthMode;
            int childHeightMode;
            int childWidth;
            int childHeight;

            if (!lp.isFullScreenPage) {
                if (lp.width == LayoutParams.WRAP_CONTENT) {
                    childWidthMode = MeasureSpec.AT_MOST;
                } else {
                    childWidthMode = MeasureSpec.EXACTLY;
                }

                if (lp.height == LayoutParams.WRAP_CONTENT) {
                    childHeightMode = MeasureSpec.AT_MOST;
                } else {
                    childHeightMode = MeasureSpec.EXACTLY;
                }

                childWidth = widthSize - horizontalPadding;
                childHeight = heightSize - verticalPadding - mInsets.top - mInsets.bottom;
                mNormalChildHeight = childHeight;

            } else {
                childWidthMode = MeasureSpec.EXACTLY;
                childHeightMode = MeasureSpec.EXACTLY;

                if (mUseMinScale) {
                    childWidth = getViewportWidth();
                    childHeight = getViewportHeight();
                } else {
                    childWidth = widthSize - getPaddingLeft() - getPaddingRight();
                    childHeight = heightSize - getPaddingTop() - getPaddingBottom();
                }
            }

            final int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidth, childWidthMode);
            final int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeight, childHeightMode);
            child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
        }
    }
    setMeasuredDimension(scaledWidthSize, scaledHeightSize);

    if (childCount > 0) {
        // Calculate the variable page spacing if necessary
        if (mAutoComputePageSpacing && mRecomputePageSpacing) {
            // The gap between pages in the PagedView should be equal to the gap from the page
            // to the edge of the screen (so it is not visible in the current screen).  To
            // account for unequal padding on each side of the paged view, we take the maximum
            // of the left/right gap and use that as the gap between each page.
            int offset = (getViewportWidth() - getChildWidth(0)) / 2;
            int spacing = Math.max(offset, widthSize - offset - getChildAt(0).getMeasuredWidth());
            setPageSpacing(spacing);
            mRecomputePageSpacing = false;
        }
    }
}

From source file:com.albedinsky.android.support.ui.widget.ViewPager.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // For simple implementation, our internal size is always 0.
    // We depend on the container to specify the layout size of
    // our view.  We can't really know what it is since we will be
    // adding and removing different arbitrary views and do not
    // want the layout to change as this happens.
    setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));

    final int measuredWidth = getMeasuredWidth();
    final int maxGutterSize = measuredWidth / 10;
    mGutterSize = Math.min(maxGutterSize, mDefaultGutterSize);

    // Children are just made to fill our space.
    int childWidthSize = measuredWidth - getPaddingLeft() - getPaddingRight();
    int childHeightSize = getMeasuredHeight() - getPaddingTop() - getPaddingBottom();

    /*//  w  ww  .  ja v  a  2 s  . c o m
     * Make sure all children have been properly measured. Decor views first.
     * Right now we cheat and make this less complicated by assuming decor
     * views won't intersect. We will pin to edges based on gravity.
     */
    int size = getChildCount();
    for (int i = 0; i < size; ++i) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp != null && lp.isDecor) {
                final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                int widthMode = MeasureSpec.AT_MOST;
                int heightMode = MeasureSpec.AT_MOST;
                boolean consumeVertical = vgrav == Gravity.TOP || vgrav == Gravity.BOTTOM;
                boolean consumeHorizontal = hgrav == Gravity.LEFT || hgrav == Gravity.RIGHT;

                if (consumeVertical) {
                    widthMode = MeasureSpec.EXACTLY;
                } else if (consumeHorizontal) {
                    heightMode = MeasureSpec.EXACTLY;
                }

                int widthSize = childWidthSize;
                int heightSize = childHeightSize;
                if (lp.width != LayoutParams.WRAP_CONTENT) {
                    widthMode = MeasureSpec.EXACTLY;
                    if (lp.width != LayoutParams.FILL_PARENT) {
                        widthSize = lp.width;
                    }
                }
                if (lp.height != LayoutParams.WRAP_CONTENT) {
                    heightMode = MeasureSpec.EXACTLY;
                    if (lp.height != LayoutParams.FILL_PARENT) {
                        heightSize = lp.height;
                    }
                }
                final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode);
                final int heightSpec = MeasureSpec.makeMeasureSpec(heightSize, heightMode);
                child.measure(widthSpec, heightSpec);

                if (consumeVertical) {
                    childHeightSize -= child.getMeasuredHeight();
                } else if (consumeHorizontal) {
                    childWidthSize -= child.getMeasuredWidth();
                }
            }
        }
    }

    mChildWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);
    mChildHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeightSize, MeasureSpec.EXACTLY);

    // Make sure we have created all fragments that we need to have shown.
    mInLayout = true;
    populate();
    mInLayout = false;

    // Page views next.
    size = getChildCount();
    for (int i = 0; i < size; ++i) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            if (DEBUG_ENABLED)
                Log.v(TAG, "Measuring #" + i + " " + child + ": " + mChildWidthMeasureSpec);

            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp == null || !lp.isDecor) {
                final int widthSpec = MeasureSpec.makeMeasureSpec((int) (childWidthSize * lp.widthFactor),
                        MeasureSpec.EXACTLY);
                child.measure(widthSpec, mChildHeightMeasureSpec);
            }
        }
    }
}

From source file:com.albedinsky.android.support.ui.widget.ViewPager.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    final int count = getChildCount();
    int width = r - l;
    int height = b - t;
    int paddingLeft = getPaddingLeft();
    int paddingTop = getPaddingTop();
    int paddingRight = getPaddingRight();
    int paddingBottom = getPaddingBottom();
    final int scrollX = getScrollX();

    int decorCount = 0;

    // First pass - decor views. We need to do this in two passes so that
    // we have the proper offsets for non-decor views later.
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            int childLeft = 0;
            int childTop = 0;
            if (lp.isDecor) {
                final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                switch (hgrav) {
                default:
                    childLeft = paddingLeft;
                    break;
                case Gravity.LEFT:
                    childLeft = paddingLeft;
                    paddingLeft += child.getMeasuredWidth();
                    break;
                case Gravity.CENTER_HORIZONTAL:
                    childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft);
                    break;
                case Gravity.RIGHT:
                    childLeft = width - paddingRight - child.getMeasuredWidth();
                    paddingRight += child.getMeasuredWidth();
                    break;
                }//from w w  w .j  ava 2 s  .  co m
                switch (vgrav) {
                default:
                    childTop = paddingTop;
                    break;
                case Gravity.TOP:
                    childTop = paddingTop;
                    paddingTop += child.getMeasuredHeight();
                    break;
                case Gravity.CENTER_VERTICAL:
                    childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop);
                    break;
                case Gravity.BOTTOM:
                    childTop = height - paddingBottom - child.getMeasuredHeight();
                    paddingBottom += child.getMeasuredHeight();
                    break;
                }
                childLeft += scrollX;
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
                decorCount++;
            }
        }
    }

    final int childWidth = width - paddingLeft - paddingRight;
    // Page views. Do this once we have the right padding offsets from above.
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            ItemInfo ii;
            if (!lp.isDecor && (ii = infoForChild(child)) != null) {
                int loff = (int) (childWidth * ii.offset);
                int childLeft = paddingLeft + loff;
                int childTop = paddingTop;
                if (lp.needsMeasure) {
                    // This was added during layout and needs measurement.
                    // Do it now that we know what we're working with.
                    lp.needsMeasure = false;
                    final int widthSpec = MeasureSpec.makeMeasureSpec((int) (childWidth * lp.widthFactor),
                            MeasureSpec.EXACTLY);
                    final int heightSpec = MeasureSpec
                            .makeMeasureSpec((int) (height - paddingTop - paddingBottom), MeasureSpec.EXACTLY);
                    child.measure(widthSpec, heightSpec);
                }
                if (DEBUG_ENABLED)
                    Log.v(TAG, "Positioning #" + i + " " + child + " f=" + ii.object + ":" + childLeft + ","
                            + childTop + " " + child.getMeasuredWidth() + "x" + child.getMeasuredHeight());
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
            }
        }
    }
    mTopPageBounds = paddingTop;
    mBottomPageBounds = height - paddingBottom;
    mDecorChildCount = decorCount;

    if (mFirstLayout) {
        scrollToItem(mCurItem, false, 0, false);
    }
    mFirstLayout = false;
}

From source file:VerticalViewPager.java

@SuppressWarnings("deprecation")
@Override//from  w  w  w . j  a v  a2s.  c  o  m
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // For simple implementation, our internal size is always 0.
    // We depend on the container to specify the layout size of
    // our view.  We can't really know what it is since we will be
    // adding and removing different arbitrary views and do not
    // want the layout to change as this happens.
    setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));

    final int measuredWidth = getMeasuredWidth();
    final int measuredHeight = getMeasuredHeight();

    final int maxGutterSize = measuredHeight / 10;
    mGutterSize = Math.min(maxGutterSize, mDefaultGutterSize);

    // Children are just made to fill our space.
    int childWidthSize = measuredWidth - getPaddingLeft() - getPaddingRight();
    int childHeightSize = measuredHeight - getPaddingTop() - getPaddingBottom();

    /*
     * Make sure all children have been properly measured. Decor views first.
     * Right now we cheat and make this less complicated by assuming decor
     * views won't intersect. We will pin to edges based on gravity.
     */
    int size = getChildCount();
    for (int i = 0; i < size; ++i) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp != null && lp.isDecor) {
                final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                int widthMode = MeasureSpec.AT_MOST;
                int heightMode = MeasureSpec.AT_MOST;
                boolean consumeVertical = vgrav == Gravity.TOP || vgrav == Gravity.BOTTOM;
                boolean consumeHorizontal = hgrav == Gravity.LEFT || hgrav == Gravity.RIGHT;

                if (consumeVertical) {
                    widthMode = MeasureSpec.EXACTLY;
                } else if (consumeHorizontal) {
                    heightMode = MeasureSpec.EXACTLY;
                }

                int widthSize = childWidthSize;
                int heightSize = childHeightSize;
                if (lp.width != LayoutParams.WRAP_CONTENT) {
                    widthMode = MeasureSpec.EXACTLY;
                    if (lp.width != LayoutParams.FILL_PARENT) {
                        widthSize = lp.width;
                    }
                }
                if (lp.height != LayoutParams.WRAP_CONTENT) {
                    heightMode = MeasureSpec.EXACTLY;
                    if (lp.height != LayoutParams.FILL_PARENT) {
                        heightSize = lp.height;
                    }
                }
                final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode);
                final int heightSpec = MeasureSpec.makeMeasureSpec(heightSize, heightMode);
                child.measure(widthSpec, heightSpec);

                if (consumeVertical) {
                    childHeightSize -= child.getMeasuredHeight();
                } else if (consumeHorizontal) {
                    childWidthSize -= child.getMeasuredWidth();
                }
            }
        }
    }

    mChildWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);
    mChildHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeightSize, MeasureSpec.EXACTLY);

    // Make sure we have created all fragments that we need to have shown.
    mInLayout = true;
    populate();
    mInLayout = false;

    // Page views next.
    size = getChildCount();
    for (int i = 0; i < size; ++i) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            if (DEBUG)
                Log.v(TAG, "Measuring #" + i + " " + child + ": " + mChildWidthMeasureSpec);

            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp == null || !lp.isDecor) {
                final int heightSpec = MeasureSpec.makeMeasureSpec((int) (childHeightSize * lp.heightFactor),
                        MeasureSpec.EXACTLY);
                child.measure(mChildWidthMeasureSpec, heightSpec);
            }
        }
    }
}

From source file:com.cxsplay.wallyskim.widget.flexbox.FlexboxLayout.java

/**
 * Sub method for {@link #onMeasure(int, int)} when the main axis direction is vertical
 * (either from top to bottom or bottom to top).
 *
 * @param widthMeasureSpec  horizontal space requirements as imposed by the parent
 * @param heightMeasureSpec vertical space requirements as imposed by the parent
 * @see #onMeasure(int, int)/*  ww w .  jav  a  2  s  .c o m*/
 * @see #setFlexDirection(int)
 * @see #setFlexWrap(int)
 * @see #setAlignItems(int)
 * @see #setAlignContent(int)
 */
private void measureVertical(int widthMeasureSpec, int heightMeasureSpec) {
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);
    int childState = 0;

    mFlexLines.clear();

    // Determine how many flex lines are needed in this layout by measuring each child.
    // (Expand or shrink the view depending on the flexGrow and flexShrink attributes in a later
    // loop)
    int childCount = getChildCount();
    int paddingTop = getPaddingTop();
    int paddingBottom = getPaddingBottom();
    int largestWidthInColumn = Integer.MIN_VALUE;
    FlexLine flexLine = new FlexLine();
    flexLine.mMainSize = paddingTop + paddingBottom;
    // The index of the view in a same flex line.
    int indexInFlexLine = 0;
    for (int i = 0; i < childCount; i++) {
        View child = getReorderedChildAt(i);
        if (child == null) {
            addFlexLineIfLastFlexItem(i, childCount, flexLine);
            continue;
        } else if (child.getVisibility() == View.GONE) {
            flexLine.mItemCount++;
            flexLine.mGoneItemCount++;
            addFlexLineIfLastFlexItem(i, childCount, flexLine);
            continue;
        }

        FlexboxLayout.LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (lp.alignSelf == LayoutParams.ALIGN_SELF_STRETCH) {
            flexLine.mIndicesAlignSelfStretch.add(i);
        }

        int childHeight = lp.height;
        if (lp.flexBasisPercent != LayoutParams.FLEX_BASIS_PERCENT_DEFAULT
                && heightMode == MeasureSpec.EXACTLY) {
            childHeight = Math.round(heightSize * lp.flexBasisPercent);
            // Use the dimension from the layout_height attribute if the heightMode is not
            // MeasureSpec.EXACTLY even if any fraction value is set to layout_flexBasisPercent.
            // There are likely quite few use cases where assigning any fraction values
            // with heightMode is not MeasureSpec.EXACTLY (e.g. FlexboxLayout's layout_height
            // is set to wrap_content)
        }

        int childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec,
                getPaddingLeft() + getPaddingRight() + lp.leftMargin + lp.rightMargin, lp.width);
        int childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec,
                getPaddingTop() + getPaddingBottom() + lp.topMargin + lp.bottomMargin, childHeight);
        child.measure(childWidthMeasureSpec, childHeightMeasureSpec);

        // Check the size constraint after the first measurement for the child
        // To prevent the child's width/height violate the size constraints imposed by the
        // {@link LayoutParams#minWidth}, {@link LayoutParams#minHeight},
        // {@link LayoutParams#maxWidth} and {@link LayoutParams#maxHeight} attributes.
        // E.g. When the child's layout_height is wrap_content the measured height may be
        // less than the min height after the first measurement.
        checkSizeConstraints(child);

        childState = ViewCompat.combineMeasuredStates(childState, ViewCompat.getMeasuredState(child));
        largestWidthInColumn = Math.max(largestWidthInColumn,
                child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin);

        if (isWrapRequired(heightMode, heightSize, flexLine.mMainSize,
                child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin, lp, i, indexInFlexLine)) {
            if (flexLine.getItemCountNotGone() > 0) {
                addFlexLine(flexLine);
            }

            flexLine = new FlexLine();
            flexLine.mItemCount = 1;
            flexLine.mMainSize = paddingTop + paddingBottom;
            largestWidthInColumn = child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
            indexInFlexLine = 0;
        } else {
            flexLine.mItemCount++;
            indexInFlexLine++;
        }
        flexLine.mMainSize += child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
        flexLine.mTotalFlexGrow += lp.flexGrow;
        flexLine.mTotalFlexShrink += lp.flexShrink;
        // Temporarily set the cross axis length as the largest child width in the column
        // Expand along the cross axis depending on the mAlignContent property if needed
        // later
        flexLine.mCrossSize = Math.max(flexLine.mCrossSize, largestWidthInColumn);

        if (hasDividerBeforeChildAtAlongMainAxis(i, indexInFlexLine)) {
            flexLine.mMainSize += mDividerHorizontalHeight;
        }
        addFlexLineIfLastFlexItem(i, childCount, flexLine);
    }

    determineMainSize(mFlexDirection, widthMeasureSpec, heightMeasureSpec);
    determineCrossSize(mFlexDirection, widthMeasureSpec, heightMeasureSpec,
            getPaddingLeft() + getPaddingRight());
    // Now cross size for each flex line is determined.
    // Expand the views if alignItems (or alignSelf in each child view) is set to stretch
    stretchViews(mFlexDirection, mAlignItems);
    setMeasuredDimensionForFlex(mFlexDirection, widthMeasureSpec, heightMeasureSpec, childState);
}

From source file:com.goodfriends.personalchef.viewflipper.MyViewPager.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {

    final int count = getChildCount();
    int width = r - l;
    int height = b - t;
    int paddingLeft = getPaddingLeft();
    int paddingTop = getPaddingTop();
    int paddingRight = getPaddingRight();
    int paddingBottom = getPaddingBottom();
    final int scrollX = getScrollX();

    int decorCount = 0;

    // First pass - decor views. We need to do this in two passes so that
    // we have the proper offsets for non-decor views later.
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            int childLeft = 0;
            int childTop = 0;
            if (lp.isDecor) {
                final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                switch (hgrav) {
                default:
                    childLeft = paddingLeft;
                    break;
                case Gravity.LEFT:
                    childLeft = paddingLeft;
                    paddingLeft += child.getMeasuredWidth();
                    break;
                case Gravity.CENTER_HORIZONTAL:
                    childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft);
                    break;
                case Gravity.RIGHT:
                    childLeft = width - paddingRight - child.getMeasuredWidth();
                    paddingRight += child.getMeasuredWidth();
                    break;
                }/*from   ww w  .  j  a v a2 s .c om*/
                switch (vgrav) {
                default:
                    childTop = paddingTop;
                    break;
                case Gravity.TOP:
                    childTop = paddingTop;
                    paddingTop += child.getMeasuredHeight();
                    break;
                case Gravity.CENTER_VERTICAL:
                    childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop);
                    break;
                case Gravity.BOTTOM:
                    childTop = height - paddingBottom - child.getMeasuredHeight();
                    paddingBottom += child.getMeasuredHeight();
                    break;
                }
                childLeft += scrollX;
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
                decorCount++;
            }
        }
    }

    final int childWidth = width - paddingLeft - paddingRight;
    // Page views. Do this once we have the right padding offsets from above.
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            ItemInfo ii;
            if (!lp.isDecor && (ii = infoForChild(child)) != null) {
                int loff = (int) (childWidth * ii.offset);
                int childLeft = paddingLeft + loff;
                int childTop = paddingTop;
                if (lp.needsMeasure) {
                    // This was added during layout and needs measurement.
                    // Do it now that we know what we're working with.
                    lp.needsMeasure = false;
                    final int widthSpec = MeasureSpec.makeMeasureSpec((int) (childWidth * lp.widthFactor),
                            MeasureSpec.EXACTLY);
                    final int heightSpec = MeasureSpec
                            .makeMeasureSpec((int) (height - paddingTop - paddingBottom), MeasureSpec.EXACTLY);
                    child.measure(widthSpec, heightSpec);
                }
                if (DEBUG)
                    Log.v(TAG, "Positioning #" + i + " " + child + " f=" + ii.object + ":" + childLeft + ","
                            + childTop + " " + child.getMeasuredWidth() + "x" + child.getMeasuredHeight());
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
            }
        }
    }
    mTopPageBounds = paddingTop;
    mBottomPageBounds = height - paddingBottom;
    mDecorChildCount = decorCount;
    //        MyLogger.showLogWithLineNum(4, "?MyViewPager ----> onLayout ___ mFirstLayout=="+mFirstLayout);
    if (mFirstLayout) {
        scrollToItem(mCurItem, false, 0, false);
    }
    mFirstLayout = false;
    //        MyLogger.showLogWithLineNum(5, "?MyViewPager ----> onLayout ___ mFirstLayout=="+mFirstLayout);
}