List of usage examples for android.view View getTop
@ViewDebug.CapturedViewProperty public final int getTop()
From source file:org.getlantern.firetweet.util.Utils.java
public static int getFirstChildOffset(final AbsListView list) { if (list == null || list.getChildCount() == 0) return 0; final View child = list.getChildAt(0); final int[] location = new int[2]; child.getLocationOnScreen(location); Log.d(LOGTAG, String.format("getFirstChildOffset %d vs %d", child.getTop(), location[1])); return child.getTop(); }
From source file:com.appunite.list.ListView.java
@Override public boolean isOpaque() { boolean retValue = (mCachingActive && mIsCacheColorOpaque && mDividerIsOpaque && hasOpaqueScrollbarsUnhide()) || super.isOpaque(); if (retValue) { // only return true if the list items cover the entire area of the view final int listTop = mListPadding != null ? mListPadding.top : getPaddingTop(); View first = getChildAt(0); if (first == null || first.getTop() > listTop) { return false; }/*from w w w. ja va 2s. com*/ final int listBottom = getHeight() - (mListPadding != null ? mListPadding.bottom : getPaddingBottom()); View last = getChildAt(getChildCount() - 1); if (last == null || last.getBottom() < listBottom) { return false; } } return retValue; }
From source file:caesar.feng.framework.widget.StaggeredGrid.ExtendableListView.java
private boolean moveTheChildren(int deltaY, int incrementalDeltaY) { if (DBG)/*from ww w . j a va 2 s .c o m*/ Log.d(TAG, "moveTheChildren deltaY: " + deltaY + "incrementalDeltaY: " + incrementalDeltaY); // there's nothing to move! if (!hasChildren()) return true; final int firstTop = getHighestChildTop(); final int lastBottom = getLowestChildBottom(); // "effective padding" In this case is the amount of padding that affects // how much space should not be filled by items. If we don't clip to padding // there is no effective padding. int effectivePaddingTop = 0; int effectivePaddingBottom = 0; if (mClipToPadding) { effectivePaddingTop = getListPaddingTop(); effectivePaddingBottom = getListPaddingBottom(); } final int gridHeight = getHeight(); final int spaceAbove = effectivePaddingTop - getFirstChildTop(); final int end = gridHeight - effectivePaddingBottom; final int spaceBelow = getLastChildBottom() - end; final int height = gridHeight - getListPaddingBottom() - getListPaddingTop(); if (incrementalDeltaY < 0) { incrementalDeltaY = Math.max(-(height - 1), incrementalDeltaY); } else { incrementalDeltaY = Math.min(height - 1, incrementalDeltaY); } final int firstPosition = mFirstPosition; int maxTop = getListPaddingTop(); int maxBottom = gridHeight - getListPaddingBottom(); int childCount = getChildCount(); final boolean cannotScrollDown = (firstPosition == 0 && firstTop >= maxTop && incrementalDeltaY >= 0); final boolean cannotScrollUp = (firstPosition + childCount == mItemCount && lastBottom <= maxBottom && incrementalDeltaY <= 0); if (DBG) { Log.d(TAG, "moveTheChildren " + " firstTop " + firstTop + " maxTop " + maxTop + " incrementalDeltaY " + incrementalDeltaY); Log.d(TAG, "moveTheChildren " + " lastBottom " + lastBottom + " maxBottom " + maxBottom + " incrementalDeltaY " + incrementalDeltaY); } if (cannotScrollDown) { if (DBG) Log.d(TAG, "moveTheChildren cannotScrollDown " + cannotScrollDown); return incrementalDeltaY != 0; } if (cannotScrollUp) { if (DBG) Log.d(TAG, "moveTheChildren cannotScrollUp " + cannotScrollUp); return incrementalDeltaY != 0; } final boolean isDown = incrementalDeltaY < 0; final int headerViewsCount = getHeaderViewsCount(); final int footerViewsStart = mItemCount - getFooterViewsCount(); int start = 0; int count = 0; if (isDown) { int top = -incrementalDeltaY; if (mClipToPadding) { top += getListPaddingTop(); } for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child.getBottom() >= top) { break; } else { count++; int position = firstPosition + i; if (position >= headerViewsCount && position < footerViewsStart) { mRecycleBin.addScrapView(child, position); } } } } else { int bottom = gridHeight - incrementalDeltaY; if (mClipToPadding) { bottom -= getListPaddingBottom(); } for (int i = childCount - 1; i >= 0; i--) { final View child = getChildAt(i); if (child.getTop() <= bottom) { break; } else { start = i; count++; int position = firstPosition + i; if (position >= headerViewsCount && position < footerViewsStart) { mRecycleBin.addScrapView(child, position); } } } } mBlockLayoutRequests = true; if (count > 0) { if (DBG) Log.d(TAG, "scrap - detachViewsFromParent start:" + start + " count:" + count); detachViewsFromParent(start, count); mRecycleBin.removeSkippedScrap(); onChildrenDetached(start, count); } // invalidate before moving the children to avoid unnecessary invalidate // calls to bubble up from the children all the way to the top if (!awakenScrollBars()) { invalidate(); } offsetChildrenTopAndBottom(incrementalDeltaY); if (isDown) { mFirstPosition += count; } final int absIncrementalDeltaY = Math.abs(incrementalDeltaY); if (spaceAbove < absIncrementalDeltaY || spaceBelow < absIncrementalDeltaY) { fillGap(isDown); } // TODO : touch mode selector handling mBlockLayoutRequests = false; invokeOnItemScrollListener(); return false; }
From source file:com.appunite.list.ListView.java
/** * Check if we have dragged the bottom of the list too high (we have pushed the * top element off the top of the screen when we did not need to). Correct by sliding * everything back down.//www.j a v a 2 s.c o m * * @param childCount Number of children */ 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. int lastPosition = mFirstPosition + childCount - 1; if (lastPosition == mItemCount - 1 && childCount > 0) { // Get the last child ... final View lastChild = getChildAt(childCount - 1); // ... and its bottom edge final int lastBottom = lastChild.getBottom(); // This is bottom of our drawable area final int end = (getBottom() - getTop()) - mListPadding.bottom; // This is how far the bottom edge of the last view is from the bottom of the // drawable area int bottomOffset = end - lastBottom; View firstChild = getChildAt(0); final int firstTop = firstChild.getTop(); // 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 (bottomOffset > 0 && (mFirstPosition > 0 || firstTop < mListPadding.top)) { if (mFirstPosition == 0) { // Don't pull the top too far down bottomOffset = Math.min(bottomOffset, mListPadding.top - firstTop); } // Move everything down offsetChildrenTopAndBottomUnhide(bottomOffset); if (mFirstPosition > 0) { // Fill the gap that was opened above mFirstPosition with more rows, if // possible fillUp(mFirstPosition - 1, firstChild.getTop() - mDividerHeight); // Close up the remaining gap adjustViewsUpOrDown(); } } } }
From source file:com.appunite.list.ListView.java
/** * Fills the list from pos up to the top of the list view. * * @param pos The first position to put in the list * * @param nextBottom The location where the bottom of the item associated * with pos should be drawn//w ww. j a va 2 s . c o m * * @return The view that is currently selected */ private View fillUp(int pos, int nextBottom) { View selectedView = null; int end = 0; if (mClipToPadding) { end = mListPadding.top; } while (nextBottom > end && pos >= 0) { // is this the selected item? boolean selected = pos == mSelectedPosition; View child = makeAndAddView(pos, nextBottom, false, mListPadding.left, selected); nextBottom = child.getTop() - mDividerHeight; if (selected) { selectedView = child; } pos--; } mFirstPosition = pos + 1; // FIXME removed bacause we do not need RemoteViews (j.m.) // setVisibleRangeHint(mFirstPosition, mFirstPosition + getChildCount() - 1); return selectedView; }
From source file:com.bulletnoid.android.widget.StaggeredGridView.StaggeredGridView2.java
int findMotionRow(int y) { int childCount = getChildCount(); if (childCount > 0) { /*if (!mStackFromBottom) { for (int i = 0; i < childCount; i++) { View v = getChildAt(i);// w ww. j a v a 2s .co m if (y <= v.getBottom()) { return mFirstPosition + i; } } } else*/ { for (int i = childCount - 1; i >= 0; i--) { View v = getChildAt(i); if (y >= v.getTop()) { return mFirstPosition + i; } } } } return INVALID_POSITION; }
From source file:com.appunite.list.ListView.java
/** * Once the selected view as been placed, fill up the visible area above and * below it.// w w w .ja v a 2 s . c om * * @param sel The selected view * @param position The position corresponding to sel */ private void fillAboveAndBelow(View sel, int position) { final int dividerHeight = mDividerHeight; if (!mStackFromBottom) { fillUp(position - 1, sel.getTop() - dividerHeight); adjustViewsUpOrDown(); fillDown(position + 1, sel.getBottom() + dividerHeight); } else { fillDown(position + 1, sel.getBottom() + dividerHeight); adjustViewsUpOrDown(); fillUp(position - 1, sel.getTop() - dividerHeight); } }
From source file:com.appunite.list.ListView.java
/** * Check if we have dragged the bottom of the list too low (we have pushed the * bottom element off the bottom of the screen when we did not need to). Correct by sliding * everything back up./*from w ww .j av a 2s .c om*/ * * @param childCount Number of children */ 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) { // Get the first child ... final View firstChild = getChildAt(0); // ... and its top edge final int firstTop = firstChild.getTop(); // This is top of our drawable area final int start = mListPadding.top; // This is bottom of our drawable area final int end = (getBottom() - getTop()) - mListPadding.bottom; // This is how far the top edge of the first view is from the top of the // drawable area int topOffset = firstTop - start; View lastChild = getChildAt(childCount - 1); final int lastBottom = lastChild.getBottom(); int lastPosition = mFirstPosition + childCount - 1; // Make sure we are 1) Too low, and 2) Either there are more rows below the // last row or the last row is scrolled off the bottom of the drawable area if (topOffset > 0) { if (lastPosition < mItemCount - 1 || lastBottom > end) { if (lastPosition == mItemCount - 1) { // Don't pull the bottom too far up topOffset = Math.min(topOffset, lastBottom - end); } // Move everything up offsetChildrenTopAndBottomUnhide(-topOffset); if (lastPosition < mItemCount - 1) { // Fill the gap that was opened below the last position with more rows, if // possible fillDown(lastPosition + 1, lastChild.getBottom() + mDividerHeight); // Close up the remaining gap adjustViewsUpOrDown(); } } else if (lastPosition == mItemCount - 1) { adjustViewsUpOrDown(); } } } }
From source file:android.support.design.widget.CoordinatorLayout.java
private void offsetChildByInset(final View child, final Rect inset, final int layoutDirection) { if (!ViewCompat.isLaidOut(child)) { // The view has not been laid out yet, so we can't obtain its bounds. return;/* ww w . java 2 s .c o m*/ } if (child.getWidth() <= 0 || child.getHeight() <= 0) { // Bounds are empty so there is nothing to dodge against, skip... return; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final Behavior behavior = lp.getBehavior(); final Rect dodgeRect = acquireTempRect(); final Rect bounds = acquireTempRect(); bounds.set(child.getLeft(), child.getTop(), child.getRight(), child.getBottom()); if (behavior != null && behavior.getInsetDodgeRect(this, child, dodgeRect)) { // Make sure that the rect is within the view's bounds if (!bounds.contains(dodgeRect)) { throw new IllegalArgumentException("Rect should be within the child's bounds." + " Rect:" + dodgeRect.toShortString() + " | Bounds:" + bounds.toShortString()); } } else { dodgeRect.set(bounds); } // We can release the bounds rect now releaseTempRect(bounds); if (dodgeRect.isEmpty()) { // Rect is empty so there is nothing to dodge against, skip... releaseTempRect(dodgeRect); return; } final int absDodgeInsetEdges = GravityCompat.getAbsoluteGravity(lp.dodgeInsetEdges, layoutDirection); boolean offsetY = false; if ((absDodgeInsetEdges & Gravity.TOP) == Gravity.TOP) { int distance = dodgeRect.top - lp.topMargin - lp.mInsetOffsetY; if (distance < inset.top) { setInsetOffsetY(child, inset.top - distance); offsetY = true; } } if ((absDodgeInsetEdges & Gravity.BOTTOM) == Gravity.BOTTOM) { int distance = getHeight() - dodgeRect.bottom - lp.bottomMargin + lp.mInsetOffsetY; if (distance < inset.bottom) { setInsetOffsetY(child, distance - inset.bottom); offsetY = true; } } if (!offsetY) { setInsetOffsetY(child, 0); } boolean offsetX = false; if ((absDodgeInsetEdges & Gravity.LEFT) == Gravity.LEFT) { int distance = dodgeRect.left - lp.leftMargin - lp.mInsetOffsetX; if (distance < inset.left) { setInsetOffsetX(child, inset.left - distance); offsetX = true; } } if ((absDodgeInsetEdges & Gravity.RIGHT) == Gravity.RIGHT) { int distance = getWidth() - dodgeRect.right - lp.rightMargin + lp.mInsetOffsetX; if (distance < inset.right) { setInsetOffsetX(child, distance - inset.right); offsetX = true; } } if (!offsetX) { setInsetOffsetX(child, 0); } releaseTempRect(dodgeRect); }
From source file:com.appunite.list.ListView.java
private View addViewAbove(View theView, int position) { int abovePosition = position - 1; View view = obtainView(abovePosition, mIsScrap); int edgeOfNewChild = theView.getTop() - mDividerHeight; setupChild(view, abovePosition, edgeOfNewChild, false, mListPadding.left, false, mIsScrap[0]); return view;/*from ww w . ja va 2 s .co m*/ }