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

/**
 * Open the specified drawer view by animating it into view.
 *
 * @param drawerView Drawer view to open
 *//* ww w.jav  a  2  s.c o  m*/
public void openDrawer(View drawerView) {
    if (!isDrawerView(drawerView)) {
        throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer");
    }

    final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
    if (mFirstLayout) {
        lp.onScreen = 1.f;
        lp.openState = LayoutParams.FLAG_IS_OPENED;

        updateChildrenImportantForAccessibility(drawerView, true);
    } else {
        lp.openState |= LayoutParams.FLAG_IS_OPENING;

        if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) {
            mLeftDragger.smoothSlideViewTo(drawerView, 0, drawerView.getTop());
        } else if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.TOP)) {
            mTopDragger.smoothSlideViewTo(drawerView, drawerView.getLeft(), 0);
        } else if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.RIGHT)) {
            mRightDragger.smoothSlideViewTo(drawerView, getWidth() - drawerView.getWidth(),
                    drawerView.getTop());
        } else {
            mBottomDragger.smoothSlideViewTo(drawerView, drawerView.getLeft(),
                    getHeight() - drawerView.getHeight());
        }

    }
    invalidate();
}

From source file:com.huangj.huangjlibrary.widget.drawerlayout.DrawerLayout.java

@Override
protected void onRestoreInstanceState(Parcelable state) {
    if (!(state instanceof SavedState)) {
        super.onRestoreInstanceState(state);
        return;//from   w  w w .  ja  va2s  .  c o m
    }

    final SavedState ss = (SavedState) state;
    super.onRestoreInstanceState(ss.getSuperState());

    if (ss.openDrawerGravity != Gravity.NO_GRAVITY) {
        final View toOpen = findDrawerWithGravity(ss.openDrawerGravity);
        if (toOpen != null) {
            openDrawer(toOpen);
        }
    }

    if (ss.lockModeLeft != LOCK_MODE_UNDEFINED) {
        setDrawerLockMode(ss.lockModeLeft, Gravity.LEFT);
    }
    if (ss.lockModeRight != LOCK_MODE_UNDEFINED) {
        setDrawerLockMode(ss.lockModeRight, Gravity.RIGHT);
    }
    if (ss.lockModeStart != LOCK_MODE_UNDEFINED) {
        setDrawerLockMode(ss.lockModeStart, GravityCompat.START);
    }
    if (ss.lockModeEnd != LOCK_MODE_UNDEFINED) {
        setDrawerLockMode(ss.lockModeEnd, GravityCompat.END);
    }
}

From source file:com.av.remusic.widget.RoundViewPager.java

/**
 * This method will be invoked when the currentPosition 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.//from ww w  .ja v  a 2s. c o m
 *
 * @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.
 * @param offsetPixels Value in pixels indicating the offset from position.
 */
@CallSuper
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);
            }
        }
    }

    dispatchOnPageScrolled(position, offset, offsetPixels);

    if (mPageTransformer != null) {
        final int scrollX = getScrollX();
        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 float transformPos = (float) (child.getLeft() - scrollX) / getClientWidth();
            mPageTransformer.transformPage(child, transformPos);
        }
    }

    mCalledSuper = true;
}

From source file:com.zyk.drawerlayout.widget.DrawerLayout.java

/**
 * Close the specified drawer view by animating it into view.
 *
 * @param drawerView Drawer view to close
 *//*ww w.j a  v  a  2  s.  com*/
public void closeDrawer(View drawerView) {
    if (!isDrawerView(drawerView)) {
        throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer");
    }

    final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
    if (mFirstLayout) {
        lp.onScreen = 0.f;
        lp.openState = 0;
    } else {
        lp.openState |= LayoutParams.FLAG_IS_CLOSING;

        if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) {
            mLeftDragger.smoothSlideViewTo(drawerView, -drawerView.getWidth() + mLeftHeader,
                    drawerView.getTop());
        } else if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.TOP)) {
            mTopDragger.smoothSlideViewTo(drawerView, drawerView.getLeft(),
                    -drawerView.getHeight() + mTopHeader);
        } else if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.RIGHT)) {
            mRightDragger.smoothSlideViewTo(drawerView, getWidth() - mRightHeader, drawerView.getTop());
        } else {
            mBottomDragger.smoothSlideViewTo(drawerView, drawerView.getLeft(), getHeight() - mBottomHeader);
        }
    }
    invalidate();
}

From source file:com.viewpagerindicator.MyDirectionalViewPager.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.//from  ww  w.  j  ava2 s  .co m
 *
 * @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.
 * @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) {
        if (mOrientation == HORIZONTAL) {
            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);
                }
            }
        } else {
            final int scrollY = getScrollY();
            int paddingTop = getPaddingTop();
            int paddingBottom = getPaddingBottom();
            final int height = getHeight();
            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 childTop = 0;
                switch (hgrav) {
                default:
                    childTop = paddingTop;
                    break;
                case Gravity.LEFT:
                    childTop = paddingTop;
                    paddingTop += child.getWidth();
                    break;
                case Gravity.CENTER_HORIZONTAL:
                    childTop = Math.max((height - child.getMeasuredWidth()) / 2, paddingTop);
                    break;
                case Gravity.RIGHT:
                    childTop = height - paddingBottom - child.getMeasuredWidth();
                    paddingTop += child.getMeasuredWidth();
                    break;
                }
                childTop += scrollY;

                final int childOffset = childTop - child.getTop();
                if (childOffset != 0) {
                    child.offsetLeftAndRight(childOffset);
                }
            }
        }
    }

    if (mOnPageChangeListener != null) {
        mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }
    if (mInternalPageChangeListener != null) {
        mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }

    if (mPageTransformer != null) {
        final int scrollX = getScrollX();
        final int scrollY = getScrollY();
        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 float transformPos;
            if (mOrientation == HORIZONTAL) {
                transformPos = (float) (child.getLeft() - scrollX) / getClientWidth();
            } else {
                transformPos = (float) (child.getTop() - scrollY) / getClientHeight();
            }
            mPageTransformer.transformPage(child, transformPos);
        }
    }

    mCalledSuper = true;
}

From source file:com.example.sky.test.view.ViewPager.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.//from www . ja  v  a2  s  . c  o m
 *
 * @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.
 * @param offsetPixels Value in pixels indicating the offset from position.
 */
@CallSuper
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 ViewPager.LayoutParams lp = (ViewPager.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);
            }
        }
    }

    dispatchOnPageScrolled(position, offset, offsetPixels);

    if (mPageTransformer != null) {
        final int scrollX = getScrollX();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final ViewPager.LayoutParams lp = (ViewPager.LayoutParams) child.getLayoutParams();

            if (lp.isDecor)
                continue;
            final float transformPos = (float) (child.getLeft() - scrollX) / getClientWidth();
            mPageTransformer.transformPage(child, transformPos);
        }
    }

    mCalledSuper = true;
}

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

private void updateUsersListFragmentVisibility() {
    boolean hide = true;
    if (userListView != null) {
        ChannelsDataSource.Channel c = null;
        if (buffer != null && buffer.type.equals("channel")) {
            c = ChannelsDataSource.getInstance().getChannelForBuffer(buffer.bid);
            if (c != null)
                hide = false;/*from www  .ja  v  a2  s . com*/
        }
        try {
            if (conn != null && conn.getUserInfo() != null && conn.getUserInfo().prefs != null
                    && findViewById(R.id.usersListFragment2) != null) {
                JSONObject hiddenMap = conn.getUserInfo().prefs.getJSONObject("channel-hiddenMembers");
                if (hiddenMap.has(String.valueOf(buffer.bid))
                        && hiddenMap.getBoolean(String.valueOf(buffer.bid)))
                    hide = true;
            }
        } catch (Exception e) {
        }
        if (hide) {
            userListView.setVisibility(View.GONE);
            if (drawerLayout != null) {
                if (findViewById(R.id.usersListFragment2) != null && c != null)
                    drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.RIGHT);
                else
                    drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.RIGHT);
            }
        } else {
            userListView.setVisibility(View.VISIBLE);
            if (drawerLayout != null) {
                if (findViewById(R.id.usersListFragment2) != null)
                    drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.RIGHT);
                else
                    drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.RIGHT);
            }
        }
    }
}

From source file:com.klinker.android.launcher.launcher3.Launcher.java

@Override
protected void onNewIntent(Intent intent) {
    long startTime = 0;
    if (DEBUG_RESUME_TIME) {
        startTime = System.currentTimeMillis();
    }/*from  ww w  .  jav a2 s. c  om*/
    super.onNewIntent(intent);

    // Close the menu
    if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        final boolean alreadyOnHome = mHasFocus && ((intent.getFlags()
                & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);

        if (mLauncherDrawer.isDrawerOpen(Gravity.LEFT)) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    mLauncherDrawer.closeDrawer(Gravity.LEFT);
                }
            }, 300);

            return;
        } else if (mLauncherDrawer.isDrawerOpen(Gravity.RIGHT)) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    mLauncherDrawer.closeDrawer(Gravity.RIGHT);
                }
            }, 300);

            return;
        } else if (!isAllAppsVisible() && alreadyOnHome && mWorkspace.getCurrentPage() == 0
                && !mWorkspace.isInOverviewMode()) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    GestureUtils.runGesture(Launcher.this, Launcher.this, AppSettings.HOME_BUTTON);
                }
            }, 300);

            return;
        }

        // also will cancel mWaitingForResult.
        closeSystemDialogs();

        if (mWorkspace == null) {
            // Can be cases where mWorkspace is null, this prevents a NPE
            return;
        }
        Folder openFolder = mWorkspace.getOpenFolder();
        // In all these cases, only animate if we're already on home
        mWorkspace.exitWidgetResizeMode();

        boolean moveToDefaultScreen = mLauncherCallbacks != null
                ? mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent()
                : true;
        if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() && openFolder == null
                && moveToDefaultScreen) {
            mWorkspace.moveToDefaultScreen(true);
        }

        closeFolder();
        exitSpringLoadedDragMode();

        // If we are already on home, then just animate back to the workspace,
        // otherwise, just wait until onResume to set the state back to Workspace
        if (alreadyOnHome) {
            showWorkspace(true);
        } else {
            mOnResumeState = State.WORKSPACE;
        }

        final View v = getWindow().peekDecorView();
        if (v != null && v.getWindowToken() != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }

        // Reset the apps view
        if (!alreadyOnHome && mAppsView != null) {
            mAppsView.scrollToTop();
        }

        // Reset the widgets view
        if (!alreadyOnHome && mWidgetsView != null) {
            mWidgetsView.scrollToTop();
        }

        if (mLauncherCallbacks != null) {
            mLauncherCallbacks.onHomeIntent();
        }
    }

    if (DEBUG_RESUME_TIME) {
        Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
    }

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onNewIntent(intent);
    }
}

From source file:com.zyk.drawerlayout.widget.DrawerLayout.java

@Override
protected void onRestoreInstanceState(Parcelable state) {
    final SavedState ss = (SavedState) state;
    super.onRestoreInstanceState(ss.getSuperState());

    if (ss.openDrawerGravity != Gravity.NO_GRAVITY) {
        final View toOpen = findDrawerWithGravity(ss.openDrawerGravity);
        if (toOpen != null) {
            openDrawer(toOpen);//from w  ww .  j  a  v  a2 s. c  om
        }
    }

    if (ss.lockModeLeft != LOCK_MODE_UNDEFINED) {
        setDrawerLockMode(ss.lockModeLeft, Gravity.LEFT);
    }
    if (ss.lockModeTop != LOCK_MODE_UNDEFINED) {
        setDrawerLockMode(ss.lockModeTop, Gravity.TOP);
    }
    if (ss.lockModeRight != LOCK_MODE_UNDEFINED) {
        setDrawerLockMode(ss.lockModeRight, Gravity.RIGHT);
    }
    if (ss.lockModeBottom != LOCK_MODE_UNDEFINED) {
        setDrawerLockMode(ss.lockModeBottom, Gravity.BOTTOM);
    }
    if (ss.lockModeStart != LOCK_MODE_UNDEFINED) {
        setDrawerLockMode(ss.lockModeStart, GravityCompat.START);
    }
    if (ss.lockModeEnd != LOCK_MODE_UNDEFINED) {
        setDrawerLockMode(ss.lockModeEnd, GravityCompat.END);
    }
}