DrawerLayout.java revision c27e9ab4a09e40911d180fa0e25a0011a3adcd71
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; 351b8262b87426b2f766b40d6ab4eaeac296d5c2feAdam Powellimport android.support.v4.view.ViewGroupCompat; 367d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powellimport android.support.v4.view.accessibility.AccessibilityNodeInfoCompat; 371d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powellimport android.util.AttributeSet; 381d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powellimport android.view.Gravity; 39791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powellimport android.view.KeyEvent; 401d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powellimport android.view.MotionEvent; 411d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powellimport android.view.View; 421d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powellimport android.view.ViewGroup; 433cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powellimport android.view.ViewParent; 447d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powellimport android.view.accessibility.AccessibilityEvent; 451d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 461d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell/** 471d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * DrawerLayout acts as a top-level container for window content that allows for 481d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * interactive "drawer" views to be pulled out from the edge of the window. 491d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * 501d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * <p>Drawer positioning and layout is controlled using the <code>android:layout_gravity</code> 5109c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * attribute on child views corresponding to which side of the view you want the drawer 5209c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * to emerge from: left or right. (Or start/end on platform versions that support layout direction.) 5309c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * </p> 5409c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * 5509c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * <p>To use a DrawerLayout, position your primary content view as the first child with 5609c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * a width and height of <code>match_parent</code>. Add drawers as child views after the main 5709c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * content view and set the <code>layout_gravity</code> appropriately. Drawers commonly use 5809c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * <code>match_parent</code> for height with a fixed width.</p> 5909c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * 6009c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * <p>{@link DrawerListener} can be used to monitor the state and motion of drawer views. 6109c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * Avoid performing expensive operations such as layout during animation as it can cause 6209c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * stuttering; try to perform expensive operations during the {@link #STATE_IDLE} state. 6309c38625b5400dcda3d872dbe865c867cc02e5ebAdam Powell * {@link SimpleDrawerListener} offers default/no-op implementations of each callback method.</p> 641d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * 651d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * <p>As per the Android Design guide, any drawers positioned to the left/start should 661d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * always contain content for navigating around the application, whereas any drawers 671d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * positioned to the right/end should always contain actions to take on the current content. 681d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * This preserves the same navigation left, actions right structure present in the Action Bar 691d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * and elsewhere.</p> 701d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell */ 711d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powellpublic class DrawerLayout extends ViewGroup { 721d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell private static final String TAG = "DrawerLayout"; 731d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 741d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell /** 751d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * Indicates that any drawers are in an idle, settled state. No animation is in progress. 761d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell */ 771d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public static final int STATE_IDLE = ViewDragHelper.STATE_IDLE; 781d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 791d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell /** 801d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * Indicates that a drawer is currently being dragged by the user. 811d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell */ 821d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public static final int STATE_DRAGGING = ViewDragHelper.STATE_DRAGGING; 831d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 841d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell /** 851d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * Indicates that a drawer is in the process of settling to a final position. 861d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell */ 871d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public static final int STATE_SETTLING = ViewDragHelper.STATE_SETTLING; 881d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 890492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell /** 900492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * The drawer is unlocked. 910492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell */ 920492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell public static final int LOCK_MODE_UNLOCKED = 0; 930492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell 940492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell /** 950492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * The drawer is locked closed. The user may not open it, though 960492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * the app may open it programmatically. 970492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell */ 980492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell public static final int LOCK_MODE_LOCKED_CLOSED = 1; 990492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell 1000492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell /** 1010492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * The drawer is locked open. The user may not close it, though the app 1020492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * may close it programmatically. 1030492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell */ 1040492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell public static final int LOCK_MODE_LOCKED_OPEN = 2; 1050492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell 1061d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell private static final int MIN_DRAWER_MARGIN = 64; // dp 1071d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 1081d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell private static final int DEFAULT_SCRIM_COLOR = 0x99000000; 1091d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 110ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell /** 1111732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell * Length of time to delay before peeking the drawer. 1121732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell */ 1131732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell private static final int PEEK_DELAY = 160; // ms 1141732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell 1151732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell /** 11679f95ce3e660d267831067e514ff455156c4381fAdam Powell * Minimum velocity that will be detected as a fling 11779f95ce3e660d267831067e514ff455156c4381fAdam Powell */ 11879f95ce3e660d267831067e514ff455156c4381fAdam Powell private static final int MIN_FLING_VELOCITY = 400; // dips per second 11979f95ce3e660d267831067e514ff455156c4381fAdam Powell 12079f95ce3e660d267831067e514ff455156c4381fAdam Powell /** 121ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell * Experimental feature. 122ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell */ 123ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell private static final boolean ALLOW_EDGE_LOCK = false; 124ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell 1251d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell private static final int[] LAYOUT_ATTRS = new int[] { 1261d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell android.R.attr.layout_gravity 1271d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell }; 1281d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 1291d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell private int mMinDrawerMargin; 1301d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 1311d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell private int mScrimColor = DEFAULT_SCRIM_COLOR; 1321d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell private float mScrimOpacity; 1331d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell private Paint mScrimPaint = new Paint(); 1341d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 1351d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell private final ViewDragHelper mLeftDragger; 1361d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell private final ViewDragHelper mRightDragger; 1371732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell private final ViewDragCallback mLeftCallback; 1381732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell private final ViewDragCallback mRightCallback; 1391d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell private int mDrawerState; 140b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell private boolean mInLayout; 14157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell private boolean mFirstLayout = true; 1420492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell private int mLockModeLeft; 1430492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell private int mLockModeRight; 1441732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell private boolean mDisallowInterceptRequested; 145cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell private boolean mChildrenCanceledTouch; 1461d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 1471d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell private DrawerListener mListener; 1481d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 1491d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell private float mInitialMotionX; 1501d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell private float mInitialMotionY; 1511d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 152b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell private Drawable mShadowLeft; 153b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell private Drawable mShadowRight; 154b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell 1551d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell /** 1561d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * Listener for monitoring events about drawers. 1571d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell */ 1581d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public interface DrawerListener { 1591d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell /** 1601d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * Called when a drawer's position changes. 1611d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * @param drawerView The child view that was moved 1621d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * @param slideOffset The new offset of this drawer within its range, from 0-1 1631d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell */ 1641d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public void onDrawerSlide(View drawerView, float slideOffset); 1651d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 1661d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell /** 1671d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * Called when a drawer has settled in a completely open state. 1681d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * The drawer is interactive at this point. 1691d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * 1701d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * @param drawerView Drawer view that is now open 1711d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell */ 1721d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public void onDrawerOpened(View drawerView); 1731d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 1741d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell /** 1751d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * Called when a drawer has settled in a completely closed state. 1761d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * 1771d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * @param drawerView Drawer view that is now closed 1781d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell */ 1791d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public void onDrawerClosed(View drawerView); 1801d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 1811d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell /** 1821d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * Called when the drawer motion state changes. The new state will 1831d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * be one of {@link #STATE_IDLE}, {@link #STATE_DRAGGING} or {@link #STATE_SETTLING}. 1841d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * 1851d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * @param newState The new drawer motion state 1861d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell */ 1871d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public void onDrawerStateChanged(int newState); 1881d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 1891d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 190b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell /** 191b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * Stub/no-op implementations of all methods of {@link DrawerListener}. 192b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * Override this if you only care about a few of the available callback methods. 193b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell */ 194b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell public static abstract class SimpleDrawerListener implements DrawerListener { 195b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell @Override 196b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell public void onDrawerSlide(View drawerView, float slideOffset) { 197b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 198b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell 199b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell @Override 200b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell public void onDrawerOpened(View drawerView) { 201b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 202b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell 203b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell @Override 204b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell public void onDrawerClosed(View drawerView) { 205b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 206b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell 207b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell @Override 208b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell public void onDrawerStateChanged(int newState) { 209b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 210b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 211b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell 2121d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public DrawerLayout(Context context) { 2131d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell this(context, null); 2141d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 2151d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 2161d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public DrawerLayout(Context context, AttributeSet attrs) { 2171d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell this(context, attrs, 0); 2181d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 2191d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 2201d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public DrawerLayout(Context context, AttributeSet attrs, int defStyle) { 2211d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell super(context, attrs, defStyle); 2221d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 2231d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final float density = getResources().getDisplayMetrics().density; 2241d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mMinDrawerMargin = (int) (MIN_DRAWER_MARGIN * density + 0.5f); 22579f95ce3e660d267831067e514ff455156c4381fAdam Powell final float minVel = MIN_FLING_VELOCITY * density; 2261d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 2271732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell mLeftCallback = new ViewDragCallback(Gravity.LEFT); 2281732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell mRightCallback = new ViewDragCallback(Gravity.RIGHT); 2291d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 2301732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell mLeftDragger = ViewDragHelper.create(this, 0.5f, mLeftCallback); 2311d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mLeftDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT); 23279f95ce3e660d267831067e514ff455156c4381fAdam Powell mLeftDragger.setMinVelocity(minVel); 2331732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell mLeftCallback.setDragger(mLeftDragger); 2341d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 2351732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell mRightDragger = ViewDragHelper.create(this, 0.5f, mRightCallback); 2361d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mRightDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_RIGHT); 23779f95ce3e660d267831067e514ff455156c4381fAdam Powell mRightDragger.setMinVelocity(minVel); 2381732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell mRightCallback.setDragger(mRightDragger); 239791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell 240791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell // So that we can catch the back button 241791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell setFocusableInTouchMode(true); 2427d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell 2437d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate()); 2441b8262b87426b2f766b40d6ab4eaeac296d5c2feAdam Powell ViewGroupCompat.setMotionEventSplittingEnabled(this, false); 2451d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 2461d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 2471d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell /** 248b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * Set a simple drawable used for the left or right shadow. 249b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * The drawable provided must have a nonzero intrinsic width. 250b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * 251b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * @param shadowDrawable Shadow drawable to use at the edge of a drawer 252b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * @param gravity Which drawer the shadow should apply to 253b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell */ 254b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell public void setDrawerShadow(Drawable shadowDrawable, int gravity) { 255b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell /* 256b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * TODO Someone someday might want to set more complex drawables here. 257b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * They're probably nuts, but we might want to consider registering callbacks, 258b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * setting states, etc. properly. 259b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell */ 260b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell 261b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell final int absGravity = GravityCompat.getAbsoluteGravity(gravity, 262b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell ViewCompat.getLayoutDirection(this)); 263b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell if ((absGravity & Gravity.LEFT) == Gravity.LEFT) { 264b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell mShadowLeft = shadowDrawable; 265b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell invalidate(); 266b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 267b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell if ((absGravity & Gravity.RIGHT) == Gravity.RIGHT) { 268b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell mShadowRight = shadowDrawable; 269b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell invalidate(); 270b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 271b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 272b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell 273b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell /** 274b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * Set a simple drawable used for the left or right shadow. 275b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * The drawable provided must have a nonzero intrinsic width. 276b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * 277b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * @param resId Resource id of a shadow drawable to use at the edge of a drawer 278b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * @param gravity Which drawer the shadow should apply to 279b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell */ 280b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell public void setDrawerShadow(int resId, int gravity) { 281b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell setDrawerShadow(getResources().getDrawable(resId), gravity); 282b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 283b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell 284b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell /** 285fe130779be95af79e875bdbeac7182a424b8b9a6Adam Powell * Set a color to use for the scrim that obscures primary content while a drawer is open. 286fe130779be95af79e875bdbeac7182a424b8b9a6Adam Powell * 287fe130779be95af79e875bdbeac7182a424b8b9a6Adam Powell * @param color Color to use in 0xAARRGGBB format. 288fe130779be95af79e875bdbeac7182a424b8b9a6Adam Powell */ 289fe130779be95af79e875bdbeac7182a424b8b9a6Adam Powell public void setScrimColor(int color) { 290fe130779be95af79e875bdbeac7182a424b8b9a6Adam Powell mScrimColor = color; 291fe130779be95af79e875bdbeac7182a424b8b9a6Adam Powell invalidate(); 292fe130779be95af79e875bdbeac7182a424b8b9a6Adam Powell } 293fe130779be95af79e875bdbeac7182a424b8b9a6Adam Powell 294fe130779be95af79e875bdbeac7182a424b8b9a6Adam Powell /** 2951d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * Set a listener to be notified of drawer events. 2961d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * 2971d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * @param listener Listener to notify when drawer events occur 2981d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * @see DrawerListener 2991d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell */ 3001d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public void setDrawerListener(DrawerListener listener) { 3011d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mListener = listener; 3021d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 3031d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 3041d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell /** 3050492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * Enable or disable interaction with all drawers. 3060492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * 3070492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * <p>This allows the application to restrict the user's ability to open or close 3080492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * any drawer within this layout. DrawerLayout will still respond to calls to 3090492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * {@link #openDrawer(int)}, {@link #closeDrawer(int)} and friends if a drawer is locked.</p> 3100492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * 3110492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * <p>Locking drawers open or closed will implicitly open or close 3120492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * any drawers as appropriate.</p> 3130492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * 3140492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * @param lockMode The new lock mode for the given drawer. One of {@link #LOCK_MODE_UNLOCKED}, 3150492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * {@link #LOCK_MODE_LOCKED_CLOSED} or {@link #LOCK_MODE_LOCKED_OPEN}. 3160492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell */ 3170492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell public void setDrawerLockMode(int lockMode) { 3180492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell setDrawerLockMode(lockMode, Gravity.LEFT); 3190492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell setDrawerLockMode(lockMode, Gravity.RIGHT); 3200492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } 3210492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell 3220492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell /** 3230492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * Enable or disable interaction with the given drawer. 3240492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * 3250492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * <p>This allows the application to restrict the user's ability to open or close 3260492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * the given drawer. DrawerLayout will still respond to calls to {@link #openDrawer(int)}, 3270492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * {@link #closeDrawer(int)} and friends if a drawer is locked.</p> 3280492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * 3290492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * <p>Locking a drawer open or closed will implicitly open or close 3300492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * that drawer as appropriate.</p> 3310492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * 3320492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * @param lockMode The new lock mode for the given drawer. One of {@link #LOCK_MODE_UNLOCKED}, 3330492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * {@link #LOCK_MODE_LOCKED_CLOSED} or {@link #LOCK_MODE_LOCKED_OPEN}. 3340492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * @param edgeGravity Gravity.LEFT, RIGHT, START or END. 3350492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * Expresses which drawer to change the mode for. 3360492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * 3370492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * @see #LOCK_MODE_UNLOCKED 3380492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * @see #LOCK_MODE_LOCKED_CLOSED 3390492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * @see #LOCK_MODE_LOCKED_OPEN 3400492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell */ 3410492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell public void setDrawerLockMode(int lockMode, int edgeGravity) { 3420492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell final int absGrav = GravityCompat.getAbsoluteGravity(edgeGravity, 3430492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell ViewCompat.getLayoutDirection(this)); 3440492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell if (absGrav == Gravity.LEFT) { 3450492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell mLockModeLeft = lockMode; 3460492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } else if (absGrav == Gravity.RIGHT) { 3470492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell mLockModeRight = lockMode; 3480492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } 3490492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell if (lockMode != LOCK_MODE_UNLOCKED) { 3500492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell // Cancel interaction in progress 3510492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell final ViewDragHelper helper = absGrav == Gravity.LEFT ? mLeftDragger : mRightDragger; 3520492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell helper.cancel(); 3530492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } 3540492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell switch (lockMode) { 3550492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell case LOCK_MODE_LOCKED_OPEN: 3560492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell final View toOpen = findDrawerWithGravity(absGrav); 3570492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell if (toOpen != null) { 3580492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell openDrawer(toOpen); 3590492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } 3600492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell break; 3610492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell case LOCK_MODE_LOCKED_CLOSED: 3620492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell final View toClose = findDrawerWithGravity(absGrav); 3630492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell if (toClose != null) { 3640492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell closeDrawer(toClose); 3650492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } 3660492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell break; 3670492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell // default: do nothing 3680492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } 3690492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } 3700492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell 3710492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell /** 3720492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * Enable or disable interaction with the given drawer. 3730492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * 3740492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * <p>This allows the application to restrict the user's ability to open or close 3750492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * the given drawer. DrawerLayout will still respond to calls to {@link #openDrawer(int)}, 3760492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * {@link #closeDrawer(int)} and friends if a drawer is locked.</p> 3770492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * 3780492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * <p>Locking a drawer open or closed will implicitly open or close 3790492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * that drawer as appropriate.</p> 3800492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * 3810492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * @param lockMode The new lock mode for the given drawer. One of {@link #LOCK_MODE_UNLOCKED}, 3820492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * {@link #LOCK_MODE_LOCKED_CLOSED} or {@link #LOCK_MODE_LOCKED_OPEN}. 3830492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * @param drawerView The drawer view to change the lock mode for 3840492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * 3850492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * @see #LOCK_MODE_UNLOCKED 3860492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * @see #LOCK_MODE_LOCKED_CLOSED 3870492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * @see #LOCK_MODE_LOCKED_OPEN 3880492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell */ 3890492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell public void setDrawerLockMode(int lockMode, View drawerView) { 3900492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell if (!isDrawerView(drawerView)) { 3910492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell throw new IllegalArgumentException("View " + drawerView + " is not a " + 3920492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell "drawer with appropriate layout_gravity"); 3930492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } 3940492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell setDrawerLockMode(lockMode, getDrawerViewGravity(drawerView)); 3950492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } 3960492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell 3970492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell /** 3980492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * Check the lock mode of the drawer with the given gravity. 3990492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * 4000492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * @param edgeGravity Gravity of the drawer to check 4010492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * @return one of {@link #LOCK_MODE_UNLOCKED}, {@link #LOCK_MODE_LOCKED_CLOSED} or 4020492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * {@link #LOCK_MODE_LOCKED_OPEN}. 4030492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell */ 4040492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell public int getDrawerLockMode(int edgeGravity) { 4050492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell final int absGrav = GravityCompat.getAbsoluteGravity(edgeGravity, 4060492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell ViewCompat.getLayoutDirection(this)); 4070492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell if (absGrav == Gravity.LEFT) { 4080492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell return mLockModeLeft; 4090492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } else if (absGrav == Gravity.RIGHT) { 4100492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell return mLockModeRight; 4110492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } 4120492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell return LOCK_MODE_UNLOCKED; 4130492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } 4140492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell 4150492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell /** 4160492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * Check the lock mode of the given drawer view. 4170492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * 4180492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * @param drawerView Drawer view to check lock mode 4190492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * @return one of {@link #LOCK_MODE_UNLOCKED}, {@link #LOCK_MODE_LOCKED_CLOSED} or 4200492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell * {@link #LOCK_MODE_LOCKED_OPEN}. 4210492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell */ 4220492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell public int getDrawerLockMode(View drawerView) { 4230492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell final int gravity = getDrawerViewGravity(drawerView); 4240492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell if (gravity == Gravity.LEFT) { 4250492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell return mLockModeLeft; 4260492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } else if (gravity == Gravity.RIGHT) { 4270492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell return mLockModeRight; 4280492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } 4290492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell 4300492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell return LOCK_MODE_UNLOCKED; 4310492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } 4320492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell 4330492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell /** 4341d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * Resolve the shared state of all drawers from the component ViewDragHelpers. 4351d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * Should be called whenever a ViewDragHelper's state changes. 4361d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell */ 437b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell void updateDrawerState(int forGravity, int activeState, View activeDrawer) { 4381d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int leftState = mLeftDragger.getViewDragState(); 4391d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int rightState = mRightDragger.getViewDragState(); 4401d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 4411d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int state; 4421d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (leftState == STATE_DRAGGING || rightState == STATE_DRAGGING) { 4431d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell state = STATE_DRAGGING; 4441d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } else if (leftState == STATE_SETTLING || rightState == STATE_SETTLING) { 4451d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell state = STATE_SETTLING; 4461d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } else { 4471d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell state = STATE_IDLE; 4481d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 4491d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 450b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell if (activeDrawer != null && activeState == STATE_IDLE) { 451b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell final LayoutParams lp = (LayoutParams) activeDrawer.getLayoutParams(); 452b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell if (lp.onScreen == 0) { 453b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell dispatchOnDrawerClosed(activeDrawer); 454b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } else if (lp.onScreen == 1) { 455b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell dispatchOnDrawerOpened(activeDrawer); 456b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 457b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 458b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell 4591d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (state != mDrawerState) { 4601d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mDrawerState = state; 461b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell 4621d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (mListener != null) { 4631d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mListener.onDrawerStateChanged(state); 4641d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 4651d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 4661d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 4671d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 4681d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell void dispatchOnDrawerClosed(View drawerView) { 4691d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams(); 4701d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (lp.knownOpen) { 4711d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell lp.knownOpen = false; 4721d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (mListener != null) { 4731d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mListener.onDrawerClosed(drawerView); 4741d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 4757d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); 4761d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 4771d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 4781d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 4791d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell void dispatchOnDrawerOpened(View drawerView) { 4801d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams(); 4811d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (!lp.knownOpen) { 4821d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell lp.knownOpen = true; 4831d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (mListener != null) { 4841d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mListener.onDrawerOpened(drawerView); 4851d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 4867d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell drawerView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); 4871d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 4881d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 4891d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 4901d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell void dispatchOnDrawerSlide(View drawerView, float slideOffset) { 4911d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (mListener != null) { 4921d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mListener.onDrawerSlide(drawerView, slideOffset); 4931d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 4941d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 4951d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 4961d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell void setDrawerViewOffset(View drawerView, float slideOffset) { 4971d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams(); 498b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell if (slideOffset == lp.onScreen) { 4991d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell return; 5001d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 5011d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 502b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell lp.onScreen = slideOffset; 5031d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell dispatchOnDrawerSlide(drawerView, slideOffset); 5041d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 5051d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 5061d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell float getDrawerViewOffset(View drawerView) { 507b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell return ((LayoutParams) drawerView.getLayoutParams()).onScreen; 5081d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 5091d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 5101d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell int getDrawerViewGravity(View drawerView) { 5111d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int gravity = ((LayoutParams) drawerView.getLayoutParams()).gravity; 5121d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell return GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(drawerView)); 5131d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 5141d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 5151d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell boolean checkDrawerViewGravity(View drawerView, int checkFor) { 5161d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int absGrav = getDrawerViewGravity(drawerView); 5171d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell return (absGrav & checkFor) == checkFor; 5181d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 5191d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 5200492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell View findOpenDrawer() { 5210492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell final int childCount = getChildCount(); 5220492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell for (int i = 0; i < childCount; i++) { 5230492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell final View child = getChildAt(i); 5240492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell if (((LayoutParams) child.getLayoutParams()).knownOpen) { 5250492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell return child; 5260492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } 5270492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } 5280492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell return null; 5290492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } 5300492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell 5311d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell void moveDrawerToOffset(View drawerView, float slideOffset) { 5321d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final float oldOffset = getDrawerViewOffset(drawerView); 5331d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int width = drawerView.getWidth(); 5341d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int oldPos = (int) (width * oldOffset); 5351d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int newPos = (int) (width * slideOffset); 5361d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int dx = newPos - oldPos; 5371d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 5381d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell drawerView.offsetLeftAndRight(checkDrawerViewGravity(drawerView, Gravity.LEFT) ? dx : -dx); 5391d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell setDrawerViewOffset(drawerView, slideOffset); 5401d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 5411d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 5421d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell View findDrawerWithGravity(int gravity) { 5431d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int childCount = getChildCount(); 5441d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell for (int i = 0; i < childCount; i++) { 5451d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final View child = getChildAt(i); 5461d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int childGravity = getDrawerViewGravity(child); 5471d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if ((childGravity & Gravity.HORIZONTAL_GRAVITY_MASK) == 5481d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell (gravity & Gravity.HORIZONTAL_GRAVITY_MASK)) { 5491d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell return child; 5501d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 5511d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 5521d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell return null; 5531d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 5541d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 5551d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell /** 5561d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * Simple gravity to string - only supports LEFT and RIGHT for debugging output. 5571d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * 5581d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * @param gravity Absolute gravity value 5591d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * @return LEFT or RIGHT as appropriate, or a hex string 5601d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell */ 5611d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell static String gravityToString(int gravity) { 5621d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if ((gravity & Gravity.LEFT) == Gravity.LEFT) { 5631d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell return "LEFT"; 5641d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 5651d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if ((gravity & Gravity.RIGHT) == Gravity.RIGHT) { 5661d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell return "RIGHT"; 5671d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 5681d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell return Integer.toHexString(gravity); 5691d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 5701d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 5711d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell @Override 57257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell protected void onDetachedFromWindow() { 57357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell super.onDetachedFromWindow(); 57457902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell mFirstLayout = true; 57557902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell } 57657902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell 57757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell @Override 57857902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell protected void onAttachedToWindow() { 57957902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell super.onAttachedToWindow(); 58057902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell mFirstLayout = true; 58157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell } 58257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell 58357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell @Override 5841d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 5851d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int widthMode = MeasureSpec.getMode(widthMeasureSpec); 5861d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int heightMode = MeasureSpec.getMode(heightMeasureSpec); 5871d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int widthSize = MeasureSpec.getSize(widthMeasureSpec); 5881d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int heightSize = MeasureSpec.getSize(heightMeasureSpec); 5891d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 5901d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (widthMode != MeasureSpec.EXACTLY || heightMode != MeasureSpec.EXACTLY) { 5911d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell throw new IllegalArgumentException( 5921d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell "DrawerLayout must be measured with MeasureSpec.EXACTLY."); 5931d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 5941d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 5951d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell setMeasuredDimension(widthSize, heightSize); 5961d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 5971d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell // Gravity value for each drawer we've seen. Only one of each permitted. 5981d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell int foundDrawers = 0; 5991d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int childCount = getChildCount(); 6001d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell for (int i = 0; i < childCount; i++) { 6011d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final View child = getChildAt(i); 6021d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 6031d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (child.getVisibility() == GONE) { 6041d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell continue; 6051d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 6061d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 60700ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell final LayoutParams lp = (LayoutParams) child.getLayoutParams(); 60800ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell 6091d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (isContentView(child)) { 6101d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell // Content views get measured at exactly the layout's size. 61100ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell final int contentWidthSpec = MeasureSpec.makeMeasureSpec( 61200ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell widthSize - lp.leftMargin - lp.rightMargin, MeasureSpec.EXACTLY); 61300ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell final int contentHeightSpec = MeasureSpec.makeMeasureSpec( 61400ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell heightSize - lp.topMargin - lp.bottomMargin, MeasureSpec.EXACTLY); 61500ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell child.measure(contentWidthSpec, contentHeightSpec); 6161d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } else if (isDrawerView(child)) { 6171d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int childGravity = 6181d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell getDrawerViewGravity(child) & Gravity.HORIZONTAL_GRAVITY_MASK; 6191d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if ((foundDrawers & childGravity) != 0) { 6201d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell throw new IllegalStateException("Child drawer has absolute gravity " + 6211d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell gravityToString(childGravity) + " but this " + TAG + " already has a " + 6221d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell "drawer view along that edge"); 6231d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 62400ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell final int drawerWidthSpec = getChildMeasureSpec(widthMeasureSpec, 62500ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell mMinDrawerMargin + lp.leftMargin + lp.rightMargin, 62600ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell lp.width); 62700ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell final int drawerHeightSpec = getChildMeasureSpec(heightMeasureSpec, 62800ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell lp.topMargin + lp.bottomMargin, 62900ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell lp.height); 63000ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell child.measure(drawerWidthSpec, drawerHeightSpec); 6311d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } else { 6321d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell throw new IllegalStateException("Child " + child + " at index " + i + 6331d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell " does not have a valid layout_gravity - must be Gravity.LEFT, " + 6341d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell "Gravity.RIGHT or Gravity.NO_GRAVITY"); 6351d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 6361d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 6371d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 6381d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 6391d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell @Override 6401d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell protected void onLayout(boolean changed, int l, int t, int r, int b) { 641b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell mInLayout = true; 642c27e9ab4a09e40911d180fa0e25a0011a3adcd71Adam Powell final int width = r - l; 6431d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int childCount = getChildCount(); 6441d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell for (int i = 0; i < childCount; i++) { 6451d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final View child = getChildAt(i); 6461d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 6471d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (child.getVisibility() == GONE) { 6481d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell continue; 6491d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 6501d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 65100ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell final LayoutParams lp = (LayoutParams) child.getLayoutParams(); 65200ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell 6531d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (isContentView(child)) { 65400ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell child.layout(lp.leftMargin, lp.topMargin, 65500ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell lp.leftMargin + child.getMeasuredWidth(), 65600ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell lp.topMargin + child.getMeasuredHeight()); 6571d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } else { // Drawer, if it wasn't onMeasure would have thrown an exception. 6581d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int childWidth = child.getMeasuredWidth(); 65900ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell final int childHeight = child.getMeasuredHeight(); 6601d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell int childLeft; 6611d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 662c27e9ab4a09e40911d180fa0e25a0011a3adcd71Adam Powell final float newOffset; 6631d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (checkDrawerViewGravity(child, Gravity.LEFT)) { 664b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell childLeft = -childWidth + (int) (childWidth * lp.onScreen); 665c27e9ab4a09e40911d180fa0e25a0011a3adcd71Adam Powell newOffset = (float) (childWidth + childLeft) / childWidth; 6661d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } else { // Right; onMeasure checked for us. 667c27e9ab4a09e40911d180fa0e25a0011a3adcd71Adam Powell childLeft = width - (int) (childWidth * lp.onScreen); 668c27e9ab4a09e40911d180fa0e25a0011a3adcd71Adam Powell newOffset = (float) (width - childLeft) / childWidth; 6691d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 6701d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 671c27e9ab4a09e40911d180fa0e25a0011a3adcd71Adam Powell final boolean changeOffset = newOffset != lp.onScreen; 672c27e9ab4a09e40911d180fa0e25a0011a3adcd71Adam Powell 67300ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; 67400ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell 67500ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell switch (vgrav) { 67600ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell default: 67700ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell case Gravity.TOP: { 67800ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell child.layout(childLeft, lp.topMargin, childLeft + childWidth, childHeight); 67900ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell break; 68000ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell } 68100ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell 68200ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell case Gravity.BOTTOM: { 68300ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell final int height = b - t; 68400ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell child.layout(childLeft, 68500ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell height - lp.bottomMargin - child.getMeasuredHeight(), 68600ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell childLeft + childWidth, 68700ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell height - lp.bottomMargin); 68800ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell break; 68900ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell } 69000ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell 69100ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell case Gravity.CENTER_VERTICAL: { 69200ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell final int height = b - t; 69300ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell int childTop = (height - childHeight) / 2; 69400ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell 69500ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell // Offset for margins. If things don't fit right because of 69600ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell // bad measurement before, oh well. 69700ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell if (childTop < lp.topMargin) { 69800ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell childTop = lp.topMargin; 69900ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell } else if (childTop + childHeight > height - lp.bottomMargin) { 70000ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell childTop = height - lp.bottomMargin - childHeight; 70100ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell } 70200ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell child.layout(childLeft, childTop, childLeft + childWidth, 70300ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell childTop + childHeight); 70400ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell break; 70500ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell } 70600ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell } 707b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell 708c27e9ab4a09e40911d180fa0e25a0011a3adcd71Adam Powell if (changeOffset) { 709c27e9ab4a09e40911d180fa0e25a0011a3adcd71Adam Powell setDrawerViewOffset(child, newOffset); 710c27e9ab4a09e40911d180fa0e25a0011a3adcd71Adam Powell } 711c27e9ab4a09e40911d180fa0e25a0011a3adcd71Adam Powell 712c27e9ab4a09e40911d180fa0e25a0011a3adcd71Adam Powell final int newVisibility = lp.onScreen > 0 ? VISIBLE : INVISIBLE; 713c27e9ab4a09e40911d180fa0e25a0011a3adcd71Adam Powell if (child.getVisibility() != newVisibility) { 714c27e9ab4a09e40911d180fa0e25a0011a3adcd71Adam Powell child.setVisibility(newVisibility); 715b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 7161d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 7171d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 718b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell mInLayout = false; 71957902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell mFirstLayout = false; 720b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 721b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell 722b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell @Override 723b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell public void requestLayout() { 724b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell if (!mInLayout) { 725b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell super.requestLayout(); 726b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 7271d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 7281d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 7291d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell @Override 7301d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public void computeScroll() { 7311d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int childCount = getChildCount(); 7321d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell float scrimOpacity = 0; 7331d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell for (int i = 0; i < childCount; i++) { 734b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell final float onscreen = ((LayoutParams) getChildAt(i).getLayoutParams()).onScreen; 7351d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell scrimOpacity = Math.max(scrimOpacity, onscreen); 7361d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 7371d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mScrimOpacity = scrimOpacity; 7381d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 7391d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell // "|" used on purpose; both need to run. 7401d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (mLeftDragger.continueSettling(true) | mRightDragger.continueSettling(true)) { 7411d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell ViewCompat.postInvalidateOnAnimation(this); 7421d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 7431d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 7441d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 745b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell private static boolean hasOpaqueBackground(View v) { 746b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell final Drawable bg = v.getBackground(); 747b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell if (bg != null) { 748b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell return bg.getOpacity() == PixelFormat.OPAQUE; 749b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 750b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell return false; 751b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 752b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell 7531d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell @Override 7541d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell protected boolean drawChild(Canvas canvas, View child, long drawingTime) { 75500ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell final int height = getHeight(); 756b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell final boolean drawingContent = isContentView(child); 757b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell int clipLeft = 0, clipRight = getWidth(); 758b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell 7591d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int restoreCount = canvas.save(); 760b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell if (drawingContent) { 761b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell final int childCount = getChildCount(); 762b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell for (int i = 0; i < childCount; i++) { 763b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell final View v = getChildAt(i); 764b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell if (v == child || v.getVisibility() != VISIBLE || 76500ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell !hasOpaqueBackground(v) || !isDrawerView(v) || 76600ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell v.getHeight() < height) { 767b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell continue; 768b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 769b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell 770b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell if (checkDrawerViewGravity(v, Gravity.LEFT)) { 771b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell final int vright = v.getRight(); 772b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell if (vright > clipLeft) clipLeft = vright; 773b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } else { 774b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell final int vleft = v.getLeft(); 775b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell if (vleft < clipRight) clipRight = vleft; 776b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 777b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 778b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell canvas.clipRect(clipLeft, 0, clipRight, getHeight()); 779b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 7801d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final boolean result = super.drawChild(canvas, child, drawingTime); 7811d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell canvas.restoreToCount(restoreCount); 782b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell 783b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell if (mScrimOpacity > 0 && drawingContent) { 7841d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int baseAlpha = (mScrimColor & 0xff000000) >>> 24; 7851d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int imag = (int) (baseAlpha * mScrimOpacity); 7861d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int color = imag << 24 | (mScrimColor & 0xffffff); 7871d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mScrimPaint.setColor(color); 7881d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 789b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell canvas.drawRect(clipLeft, 0, clipRight, getHeight(), mScrimPaint); 790b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } else if (mShadowLeft != null && checkDrawerViewGravity(child, Gravity.LEFT)) { 791b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell final int shadowWidth = mShadowLeft.getIntrinsicWidth(); 792b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell final int childRight = child.getRight(); 793ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell final int drawerPeekDistance = mLeftDragger.getEdgeSize(); 794b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell final float alpha = 795ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell Math.max(0, Math.min((float) childRight / drawerPeekDistance, 1.f)); 796b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell mShadowLeft.setBounds(childRight, child.getTop(), 797b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell childRight + shadowWidth, child.getBottom()); 798b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell mShadowLeft.setAlpha((int) (0xff * alpha)); 799b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell mShadowLeft.draw(canvas); 800b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } else if (mShadowRight != null && checkDrawerViewGravity(child, Gravity.RIGHT)) { 801b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell final int shadowWidth = mShadowRight.getIntrinsicWidth(); 802b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell final int childLeft = child.getLeft(); 803b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell final int showing = getWidth() - childLeft; 804ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell final int drawerPeekDistance = mRightDragger.getEdgeSize(); 805b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell final float alpha = 806ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f)); 807b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell mShadowRight.setBounds(childLeft - shadowWidth, child.getTop(), 808b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell childLeft, child.getBottom()); 809b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell mShadowRight.setAlpha((int) (0xff * alpha)); 810b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell mShadowRight.draw(canvas); 8111d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 8121d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell return result; 8131d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 8141d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 8151d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell boolean isContentView(View child) { 8161d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell return ((LayoutParams) child.getLayoutParams()).gravity == Gravity.NO_GRAVITY; 8171d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 8181d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 8191d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell boolean isDrawerView(View child) { 8201d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int gravity = ((LayoutParams) child.getLayoutParams()).gravity; 8211d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int absGravity = GravityCompat.getAbsoluteGravity(gravity, 8221d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell ViewCompat.getLayoutDirection(child)); 8231d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell return (absGravity & (Gravity.LEFT | Gravity.RIGHT)) != 0; 8241d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 8251d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 8261d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell @Override 8271d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public boolean onInterceptTouchEvent(MotionEvent ev) { 8281d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int action = MotionEventCompat.getActionMasked(ev); 8291d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 8301d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell // "|" used deliberately here; both methods should be invoked. 8311d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final boolean interceptForDrag = mLeftDragger.shouldInterceptTouchEvent(ev) | 8321d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mRightDragger.shouldInterceptTouchEvent(ev); 8331d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 8341d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell boolean interceptForTap = false; 8351d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 8361d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell switch (action) { 8371d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell case MotionEvent.ACTION_DOWN: { 8381d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final float x = ev.getX(); 8391d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final float y = ev.getY(); 8401d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mInitialMotionX = x; 8411d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mInitialMotionY = y; 8421d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (mScrimOpacity > 0 && 8431d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell isContentView(mLeftDragger.findTopChildUnder((int) x, (int) y))) { 8441d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell interceptForTap = true; 8451d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 8461732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell mDisallowInterceptRequested = false; 847cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell mChildrenCanceledTouch = false; 8481732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell break; 8491732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell } 8501732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell 8511732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell case MotionEvent.ACTION_MOVE: { 8521732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell // If we cross the touch slop, don't perform the delayed peek for an edge touch. 8531732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell if (mLeftDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) { 8541732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell mLeftCallback.removeCallbacks(); 8551732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell mRightCallback.removeCallbacks(); 8561732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell } 8571d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell break; 8581d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 8591d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 8601d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell case MotionEvent.ACTION_CANCEL: 8611d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell case MotionEvent.ACTION_UP: { 8621d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell closeDrawers(true); 8631732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell mDisallowInterceptRequested = false; 864cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell mChildrenCanceledTouch = false; 8651d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 8661d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 8671732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell 868cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell return interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch; 8691d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 8701d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 8711d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell @Override 8721d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public boolean onTouchEvent(MotionEvent ev) { 8731d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mLeftDragger.processTouchEvent(ev); 8741d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mRightDragger.processTouchEvent(ev); 8751d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 8761d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int action = ev.getAction(); 8771d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell boolean wantTouchEvents = true; 8781d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 8791d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell switch (action & MotionEventCompat.ACTION_MASK) { 8801d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell case MotionEvent.ACTION_DOWN: { 8811d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final float x = ev.getX(); 8821d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final float y = ev.getY(); 8831d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mInitialMotionX = x; 8841d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mInitialMotionY = y; 8851732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell mDisallowInterceptRequested = false; 886cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell mChildrenCanceledTouch = false; 8871d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell break; 8881d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 8891d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 8901d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell case MotionEvent.ACTION_UP: { 8911d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final float x = ev.getX(); 8921d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final float y = ev.getY(); 8931d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell boolean peekingOnly = true; 8948bc268e9c40e4ae375a0d65dc1293dccc541186fAdam Powell final View touchedView = mLeftDragger.findTopChildUnder((int) x, (int) y); 8958bc268e9c40e4ae375a0d65dc1293dccc541186fAdam Powell if (touchedView != null && isContentView(touchedView)) { 8961d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final float dx = x - mInitialMotionX; 8971d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final float dy = y - mInitialMotionY; 8981d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int slop = mLeftDragger.getTouchSlop(); 8991d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (dx * dx + dy * dy < slop * slop) { 9000492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell // Taps close a dimmed open drawer but only if it isn't locked open. 9010492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell final View openDrawer = findOpenDrawer(); 9020492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell if (openDrawer != null) { 9030492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell peekingOnly = getDrawerLockMode(openDrawer) == LOCK_MODE_LOCKED_OPEN; 9040492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } 9051d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 9061d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 9071d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell closeDrawers(peekingOnly); 9081732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell mDisallowInterceptRequested = false; 9091d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell break; 9101d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 9111d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 9121d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell case MotionEvent.ACTION_CANCEL: { 9131d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell closeDrawers(true); 9141732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell mDisallowInterceptRequested = false; 915cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell mChildrenCanceledTouch = false; 9161d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell break; 9171d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 9181d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 9191d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 9201d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell return wantTouchEvents; 9211d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 9221d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 923ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { 9241732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell if (!mLeftDragger.isEdgeTouched(ViewDragHelper.EDGE_LEFT) && 9251732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell !mRightDragger.isEdgeTouched(ViewDragHelper.EDGE_RIGHT)) { 9261732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell // If we have an edge touch we want to skip this and track it for later instead. 9271732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell super.requestDisallowInterceptTouchEvent(disallowIntercept); 9281732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell } 9291732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell mDisallowInterceptRequested = disallowIntercept; 930ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell if (disallowIntercept) { 931ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell closeDrawers(true); 932ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell } 933ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell } 934ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell 9351d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell /** 9361d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * Close all currently open drawer views by animating them out of view. 9371d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell */ 9381d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public void closeDrawers() { 9391d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell closeDrawers(false); 9401d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 9411d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 9421d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell void closeDrawers(boolean peekingOnly) { 9431d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell boolean needsInvalidate = false; 9441d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int childCount = getChildCount(); 9451d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell for (int i = 0; i < childCount; i++) { 9461d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final View child = getChildAt(i); 9471d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final LayoutParams lp = (LayoutParams) child.getLayoutParams(); 9481d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 9491d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (!isDrawerView(child) || (peekingOnly && !lp.isPeeking)) { 9501d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell continue; 9511d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 9521d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 9531d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int childWidth = child.getWidth(); 9541d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 9551d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (checkDrawerViewGravity(child, Gravity.LEFT)) { 9561d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell needsInvalidate |= mLeftDragger.smoothSlideViewTo(child, 9571d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell -childWidth, child.getTop()); 9581d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } else { 9591d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell needsInvalidate |= mRightDragger.smoothSlideViewTo(child, 9601d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell getWidth(), child.getTop()); 9611d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 9621d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 9631d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell lp.isPeeking = false; 9641d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 9651d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 9661732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell mLeftCallback.removeCallbacks(); 9671732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell mRightCallback.removeCallbacks(); 9681732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell 9691d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (needsInvalidate) { 9701d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell invalidate(); 9711d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 9721d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 9731d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 9741d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell /** 9751d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * Open the specified drawer view by animating it into view. 9761d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * 9771d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * @param drawerView Drawer view to open 9781d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell */ 9791d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public void openDrawer(View drawerView) { 9801d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (!isDrawerView(drawerView)) { 9811d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer"); 9821d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 9831d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 98457902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell if (mFirstLayout) { 98557902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams(); 98657902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell lp.onScreen = 1.f; 98757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell lp.knownOpen = true; 9881d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } else { 98957902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell if (checkDrawerViewGravity(drawerView, Gravity.LEFT)) { 99057902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell mLeftDragger.smoothSlideViewTo(drawerView, 0, drawerView.getTop()); 99157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell } else { 99257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell mRightDragger.smoothSlideViewTo(drawerView, getWidth() - drawerView.getWidth(), 99357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell drawerView.getTop()); 99457902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell } 9951d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 9961d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell invalidate(); 9971d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 9981d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 9991d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell /** 10001d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * Open the specified drawer by animating it out of view. 10011d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * 10021d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * @param gravity Gravity.LEFT to move the left drawer or Gravity.RIGHT for the right. 10031d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * GravityCompat.START or GravityCompat.END may also be used. 10041d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell */ 10051d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public void openDrawer(int gravity) { 10061d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int absGravity = GravityCompat.getAbsoluteGravity(gravity, 10071d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell ViewCompat.getLayoutDirection(this)); 10081d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final View drawerView = findDrawerWithGravity(absGravity); 10091d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 10101d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (drawerView == null) { 10111d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell throw new IllegalArgumentException("No drawer view found with absolute gravity " + 10121d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell gravityToString(absGravity)); 10131d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 10141d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell openDrawer(drawerView); 10151d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 10161d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 10171d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell /** 10181d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * Close the specified drawer view by animating it into view. 10191d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * 10201d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * @param drawerView Drawer view to close 10211d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell */ 10221d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public void closeDrawer(View drawerView) { 10231d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (!isDrawerView(drawerView)) { 10241d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer"); 10251d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 10261d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 102757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell if (mFirstLayout) { 102857902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams(); 102957902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell lp.onScreen = 0.f; 103057902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell lp.knownOpen = false; 10311d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } else { 103257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell if (checkDrawerViewGravity(drawerView, Gravity.LEFT)) { 103357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell mLeftDragger.smoothSlideViewTo(drawerView, -drawerView.getWidth(), 103457902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell drawerView.getTop()); 103557902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell } else { 103657902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell mRightDragger.smoothSlideViewTo(drawerView, getWidth(), drawerView.getTop()); 103757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell } 10381d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 10391d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell invalidate(); 10401d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 10411d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 10421d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell /** 10431d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * Close the specified drawer by animating it out of view. 10441d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * 10451d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * @param gravity Gravity.LEFT to move the left drawer or Gravity.RIGHT for the right. 10461d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell * GravityCompat.START or GravityCompat.END may also be used. 10471d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell */ 10481d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public void closeDrawer(int gravity) { 10491d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int absGravity = GravityCompat.getAbsoluteGravity(gravity, 10501d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell ViewCompat.getLayoutDirection(this)); 10511d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final View drawerView = findDrawerWithGravity(absGravity); 10521d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 10531d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (drawerView == null) { 10541d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell throw new IllegalArgumentException("No drawer view found with absolute gravity " + 10551d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell gravityToString(absGravity)); 10561d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 10571d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell closeDrawer(drawerView); 10581d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 10591d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 1060b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell /** 1061b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * Check if the given drawer view is currently in an open state. 1062b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * To be considered "open" the drawer must have settled into its fully 1063b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * visible state. To check for partial visibility use 1064b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * {@link #isDrawerVisible(android.view.View)}. 1065b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * 1066b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * @param drawer Drawer view to check 1067b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * @return true if the given drawer view is in an open state 1068b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * @see #isDrawerVisible(android.view.View) 1069b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell */ 1070b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell public boolean isDrawerOpen(View drawer) { 1071b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell if (!isDrawerView(drawer)) { 1072b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell throw new IllegalArgumentException("View " + drawer + " is not a drawer"); 1073b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 1074b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell return ((LayoutParams) drawer.getLayoutParams()).knownOpen; 1075b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 1076b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell 1077b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell /** 107879f95ce3e660d267831067e514ff455156c4381fAdam Powell * Check if the given drawer view is currently in an open state. 107979f95ce3e660d267831067e514ff455156c4381fAdam Powell * To be considered "open" the drawer must have settled into its fully 108079f95ce3e660d267831067e514ff455156c4381fAdam Powell * visible state. If there is no drawer with the given gravity this method 108179f95ce3e660d267831067e514ff455156c4381fAdam Powell * will return false. 108279f95ce3e660d267831067e514ff455156c4381fAdam Powell * 108379f95ce3e660d267831067e514ff455156c4381fAdam Powell * @param drawerGravity Gravity of the drawer to check 108479f95ce3e660d267831067e514ff455156c4381fAdam Powell * @return true if the given drawer view is in an open state 108579f95ce3e660d267831067e514ff455156c4381fAdam Powell */ 108679f95ce3e660d267831067e514ff455156c4381fAdam Powell public boolean isDrawerOpen(int drawerGravity) { 108779f95ce3e660d267831067e514ff455156c4381fAdam Powell final View drawerView = findDrawerWithGravity(drawerGravity); 108879f95ce3e660d267831067e514ff455156c4381fAdam Powell if (drawerView != null) { 108979f95ce3e660d267831067e514ff455156c4381fAdam Powell return isDrawerOpen(drawerView); 109079f95ce3e660d267831067e514ff455156c4381fAdam Powell } 109179f95ce3e660d267831067e514ff455156c4381fAdam Powell return false; 109279f95ce3e660d267831067e514ff455156c4381fAdam Powell } 109379f95ce3e660d267831067e514ff455156c4381fAdam Powell 109479f95ce3e660d267831067e514ff455156c4381fAdam Powell /** 1095b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * Check if a given drawer view is currently visible on-screen. The drawer 1096b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * may be only peeking onto the screen, fully extended, or anywhere inbetween. 1097b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * 1098b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * @param drawer Drawer view to check 1099b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * @return true if the given drawer is visible on-screen 1100b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell * @see #isDrawerOpen(android.view.View) 1101b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell */ 1102b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell public boolean isDrawerVisible(View drawer) { 1103b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell if (!isDrawerView(drawer)) { 1104b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell throw new IllegalArgumentException("View " + drawer + " is not a drawer"); 1105b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 1106b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell return ((LayoutParams) drawer.getLayoutParams()).onScreen > 0; 1107b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell } 1108b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell 110979f95ce3e660d267831067e514ff455156c4381fAdam Powell /** 111079f95ce3e660d267831067e514ff455156c4381fAdam Powell * Check if a given drawer view is currently visible on-screen. The drawer 111179f95ce3e660d267831067e514ff455156c4381fAdam Powell * may be only peeking onto the screen, fully extended, or anywhere inbetween. 111279f95ce3e660d267831067e514ff455156c4381fAdam Powell * If there is no drawer with the given gravity this method will return false. 111379f95ce3e660d267831067e514ff455156c4381fAdam Powell * 111479f95ce3e660d267831067e514ff455156c4381fAdam Powell * @param drawerGravity Gravity of the drawer to check 111579f95ce3e660d267831067e514ff455156c4381fAdam Powell * @return true if the given drawer is visible on-screen 111679f95ce3e660d267831067e514ff455156c4381fAdam Powell */ 111779f95ce3e660d267831067e514ff455156c4381fAdam Powell public boolean isDrawerVisible(int drawerGravity) { 111879f95ce3e660d267831067e514ff455156c4381fAdam Powell final View drawerView = findDrawerWithGravity(drawerGravity); 111979f95ce3e660d267831067e514ff455156c4381fAdam Powell if (drawerView != null) { 112079f95ce3e660d267831067e514ff455156c4381fAdam Powell return isDrawerVisible(drawerView); 112179f95ce3e660d267831067e514ff455156c4381fAdam Powell } 112279f95ce3e660d267831067e514ff455156c4381fAdam Powell return false; 112379f95ce3e660d267831067e514ff455156c4381fAdam Powell } 112479f95ce3e660d267831067e514ff455156c4381fAdam Powell 1125ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell private boolean hasPeekingDrawer() { 1126ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell final int childCount = getChildCount(); 1127ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell for (int i = 0; i < childCount; i++) { 1128ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell final LayoutParams lp = (LayoutParams) getChildAt(i).getLayoutParams(); 1129ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell if (lp.isPeeking) { 1130ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell return true; 1131ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell } 1132ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell } 1133ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell return false; 1134ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell } 1135ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell 11361d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell @Override 11371d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell protected ViewGroup.LayoutParams generateDefaultLayoutParams() { 11381d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell return new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); 11391d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 11401d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 11411d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell @Override 11421d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) { 11431d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell return p instanceof LayoutParams 11441d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell ? new LayoutParams((LayoutParams) p) 114500ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell : p instanceof ViewGroup.MarginLayoutParams 114600ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell ? new LayoutParams((MarginLayoutParams) p) 11471d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell : new LayoutParams(p); 11481d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 11491d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 11501d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell @Override 11511d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell protected boolean checkLayoutParams(ViewGroup.LayoutParams p) { 11521d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell return p instanceof LayoutParams && super.checkLayoutParams(p); 11531d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 11541d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 11551d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell @Override 11561d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) { 11571d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell return new LayoutParams(getContext(), attrs); 11581d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 11591d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 1160791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell private boolean hasVisibleDrawer() { 11610492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell return findVisibleDrawer() != null; 11620492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } 11630492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell 11640492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell private View findVisibleDrawer() { 1165791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell final int childCount = getChildCount(); 1166791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell for (int i = 0; i < childCount; i++) { 1167791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell final View child = getChildAt(i); 1168791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell if (isDrawerView(child) && isDrawerVisible(child)) { 11690492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell return child; 1170791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell } 1171791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell } 11720492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell return null; 1173791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell } 1174791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell 1175cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell void cancelChildViewTouch() { 1176cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell // Cancel child touches 1177cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell if (!mChildrenCanceledTouch) { 1178cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell final long now = SystemClock.uptimeMillis(); 1179cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell final MotionEvent cancelEvent = MotionEvent.obtain(now, now, 1180cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0); 1181cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell final int childCount = getChildCount(); 1182cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell for (int i = 0; i < childCount; i++) { 1183cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell getChildAt(i).dispatchTouchEvent(cancelEvent); 1184cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell } 1185cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell cancelEvent.recycle(); 1186cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell mChildrenCanceledTouch = true; 1187cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell } 1188cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell } 1189cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell 1190791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell @Override 1191791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell public boolean onKeyDown(int keyCode, KeyEvent event) { 1192791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell if (keyCode == KeyEvent.KEYCODE_BACK && hasVisibleDrawer()) { 1193791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell KeyEventCompat.startTracking(event); 1194791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell return true; 1195791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell } 1196791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell return super.onKeyDown(keyCode, event); 1197791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell } 1198791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell 1199791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell @Override 1200791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell public boolean onKeyUp(int keyCode, KeyEvent event) { 12010492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell if (keyCode == KeyEvent.KEYCODE_BACK) { 12020492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell final View visibleDrawer = findVisibleDrawer(); 12030492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell if (visibleDrawer != null && getDrawerLockMode(visibleDrawer) == LOCK_MODE_UNLOCKED) { 12040492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell closeDrawers(); 12050492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell } 12060492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell return visibleDrawer != null; 1207791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell } 1208791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell return super.onKeyUp(keyCode, event); 1209791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell } 1210791f31bbba40b8b51694a1b2cdc804f360786ed1Adam Powell 121157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell @Override 121257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell protected void onRestoreInstanceState(Parcelable state) { 121357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell final SavedState ss = (SavedState) state; 121457902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell super.onRestoreInstanceState(ss.getSuperState()); 121557902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell 121657902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell if (ss.openDrawerGravity != Gravity.NO_GRAVITY) { 121757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell final View toOpen = findDrawerWithGravity(ss.openDrawerGravity); 121857902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell if (toOpen != null) { 121957902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell openDrawer(toOpen); 122057902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell } 122157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell } 12228e01d24e718d603974182cd48f648369c07edec1Adam Powell 12238e01d24e718d603974182cd48f648369c07edec1Adam Powell setDrawerLockMode(ss.lockModeLeft, Gravity.LEFT); 12248e01d24e718d603974182cd48f648369c07edec1Adam Powell setDrawerLockMode(ss.lockModeRight, Gravity.RIGHT); 122557902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell } 122657902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell 122757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell @Override 122857902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell protected Parcelable onSaveInstanceState() { 122957902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell final Parcelable superState = super.onSaveInstanceState(); 123057902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell 123157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell final SavedState ss = new SavedState(superState); 123257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell 123357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell final int childCount = getChildCount(); 123457902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell for (int i = 0; i < childCount; i++) { 123557902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell final View child = getChildAt(i); 123657902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell if (!isDrawerView(child)) { 123757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell continue; 123857902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell } 123957902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell 124057902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell final LayoutParams lp = (LayoutParams) child.getLayoutParams(); 124157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell if (lp.knownOpen) { 124257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell ss.openDrawerGravity = lp.gravity; 124357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell // Only one drawer can be open at a time. 124457902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell break; 124557902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell } 124657902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell } 124757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell 12488e01d24e718d603974182cd48f648369c07edec1Adam Powell ss.lockModeLeft = mLockModeLeft; 12498e01d24e718d603974182cd48f648369c07edec1Adam Powell ss.lockModeRight = mLockModeRight; 12508e01d24e718d603974182cd48f648369c07edec1Adam Powell 125157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell return ss; 125257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell } 125357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell 125457902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell /** 125557902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell * State persisted across instances 125657902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell */ 125757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell protected static class SavedState extends BaseSavedState { 125857902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell int openDrawerGravity = Gravity.NO_GRAVITY; 12598e01d24e718d603974182cd48f648369c07edec1Adam Powell int lockModeLeft = LOCK_MODE_UNLOCKED; 12608e01d24e718d603974182cd48f648369c07edec1Adam Powell int lockModeRight = LOCK_MODE_UNLOCKED; 126157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell 126257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell public SavedState(Parcel in) { 126357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell super(in); 126457902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell openDrawerGravity = in.readInt(); 126557902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell } 126657902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell 126757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell public SavedState(Parcelable superState) { 126857902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell super(superState); 126957902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell } 127057902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell 127157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell @Override 127257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell public void writeToParcel(Parcel dest, int flags) { 127357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell super.writeToParcel(dest, flags); 127457902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell dest.writeInt(openDrawerGravity); 127557902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell } 127657902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell 127757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell public static final Parcelable.Creator<SavedState> CREATOR = 127857902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell new Parcelable.Creator<SavedState>() { 127957902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell @Override 128057902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell public SavedState createFromParcel(Parcel source) { 128157902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell return new SavedState(source); 128257902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell } 128357902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell 128457902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell @Override 128557902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell public SavedState[] newArray(int size) { 128657902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell return new SavedState[size]; 128757902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell } 128857902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell }; 128957902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell } 129057902cff6c54c245feea589b06d12dba8f1a2a24Adam Powell 12911d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell private class ViewDragCallback extends ViewDragHelper.Callback { 12921d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell private final int mGravity; 12931d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell private ViewDragHelper mDragger; 12941d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 12951732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell private final Runnable mPeekRunnable = new Runnable() { 12961732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell @Override public void run() { 12971732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell peekDrawer(); 12981732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell } 12991732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell }; 13001732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell 13011d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public ViewDragCallback(int gravity) { 13021d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mGravity = gravity; 13031d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 13041d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 13051d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public void setDragger(ViewDragHelper dragger) { 13061d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mDragger = dragger; 13071d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 13081d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 13091732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell public void removeCallbacks() { 13101732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell DrawerLayout.this.removeCallbacks(mPeekRunnable); 13111732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell } 13121732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell 13131d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell @Override 13141d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public boolean tryCaptureView(View child, int pointerId) { 13151d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell // Only capture views where the gravity matches what we're looking for. 13161d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell // This lets us use two ViewDragHelpers, one for each side drawer. 13170492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell return isDrawerView(child) && checkDrawerViewGravity(child, mGravity) && 13180492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell getDrawerLockMode(child) == LOCK_MODE_UNLOCKED; 13191d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 13201d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 13211d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell @Override 13221d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public void onViewDragStateChanged(int state) { 1323b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell updateDrawerState(mGravity, state, mDragger.getCapturedView()); 13241d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 13251d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 13261d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell @Override 13271d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) { 13281d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell float offset; 13291d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int childWidth = changedView.getWidth(); 13301d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 13311d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell // This reverses the positioning shown in onLayout. 13321d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (checkDrawerViewGravity(changedView, Gravity.LEFT)) { 13331d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell offset = (float) (childWidth + left) / childWidth; 13341d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } else { 13351d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int width = getWidth(); 13361d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell offset = (float) (width - left) / childWidth; 13371d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 13381d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell setDrawerViewOffset(changedView, offset); 1339b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell changedView.setVisibility(offset == 0 ? INVISIBLE : VISIBLE); 13401d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell invalidate(); 13411d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 13421d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 13431d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell @Override 13441d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public void onViewCaptured(View capturedChild, int activePointerId) { 13451d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final LayoutParams lp = (LayoutParams) capturedChild.getLayoutParams(); 13461d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell lp.isPeeking = false; 13471d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 13481d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell closeOtherDrawer(); 13491d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 13501d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 13511d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell private void closeOtherDrawer() { 13521d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int otherGrav = mGravity == Gravity.LEFT ? Gravity.RIGHT : Gravity.LEFT; 13531d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final View toClose = findDrawerWithGravity(otherGrav); 13541d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (toClose != null) { 13551d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell closeDrawer(toClose); 13561d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 13571d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 13581d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 13591d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell @Override 13601d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public void onViewReleased(View releasedChild, float xvel, float yvel) { 13611d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell // Offset is how open the drawer is, therefore left/right values 13621d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell // are reversed from one another. 13631d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final float offset = getDrawerViewOffset(releasedChild); 13641d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int childWidth = releasedChild.getWidth(); 13651d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 13661d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell int left; 13671d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (checkDrawerViewGravity(releasedChild, Gravity.LEFT)) { 13681d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell left = xvel > 0 || xvel == 0 && offset > 0.5f ? 0 : -childWidth; 13691d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } else { 13701d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int width = getWidth(); 13711d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell left = xvel < 0 || xvel == 0 && offset < 0.5f ? width - childWidth : width; 13721d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 13731d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 13741d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mDragger.settleCapturedViewAt(left, releasedChild.getTop()); 13751d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell invalidate(); 13761d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 13771d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 13781d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell @Override 13791d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public void onEdgeTouched(int edgeFlags, int pointerId) { 13801732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell postDelayed(mPeekRunnable, PEEK_DELAY); 13811732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell } 13821732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell 13831732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell private void peekDrawer() { 13841d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final View toCapture; 13851d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int childLeft; 1386ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell final int peekDistance = mDragger.getEdgeSize(); 13871732720ad57fe6d01392cd06551f1a25cff0333cAdam Powell final boolean leftEdge = mGravity == Gravity.LEFT; 1388b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell if (leftEdge) { 13891d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell toCapture = findDrawerWithGravity(Gravity.LEFT); 1390ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell childLeft = (toCapture != null ? -toCapture.getWidth() : 0) + peekDistance; 13911d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } else { 13921d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell toCapture = findDrawerWithGravity(Gravity.RIGHT); 1393ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell childLeft = getWidth() - peekDistance; 13941d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 13950492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell // Only peek if it would mean making the drawer more visible and the drawer isn't locked 1396b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell if (toCapture != null && ((leftEdge && toCapture.getLeft() < childLeft) || 13970492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell (!leftEdge && toCapture.getLeft() > childLeft)) && 13980492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell getDrawerLockMode(toCapture) == LOCK_MODE_UNLOCKED) { 1399b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell final LayoutParams lp = (LayoutParams) toCapture.getLayoutParams(); 14001d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mDragger.smoothSlideViewTo(toCapture, childLeft, toCapture.getTop()); 1401b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell lp.isPeeking = true; 14021d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell invalidate(); 14031d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 14041d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell closeOtherDrawer(); 1405cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell 1406cde2707260e8241ffb816a03cbf5d52c28004b8aAdam Powell cancelChildViewTouch(); 14071d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 14081d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 14091d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 14101d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell @Override 1411ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell public boolean onEdgeLock(int edgeFlags) { 1412ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell if (ALLOW_EDGE_LOCK) { 1413ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell final View drawer = findDrawerWithGravity(mGravity); 1414ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell if (drawer != null && !isDrawerOpen(drawer)) { 1415ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell closeDrawer(drawer); 1416ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell } 1417ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell return true; 1418acc82321ad119706485db342eaa12b225fa9b667Adam Powell } 1419ea7b10f4d5531713506e98c8093e7aab811f21f3Adam Powell return false; 1420acc82321ad119706485db342eaa12b225fa9b667Adam Powell } 1421acc82321ad119706485db342eaa12b225fa9b667Adam Powell 1422acc82321ad119706485db342eaa12b225fa9b667Adam Powell @Override 14231d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public void onEdgeDragStarted(int edgeFlags, int pointerId) { 14241d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final View toCapture; 14251d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if ((edgeFlags & ViewDragHelper.EDGE_LEFT) == ViewDragHelper.EDGE_LEFT) { 14261d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell toCapture = findDrawerWithGravity(Gravity.LEFT); 14271d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } else { 14281d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell toCapture = findDrawerWithGravity(Gravity.RIGHT); 14291d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 14301d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 14310492ea23e32dbf509a7613d29e5791fdd44b2135Adam Powell if (toCapture != null && getDrawerLockMode(toCapture) == LOCK_MODE_UNLOCKED) { 14321d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell mDragger.captureChildView(toCapture, pointerId); 14331d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 14341d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 14351d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 14361d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell @Override 14371d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public int getViewHorizontalDragRange(View child) { 14381d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell return child.getWidth(); 14391d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 14401d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 14411d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell @Override 14421d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public int clampViewPositionHorizontal(View child, int left, int dx) { 14431d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell if (checkDrawerViewGravity(child, Gravity.LEFT)) { 14441d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell return Math.max(-child.getWidth(), Math.min(left, 0)); 14451d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } else { 14461d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final int width = getWidth(); 14471d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell return Math.max(width - child.getWidth(), Math.min(left, width)); 14481d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 14491d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 145000ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell 145100ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell @Override 145200ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell public int clampViewPositionVertical(View child, int top, int dy) { 145300ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell return child.getTop(); 145400ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell } 14551d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 14561d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 145700ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell public static class LayoutParams extends ViewGroup.MarginLayoutParams { 14581d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 14591d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public int gravity = Gravity.NO_GRAVITY; 1460b562d856f6ff58b7fc421a3b0cd1e0e089b994abAdam Powell float onScreen; 14611d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell boolean isPeeking; 14621d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell boolean knownOpen; 14631d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 14641d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public LayoutParams(Context c, AttributeSet attrs) { 14651d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell super(c, attrs); 14661d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 14671d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell final TypedArray a = c.obtainStyledAttributes(attrs, LAYOUT_ATTRS); 14681d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell this.gravity = a.getInt(0, Gravity.NO_GRAVITY); 14691d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell a.recycle(); 14701d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 14711d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 14721d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public LayoutParams(int width, int height) { 14731d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell super(width, height); 14741d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 14751d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 14761d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public LayoutParams(int width, int height, int gravity) { 14771d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell this(width, height); 14781d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell this.gravity = gravity; 14791d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 14801d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 14811d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public LayoutParams(LayoutParams source) { 14821d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell super(source); 14831d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell this.gravity = source.gravity; 14841d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 14851d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell 14861d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell public LayoutParams(ViewGroup.LayoutParams source) { 14871d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell super(source); 14881d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 148900ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell 149000ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell public LayoutParams(ViewGroup.MarginLayoutParams source) { 149100ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell super(source); 149200ca2532981fbd705f947a637ffd967a8d6f733bAdam Powell } 14931d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell } 14947d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell 14957d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell class AccessibilityDelegate extends AccessibilityDelegateCompat { 14963cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell private final Rect mTmpRect = new Rect(); 14973cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell 14987d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell @Override 14997d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { 15003cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell final AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info); 15013cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell super.onInitializeAccessibilityNodeInfo(host, superNode); 15023cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell 15033cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell info.setSource(host); 15043cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell final ViewParent parent = ViewCompat.getParentForAccessibility(host); 15053cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell if (parent instanceof View) { 15063cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell info.setParent((View) parent); 15073cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell } 15083cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell copyNodeInfoNoChildren(info, superNode); 15093cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell 15103cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell superNode.recycle(); 15113cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell 15127d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell final int childCount = getChildCount(); 15137d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell for (int i = 0; i < childCount; i++) { 15147d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell final View child = getChildAt(i); 15157d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell if (!filter(child)) { 15167d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell info.addChild(child); 15177d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell } 15187d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell } 15197d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell } 15207d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell 15217d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell @Override 15227d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, 15237d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell AccessibilityEvent event) { 15247d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell if (!filter(child)) { 15257d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell return super.onRequestSendAccessibilityEvent(host, child, event); 15267d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell } 15277d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell return false; 15287d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell } 15297d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell 15307d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell public boolean filter(View child) { 15317d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell final View openDrawer = findOpenDrawer(); 15327d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell return openDrawer != null && openDrawer != child; 15337d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell } 15343cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell 15353cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell /** 15363cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell * This should really be in AccessibilityNodeInfoCompat, but there unfortunately 15373cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell * seem to be a few elements that are not easily cloneable using the underlying API. 15383cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell * Leave it private here as it's not general-purpose useful. 15393cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell */ 15403cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell private void copyNodeInfoNoChildren(AccessibilityNodeInfoCompat dest, 15413cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell AccessibilityNodeInfoCompat src) { 15423cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell final Rect rect = mTmpRect; 15433cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell 15443cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell src.getBoundsInParent(rect); 15453cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell dest.setBoundsInParent(rect); 15463cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell 15473cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell src.getBoundsInScreen(rect); 15483cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell dest.setBoundsInScreen(rect); 15493cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell 15503cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell dest.setVisibleToUser(src.isVisibleToUser()); 15513cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell dest.setPackageName(src.getPackageName()); 15523cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell dest.setClassName(src.getClassName()); 15533cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell dest.setContentDescription(src.getContentDescription()); 15543cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell 15553cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell dest.setEnabled(src.isEnabled()); 15563cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell dest.setClickable(src.isClickable()); 15573cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell dest.setFocusable(src.isFocusable()); 15583cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell dest.setFocused(src.isFocused()); 15593cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell dest.setAccessibilityFocused(src.isAccessibilityFocused()); 15603cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell dest.setSelected(src.isSelected()); 15613cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell dest.setLongClickable(src.isLongClickable()); 15623cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell 15633cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell dest.addAction(src.getActions()); 15643cf6141d516a0a6170823b1bda5c0b6d7500e76cAdam Powell } 15657d0061d5605a1ac298837bee21c0d4eb4a34bd4eAdam Powell } 15661d26501f0c8e9f3577f651938a03f6b3a1a672c7Adam Powell} 1567