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.sinyuk.jianyi.utils.list.SlideInItemAnimator.java

public SlideInItemAnimator(int slideFromEdge, int layoutDirection) {
    this.slideFromEdge = Gravity.getAbsoluteGravity(slideFromEdge, layoutDirection);
    setAddDuration(160L);/* w ww  .jav a 2 s.c  om*/
}

From source file:se.johan.wendler.ui.view.DragGripView.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    float drawWidth = HORIZ_RIDGES * (mRidgeSize + mRidgeGap) - mRidgeGap;
    float drawLeft;

    switch (Gravity.getAbsoluteGravity(mGravity, ViewCompat.getLayoutDirection(this))
            & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        drawLeft = getPaddingLeft() + ((mWidth - getPaddingLeft() - getPaddingRight()) - drawWidth) / 2;
        break;/*from ww w  .ja va  2s.c o m*/
    case GravityCompat.END:
        drawLeft = getWidth() - getPaddingRight() - drawWidth;
        break;
    default:
        drawLeft = getPaddingLeft();
    }

    int vertRidges = (int) ((mHeight - getPaddingTop() - getPaddingBottom() + mRidgeGap)
            / (mRidgeSize + mRidgeGap));
    float drawHeight = vertRidges * (mRidgeSize + mRidgeGap) - mRidgeGap;
    float drawTop = getPaddingTop() + ((mHeight - getPaddingTop() - getPaddingBottom()) - drawHeight) / 2;

    for (int y = 0; y < vertRidges; y++) {
        for (int x = 0; x < HORIZ_RIDGES; x++) {
            canvas.drawRect(drawLeft + x * (mRidgeSize + mRidgeGap), drawTop + y * (mRidgeSize + mRidgeGap),
                    drawLeft + x * (mRidgeSize + mRidgeGap) + mRidgeSize,
                    drawTop + y * (mRidgeSize + mRidgeGap) + mRidgeSize, mRidgePaint);
        }
    }
}

From source file:li.barter.widgets.FullWidthDrawerLayout.java

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

From source file:li.barter.widgets.FullWidthDrawerLayout.java

int getDrawerViewGravity(final View drawerView) {
    final int gravity = ((LayoutParams) drawerView.getLayoutParams()).gravity;
    return Gravity.getAbsoluteGravity(gravity,
            GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(drawerView)));
}

From source file:com.andremion.floatingnavigationview.FloatingNavigationView.java

private void attachNavigationView() {

    CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) getLayoutParams();
    int gravity = Gravity.LEFT;
    if (layoutParams.getAnchorId() != View.NO_ID && layoutParams.anchorGravity != Gravity.NO_GRAVITY) {
        if (Gravity.isHorizontal(layoutParams.anchorGravity)) {
            gravity = layoutParams.anchorGravity;
        }//from  w  w  w. j  av a2 s  . co m
    } else if (layoutParams.gravity != Gravity.NO_GRAVITY) {
        if (Gravity.isHorizontal(layoutParams.gravity)) {
            gravity = layoutParams.gravity;
        }
    }

    // Gravity.START and Gravity.END don't work for views added in WindowManager with RTL.
    // We need to convert script specific gravity to absolute horizontal value
    // If horizontal direction is LTR, then START will set LEFT and END will set RIGHT.
    // If horizontal direction is RTL, then START will set RIGHT and END will set LEFT.
    gravity = Gravity.getAbsoluteGravity(gravity, getLayoutDirection());

    mWindowManager.addView(mNavigationView, createLayoutParams(gravity));
}

From source file:com.nile.kmooc.view.custom.popup.menu.MenuPopupHelper.java

public boolean tryShow() {
    mPopup = new ListPopupWindow(mContext, null, mPopupStyleAttr, mPopupStyleRes);
    mPopup.setOnDismissListener(this);
    mPopup.setOnItemClickListener(this);
    mPopup.setAdapter(mAdapter);//from www. ja v  a 2 s.com
    mPopup.setModal(true);

    View anchor = mAnchorView;
    if (anchor != null) {
        final boolean addGlobalListener = mTreeObserver == null;
        mTreeObserver = anchor.getViewTreeObserver(); // Refresh to latest
        if (addGlobalListener)
            mTreeObserver.addOnGlobalLayoutListener(this);
        anchor.addOnAttachStateChangeListener(this);
        mPopup.setAnchorView(anchor);
        mPopup.setDropDownGravity(mDropDownGravity);
    } else {
        return false;
    }

    if (mContentWidth == Integer.MIN_VALUE) {
        mContentWidth = measureContentWidth();
    }
    mPopup.setContentWidth(mContentWidth);
    // Invert the horizontal offset in RTL mode.
    if (ViewCompat.getLayoutDirection(mAnchorView) == ViewCompat.LAYOUT_DIRECTION_RTL) {
        mPopup.setHorizontalOffset(-mPopup.getHorizontalOffset());
    }
    // Implement right gravity manually through horizontal offset pre-KitKat.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT
            && (Gravity.getAbsoluteGravity(mDropDownGravity, ViewCompat.getLayoutDirection(anchor))
                    & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.RIGHT) {
        mPopup.setHorizontalOffset(mPopup.getHorizontalOffset() + (mAnchorView.getWidth() - mPopup.getWidth()));
    }
    // If vertical offset is defined as 0, then ListPopupWindow infers
    // it as the negative of the top padding of the background, in
    // order to anchor the content area. Since that is not the effect
    // we want, we'll force it to use only the explicitly defined
    // offset by explicitly setting it dynamically as well, and thus
    // forcing it to discard it's 'unset' flag.
    mPopup.setVerticalOffset(mPopup.getVerticalOffset());
    // Top/bottom padding will be applied on the background drawable,
    // as the ListView is both initialized and set up only after show()
    // is called on the ListPopupWindow. Left/right padding will be
    // set up on the list items from the adapter, to keep the correct
    // item boundaries for the selector.
    ShapeDrawable paddedDrawable = new ShapeDrawable();
    paddedDrawable.setAlpha(0);
    // Don't apply top padding if the first item is a header, to
    // comply with the design.
    paddedDrawable.setPadding(0, mAdapter.hasHeader() ? 0 : (mPopupPaddingTop - mPopupItemVerticalPadding), 0,
            mPopupPaddingBottom - mPopupItemVerticalPadding);
    Drawable background = mPopup.getBackground();
    mPopup.setBackgroundDrawable(background == null ? paddedDrawable
            : new LayerDrawable(new Drawable[] { background, paddedDrawable }));
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
    mPopup.show();
    mPopup.getListView().setOnKeyListener(this);
    return true;
}

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

/**
 * Set a simple drawable used for the left or right shadow.
 * The drawable provided must have a nonzero intrinsic width.
 *
 * @param shadowDrawable Shadow drawable to use at the edge of a drawer
 * @param gravity Which drawer the shadow should apply to
 *//*from  w w  w  . j  a  v a 2s . co  m*/
public void setDrawerShadow(Drawable shadowDrawable, int gravity) {
    /*
     * TODO Someone someday might want to set more complex drawables here.
     * They're probably nuts, but we might want to consider registering callbacks,
     * setting states, etc. properly.
     */

    final int absGravity = Gravity.getAbsoluteGravity(gravity, this.getLayoutDirection());
    if ((absGravity & Gravity.LEFT) == Gravity.LEFT) {
        mShadowLeft = shadowDrawable;
        invalidate();
    }
    if ((absGravity & Gravity.RIGHT) == Gravity.RIGHT) {
        mShadowRight = shadowDrawable;
        invalidate();
    }
}

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

/**
 * Enable or disable interaction with the given drawer.
 *
 * <p>This allows the application to restrict the user's ability to open or close
 * the given drawer. DrawerLayout will still respond to calls to {@link #openDrawer(int)},
 * {@link #closeDrawer(int)} and friends if a drawer is locked.</p>
 *
 * <p>Locking a drawer open or closed will implicitly open or close
 * that drawer as appropriate.</p>
 *
 * @param lockMode The new lock mode for the given drawer. One of {@link #LOCK_MODE_UNLOCKED},
 *                 {@link #LOCK_MODE_LOCKED_CLOSED} or {@link #LOCK_MODE_LOCKED_OPEN}.
 * @param edgeGravity Gravity.LEFT, RIGHT, START or END.
 *                    Expresses which drawer to change the mode for.
 *
 * @see #LOCK_MODE_UNLOCKED/* w ww .  j  a  va  2 s  .c om*/
 * @see #LOCK_MODE_LOCKED_CLOSED
 * @see #LOCK_MODE_LOCKED_OPEN
 */
public void setDrawerLockMode(int lockMode, int edgeGravity) {
    final int absGravity = Gravity.getAbsoluteGravity(edgeGravity, this.getLayoutDirection());
    if (absGravity == Gravity.LEFT) {
        mLockModeLeft = lockMode;
    } else if (absGravity == Gravity.RIGHT) {
        mLockModeRight = lockMode;
    }
    if (lockMode != LOCK_MODE_UNLOCKED) {
        // Cancel interaction in progress
        final ViewDragHelper helper = absGravity == Gravity.LEFT ? mLeftDragger : mRightDragger;
        helper.cancel();
    }
    switch (lockMode) {
    case LOCK_MODE_LOCKED_OPEN:
        final View toOpen = findDrawerWithGravity(absGravity);
        if (toOpen != null) {
            openDrawer(toOpen);
        }
        break;
    case LOCK_MODE_LOCKED_CLOSED:
        final View toClose = findDrawerWithGravity(absGravity);
        if (toClose != null) {
            closeDrawer(toClose);
        }
        break;
    // default: do nothing
    }
}

From source file:com.cyanogenmod.filemanager.ui.widgets.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  . java2s  . c  o m
public int getDrawerLockMode(int edgeGravity) {
    final int absGravity = Gravity.getAbsoluteGravity(edgeGravity, this.getLayoutDirection());
    if (absGravity == Gravity.LEFT) {
        return mLockModeLeft;
    } else if (absGravity == Gravity.RIGHT) {
        return mLockModeRight;
    }
    return LOCK_MODE_UNLOCKED;
}

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

/**
 * @return the absolute gravity of the child drawerView, resolved according
 *         to the current layout direction
 *//*  w w  w . j a  v  a  2s .  c o m*/
int getDrawerViewAbsoluteGravity(View drawerView) {
    final int gravity = ((LayoutParams) drawerView.getLayoutParams()).gravity;
    return Gravity.getAbsoluteGravity(gravity, this.getLayoutDirection());
}