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.hippo.drawerlayout.DrawerLayout.java

public void openDrawer(int gravity) {
    if (gravity == Gravity.LEFT) {
        openDrawer(mLeftDrawer);//from w  w  w .j  a v a2  s . co  m
    } else if (gravity == Gravity.RIGHT) {
        openDrawer(mRightDrawer);
    }
}

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  www.  j  a v a 2  s  .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.acbelter.directionalcarousel.CarouselViewPager.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int width = MeasureSpec.getSize(widthMeasureSpec);
    final int height = MeasureSpec.getSize(heightMeasureSpec);

    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);

    if (DEBUG) {//  w w  w.  ja va  2  s  . co  m
        Log.d(TAG, "w=" + width + " h=" + height);
        Log.d(TAG, "wMode=" + getModeDescription(widthMode) + " hMode=" + getModeDescription(heightMode));
    }

    // FIXME Supported only match_parent and wrap_content attributes
    if (mConfig.orientation == CarouselConfig.VERTICAL) {
        int pageContentWidth = getPageContentWidth();
        int newWidth = width;
        if (widthMode == MeasureSpec.AT_MOST || pageContentWidth + 2 * mWrapPadding > width) {

            newWidth = pageContentWidth + 2 * mWrapPadding;
            widthMeasureSpec = MeasureSpec.makeMeasureSpec(newWidth, widthMode);
        }

        ViewGroup.LayoutParams lp = getLayoutParams();
        // FIXME Supported only FrameLayout as parent
        if (lp instanceof FrameLayout.LayoutParams) {
            if (!parentHasExactDimensions()) {
                throw new UnsupportedOperationException("Parent layout should have exact " + "dimensions.");
            }

            FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) lp;
            if (!mSizeChanged) {
                gravityOffset = 0.0f;
                int hGrav = params.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                if (hGrav == Gravity.CENTER_HORIZONTAL || hGrav == Gravity.CENTER) {
                    gravityOffset = (width - newWidth) * 0.5f;
                }
                if (hGrav == Gravity.RIGHT) {
                    gravityOffset = width - newWidth;
                }
            }

            setRotation(90);
            setTranslationX((newWidth - height) * 0.5f + gravityOffset);
            setTranslationY(-(newWidth - height) * 0.5f);
            params.gravity = Gravity.NO_GRAVITY;
            setLayoutParams(params);
        } else {
            throw new UnsupportedOperationException("Parent layout should be instance of " + "FrameLayout.");
        }

        mSizeChanged = true;
        super.onMeasure(heightMeasureSpec, widthMeasureSpec);
    } else {
        int pageContentHeight = getPageContentHeight();
        if (heightMode == MeasureSpec.AT_MOST || pageContentHeight + 2 * mWrapPadding > height) {

            int newHeight = pageContentHeight + 2 * mWrapPadding;
            heightMeasureSpec = MeasureSpec.makeMeasureSpec(newHeight, heightMode);
        }

        // FIXME Supported only FrameLayout as parent
        if (!(getLayoutParams() instanceof FrameLayout.LayoutParams)) {
            throw new UnsupportedOperationException("Parent layout should be instance of " + "FrameLayout.");
        } else {
            if (!parentHasExactDimensions()) {
                throw new UnsupportedOperationException("Parent layout should have exact " + "dimensions.");
            }
        }

        mSizeChanged = true;
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    mViewPagerWidth = getMeasuredWidth();
    mViewPagerHeight = getMeasuredHeight();

    if (calculatePageLimitAndMargin()) {
        setOffscreenPageLimit(mConfig.pageLimit);
        setPageMargin(mConfig.pageMargin);
    }

    if (DEBUG) {
        Log.d(TAG, mConfig.toString());
    }
}

From source file:com.lansun.qmyo.view.DrawerLayout.java

/**
 * Set a simple drawable used for the left or right shadow. The drawable provided must have a nonzero intrinsic width.
 * // w  w  w. jav a  2  s  .com
 * @param shadowDrawable
 *            Shadow drawable to use at the edge of a drawer
 * @param gravity
 *            Which drawer the shadow should apply to
 */
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 = 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.hippo.widget.slidingdrawerlayout.SlidingDrawerLayout.java

public void closeDrawer(int gravity) {
    if (gravity == Gravity.LEFT)
        closeDrawer(mLeftDrawer);/* ww  w .  j  a  v  a  2s.  c om*/
    else if (gravity == Gravity.RIGHT)
        closeDrawer(mRightDrawer);
}

From source file:com.adamkruger.myipaddressinfo.NetworkInfoFragment.java

private void addTableRow(Row row) {
    if (row.mLabel.length() > 0 || row.mValue.length() > 0) {
        int horizontalPadding = (int) (getResources().getDisplayMetrics().density
                * getResources().getDimension(R.dimen.label_value_padding) + 0.5f);
        TextView labelView = makeTextView(row.mLabel, getResources().getColor(R.color.dark_text_color),
                horizontalPadding);//w ww.j a v a  2s  .  c o  m
        labelView.setGravity(Gravity.RIGHT);
        TextView valueView = makeTextView(row.mValue, getResources().getColor(R.color.dark_text_color),
                horizontalPadding);
        TableRow tableRow = makeTableRow(labelView, valueView);
        int verticalPadding = (int) (getResources().getDisplayMetrics().density
                * getResources().getDimension(R.dimen.network_info_vertical_padding) + 0.5f);
        tableRow.setPadding(0, verticalPadding, 0, verticalPadding);
        tableRow.setBackgroundColor(getResources().getColor(R.color.background_color_white));
        tableRow.setGravity(Gravity.CENTER_HORIZONTAL);
        mNetworkInfoTableLayout.addView(tableRow);
    }
}

From source file:com.putaotown.views.PagerSlidingTabStrip.java

private void addIconTab(final int position, int resId) {
    boolean isMessage = false; //??
    if (resId == R.drawable.iconfont_message || resId == R.drawable.iconfont_message_press)
        isMessage = true;/*from  w  ww.  j av  a  2s .co m*/

    ImageButton tab = new ImageButton(getContext());
    //      LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1);
    LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabWidth,
                    getResources().getDisplayMetrics()),
            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabWidth,
                    getResources().getDisplayMetrics()));
    int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
            getResources().getDisplayMetrics());

    if (isMessage) {
        FrameLayout.LayoutParams paramx = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabWidth,
                        getResources().getDisplayMetrics()));
        FrameLayout flayout = new FrameLayout(this.getContext());
        param.gravity = Gravity.RIGHT;
        flayout.setLayoutParams(param);
        flayout.setPadding(padding, padding, padding, padding);
        View view = inflate(this.getContext(), R.layout.actionbar_mess_view, null);
        this.messRedPos = view.findViewById(R.id.actionbar_mess_redpos);
        this.messImage = (ImageView) view.findViewById(R.id.actionbar_mess_icon);
        flayout.addView(view);
        flayout.setTag("mess"); //??
        addTab(position, flayout);
    } else {
        tab.setLayoutParams(param);
        tab.setPadding(padding, padding, padding, padding);
        tab.setImageResource(resId);
        tab.setScaleType(ScaleType.CENTER_INSIDE);
        tab.setAdjustViewBounds(true);
        addTab(position, tab);
    }

}

From source file:com.actionbarsherlock.internal.widget.IcsSpinner.java

/**
 * Creates and positions all views for this Spinner.
 *
 * @param delta Change in the selected position. +1 moves selection is moving to the right,
 * so views are scrolling to the left. -1 means selection is moving to the left.
 *//*  www.ja  v a 2 s.c o m*/
@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;
    View sel = makeAndAddView(mSelectedPosition);
    int width = sel.getMeasuredWidth();
    int selectedOffset = childrenLeft;
    switch (mGravity & 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.google.android.gms.example.bannerexample.CreateFile.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // toggle nav drawer on selecting action bar app icon/title
    if (item != null && item.getItemId() == android.R.id.home) {
        if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
            mDrawerLayout.closeDrawer(Gravity.RIGHT);
        } else {/*  w  w w .j a v  a 2  s. co m*/
            mDrawerLayout.openDrawer(Gravity.RIGHT);
        }
    }
    return false;
}

From source file:com.abewy.android.apps.klyph.widget.KlyphDrawerLayout.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
 *//* w w  w. j av  a  2  s  .c o 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 = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this));
    if ((absGravity & Gravity.LEFT) == Gravity.LEFT) {
        mShadowLeft = shadowDrawable;
        invalidate();
    }
    if ((absGravity & Gravity.RIGHT) == Gravity.RIGHT) {
        mShadowRight = shadowDrawable;
        invalidate();
    }
}