Example usage for android.view Gravity LEFT

List of usage examples for android.view Gravity LEFT

Introduction

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

Prototype

int LEFT

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

Click Source Link

Document

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

Usage

From source file:com.chatwingsdk.activities.CommunicationActivity.java

protected void setupMode(CommunicationModeManager newMode, CommunicationMessagesFragment newFragment) {
    /*//  ww  w.ja  v  a2s  . c  o m
     * Update fragments
     */
    String fragmentTag = getString(R.string.tag_communication_messages);
    FragmentManager fragmentManager = getSupportFragmentManager();
    Fragment oldFragment = fragmentManager.findFragmentByTag(fragmentTag);
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    if (oldFragment != null) {
        fragmentTransaction.remove(oldFragment);
    }
    fragmentTransaction.add(R.id.fragment_container, newFragment, fragmentTag);
    fragmentTransaction.commit();

    /*
     * Deactivate old mode and activate the new one
     */
    if (mCurrentCommunicationMode != null) {
        mCurrentCommunicationMode.deactivate();
    }
    mCurrentCommunicationMode = newMode;
    mCurrentCommunicationMode.activate();

    /*
     * Setup drawer layout
     */
    // Set custom shadows that overlay the main content when a drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_left, Gravity.LEFT);
    mDrawerToggle = mCurrentCommunicationMode.getDrawerToggleListener();
    mDrawerToggle.setDrawerIndicatorEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    // Don't allow the drawer layout to catch back button and close itself
    // on back key is pressed. This activity will handle it.
    mDrawerLayout.setFocusableInTouchMode(false);

    invalidateOptionsMenu();
}

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

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    Log.i(TAG, "onLayout()");
    mInLayout = true;/*from w  w  w  .  ja  v  a 2  s  .c om*/
    final int width = r - l;
    final int height = b - t;
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() == GONE) {
            continue;
        }
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (isContentView(child)) {
            child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(),
                    lp.topMargin + child.getMeasuredHeight());
        } else {
            final int childWidth = child.getMeasuredWidth();
            final int childHeight = child.getMeasuredHeight();
            int childTop;

            final float newOffset;
            if (checkDrawerViewAbsoluteGravity(child, Gravity.BOTTOM)) {
                childTop = height - (int) (childHeight * lp.onScreen);
                newOffset = (float) (height - childTop) / childWidth;
            } else {
                childTop = -childHeight + (int) (childHeight * lp.onScreen);
                newOffset = (float) (childHeight + childTop) / childHeight;
            }
            final boolean changeOffset = newOffset != lp.onScreen;
            final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
            switch (vgrav) {
            default:
            case Gravity.LEFT: {
                child.layout(lp.leftMargin, childTop, lp.leftMargin + childWidth, childTop + childHeight);
                break;
            }
            case Gravity.RIGHT: {
                child.layout(width - lp.rightMargin, childTop, width - lp.rightMargin, childTop + childHeight);
                break;
            }
            case Gravity.CENTER_HORIZONTAL: {
                int childLeft = (width - childWidth) / 2;
                if (childLeft < lp.leftMargin) {
                    childLeft = lp.leftMargin;
                } else if (childLeft + childWidth > width - lp.rightMargin) {
                    childLeft = width - lp.rightMargin - childWidth;
                }
                child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
                break;
            }
            }

            if (changeOffset) {
                setDrawerViewOffset(child, newOffset);
            }

            final int newVisibility = lp.onScreen > 0 ? VISIBLE : INVISIBLE;
            if (child.getVisibility() != newVisibility) {
                child.setVisibility(newVisibility);
            }
        }
    }
    mInLayout = false;
    mFirstLayout = false;
}

From source file:com.aegiswallet.actions.MainActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        if (mDrawerLayout != null) {
            if (mDrawerLayout.isDrawerOpen(Gravity.LEFT))
                mDrawerLayout.closeDrawer(Gravity.LEFT);
            else/*w ww .  j a  va 2  s  .co m*/
                mDrawerLayout.openDrawer(Gravity.LEFT);
        }
        return true;
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.jecelyin.editor.v2.widget.AnyDrawerLayout.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 w  w .ja  v a  2  s  .  c  om
 * @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));

    switch (edgeGravity) {
    case Gravity.LEFT:
        mLockModeLeft = lockMode;
        break;
    case Gravity.RIGHT:
        mLockModeRight = lockMode;
        break;
    case GravityCompat.START:
        mLockModeStart = lockMode;
        break;
    case GravityCompat.END:
        mLockModeEnd = lockMode;
        break;
    }

    if (lockMode != LOCK_MODE_UNLOCKED) {
        // Cancel interaction in progress
        final ViewDragHelper helper = absGravity == Gravity.LEFT ? mLeftDragger
                : (absGravity == Gravity.RIGHT ? mRightDragger : mBottomDragger);
        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.actionbarsherlock.custom.widget.VerticalDrawerLayout.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;/* ww w . ja v a  2  s  .c  o m*/
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (isContentView(child)) {
            child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(),
                    lp.topMargin + child.getMeasuredHeight());
        } else { // Drawer, if it wasn't onMeasure would have thrown an exception.
            final int childWidth = child.getMeasuredWidth();
            final int childHeight = child.getMeasuredHeight();
            int childTop;

            if (checkDrawerViewGravity(child, Gravity.TOP)) {
                childTop = -childHeight + (int) (childHeight * lp.onScreen);
            } else { // Bottom; onMeasure checked for us.
                childTop = b - t - (int) (childHeight * lp.onScreen);
            }

            final int vgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;

            switch (vgrav) {
            default:
            case Gravity.LEFT: {
                child.layout(lp.leftMargin, childTop, childWidth, childTop + childHeight);
                break;
            }

            case Gravity.RIGHT: {
                final int width = r - l;
                child.layout(width - lp.rightMargin - child.getMeasuredWidth(), childTop,
                        width - lp.rightMargin, childTop + childHeight);
                break;
            }

            case Gravity.CENTER_HORIZONTAL: {
                final int width = r - l;
                int childLeft = (width - childWidth) / 2;

                // Offset for margins. If things don't fit right because of
                // bad measurement before, oh well.
                if (childLeft < lp.leftMargin) {
                    childLeft = lp.leftMargin;
                } else if (childLeft + childWidth > width - lp.rightMargin) {
                    childLeft = width - lp.rightMargin - childWidth;
                }
                child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
                break;
            }
            }

            if (lp.onScreen == 0) {
                child.setVisibility(INVISIBLE);
            }
        }
    }
    mInLayout = false;
    mFirstLayout = false;
}

From source file:com.daiv.android.twitter.manipulations.widgets.NotificationDrawerLayout.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;/*from  w  w  w  . j ava 2  s.  c  o  m*/
    final int width = r - l;
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (isContentView(child)) {
            try {
                child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(),
                        lp.topMargin + child.getMeasuredHeight());
            } catch (Exception e) {

            }
        } else { // Drawer, if it wasn't onMeasure would have thrown an exception.
            final int childWidth = child.getMeasuredWidth();
            final int childHeight = child.getMeasuredHeight();
            int childLeft;

            final float newOffset;
            if (checkDrawerViewGravity(child, Gravity.LEFT)) {
                childLeft = -childWidth + (int) (childWidth * lp.onScreen);
                newOffset = (float) (childWidth + childLeft) / childWidth;
            } else { // Right; onMeasure checked for us.
                childLeft = width - (int) (childWidth * lp.onScreen);
                newOffset = (float) (width - childLeft) / childWidth;
            }

            final boolean changeOffset = newOffset != lp.onScreen;

            final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;

            switch (vgrav) {
            default:
            case Gravity.TOP: {
                child.layout(childLeft, lp.topMargin, childLeft + childWidth, childHeight);
                break;
            }

            case Gravity.BOTTOM: {
                final int height = b - t;
                child.layout(childLeft, height - lp.bottomMargin - child.getMeasuredHeight(),
                        childLeft + childWidth, height - lp.bottomMargin);
                break;
            }

            case Gravity.CENTER_VERTICAL: {
                final int height = b - t;
                int childTop = (height - childHeight) / 2;

                // Offset for margins. If things don't fit right because of
                // bad measurement before, oh well.
                if (childTop < lp.topMargin) {
                    childTop = lp.topMargin;
                } else if (childTop + childHeight > height - lp.bottomMargin) {
                    childTop = height - lp.bottomMargin - childHeight;
                }
                child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
                break;
            }
            }

            if (changeOffset) {
                setDrawerViewOffset(child, newOffset);
            }

            final int newVisibility = lp.onScreen > 0 ? VISIBLE : INVISIBLE;
            if (child.getVisibility() != newVisibility) {
                child.setVisibility(newVisibility);
            }
        }
    }
    mInLayout = false;
    mFirstLayout = false;
}

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

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;//from www . j av  a  2 s.  c o  m
    final int width = r - l;

    View contentView = findContentView();
    View drawerView = findDrawerView();

    LayoutParams drawerLp = (LayoutParams) drawerView.getLayoutParams();
    LayoutParams contentLp = (LayoutParams) contentView.getLayoutParams();

    int contentRight = contentLp.getMarginStart() + getWidth();
    contentView.layout(contentRight - contentView.getMeasuredWidth(), contentLp.topMargin, contentRight,
            contentLp.topMargin + contentView.getMeasuredHeight());

    final int childHeight = drawerView.getMeasuredHeight();
    int onScreen = (int) (drawerView.getWidth() * drawerLp.onScreen);
    int offset;
    if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) {
        offset = onScreen - drawerView.getWidth();
    } else {
        offset = width - onScreen;
    }
    drawerView.layout(drawerLp.getMarginStart() + offset, drawerLp.topMargin,
            width - drawerLp.getMarginEnd() + offset, childHeight + drawerLp.topMargin);
    updateDrawerAlpha();
    updateViewFaders();
    if (mFirstLayout) {

        // TODO(b/15394507): Normally, onMeasure()/onLayout() are called three times when
        // you create CarDrawerLayout, but when you pop it back it's only called once which
        // leaves us in a weird state. This is a pretty ugly hack to fix that.
        mHandler.post(mInvalidateRunnable);

        mFirstLayout = false;
    }

    if (mNeedsFocus) {
        if (initializeFocus()) {
            mNeedsFocus = false;
        }
    }

    mInLayout = false;
}

From source file:com.hippo.nimingban.ui.ListActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent;//from   w  w  w. j  av a 2s.  c  om
    switch (item.getItemId()) {
    case android.R.id.home:
        if (mSlidingDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
            mSlidingDrawerLayout.closeDrawer(Gravity.LEFT);
        } else {
            mSlidingDrawerLayout.openDrawer(Gravity.LEFT);
        }
        mSlidingDrawerLayout.closeDrawer(Gravity.RIGHT);
        return true;
    case R.id.action_rule:
        if (mCurrentForum != null && mCurrentForum.getNMBMsg() != null) {
            View view = getLayoutInflater().inflate(R.layout.dialog_rule, null);
            TextView tv = (TextView) view.findViewById(R.id.text);
            tv.setText(fixURLSpan(Html.fromHtml(mCurrentForum.getNMBMsg(),
                    new URLImageGetter(tv, NMBApplication.getConaco(this)), null)));
            tv.setMovementMethod(new LinkMovementMethod2(ListActivity.this));
            new AlertDialog.Builder(this).setTitle(R.string.rule).setView(view).show();
        }
        return true;
    case R.id.action_create_post:
        if (mCurrentForum != null) {
            intent = new Intent(this, TypeSendActivity.class);
            intent.setAction(TypeSendActivity.ACTION_CREATE_POST);
            intent.putExtra(TypeSendActivity.KEY_SITE, mCurrentForum.getNMBSite().getId());
            intent.putExtra(TypeSendActivity.KEY_ID, mCurrentForum.getNMBId());
            startActivity(intent);
        }
        return true;
    case R.id.action_refresh:
        mPostHelper.refresh();
        return true;
    case R.id.action_sort_forums:
        intent = new Intent(this, SortForumsActivity.class);
        intent.putExtra(SortForumsActivity.KEY_SITE, ACSite.getInstance().getId()); // TODO support other site
        startActivityForResult(intent, REQUEST_CODE_SORT_FORUMS);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.abewy.android.apps.klyph.widget.KlyphDrawerLayout.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;/*from  w w w . j a  v  a2 s  .c om*/
    final int width = r - l;
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (isContentView(child)) {
            child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(),
                    lp.topMargin + child.getMeasuredHeight());
        } else { // Drawer, if it wasn't onMeasure would have thrown an exception.
            final int childWidth = child.getMeasuredWidth();
            final int childHeight = child.getMeasuredHeight();
            int childLeft;

            final float newOffset;
            if (checkDrawerViewGravity(child, Gravity.LEFT)) {
                childLeft = -childWidth + (int) (childWidth * lp.onScreen);
                newOffset = (float) (childWidth + childLeft) / childWidth;
            } else { // Right; onMeasure checked for us.
                childLeft = width - (int) (childWidth * lp.onScreen);
                newOffset = (float) (width - childLeft) / childWidth;
            }

            final boolean changeOffset = newOffset != lp.onScreen;

            final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;

            switch (vgrav) {
            default:
            case Gravity.TOP: {
                child.layout(childLeft, lp.topMargin, childLeft + childWidth, childHeight);
                break;
            }

            case Gravity.BOTTOM: {
                final int height = b - t;
                child.layout(childLeft, height - lp.bottomMargin - child.getMeasuredHeight(),
                        childLeft + childWidth, height - lp.bottomMargin);
                break;
            }

            case Gravity.CENTER_VERTICAL: {
                final int height = b - t;
                int childTop = (height - childHeight) / 2;

                // Offset for margins. If things don't fit right because of
                // bad measurement before, oh well.
                if (childTop < lp.topMargin) {
                    childTop = lp.topMargin;
                } else if (childTop + childHeight > height - lp.bottomMargin) {
                    childTop = height - lp.bottomMargin - childHeight;
                }
                child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
                break;
            }
            }

            if (changeOffset) {
                setDrawerViewOffset(child, newOffset);
            }

            final int newVisibility = lp.onScreen > 0 ? VISIBLE : INVISIBLE;
            if (child.getVisibility() != newVisibility) {
                child.setVisibility(newVisibility);
            }
        }
    }
    mInLayout = false;
    mFirstLayout = false;
}

From source file:ca.co.rufus.androidboilerplate.ui.DebugDrawerLayout.java

void moveDrawerToOffset(View drawerView, float slideOffset) {
    final float oldOffset = getDrawerViewOffset(drawerView);
    final int width = drawerView.getWidth();
    final int oldPos = (int) (width * oldOffset);
    final int newPos = (int) (width * slideOffset);
    final int dx = newPos - oldPos;

    drawerView.offsetLeftAndRight(checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT) ? dx : -dx);
    setDrawerViewOffset(drawerView, slideOffset);
}