8
8
import android .graphics .PixelFormat ;
9
9
import android .graphics .Rect ;
10
10
import android .graphics .drawable .Drawable ;
11
- import android .os .Build ;
12
11
import android .os .Bundle ;
13
- import android .os .Parcel ;
14
12
import android .os .Parcelable ;
15
- import android .support .annotation .NonNull ;
16
- import android .support .v4 .app .BundleCompat ;
17
13
import android .support .v4 .view .MotionEventCompat ;
18
14
import android .support .v4 .view .ViewCompat ;
19
15
import android .util .AttributeSet ;
@@ -216,7 +212,7 @@ public enum PanelState {
216
212
private float mInitialMotionY ;
217
213
private boolean mIsScrollableViewHandlingTouch = false ;
218
214
219
- private List <PanelSlideListener > mPanelSlideListeners = new CopyOnWriteArrayList <>();
215
+ private final List <PanelSlideListener > mPanelSlideListeners = new CopyOnWriteArrayList <>();
220
216
private View .OnClickListener mFadeOnClickListener ;
221
217
222
218
private final ViewDragHelper mDragHelper ;
@@ -288,9 +284,9 @@ public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) {
288
284
if (defAttrs != null ) {
289
285
int gravity = defAttrs .getInt (0 , Gravity .NO_GRAVITY );
290
286
setGravity (gravity );
287
+ defAttrs .recycle ();
291
288
}
292
289
293
- defAttrs .recycle ();
294
290
295
291
TypedArray ta = context .obtainStyledAttributes (attrs , R .styleable .SlidingUpPanelLayout );
296
292
@@ -316,9 +312,8 @@ public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) {
316
312
if (interpolatorResId != -1 ) {
317
313
scrollerInterpolator = AnimationUtils .loadInterpolator (context , interpolatorResId );
318
314
}
315
+ ta .recycle ();
319
316
}
320
-
321
- ta .recycle ();
322
317
}
323
318
324
319
final float density = context .getResources ().getDisplayMetrics ().density ;
@@ -520,6 +515,7 @@ public void removePanelSlideListener(PanelSlideListener listener) {
520
515
* Provides an on click for the portion of the main view that is dimmed. The listener is not
521
516
* triggered if the panel is in a collapsed or a hidden position. If the on click listener is
522
517
* not provided, the clicks on the dimmed area are passed through to the main layout.
518
+ *
523
519
* @param listener
524
520
*/
525
521
public void setFadeOnClickListener (View .OnClickListener listener ) {
@@ -581,6 +577,7 @@ public void setScrollableView(View scrollableView) {
581
577
582
578
/**
583
579
* Sets the current scrollable view helper. See ScrollableViewHelper description for details.
580
+ *
584
581
* @param helper
585
582
*/
586
583
public void setScrollableViewHelper (ScrollableViewHelper helper ) {
@@ -1325,7 +1322,7 @@ public Parcelable onSaveInstanceState() {
1325
1322
1326
1323
@ Override
1327
1324
public void onRestoreInstanceState (Parcelable state ) {
1328
- if (state instanceof Bundle ) {
1325
+ if (state instanceof Bundle ) {
1329
1326
Bundle bundle = (Bundle ) state ;
1330
1327
mSlideState = (PanelState ) bundle .getSerializable (SLIDING_STATE );
1331
1328
mSlideState = mSlideState == null ? DEFAULT_SLIDE_STATE : mSlideState ;
@@ -1338,16 +1335,13 @@ private class DragHelperCallback extends ViewDragHelper.Callback {
1338
1335
1339
1336
@ Override
1340
1337
public boolean tryCaptureView (View child , int pointerId ) {
1341
- if (mIsUnableToDrag ) {
1342
- return false ;
1343
- }
1338
+ return !mIsUnableToDrag && child == mSlideableView ;
1344
1339
1345
- return child == mSlideableView ;
1346
1340
}
1347
1341
1348
1342
@ Override
1349
1343
public void onViewDragStateChanged (int state ) {
1350
- if (mDragHelper .getViewDragState () == ViewDragHelper .STATE_IDLE ) {
1344
+ if (mDragHelper != null && mDragHelper .getViewDragState () == ViewDragHelper .STATE_IDLE ) {
1351
1345
mSlideOffset = computeSlideOffset (mSlideableView .getTop ());
1352
1346
applyParallaxForCurrentSlideOffset ();
1353
1347
@@ -1407,7 +1401,9 @@ public void onViewReleased(View releasedChild, float xvel, float yvel) {
1407
1401
target = computePanelTopPosition (0.0f );
1408
1402
}
1409
1403
1410
- mDragHelper .settleCapturedViewAt (releasedChild .getLeft (), target );
1404
+ if (mDragHelper != null ) {
1405
+ mDragHelper .settleCapturedViewAt (releasedChild .getLeft (), target );
1406
+ }
1411
1407
invalidate ();
1412
1408
}
1413
1409
@@ -1466,9 +1462,10 @@ public LayoutParams(Context c, AttributeSet attrs) {
1466
1462
final TypedArray ta = c .obtainStyledAttributes (attrs , ATTRS );
1467
1463
if (ta != null ) {
1468
1464
this .weight = ta .getFloat (0 , 0 );
1465
+ ta .recycle ();
1469
1466
}
1470
1467
1471
- ta . recycle ();
1468
+
1472
1469
}
1473
1470
}
1474
1471
}
0 commit comments