Example usage for android.graphics RectF contains

List of usage examples for android.graphics RectF contains

Introduction

In this page you can find the example usage for android.graphics RectF contains.

Prototype

public boolean contains(float x, float y) 

Source Link

Document

Returns true if (x,y) is inside the rectangle.

Usage

From source file:im.ene.lab.design.widget.coverflow.FeatureCoverFlow.java

@Override
protected void handleClick(Point p) {
    final int c = getChildCount();
    View v;// ww  w.  jav a 2s.  c  o  m
    final RectF r = new RectF();
    final int[] childOrder = new int[c];

    for (int i = 0; i < c; i++) {
        childOrder[i] = getChildDrawingOrder(c, i);
    }

    for (int i = c - 1; i >= 0; i--) {
        v = getChildAt(childOrder[i]); //we need reverse drawing order. Check children drawn last
        // first
        getScrolledTransformedChildRectangle(v, r);
        if (r.contains(p.x, p.y)) {
            final View old = getSelectedView();
            if (old != null)
                old.setSelected(false);

            int position = mFirstItemPosition + childOrder[i];
            if (position >= mAdapter.getCount())
                position = position - mAdapter.getCount();

            mSelectedPosition = position;
            v.setSelected(true);

            if (mOnItemClickListener != null)
                mOnItemClickListener.onItemClick(this, v, position, getItemIdAtPosition(position));
            if (mOnItemSelectedListener != null)
                mOnItemSelectedListener.onItemSelected(this, v, position, getItemIdAtPosition(position));

            break;
        }
    }
}

From source file:im.ene.lab.design.widget.coverflow.FeatureCoverFlow.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    final int action = ev.getAction();
    final float xf = ev.getX();
    final float yf = ev.getY();
    final RectF frame = mTouchRect;

    if (action == MotionEvent.ACTION_DOWN) {
        if (mMotionTarget != null) {
            // this is weird, we got a pen down, but we thought it was
            // already down!
            // We should probably send an ACTION_UP to the current
            // target.
            mMotionTarget = null;//  ww  w  . ja  v  a  2s  . c  o m
        }
        // If we're disallowing intercept or if we're allowing and we didn't
        // intercept
        if (!onInterceptTouchEvent(ev)) {
            // reset this event's action (just to protect ourselves)
            ev.setAction(MotionEvent.ACTION_DOWN);
            // We know we want to dispatch the event down, find a child
            // who can handle it, start with the front-most child.

            final int count = getChildCount();
            final int[] childOrder = new int[count];

            for (int i = 0; i < count; i++) {
                childOrder[i] = getChildDrawingOrder(count, i);
            }

            for (int i = count - 1; i >= 0; i--) {
                final View child = getChildAt(childOrder[i]);
                if (child.getVisibility() == VISIBLE || child.getAnimation() != null) {

                    getScrolledTransformedChildRectangle(child, frame);

                    if (frame.contains(xf, yf)) {
                        // offset the event to the view's coordinate system
                        final float xc = xf - frame.left;
                        final float yc = yf - frame.top;
                        ev.setLocation(xc, yc);
                        if (child.dispatchTouchEvent(ev)) {
                            // Event handled, we have a target now.
                            mMotionTarget = child;
                            mTargetTop = frame.top;
                            mTargetLeft = frame.left;
                            return true;
                        }

                        break;
                    }
                }
            }
        }
    }

    boolean isUpOrCancel = (action == MotionEvent.ACTION_UP) || (action == MotionEvent.ACTION_CANCEL);

    // The event wasn't an ACTION_DOWN, dispatch it to our target if
    // we have one.
    final View target = mMotionTarget;
    if (target == null) {
        // We don't have a target, this means we're handling the
        // event as a regular view.
        ev.setLocation(xf, yf);
        return onTouchEvent(ev);
    }

    // if have a target, see if we're allowed to and want to intercept its
    // events
    if (onInterceptTouchEvent(ev)) {
        final float xc = xf - mTargetLeft;
        final float yc = yf - mTargetTop;
        ev.setAction(MotionEvent.ACTION_CANCEL);
        ev.setLocation(xc, yc);
        if (!target.dispatchTouchEvent(ev)) {
            // target didn't handle ACTION_CANCEL. not much we can do
            // but they should have.
        }
        // clear the target
        mMotionTarget = null;
        // Don't dispatch this event to our own view, because we already
        // saw it when intercepting; we just want to give the following
        // event to the normal onTouchEvent().
        return true;
    }

    if (isUpOrCancel) {
        mMotionTarget = null;
        mTargetTop = -1;
        mTargetLeft = -1;
    }

    // finally offset the event to the target's coordinate system and
    // dispatch the event.
    final float xc = xf - mTargetLeft;
    final float yc = yf - mTargetTop;
    ev.setLocation(xc, yc);

    return target.dispatchTouchEvent(ev);
}