Example usage for android.view Gravity LEFT

List of usage examples for android.view Gravity LEFT

Introduction

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

Prototype

int LEFT

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

Click Source Link

Document

Push object to the left of its container, not changing its size.

Usage

From source file:ca.co.rufus.androidboilerplate.ui.DebugDrawerLayout.java

/**
 * Simple gravity to string - only supports LEFT and RIGHT for debugging output.
 *
 * @param gravity Absolute gravity value
 * @return LEFT or RIGHT as appropriate, or a hex string
 *//*ww  w  .j a  v a 2  s. c  om*/
static String gravityToString(@EdgeGravity int gravity) {
    if ((gravity & Gravity.LEFT) == Gravity.LEFT) {
        return "LEFT";
    }
    if ((gravity & Gravity.RIGHT) == Gravity.RIGHT) {
        return "RIGHT";
    }
    return Integer.toHexString(gravity);
}

From source file:com.hippo.ehviewer.ui.scene.FavoritesScene.java

@Override
@Implemented(EasyRecyclerView.CustomChoiceListener.class)
public void onIntoCustomChoice(EasyRecyclerView view) {
    if (mFabLayout != null) {
        mFabLayout.setExpanded(true);//  w  w  w.  j  a  v  a 2  s.  c  o  m
    }
    if (mHelper != null) {
        mHelper.setRefreshLayoutEnable(false);
    }
    // Lock drawer
    setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.LEFT);
    setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.RIGHT);
}

From source file:com.nickandjerry.dynamiclayoutinflator.DynamicLayoutInflator.java

private static int parseGravity(String value) {
    int gravity = Gravity.NO_GRAVITY;
    String[] parts = value.toLowerCase().split("[|]");
    for (String part : parts) {
        switch (part) {
        case "center":
            gravity = gravity | Gravity.CENTER;
            break;
        case "left":
        case "textStart":
            gravity = gravity | Gravity.LEFT;
            break;
        case "right":
        case "textEnd":
            gravity = gravity | Gravity.RIGHT;
            break;
        case "top":
            gravity = gravity | Gravity.TOP;
            break;
        case "bottom":
            gravity = gravity | Gravity.BOTTOM;
            break;
        case "center_horizontal":
            gravity = gravity | Gravity.CENTER_HORIZONTAL;
            break;
        case "center_vertical":
            gravity = gravity | Gravity.CENTER_VERTICAL;
            break;
        }//from   w w w  .j  a v  a2 s.  com
    }
    return gravity;
}

From source file:com.huangj.huangjlibrary.widget.drawerlayout.DrawerLayout.java

/**
 * Check the lock mode of the drawer with the given gravity.
 *
 * @param edgeGravity Gravity of the drawer to check
 * @return one of {@link #LOCK_MODE_UNLOCKED}, {@link #LOCK_MODE_LOCKED_CLOSED} or
 *         {@link #LOCK_MODE_LOCKED_OPEN}.
 *//*w  w w  .jav  a  2  s.  c  om*/
@LockMode
public int getDrawerLockMode(@EdgeGravity int edgeGravity) {
    int layoutDirection = ViewCompat.getLayoutDirection(this);

    switch (edgeGravity) {
    case Gravity.LEFT:
        if (mLockModeLeft != LOCK_MODE_UNDEFINED) {
            return mLockModeLeft;
        }
        int leftLockMode = (layoutDirection == ViewCompat.LAYOUT_DIRECTION_LTR) ? mLockModeStart : mLockModeEnd;
        if (leftLockMode != LOCK_MODE_UNDEFINED) {
            return leftLockMode;
        }
        break;
    case Gravity.RIGHT:
        if (mLockModeRight != LOCK_MODE_UNDEFINED) {
            return mLockModeRight;
        }
        int rightLockMode = (layoutDirection == ViewCompat.LAYOUT_DIRECTION_LTR) ? mLockModeEnd
                : mLockModeStart;
        if (rightLockMode != LOCK_MODE_UNDEFINED) {
            return rightLockMode;
        }
        break;
    case GravityCompat.START:
        if (mLockModeStart != LOCK_MODE_UNDEFINED) {
            return mLockModeStart;
        }
        int startLockMode = (layoutDirection == ViewCompat.LAYOUT_DIRECTION_LTR) ? mLockModeLeft
                : mLockModeRight;
        if (startLockMode != LOCK_MODE_UNDEFINED) {
            return startLockMode;
        }
        break;
    case GravityCompat.END:
        if (mLockModeEnd != LOCK_MODE_UNDEFINED) {
            return mLockModeEnd;
        }
        int endLockMode = (layoutDirection == ViewCompat.LAYOUT_DIRECTION_LTR) ? mLockModeRight : mLockModeLeft;
        if (endLockMode != LOCK_MODE_UNDEFINED) {
            return endLockMode;
        }
        break;
    }

    return LOCK_MODE_UNLOCKED;
}

From source file:com.hippo.ehviewer.ui.scene.FavoritesScene.java

@Override
@Implemented(EasyRecyclerView.CustomChoiceListener.class)
public void onOutOfCustomChoice(EasyRecyclerView view) {
    if (mFabLayout != null) {
        mFabLayout.setExpanded(false);/* ww w. j  a  va2 s  . c  om*/
    }
    if (mHelper != null) {
        mHelper.setRefreshLayoutEnable(true);
    }
    // Unlock drawer
    setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.LEFT);
    setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.RIGHT);
}

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

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    Log.i(TAG, "onLayout()");
    mInLayout = true;/*from  www .  j a 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();

        if (isContentView(child)) {
            child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(),
                    lp.topMargin + 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;

            final float newOffset;
            if (checkDrawerViewAbsoluteGravity(child, Gravity.LEFT)) {
                childLeft = -childWidth + (int) (childWidth * lp.onScreen);
                newOffset = (float) (childWidth + childLeft) / childWidth;
            } else { // Right; onMeasure checked for us.
                childLeft = width - (int) (childWidth * lp.onScreen);
                newOffset = (float) (width - childLeft) / childWidth;
            }

            final boolean changeOffset = newOffset != lp.onScreen;

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

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

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

            case Gravity.CENTER_VERTICAL: {
                final int height = b - t;
                int childTop = (height - childHeight) / 2;

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

            if (changeOffset) {
                setDrawerViewOffset(child, newOffset);
            }

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

From source file:android.support.designox.widget.CoordinatorLayout.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    prepareChildren();/*w w w .j a  v a 2s.  co m*/
    ensurePreDrawListener();

    final int paddingLeft = getPaddingLeft();
    final int paddingTop = getPaddingTop();
    final int paddingRight = getPaddingRight();
    final int paddingBottom = getPaddingBottom();
    final int layoutDirection = ViewCompat.getLayoutDirection(this);
    final boolean isRtl = layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL;
    final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    final int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    final int widthPadding = paddingLeft + paddingRight;
    final int heightPadding = paddingTop + paddingBottom;
    int widthUsed = getSuggestedMinimumWidth();
    int heightUsed = getSuggestedMinimumHeight();
    int childState = 0;

    final boolean applyInsets = mLastInsets != null && ViewCompat.getFitsSystemWindows(this);

    final int childCount = mDependencySortedChildren.size();
    for (int i = 0; i < childCount; i++) {
        final View child = mDependencySortedChildren.get(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        int keylineWidthUsed = 0;
        if (lp.keyline >= 0 && widthMode != MeasureSpec.UNSPECIFIED) {
            final int keylinePos = getKeyline(lp.keyline);
            final int keylineGravity = GravityCompat.getAbsoluteGravity(resolveKeylineGravity(lp.gravity),
                    layoutDirection) & Gravity.HORIZONTAL_GRAVITY_MASK;
            if ((keylineGravity == Gravity.LEFT && !isRtl) || (keylineGravity == Gravity.RIGHT && isRtl)) {
                keylineWidthUsed = Math.max(0, widthSize - paddingRight - keylinePos);
            } else if ((keylineGravity == Gravity.RIGHT && !isRtl)
                    || (keylineGravity == Gravity.LEFT && isRtl)) {
                keylineWidthUsed = Math.max(0, keylinePos - paddingLeft);
            }
        }

        int childWidthMeasureSpec = widthMeasureSpec;
        int childHeightMeasureSpec = heightMeasureSpec;
        if (applyInsets && !ViewCompat.getFitsSystemWindows(child)) {
            // We're set to handle insets but this child isn't, so we will measure the
            // child as if there are no insets
            final int horizInsets = mLastInsets.getSystemWindowInsetLeft()
                    + mLastInsets.getSystemWindowInsetRight();
            final int vertInsets = mLastInsets.getSystemWindowInsetTop()
                    + mLastInsets.getSystemWindowInsetBottom();

            childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(widthSize - horizInsets, widthMode);
            childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize - vertInsets, heightMode);
        }

        final Behavior b = lp.getBehavior();
        if (b == null || !b.onMeasureChild(this, child, childWidthMeasureSpec, keylineWidthUsed,
                childHeightMeasureSpec, 0)) {
            onMeasureChild(child, childWidthMeasureSpec, keylineWidthUsed, childHeightMeasureSpec, 0);
        }

        widthUsed = Math.max(widthUsed,
                widthPadding + child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin);

        heightUsed = Math.max(heightUsed,
                heightPadding + child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin);
        childState = ViewCompat.combineMeasuredStates(childState, ViewCompat.getMeasuredState(child));
    }

    final int width = ViewCompat.resolveSizeAndState(widthUsed, widthMeasureSpec,
            childState & ViewCompat.MEASURED_STATE_MASK);
    final int height = ViewCompat.resolveSizeAndState(heightUsed, heightMeasureSpec,
            childState << ViewCompat.MEASURED_HEIGHT_STATE_SHIFT);
    setMeasuredDimension(width, height);
}

From source file:android.car.ui.provider.CarDrawerLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final int height = getHeight();
    final boolean drawingContent = isContentView(child);
    int clipLeft = findContentView().getLeft();
    int clipRight = findContentView().getRight();
    final int baseAlpha = (mScrimColor & 0xff000000) >>> 24;

    final int restoreCount = canvas.save();
    if (drawingContent) {
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View v = getChildAt(i);
            if (v == child || v.getVisibility() != VISIBLE || !hasOpaqueBackground(v) || !isDrawerView(v)
                    || v.getHeight() < height) {
                continue;
            }//from ww w  . j  a v a 2 s.com

            if (checkDrawerViewAbsoluteGravity(v, Gravity.LEFT)) {
                final int vright = v.getRight();
                if (vright > clipLeft) {
                    clipLeft = vright;
                }
            } else {
                final int vleft = v.getLeft();
                if (vleft < clipRight) {
                    clipRight = vleft;
                }
            }
        }
        canvas.clipRect(clipLeft, 0, clipRight, getHeight());
    }
    final boolean result = super.drawChild(canvas, child, drawingTime);
    canvas.restoreToCount(restoreCount);

    if (drawingContent) {
        int scrimAlpha = SCRIM_ENABLED
                ? (int) (baseAlpha * Math.max(0, Math.min(1, onScreen())) * MAX_SCRIM_ALPHA)
                : 0;

        if (scrimAlpha > 0) {
            int color = scrimAlpha << 24 | (mScrimColor & 0xffffff);
            mScrimPaint.setColor(color);

            canvas.drawRect(clipLeft, 0, clipRight, getHeight(), mScrimPaint);

            canvas.drawRect(clipLeft - 1, 0, clipLeft, getHeight(), mEdgeHighlightPaint);
        }

        LayoutParams drawerLp = (LayoutParams) findDrawerView().getLayoutParams();
        if (mShadow != null && checkDrawerViewAbsoluteGravity(findDrawerView(), Gravity.LEFT)) {
            final int offScreen = (int) ((1 - drawerLp.onScreen) * findDrawerView().getWidth());
            final int drawerRight = getWidth() - drawerLp.getMarginEnd() - offScreen;
            final int shadowWidth = mShadow.getIntrinsicWidth();
            final float alpha = Math.max(0, Math.min((float) drawerRight / mDragger.getEdgeSize(), 1.f));
            mShadow.setBounds(drawerRight, child.getTop(), drawerRight + shadowWidth, child.getBottom());
            mShadow.setAlpha((int) (255 * alpha * alpha * alpha));
            mShadow.draw(canvas);
        } else if (mShadow != null && checkDrawerViewAbsoluteGravity(findDrawerView(), Gravity.RIGHT)) {
            final int onScreen = (int) (findDrawerView().getWidth() * drawerLp.onScreen);
            final int drawerLeft = drawerLp.getMarginStart() + getWidth() - onScreen;
            final int shadowWidth = mShadow.getIntrinsicWidth();
            final float alpha = Math.max(0, Math.min((float) onScreen / mDragger.getEdgeSize(), 1.f));
            canvas.save();
            canvas.translate(2 * drawerLeft - shadowWidth, 0);
            canvas.scale(-1.0f, 1.0f);
            mShadow.setBounds(drawerLeft - shadowWidth, child.getTop(), drawerLeft, child.getBottom());
            mShadow.setAlpha((int) (255 * alpha * alpha * alpha * alpha));
            mShadow.draw(canvas);
            canvas.restore();
        }
    }
    return result;
}

From source file:com.abewy.android.apps.klyph.widget.KlyphDrawerLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final int height = getHeight();
    final boolean drawingContent = isContentView(child);
    int clipLeft = 0, clipRight = getWidth();

    final int restoreCount = canvas.save();
    if (drawingContent) {
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View v = getChildAt(i);
            if (v == child || v.getVisibility() != VISIBLE || !hasOpaqueBackground(v) || !isDrawerView(v)
                    || v.getHeight() < height) {
                continue;
            }//from w ww. jav  a 2s . com

            if (checkDrawerViewGravity(v, Gravity.LEFT)) {
                final int vright = v.getRight();
                if (vright > clipLeft)
                    clipLeft = vright;
            } else {
                final int vleft = v.getLeft();
                if (vleft < clipRight)
                    clipRight = vleft;
            }
        }
        canvas.clipRect(clipLeft, 0, clipRight, getHeight());
    }
    final boolean result = super.drawChild(canvas, child, drawingTime);
    canvas.restoreToCount(restoreCount);

    if (mScrimOpacity > 0 && drawingContent) {
        final int baseAlpha = (mScrimColor & 0xff000000) >>> 24;
        final int imag = (int) (baseAlpha * mScrimOpacity);
        final int color = imag << 24 | (mScrimColor & 0xffffff);
        mScrimPaint.setColor(color);

        canvas.drawRect(clipLeft, 0, clipRight, getHeight(), mScrimPaint);
    } else if (mShadowLeft != null && checkDrawerViewGravity(child, Gravity.LEFT)) {
        final int shadowWidth = mShadowLeft.getIntrinsicWidth();
        final int childRight = child.getRight();
        final int drawerPeekDistance = mLeftDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) childRight / drawerPeekDistance, 1.f));
        mShadowLeft.setBounds(childRight, child.getTop(), childRight + shadowWidth, child.getBottom());
        mShadowLeft.setAlpha((int) (0xff * alpha));
        mShadowLeft.draw(canvas);
    } else if (mShadowRight != null && checkDrawerViewGravity(child, Gravity.RIGHT)) {
        final int shadowWidth = mShadowRight.getIntrinsicWidth();
        final int childLeft = child.getLeft();
        final int showing = getWidth() - childLeft;
        final int drawerPeekDistance = mRightDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f));
        mShadowRight.setBounds(childLeft - shadowWidth, child.getTop(), childLeft, child.getBottom());
        mShadowRight.setAlpha((int) (0xff * alpha));
        mShadowRight.draw(canvas);
    }
    return result;
}