Example usage for android.view Gravity VERTICAL_GRAVITY_MASK

List of usage examples for android.view Gravity VERTICAL_GRAVITY_MASK

Introduction

In this page you can find the example usage for android.view Gravity VERTICAL_GRAVITY_MASK.

Prototype

int VERTICAL_GRAVITY_MASK

To view the source code for android.view Gravity VERTICAL_GRAVITY_MASK.

Click Source Link

Document

Binary mask to get the vertical gravity of a gravity.

Usage

From source file:com.actionbarsherlock.custom.widget.VerticalDrawerLayout.java

View findDrawerWithGravity(int gravity) {
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final int childGravity = getDrawerViewGravity(child);
        if ((childGravity & Gravity.VERTICAL_GRAVITY_MASK) == (gravity & Gravity.VERTICAL_GRAVITY_MASK)) {
            return child;
        }/*from   www.  j a  v  a 2  s .c o m*/
    }
    return null;
}

From source file:org.telegram.ui.ActionBar.ActionBar.java

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    int additionalTop = occupyStatusBar ? AndroidUtilities.statusBarHeight : 0;

    int textLeft;
    if (backButtonImageView != null && backButtonImageView.getVisibility() != GONE) {
        backButtonImageView.layout(0, additionalTop, backButtonImageView.getMeasuredWidth(),
                additionalTop + backButtonImageView.getMeasuredHeight());
        textLeft = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 80 : 72);
    } else {//from w  w  w .  ja  v a  2s.c  om
        textLeft = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 26 : 18);
    }

    if (menu != null && menu.getVisibility() != GONE) {
        int menuLeft = isSearchFieldVisible ? AndroidUtilities.dp(AndroidUtilities.isTablet() ? 74 : 66)
                : (right - left) - menu.getMeasuredWidth();
        menu.layout(menuLeft, additionalTop, menuLeft + menu.getMeasuredWidth(),
                additionalTop + menu.getMeasuredHeight());
    }

    if (titleTextView != null && titleTextView.getVisibility() != GONE) {
        int textTop;
        if (subtitleTextView != null && subtitleTextView.getVisibility() != GONE) {
            textTop = (getCurrentActionBarHeight() / 2 - titleTextView.getTextHeight()) / 2
                    + AndroidUtilities.dp(!AndroidUtilities.isTablet() && getResources()
                            .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 2 : 3);
        } else {
            textTop = (getCurrentActionBarHeight() - titleTextView.getTextHeight()) / 2;
        }
        titleTextView.layout(textLeft, additionalTop + textTop, textLeft + titleTextView.getMeasuredWidth(),
                additionalTop + textTop + titleTextView.getTextHeight());
    }
    if (subtitleTextView != null && subtitleTextView.getVisibility() != GONE) {
        int textTop = getCurrentActionBarHeight() / 2
                + (getCurrentActionBarHeight() / 2 - subtitleTextView.getTextHeight()) / 2
                - AndroidUtilities.dp(!AndroidUtilities.isTablet()
                        && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE
                                ? 1
                                : 1);
        subtitleTextView.layout(textLeft, additionalTop + textTop,
                textLeft + subtitleTextView.getMeasuredWidth(),
                additionalTop + textTop + subtitleTextView.getTextHeight());
    }

    int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = getChildAt(i);
        if (child.getVisibility() == GONE || child == titleTextView || child == subtitleTextView
                || child == menu || child == backButtonImageView) {
            continue;
        }

        LayoutParams lp = (LayoutParams) child.getLayoutParams();

        int width = child.getMeasuredWidth();
        int height = child.getMeasuredHeight();
        int childLeft;
        int childTop;

        int gravity = lp.gravity;
        if (gravity == -1) {
            gravity = Gravity.TOP | Gravity.LEFT;
        }

        final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
        final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;

        switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.CENTER_HORIZONTAL:
            childLeft = (right - left - width) / 2 + lp.leftMargin - lp.rightMargin;
            break;
        case Gravity.RIGHT:
            childLeft = right - width - lp.rightMargin;
            break;
        case Gravity.LEFT:
        default:
            childLeft = lp.leftMargin;
        }

        switch (verticalGravity) {
        case Gravity.TOP:
            childTop = lp.topMargin;
            break;
        case Gravity.CENTER_VERTICAL:
            childTop = (bottom - top - height) / 2 + lp.topMargin - lp.bottomMargin;
            break;
        case Gravity.BOTTOM:
            childTop = (bottom - top) - height - lp.bottomMargin;
            break;
        default:
            childTop = lp.topMargin;
        }
        child.layout(childLeft, childTop, childLeft + width, childTop + height);
    }
}

From source file:com.hippo.drawerlayout.DrawerLayout.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;/*from  w ww  . ja  v  a  2s .c  o m*/
    final int width = r - l;
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        int additionalTopMargin = 0;
        int additionalBottomMargin = 0;
        if (child instanceof DrawerLayoutChild) {
            DrawerLayoutChild dlc = (DrawerLayoutChild) child;
            additionalTopMargin = dlc.getAdditionalTopMargin();
            additionalBottomMargin = dlc.getAdditionalBottomMargin();
        }
        if (child == mContentView) {
            child.layout(lp.leftMargin, lp.topMargin + additionalTopMargin,
                    lp.leftMargin + child.getMeasuredWidth(),
                    lp.topMargin + additionalTopMargin + child.getMeasuredHeight());
        } else if (child == mShadow) {
            child.layout(0, 0, child.getMeasuredWidth(), child.getMeasuredHeight());
        } else { // Drawer, if it wasn't onMeasure would have thrown an exception.
            final int childWidth = child.getMeasuredWidth();
            final int childHeight = child.getMeasuredHeight();
            int childLeft;
            float percent;

            if (child == mLeftDrawer) {
                percent = mLeftPercent;
                childLeft = -childWidth + (int) (childWidth * percent);
            } else { // Right; onMeasure checked for us.
                percent = mRightPercent;
                childLeft = width - (int) (childWidth * percent);
            }

            final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;

            switch (vgrav) {
            default:
            case Gravity.TOP: {
                child.layout(childLeft, lp.topMargin + additionalTopMargin, childLeft + childWidth,
                        lp.topMargin + additionalTopMargin + childHeight);
                break;
            }

            case Gravity.BOTTOM: {
                final int height = b - t;
                child.layout(childLeft,
                        height - lp.bottomMargin - additionalBottomMargin - child.getMeasuredHeight(),
                        childLeft + childWidth, height - lp.bottomMargin - additionalBottomMargin);
                break;
            }

            case Gravity.CENTER_VERTICAL: {
                final int height = b - t;
                int childTop = (height - childHeight - additionalTopMargin - additionalBottomMargin
                        - lp.topMargin - lp.bottomMargin) / 2 + additionalTopMargin;
                // Offset for margins. If things don't fit right because of
                // bad measurement before, oh well.
                if (childTop < lp.topMargin + additionalTopMargin) {
                    childTop = lp.topMargin + additionalTopMargin;
                } else if (childTop + childHeight > height - additionalBottomMargin - lp.bottomMargin) {
                    childTop = height - additionalBottomMargin - lp.bottomMargin - childHeight;
                }
                child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
                break;
            }
            }

            final int newVisibility = percent > 0 ? VISIBLE : INVISIBLE;
            if (child.getVisibility() != newVisibility) {
                child.setVisibility(newVisibility);
            }
        }
    }
    mInLayout = false;
}

From source file:com.facebook.litho.widget.TextSpec.java

private static VerticalGravity getVerticalGravity(int gravity) {
    final VerticalGravity verticalGravity;
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.TOP:
        verticalGravity = TOP;/*  w  w  w.  j a v  a 2  s .  c o m*/
        break;
    case Gravity.CENTER_VERTICAL:
        verticalGravity = CENTER;
        break;
    case Gravity.BOTTOM:
        verticalGravity = BOTTOM;
        break;
    default:
        verticalGravity = TextSpec.verticalGravity;
        break;
    }
    return verticalGravity;
}

From source file:com.mixiaoxiao.mxxedgeeffect.widget.MxxPagerTitleStrip.java

void updateTextPositions(int position, float positionOffset, boolean force) {
    // position??item,currText
    // onPageScrolledpositionOffset>0.5fposition+1
    if (position != mLastKnownCurrentPage) {
        updateText(position, mPager.getAdapter());
    } else if (!force && positionOffset == mLastKnownPositionOffset) {
        return;/*w  ww. ja v  a 2s  .  c o  m*/
    }

    // ///////////////
    if (positionOffset == 0f) {
        mPrevText.setTextColor(convertTextColor(0f));
        mCurrText.setTextColor(convertTextColor(1f));
        mNextText.setTextColor(convertTextColor(0f));
    } else {
        //         Log.d(TAG, "position->" + position + "  positionOffset->" + positionOffset);
        float currPercent = positionOffset;// positionOffset=0.6
        // currOffset=0.1
        // boolean isOffsetAdding = (positionOffset -
        // mLastKnownPositionOffset)>0f;//offset
        if (currPercent <= 0.5f) {// 
            mPrevText.setTextColor(convertTextColor(0f));
            mCurrText.setTextColor(convertTextColor((1f - currPercent)));
            // if(isOffsetAdding){

            mNextText.setTextColor(convertTextColor(currPercent));
            // }

        } else {// 
                // currPercent -= 0.5f;
            mPrevText.setTextColor(convertTextColor(1f - currPercent));
            mCurrText.setTextColor(convertTextColor(currPercent));
            mNextText.setTextColor(convertTextColor(0));
        }
        // if (currPercent > 0.5f) {
        // currPercent -= 0.5f;
        // }
        // mPrevText.setTextColor(convertTextColor(currPercent));

    }

    // mNextText.setTextColor(transparentColor);

    mUpdatingPositions = true;

    final int prevWidth = mPrevText.getMeasuredWidth();
    final int currWidth = mCurrText.getMeasuredWidth();
    final int nextWidth = mNextText.getMeasuredWidth();
    final int halfCurrWidth = 0;// currWidth / 2;

    final int stripWidth = getWidth();
    final int stripHeight = getHeight();
    final int paddingLeft = getPaddingLeft();
    final int paddingRight = getPaddingRight();
    final int paddingTop = getPaddingTop();
    final int paddingBottom = getPaddingBottom();
    //      final int textPaddedLeft = paddingLeft + halfCurrWidth;
    //      final int textPaddedRight = paddingRight + halfCurrWidth;
    //      final int contentWidth = prevWidth + currWidth + nextWidth;// stripWidth
    // -
    // textPaddedLeft
    // -
    // textPaddedRight;

    float currOffset = positionOffset + 0.5f;// positionOffset=0.6
    // currOffset=0.1
    if (currOffset > 1.f) {
        currOffset -= 1.f;
    }
    // float currOffset = positionOffset;
    // if (currOffset > 1.f) {
    // currOffset -= 1.f;
    // }
    final int currCenter = stripWidth / 2 - (int) (currWidth * (currOffset - 0.5f));// stripWidth
    // -
    // textPaddedRight
    // -
    // (int)
    // (contentWidth
    // *
    // currOffset);

    final int currLeft = currCenter - currWidth / 2;
    final int currRight = currLeft + currWidth;

    final int prevBaseline = mPrevText.getBaseline();
    final int currBaseline = mCurrText.getBaseline();
    final int nextBaseline = mNextText.getBaseline();
    final int maxBaseline = Math.max(Math.max(prevBaseline, currBaseline), nextBaseline);
    final int prevTopOffset = maxBaseline - prevBaseline;
    final int currTopOffset = maxBaseline - currBaseline;
    final int nextTopOffset = maxBaseline - nextBaseline;
    final int alignedPrevHeight = prevTopOffset + mPrevText.getMeasuredHeight();
    final int alignedCurrHeight = currTopOffset + mCurrText.getMeasuredHeight();
    final int alignedNextHeight = nextTopOffset + mNextText.getMeasuredHeight();
    final int maxTextHeight = Math.max(Math.max(alignedPrevHeight, alignedCurrHeight), alignedNextHeight);

    final int vgrav = mGravity & Gravity.VERTICAL_GRAVITY_MASK;

    int prevTop;
    int currTop;
    int nextTop;
    switch (vgrav) {
    default:
    case Gravity.TOP:
        prevTop = paddingTop + prevTopOffset;
        currTop = paddingTop + currTopOffset;
        nextTop = paddingTop + nextTopOffset;
        break;
    case Gravity.CENTER_VERTICAL:
        final int paddedHeight = stripHeight - paddingTop - paddingBottom;
        final int centeredTop = (paddedHeight - maxTextHeight) / 2;
        prevTop = centeredTop + prevTopOffset;
        currTop = centeredTop + currTopOffset;
        nextTop = centeredTop + nextTopOffset;
        break;
    case Gravity.BOTTOM:
        final int bottomGravTop = stripHeight - paddingBottom - maxTextHeight;
        prevTop = bottomGravTop + prevTopOffset;
        currTop = bottomGravTop + currTopOffset;
        nextTop = bottomGravTop + nextTopOffset;
        break;
    }

    mCurrText.layout(currLeft, currTop, currRight, currTop + mCurrText.getMeasuredHeight());

    final int prevLeft = currLeft - mScaledTextSpacing - prevWidth;// Math.min(paddingLeft,
    // currLeft
    // -
    // mScaledTextSpacing
    // -
    // prevWidth);
    mPrevText.layout(prevLeft, prevTop, prevLeft + prevWidth, prevTop + mPrevText.getMeasuredHeight());

    final int nextLeft = currRight + mScaledTextSpacing;// Math.max(stripWidth
    // - paddingRight -
    // nextWidth,
    // currRight + mScaledTextSpacing);
    mNextText.layout(nextLeft, nextTop, nextLeft + nextWidth, nextTop + mNextText.getMeasuredHeight());

    mLastKnownPositionOffset = positionOffset;
    mUpdatingPositions = false;
}

From source file:com.aidy.bottomdrawerlayout.BottomDrawerLayout.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    Log.i(TAG, "onMeasure() -- widthMeasureSpec = " + widthMeasureSpec + " -- heightMeasureSpec = "
            + heightMeasureSpec);/*from  ww w. j  a v a 2 s  . c om*/
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    if (widthMode != MeasureSpec.EXACTLY || heightMode != MeasureSpec.EXACTLY) {
        if (isInEditMode()) {
            if (widthMode == MeasureSpec.AT_MOST) {
                widthMode = MeasureSpec.EXACTLY;
            } else if (widthMode == MeasureSpec.UNSPECIFIED) {
                widthMode = MeasureSpec.EXACTLY;
                widthSize = 300;
            }
            if (heightMode == MeasureSpec.AT_MOST) {
                heightMode = MeasureSpec.EXACTLY;
            } else if (heightMode == MeasureSpec.UNSPECIFIED) {
                heightMode = MeasureSpec.EXACTLY;
                heightSize = 300;
            }
        } else {
            throw new IllegalArgumentException("DrawerLayout must be measured with MeasureSpec.EXACTLY.");
        }
    }

    setMeasuredDimension(widthSize, heightSize);

    // Gravity value for each drawer we've seen. Only one of each permitted.
    int foundDrawers = 0;
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (isContentView(child)) {
            final int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize - lp.leftMargin - lp.rightMargin,
                    MeasureSpec.EXACTLY);
            final int contentHeightSpec = MeasureSpec
                    .makeMeasureSpec(heightSize - lp.topMargin - lp.bottomMargin, MeasureSpec.EXACTLY);
            child.measure(contentWidthSpec, contentHeightSpec);
        } else if (isDrawerView(child)) {
            final int childGravity = getDrawerViewAbsoluteGravity(child) & Gravity.VERTICAL_GRAVITY_MASK;
            if ((foundDrawers & childGravity) != 0) {
                throw new IllegalStateException(
                        "Child drawer has absolute gravity " + gravityToString(childGravity) + " but this "
                                + TAG + " already has a " + "drawer view along that edge");
            }
            final int drawerWidthSpec = getChildMeasureSpec(widthMeasureSpec, lp.leftMargin + lp.rightMargin,
                    lp.width);
            final int drawerHeightSpec = getChildMeasureSpec(heightMeasureSpec,
                    mMinDrawerMargin + lp.topMargin + lp.bottomMargin, lp.height);
            child.measure(drawerWidthSpec, drawerHeightSpec);
        } else {
            throw new IllegalStateException("Child " + child + " at index " + i
                    + " does not have a valid layout_gravity - must be Gravity.LEFT, "
                    + "Gravity.RIGHT or Gravity.NO_GRAVITY");
        }
    }
}

From source file:com.android.mail.browse.ConversationContainer.java

private static OverlayPosition calculatePosition(final ConversationOverlayItem adapterItem, final int withinTop,
        final int withinBottom, final int forceGravity) {
    if (adapterItem.getHeight() == 0) {
        // "place" invisible items at the bottom of their region to stay consistent with the
        // stacking algorithm in positionOverlays(), unless gravity is forced to the top
        final int y = (forceGravity == Gravity.TOP) ? withinTop : withinBottom;
        return new OverlayPosition(y, y);
    }/* w  w  w.j  a va 2 s  .c  o m*/

    final int v = ((forceGravity != Gravity.NO_GRAVITY) ? forceGravity : adapterItem.getGravity())
            & Gravity.VERTICAL_GRAVITY_MASK;
    switch (v) {
    case Gravity.BOTTOM:
        return new OverlayPosition(withinBottom - adapterItem.getHeight(), withinBottom);
    case Gravity.TOP:
        return new OverlayPosition(withinTop, withinTop + adapterItem.getHeight());
    default:
        throw new UnsupportedOperationException("unsupported gravity: " + v);
    }
}

From source file:com.actionbarsherlock.custom.widget.VerticalDrawerLayout.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    final int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    if (widthMode != MeasureSpec.EXACTLY || heightMode != MeasureSpec.EXACTLY) {
        throw new IllegalArgumentException("VerticalDrawerLayout must be measured with MeasureSpec.EXACTLY.");
    }//from w  w w.  ja v  a 2s. com

    setMeasuredDimension(widthSize, heightSize);

    // Gravity value for each drawer we've seen. Only one of each permitted.
    int foundDrawers = 0;
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (isContentView(child)) {
            // Content views get measured at exactly the layout's size.
            final int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize - lp.leftMargin - lp.rightMargin,
                    MeasureSpec.EXACTLY);
            final int contentHeightSpec = MeasureSpec
                    .makeMeasureSpec(heightSize - lp.topMargin - lp.bottomMargin, MeasureSpec.EXACTLY);
            child.measure(contentWidthSpec, contentHeightSpec);
        } else if (isDrawerView(child)) {
            final int childGravity = getDrawerViewGravity(child) & Gravity.VERTICAL_GRAVITY_MASK;
            if ((foundDrawers & childGravity) != 0) {
                throw new IllegalStateException(
                        "Child drawer has absolute gravity " + gravityToString(childGravity) + " but this "
                                + TAG + " already has a " + "drawer view along that edge");
            }
            final int drawerWidthSpec = getChildMeasureSpec(widthMeasureSpec, lp.leftMargin + lp.rightMargin,
                    lp.width);
            final int drawerHeightSpec = getChildMeasureSpec(heightMeasureSpec,
                    mMinDrawerMargin + lp.topMargin + lp.bottomMargin, lp.height);
            child.measure(drawerWidthSpec, drawerHeightSpec);
        } else {
            throw new IllegalStateException("Child " + child + " at index " + i
                    + " does not have a valid layout_gravity - must be Gravity.TOP, "
                    + "Gravity.BOTTOM or Gravity.NO_GRAVITY");
        }
    }
}

From source file:com.scoreflex.ScoreflexView.java

/**
 * Adds a drop shadow to this view.//from  w  w w.  ja  v a2  s .  com
 *
 * @param gravity
 *          The gravity of the Scoreflex view (not the drop shadow's).
 */
@SuppressWarnings("deprecation")
public void addDropShadow(int gravity) {
    boolean top = Gravity.TOP != (gravity & Gravity.VERTICAL_GRAVITY_MASK);
    setBackgroundDrawable(getContext().getResources()
            .getDrawable(top ? R.drawable.scoreflex_top_shadow : R.drawable.scoreflex_bottom_shadow));
    int height = getResources().getDimensionPixelSize(R.dimen.scoreflex_shadow_height);
    setPadding(0, top ? height : 0, 0, top ? 0 : height);
}

From source file:com.example.verticaldrawerlayout.VerticalDrawerLayout.java

/**
 * @param gravity//w  ww.  j  a  v  a  2 s . c  o  m
 *            the gravity of the child to return. If specified as a
 *            relative value, it will be resolved according to the current
 *            layout direction.
 * @return the drawer with the specified gravity
 */
View findDrawerWithGravity(int gravity) {
    final int absHorizGravity = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this))
            & Gravity.VERTICAL_GRAVITY_MASK;
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final int childAbsGravity = getDrawerViewAbsoluteGravity(child);
        if ((childAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) == absHorizGravity) {
            return child;
        }
    }
    return null;
}