Skip to content

Commit debf326

Browse files
committed
Added experimental support for nested layout or touch focusable view ripples #12 #26
1 parent 0483d16 commit debf326

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

library/src/main/java/com/balysv/materialripple/MaterialRippleLayout.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public void setOnClickListener(OnClickListener onClickListener) {
175175

176176
@Override
177177
public boolean onInterceptTouchEvent(MotionEvent event) {
178-
return true;
178+
return !findClickableViewInChild(childView, (int) event.getX(), (int) event.getY());
179179
}
180180

181181
@Override
@@ -426,6 +426,26 @@ private boolean adapterPositionChanged() {
426426
return false;
427427
}
428428

429+
private boolean findClickableViewInChild(View view, int x, int y) {
430+
if (view instanceof ViewGroup) {
431+
ViewGroup viewGroup = (ViewGroup) view;
432+
for (int i = 0; i < viewGroup.getChildCount(); i++) {
433+
View child = viewGroup.getChildAt(i);
434+
final Rect rect = new Rect();
435+
child.getHitRect(rect);
436+
437+
final boolean contains = rect.contains(x, y);
438+
if (contains) {
439+
return findClickableViewInChild(child, x - rect.left, y - rect.top);
440+
}
441+
}
442+
} else if (view != childView) {
443+
return (view.isEnabled() && (view.isClickable() || view.isLongClickable() || view.isFocusableInTouchMode()));
444+
}
445+
446+
return view.isFocusableInTouchMode();
447+
}
448+
429449
@Override
430450
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
431451
super.onSizeChanged(w, h, oldw, oldh);

0 commit comments

Comments
 (0)