Java Code Examples for android.view.Gravity#AXIS_Y_SHIFT

The following examples show how to use android.view.Gravity#AXIS_Y_SHIFT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommonLogic.java    From Last-Launcher with GNU General Public License v3.0 6 votes vote down vote up
public static int getGravityFromRelative(int childGravity, ConfigDefinition config) {
    // swap directions for vertical non relative view
    // if it is relative, then START is TOP, and we do not need to switch it here.
    // it will be switched later on onMeasure stage when calculations will be with length and thickness
    if (config.getOrientation() == CommonLogic.VERTICAL && (childGravity & Gravity.RELATIVE_LAYOUT_DIRECTION) == 0) {
        int horizontalGravity = childGravity;
        childGravity = 0;
        childGravity |= (horizontalGravity & Gravity.HORIZONTAL_GRAVITY_MASK) >> Gravity.AXIS_X_SHIFT << Gravity.AXIS_Y_SHIFT;
        childGravity |= (horizontalGravity & Gravity.VERTICAL_GRAVITY_MASK) >> Gravity.AXIS_Y_SHIFT << Gravity.AXIS_X_SHIFT;
    }

    // for relative layout and RTL direction swap left and right gravity
    if (config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL && (childGravity & Gravity.RELATIVE_LAYOUT_DIRECTION) != 0) {
        int ltrGravity = childGravity;
        childGravity = 0;
        childGravity |= (ltrGravity & Gravity.LEFT) == Gravity.LEFT ? Gravity.RIGHT : 0;
        childGravity |= (ltrGravity & Gravity.RIGHT) == Gravity.RIGHT ? Gravity.LEFT : 0;
    }

    return childGravity;
}
 
Example 2
Source File: QiscusFlowLayout.java    From qiscus-sdk-android with Apache License 2.0 6 votes vote down vote up
private int getGravityFromRelative(int childGravity) {
    // swap directions for vertical non relative view
    // if it is relative, then START is TOP, and we do not need to switch it here.
    // it will be switched later on onMeasure stage when calculations will be with length and thickness
    if (this.config.getOrientation() == VERTICAL && (childGravity & Gravity.RELATIVE_LAYOUT_DIRECTION) == 0) {
        int horizontalGravity = childGravity;
        childGravity = 0;
        childGravity |= (horizontalGravity & Gravity.HORIZONTAL_GRAVITY_MASK) >> Gravity.AXIS_X_SHIFT << Gravity.AXIS_Y_SHIFT;
        childGravity |= (horizontalGravity & Gravity.VERTICAL_GRAVITY_MASK) >> Gravity.AXIS_Y_SHIFT << Gravity.AXIS_X_SHIFT;
    }

    // for relative layout and RTL direction swap left and right gravity
    if (this.config.getLayoutDirection() == LAYOUT_DIRECTION_RTL && (childGravity & Gravity.RELATIVE_LAYOUT_DIRECTION) != 0) {
        int ltrGravity = childGravity;
        childGravity = 0;
        childGravity |= (ltrGravity & Gravity.LEFT) == Gravity.LEFT ? Gravity.RIGHT : 0;
        childGravity |= (ltrGravity & Gravity.RIGHT) == Gravity.RIGHT ? Gravity.LEFT : 0;
    }

    return childGravity;
}
 
Example 3
Source File: Compat.java    From ProjectX with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("SameParameterValue")
private static void apply(int gravity, float w, float h, Rect container,
                          float xAdj, float yAdj, RectF outRect) {
    switch (gravity & ((Gravity.AXIS_PULL_BEFORE | Gravity.AXIS_PULL_AFTER) <<
            Gravity.AXIS_X_SHIFT)) {
        case 0:
            outRect.left = container.left
                    + ((container.right - container.left - w) * 0.5f) + xAdj;
            outRect.right = outRect.left + w;
            if ((gravity & (Gravity.AXIS_CLIP << Gravity.AXIS_X_SHIFT))
                    == (Gravity.AXIS_CLIP << Gravity.AXIS_X_SHIFT)) {
                if (outRect.left < container.left) {
                    outRect.left = container.left;
                }
                if (outRect.right > container.right) {
                    outRect.right = container.right;
                }
            }
            break;
        case Gravity.AXIS_PULL_BEFORE << Gravity.AXIS_X_SHIFT:
            outRect.left = container.left + xAdj;
            outRect.right = outRect.left + w;
            if ((gravity & (Gravity.AXIS_CLIP << Gravity.AXIS_X_SHIFT))
                    == (Gravity.AXIS_CLIP << Gravity.AXIS_X_SHIFT)) {
                if (outRect.right > container.right) {
                    outRect.right = container.right;
                }
            }
            break;
        case Gravity.AXIS_PULL_AFTER << Gravity.AXIS_X_SHIFT:
            outRect.right = container.right - xAdj;
            outRect.left = outRect.right - w;
            if ((gravity & (Gravity.AXIS_CLIP << Gravity.AXIS_X_SHIFT))
                    == (Gravity.AXIS_CLIP << Gravity.AXIS_X_SHIFT)) {
                if (outRect.left < container.left) {
                    outRect.left = container.left;
                }
            }
            break;
        default:
            outRect.left = container.left + xAdj;
            outRect.right = container.right + xAdj;
            break;
    }

    switch (gravity & ((Gravity.AXIS_PULL_BEFORE | Gravity.AXIS_PULL_AFTER) <<
            Gravity.AXIS_Y_SHIFT)) {
        case 0:
            outRect.top = container.top
                    + ((container.bottom - container.top - h) * 0.5f) + yAdj;
            outRect.bottom = outRect.top + h;
            if ((gravity & (Gravity.AXIS_CLIP << Gravity.AXIS_Y_SHIFT))
                    == (Gravity.AXIS_CLIP << Gravity.AXIS_Y_SHIFT)) {
                if (outRect.top < container.top) {
                    outRect.top = container.top;
                }
                if (outRect.bottom > container.bottom) {
                    outRect.bottom = container.bottom;
                }
            }
            break;
        case Gravity.AXIS_PULL_BEFORE << Gravity.AXIS_Y_SHIFT:
            outRect.top = container.top + yAdj;
            outRect.bottom = outRect.top + h;
            if ((gravity & (Gravity.AXIS_CLIP << Gravity.AXIS_Y_SHIFT))
                    == (Gravity.AXIS_CLIP << Gravity.AXIS_Y_SHIFT)) {
                if (outRect.bottom > container.bottom) {
                    outRect.bottom = container.bottom;
                }
            }
            break;
        case Gravity.AXIS_PULL_AFTER << Gravity.AXIS_Y_SHIFT:
            outRect.bottom = container.bottom - yAdj;
            outRect.top = outRect.bottom - h;
            if ((gravity & (Gravity.AXIS_CLIP << Gravity.AXIS_Y_SHIFT))
                    == (Gravity.AXIS_CLIP << Gravity.AXIS_Y_SHIFT)) {
                if (outRect.top < container.top) {
                    outRect.top = container.top;
                }
            }
            break;
        default:
            outRect.top = container.top + yAdj;
            outRect.bottom = container.bottom + yAdj;
            break;
    }
}
 
Example 4
Source File: Compat.java    From ProjectX with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("SameParameterValue")
private static void apply(int gravity, float w, float h, RectF container,
                          float xAdj, float yAdj, RectF outRect) {
    switch (gravity & ((Gravity.AXIS_PULL_BEFORE | Gravity.AXIS_PULL_AFTER) <<
            Gravity.AXIS_X_SHIFT)) {
        case 0:
            outRect.left = container.left
                    + ((container.right - container.left - w) * 0.5f) + xAdj;
            outRect.right = outRect.left + w;
            if ((gravity & (Gravity.AXIS_CLIP << Gravity.AXIS_X_SHIFT))
                    == (Gravity.AXIS_CLIP << Gravity.AXIS_X_SHIFT)) {
                if (outRect.left < container.left) {
                    outRect.left = container.left;
                }
                if (outRect.right > container.right) {
                    outRect.right = container.right;
                }
            }
            break;
        case Gravity.AXIS_PULL_BEFORE << Gravity.AXIS_X_SHIFT:
            outRect.left = container.left + xAdj;
            outRect.right = outRect.left + w;
            if ((gravity & (Gravity.AXIS_CLIP << Gravity.AXIS_X_SHIFT))
                    == (Gravity.AXIS_CLIP << Gravity.AXIS_X_SHIFT)) {
                if (outRect.right > container.right) {
                    outRect.right = container.right;
                }
            }
            break;
        case Gravity.AXIS_PULL_AFTER << Gravity.AXIS_X_SHIFT:
            outRect.right = container.right - xAdj;
            outRect.left = outRect.right - w;
            if ((gravity & (Gravity.AXIS_CLIP << Gravity.AXIS_X_SHIFT))
                    == (Gravity.AXIS_CLIP << Gravity.AXIS_X_SHIFT)) {
                if (outRect.left < container.left) {
                    outRect.left = container.left;
                }
            }
            break;
        default:
            outRect.left = container.left + xAdj;
            outRect.right = container.right + xAdj;
            break;
    }

    switch (gravity & ((Gravity.AXIS_PULL_BEFORE | Gravity.AXIS_PULL_AFTER) <<
            Gravity.AXIS_Y_SHIFT)) {
        case 0:
            outRect.top = container.top
                    + ((container.bottom - container.top - h) * 0.5f) + yAdj;
            outRect.bottom = outRect.top + h;
            if ((gravity & (Gravity.AXIS_CLIP << Gravity.AXIS_Y_SHIFT))
                    == (Gravity.AXIS_CLIP << Gravity.AXIS_Y_SHIFT)) {
                if (outRect.top < container.top) {
                    outRect.top = container.top;
                }
                if (outRect.bottom > container.bottom) {
                    outRect.bottom = container.bottom;
                }
            }
            break;
        case Gravity.AXIS_PULL_BEFORE << Gravity.AXIS_Y_SHIFT:
            outRect.top = container.top + yAdj;
            outRect.bottom = outRect.top + h;
            if ((gravity & (Gravity.AXIS_CLIP << Gravity.AXIS_Y_SHIFT))
                    == (Gravity.AXIS_CLIP << Gravity.AXIS_Y_SHIFT)) {
                if (outRect.bottom > container.bottom) {
                    outRect.bottom = container.bottom;
                }
            }
            break;
        case Gravity.AXIS_PULL_AFTER << Gravity.AXIS_Y_SHIFT:
            outRect.bottom = container.bottom - yAdj;
            outRect.top = outRect.bottom - h;
            if ((gravity & (Gravity.AXIS_CLIP << Gravity.AXIS_Y_SHIFT))
                    == (Gravity.AXIS_CLIP << Gravity.AXIS_Y_SHIFT)) {
                if (outRect.top < container.top) {
                    outRect.top = container.top;
                }
            }
            break;
        default:
            outRect.top = container.top + yAdj;
            outRect.bottom = container.bottom + yAdj;
            break;
    }
}