Search in sources :

Example 11 with ViewDragHelper

use of android.support.v4.widget.ViewDragHelper in project apps-android-wikipedia by wikimedia.

the class WikiDrawerLayout method setDragEdgeWidth.

/**
 * Set the drag margin width.
 * @param width Width in pixels.
 */
public void setDragEdgeWidth(final int width) {
    this.post(() -> {
        try {
            // Use a little bit of reflection to set a private member in DrawerLayout that extends the
            // "drag edge" from which the drawer can be pulled by the user.
            // A bit hacky, but what are you gonna do...
            View pullOutView = getChildAt(1);
            int absGravity = GravityCompat.getAbsoluteGravity(((LayoutParams) pullOutView.getLayoutParams()).gravity, ViewCompat.getLayoutDirection(pullOutView));
            // Determine whether to modify the left or right dragger, based on RTL/LTR orientation
            @SuppressLint("RtlHardcoded") Field mDragger = (absGravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.LEFT ? WikiDrawerLayout.this.getClass().getSuperclass().getSuperclass().getDeclaredField("mLeftDragger") : WikiDrawerLayout.this.getClass().getSuperclass().getSuperclass().getDeclaredField("mRightDragger");
            mDragger.setAccessible(true);
            ViewDragHelper dragHelper = (ViewDragHelper) mDragger.get(WikiDrawerLayout.this);
            Field edgeWidth = dragHelper.getClass().getDeclaredField("mEdgeSize");
            edgeWidth.setAccessible(true);
            edgeWidth.setInt(dragHelper, width);
        } catch (Exception e) {
            L.e("Setting the draggable zone for the drawer failed!", e);
        }
    });
}
Also used : Field(java.lang.reflect.Field) ViewDragHelper(android.support.v4.widget.ViewDragHelper) SuppressLint(android.annotation.SuppressLint) View(android.view.View) SuppressLint(android.annotation.SuppressLint)

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