Java Code Examples for android.view.View.getTop()

The following are Jave code examples for showing how to use getTop() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: letv   File: RecyclerView.java   View Source Code Vote up 6 votes
public View findChildViewUnder(float x, float y) {
    for (int i = this.mChildHelper.getChildCount() - 1; i >= 0; i--) {
        View child = this.mChildHelper.getChildAt(i);
        float translationX = ViewCompat.getTranslationX(child);
        float translationY = ViewCompat.getTranslationY(child);
        if (x >= ((float) child.getLeft()) + translationX && x <= ((float) child.getRight()) + translationX && y >= ((float) child.getTop()) + translationY && y <= ((float) child.getBottom()) + translationY) {
            return child;
        }
    }
    return null;
}
 
Example 2
Project: CoordinatorLayoutExample-master   File: UcNewsTabBehavior.java   View Source Code Vote up 6 votes
private void offsetChildAsNeeded(CoordinatorLayout parent, View child, View dependency) {
    float offsetRange = dependency.getTop() + getFinalHeight() - child.getTop();
    int headerOffsetRange = getHeaderOffsetRange();
    if (dependency.getTranslationY() == headerOffsetRange) {
        child.setTranslationY(offsetRange);
    } else if (dependency.getTranslationY() == 0) {
        child.setTranslationY(0);
    } else {
        child.setTranslationY((int) (dependency.getTranslationY() / (getHeaderOffsetRange() * 1.0f) * offsetRange));
    }
}
 
Example 3
Project: redpacketui-open   File: HeaderPositionCalculator.java   View Source Code Vote up 6 votes
private void initDefaultHeaderOffset(Rect headerMargins, RecyclerView recyclerView, View header, View firstView, int orientation) {
    int translationX, translationY;
    mDimensionCalculator.initMargins(mTempRect1, header);

    ViewGroup.LayoutParams layoutParams = firstView.getLayoutParams();
    int leftMargin = 0;
    int topMargin = 0;
    if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
        ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
        leftMargin = marginLayoutParams.leftMargin;
        topMargin = marginLayoutParams.topMargin;
    }

    if (orientation == LinearLayoutManager.VERTICAL) {
        translationX = firstView.getLeft() - leftMargin + mTempRect1.left;
        translationY = Math.max(
                firstView.getTop() - topMargin - header.getHeight() - mTempRect1.bottom,
                getListTop(recyclerView) + mTempRect1.top);
    } else {
        translationY = firstView.getTop() - topMargin + mTempRect1.top;
        translationX = Math.max(
                firstView.getLeft() - leftMargin - header.getWidth() - mTempRect1.right,
                getListLeft(recyclerView) + mTempRect1.left);
    }

    headerMargins.set(translationX, translationY, translationX + header.getWidth(),
            translationY + header.getHeight());
}
 
Example 4
Project: NoChat   File: NoChatScrollUtils.java   View Source Code Vote up 6 votes
public static boolean isOnTop(RecyclerView recyclerView, int loadingTriggerThreshold) {
    final int firstVisiblePosition = getFirstVisibleItemPositionByLayoutManager(recyclerView.getLayoutManager());
    final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    final View viewByPosition = layoutManager.findViewByPosition(firstVisiblePosition);
    if (viewByPosition != null) {
        final int topPosition = viewByPosition.getTop();
        return (topPosition == 0 && firstVisiblePosition == 0);
    }
    return false;
}
 
Example 5
Project: ultrasonic   File: PullToRefreshAdapterViewBase.java   View Source Code Vote up 6 votes
private boolean isFirstItemVisible() {
	final Adapter adapter = mRefreshableView.getAdapter();

	if (null == adapter || adapter.isEmpty()) {
		if (DEBUG) {
			Log.d(LOG_TAG, "isFirstItemVisible. Empty View.");
		}
		return true;

	} else {

		/**
		 * This check should really just be:
		 * mRefreshableView.getFirstVisiblePosition() == 0, but PtRListView
		 * internally use a HeaderView which messes the positions up. For
		 * now we'll just add one to account for it and rely on the inner
		 * condition which checks getTop().
		 */
		if (mRefreshableView.getFirstVisiblePosition() <= 1) {
			final View firstVisibleChild = mRefreshableView.getChildAt(0);
			if (firstVisibleChild != null) {
				return firstVisibleChild.getTop() >= mRefreshableView.getTop();
			}
		}
	}

	return false;
}
 
Example 6
Project: boohee_v5.6   File: ViewDragHelper.java   View Source Code Vote up 6 votes
public boolean isViewUnder(View view, int x, int y) {
    if (view != null && x >= view.getLeft() && x < view.getRight() && y >= view.getTop() && y
            < view.getBottom()) {
        return true;
    }
    return false;
}
 
Example 7
Project: bananapeel   File: SelectableScrollbackView.java   View Source Code Vote up 6 votes
private float[] getScreenCoordsForPos(int line, int pos)
{
	LayoutManager manager = getLayoutManager();
	ViewHolder holder = findViewHolderForAdapterPosition(line);
	if(holder == null)
	{
		if(getChildCount() > 0 && getChildAdapterPosition(getChildAt(getChildCount() - 1)) < line)
			return new float[]{getWidth() / 2, getHeight(), 0};
		return new float[]{getWidth() / 2, 0, 0};
	}
	View view = manager.findViewByPosition(findViewHolderForAdapterPosition(line).getLayoutPosition());
	if(view == null)
		return new float[]{0, 0, 0};
	Layout layout = ((TextView)view).getLayout();
	float x = layout.getPrimaryHorizontal(pos);
	int ln = layout.getLineForOffset(pos);
	float y = (float)(layout.getLineTop(ln) + layout.getLineBottom(ln)) / 2;
	float screenX = x + view.getLeft() + getScrollX();
	float screenY = y + view.getTop() + getScrollY();
	if(screenY < 0)
		screenY = 0;
	if(screenY > getBottom())
		screenY = getBottom();
	return new float[]{screenX, screenY, layout.getLineBottom(ln) - y};
}
 
Example 8
Project: AndroidBasicLibs   File: InnerScrollView.java   View Source Code Vote up 6 votes
/**
 * 将targetView滚到最顶端
 */
public void scrollTo(View targetView) {

	int oldScrollY = getScrollY();
	int top = targetView.getTop() - mTop;
	int delatY = top - oldScrollY;
	lastScrollDelta = delatY;
	overScrollBy(0, delatY, 0, getScrollY(), 0, getScrollRange(), 0, 0,
			true);
}
 
Example 9
Project: garras   File: AnchorSheetBehavior.java   View Source Code Vote up 6 votes
@Override
public void onViewReleased(View releasedChild, float xvel, float yvel) {
    int top;
    @State int targetState;
    if (mHideable && shouldHide(releasedChild, yvel)) {
        top = mParentHeight;
        targetState = STATE_HIDDEN;
    } else if (yvel <= 0.f) {
        int currentTop = releasedChild.getTop();
        if (Math.abs(currentTop - mAnchorOffset) < Math.abs(currentTop - mMinOffset)) {
            top = mAnchorOffset;
            targetState = STATE_ANCHOR;
        } else if (Math.abs(currentTop - mMinOffset) < Math.abs(currentTop - mMaxOffset)) {
            top = mMinOffset;
            targetState = STATE_EXPANDED;
        } else {
            top = mMaxOffset;
            targetState = STATE_COLLAPSED;
        }
    } else {
        top = mMaxOffset;
        targetState = STATE_COLLAPSED;
    }
    if (mViewDragHelper.settleCapturedViewAt(releasedChild.getLeft(), top)) {
        setStateInternal(STATE_SETTLING);
        ViewCompat.postOnAnimation(releasedChild, new SettleRunnable(releasedChild, targetState));
    } else {
        setStateInternal(targetState);
    }
}
 
Example 10
Project: android-magic-surface-view   File: ViewUtil.java   View Source Code Vote up 6 votes
private static void getViewPosition(View view, Point p) {
    p.x += view.getLeft();
    p.y += view.getTop();
    if (view.getParent() != null && view.getParent() instanceof View) {
        getViewPosition((View) view.getParent(), p);
    }
}
 
Example 11
Project: RecycylerViewItemDecoration   File: LinearLayoutDividerItemDecoration.java   View Source Code Vote up 6 votes
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {

    c.save();
    int left, right, top, bottom;
    int count = parent.getChildCount();
    if (!mBuilder.isShowLastDivider) {
        count -= 1;
    }

    Context context = parent.getContext();
    for (int i = 0; i < count; i++) {
        final View child = parent.getChildAt(i);
        int transitionX = (int) ViewCompat.getTranslationX(child);
        int transitionY = (int) ViewCompat.getTranslationY(child);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();

        if (mBuilder.orientation == LinearLayoutManager.VERTICAL) {
            left = child.getLeft() - params.leftMargin + transitionX + ViewUtil.dp2px(context, mBuilder.leftMargin);
            top = child.getBottom() + params.bottomMargin;
            right = child.getRight() + params.rightMargin - ViewUtil.dp2px(context, mBuilder.rightMargin);
            bottom = top + mBuilder.dividerHeight + transitionY;
        } else {
            top = child.getTop() - params.topMargin + ViewUtil.dp2px(context, mBuilder.topMargin);
            bottom = child.getBottom() + params.bottomMargin + transitionY - ViewUtil.dp2px(context, mBuilder.bottomMargin);
            left = child.getRight() + params.rightMargin + transitionX;
            right = left + mBuilder.dividerHeight;
        }

        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
    c.restore();
}
 
Example 12
Project: boohee_v5.6   File: ItemTouchHelper.java   View Source Code Vote up 6 votes
private List<ViewHolder> findSwapTargets(ViewHolder viewHolder) {
    if (this.mSwapTargets == null) {
        this.mSwapTargets = new ArrayList();
        this.mDistances = new ArrayList();
    } else {
        this.mSwapTargets.clear();
        this.mDistances.clear();
    }
    int margin = this.mCallback.getBoundingBoxMargin();
    int left = Math.round(this.mSelectedStartX + this.mDx) - margin;
    int top = Math.round(this.mSelectedStartY + this.mDy) - margin;
    int right = (viewHolder.itemView.getWidth() + left) + (margin * 2);
    int bottom = (viewHolder.itemView.getHeight() + top) + (margin * 2);
    int centerX = (left + right) / 2;
    int centerY = (top + bottom) / 2;
    LayoutManager lm = this.mRecyclerView.getLayoutManager();
    int childCount = lm.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View other = lm.getChildAt(i);
        if (other != viewHolder.itemView && other.getBottom() >= top && other.getTop() <= bottom && other.getRight() >= left && other.getLeft() <= right) {
            ViewHolder otherVh = this.mRecyclerView.getChildViewHolder(other);
            if (this.mCallback.canDropOver(this.mRecyclerView, this.mSelected, otherVh)) {
                int dx = Math.abs(centerX - ((other.getLeft() + other.getRight()) / 2));
                int dy = Math.abs(centerY - ((other.getTop() + other.getBottom()) / 2));
                int dist = (dx * dx) + (dy * dy);
                int pos = 0;
                int cnt = this.mSwapTargets.size();
                int j = 0;
                while (j < cnt && dist > ((Integer) this.mDistances.get(j)).intValue()) {
                    pos++;
                    j++;
                }
                this.mSwapTargets.add(pos, otherVh);
                this.mDistances.add(pos, Integer.valueOf(dist));
            }
        }
    }
    return this.mSwapTargets;
}
 
Example 13
Project: ultrasonic   File: DragSortListView.java   View Source Code Vote up 6 votes
private int getTargetY() {
    final int first = getFirstVisiblePosition();
    final int otherAdjust = (mItemHeightCollapsed + getDividerHeight()) / 2;
    View v = getChildAt(mDropPos - first);
    int targetY = -1;
    if (v != null) {
        if (mDropPos == srcPos) {
            targetY = v.getTop();
        } else if (mDropPos < srcPos) {
            // expanded down
            targetY = v.getTop() - otherAdjust;
        } else {
            // expanded up
            targetY = v.getBottom() + otherAdjust - mFloatViewHeight;
        }
    } else {
        // drop position is not on screen?? no animation
        cancel();
    }

    return targetY;
}
 
Example 14
Project: cwac-crossport   File: AppBarLayout.java   View Source Code Vote up 6 votes
private static View getAppBarChildOnOffset(final AppBarLayout layout, final int offset) {
  final int absOffset = Math.abs(offset);
  for (int i = 0, z = layout.getChildCount(); i < z; i++) {
    final View child = layout.getChildAt(i);
    if (absOffset >= child.getTop() && absOffset <= child.getBottom()) {
      return child;
    }
  }
  return null;
}
 
Example 15
Project: CSipSimple   File: DragnDropListView.java   View Source Code Vote up 5 votes
@Override
public boolean onTouchEvent(MotionEvent ev) {
	if ((mDragListener != null || mDropListener != null) && mDragView != null) {
		int action = ev.getAction();
		switch (action) {
		case MotionEvent.ACTION_UP:
		case MotionEvent.ACTION_CANCEL:
			Rect r = mTempRect;
			mDragView.getDrawingRect(r);
			stopDragging();
			
			if (mDropListener != null && mDragPos >= 0 && mDragPos < getCount()) {
				mDropListener.drop(mFirstDragPos, mDragPos);
			}
			unExpandViews(false);
			break;

		case MotionEvent.ACTION_DOWN:
		case MotionEvent.ACTION_MOVE:
			int x = (int) ev.getX();
			int y = (int) ev.getY();
			dragView(x, y);
			int itemnum = getItemForPosition(y);
			if (itemnum >= 0) {
				if (action == MotionEvent.ACTION_DOWN || itemnum != mDragPos) {
					if (mDragListener != null) {
						mDragListener.drag(mDragPos, itemnum);
					}
					mDragPos = itemnum;
					doExpansion();
				}
				int speed = 0;
				adjustScrollBounds(y);
				if (y > mLowerBound) {
					// scroll the list up a bit
					speed = y > (mHeight + mLowerBound) / 2 ? 16 : 4;
				} else if (y < mUpperBound) {
					// scroll the list down a bit
					speed = y < mUpperBound / 2 ? -16 : -4;
				}
				if (speed != 0) {
					int ref = pointToPosition(0, mHeight / 2);
					if (ref == AdapterView.INVALID_POSITION) {
						// we hit a divider or an invisible view, check
						// somewhere else
						ref = pointToPosition(0, mHeight / 2 + getDividerHeight() + 64);
					}
					View v = getChildAt(ref - getFirstVisiblePosition());
					if (v != null) {
						int pos = v.getTop();
						setSelectionFromTop(ref, pos - speed);
					}
				}
			}
			break;
		default:
			break;
		}
		return true;
	}
	return super.onTouchEvent(ev);
}
 
Example 16
Project: DMAudioStreamer   File: Slider.java   View Source Code Vote up 5 votes
public static int getRelativeTop(View myView) {
    if (myView.getId() == android.R.id.content)
        return myView.getTop();
    else
        return myView.getTop() + getRelativeTop((View) myView.getParent());
}
 
Example 17
Project: Kids-Portal-Android   File: Fragment_Pass.java   View Source Code Vote up 5 votes
private void isEdited () {
    index = listView.getFirstVisiblePosition();
    View v = listView.getChildAt(0);
    top = (v == null) ? 0 : (v.getTop() - listView.getPaddingTop());
}
 
Example 18
Project: Android-CoolMenu   File: CoolMenu.java   View Source Code Vote up 5 votes
public void show() {

        int childCount = getChildCount();
        if (childCount > 1) {

            mAngle = 0;//复位

            float x = 0.5f * mEdge;
            float y = 0.5f * mEdge;
            Animator[] anim = new Animator[childCount];

            for (int i = 0; i < childCount; i++) {

                View child = getChildAt(i);
                float pivotX = x - child.getLeft();
                float pivotY = y - child.getTop();
                child.setPivotX(pivotX);
                child.setPivotY(pivotY);
                float childX = 0.5f * child.getLeft() + child.getRight() * 0.5f;
                float childY = 0.5f * child.getTop() + 0.5f * child.getBottom();

                PropertyValuesHolder ca = PropertyValuesHolder.ofFloat("alpha", 0.5f, 1.0f);
                PropertyValuesHolder csx = PropertyValuesHolder.ofFloat("scaleX", 0, 1.0f);
                PropertyValuesHolder csy = PropertyValuesHolder.ofFloat("scaleY", 0, 1.0f);

                if (i == 0) {

                    anim[i] = ObjectAnimator.ofPropertyValuesHolder(child, ca, csx, csy);
                } else {
                    PropertyValuesHolder ctx = PropertyValuesHolder.ofFloat("translationX", -x + childX, 0);
                    PropertyValuesHolder cty = PropertyValuesHolder.ofFloat("translationY", -y + childY, 0);
                    PropertyValuesHolder cr = PropertyValuesHolder.ofFloat("rotation", 0, 360f);
                    anim[i] = ObjectAnimator.ofPropertyValuesHolder(child, ctx, cty, ca, csx, csy, cr);
                }
            }

            AnimatorSet set = new AnimatorSet();
            set.setDuration(ANIM_SHOW_DURATION);
            set.setInterpolator(new LinearInterpolator());
            set.playTogether(anim);
            set.start();
        }
    }
 
Example 19
Project: airgram   File: StickerPreviewViewer.java   View Source Code Vote up 5 votes
public boolean onInterceptTouchEvent(MotionEvent event, final View listView, final int height) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        int x = (int) event.getX();
        int y = (int) event.getY();
        int count = 0;
        if (listView instanceof AbsListView) {
            count = ((AbsListView) listView).getChildCount();
        } else if (listView instanceof RecyclerListView) {
            count = ((RecyclerListView) listView).getChildCount();
        }
        for (int a = 0; a < count; a++) {
            View view = null;
            if (listView instanceof AbsListView) {
                view = ((AbsListView) listView).getChildAt(a);
            } else if (listView instanceof RecyclerListView) {
                view = ((RecyclerListView) listView).getChildAt(a);
            }
            if (view == null) {
                return false;
            }
            int top = view.getTop();
            int bottom = view.getBottom();
            int left = view.getLeft();
            int right = view.getRight();
            if (top > y || bottom < y || left > x || right < x) {
                continue;
            }
            boolean ok = false;
            if (view instanceof StickerEmojiCell) {
                ok = ((StickerEmojiCell) view).showingBitmap();
            } else if (view instanceof StickerCell) {
                ok = ((StickerCell) view).showingBitmap();
            } else if (view instanceof ContextLinkCell) {
                ContextLinkCell cell = (ContextLinkCell) view;
                ok = cell.isSticker() && cell.showingBitmap();
            }
            if (!ok) {
                return false;
            }
            startX = x;
            startY = y;
            currentStickerPreviewCell = view;
            openStickerPreviewRunnable = new Runnable() {
                @Override
                public void run() {
                    if (openStickerPreviewRunnable == null) {
                        return;
                    }
                    if (listView instanceof AbsListView) {
                        ((AbsListView) listView).setOnItemClickListener(null);
                        ((AbsListView) listView).requestDisallowInterceptTouchEvent(true);
                    } else if (listView instanceof RecyclerListView) {
                        ((RecyclerListView) listView).setOnItemClickListener(null);
                        ((RecyclerListView) listView).requestDisallowInterceptTouchEvent(true);
                    }
                    openStickerPreviewRunnable = null;
                    setParentActivity((Activity) listView.getContext());
                    setKeyboardHeight(height);
                    if (currentStickerPreviewCell instanceof StickerEmojiCell) {
                        open(((StickerEmojiCell) currentStickerPreviewCell).getSticker());
                        ((StickerEmojiCell) currentStickerPreviewCell).setScaled(true);
                    } else if (currentStickerPreviewCell instanceof StickerCell) {
                        open(((StickerCell) currentStickerPreviewCell).getSticker());
                        ((StickerCell) currentStickerPreviewCell).setScaled(true);
                    } else if (currentStickerPreviewCell instanceof ContextLinkCell) {
                        open(((ContextLinkCell) currentStickerPreviewCell).getDocument());
                        ((ContextLinkCell) currentStickerPreviewCell).setScaled(true);
                    }
                }
            };
            AndroidUtilities.runOnUIThread(openStickerPreviewRunnable, 200);
            return true;
        }
    }
    return false;
}
 
Example 20
Project: Slide-RSS   File: ViewDragHelper.java   View Source Code Vote up 4 votes
/**
 * Determine if the supplied view is under the given point in the parent
 * view's coordinate system.
 *
 * @param view Child view of the parent to hit test
 * @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 true if the supplied view is under the given point, false
 * otherwise
 */
public boolean isViewUnder(View view, int x, int y) {
    if (view == null) {
        return false;
    }
    return x >= view.getLeft() && x < view.getRight() && y >= view.getTop()
            && y < view.getBottom();
}