Example usage for android.view View getRight

List of usage examples for android.view View getRight

Introduction

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

Prototype

@ViewDebug.CapturedViewProperty
public final int getRight() 

Source Link

Document

Right position of this view relative to its parent.

Usage

From source file:com.example.appdetail_optimization.HorizontalListView.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        scrollMode = SCROLL_MODE_IDLE;/*from   www .  j av  a2  s  . co m*/
        downEventX = ev.getRawX();
        downEventY = ev.getRawY();
        isFullScroll = false;

        int lastVisiblePos = getLastVisiblePosition();
        if (lastVisiblePos >= mAdapter.getCount() - 1) {
            View view = getChildAt(getChildCount() - 1);
            if (Math.abs(view.getRight() - getWidth()) < 10) {
                isFullScroll = true;
            }
        }
        getParent().requestDisallowInterceptTouchEvent(true);
        break;
    case MotionEvent.ACTION_MOVE:
        if (scrollMode == SCROLL_MODE_HORIZONTAL) {
            // view
        } else if (scrollMode == SCROLL_MODE_VERTICAL) {
            // viewtouch
            return false;
        } else if (scrollMode == SCROLL_MODE_IDLE) {
            float distanceX = Math.abs(ev.getRawX() - downEventX);
            float distanceY = Math.abs(ev.getRawY() - downEventY);
            if (distanceX > distanceY && distanceX > 5) {
                if (isFullScroll) {
                    if (ev.getRawX() < downEventX) {
                        Log.i("LeiTest", "viewpager");
                        scrollMode = SCROLL_MODE_VERTICAL;
                        getParent().requestDisallowInterceptTouchEvent(false);
                        return super.dispatchTouchEvent(ev);
                    }
                }

                scrollMode = SCROLL_MODE_HORIZONTAL;
                getParent().requestDisallowInterceptTouchEvent(true);
            } else if (distanceY > distanceX && distanceY > 5) {
                scrollMode = SCROLL_MODE_VERTICAL;
                getParent().requestDisallowInterceptTouchEvent(false);
                return false;
            }
        }

        break;
    case MotionEvent.ACTION_UP:
        scrollMode = SCROLL_MODE_IDLE;
        getParent().requestDisallowInterceptTouchEvent(false);
        break;

    case MotionEvent.ACTION_CANCEL:
        scrollMode = SCROLL_MODE_IDLE;
        getParent().requestDisallowInterceptTouchEvent(false);
        break;

    default:
        break;
    }

    return super.dispatchTouchEvent(ev);
}

From source file:com.example.nwilde.myfirstapp.SimpleListDividerDecorator.java

@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    final int childCount = parent.getChildCount();
    final float yPositionThreshold = (mOverlap) ? 1.0f : (mDividerHeight + 1.0f); // [px]
    final float zPositionThreshold = 1.0f; // [px]

    if (childCount == 0) {
        return;/*from  w  w  w  .  j  a  v  a2s.  c  o m*/
    }

    int savedCount = c.save(Canvas.CLIP_SAVE_FLAG);

    c.clipRect(parent.getLeft() + parent.getPaddingLeft(), parent.getTop() + parent.getPaddingTop(),
            parent.getRight() - parent.getPaddingRight(), parent.getBottom() + parent.getPaddingBottom());

    for (int i = 0; i < childCount - 1; i++) {
        final View child = parent.getChildAt(i);
        final View nextChild = parent.getChildAt(i + 1);

        if ((child.getVisibility() != View.VISIBLE) || (nextChild.getVisibility() != View.VISIBLE)) {
            continue;
        }

        // check if the next item is placed at the bottom
        final float childBottom = child.getBottom() + ViewCompat.getTranslationY(child);
        final float nextChildTop = nextChild.getTop() + ViewCompat.getTranslationY(nextChild);

        if (!(Math.abs(nextChildTop - childBottom) < yPositionThreshold)) {
            continue;
        }

        // check if the next item is placed on the same plane
        final float childZ = ViewCompat.getTranslationZ(child) + ViewCompat.getElevation(child);
        final float nextChildZ = ViewCompat.getTranslationZ(nextChild) + ViewCompat.getElevation(nextChild);

        if (!(Math.abs(nextChildZ - childZ) < zPositionThreshold)) {
            continue;
        }

        final float childAlpha = ViewCompat.getAlpha(child);
        final float nextChildAlpha = ViewCompat.getAlpha(nextChild);

        final int tx = (int) (ViewCompat.getTranslationX(child) + 0.5f);
        final int ty = (int) (ViewCompat.getTranslationY(child) + 0.5f);
        final int left = child.getLeft();
        final int right = child.getRight();
        final int top = child.getBottom();
        final int bottom = top + mDividerHeight;

        mDividerDrawable.setAlpha((int) ((0.5f * 255) * (childAlpha + nextChildAlpha) + 0.5f));
        mDividerDrawable.setBounds(left + tx, top + ty, right + tx, bottom + ty);
        mDividerDrawable.draw(c);
    }

    c.restoreToCount(savedCount);
}

From source file:com.lansun.qmyo.view.ViewDragHelper.java

/**
 * Tests scrollability within child views of v given a delta of dx.
 * /*from w ww .  j a v a  2s .  co  m*/
 * @param v
 *            View to test for horizontal scrollability
 * @param checkV
 *            Whether the view v passed should itself be checked for scrollability (true), or just its children (false).
 * @param dx
 *            Delta scrolled in pixels along the X axis
 * @param dy
 *            Delta scrolled in pixels along the Y axis
 * @param x
 *            X coordinate of the active touch point
 * @param y
 *            Y coordinate of the active touch point
 * @return true if child views of v can be scrolled by delta of dx.
 */
protected boolean canScroll(View v, boolean checkV, int dx, int dy, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();
        final int count = group.getChildCount();
        // Count backwards - let topmost views consume scroll distance first.
        for (int i = count - 1; i >= 0; i--) {
            // This will not work for transformed views in Honeycomb+
            final View child = group.getChildAt(i);
            if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight()
                    && y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && canScroll(child,
                            true, dx, dy, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    return checkV && (ViewCompat.canScrollHorizontally(v, -dx) || ViewCompat.canScrollVertically(v, -dy));
}

From source file:aksha.upcomingdemo.HorizontalListView.java

/**
 * Determine the Max X position. This is the farthest that the user can scroll the screen. Until the last adapter item has been
 * laid out it is impossible to calculate; once that has occurred this will perform the calculation, and if necessary force a
 * redraw and relayout of this view./* w w  w .jav  a  2 s .  c o  m*/
 *
 * @return true if the maxx position was just determined
 */
private boolean determineMaxX() {
    // If the last view has been laid out, then we can determine the maximum x position
    if (isLastItemInAdapter(mRightViewAdapterIndex)) {
        View rightView = getRightmostChild();

        if (rightView != null) {
            int oldMaxX = mMaxX;

            // Determine the maximum x position
            mMaxX = mCurrentX + (rightView.getRight() - getPaddingLeft()) - getRenderWidth();

            // Handle the case where the views do not fill at least 1 screen
            if (mMaxX < 0) {
                mMaxX = 0;
            }

            if (mMaxX != oldMaxX) {
                return true;
            }
        }
    }

    return false;
}

From source file:com.android.slidingmenu.HorizontalListView.java

/** Draws the dividers that go in between the horizontal list view items */
private void drawDividers(Canvas canvas) {
    final int count = getChildCount();

    // Only modify the left and right in the loop, we set the top and bottom
    // here since they are always the same
    final Rect bounds = mRect;
    mRect.top = getPaddingTop();//from w  w  w.ja  va  2s .c o  m
    mRect.bottom = mRect.top + getRenderHeight();

    // Draw the list dividers
    for (int i = 0; i < count; i++) {
        // Don't draw a divider to the right of the last item in the adapter
        if (!(i == count - 1 && isLastItemInAdapter(mRightViewAdapterIndex))) {
            View child = getChildAt(i);

            bounds.left = child.getRight();
            bounds.right = child.getRight() + mDividerWidth;

            // Clip at the left edge of the screen
            if (bounds.left < getPaddingLeft()) {
                bounds.left = getPaddingLeft();
            }

            // Clip at the right edge of the screen
            if (bounds.right > getWidth() - getPaddingRight()) {
                bounds.right = getWidth() - getPaddingRight();
            }

            // Draw a divider to the right of the child
            drawDivider(canvas, bounds);

            // If the first view, determine if a divider should be shown to
            // the left of it.
            // A divider should be shown if the left side of this view does
            // not fill to the left edge of the screen.
            if (i == 0 && child.getLeft() > getPaddingLeft()) {
                bounds.left = getPaddingLeft();
                bounds.right = child.getLeft();
                drawDivider(canvas, bounds);
            }
        }
    }
}

From source file:com.fancyfamily.primarylibrary.commentlibrary.widget.HorizontalListView.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        scrollMode = SCROLL_MODE_IDLE;/*from  w w w.  ja  va 2  s  .c  o  m*/
        downEventX = ev.getRawX();
        downEventY = ev.getRawY();
        isFullScroll = false;

        int lastVisiblePos = getLastVisiblePosition();
        if (lastVisiblePos >= mAdapter.getCount() - 1) {
            View view = getChildAt(getChildCount() - 1);

            if (view != null && Math.abs(view.getRight() - getWidth()) < 10) {
                isFullScroll = true;
            }
        }
        getParent().requestDisallowInterceptTouchEvent(true);
        break;
    case MotionEvent.ACTION_MOVE:
        if (scrollMode == SCROLL_MODE_HORIZONTAL) {
            // view
        } else if (scrollMode == SCROLL_MODE_VERTICAL) {
            // viewtouch
            return false;
        } else if (scrollMode == SCROLL_MODE_IDLE) {
            float distanceX = Math.abs(ev.getRawX() - downEventX);
            float distanceY = Math.abs(ev.getRawY() - downEventY);
            if (distanceX > distanceY && distanceX > 5) {
                if (isFullScroll) {
                    if (ev.getRawX() < downEventX) {
                        Log.i("LeiTest", "viewpager");
                        scrollMode = SCROLL_MODE_VERTICAL;
                        getParent().requestDisallowInterceptTouchEvent(false);
                        return super.dispatchTouchEvent(ev);
                    }
                }

                scrollMode = SCROLL_MODE_HORIZONTAL;
                getParent().requestDisallowInterceptTouchEvent(true);
            } else if (distanceY > distanceX && distanceY > 5) {
                scrollMode = SCROLL_MODE_VERTICAL;
                getParent().requestDisallowInterceptTouchEvent(false);
                return false;
            }
        }

        break;
    case MotionEvent.ACTION_UP:
        scrollMode = SCROLL_MODE_IDLE;
        getParent().requestDisallowInterceptTouchEvent(false);
        break;

    case MotionEvent.ACTION_CANCEL:
        scrollMode = SCROLL_MODE_IDLE;
        getParent().requestDisallowInterceptTouchEvent(false);
        break;

    default:
        break;
    }

    return super.dispatchTouchEvent(ev);
}

From source file:com.android.slidingmenu.HorizontalListView.java

/**
 * Adds children views to the left and right of the current views until the
 * screen is full//from w w w  .  ja va2  s .com
 */
private void fillList(final int dx) {
    // Get the rightmost child and determine its right edge
    int edge = 0;
    View child = getRightmostChild();
    if (child != null) {
        edge = child.getRight();
    }

    // Add new children views to the right, until past the edge of the
    // screen
    fillListRight(edge, dx);

    // Get the leftmost child and determine its left edge
    edge = 0;
    child = getLeftmostChild();
    if (child != null) {
        edge = child.getLeft();
    }

    // Add new children views to the left, until past the edge of the screen
    fillListLeft(edge, dx);
}

From source file:com.cyanogenmod.filemanager.ui.widgets.ViewDragHelper.java

/**
 * Tests scrollability within child views of v given a delta of dx.
 *
 * @param v View to test for horizontal scrollability
 * @param checkV Whether the view v passed should itself be checked for scrollability (true),
 *               or just its children (false).
 * @param dx Delta scrolled in pixels along the X axis
 * @param dy Delta scrolled in pixels along the Y axis
 * @param x X coordinate of the active touch point
 * @param y Y coordinate of the active touch point
 * @return true if child views of v can be scrolled by delta of dx.
 *///  w  w w .  j a va 2  s .c o m
protected boolean canScroll(View v, boolean checkV, int dx, int dy, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();
        final int count = group.getChildCount();
        // Count backwards - let topmost views consume scroll distance first.
        for (int i = count - 1; i >= 0; i--) {
            // TODO: Add versioned support here for transformed views.
            // This will not work for transformed views in Honeycomb+
            final View child = group.getChildAt(i);
            if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight()
                    && y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && canScroll(child,
                            true, dx, dy, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    return checkV && (v.canScrollHorizontally(-dx) || v.canScrollVertically(-dy));
}

From source file:com.dmcc.bid.widget.swipebacklayout.ViewDragHelper.java

public View findTopChildUnder(int x, int y) {
    final int childCount = mParentView.getChildCount();
    for (int i = childCount - 1; i >= 0; i--) {
        final View child = mParentView.getChildAt(mCallback.getOrderedChildIndex(i));
        if (x >= child.getLeft() && x < child.getRight() && y >= child.getTop() && y < child.getBottom()) {
            return child;
        }//from  w  w  w. ja v  a 2 s . c  om
    }
    return null;
}

From source file:com.aviary.android.feather.sdk.widget.AviaryWorkspace.java

private void detachOffScreenChildren(boolean toLeft) {
    int numChildren = getChildCount();
    int start = 0;
    int count = 0;
    int viewType;

    if (toLeft) {
        final int galleryLeft = mPaddingLeft + getScreenScrollPositionX(mCurrentScreen - 1);
        for (int i = 0; i < numChildren; i++) {
            final View child = getChildAt(i);
            if (child.getRight() > galleryLeft) {
                break;
            } else {
                count++;//ww  w.j  a  v  a  2s. c o m
                viewType = mAdapter.getItemViewType(i + mFirstPosition);
                mRecycleBin.get(viewType).offer(child);
            }
        }
    } else {
        final int galleryRight = getTotalWidth() + getScreenScrollPositionX(mCurrentScreen + 1);
        for (int i = numChildren - 1; i >= 0; i--) {
            final View child = getChildAt(i);
            if (child.getLeft() < galleryRight) {
                break;
            } else {
                start = i;
                count++;
                viewType = mAdapter.getItemViewType(i + mFirstPosition);
                mRecycleBin.get(viewType).offer(child);
            }
        }
    }

    detachViewsFromParent(start, count);

    if (toLeft && count > 0) {
        mFirstPosition += count;
    }

}