Skip to content

Commit

Permalink
Add property which allows header view to handle touch events.
Browse files Browse the repository at this point in the history
  • Loading branch information
DeRon Brown committed Jun 26, 2014
1 parent e7141ee commit 9439d5a
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public abstract class FadingActionBarHelperBase {
private boolean mFirstGlobalLayoutPerformed;
private FrameLayout mMarginView;
private View mListViewBackgroundView;
private boolean mAllowHeaderTouchEvents = false;

public final <T extends FadingActionBarHelperBase> T actionBarBackground(int drawableResId) {
mActionBarBackgroundResId = drawableResId;
Expand Down Expand Up @@ -110,6 +111,11 @@ public final <T extends FadingActionBarHelperBase> T parallax(boolean value) {
return (T)this;
}

public final <T extends FadingActionBarHelperBase> T allowHeaderTouchEvents(boolean value) {
mAllowHeaderTouchEvents = value;
return (T)this;
}

public final View createView(Context context) {
return createView(LayoutInflater.from(context));
}
Expand Down Expand Up @@ -232,6 +238,10 @@ private View createWebView() {
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
webView.addView(mMarginView);

if (mAllowHeaderTouchEvents) {
setMarginViewTouchListener();
}

return webViewContainer;
}

Expand All @@ -251,6 +261,10 @@ private View createScrollView() {
mHeaderContainer.addView(mHeaderView, 0);
mMarginView = (FrameLayout) contentContainer.findViewById(R.id.fab__content_top_margin);

if (mAllowHeaderTouchEvents) {
setMarginViewTouchListener();
}

return scrollViewContainer;
}

Expand Down Expand Up @@ -279,6 +293,11 @@ private View createListView(ListView listView) {
mListViewBackgroundView.setLayoutParams(params);

listView.setOnScrollListener(mOnScrollListener);

if (mAllowHeaderTouchEvents) {
setMarginViewTouchListener();
}

return contentContainer;
}

Expand Down Expand Up @@ -356,4 +375,13 @@ private void initializeGradient(ViewGroup headerContainer) {
}
gradientView.setBackgroundResource(gradient);
}

private void setMarginViewTouchListener() {
mMarginView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return mHeaderView.dispatchTouchEvent(event);
}
});
}
}

0 comments on commit 9439d5a

Please sign in to comment.