Search in sources :

Example 6 with ViewDragHelper

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;
    }
}
Also used : ViewDragHelper(android.support.v4.widget.ViewDragHelper) View(android.view.View) Paint(android.graphics.Paint)

Example 7 with ViewDragHelper

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());
}
Also used : GestureDetectorCompat(android.support.v4.view.GestureDetectorCompat)

Example 8 with ViewDragHelper

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");
    }
}
Also used : Field(java.lang.reflect.Field) ViewDragHelper(android.support.v4.widget.ViewDragHelper) Point(android.graphics.Point) Point(android.graphics.Point) ApiException(net.dean.jraw.ApiException) ActivityNotFoundException(android.content.ActivityNotFoundException) NetworkException(net.dean.jraw.http.NetworkException)

Example 9 with ViewDragHelper

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);
}
Also used : ViewDragHelper(android.support.v4.widget.ViewDragHelper) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 10 with ViewDragHelper

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);
}
Also used : ViewDragHelper(android.support.v4.widget.ViewDragHelper) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ViewDragHelper (android.support.v4.widget.ViewDragHelper)8 View (android.view.View)6 Paint (android.graphics.Paint)3 Field (java.lang.reflect.Field)3 Point (android.graphics.Point)2 UiController (android.support.test.espresso.UiController)2 ViewAction (android.support.test.espresso.ViewAction)2 DrawerLayout (android.support.v4.widget.DrawerLayout)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 SuppressLint (android.annotation.SuppressLint)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 GestureDetectorCompat (android.support.v4.view.GestureDetectorCompat)1 ApiException (net.dean.jraw.ApiException)1 NetworkException (net.dean.jraw.http.NetworkException)1