@Override public boolean dispatchTouchEvent(MotionEvent event) { int x = (int) event.getRawX(); int y = (int) event.getRawY(); int action = event.getAction(); if (action == MotionEvent.ACTION_DOWN) { View clickedView = getTouchTarget(this, x, y); if (clickedView != null && clickedView.isClickable() && clickedView.isEnabled()) { this.clickedView = clickedView; isClickedParent = false; initParamForRipple(event, clickedView, false); postInvalidateDelayed(INVALIDATE_DURATION); } else { this.clickedView = this; isClickedParent = true; RippleLayout.this.setClickable(true); initParamForRipple(event, clickedView, true); postInvalidateDelayed(INVALIDATE_DURATION); } } else if (action == MotionEvent.ACTION_UP) { isPressed = false; RippleLayout.this.setClickable(false); postInvalidateDelayed(INVALIDATE_DURATION); return true; } else if (action == MotionEvent.ACTION_CANCEL) { isPressed = false; postInvalidateDelayed(INVALIDATE_DURATION); } return super.dispatchTouchEvent(event); }
@Test public void testClickable() { assertFalse(view.isClickable()); view.setClickable(true); assertTrue(view.isClickable()); view.setClickable(false); assertFalse(view.isClickable()); }
@Test public void testClickableWhenLoadedFromXml() { LinearLayout root = new LinearLayout(null); ShadowView.inflate(new Activity(), R.layout.views, root); View defaultView = root.findViewById(R.id.default_view); assertFalse(defaultView.isClickable()); View clickableFalseView = root.findViewById(R.id.clickable_false_view); assertFalse(clickableFalseView.isClickable()); View clickableTrueView = root.findViewById(R.id.clickable_true_view); assertTrue(clickableTrueView.isClickable()); }
private View findViewByCoordinate(ViewGroup viewGroup, float x, float y, int depth) { final int childCount = viewGroup.getChildCount(); for (int i = childCount - 1; i >= 0; i--) { final View child = viewGroup.getChildAt(i); assert child != null; if (child.getVisibility() != View.VISIBLE || !child.isEnabled()) { continue; } if (child instanceof ViewGroup && (depth < mForwardDepth || !mForwardAll)) { View view = findViewByCoordinate( (ViewGroup) child, x - child.getLeft(), y - child.getTop(), depth + 1); if (view != null) { return view; } } if ((child.isClickable() || mForwardAll) && ViewUtils.pointInView(child, x, y, 0)) { return child; } } return null; }
/* * Used just to setup the click listener if applicable. */ private void doSetClickable() { View view = getTouchView(); if (view == null) { return; } doSetClickable(view, view.isClickable()); }
@Override public boolean dispatchTouchEvent(MotionEvent ev) { int x = (int) ev.getX(); int y = (int) ev.getY(); int pos = pointToPosition(x, y); if (mHeaderView != null && y >= mHeaderView.getTop() && y <= mHeaderView.getBottom()) { if (ev.getAction() == MotionEvent.ACTION_DOWN) { mTouchTarget = getTouchTarget(mHeaderView, x, y); mActionDownHappened = true; } else if (ev.getAction() == MotionEvent.ACTION_UP) { View touchTarget = getTouchTarget(mHeaderView, x, y); if (touchTarget == mTouchTarget && mTouchTarget.isClickable()) { mTouchTarget.performClick(); invalidate(new Rect(0, 0, mHeaderWidth, mHeaderHeight)); } else if (mIsHeaderGroupClickable) { int groupPosition = getPackedPositionGroup(getExpandableListPosition(pos)); if (groupPosition != INVALID_POSITION && mActionDownHappened) { if (isGroupExpanded(groupPosition)) { collapseGroup(groupPosition); } else { expandGroup(groupPosition); } } } mActionDownHappened = false; } return true; } return super.dispatchTouchEvent(ev); }
public static boolean isClickable(Object v) { if (!(v instanceof View)) { return true; } View view = (View) v; return view.isClickable(); }
private boolean isTouchPointInView(View view, int x, int y) { if (view.isClickable() && y >= view.getTop() && y <= view.getBottom() && x >= view.getLeft() && x <= view.getRight()) { return true; } return false; }
/* * Captures the back button press to pause the game instead of killing the activity * */ public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (mBackButton.isClickable()) { transitionIntoActivity(null); } return false; } return super.onKeyDown(keyCode, event); }
private boolean isTouchPointInView(View view, int x, int y) { int[] location = new int[2]; view.getLocationOnScreen(location); int left = location[0]; int top = location[1]; int right = left + view.getMeasuredWidth(); int bottom = top + view.getMeasuredHeight(); if (view.isClickable() && y >= top && y <= bottom && x >= left && x <= right) { return true; } 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 public boolean dispatchTouchEvent(MotionEvent event) { /** 触摸点的x,y坐标 */ int x = (int) event.getRawX(); int y = (int) event.getRawY(); mEventX = (int) event.getX(); mEventY = (int) event.getY(); Log.e("TAG", "x:" + x + "Y:" + y + "mEvent" + mEventX + "mEventY" + mEventY); /** 触摸行为是down还是up还是move等其他 */ int action = event.getAction(); /** 是Down的话 */ if (action == MotionEvent.ACTION_DOWN) { // 根据坐标获取到view,可点击并且落点在可点击View内部返回值才不为空,其他都为空 View touchTarget = getTouchTarget(this, x, y); if (touchTarget != null && touchTarget.isClickable() && touchTarget.isEnabled()) { // 将点击子View传给mTouchTarget mTouchTarget = touchTarget; // 初始化子View的参数和水波纹半径 initParametersForChild(event, touchTarget); // 触发dispatchDraw postInvalidateDelayed(INVALIDATE_DURATION); } } else if (action == MotionEvent.ACTION_UP) { // 抬起时候将点击标志位设置为false mIsPressed = false; // 触发dispatchDraw postInvalidateDelayed(INVALIDATE_DURATION); mDispatchUpTouchEventRunnable.event = event; // 后面的参数会影响点是绘制播放时间,设置适量大一点可以实现播放完波纹在执行点击事件 postDelayed(mDispatchUpTouchEventRunnable, 0); return true; } else if (action == MotionEvent.ACTION_CANCEL) { mIsPressed = false; // 触发dispatchDraw postInvalidateDelayed(INVALIDATE_DURATION); } return super.dispatchTouchEvent(event); }
private static String m91a(View view) { char c = 'F'; char c2 = '.'; StringBuilder stringBuilder = new StringBuilder(128); stringBuilder.append(view.getClass().getName()); stringBuilder.append('{'); stringBuilder.append(Integer.toHexString(System.identityHashCode(view))); stringBuilder.append(' '); switch (view.getVisibility()) { case 0: stringBuilder.append('V'); break; case 4: stringBuilder.append('I'); break; case 8: stringBuilder.append('G'); break; default: stringBuilder.append('.'); break; } stringBuilder.append(view.isFocusable() ? 'F' : '.'); stringBuilder.append(view.isEnabled() ? 'E' : '.'); stringBuilder.append(view.willNotDraw() ? '.' : 'D'); stringBuilder.append(view.isHorizontalScrollBarEnabled() ? 'H' : '.'); stringBuilder.append(view.isVerticalScrollBarEnabled() ? 'V' : '.'); stringBuilder.append(view.isClickable() ? 'C' : '.'); stringBuilder.append(view.isLongClickable() ? 'L' : '.'); stringBuilder.append(' '); if (!view.isFocused()) { c = '.'; } stringBuilder.append(c); stringBuilder.append(view.isSelected() ? 'S' : '.'); if (view.isPressed()) { c2 = 'P'; } stringBuilder.append(c2); stringBuilder.append(' '); stringBuilder.append(view.getLeft()); stringBuilder.append(','); stringBuilder.append(view.getTop()); stringBuilder.append('-'); stringBuilder.append(view.getRight()); stringBuilder.append(','); stringBuilder.append(view.getBottom()); int id = view.getId(); if (id != -1) { stringBuilder.append(" #"); stringBuilder.append(Integer.toHexString(id)); Resources resources = view.getResources(); if (!(id == 0 || resources == null)) { String str; switch (-16777216 & id) { case 16777216: str = "android"; break; case 2130706432: str = "app"; break; default: try { str = resources.getResourcePackageName(id); break; } catch (NotFoundException e) { break; } } String resourceTypeName = resources.getResourceTypeName(id); String resourceEntryName = resources.getResourceEntryName(id); stringBuilder.append(" "); stringBuilder.append(str); stringBuilder.append(":"); stringBuilder.append(resourceTypeName); stringBuilder.append("/"); stringBuilder.append(resourceEntryName); } } stringBuilder.append("}"); return stringBuilder.toString(); }
private static String a(View paramView) { char c3 = 'F'; char c2 = '.'; StringBuilder localStringBuilder = new StringBuilder(128); localStringBuilder.append(paramView.getClass().getName()); localStringBuilder.append('{'); localStringBuilder.append(Integer.toHexString(System.identityHashCode(paramView))); localStringBuilder.append(' '); char c1; label118: label135: label152: label169: label186: label203: label220: label244: label261: int n; Object localObject; switch (paramView.getVisibility()) { default: localStringBuilder.append('.'); if (paramView.isFocusable()) { c1 = 'F'; localStringBuilder.append(c1); if (!paramView.isEnabled()) { break label562; } c1 = 'E'; localStringBuilder.append(c1); if (!paramView.willNotDraw()) { break label568; } c1 = '.'; localStringBuilder.append(c1); if (!paramView.isHorizontalScrollBarEnabled()) { break label574; } c1 = 'H'; localStringBuilder.append(c1); if (!paramView.isVerticalScrollBarEnabled()) { break label580; } c1 = 'V'; localStringBuilder.append(c1); if (!paramView.isClickable()) { break label586; } c1 = 'C'; localStringBuilder.append(c1); if (!paramView.isLongClickable()) { break label592; } c1 = 'L'; localStringBuilder.append(c1); localStringBuilder.append(' '); if (!paramView.isFocused()) { break label598; } c1 = c3; localStringBuilder.append(c1); if (!paramView.isSelected()) { break label604; } c1 = 'S'; localStringBuilder.append(c1); c1 = c2; if (paramView.isPressed()) { c1 = 'P'; } localStringBuilder.append(c1); localStringBuilder.append(' '); localStringBuilder.append(paramView.getLeft()); localStringBuilder.append(','); localStringBuilder.append(paramView.getTop()); localStringBuilder.append('-'); localStringBuilder.append(paramView.getRight()); localStringBuilder.append(','); localStringBuilder.append(paramView.getBottom()); n = paramView.getId(); if (n != -1) { localStringBuilder.append(" #"); localStringBuilder.append(Integer.toHexString(n)); localObject = paramView.getResources(); if ((n != 0) && (localObject != null)) { switch (0xFF000000 & n) { } } } } break; } for (;;) { try { paramView = ((Resources)localObject).getResourcePackageName(n); String str = ((Resources)localObject).getResourceTypeName(n); localObject = ((Resources)localObject).getResourceEntryName(n); localStringBuilder.append(" "); localStringBuilder.append(paramView); localStringBuilder.append(":"); localStringBuilder.append(str); localStringBuilder.append("/"); localStringBuilder.append((String)localObject); } catch (Resources.NotFoundException paramView) { label562: label568: label574: label580: label586: label592: label598: label604: continue; } localStringBuilder.append("}"); return localStringBuilder.toString(); localStringBuilder.append('V'); break; localStringBuilder.append('I'); break; localStringBuilder.append('G'); break; c1 = '.'; break label118; c1 = '.'; break label135; c1 = 'D'; break label152; c1 = '.'; break label169; c1 = '.'; break label186; c1 = '.'; break label203; c1 = '.'; break label220; c1 = '.'; break label244; c1 = '.'; break label261; paramView = "app"; continue; paramView = "android"; } }
/* * Used just to setup the click listener if applicable. */ private void doSetClickable(View view) { if (view == null) { return; } doSetClickable(view, view.isClickable()); }