Example usage for android.view Gravity RIGHT

List of usage examples for android.view Gravity RIGHT

Introduction

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

Prototype

int RIGHT

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

Click Source Link

Document

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

Usage

From source file:com.abewy.android.apps.klyph.widget.KlyphDrawerLayout.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//from   w w w  . j  a  va 2  s  . c  o m
 * @see #LOCK_MODE_LOCKED_CLOSED
 * @see #LOCK_MODE_LOCKED_OPEN
 */
public void setDrawerLockMode(int lockMode, int edgeGravity) {
    final int absGrav = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this));
    if (absGrav == Gravity.LEFT) {
        mLockModeLeft = lockMode;
    } else if (absGrav == Gravity.RIGHT) {
        mLockModeRight = lockMode;
    }
    if (lockMode != LOCK_MODE_UNLOCKED) {
        // Cancel interaction in progress
        final ViewDragHelper helper = absGrav == Gravity.LEFT ? mLeftDragger : mRightDragger;
        helper.cancel();
    }
    switch (lockMode) {
    case LOCK_MODE_LOCKED_OPEN:
        final View toOpen = findDrawerWithGravity(absGrav);
        if (toOpen != null) {
            openDrawer(toOpen);
        }
        break;
    case LOCK_MODE_LOCKED_CLOSED:
        final View toClose = findDrawerWithGravity(absGrav);
        if (toClose != null) {
            closeDrawer(toClose);
        }
        break;
    // default: do nothing
    }
}

From source file:ca.co.rufus.androidboilerplate.ui.DebugDrawerLayout.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  . ja v a  2  s .  c o m*/
public void setDrawerShadow(Drawable shadowDrawable, @EdgeGravity 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 = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this));
    if ((absGravity & Gravity.LEFT) == Gravity.LEFT) {
        mShadowLeft = shadowDrawable;
        invalidate();
    }
    if ((absGravity & Gravity.RIGHT) == Gravity.RIGHT) {
        mShadowRight = shadowDrawable;
        invalidate();
    }
}

From source file:com.abewy.android.apps.klyph.app.MainActivity.java

@Override
public void onBackPressed() {
    if (drawer.isDrawerOpen(Gravity.RIGHT)) {
        drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.RIGHT);
        drawer.closeDrawer(Gravity.RIGHT);
    } else {/*from   w  w  w . j a  v  a2  s.c o m*/
        super.onBackPressed();
    }
}

From source file:com.waz.zclient.pages.main.participants.dialog.ParticipantsDialogFragment.java

private void setDialogPosition(Rect rect, int posX, int posY, int dialogWidth, int dialogHeight) {
    if (getControllerFactory().getConversationScreenController()
            .getPopoverLaunchMode() == DialogLaunchMode.COMMON_USER) {
        dialogTranslationX = posX + (rect.width() - dialogWidth) / 2;
        marker.setVisibility(View.VISIBLE);
    } else if (getControllerFactory().getConversationScreenController()
            .getPopoverLaunchMode() == DialogLaunchMode.CONVERSATION_TOOLBAR) {
        int screenWidth = ViewUtils.getRealDisplayWidth(getActivity());
        dialogTranslationX = screenWidth / 2 - dialogWidth / 2;
        marker.setVisibility(View.INVISIBLE);
    } else {//w w  w.j ava2 s.c om
        dialogTranslationX = getResources()
                .getDimensionPixelSize(R.dimen.framework__participants_dialog__pos_x);
        marker.setVisibility(View.VISIBLE);
    }

    int markerHeight = marker.getMeasuredHeight() / 2; // because we draw on our own
    int markerWidth = marker.getMeasuredWidth();

    markerTranslationX = posX + (rect.width() - markerWidth) / 2;

    int displayHeight;
    int displayWidth;

    boolean forceRight = getControllerFactory().getConversationScreenController()
            .getPopoverLaunchMode() == DialogLaunchMode.SEARCH
            || getControllerFactory().getConversationScreenController()
                    .getPopoverLaunchMode() == DialogLaunchMode.CONVERSATION_MENU;

    if (ViewUtils.isInPortrait(getActivity())) {
        displayHeight = ViewUtils.getOrientationIndependentDisplayHeight(getActivity());
        displayWidth = ViewUtils.getOrientationIndependentDisplayWidth(getActivity());
    } else {
        displayHeight = ViewUtils.getOrientationIndependentDisplayWidth(getActivity());
        displayWidth = ViewUtils.getOrientationIndependentDisplayHeight(getActivity());
    }

    final int screenBottom = displayHeight - participantDialogPadding
            - ViewUtils.getStatusBarHeight(getActivity());
    final int screenRight = displayWidth - participantDialogPadding;
    final int screenLeft = participantDialogPadding;

    if ((posY - dialogHeight - markerHeight) >= participantDialogPadding && !forceRight) {
        // put above
        markerTranslationY = posY - markerHeight;
        dialogTranslationY = markerTranslationY - dialogHeight;
        marker.setRotation(0f);
        if (dialogTranslationX + dialogWidth > screenRight) {
            // too far right
            dialogTranslationX = screenRight - dialogWidth;
        } else if (dialogTranslationX < participantDialogPadding) {
            // too far left
            dialogTranslationX = participantDialogPadding;
        }
        selfGravity = Gravity.TOP;
    } else if (posY + rect.height() + dialogHeight + markerHeight < screenBottom && !forceRight) {
        // put below
        markerTranslationY = posY + rect.height() - markerHeight;
        dialogTranslationY = markerTranslationY + 2 * markerHeight; // 2 * because we draw on our own
        marker.setRotation(180f);
        if (dialogTranslationX + dialogWidth > screenRight) {
            // too far right
            dialogTranslationX = screenRight - dialogWidth;
        } else if (dialogTranslationX < participantDialogPadding) {
            // too far left
            dialogTranslationX = participantDialogPadding;
        }
        selfGravity = Gravity.BOTTOM;
    } else if (posX + rect.width() + markerWidth + dialogWidth <= displayWidth - participantDialogPadding
            || forceRight) {
        int tmp = markerHeight;
        //noinspection SuspiciousNameCombination
        markerHeight = markerWidth;
        markerWidth = tmp;

        // centered
        markerTranslationX = posX + rect.width() - markerWidth;
        dialogTranslationX = markerTranslationX + 2 * markerWidth; // 2 * because we draw on our own

        markerTranslationY = (posY + rect.centerY()) - (markerHeight / 2);
        dialogTranslationY = (posY + rect.centerY()) - (dialogHeight / 2);
        marker.setRotation(90f);

        if (dialogTranslationY < participantDialogPadding) {
            // too high
            dialogTranslationY = participantDialogPadding;
        } else if (posY + dialogHeight > screenBottom) {
            // too low
            dialogTranslationY = displayHeight - participantDialogPadding - dialogHeight
                    - ViewUtils.getStatusBarHeight(getActivity());
        }

        // too far right
        if (dialogTranslationX + dialogWidth > screenRight) {
            dialogTranslationX = screenRight - dialogWidth;
            markerTranslationX = dialogTranslationX - 2 * markerWidth; // 2 * because we draw on our own
        }
        selfGravity = Gravity.RIGHT;
    } else {
        int tmp = markerHeight;
        //noinspection SuspiciousNameCombination
        markerHeight = markerWidth;
        markerWidth = tmp;

        // centered
        markerTranslationX = posX - markerWidth;
        dialogTranslationX = markerTranslationX - dialogWidth;

        markerTranslationY = (posY + rect.centerY()) - (markerHeight / 2);
        dialogTranslationY = (posY + rect.centerY()) - (dialogHeight / 2);
        marker.setRotation(270f);

        if (dialogTranslationY < participantDialogPadding) {
            // too high
            dialogTranslationY = participantDialogPadding;
        } else if (posY + dialogHeight > screenBottom) {
            // too low
            dialogTranslationY = displayHeight - participantDialogPadding - dialogHeight
                    - ViewUtils.getStatusBarHeight(getActivity());
        }

        // too far left
        if (dialogTranslationX < screenLeft) {
            dialogTranslationX = screenLeft;
            markerTranslationX = dialogTranslationX + dialogWidth;
        }

        selfGravity = Gravity.LEFT;
    }

    dialogFrameLayout.setTranslationX(dialogTranslationX);
    dialogFrameLayout.setTranslationY(dialogTranslationY);

    marker.setTranslationX(markerTranslationX);
    marker.setTranslationY(markerTranslationY);
}

From source file:com.money.manager.ex.home.DashboardFragment.java

private View showTableLayoutTopWithdrawals(Cursor cursor) {
    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.dashboard_summary_layout, null);
    CurrencyService currencyService = new CurrencyService(getActivity().getApplicationContext());

    // Textview Title
    TextView title = (TextView) layout.findViewById(R.id.textViewTitle);
    title.setText(R.string.top_withdrawals_last_30_days);
    // Table//from w w  w.  jav a  2s.co m
    TableLayout tableLayout = (TableLayout) layout.findViewById(R.id.tableLayoutSummary);
    // Create Title
    tableLayout.addView(createTableRow(
            new String[] { "<small><b>" + getString(R.string.category) + "</b></small>",
                    "<small><b>" + getString(R.string.quantity) + "</b></small>",
                    "<small><b>" + getString(R.string.summary) + "</b></small>" },
            new Float[] { 1f, null, null }, new Integer[] { null, Gravity.RIGHT, Gravity.RIGHT },
            new Integer[][] { null, { 0, 0, padding_in_px, 0 }, null }));
    // add rows
    while (cursor.moveToNext()) {
        // load values
        String category = "<b>" + cursor.getString(cursor.getColumnIndex(ViewMobileData.Category)) + "</b>";
        if (!TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(ViewMobileData.Subcategory)))) {
            category += " : " + cursor.getString(cursor.getColumnIndex(ViewMobileData.Subcategory));
        }
        double total = cursor.getDouble(cursor.getColumnIndex("TOTAL"));
        int num = cursor.getInt(cursor.getColumnIndex("NUM"));
        // Add Row
        tableLayout.addView(createTableRow(
                new String[] { "<small>" + category + "</small>",
                        "<small><i>" + Integer.toString(num) + "</i></small>",
                        "<small>" + currencyService.getCurrencyFormatted(currencyService.getBaseCurrencyId(),
                                MoneyFactory.fromDouble(total)) + "</small>" },
                new Float[] { 1f, null, null }, new Integer[] { null, Gravity.RIGHT, Gravity.RIGHT },
                new Integer[][] { null, { 0, 0, padding_in_px, 0 }, null }));
    }
    // return Layout
    return layout;
}

From source file:com.tr4android.support.extension.widget.CollapsingTextHelper.java

private void calculateBaseOffsets() {
    final float currentTextSize = mCurrentTextSize;

    // We then calculate the collapsed text size, using the same logic
    calculateUsingTextSize(mCollapsedTextSize);
    mCollapsedTextHeight = -mTextPaint.ascent();
    float width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0;
    final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity,
            mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR);
    switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.BOTTOM:
        mCollapsedDrawY = mCollapsedBounds.bottom - mCollapsedTextOffsetBottom;
        break;/*from  w ww  . j  a  v a2  s.  c  om*/
    case Gravity.TOP:
        mCollapsedDrawY = mCollapsedBounds.top - mTextPaint.ascent() + mCollapsedTextOffsetTop;
        break;
    case Gravity.CENTER_VERTICAL:
    default:
        float textHeight = mTextPaint.descent() - mTextPaint.ascent();
        float textOffset = (textHeight / 2) - mTextPaint.descent();
        mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset - (mCollapsedTextOffsetBottom / 2)
                + (mCollapsedTextOffsetTop / 2);
        break;
    }
    switch (collapsedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2);
        break;
    case Gravity.RIGHT:
        mCollapsedDrawX = mCollapsedBounds.right - width;
        break;
    case Gravity.LEFT:
    default:
        mCollapsedDrawX = mCollapsedBounds.left;
        break;
    }

    calculateUsingTextSize(mExpandedTextSize);
    mExpandedTextHeight = -mTextPaint.ascent();
    width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0;
    final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity,
            mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR);
    switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.BOTTOM:
        mExpandedDrawY = mExpandedBounds.bottom - mExpandedTextOffsetBottom;
        break;
    case Gravity.TOP:
        mExpandedDrawY = mExpandedBounds.top - mTextPaint.ascent() + mExpandedTextOffsetTop;
        break;
    case Gravity.CENTER_VERTICAL:
    default:
        float textHeight = mTextPaint.descent() - mTextPaint.ascent();
        float textOffset = (textHeight / 2) - mTextPaint.descent();
        mExpandedDrawY = mExpandedBounds.centerY() + textOffset - (mExpandedTextOffsetBottom / 2)
                + (mExpandedTextOffsetTop / 2);
        break;
    }
    switch (expandedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        mExpandedDrawX = mExpandedBounds.centerX() - (width / 2);
        break;
    case Gravity.RIGHT:
        mExpandedDrawX = mExpandedBounds.right - width;
        break;
    case Gravity.LEFT:
    default:
        mExpandedDrawX = mExpandedBounds.left;
        break;
    }

    // The bounds have changed so we need to clear the texture
    clearTexture();
    // Now reset the text size back to the original
    setInterpolatedTextSize(currentTextSize);
}

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

/**
 * Enable or disable interaction with the given drawer.
 * //from w w w. j a v  a2  s  . com
 * <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
 * @see #LOCK_MODE_LOCKED_CLOSED
 * @see #LOCK_MODE_LOCKED_OPEN
 */
public void setDrawerLockMode(int lockMode, int edgeGravity) {
    final int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this));
    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.hippo.drawerlayout.DrawerLayout.java

public int getDrawerLockMode(int gravity) {
    if (gravity == Gravity.LEFT) {
        return getDrawerLockMode(mLeftDrawer);
    } else if (gravity == Gravity.RIGHT) {
        return getDrawerLockMode(mRightDrawer);
    } else {//from ww  w  . j a  v  a2  s  . co m
        throw new IllegalArgumentException("gravity must be Gravity.LEFT or Gravity.RIGHT");
    }
}

From source file:com.hippo.widget.slidingdrawerlayout.SlidingDrawerLayout.java

@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final int absGravity = GravityCompat.getAbsoluteGravity(
                ((LayoutParams) child.getLayoutParams()).gravity, ViewCompat.getLayoutDirection(child));

        if (absGravity == Gravity.NO_GRAVITY) {
            if (mContentView != null)
                throw new IllegalStateException("There is more than one content view");
            mContentView = child;//w  w w . jav  a2 s .co  m
        } else if ((absGravity & Gravity.LEFT) == Gravity.LEFT) {
            if (mLeftDrawer != null)
                throw new IllegalStateException("There is more than one left menu");
            mLeftDrawer = child;
        } else if ((absGravity & Gravity.RIGHT) == Gravity.RIGHT) {
            if (mRightDrawer != null)
                throw new IllegalStateException("There is more than one right menu");
            mRightDrawer = child;
        } else {
            throw new IllegalStateException("Child " + child + " at index " + i
                    + " does not have a valid layout_gravity - must be Gravity.LEFT, "
                    + "Gravity.RIGHT or Gravity.NO_GRAVITY");
        }
    }

    if (mContentView == null)
        throw new IllegalStateException("There is no content view");
    // Material is solid.
    // Input events cannot pass through material.
    if (mLeftDrawer != null)
        mLeftDrawer.setClickable(true);
    if (mRightDrawer != null)
        mRightDrawer.setClickable(true);

    mShadow = new ShadowView(getContext());
    addView(mShadow, 1);
}

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

/**
 * Enable or disable interaction with all drawers.
 * /*  w  ww  .  jav a  2s .c om*/
 * <p>
 * This allows the application to restrict the user's ability to open or
 * close any drawer within this layout. DrawerLayout will still respond to
 * calls to {@link #openDrawer(int)}, {@link #closeDrawer(int)} and friends
 * if a drawer is locked.
 * </p>
 * 
 * <p>
 * Locking drawers open or closed will implicitly open or close any drawers
 * 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}.
 */
public void setDrawerLockMode(int lockMode) {
    setDrawerLockMode(lockMode, Gravity.LEFT);
    setDrawerLockMode(lockMode, Gravity.RIGHT);
    setDrawerLockMode(lockMode, Gravity.TOP);
    setDrawerLockMode(lockMode, Gravity.BOTTOM);
}