From debf326398fed25ca35903583df77c502be00d54 Mon Sep 17 00:00:00 2001 From: Balys Valentukevicius Date: Sat, 31 Jan 2015 17:49:44 +0000 Subject: [PATCH] Added experimental support for nested layout or touch focusable view ripples #12 #26 --- .../materialripple/MaterialRippleLayout.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/com/balysv/materialripple/MaterialRippleLayout.java b/library/src/main/java/com/balysv/materialripple/MaterialRippleLayout.java index bee4181..7cafd9e 100644 --- a/library/src/main/java/com/balysv/materialripple/MaterialRippleLayout.java +++ b/library/src/main/java/com/balysv/materialripple/MaterialRippleLayout.java @@ -175,7 +175,7 @@ public void setOnClickListener(OnClickListener onClickListener) { @Override public boolean onInterceptTouchEvent(MotionEvent event) { - return true; + return !findClickableViewInChild(childView, (int) event.getX(), (int) event.getY()); } @Override @@ -426,6 +426,26 @@ private boolean adapterPositionChanged() { return false; } + private boolean findClickableViewInChild(View view, int x, int y) { + if (view instanceof ViewGroup) { + ViewGroup viewGroup = (ViewGroup) view; + for (int i = 0; i < viewGroup.getChildCount(); i++) { + View child = viewGroup.getChildAt(i); + final Rect rect = new Rect(); + child.getHitRect(rect); + + final boolean contains = rect.contains(x, y); + if (contains) { + return findClickableViewInChild(child, x - rect.left, y - rect.top); + } + } + } else if (view != childView) { + return (view.isEnabled() && (view.isClickable() || view.isLongClickable() || view.isFocusableInTouchMode())); + } + + return view.isFocusableInTouchMode(); + } + @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh);