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.itsronald.widget.ViewPagerIndicator.java

/**
 * Calculate the starting vertical position for the line of indicator dots.
 * @return The first Y coordinate where the indicator dots start.
 *///from ww w.  ja  va 2s.  co  m
@Px
private int calculateIndicatorDotTop() {
    final int top;
    final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
    switch (verticalGravity) {
    default:
    case Gravity.CENTER_VERTICAL:
        top = (getHeight() - getPaddingTop() - getPaddingBottom()) / 2 - getDotRadius();
        break;
    case Gravity.TOP:
        top = getPaddingTop();
        break;
    case Gravity.BOTTOM:
        top = getHeight() - getPaddingBottom() - 2 * getDotRadius();
        break;
    }
    return top;
}

From source file:net.grobas.widget.AutoLinearLayout.java

private void updateTopPositionByGravity(ViewPosition pos, int size, int gravity) {
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.BOTTOM:
        pos.top += (size > 0) ? size : 0;
        break;//from   w ww  .j  a  v a 2  s  .  co m

    case Gravity.CENTER_VERTICAL:
        pos.top += ((size > 0) ? size : 0) / 2;
        break;
    }
}

From source file:android.support.v7.widget.LinearLayoutCompat.java

@Override
public int getBaseline() {
    if (mBaselineAlignedChildIndex < 0) {
        return super.getBaseline();
    }//from  www .  ja v a2 s. c  o  m

    if (getChildCount() <= mBaselineAlignedChildIndex) {
        throw new RuntimeException(
                "mBaselineAlignedChildIndex of LinearLayout " + "set to an index that is out of bounds.");
    }

    final View child = getChildAt(mBaselineAlignedChildIndex);
    final int childBaseline = child.getBaseline();

    if (childBaseline == -1) {
        if (mBaselineAlignedChildIndex == 0) {
            // this is just the default case, safe to return -1
            return -1;
        }
        // the user picked an index that points to something that doesn't
        // know how to calculate its baseline.
        throw new RuntimeException("mBaselineAlignedChildIndex of LinearLayout "
                + "points to a View that doesn't know how to get its baseline.");
    }

    // TODO: This should try to take into account the virtual offsets
    // (See getNextLocationOffset and getLocationOffset)
    // We should add to childTop:
    // sum([getNextLocationOffset(getChildAt(i)) / i < mBaselineAlignedChildIndex])
    // and also add:
    // getLocationOffset(child)
    int childTop = mBaselineChildTop;

    if (mOrientation == VERTICAL) {
        final int majorGravity = mGravity & Gravity.VERTICAL_GRAVITY_MASK;
        if (majorGravity != Gravity.TOP) {
            switch (majorGravity) {
            case Gravity.BOTTOM:
                childTop = getBottom() - getTop() - getPaddingBottom() - mTotalLength;
                break;

            case Gravity.CENTER_VERTICAL:
                childTop += ((getBottom() - getTop() - getPaddingTop() - getPaddingBottom()) - mTotalLength)
                        / 2;
                break;
            }
        }
    }

    LinearLayoutCompat.LayoutParams lp = (LinearLayoutCompat.LayoutParams) child.getLayoutParams();
    return childTop + lp.topMargin + childBaseline;
}

From source file:com.scoreflex.ScoreflexView.java

/**
 * Closes this ScoreflexView. If the view is attached to the developer
 * hierarchy it will be detached. If the view is attached to a
 * ScoreflexActivity, this activity will be terminated.
 *//*  w  w  w.ja v a2s  .c o  m*/
public void close() {
    // If we're displayed in the developer view hierarchy,
    // remove ourselves.
    final ViewParent parent = this.getParent();
    ViewGroup.LayoutParams currentLayoutParams = getLayoutParams();
    boolean isFullscreen = currentLayoutParams.height == LayoutParams.MATCH_PARENT;

    LocalBroadcastManager.getInstance(getContext()).unregisterReceiver(mLoginReceiver);

    if (isFullscreen && null != parent && parent instanceof ViewGroup) {
        int gravity = getLayoutGravity();
        int anim = (Gravity.TOP == (gravity & Gravity.VERTICAL_GRAVITY_MASK)) ? R.anim.scoreflex_exit_slide_up
                : R.anim.scoreflex_exit_slide_down;
        Animation animation = AnimationUtils.loadAnimation(mParentActivity, anim);
        animation.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationEnd(Animation arg0) {
                ViewGroup parentGroup = (ViewGroup) parent;
                parentGroup.removeView(ScoreflexView.this);
                if (mScoreflexViewHandler != null) {
                    mScoreflexViewHandler.onViewClosed();
                    mScoreflexViewHandler = null;
                }
            }

            @Override
            public void onAnimationRepeat(Animation arg0) {

            }

            @Override
            public void onAnimationStart(Animation arg0) {

            }

        });
        startAnimation(animation);
    } else if (null != parent && parent instanceof ViewGroup) {
        ViewGroup parentGroup = (ViewGroup) parent;
        parentGroup.removeView(this);
        if (mScoreflexViewHandler != null) {
            mScoreflexViewHandler.onViewClosed();
            mScoreflexViewHandler = null;
        }
    }
}

From source file:net.grobas.widget.AutoLinearLayout.java

/**
 * Describes how the child views are positioned. Defaults to GRAVITY_TOP. If
 * this layout has a VERTICAL orientation, this controls where all the child
 * views are placed if there is extra vertical space. If this layout has a
 * HORIZONTAL orientation, this controls the alignment of the children.
 *
 * @param gravity See {@link android.view.Gravity}
 *//*from w  ww .j av  a 2 s.c  o  m*/
public void setGravity(int gravity) {
    if (mGravity != gravity) {
        if ((gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) {
            gravity |= GravityCompat.START;
        }

        if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) {
            gravity |= Gravity.TOP;
        }

        mGravity = gravity;
        requestLayout();
    }
}

From source file:com.scoreflex.ScoreflexView.java

protected int getLayoutGravity() {
    ViewGroup.LayoutParams currentLayoutParams = getLayoutParams();
    int gravity = Scoreflex.getDefaultGravity() & Gravity.VERTICAL_GRAVITY_MASK;
    if (currentLayoutParams instanceof FrameLayout.LayoutParams) {
        FrameLayout.LayoutParams frameLayoutParams = (FrameLayout.LayoutParams) currentLayoutParams;
        gravity = (Gravity.TOP == (frameLayoutParams.gravity & Gravity.VERTICAL_GRAVITY_MASK)) ? Gravity.TOP
                : Gravity.BOTTOM;/*from  w ww  .  j  a va 2  s  . c o m*/
    }
    return gravity;
}

From source file:com.scoreflex.ScoreflexView.java

protected View openNewView(String resource, Scoreflex.RequestParams params, boolean forceFullScreen) {
    int gravity = getLayoutGravity();
    int anim = (Gravity.TOP == (gravity & Gravity.VERTICAL_GRAVITY_MASK)) ? R.anim.scoreflex_enter_slide_down
            : R.anim.scoreflex_enter_slide_up;
    Animation animation = AnimationUtils.loadAnimation(mParentActivity, anim);

    ScoreflexView webview = new ScoreflexView(mParentActivity);
    webview.setResource(resource, params, forceFullScreen);
    ViewGroup contentView = (ViewGroup) mParentActivity.getWindow().getDecorView()
            .findViewById(android.R.id.content);
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, gravity);
    webview.setLayoutParams(layoutParams);
    contentView.addView(webview);// w  ww. j ava2s. c om
    webview.startAnimation(animation);
    Scoreflex.setCurrentScoreflexView(this);
    return webview;
}

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

/**
 * @param gravity/*from ww  w  . ja va  2 s .  com*/
 *            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 absVerticalGravity = 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) == absVerticalGravity) {
            return child;
        }
    }
    return null;
}

From source file:com.scoreflex.Scoreflex.java

/**
 * Changes the default gravity./* w w  w .j  av a 2  s . c  om*/
 *
 * @param defaultGravity
 *            The new default gravity.
 */
public static void setDefaultGravity(int defaultGravity) {
    if (Gravity.TOP == (defaultGravity & Gravity.VERTICAL_GRAVITY_MASK))
        sDefaultGravity = Gravity.TOP;
    else
        sDefaultGravity = Gravity.BOTTOM;
}

From source file:com.hippo.widget.slidingdrawerlayout.SlidingDrawerLayout.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;//from  ww w.  j  a  va2  s .c  om
    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 paddingTop = 0;
        int paddingBottom = mFitPaddingBottom;
        if (child instanceof DrawerLayoutChild) {
            DrawerLayoutChild dlc = (DrawerLayoutChild) child;
            paddingTop = dlc.getLayoutPaddingTop();
            paddingBottom = dlc.getLayoutPaddingBottom() + mFitPaddingBottom;
        }
        if (child == mContentView) {
            child.layout(lp.leftMargin, lp.topMargin + paddingTop, lp.leftMargin + child.getMeasuredWidth(),
                    lp.topMargin + paddingTop + 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 + paddingTop, childLeft + childWidth,
                        lp.topMargin + paddingTop + childHeight);
                break;
            }

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

            case Gravity.CENTER_VERTICAL: {
                final int height = b - t;
                int childTop = (height - childHeight - paddingTop - paddingBottom - lp.topMargin
                        - lp.bottomMargin) / 2 + paddingTop;
                // Offset for margins. If things don't fit right because of
                // bad measurement before, oh well.
                if (childTop < lp.topMargin + paddingTop) {
                    childTop = lp.topMargin + paddingTop;
                } else if (childTop + childHeight > height - paddingBottom - lp.bottomMargin) {
                    childTop = height - paddingBottom - 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;
}