Search in sources :

Example 1 with ViewDragHelper

use of androidx.customview.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
 */
private 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(androidx.customview.widget.ViewDragHelper) Point(android.graphics.Point) Point(android.graphics.Point) ApiException(net.dean.jraw.ApiException) NetworkException(net.dean.jraw.http.NetworkException)

Aggregations

Point (android.graphics.Point)1 ViewDragHelper (androidx.customview.widget.ViewDragHelper)1 Field (java.lang.reflect.Field)1 ApiException (net.dean.jraw.ApiException)1 NetworkException (net.dean.jraw.http.NetworkException)1