Example usage for android.view Gravity getAbsoluteGravity

List of usage examples for android.view Gravity getAbsoluteGravity

Introduction

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

Prototype

public static int getAbsoluteGravity(int gravity, int layoutDirection) 

Source Link

Document

Convert script specific gravity to absolute horizontal value.

if horizontal direction is LTR, then START will set LEFT and END will set RIGHT.

Usage

From source file:com.cyanogenmod.filemanager.ui.widgets.DrawerLayout.java

/**
 * @param gravity the gravity of the child to return. If specified as a
 *            relative value, it will be resolved according to the current
 *            layout direction./*from   w ww .j  a v  a2 s. co  m*/
 * @return the drawer with the specified gravity
 */
View findDrawerWithGravity(int gravity) {
    final int absHorizGravity = Gravity.getAbsoluteGravity(gravity, this.getLayoutDirection())
            & Gravity.HORIZONTAL_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.HORIZONTAL_GRAVITY_MASK) == absHorizGravity) {
            return child;
        }
    }
    return null;
}

From source file:com.cyanogenmod.filemanager.ui.widgets.DrawerLayout.java

boolean isDrawerView(View child) {
    final int gravity = ((LayoutParams) child.getLayoutParams()).gravity;
    final int absGravity = Gravity.getAbsoluteGravity(gravity, child.getLayoutDirection());
    return (absGravity & (Gravity.LEFT | Gravity.RIGHT)) != 0;
}

From source file:com.android.incallui.widget.multiwaveview.GlowPadView.java

private void computeInsets(int dx, int dy) {
    final int layoutDirection = getLayoutDirection();
    final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection);

    switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.LEFT:
        mHorizontalInset = 0;// ww  w . j  a v  a  2  s.  c  o  m
        break;
    case Gravity.RIGHT:
        mHorizontalInset = dx;
        break;
    case Gravity.CENTER_HORIZONTAL:
    default:
        mHorizontalInset = dx / 2;
        break;
    }
    switch (absoluteGravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.TOP:
        mVerticalInset = 0;
        break;
    case Gravity.BOTTOM:
        mVerticalInset = dy;
        break;
    case Gravity.CENTER_VERTICAL:
    default:
        mVerticalInset = dy / 2;
        break;
    }
}

From source file:com.android.incallui.widget.multiwaveview.GlowPadView.java

/**
 * Given the desired width and height of the ring and the allocated width and height, compute
 * how much we need to scale the ring.//from  w  ww.ja va 2 s.c  o  m
 */
private float computeScaleFactor(int desiredWidth, int desiredHeight, int actualWidth, int actualHeight) {

    // Return unity if scaling is not allowed.
    if (!mAllowScaling)
        return 1f;

    final int layoutDirection = getLayoutDirection();
    final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection);

    float scaleX = 1f;
    float scaleY = 1f;

    // We use the gravity as a cue for whether we want to scale on a particular axis.
    // We only scale to fit horizontally if we're not pinned to the left or right. Likewise,
    // we only scale to fit vertically if we're not pinned to the top or bottom. In these
    // cases, we want the ring to hang off the side or top/bottom, respectively.
    switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.LEFT:
    case Gravity.RIGHT:
        break;
    case Gravity.CENTER_HORIZONTAL:
    default:
        if (desiredWidth > actualWidth) {
            scaleX = (1f * actualWidth - mMaxTargetWidth) / (desiredWidth - mMaxTargetWidth);
        }
        break;
    }
    switch (absoluteGravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.TOP:
    case Gravity.BOTTOM:
        break;
    case Gravity.CENTER_VERTICAL:
    default:
        if (desiredHeight > actualHeight) {
            scaleY = (1f * actualHeight - mMaxTargetHeight) / (desiredHeight - mMaxTargetHeight);
        }
        break;
    }
    return Math.min(scaleX, scaleY);
}

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)//from   w  w  w . j ava 2s  .co  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)/*from w  ww.j av  a  2s .  co m*/
        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)/*from w w  w. j  a v  a  2 s.  com*/
        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();
}