Example usage for android.support.v4.view GravityCompat getAbsoluteGravity

List of usage examples for android.support.v4.view GravityCompat getAbsoluteGravity

Introduction

In this page you can find the example usage for android.support.v4.view GravityCompat getAbsoluteGravity.

Prototype

public static int getAbsoluteGravity(int i, int i2) 

Source Link

Usage

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

/**
 * Sets the title of the drawer with the given gravity.
 * <p>//from w ww . ja  va2  s  .com
 * When accessibility is turned on, this is the title that will be used to
 * identify the drawer to the active accessibility service.
 *
 * @param edgeGravity Gravity.LEFT, RIGHT, START or END. Expresses which
 *            drawer to set the title for.
 * @param title The title for the drawer.
 */
public void setDrawerTitle(@EdgeGravity int edgeGravity, CharSequence title) {
    final int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this));
    if (absGravity == Gravity.LEFT) {
        mTitleLeft = title;
    } else if (absGravity == Gravity.RIGHT) {
        mTitleRight = title;
    }
}

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

/**
 * @return the absolute gravity of the child drawerView, resolved according
 *         to the current layout direction
 *//*from   w w w  .  ja va 2 s  .c  om*/
private int getDrawerViewAbsoluteGravity(View drawerView) {
    final int gravity = ((LayoutParams) drawerView.getLayoutParams()).gravity;
    return GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this));
}

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

/**
 * Returns the title of the drawer with the given gravity.
 *
 * @param edgeGravity Gravity.LEFT, RIGHT, START or END. Expresses which
 *            drawer to return the title for.
 * @return The title of the drawer, or null if none set.
 * @see #setDrawerTitle(int, CharSequence)
 */// w  w  w .j  a v  a 2 s.co  m
@Nullable
public CharSequence getDrawerTitle(@EdgeGravity int edgeGravity) {
    final int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this));
    if (absGravity == Gravity.LEFT) {
        return mTitleLeft;
    } else if (absGravity == Gravity.RIGHT) {
        return mTitleRight;
    }
    return null;
}

From source file:android.support.v7.view.menu.CascadingMenuPopup.java

@Override
public void setGravity(int dropDownGravity) {
    if (mRawDropDownGravity != dropDownGravity) {
        mRawDropDownGravity = dropDownGravity;
        mDropDownGravity = GravityCompat.getAbsoluteGravity(dropDownGravity,
                ViewCompat.getLayoutDirection(mAnchorView));
    }//  w w  w  . j  a v  a2 s  .  c  o  m
}

From source file:com.huangj.huangjlibrary.widget.drawerlayout.DrawerLayout.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//ww  w. ja  va2 s. 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));

    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 : 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.example.verticaldrawerlayout.VerticalDrawerLayout.java

/**
 * @param gravity/*from  ww  w.j av  a  2  s.c o  m*/
 *            the gravity of the child to return. If specified as a
 *            relative value, it will be resolved according to the current
 *            layout direction.
 * @return the drawer with the specified gravity
 */
View findDrawerWithGravity(int gravity) {
    final int absHorizGravity = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this))
            & Gravity.VERTICAL_GRAVITY_MASK;
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final int childAbsGravity = getDrawerViewAbsoluteGravity(child);
        if ((childAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) == absHorizGravity) {
            return child;
        }
    }
    return null;
}

From source file:android.support.v7.view.menu.CascadingMenuPopup.java

@Override
public void setAnchorView(@NonNull View anchor) {
    if (mAnchorView != anchor) {
        mAnchorView = anchor;/* w w w .j  a v  a2s  .co m*/

        // Gravity resolution may have changed, update from raw gravity.
        mDropDownGravity = GravityCompat.getAbsoluteGravity(mRawDropDownGravity,
                ViewCompat.getLayoutDirection(mAnchorView));
    }
}

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 . j  a v  a 2s .  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:ca.co.rufus.androidboilerplate.ui.DebugDrawerLayout.java

/**
 * @return the absolute gravity of the child drawerView, resolved according
 *         to the current layout direction
 *///from  w  w  w  . jav  a  2  s  .  co m
int getDrawerViewAbsoluteGravity(View drawerView) {
    final int gravity = ((LayoutParams) drawerView.getLayoutParams()).gravity;
    return GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this));
}

From source file:org.gateshipone.malp.application.activities.MainActivity.java

@Override
public void editProfile(MPDServerProfile profile) {
    if (null == profile) {
        profile = new MPDServerProfile(getString(R.string.fragment_profile_default_name), true);
        addProfile(profile);/*from   w  w  w.j  a  v  a2  s .c o m*/
    }

    // Create fragment and give it an argument for the selected article
    EditProfileFragment newFragment = new EditProfileFragment();
    Bundle args = new Bundle();
    if (null != profile) {
        args.putParcelable(EditProfileFragment.EXTRA_PROFILE, profile);
    }

    newFragment.setArguments(args);

    android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    newFragment.setEnterTransition(new Slide(GravityCompat.getAbsoluteGravity(GravityCompat.START,
            getResources().getConfiguration().getLayoutDirection())));
    newFragment.setExitTransition(new Slide(GravityCompat.getAbsoluteGravity(GravityCompat.END,
            getResources().getConfiguration().getLayoutDirection())));
    // Replace whatever is in the fragment_container view with this
    // fragment,
    // and add the transaction to the back stack so the user can navigate
    // back
    transaction.replace(R.id.fragment_container, newFragment, EditProfileFragment.TAG);
    transaction.addToBackStack("EditProfileFragment");

    // Commit the transaction
    transaction.commit();
}