Skip to content

Commit

Permalink
Refactor: extract method to check it has any callbacks.
Browse files Browse the repository at this point in the history
  • Loading branch information
ksoichiro committed Nov 29, 2015
1 parent 4ed0f72 commit dd3097f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public Parcelable onSaveInstanceState() {

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (mCallbacks != null || mCallbackCollection != null) {
if (hasCallbacks()) {
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
// Whether or not motion events are consumed by children,
Expand All @@ -147,7 +147,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {

@Override
public boolean onTouchEvent(MotionEvent ev) {
if (mCallbacks != null || mCallbackCollection != null) {
if (hasCallbacks()) {
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
Expand Down Expand Up @@ -408,7 +408,7 @@ private int getNumColumnsCompat() {
}

private void onScrollChanged() {
if (mCallbacks != null || mCallbackCollection != null) {
if (hasCallbacks()) {
if (getChildCount() > 0) {
int firstVisiblePosition = getFirstVisiblePosition();
for (int i = getFirstVisiblePosition(), j = 0; i <= getLastVisiblePosition(); i++, j++) {
Expand Down Expand Up @@ -484,6 +484,10 @@ private void removeFixedViewInfo(View v, ArrayList<FixedViewInfo> where) {
}
}

private boolean hasCallbacks() {
return mCallbacks != null || mCallbackCollection != null;
}

private class FullWidthFixedViewLayout extends FrameLayout {
public FullWidthFixedViewLayout(Context context) {
super(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public Parcelable onSaveInstanceState() {

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (mCallbacks != null || mCallbackCollection != null) {
if (hasCallbacks()) {
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
// Whether or not motion events are consumed by children,
Expand All @@ -135,7 +135,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {

@Override
public boolean onTouchEvent(MotionEvent ev) {
if (mCallbacks != null || mCallbackCollection != null) {
if (hasCallbacks()) {
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
Expand Down Expand Up @@ -270,7 +270,7 @@ private void init() {
}

private void onScrollChanged() {
if (mCallbacks != null || mCallbackCollection != null) {
if (hasCallbacks()) {
if (getChildCount() > 0) {
int firstVisiblePosition = getFirstVisiblePosition();
for (int i = getFirstVisiblePosition(), j = 0; i <= getLastVisiblePosition(); i++, j++) {
Expand Down Expand Up @@ -380,6 +380,10 @@ private void dispatchOnUpOrCancelMotionEvent(ScrollState scrollState) {
}
}

private boolean hasCallbacks() {
return mCallbacks != null || mCallbackCollection != null;
}

static class SavedState extends BaseSavedState {
int prevFirstVisiblePosition;
int prevFirstVisibleChildHeight = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public Parcelable onSaveInstanceState() {
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (mCallbacks != null || mCallbackCollection != null) {
if (hasCallbacks()) {
if (getChildCount() > 0) {
int firstVisiblePosition = getChildAdapterPosition(getChildAt(0));
int lastVisiblePosition = getChildAdapterPosition(getChildAt(getChildCount() - 1));
Expand Down Expand Up @@ -183,7 +183,7 @@ protected void onScrollChanged(int l, int t, int oldl, int oldt) {

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (mCallbacks != null || mCallbackCollection != null) {
if (hasCallbacks()) {
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
// Whether or not motion events are consumed by children,
Expand All @@ -202,7 +202,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {

@Override
public boolean onTouchEvent(MotionEvent ev) {
if (mCallbacks != null || mCallbackCollection != null) {
if (hasCallbacks()) {
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
Expand Down Expand Up @@ -399,6 +399,10 @@ private void dispatchOnUpOrCancelMotionEvent(ScrollState scrollState) {
}
}

private boolean hasCallbacks() {
return mCallbacks != null || mCallbackCollection != null;
}

/**
* This saved state class is a Parcelable and should not extend
* {@link android.view.View.BaseSavedState} nor {@link android.view.AbsSavedState}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public Parcelable onSaveInstanceState() {
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (mCallbacks != null || mCallbackCollection != null) {
if (hasCallbacks()) {
mScrollY = t;

dispatchOnScrollChanged(t, mFirstScroll, mDragging);
Expand All @@ -104,7 +104,7 @@ protected void onScrollChanged(int l, int t, int oldl, int oldt) {

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (mCallbacks != null || mCallbackCollection != null) {
if (hasCallbacks()) {
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
// Whether or not motion events are consumed by children,
Expand All @@ -123,7 +123,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {

@Override
public boolean onTouchEvent(MotionEvent ev) {
if (mCallbacks != null || mCallbackCollection != null) {
if (hasCallbacks()) {
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
Expand Down Expand Up @@ -271,6 +271,10 @@ private void dispatchOnUpOrCancelMotionEvent(ScrollState scrollState) {
}
}

private boolean hasCallbacks() {
return mCallbacks != null || mCallbackCollection != null;
}

static class SavedState extends BaseSavedState {
int prevScrollY;
int scrollY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public Parcelable onSaveInstanceState() {
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (mCallbacks != null || mCallbackCollection != null) {
if (hasCallbacks()) {
mScrollY = t;

dispatchOnScrollChanged(mScrollY, mFirstScroll, mDragging);
Expand All @@ -100,7 +100,7 @@ protected void onScrollChanged(int l, int t, int oldl, int oldt) {

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (mCallbacks != null || mCallbackCollection != null) {
if (hasCallbacks()) {
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
// Whether or not motion events are consumed by children,
Expand All @@ -119,7 +119,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {

@Override
public boolean onTouchEvent(MotionEvent ev) {
if (mCallbacks != null || mCallbackCollection != null) {
if (hasCallbacks()) {
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
break;
Expand Down Expand Up @@ -269,6 +269,10 @@ private void dispatchOnUpOrCancelMotionEvent(ScrollState scrollState) {
}
}

private boolean hasCallbacks() {
return mCallbacks != null || mCallbackCollection != null;
}

static class SavedState extends BaseSavedState {
int prevScrollY;
int scrollY;
Expand Down

0 comments on commit dd3097f

Please sign in to comment.