From 951523137919e7eb45d3467ee5996827f2225bf8 Mon Sep 17 00:00:00 2001 From: Shai Slobodov Date: Sun, 15 Jul 2018 16:55:41 +0300 Subject: [PATCH] Added support for the background of the slideview to be clickable #833 #832 #696 --- .../slidinguppanel/SlidingUpPanelLayout.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/library/src/main/java/com/sothree/slidinguppanel/SlidingUpPanelLayout.java b/library/src/main/java/com/sothree/slidinguppanel/SlidingUpPanelLayout.java index 424a008c..3dcb1286 100644 --- a/library/src/main/java/com/sothree/slidinguppanel/SlidingUpPanelLayout.java +++ b/library/src/main/java/com/sothree/slidinguppanel/SlidingUpPanelLayout.java @@ -208,6 +208,8 @@ public enum PanelState { */ private boolean mIsTouchEnabled; + private OnBackgroundClick mBackgroundListener; + private float mPrevMotionX; private float mPrevMotionY; private float mInitialMotionX; @@ -966,6 +968,14 @@ public boolean dispatchTouchEvent(MotionEvent ev) { final float x = ev.getX(); final float y = ev.getY(); + if (!isViewUnder(mSlideableView, (int)x, (int)y)) { + if (mBackgroundListener != null) { + mBackgroundListener.onClick(); + } + + return false; + } + if (action == MotionEvent.ACTION_DOWN) { mIsScrollableViewHandlingTouch = false; mPrevMotionX = x; @@ -1144,6 +1154,10 @@ private void setPanelStateInternal(PanelState state) { dispatchOnPanelStateChanged(this, oldState, state); } + public void setOnBackgroundClicked(OnBackgroundClick listener) { + mBackgroundListener = listener; + } + /** * Update the parallax based on the current slide offset. */ @@ -1487,4 +1501,8 @@ public LayoutParams(Context c, AttributeSet attrs) { } } + + public interface OnBackgroundClick { + void onClick(); + } }