Example usage for android.view Gravity RELATIVE_HORIZONTAL_GRAVITY_MASK

List of usage examples for android.view Gravity RELATIVE_HORIZONTAL_GRAVITY_MASK

Introduction

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

Prototype

int RELATIVE_HORIZONTAL_GRAVITY_MASK

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

Click Source Link

Document

Binary mask for the horizontal gravity and script specific direction bit.

Usage

From source file:Main.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Layout.Alignment getLayoutAlignment(TextView textView) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return Layout.Alignment.ALIGN_NORMAL;
    }//from  w  w w.j  a  v  a2 s .  com

    Layout.Alignment alignment;
    switch (textView.getTextAlignment()) {
    case TextView.TEXT_ALIGNMENT_GRAVITY:
        switch (textView.getGravity() & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) {
        case Gravity.START:
            alignment = Layout.Alignment.ALIGN_NORMAL;
            break;
        case Gravity.END:
            alignment = Layout.Alignment.ALIGN_OPPOSITE;
            break;
        case Gravity.LEFT:
            alignment = (textView.getLayoutDirection() == TextView.LAYOUT_DIRECTION_RTL)
                    ? Layout.Alignment.ALIGN_OPPOSITE
                    : Layout.Alignment.ALIGN_NORMAL;
            break;
        case Gravity.RIGHT:
            alignment = (textView.getLayoutDirection() == TextView.LAYOUT_DIRECTION_RTL)
                    ? Layout.Alignment.ALIGN_NORMAL
                    : Layout.Alignment.ALIGN_OPPOSITE;
            break;
        case Gravity.CENTER_HORIZONTAL:
            alignment = Layout.Alignment.ALIGN_CENTER;
            break;
        default:
            alignment = Layout.Alignment.ALIGN_NORMAL;
            break;
        }
        break;
    case TextView.TEXT_ALIGNMENT_TEXT_START:
        alignment = Layout.Alignment.ALIGN_NORMAL;
        break;
    case TextView.TEXT_ALIGNMENT_TEXT_END:
        alignment = Layout.Alignment.ALIGN_OPPOSITE;
        break;
    case TextView.TEXT_ALIGNMENT_CENTER:
        alignment = Layout.Alignment.ALIGN_CENTER;
        break;
    case TextView.TEXT_ALIGNMENT_VIEW_START:
        alignment = Layout.Alignment.ALIGN_NORMAL;
        break;
    case TextView.TEXT_ALIGNMENT_VIEW_END:
        alignment = Layout.Alignment.ALIGN_OPPOSITE;
        break;
    case TextView.TEXT_ALIGNMENT_INHERIT:
        //
    default:
        alignment = Layout.Alignment.ALIGN_NORMAL;
        break;
    }
    return alignment;
}

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 ww w. j a v a  2 s.c  om
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:net.grobas.widget.AutoLinearLayout.java

public void setHorizontalGravity(int horizontalGravity) {
    final int gravity = horizontalGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK;
    if ((mGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) != gravity) {
        mGravity = (mGravity & ~GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) | gravity;
        requestLayout();//w  w w. j  a v a  2 s.co m
    }
}

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

private static Alignment getAlignment(int gravity) {
    final Alignment alignment;
    switch (gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) {
    case Gravity.START:
        alignment = ALIGN_NORMAL;// w ww  .  j  ava 2  s.c om
        break;
    case Gravity.END:
        alignment = ALIGN_OPPOSITE;
        break;
    case Gravity.LEFT: // unsupported, default to normal
        alignment = ALIGN_NORMAL;
        break;
    case Gravity.RIGHT: // unsupported, default to opposite
        alignment = ALIGN_OPPOSITE;
        break;
    case Gravity.CENTER_HORIZONTAL:
        alignment = ALIGN_CENTER;
        break;
    default:
        alignment = textAlignment;
        break;
    }
    return alignment;
}

From source file:io.github.clendy.leanback.widget.GridLayoutManager.java

private void layoutChild(int rowIndex, View v, int start, int end, int startSecondary) {
    if (TRACE)//  w w w.ja v a2 s. c o m
        TraceHelper.beginSection("layoutChild");
    int sizeSecondary = mOrientation == HORIZONTAL ? v.getMeasuredHeight() : v.getMeasuredWidth();
    if (mFixedRowSizeSecondary > 0) {
        sizeSecondary = Math.min(sizeSecondary, mFixedRowSizeSecondary);
    }
    final int verticalGravity = mGravity & Gravity.VERTICAL_GRAVITY_MASK;
    final int horizontalGravity = (mReverseFlowPrimary || mReverseFlowSecondary)
            ? Gravity.getAbsoluteGravity(mGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK,
                    View.LAYOUT_DIRECTION_RTL)
            : mGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    if (mOrientation == HORIZONTAL && verticalGravity == Gravity.TOP
            || mOrientation == VERTICAL && horizontalGravity == Gravity.LEFT) {
        // do nothing
    } else if (mOrientation == HORIZONTAL && verticalGravity == Gravity.BOTTOM
            || mOrientation == VERTICAL && horizontalGravity == Gravity.RIGHT) {
        startSecondary += getRowSizeSecondary(rowIndex) - sizeSecondary;
    } else if (mOrientation == HORIZONTAL && verticalGravity == Gravity.CENTER_VERTICAL
            || mOrientation == VERTICAL && horizontalGravity == Gravity.CENTER_HORIZONTAL) {
        startSecondary += (getRowSizeSecondary(rowIndex) - sizeSecondary) / 2;
    }
    int left, top, right, bottom;
    if (mOrientation == HORIZONTAL) {
        left = start;
        top = startSecondary;
        right = end;
        bottom = startSecondary + sizeSecondary;
    } else {
        top = start;
        left = startSecondary;
        bottom = end;
        right = startSecondary + sizeSecondary;
    }
    v.layout(left, top, right, bottom);
    updateChildOpticalInsets(v, left, top, right, bottom);
    updateChildAlignments(v);
    if (TRACE)
        TraceHelper.endSection();
}

From source file:com.rbware.github.androidcouchpotato.widget.GridLayoutManager.java

void layoutChild(int rowIndex, View v, int start, int end, int startSecondary) {
    if (TRACE)//  w  w w .  j a va2s  .  c  om
        TraceHelper.beginSection("layoutChild");
    int sizeSecondary = mOrientation == HORIZONTAL ? getDecoratedMeasuredHeightWithMargin(v)
            : getDecoratedMeasuredWidthWithMargin(v);
    if (mFixedRowSizeSecondary > 0) {
        sizeSecondary = Math.min(sizeSecondary, mFixedRowSizeSecondary);
    }
    final int verticalGravity = mGravity & Gravity.VERTICAL_GRAVITY_MASK;
    final int horizontalGravity = (mReverseFlowPrimary || mReverseFlowSecondary)
            ? Gravity.getAbsoluteGravity(mGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK,
                    View.LAYOUT_DIRECTION_RTL)
            : mGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    if (mOrientation == HORIZONTAL && verticalGravity == Gravity.TOP
            || mOrientation == VERTICAL && horizontalGravity == Gravity.LEFT) {
        // do nothing
    } else if (mOrientation == HORIZONTAL && verticalGravity == Gravity.BOTTOM
            || mOrientation == VERTICAL && horizontalGravity == Gravity.RIGHT) {
        startSecondary += getRowSizeSecondary(rowIndex) - sizeSecondary;
    } else if (mOrientation == HORIZONTAL && verticalGravity == Gravity.CENTER_VERTICAL
            || mOrientation == VERTICAL && horizontalGravity == Gravity.CENTER_HORIZONTAL) {
        startSecondary += (getRowSizeSecondary(rowIndex) - sizeSecondary) / 2;
    }
    int left, top, right, bottom;
    if (mOrientation == HORIZONTAL) {
        left = start;
        top = startSecondary;
        right = end;
        bottom = startSecondary + sizeSecondary;
    } else {
        top = start;
        left = startSecondary;
        bottom = end;
        right = startSecondary + sizeSecondary;
    }
    LayoutParams params = (LayoutParams) v.getLayoutParams();
    layoutDecoratedWithMargins(v, left, top, right, bottom);
    // Now super.getDecoratedBoundsWithMargins() includes the extra space for optical bounds,
    // subtracting it from value passed in layoutDecoratedWithMargins(), we can get the optical
    // bounds insets.
    super.getDecoratedBoundsWithMargins(v, sTempRect);
    params.setOpticalInsets(left - sTempRect.left, top - sTempRect.top, sTempRect.right - right,
            sTempRect.bottom - bottom);
    updateChildAlignments(v);
    if (TRACE)
        TraceHelper.endSection();
}

From source file:android.support.v17.leanback.widget.GridLayoutManager.java

private void layoutChild(int rowIndex, View v, int start, int end, int startSecondary) {
    if (TRACE)// w  ww . j a v a2  s. c  om
        TraceHelper.beginSection("layoutChild");
    int sizeSecondary = mOrientation == HORIZONTAL ? getDecoratedMeasuredHeightWithMargin(v)
            : getDecoratedMeasuredWidthWithMargin(v);
    if (mFixedRowSizeSecondary > 0) {
        sizeSecondary = Math.min(sizeSecondary, mFixedRowSizeSecondary);
    }
    final int verticalGravity = mGravity & Gravity.VERTICAL_GRAVITY_MASK;
    final int horizontalGravity = (mReverseFlowPrimary || mReverseFlowSecondary)
            ? Gravity.getAbsoluteGravity(mGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK,
                    View.LAYOUT_DIRECTION_RTL)
            : mGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    if (mOrientation == HORIZONTAL && verticalGravity == Gravity.TOP
            || mOrientation == VERTICAL && horizontalGravity == Gravity.LEFT) {
        // do nothing
    } else if (mOrientation == HORIZONTAL && verticalGravity == Gravity.BOTTOM
            || mOrientation == VERTICAL && horizontalGravity == Gravity.RIGHT) {
        startSecondary += getRowSizeSecondary(rowIndex) - sizeSecondary;
    } else if (mOrientation == HORIZONTAL && verticalGravity == Gravity.CENTER_VERTICAL
            || mOrientation == VERTICAL && horizontalGravity == Gravity.CENTER_HORIZONTAL) {
        startSecondary += (getRowSizeSecondary(rowIndex) - sizeSecondary) / 2;
    }
    int left, top, right, bottom;
    if (mOrientation == HORIZONTAL) {
        left = start;
        top = startSecondary;
        right = end;
        bottom = startSecondary + sizeSecondary;
    } else {
        top = start;
        left = startSecondary;
        bottom = end;
        right = startSecondary + sizeSecondary;
    }
    LayoutParams params = (LayoutParams) v.getLayoutParams();
    layoutDecoratedWithMargins(v, left, top, right, bottom);
    // Now super.getDecoratedBoundsWithMargins() includes the extra space for optical bounds,
    // subtracting it from value passed in layoutDecoratedWithMargins(), we can get the optical
    // bounds insets.
    super.getDecoratedBoundsWithMargins(v, sTempRect);
    params.setOpticalInsets(left - sTempRect.left, top - sTempRect.top, sTempRect.right - right,
            sTempRect.bottom - bottom);
    updateChildAlignments(v);
    if (TRACE)
        TraceHelper.endSection();
}