List of usage examples for android.view View getTop
@ViewDebug.CapturedViewProperty public final int getTop()
From source file:android.support.design.widget.CoordinatorLayout.java
/** * Get the position rect for the given child. If the child has currently requested layout * or has a visibility of GONE./* w w w . jav a 2 s. c o m*/ * * @param child child view to check * @param transform true to include transformation in the output rect, false to * only account for the base position * @param out rect to set to the output values */ void getChildRect(View child, boolean transform, Rect out) { if (child.isLayoutRequested() || child.getVisibility() == View.GONE) { out.setEmpty(); return; } if (transform) { getDescendantRect(child, out); } else { out.set(child.getLeft(), child.getTop(), child.getRight(), child.getBottom()); } }
From source file:com.cxsplay.wallyskim.widget.flexbox.FlexboxLayout.java
/** * Sub method for {@link #onDraw(Canvas)} when the main axis direction is vertical * ({@link #mFlexDirection} is either of {@link #FLEX_DIRECTION_COLUMN} or * {@link #FLEX_DIRECTION_COLUMN_REVERSE}. * * @param canvas the canvas on which the background will be drawn * @param isRtl {@code true} when the horizontal layout direction is right to left, * {@code false} otherwise * @param fromBottomToTop {@code true} when the vertical layout direction is bottom to top, * {@code false} otherwise *///from ww w . j ava2 s . c o m private void drawDividersVertical(Canvas canvas, boolean isRtl, boolean fromBottomToTop) { int currentViewIndex = 0; int paddingTop = getPaddingTop(); int paddingBottom = getPaddingBottom(); int verticalDividerLength = Math.max(0, getHeight() - paddingBottom - paddingTop); for (int i = 0, size = mFlexLines.size(); i < size; i++) { FlexLine flexLine = mFlexLines.get(i); // Draw horizontal dividers if needed for (int j = 0; j < flexLine.mItemCount; j++) { View view = getReorderedChildAt(currentViewIndex); if (view == null || view.getVisibility() == View.GONE) { continue; } LayoutParams lp = (LayoutParams) view.getLayoutParams(); // Judge if the beginning or middle divider is needed if (hasDividerBeforeChildAtAlongMainAxis(currentViewIndex, j)) { int dividerTop; if (fromBottomToTop) { dividerTop = view.getBottom() + lp.bottomMargin; } else { dividerTop = view.getTop() - lp.topMargin - mDividerHorizontalHeight; } drawHorizontalDivider(canvas, flexLine.mLeft, dividerTop, flexLine.mCrossSize); } // Judge if the end divider is needed if (j == flexLine.mItemCount - 1) { if ((mShowDividerHorizontal & SHOW_DIVIDER_END) > 0) { int dividerTop; if (fromBottomToTop) { dividerTop = view.getTop() - lp.topMargin - mDividerHorizontalHeight; } else { dividerTop = view.getBottom() + lp.bottomMargin; } drawHorizontalDivider(canvas, flexLine.mLeft, dividerTop, flexLine.mCrossSize); } } currentViewIndex++; } // Judge if the beginning or middle dividers are needed before the flex line if (hasDividerBeforeFlexLine(i)) { int verticalDividerLeft; if (isRtl) { verticalDividerLeft = flexLine.mRight; } else { verticalDividerLeft = flexLine.mLeft - mDividerVerticalWidth; } drawVerticalDivider(canvas, verticalDividerLeft, paddingTop, verticalDividerLength); } if (hasEndDividerAfterFlexLine(i)) { if ((mShowDividerVertical & SHOW_DIVIDER_END) > 0) { int verticalDividerLeft; if (isRtl) { verticalDividerLeft = flexLine.mLeft - mDividerVerticalWidth; } else { verticalDividerLeft = flexLine.mRight; } drawVerticalDivider(canvas, verticalDividerLeft, paddingTop, verticalDividerLength); } } } }
From source file:cn.androidy.materialdesignsample.ryanharterviewpager.ViewPager.java
/** * 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// w ww .ja va 2s. c om * @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; } } } boolean canScroll = false; if (isOrientationHorizontal()) { canScroll = ViewCompat.canScrollHorizontally(v, -dx); } else { canScroll = ViewCompat.canScrollVertically(v, -dx); } return checkV && canScroll; }
From source file:administrator.example.com.myscrollview.VerticalViewPager.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 w w . ja v a2s.c o 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 scrollY = getScrollY(); int paddingTop = getPaddingTop(); int paddingBottom = getPaddingBottom(); final int height = getHeight(); 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 vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; int childTop = 0; switch (vgrav) { default: childTop = paddingTop; break; case Gravity.TOP: childTop = paddingTop; paddingTop += child.getHeight(); break; case Gravity.CENTER_HORIZONTAL: childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop); break; case Gravity.BOTTOM: childTop = height - paddingBottom - child.getMeasuredHeight(); paddingBottom += child.getMeasuredHeight(); break; } /* end of switch */ childTop += scrollY; final int childOffset = childTop - child.getTop(); if (childOffset != 0) { child.offsetTopAndBottom(childOffset); } /* end of if */ } /* end of for */ } /* end of for */ if (mOnPageChangeListener != null) { mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels); } /* end of if */ if (mInternalPageChangeListener != null) { mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels); } /* end of if */ mCalledSuper = true; }
From source file:android.improving.utils.views.cardsview.OrientedViewPager.java
/** * 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 delta 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. *//*from ww w . jav a2 s .c o m*/ protected boolean canScroll(View v, boolean checkV, int delta, 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 (mOrientation == Orientation.VERTICAL) { if (y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && x + scrollX >= child.getLeft() && x + scrollX < child.getRight() && canScroll(child, true, delta, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) { return true; } } else { if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() && y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && canScroll(child, true, delta, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) { return true; } } } } return checkV && ViewCompat.canScrollVertically(v, -delta); }
From source file:com.kaichaohulian.baocms.ecdemo.ui.chatting.ChattingFragment.java
@Override public void onScrollStateChanged(AbsListView view, int scrollState) { if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) { View topView = mListView.getChildAt(mListView.getFirstVisiblePosition()); if ((topView != null) && (topView.getTop() == 0)) { LogUtil.d(LogUtil.getLogUtilsTag(ChattingActivity.class), "doLoadingView auto pull"); mECPullDownView.startTopScroll(); }/* w ww . java 2 s . co m*/ } }
From source file:android.support.transition.Visibility.java
/** * The default implementation of this method does nothing. Subclasses * should override if they need to create an Animator when targets disappear. * The method should only be called by the Visibility class; it is * not intended to be called from external classes. * * @param sceneRoot The root of the transition hierarchy * @param startValues The target values in the start scene * @param startVisibility The target visibility in the start scene * @param endValues The target values in the end scene * @param endVisibility The target visibility in the end scene * @return An Animator to be started at the appropriate time in the * overall transition for this scene change. A null value means no animation * should be run.//from w ww .java2 s. c o m */ @SuppressWarnings("UnusedParameters") public Animator onDisappear(ViewGroup sceneRoot, TransitionValues startValues, int startVisibility, TransitionValues endValues, int endVisibility) { if ((mMode & MODE_OUT) != MODE_OUT) { return null; } View startView = (startValues != null) ? startValues.view : null; View endView = (endValues != null) ? endValues.view : null; View overlayView = null; View viewToKeep = null; if (endView == null || endView.getParent() == null) { if (endView != null) { // endView was removed from its parent - add it to the overlay overlayView = endView; } else if (startView != null) { // endView does not exist. Use startView only under certain // conditions, because placing a view in an overlay necessitates // it being removed from its current parent if (startView.getParent() == null) { // no parent - safe to use overlayView = startView; } else if (startView.getParent() instanceof View) { View startParent = (View) startView.getParent(); TransitionValues startParentValues = getTransitionValues(startParent, true); TransitionValues endParentValues = getMatchedTransitionValues(startParent, true); VisibilityInfo parentVisibilityInfo = getVisibilityChangeInfo(startParentValues, endParentValues); if (!parentVisibilityInfo.mVisibilityChange) { overlayView = TransitionUtils.copyViewImage(sceneRoot, startView, startParent); } else if (startParent.getParent() == null) { int id = startParent.getId(); if (id != View.NO_ID && sceneRoot.findViewById(id) != null && mCanRemoveViews) { // no parent, but its parent is unparented but the parent // hierarchy has been replaced by a new hierarchy with the same id // and it is safe to un-parent startView overlayView = startView; } } } } } else { // visibility change if (endVisibility == View.INVISIBLE) { viewToKeep = endView; } else { // Becoming GONE if (startView == endView) { viewToKeep = endView; } else { overlayView = startView; } } } final int finalVisibility = endVisibility; if (overlayView != null && startValues != null) { // TODO: Need to do this for general case of adding to overlay int[] screenLoc = (int[]) startValues.values.get(PROPNAME_SCREEN_LOCATION); int screenX = screenLoc[0]; int screenY = screenLoc[1]; int[] loc = new int[2]; sceneRoot.getLocationOnScreen(loc); overlayView.offsetLeftAndRight((screenX - loc[0]) - overlayView.getLeft()); overlayView.offsetTopAndBottom((screenY - loc[1]) - overlayView.getTop()); final ViewGroupOverlayImpl overlay = ViewGroupUtils.getOverlay(sceneRoot); overlay.add(overlayView); Animator animator = onDisappear(sceneRoot, overlayView, startValues, endValues); if (animator == null) { overlay.remove(overlayView); } else { final View finalOverlayView = overlayView; animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { overlay.remove(finalOverlayView); } }); } return animator; } if (viewToKeep != null) { int originalVisibility = viewToKeep.getVisibility(); ViewUtils.setTransitionVisibility(viewToKeep, View.VISIBLE); Animator animator = onDisappear(sceneRoot, viewToKeep, startValues, endValues); if (animator != null) { DisappearListener disappearListener = new DisappearListener(viewToKeep, finalVisibility, true); animator.addListener(disappearListener); AnimatorUtils.addPauseListener(animator, disappearListener); addListener(disappearListener); } else { ViewUtils.setTransitionVisibility(viewToKeep, originalVisibility); } return animator; } return null; }
From source file:com.abewy.android.apps.klyph.widget.KlyphDrawerLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { final int height = getHeight(); final boolean drawingContent = isContentView(child); int clipLeft = 0, clipRight = getWidth(); final int restoreCount = canvas.save(); if (drawingContent) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View v = getChildAt(i); if (v == child || v.getVisibility() != VISIBLE || !hasOpaqueBackground(v) || !isDrawerView(v) || v.getHeight() < height) { continue; }//w w w . j ava2s . c om if (checkDrawerViewGravity(v, Gravity.LEFT)) { final int vright = v.getRight(); if (vright > clipLeft) clipLeft = vright; } else { final int vleft = v.getLeft(); if (vleft < clipRight) clipRight = vleft; } } canvas.clipRect(clipLeft, 0, clipRight, getHeight()); } final boolean result = super.drawChild(canvas, child, drawingTime); canvas.restoreToCount(restoreCount); if (mScrimOpacity > 0 && drawingContent) { final int baseAlpha = (mScrimColor & 0xff000000) >>> 24; final int imag = (int) (baseAlpha * mScrimOpacity); final int color = imag << 24 | (mScrimColor & 0xffffff); mScrimPaint.setColor(color); canvas.drawRect(clipLeft, 0, clipRight, getHeight(), mScrimPaint); } else if (mShadowLeft != null && checkDrawerViewGravity(child, Gravity.LEFT)) { final int shadowWidth = mShadowLeft.getIntrinsicWidth(); final int childRight = child.getRight(); final int drawerPeekDistance = mLeftDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) childRight / drawerPeekDistance, 1.f)); mShadowLeft.setBounds(childRight, child.getTop(), childRight + shadowWidth, child.getBottom()); mShadowLeft.setAlpha((int) (0xff * alpha)); mShadowLeft.draw(canvas); } else if (mShadowRight != null && checkDrawerViewGravity(child, Gravity.RIGHT)) { final int shadowWidth = mShadowRight.getIntrinsicWidth(); final int childLeft = child.getLeft(); final int showing = getWidth() - childLeft; final int drawerPeekDistance = mRightDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f)); mShadowRight.setBounds(childLeft - shadowWidth, child.getTop(), childLeft, child.getBottom()); mShadowRight.setAlpha((int) (0xff * alpha)); mShadowRight.draw(canvas); } return result; }
From source file:com.appunite.list.GridView.java
/** * Fills the grid based on positioning the new selection relative to the old * selection. The new selection will be placed at, above, or below the * location of the new selection depending on how the selection is moving. * The selection will then be pinned to the visible part of the screen, * excluding the edges that are faded. The grid is then filled upwards and * downwards from there./*from w ww . ja v a2 s.co m*/ * * @param delta Which way we are moving * @param childrenTop Where to start drawing children * @param childrenBottom Last pixel where children can be drawn * @return The view that currently has selection */ private View moveSelection(int delta, int childrenTop, int childrenBottom) { final int fadingEdgeLength = getVerticalFadingEdgeLength(); final int selectedPosition = mSelectedPosition; final int numColumns = mNumColumns; final int verticalSpacing = mVerticalSpacing; int oldRowStart; int rowStart; int rowEnd = -1; if (!mStackFromBottom) { oldRowStart = (selectedPosition - delta) - ((selectedPosition - delta) % numColumns); rowStart = selectedPosition - (selectedPosition % numColumns); } else { int invertedSelection = mItemCount - 1 - selectedPosition; rowEnd = mItemCount - 1 - (invertedSelection - (invertedSelection % numColumns)); rowStart = Math.max(0, rowEnd - numColumns + 1); invertedSelection = mItemCount - 1 - (selectedPosition - delta); oldRowStart = mItemCount - 1 - (invertedSelection - (invertedSelection % numColumns)); oldRowStart = Math.max(0, oldRowStart - numColumns + 1); } final int rowDelta = rowStart - oldRowStart; final int topSelectionPixel = getTopSelectionPixel(childrenTop, fadingEdgeLength, rowStart); final int bottomSelectionPixel = getBottomSelectionPixel(childrenBottom, fadingEdgeLength, numColumns, rowStart); // Possibly changed again in fillUp if we add rows above this one. mFirstPosition = rowStart; View sel; View referenceView; if (rowDelta > 0) { /* * Case 1: Scrolling down. */ final int oldBottom = mReferenceViewInSelectedRow == null ? 0 : mReferenceViewInSelectedRow.getBottom(); sel = makeRow(mStackFromBottom ? rowEnd : rowStart, oldBottom + verticalSpacing, true); referenceView = mReferenceView; adjustForBottomFadingEdge(referenceView, topSelectionPixel, bottomSelectionPixel); } else if (rowDelta < 0) { /* * Case 2: Scrolling up. */ final int oldTop = mReferenceViewInSelectedRow == null ? 0 : mReferenceViewInSelectedRow.getTop(); sel = makeRow(mStackFromBottom ? rowEnd : rowStart, oldTop - verticalSpacing, false); referenceView = mReferenceView; adjustForTopFadingEdge(referenceView, topSelectionPixel, bottomSelectionPixel); } else { /* * Keep selection where it was */ final int oldTop = mReferenceViewInSelectedRow == null ? 0 : mReferenceViewInSelectedRow.getTop(); sel = makeRow(mStackFromBottom ? rowEnd : rowStart, oldTop, true); referenceView = mReferenceView; } if (!mStackFromBottom) { fillUp(rowStart - numColumns, referenceView.getTop() - verticalSpacing); adjustViewsUpOrDown(); fillDown(rowStart + numColumns, referenceView.getBottom() + verticalSpacing); } else { fillDown(rowEnd + numColumns, referenceView.getBottom() + verticalSpacing); adjustViewsUpOrDown(); fillUp(rowStart - 1, referenceView.getTop() - verticalSpacing); } return sel; }