Skip to content

Commit 3f7b9e3

Browse files
author
Marco Salis
committed
Adapter null check on every access in onTouchEvent()
A previous pull request performed a null check only in one of the three accesses to the instance variable 'mAdapter' in the onTouchEvent() method, which can be null when a touch event occurs.
1 parent 53dea18 commit 3f7b9e3

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/com/origamilabs/library/views/StaggeredGridView.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,8 @@ public boolean onTouchEvent(MotionEvent ev) {
457457
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
458458
mTouchRemainderY = 0;
459459

460-
if(mTouchMode != TOUCH_MODE_FLINGING && !mDataChanged && motionPosition >= 0 && getAdapter().isEnabled(motionPosition)){
460+
if(mTouchMode != TOUCH_MODE_FLINGING && !mDataChanged && motionPosition >= 0
461+
&& mAdapter != null && mAdapter.isEnabled(motionPosition)) {
461462
mTouchMode = TOUCH_MODE_DOWN;
462463

463464
mBeginClick = true;
@@ -576,7 +577,7 @@ public boolean onTouchEvent(MotionEvent ev) {
576577
mPendingCheckForTap : mPendingCheckForLongPress);
577578
}
578579

579-
if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
580+
if (!mDataChanged && mAdapter != null && mAdapter.isEnabled(motionPosition)) {
580581
mTouchMode = TOUCH_MODE_TAP;
581582

582583
layoutChildren(mDataChanged);
@@ -609,7 +610,7 @@ public void run() {
609610
mTouchMode = TOUCH_MODE_REST;
610611
}
611612
return true;
612-
} else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
613+
} else if (!mDataChanged && mAdapter != null && mAdapter.isEnabled(motionPosition)) {
613614
performClick.run();
614615
}
615616
}

0 commit comments

Comments
 (0)