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:ca.co.rufus.androidboilerplate.ui.DebugDrawerLayout.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  . ja  v  a 2s  .  c o m
 * @see #LOCK_MODE_LOCKED_CLOSED
 * @see #LOCK_MODE_LOCKED_OPEN
 */
public void setDrawerLockMode(@LockMode int lockMode, @EdgeGravity 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.cssweb.android.quote.QHSCGridActivity.java

private void AddViewItem(int paramInt1, LinearLayout paramLinearLayout, int paramInt2, int paramInt3,
        int paramInt4, boolean paramBoolean) {
    TextView localTextView = new TextView(this);
    float f = this.mFontSize;
    localTextView.setTextSize(f);// www. j  a  v  a 2 s  . c  om

    localTextView.setGravity(Gravity.CENTER);
    localTextView.setFocusable(paramBoolean);
    localTextView.setOnClickListener(mClickListener);
    localTextView.setOnLongClickListener(mLongClickListener);
    localTextView.setOnTouchListener(this); // touch
    localTextView.setTag(paramInt2);
    localTextView.setEnabled(paramBoolean);
    localTextView.setSingleLine(true);
    Resources localResources = getResources();
    Drawable localDrawable = null;
    if (paramInt4 == 0 && paramInt3 >= 0) {// 
        int i1 = this.residTitleCol;
        int i8 = 0;
        localTextView.setTextColor(paramInt1);
        if (paramInt3 == 0) {
            localDrawable = localResources.getDrawable(i1);
            i8 = localDrawable.getIntrinsicWidth();
        } else if (paramInt3 == 100) {
            localDrawable = localResources.getDrawable(this.residTitleScrollCol[2]);
            i8 = localDrawable.getIntrinsicWidth();
            i8 += 20;
        } else if (paramInt3 == 13) {
            localDrawable = localResources.getDrawable(this.residTitleScrollCol[0]);
            i8 = localDrawable.getIntrinsicWidth();

        } else if (paramInt3 % 2 == 0) {
            localDrawable = localResources.getDrawable(this.residTitleScrollCol[1]);
            i8 = localDrawable.getIntrinsicWidth();
        } else {
            localDrawable = localResources.getDrawable(this.residTitleScrollCol[0]);
            i8 = localDrawable.getIntrinsicWidth();
        }
        localTextView.setBackgroundDrawable(localDrawable);
        int i6 = localDrawable.getIntrinsicHeight();
        localTextView.setHeight(i6 + CssSystem.getTableTitleHeight(this));
        localTextView.setWidth(i8);
        paramLinearLayout.addView(localTextView);
        return;
    }
    if (paramInt4 != 0 && paramInt3 >= 0) {
        int i8 = 0;
        localTextView.setTextColor(paramInt1);
        if (paramInt3 == 0) {
            localDrawable = localResources.getDrawable(this.residCol);
            i8 = localDrawable.getIntrinsicWidth();
        } else if (paramInt3 == 100) {
            localDrawable = localResources.getDrawable(this.residScrollCol[2]);
            localTextView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
            i8 = localDrawable.getIntrinsicWidth();
            i8 += 20;
        } else if (paramInt3 == 13) {
            localDrawable = localResources.getDrawable(this.residScrollCol[0]);
            localTextView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
            i8 = localDrawable.getIntrinsicWidth();

        } else if (paramInt3 % 2 == 0) {
            localDrawable = localResources.getDrawable(this.residScrollCol[1]);
            localTextView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
            i8 = localDrawable.getIntrinsicWidth();
        } else {
            localDrawable = localResources.getDrawable(this.residScrollCol[0]);
            localTextView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
            i8 = localDrawable.getIntrinsicWidth();
        }
        localTextView.setBackgroundDrawable(localDrawable);
        int i6 = localDrawable.getIntrinsicHeight();
        localTextView.setHeight(i6 + rowHeight);
        localTextView.setWidth(i8);
        paramLinearLayout.addView(localTextView);
        return;
    }
}

From source file:com.doubleTwist.drawerlib.ADrawerLayout.java

protected void layoutView(View v, int l, int t, int r, int b) {
    LayoutParams params = (LayoutParams) v.getLayoutParams();

    Rect bounds = new Rect();
    Rect boundsWithoutPeek = new Rect();
    int gravity = params.gravity;
    switch (gravity) {
    case Gravity.RIGHT:
        if (DEBUG)
            Log.d(TAG, "gravity: right");
        bounds.left = r - v.getMeasuredWidth() - mPeekSize.right;
        bounds.top = t;//from ww  w  . j a v  a2  s.c om
        bounds.right = r - mPeekSize.right;
        bounds.bottom = t + v.getMeasuredHeight();
        v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom);
        boundsWithoutPeek = new Rect(bounds);
        boundsWithoutPeek.offset(mPeekSize.right, 0);
        mMinScrollX = -bounds.width();
        break;
    case Gravity.TOP:
        if (DEBUG)
            Log.d(TAG, "gravity: top");
        bounds.left = l;
        bounds.top = t + mPeekSize.top;
        bounds.right = v.getMeasuredWidth();
        bounds.bottom = t + v.getMeasuredHeight() + mPeekSize.top;
        v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom);
        boundsWithoutPeek = new Rect(bounds);
        boundsWithoutPeek.offset(0, -mPeekSize.top);
        mMaxScrollY = bounds.height();
        break;
    case Gravity.BOTTOM:
        if (DEBUG)
            Log.d(TAG, "gravity: bottom");
        bounds.left = l;
        bounds.top = b - v.getMeasuredHeight() - mPeekSize.bottom;
        bounds.right = l + v.getMeasuredWidth();
        bounds.bottom = b - mPeekSize.bottom;
        v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom);
        boundsWithoutPeek = new Rect(bounds);
        boundsWithoutPeek.offset(0, mPeekSize.bottom);
        mMinScrollY = -bounds.height();
        break;
    case Gravity.LEFT:
        if (DEBUG)
            Log.d(TAG, "gravity: left");
        bounds.left = l + mPeekSize.left;
        bounds.top = t;
        bounds.right = l + v.getMeasuredWidth() + mPeekSize.left;
        bounds.bottom = t + v.getMeasuredHeight();
        v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom);
        mMaxScrollX = bounds.width();
        boundsWithoutPeek = new Rect(bounds);
        boundsWithoutPeek.offset(-mPeekSize.left, 0);
        break;
    default:
        if (DEBUG)
            Log.d(TAG, "gravity: default");
        bounds.left = l;
        bounds.top = t;
        bounds.right = l + v.getMeasuredWidth();
        bounds.bottom = t + v.getMeasuredHeight();
        v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom);
        boundsWithoutPeek = new Rect(bounds);
        break;
    }

    if (DEBUG) {
        Log.d(TAG, " == VIEW LAYOUT == " + v.toString());
        Log.d(TAG, "bounds: " + bounds.left + "," + bounds.top + "," + bounds.right + "," + bounds.bottom);
    }

    if (mLayoutBounds.containsKey(v))
        mLayoutBounds.remove(v);
    mLayoutBounds.put(v, bounds);
    if (mLayoutBoundsWithoutPeek.containsKey(v))
        mLayoutBoundsWithoutPeek.remove(v);
    mLayoutBoundsWithoutPeek.put(v, boundsWithoutPeek);
}

From source file:com.sim2dial.dialer.StatusFragment.java

private void showZRTPDialog(final LinphoneCall call) {
    boolean authVerified = call.isAuthenticationTokenVerified();
    String format = getString(authVerified ? R.string.reset_sas_fmt : R.string.verify_sas_fmt);

    LayoutInflater inflater = LayoutInflater.from(getActivity());
    View layout = inflater.inflate(R.layout.zrtp_dialog,
            (ViewGroup) getActivity().findViewById(R.id.toastRoot));

    TextView toastText = (TextView) layout.findViewById(R.id.toastMessage);
    toastText.setText(String.format(format, call.getAuthenticationToken()));

    zrtpToast = new Toast(getActivity());
    zrtpToast.setGravity(Gravity.TOP | Gravity.RIGHT, 0, LinphoneUtils.pixelsToDpi(getResources(), 40));
    zrtpToast.setDuration(Toast.LENGTH_LONG);

    ImageView ok = (ImageView) layout.findViewById(R.id.toastOK);
    ok.setOnClickListener(new OnClickListener() {
        @Override// w w w .java2 s .c o m
        public void onClick(View v) {
            if (call != null) {
                call.setAuthenticationTokenVerified(true);
            }
            if (encryption != null) {
                encryption.setImageResource(R.drawable.security_ok);
            }
            hideZRTPDialog();
        }
    });

    ImageView notOk = (ImageView) layout.findViewById(R.id.toastNotOK);
    notOk.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (call != null) {
                call.setAuthenticationTokenVerified(false);
            }
            if (encryption != null) {
                encryption.setImageResource(R.drawable.security_pending);
            }
            hideZRTPDialog();
        }
    });

    zrtpHack = new CountDownTimer(3000, 1000) {
        public void onTick(long millisUntilFinished) {
            if (!hideZrtpToast) {
                zrtpToast.show();
            }
        }

        public void onFinish() {
            if (!hideZrtpToast) {
                zrtpToast.show();
                zrtpHack.start();
            }
        }

    };

    zrtpToast.setView(layout);
    hideZrtpToast = false;
    zrtpToast.show();
    zrtpHack.start();
}

From source file:com.quran.labs.androidquran.widgets.spinner.SpinnerCompat.java

/**
 * Creates and positions all views for this Spinner.
 *
 * @param delta Change in the selected position. +1 means selection is moving to the right, so
 *              views are scrolling to the left. -1 means selection is moving to the left.
 *//*from   www.  j a va  2  s. co m*/
@SuppressLint("RtlHardcoded")
@Override
void layout(int delta, boolean animate) {
    int childrenLeft = mSpinnerPadding.left;
    int childrenWidth = getRight() - getLeft() - mSpinnerPadding.left - mSpinnerPadding.right;

    if (mDataChanged) {
        handleDataChanged();
    }

    // Handle the empty set by removing all views
    if (mItemCount == 0) {
        resetList();
        return;
    }

    if (mNextSelectedPosition >= 0) {
        setSelectedPositionInt(mNextSelectedPosition);
    }

    recycleAllViews();

    // Clear out old views
    removeAllViewsInLayout();

    // Make selected view and position it
    mFirstPosition = mSelectedPosition;
    if (mAdapter != null) {
        View sel = makeView(mSelectedPosition, true);
        int width = sel.getMeasuredWidth();
        int selectedOffset = childrenLeft;
        final int layoutDirection = ViewCompat.getLayoutDirection(this);
        final int absoluteGravity = GravityCompat.getAbsoluteGravity(mGravity, layoutDirection);
        switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.CENTER_HORIZONTAL:
            selectedOffset = childrenLeft + (childrenWidth / 2) - (width / 2);
            break;
        case Gravity.RIGHT:
            selectedOffset = childrenLeft + childrenWidth - width;
            break;
        }
        sel.offsetLeftAndRight(selectedOffset);
    }

    // Flush any cached views that did not get reused above
    mRecycler.clear();

    invalidate();

    checkSelectionChanged();

    mDataChanged = false;
    mNeedSync = false;
    setNextSelectedPositionInt(mSelectedPosition);
}

From source file:de.madvertise.android.sdk.MadvertiseMraidView.java

private ImageButton addCloseButtonToViewGroup(final ViewGroup parent) {
    final ImageButton closeButton = new ImageButton(getContext());
    final FrameLayout.LayoutParams closeButtonParams = new FrameLayout.LayoutParams(CLOSE_BUTTON_SIZE,
            CLOSE_BUTTON_SIZE);/*  w w  w . j  a va 2  s . c o m*/
    closeButtonParams.gravity = Gravity.RIGHT;
    closeButton.setLayoutParams(closeButtonParams);
    closeButton.setBackgroundColor(Color.TRANSPARENT);
    closeButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            close();
        }
    });

    parent.addView(closeButton);

    return closeButton;
}

From source file:android.support.v7.internal.widget.SpinnerCompat.java

/**
 * Creates and positions all views for this Spinner.
 *
 * @param delta Change in the selected position. +1 means selection is moving to the right, so
 *              views are scrolling to the left. -1 means selection is moving to the left.
 *//*from   www  . j  a v a2s.c om*/
@Override
void layout(int delta, boolean animate) {
    int childrenLeft = mSpinnerPadding.left;
    int childrenWidth = getRight() - getLeft() - mSpinnerPadding.left - mSpinnerPadding.right;

    if (mDataChanged) {
        handleDataChanged();
    }

    // Handle the empty set by removing all views
    if (mItemCount == 0) {
        resetList();
        return;
    }

    if (mNextSelectedPosition >= 0) {
        setSelectedPositionInt(mNextSelectedPosition);
    }

    recycleAllViews();

    // Clear out old views
    removeAllViewsInLayout();

    // Make selected view and position it
    mFirstPosition = mSelectedPosition;
    if (mAdapter != null) {
        View sel = makeView(mSelectedPosition, true);
        int width = sel.getMeasuredWidth();
        int selectedOffset = childrenLeft;
        final int layoutDirection = ViewCompat.getLayoutDirection(this);
        final int absoluteGravity = GravityCompat.getAbsoluteGravity(mGravity, layoutDirection);
        switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.CENTER_HORIZONTAL:
            selectedOffset = childrenLeft + (childrenWidth / 2) - (width / 2);
            break;
        case Gravity.RIGHT:
            selectedOffset = childrenLeft + childrenWidth - width;
            break;
        }
        sel.offsetLeftAndRight(selectedOffset);
    }

    // Flush any cached views that did not get reused above
    mRecycler.clear();

    invalidate();

    checkSelectionChanged();

    mDataChanged = false;
    mNeedSync = false;
    setNextSelectedPositionInt(mSelectedPosition);
}

From source file:com.waz.zclient.ui.cursor.CursorLayout.java

@Override
public void onShowTooltip(CursorMenuItem item, String message, View anchor) {
    if (tooltipEnabled) {
        return;//w w w .  ja v  a2  s. c  o  m
    }

    int w = (int) (anchor.getX() + anchor.getMeasuredWidth() / 2);
    int gravity;

    if (w < getMeasuredWidth() / 4) {
        gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;

    } else if (w > 3 * getMeasuredWidth() / 4) {
        gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
    } else {
        gravity = Gravity.CENTER;
    }

    ((FrameLayout.LayoutParams) tooltip.getLayoutParams()).gravity = gravity;

    tooltipEnabled = true;
    tooltip.setText(message);
    tooltip.animate().alpha(1).withStartAction(new Runnable() {
        @Override
        public void run() {
            tooltip.setVisibility(View.VISIBLE);
            tooltip.setAlpha(0);
        }
    });

    if (cursorCallback != null) {
        cursorCallback.onShowedActionHint(item);
    }

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            dismissToolbar();
        }
    }, TOOLTIP_DURATION);
}

From source file:com.google.blockly.android.ToolboxFragment.java

/**
 * Updates the padding used to calculate the margins of the scrollable blocks, based on the size
 * and placement of the tabs.//  w  ww .j  a  va 2s  .  c  o  m
 */
private void updateScrollablePadding() {
    int buttonHeight = mActionButton.getVisibility() == View.GONE ? 0 : mActionButton.getMeasuredHeight();
    int buttonWidth = mActionButton.getVisibility() == View.GONE ? 0 : mActionButton.getMeasuredWidth();
    int buttonVerticalPadding = 0, buttonHorizontalPadding = 0;
    if (mScrollOrientation == SCROLL_VERTICAL) {
        buttonVerticalPadding = buttonHeight;
    } else {
        buttonHorizontalPadding = buttonWidth;
    }
    int layoutDir = ViewCompat.getLayoutDirection(mRootView);
    int spacingForTabs;
    switch (GravityCompat.getAbsoluteGravity(mTabEdge, layoutDir)) {
    case Gravity.LEFT:
        spacingForTabs = hasTabs() ? mCategoryTabs.getMeasuredWidth() : 0; // Horizontal
        mScrollablePadding.set(spacingForTabs + buttonHorizontalPadding, buttonVerticalPadding, 0, 0);
        break;
    case Gravity.TOP:
        spacingForTabs = hasTabs() ? mCategoryTabs.getMeasuredHeight() : 0; // Vertical
        if (layoutDir == ViewCompat.LAYOUT_DIRECTION_LTR) {
            mScrollablePadding.set(buttonHorizontalPadding, spacingForTabs + buttonVerticalPadding, 0, 0);
        } else {
            mScrollablePadding.set(0, spacingForTabs + buttonVerticalPadding, buttonHorizontalPadding, 0);
        }
        break;
    case Gravity.RIGHT:
        spacingForTabs = hasTabs() ? mCategoryTabs.getMeasuredWidth() : 0; // Horizontal
        mScrollablePadding.set(0, buttonVerticalPadding, spacingForTabs + buttonHorizontalPadding, 0);
        break;
    case Gravity.BOTTOM:
        spacingForTabs = hasTabs() ? mCategoryTabs.getMeasuredHeight() : 0; // Vertical
        if (layoutDir == ViewCompat.LAYOUT_DIRECTION_LTR) {
            mScrollablePadding.set(buttonHorizontalPadding, 0, 0, spacingForTabs + buttonVerticalPadding);
        } else {
            mScrollablePadding.set(0, 0, buttonHorizontalPadding, spacingForTabs + buttonVerticalPadding);
        }
        break;
    }
}

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

private void loadData() {
    if (!isFinishing()) {
        // Let the Application class that the first launch is complete
        // So next time, don't display the fullscreen ad
        KlyphApplication.getInstance().launchComplete();

        // Load other stuff
        notificationsFragment = new Notifications();
        getFragmentManager().beginTransaction()
                .replace(R.id.notifications_container, notificationsFragment, "NotificationsFragment")
                .commitAllowingStateLoss();
        getFragmentManager().invalidateOptionsMenu();

        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);

        if (getIntent().getBooleanExtra(KlyphBundleExtras.SHOW_BIRTHDAYS, false) == true) {
            // Show birthdays fragment
            updateContent(9);//from ww  w  . j  a  va 2s .c o m
        } else {
            // Show newsfeed0 fragment
            updateContent(0);
        }

        drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);

        getUser();

        sessionInitalized = true;

        if (getIntent().getBooleanExtra(KlyphBundleExtras.SHOW_NOTIFICATION_MENU, false) == true) {
            drawer.openDrawer(Gravity.RIGHT);

            notificationsFragment.setHasOptionsMenu(true);

            ((Fragment) previousFragment).setHasOptionsMenu(false);

            invalidateOptionsMenu();
        }
    }
}