Example usage for android.view View getTop

List of usage examples for android.view View getTop

Introduction

In this page you can find the example usage for android.view View getTop.

Prototype

@ViewDebug.CapturedViewProperty
public final int getTop() 

Source Link

Document

Top position of this view relative to its parent.

Usage

From source file:com.aigo.kt03airdemo.ui.view.ResideLayout.java

void updateObscuredViewsVisibility(View panel) {
    final int startBound = getPaddingLeft();
    final int endBound = getWidth() - getPaddingRight();
    final int topBound = getPaddingTop();
    final int bottomBound = getHeight() - getPaddingBottom();
    final int left;
    final int right;
    final int top;
    final int bottom;
    if (panel != null && viewIsOpaque(panel)) {
        left = panel.getLeft();/*from  www.ja v  a  2  s  . c  om*/
        right = panel.getRight();
        top = panel.getTop();
        bottom = panel.getBottom();
    } else {
        left = right = top = bottom = 0;
    }

    for (int i = 0, childCount = getChildCount(); i < childCount; i++) {
        final View child = getChildAt(i);

        if (child == panel) {
            // There are still more children above the panel but they won't be affected.
            break;
        }

        final int clampedChildLeft = Math.max(startBound, child.getLeft());
        final int clampedChildTop = Math.max(topBound, child.getTop());
        final int clampedChildRight = Math.min(endBound, child.getRight());
        final int clampedChildBottom = Math.min(bottomBound, child.getBottom());
        final int vis;
        if (clampedChildLeft >= left && clampedChildTop >= top && clampedChildRight <= right
                && clampedChildBottom <= bottom) {
            vis = INVISIBLE;
        } else {
            vis = VISIBLE;
        }
        child.setVisibility(vis);
    }
}

From source file:cn.ieclipse.af.view.StaggeredGridView.java

private void dumpItemPositions() {
    final int childCount = getChildCount();
    Log.d(TAG, "dumpItemPositions:");
    Log.d(TAG, " => Tops:");
    for (int i = 0; i < mColCount; i++) {
        Log.d(TAG, "  => " + mItemTops[i]);
        boolean found = false;
        for (int j = 0; j < childCount; j++) {
            final View child = getChildAt(j);
            if (mItemTops[i] == child.getTop() - mItemMargin) {
                found = true;/* w  w  w.j  a va  2s .com*/
            }
        }
        if (!found) {
            Log.d(TAG, "!!! No top item found for column " + i + " value " + mItemTops[i]);
        }
    }
    Log.d(TAG, " => Bottoms:");
    for (int i = 0; i < mColCount; i++) {
        Log.d(TAG, "  => " + mItemBottoms[i]);
        boolean found = false;
        for (int j = 0; j < childCount; j++) {
            final View child = getChildAt(j);
            if (mItemBottoms[i] == child.getBottom()) {
                found = true;
            }
        }
        if (!found) {
            Log.d(TAG, "!!! No bottom item found for column " + i + " value " + mItemBottoms[i]);
        }
    }
}

From source file:com.android.launcher3.Utilities.java

/**
 * Given a coordinate relative to the descendant, find the coordinate in a parent view's
 * coordinates.//from   ww w .  j  a  v  a2 s.  com
 *
 * @param descendant The descendant to which the passed coordinate is relative.
 * @param ancestor The root view to make the coordinates relative to.
 * @param coord The coordinate that we want mapped.
 * @param includeRootScroll Whether or not to account for the scroll of the descendant:
 *          sometimes this is relevant as in a child's coordinates within the descendant.
 * @return The factor by which this descendant is scaled relative to this DragLayer. Caution
 *         this scale factor is assumed to be equal in X and Y, and so if at any point this
 *         assumption fails, we will need to return a pair of scale factors.
 */
public static float getDescendantCoordRelativeToAncestor(View descendant, View ancestor, int[] coord,
        boolean includeRootScroll) {
    float[] pt = { coord[0], coord[1] };
    float scale = 1.0f;
    View v = descendant;
    while (v != ancestor && v != null) {
        // For TextViews, scroll has a meaning which relates to the text position
        // which is very strange... ignore the scroll.
        if (v != descendant || includeRootScroll) {
            pt[0] -= v.getScrollX();
            pt[1] -= v.getScrollY();
        }

        v.getMatrix().mapPoints(pt);
        pt[0] += v.getLeft();
        pt[1] += v.getTop();
        scale *= v.getScaleX();

        v = (View) v.getParent();
    }

    coord[0] = Math.round(pt[0]);
    coord[1] = Math.round(pt[1]);
    return scale;
}

From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.MessageCenterFragment.java

public void addAttachmentsToComposer(ImageItem... images) {
    ArrayList<ImageItem> newImages = new ArrayList<ImageItem>();
    // only add new images, and filter out duplicates
    if (images != null && images.length > 0) {
        for (ImageItem newImage : images) {
            boolean bDupFound = false;
            for (ImageItem pendingAttachment : pendingAttachments) {
                if (newImage.originalPath.equals(pendingAttachment.originalPath)) {
                    bDupFound = true;/* www.ja  va2s  . co  m*/
                    break;
                }
            }
            if (bDupFound) {
                continue;
            } else {
                pendingAttachments.add(newImage);
                newImages.add(newImage);
            }
        }
    }
    View v = messageCenterRecyclerView.getChildAt(0);
    int top = (v == null) ? 0 : v.getTop();

    if (newImages.isEmpty()) {
        return;
    }
    messageCenterRecyclerViewAdapter.addImagestoComposer(composer, newImages);
    messageCenterRecyclerViewAdapter.notifyItemChanged(listItems.size() - 1);
    int firstIndex = messageCenterRecyclerView.getFirstVisiblePosition();
    messagingActionHandler
            .sendMessage(messagingActionHandler.obtainMessage(MSG_SCROLL_FROM_TOP, firstIndex, top));
}

From source file:com.cylee.dragcontentviewpager.ViewDragHelper.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)./*from  w  w w .  j  a v  a 2  s  .c om*/
 * @param dx Delta scrolled in pixels along the X axis
 * @param dy Delta scrolled in pixels along the Y axis
 * @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 dy, int x, int y) {
    if (v instanceof ViewGroup) {
        if (v instanceof AbsListView && Math.abs(dy) > Math.abs(dx)) {
            if (Build.VERSION.SDK_INT >= 19) {
                return ((AbsListView) v).canScrollList(-dy);
            }
            return true;
        }
        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,
                            checkV, dx, dy, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.MessageCenterFragment.java

/**
 * Call only from handler./* w  w w  .  java 2s  .c  o m*/
 */
public void displayNewIncomingMessageItem(ApptentiveMessage message) {
    messagingActionHandler.sendEmptyMessage(MSG_REMOVE_STATUS);
    // Determine where to insert the new incoming message. It will be in front of any eidting
    // area, i.e. composing, Who Card ...
    int insertIndex = listItems.size(); // If inserted onto the end, then the list will have grown by one.

    outside_loop:
    // Starting at end of list, go back up the list to find the proper place to insert the incoming message.
    for (int i = listItems.size() - 1; i > 0; i--) {
        MessageCenterListItem item = listItems.get(i);
        switch (item.getListItemType()) {
        case MESSAGE_COMPOSER:
        case MESSAGE_CONTEXT:
        case WHO_CARD:
        case STATUS:
            insertIndex--;
            break;
        default:
            // Any other type means we are past the temporary items.
            break outside_loop;
        }
    }
    listItems.add(insertIndex, message);
    messageCenterRecyclerViewAdapter.notifyItemInserted(insertIndex);

    int firstIndex = messageCenterRecyclerView.getFirstVisiblePosition();
    int lastIndex = messageCenterRecyclerView.getLastVisiblePosition();
    boolean composingAreaTakesUpVisibleArea = firstIndex <= insertIndex && insertIndex < lastIndex;
    if (composingAreaTakesUpVisibleArea) {
        View v = messageCenterRecyclerView.getChildAt(0);
        int top = (v == null) ? 0 : v.getTop();
        updateMessageSentStates();
        // Restore the position of listview to composing view
        messagingActionHandler
                .sendMessage(messagingActionHandler.obtainMessage(MSG_SCROLL_FROM_TOP, insertIndex, top));
    } else {
        updateMessageSentStates();
    }
}

From source file:cn.ieclipse.af.view.StaggeredGridView.java

/**
 * Important: this method will leave offscreen views attached if they
 * are required to maintain the invariant that child view with index i
 * is always the view corresponding to position mFirstPosition + i.
 *///from  www  . j  a  v a2  s.c  o  m
private void recycleOffscreenViews() {
    final int height = getHeight();
    final int clearAbove = -mItemMargin;
    final int clearBelow = height + mItemMargin;
    for (int i = getChildCount() - 1; i >= 0; i--) {
        final View child = getChildAt(i);
        if (child.getTop() <= clearBelow) {
            // There may be other offscreen views, but we need to maintain
            // the invariant documented above.
            break;
        }

        if (mInLayout) {
            removeViewsInLayout(i, 1);
        } else {
            removeViewAt(i);
        }

        mRecycler.addScrap(child);
    }

    while (getChildCount() > 0) {
        final View child = getChildAt(0);
        if (child.getBottom() >= clearAbove) {
            // There may be other offscreen views, but we need to maintain
            // the invariant documented above.
            break;
        }

        if (mInLayout) {
            removeViewsInLayout(0, 1);
        } else {
            removeViewAt(0);
        }

        mRecycler.addScrap(child);
        mFirstPosition++;
    }

    final int childCount = getChildCount();
    if (childCount > 0) {
        // Repair the top and bottom column boundaries from the views we still have
        Arrays.fill(mItemTops, Integer.MAX_VALUE);
        Arrays.fill(mItemBottoms, Integer.MIN_VALUE);

        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            final int top = child.getTop() - mItemMargin;
            final int bottom = child.getBottom();
            final LayoutRecord rec = mLayoutRecords.get(mFirstPosition + i);

            final int colEnd = lp.column + Math.min(mColCount, lp.span);
            for (int col = lp.column; col < colEnd; col++) {
                final int colTop = top - rec.getMarginAbove(col - lp.column);
                final int colBottom = bottom + rec.getMarginBelow(col - lp.column);
                if (colTop < mItemTops[col]) {
                    mItemTops[col] = colTop;
                }
                if (colBottom > mItemBottoms[col]) {
                    mItemBottoms[col] = colBottom;
                }
            }
        }

        for (int col = 0; col < mColCount; col++) {
            if (mItemTops[col] == Integer.MAX_VALUE) {
                // If one was untouched, both were.
                mItemTops[col] = 0;
                mItemBottoms[col] = 0;
            }
        }
    }
}

From source file:com.bright.cloudutils.view.ResideLayout.java

void updateObscuredViewsVisibility(View panel) {
    final int startBound = getPaddingLeft();
    final int endBound = getWidth() - getPaddingRight();
    final int topBound = getPaddingTop();
    final int bottomBound = getHeight() - getPaddingBottom();
    final int left;
    final int right;
    final int top;
    final int bottom;
    if (panel != null && viewIsOpaque(panel)) {
        left = panel.getLeft();//from  w w w .  j  a  va  2s  .  c  o m
        right = panel.getRight();
        top = panel.getTop();
        bottom = panel.getBottom();
    } else {
        left = right = top = bottom = 0;
    }

    for (int i = 0, childCount = getChildCount(); i < childCount; i++) {
        final View child = getChildAt(i);

        if (child == panel) {
            // There are still more children above the panel but they won't
            // be affected.
            break;
        }

        final int clampedChildLeft = Math.max(startBound, child.getLeft());
        final int clampedChildTop = Math.max(topBound, child.getTop());
        final int clampedChildRight = Math.min(endBound, child.getRight());
        final int clampedChildBottom = Math.min(bottomBound, child.getBottom());
        final int vis;
        if (clampedChildLeft >= left && clampedChildTop >= top && clampedChildRight <= right
                && clampedChildBottom <= bottom) {
            vis = INVISIBLE;
        } else {
            vis = VISIBLE;
        }
        child.setVisibility(vis);
    }
}

From source file:cn.xm.xmvideoplayer.widget.swipebacklayout.ViewDragHelper.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 along the X axis
 * @param dy     Delta scrolled in pixels along the Y axis
 * @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 w w w  .  j ava2s .  c o  m*/
protected boolean canScroll(View v, boolean checkV, int dx, int dy, 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--) {
            // 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, dy, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    return checkV && (ViewCompat.canScrollHorizontally(v, -dx) || ViewCompat.canScrollVertically(v, -dy));
}

From source file:com.along.practice.widget.swipbacklayout.ViewDragHelper.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 along the X axis
 * @param dy     Delta scrolled in pixels along the Y axis
 * @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.
 *//*  w  ww . j a  va2s  .  c  o m*/
protected boolean canScroll(View v, boolean checkV, int dx, int dy, 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--) {
            //  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, dy, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    return checkV && (ViewCompat.canScrollHorizontally(v, -dx) || ViewCompat.canScrollVertically(v, -dy));
}