DrawerLayout.java revision 3cf6141d516a0a6170823b1bda5c0b6d7500e76c
11d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell/*
21d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * Copyright (C) 2013 The Android Open Source Project
31d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell *
41d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * Licensed under the Apache License, Version 2.0 (the "License");
51d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * you may not use this file except in compliance with the License.
61d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * You may obtain a copy of the License at
71d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell *
81d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell *      http://www.apache.org/licenses/LICENSE-2.0
91d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell *
101d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * Unless required by applicable law or agreed to in writing, software
111d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * distributed under the License is distributed on an "AS IS" BASIS,
121d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * See the License for the specific language governing permissions and
141d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * limitations under the License.
151d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell */
161d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
171d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
181d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powellpackage android.support.v4.widget;
191d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
201d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powellimport android.content.Context;
211d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powellimport android.content.res.TypedArray;
221d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powellimport android.graphics.Canvas;
231d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powellimport android.graphics.Paint;
24b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powellimport android.graphics.PixelFormat;
253cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powellimport android.graphics.Rect;
26b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powellimport android.graphics.drawable.Drawable;
2757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powellimport android.os.Parcel;
2857902cff6c54c245feea589b06d12dba8f1a2a24Adam Powellimport android.os.Parcelable;
29cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powellimport android.os.SystemClock;
307d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powellimport android.support.v4.view.AccessibilityDelegateCompat;
311d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powellimport android.support.v4.view.GravityCompat;
32791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powellimport android.support.v4.view.KeyEventCompat;
331d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powellimport android.support.v4.view.MotionEventCompat;
341d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powellimport android.support.v4.view.ViewCompat;
357d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powellimport android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
361d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powellimport android.util.AttributeSet;
371d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powellimport android.view.Gravity;
38791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powellimport android.view.KeyEvent;
391d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powellimport android.view.MotionEvent;
401d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powellimport android.view.View;
411d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powellimport android.view.ViewGroup;
423cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powellimport android.view.ViewParent;
437d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powellimport android.view.accessibility.AccessibilityEvent;
441d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
451d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell/**
461d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * DrawerLayout acts as a top-level container for window content that allows for
471d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * interactive "drawer" views to be pulled out from the edge of the window.
481d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell *
491d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * <p>Drawer positioning and layout is controlled using the <code>android:layout_gravity</code>
5009c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * attribute on child views corresponding to which side of the view you want the drawer
5109c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * to emerge from: left or right. (Or start/end on platform versions that support layout direction.)
5209c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * </p>
5309c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell *
5409c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * <p>To use a DrawerLayout, position your primary content view as the first child with
5509c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * a width and height of <code>match_parent</code>. Add drawers as child views after the main
5609c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * content view and set the <code>layout_gravity</code> appropriately. Drawers commonly use
5709c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * <code>match_parent</code> for height with a fixed width.</p>
5809c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell *
5909c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * <p>{@link DrawerListener} can be used to monitor the state and motion of drawer views.
6009c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * Avoid performing expensive operations such as layout during animation as it can cause
6109c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * stuttering; try to perform expensive operations during the {@link #STATE_IDLE} state.
6209c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * {@link SimpleDrawerListener} offers default/no-op implementations of each callback method.</p>
631d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell *
641d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * <p>As per the Android Design guide, any drawers positioned to the left/start should
651d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * always contain content for navigating around the application, whereas any drawers
661d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * positioned to the right/end should always contain actions to take on the current content.
671d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * This preserves the same navigation left, actions right structure present in the Action Bar
681d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * and elsewhere.</p>
691d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell */
701d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powellpublic class DrawerLayout extends ViewGroup {
711d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    private static final String TAG = "DrawerLayout";
721d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
731d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    /**
741d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     * Indicates that any drawers are in an idle, settled state. No animation is in progress.
751d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     */
761d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    public static final int STATE_IDLE = ViewDragHelper.STATE_IDLE;
771d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
781d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    /**
791d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     * Indicates that a drawer is currently being dragged by the user.
801d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     */
811d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    public static final int STATE_DRAGGING = ViewDragHelper.STATE_DRAGGING;
821d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
831d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    /**
841d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     * Indicates that a drawer is in the process of settling to a final position.
851d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     */
861d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    public static final int STATE_SETTLING = ViewDragHelper.STATE_SETTLING;
871d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
880492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    /**
890492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * The drawer is unlocked.
900492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     */
910492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    public static final int LOCK_MODE_UNLOCKED = 0;
920492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell
930492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    /**
940492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * The drawer is locked closed. The user may not open it, though
950492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * the app may open it programmatically.
960492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     */
970492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    public static final int LOCK_MODE_LOCKED_CLOSED = 1;
980492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell
990492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    /**
1000492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * The drawer is locked open. The user may not close it, though the app
1010492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * may close it programmatically.
1020492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     */
1030492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    public static final int LOCK_MODE_LOCKED_OPEN = 2;
1040492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell
1051d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    private static final int MIN_DRAWER_MARGIN = 64; // dp
1061d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
1071d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    private static final int DEFAULT_SCRIM_COLOR = 0x99000000;
1081d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
109ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell    /**
1101732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell     * Length of time to delay before peeking the drawer.
1111732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell     */
1121732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell    private static final int PEEK_DELAY = 160; // ms
1131732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell
1141732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell    /**
115ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell     * Experimental feature.
116ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell     */
117ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell    private static final boolean ALLOW_EDGE_LOCK = false;
118ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell
1191d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    private static final int[] LAYOUT_ATTRS = new int[] {
1201d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            android.R.attr.layout_gravity
1211d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    };
1221d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
1231d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    private int mMinDrawerMargin;
1241d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
1251d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    private int mScrimColor = DEFAULT_SCRIM_COLOR;
1261d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    private float mScrimOpacity;
1271d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    private Paint mScrimPaint = new Paint();
1281d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
1291d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    private final ViewDragHelper mLeftDragger;
1301d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    private final ViewDragHelper mRightDragger;
1311732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell    private final ViewDragCallback mLeftCallback;
1321732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell    private final ViewDragCallback mRightCallback;
1331d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    private int mDrawerState;
134b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    private boolean mInLayout;
13557902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell    private boolean mFirstLayout = true;
1360492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    private int mLockModeLeft;
1370492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    private int mLockModeRight;
1381732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell    private boolean mDisallowInterceptRequested;
139cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell    private boolean mChildrenCanceledTouch;
1401d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
1411d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    private DrawerListener mListener;
1421d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
1431d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    private float mInitialMotionX;
1441d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    private float mInitialMotionY;
1451d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
146b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    private Drawable mShadowLeft;
147b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    private Drawable mShadowRight;
148b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell
1491d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    /**
1501d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     * Listener for monitoring events about drawers.
1511d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     */
1521d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    public interface DrawerListener {
1531d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        /**
1541d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell         * Called when a drawer's position changes.
1551d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell         * @param drawerView The child view that was moved
1561d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell         * @param slideOffset The new offset of this drawer within its range, from 0-1
1571d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell         */
1581d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        public void onDrawerSlide(View drawerView, float slideOffset);
1591d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
1601d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        /**
1611d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell         * Called when a drawer has settled in a completely open state.
1621d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell         * The drawer is interactive at this point.
1631d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell         *
1641d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell         * @param drawerView Drawer view that is now open
1651d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell         */
1661d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        public void onDrawerOpened(View drawerView);
1671d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
1681d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        /**
1691d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell         * Called when a drawer has settled in a completely closed state.
1701d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell         *
1711d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell         * @param drawerView Drawer view that is now closed
1721d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell         */
1731d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        public void onDrawerClosed(View drawerView);
1741d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
1751d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        /**
1761d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell         * Called when the drawer motion state changes. The new state will
1771d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell         * be one of {@link #STATE_IDLE}, {@link #STATE_DRAGGING} or {@link #STATE_SETTLING}.
1781d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell         *
1791d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell         * @param newState The new drawer motion state
1801d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell         */
1811d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        public void onDrawerStateChanged(int newState);
1821d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
1831d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
184b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    /**
185b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * Stub/no-op implementations of all methods of {@link DrawerListener}.
186b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * Override this if you only care about a few of the available callback methods.
187b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     */
188b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    public static abstract class SimpleDrawerListener implements DrawerListener {
189b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        @Override
190b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        public void onDrawerSlide(View drawerView, float slideOffset) {
191b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        }
192b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell
193b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        @Override
194b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        public void onDrawerOpened(View drawerView) {
195b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        }
196b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell
197b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        @Override
198b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        public void onDrawerClosed(View drawerView) {
199b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        }
200b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell
201b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        @Override
202b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        public void onDrawerStateChanged(int newState) {
203b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        }
204b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    }
205b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell
2061d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    public DrawerLayout(Context context) {
2071d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        this(context, null);
2081d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
2091d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
2101d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    public DrawerLayout(Context context, AttributeSet attrs) {
2111d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        this(context, attrs, 0);
2121d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
2131d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
2141d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    public DrawerLayout(Context context, AttributeSet attrs, int defStyle) {
2151d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        super(context, attrs, defStyle);
2161d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
2171d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final float density = getResources().getDisplayMetrics().density;
2181d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        mMinDrawerMargin = (int) (MIN_DRAWER_MARGIN * density + 0.5f);
2191d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
2201732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell        mLeftCallback = new ViewDragCallback(Gravity.LEFT);
2211732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell        mRightCallback = new ViewDragCallback(Gravity.RIGHT);
2221d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
2231732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell        mLeftDragger = ViewDragHelper.create(this, 0.5f, mLeftCallback);
2241d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        mLeftDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT);
2251732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell        mLeftCallback.setDragger(mLeftDragger);
2261d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
2271732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell        mRightDragger = ViewDragHelper.create(this, 0.5f, mRightCallback);
2281d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        mRightDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_RIGHT);
2291732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell        mRightCallback.setDragger(mRightDragger);
230791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell
231791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell        // So that we can catch the back button
232791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell        setFocusableInTouchMode(true);
2337d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell
2347d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell        ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate());
2351d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
2361d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
2371d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    /**
238b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * Set a simple drawable used for the left or right shadow.
239b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * The drawable provided must have a nonzero intrinsic width.
240b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     *
241b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * @param shadowDrawable Shadow drawable to use at the edge of a drawer
242b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * @param gravity Which drawer the shadow should apply to
243b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     */
244b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    public void setDrawerShadow(Drawable shadowDrawable, int gravity) {
245b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        /*
246b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell         * TODO Someone someday might want to set more complex drawables here.
247b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell         * They're probably nuts, but we might want to consider registering callbacks,
248b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell         * setting states, etc. properly.
249b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell         */
250b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell
251b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        final int absGravity = GravityCompat.getAbsoluteGravity(gravity,
252b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                ViewCompat.getLayoutDirection(this));
253b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        if ((absGravity & Gravity.LEFT) == Gravity.LEFT) {
254b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            mShadowLeft = shadowDrawable;
255b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            invalidate();
256b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        }
257b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        if ((absGravity & Gravity.RIGHT) == Gravity.RIGHT) {
258b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            mShadowRight = shadowDrawable;
259b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            invalidate();
260b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        }
261b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    }
262b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell
263b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    /**
264b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * Set a simple drawable used for the left or right shadow.
265b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * The drawable provided must have a nonzero intrinsic width.
266b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     *
267b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * @param resId Resource id of a shadow drawable to use at the edge of a drawer
268b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * @param gravity Which drawer the shadow should apply to
269b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     */
270b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    public void setDrawerShadow(int resId, int gravity) {
271b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        setDrawerShadow(getResources().getDrawable(resId), gravity);
272b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    }
273b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell
274b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    /**
275fe130779be95af79e875bdbeac7182a424b8b9a6Adam Powell     * Set a color to use for the scrim that obscures primary content while a drawer is open.
276fe130779be95af79e875bdbeac7182a424b8b9a6Adam Powell     *
277fe130779be95af79e875bdbeac7182a424b8b9a6Adam Powell     * @param color Color to use in 0xAARRGGBB format.
278fe130779be95af79e875bdbeac7182a424b8b9a6Adam Powell     */
279fe130779be95af79e875bdbeac7182a424b8b9a6Adam Powell    public void setScrimColor(int color) {
280fe130779be95af79e875bdbeac7182a424b8b9a6Adam Powell        mScrimColor = color;
281fe130779be95af79e875bdbeac7182a424b8b9a6Adam Powell        invalidate();
282fe130779be95af79e875bdbeac7182a424b8b9a6Adam Powell    }
283fe130779be95af79e875bdbeac7182a424b8b9a6Adam Powell
284fe130779be95af79e875bdbeac7182a424b8b9a6Adam Powell    /**
2851d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     * Set a listener to be notified of drawer events.
2861d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     *
2871d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     * @param listener Listener to notify when drawer events occur
2881d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     * @see DrawerListener
2891d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     */
2901d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    public void setDrawerListener(DrawerListener listener) {
2911d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        mListener = listener;
2921d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
2931d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
2941d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    /**
2950492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * Enable or disable interaction with all drawers.
2960492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     *
2970492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * <p>This allows the application to restrict the user's ability to open or close
2980492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * any drawer within this layout. DrawerLayout will still respond to calls to
2990492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * {@link #openDrawer(int)}, {@link #closeDrawer(int)} and friends if a drawer is locked.</p>
3000492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     *
3010492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * <p>Locking drawers open or closed will implicitly open or close
3020492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * any drawers as appropriate.</p>
3030492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     *
3040492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * @param lockMode The new lock mode for the given drawer. One of {@link #LOCK_MODE_UNLOCKED},
3050492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     *                 {@link #LOCK_MODE_LOCKED_CLOSED} or {@link #LOCK_MODE_LOCKED_OPEN}.
3060492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     */
3070492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    public void setDrawerLockMode(int lockMode) {
3080492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        setDrawerLockMode(lockMode, Gravity.LEFT);
3090492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        setDrawerLockMode(lockMode, Gravity.RIGHT);
3100492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    }
3110492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell
3120492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    /**
3130492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * Enable or disable interaction with the given drawer.
3140492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     *
3150492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * <p>This allows the application to restrict the user's ability to open or close
3160492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * the given drawer. DrawerLayout will still respond to calls to {@link #openDrawer(int)},
3170492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * {@link #closeDrawer(int)} and friends if a drawer is locked.</p>
3180492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     *
3190492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * <p>Locking a drawer open or closed will implicitly open or close
3200492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * that drawer as appropriate.</p>
3210492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     *
3220492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * @param lockMode The new lock mode for the given drawer. One of {@link #LOCK_MODE_UNLOCKED},
3230492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     *                 {@link #LOCK_MODE_LOCKED_CLOSED} or {@link #LOCK_MODE_LOCKED_OPEN}.
3240492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * @param edgeGravity Gravity.LEFT, RIGHT, START or END.
3250492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     *                    Expresses which drawer to change the mode for.
3260492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     *
3270492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * @see #LOCK_MODE_UNLOCKED
3280492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * @see #LOCK_MODE_LOCKED_CLOSED
3290492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * @see #LOCK_MODE_LOCKED_OPEN
3300492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     */
3310492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    public void setDrawerLockMode(int lockMode, int edgeGravity) {
3320492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        final int absGrav = GravityCompat.getAbsoluteGravity(edgeGravity,
3330492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                ViewCompat.getLayoutDirection(this));
3340492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        if (absGrav == Gravity.LEFT) {
3350492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            mLockModeLeft = lockMode;
3360492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        } else if (absGrav == Gravity.RIGHT) {
3370492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            mLockModeRight = lockMode;
3380492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        }
3390492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        if (lockMode != LOCK_MODE_UNLOCKED) {
3400492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            // Cancel interaction in progress
3410492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            final ViewDragHelper helper = absGrav == Gravity.LEFT ? mLeftDragger : mRightDragger;
3420492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            helper.cancel();
3430492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        }
3440492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        switch (lockMode) {
3450492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            case LOCK_MODE_LOCKED_OPEN:
3460492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                final View toOpen = findDrawerWithGravity(absGrav);
3470492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                if (toOpen != null) {
3480492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                    openDrawer(toOpen);
3490492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                }
3500492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                break;
3510492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            case LOCK_MODE_LOCKED_CLOSED:
3520492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                final View toClose = findDrawerWithGravity(absGrav);
3530492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                if (toClose != null) {
3540492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                    closeDrawer(toClose);
3550492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                }
3560492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                break;
3570492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            // default: do nothing
3580492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        }
3590492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    }
3600492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell
3610492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    /**
3620492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * Enable or disable interaction with the given drawer.
3630492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     *
3640492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * <p>This allows the application to restrict the user's ability to open or close
3650492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * the given drawer. DrawerLayout will still respond to calls to {@link #openDrawer(int)},
3660492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * {@link #closeDrawer(int)} and friends if a drawer is locked.</p>
3670492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     *
3680492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * <p>Locking a drawer open or closed will implicitly open or close
3690492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * that drawer as appropriate.</p>
3700492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     *
3710492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * @param lockMode The new lock mode for the given drawer. One of {@link #LOCK_MODE_UNLOCKED},
3720492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     *                 {@link #LOCK_MODE_LOCKED_CLOSED} or {@link #LOCK_MODE_LOCKED_OPEN}.
3730492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * @param drawerView The drawer view to change the lock mode for
3740492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     *
3750492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * @see #LOCK_MODE_UNLOCKED
3760492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * @see #LOCK_MODE_LOCKED_CLOSED
3770492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * @see #LOCK_MODE_LOCKED_OPEN
3780492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     */
3790492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    public void setDrawerLockMode(int lockMode, View drawerView) {
3800492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        if (!isDrawerView(drawerView)) {
3810492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            throw new IllegalArgumentException("View " + drawerView + " is not a " +
3820492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                    "drawer with appropriate layout_gravity");
3830492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        }
3840492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        setDrawerLockMode(lockMode, getDrawerViewGravity(drawerView));
3850492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    }
3860492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell
3870492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    /**
3880492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * Check the lock mode of the drawer with the given gravity.
3890492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     *
3900492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * @param edgeGravity Gravity of the drawer to check
3910492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * @return one of {@link #LOCK_MODE_UNLOCKED}, {@link #LOCK_MODE_LOCKED_CLOSED} or
3920492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     *         {@link #LOCK_MODE_LOCKED_OPEN}.
3930492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     */
3940492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    public int getDrawerLockMode(int edgeGravity) {
3950492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        final int absGrav = GravityCompat.getAbsoluteGravity(edgeGravity,
3960492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                ViewCompat.getLayoutDirection(this));
3970492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        if (absGrav == Gravity.LEFT) {
3980492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            return mLockModeLeft;
3990492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        } else if (absGrav == Gravity.RIGHT) {
4000492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            return mLockModeRight;
4010492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        }
4020492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        return LOCK_MODE_UNLOCKED;
4030492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    }
4040492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell
4050492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    /**
4060492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * Check the lock mode of the given drawer view.
4070492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     *
4080492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * @param drawerView Drawer view to check lock mode
4090492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     * @return one of {@link #LOCK_MODE_UNLOCKED}, {@link #LOCK_MODE_LOCKED_CLOSED} or
4100492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     *         {@link #LOCK_MODE_LOCKED_OPEN}.
4110492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell     */
4120492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    public int getDrawerLockMode(View drawerView) {
4130492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        final int gravity = getDrawerViewGravity(drawerView);
4140492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        if (gravity == Gravity.LEFT) {
4150492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            return mLockModeLeft;
4160492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        } else if (gravity == Gravity.RIGHT) {
4170492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            return mLockModeRight;
4180492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        }
4190492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell
4200492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        return LOCK_MODE_UNLOCKED;
4210492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    }
4220492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell
4230492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    /**
4241d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     * Resolve the shared state of all drawers from the component ViewDragHelpers.
4251d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     * Should be called whenever a ViewDragHelper's state changes.
4261d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     */
427b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    void updateDrawerState(int forGravity, int activeState, View activeDrawer) {
4281d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int leftState = mLeftDragger.getViewDragState();
4291d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int rightState = mRightDragger.getViewDragState();
4301d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
4311d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int state;
4321d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        if (leftState == STATE_DRAGGING || rightState == STATE_DRAGGING) {
4331d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            state = STATE_DRAGGING;
4341d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        } else if (leftState == STATE_SETTLING || rightState == STATE_SETTLING) {
4351d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            state = STATE_SETTLING;
4361d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        } else {
4371d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            state = STATE_IDLE;
4381d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
4391d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
440b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        if (activeDrawer != null && activeState == STATE_IDLE) {
441b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            final LayoutParams lp = (LayoutParams) activeDrawer.getLayoutParams();
442b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            if (lp.onScreen == 0) {
443b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                dispatchOnDrawerClosed(activeDrawer);
444b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            } else if (lp.onScreen == 1) {
445b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                dispatchOnDrawerOpened(activeDrawer);
446b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            }
447b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        }
448b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell
4491d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        if (state != mDrawerState) {
4501d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            mDrawerState = state;
451b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell
4521d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            if (mListener != null) {
4531d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                mListener.onDrawerStateChanged(state);
4541d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
4551d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
4561d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
4571d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
4581d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    void dispatchOnDrawerClosed(View drawerView) {
4591d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
4601d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        if (lp.knownOpen) {
4611d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            lp.knownOpen = false;
4621d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            if (mListener != null) {
4631d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                mListener.onDrawerClosed(drawerView);
4641d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
4657d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell            sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
4661d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
4671d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
4681d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
4691d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    void dispatchOnDrawerOpened(View drawerView) {
4701d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
4711d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        if (!lp.knownOpen) {
4721d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            lp.knownOpen = true;
4731d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            if (mListener != null) {
4741d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                mListener.onDrawerOpened(drawerView);
4751d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
4767d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell            drawerView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
4771d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
4781d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
4791d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
4801d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    void dispatchOnDrawerSlide(View drawerView, float slideOffset) {
4811d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        if (mListener != null) {
4821d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            mListener.onDrawerSlide(drawerView, slideOffset);
4831d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
4841d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
4851d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
4861d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    void setDrawerViewOffset(View drawerView, float slideOffset) {
4871d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
488b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        if (slideOffset == lp.onScreen) {
4891d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            return;
4901d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
4911d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
492b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        lp.onScreen = slideOffset;
4931d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        dispatchOnDrawerSlide(drawerView, slideOffset);
4941d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
4951d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
4961d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    float getDrawerViewOffset(View drawerView) {
497b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        return ((LayoutParams) drawerView.getLayoutParams()).onScreen;
4981d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
4991d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
5001d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    int getDrawerViewGravity(View drawerView) {
5011d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int gravity = ((LayoutParams) drawerView.getLayoutParams()).gravity;
5021d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        return GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(drawerView));
5031d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
5041d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
5051d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    boolean checkDrawerViewGravity(View drawerView, int checkFor) {
5061d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int absGrav = getDrawerViewGravity(drawerView);
5071d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        return (absGrav & checkFor) == checkFor;
5081d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
5091d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
5100492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    View findOpenDrawer() {
5110492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        final int childCount = getChildCount();
5120492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        for (int i = 0; i < childCount; i++) {
5130492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            final View child = getChildAt(i);
5140492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            if (((LayoutParams) child.getLayoutParams()).knownOpen) {
5150492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                return child;
5160492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            }
5170492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        }
5180492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        return null;
5190492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    }
5200492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell
5211d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    void moveDrawerToOffset(View drawerView, float slideOffset) {
5221d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final float oldOffset = getDrawerViewOffset(drawerView);
5231d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int width = drawerView.getWidth();
5241d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int oldPos = (int) (width * oldOffset);
5251d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int newPos = (int) (width * slideOffset);
5261d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int dx = newPos - oldPos;
5271d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
5281d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        drawerView.offsetLeftAndRight(checkDrawerViewGravity(drawerView, Gravity.LEFT) ? dx : -dx);
5291d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        setDrawerViewOffset(drawerView, slideOffset);
5301d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
5311d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
5321d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    View findDrawerWithGravity(int gravity) {
5331d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int childCount = getChildCount();
5341d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        for (int i = 0; i < childCount; i++) {
5351d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            final View child = getChildAt(i);
5361d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            final int childGravity = getDrawerViewGravity(child);
5371d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            if ((childGravity & Gravity.HORIZONTAL_GRAVITY_MASK) ==
5381d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                    (gravity & Gravity.HORIZONTAL_GRAVITY_MASK)) {
5391d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                return child;
5401d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
5411d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
5421d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        return null;
5431d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
5441d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
5451d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    /**
5461d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     * Simple gravity to string - only supports LEFT and RIGHT for debugging output.
5471d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     *
5481d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     * @param gravity Absolute gravity value
5491d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     * @return LEFT or RIGHT as appropriate, or a hex string
5501d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     */
5511d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    static String gravityToString(int gravity) {
5521d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        if ((gravity & Gravity.LEFT) == Gravity.LEFT) {
5531d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            return "LEFT";
5541d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
5551d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        if ((gravity & Gravity.RIGHT) == Gravity.RIGHT) {
5561d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            return "RIGHT";
5571d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
5581d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        return Integer.toHexString(gravity);
5591d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
5601d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
5611d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    @Override
56257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell    protected void onDetachedFromWindow() {
56357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        super.onDetachedFromWindow();
56457902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        mFirstLayout = true;
56557902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell    }
56657902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell
56757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell    @Override
56857902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell    protected void onAttachedToWindow() {
56957902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        super.onAttachedToWindow();
57057902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        mFirstLayout = true;
57157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell    }
57257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell
57357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell    @Override
5741d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
5751d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
5761d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
5771d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
5781d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int heightSize = MeasureSpec.getSize(heightMeasureSpec);
5791d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
5801d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        if (widthMode != MeasureSpec.EXACTLY || heightMode != MeasureSpec.EXACTLY) {
5811d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            throw new IllegalArgumentException(
5821d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                    "DrawerLayout must be measured with MeasureSpec.EXACTLY.");
5831d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
5841d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
5851d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        setMeasuredDimension(widthSize, heightSize);
5861d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
5871d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        // Gravity value for each drawer we've seen. Only one of each permitted.
5881d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        int foundDrawers = 0;
5891d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int childCount = getChildCount();
5901d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        for (int i = 0; i < childCount; i++) {
5911d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            final View child = getChildAt(i);
5921d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
5931d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            if (child.getVisibility() == GONE) {
5941d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                continue;
5951d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
5961d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
59700ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
59800ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell
5991d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            if (isContentView(child)) {
6001d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                // Content views get measured at exactly the layout's size.
60100ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                final int contentWidthSpec = MeasureSpec.makeMeasureSpec(
60200ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        widthSize - lp.leftMargin - lp.rightMargin, MeasureSpec.EXACTLY);
60300ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                final int contentHeightSpec = MeasureSpec.makeMeasureSpec(
60400ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        heightSize - lp.topMargin - lp.bottomMargin, MeasureSpec.EXACTLY);
60500ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                child.measure(contentWidthSpec, contentHeightSpec);
6061d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            } else if (isDrawerView(child)) {
6071d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                final int childGravity =
6081d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                        getDrawerViewGravity(child) & Gravity.HORIZONTAL_GRAVITY_MASK;
6091d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                if ((foundDrawers & childGravity) != 0) {
6101d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                    throw new IllegalStateException("Child drawer has absolute gravity " +
6111d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                            gravityToString(childGravity) + " but this " + TAG + " already has a " +
6121d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                            "drawer view along that edge");
6131d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                }
61400ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                final int drawerWidthSpec = getChildMeasureSpec(widthMeasureSpec,
61500ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        mMinDrawerMargin + lp.leftMargin + lp.rightMargin,
61600ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        lp.width);
61700ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                final int drawerHeightSpec = getChildMeasureSpec(heightMeasureSpec,
61800ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        lp.topMargin + lp.bottomMargin,
61900ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        lp.height);
62000ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                child.measure(drawerWidthSpec, drawerHeightSpec);
6211d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            } else {
6221d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                throw new IllegalStateException("Child " + child + " at index " + i +
6231d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                        " does not have a valid layout_gravity - must be Gravity.LEFT, " +
6241d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                        "Gravity.RIGHT or Gravity.NO_GRAVITY");
6251d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
6261d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
6271d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
6281d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
6291d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    @Override
6301d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    protected void onLayout(boolean changed, int l, int t, int r, int b) {
631b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        mInLayout = true;
6321d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int childCount = getChildCount();
6331d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        for (int i = 0; i < childCount; i++) {
6341d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            final View child = getChildAt(i);
6351d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
6361d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            if (child.getVisibility() == GONE) {
6371d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                continue;
6381d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
6391d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
64000ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
64100ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell
6421d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            if (isContentView(child)) {
64300ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                child.layout(lp.leftMargin, lp.topMargin,
64400ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        lp.leftMargin + child.getMeasuredWidth(),
64500ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        lp.topMargin + child.getMeasuredHeight());
6461d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            } else { // Drawer, if it wasn't onMeasure would have thrown an exception.
6471d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                final int childWidth = child.getMeasuredWidth();
64800ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                final int childHeight = child.getMeasuredHeight();
6491d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                int childLeft;
6501d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
6511d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                if (checkDrawerViewGravity(child, Gravity.LEFT)) {
652b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                    childLeft = -childWidth + (int) (childWidth * lp.onScreen);
6531d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                } else { // Right; onMeasure checked for us.
654b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                    childLeft = r - l - (int) (childWidth * lp.onScreen);
6551d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                }
6561d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
65700ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
65800ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell
65900ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                switch (vgrav) {
66000ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                    default:
66100ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                    case Gravity.TOP: {
66200ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        child.layout(childLeft, lp.topMargin, childLeft + childWidth, childHeight);
66300ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        break;
66400ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                    }
66500ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell
66600ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                    case Gravity.BOTTOM: {
66700ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        final int height = b - t;
66800ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        child.layout(childLeft,
66900ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                                height - lp.bottomMargin - child.getMeasuredHeight(),
67000ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                                childLeft + childWidth,
67100ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                                height - lp.bottomMargin);
67200ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        break;
67300ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                    }
67400ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell
67500ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                    case Gravity.CENTER_VERTICAL: {
67600ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        final int height = b - t;
67700ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        int childTop = (height - childHeight) / 2;
67800ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell
67900ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        // Offset for margins. If things don't fit right because of
68000ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        // bad measurement before, oh well.
68100ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        if (childTop < lp.topMargin) {
68200ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                            childTop = lp.topMargin;
68300ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        } else if (childTop + childHeight > height - lp.bottomMargin) {
68400ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                            childTop = height - lp.bottomMargin - childHeight;
68500ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        }
68600ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        child.layout(childLeft, childTop, childLeft + childWidth,
68700ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                                childTop + childHeight);
68800ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        break;
68900ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                    }
69000ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                }
691b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell
692b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                if (lp.onScreen == 0) {
693b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                    child.setVisibility(INVISIBLE);
694b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                }
6951d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
6961d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
697b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        mInLayout = false;
69857902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        mFirstLayout = false;
699b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    }
700b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell
701b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    @Override
702b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    public void requestLayout() {
703b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        if (!mInLayout) {
704b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            super.requestLayout();
705b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        }
7061d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
7071d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
7081d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    @Override
7091d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    public void computeScroll() {
7101d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int childCount = getChildCount();
7111d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        float scrimOpacity = 0;
7121d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        for (int i = 0; i < childCount; i++) {
713b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            final float onscreen = ((LayoutParams) getChildAt(i).getLayoutParams()).onScreen;
7141d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            scrimOpacity = Math.max(scrimOpacity, onscreen);
7151d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
7161d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        mScrimOpacity = scrimOpacity;
7171d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
7181d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        // "|" used on purpose; both need to run.
7191d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        if (mLeftDragger.continueSettling(true) | mRightDragger.continueSettling(true)) {
7201d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            ViewCompat.postInvalidateOnAnimation(this);
7211d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
7221d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
7231d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
724b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    private static boolean hasOpaqueBackground(View v) {
725b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        final Drawable bg = v.getBackground();
726b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        if (bg != null) {
727b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            return bg.getOpacity() == PixelFormat.OPAQUE;
728b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        }
729b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        return false;
730b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    }
731b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell
7321d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    @Override
7331d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
73400ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell        final int height = getHeight();
735b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        final boolean drawingContent = isContentView(child);
736b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        int clipLeft = 0, clipRight = getWidth();
737b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell
7381d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int restoreCount = canvas.save();
739b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        if (drawingContent) {
740b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            final int childCount = getChildCount();
741b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            for (int i = 0; i < childCount; i++) {
742b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                final View v = getChildAt(i);
743b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                if (v == child || v.getVisibility() != VISIBLE ||
74400ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        !hasOpaqueBackground(v) || !isDrawerView(v) ||
74500ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                        v.getHeight() < height) {
746b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                    continue;
747b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                }
748b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell
749b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                if (checkDrawerViewGravity(v, Gravity.LEFT)) {
750b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                    final int vright = v.getRight();
751b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                    if (vright > clipLeft) clipLeft = vright;
752b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                } else {
753b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                    final int vleft = v.getLeft();
754b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                    if (vleft < clipRight) clipRight = vleft;
755b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                }
756b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            }
757b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            canvas.clipRect(clipLeft, 0, clipRight, getHeight());
758b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        }
7591d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final boolean result = super.drawChild(canvas, child, drawingTime);
7601d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        canvas.restoreToCount(restoreCount);
761b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell
762b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        if (mScrimOpacity > 0 && drawingContent) {
7631d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            final int baseAlpha = (mScrimColor & 0xff000000) >>> 24;
7641d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            final int imag = (int) (baseAlpha * mScrimOpacity);
7651d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            final int color = imag << 24 | (mScrimColor & 0xffffff);
7661d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            mScrimPaint.setColor(color);
7671d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
768b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            canvas.drawRect(clipLeft, 0, clipRight, getHeight(), mScrimPaint);
769b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        } else if (mShadowLeft != null && checkDrawerViewGravity(child, Gravity.LEFT)) {
770b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            final int shadowWidth = mShadowLeft.getIntrinsicWidth();
771b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            final int childRight = child.getRight();
772ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell            final int drawerPeekDistance = mLeftDragger.getEdgeSize();
773b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            final float alpha =
774ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell                    Math.max(0, Math.min((float) childRight / drawerPeekDistance, 1.f));
775b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            mShadowLeft.setBounds(childRight, child.getTop(),
776b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                    childRight + shadowWidth, child.getBottom());
777b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            mShadowLeft.setAlpha((int) (0xff * alpha));
778b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            mShadowLeft.draw(canvas);
779b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        } else if (mShadowRight != null && checkDrawerViewGravity(child, Gravity.RIGHT)) {
780b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            final int shadowWidth = mShadowRight.getIntrinsicWidth();
781b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            final int childLeft = child.getLeft();
782b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            final int showing = getWidth() - childLeft;
783ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell            final int drawerPeekDistance = mRightDragger.getEdgeSize();
784b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            final float alpha =
785ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell                    Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f));
786b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            mShadowRight.setBounds(childLeft - shadowWidth, child.getTop(),
787b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                    childLeft, child.getBottom());
788b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            mShadowRight.setAlpha((int) (0xff * alpha));
789b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            mShadowRight.draw(canvas);
7901d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
7911d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        return result;
7921d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
7931d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
7941d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    boolean isContentView(View child) {
7951d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        return ((LayoutParams) child.getLayoutParams()).gravity == Gravity.NO_GRAVITY;
7961d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
7971d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
7981d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    boolean isDrawerView(View child) {
7991d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int gravity = ((LayoutParams) child.getLayoutParams()).gravity;
8001d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int absGravity = GravityCompat.getAbsoluteGravity(gravity,
8011d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                ViewCompat.getLayoutDirection(child));
8021d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        return (absGravity & (Gravity.LEFT | Gravity.RIGHT)) != 0;
8031d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
8041d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
8051d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    @Override
8061d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    public boolean onInterceptTouchEvent(MotionEvent ev) {
8071d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int action = MotionEventCompat.getActionMasked(ev);
8081d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
8091d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        // "|" used deliberately here; both methods should be invoked.
8101d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final boolean interceptForDrag = mLeftDragger.shouldInterceptTouchEvent(ev) |
8111d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                mRightDragger.shouldInterceptTouchEvent(ev);
8121d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
8131d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        boolean interceptForTap = false;
8141d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
8151d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        switch (action) {
8161d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            case MotionEvent.ACTION_DOWN: {
8171d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                final float x = ev.getX();
8181d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                final float y = ev.getY();
8191d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                mInitialMotionX = x;
8201d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                mInitialMotionY = y;
8211d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                if (mScrimOpacity > 0 &&
8221d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                        isContentView(mLeftDragger.findTopChildUnder((int) x, (int) y))) {
8231d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                    interceptForTap = true;
8241d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                }
8251732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell                mDisallowInterceptRequested = false;
826cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell                mChildrenCanceledTouch = false;
8271732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell                break;
8281732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell            }
8291732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell
8301732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell            case MotionEvent.ACTION_MOVE: {
8311732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell                // If we cross the touch slop, don't perform the delayed peek for an edge touch.
8321732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell                if (mLeftDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) {
8331732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell                    mLeftCallback.removeCallbacks();
8341732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell                    mRightCallback.removeCallbacks();
8351732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell                }
8361d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                break;
8371d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
8381d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
8391d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            case MotionEvent.ACTION_CANCEL:
8401d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            case MotionEvent.ACTION_UP: {
8411d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                closeDrawers(true);
8421732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell                mDisallowInterceptRequested = false;
843cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell                mChildrenCanceledTouch = false;
8441d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
8451d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
8461732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell
847cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell        return interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch;
8481d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
8491d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
8501d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    @Override
8511d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    public boolean onTouchEvent(MotionEvent ev) {
8521d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        mLeftDragger.processTouchEvent(ev);
8531d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        mRightDragger.processTouchEvent(ev);
8541d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
8551d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int action = ev.getAction();
8561d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        boolean wantTouchEvents = true;
8571d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
8581d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        switch (action & MotionEventCompat.ACTION_MASK) {
8591d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            case MotionEvent.ACTION_DOWN: {
8601d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                final float x = ev.getX();
8611d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                final float y = ev.getY();
8621d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                mInitialMotionX = x;
8631d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                mInitialMotionY = y;
8641732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell                mDisallowInterceptRequested = false;
865cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell                mChildrenCanceledTouch = false;
8661d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                break;
8671d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
8681d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
8691d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            case MotionEvent.ACTION_UP: {
8701d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                final float x = ev.getX();
8711d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                final float y = ev.getY();
8721d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                boolean peekingOnly = true;
8738bc268e9c40e4ae375a0d65dc1293dccc541186fAdam Powell                final View touchedView = mLeftDragger.findTopChildUnder((int) x, (int) y);
8748bc268e9c40e4ae375a0d65dc1293dccc541186fAdam Powell                if (touchedView != null && isContentView(touchedView)) {
8751d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                    final float dx = x - mInitialMotionX;
8761d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                    final float dy = y - mInitialMotionY;
8771d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                    final int slop = mLeftDragger.getTouchSlop();
8781d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                    if (dx * dx + dy * dy < slop * slop) {
8790492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                        // Taps close a dimmed open drawer but only if it isn't locked open.
8800492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                        final View openDrawer = findOpenDrawer();
8810492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                        if (openDrawer != null) {
8820492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                            peekingOnly = getDrawerLockMode(openDrawer) == LOCK_MODE_LOCKED_OPEN;
8830492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                        }
8841d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                    }
8851d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                }
8861d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                closeDrawers(peekingOnly);
8871732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell                mDisallowInterceptRequested = false;
8881d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                break;
8891d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
8901d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
8911d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            case MotionEvent.ACTION_CANCEL: {
8921d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                closeDrawers(true);
8931732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell                mDisallowInterceptRequested = false;
894cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell                mChildrenCanceledTouch = false;
8951d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                break;
8961d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
8971d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
8981d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
8991d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        return wantTouchEvents;
9001d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
9011d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
902ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell    public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
9031732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell        if (!mLeftDragger.isEdgeTouched(ViewDragHelper.EDGE_LEFT) &&
9041732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell                !mRightDragger.isEdgeTouched(ViewDragHelper.EDGE_RIGHT)) {
9051732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell            // If we have an edge touch we want to skip this and track it for later instead.
9061732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell            super.requestDisallowInterceptTouchEvent(disallowIntercept);
9071732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell        }
9081732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell        mDisallowInterceptRequested = disallowIntercept;
909ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell        if (disallowIntercept) {
910ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell            closeDrawers(true);
911ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell        }
912ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell    }
913ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell
9141d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    /**
9151d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     * Close all currently open drawer views by animating them out of view.
9161d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     */
9171d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    public void closeDrawers() {
9181d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        closeDrawers(false);
9191d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
9201d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
9211d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    void closeDrawers(boolean peekingOnly) {
9221d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        boolean needsInvalidate = false;
9231d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int childCount = getChildCount();
9241d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        for (int i = 0; i < childCount; i++) {
9251d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            final View child = getChildAt(i);
9261d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
9271d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
9281d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            if (!isDrawerView(child) || (peekingOnly && !lp.isPeeking)) {
9291d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                continue;
9301d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
9311d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
9321d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            final int childWidth = child.getWidth();
9331d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
9341d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            if (checkDrawerViewGravity(child, Gravity.LEFT)) {
9351d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                needsInvalidate |= mLeftDragger.smoothSlideViewTo(child,
9361d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                        -childWidth, child.getTop());
9371d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            } else {
9381d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                needsInvalidate |= mRightDragger.smoothSlideViewTo(child,
9391d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                        getWidth(), child.getTop());
9401d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
9411d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
9421d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            lp.isPeeking = false;
9431d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
9441d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
9451732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell        mLeftCallback.removeCallbacks();
9461732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell        mRightCallback.removeCallbacks();
9471732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell
9481d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        if (needsInvalidate) {
9491d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            invalidate();
9501d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
9511d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
9521d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
9531d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    /**
9541d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     * Open the specified drawer view by animating it into view.
9551d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     *
9561d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     * @param drawerView Drawer view to open
9571d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     */
9581d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    public void openDrawer(View drawerView) {
9591d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        if (!isDrawerView(drawerView)) {
9601d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer");
9611d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
9621d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
96357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        if (mFirstLayout) {
96457902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
96557902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            lp.onScreen = 1.f;
96657902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            lp.knownOpen = true;
9671d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        } else {
96857902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            if (checkDrawerViewGravity(drawerView, Gravity.LEFT)) {
96957902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell                mLeftDragger.smoothSlideViewTo(drawerView, 0, drawerView.getTop());
97057902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            } else {
97157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell                mRightDragger.smoothSlideViewTo(drawerView, getWidth() - drawerView.getWidth(),
97257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell                        drawerView.getTop());
97357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            }
9741d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
9751d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        invalidate();
9761d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
9771d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
9781d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    /**
9791d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     * Open the specified drawer by animating it out of view.
9801d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     *
9811d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     * @param gravity Gravity.LEFT to move the left drawer or Gravity.RIGHT for the right.
9821d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     *                GravityCompat.START or GravityCompat.END may also be used.
9831d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     */
9841d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    public void openDrawer(int gravity) {
9851d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int absGravity = GravityCompat.getAbsoluteGravity(gravity,
9861d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                ViewCompat.getLayoutDirection(this));
9871d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final View drawerView = findDrawerWithGravity(absGravity);
9881d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
9891d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        if (drawerView == null) {
9901d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            throw new IllegalArgumentException("No drawer view found with absolute gravity " +
9911d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                    gravityToString(absGravity));
9921d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
9931d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        openDrawer(drawerView);
9941d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
9951d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
9961d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    /**
9971d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     * Close the specified drawer view by animating it into view.
9981d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     *
9991d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     * @param drawerView Drawer view to close
10001d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     */
10011d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    public void closeDrawer(View drawerView) {
10021d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        if (!isDrawerView(drawerView)) {
10031d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer");
10041d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
10051d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
100657902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        if (mFirstLayout) {
100757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
100857902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            lp.onScreen = 0.f;
100957902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            lp.knownOpen = false;
10101d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        } else {
101157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            if (checkDrawerViewGravity(drawerView, Gravity.LEFT)) {
101257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell                mLeftDragger.smoothSlideViewTo(drawerView, -drawerView.getWidth(),
101357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell                        drawerView.getTop());
101457902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            } else {
101557902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell                mRightDragger.smoothSlideViewTo(drawerView, getWidth(), drawerView.getTop());
101657902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            }
10171d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
10181d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        invalidate();
10191d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
10201d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
10211d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    /**
10221d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     * Close the specified drawer by animating it out of view.
10231d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     *
10241d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     * @param gravity Gravity.LEFT to move the left drawer or Gravity.RIGHT for the right.
10251d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     *                GravityCompat.START or GravityCompat.END may also be used.
10261d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell     */
10271d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    public void closeDrawer(int gravity) {
10281d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final int absGravity = GravityCompat.getAbsoluteGravity(gravity,
10291d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                ViewCompat.getLayoutDirection(this));
10301d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        final View drawerView = findDrawerWithGravity(absGravity);
10311d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
10321d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        if (drawerView == null) {
10331d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            throw new IllegalArgumentException("No drawer view found with absolute gravity " +
10341d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                    gravityToString(absGravity));
10351d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
10361d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        closeDrawer(drawerView);
10371d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
10381d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
1039b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    /**
1040b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * Check if the given drawer view is currently in an open state.
1041b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * To be considered "open" the drawer must have settled into its fully
1042b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * visible state. To check for partial visibility use
1043b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * {@link #isDrawerVisible(android.view.View)}.
1044b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     *
1045b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * @param drawer Drawer view to check
1046b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * @return true if the given drawer view is in an open state
1047b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * @see #isDrawerVisible(android.view.View)
1048b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     */
1049b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    public boolean isDrawerOpen(View drawer) {
1050b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        if (!isDrawerView(drawer)) {
1051b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            throw new IllegalArgumentException("View " + drawer + " is not a drawer");
1052b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        }
1053b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        return ((LayoutParams) drawer.getLayoutParams()).knownOpen;
1054b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    }
1055b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell
1056b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    /**
1057b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * Check if a given drawer view is currently visible on-screen. The drawer
1058b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * may be only peeking onto the screen, fully extended, or anywhere inbetween.
1059b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     *
1060b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * @param drawer Drawer view to check
1061b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * @return true if the given drawer is visible on-screen
1062b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     * @see #isDrawerOpen(android.view.View)
1063b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell     */
1064b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    public boolean isDrawerVisible(View drawer) {
1065b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        if (!isDrawerView(drawer)) {
1066b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            throw new IllegalArgumentException("View " + drawer + " is not a drawer");
1067b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        }
1068b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        return ((LayoutParams) drawer.getLayoutParams()).onScreen > 0;
1069b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell    }
1070b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell
1071ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell    private boolean hasPeekingDrawer() {
1072ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell        final int childCount = getChildCount();
1073ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell        for (int i = 0; i < childCount; i++) {
1074ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell            final LayoutParams lp = (LayoutParams) getChildAt(i).getLayoutParams();
1075ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell            if (lp.isPeeking) {
1076ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell                return true;
1077ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell            }
1078ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell        }
1079ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell        return false;
1080ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell    }
1081ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell
10821d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    @Override
10831d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
10841d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        return new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
10851d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
10861d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
10871d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    @Override
10881d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
10891d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        return p instanceof LayoutParams
10901d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                ? new LayoutParams((LayoutParams) p)
109100ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                : p instanceof ViewGroup.MarginLayoutParams
109200ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell                ? new LayoutParams((MarginLayoutParams) p)
10931d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                : new LayoutParams(p);
10941d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
10951d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
10961d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    @Override
10971d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
10981d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        return p instanceof LayoutParams && super.checkLayoutParams(p);
10991d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
11001d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
11011d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    @Override
11021d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
11031d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        return new LayoutParams(getContext(), attrs);
11041d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
11051d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
1106791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell    private boolean hasVisibleDrawer() {
11070492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        return findVisibleDrawer() != null;
11080492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    }
11090492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell
11100492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell    private View findVisibleDrawer() {
1111791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell        final int childCount = getChildCount();
1112791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell        for (int i = 0; i < childCount; i++) {
1113791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell            final View child = getChildAt(i);
1114791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell            if (isDrawerView(child) && isDrawerVisible(child)) {
11150492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                return child;
1116791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell            }
1117791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell        }
11180492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        return null;
1119791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell    }
1120791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell
1121cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell    void cancelChildViewTouch() {
1122cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell        // Cancel child touches
1123cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell        if (!mChildrenCanceledTouch) {
1124cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell            final long now = SystemClock.uptimeMillis();
1125cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell            final MotionEvent cancelEvent = MotionEvent.obtain(now, now,
1126cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell                    MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0);
1127cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell            final int childCount = getChildCount();
1128cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell            for (int i = 0; i < childCount; i++) {
1129cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell                getChildAt(i).dispatchTouchEvent(cancelEvent);
1130cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell            }
1131cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell            cancelEvent.recycle();
1132cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell            mChildrenCanceledTouch = true;
1133cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell        }
1134cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell    }
1135cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell
1136791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell    @Override
1137791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell    public boolean onKeyDown(int keyCode, KeyEvent event) {
1138791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell        if (keyCode == KeyEvent.KEYCODE_BACK && hasVisibleDrawer()) {
1139791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell            KeyEventCompat.startTracking(event);
1140791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell            return true;
1141791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell        }
1142791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell        return super.onKeyDown(keyCode, event);
1143791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell    }
1144791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell
1145791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell    @Override
1146791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell    public boolean onKeyUp(int keyCode, KeyEvent event) {
11470492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell        if (keyCode == KeyEvent.KEYCODE_BACK) {
11480492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            final View visibleDrawer = findVisibleDrawer();
11490492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            if (visibleDrawer != null && getDrawerLockMode(visibleDrawer) == LOCK_MODE_UNLOCKED) {
11500492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                closeDrawers();
11510492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            }
11520492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            return visibleDrawer != null;
1153791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell        }
1154791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell        return super.onKeyUp(keyCode, event);
1155791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell    }
1156791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell
115757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell    @Override
115857902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell    protected void onRestoreInstanceState(Parcelable state) {
115957902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        final SavedState ss = (SavedState) state;
116057902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        super.onRestoreInstanceState(ss.getSuperState());
116157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell
116257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        if (ss.openDrawerGravity != Gravity.NO_GRAVITY) {
116357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            final View toOpen = findDrawerWithGravity(ss.openDrawerGravity);
116457902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            if (toOpen != null) {
116557902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell                openDrawer(toOpen);
116657902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            }
116757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        }
11688e01d24e718d603974182cd48f648369c07edec1Adam Powell
11698e01d24e718d603974182cd48f648369c07edec1Adam Powell        setDrawerLockMode(ss.lockModeLeft, Gravity.LEFT);
11708e01d24e718d603974182cd48f648369c07edec1Adam Powell        setDrawerLockMode(ss.lockModeRight, Gravity.RIGHT);
117157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell    }
117257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell
117357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell    @Override
117457902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell    protected Parcelable onSaveInstanceState() {
117557902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        final Parcelable superState = super.onSaveInstanceState();
117657902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell
117757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        final SavedState ss = new SavedState(superState);
117857902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell
117957902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        final int childCount = getChildCount();
118057902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        for (int i = 0; i < childCount; i++) {
118157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            final View child = getChildAt(i);
118257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            if (!isDrawerView(child)) {
118357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell                continue;
118457902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            }
118557902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell
118657902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
118757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            if (lp.knownOpen) {
118857902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell                ss.openDrawerGravity = lp.gravity;
118957902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell                // Only one drawer can be open at a time.
119057902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell                break;
119157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            }
119257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        }
119357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell
11948e01d24e718d603974182cd48f648369c07edec1Adam Powell        ss.lockModeLeft = mLockModeLeft;
11958e01d24e718d603974182cd48f648369c07edec1Adam Powell        ss.lockModeRight = mLockModeRight;
11968e01d24e718d603974182cd48f648369c07edec1Adam Powell
119757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        return ss;
119857902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell    }
119957902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell
120057902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell    /**
120157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell     * State persisted across instances
120257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell     */
120357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell    protected static class SavedState extends BaseSavedState {
120457902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        int openDrawerGravity = Gravity.NO_GRAVITY;
12058e01d24e718d603974182cd48f648369c07edec1Adam Powell        int lockModeLeft = LOCK_MODE_UNLOCKED;
12068e01d24e718d603974182cd48f648369c07edec1Adam Powell        int lockModeRight = LOCK_MODE_UNLOCKED;
120757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell
120857902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        public SavedState(Parcel in) {
120957902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            super(in);
121057902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            openDrawerGravity = in.readInt();
121157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        }
121257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell
121357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        public SavedState(Parcelable superState) {
121457902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            super(superState);
121557902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        }
121657902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell
121757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        @Override
121857902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        public void writeToParcel(Parcel dest, int flags) {
121957902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            super.writeToParcel(dest, flags);
122057902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            dest.writeInt(openDrawerGravity);
122157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        }
122257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell
122357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        public static final Parcelable.Creator<SavedState> CREATOR =
122457902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell                new Parcelable.Creator<SavedState>() {
122557902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            @Override
122657902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            public SavedState createFromParcel(Parcel source) {
122757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell                return new SavedState(source);
122857902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            }
122957902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell
123057902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            @Override
123157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            public SavedState[] newArray(int size) {
123257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell                return new SavedState[size];
123357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell            }
123457902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell        };
123557902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell    }
123657902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell
12371d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    private class ViewDragCallback extends ViewDragHelper.Callback {
12381d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        private final int mGravity;
12391d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        private ViewDragHelper mDragger;
12401d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
12411732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell        private final Runnable mPeekRunnable = new Runnable() {
12421732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell            @Override public void run() {
12431732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell                peekDrawer();
12441732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell            }
12451732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell        };
12461732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell
12471d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        public ViewDragCallback(int gravity) {
12481d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            mGravity = gravity;
12491d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
12501d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
12511d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        public void setDragger(ViewDragHelper dragger) {
12521d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            mDragger = dragger;
12531d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
12541d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
12551732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell        public void removeCallbacks() {
12561732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell            DrawerLayout.this.removeCallbacks(mPeekRunnable);
12571732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell        }
12581732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell
12591d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        @Override
12601d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        public boolean tryCaptureView(View child, int pointerId) {
12611d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            // Only capture views where the gravity matches what we're looking for.
12621d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            // This lets us use two ViewDragHelpers, one for each side drawer.
12630492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            return isDrawerView(child) && checkDrawerViewGravity(child, mGravity) &&
12640492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                    getDrawerLockMode(child) == LOCK_MODE_UNLOCKED;
12651d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
12661d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
12671d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        @Override
12681d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        public void onViewDragStateChanged(int state) {
1269b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            updateDrawerState(mGravity, state, mDragger.getCapturedView());
12701d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
12711d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
12721d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        @Override
12731d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
12741d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            float offset;
12751d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            final int childWidth = changedView.getWidth();
12761d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
12771d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            // This reverses the positioning shown in onLayout.
12781d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            if (checkDrawerViewGravity(changedView, Gravity.LEFT)) {
12791d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                offset = (float) (childWidth + left) / childWidth;
12801d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            } else {
12811d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                final int width = getWidth();
12821d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                offset = (float) (width - left) / childWidth;
12831d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
12841d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            setDrawerViewOffset(changedView, offset);
1285b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            changedView.setVisibility(offset == 0 ? INVISIBLE : VISIBLE);
12861d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            invalidate();
12871d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
12881d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
12891d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        @Override
12901d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        public void onViewCaptured(View capturedChild, int activePointerId) {
12911d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            final LayoutParams lp = (LayoutParams) capturedChild.getLayoutParams();
12921d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            lp.isPeeking = false;
12931d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
12941d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            closeOtherDrawer();
12951d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
12961d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
12971d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        private void closeOtherDrawer() {
12981d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            final int otherGrav = mGravity == Gravity.LEFT ? Gravity.RIGHT : Gravity.LEFT;
12991d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            final View toClose = findDrawerWithGravity(otherGrav);
13001d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            if (toClose != null) {
13011d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                closeDrawer(toClose);
13021d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
13031d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
13041d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
13051d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        @Override
13061d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        public void onViewReleased(View releasedChild, float xvel, float yvel) {
13071d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            // Offset is how open the drawer is, therefore left/right values
13081d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            // are reversed from one another.
13091d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            final float offset = getDrawerViewOffset(releasedChild);
13101d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            final int childWidth = releasedChild.getWidth();
13111d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
13121d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            int left;
13131d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            if (checkDrawerViewGravity(releasedChild, Gravity.LEFT)) {
13141d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                left = xvel > 0 || xvel == 0 && offset > 0.5f ? 0 : -childWidth;
13151d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            } else {
13161d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                final int width = getWidth();
13171d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                left = xvel < 0 || xvel == 0 && offset < 0.5f ? width - childWidth : width;
13181d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
13191d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
13201d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            mDragger.settleCapturedViewAt(left, releasedChild.getTop());
13211d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            invalidate();
13221d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
13231d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
13241d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        @Override
13251d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        public void onEdgeTouched(int edgeFlags, int pointerId) {
13261732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell            postDelayed(mPeekRunnable, PEEK_DELAY);
13271732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell        }
13281732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell
13291732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell        private void peekDrawer() {
13301d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            final View toCapture;
13311d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            final int childLeft;
1332ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell            final int peekDistance = mDragger.getEdgeSize();
13331732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell            final boolean leftEdge = mGravity == Gravity.LEFT;
1334b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            if (leftEdge) {
13351d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                toCapture = findDrawerWithGravity(Gravity.LEFT);
1336ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell                childLeft = (toCapture != null ? -toCapture.getWidth() : 0) + peekDistance;
13371d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            } else {
13381d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                toCapture = findDrawerWithGravity(Gravity.RIGHT);
1339ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell                childLeft = getWidth() - peekDistance;
13401d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
13410492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            // Only peek if it would mean making the drawer more visible and the drawer isn't locked
1342b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell            if (toCapture != null && ((leftEdge && toCapture.getLeft() < childLeft) ||
13430492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                    (!leftEdge && toCapture.getLeft() > childLeft)) &&
13440492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell                    getDrawerLockMode(toCapture) == LOCK_MODE_UNLOCKED) {
1345b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                final LayoutParams lp = (LayoutParams) toCapture.getLayoutParams();
13461d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                mDragger.smoothSlideViewTo(toCapture, childLeft, toCapture.getTop());
1347b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell                lp.isPeeking = true;
13481d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                invalidate();
13491d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
13501d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                closeOtherDrawer();
1351cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell
1352cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell                cancelChildViewTouch();
13531d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
13541d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
13551d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
13561d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        @Override
1357ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell        public boolean onEdgeLock(int edgeFlags) {
1358ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell            if (ALLOW_EDGE_LOCK) {
1359ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell                final View drawer = findDrawerWithGravity(mGravity);
1360ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell                if (drawer != null && !isDrawerOpen(drawer)) {
1361ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell                    closeDrawer(drawer);
1362ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell                }
1363ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell                return true;
1364acc82321ad119706485db342eaa12b225fa9b667Adam Powell            }
1365ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell            return false;
1366acc82321ad119706485db342eaa12b225fa9b667Adam Powell        }
1367acc82321ad119706485db342eaa12b225fa9b667Adam Powell
1368acc82321ad119706485db342eaa12b225fa9b667Adam Powell        @Override
13691d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        public void onEdgeDragStarted(int edgeFlags, int pointerId) {
13701d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            final View toCapture;
13711d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            if ((edgeFlags & ViewDragHelper.EDGE_LEFT) == ViewDragHelper.EDGE_LEFT) {
13721d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                toCapture = findDrawerWithGravity(Gravity.LEFT);
13731d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            } else {
13741d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                toCapture = findDrawerWithGravity(Gravity.RIGHT);
13751d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
13761d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
13770492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell            if (toCapture != null && getDrawerLockMode(toCapture) == LOCK_MODE_UNLOCKED) {
13781d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                mDragger.captureChildView(toCapture, pointerId);
13791d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
13801d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
13811d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
13821d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        @Override
13831d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        public int getViewHorizontalDragRange(View child) {
13841d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            return child.getWidth();
13851d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
13861d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
13871d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        @Override
13881d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        public int clampViewPositionHorizontal(View child, int left, int dx) {
13891d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            if (checkDrawerViewGravity(child, Gravity.LEFT)) {
13901d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                return Math.max(-child.getWidth(), Math.min(left, 0));
13911d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            } else {
13921d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                final int width = getWidth();
13931d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell                return Math.max(width - child.getWidth(), Math.min(left, width));
13941d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            }
13951d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
139600ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell
139700ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell        @Override
139800ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell        public int clampViewPositionVertical(View child, int top, int dy) {
139900ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell            return child.getTop();
140000ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell        }
14011d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
14021d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
140300ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell    public static class LayoutParams extends ViewGroup.MarginLayoutParams {
14041d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
14051d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        public int gravity = Gravity.NO_GRAVITY;
1406b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell        float onScreen;
14071d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        boolean isPeeking;
14081d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        boolean knownOpen;
14091d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
14101d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        public LayoutParams(Context c, AttributeSet attrs) {
14111d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            super(c, attrs);
14121d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
14131d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            final TypedArray a = c.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
14141d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            this.gravity = a.getInt(0, Gravity.NO_GRAVITY);
14151d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            a.recycle();
14161d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
14171d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
14181d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        public LayoutParams(int width, int height) {
14191d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            super(width, height);
14201d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
14211d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
14221d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        public LayoutParams(int width, int height, int gravity) {
14231d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            this(width, height);
14241d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            this.gravity = gravity;
14251d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
14261d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
14271d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        public LayoutParams(LayoutParams source) {
14281d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            super(source);
14291d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            this.gravity = source.gravity;
14301d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
14311d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell
14321d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        public LayoutParams(ViewGroup.LayoutParams source) {
14331d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell            super(source);
14341d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell        }
143500ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell
143600ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell        public LayoutParams(ViewGroup.MarginLayoutParams source) {
143700ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell            super(source);
143800ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell        }
14391d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell    }
14407d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell
14417d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell    class AccessibilityDelegate extends AccessibilityDelegateCompat {
14423cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell        private final Rect mTmpRect = new Rect();
14433cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell
14447d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell        @Override
14457d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
14463cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info);
14473cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            super.onInitializeAccessibilityNodeInfo(host, superNode);
14483cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell
14493cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            info.setSource(host);
14503cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            final ViewParent parent = ViewCompat.getParentForAccessibility(host);
14513cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            if (parent instanceof View) {
14523cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell                info.setParent((View) parent);
14533cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            }
14543cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            copyNodeInfoNoChildren(info, superNode);
14553cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell
14563cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            superNode.recycle();
14573cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell
14587d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell            final int childCount = getChildCount();
14597d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell            for (int i = 0; i < childCount; i++) {
14607d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell                final View child = getChildAt(i);
14617d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell                if (!filter(child)) {
14627d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell                    info.addChild(child);
14637d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell                }
14647d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell            }
14657d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell        }
14667d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell
14677d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell        @Override
14687d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell        public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child,
14697d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell                AccessibilityEvent event) {
14707d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell            if (!filter(child)) {
14717d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell                return super.onRequestSendAccessibilityEvent(host, child, event);
14727d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell            }
14737d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell            return false;
14747d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell        }
14757d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell
14767d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell        public boolean filter(View child) {
14777d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell            final View openDrawer = findOpenDrawer();
14787d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell            return openDrawer != null && openDrawer != child;
14797d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell        }
14803cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell
14813cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell        /**
14823cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell         * This should really be in AccessibilityNodeInfoCompat, but there unfortunately
14833cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell         * seem to be a few elements that are not easily cloneable using the underlying API.
14843cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell         * Leave it private here as it's not general-purpose useful.
14853cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell         */
14863cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell        private void copyNodeInfoNoChildren(AccessibilityNodeInfoCompat dest,
14873cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell                AccessibilityNodeInfoCompat src) {
14883cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            final Rect rect = mTmpRect;
14893cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell
14903cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            src.getBoundsInParent(rect);
14913cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            dest.setBoundsInParent(rect);
14923cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell
14933cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            src.getBoundsInScreen(rect);
14943cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            dest.setBoundsInScreen(rect);
14953cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell
14963cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            dest.setViewIdResourceName(src.getViewIdResourceName());
14973cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            dest.setVisibleToUser(src.isVisibleToUser());
14983cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            dest.setPackageName(src.getPackageName());
14993cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            dest.setClassName(src.getClassName());
15003cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            dest.setContentDescription(src.getContentDescription());
15013cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell
15023cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            dest.setEnabled(src.isEnabled());
15033cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            dest.setClickable(src.isClickable());
15043cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            dest.setFocusable(src.isFocusable());
15053cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            dest.setFocused(src.isFocused());
15063cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            dest.setAccessibilityFocused(src.isAccessibilityFocused());
15073cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            dest.setSelected(src.isSelected());
15083cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            dest.setLongClickable(src.isLongClickable());
15093cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell
15103cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell            dest.addAction(src.getActions());
15113cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell        }
15127d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell    }
15131d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell}
1514