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

The following examples show how to use android.view.View#getLeft() . 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: SlidingPaneLayout.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
public void draw(Canvas canvas)
{
    super.draw(canvas);
    View view;
    if (getChildCount() > 1)
    {
        view = getChildAt(1);
    } else
    {
        view = null;
    }
    if (view == null || h == null)
    {
        return;
    } else
    {
        int i1 = h.getIntrinsicWidth();
        int j1 = view.getLeft();
        int k1 = view.getTop();
        int l1 = view.getBottom();
        int i2 = j1 - i1;
        h.setBounds(i2, k1, j1, l1);
        h.draw(canvas);
        return;
    }
}
 
Example 2
Source File: DayPickerView.java    From MaterialDateTimePicker with Apache License 2.0 6 votes vote down vote up
public @Nullable MonthView getMostVisibleMonth() {
    boolean verticalScroll = mController.getScrollOrientation() == DatePickerDialog.ScrollOrientation.VERTICAL;
    final int maxSize = verticalScroll ? getHeight() : getWidth();
    int maxDisplayedSize = 0;
    int i = 0;
    int size = 0;
    MonthView mostVisibleMonth = null;

    while (size < maxSize) {
        View child = getChildAt(i);
        if (child == null) {
            break;
        }
        size = verticalScroll ? child.getBottom() : child.getRight();
        int endPosition = verticalScroll ? child.getTop() : child.getLeft();
        int displayedSize = Math.min(size, maxSize) - Math.max(0, endPosition);
        if (displayedSize > maxDisplayedSize) {
            mostVisibleMonth = (MonthView) child;
            maxDisplayedSize = displayedSize;
        }
        i++;
    }
    return mostVisibleMonth;
}
 
Example 3
Source File: TwoDScrollView.java    From AndroidTreeView with Apache License 2.0 6 votes vote down vote up
/**
  * Finds the next focusable component that fits in this View's bounds
  * (excluding fading edges) pretending that this View's top is located at
  * the parameter top.
  *
  * @param topFocus           look for a candidate is the one at the top of the bounds
  *                           if topFocus is true, or at the bottom of the bounds if topFocus is
  *                           false
  * @param top                the top offset of the bounds in which a focusable must be
  *                           found (the fading edge is assumed to start at this position)
  * @param preferredFocusable the View that has highest priority and will be
  *                           returned if it is within my bounds (null is valid)
  * @return the next focusable component in the bounds or null if none can be
  * found
  */
 private View findFocusableViewInMyBounds(final boolean topFocus, final int top, final boolean leftFocus, final int left, View preferredFocusable) {
/*
* The fading edge's transparent side should be considered for focus
* since it's mostly visible, so we divide the actual fading edge length
* by 2.
*/
     final int verticalFadingEdgeLength = getVerticalFadingEdgeLength() / 2;
     final int topWithoutFadingEdge = top + verticalFadingEdgeLength;
     final int bottomWithoutFadingEdge = top + getHeight() - verticalFadingEdgeLength;
     final int horizontalFadingEdgeLength = getHorizontalFadingEdgeLength() / 2;
     final int leftWithoutFadingEdge = left + horizontalFadingEdgeLength;
     final int rightWithoutFadingEdge = left + getWidth() - horizontalFadingEdgeLength;

     if ((preferredFocusable != null)
             && (preferredFocusable.getTop() < bottomWithoutFadingEdge)
             && (preferredFocusable.getBottom() > topWithoutFadingEdge)
             && (preferredFocusable.getLeft() < rightWithoutFadingEdge)
             && (preferredFocusable.getRight() > leftWithoutFadingEdge)) {
         return preferredFocusable;
     }
     return findFocusableViewInBounds(topFocus, topWithoutFadingEdge, bottomWithoutFadingEdge, leftFocus, leftWithoutFadingEdge, rightWithoutFadingEdge);
 }
 
Example 4
Source File: RecyclerListView.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public View findChildViewUnder(float x, float y) {
    final int count = getChildCount();
    for (int a = 0; a < 2; a++) {
        for (int i = count - 1; i >= 0; i--) {
            final View child = getChildAt(i);
            final float translationX = a == 0 ? child.getTranslationX() : 0;
            final float translationY = a == 0 ? child.getTranslationY() : 0;
            if (x >= child.getLeft() + translationX
                    && x <= child.getRight() + translationX
                    && y >= child.getTop() + translationY
                    && y <= child.getBottom() + translationY) {
                return child;
            }
        }
    }
    return null;
}
 
Example 5
Source File: CommonTabLayout.java    From AndroidUiKit with Apache License 2.0 6 votes vote down vote up
private void calcOffset() {
        final View currentTabView = mTabsContainer.getChildAt(this.mCurrentTab);
        mCurrentP.left = currentTabView.getLeft();
        mCurrentP.right = currentTabView.getRight();

        final View lastTabView = mTabsContainer.getChildAt(this.mLastTab);
        mLastP.left = lastTabView.getLeft();
        mLastP.right = lastTabView.getRight();

//        Log.d("AAA", "mLastP--->" + mLastP.left + "&" + mLastP.right);
//        Log.d("AAA", "mCurrentP--->" + mCurrentP.left + "&" + mCurrentP.right);
        if (mLastP.left == mCurrentP.left && mLastP.right == mCurrentP.right) {
            invalidate();
        } else {
            mValueAnimator.setObjectValues(mLastP, mCurrentP);
            if (mIndicatorBounceEnable) {
                mValueAnimator.setInterpolator(mInterpolator);
            }

            if (mIndicatorAnimDuration < 0) {
                mIndicatorAnimDuration = mIndicatorBounceEnable ? 500 : 250;
            }
            mValueAnimator.setDuration(mIndicatorAnimDuration);
            mValueAnimator.start();
        }
    }
 
Example 6
Source File: AbsHListView.java    From letv with Apache License 2.0 6 votes vote down vote up
protected int computeHorizontalScrollOffset() {
    int firstPosition = this.mFirstPosition;
    int childCount = getChildCount();
    if (firstPosition < 0 || childCount <= 0) {
        return 0;
    }
    if (this.mSmoothScrollbarEnabled) {
        View view = getChildAt(0);
        int left = view.getLeft();
        int width = view.getWidth();
        if (width > 0) {
            return Math.max(((firstPosition * 100) - ((left * 100) / width)) + ((int) (((((float) getScrollX()) / ((float) getWidth())) * ((float) this.mItemCount)) * 100.0f)), 0);
        }
        return 0;
    }
    int index;
    int count = this.mItemCount;
    if (firstPosition == 0) {
        index = 0;
    } else if (firstPosition + childCount == count) {
        index = count;
    } else {
        index = firstPosition + (childCount / 2);
    }
    return (int) (((float) firstPosition) + (((float) childCount) * (((float) index) / ((float) count))));
}
 
Example 7
Source File: MyTaskAdapter.java    From Conquer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCheckCanStartDrag(TaskViewHolder holder, int position, int x, int y) {
    // x, y --- relative from the itemView's top-left
    final View mContainerView = holder.mContainer;
    final View dragHandleView = holder.mDragHandle;

    final int offsetX = mContainerView.getLeft() + (int) (ViewCompat.getTranslationX(mContainerView) + 0.5f);
    final int offsetY = mContainerView.getTop() + (int) (ViewCompat.getTranslationY(mContainerView) + 0.5f);

    return hitTest(dragHandleView, x - offsetX, y - offsetY);
}
 
Example 8
Source File: Utils.java    From KUtils with Apache License 2.0 5 votes vote down vote up
static int getStart(View v, boolean withoutPadding) {
  if (v == null) {
    return 0;
  }
  if (isLayoutRtl(v)) {
    return (withoutPadding) ? v.getRight() - getPaddingStart(v) : v.getRight();
  } else {
    return (withoutPadding) ? v.getLeft() + getPaddingStart(v) : v.getLeft();
  }
}
 
Example 9
Source File: ViewGroupFocusHelper.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
private void computeLocationRelativeToContainer(View child, Rect outRect) {
    View parent = (View) child.getParent();
    outRect.left += child.getLeft();
    outRect.top += child.getTop();

    if (parent != mContainer) {
        if (parent instanceof PagedView) {
            PagedView page = (PagedView) parent;
            outRect.left -= page.getScrollForPage(page.indexOfChild(child));
        }

        computeLocationRelativeToContainer(parent, outRect);
    }
}
 
Example 10
Source File: TouchTargetHelper.java    From react-native-GPay with MIT License 5 votes vote down vote up
/**
 * Returns whether the touch point is within the child View
 * It is transform aware and will invert the transform Matrix to find the true local points
 * This code is taken from {@link ViewGroup#isTransformedTouchPointInView()}
 */
private static boolean isTransformedTouchPointInView(
    float x,
    float y,
    ViewGroup parent,
    View child,
    PointF outLocalPoint) {
  float localX = x + parent.getScrollX() - child.getLeft();
  float localY = y + parent.getScrollY() - child.getTop();
  Matrix matrix = child.getMatrix();
  if (!matrix.isIdentity()) {
    float[] localXY = mMatrixTransformCoords;
    localXY[0] = localX;
    localXY[1] = localY;
    Matrix inverseMatrix = mInverseMatrix;
    matrix.invert(inverseMatrix);
    inverseMatrix.mapPoints(localXY);
    localX = localXY[0];
    localY = localXY[1];
  }
  if (child instanceof ReactHitSlopView && ((ReactHitSlopView) child).getHitSlopRect() != null) {
    Rect hitSlopRect = ((ReactHitSlopView) child).getHitSlopRect();
    if ((localX >= -hitSlopRect.left && localX < (child.getRight() - child.getLeft()) + hitSlopRect.right)
        && (localY >= -hitSlopRect.top && localY < (child.getBottom() - child.getTop()) + hitSlopRect.bottom)) {
      outLocalPoint.set(localX, localY);
      return true;
    }

    return false;
  } else {
    if ((localX >= 0 && localX < (child.getRight() - child.getLeft()))
        && (localY >= 0 && localY < (child.getBottom() - child.getTop()))) {
      outLocalPoint.set(localX, localY);
      return true;
    }

    return false;
  }
}
 
Example 11
Source File: ScrollingTabContainerView.java    From android-apps with MIT License 5 votes vote down vote up
public void animateToTab(final int position) {
    final View tabView = mTabLayout.getChildAt(position);
    if (mTabSelector != null) {
        removeCallbacks(mTabSelector);
    }
    mTabSelector = new Runnable() {
        public void run() {
            final int scrollPos = tabView.getLeft() - (getWidth() - tabView.getWidth()) / 2;
            smoothScrollTo(scrollPos, 0);
            mTabSelector = null;
        }
    };
    post(mTabSelector);
}
 
Example 12
Source File: Utils.java    From SmartTabLayout with Apache License 2.0 5 votes vote down vote up
static int getStart(View v, boolean withoutPadding) {
  if (v == null) {
    return 0;
  }
  if (isLayoutRtl(v)) {
    return (withoutPadding) ? v.getRight() - getPaddingStart(v) : v.getRight();
  } else {
    return (withoutPadding) ? v.getLeft() + getPaddingStart(v) : v.getLeft();
  }
}
 
Example 13
Source File: ViewDragHelper.java    From CoreModule 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 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 14
Source File: DividerHelper.java    From LRecyclerView with Apache License 2.0 5 votes vote down vote up
public static void drawLeftAlignItem(Canvas canvas, Drawable drawable, View child, ViewGroup.MarginLayoutParams params) {

        final int top = child.getTop() - params.topMargin;
        final int bottom = child.getBottom() + params.bottomMargin;
        final int left = child.getLeft() - params.leftMargin - drawable.getIntrinsicWidth();
        final int right = left + drawable.getIntrinsicWidth();

        drawable.setBounds(left, top, right, bottom);

        drawable.draw(canvas);
    }
 
Example 15
Source File: VerticalViewPager.java    From VerticalViewPager with MIT License 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 dy 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 dy.
 */
protected boolean canScroll(View v, boolean checkV, 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, dy, x + scrollX - child.getLeft(),
                            y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    // to vertical scroll inner WebViews for Froyo+
    if (v instanceof ExtendedWebView) {
        return ((ExtendedWebView) v).canScrollVertical(-dy);
    } else {
        return checkV && ViewCompat.canScrollVertically(v, -dy);
    }
}
 
Example 16
Source File: VerticalDividerItemDecoration.java    From RecyclerView-FlexibleDivider with Apache License 2.0 4 votes vote down vote up
@Override
protected Rect getDividerBound(int position, RecyclerView parent, View child) {
    Rect bounds = new Rect(0, 0, 0, 0);
    int transitionX = (int) ViewCompat.getTranslationX(child);
    int transitionY = (int) ViewCompat.getTranslationY(child);
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
    bounds.top = parent.getPaddingTop() +
            mMarginProvider.dividerTopMargin(position, parent) + transitionY;
    bounds.bottom = parent.getHeight() - parent.getPaddingBottom() -
            mMarginProvider.dividerBottomMargin(position, parent) + transitionY;

    int dividerSize = getDividerSize(position, parent);
    boolean isReverseLayout = isReverseLayout(parent);
    if (mDividerType == DividerType.DRAWABLE) {
        // set left and right position of divider
        if (isReverseLayout) {
            bounds.right = child.getLeft() - params.leftMargin + transitionX;
            bounds.left = bounds.right - dividerSize;
        } else {
            bounds.left = child.getRight() + params.rightMargin + transitionX;
            bounds.right = bounds.left + dividerSize;
        }
    } else {
        // set center point of divider
        int halfSize = dividerSize / 2;
        if (isReverseLayout) {
            bounds.left = child.getLeft() - params.leftMargin - halfSize + transitionX;
        } else {
            bounds.left = child.getRight() + params.rightMargin + halfSize + transitionX;
        }
        bounds.right = bounds.left;
    }

    if (mPositionInsideItem) {
        if (isReverseLayout) {
            bounds.left += dividerSize;
            bounds.right += dividerSize;
        } else {
            bounds.left -= dividerSize;
            bounds.right -= dividerSize;
        }
    }

    return bounds;
}
 
Example 17
Source File: FastScroller.java    From AndroidFastScroll with Apache License 2.0 4 votes vote down vote up
private boolean isInView(@NonNull View view, float x, float y) {
    int scrollX = mView.getScrollX();
    int scrollY = mView.getScrollY();
    return x >= view.getLeft() - scrollX && x < view.getRight() - scrollX
            && y >= view.getTop() - scrollY && y < view.getBottom() - scrollY;
}
 
Example 18
Source File: TwoWayGridView.java    From recent-images with MIT License 4 votes vote down vote up
private void correctTooRight(int numRows, int horizontalSpacing, int childCount) {
	if (DEBUG) Log.i(TAG, "correctTooRight() numRows: " + numRows + " horizontalSpacing: " + horizontalSpacing + M_FIRST_POSITION + mFirstPosition);
	if (mFirstPosition == 0 && childCount > 0) {
		// Get the first child ...
		final View firstChild = getChildAt(0);

		// ... and its left edge
		final int firstLeft = firstChild.getLeft();

		// This is left of our drawable area
		final int start = mListPadding.left;

		// This is right of our drawable area
		final int end = (getRight() - getLeft()) - mListPadding.right;

		// This is how far the left edge of the first view is from the left of the
		// drawable area
		int leftOffset = firstLeft - start;
		final View lastChild = getChildAt(childCount - 1);
		final int lastRight = lastChild.getRight();
		final int lastPosition = mFirstPosition + childCount - 1;

		// Make sure we are 1) Too right, and 2) Either there are more columns to right of the
		// last column or the last column is scrolled off the right of the drawable area
		if (leftOffset > 0 && (lastPosition < mItemCount - 1 || lastRight > end))  {
			if (lastPosition == mItemCount - 1 ) {
				// Don't pull the right too far left
				leftOffset = Math.min(leftOffset, lastRight - end);
			}

			// Move everything left
			offsetChildrenLeftAndRight(-leftOffset);
			if (lastPosition < mItemCount - 1) {
				// Fill the gap that was opened to right of the last position with
				// more columns, if possible
				fillRight(lastPosition + (!mStackFromBottom ? 1 : numRows),
						lastChild.getRight() + horizontalSpacing);
				// Close up the remaining gap
				adjustViewsLeftOrRight();
			}
		}
	}
}
 
Example 19
Source File: FlipPageTransformer.java    From BuildmLearn-Toolkit-Android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void setTranslation(View page) {
    ViewPager viewPager = (ViewPager) page.getParent();
    int scroll = viewPager.getScrollX() - page.getLeft();
    page.setTranslationX(scroll);
}
 
Example 20
Source File: ScrollableTabView.java    From SweetMusicPlayer with Apache License 2.0 3 votes vote down vote up
private void selectTab(int position){
		for(int i=0;i<mContainer.getChildCount();i++)
			mContainer.getChildAt(i).setSelected(i==position);
		

		View selectedTab=mContainer.getChildAt(position);
		
		final int w=selectedTab.getMeasuredWidth();
		final int l=selectedTab.getLeft();
		
		int x=l-this.getWidth()/2+w/2;
		
//		scrollTo(x, this.getScrollY());
	}