use of android.support.v4.widget.ViewDragHelper in project material-components-android by material-components.
the class DrawerLayoutActions method openDrawer.
/** Opens the drawer at the specified edge gravity. */
public static ViewAction openDrawer(final int drawerEdgeGravity) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isAssignableFrom(DrawerLayout.class);
}
@Override
public String getDescription() {
return "Opens the drawer";
}
@Override
public void perform(UiController uiController, View view) {
uiController.loopMainThreadUntilIdle();
DrawerLayout drawerLayout = (DrawerLayout) view;
drawerLayout.openDrawer(drawerEdgeGravity);
// Wait for a full second to let the inner ViewDragHelper complete the operation
uiController.loopMainThreadForAtLeast(1000);
}
};
}
use of android.support.v4.widget.ViewDragHelper in project material-components-android by material-components.
the class DrawerLayoutActions method closeDrawer.
/** Closes the drawer at the specified edge gravity. */
public static ViewAction closeDrawer(final int drawerEdgeGravity) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isAssignableFrom(DrawerLayout.class);
}
@Override
public String getDescription() {
return "Closes the drawer";
}
@Override
public void perform(UiController uiController, View view) {
uiController.loopMainThreadUntilIdle();
DrawerLayout drawerLayout = (DrawerLayout) view;
drawerLayout.closeDrawer(drawerEdgeGravity);
// Wait for a full second to let the inner ViewDragHelper complete the operation
uiController.loopMainThreadForAtLeast(1000);
}
};
}
use of android.support.v4.widget.ViewDragHelper in project Klyph by jonathangerbaud.
the class KlyphDrawerLayout method setDrawerLockMode.
/**
* 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
* @see #LOCK_MODE_LOCKED_CLOSED
* @see #LOCK_MODE_LOCKED_OPEN
*/
public void setDrawerLockMode(int lockMode, int edgeGravity) {
final int absGrav = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this));
if (absGrav == Gravity.LEFT) {
mLockModeLeft = lockMode;
} else if (absGrav == Gravity.RIGHT) {
mLockModeRight = lockMode;
}
if (lockMode != LOCK_MODE_UNLOCKED) {
// Cancel interaction in progress
final ViewDragHelper helper = absGrav == Gravity.LEFT ? mLeftDragger : mRightDragger;
helper.cancel();
}
switch(lockMode) {
case LOCK_MODE_LOCKED_OPEN:
final View toOpen = findDrawerWithGravity(absGrav);
if (toOpen != null) {
openDrawer(toOpen);
}
break;
case LOCK_MODE_LOCKED_CLOSED:
final View toClose = findDrawerWithGravity(absGrav);
if (toClose != null) {
closeDrawer(toClose);
}
break;
}
}
use of android.support.v4.widget.ViewDragHelper in project Slide by ccrama.
the class NewsActivity method setDrawerEdge.
/**
* Set the drawer edge (i.e. how sensitive the drawer is) Based on a given screen width
* percentage.
*
* @param displayWidthPercentage larger the value, the more sensitive the drawer swipe is;
* percentage of screen width
* @param drawerLayout drawerLayout to adjust the swipe edge
*/
public static void setDrawerEdge(Activity activity, final float displayWidthPercentage, DrawerLayout drawerLayout) {
try {
Field mDragger = drawerLayout.getClass().getSuperclass().getDeclaredField("mLeftDragger");
mDragger.setAccessible(true);
ViewDragHelper leftDragger = (ViewDragHelper) mDragger.get(drawerLayout);
Field mEdgeSize = leftDragger.getClass().getDeclaredField("mEdgeSize");
mEdgeSize.setAccessible(true);
final int currentEdgeSize = mEdgeSize.getInt(leftDragger);
Point displaySize = new Point();
activity.getWindowManager().getDefaultDisplay().getSize(displaySize);
mEdgeSize.setInt(leftDragger, Math.max(currentEdgeSize, (int) (displaySize.x * displayWidthPercentage)));
} catch (Exception e) {
LogUtil.e(e + ": Exception thrown while changing navdrawer edge size");
}
}
use of android.support.v4.widget.ViewDragHelper in project sbt-android by scala-android.
the class DebugDrawerLayout method setDrawerLockMode.
/**
* 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
* @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));
if (absGravity == Gravity.LEFT) {
mLockModeLeft = lockMode;
} else if (absGravity == Gravity.RIGHT) {
mLockModeRight = lockMode;
}
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;
}
}
Aggregations