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:android.improving.utils.views.swipeback.ViewDragHelper.java

/**
 * Find the topmost child under the given point within the parent view's
 * coordinate system. The child order is determined using
 * {@link com.way.ui.swipeback.ViewDragHelper.Callback#getOrderedChildIndex(int)}
 * .//from   w w w.  j av a 2  s. c  o m
 * 
 * @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 The topmost child view under (x, y) or null if none found.
 */
public View findTopChildUnder(int x, int y) {
    final int childCount = mParentView.getChildCount();
    for (int i = childCount - 1; i >= 0; i--) {
        final View child = mParentView.getChildAt(mCallback.getOrderedChildIndex(i));
        if (x >= child.getLeft() && x < child.getRight() && y >= child.getTop() && y < child.getBottom()) {
            return child;
        }
    }
    return null;
}

From source file:android.improving.utils.views.swipeback.ViewDragHelper.java

/**
 * Determine if the supplied view is under the given point in the parent
 * view's coordinate system./*from ww w  .ja va  2  s  .  co  m*/
 * 
 * @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();
}

From source file:com.zertinteractive.wallpaper.MainActivity.java

@SuppressWarnings("NewApi")
private void animateRevealHide(final View viewRoot) {
    int cx = (viewRoot.getLeft() + viewRoot.getRight()) / 2;
    int cy = (viewRoot.getTop() + viewRoot.getBottom()) / 2;
    int initialRadius = viewRoot.getWidth();

    android.animation.Animator anim = ViewAnimationUtils.createCircularReveal(viewRoot, cx, cy, initialRadius,
            0);//from   w w w .j  a  va  2  s.  co m
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(android.animation.Animator animation) {
            super.onAnimationEnd(animation);
            viewRoot.setVisibility(View.INVISIBLE);
        }
    });
    anim.setDuration(getResources().getInteger(R.integer.anim_duration_medium));
    anim.start();
}

From source file:androidx.mediarouter.app.MediaRouteControllerDialog.java

void animateGroupListItemsInternal(Map<MediaRouter.RouteInfo, Rect> previousRouteBoundMap,
        Map<MediaRouter.RouteInfo, BitmapDrawable> previousRouteBitmapMap) {
    if (mGroupMemberRoutesAdded == null || mGroupMemberRoutesRemoved == null) {
        return;/*w  w  w.j a v  a 2  s .  c  om*/
    }
    int groupSizeDelta = mGroupMemberRoutesAdded.size() - mGroupMemberRoutesRemoved.size();
    boolean listenerRegistered = false;
    Animation.AnimationListener listener = new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            mVolumeGroupList.startAnimationAll();
            mVolumeGroupList.postDelayed(mGroupListFadeInAnimation, mGroupListAnimationDurationMs);
        }

        @Override
        public void onAnimationEnd(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    };

    // Animate visible items from previous positions to current positions except routes added
    // just before. Added routes will remain hidden until translate animation finishes.
    int first = mVolumeGroupList.getFirstVisiblePosition();
    for (int i = 0; i < mVolumeGroupList.getChildCount(); ++i) {
        View view = mVolumeGroupList.getChildAt(i);
        int position = first + i;
        MediaRouter.RouteInfo route = mVolumeGroupAdapter.getItem(position);
        Rect previousBounds = previousRouteBoundMap.get(route);
        int currentTop = view.getTop();
        int previousTop = previousBounds != null ? previousBounds.top
                : (currentTop + mVolumeGroupListItemHeight * groupSizeDelta);
        AnimationSet animSet = new AnimationSet(true);
        if (mGroupMemberRoutesAdded != null && mGroupMemberRoutesAdded.contains(route)) {
            previousTop = currentTop;
            Animation alphaAnim = new AlphaAnimation(0.0f, 0.0f);
            alphaAnim.setDuration(mGroupListFadeInDurationMs);
            animSet.addAnimation(alphaAnim);
        }
        Animation translationAnim = new TranslateAnimation(0, 0, previousTop - currentTop, 0);
        translationAnim.setDuration(mGroupListAnimationDurationMs);
        animSet.addAnimation(translationAnim);
        animSet.setFillAfter(true);
        animSet.setFillEnabled(true);
        animSet.setInterpolator(mInterpolator);
        if (!listenerRegistered) {
            listenerRegistered = true;
            animSet.setAnimationListener(listener);
        }
        view.clearAnimation();
        view.startAnimation(animSet);
        previousRouteBoundMap.remove(route);
        previousRouteBitmapMap.remove(route);
    }

    // If a member route doesn't exist any longer, it can be either removed or moved out of the
    // ListView layout boundary. In this case, use the previously captured bitmaps for
    // animation.
    for (Map.Entry<MediaRouter.RouteInfo, BitmapDrawable> item : previousRouteBitmapMap.entrySet()) {
        final MediaRouter.RouteInfo route = item.getKey();
        final BitmapDrawable bitmap = item.getValue();
        final Rect bounds = previousRouteBoundMap.get(route);
        OverlayListView.OverlayObject object = null;
        if (mGroupMemberRoutesRemoved.contains(route)) {
            object = new OverlayListView.OverlayObject(bitmap, bounds).setAlphaAnimation(1.0f, 0.0f)
                    .setDuration(mGroupListFadeOutDurationMs).setInterpolator(mInterpolator);
        } else {
            int deltaY = groupSizeDelta * mVolumeGroupListItemHeight;
            object = new OverlayListView.OverlayObject(bitmap, bounds).setTranslateYAnimation(deltaY)
                    .setDuration(mGroupListAnimationDurationMs).setInterpolator(mInterpolator)
                    .setAnimationEndListener(new OverlayListView.OverlayObject.OnAnimationEndListener() {
                        @Override
                        public void onAnimationEnd() {
                            mGroupMemberRoutesAnimatingWithBitmap.remove(route);
                            mVolumeGroupAdapter.notifyDataSetChanged();
                        }
                    });
            mGroupMemberRoutesAnimatingWithBitmap.add(route);
        }
        mVolumeGroupList.addOverlayObject(object);
    }
}

From source file:com.baidayi.swipback.ViewDragHelper.java

/**
 * Tests scrollability within child views of v given a delta of dx.
 * /*from  w  ww .j  av  a  2  s.co m*/
 * @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.
 */
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--) {
            // 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:android.improving.utils.views.swipeback.ViewDragHelper.java

/**
 * Tests scrollability within child views of v given a delta of dx.
 * /*from  w  w w .  j av  a  2 s .c  o m*/
 * @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.
 */
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--) {
            // 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, 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.cw.litenote.operation.audio.AudioPlayer_page.java

/**
* Scroll highlight audio item to visible position
*
* At the following conditions//w w w .j  a  va  2 s.c  o  m
*    1) click audio item of list view (this highlight is not good for user expectation, so cancel this condition now)
*    2) click previous/next item in audio controller
*    3) change tab to playing tab
*    4) back from key protect off
*    5) if seeker bar reaches the end
* In order to view audio highlight item, playing(highlighted) audio item can be auto scrolled to top,
* unless it is at the end page of list view, there is no need to scroll.
*/
public void scrollHighlightAudioItemToVisible(RecyclerView recyclerView) {
    //      System.out.println("AudioPlayer_page / _scrollHighlightAudioItemToVisible");
    if (recyclerView == null)
        return;

    LinearLayoutManager layoutMgr = ((LinearLayoutManager) recyclerView.getLayoutManager());
    // version limitation: _scrollListBy
    // NoteFragment.drag_listView.scrollListBy(firstVisibleIndex_top);
    if (Build.VERSION.SDK_INT < 19)
        return;

    int pos;
    int itemHeight = 50;//init
    int dividerHeight;
    int firstVisible_note_pos;
    View v;

    pos = layoutMgr.findFirstVisibleItemPosition();
    //         System.out.println("---------------- pos = " + pos);

    View childView;
    if (recyclerView.getAdapter() != null) {
        childView = layoutMgr.findViewByPosition(pos);

        // avoid exception: audio playing and doing checked notes operation at non-playing page
        if (childView == null)
            return;

        childView.measure(UNBOUNDED, UNBOUNDED);
        itemHeight = childView.getMeasuredHeight();
        //                System.out.println("---------------- itemHeight = " + itemHeight);
    }

    //      dividerHeight = recyclerView.getDividerHeight();//todo temp
    dividerHeight = 0;
    //         System.out.println("---------------- dividerHeight = " + dividerHeight);

    firstVisible_note_pos = layoutMgr.findFirstVisibleItemPosition();

    //      System.out.println("---------------- firstVisible_note_pos = " + firstVisible_note_pos);

    v = recyclerView.getChildAt(0);

    int firstVisibleNote_top = (v == null) ? 0 : v.getTop();
    //         System.out.println("---------------- firstVisibleNote_top = " + firstVisibleNote_top);

    //      System.out.println("---------------- Audio_manager.mAudioPos = " + Audio_manager.mAudioPos);

    if (firstVisibleNote_top < 0) {
        // restore index and top position
        recyclerView.scrollBy(0, firstVisibleNote_top);
        //            System.out.println("----- scroll backwards by firstVisibleNote_top " + firstVisibleNote_top);
    }

    boolean noScroll = false;
    // base on Audio_manager.mAudioPos to scroll
    if (firstVisible_note_pos != Audio_manager.mAudioPos) {
        while ((firstVisible_note_pos != Audio_manager.mAudioPos) && (!noScroll)) {
            int offset = itemHeight + dividerHeight;
            // scroll forwards
            if (firstVisible_note_pos > Audio_manager.mAudioPos) {
                recyclerView.scrollBy(0, -offset);
                //                  System.out.println("-----scroll forwards (to top)" + (-offset));
            }
            // scroll backwards
            else if (firstVisible_note_pos < Audio_manager.mAudioPos) {
                // when real item height could be larger than visible item height, so
                // scroll twice here in odder to do scroll successfully, otherwise scroll could fail
                recyclerView.scrollBy(0, offset / 2);
                recyclerView.scrollBy(0, offset / 2);
                //               System.out.println("-----scroll backwards (to bottom) " + offset);
            }

            //               System.out.println("---------------- firstVisible_note_pos = " + firstVisible_note_pos);
            //               System.out.println("---------------- Page.drag_listView.getFirstVisiblePosition() = " + listView.getFirstVisiblePosition());
            if (firstVisible_note_pos == layoutMgr.findFirstVisibleItemPosition())
                noScroll = true;
            else {
                // update first visible index
                firstVisible_note_pos = layoutMgr.findFirstVisibleItemPosition();
            }
        }

        // do v scroll
        TabsHost.store_listView_vScroll(recyclerView);
        TabsHost.resume_listView_vScroll(recyclerView);
    }
}

From source file:com.comcast.freeflow.core.FreeFlowContainer.java

/**
 * Returns the actual frame for a view as its on stage. The FreeFlowItem's
 * frame object always represents the position it wants to be in but actual
 * frame may be different based on animation etc.
 * // ww w  . ja va2s.c  o m
 * @param freeflowItem
 *            The freeflowItem to get the <code>Frame</code> for
 * @return The Frame for the freeflowItem or null if that view doesn't exist
 */
public Rect getActualFrame(final FreeFlowItem freeflowItem) {
    View v = freeflowItem.view;
    if (v == null) {
        return null;
    }

    Rect of = new Rect();
    of.left = (int) (v.getLeft() + v.getTranslationX());
    of.top = (int) (v.getTop() + v.getTranslationY());
    of.right = (int) (v.getRight() + v.getTranslationX());
    of.bottom = (int) (v.getBottom() + v.getTranslationY());

    return of;

}

From source file:com.android.dialer.widget.OverlappingPaneLayout.java

void updateObscuredViewsVisibility(View panel) {
    final int startBound = getPaddingTop();
    final int endBound = getHeight() - getPaddingBottom();

    final int leftBound = getPaddingLeft();
    final int rightBound = getWidth() - getPaddingRight();
    final int left;
    final int right;
    final int top;
    final int bottom;
    if (panel != null && viewIsOpaque(panel)) {
        left = panel.getLeft();//from  www  . ja  va  2 s.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(leftBound, child.getLeft());
        final int clampedChildRight = Math.min(rightBound, child.getRight());
        final int clampedChildTop = Math.max(startBound, child.getTop());
        final int clampedChildBottom = Math.min(endBound, 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:am.widget.scalerecyclerview.ScaleRecyclerView.java

/**
 * /*from  w  ww  .  j  av  a 2 s . c  om*/
 *
 * @param scale  
 * @param focusX X
 * @param focusY Y
 */
public void scaleTo(float scale, float focusX, float focusY) {
    scale = scale > mMaxScale ? mMaxScale : scale;
    scale = scale < mMinScale ? mMinScale : scale;
    if (scale == mScale)
        return;
    final ScaleLinearLayoutManager manager = getLayoutManager();
    if (manager == null) {
        mScale = scale;
        invalidateLayoutManagerScale();
        requestLayout();
        return;
    }
    final View target = findChildViewNear(focusX, focusY);
    if (target == null) {
        mScale = scale;
        invalidateLayoutManagerScale();
        requestLayout();
        return;
    }
    final int position = getChildAdapterPosition(target);
    float maxWidth = manager.getChildMaxWidth(manager.getChildMaxWidth());
    float maxHeight = manager.getChildMaxHeight(manager.getChildMaxHeight());
    final int offsetA = manager.computeAnotherDirectionScrollOffset();
    final float normalWidth = target.getWidth() / mScale;
    final float normalHeight = target.getHeight() / mScale;
    final float inset;
    final float focusA;
    final float focusS;
    getDecoratedBoundsWithMargins(target, tRect);
    if (manager.getOrientation() == HORIZONTAL) {
        focusA = (offsetA + (focusY - getPaddingTop())) / maxHeight;
        inset = target.getLeft() - tRect.left;
        focusS = (focusX - target.getLeft()) / target.getWidth();
    } else {
        focusA = (offsetA + (focusX - getPaddingLeft())) / maxWidth;
        focusS = (focusY - target.getTop()) / target.getHeight();
        inset = target.getTop() - tRect.top;
    }
    mScale = scale;
    invalidateLayoutManagerScale();
    final float maxOffset = manager.computeAnotherDirectionMaxScrollOffset();
    if (maxOffset <= 0) {
        manager.setAnotherDirectionScrollOffsetPercentage(0);
    } else {
        maxWidth = manager.getChildMaxWidth(manager.getChildMaxWidth());
        maxHeight = manager.getChildMaxHeight(manager.getChildMaxHeight());
        final float scaleOffset;
        if (manager.getOrientation() == HORIZONTAL) {
            scaleOffset = focusA * maxHeight - (focusY - getPaddingTop());
        } else {
            scaleOffset = focusA * maxWidth - (focusX - getPaddingLeft());
        }
        manager.setAnotherDirectionScrollOffsetPercentage(scaleOffset / maxOffset);
    }
    final float offsetS;
    if (manager.getOrientation() == HORIZONTAL) {
        offsetS = -(focusS * normalWidth * mScale - (focusX - getPaddingLeft())) - inset;
    } else {
        offsetS = -(focusS * normalHeight * mScale - (focusY - getPaddingTop())) - inset;
    }
    manager.scrollToPositionWithOffset(position, Math.round(offsetS));
}