Java Code Examples for android.view.View.getHitRect()

The following are Jave code examples for showing how to use getHitRect() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: QiangHongBao   File: MaterialRippleLayout.java   Source Code and License Vote up 7 votes
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();
}
 
Example 2
Project: YCUtils   File: MaterialRippleLayout.java   Source Code and License Vote up 7 votes
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();
}
 
Example 3
Project: container   File: PendIntentCompat.java   Source Code and License Vote up 7 votes
/***
 *
 * @param remoteViews
 *            当前
 * @param remoteview
 *            当前remoteviews的view
 * @param oldRemoteView
 *            旧的view
 */
public void setPendIntent(RemoteViews remoteViews, View remoteview, View oldRemoteView) {
	if (findPendIntents() > 0) {
		// view2+clickIntents=>区域和事件
		Iterator<Map.Entry<Integer, PendingIntent>> set = clickIntents.entrySet().iterator();
		List<RectInfo> list = new ArrayList<>();
		// 区域对应点击事件
		while (set.hasNext()) {
			Map.Entry<Integer, PendingIntent> e = set.next();
			View view = oldRemoteView.findViewById(e.getKey());
			if (view != null) {
				Rect rect = new Rect();
				view.getHitRect(rect);
				list.add(new RectInfo(rect, e.getValue()));
			}
		}
		// 根据区域查找id,设置点击事件
		if (remoteview instanceof ViewGroup) {
			setIntentByViewGroup(remoteViews, (ViewGroup) remoteview, list);
		}
	}
}
 
Example 4
Project: VirtualHook   File: MaterialRippleLayout.java   Source Code and License Vote up 7 votes
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();
}
 
Example 5
Project: HorizontalPicker   File: HorizontalPicker.java   Source Code and License Vote up 7 votes
/**
 * Monitors the touch event.
 * If the action is ACTION_DOWN or ACTION_MOVE, the LinearLayout is traversed to get the hitRect of each child.
 * Each child hitRect is checked to see if it contains x,y touch co-ordinates.
 * If it does, selectChild(index) method is called.
 * @param view
 * @param motionEvent
 * @return
 */
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
    switch (motionEvent.getAction()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_MOVE:
            int x = (int) motionEvent.getX();
            int y = (int) motionEvent.getY();
            Rect hitRect = new Rect();
            View v;

            for (int i = 0; i < getChildCount(); i++) {
                v = getChildAt(i);
                v.getHitRect(hitRect);
                if (hitRect.contains(x, y)) {
                    selectChild(i);
                    break;
                }
            }
            break;
        default:
            break;
    }

    return true;
}
 
Example 6
Project: boohee_v5.6   File: MaterialRippleLayout.java   Source Code and License Vote up 7 votes
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);
            Rect rect = new Rect();
            child.getHitRect(rect);
            if (rect.contains(x, y)) {
                return findClickableViewInChild(child, x - rect.left, y - rect.top);
            }
        }
    } else if (view != this.childView) {
        return view.isEnabled() && (view.isClickable() || view.isLongClickable() || view.isFocusableInTouchMode());
    }
    return view.isFocusableInTouchMode();
}
 
Example 7
Project: q-mail   File: NonLockingScrollView.java   Source Code and License Vote up 6 votes
private boolean isEventOverChild(MotionEvent ev, List<View> children) {
    final int actionIndex = ev.getActionIndex();
    final float x = ev.getX(actionIndex) + getScrollX();
    final float y = ev.getY(actionIndex) + getScrollY();

    for (View child : children) {
        if (!canViewReceivePointerEvents(child)) {
            continue;
        }
        child.getHitRect(sHitFrame);

        // child can receive the motion event.
        if (sHitFrame.contains((int) x, (int) y)) {
            return true;
        }
    }
    return false;
}
 
Example 8
Project: DailyZhiHu   File: CustomViewAbove.java   Source Code and License Vote up 6 votes
private boolean isInIgnoredView(MotionEvent ev) {
	Rect rect = new Rect();
	for (View v : mIgnoredViews) {
		v.getHitRect(rect);
		if (rect.contains((int)ev.getX(), (int)ev.getY())) return true;
	}
	return false;
}
 
Example 9
Project: GitHub   File: PinnedSectionListView.java   Source Code and License Vote up 6 votes
private boolean isPinnedViewTouched(View view, float x, float y) {
    view.getHitRect(mTouchRect);

    // by taping top or bottom padding, the list performs on click on a border item.
    // we don't add top padding here to keep behavior consistent.
    mTouchRect.top += mTranslateY;

    mTouchRect.bottom += mTranslateY + getPaddingTop();
    mTouchRect.left += getPaddingLeft();
    mTouchRect.right -= getPaddingRight();
    return mTouchRect.contains((int)x, (int)y);
}
 
Example 10
Project: WeatherStream   File: CustomViewAbove.java   Source Code and License Vote up 6 votes
private boolean isInIgnoredView(MotionEvent ev) {
	Rect rect = new Rect();
	for (View v : mIgnoredViews) {
		v.getHitRect(rect);
		if (rect.contains((int)ev.getX(), (int)ev.getY())) return true;
	}
	return false;
}
 
Example 11
Project: RNLearn_Project1   File: FlatViewGroup.java   Source Code and License Vote up 6 votes
/**
 * Draws the next child of the FlatViewGroup.  Each draw view calls FlatViewGroup.drawNextChild,
 * which keeps track of the current child index to draw.
 *
 * @param canvas The canvas to draw on.
 */
/* package */ void drawNextChild(Canvas canvas) {
  View child = getChildAt(mDrawChildIndex);
  if (child instanceof FlatViewGroup) {
    super.drawChild(canvas, child, getDrawingTime());
  } else {
    // Make sure non-React Views clip properly.
    canvas.save(Canvas.CLIP_SAVE_FLAG);
    child.getHitRect(VIEW_BOUNDS);
    canvas.clipRect(VIEW_BOUNDS);
    super.drawChild(canvas, child, getDrawingTime());
    canvas.restore();
  }

  ++mDrawChildIndex;
}
 
Example 12
Project: QiangHongBao   File: SwipeBackLayout.java   Source Code and License Vote up 6 votes
private void drawShadow(Canvas canvas, View child) {
    final Rect childRect = mTmpRect;
    child.getHitRect(childRect);

    if ((mEdgeFlag & EDGE_LEFT) != 0) {
        mShadowLeft.setBounds(childRect.left - mShadowLeft.getIntrinsicWidth(), childRect.top,
                childRect.left, childRect.bottom);
        mShadowLeft.setAlpha((int) (mScrimOpacity * FULL_ALPHA));
        mShadowLeft.draw(canvas);
    }

    if ((mEdgeFlag & EDGE_RIGHT) != 0) {
        mShadowRight.setBounds(childRect.right, childRect.top,
                childRect.right + mShadowRight.getIntrinsicWidth(), childRect.bottom);
        mShadowRight.setAlpha((int) (mScrimOpacity * FULL_ALPHA));
        mShadowRight.draw(canvas);
    }

    if ((mEdgeFlag & EDGE_BOTTOM) != 0) {
        mShadowBottom.setBounds(childRect.left, childRect.bottom, childRect.right,
                childRect.bottom + mShadowBottom.getIntrinsicHeight());
        mShadowBottom.setAlpha((int) (mScrimOpacity * FULL_ALPHA));
        mShadowBottom.draw(canvas);
    }
}
 
Example 13
Project: Cashew   File: SwipeBackLayout.java   Source Code and License Vote up 6 votes
private void drawShadow(Canvas canvas, View child) {
    final Rect childRect = mTmpRect;
    child.getHitRect(childRect);

    mShadowLeft.setBounds(childRect.left - mShadowLeft.getIntrinsicWidth(), childRect.top,
            childRect.left, childRect.bottom);
    mShadowLeft.setAlpha((int) (mScrimOpacity * FULL_ALPHA));
    mShadowLeft.draw(canvas);
}
 
Example 14
Project: ankihelper   File: BigBangLayout.java   Source Code and License Vote up 6 votes
private View findChildByPoint(int x, int y) {
    int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = getChildAt(i);
        Rect rect = new Rect();
        child.getHitRect(rect);
        if (rect.contains(x, y)) {
            return child;
        }
    }
    return null;
}
 
Example 15
Project: Slide-RSS   File: SwipeBackLayout.java   Source Code and License Vote up 6 votes
private void drawShadow(Canvas canvas, View child) {
    final Rect childRect = mTmpRect;
    child.getHitRect(childRect);

    if ((mEdgeFlag & EDGE_LEFT) != 0) {
        mShadowLeft.setBounds(childRect.left - mShadowLeft.getIntrinsicWidth(), childRect.top,
                childRect.left, childRect.bottom);
        mShadowLeft.setAlpha((int) (mScrimOpacity * FULL_ALPHA));
        mShadowLeft.draw(canvas);
    }

    if ((mEdgeFlag & EDGE_RIGHT) != 0) {
        mShadowRight.setBounds(childRect.right, childRect.top,
                childRect.right + mShadowRight.getIntrinsicWidth(), childRect.bottom);
        mShadowRight.setAlpha((int) (mScrimOpacity * FULL_ALPHA));
        mShadowRight.draw(canvas);
    }

    if ((mEdgeFlag & EDGE_BOTTOM) != 0) {
        mShadowBottom.setBounds(childRect.left, childRect.bottom, childRect.right,
                childRect.bottom + mShadowBottom.getIntrinsicHeight());
        mShadowBottom.setAlpha((int) (mScrimOpacity * FULL_ALPHA));
        mShadowBottom.draw(canvas);
    }

    if ((mEdgeFlag & EDGE_TOP) != 0) {
        mShadowTop.setBounds(childRect.left, childRect.top - mShadowTop.getIntrinsicHeight(),
                childRect.right, childRect.top + getStatusBarHeight());
        mShadowTop.setAlpha((int) (mScrimOpacity * FULL_ALPHA));
        mShadowTop.draw(canvas);
    }
}
 
Example 16
Project: R-a-dio-Amazing-Android-App   File: ActivityMain.java   Source Code and License Vote up 6 votes
private boolean isDrawerVisible(View view) {

        Rect scrollBounds = new Rect();
        view.getHitRect(scrollBounds);
        if (view.findViewById(R.id.drawer_layout).findViewById(R.id.left_drawer).getLocalVisibleRect(scrollBounds)) {
            return true;
        } else {
            return false;
        }
    }
 
Example 17
Project: LiuAGeAndroid   File: CustomViewAbove.java   Source Code and License Vote up 6 votes
private boolean isInIgnoredView(MotionEvent ev) {
	Rect rect = new Rect();
	for (View v : mIgnoredViews) {
		v.getHitRect(rect);
		if (rect.contains((int)ev.getX(), (int)ev.getY())) return true;
	}
	return false;
}
 
Example 18
Project: Linphone4Android   File: SlidingDrawer.java   Source Code and License Vote up 5 votes
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
	if (mLocked) {
		return false;
	}

	final int action = event.getAction();

	float x = event.getX();
	float y = event.getY();

	final Rect frame = mFrame;
	final View handle = mHandle;

	handle.getHitRect(frame);
	if (!mTracking && !frame.contains((int) x, (int) y)) {
		return false;
	}

	if (action == MotionEvent.ACTION_DOWN) {
		mTracking = true;

		handle.setPressed(true);
		// Must be called before prepareTracking()
		prepareContent();

		// Must be called after prepareContent()
		if (mOnDrawerScrollListener != null) {
			mOnDrawerScrollListener.onScrollStarted();
		}

		if (mVertical) {
			final int top = mHandle.getTop();
			mTouchDelta = (int) y - top;
			prepareTracking(top);
		} else {
			final int left = mHandle.getLeft();
			mTouchDelta = (int) x - left;
			prepareTracking(left);
		}
		mVelocityTracker.addMovement(event);
	}

	return onTouchEvent(event);
}
 
Example 19
Project: PlusGram   File: ActionBarMenuItem.java   Source Code and License Vote up 5 votes
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
        if (hasSubMenu() && (popupWindow == null || popupWindow != null && !popupWindow.isShowing())) {
            showMenuRunnable = new Runnable() {
                @Override
                public void run() {
                    if (getParent() != null) {
                        getParent().requestDisallowInterceptTouchEvent(true);
                    }
                    toggleSubMenu();
                }
            };
            AndroidUtilities.runOnUIThread(showMenuRunnable, 200);
        }
    } else if (event.getActionMasked() == MotionEvent.ACTION_MOVE) {
        if (hasSubMenu() && (popupWindow == null || popupWindow != null && !popupWindow.isShowing())) {
            if (event.getY() > getHeight()) {
                if (getParent() != null) {
                    getParent().requestDisallowInterceptTouchEvent(true);
                }
                toggleSubMenu();
                return true;
            }
        } else if (popupWindow != null && popupWindow.isShowing()) {
            getLocationOnScreen(location);
            float x = event.getX() + location[0];
            float y = event.getY() + location[1];
            popupLayout.getLocationOnScreen(location);
            x -= location[0];
            y -= location[1];
            selectedMenuView = null;
            for (int a = 0; a < popupLayout.getItemsCount(); a++) {
                View child = popupLayout.getItemAt(a);
                child.getHitRect(rect);
                if ((Integer) child.getTag() < 100) {
                    if (!rect.contains((int) x, (int) y)) {
                        child.setPressed(false);
                        child.setSelected(false);
                        if (Build.VERSION.SDK_INT == 21) {
                            child.getBackground().setVisible(false, false);
                        }
                    } else {
                        child.setPressed(true);
                        child.setSelected(true);
                        if (Build.VERSION.SDK_INT >= 21) {
                            if (Build.VERSION.SDK_INT == 21) {
                                child.getBackground().setVisible(true, false);
                            }
                            child.drawableHotspotChanged(x, y - child.getTop());
                        }
                        selectedMenuView = child;
                    }
                }
            }
        }
    } else if (popupWindow != null && popupWindow.isShowing() && event.getActionMasked() == MotionEvent.ACTION_UP) {
        if (selectedMenuView != null) {
            selectedMenuView.setSelected(false);
            if (parentMenu != null) {
                parentMenu.onItemClick((Integer) selectedMenuView.getTag());
            } else if (delegate != null) {
                delegate.onItemClick((Integer) selectedMenuView.getTag());
            }
            popupWindow.dismiss(allowCloseAnimation);
        } else {
            popupWindow.dismiss();
        }
    } else {
        if (selectedMenuView != null) {
            selectedMenuView.setSelected(false);
            selectedMenuView = null;
        }
    }
    return super.onTouchEvent(event);
}
 
Example 20
Project: CustomAndroidOneSheeld   File: MultiDirectionSlidingDrawer.java   Source Code and License Vote up 5 votes
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if (mLocked) {
        return false;
    }

    final int action = event.getAction();

    float x = event.getX();
    float y = event.getY();

    final Rect frame = mFrame;
    final View handle = mHandle;

    handle.getHitRect(frame);
    if (!mTracking && !frame.contains((int) x, (int) y)) {
        return false;
    }

    if (action == MotionEvent.ACTION_DOWN) {
        mTracking = true;

        handle.setPressed(true);
        // Must be called before prepareTracking()
        prepareContent();

        // Must be called after prepareContent()
        if (mOnDrawerScrollListener != null) {
            mOnDrawerScrollListener.onScrollStarted();
        }

        if (mVertical) {
            final int top = mHandle.getTop();
            mTouchDelta = (int) y - top;
            prepareTracking(top);
        } else {
            final int left = mHandle.getLeft();
            mTouchDelta = (int) x - left;
            prepareTracking(left);
        }
        mVelocityTracker.addMovement(event);
    }

    return true;
}