88import android .graphics .PixelFormat ;
99import android .graphics .Rect ;
1010import android .graphics .drawable .Drawable ;
11- import android .os .Build ;
1211import android .os .Bundle ;
13- import android .os .Parcel ;
1412import android .os .Parcelable ;
15- import android .support .annotation .NonNull ;
16- import android .support .v4 .app .BundleCompat ;
1713import android .support .v4 .view .MotionEventCompat ;
1814import android .support .v4 .view .ViewCompat ;
1915import android .util .AttributeSet ;
@@ -216,7 +212,7 @@ public enum PanelState {
216212 private float mInitialMotionY ;
217213 private boolean mIsScrollableViewHandlingTouch = false ;
218214
219- private List <PanelSlideListener > mPanelSlideListeners = new CopyOnWriteArrayList <>();
215+ private final List <PanelSlideListener > mPanelSlideListeners = new CopyOnWriteArrayList <>();
220216 private View .OnClickListener mFadeOnClickListener ;
221217
222218 private final ViewDragHelper mDragHelper ;
@@ -288,9 +284,9 @@ public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) {
288284 if (defAttrs != null ) {
289285 int gravity = defAttrs .getInt (0 , Gravity .NO_GRAVITY );
290286 setGravity (gravity );
287+ defAttrs .recycle ();
291288 }
292289
293- defAttrs .recycle ();
294290
295291 TypedArray ta = context .obtainStyledAttributes (attrs , R .styleable .SlidingUpPanelLayout );
296292
@@ -316,9 +312,8 @@ public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) {
316312 if (interpolatorResId != -1 ) {
317313 scrollerInterpolator = AnimationUtils .loadInterpolator (context , interpolatorResId );
318314 }
315+ ta .recycle ();
319316 }
320-
321- ta .recycle ();
322317 }
323318
324319 final float density = context .getResources ().getDisplayMetrics ().density ;
@@ -520,6 +515,7 @@ public void removePanelSlideListener(PanelSlideListener listener) {
520515 * Provides an on click for the portion of the main view that is dimmed. The listener is not
521516 * triggered if the panel is in a collapsed or a hidden position. If the on click listener is
522517 * not provided, the clicks on the dimmed area are passed through to the main layout.
518+ *
523519 * @param listener
524520 */
525521 public void setFadeOnClickListener (View .OnClickListener listener ) {
@@ -581,6 +577,7 @@ public void setScrollableView(View scrollableView) {
581577
582578 /**
583579 * Sets the current scrollable view helper. See ScrollableViewHelper description for details.
580+ *
584581 * @param helper
585582 */
586583 public void setScrollableViewHelper (ScrollableViewHelper helper ) {
@@ -1325,7 +1322,7 @@ public Parcelable onSaveInstanceState() {
13251322
13261323 @ Override
13271324 public void onRestoreInstanceState (Parcelable state ) {
1328- if (state instanceof Bundle ) {
1325+ if (state instanceof Bundle ) {
13291326 Bundle bundle = (Bundle ) state ;
13301327 mSlideState = (PanelState ) bundle .getSerializable (SLIDING_STATE );
13311328 mSlideState = mSlideState == null ? DEFAULT_SLIDE_STATE : mSlideState ;
@@ -1338,16 +1335,13 @@ private class DragHelperCallback extends ViewDragHelper.Callback {
13381335
13391336 @ Override
13401337 public boolean tryCaptureView (View child , int pointerId ) {
1341- if (mIsUnableToDrag ) {
1342- return false ;
1343- }
1338+ return !mIsUnableToDrag && child == mSlideableView ;
13441339
1345- return child == mSlideableView ;
13461340 }
13471341
13481342 @ Override
13491343 public void onViewDragStateChanged (int state ) {
1350- if (mDragHelper .getViewDragState () == ViewDragHelper .STATE_IDLE ) {
1344+ if (mDragHelper != null && mDragHelper .getViewDragState () == ViewDragHelper .STATE_IDLE ) {
13511345 mSlideOffset = computeSlideOffset (mSlideableView .getTop ());
13521346 applyParallaxForCurrentSlideOffset ();
13531347
@@ -1407,7 +1401,9 @@ public void onViewReleased(View releasedChild, float xvel, float yvel) {
14071401 target = computePanelTopPosition (0.0f );
14081402 }
14091403
1410- mDragHelper .settleCapturedViewAt (releasedChild .getLeft (), target );
1404+ if (mDragHelper != null ) {
1405+ mDragHelper .settleCapturedViewAt (releasedChild .getLeft (), target );
1406+ }
14111407 invalidate ();
14121408 }
14131409
@@ -1466,9 +1462,10 @@ public LayoutParams(Context c, AttributeSet attrs) {
14661462 final TypedArray ta = c .obtainStyledAttributes (attrs , ATTRS );
14671463 if (ta != null ) {
14681464 this .weight = ta .getFloat (0 , 0 );
1465+ ta .recycle ();
14691466 }
14701467
1471- ta . recycle ();
1468+
14721469 }
14731470 }
14741471}
0 commit comments