Java Code Examples for android.view.View#getRight()

The following examples show how to use android.view.View#getRight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwipeLayout.java    From AndroidSwipeLayout with MIT License 6 votes vote down vote up
@Override
public boolean onDoubleTap(MotionEvent e) {
    if (mDoubleClickListener != null) {
        View target;
        View bottom = getCurrentBottomView();
        View surface = getSurfaceView();
        if (bottom != null && e.getX() > bottom.getLeft() && e.getX() < bottom.getRight()
                && e.getY() > bottom.getTop() && e.getY() < bottom.getBottom()) {
            target = bottom;
        } else {
            target = surface;
        }
        mDoubleClickListener.onDoubleClick(SwipeLayout.this, target == surface);
    }
    return true;
}
 
Example 2
Source File: RcvGridDecoration.java    From RecyclerViewAdapter with Apache License 2.0 6 votes vote down vote up
public void drawHorizontal(Canvas c, RecyclerView recyclerView)
{
    int childCount = recyclerView.getChildCount();
    for (int i = 0; i < childCount; i++)
    {
        final View child = recyclerView.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int left = child.getLeft() - params.leftMargin;
        final int right = child.getRight() + params.rightMargin + mDividerWidth;
        final int top = child.getBottom() + params.bottomMargin;
        final int bottom = top + mDividerHeight;
        if (mDividerDrawable != null)
        {
            mDividerDrawable.setBounds(left, top, right, bottom);
            mDividerDrawable.draw(c);
        } else if (mDividerPaint != null)
        {
            c.drawRect(left, top, right, bottom, mDividerPaint);
        }
    }
}
 
Example 3
Source File: CustomViewPager.java    From material-intro-screen with MIT License 6 votes vote down vote up
/**
 * 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
 * @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 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, x + scrollX - child.getLeft(),
                    y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    return checkV && ViewCompat.canScrollHorizontally(v, -dx);
}
 
Example 4
Source File: SlidingUpPanelLayout.java    From Tweetin with Apache License 2.0 6 votes vote down vote up
/**
 * 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
 * @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 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--) {
            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, x + scrollX - child.getLeft(),
                            y + scrollY - child.getTop())) {
                return true;
            }
        }
    }
    return checkV && ViewCompat.canScrollHorizontally(v, -dx);
}
 
Example 5
Source File: GridDividerDecorator.java    From AlbumSelector with Apache License 2.0 5 votes vote down vote up
private void drawRightDivider(Canvas c, RecyclerView parent) {
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {

        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                .getLayoutParams();
        final int left = child.getRight() + params.rightMargin;
        final int right = left + mDividerSize;
        final int top = child.getTop() - params.topMargin;
        final int bottom = child.getBottom() + params.bottomMargin;
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 6
Source File: ViewDragHelper.java    From letv with Apache License 2.0 5 votes vote down vote up
public View findTopChildUnder(int x, int y) {
    for (int i = this.mParentView.getChildCount() - 1; i >= 0; i--) {
        View child = this.mParentView.getChildAt(this.mCallback.getOrderedChildIndex(i));
        if (x >= child.getLeft() && x < child.getRight() && y >= child.getTop() && y < child.getBottom()) {
            return child;
        }
    }
    return null;
}
 
Example 7
Source File: ViewDragHelper.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find the topmost child under the given point within the parent view's
 * coordinate system. The child order is determined using
 * {@link me.imid.swipebacklayout.lib.ViewDragHelper.Callback#getOrderedChildIndex(int)}
 * .
 *
 * @param x X position to test in the parent's coordinate system
 * @param y Y position to test in the parent's coordinate system
 * @return The topmost child view under (x, y) or null if none found.
 */
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;
        }
    }
    return null;
}
 
Example 8
Source File: ViewDragHelper.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
/**
 * 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.
 */
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
            && (ViewCompat.canScrollHorizontally(v, -dx) || ViewCompat.canScrollVertically(v,
            -dy));
}
 
Example 9
Source File: DividerGridItemDecoration.java    From RecyclerViewEvent with Apache License 2.0 5 votes vote down vote up
public void drawHorizontal(Canvas c, RecyclerView parent) {
    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                .getLayoutParams();
        final int left = child.getLeft() - params.leftMargin;
        final int right = child.getRight() + params.rightMargin
                + lineWidth;
        final int top = child.getBottom() + params.bottomMargin;
        final int bottom = top + lineWidth;
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 10
Source File: GridDividerDecorator.java    From AlbumSelector with Apache License 2.0 5 votes vote down vote up
private void drawBottomDivider(Canvas c, RecyclerView parent) {
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                .getLayoutParams();
        final int left = child.getLeft() - params.leftMargin;
        final int right = child.getRight() - params.rightMargin + mDividerSize;
        final int top = child.getBottom() + params.bottomMargin +
                Math.round(ViewCompat.getTranslationY(child));
        final int bottom = top + mDividerSize;
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 11
Source File: Y_DividerItemDecoration.java    From Y_DividerItemDecoration with Apache License 2.0 5 votes vote down vote up
private void drawChildRightVertical(View child, Canvas c, RecyclerView parent, @ColorInt int color, int lineWidthPx, int startPaddingPx, int endPaddingPx) {

        int topPadding = 0;
        int bottomPadding = 0;

        if (startPaddingPx <= 0) {
            //padding<0当作==0处理
            //上下左右默认分割线的两头都出头一个分割线的宽度,避免十字交叉的时候,交叉点是空白
            topPadding = -lineWidthPx;
        } else {
            topPadding = startPaddingPx;
        }
        if (endPaddingPx <= 0) {
            bottomPadding = lineWidthPx;
        } else {
            bottomPadding = -endPaddingPx;
        }

        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                .getLayoutParams();
        int top = child.getTop() - params.topMargin + topPadding;
        int bottom = child.getBottom() + params.bottomMargin + bottomPadding;
        int left = child.getRight() + params.rightMargin;
        int right = left + lineWidthPx;
        mPaint.setColor(color);

        c.drawRect(left, top, right, bottom, mPaint);

    }
 
Example 12
Source File: DidiViewDragHelper.java    From DidiLayout with Apache License 2.0 5 votes vote down vote up
/**
 * Find the topmost child under the given point within the parent view's coordinate system.
 * The child order is determined using {@link Callback#getOrderedChildIndex(int)}.
 *
 * @param x X position to test in the parent's coordinate system
 * @param y Y position to test in the parent's coordinate system
 * @return The topmost child view under (x, y) or null if none found.
 */
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;
        }
    }
    return null;
}
 
Example 13
Source File: SnappyRecyclerView.java    From CustomViewSets with Apache License 2.0 5 votes vote down vote up
@Override
    public void onScrollStateChanged(int state) {
        super.onScrollStateChanged(state);

        // If you tap on the phone while the RecyclerView is scrolling it will stop in the middle.
        // This code fixes this. This code is not strictly necessary but it improves the behaviour.

        if (state == SCROLL_STATE_IDLE) {
            LinearLayoutManager linearLayoutManager = (LinearLayoutManager) getLayoutManager();

//            int screenWidth = Resources.getSystem().getDisplayMetrics().widthPixels;
            int screenWidth = getMeasuredWidth();
            // views on the screen
            int lastVisibleItemPosition = linearLayoutManager.findLastVisibleItemPosition();
            View lastView = linearLayoutManager.findViewByPosition(lastVisibleItemPosition);
            int firstVisibleItemPosition = linearLayoutManager.findFirstVisibleItemPosition();
            View firstView = linearLayoutManager.findViewByPosition(firstVisibleItemPosition);

            // distance we need to scroll
            int leftMargin = (screenWidth - lastView.getWidth()) / 2;
            int rightMargin = (screenWidth - firstView.getWidth()) / 2 + firstView.getWidth();
            int leftEdge = lastView.getLeft();
            int rightEdge = firstView.getRight();
            int scrollDistanceLeft = leftEdge - leftMargin;
            int scrollDistanceRight = rightMargin - rightEdge;

            if (leftEdge > screenWidth / 2) {
                smoothScrollBy(-scrollDistanceRight, 0);
            } else if (rightEdge < screenWidth / 2) {
                smoothScrollBy(scrollDistanceLeft, 0);
            }
        }
    }
 
Example 14
Source File: ViewDragHelper.java    From android-recipes-app with Apache License 2.0 5 votes vote down vote up
/**
 * Determine if the supplied view is under the given point in the
 * parent view's coordinate system.
 *
 * @param view Child view of the parent to hit test
 * @param x X position to test in the parent's coordinate system
 * @param y Y position to test in the parent's coordinate system
 * @return true if the supplied view is under the given point, false otherwise
 */
public boolean isViewUnder(View view, int x, int y) {
    if (view == null) {
        return false;
    }
    return x >= view.getLeft() &&
            x < view.getRight() &&
            y >= view.getTop() &&
            y < view.getBottom();
}
 
Example 15
Source File: BoardView.java    From DragListView with Apache License 2.0 5 votes vote down vote up
public void scrollToColumn(int column, boolean animate) {
    if (mLists.size() <= column) {
        return;
    }

    View parent = (View) mLists.get(column).getParent();
    MarginLayoutParams parentLayoutParams = (MarginLayoutParams) parent.getLayoutParams();
    int newX = 0;
    switch (mSnapPosition) {
        case LEFT:
            newX = parent.getLeft() - parentLayoutParams.leftMargin;
            break;
        case CENTER:
            int indent = (getMeasuredWidth() - parent.getMeasuredWidth() - parentLayoutParams.leftMargin - parentLayoutParams.rightMargin) / 2;
            newX = parent.getLeft() - parentLayoutParams.leftMargin - indent;
            break;
        case RIGHT:
            newX = parent.getRight() + parentLayoutParams.rightMargin - getMeasuredWidth();
            break;
    }

    int maxScroll = mRootLayout.getMeasuredWidth() - getMeasuredWidth();
    newX = newX < 0 ? 0 : newX;
    newX = newX > maxScroll ? maxScroll : newX;
    if (getScrollX() != newX) {
        mScroller.forceFinished(true);
        if (animate) {
            mScroller.startScroll(getScrollX(), getScrollY(), newX - getScrollX(), 0, SCROLL_ANIMATION_DURATION);
            ViewCompat.postInvalidateOnAnimation(this);
        } else {
            scrollTo(newX, getScrollY());
        }
    }

    int oldColumn = mCurrentColumn;
    mCurrentColumn = column;
    if (mBoardListener != null && oldColumn != mCurrentColumn) {
        mBoardListener.onFocusedColumnChanged(oldColumn, mCurrentColumn);
    }
}
 
Example 16
Source File: PagerSlidingTabStrip.java    From ScrollableLayout with MIT License 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
	super.onDraw(canvas);

	if (isInEditMode() || tabCount == 0) {
		return;
	}

	final int height = getHeight();

	// draw indicator line

	rectPaint.setColor(indicatorColor);

	// default: line below current tab
	View currentTab = tabsContainer.getChildAt(currentPosition);
	float lineLeft = currentTab.getLeft();
	float lineRight = currentTab.getRight();

	// if there is an offset, start interpolating left and right coordinates between current and next tab
	if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

		View nextTab = tabsContainer.getChildAt(currentPosition + 1);
		final float nextTabLeft = nextTab.getLeft();
		final float nextTabRight = nextTab.getRight();

		lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
		lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
	}

	canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);

	// draw underline

	rectPaint.setColor(underlineColor);
	canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

	// draw divider

	dividerPaint.setColor(dividerColor);
	for (int i = 0; i < tabCount - 1; i++) {
		View tab = tabsContainer.getChildAt(i);
		canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
	}
}
 
Example 17
Source File: ViewHelper.java    From Cybernet-VPN with GNU General Public License v3.0 4 votes vote down vote up
@SuppressLint("NewApi")
static int getRight(View v) {
    return (int) (v.getRight() + v.getTranslationX());
}
 
Example 18
Source File: GridLayoutManager.java    From TvRecyclerView with Apache License 2.0 4 votes vote down vote up
int getOpticalRight(View view) {
    return view.getRight() - mDecorInsets.right;
}
 
Example 19
Source File: WeSwipeHelper.java    From monero-wallet-android-app with MIT License 4 votes vote down vote up
private List<RecyclerView.ViewHolder> findSwapTargets(RecyclerView.ViewHolder viewHolder) {
    if (mSwapTargets == null) {
        mSwapTargets = new ArrayList<RecyclerView.ViewHolder>();
        mDistances = new ArrayList<Integer>();
    } else {
        mSwapTargets.clear();
        mDistances.clear();
    }
    final int margin = mCallback.getBoundingBoxMargin();
    final int left = Math.round(mSelectedStartX + mDx) - margin;
    final int top = Math.round(mSelectedStartY + mDy) - margin;
    final int right = left + viewHolder.itemView.getWidth() + 2 * margin;
    final int bottom = top + viewHolder.itemView.getHeight() + 2 * margin;
    final int centerX = (left + right) / 2;
    final int centerY = (top + bottom) / 2;
    final RecyclerView.LayoutManager lm = mRecyclerView.getLayoutManager();
    final int childCount = lm.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View other = lm.getChildAt(i);
        if (other == viewHolder.itemView) {
            continue; //myself!
        }
        if (other.getBottom() < top || other.getTop() > bottom
                || other.getRight() < left || other.getLeft() > right) {
            continue;
        }
        final RecyclerView.ViewHolder otherVh = mRecyclerView.getChildViewHolder(other);
        if (mCallback.canDropOver(mRecyclerView, mSelected, otherVh)) {
            // find the index to add
            final int dx = Math.abs(centerX - (other.getLeft() + other.getRight()) / 2);
            final int dy = Math.abs(centerY - (other.getTop() + other.getBottom()) / 2);
            final int dist = dx * dx + dy * dy;

            int pos = 0;
            final int cnt = mSwapTargets.size();
            for (int j = 0; j < cnt; j++) {
                if (dist > mDistances.get(j)) {
                    pos++;
                } else {
                    break;
                }
            }
            mSwapTargets.add(pos, otherVh);
            mDistances.add(pos, dist);
        }
    }
    return mSwapTargets;
}
 
Example 20
Source File: DetailsOverviewRowPresenter.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
private int getViewCenter(View view) {
    return (view.getRight() - view.getLeft()) / 2;
}