List of usage examples for android.view View getLeft
@ViewDebug.CapturedViewProperty public final int getLeft()
From source file:com.appunite.list.HorizontalListView.java
/** * Handle an arrow scroll going up or down. Take into account whether items are selectable, * whether there are focusable items etc. * * @param direction Either {@link android.view.View#FOCUS_LEFT} or {@link android.view.View#FOCUS_RIGHT}. * @return Whether any scrolling, selection or focus change occured. *//*from ww w . j a v a 2 s . co m*/ private boolean arrowScrollImpl(int direction) { if (getChildCount() <= 0) { return false; } View selectedView = getSelectedView(); int selectedPos = mSelectedPosition; int nextSelectedPosition = (direction == View.FOCUS_RIGHT) ? lookForSelectablePosition(selectedPos + 1, true) : lookForSelectablePosition(selectedPos - 1, false); int amountToScroll = amountToScroll(direction, nextSelectedPosition); // if we are moving focus, we may OVERRIDE the default behavior final ArrowScrollFocusResult focusResult = mItemsCanFocus ? arrowScrollFocused(direction) : null; if (focusResult != null) { nextSelectedPosition = focusResult.getSelectedPosition(); amountToScroll = focusResult.getAmountToScroll(); } boolean needToRedraw = focusResult != null; if (nextSelectedPosition != INVALID_POSITION) { handleNewSelectionChange(selectedView, direction, nextSelectedPosition, focusResult != null); setSelectedPositionInt(nextSelectedPosition); setNextSelectedPositionInt(nextSelectedPosition); selectedView = getSelectedView(); selectedPos = nextSelectedPosition; if (mItemsCanFocus && focusResult == null) { // there was no new view found to take focus, make sure we // don't leave focus with the old selection final View focused = getFocusedChild(); if (focused != null) { focused.clearFocus(); } } needToRedraw = true; checkSelectionChanged(); } if (amountToScroll > 0) { scrollListItemsBy((direction == View.FOCUS_UP) ? amountToScroll : -amountToScroll); needToRedraw = true; } // if we didn't find a new focusable, make sure any existing focused // item that was panned off screen gives up focus. if (mItemsCanFocus && (focusResult == null) && selectedView != null && selectedView.hasFocus()) { final View focused = selectedView.findFocus(); if (!isViewAncestorOf(focused, this) || distanceToView(focused) > 0) { focused.clearFocus(); } } // if the current selection is panned off, we need to remove the selection if (nextSelectedPosition == INVALID_POSITION && selectedView != null && !isViewAncestorOf(selectedView, this)) { selectedView = null; hideSelector(); // but we don't want to set the ressurect position (that would make subsequent // unhandled key events bring back the item we just scrolled off!) mResurrectToPosition = INVALID_POSITION; } if (needToRedraw) { if (selectedView != null) { positionSelector(selectedPos, selectedView); mSelectedLeft = selectedView.getLeft(); } if (!awakenScrollBars()) { invalidate(); } invokeOnItemScrollListener(); return true; } return false; }
From source file:com.boutline.sports.helpers.TwoWayView.java
boolean resurrectSelection() { final int childCount = getChildCount(); if (childCount <= 0) { return false; }/*from w ww .j av a 2 s . c om*/ int selectedStart = 0; int selectedPosition; final int start = getStartEdge(); final int end = getEndEdge(); final int firstPosition = mFirstPosition; final int toPosition = mResurrectToPosition; boolean down = true; if (toPosition >= firstPosition && toPosition < firstPosition + childCount) { selectedPosition = toPosition; final View selected = getChildAt(selectedPosition - mFirstPosition); selectedStart = (mIsVertical ? selected.getTop() : selected.getLeft()); } else if (toPosition < firstPosition) { // Default to selecting whatever is first selectedPosition = firstPosition; for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final int childStart = (mIsVertical ? child.getTop() : child.getLeft()); if (i == 0) { // Remember the position of the first item selectedStart = childStart; } if (childStart >= start) { // Found a view whose top is fully visible selectedPosition = firstPosition + i; selectedStart = childStart; break; } } } else { selectedPosition = firstPosition + childCount - 1; down = false; for (int i = childCount - 1; i >= 0; i--) { final View child = getChildAt(i); final int childStart = getChildStartEdge(child); final int childEnd = getChildEndEdge(child); if (i == childCount - 1) { selectedStart = childStart; } if (childEnd <= end) { selectedPosition = firstPosition + i; selectedStart = childStart; break; } } } mResurrectToPosition = INVALID_POSITION; mTouchMode = TOUCH_MODE_REST; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); mSpecificStart = selectedStart; selectedPosition = lookForSelectablePosition(selectedPosition, down); if (selectedPosition >= firstPosition && selectedPosition <= getLastVisiblePosition()) { mLayoutMode = LAYOUT_SPECIFIC; updateSelectorState(); setSelectionInt(selectedPosition); invokeOnItemScrollListener(); } else { selectedPosition = INVALID_POSITION; } return selectedPosition >= 0; }
From source file:com.aliasapps.seq.scroller.TwoWayView.java
private void correctTooHigh(int childCount) { // First see if the last item is visible. If it is not, it is OK for the // top of the list to be pushed up. final int lastPosition = mFirstPosition + childCount - 1; if (lastPosition != mItemCount - 1 || childCount == 0) { return;/*w w w . j a va 2s. co m*/ } // Get the last child ... final View lastChild = getChildAt(childCount - 1); // ... and its end edge final int lastEnd; if (mIsVertical) { lastEnd = lastChild.getBottom(); } else { lastEnd = lastChild.getRight(); } // This is bottom of our drawable area final int start = (mIsVertical ? getPaddingTop() : getPaddingLeft()); final int end = (mIsVertical ? getHeight() - getPaddingBottom() : getWidth() - getPaddingRight()); // This is how far the end edge of the last view is from the end of the // drawable area int endOffset = end - lastEnd; View firstChild = getChildAt(0); int firstStart = (mIsVertical ? firstChild.getTop() : firstChild.getLeft()); // Make sure we are 1) Too high, and 2) Either there are more rows above the // first row or the first row is scrolled off the top of the drawable area if (endOffset > 0 && (mFirstPosition > 0 || firstStart < start)) { if (mFirstPosition == 0) { // Don't pull the top too far down endOffset = Math.min(endOffset, start - firstStart); } // Move everything down offsetChildren(endOffset); if (mFirstPosition > 0) { firstStart = (mIsVertical ? firstChild.getTop() : firstChild.getLeft()); // Fill the gap that was opened above mFirstPosition with more rows, if // possible fillBefore(mFirstPosition - 1, firstStart - mItemMargin); // Close up the remaining gap adjustViewsStartOrEnd(); } } }
From source file:com.aliasapps.seq.scroller.TwoWayView.java
private void correctTooLow(int childCount) { // First see if the first item is visible. If it is not, it is OK for the // bottom of the list to be pushed down. if (mFirstPosition != 0 || childCount == 0) { return;//www . j a v a 2 s.c o m } final View first = getChildAt(0); final int firstStart = (mIsVertical ? first.getTop() : first.getLeft()); final int start = (mIsVertical ? getPaddingTop() : getPaddingLeft()); final int end; if (mIsVertical) { end = getHeight() - getPaddingBottom(); } else { end = getWidth() - getPaddingRight(); } // This is how far the start edge of the first view is from the start of the // drawable area int startOffset = firstStart - start; View last = getChildAt(childCount - 1); int lastEnd = (mIsVertical ? last.getBottom() : last.getRight()); int lastPosition = mFirstPosition + childCount - 1; // Make sure we are 1) Too low, and 2) Either there are more columns/rows below the // last column/row or the last column/row is scrolled off the end of the // drawable area if (startOffset > 0) { if (lastPosition < mItemCount - 1 || lastEnd > end) { if (lastPosition == mItemCount - 1) { // Don't pull the bottom too far up startOffset = Math.min(startOffset, lastEnd - end); } // Move everything up offsetChildren(-startOffset); if (lastPosition < mItemCount - 1) { lastEnd = (mIsVertical ? last.getBottom() : last.getRight()); // Fill the gap that was opened below the last position with more rows, if // possible fillAfter(lastPosition + 1, lastEnd + mItemMargin); // Close up the remaining gap adjustViewsStartOrEnd(); } } else if (lastPosition == mItemCount - 1) { adjustViewsStartOrEnd(); } } }
From source file:com.aliasapps.seq.scroller.TwoWayView.java
private void positionSelector(int position, View selected) { if (position != INVALID_POSITION) { mSelectorPosition = position;//from w ww.j av a 2s .co m } mSelectorRect.set(selected.getLeft(), selected.getTop(), selected.getRight(), selected.getBottom()); final boolean isChildViewEnabled = mIsChildViewEnabled; if (selected.isEnabled() != isChildViewEnabled) { mIsChildViewEnabled = !isChildViewEnabled; if (getSelectedItemPosition() != INVALID_POSITION) { refreshDrawableState(); } } }
From source file:com.aliasapps.seq.scroller.TwoWayView.java
@Override public Parcelable onSaveInstanceState() { Parcelable superState = super.onSaveInstanceState(); SavedState ss = new SavedState(superState); if (mPendingSync != null) { ss.selectedId = mPendingSync.selectedId; ss.firstId = mPendingSync.firstId; ss.viewStart = mPendingSync.viewStart; ss.position = mPendingSync.position; ss.height = mPendingSync.height; return ss; }// w w w .jav a 2s . c om boolean haveChildren = (getChildCount() > 0 && mItemCount > 0); long selectedId = getSelectedItemId(); ss.selectedId = selectedId; ss.height = getHeight(); if (selectedId >= 0) { ss.viewStart = mSelectedStart; ss.position = getSelectedItemPosition(); ss.firstId = INVALID_POSITION; } else if (haveChildren && mFirstPosition > 0) { // Remember the position of the first child. // We only do this if we are not currently at the top of // the list, for two reasons: // // (1) The list may be in the process of becoming empty, in // which case mItemCount may not be 0, but if we try to // ask for any information about position 0 we will crash. // // (2) Being "at the top" seems like a special case, anyway, // and the user wouldn't expect to end up somewhere else when // they revisit the list even if its content has changed. View child = getChildAt(0); ss.viewStart = (mIsVertical ? child.getTop() : child.getLeft()); int firstPos = mFirstPosition; if (firstPos >= mItemCount) { firstPos = mItemCount - 1; } ss.position = firstPos; ss.firstId = mAdapter.getItemId(firstPos); } else { ss.viewStart = 0; ss.firstId = INVALID_POSITION; ss.position = 0; } if (mCheckStates != null) { ss.checkState = cloneCheckStates(); } if (mCheckedIdStates != null) { final LongSparseArray<Integer> idState = new LongSparseArray<Integer>(); final int count = mCheckedIdStates.size(); for (int i = 0; i < count; i++) { idState.put(mCheckedIdStates.keyAt(i), mCheckedIdStates.valueAt(i)); } ss.checkIdState = idState; } ss.checkedItemCount = mCheckedItemCount; return ss; }
From source file:com.boutline.sports.helpers.TwoWayView.java
private View fillBefore(int pos, int nextOffset) { View selectedView = null;// w ww . jav a 2s . c o m final int start = getStartEdge(); while (nextOffset > start && pos >= 0) { boolean isSelected = (pos == mSelectedPosition); View child = makeAndAddView(pos, nextOffset, false, isSelected); if (mIsVertical) { nextOffset = child.getTop() - mItemMargin; } else { nextOffset = child.getLeft() - mItemMargin; } if (isSelected) { selectedView = child; } pos--; } mFirstPosition = pos + 1; return selectedView; }
From source file:com.aliasapps.seq.scroller.TwoWayView.java
private void handleDragChange(int delta) { // Time to start stealing events! Once we've stolen them, don't // let anyone steal from us. final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); }// w ww . j a va2 s .c om final int motionIndex; if (mMotionPosition >= 0) { motionIndex = mMotionPosition - mFirstPosition; } else { // If we don't have a motion position that we can reliably track, // pick something in the middle to make a best guess at things below. motionIndex = getChildCount() / 2; } int motionViewPrevStart = 0; View motionView = this.getChildAt(motionIndex); if (motionView != null) { motionViewPrevStart = (mIsVertical ? motionView.getTop() : motionView.getLeft()); } boolean atEdge = scrollListItemsBy(delta); motionView = this.getChildAt(motionIndex); if (motionView != null) { final int motionViewRealStart = (mIsVertical ? motionView.getTop() : motionView.getLeft()); if (atEdge) { final int overscroll = -delta - (motionViewRealStart - motionViewPrevStart); updateOverScrollState(delta, overscroll); } } }
From source file:com.aliasapps.seq.scroller.TwoWayView.java
private View fillFromSelection(int selectedTop, int start, int end) { final int selectedPosition = mSelectedPosition; View selected; selected = makeAndAddView(selectedPosition, selectedTop, true, true); final int selectedStart = (mIsVertical ? selected.getTop() : selected.getLeft()); final int selectedEnd = (mIsVertical ? selected.getBottom() : selected.getRight()); // Some of the newly selected item extends below the bottom of the list if (selectedEnd > end) { // Find space available above the selection into which we can scroll // upwards final int spaceAbove = selectedStart - start; // Find space required to bring the bottom of the selected item // fully into view final int spaceBelow = selectedEnd - end; final int offset = Math.min(spaceAbove, spaceBelow); // Now offset the selected item to get it into view selected.offsetTopAndBottom(-offset); } else if (selectedStart < start) { // Find space required to bring the top of the selected item fully // into view final int spaceAbove = start - selectedStart; // Find space available below the selection into which we can scroll // downwards final int spaceBelow = end - selectedEnd; final int offset = Math.min(spaceAbove, spaceBelow); // Offset the selected item to get it into view selected.offsetTopAndBottom(offset); }/*from w w w. ja v a 2 s . co m*/ // Fill in views above and below fillBeforeAndAfter(selected, selectedPosition); correctTooHigh(getChildCount()); return selected; }
From source file:com.aliasapps.seq.scroller.TwoWayView.java
boolean resurrectSelection() { final int childCount = getChildCount(); if (childCount <= 0) { return false; }/*from www. ja v a 2 s . c o m*/ int selectedStart = 0; int selectedPosition; final int start = (mIsVertical ? getPaddingTop() : getPaddingLeft()); final int end = (mIsVertical ? getHeight() - getPaddingBottom() : getWidth() - getPaddingRight()); final int firstPosition = mFirstPosition; final int toPosition = mResurrectToPosition; boolean down = true; if (toPosition >= firstPosition && toPosition < firstPosition + childCount) { selectedPosition = toPosition; final View selected = getChildAt(selectedPosition - mFirstPosition); selectedStart = (mIsVertical ? selected.getTop() : selected.getLeft()); } else if (toPosition < firstPosition) { // Default to selecting whatever is first selectedPosition = firstPosition; for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final int childStart = (mIsVertical ? child.getTop() : child.getLeft()); if (i == 0) { // Remember the position of the first item selectedStart = childStart; } if (childStart >= start) { // Found a view whose top is fully visible selectedPosition = firstPosition + i; selectedStart = childStart; break; } } } else { selectedPosition = firstPosition + childCount - 1; down = false; for (int i = childCount - 1; i >= 0; i--) { final View child = getChildAt(i); final int childStart = (mIsVertical ? child.getTop() : child.getLeft()); final int childEnd = (mIsVertical ? child.getBottom() : child.getRight()); if (i == childCount - 1) { selectedStart = childStart; } if (childEnd <= end) { selectedPosition = firstPosition + i; selectedStart = childStart; break; } } } mResurrectToPosition = INVALID_POSITION; mTouchMode = TOUCH_MODE_REST; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); mSpecificStart = selectedStart; selectedPosition = lookForSelectablePosition(selectedPosition, down); if (selectedPosition >= firstPosition && selectedPosition <= getLastVisiblePosition()) { mLayoutMode = LAYOUT_SPECIFIC; updateSelectorState(); setSelectionInt(selectedPosition); invokeOnItemScrollListener(); } else { selectedPosition = INVALID_POSITION; } return selectedPosition >= 0; }