Example usage for android.view View getHitRect

List of usage examples for android.view View getHitRect

Introduction

In this page you can find the example usage for android.view View getHitRect.

Prototype

public void getHitRect(Rect outRect) 

Source Link

Document

Hit rectangle in parent's coordinates

Usage

From source file:org.xbmc.kore.utils.UIUtils.java

/**
 * Returns true if {@param view} is contained within {@param container}'s bounds.
 *///from   w w  w  . jav a2s.com
public static boolean isViewInBounds(@NonNull View container, @NonNull View view) {
    Rect containerBounds = new Rect();
    container.getHitRect(containerBounds);
    return view.getLocalVisibleRect(containerBounds);
}

From source file:Main.java

public static Rect getLocationInView(View parent, View child) {
    if (child == null || parent == null) {
        throw new IllegalArgumentException("parent and child can not be null .");
    }/*  w  ww .  j a  v  a  2  s .  c o  m*/

    View decorView = null;
    Context context = child.getContext();
    if (context instanceof Activity) {
        decorView = ((Activity) context).getWindow().getDecorView();
    }

    Rect result = new Rect();
    Rect tmpRect = new Rect();

    View tmp = child;

    if (child == parent) {
        child.getHitRect(result);
        return result;
    }
    while (tmp != decorView && tmp != parent) {
        tmp.getHitRect(tmpRect);
        if (!tmp.getClass().equals(FRAGMENT_CON)) {
            result.left += tmpRect.left;
            result.top += tmpRect.top;
        }
        tmp = (View) tmp.getParent();
    }
    result.right = result.left + child.getMeasuredWidth();
    result.bottom = result.top + child.getMeasuredHeight();
    return result;
}

From source file:Main.java

/**
 * @param top/*w  ww.  ja v a 2  s  . co  m*/
 * @param left
 * @param bottom
 * @param right
 * @param delegate
 */
public static void increaseHitRectBy(final int top, final int left, final int bottom, final int right,
        final View delegate) {
    final View parent = (View) delegate.getParent();
    if (parent != null && delegate.getContext() != null) {
        parent.post(new Runnable() {
            // Post in the parent's message queue to make sure the parent
            // lays out its children before we call getHitRect()
            public void run() {
                final float densityDpi = delegate.getContext().getResources().getDisplayMetrics().densityDpi;
                final Rect r = new Rect();
                delegate.getHitRect(r);
                r.top -= transformToDensityPixel(top, densityDpi);
                r.left -= transformToDensityPixel(left, densityDpi);
                r.bottom += transformToDensityPixel(bottom, densityDpi);
                r.right += transformToDensityPixel(right, densityDpi);
                parent.setTouchDelegate(new TouchDelegate(r, delegate));
            }
        });
    }
}

From source file:com.ratebeer.android.app.location.TouchableMapViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    View map = findViewById(R.id.map_nearby);
    if (map != null) {
        Rect rect = new Rect();
        map.getHitRect(rect);
        int pageOffset = getMeasuredWidth() * activePage;
        if (rect.contains(pageOffset + (int) ev.getX(), (int) ev.getY())) {
            return false;
        }//  ww  w.j  a v  a  2 s  .  c o m
    }
    return super.onInterceptTouchEvent(ev);
}

From source file:com.todoroo.astrid.ui.TaskListFragmentPager.java

private boolean checkForPeopleHeaderScroll(MotionEvent ev) {
    TaskListFragment current = getCurrentFragment();
    if (current != null) {
        View v = current.getView();
        if (v != null) {
            View peopleView = v.findViewById(R.id.shared_with);
            if (peopleView != null) {
                Rect rect = new Rect();
                peopleView.getHitRect(rect);
                if (rect.contains((int) ev.getX(), (int) ev.getY()))
                    return true;
            }/*  w w w . j  a v  a2 s.co m*/
        }
    }
    return false;
}

From source file:com.tingtingapps.securesms.ContactSelectionActivity.java

private void expandTapArea(final View container, final View child, final int padding) {
    container.post(new Runnable() {
        @Override//from  w  w  w.  j av  a  2s .  co  m
        public void run() {
            Rect rect = new Rect();
            child.getHitRect(rect);

            rect.top -= padding;
            rect.left -= padding;
            rect.right += padding;
            rect.bottom += padding;

            container.setTouchDelegate(new TouchDelegate(rect, child));
        }
    });
}

From source file:individual.leobert.calendar.CalendarLayout.java

public boolean isClickView(View view, MotionEvent ev) {
    Rect rect = new Rect();
    view.getHitRect(rect);
    boolean isClick = rect.contains((int) ev.getX(), (int) ev.getY());
    Log.d(TAG, "isClickView() called with: isClick = [" + isClick + "]");
    return isClick;
}

From source file:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterListView.java

private boolean isStickyViewTouched(View view, float x, float y) {
    view.getHitRect(touchRect);

    touchRect.bottom += getPaddingTop() - view.getTop();
    touchRect.left += getPaddingLeft();/*w  ww .ja v  a2 s.  co  m*/
    touchRect.right -= getPaddingRight();
    return touchRect.contains((int) x, (int) y);
}

From source file:com.example.zw.demolist.widget.BigBangLayout.java

private View findChildFromPoint(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;
        }//ww  w. j av a  2s .c o m
    }
    return null;
}

From source file:com.codingfeel.sm.views.superrecyclerview.swipe.SwipeDismissRecyclerViewTouchListener.java

private void caseMotionActionDown(MotionEvent motionEvent) {
    // Find the child view that was touched (perform a hit test)
    Rect rect = new Rect();
    int childCount = mRecyclerView.getChildCount();
    int[] listViewCoords = new int[2];
    mRecyclerView.getLocationOnScreen(listViewCoords);
    int x = (int) motionEvent.getRawX() - listViewCoords[0];
    int y = (int) motionEvent.getRawY() - listViewCoords[1];
    View child;
    for (int i = 0; i < childCount; i++) {
        child = mRecyclerView.getChildAt(i);
        child.getHitRect(rect);
        if (rect.contains(x, y)) {
            mDownView = child;//from  w w  w .  j  a v a 2s. c  o m
            break;
        }
    }

    if (mDownView != null) {
        mDownX = motionEvent.getRawX();
        mDownY = motionEvent.getRawY();
        mDownPosition = mRecyclerView.getChildAdapterPosition(mDownView);
        if (mCallbacks.canDismiss(mDownPosition)) {
            mVelocityTracker = VelocityTracker.obtain();
            mVelocityTracker.addMovement(motionEvent);
        } else {
            mDownView = null;
        }
    }
}