List of usage examples for android.view View getLeft
@ViewDebug.CapturedViewProperty public final int getLeft()
From source file:com.bahrini.pager.pager.RtlSupportViewPager.java
/** * This method will be invoked when the current page is scrolled, either as part * of a programmatically initiated smooth scroll or a user initiated touch scroll. * If you override this method you must call through to the superclass implementation * (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled * returns.//from w ww. j a v a 2 s .co m * * @param position Position index of the first page currently being displayed. * Page position+1 will be visible if positionOffset is nonzero. * @param offset Value from [0, 1) indicating the offset from the page at position. * @param offsetPixels Value in pixels indicating the offset from position. */ protected void onPageScrolled(int position, float offset, int offsetPixels) { // Offset any decor views if needed - keep them on-screen at all times. if (mDecorChildCount > 0) { final int scrollX = getScrollX(); int paddingLeft = getPaddingLeft(); int paddingRight = getPaddingRight(); final int width = getWidth(); final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (!lp.isDecor) continue; final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; int childLeft = 0; switch (hgrav) { default: childLeft = paddingLeft; break; case Gravity.LEFT: childLeft = paddingLeft; paddingLeft += child.getWidth(); break; case Gravity.CENTER_HORIZONTAL: childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft); break; case Gravity.RIGHT: childLeft = width - paddingRight - child.getMeasuredWidth(); paddingRight += child.getMeasuredWidth(); break; } childLeft += scrollX; final int childOffset = childLeft - child.getLeft(); if (childOffset != 0) { child.offsetLeftAndRight(childOffset); } } } if (mOnPageChangeListener != null) { mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels); } if (mInternalPageChangeListener != null) { mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels); } if (mSlidingTabPageChangeListener != null) { mSlidingTabPageChangeListener.onPageScrolled(position, offset, offsetPixels); } if (mPageTransformer != null) { final int scrollX = getScrollX(); final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp.isDecor) continue; final float transformPos = (float) (child.getLeft() - scrollX) / getClientWidth(); mPageTransformer.transformPage(child, transformPos); } } mCalledSuper = true; }
From source file:com.appunite.list.HorizontalListView.java
/** * Fills the grid based on positioning the new selection at a specific * location. The selection may be moved so that it does not intersect the * faded edges. The grid is then filled upwards and downwards from there. * * @param selectedLeft Where the selected item should be * @param childrenLeft Where to start drawing children * @param childrenRight Last pixel where children can be drawn * @return The view that currently has selection *///from w w w .j a v a 2s . c o m private View fillFromSelection(int selectedLeft, int childrenLeft, int childrenRight) { int fadingEdgeLength = getHorizontalFadingEdgeLength(); final int selectedPosition = mSelectedPosition; View sel; final int leftSelectionPixel = getLeftSelectionPixel(childrenLeft, fadingEdgeLength, selectedPosition); final int rightSelectionPixel = getRightSelectionPixel(childrenRight, fadingEdgeLength, selectedPosition); sel = makeAndAddView(selectedPosition, selectedLeft, true, mListPadding.top, true); // Some of the newly selected item extends below the bottom of the list if (sel.getRight() > rightSelectionPixel) { // Find space available above the selection into which we can scroll // upwards final int spaceAbove = sel.getLeft() - leftSelectionPixel; // Find space required to bring the bottom of the selected item // fully into view final int spaceBelow = sel.getRight() - rightSelectionPixel; final int offset = Math.min(spaceAbove, spaceBelow); // Now offset the selected item to get it into view sel.offsetLeftAndRight(-offset); } else if (sel.getLeft() < leftSelectionPixel) { // Find space required to bring the top of the selected item fully // into view final int spaceAbove = leftSelectionPixel - sel.getLeft(); // Find space available below the selection into which we can scroll // downwards final int spaceBelow = rightSelectionPixel - sel.getRight(); final int offset = Math.min(spaceAbove, spaceBelow); // Offset the selected item to get it into view sel.offsetLeftAndRight(offset); } // Fill in views above and below fillToLeftAndRight(sel, selectedPosition); if (!mStackFromRight) { correctTooHigh(getChildCount()); } else { correctTooLow(getChildCount()); } return sel; }
From source file:com.appunite.list.HorizontalListView.java
/** * Do an arrow scroll based on focus searching. If a new view is * given focus, return the selection delta and amount to scroll via * an {@link ArrowScrollFocusResult}, otherwise, return null. * * @param direction either {@link android.view.View#FOCUS_UP} or * {@link android.view.View#FOCUS_DOWN}. * @return The result if focus has changed, or <code>null</code>. */// ww w .j a v a2s . c om private ArrowScrollFocusResult arrowScrollFocused(final int direction) { final View selectedView = getSelectedView(); View newFocus; if (selectedView != null && selectedView.hasFocus()) { View oldFocus = selectedView.findFocus(); newFocus = FocusFinder.getInstance().findNextFocus(this, oldFocus, direction); } else { if (direction == View.FOCUS_RIGHT) { final boolean topFadingEdgeShowing = (mFirstPosition > 0); final int listLeft = mListPadding.left + (topFadingEdgeShowing ? getArrowScrollPreviewLength() : 0); final int xSearchPoint = (selectedView != null && selectedView.getLeft() > listLeft) ? selectedView.getLeft() : listLeft; mTempRect.set(xSearchPoint, 0, xSearchPoint, 0); } else { final boolean rightFadingEdgeShowing = (mFirstPosition + getChildCount() - 1) < mItemCount; final int listRight = getWidth() - mListPadding.right - (rightFadingEdgeShowing ? getArrowScrollPreviewLength() : 0); final int xSearchPoint = (selectedView != null && selectedView.getRight() < listRight) ? selectedView.getRight() : listRight; mTempRect.set(xSearchPoint, 0, xSearchPoint, 0); } newFocus = FocusFinder.getInstance().findNextFocusFromRect(this, mTempRect, direction); } if (newFocus != null) { final int positionOfNewFocus = positionOfNewFocus(newFocus); // if the focus change is in a different new position, make sure // we aren't jumping over another selectable position if (mSelectedPosition != INVALID_POSITION && positionOfNewFocus != mSelectedPosition) { final int selectablePosition = lookForSelectablePositionOnScreen(direction); if (selectablePosition != INVALID_POSITION && ((direction == View.FOCUS_RIGHT && selectablePosition < positionOfNewFocus) || (direction == View.FOCUS_LEFT && selectablePosition > positionOfNewFocus))) { return null; } } int focusScroll = amountToScrollToNewFocus(direction, newFocus, positionOfNewFocus); final int maxScrollAmount = getMaxScrollAmount(); if (focusScroll < maxScrollAmount) { // not moving too far, safe to give next view focus newFocus.requestFocus(direction); mArrowScrollFocusResult.populate(positionOfNewFocus, focusScroll); return mArrowScrollFocusResult; } else if (distanceToView(newFocus) < maxScrollAmount) { // Case to consider: // too far to get entire next focusable on screen, but by going // max scroll amount, we are getting it at least partially in view, // so give it focus and scroll the max ammount. newFocus.requestFocus(direction); mArrowScrollFocusResult.populate(positionOfNewFocus, maxScrollAmount); return mArrowScrollFocusResult; } } return null; }
From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java
/** * Fills the grid based on positioning the new selection at a specific location. The selection may be moved so that it does not * intersect the faded edges. The grid is then filled upwards and downwards from there. * //from w w w . j a v a 2 s. c o m * @param selectedLeft * Where the selected item should be * @param childrenLeft * Where to start drawing children * @param childrenRight * Last pixel where children can be drawn * @return The view that currently has selection */ private View fillFromSelection(int selectedLeft, int childrenLeft, int childrenRight) { int fadingEdgeLength = getHorizontalFadingEdgeLength(); final int selectedPosition = mSelectedPosition; View sel; final int leftSelectionPixel = getLeftSelectionPixel(childrenLeft, fadingEdgeLength, selectedPosition); final int rightSelectionPixel = getRightSelectionPixel(childrenRight, fadingEdgeLength, selectedPosition); sel = makeAndAddView(selectedPosition, selectedLeft, true, mListPadding.top, true); // Some of the newly selected item extends below the bottom of the list if (sel.getRight() > rightSelectionPixel) { // Find space available above the selection into which we can scroll // upwards final int spaceBefore = sel.getLeft() - leftSelectionPixel; // Find space required to bring the bottom of the selected item // fully into view final int spaceAfter = sel.getRight() - rightSelectionPixel; final int offset = Math.min(spaceBefore, spaceAfter); // Now offset the selected item to get it into view sel.offsetLeftAndRight(-offset); } else if (sel.getLeft() < leftSelectionPixel) { // Find space required to bring the top of the selected item fully // into view final int spaceBefore = leftSelectionPixel - sel.getLeft(); // Find space available below the selection into which we can scroll // downwards final int spaceAfter = rightSelectionPixel - sel.getRight(); final int offset = Math.min(spaceBefore, spaceAfter); // Offset the selected item to get it into view sel.offsetLeftAndRight(offset); } // Fill in views above and below fillBeforeAndAfter(sel, selectedPosition); if (!mStackFromRight) { correctTooWide(getChildCount()); } else { correctTooSmall(getChildCount()); } return sel; }
From source file:com.appunite.list.HorizontalListView.java
/** * Scroll the children by amount, adding a view at the end and removing * views that fall off as necessary./*from w ww. ja v a2 s. com*/ * * @param amount The amount (positive or negative) to scroll. */ private void scrollListItemsBy(int amount) { offsetChildrenLeftAndRightUnhide(amount); final int listRight = getWidth() - mListPadding.right; final int listLeft = mListPadding.left; final RecycleBin recycleBin = mRecycler; if (amount < 0) { // shifted items up // may need to pan views into the bottom space int numChildren = getChildCount(); View last = getChildAt(numChildren - 1); while (last.getRight() < listRight) { final int lastVisiblePosition = mFirstPosition + numChildren - 1; if (lastVisiblePosition < mItemCount - 1) { last = addViewToRight(last, lastVisiblePosition); numChildren++; } else { break; } } // may have brought in the last child of the list that is skinnier // than the fading edge, thereby leaving space at the end. need // to shift back if (last.getRight() < listRight) { offsetChildrenLeftAndRightUnhide(listRight - last.getRight()); } // top views may be panned off screen View first = getChildAt(0); while (first.getRight() < listLeft) { LayoutParams layoutParams = (LayoutParams) first.getLayoutParams(); if (recycleBin.shouldRecycleViewType(layoutParams.viewType)) { recycleBin.addScrapView(first, mFirstPosition); } detachViewFromParent(first); first = getChildAt(0); mFirstPosition++; } } else { // shifted items down View first = getChildAt(0); // may need to pan views into top while ((first.getLeft() > listLeft) && (mFirstPosition > 0)) { first = addViewToLeft(first, mFirstPosition); mFirstPosition--; } // may have brought the very first child of the list in too far and // need to shift it back if (first.getLeft() > listLeft) { offsetChildrenLeftAndRightUnhide(listLeft - first.getLeft()); } int lastIndex = getChildCount() - 1; View last = getChildAt(lastIndex); // bottom view may be panned off screen while (last.getLeft() > listRight) { LayoutParams layoutParams = (LayoutParams) last.getLayoutParams(); if (recycleBin.shouldRecycleViewType(layoutParams.viewType)) { recycleBin.addScrapView(last, mFirstPosition + lastIndex); } detachViewFromParent(last); last = getChildAt(--lastIndex); } } }
From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java
/** * Do an arrow scroll based on focus searching. If a new view is given focus, return the selection delta and amount to scroll via * an {@link ArrowScrollFocusResult}, otherwise, return null. * /*from w w w . ja va 2 s .c om*/ * @param direction * either {@link android.view.View#FOCUS_UP} or {@link android.view.View#FOCUS_DOWN}. * @return The result if focus has changed, or <code>null</code>. */ private ArrowScrollFocusResult arrowScrollFocused(final int direction) { final View selectedView = getSelectedView(); View newFocus; if (selectedView != null && selectedView.hasFocus()) { View oldFocus = selectedView.findFocus(); newFocus = FocusFinder.getInstance().findNextFocus(this, oldFocus, direction); } else { if (direction == View.FOCUS_DOWN) { final boolean leftFadingEdgeShowing = (mFirstPosition > 0); final int listLeft = mListPadding.left + (leftFadingEdgeShowing ? getArrowScrollPreviewLength() : 0); final int xSearchPoint = (selectedView != null && selectedView.getLeft() > listLeft) ? selectedView.getLeft() : listLeft; mTempRect.set(xSearchPoint, 0, xSearchPoint, 0); } else { final boolean rightFadingEdgeShowing = (mFirstPosition + getChildCount() - 1) < mItemCount; final int listRight = getWidth() - mListPadding.right - (rightFadingEdgeShowing ? getArrowScrollPreviewLength() : 0); final int xSearchPoint = (selectedView != null && selectedView.getRight() < listRight) ? selectedView.getRight() : listRight; mTempRect.set(xSearchPoint, 0, xSearchPoint, 0); } newFocus = FocusFinder.getInstance().findNextFocusFromRect(this, mTempRect, direction); } if (newFocus != null) { final int positionOfNewFocus = positionOfNewFocus(newFocus); // if the focus change is in a different new position, make sure // we aren't jumping over another selectable position if (mSelectedPosition != INVALID_POSITION && positionOfNewFocus != mSelectedPosition) { final int selectablePosition = lookForSelectablePositionOnScreen(direction); if (selectablePosition != INVALID_POSITION && ((direction == View.FOCUS_DOWN && selectablePosition < positionOfNewFocus) || (direction == View.FOCUS_UP && selectablePosition > positionOfNewFocus))) { return null; } } int focusScroll = amountToScrollToNewFocus(direction, newFocus, positionOfNewFocus); final int maxScrollAmount = getMaxScrollAmount(); if (focusScroll < maxScrollAmount) { // not moving too far, safe to give next view focus newFocus.requestFocus(direction); mArrowScrollFocusResult.populate(positionOfNewFocus, focusScroll); return mArrowScrollFocusResult; } else if (distanceToView(newFocus) < maxScrollAmount) { // Case to consider: // too far to get entire next focusable on screen, but by going // max scroll amount, we are getting it at least partially in view, // so give it focus and scroll the max ammount. newFocus.requestFocus(direction); mArrowScrollFocusResult.populate(positionOfNewFocus, maxScrollAmount); return mArrowScrollFocusResult; } } return null; }
From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java
/** * Scroll the children by amount, adding a view at the end and removing views that fall off as necessary. * //from w w w . j a va2 s . com * @param amount * The amount (positive or negative) to scroll. */ private void scrollListItemsBy(int amount) { offsetChildrenLeftAndRight(amount); final int listRight = getWidth() - mListPadding.right; final int listLeft = mListPadding.left; final AbsHListView.RecycleBin recycleBin = mRecycler; if (amount < 0) { // shifted items up // may need to pan views into the bottom space int numChildren = getChildCount(); View last = getChildAt(numChildren - 1); while (last.getRight() < listRight) { final int lastVisiblePosition = mFirstPosition + numChildren - 1; if (lastVisiblePosition < mItemCount - 1) { last = addViewAfter(last, lastVisiblePosition); numChildren++; } else { break; } } // may have brought in the last child of the list that is skinnier // than the fading edge, thereby leaving space at the end. need // to shift back if (last.getBottom() < listRight) { offsetChildrenLeftAndRight(listRight - last.getRight()); } // top views may be panned off screen View first = getChildAt(0); while (first.getRight() < listLeft) { AbsHListView.LayoutParams layoutParams = (LayoutParams) first.getLayoutParams(); if (recycleBin.shouldRecycleViewType(layoutParams.viewType)) { detachViewFromParent(first); recycleBin.addScrapView(first, mFirstPosition); } else { removeViewInLayout(first); } first = getChildAt(0); mFirstPosition++; } } else { // shifted items down View first = getChildAt(0); // may need to pan views into top while ((first.getLeft() > listLeft) && (mFirstPosition > 0)) { first = addViewBefore(first, mFirstPosition); mFirstPosition--; } // may have brought the very first child of the list in too far and // need to shift it back if (first.getLeft() > listLeft) { offsetChildrenLeftAndRight(listLeft - first.getLeft()); } int lastIndex = getChildCount() - 1; View last = getChildAt(lastIndex); // bottom view may be panned off screen while (last.getLeft() > listRight) { AbsHListView.LayoutParams layoutParams = (LayoutParams) last.getLayoutParams(); if (recycleBin.shouldRecycleViewType(layoutParams.viewType)) { detachViewFromParent(last); recycleBin.addScrapView(last, mFirstPosition + lastIndex); } else { removeViewInLayout(last); } last = getChildAt(--lastIndex); } } }
From source file:com.chinaztt.widget.ViewDragHelper.java
/** * Check if this event as provided to the parent view's onInterceptTouchEvent should * cause the parent to intercept the touch event stream. * * @param ev MotionEvent provided to onInterceptTouchEvent * @return true if the parent view should return true from onInterceptTouchEvent *///from ww w .j a va 2 s . c o m public boolean shouldInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); final int actionIndex = MotionEventCompat.getActionIndex(ev); if (action == MotionEvent.ACTION_DOWN) { // Reset things for a new event stream, just in case we didn't get // the whole previous stream. cancel(); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); final int pointerId = MotionEventCompat.getPointerId(ev, 0); saveInitialMotion(x, y, pointerId); final View toCapture = findTopChildUnder((int) x, (int) y); // Catch a settling view if possible. if (toCapture == mCapturedView && mDragState == STATE_SETTLING) { tryCaptureViewForDrag(toCapture, pointerId); } final int edgesTouched = mInitialEdgesTouched[pointerId]; if ((edgesTouched & mTrackingEdges) != 0) { mCallback.onEdgeTouched(edgesTouched & mTrackingEdges, pointerId); } break; } case MotionEventCompat.ACTION_POINTER_DOWN: { final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex); final float x = MotionEventCompat.getX(ev, actionIndex); final float y = MotionEventCompat.getY(ev, actionIndex); saveInitialMotion(x, y, pointerId); // A ViewDragHelper can only manipulate one view at a time. if (mDragState == STATE_IDLE) { final int edgesTouched = mInitialEdgesTouched[pointerId]; if ((edgesTouched & mTrackingEdges) != 0) { mCallback.onEdgeTouched(edgesTouched & mTrackingEdges, pointerId); } } else if (mDragState == STATE_SETTLING) { // Catch a settling view if possible. final View toCapture = findTopChildUnder((int) x, (int) y); if (toCapture == mCapturedView) { tryCaptureViewForDrag(toCapture, pointerId); } } break; } case MotionEvent.ACTION_MOVE: { if (mInitialMotionX == null || mInitialMotionY == null) break; // First to cross a touch slop over a draggable view wins. Also report edge drags. final int pointerCount = MotionEventCompat.getPointerCount(ev); for (int i = 0; i < pointerCount; i++) { final int pointerId = MotionEventCompat.getPointerId(ev, i); final float x = MotionEventCompat.getX(ev, i); final float y = MotionEventCompat.getY(ev, i); final float dx = x - mInitialMotionX[pointerId]; final float dy = y - mInitialMotionY[pointerId]; final View toCapture = findTopChildUnder((int) x, (int) y); final boolean pastSlop = toCapture != null && checkTouchSlop(toCapture, dx, dy); if (pastSlop) { // check the callback's // getView[Horizontal|Vertical]DragRange methods to know // if you can move at all along an axis, then see if it // would clamp to the same value. If you can't move at // all in every dimension with a nonzero range, bail. final int oldLeft = toCapture.getLeft(); final int targetLeft = oldLeft + (int) dx; final int newLeft = mCallback.clampViewPositionHorizontal(toCapture, targetLeft, (int) dx); final int oldTop = toCapture.getTop(); final int targetTop = oldTop + (int) dy; final int newTop = mCallback.clampViewPositionVertical(toCapture, targetTop, (int) dy); final int horizontalDragRange = mCallback.getViewHorizontalDragRange(toCapture); final int verticalDragRange = mCallback.getViewVerticalDragRange(toCapture); if ((horizontalDragRange == 0 || horizontalDragRange > 0 && newLeft == oldLeft) && (verticalDragRange == 0 || verticalDragRange > 0 && newTop == oldTop)) { break; } } reportNewEdgeDrags(dx, dy, pointerId); if (mDragState == STATE_DRAGGING) { // Callback might have started an edge drag break; } if (pastSlop && tryCaptureViewForDrag(toCapture, pointerId)) { break; } } saveLastMotion(ev); break; } case MotionEventCompat.ACTION_POINTER_UP: { final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex); clearMotionHistory(pointerId); break; } case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: { cancel(); break; } } return mDragState == STATE_DRAGGING; }
From source file:cc.flydev.launcher.Workspace.java
void mapPointFromChildToSelf(View v, float[] xy) { xy[0] += v.getLeft(); xy[1] += v.getTop(); }
From source file:cc.flydev.launcher.Workspace.java
void mapPointFromSelfToChild(View v, float[] xy, Matrix cachedInverseMatrix) { xy[0] = xy[0] - v.getLeft(); xy[1] = xy[1] - v.getTop(); }