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.daiv.android.twitter.ui.drawer_activities.DrawerActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {

    final int DISMISS = 0;
    final int SEARCH = 1;
    final int COMPOSE = 2;
    final int NOTIFICATIONS = 3;
    final int DM = 4;
    final int SETTINGS = 5;
    final int TOFIRST = 6;
    final int TWEETMARKER = 7;

    try {/*from   w  w  w .j av  a  2s . com*/
        searchItem = menu.findItem(R.id.menu_search);
    } catch (Exception e) {
        searchItem = null;
    }

    menu.getItem(TWEETMARKER).setVisible(false);

    if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT) || sharedPrefs.getBoolean("open_interactions", false)) {
        menu.getItem(DISMISS).setVisible(true);

        menu.getItem(SEARCH).setVisible(false);
        menu.getItem(COMPOSE).setVisible(false);
        menu.getItem(DM).setVisible(false);
        menu.getItem(TOFIRST).setVisible(false);

        if (settings.pushNotifications && settings.useInteractionDrawer) {
            menu.getItem(NOTIFICATIONS).setVisible(true);
        } else {
            menu.getItem(NOTIFICATIONS).setVisible(false);
        }

    } else {
        menu.getItem(DISMISS).setVisible(false);

        menu.getItem(SEARCH).setVisible(true);
        menu.getItem(COMPOSE).setVisible(true);
        menu.getItem(DM).setVisible(true);

        if (!settings.pushNotifications || !settings.useInteractionDrawer) {
            menu.getItem(NOTIFICATIONS).setVisible(false);
        } else {
            if (settings.floatingCompose || getResources().getBoolean(R.bool.isTablet)) {
                menu.getItem(NOTIFICATIONS).setVisible(true);
            } else {
                menu.getItem(NOTIFICATIONS).setVisible(false);
            }
        }
    }

    // to first button in overflow instead of the toast
    if (MainDrawerArrayAdapter.current > adapter.pageTypes.size() || (settings.uiExtras && settings.useToast)) {
        menu.getItem(TOFIRST).setVisible(false);
    } else {
        menu.getItem(TOFIRST).setVisible(true);
    }

    if (MainActivity.isPopup) {
        menu.getItem(SETTINGS).setVisible(false); // hide the settings button if the popup is up
        menu.getItem(SEARCH).setVisible(false); // hide the search button in popup

        // disable the left drawer so they can't switch activities in the popup.
        // causes problems with the layouts
        mDrawerLayout.setDrawerLockMode(NotificationDrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.START);
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayHomeAsUpEnabled(false);
        actionBar.setHomeButtonEnabled(false);
    }

    noti = menu.getItem(NOTIFICATIONS);

    if (InteractionsDataSource.getInstance(context).getUnreadCount(settings.currentAccount) > 0) {
        setNotificationFilled(true);
    } else {
        setNotificationFilled(false);
    }

    return true;
}

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

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

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

@Override
public void onStateChange(SearchBar searchBar, int newState, int oldState, boolean animation) {
    if (null == mLeftDrawable || null == mRightDrawable) {
        return;//  w  w  w .ja  v  a 2  s.c om
    }

    switch (oldState) {
    default:
    case SearchBar.STATE_NORMAL:
        mLeftDrawable.setArrow(animation ? ANIMATE_TIME : 0);
        mRightDrawable.setDelete(animation ? ANIMATE_TIME : 0);
        break;
    case SearchBar.STATE_SEARCH:
        if (newState == SearchBar.STATE_NORMAL) {
            mLeftDrawable.setMenu(animation ? ANIMATE_TIME : 0);
            mRightDrawable.setAdd(animation ? ANIMATE_TIME : 0);
        }
        break;
    case SearchBar.STATE_SEARCH_LIST:
        if (newState == STATE_NORMAL) {
            mLeftDrawable.setMenu(animation ? ANIMATE_TIME : 0);
            mRightDrawable.setAdd(animation ? ANIMATE_TIME : 0);
        }
        break;
    }

    if (newState == STATE_NORMAL || newState == STATE_SIMPLE_SEARCH) {
        setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.LEFT);
        setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.RIGHT);
    } else {
        setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.LEFT);
        setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.RIGHT);
    }
}

From source file:com.klinker.android.twitter.ui.drawer_activities.DrawerActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {

    final int DISMISS = 0;
    final int SEARCH = 1;
    final int COMPOSE = 2;
    final int NOTIFICATIONS = 3;
    final int DM = 4;
    final int SETTINGS = 5;
    final int TOFIRST = 6;
    final int TWEETMARKER = 7;

    try {/*from   w w  w . j av a2  s.  c o  m*/
        searchItem = menu.findItem(R.id.menu_search);
    } catch (Exception e) {
        searchItem = null;
    }

    menu.getItem(TWEETMARKER).setVisible(false);

    if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT) || sharedPrefs.getBoolean("open_interactions", false)) {
        menu.getItem(DISMISS).setVisible(true);

        menu.getItem(SEARCH).setVisible(false);
        menu.getItem(COMPOSE).setVisible(false);
        menu.getItem(DM).setVisible(false);
        menu.getItem(TOFIRST).setVisible(false);

        if (settings.pushNotifications) {
            menu.getItem(NOTIFICATIONS).setVisible(true);
        } else {
            menu.getItem(NOTIFICATIONS).setVisible(false);
        }

    } else {
        menu.getItem(DISMISS).setVisible(false);

        menu.getItem(SEARCH).setVisible(true);
        menu.getItem(COMPOSE).setVisible(true);
        menu.getItem(DM).setVisible(true);

        if (!settings.pushNotifications) {
            menu.getItem(NOTIFICATIONS).setVisible(false);
        } else {
            if (settings.floatingCompose || getResources().getBoolean(R.bool.isTablet)) {
                menu.getItem(NOTIFICATIONS).setVisible(true);
            } else {
                menu.getItem(NOTIFICATIONS).setVisible(false);
            }
        }
    }

    // to first button in overflow instead of the toast
    if (MainDrawerArrayAdapter.current > 2 || (settings.uiExtras && settings.useToast)) {
        menu.getItem(TOFIRST).setVisible(false);
    } else {
        menu.getItem(TOFIRST).setVisible(true);
    }

    if (MainActivity.isPopup) {
        menu.getItem(SETTINGS).setVisible(false); // hide the settings button if the popup is up
        menu.getItem(SEARCH).setVisible(false); // hide the search button in popup

        // disable the left drawer so they can't switch activities in the popup.
        // causes problems with the layouts
        mDrawerLayout.setDrawerLockMode(NotificationDrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.START);
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayHomeAsUpEnabled(false);
        actionBar.setHomeButtonEnabled(false);
    }

    noti = menu.getItem(NOTIFICATIONS);

    if (InteractionsDataSource.getInstance(context).getUnreadCount(settings.currentAccount) > 0) {
        setNotificationFilled(true);
    } else {
        setNotificationFilled(false);
    }

    return true;
}

From source file:com.irccloud.android.activity.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) { //Back key pressed
        if (drawerLayout != null
                && (drawerLayout.isDrawerOpen(Gravity.LEFT) || drawerLayout.isDrawerOpen(Gravity.RIGHT))) {
            drawerLayout.closeDrawers();
            return true;
        }//  www  .  j  a  v a 2  s  .c  om
        while (backStack != null && backStack.size() > 0) {
            Integer bid = backStack.get(0);
            backStack.remove(0);
            if (buffer == null || bid != buffer.bid) {
                BuffersDataSource.Buffer b = BuffersDataSource.getInstance().getBuffer(bid);
                if (b != null) {
                    onBufferSelected(bid);
                    if (backStack.size() > 0)
                        backStack.remove(0);
                    return true;
                }
            }
        }
    }
    return super.onKeyDown(keyCode, event);
}

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

@Override
protected void onRestoreInstanceState(Parcelable state) {
    SavedState ss = null;/*w ww .j av a 2 s.c  o  m*/
    if (state.getClass().getClassLoader() != getClass().getClassLoader()) {
        // Class loader mismatch, recreate from parcel.
        Parcel stateParcel = Parcel.obtain();
        state.writeToParcel(stateParcel, 0);
        ss = SavedState.CREATOR.createFromParcel(stateParcel);
    } else {
        ss = (SavedState) state;
    }
    super.onRestoreInstanceState(ss.getSuperState());

    if (ss.openDrawerGravity != Gravity.NO_GRAVITY) {
        openDrawer();
    }

    setDrawerLockMode(ss.lockModeLeft, Gravity.LEFT);
    setDrawerLockMode(ss.lockModeRight, Gravity.RIGHT);
}

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

/**
 * Lay out a child view with respect to a keyline.
 *
 * <p>The keyline represents a horizontal offset from the unpadded starting edge of
 * the CoordinatorLayout. The child's gravity will affect how it is positioned with
 * respect to the keyline.</p>//from  w ww .j  a v a 2  s  . c  om
 *
 * @param child child to lay out
 * @param keyline offset from the starting edge in pixels of the keyline to align with
 * @param layoutDirection ViewCompat constant for layout direction
 */
private void layoutChildWithKeyline(View child, int keyline, int layoutDirection) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    final int absGravity = GravityCompat.getAbsoluteGravity(resolveKeylineGravity(lp.gravity), layoutDirection);

    final int hgrav = absGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    final int vgrav = absGravity & Gravity.VERTICAL_GRAVITY_MASK;
    final int width = getWidth();
    final int height = getHeight();
    final int childWidth = child.getMeasuredWidth();
    final int childHeight = child.getMeasuredHeight();

    if (layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL) {
        keyline = width - keyline;
    }

    int left = getKeyline(keyline) - childWidth;
    int top = 0;

    switch (hgrav) {
    default:
    case Gravity.LEFT:
        // Nothing to do.
        break;
    case Gravity.RIGHT:
        left += childWidth;
        break;
    case Gravity.CENTER_HORIZONTAL:
        left += childWidth / 2;
        break;
    }

    switch (vgrav) {
    default:
    case Gravity.TOP:
        // Do nothing, we're already in position.
        break;
    case Gravity.BOTTOM:
        top += childHeight;
        break;
    case Gravity.CENTER_VERTICAL:
        top += childHeight / 2;
        break;
    }

    // Obey margins and padding
    left = Math.max(getPaddingLeft() + lp.leftMargin,
            Math.min(left, width - getPaddingRight() - childWidth - lp.rightMargin));
    top = Math.max(getPaddingTop() + lp.topMargin,
            Math.min(top, height - getPaddingBottom() - childHeight - lp.bottomMargin));

    child.layout(left, top, left + childWidth, top + childHeight);
}

From source file:com.gome.ecmall.custom.VerticalViewPager.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // For simple implementation, or internal size is always 0.
    // We depend on the container to specify the layout size of
    // our view. We can't really know what it is since we will be
    // adding and removing different arbitrary views and do not
    // want the layout to change as this happens.
    setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));

    // final int measuredWidth = getMeasuredWidth();
    final int measuredHeight = getMeasuredHeight();
    final int maxGutterSize = measuredHeight / 10;
    mGutterSize = Math.min(maxGutterSize, mDefaultGutterSize);

    // Children are just made to fill our space.
    // int childWidthSize = measuredWidth - getPaddingLeft()
    // - getPaddingRight();
    // int childHeightSize = getMeasuredHeight() - getPaddingTop()
    // - getPaddingBottom();

    int childWidthSize = getMeasuredWidth() - getPaddingLeft() - getPaddingRight();
    int childHeightSize = measuredHeight - getPaddingTop() - getPaddingBottom();

    /*//  www .j  a  v a  2s. c  o  m
     * Make sure all children have been properly measured. Decor views first. Right now we cheat and make this less
     * complicated by assuming decor views won't intersect. We will pin to edges based on gravity.
     */
    int size = getChildCount();
    for (int i = 0; i < size; ++i) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp != null && lp.isDecor) {
                final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                int widthMode = MeasureSpec.AT_MOST;
                int heightMode = MeasureSpec.AT_MOST;
                boolean consumeVertical = vgrav == Gravity.TOP || vgrav == Gravity.BOTTOM;
                boolean consumeHorizontal = hgrav == Gravity.LEFT || hgrav == Gravity.RIGHT;

                if (consumeVertical) {
                    widthMode = MeasureSpec.EXACTLY;
                } else if (consumeHorizontal) {
                    heightMode = MeasureSpec.EXACTLY;
                }

                int widthSize = childWidthSize;
                int heightSize = childHeightSize;
                if (lp.width != LayoutParams.WRAP_CONTENT) {
                    widthMode = MeasureSpec.EXACTLY;
                    if (lp.width != LayoutParams.MATCH_PARENT) {
                        widthSize = lp.width;
                    }
                }
                if (lp.height != LayoutParams.WRAP_CONTENT) {
                    heightMode = MeasureSpec.EXACTLY;
                    if (lp.height != LayoutParams.MATCH_PARENT) {
                        heightSize = lp.height;
                    }
                }
                final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode);
                final int heightSpec = MeasureSpec.makeMeasureSpec(heightSize, heightMode);
                child.measure(widthSpec, heightSpec);

                if (consumeVertical) {
                    childHeightSize -= child.getMeasuredHeight();
                } else if (consumeHorizontal) {
                    childWidthSize -= child.getMeasuredWidth();
                }
            }
        }
    }

    mChildWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);
    mChildHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeightSize, MeasureSpec.EXACTLY);

    // Make sure we have created all fragments that we need to have shown.
    mInLayout = true;
    populate();
    mInLayout = false;

    // Page views next.
    size = getChildCount();
    for (int i = 0; i < size; ++i) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            if (DEBUG)
                Log.v(TAG, "Measuring #" + i + " " + child + ": " + mChildWidthMeasureSpec);

            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp == null || !lp.isDecor) {
                // final int widthSpec = MeasureSpec.makeMeasureSpec(
                // (int) (childWidthSize * lp.heightFactor),
                // MeasureSpec.EXACTLY);
                final int heightSpec = MeasureSpec.makeMeasureSpec((int) (childHeightSize * lp.heightFactor),
                        MeasureSpec.EXACTLY);
                child.measure(mChildWidthMeasureSpec, heightSpec);
            }
        }
    }
}

From source file:com.daiv.android.twitter.ui.drawer_activities.DrawerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    try {/*ww w.  j a v a 2s  . c om*/
        if (mDrawerToggle.onOptionsItemSelected(item)) {
            if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
                mDrawerLayout.closeDrawer(Gravity.RIGHT);
            }
            return true;
        }
    } catch (Exception e) {
        // landscape
    }

    switch (item.getItemId()) {
    case R.id.menu_search:
        overridePendingTransition(0, 0);
        finish();
        overridePendingTransition(0, 0);
        return super.onOptionsItemSelected(item);

    case R.id.menu_compose:
        Intent compose = new Intent(context, ComposeActivity.class);
        sharedPrefs.edit().putBoolean("from_notification_bool", false).commit();
        startActivity(compose);
        return super.onOptionsItemSelected(item);

    case R.id.menu_settings:
        context.sendBroadcast(new Intent("com.daiv.android.twitter.MARK_POSITION"));
        finish();
        sharedPrefs.edit().putBoolean("should_refresh", false).commit();
        overridePendingTransition(R.anim.slide_in_left, R.anim.activity_zoom_exit);
        return super.onOptionsItemSelected(item);

    case R.id.menu_dismiss:
        InteractionsDataSource data = InteractionsDataSource.getInstance(context);
        data.markAllRead(DrawerActivity.settings.currentAccount);
        mDrawerLayout.closeDrawer(Gravity.RIGHT);
        notificationAdapter = new InteractionsCursorAdapter(context,
                data.getUnreadCursor(DrawerActivity.settings.currentAccount));
        notificationList.setAdapter(notificationAdapter);

        return super.onOptionsItemSelected(item);

    case R.id.menu_notifications:
        if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
            mDrawerLayout.closeDrawer(Gravity.LEFT);
        }

        if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
            mDrawerLayout.closeDrawer(Gravity.RIGHT);
        } else {
            mDrawerLayout.openDrawer(Gravity.RIGHT);
        }

        return super.onOptionsItemSelected(item);

    case R.id.menu_to_first:
        context.sendBroadcast(new Intent("com.daiv.android.twitter.TOP_TIMELINE"));
        return super.onOptionsItemSelected(item);

    case R.id.menu_tweetmarker:
        context.sendBroadcast(new Intent("com.daiv.android.twitter.TWEETMARKER"));
        return super.onOptionsItemSelected(item);

    case R.id.menu_get_help:
        new AlertDialog.Builder(context).setTitle(R.string.faq).setMessage(R.string.faq_first)
                .setPositiveButton("FAQ", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        XmlFaqUtils.showFaqDialog(context);
                    }
                }).setNegativeButton(R.string.contact, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        showContactUsDialog();
                    }
                }).setNeutralButton(R.string.follow, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        showFollowDialog();
                    }
                }).create().show();
        return super.onOptionsItemSelected(item);

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.chenglong.muscle.ui.LazyViewPager.java

/**
 * This method will be invoked when the current page is scrolled, either as
 * part of a programmatically initiated smooth scroll or a user initiated
 * touch scroll. If you override this method you must call through to the
 * superclass implementation (e.g. super.onPageScrolled(position, offset,
 * offsetPixels)) before onPageScrolled returns.
 *
 * @param position     Position index of the first page currently being displayed.
 *                     Page position+1 will be visible if positionOffset is nonzero.
 * @param offset       Value from [0, 1) indicating the offset from the page at
 *                     position.//ww w  .  java2 s  .  c  o  m
 * @param offsetPixels Value in pixels indicating the offset from position.
 */
protected void onPageScrolled(int position, float offset, int offsetPixels) {
    // Offset any decor views if needed - keep them on-screen at all times.
    if (mDecorChildCount > 0) {
        final int scrollX = getScrollX();
        int paddingLeft = getPaddingLeft();
        int paddingRight = getPaddingRight();
        final int width = getWidth();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (!lp.isDecor)
                continue;
            final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
            int childLeft = 0;
            switch (hgrav) {
            default:
                childLeft = paddingLeft;
                break;
            case Gravity.LEFT:
                childLeft = paddingLeft;
                paddingLeft += child.getWidth();
                break;
            case Gravity.CENTER_HORIZONTAL:
                childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft);
                break;
            case Gravity.RIGHT:
                childLeft = width - paddingRight - child.getMeasuredWidth();
                paddingRight += child.getMeasuredWidth();
                break;
            }
            childLeft += scrollX;
            final int childOffset = childLeft - child.getLeft();
            if (childOffset != 0) {
                child.offsetLeftAndRight(childOffset);
            }
        }
    }
    if (mOnPageChangeListener != null) {
        mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }
    if (mInternalPageChangeListener != null) {
        mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }
    mCalledSuper = true;
}