Search in sources :

Example 1 with ViewDragHelper

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);
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) DrawerLayout(android.support.v4.widget.DrawerLayout) View(android.view.View)

Example 2 with ViewDragHelper

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);
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) DrawerLayout(android.support.v4.widget.DrawerLayout) View(android.view.View)

Example 3 with ViewDragHelper

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

Example 4 with ViewDragHelper

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");
    }
}
Also used : Field(java.lang.reflect.Field) ViewDragHelper(android.support.v4.widget.ViewDragHelper) Point(android.graphics.Point) Point(android.graphics.Point)

Example 5 with ViewDragHelper

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

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