use of android.support.v4.widget.ViewDragHelper in project u2020 by JakeWharton.
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;
}
}
use of android.support.v4.widget.ViewDragHelper in project JJSwipeBack by android-cjj.
the class SwipeBackLayout method init.
/**
* 初始化
*/
private void init() {
// 创建ViewDragHelper的实例,第一个参数是ViewGroup,传自己,第二个灵敏度,一般正常是1.0,不正常你自己写,第三个是回调,看下面...
mViewDragHelper = ViewDragHelper.create(this, 1.0f, new DragHelperCallback());
// 手势操作,第二参数什么意思看下面
mGestureDetectorCompat = new GestureDetectorCompat(getContext(), new XScrollDetector());
}
use of android.support.v4.widget.ViewDragHelper in project Slide by ccrama.
the class MainActivity 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 Slidr by r0adkll.
the class SliderPanelTest method testOnTouchEvent_whenNotLocked.
@Test
public void testOnTouchEvent_whenNotLocked() throws Exception {
// given
SliderPanel sliderPanel = Mockito.spy(new SliderPanel(context));
setInternalState(sliderPanel, "isLocked", false);
ViewDragHelper viewDragHelper = Mockito.mock(ViewDragHelper.class);
setInternalState(sliderPanel, "dragHelper", viewDragHelper);
// when
boolean result = sliderPanel.onTouchEvent(motionEvent);
// then
assertTrue("Result must be true when not locked", result);
}
use of android.support.v4.widget.ViewDragHelper in project Slidr by r0adkll.
the class SliderPanelTest method testOnTouchEvent_whenNotLocked_butExceptionInProcessTouchEvent.
@Test
public void testOnTouchEvent_whenNotLocked_butExceptionInProcessTouchEvent() throws Exception {
// given
SliderPanel sliderPanel = Mockito.spy(new SliderPanel(context));
setInternalState(sliderPanel, "isLocked", false);
ViewDragHelper viewDragHelper = Mockito.mock(ViewDragHelper.class);
PowerMockito.doThrow(new IllegalArgumentException()).when(viewDragHelper).processTouchEvent(motionEvent);
setInternalState(sliderPanel, "dragHelper", viewDragHelper);
// when
boolean result = sliderPanel.onTouchEvent(motionEvent);
// then
assertFalse("Result must be false when not locked but exception occured during processTouchEvent()", result);
}
Aggregations